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

#include <KisVisualDiamondSelectorShape.h>

+ Inheritance diagram for KisVisualDiamondSelectorShape:

Public Member Functions

QRect getSpaceForCircle (QRect geom) override
 
QRect getSpaceForSquare (QRect geom) override
 getSpaceForSquare
 
QRect getSpaceForTriangle (QRect geom) override
 
 KisVisualDiamondSelectorShape (KisVisualColorSelector *parent, Dimensions dimension, int channel1, int channel2, int margin=5)
 
void setBorderWidth (int) override
 setBorderWidth set the border of the single dimensional selector.
 
 ~KisVisualDiamondSelectorShape () override
 
- Public Member Functions inherited from KisVisualColorSelectorShape
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
 
bool isHueControl () const
 
 KisVisualColorSelectorShape (KisVisualColorSelector *parent, KisVisualColorSelectorShape::Dimensions dimension, int channel1, int channel2)
 
void setAcceptTabletEvents (bool on)
 
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

QImage renderAlphaMask () const override
 render the alpha mask for the widget background the returned image is expected to be QImage::Format_Alpha8
 
- Protected Member Functions inherited from KisVisualColorSelectorShape
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 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

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

Private Attributes

int m_margin { 5 }
 

Additional Inherited Members

- Public Types inherited from KisVisualColorSelectorShape
enum  Dimensions { onedimensional , twodimensional }
 The Dimensions enum Whether or not the shape is single or two dimensional. More...
 
- Signals inherited from KisVisualColorSelectorShape
void sigCursorMoved (QPointF pos)
 

Detailed Description

Definition at line 12 of file KisVisualDiamondSelectorShape.h.

Constructor & Destructor Documentation

◆ KisVisualDiamondSelectorShape()

KisVisualDiamondSelectorShape::KisVisualDiamondSelectorShape ( KisVisualColorSelector * parent,
Dimensions dimension,
int channel1,
int channel2,
int margin = 5 )
explicit

Definition at line 16 of file KisVisualDiamondSelectorShape.cpp.

20 : KisVisualColorSelectorShape(parent, dimension, channel1, channel2),
21 m_margin(margin)
22{
23}
KisVisualColorSelectorShape(KisVisualColorSelector *parent, KisVisualColorSelectorShape::Dimensions dimension, int channel1, int channel2)

◆ ~KisVisualDiamondSelectorShape()

KisVisualDiamondSelectorShape::~KisVisualDiamondSelectorShape ( )
override

Definition at line 25 of file KisVisualDiamondSelectorShape.cpp.

26{
27}

Member Function Documentation

◆ convertShapeCoordinateToWidgetCoordinate()

QPointF KisVisualDiamondSelectorShape::convertShapeCoordinateToWidgetCoordinate ( QPointF ) const
overrideprivatevirtual

convertShapeCoordinateToWidgetCoordinate

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

Implements KisVisualColorSelectorShape.

Definition at line 49 of file KisVisualDiamondSelectorShape.cpp.

50{
51 // margin serves to render the cursor, and triangle is rendered 1px larger than its active area
52 qreal offset = m_margin + 1.0;
53
54 qreal y = ((1.0 - coordinate.y()) * (height() - 1 - 2 * offset)) + offset;
55
56 qreal triWidth = width() - 1 - 2 * offset;
57 qreal horizontalLineLength;
58 if (coordinate.y() < 0.5) {
59 horizontalLineLength = 2.0 * coordinate.y() * triWidth;
60 } else {
61 horizontalLineLength = 2.0 * (1.0 - coordinate.y()) * triWidth;
62 }
63 qreal horizontalLineStart = offset + 0.5 * (triWidth - horizontalLineLength);
64
65 qreal x = coordinate.x() * horizontalLineLength + horizontalLineStart;
66
67 return QPointF(x, y);
68}

References m_margin.

◆ convertWidgetCoordinateToShapeCoordinate()

QPointF KisVisualDiamondSelectorShape::convertWidgetCoordinateToShapeCoordinate ( QPointF coordinate) const
overrideprivatevirtual

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.

Implements KisVisualColorSelectorShape.

Definition at line 70 of file KisVisualDiamondSelectorShape.cpp.

71{
72 // margin serves to render the cursor, and triangle is rendered 1px larger than its active area
73 qreal offset = m_margin + 1.0;
74
75 qreal x = 0.5;
76 qreal y = qBound(0.0, 1.0 - (coordinate.y() - offset)/(height() - 1 - 2 * offset), 1.0);
77
78 qreal triWidth = width() - 1 - 2 * offset;
79 qreal horizontalLineLength;
80
81 if (y < 0.5) {
82 horizontalLineLength = 2.0 * y * triWidth;
83 } else {
84 horizontalLineLength = 2.0 * (1.0 - y) * triWidth;
85 }
86
87 if (horizontalLineLength > 1e-4) {
88 qreal horizontalLineStart = offset + 0.5 * (triWidth - horizontalLineLength);
89 x = qBound(0.0, (coordinate.x() - horizontalLineStart) / horizontalLineLength, 1.0);
90 }
91
92 return QPointF(x, y);
93}

References m_margin.

◆ drawCursor()

void KisVisualDiamondSelectorShape::drawCursor ( QPainter & painter)
overrideprivatevirtual

