• Skip to content
  • Skip to link menu
KDE 4.6 API Reference
  • KDE API Reference
  • kdelibs
  • KDE Home
  • Contact Us
 

KDEUI

khuesaturationselect.cpp

Go to the documentation of this file.
00001 /* This file is part of the KDE libraries
00002   Copyright (C) 1997 Martin Jones (mjones@kde.org)
00003 
00004   This library is free software; you can redistribute it and/or
00005   modify it under the terms of the GNU Library General Public
00006   License as published by the Free Software Foundation; either
00007   version 2 of the License, or (at your option) any later version.
00008 
00009   This library is distributed in the hope that it will be useful,
00010   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012   Library General Public License for more details.
00013 
00014   You should have received a copy of the GNU Library General Public License
00015   along with this library; see the file COPYING.LIB.  If not, write to
00016   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017   Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #include "khuesaturationselect.h"
00021 
00022 #include <QtGui/QPainter>
00023 
00024 #include "kcolorchoosermode_p.h"
00025 
00026 using namespace KDEPrivate;
00027 
00028 class KHueSaturationSelector::Private
00029 {
00030 public:
00031     Private(KHueSaturationSelector *q): q(q) {}
00032 
00033     KHueSaturationSelector *q;
00034     QPixmap pixmap;
00035 
00039     KColorChooserMode _mode;
00040 
00044     int _hue, _sat, _colorValue;
00045 };
00046 
00047 
00048 
00049 KHueSaturationSelector::KHueSaturationSelector( QWidget *parent )
00050         : KXYSelector( parent ), d( new Private( this ) )
00051 {
00052     setChooserMode( ChooserClassic );
00053 }
00054 
00055 KColorChooserMode KHueSaturationSelector::chooserMode() const
00056 {
00057     return d->_mode;
00058 }
00059 
00060 void KHueSaturationSelector::setChooserMode( KColorChooserMode chooserMode )
00061 {
00062     int x;
00063     int y = 255;
00064 
00065     switch ( chooserMode ) {
00066     case ChooserSaturation:
00067     case ChooserValue:
00068         x = 359;
00069         break;
00070     default:
00071         x = 255;
00072         break;
00073     }
00074 
00075     setRange( 0, 0, x, y );
00076     d->_mode = chooserMode;
00077 }
00078 
00079 int KHueSaturationSelector::hue () const
00080 {
00081     return d->_hue;
00082 }
00083 
00084 void KHueSaturationSelector::setHue ( int hue )
00085 {
00086     d->_hue = hue;
00087 }
00088 
00089 int KHueSaturationSelector::saturation () const
00090 
00091 {
00092     return d->_sat;
00093 }
00094 
00095 void KHueSaturationSelector::setSaturation( int saturation )
00096 {
00097     d->_sat = saturation;
00098 }
00099 
00100 int KHueSaturationSelector::colorValue() const
00101 {
00102     return d->_colorValue;
00103 }
00104 
00105 void KHueSaturationSelector::setColorValue( int colorValue )
00106 {
00107     d->_colorValue = colorValue;
00108 }
00109 
00110 KHueSaturationSelector::~KHueSaturationSelector()
00111 {
00112     delete d;
00113 }
00114 
00115 void KHueSaturationSelector::updateContents()
00116 {
00117     drawPalette( &d->pixmap );
00118 }
00119 
00120 void KHueSaturationSelector::resizeEvent( QResizeEvent * )
00121 {
00122     updateContents();
00123 }
00124 
00125 void KHueSaturationSelector::drawContents( QPainter *painter )
00126 {
00127     painter->drawPixmap( contentsRect().x(), contentsRect().y(), d->pixmap );
00128 }
00129 
00130 void KHueSaturationSelector::drawPalette( QPixmap *pixmap )
00131 {
00132     int xSteps = componentXSteps(chooserMode());
00133     int ySteps = componentYSteps(chooserMode());
00134 
00135     QColor color;
00136     color.setHsv(hue(), saturation(), chooserMode() == ChooserClassic ? 192 : colorValue());
00137 
00138     QImage image(QSize(xSteps + 1, ySteps + 1), QImage::Format_RGB32);
00139     for (int y = 0; y <= ySteps; ++y) {
00140         setComponentY(color, chooserMode(), y * (1.0 / ySteps));
00141         for (int x = 0; x <= xSteps; ++x) {
00142             setComponentX(color, chooserMode(), x * (1.0 / xSteps));
00143             image.setPixel(x, ySteps - y, color.rgb());
00144         }
00145     }
00146 
00147     QPixmap pix(contentsRect().size());
00148     QPainter painter(&pix);
00149     // Bilinear filtering
00150     painter.setRenderHint(QPainter::SmoothPixmapTransform, true);
00151     QRectF srcRect(0.5, 0.5, xSteps, ySteps);
00152     QRectF destRect(QPointF(0, 0), contentsRect().size());
00153     painter.drawImage(destRect, image, srcRect);
00154     painter.end();
00155 
00156     *pixmap = pix;
00157 }
00158 
00159 #include "khuesaturationselect.moc"

KDEUI

Skip menu "KDEUI"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.7.3
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal