Krita Source Code Documentation
Loading...
Searching...
No Matches
KisGradientWidgetsUtils Namespace Reference

Classes

struct  StopHandleColor
 

Enumerations

enum  ColorType { None , Foreground , Background , Custom }
 

Functions

KoGradientSegmentEndpointType colorTypeToSegmentEndPointType (KisGradientWidgetsUtils::ColorType type, bool transparent)
 
void paintGradientBox (QPainter &painter, const KoAbstractGradientSP gradient, const QRectF &rect)
 
void paintMidPointHandle (QPainter &painter, const QPointF &position, qreal size, bool isSelected, bool isHovered, bool hasFocus, const QColor &borderColor, const QColor &fillColor, const QColor &highlightColor)
 
void paintStopHandle (QPainter &painter, const QPointF &position, const QSizeF &size, bool isSelected, bool isHovered, bool hasFocus, const QColor &highlightColor, const StopHandleColor &color1, const StopHandleColor &color2)
 
KisGradientWidgetsUtils::ColorType segmentEndPointTypeToColorType (KoGradientSegmentEndpointType type)
 

Enumeration Type Documentation

◆ ColorType

Enumerator
None 
Foreground 
Background 
Custom 

Definition at line 23 of file KisGradientWidgetsUtils.h.

24{
25 None, Foreground, Background, Custom
26};

Function Documentation

◆ colorTypeToSegmentEndPointType()

KoGradientSegmentEndpointType KRITAUI_EXPORT KisGradientWidgetsUtils::colorTypeToSegmentEndPointType ( KisGradientWidgetsUtils::ColorType type,
bool transparent )

Definition at line 180 of file KisGradientWidgetsUtils.cpp.

181{
182 if (type == Foreground) {
184 } else if (type == Background) {
186 }
187 return COLOR_ENDPOINT;
188}
@ COLOR_ENDPOINT
@ BACKGROUND_TRANSPARENT_ENDPOINT
@ FOREGROUND_ENDPOINT
@ BACKGROUND_ENDPOINT
@ FOREGROUND_TRANSPARENT_ENDPOINT

References Background, BACKGROUND_ENDPOINT, BACKGROUND_TRANSPARENT_ENDPOINT, COLOR_ENDPOINT, Foreground, FOREGROUND_ENDPOINT, and FOREGROUND_TRANSPARENT_ENDPOINT.

◆ paintGradientBox()

void KRITAUI_EXPORT KisGradientWidgetsUtils::paintGradientBox ( QPainter & painter,
const KoAbstractGradientSP gradient,
const QRectF & rect )

Definition at line 16 of file KisGradientWidgetsUtils.cpp.

17{
18 static KoCheckerBoardPainter checkerBoardPainter(4);
19
20 // Background
21 checkerBoardPainter.paint(painter, rect, rect.topLeft());
22 // Gradient
23 QImage image = gradient->generatePreview(rect.width(), rect.height());
24 if (!image.isNull()) {
25 painter.drawImage(rect.topLeft(), image);
26 }
27 // Border
28 painter.setPen(QColor(0, 0, 0, 192));
29 painter.drawRect(rect);
30}

References KoCheckerBoardPainter::paint().

◆ paintMidPointHandle()

void KRITAUI_EXPORT KisGradientWidgetsUtils::paintMidPointHandle ( QPainter & painter,
const QPointF & position,
qreal size,
bool isSelected,
bool isHovered,
bool hasFocus,
const QColor & borderColor,
const QColor & fillColor,
const QColor & highlightColor )

Definition at line 127 of file KisGradientWidgetsUtils.cpp.

134{
135 painter.save();
136
137 QColor brushColor;
138 int penWidth;
139 if (isSelected) {
140 brushColor = highlightColor;
141 penWidth = hasFocus ? 2 : 1;
142 } else {
143 if (isHovered) {
144 brushColor = highlightColor;
145 brushColor.setAlpha(192);
146 } else {
147 brushColor = fillColor;
148 }
149 penWidth = 1;
150 }
151 const QPointF alignedPosition(qRound(position.x() + 0.5) - 0.5, qRound(position.y() + 0.5) - 0.5);
152 const qreal alignedSize = qRound(size);
153 const qreal handleSizeOverTwo = alignedSize * 0.5;
154 const QPointF points[4] =
155 {
156 QPointF(0.0, 0.0),
157 QPointF(-handleSizeOverTwo, handleSizeOverTwo),
158 QPointF(0.0, size),
159 QPointF(handleSizeOverTwo, handleSizeOverTwo)
160 };
161 painter.translate(alignedPosition);
162 painter.setPen(QPen(borderColor, penWidth));
163 painter.setBrush(brushColor);
164 painter.drawPolygon(points, 4);
165
166 painter.restore();
167}

◆ paintStopHandle()

void KRITAUI_EXPORT KisGradientWidgetsUtils::paintStopHandle ( QPainter & painter,
const QPointF & position,
const QSizeF & size,
bool isSelected,
bool isHovered,
bool hasFocus,
const QColor & highlightColor,
const StopHandleColor & color1,
const StopHandleColor & color2 )

Definition at line 32 of file KisGradientWidgetsUtils.cpp.

39{
40 painter.save();
41
42 QColor borderColor;
43 int borderWidth;
44 if (isSelected) {
45 borderColor = highlightColor;
46 borderColor.setAlpha(255);
47 borderWidth = hasFocus ? 2 : 1;
48 } else {
49 if (isHovered) {
50 borderColor = highlightColor;
51 borderColor.setAlpha(192);
52 } else {
53 borderColor = QColor(0, 0, 0, 128);
54 }
55 borderWidth = 1;
56 }
57 const QPointF alignedPosition(qRound(position.x() + 0.5) - 0.5, position.y());
58 const qreal halfWidth = size.width() * 0.5;
59 QPainterPath path(alignedPosition);
60 path.arcTo(
61 alignedPosition.x() - halfWidth,
62 alignedPosition.y() + size.height() - size.width(),
63 size.width(),
64 size.width(),
65 150,
66 240
67 );
68 path.closeSubpath();
69 // paint the "drop" handle
70 if (color1.type != None && color2.type != None && color1.color != color2.color) {
71 painter.setClipRect(QRectF(QPointF(alignedPosition.x() - halfWidth, alignedPosition.y()), QSizeF(halfWidth, size.height())));
72 painter.setPen(Qt::NoPen);
73 painter.setBrush(color1.color);
74 painter.drawPath(path);
75 painter.setClipRect(QRectF(alignedPosition, QSizeF(halfWidth, size.height())));
76 painter.setBrush(color2.color);
77 painter.drawPath(path);
78 painter.setClipping(false);
79 painter.setPen(QPen(borderColor, borderWidth));
80 painter.setBrush(Qt::NoBrush);
81 painter.drawPath(path);
82 } else {
83 painter.setPen(QPen(borderColor, borderWidth));
84 if (color1.type != None) {
85 // Only color 1 was specified
86 painter.setBrush(color1.color);
87 } else {
88 // Only color 2 was specified
89 painter.setBrush(color2.color);
90 }
91 painter.drawPath(path);
92 }
93 // paint the type indicator
94 constexpr QSizeF typeIndicatorSize(5.0, 5.0);
95 if (color1.type == Foreground || color1.type == Background) {
96 QPointF typeIndicatorPosition(
97 alignedPosition.x() - halfWidth - 1.0,
98 alignedPosition.y() + size.height() - typeIndicatorSize.height() + 1.0
99 );
100 if (color1.type == Foreground) {
101 painter.setPen(QPen(Qt::white, 1));
102 painter.setBrush(Qt::black);
103 } else if (color1.type == Background) {
104 painter.setPen(QPen(Qt::black, 1));
105 painter.setBrush(Qt::white);
106 }
107 painter.drawEllipse(QRectF(typeIndicatorPosition, typeIndicatorSize));
108 }
109 if (color2.type == Foreground || color2.type == Background) {
110 QPointF typeIndicatorPosition(
111 alignedPosition.x() + halfWidth - typeIndicatorSize.width() + 1.0,
112 alignedPosition.y() + size.height() - typeIndicatorSize.height() + 1.0
113 );
114 if (color2.type == Foreground) {
115 painter.setPen(QPen(Qt::white, 1));
116 painter.setBrush(Qt::black);
117 } else if (color2.type == Background) {
118 painter.setPen(QPen(Qt::black, 1));
119 painter.setBrush(Qt::white);
120 }
121 painter.drawEllipse(QRectF(typeIndicatorPosition, typeIndicatorSize));
122 }
123
124 painter.restore();
125}
int size(const Forest< T > &forest)
Definition KisForest.h:1232

References Background, KisGradientWidgetsUtils::StopHandleColor::color, Foreground, None, and KisGradientWidgetsUtils::StopHandleColor::type.

◆ segmentEndPointTypeToColorType()