Implements KisVisualColorSelectorShape.

Definition at line 136 of file KisVisualDiamondSelectorShape.cpp.

137{
140 QBrush fill(Qt::SolidPattern);
141
142 int cursorwidth = 5;
143
144 painter.setPen(Qt::white);
145 fill.setColor(Qt::white);
146 painter.setBrush(fill);
147 painter.drawEllipse(cursorPoint, cursorwidth, cursorwidth);
148 fill.setColor(col);
149 painter.setPen(Qt::black);
150 painter.setBrush(fill);
151 painter.drawEllipse(cursorPoint, cursorwidth-1.0, cursorwidth-1.0);
152}
QPointF getCursorPosition() const
getCursorPosition
QColor getColorFromConverter(KoColor c)
getColorFromConverter
QPointF convertShapeCoordinateToWidgetCoordinate(QPointF coordinate) const override
convertShapeCoordinateToWidgetCoordinate

References convertShapeCoordinateToWidgetCoordinate(), KisVisualColorSelectorShape::getColorFromConverter(), KisVisualColorSelectorShape::getCurrentColor(), and KisVisualColorSelectorShape::getCursorPosition().

◆ getMaskMap()

QRegion KisVisualDiamondSelectorShape::getMaskMap ( )
overrideprivatevirtual

getPixmap

Returns
the pixmap of this shape.

Implements KisVisualColorSelectorShape.

Definition at line 95 of file KisVisualDiamondSelectorShape.cpp.

96{
97 const int cursorWidth = qMax(2 * m_margin, 2);
98 QPolygon maskPoly;
99 maskPoly << QPoint(qFloor(0.5 * (width() - cursorWidth)), 0)
100 << QPoint(qCeil(0.5 * (width() + cursorWidth)), 0)
101 << QPoint(width(), qFloor(0.5 * height() - cursorWidth))
102 << QPoint(width(), qCeil(0.5 * height() + cursorWidth))
103 << QPoint(qCeil(0.5 * (width() + cursorWidth)), height())
104 << QPoint(qFloor(0.5 * (width() - cursorWidth)), height())
105 << QPoint(0, qCeil(0.5 * height() + cursorWidth))
106 << QPoint(0, qFloor(0.5 * height() - cursorWidth));
107
108 return QRegion(maskPoly);
109}

References m_margin.

◆ getSpaceForCircle()

QRect KisVisualDiamondSelectorShape::getSpaceForCircle ( QRect geom)
overridevirtual

Implements KisVisualColorSelectorShape.

Definition at line 39 of file KisVisualDiamondSelectorShape.cpp.

40{
41 return geom;
42}

◆ getSpaceForSquare()

QRect KisVisualDiamondSelectorShape::getSpaceForSquare ( QRect geom)
overridevirtual

getSpaceForSquare

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

Implements KisVisualColorSelectorShape.

Definition at line 34 of file KisVisualDiamondSelectorShape.cpp.

35{
36 return geom;
37}

◆ getSpaceForTriangle()

QRect KisVisualDiamondSelectorShape::getSpaceForTriangle ( QRect geom)
overridevirtual

Implements KisVisualColorSelectorShape.

Definition at line 44 of file KisVisualDiamondSelectorShape.cpp.

45{
46 return geom;
47}

◆ renderAlphaMask()

QImage KisVisualDiamondSelectorShape::renderAlphaMask ( ) const
overrideprotectedvirtual

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

Reimplemented from KisVisualColorSelectorShape.

Definition at line 111 of file KisVisualDiamondSelectorShape.cpp.

112{
113 // Hi-DPI aware rendering requires that we determine the device pixel dimension;
114 // actual widget size in device pixels is not accessible unfortunately, it might be 1px smaller...
115 const int deviceWidth = qCeil(width() * devicePixelRatioF());
116 const int deviceHeight = qCeil(height() * devicePixelRatioF());
117
118 QImage alphaMask(deviceWidth, deviceHeight, QImage::Format_Alpha8);
119 alphaMask.fill(0);
120 alphaMask.setDevicePixelRatio(devicePixelRatioF());
121 QPainter painter(&alphaMask);
122 painter.setRenderHint(QPainter::Antialiasing);
123 painter.setBrush(Qt::white);
124 painter.setPen(Qt::NoPen);
125 QPointF diamond[4] = {
126 QPointF(0.5 * width(), m_margin),
127 QPointF(m_margin, 0.5 * height()),
128 QPointF(0.5 * width(), height() - m_margin),
129 QPointF(width() - m_margin, 0.5 * height())
130 };
131 painter.drawConvexPolygon(diamond, 4);
132
133 return alphaMask;
134}

References m_margin.

◆ setBorderWidth()

void KisVisualDiamondSelectorShape::setBorderWidth ( int width)
overridevirtual

setBorderWidth set the border of the single dimensional selector.

Parameters
width

Implements KisVisualColorSelectorShape.

Definition at line 29 of file KisVisualDiamondSelectorShape.cpp.

30{
31 // Diamond doesn't have a 1-dimensional mode
32}

Member Data Documentation

◆ m_margin

int KisVisualDiamondSelectorShape::m_margin { 5 }
private

Definition at line 45 of file KisVisualDiamondSelectorShape.h.

45{ 5 };

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