• Skip to content
  • Skip to link menu
KDE 4.3 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • 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 #include <kglobal.h>
00024 
00025 K_GLOBAL_STATIC(QVector<QColor>, s_standardPalette)
00026 
00027 // Shared with KColorValueSelector
00028 KDEUI_EXPORT QVector<QColor> kdeui_standardPalette()
00029 {
00030     if ( !s_standardPalette ) {
00031 
00032         int i = 0;
00033 #ifndef STANDARD_PAL_SIZE
00034 #define STANDARD_PAL_SIZE 17
00035 #endif
00036         s_standardPalette->resize( STANDARD_PAL_SIZE );
00037 
00038         ( *s_standardPalette ) [ i++ ] = Qt::red;
00039         ( *s_standardPalette ) [ i++ ] = Qt::green;
00040         ( *s_standardPalette ) [ i++ ] = Qt::blue;
00041         ( *s_standardPalette ) [ i++ ] = Qt::cyan;
00042         ( *s_standardPalette ) [ i++ ] = Qt::magenta;
00043         ( *s_standardPalette ) [ i++ ] = Qt::yellow;
00044         ( *s_standardPalette ) [ i++ ] = Qt::darkRed;
00045         ( *s_standardPalette ) [ i++ ] = Qt::darkGreen;
00046         ( *s_standardPalette ) [ i++ ] = Qt::darkBlue;
00047         ( *s_standardPalette ) [ i++ ] = Qt::darkCyan;
00048         ( *s_standardPalette ) [ i++ ] = Qt::darkMagenta;
00049         ( *s_standardPalette ) [ i++ ] = Qt::darkYellow;
00050         ( *s_standardPalette ) [ i++ ] = Qt::white;
00051         ( *s_standardPalette ) [ i++ ] = Qt::lightGray;
00052         ( *s_standardPalette ) [ i++ ] = Qt::gray;
00053         ( *s_standardPalette ) [ i++ ] = Qt::darkGray;
00054         ( *s_standardPalette ) [ i++ ] = Qt::black;
00055     }
00056     return *s_standardPalette;
00057 }
00058 
00059 
00060 class KHueSaturationSelector::Private
00061 {
00062 public:
00063     Private(KHueSaturationSelector *q): q(q) {}
00064 
00065     KHueSaturationSelector *q;
00066     QPixmap pixmap;
00067 
00071     KColorChooserMode _mode;
00072 
00076     int _hue, _sat, _colorValue;
00077 };
00078 
00079 
00080 
00081 KHueSaturationSelector::KHueSaturationSelector( QWidget *parent )
00082         : KXYSelector( parent ), d( new Private( this ) )
00083 {
00084     setRange( 0, 0, 359, 255 );
00085     setChooserMode( ChooserClassic );
00086 }
00087 
00088 KColorChooserMode KHueSaturationSelector::chooserMode() const
00089 {
00090     return d->_mode;
00091 }
00092 
00093 void KHueSaturationSelector::setChooserMode( KColorChooserMode chooserMode )
00094 {
00095     int x;
00096     int y = 255;
00097 
00098     switch ( chooserMode ) {
00099     case ChooserSaturation:
00100     case ChooserValue:
00101         x = 359;
00102         break;
00103     default:
00104         x = 255;
00105         break;
00106     }
00107 
00108     setRange( 0, 0, x, y );
00109     d->_mode = chooserMode;
00110 }
00111 
00112 int KHueSaturationSelector::hue () const
00113 {
00114     return d->_hue;
00115 }
00116 
00117 void KHueSaturationSelector::setHue ( int hue )
00118 {
00119     d->_hue = hue;
00120 }
00121 
00122 int KHueSaturationSelector::saturation () const
00123 
00124 {
00125     return d->_sat;
00126 }
00127 
00128 void KHueSaturationSelector::setSaturation( int saturation )
00129 {
00130     d->_sat = saturation;
00131 }
00132 
00133 int KHueSaturationSelector::colorValue() const
00134 {
00135     return d->_colorValue;
00136 }
00137 
00138 void KHueSaturationSelector::setColorValue( int colorValue )
00139 {
00140     d->_colorValue = colorValue;
00141 }
00142 
00143 KHueSaturationSelector::~KHueSaturationSelector()
00144 {
00145     delete d;
00146 }
00147 
00148 void KHueSaturationSelector::updateContents()
00149 {
00150     drawPalette( &d->pixmap );
00151 }
00152 
00153 void KHueSaturationSelector::resizeEvent( QResizeEvent * )
00154 {
00155     updateContents();
00156 }
00157 
00158 void KHueSaturationSelector::drawContents( QPainter *painter )
00159 {
00160     painter->drawPixmap( contentsRect().x(), contentsRect().y(), d->pixmap );
00161 }
00162 
00163 void KHueSaturationSelector::drawPalette( QPixmap *pixmap )
00164 {
00165     int xSize = contentsRect().width(), ySize = contentsRect().height();
00166     QImage image( QSize( xSize, ySize ), QImage::Format_RGB32 );
00167     QColor col;
00168     int h, s;
00169     uint *p;
00170 
00171     col.setHsv( hue(), saturation(), colorValue() );
00172 
00173     int _h, _s, _v, _r, _g, _b;
00174     col.getHsv( &_h, &_s, &_v );
00175     col.getRgb( &_r, &_g, &_b );
00176 
00177     for ( s = ySize-1; s >= 0; s-- )
00178     {
00179         p = ( uint * ) image.scanLine( ySize - s - 1 );
00180         for( h = 0; h < xSize; h++ )
00181         {
00182             switch ( chooserMode() ) {
00183             case ChooserClassic:
00184             default:
00185                 col.setHsv( 359 * h / ( xSize - 1 ), 255 * s / ( ( ySize == 1 ) ? 1 : ySize - 1 ), 192 );
00186                 break;
00187             case ChooserHue:
00188                 col.setHsv( _h, 255 * h / ( xSize - 1 ), 255 * s / ( ( ySize == 1 ) ? 1 : ySize - 1 ) );
00189                 break;
00190             case ChooserSaturation:
00191                 col.setHsv( 359 * h / ( xSize - 1 ), _s, 255 * s / ( ( ySize == 1 ) ? 1 : ySize - 1 ) );
00192                 break;
00193             case ChooserValue:
00194                 col.setHsv( 359 * h / ( xSize - 1 ), 255 * s / ( ( ySize == 1 ) ? 1 : ySize - 1 ), _v );
00195                 break;
00196             case ChooserRed:
00197                 col.setRgb( _r, 255 * h / ( xSize - 1 ), 255 * s / ( ( ySize == 1 ) ? 1 : ySize - 1 ) );
00198                 break;
00199             case ChooserGreen:
00200                 col.setRgb( 255 * h / ( xSize - 1 ), _g, 255 * s / ( ( ySize == 1 ) ? 1 : ySize - 1 ) );
00201                 break;
00202             case ChooserBlue:
00203                 col.setRgb( 255 * s / ( ( ySize == 1 ) ? 1 : ySize - 1 ), 255 * h / ( xSize - 1 ), _b );
00204                 break;
00205             }
00206 
00207             *p = col.rgb();
00208             p++;
00209         }
00210     }
00211 
00212     /*
00213     if ( pixmap->depth() <= 8 )
00214     {
00215         const QVector<QColor> standardPalette = kdeui_standardPalette();
00216         KImageEffect::dither( image, standardPalette.data(), standardPalette.size() );
00217     }
00218     */
00219     *pixmap = QPixmap::fromImage( image );
00220 }
00221 
00222 #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
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.6.1
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