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

The KisVisualColorSelectorShape class A 2d widget can represent at maximum 2 coordinates. So first decide how many coordinates you need. (onedimensional, or twodimensional) Then, select the channels you wish to be affected. This uses the model, so for cmyk the channel is c=0, m=1, y=2, k=3, but for hsv, hue=0, sat=1, and val=2 Then finally, connect the displayrenderer, you can also do this with 'setdisplayrenderer'. More...

#include <KisVisualColorSelectorShape.h>

+ Inheritance diagram for KisVisualColorSelectorShape:

Classes

struct  Private
 

Public Types

enum  Dimensions { onedimensional , twodimensional }
 The Dimensions enum Whether or not the shape is single or two dimensional. More...
 

Signals

void sigCursorMoved (QPointF pos)
 

Public Member Functions

int channel (int dimension) const
 channel Get the channel index associated with a selector shape dimension
 
quint32 channelMask () const
 
void forceImageUpdate ()
 forceImageUpdate force the image to recache.
 
QColor getColorFromConverter (KoColor c)
 getColorFromConverter
 
KoColor getCurrentColor ()
 getCurrentColor
 
QPointF getCursorPosition () const
 getCursorPosition
 
Dimensions getDimensions () const
 getDimensions
 
const QImage & getImageMap ()
 getImageMap returns the updated base image
 
virtual QRect getSpaceForCircle (QRect geom)=0
 
virtual QRect getSpaceForSquare (QRect geom)=0
 getSpaceForSquare
 
virtual QRect getSpaceForTriangle (QRect geom)=0
 
bool isHueControl () const
 
 KisVisualColorSelectorShape (KisVisualColorSelector *parent, KisVisualColorSelectorShape::Dimensions dimension, int channel1, int channel2)
 
void setAcceptTabletEvents (bool on)
 
virtual void setBorderWidth (int width)=0
 setBorderWidth set the border of the single dimensional selector.
 
void setChannelValues (QVector4D channelValues, quint32 channelFlags)
 setChannelValues Set the current channel values; Note that channel values controlled by the shape itself have no effect unless setCursor is true. This will trigger a full widget repaint.
 
void setCursorPosition (QPointF position, bool signal=false)
 setCursorPosition Set the cursor to normalized shape coordinates. This will only repaint the cursor.
 
virtual bool supportsGamutMask () const
 
virtual void updateGamutMask ()
 Notify shape that the gamut mask changed.
 
 ~KisVisualColorSelectorShape () override
 

Protected Member Functions

KisVisualColorSelectorcolorSelector () const
 
virtual QImage compositeBackground () const
 
QImage convertImageMap (const quint8 *rawColor, quint32 bufferSize, QSize imgSize) const
 convertImageMap convert image data containing raw KoColor data into a QImage
 
void mouseMoveEvent (QMouseEvent *e) override
 
virtual QPointF mousePositionToShapeCoordinate (const QPointF &pos, const QPointF &dragStart) const
 default implementation just calls convertWidgetCoordinateToShapeCoordinate(pos)
 
void mousePressEvent (QMouseEvent *e) override
 
void mouseReleaseEvent (QMouseEvent *e) override
 
void paintEvent (QPaintEvent *) override
 
virtual QImage renderAlphaMask () const
 render the alpha mask for the widget background the returned image is expected to be QImage::Format_Alpha8
 
virtual QImage renderBackground (const QVector4D &channelValues, const QImage &alpha) const
 renderBackground Render the widget background visible inside the widget's mask in current color space Rendering shall be done with the conversion functions of KisVisualColorSelector
 
virtual QImage renderStaticAlphaMask () const
 
void resizeEvent (QResizeEvent *) override
 
KisVisualColorModelselectorModel () const
 
void tabletEvent (QTabletEvent *event) override
 

Private Member Functions

virtual QPointF convertShapeCoordinateToWidgetCoordinate (QPointF) const =0
 convertShapeCoordinateToWidgetCoordinate
 
virtual QPointF convertWidgetCoordinateToShapeCoordinate (QPointF coordinate) const =0
 convertWidgetCoordinateToShapeCoordinate Convert a coordinate in the widget's height/width to a shape coordinate.
 
virtual void drawCursor (QPainter &painter)=0
 
