Krita Source Code Documentation
Loading...
Searching...
No Matches
KisShadeSelectorLine Class Reference

#include <kis_shade_selector_line.h>

+ Inheritance diagram for KisShadeSelectorLine:

Public Member Functions

void fromString (const QString &string) override
 
 KisShadeSelectorLine (KisColorSelectorBaseProxy *parentProxy, QWidget *parent=0)
 
 KisShadeSelectorLine (qreal hueDelta, qreal satDelta, qreal valDelta, KisColorSelectorBaseProxy *parentProxy, QWidget *parent=0, qreal hueShift=0, qreal satShift=0, qreal valShift=0)
 
void mouseMoveEvent (QMouseEvent *) override
 
void mousePressEvent (QMouseEvent *) override
 
void mouseReleaseEvent (QMouseEvent *) override
 
void paintEvent (QPaintEvent *) override
 
void resizeEvent (QResizeEvent *) override
 
void setCanvas (KisCanvas2 *canvas)
 
void setColor (const KoColor &color)
 
void setParam (qreal hue, qreal sat, qreal val, qreal hueShift, qreal satShift, qreal shiftVal)
 
void showHelpText ()
 
QString toString () const override
 
void updateSettings ()
 
 ~KisShadeSelectorLine () override
 
- Public Member Functions inherited from KisShadeSelectorLineBase
 KisShadeSelectorLineBase (QWidget *parent)
 
void setLineNumber (int n)
 

Private Attributes

const KoColorSpacem_cachedColorSpace {0}
 
bool m_displayHelpText {false}
 
QPoint m_ev
 
bool m_gradient {false}
 
qreal m_hueDelta {0.0}
 
qreal m_hueShift {0.0}
 
bool m_isDown {false}
 
int m_lineHeight {0}
 
int m_mouseX {0}
 
KisColorSelectorBaseProxym_parentProxy {0}
 
int m_patchCount {0}
 
KoColor m_realColor
 
KisPaintDeviceSP m_realPixelCache
 
qreal m_saturationDelta {0.0}
 
qreal m_saturationShift {0.0}
 
qreal m_valueDelta {0.0}
 
qreal m_valueShift {0.0}
 
int m_width {0}
 

Friends

class KisShadeSelectorLineComboBox
 

Additional Inherited Members

- Protected Attributes inherited from KisShadeSelectorLineBase
int m_lineNumber {0}
 

Detailed Description

Definition at line 32 of file kis_shade_selector_line.h.

Constructor & Destructor Documentation

◆ KisShadeSelectorLine() [1/2]

KisShadeSelectorLine::KisShadeSelectorLine ( KisColorSelectorBaseProxy * parentProxy,
QWidget * parent = 0 )
explicit

Definition at line 28 of file kis_shade_selector_line.cpp.

32 m_displayHelpText(false),
33 m_parentProxy(parentProxy)
34{
35 setParam(0, 0, 0, 0, 0, 0);
37 setMouseTracking(true);
38 m_mouseX=width()/2;
39 m_isDown=false;
40}
KisShadeSelectorLineBase(QWidget *parent)
void setParam(qreal hue, qreal sat, qreal val, qreal hueShift, qreal satShift, qreal shiftVal)
KisColorSelectorBaseProxy * m_parentProxy
const KoColorSpace * m_cachedColorSpace

References m_isDown, m_mouseX, setParam(), and updateSettings().

◆ KisShadeSelectorLine() [2/2]

KisShadeSelectorLine::KisShadeSelectorLine ( qreal hueDelta,
qreal satDelta,
qreal valDelta,
KisColorSelectorBaseProxy * parentProxy,
QWidget * parent = 0,
qreal hueShift = 0,
qreal satShift = 0,
qreal valShift = 0 )
explicit

Definition at line 42 of file kis_shade_selector_line.cpp.

43 :
46 m_displayHelpText(false),
47 m_parentProxy(parentProxy)
48{
49 setParam(hueDelta, satDelta, valDelta, hueShift, satShift, valShift);
51 m_mouseX=width()/2;
52 m_isDown=false;
53}

References m_isDown, m_mouseX, setParam(), and updateSettings().

◆ ~KisShadeSelectorLine()

KisShadeSelectorLine::~KisShadeSelectorLine ( )
override

Definition at line 55 of file kis_shade_selector_line.cpp.

56{
57}

Member Function Documentation

◆ fromString()

void KisShadeSelectorLine::fromString ( const QString & string)
overridevirtual

Implements KisShadeSelectorLineBase.

Definition at line 96 of file kis_shade_selector_line.cpp.

97{
98 QStringList strili = string.split('|');
99 m_lineNumber = strili.at(0).toInt();
100 m_hueDelta = strili.at(1).toDouble();
101 m_saturationDelta = strili.at(2).toDouble();
102 m_valueDelta = strili.at(3).toDouble();
103 if(strili.size()==4) return; // don't crash, if reading old config files.
104 m_hueShift = strili.at(4).toDouble();
105 m_saturationShift = strili.at(5).toDouble();
106 m_valueShift = strili.at(6).toDouble();
107}

References m_hueDelta, m_hueShift, KisShadeSelectorLineBase::m_lineNumber, m_saturationDelta, m_saturationShift, m_valueDelta, and m_valueShift.

◆ mouseMoveEvent()

void KisShadeSelectorLine::mouseMoveEvent ( QMouseEvent * e)
override

Definition at line 235 of file kis_shade_selector_line.cpp.

236{
237 if ((m_isDown) && (e->buttons() & Qt::LeftButton)) {
238 m_mouseX=e->x();
239 const QPoint mouseEv(qBound(5, m_mouseX, m_width - 5), 5);
242 update();
243 }
244}
virtual void updateColorPreview(const KoColor &color)=0
KisPaintDeviceSP m_realPixelCache
KoColor sampleColor(PaintDeviceSP device, const QPoint &pt)
bool update(QSpinBox *spinBox)

References m_isDown, m_mouseX, m_parentProxy, m_realPixelCache, m_width, Acs::sampleColor(), and KisColorSelectorBaseProxy::updateColorPreview().

◆ mousePressEvent()

void KisShadeSelectorLine::mousePressEvent ( QMouseEvent * e)
override

Definition at line 220 of file kis_shade_selector_line.cpp.

221{
222 if(e->button()!=Qt::LeftButton && e->button()!=Qt::RightButton) {
223 e->setAccepted(false);
224 return;
225 }
226 if (e->y() > 0 && e->y() < height()) {
228 e->accept();
229 m_mouseX = e->x();
230 m_isDown=true;
231 update();
232 }
233}
virtual void showColorPreview()=0

References m_isDown, m_mouseX, m_parentProxy, and KisColorSelectorBaseProxy::showColorPreview().

◆ mouseReleaseEvent()

void KisShadeSelectorLine::mouseReleaseEvent ( QMouseEvent * e)
override

Definition at line 246 of file kis_shade_selector_line.cpp.

247{
248 if (e->button() != Qt::LeftButton && e->button() != Qt::RightButton) {
249 e->ignore();
250 return;
251 }
252 m_mouseX=e->x();
253 const QPoint mouseEv(qBound(5, m_mouseX, m_width - 5), 5);
256 Acs::ColorRole role = Acs::buttonToRole(e->button());
257
258 KConfigGroup cfg = KSharedConfig::openConfig()->group("advancedColorSelector");
259
260 bool onRightClick = cfg.readEntry("shadeSelectorUpdateOnRightClick", false);
261 bool onLeftClick = cfg.readEntry("shadeSelectorUpdateOnLeftClick", false);
262
263 bool explicitColorReset =
264 (e->button() == Qt::LeftButton && onLeftClick) ||
265 (e->button() == Qt::RightButton && onRightClick);
266
267 m_parentProxy->updateColor(color, role, explicitColorReset);
268 e->accept();
269 m_isDown=false;
270}
virtual void updateColor(const KoColor &color, Acs::ColorRole role, bool needsExplicitColorReset)=0
ColorRole buttonToRole(Qt::MouseButton button)

References Acs::buttonToRole(), m_isDown, m_mouseX, m_parentProxy, m_realPixelCache, m_width, Acs::sampleColor(), KisColorSelectorBaseProxy::updateColor(), and KisColorSelectorBaseProxy::updateColorPreview().

◆ paintEvent()

void KisShadeSelectorLine::paintEvent ( QPaintEvent * )
override

Definition at line 109 of file kis_shade_selector_line.cpp.

110{
111
115 }
116 else {
118 }
119
120 int patchCount = 0;
121 int patchSpacing = 0;
122 int patchWidth = 0;
123
124 if(m_gradient) {
125 patchCount = width();
126 patchSpacing = 0;
127 patchWidth = 1;
128 }
129 else {
130 patchCount = m_patchCount;
131 patchSpacing = 3;
132 patchWidth = std::lround((width() - patchSpacing * patchCount) / qreal(patchCount));
133 }
134 qreal hueStep;
135 qreal saturationStep;
136 qreal valueStep;
137
138 if(m_gradient){
139 hueStep=m_hueDelta/qreal(patchCount-10);
140 saturationStep=m_saturationDelta/qreal(patchCount-10);
141 valueStep=m_valueDelta/qreal(patchCount-10);
142 }
143 else{
144 hueStep=m_hueDelta/qreal(patchCount);
145 saturationStep=m_saturationDelta/qreal(patchCount);
146 valueStep=m_valueDelta/qreal(patchCount);
147 }
148
149 qreal baseHue;
150 qreal baseSaturation;
151 qreal baseValue;
153 getHsvF(m_realColor, &baseHue, &baseSaturation, &baseValue);
154
155 int z=0;
156 for(int i=-patchCount/2; i<=patchCount/2; i++) {
157 if(i==0 && patchCount%2==0) continue;
158 qreal hue = baseHue + (i * hueStep) + m_hueShift;
159 while (hue < 0.0) hue += 1.0;
160 while (hue > 1.0) hue -= 1.0;
161
162 qreal saturation = qBound<qreal>(0., baseSaturation + (i * saturationStep) + m_saturationShift, 1.);
163 qreal value = qBound<qreal>(0., baseValue + (i * valueStep) + m_valueShift, 1.);
164
165 if (qAbs(i) <= 5 && m_gradient) {
166 hue = baseHue;
167 saturation=baseSaturation;
168 value=baseValue;
169 }
170
171 const QRect patchRect(z * (patchWidth + patchSpacing), 0, patchWidth, m_lineHeight);
172 KoColor patchColor = m_parentProxy->converter()->fromHsvF(hue, saturation, value);
173
175 m_realPixelCache->fill(patchRect, patchColor);
176
177 z++;
178 }
179
180 QPainter wpainter(this);
181 if (!isEnabled()) {
182 wpainter.setOpacity(0.2);
183 }
184 const QImage renderedImage = m_parentProxy->converter()->toQImage(m_realPixelCache).scaledToWidth(m_width);
185 wpainter.drawImage(0, 0, renderedImage);
186 if (m_gradient) {
187 wpainter.setPen(QColor(175,175,175));
188 wpainter.drawRect(renderedImage.width()/2-5,0,10,renderedImage.height()-1);
189 wpainter.setPen(QColor(75,75,75));
190 wpainter.drawRect(renderedImage.width()/2-4,0,8,renderedImage.height()-1);
191 wpainter.setPen(QColor(175,175,175));
192 const int mouseX = qBound(5, m_mouseX, m_width - 5);
193 wpainter.drawRect(mouseX-5,0,10,renderedImage.height()-1);
194 wpainter.setPen(QColor(75,75,75));
195 wpainter.drawRect(mouseX-4,0,8,renderedImage.height()-1);
196 }
197
199 QString helpText(i18n("delta h=%1 s=%2 v=%3 shift h=%4 s=%5 v=%6",
205 m_valueShift));
206 wpainter.setPen(QColor(255,255,255));
207 wpainter.drawText(rect(), helpText);
208 }
209}
float value(const T *src, size_t ch)
virtual const KoColorSpace * colorSpace() const =0
virtual KisDisplayColorConverter * converter() const =0
QImage toQImage(KisPaintDeviceSP srcDevice, bool proofPaintColors=false) const
KoColor fromHsvF(qreal h, qreal s, qreal v, qreal a=1.0)
virtual void clear()
void fill(const QRect &rc, const KoColor &color)
const KoColorSpace * colorSpace() const
void convertTo(const KoColorSpace *cs, KoColorConversionTransformation::Intent renderingIntent, KoColorConversionTransformation::ConversionFlags conversionFlags)
Definition KoColor.cpp:136

References KisPaintDevice::clear(), KisPaintDevice::colorSpace(), KisColorSelectorBaseProxy::colorSpace(), KisColorSelectorBaseProxy::converter(), KoColor::convertTo(), KisPaintDevice::fill(), KisDisplayColorConverter::fromHsvF(), m_cachedColorSpace, m_displayHelpText, m_gradient, m_hueDelta, m_hueShift, m_lineHeight, m_mouseX, m_parentProxy, m_patchCount, m_realColor, m_realPixelCache, m_saturationDelta, m_saturationShift, m_valueDelta, m_valueShift, m_width, KisDisplayColorConverter::toQImage(), and value().

◆ resizeEvent()

void KisShadeSelectorLine::resizeEvent ( QResizeEvent * e)
override

Definition at line 211 of file kis_shade_selector_line.cpp.

212{
213 QSize m_old = e->oldSize();
214 QSize m_new = e->size();
215 int m_nWidth = m_new.width();
216 int m_oWidth = m_old.width();
217 m_width = width();
218 m_mouseX = m_mouseX * m_nWidth / m_oWidth;
219}

References m_mouseX, and m_width.

◆ setCanvas()

void KisShadeSelectorLine::setCanvas ( KisCanvas2 * canvas)

◆ setColor()

void KisShadeSelectorLine::setColor ( const KoColor & color)

◆ setParam()

void KisShadeSelectorLine::setParam ( qreal hue,
qreal sat,
qreal val,
qreal hueShift,
qreal satShift,
qreal shiftVal )

Definition at line 59 of file kis_shade_selector_line.cpp.

60{
61 m_hueDelta = hueDelta;
62 m_saturationDelta = satDelta;
63 m_valueDelta = valDelta;
64
65 m_hueShift = hueShift;
66 m_saturationShift = satShift;
67 m_valueShift = valShift;
68}

References m_hueDelta, m_hueShift, m_saturationDelta, m_saturationShift, m_valueDelta, and m_valueShift.

◆ showHelpText()

void KisShadeSelectorLine::showHelpText ( )
inline

Definition at line 48 of file kis_shade_selector_line.h.

References m_displayHelpText.

◆ toString()

QString KisShadeSelectorLine::toString ( ) const
overridevirtual

◆ updateSettings()

void KisShadeSelectorLine::updateSettings ( )

Definition at line 79 of file kis_shade_selector_line.cpp.

80{
81 KConfigGroup cfg = KSharedConfig::openConfig()->group("advancedColorSelector");
82
83 m_gradient = cfg.readEntry("minimalShadeSelectorAsGradient", false);
84 m_patchCount = cfg.readEntry("minimalShadeSelectorPatchCount", 10);
85 m_lineHeight = cfg.readEntry("minimalShadeSelectorLineHeight", 20);
86
87 setMaximumHeight(m_lineHeight);
88 setMinimumHeight(m_lineHeight);
89}

References m_gradient, m_lineHeight, and m_patchCount.

Friends And Related Symbol Documentation

◆ KisShadeSelectorLineComboBox

friend class KisShadeSelectorLineComboBox
friend

Definition at line 80 of file kis_shade_selector_line.h.

Member Data Documentation

◆ m_cachedColorSpace

const KoColorSpace* KisShadeSelectorLine::m_cachedColorSpace {0}
private

Definition at line 69 of file kis_shade_selector_line.h.

69{0};

◆ m_displayHelpText

bool KisShadeSelectorLine::m_displayHelpText {false}
private

Definition at line 74 of file kis_shade_selector_line.h.

74{false};

◆ m_ev

QPoint KisShadeSelectorLine::m_ev
private

Definition at line 76 of file kis_shade_selector_line.h.

◆ m_gradient

bool KisShadeSelectorLine::m_gradient {false}
private

Definition at line 71 of file kis_shade_selector_line.h.

71{false};

◆ m_hueDelta

qreal KisShadeSelectorLine::m_hueDelta {0.0}
private

Definition at line 59 of file kis_shade_selector_line.h.

59{0.0};

◆ m_hueShift

qreal KisShadeSelectorLine::m_hueShift {0.0}
private

Definition at line 63 of file kis_shade_selector_line.h.

63{0.0};

◆ m_isDown

bool KisShadeSelectorLine::m_isDown {false}
private

Definition at line 78 of file kis_shade_selector_line.h.

78{false};

◆ m_lineHeight

int KisShadeSelectorLine::m_lineHeight {0}
private

Definition at line 73 of file kis_shade_selector_line.h.

73{0};

◆ m_mouseX

int KisShadeSelectorLine::m_mouseX {0}
private

Definition at line 75 of file kis_shade_selector_line.h.

75{0};

◆ m_parentProxy

KisColorSelectorBaseProxy* KisShadeSelectorLine::m_parentProxy {0}
private

Definition at line 82 of file kis_shade_selector_line.h.

82{0};

◆ m_patchCount

int KisShadeSelectorLine::m_patchCount {0}
private

Definition at line 72 of file kis_shade_selector_line.h.

72{0};

◆ m_realColor

KoColor KisShadeSelectorLine::m_realColor
private

Definition at line 67 of file kis_shade_selector_line.h.

◆ m_realPixelCache

KisPaintDeviceSP KisShadeSelectorLine::m_realPixelCache
private

Definition at line 68 of file kis_shade_selector_line.h.

◆ m_saturationDelta

qreal KisShadeSelectorLine::m_saturationDelta {0.0}
private

Definition at line 60 of file kis_shade_selector_line.h.

60{0.0};

◆ m_saturationShift

qreal KisShadeSelectorLine::m_saturationShift {0.0}
private

Definition at line 64 of file kis_shade_selector_line.h.

64{0.0};

◆ m_valueDelta

qreal KisShadeSelectorLine::m_valueDelta {0.0}
private

Definition at line 61 of file kis_shade_selector_line.h.

61{0.0};

◆ m_valueShift

qreal KisShadeSelectorLine::m_valueShift {0.0}
private

Definition at line 65 of file kis_shade_selector_line.h.

65{0.0};

◆ m_width

int KisShadeSelectorLine::m_width {0}
private

Definition at line 77 of file kis_shade_selector_line.h.

77{0};

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