• 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
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 
26 using namespace KDEPrivate;
27 
28 class KColorValueSelector::Private
29 {
30 public:
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 
41 KColorValueSelector::KColorValueSelector( QWidget *parent )
42  : KSelector( Qt::Vertical, parent ), d( new Private( this ) )
43 {
44  setRange( 0, 255 );
45 }
46 
47 KColorValueSelector::KColorValueSelector( Qt::Orientation o, QWidget *parent )
48  : KSelector( o, parent ), d( new Private( this ) )
49 {
50  setRange( 0, 255 );
51 }
52 
53 KColorValueSelector::~KColorValueSelector()
54 {
55  delete d;
56 }
57 
58 int KColorValueSelector::hue() const
59 {
60  return d->_hue;
61 }
62 
63 void KColorValueSelector::setHue( int hue )
64 {
65  d->_hue = hue;
66 }
67 
68 int KColorValueSelector::saturation() const
69 {
70  return d->_sat;
71 }
72 
73 void KColorValueSelector::setSaturation( int saturation )
74 {
75  d->_sat = saturation;
76 }
77 
78 int KColorValueSelector::colorValue () const
79 {
80  return d->_colorValue;
81 }
82 
83 void KColorValueSelector::setColorValue ( int colorValue )
84 {
85  d->_colorValue = colorValue;
86 }
87 
88 
89 
90 void KColorValueSelector::updateContents()
91 {
92  drawPalette( &d->pixmap );
93 }
94 
95 void KColorValueSelector::resizeEvent( QResizeEvent * )
96 {
97  updateContents();
98 }
99 
100 void KColorValueSelector::drawContents( QPainter *painter )
101 {
102  painter->drawPixmap( contentsRect().x(), contentsRect().y(), d->pixmap );
103 }
104 
105 void 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 
118 KColorChooserMode KColorValueSelector::chooserMode () const
119 {
120  return d->_mode;
121 }
122 
123 void 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::colorValue
int colorValue() const
Returns the current color value.
KColorValueSelector::KColorValueSelector
KColorValueSelector(QWidget *parent=0)
Constructs a widget for color selection.
Definition: kcolorvalueselector.cpp:41
KColorValueSelector::~KColorValueSelector
~KColorValueSelector()
Definition: kcolorvalueselector.cpp:53
KColorValueSelector::setSaturation
void setSaturation(int saturation)
Sets the saturation value.
Definition: kcolorvalueselector.cpp:73
QResizeEvent
QWidget
KColorValueSelector::Private
friend class Private
Definition: kcolorvalueselector.h:127
QPainter::fillRect
void fillRect(const QRectF &rectangle, const QBrush &brush)
KColorValueSelector
Definition: kcolorvalueselector.h:28
QAbstractSlider::setRange
void setRange(int min, int max)
KColorValueSelector::drawContents
virtual void drawContents(QPainter *painter)
Reimplemented from KSelector.
Definition: kcolorvalueselector.cpp:100
QGradient::setColorAt
void setColorAt(qreal position, const QColor &color)
KColorValueSelector::updateContents
void updateContents()
Updates the widget's contents.
Definition: kcolorvalueselector.cpp:90
KColorValueSelector::saturation
int saturation() const
Returns the current saturation value.
QWidget::y
int y() const
QLinearGradient
KDEPrivate::setComponentValue
void setComponentValue(QColor &color, KColorChooserMode chooserMode, qreal value)
Definition: kcolorchoosermode.cpp:44
KSelector::contentsRect
QRect contentsRect() const
Definition: kselector.cpp:96
KColorValueSelector::setColorValue
void setColorValue(int colorValue)
Sets the color value.
Definition: kcolorvalueselector.cpp:83
QWidget::width
int width() const
QWidget::size
QSize size() const
KColorValueSelector::setHue
void setHue(int hue)
Sets the hue value.
Definition: kcolorvalueselector.cpp:63
QAbstractSlider::orientation
Qt::Orientation orientation() const
QWidget::x
int x() const
QPainter::drawPixmap
void drawPixmap(const QRectF &target, const QPixmap &pixmap, const QRectF &source)
QPainter
QColor
QPixmap
KColorChooserMode
KColorChooserMode
Definition: kcolorchoosermode.h:22
QLinearGradient::setFinalStop
void setFinalStop(const QPointF &stop)
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::setChooserMode
void setChooserMode(KColorChooserMode chooserMode)
Sets the chooser mode.
Definition: kcolorvalueselector.cpp:105
ChooserHue
Definition: kcolorchoosermode.h:25
ChooserClassic
Definition: kcolorchoosermode.h:24
KColorValueSelector::resizeEvent
virtual void resizeEvent(QResizeEvent *)
Definition: kcolorvalueselector.cpp:95
kcolorvalueselector.h
QColor::setHsv
void setHsv(int h, int s, int v, int a)
QLinearGradient::setStart
void setStart(const QPointF &start)
QPixmap::rect
QRect rect() const
KColorValueSelector::chooserMode
KColorChooserMode chooserMode() const
Returns the current chooser mode.
Definition: kcolorvalueselector.cpp:118
KSelector
KSelector is the base class for other widgets which provides the ability to choose from a one-dimensi...
Definition: kselector.h:41
QWidget::height
int height() const
KColorValueSelector::hue
int hue() const
Returns the current hue value.
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