virtual void drawGamutMask (QPainter &painter)
 
virtual QRegion getMaskMap ()=0
 getPixmap
 

Private Attributes

const QScopedPointer< Privatem_d
 

Detailed Description

The KisVisualColorSelectorShape class A 2d widget can represent at maximum 2 coordinates. So first decide how many coordinates you need. (onedimensional, or twodimensional) Then, select the channels you wish to be affected. This uses the model, so for cmyk the channel is c=0, m=1, y=2, k=3, but for hsv, hue=0, sat=1, and val=2 Then finally, connect the displayrenderer, you can also do this with 'setdisplayrenderer'.

Either way, this class is made to be subclassed, with a few virtuals so that the geometry can be calculated properly.

Definition at line 33 of file KisVisualColorSelectorShape.h.

Member Enumeration Documentation

◆ Dimensions

The Dimensions enum Whether or not the shape is single or two dimensional.

Enumerator
onedimensional 
twodimensional 

Definition at line 41 of file KisVisualColorSelectorShape.h.

Constructor & Destructor Documentation

◆ KisVisualColorSelectorShape()

KisVisualColorSelectorShape::KisVisualColorSelectorShape ( KisVisualColorSelector * parent,
KisVisualColorSelectorShape::Dimensions dimension,
int channel1,
int channel2 )
explicit

Definition at line 40 of file KisVisualColorSelectorShape.cpp.

43 : QWidget(parent), m_d(new Private)
44{
45 m_d->dimension = dimension;
46 int maxchannel = parent->selectorModel()->colorSpace()->colorChannelCount()-1;
47 m_d->channel1 = qBound(0, channel1, maxchannel);
48 m_d->channel2 = qBound(0, channel2, maxchannel);
49 m_d->channelMask = 1 << channel1;
50 if (dimension == Dimensions::twodimensional) {
51 m_d->channelMask |= 1 << channel2;
52 }
53 this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
54 // Color selectors don't have context menus. Setting this prevents any
55 // long-presses from delaying inputs, see KisLongPressEventFilter.cpp.
56 setContextMenuPolicy(Qt::PreventContextMenu);
57}
const QScopedPointer< Private > m_d
ChildIterator< value_type, is_const > parent(const ChildIterator< value_type, is_const > &it)
Definition KisForest.h:327

References m_d, and twodimensional.

◆ ~KisVisualColorSelectorShape()

KisVisualColorSelectorShape::~KisVisualColorSelectorShape ( )
override

Definition at line 59 of file KisVisualColorSelectorShape.cpp.

60{
61}

Member Function Documentation

◆ channel()

int KisVisualColorSelectorShape::channel ( int dimension) const

channel Get the channel index associated with a selector shape dimension

Parameters
dimensionA shape dimension that can be controlled by the cursor
Returns

Definition at line 408 of file KisVisualColorSelectorShape.cpp.

409{
410 if (dimension == 0) {
411 return m_d->channel1;
412 }
413 if (dimension == 1 && getDimensions() == twodimensional) {
414 return m_d->channel2;
415 }
416 return -1;
417}
Dimensions getDimensions() const
getDimensions

References getDimensions(), m_d, and twodimensional.

◆ channelMask()

quint32 KisVisualColorSelectorShape::channelMask ( ) const

Definition at line 419 of file KisVisualColorSelectorShape.cpp.

420{
421 return m_d->channelMask;
422}

References m_d.

◆ colorSelector()

KisVisualColorSelector * KisVisualColorSelectorShape::colorSelector ( ) const
protected

Definition at line 140 of file KisVisualColorSelectorShape.cpp.

141{
142 KisVisualColorSelector* selectorWidget = qobject_cast<KisVisualColorSelector*>(parent());
143 KIS_ASSERT(selectorWidget);
144 return selectorWidget;
145}
The KisVisualColorSelector class.
#define KIS_ASSERT(cond)
Definition kis_assert.h:33

References KIS_ASSERT.

◆ compositeBackground()

QImage KisVisualColorSelectorShape::compositeBackground ( ) const
protectedvirtual

Definition at line 242 of file KisVisualColorSelectorShape.cpp.

