Krita Source Code Documentation
Loading...
Searching...
No Matches
KisColorSelectorComponent Class Referenceabstract

#include <kis_color_selector_component.h>

+ Inheritance diagram for KisColorSelectorComponent:

Public Types

typedef KisColorSelectorConfiguration::Parameters Parameter
 
typedef KisColorSelectorConfiguration::Type Type
 

Public Slots

void setParam (qreal hue, qreal hsvSaturation, qreal value, qreal hslSaturation, qreal lightness, qreal hsiSaturation, qreal intensity, qreal hsySaturation, qreal luma)
 

Signals

void paramChanged (qreal hue, qreal hsvSaturation, qreal value, qreal hslSaturation, qreal lightness, qreal hsiSaturation, qreal intensity, qreal hsySaturation, qreal luma)
 -1, if unaffected
 
void update ()
 request for repaint, for instance, if the hue changes.
 

Public Member Functions

KoColor currentColor ()
 return the color, that was selected by calling mouseEvent
 
int height () const
 
 KisColorSelectorComponent (KisColorSelector *parent)
 
virtual void mouseEvent (int x, int y)
 saves the mouse position, so that a blip can be created.
 
void paintEvent (QPainter *)
 
virtual void setColor (const KoColor &color)
 set the color, blibs etc
 
void setConfiguration (Parameter param, Type type)
 setConfiguration can be ignored (for instance ring and triangle, as they can have only one config)
 
void setDirty ()
 force subsequent redraw of the component
 
void setGamutMask (KoGamutMaskSP gamutMask)
 
void setGeometry (int x, int y, int width, int height)
 
void toggleGamutMask (bool state)
 
void unsetGamutMask ()
 
void updateGamutMaskPreview ()
 
bool wantsGrab (int x, int y)
 returns true, if this component wants to grab the mouse (normally true, if containsPoint returns true)
 
int width () const
 

Protected Member Functions

virtual bool allowsColorSelectionAtPoint (const QPoint &) const
 
const KoColorSpacecolorSpace () const
 
virtual bool containsPointInComponentCoords (int x, int y) const
 
bool isDirty () const
 returns true, if ether the color space, the size or the parameters have changed since the last paint event
 
virtual void paint (QPainter *)=0
 
virtual KoColor selectColor (int x, int y)=0
 this method must be overloaded to return the color at position x/y and draw a marker on that position
 
void setLastMousePosition (int x, int y)
 

Protected Attributes

KoGamutMaskSP m_currentGamutMask
 
bool m_gamutMaskOn {false}
 
qreal m_hsiSaturation {0.0}
 
qreal m_hslSaturation {0.0}
 
qreal m_hsvSaturation {0.0}
 
qreal m_hsySaturation {0.0}
 
qreal m_hue {0.0}
 
qreal m_intensity {0.0}
 
qreal m_lastX {0.0}
 
qreal m_lastY {0.0}
 
qreal m_lightness {0.0}
 
qreal m_luma {0.0}
 
bool m_maskPreviewActive {false}
 
Parameter m_parameter
 
KisColorSelectorm_parent {0}
 
Type m_type
 
qreal m_value {0.0}
 
int m_x {0}
 
int m_y {0}
 

Private Attributes

bool m_dirty {false}
 
int m_height {0}
 
const KoColorSpacem_lastColorSpace {0}
 
KoColor m_lastSelectedColor
 
int m_width {0}
 

Detailed Description

Definition at line 22 of file kis_color_selector_component.h.

Member Typedef Documentation

◆ Parameter

◆ Type

Constructor & Destructor Documentation

◆ KisColorSelectorComponent()

KisColorSelectorComponent::KisColorSelectorComponent ( KisColorSelector * parent)
explicit

Definition at line 17 of file kis_color_selector_component.cpp.

17 :
18 QObject(parent),
19 m_hue(0),
21 m_value(1),
23 m_lightness(0.5),
25 m_intensity(0.333),
27 m_luma(0.299),
28 m_parent(parent),
29 m_gamutMaskOn(false),
30 m_currentGamutMask(nullptr),
32 m_lastX(0),
33 m_lastY(0),
34 m_x(0),
35 m_y(0),
36 m_width(0),
37 m_height(0),
38 m_dirty(true),
40{
41 Q_ASSERT(parent);
42}

Member Function Documentation

◆ allowsColorSelectionAtPoint()

bool KisColorSelectorComponent::allowsColorSelectionAtPoint ( const QPoint & ) const
protectedvirtual

a subclass can implement this method to note that the point, although it is in containsPointInComponentCoords area, still cannot be selected as a color (e.g. it is masked out). Default implementation always returns true.

Reimplemented in KisColorSelectorWheel.

Definition at line 128 of file kis_color_selector_component.cpp.

129{
130 return true;
131}

◆ colorSpace()

const KoColorSpace * KisColorSelectorComponent::colorSpace ( ) const
protected

Definition at line 76 of file kis_color_selector_component.cpp.

77{
78 const KoColorSpace* cs = m_parent->colorSpace();
79 Q_ASSERT(cs);
80 return cs;
81}
const KoColorSpace * colorSpace() const

References KisColorSelectorBase::colorSpace(), and m_parent.

◆ containsPointInComponentCoords()

bool KisColorSelectorComponent::containsPointInComponentCoords ( int x,
int y ) const
protectedvirtual

a subclass can implement this method, the default returns true if the coordinates are in the component rect values for the subclasses are provided in component coordinates, eg (0,0) is top left of component

Reimplemented in KisColorSelectorRing, and KisColorSelectorTriangle.

Definition at line 120 of file kis_color_selector_component.cpp.

121{
122 if(x>=0 && y>=0 && x<=width() && y<=height())
123 return true;
124 else
125 return false;
126}

References height(), and width().

◆ currentColor()

KoColor KisColorSelectorComponent::currentColor ( )

return the color, that was selected by calling mouseEvent

Definition at line 133 of file kis_color_selector_component.cpp.

134{
135 return selectColor(m_lastX, m_lastY);
136}
virtual KoColor selectColor(int x, int y)=0
this method must be overloaded to return the color at position x/y and draw a marker on that position

References m_lastX, m_lastY, and selectColor().

◆ height()

int KisColorSelectorComponent::height ( ) const

Definition at line 220 of file kis_color_selector_component.cpp.

221{
222 return m_height;
223}

References m_height.

◆ isDirty()

bool KisColorSelectorComponent::isDirty ( ) const
protected

returns true, if ether the color space, the size or the parameters have changed since the last paint event

Definition at line 115 of file kis_color_selector_component.cpp.

116{
118}
const KoColorSpace * colorSpace() const

References colorSpace(), m_dirty, and m_lastColorSpace.

◆ mouseEvent()

void KisColorSelectorComponent::mouseEvent ( int x,
int y )
virtual

saves the mouse position, so that a blip can be created.

Definition at line 64 of file kis_color_selector_component.cpp.

65{
66 int newX=qBound(0, (x-m_x), width());
67 int newY=qBound(0, (y-m_y), height());
68
69 if (allowsColorSelectionAtPoint(QPoint(newX, newY))) {
70 m_lastSelectedColor = selectColor(newX, newY);
71 m_lastX=newX;
72 m_lastY=newY;
73 }
74}
virtual bool allowsColorSelectionAtPoint(const QPoint &) const

References allowsColorSelectionAtPoint(), height(), m_lastSelectedColor, m_lastX, m_lastY, m_x, m_y, selectColor(), and width().

◆ paint()

virtual void KisColorSelectorComponent::paint ( QPainter * )
protectedpure virtual

paint component using given painter the component should respect width() and height() (eg. scale to width and height), but doesn't have to care about x/y coordinates (top left corner)

Implemented in KisColorSelectorRing, KisColorSelectorSimple, KisColorSelectorTriangle, and KisColorSelectorWheel.

◆ paintEvent()

