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

KDEUI

  • kdeui
  • colors
kcolorvalueselector.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 "kcolorvalueselector.h"
21
22#include <QtGui/QPainter>
23
24#include "kcolorchoosermode_p.h"
25
26using namespace KDEPrivate;
27
28class KColorValueSelector::Private
29{
30public:
31 Private(KColorValueSelector *q): q(q), _hue(0), _sat(0), _colorValue(0), _mode(ChooserClassic) {}
32
33 KColorValueSelector *q;
34 int _hue;
35 int _sat;
36 int _colorValue;
37 KColorChooserMode _mode;
38 QPixmap pixmap;
39};
40
41KColorValueSelector::KColorValueSelector( QWidget *parent )
42 : KSelector( Qt::Vertical, parent ), d( new Private( this ) )
43{
44 setRange( 0, 255 );
45}
46
47KColorValueSelector::KColorValueSelector( Qt::Orientation o, QWidget *parent )
48 : KSelector( o, parent ), d( new Private( this ) )
49{
50 setRange( 0, 255 );
51}
52
53KColorValueSelector::~KColorValueSelector()
54{
55 delete d;
56}
57
58int KColorValueSelector::hue() const
59{
60 return d->_hue;
61}
62
63void KColorValueSelector::setHue( int hue )
64{
65 d->_hue = hue;
66}
67
68int KColorValueSelector::saturation() const
69{
70 return d->_sat;
71}
72
73void KColorValueSelector::setSaturation( int saturation )
74{
75 d->_sat = saturation;
76}
77
78int KColorValueSelector::colorValue () const
79{
80 return d->_colorValue;
81}
82
83void KColorValueSelector::setColorValue ( int colorValue )
84{
85 d->_colorValue = colorValue;
86}
87
88
89
90void KColorValueSelector::updateContents()
91{
92 drawPalette( &d->pixmap );
93}
94
95void KColorValueSelector::resizeEvent( QResizeEvent * )
96{
97 updateContents();
98}
99
100void KColorValueSelector::drawContents( QPainter *painter )
101{
102 painter->drawPixmap( contentsRect().x(), contentsRect().y(), d->pixmap );
103}
104
105void KColorValueSelector::setChooserMode( KColorChooserMode c )
106{
107 if ( c == ChooserHue ) {
108 setRange( 0, 360 );
109 } else {
110 setRange( 0, 255 );
111 }
112 d->_mode = c;
113
114 //really needed?
115 //emit modeChanged();
116}
117
118KColorChooserMode KColorValueSelector::chooserMode () const
119{
120 return d->_mode;
121}
122
123void KColorValueSelector::drawPalette( QPixmap *pixmap )
124{
125 QColor color;
126 if (chooserMode() == ChooserHue) {
127 color.setHsv(hue(), 255, 255);
128 } else {
129 color.setHsv(hue(), saturation(), colorValue());
130 }
131
132 QLinearGradient gradient;
133 if (orientation() == Qt::Vertical) {
134 gradient.setStart(0, contentsRect().height());
135 gradient.setFinalStop(0, 0);
136 } else {
137 gradient.setStart(0, 0);
138 gradient.setFinalStop(contentsRect().width(), 0);
139 }
140
141 const int steps = componentValueSteps(chooserMode());
142 for (int v = 0; v <= steps; ++v) {
143 setComponentValue(color, chooserMode(), v * (1.0 / steps));
144 gradient.setColorAt(v * (1.0 / steps), color);
145 }
146
147 *pixmap = QPixmap(contentsRect().size());
148 QPainter painter(pixmap);
149 painter.fillRect(pixmap->rect(), gradient);
150}
151
152
153#include "kcolorvalueselector.moc"
KColorValueSelector
Definition: kcolorvalueselector.h:29
KColorValueSelector::drawContents
virtual void drawContents(QPainter *painter)
Reimplemented from KSelector.
Definition: kcolorvalueselector.cpp:100
KColorValueSelector::setChooserMode
void setChooserMode(KColorChooserMode chooserMode)
Sets the chooser mode.
Definition: kcolorvalueselector.cpp:105
KColorValueSelector::chooserMode
KColorChooserMode chooserMode() const
Returns the current chooser mode.
Definition: kcolorvalueselector.cpp:118
KColorValueSelector::KColorValueSelector
KColorValueSelector(QWidget *parent=0)
Constructs a widget for color selection.
Definition: kcolorvalueselector.cpp:41
KColorValueSelector::drawPalette
virtual void drawPalette(QPixmap *pixmap)
Draws the contents of the widget on a pixmap, which is used for buffering.
Definition: kcolorvalueselector.cpp:123
KColorValueSelector::resizeEvent
virtual void resizeEvent(QResizeEvent *)
Definition: kcolorvalueselector.cpp:95
KColorValueSelector::setHue
void setHue(int hue)
Sets the hue value.
Definition: kcolorvalueselector.cpp:63
KColorValueSelector::setColorValue
void setColorValue(int colorValue)
Sets the color value.
Definition: kcolorvalueselector.cpp:83
KColorValueSelector::~KColorValueSelector
~KColorValueSelector()
Definition: kcolorvalueselector.cpp:53
KColorValueSelector::saturation
int saturation
Definition: kcolorvalueselector.h:32
KColorValueSelector::colorValue
int colorValue
Definition: kcolorvalueselector.h:33
KColorValueSelector::setSaturation
void setSaturation(int saturation)
Sets the saturation value.
Definition: kcolorvalueselector.cpp:73
KColorValueSelector::hue
int hue
Definition: kcolorvalueselector.h:31
KColorValueSelector::updateContents
void updateContents()
Updates the widget's contents.
Definition: kcolorvalueselector.cpp:90
KSelector
KSelector is the base class for other widgets which provides the ability to choose from a one-dimensi...
Definition: kselector.h:42
KSelector::contentsRect
QRect contentsRect() const
Definition: kselector.cpp:96
QWidget
KColorChooserMode
KColorChooserMode
Definition: kcolorchoosermode.h:23
ChooserHue
@ ChooserHue
Definition: kcolorchoosermode.h:25
ChooserClassic
@ ChooserClassic
Definition: kcolorchoosermode.h:24
kcolorvalueselector.h
KDEPrivate
Definition: kcolorchoosermode.cpp:24
KDEPrivate::setComponentValue
void setComponentValue(QColor &color, KColorChooserMode chooserMode, qreal value)
Definition: kcolorchoosermode.cpp:44
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 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.14.38 API Reference

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