Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_canvas_widget_base.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2007, 2010 Adrian Page <adrian@pagenet.plus.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
8
9#include <QImage>
10#include <QPainter>
11#include <QTimer>
12
13#include <KoShapeManager.h>
14#include <KoToolManager.h>
15#include <KoViewConverter.h>
16#include <KoToolProxy.h>
17#include <KoCanvasController.h>
18#include <KoShape.h>
19#include <KoSelection.h>
20
21
24#include "kis_config.h"
25#include "kis_canvas2.h"
26#include "KisViewManager.h"
28#include "KisDocument.h"
29#include "kis_update_info.h"
31
32
34{
35public:
36 Private(KisCanvas2 *newCanvas, KisCoordinatesConverter *newCoordinatesConverter)
37 : canvas(newCanvas)
38 , coordinatesConverter(newCoordinatesConverter)
39 , viewConverter(newCanvas->viewConverter())
40 , toolProxy(newCanvas->toolProxy())
42 , borderColor(Qt::gray)
43 {}
44
51
52 bool ignorenextMouseEventExceptRightMiddleClick; // HACK work around Qt bug not sending tablet right/dblclick https://bugreports.qt.io/browse/QTBUG-8598
54};
55
57 : m_d(new Private(canvas, coordinatesConverter))
58{
59 m_d->blockMouseEvent.setSingleShot(true);
60}
61
63{
69 //5qDeleteAll(m_d->decorations);
70 m_d->decorations.clear();
71
72 delete m_d;
73}
74
75void KisCanvasWidgetBase::drawDecorations(QPainter & gc, const QRect &updateWidgetRect) const
76{
77 if (!m_d->canvas) {
78 dbgFile<<"canvas doesn't exist, in canvas widget base!";
79 return;
80 }
81 gc.save();
82
83 // Setup the painter to take care of the offset; all that the
84 // classes that do painting need to keep track of is resolution
85 gc.setRenderHint(QPainter::Antialiasing);
86 gc.setRenderHint(QPainter::TextAntialiasing);
87
88 // This option does not do anything anymore with Qt4.6, so don't re-enable it since it seems to break display
89 // https://lists.qt-project.org/pipermail/qt-interest-old/2009-December/017078.html
90 // gc.setRenderHint(QPainter::Antialiasing);
91
92 gc.setRenderHint(QPainter::SmoothPixmapTransform);
93
94 {
95 KisQPainterStateSaver paintShapesState(&gc);
97
98 // Paint the shapes (other than the layers)
100
101 }
102
103 // ask the decorations to paint themselves
104 // decorations are painted in "widget" coordinate system
105 Q_FOREACH (KisCanvasDecorationSP deco, m_d->decorations) {
106 if (deco->visible()) {
107 deco->paint(gc, m_d->coordinatesConverter->widgetToDocument(updateWidgetRect), m_d->coordinatesConverter,m_d->canvas);
108 }
109 }
110
111 {
112 KisQPainterStateSaver paintDecorationsState(&gc);
114
115 // - some tools do not restore gc, but that is not important here
117 }
118
119 gc.restore();
120}
121
123{
124 m_d->decorations.push_back(deco);
125 std::stable_sort(m_d->decorations.begin(), m_d->decorations.end(), KisCanvasDecoration::comparePriority);
126}
127
129{
130 for (auto it = m_d->decorations.begin(); it != m_d->decorations.end(); ++it) {
131 if ((*it)->id() == id) {
132 it = m_d->decorations.erase(it);
133 break;
134 }
135 }
136}
137
139{
140 Q_FOREACH (KisCanvasDecorationSP deco, m_d->decorations) {
141 if (deco->id() == id) {
142 return deco;
143 }
144 }
145 return 0;
146}
147
153
159{
160 Q_FOREACH (KisCanvasDecorationSP deco, m_d->decorations) {
161 deco->notifyWindowMinimized(minimized);
162 }
163}
168
173
175{
176 KisConfig cfg(true);
177
178 if(checkSize < 0)
179 checkSize = cfg.checkSize();
180
181 QColor checkColor1 = cfg.checkersColor1();
182 QColor checkColor2 = cfg.checkersColor2();
183
184 QImage tile(checkSize * 2, checkSize * 2, QImage::Format_RGB32);
185 QPainter pt(&tile);
186 pt.fillRect(tile.rect(), checkColor2);
187 pt.fillRect(0, 0, checkSize, checkSize, checkColor1);
188 pt.fillRect(checkSize, checkSize, checkSize, checkSize, checkColor1);
189 pt.end();
190
191 return tile;
192}
193
199
201{
202 return m_d->borderColor;
203}
204
206{
207 return m_d->canvas;
208}
209
214
216{
217 QVector<QRect> dirtyViewRects;
218
219 Q_FOREACH (KisUpdateInfoSP info, infoObjects) {
220 dirtyViewRects << this->updateCanvasProjection(info);
221 }
222
223 return dirtyViewRects;
224}
225
230
231QVariant KisCanvasWidgetBase::processInputMethodQuery(Qt::InputMethodQuery query) const
232{
233 return m_d->toolProxy->inputMethodQuery(query);
234}
235
237{
239}
240
242{
243 m_d->toolProxy->focusInEvent(event);
244}
245
247{
248 m_d->toolProxy->focusOutEvent(event);
249}
250
255
257{
258 return QString("Canvas bit depth management is not supported\n");
259}
float value(const T *src, size_t ch)
WrapAroundAxis
KoShapeManager * globalShapeManager() const
static bool comparePriority(KisCanvasDecorationSP decoration1, KisCanvasDecorationSP decoration2)
void drawDecorations(QPainter &gc, const QRect &updateWidgetRect) const override
void removeDecoration(const QString &id) override
KisCoordinatesConverter * coordinatesConverter() const
QVariant processInputMethodQuery(Qt::InputMethodQuery query) const
void processFocusInEvent(QFocusEvent *event)
void setDecorations(const QList< KisCanvasDecorationSP > &) override
void processInputMethodEvent(QInputMethodEvent *event)
KisCanvasDecorationSP decoration(const QString &id) const override
QString currentBitDepthUserReport() const override
void setWrapAroundViewingMode(bool value) override
void processFocusOutEvent(QFocusEvent *event)
KisCanvasWidgetBase(KisCanvas2 *canvas, KisCoordinatesConverter *coordinatesConverter)
void addDecoration(KisCanvasDecorationSP deco) override
KisCanvas2 * canvas() const
void notifyDecorationsWindowMinimized(bool minimized)
QList< KisCanvasDecorationSP > decorations() const override
static QImage createCheckersImage(qint32 checkSize=-1)
BitDepthMode currentBitDepthMode() const override
QVector< QRect > updateCanvasProjection(const QVector< KisUpdateInfoSP > &infoObjects) override
KoToolProxy * toolProxy() const override
void setWrapAroundViewingModeAxis(WrapAroundAxis value) override
QColor checkersColor2(bool defaultValue=false) const
QColor checkersColor1(bool defaultValue=false) const
QColor canvasBorderColor(bool defaultValue=false) const
qint32 checkSize(bool defaultValue=false) const
_Private::Traits< T >::Result widgetToDocument(const T &obj) const
void paint(QPainter &painter)
void paint(QPainter &painter, const KoViewConverter &converter)
Forwarded to the current KoToolBase.
void focusInEvent(QFocusEvent *event)
Forwarded to the current KoToolBase.
void focusOutEvent(QFocusEvent *event)
Forwarded to the current KoToolBase.
void inputMethodEvent(QInputMethodEvent *event)
Forwarded to the current KoToolBase.
QVariant inputMethodQuery(Qt::InputMethodQuery query) const
Forwarded to the current KoToolBase.
#define dbgFile
Definition kis_debug.h:53
Private(KisCanvas2 *newCanvas, KisCoordinatesConverter *newCoordinatesConverter)
KisCoordinatesConverter * coordinatesConverter
QList< KisCanvasDecorationSP > decorations
const KoViewConverter * viewConverter