243{
244 // Shapes are expect to return a valid alpha mask or a valid
245 // static alpha mask. If they provide both, the rendered backgrounds
246 // get composited.
247 if (m_d->alphaNeedsUpdate) {
248 QImage staticAlpha = renderStaticAlphaMask();
249 if (!staticAlpha.isNull()) {
250 QVector4D neutralValues(1, 1, 1, 1);
251 switch (selectorModel()->colorModel()) {
255 neutralValues.setZ(0.5f);
256 default:
257 break;
258 }
259
260 m_d->staticBackground = renderBackground(neutralValues, staticAlpha);
261 }
262 m_d->alphaMask = renderAlphaMask();
263 m_d->alphaNeedsUpdate = false;
264 }
265 if (m_d->alphaMask.isNull()) {
266 return m_d->staticBackground;
267 }
268
269 QImage bgImage = renderBackground(m_d->currentChannelValues, m_d->alphaMask);
270 if (!m_d->staticBackground.isNull()) {
271 QPainter painter(&bgImage);
272 // composite static and dynamic background parts
273 painter.setCompositionMode(QPainter::CompositionMode_DestinationOver);
274 painter.drawImage(0, 0, m_d->staticBackground);
275 }
276 return bgImage;
277}
KisVisualColorModel * selectorModel() const
virtual QImage renderBackground(const QVector4D &channelValues, const QImage &alpha) const
renderBackground Render the widget background visible inside the widget's mask in current color space...
virtual QImage renderAlphaMask() const
render the alpha mask for the widget background the returned image is expected to be QImage::Format_A...

References KisVisualColorModel::HSI, KisVisualColorModel::HSL, KisVisualColorModel::HSY, m_d, renderAlphaMask(), renderBackground(), renderStaticAlphaMask(), and selectorModel().

◆ convertImageMap()

QImage KisVisualColorSelectorShape::convertImageMap ( const quint8 * rawColor,
quint32 bufferSize,
QSize imgSize ) const
protected

convertImageMap convert image data containing raw KoColor data into a QImage

Parameters
datamust point to memory of size width()*height()*pixelSize
sizethe number of bytes to read from data, must match aforementioned criteria
Returns
the converted QImage guaranteed to match the widget size (black content on failure)

Definition at line 168 of file KisVisualColorSelectorShape.cpp.

169{
170 const KoColorSpace *colorSpace = selectorModel()->colorSpace();
171 Q_ASSERT(bufferSize == imgSize.width() * imgSize.height() * colorSpace->pixelSize());
173
174 // Convert the buffer to a qimage
175 QImage image = renderer->toQImage(colorSpace, rawColor, imgSize, colorSelector()->proofColors());
176
177 // safeguard:
178 if (image.isNull())
179 {
180 image = QImage(width(), height(), QImage::Format_ARGB32);
181 image.fill(Qt::black);
182 }
183
184 return image;
185}
const KoColorSpace * colorSpace() const
KisVisualColorSelector * colorSelector() const
const KoColorDisplayRendererInterface * displayRenderer() const
virtual QImage toQImage(const KoColorSpace *srcColorSpace, const quint8 *data, QSize size, bool proofPaintColors=false) const =0
Convert a consecutive block of pixel data to an ARGB32 QImage.
virtual quint32 pixelSize() const =0

References colorSelector(), KisVisualColorModel::colorSpace(), KisVisualColorSelector::displayRenderer(), KoColorSpace::pixelSize(), selectorModel(), and KoColorDisplayRendererInterface::toQImage().

◆ convertShapeCoordinateToWidgetCoordinate()

virtual QPointF KisVisualColorSelectorShape::convertShapeCoordinateToWidgetCoordinate ( QPointF ) const
privatepure virtual

convertShapeCoordinateToWidgetCoordinate

Returns
take the position in the shape and convert it to screen coordinates.

Implemented in KisVisualDiamondSelectorShape, KisVisualEllipticalSelectorShape, KisVisualRectangleSelectorShape, and KisVisualTriangleSelectorShape.

◆ convertWidgetCoordinateToShapeCoordinate()

virtual QPointF KisVisualColorSelectorShape::convertWidgetCoordinateToShapeCoordinate ( QPointF coordinate) const
privatepure virtual

convertWidgetCoordinateToShapeCoordinate Convert a coordinate in the widget's height/width to a shape coordinate.