void KisColorSelectorComponent::paintEvent ( QPainter * painter)

Definition at line 53 of file kis_color_selector_component.cpp.

54{
55 painter->save();
56 painter->translate(m_x, m_y);
57 paint(painter);
58 painter->restore();
59
60 m_dirty=false;
62}
virtual void paint(QPainter *)=0

References colorSpace(), m_dirty, m_lastColorSpace, m_x, m_y, and paint().

◆ paramChanged

void KisColorSelectorComponent::paramChanged ( qreal hue,
qreal hsvSaturation,
qreal value,
qreal hslSaturation,
qreal lightness,
qreal hsiSaturation,
qreal intensity,
qreal hsySaturation,
qreal luma )
signal

-1, if unaffected

◆ selectColor()

virtual KoColor KisColorSelectorComponent::selectColor ( int x,
int y )
protectedpure virtual

this method must be overloaded to return the color at position x/y and draw a marker on that position

Implemented in KisColorSelectorRing, KisColorSelectorSimple, KisColorSelectorTriangle, and KisColorSelectorWheel.

◆ setColor()

void KisColorSelectorComponent::setColor ( const KoColor & color)
virtual

set the color, blibs etc

Reimplemented in KisColorSelectorRing, KisColorSelectorSimple, KisColorSelectorTriangle, and KisColorSelectorWheel.

Definition at line 231 of file kis_color_selector_component.cpp.

232{
233 m_lastSelectedColor = color;
234}

References m_lastSelectedColor.

◆ setConfiguration()

void KisColorSelectorComponent::setConfiguration ( Parameter param,
Type type )

setConfiguration can be ignored (for instance ring and triangle, as they can have only one config)

Definition at line 225 of file kis_color_selector_component.cpp.

References m_parameter, and m_type.

◆ setDirty()

void KisColorSelectorComponent::setDirty ( )

force subsequent redraw of the component

Definition at line 83 of file kis_color_selector_component.cpp.

84{
85 m_dirty = true;
87}
virtual void setColor(const KoColor &color)
set the color, blibs etc

References m_dirty, m_lastSelectedColor, and setColor().

◆ setGamutMask()

void KisColorSelectorComponent::setGamutMask ( KoGamutMaskSP gamutMask)

Definition at line 89 of file kis_color_selector_component.cpp.

90{
91 m_currentGamutMask = gamutMask;
92 m_gamutMaskOn = true;
93}

References m_currentGamutMask, and m_gamutMaskOn.

◆ setGeometry()

void KisColorSelectorComponent::setGeometry ( int x,
int y,
int width,
int height )

◆ setLastMousePosition()

void KisColorSelectorComponent::setLastMousePosition ( int x,
int y )
protected

Definition at line 236 of file kis_color_selector_component.cpp.

237{
238 // prevent movement due to rounding errors
239 if (abs((int)m_lastX - x) > 1 || abs((int)m_lastY - y) > 1) {
240 m_lastX = x;
241 m_lastY = y;
242 }
243}
Point abs(const Point &pt)

References m_lastX, and m_lastY.

◆ setParam

void KisColorSelectorComponent::setParam ( qreal hue,
qreal hsvSaturation,
qreal value,
qreal hslSaturation,
qreal lightness,
qreal hsiSaturation,
qreal intensity,
qreal hsySaturation,
qreal luma )
slot

set hue, saturation, value or/and lightness unused parameters should be set to -1

Definition at line 138 of file kis_color_selector_component.cpp.

