Krita Source Code Documentation
Loading...
Searching...
No Matches
KisClickableGLImageWidget.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2019 Dmitry Kazakov <dimula73@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
8
9#include <QMouseEvent>
10#include <QPainter>
11#include "kis_algebra_2d.h"
12#include <kis_debug.h>
13
18
20 : KisGLImageWidget(colorSpace, parent)
21{
22}
23
27
32
38
43
44void KisClickableGLImageWidget::setNormalizedPos(const QPointF &pos, bool update)
45{
46 m_normalizedClickPoint = KisAlgebra2D::clampPoint(pos, QRectF(0,0,1.0,1.0));
47 if (update) {
48 this->update();
49 }
50}
51
53{
55
56 if (m_handleStrategy) {
57 QPainter p(this);
59 }
60}
61
63{
64 KisGLImageWidget::mousePressEvent(event);
65
66 if (!event->isAccepted()) {
67 event->accept();
68 m_normalizedClickPoint = normalizePoint(event->localPos());
70
71 if (m_handleStrategy) {
72 update();
73 }
74 }
75}
76
78{
79 KisGLImageWidget::mouseReleaseEvent(event);
80
81 if (!event->isAccepted()) {
82 event->accept();
83 m_normalizedClickPoint = normalizePoint(event->localPos());
85
86 if (m_handleStrategy) {
87 update();
88 }
89 }
90}
91
93{
94 KisGLImageWidget::mouseMoveEvent(event);
95
96 if (!event->isAccepted()) {
97 event->accept();
98 m_normalizedClickPoint = normalizePoint(event->localPos());
100
101 if (m_handleStrategy) {
102 update();
103 }
104 }
105}
106
107QPointF KisClickableGLImageWidget::normalizePoint(const QPointF &pos) const
108{
109 const QPointF croppedPoint = KisAlgebra2D::clampPoint(pos, rect());
110 return QPointF(croppedPoint.x() / width(), croppedPoint.y() / height());
111}
112
113
114namespace {
115QPen outerHandlePen(bool useOpacity) {
116 // opacity works unexpectedly in HDR mode, so let the user switch it off
117 return QPen(QColor(0, 0, 0, useOpacity ? 180 : 255), 0);
118}
119QPen innerHandlePen(bool useOpacity) {
120 // opacity works unexpectedly in HDR mode, so let the user switch it off
121 return QPen(QColor(255, 255, 255, useOpacity ? 180 : 255), 0);
122}
123}
124
125void KisClickableGLImageWidget::VerticalLineHandleStrategy::drawHandle(QPainter *p, const QPointF &normalizedPoint, const QRect &rect, bool useOpacity)
126{
127 const QPointF pos = KisAlgebra2D::relativeToAbsolute(normalizedPoint, rect);
128 const int x = std::floor(pos.x());
129
130 p->setPen(outerHandlePen(useOpacity));
131 p->drawLine(x, rect.top(), x, rect.bottom());
132 p->setPen(innerHandlePen(useOpacity));
133 p->drawLine(x + 1, rect.top(), x + 1, rect.bottom());
134}
135
136void KisClickableGLImageWidget::CircularHandleStrategy::drawHandle(QPainter *p, const QPointF &normalizedPoint, const QRect &rect, bool useOpacity)
137{
138 const QPointF pos = KisAlgebra2D::relativeToAbsolute(normalizedPoint, rect);
139
140 p->setRenderHint(QPainter::Antialiasing);
141 p->setPen(outerHandlePen(useOpacity));
142 p->drawEllipse(pos, 5, 5);
143
144 p->setPen(innerHandlePen(useOpacity));
145 p->drawEllipse(pos, 4, 4);
146}
float value(const T *src, size_t ch)
const Params2D p
void setHandlePaintingStrategy(HandlePaintingStrategy *strategy)
void mouseMoveEvent(QMouseEvent *event) override
QPointF normalizePoint(const QPointF &pos) const
void setNormalizedPos(const QPointF &pos, bool update=true)
KisClickableGLImageWidget(QWidget *parent=nullptr)
void mousePressEvent(QMouseEvent *event) override
void paintEvent(QPaintEvent *event) override
QScopedPointer< HandlePaintingStrategy > m_handleStrategy
void selected(const QPointF &normalizedPos)
void mouseReleaseEvent(QMouseEvent *event) override
void paintEvent(QPaintEvent *event) override
QPointF relativeToAbsolute(const QPointF &pt, const QRectF &rc)
Point clampPoint(Point pt, const Rect &bounds)
void drawHandle(QPainter *p, const QPointF &normalizedPoint, const QRect &rect, bool useOpacity) override
void drawHandle(QPainter *p, const QPointF &normalizedPoint, const QRect &rect, bool useOpacity) override