Krita Source Code Documentation
Loading...
Searching...
No Matches
KisColorSamplerPreviewPreview.cpp
Go to the documentation of this file.
1/*
2 * This file is part of Krita
3 *
4 * SPDX-FileCopyrightText: 2025 Agata Cacko <cacko.azh@gmail.com>
5 *
6 * SPDX-License-Identifier: GPL-2.0-or-later
7 */
8
10
11#include <QPainter>
12#include <QPainterPath>
13
14#include <kis_global.h>
15#include <kis_algebra_2d.h>
16#include <kis_painting_tweaks.h>
17
18#include <QDebug>
19
20
22 : QLabel(parent)
23{
24}
25
27{
28 m_diameter = diameter;
29 repaint();
30}
31
33{
34 m_outlineEnabled = enabled;
35 repaint();
36}
37
39{
40 m_thickness = thickness;
41 repaint();
42}
43
45{
46 Q_UNUSED(e);
47
48
49 QPainter painter(this);
50 painter.save();
51
52 painter.setRenderHint(QPainter::Antialiasing);
53 painter.setPen(Qt::transparent);
54
55
56 QPainterPath edge;
57
58 QRect viewRect = rect();
60
61
62 QRect edgeRect = viewRect;
63 QRect edgeRectSmaller = kisGrowRect(viewRect, -1);
64
65
66 edge.addRoundedRect(edgeRect, m_roundingMargin, m_roundingMargin);
67
68 QColor outsideColor = palette().base().color();
69 painter.setBrush(outsideColor);
70
71 painter.fillPath(edge, outsideColor);
72
73
74 int maxWidth = viewRect.width();
75 int thicknessPixels = m_thickness*m_diameter;
76 int innerWidth = m_diameter - 2*thicknessPixels;
77
78 int outsideWidths = maxWidth - innerWidth - 2*thicknessPixels;
79 int outsideWidth = outsideWidths/2;
80
81 // if there are any inaccuracies, no worries, it doesn't have to be exact
82
83 QRect leftSide = QRect(QPoint(), QPoint(thicknessPixels, viewRect.height()));
84 leftSide.translate(viewRect.topLeft());
85 QRect rightSide = leftSide;
86 leftSide.translate(outsideWidth, 0);
87 rightSide.translate(maxWidth - outsideWidth - thicknessPixels, 0);
88
89 QRect leftBottom = QRect(QPoint(leftSide.left(), leftSide.top() + leftSide.height()/2), QPoint(leftSide.bottomRight()));
90 QRect leftTop = QRect(leftSide.topLeft(), QPoint(leftSide.right(), leftSide.top() + leftSide.height()/2));
91
92 QRect rightBottom = QRect(QPoint(rightSide.left(), rightSide.top() + rightSide.height()/2), QPoint(rightSide.bottomRight()));
93 QRect rightTop = QRect(rightSide.topLeft(), QPoint(rightSide.right(), rightSide.top() + rightSide.height()/2));
94
95 painter.setBrush(m_sampledColorTop);
96 painter.fillRect(leftTop, m_sampledColorTop);
97 painter.fillRect(leftBottom, m_sampledColorBottom);
98
99 painter.fillRect(rightTop, m_sampledColorTop);
100 painter.fillRect(rightBottom, m_sampledColorBottom);
101
102 painter.setBrush(Qt::transparent);
103 if (m_outlineEnabled) {
104 painter.setPen(QPen(m_outlineColor, 2));
105 painter.drawRect(leftSide.adjusted(0, -m_verticalOutlineMargins, 0, m_verticalOutlineMargins));
106 painter.drawRect(rightSide.adjusted(0, -m_verticalOutlineMargins, 0, m_verticalOutlineMargins));
107 }
108
109 QColor crossColor = Qt::white;
110 crossColor.setAlphaF(0.4);
111 painter.setPen(crossColor);
112
113 QPointF center = viewRect.topLeft() + QPoint(viewRect.width()/2, viewRect.height()/2);
114 painter.drawLine(center - QPointF(m_crossLength, 0), center - QPointF(m_crossSpace, 0));
115 painter.drawLine(center + QPointF(m_crossLength, 0), center + QPointF(m_crossSpace, 0));
116
117 painter.drawLine(center - QPointF(0, m_crossLength), center - QPointF(0, m_crossSpace));
118 painter.drawLine(center + QPointF(0, m_crossLength), center + QPointF(0, m_crossSpace));
119
120
121 edge.clear();
122 QColor darkTransparent = palette().dark().color();
123 darkTransparent = KisPaintingTweaks::blendColors(outsideColor, darkTransparent, 0.6);
124
125 painter.setPen(QPen(darkTransparent, 2));
126 edge.addRoundedRect(edgeRectSmaller, m_roundingMargin, m_roundingMargin);
127 painter.drawPath(edge);
128
129 painter.restore();
130
131}
T kisGrowRect(const T &rect, U offset)
Definition kis_global.h:186
QColor blendColors(const QColor &c1, const QColor &c2, qreal r1)
rgba palette[MAX_PALETTE]
Definition palette.c:35