139{
140 if(qFuzzyCompare(m_hue, hue) &&
141 qFuzzyCompare(m_hsvSaturation, hsvSaturation) &&
143 qFuzzyCompare(m_hslSaturation, hslSaturation) &&
144 qFuzzyCompare(m_lightness, lightness) &&
145 qFuzzyCompare(m_hsiSaturation, hsiSaturation) &&
146 qFuzzyCompare(m_intensity, intensity) &&
147 qFuzzyCompare(m_hsySaturation, hsySaturation) &&
148 qFuzzyCompare(m_luma, luma))
149 return;
150
151 if (hue >= 0) {
152 m_hue = qMin(hue, qreal(1));
153 }
154
155 if (hsvSaturation >= 0) {
156 m_hsvSaturation = qMin(hsvSaturation, qreal(1));
157 m_hslSaturation = -1;
158 m_hsiSaturation = -1;
159 m_hsySaturation = -1;
160 }
161
162 if (value >= 0) {
163 m_value = qMin(value, qreal(1));
164 m_intensity = -1;
165 m_luma = -1;
166 m_lightness = -1;
167 }
168
169 if (hslSaturation >= 0) {
170 m_hslSaturation = qMin(hslSaturation, qreal(1));
171 m_hsvSaturation = -1;
172 m_hsiSaturation = -1;
173 m_hsySaturation = -1;
174 }
175
176 if (lightness >= 0) {
177 m_lightness = qMin(lightness, qreal(1));
178 m_value = -1;
179 m_luma = -1;
180 m_intensity = -1;
181 }
182
183 if (hsiSaturation >= 0) {
184 m_hsiSaturation = qMin(hsiSaturation, qreal(1));
185 m_hsvSaturation = -1;
186 m_hslSaturation = -1;
187 m_hsySaturation = -1;
188 }
189
190 if (intensity >= 0) {
191 m_intensity = qMin(intensity, qreal(1));
192 m_value = -1;
193 m_luma = -1;
194 m_lightness = -1;
195 }
196
197 if (hsySaturation >= 0) {
198 m_hsySaturation = qMin(hsySaturation, qreal(1));
199 m_hsvSaturation = -1;
200 m_hsiSaturation = -1;
201 m_hslSaturation = -1;
202 }
203
204 if (luma >= 0) {
205 m_luma = qMin(luma, qreal(1));
206 m_intensity = -1;
207 m_value = -1;
208 m_lightness = -1;
209 }
210
211 m_dirty=true;
212 Q_EMIT update();
213}
float value(const T *src, size_t ch)
void update()
request for repaint, for instance, if the hue changes.
static bool qFuzzyCompare(half p1, half p2)

References m_dirty, m_hsiSaturation, m_hslSaturation, m_hsvSaturation, m_hsySaturation, m_hue, m_intensity, m_lightness, m_luma, m_value, qFuzzyCompare(), update(), and value().

◆ toggleGamutMask()

void KisColorSelectorComponent::toggleGamutMask ( bool state)

Definition at line 107 of file kis_color_selector_component.cpp.

108{
109 m_gamutMaskOn = state;
110 setDirty();
111 update();
112}
void setDirty()
force subsequent redraw of the component

References m_gamutMaskOn, setDirty(), and update().

◆ unsetGamutMask()

void KisColorSelectorComponent::unsetGamutMask ( )

Definition at line 95 of file kis_color_selector_component.cpp.

96{
97 m_gamutMaskOn = false;
98 m_currentGamutMask = nullptr;
99}

References m_currentGamutMask, and m_gamutMaskOn.

◆ update

void KisColorSelectorComponent::update ( )
signal

request for repaint, for instance, if the hue changes.

◆ updateGamutMaskPreview()

void KisColorSelectorComponent::updateGamutMaskPreview ( )

Definition at line 101 of file kis_color_selector_component.cpp.

102{
103 setDirty();
104 update();
105}

References setDirty(), and update().

◆ wantsGrab()

bool KisColorSelectorComponent::wantsGrab ( int x,
int y )
inline

returns true, if this component wants to grab the mouse (normally true, if containsPoint returns true)

Definition at line 52 of file kis_color_selector_component.h.

virtual bool containsPointInComponentCoords(int x, int y) const

References containsPointInComponentCoords(), m_x, and m_y.

◆ width()

int KisColorSelectorComponent::width ( ) const

Definition at line 215 of file kis_color_selector_component.cpp.

216{
217 return m_width;
218}

References m_width.

Member Data Documentation

◆ m_currentGamutMask

