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

KDEUI

  • sources
  • kde-4.14
  • kdelibs
  • 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"
QResizeEvent
QWidget
KHueSaturationSelector::chooserMode
KColorChooserMode chooserMode() const
Returns the chooser mode.
Definition: khuesaturationselect.cpp:55
KHueSaturationSelector::updateContents
void updateContents()
Updates the contents.
Definition: khuesaturationselect.cpp:115
QPainter::end
bool end()
QPainter::setRenderHint
void setRenderHint(RenderHint hint, bool on)
KHueSaturationSelector::colorValue
int colorValue() const
Returns the color value (also known as lumniousity, 0-255)
Definition: khuesaturationselect.cpp:100
QImage::setPixel
void setPixel(int x, int y, uint index_or_rgb)
QWidget::y
int y() const
KHueSaturationSelector::setHue
void setHue(int hue)
Sets the hue value (0-360)
Definition: khuesaturationselect.cpp:84
KXYSelector::setRange
void setRange(int minX, int minY, int maxX, int maxY)
Sets the range of possible values.
Definition: kxyselector.cpp:83
ChooserValue
Definition: kcolorchoosermode.h:27
KHueSaturationSelector::KHueSaturationSelector
KHueSaturationSelector(QWidget *parent=0)
Constructs a hue/saturation selection widget.
Definition: khuesaturationselect.cpp:49
KHueSaturationSelector::setColorValue
void setColorValue(int colorValue)
Sets the color value (0-255)
Definition: khuesaturationselect.cpp:105
QPointF
KHueSaturationSelector
Definition: khuesaturationselect.h:28
ChooserSaturation
Definition: kcolorchoosermode.h:26
QWidget::size
QSize size() const
KHueSaturationSelector::Private
friend class Private
Definition: khuesaturationselect.h:123
khuesaturationselect.h
KHueSaturationSelector::hue
int hue() const
Returns the hue value.
Definition: khuesaturationselect.cpp:79
QWidget::x
int x() const
KHueSaturationSelector::drawPalette
virtual void drawPalette(QPixmap *pixmap)
Draws the contents of the widget on a pixmap, which is used for buffering.
Definition: khuesaturationselect.cpp:130
QColor::rgb
QRgb rgb() const
QPainter::drawPixmap
void drawPixmap(const QRectF &target, const QPixmap &pixmap, const QRectF &source)
QPainter
KHueSaturationSelector::~KHueSaturationSelector
~KHueSaturationSelector()
Destructor.
Definition: khuesaturationselect.cpp:110
QColor
KXYSelector::contentsRect
QRect contentsRect() const
Definition: kxyselector.cpp:150
KHueSaturationSelector::resizeEvent
virtual void resizeEvent(QResizeEvent *)
Definition: khuesaturationselect.cpp:120
QPixmap
KColorChooserMode
KColorChooserMode
Definition: kcolorchoosermode.h:22
QSize
QImage
KHueSaturationSelector::saturation
int saturation() const
Returns the saturation (0-255)
Definition: khuesaturationselect.cpp:89
QPainter::drawImage
void drawImage(const QRectF &target, const QImage &image, const QRectF &source, QFlags< Qt::ImageConversionFlag > flags)
ChooserClassic
Definition: kcolorchoosermode.h:24
QRectF
KHueSaturationSelector::setChooserMode
void setChooserMode(KColorChooserMode chooserMode)
Sets the chooser mode.
Definition: khuesaturationselect.cpp:60
KXYSelector
KXYSelector is the base class for other widgets which provides the ability to choose from a two-dimen...
Definition: kxyselector.h:39
QColor::setHsv
void setHsv(int h, int s, int v, int a)
KHueSaturationSelector::drawContents
virtual void drawContents(QPainter *painter)
Reimplemented from KXYSelector.
Definition: khuesaturationselect.cpp:125
KHueSaturationSelector::setSaturation
void setSaturation(int saturation)
Sets the saturation (0-255)
Definition: khuesaturationselect.cpp:95
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:23:59 by doxygen 1.8.7 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 API Reference

Skip menu "kdelibs 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

Search



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