Parameters
coordinatethe position your wish to have the shape coordinates of.

Implemented in KisVisualDiamondSelectorShape, KisVisualEllipticalSelectorShape, KisVisualRectangleSelectorShape, and KisVisualTriangleSelectorShape.

◆ drawCursor()

virtual void KisVisualColorSelectorShape::drawCursor ( QPainter & painter)
privatepure virtual

◆ drawGamutMask()

void KisVisualColorSelectorShape::drawGamutMask ( QPainter & painter)
privatevirtual

Reimplemented in KisVisualEllipticalSelectorShape.

Definition at line 387 of file KisVisualColorSelectorShape.cpp.

388{
389 // Nothing to do if gamut masks not supported
390 Q_UNUSED(painter);
391}

◆ forceImageUpdate()

void KisVisualColorSelectorShape::forceImageUpdate ( )

forceImageUpdate force the image to recache.

Definition at line 122 of file KisVisualColorSelectorShape.cpp.

123{
124 //qDebug() << this << "forceImageUpdate";
125 m_d->alphaNeedsUpdate = true;
126 m_d->imagesNeedUpdate = true;
127}

References m_d.

◆ getColorFromConverter()

QColor KisVisualColorSelectorShape::getColorFromConverter ( KoColor c)

getColorFromConverter

Parameters
ca koColor.
Returns
get the qcolor from the given kocolorusing this widget's display renderer.

Definition at line 134 of file KisVisualColorSelectorShape.cpp.

135{
137 return renderer->toQColor(c, colorSelector()->proofColors());
138}
virtual QColor toQColor(const KoColor &c, bool proofToPaintColors=false) const =0

References colorSelector(), KisVisualColorSelector::displayRenderer(), and KoColorDisplayRendererInterface::toQColor().

◆ getCurrentColor()

KoColor KisVisualColorSelectorShape::getCurrentColor ( )

getCurrentColor

Returns
the current kocolor

Definition at line 398 of file KisVisualColorSelectorShape.cpp.

399{
400 const KisVisualColorModel *selector = selectorModel();
401 if (selector)
402 {
403 return selector->convertChannelValuesToKoColor(m_d->currentChannelValues);
404 }
405 return KoColor();
406}
The KisVisualColorModel class allows manipulating a KoColor using various color models.
KoColor convertChannelValuesToKoColor(const QVector4D &values) const

References KisVisualColorModel::convertChannelValuesToKoColor(), m_d, and selectorModel().

◆ getCursorPosition()

QPointF KisVisualColorSelectorShape::getCursorPosition ( ) const

getCursorPosition

Returns
current cursor position in shape-coordinates.

Definition at line 63 of file KisVisualColorSelectorShape.cpp.

63 {
64 return m_d->currentCoordinates;
65}

References m_d.

◆ getDimensions()

KisVisualColorSelectorShape::Dimensions KisVisualColorSelectorShape::getDimensions ( ) const

getDimensions

Returns
whether this is a single or twodimensional widget.

Definition at line 393 of file KisVisualColorSelectorShape.cpp.

394{
395 return m_d->dimension;
396}

References m_d.

◆ getImageMap()

const QImage & KisVisualColorSelectorShape::getImageMap ( )

getImageMap returns the updated base image

Returns
the final image of the shape content, before the handle gets drawn. the pixmap will not change until a redraw is required, which depends on whether the shape is static or changes depending on other color channels.

Definition at line 154 of file KisVisualColorSelectorShape.cpp.

155{
156 //qDebug() << this << ">>>>>>>>> getImageMap()" << m_d->imagesNeedUpdate;
157
158 if (m_d->imagesNeedUpdate) {
159 // NOTE: pure static backgrounds are currently somewhat implicitly handled,
160 // it would be nicer to avoid re-checking and overwriting m_d->gradient.
161 // But QImage's implicit data sharing allows all this mindless by-value stuff...
162 m_d->gradient = compositeBackground();
163 m_d->imagesNeedUpdate = false;
164 }
165 return m_d->gradient;
166}

References compositeBackground(), and m_d.

◆ getMaskMap()

virtual QRegion KisVisualColorSelectorShape::getMaskMap ( )
privatepure virtual

◆ getSpaceForCircle()

virtual QRect KisVisualColorSelectorShape::getSpaceForCircle ( QRect geom)
pure virtual

◆ getSpaceForSquare()

virtual QRect KisVisualColorSelectorShape::getSpaceForSquare ( QRect geom)
pure virtual

getSpaceForSquare

Parameters
geomthe full widget rectangle
Returns
rectangle with enough space for second widget

Implemented in KisVisualDiamondSelectorShape, KisVisualEllipticalSelectorShape, KisVisualRectangleSelectorShape, and KisVisualTriangleSelectorShape.

◆ getSpaceForTriangle()

virtual QRect KisVisualColorSelectorShape::getSpaceForTriangle ( QRect geom)
pure virtual

◆ isHueControl()

bool KisVisualColorSelectorShape::isHueControl ( ) const

◆ mouseMoveEvent()

void KisVisualColorSelectorShape::mouseMoveEvent ( QMouseEvent * e)
overrideprotected

Definition at line 308 of file KisVisualColorSelectorShape.cpp.

309{
310 if (e->buttons() & Qt::LeftButton) {
311 QPointF coordinates = mousePositionToShapeCoordinate(e->localPos(), m_d->dragStart);
312 setCursorPosition(coordinates, true);
313 } else {
314 e->ignore();
315 }
316}
void setCursorPosition(QPointF position, bool signal=false)
setCursorPosition Set the cursor to normalized shape coordinates. This will only repaint the cursor.
virtual QPointF mousePositionToShapeCoordinate(const QPointF &pos, const QPointF &dragStart) const
default implementation just calls convertWidgetCoordinateToShapeCoordinate(pos)

References m_d, mousePositionToShapeCoordinate(), and setCursorPosition().

◆ mousePositionToShapeCoordinate()

QPointF KisVisualColorSelectorShape::mousePositionToShapeCoordinate ( const QPointF & pos,
const QPointF & dragStart ) const
protectedvirtual

default implementation just calls convertWidgetCoordinateToShapeCoordinate(pos)

Reimplemented in KisVisualEllipticalSelectorShape.

Definition at line 289 of file KisVisualColorSelectorShape.cpp.

290{
291 Q_UNUSED(dragStart);
293}
virtual QPointF convertWidgetCoordinateToShapeCoordinate(QPointF coordinate) const =0
convertWidgetCoordinateToShapeCoordinate Convert a coordinate in the widget's height/width to a shape...

References convertWidgetCoordinateToShapeCoordinate().

◆ mousePressEvent()

void KisVisualColorSelectorShape::mousePressEvent ( QMouseEvent * e)
overrideprotected

Definition at line 295 of file KisVisualColorSelectorShape.cpp.

296{
297 if (e->button() == Qt::LeftButton) {
298 m_d->dragStart = e->localPos();
299 Q_EMIT colorSelector()->sigInteraction(true);
300 QPointF coordinates = mousePositionToShapeCoordinate(e->localPos(), m_d->dragStart);
301 setCursorPosition(coordinates, true);
302 }
303 else {
304 e->ignore();
305 }
306}
void sigInteraction(bool active)
sigInteraction is emitted whenever mouse interaction status changes

References colorSelector(), m_d, mousePositionToShapeCoordinate(), setCursorPosition(), and KisVisualColorSelector::sigInteraction().

◆ mouseReleaseEvent()

void KisVisualColorSelectorShape::mouseReleaseEvent ( QMouseEvent * e)
overrideprotected

Definition at line 318 of file KisVisualColorSelectorShape.cpp.

319{
320 if (e->button() == Qt::LeftButton) {
321 Q_EMIT colorSelector()->sigInteraction(false);
322 } else {
323 e->ignore();
324 }
325}

References colorSelector(), and KisVisualColorSelector::sigInteraction().

◆ paintEvent()

void KisVisualColorSelectorShape::paintEvent ( QPaintEvent * )
overrideprotected

Definition at line 363 of file KisVisualColorSelectorShape.cpp.

364{
365 QPainter painter(this);
366
367 const QImage &fullSelector = getImageMap();
368 if (!fullSelector.isNull()) {
369 painter.drawImage(0, 0, fullSelector);
370 }
371
372 drawGamutMask(painter);
373
374 if (isEnabled()) {
375 painter.setRenderHint(QPainter::Antialiasing);
376 drawCursor(painter);
377 }
378}
virtual void drawCursor(QPainter &painter)=0
virtual void drawGamutMask(QPainter &painter)
const QImage & getImageMap()
getImageMap returns the updated base image

References drawCursor(), drawGamutMask(), and getImageMap().

◆ renderAlphaMask()

QImage KisVisualColorSelectorShape::renderAlphaMask ( ) const
protectedvirtual

render the alpha mask for the widget background the returned image is expected to be QImage::Format_Alpha8

Reimplemented in KisVisualDiamondSelectorShape, KisVisualEllipticalSelectorShape, KisVisualRectangleSelectorShape, and KisVisualTriangleSelectorShape.

Definition at line 279 of file KisVisualColorSelectorShape.cpp.

280{
281 return QImage();
282}

◆ renderBackground()

QImage KisVisualColorSelectorShape::renderBackground ( const QVector4D & channelValues,
const QImage & alpha ) const
protectedvirtual

renderBackground Render the widget background visible inside the widget's mask in current color space Rendering shall be done with the conversion functions of KisVisualColorSelector

Parameters
datapoints to zero-initialized memory of size width()*height()*pixelSize
pixelSizethe data size to transfer from KoColor::data() to data per pixel in the current color space
channelValuesthe normalized channel values of the currently selected color

Definition at line 187 of file KisVisualColorSelectorShape.cpp.

188{
189 const KisVisualColorModel *selector = selectorModel();
190 Q_ASSERT(selector);
191
192 // Hi-DPI aware rendering requires that we determine the device pixel dimension;
193 // actual widget size in device pixels is not accessible unfortunately, it might be 1px smaller...
194 const qreal deviceDivider = 1.0 / devicePixelRatioF();
195 const int deviceWidth = qCeil(width() * devicePixelRatioF());
196 const int deviceHeight = qCeil(height() * devicePixelRatioF());
197 quint32 imageSize = deviceWidth * deviceHeight * selector->colorSpace()->pixelSize();
198 QScopedArrayPointer<quint8> raw(new quint8[imageSize] {});
199 quint8 *dataPtr = raw.data();
200 QVector4D coordinates = channelValues;
201 const qsizetype pixelSize = selector->colorSpace()->pixelSize();
202
203 bool checkAlpha = !alpha.isNull() && alpha.valid(deviceWidth - 1, deviceHeight - 1);
204 KIS_SAFE_ASSERT_RECOVER(!checkAlpha || alpha.format() == QImage::Format_Alpha8) {
205 checkAlpha = false;
206 }
207
208 KoColor filler(Qt::white, selector->colorSpace());
209 for (int y = 0; y < deviceHeight; y++) {
210 const uchar *alphaLine = checkAlpha ? alpha.scanLine(y) : 0;
211 for (int x=0; x < deviceWidth; x++) {
212 if (!checkAlpha || alphaLine[x]) {
213 QPointF newcoordinate = convertWidgetCoordinateToShapeCoordinate(QPointF(x, y) * deviceDivider);
214 coordinates[m_d->channel1] = newcoordinate.x();
215 if (m_d->dimension == Dimensions::twodimensional) {
216 coordinates[m_d->channel2] = newcoordinate.y();
217 }
218 KoColor c = selector->convertChannelValuesToKoColor(coordinates);
219 memcpy(dataPtr, c.data(), pixelSize);
220 }
221 else {
222 // need to write a color with non-zero alpha, otherwise the display converter
223 // will for some arcane reason crop the final QImage and screw rendering
224 memcpy(dataPtr, filler.data(), pixelSize);
225 }
226 dataPtr += pixelSize;
227 }
228 }
229 QImage image = convertImageMap(raw.data(), imageSize, QSize(deviceWidth, deviceHeight));
230 image.setDevicePixelRatio(devicePixelRatioF());
231
232 if (!alpha.isNull()) {
233 QPainter painter(&image);
234 // transfer alphaMask to Alpha channel
235 painter.setCompositionMode(QPainter::CompositionMode_DestinationIn);
236 painter.drawImage(0, 0, alpha);
237 }
238
239 return image;
240}
QImage convertImageMap(const quint8 *rawColor, quint32 bufferSize, QSize imgSize) const
convertImageMap convert image data containing raw KoColor data into a QImage
quint8 * data()
Definition KoColor.h:144
#define KIS_SAFE_ASSERT_RECOVER(cond)
Definition kis_assert.h:126

References KisVisualColorModel::colorSpace(), KisVisualColorModel::convertChannelValuesToKoColor(), convertImageMap(), convertWidgetCoordinateToShapeCoordinate(), KoColor::data(), KIS_SAFE_ASSERT_RECOVER, m_d, KoColorSpace::pixelSize(), selectorModel(), and twodimensional.

◆ renderStaticAlphaMask()

QImage KisVisualColorSelectorShape::renderStaticAlphaMask ( ) const
protectedvirtual

Reimplemented in KisVisualEllipticalSelectorShape.

Definition at line 284 of file KisVisualColorSelectorShape.cpp.

285{
286 return QImage();
287}

◆ resizeEvent()

void KisVisualColorSelectorShape::resizeEvent ( QResizeEvent * )
overrideprotected

Definition at line 380 of file KisVisualColorSelectorShape.cpp.

381{
384 setMask(getMaskMap());
385}
void forceImageUpdate()
forceImageUpdate force the image to recache.
virtual void updateGamutMask()
Notify shape that the gamut mask changed.
virtual QRegion getMaskMap()=0
getPixmap

References forceImageUpdate(), getMaskMap(), and updateGamutMask().

◆ selectorModel()

KisVisualColorModel * KisVisualColorSelectorShape::selectorModel ( ) const
protected

Definition at line 147 of file KisVisualColorSelectorShape.cpp.

148{
149 KisVisualColorSelector* selectorWidget = qobject_cast<KisVisualColorSelector*>(parent());
150 KIS_ASSERT(selectorWidget);
151 return selectorWidget->selectorModel().data();
152}
KisVisualColorModelSP selectorModel() const

References KIS_ASSERT, and KisVisualColorSelector::selectorModel().

◆ setAcceptTabletEvents()

void KisVisualColorSelectorShape::setAcceptTabletEvents ( bool on)

Definition at line 105 of file KisVisualColorSelectorShape.cpp.

106{
107 m_d->acceptTabletEvents = on;
108}

References m_d.

◆ setBorderWidth()

virtual void KisVisualColorSelectorShape::setBorderWidth ( int width)
pure virtual

setBorderWidth set the border of the single dimensional selector.

Parameters
width

Implemented in KisVisualEllipticalSelectorShape, KisVisualRectangleSelectorShape, KisVisualDiamondSelectorShape, and KisVisualTriangleSelectorShape.

◆ setChannelValues()

void KisVisualColorSelectorShape::setChannelValues ( QVector4D channelValues,
quint32 channelFlags )

setChannelValues Set the current channel values; Note that channel values controlled by the shape itself have no effect unless setCursor is true. This will trigger a full widget repaint.

Parameters
positionnormalized shape coordinates ([0,1] range) these are not yet transformed to color space specific ranges!
setCursorif true, sets the cursor too, otherwise the shape-controlled channels are not set

Definition at line 85 of file KisVisualColorSelectorShape.cpp.

86{
87 //qDebug() << this << "setChannelValues";
88 m_d->currentChannelValues = channelValues;
89 bool setCursor = channelFlags & m_d->channelMask;
90 if (setCursor) {
91 m_d->currentCoordinates = QPointF(qBound(0.f, channelValues[m_d->channel1], 1.f),
92 qBound(0.f, channelValues[m_d->channel2], 1.f));
93 }
94 else {
95 // for internal consistency, because we have a bit of redundancy here
96 m_d->currentChannelValues[m_d->channel1] = m_d->currentCoordinates.x();
97 if (m_d->dimension == Dimensions::twodimensional){
98 m_d->currentChannelValues[m_d->channel2] = m_d->currentCoordinates.y();
99 }
100 }
101 m_d->imagesNeedUpdate = m_d->imagesNeedUpdate || channelFlags & ~m_d->channelMask;
102 update();
103}
bool update(QSpinBox *spinBox)

References m_d, and twodimensional.

◆ setCursorPosition()

void KisVisualColorSelectorShape::setCursorPosition ( QPointF position,
bool signal = false )

setCursorPosition Set the cursor to normalized shape coordinates. This will only repaint the cursor.

Parameters
positionnormalized shape coordinates ([0,1] range, not yet transformed to actual channel values!)
signalif true, Q_EMIT a sigCursorMoved signal

Definition at line 67 of file KisVisualColorSelectorShape.cpp.

68{
69 QPointF newPos(qBound(0.0, position.x(), 1.0), qBound(0.0, position.y(), 1.0));
70 if (newPos != m_d->currentCoordinates)
71 {
72 m_d->currentCoordinates = newPos;
73 // for internal consistency, because we have a bit of redundancy here
74 m_d->currentChannelValues[m_d->channel1] = newPos.x();
75 if (m_d->dimension == Dimensions::twodimensional){
76 m_d->currentChannelValues[m_d->channel2] = newPos.y();
77 }
78 update();
79 if (signal){
80 Q_EMIT sigCursorMoved(newPos);
81 }
82 }
83}
void sigCursorMoved(QPointF pos)

References m_d, sigCursorMoved(), and twodimensional.

◆ sigCursorMoved

void KisVisualColorSelectorShape::sigCursorMoved ( QPointF pos)
signal

◆ supportsGamutMask()

bool KisVisualColorSelectorShape::supportsGamutMask ( ) const
virtual

Reimplemented in KisVisualEllipticalSelectorShape.

Definition at line 117 of file KisVisualColorSelectorShape.cpp.

118{
119 return false;
120}

◆ tabletEvent()

void KisVisualColorSelectorShape::tabletEvent ( QTabletEvent * event)
overrideprotected

Definition at line 327 of file KisVisualColorSelectorShape.cpp.

328{
329 // only accept tablet events that are associated to "left" button
330 // NOTE: QTabletEvent does not have a windowPos() equivalent, but we don't need it
331 if (m_d->acceptTabletEvents &&
332 (event->button() == Qt::LeftButton || (event->buttons() & Qt::LeftButton)))
333 {
334 event->accept();
335 switch (event->type()) {
336 case QEvent::TabletPress: {
337 QMouseEvent mouseEvent(QEvent::MouseButtonPress, event->posF(), event->posF(),
338 event->globalPosF(), event->button(), event->buttons(),
339 event->modifiers(), Qt::MouseEventSynthesizedByApplication);
340 mousePressEvent(&mouseEvent);
341 break;
342 }
343 case QEvent::TabletMove: {
344 QMouseEvent mouseEvent(QEvent::MouseMove, event->posF(), event->posF(),
345 event->globalPosF(), event->button(), event->buttons(),
346 event->modifiers(), Qt::MouseEventSynthesizedByApplication);
347 mouseMoveEvent(&mouseEvent);
348 break;
349 }
350 case QEvent::TabletRelease: {
351 QMouseEvent mouseEvent(QEvent::MouseButtonRelease, event->posF(), event->posF(),
352 event->globalPosF(), event->button(), event->buttons(),
353 event->modifiers(), Qt::MouseEventSynthesizedByApplication);
354 mouseReleaseEvent(&mouseEvent);
355 break;
356 }
357 default:
358 event->ignore();
359 }
360 }
361}
void mouseReleaseEvent(QMouseEvent *e) override
void mouseMoveEvent(QMouseEvent *e) override
void mousePressEvent(QMouseEvent *e) override

References m_d, mouseMoveEvent(), mousePressEvent(), and mouseReleaseEvent().

◆ updateGamutMask()

void KisVisualColorSelectorShape::updateGamutMask ( )
virtual

Notify shape that the gamut mask changed.

The gamut mask shall be updated and the widget repainted if necessary. This includes removal of gamut masks

Reimplemented in KisVisualEllipticalSelectorShape.

Definition at line 129 of file KisVisualColorSelectorShape.cpp.

130{
131 // Nothing to do if gamut masks not supported
132}

Member Data Documentation

◆ m_d

const QScopedPointer<Private> KisVisualColorSelectorShape::m_d
private

Definition at line 185 of file KisVisualColorSelectorShape.h.


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