KoGamutMaskSP KisColorSelectorComponent::m_currentGamutMask
protected

Definition at line 106 of file kis_color_selector_component.h.

◆ m_dirty

bool KisColorSelectorComponent::m_dirty {false}
private

Definition at line 115 of file kis_color_selector_component.h.

115{false};

◆ m_gamutMaskOn

bool KisColorSelectorComponent::m_gamutMaskOn {false}
protected

Definition at line 105 of file kis_color_selector_component.h.

105{false};

◆ m_height

int KisColorSelectorComponent::m_height {0}
private

Definition at line 114 of file kis_color_selector_component.h.

114{0};

◆ m_hsiSaturation

qreal KisColorSelectorComponent::m_hsiSaturation {0.0}
protected

Definition at line 98 of file kis_color_selector_component.h.

98{0.0};

◆ m_hslSaturation

qreal KisColorSelectorComponent::m_hslSaturation {0.0}
protected

Definition at line 96 of file kis_color_selector_component.h.

96{0.0};

◆ m_hsvSaturation

qreal KisColorSelectorComponent::m_hsvSaturation {0.0}
protected

Definition at line 94 of file kis_color_selector_component.h.

94{0.0};

◆ m_hsySaturation

qreal KisColorSelectorComponent::m_hsySaturation {0.0}
protected

Definition at line 100 of file kis_color_selector_component.h.

100{0.0};

◆ m_hue

qreal KisColorSelectorComponent::m_hue {0.0}
protected

Definition at line 93 of file kis_color_selector_component.h.

93{0.0};

◆ m_intensity

qreal KisColorSelectorComponent::m_intensity {0.0}
protected

Definition at line 99 of file kis_color_selector_component.h.

99{0.0};

◆ m_lastColorSpace

const KoColorSpace* KisColorSelectorComponent::m_lastColorSpace {0}
private

Definition at line 116 of file kis_color_selector_component.h.

116{0};

◆ m_lastSelectedColor

KoColor KisColorSelectorComponent::m_lastSelectedColor
private

Definition at line 117 of file kis_color_selector_component.h.

◆ m_lastX

qreal KisColorSelectorComponent::m_lastX {0.0}
protected

Definition at line 108 of file kis_color_selector_component.h.

108{0.0};

◆ m_lastY

qreal KisColorSelectorComponent::m_lastY {0.0}
protected

Definition at line 109 of file kis_color_selector_component.h.

109{0.0};

◆ m_lightness

qreal KisColorSelectorComponent::m_lightness {0.0}
protected

Definition at line 97 of file kis_color_selector_component.h.

97{0.0};

◆ m_luma

qreal KisColorSelectorComponent::m_luma {0.0}
protected

Definition at line 101 of file kis_color_selector_component.h.

101{0.0};

◆ m_maskPreviewActive

bool KisColorSelectorComponent::m_maskPreviewActive {false}
protected

Definition at line 107 of file kis_color_selector_component.h.

107{false};

◆ m_parameter

Parameter KisColorSelectorComponent::m_parameter
protected

Definition at line 102 of file kis_color_selector_component.h.

◆ m_parent

KisColorSelector* KisColorSelectorComponent::m_parent {0}
protected

Definition at line 104 of file kis_color_selector_component.h.

104{0};

◆ m_type

Type KisColorSelectorComponent::m_type
protected

Definition at line 103 of file kis_color_selector_component.h.

◆ m_value

qreal KisColorSelectorComponent::m_value {0.0}
protected

Definition at line 95 of file kis_color_selector_component.h.

95{0.0};

◆ m_width

int KisColorSelectorComponent::m_width {0}
private

Definition at line 113 of file kis_color_selector_component.h.

113{0};

◆ m_x

int KisColorSelectorComponent::m_x {0}
protected

Definition at line 110 of file kis_color_selector_component.h.

110{0};

◆ m_y

int KisColorSelectorComponent::m_y {0}
protected

Definition at line 111 of file kis_color_selector_component.h.

111{0};

The documentation for this class was generated from the following files: