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

KDEUI

  • kdeui
  • colors
khuesaturationselect.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE libraries
2  Copyright (C) 1997 Martin Jones (mjones@kde.org)
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License as published by the Free Software Foundation; either
7  version 2 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18 */
19 
20 #include "khuesaturationselect.h"
21 
22 #include <QtGui/QPainter>
23 
24 #include "kcolorchoosermode_p.h"
25 
26 using namespace KDEPrivate;
27 
28 class KHueSaturationSelector::Private
29 {
30 public:
31  Private(KHueSaturationSelector *q): q(q) {}
32 
33  KHueSaturationSelector *q;
34  QPixmap pixmap;
35 
39  KColorChooserMode _mode;
40 
44  int _hue, _sat, _colorValue;
45 };
46 
47 
48 
49 KHueSaturationSelector::KHueSaturationSelector( QWidget *parent )
50  : KXYSelector( parent ), d( new Private( this ) )
51 {
52  setChooserMode( ChooserClassic );
53 }
54 
55 KColorChooserMode KHueSaturationSelector::chooserMode() const
56 {
57  return d->_mode;
58 }
59 
60 void KHueSaturationSelector::setChooserMode( KColorChooserMode chooserMode )
61 {
62  int x;
63  int y = 255;
64 
65  switch ( chooserMode ) {
66  case ChooserSaturation:
67  case ChooserValue:
68  x = 359;
69  break;
70  default:
71  x = 255;
72  break;
73  }
74 
75  setRange( 0, 0, x, y );
76  d->_mode = chooserMode;
77 }
78 
79 int KHueSaturationSelector::hue () const
80 {
81  return d->_hue;
82 }
83 
84 void KHueSaturationSelector::setHue ( int hue )
85 {
86  d->_hue = hue;
87 }
88 
89 int KHueSaturationSelector::saturation () const
90 
91 {
92  return d->_sat;
93 }
94 
95 void KHueSaturationSelector::setSaturation( int saturation )
96 {
97  d->_sat = saturation;
98 }
99 
100 int KHueSaturationSelector::colorValue() const
101 {
102  return d->_colorValue;
103 }
104 
105 void KHueSaturationSelector::setColorValue( int colorValue )
106 {
107  d->_colorValue = colorValue;
108 }
109 
110 KHueSaturationSelector::~KHueSaturationSelector()
111 {
112  delete d;
113 }
114 
115 void KHueSaturationSelector::updateContents()
116 {
117  drawPalette( &d->pixmap );
118 }
119 
120 void KHueSaturationSelector::resizeEvent( QResizeEvent * )
121 {
122  updateContents();
123 }
124 
125 void KHueSaturationSelector::drawContents( QPainter *painter )
126 {
127  painter->drawPixmap( contentsRect().x(), contentsRect().y(), d->pixmap );
128 }
129 
130 void KHueSaturationSelector::drawPalette( QPixmap *pixmap )
131 {
132  int xSteps = componentXSteps(chooserMode());
133  int ySteps = componentYSteps(chooserMode());
134 
135  QColor color;
136  color.setHsv(hue(), saturation(), chooserMode() == ChooserClassic ? 192 : colorValue());
137 
138  QImage image(QSize(xSteps + 1, ySteps + 1), QImage::Format_RGB32);
139  for (int y = 0; y <= ySteps; ++y) {
140  setComponentY(color, chooserMode(), y * (1.0 / ySteps));
141  for (int x = 0; x <= xSteps; ++x) {
142  setComponentX(color, chooserMode(), x * (1.0 / xSteps));
143  image.setPixel(x, ySteps - y, color.rgb());
144  }
145  }
146 
147  QPixmap pix(contentsRect().size());
148  QPainter painter(&pix);
149  // Bilinear filtering
150  painter.setRenderHint(QPainter::SmoothPixmapTransform, true);
151  QRectF srcRect(0.5, 0.5, xSteps, ySteps);
152  QRectF destRect(QPointF(0, 0), contentsRect().size());
153  painter.drawImage(destRect, image, srcRect);
154  painter.end();
155 
156  *pixmap = pix;
157 }
158 
159 #include "khuesaturationselect.moc"
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Fri Jul 12 2013 08:52:49 by doxygen 1.8.3.1 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDEUI

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

kdelibs-4.10.5 API Reference

Skip menu "kdelibs-4.10.5 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • 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
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal