Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_shape_selection_model.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2007 Sven Langkamp <sven.langkamp@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
8#include "kis_debug.h"
9
10#include <KoShapeContainer.h>
11#include <KoShapeBackground.h>
12#include <KoShapeManager.h>
13
14#include "kis_shape_selection.h"
15#include "kis_selection.h"
16#include "kis_image.h"
18
19
21 : m_resolutionProxy(resolutionProxy)
22 , m_parentSelection(selection)
23 , m_shapeSelection(shapeSelection)
24 , m_updatesEnabled(true)
25{
26}
27
32
41
43{
44 const bool resolutionChanged = !m_resolutionProxy->compareResolution(*newResolutionProxy);
45
46 m_resolutionProxy = newResolutionProxy;
47
48 if (resolutionChanged) {
49 requestUpdate(QRect());
50 }
51}
52
57
59{
60 if (!m_shapeSelection) return;
61
62 if (m_shapeMap.contains(child))
63 return;
64
67 m_shapeMap.insert(child, child->boundingRect());
69
70 QRect updateRect = child->boundingRect().toAlignedRect();
71 QTransform matrix;
72 matrix.scale(m_resolutionProxy->xRes(), m_resolutionProxy->yRes());
73 updateRect = matrix.mapRect(updateRect);
74
75 if (m_shapeMap.count() == 1) {
76 // The shape is the first one, so the shape selection just got created
77 // Pixel selection provides no longer the datamanager of the selection
78 // so update the whole selection
79 requestUpdate(QRect());
80 } else {
81 requestUpdate(updateRect);
82 }
83}
84
86{
87 if (!m_shapeMap.contains(child)) return;
88
89 QRect updateRect = child->boundingRect().toAlignedRect();
90 m_shapeMap.remove(child);
91
92 if (m_shapeSelection) {
94 }
95 QTransform matrix;
96 matrix.scale(m_resolutionProxy->xRes(), m_resolutionProxy->yRes());
97 updateRect = matrix.mapRect(updateRect);
98 if (m_shapeSelection) { // No m_shapeSelection indicates the selection is being deleted
99 requestUpdate(updateRect);
100 }
101}
102
104{
105 m_updatesEnabled = enabled;
106}
107
112
113void KisShapeSelectionModel::setClipped(const KoShape *child, bool clipping)
114{
115 Q_UNUSED(child);
116 Q_UNUSED(clipping);
117}
118
120{
121 Q_UNUSED(child);
122 return false;
123}
124
126{
127 Q_UNUSED(shape);
128 Q_UNUSED(inherit);
129}
130
132{
133 Q_UNUSED(shape);
134 return false;
135}
136
138{
139 return m_shapeMap.count();
140}
141
149
151{
152 if (!m_shapeSelection) return;
153
154 // TODO: check if still needed
155 if (type == KoShape::ParentChanged) return;
156
157 QRectF changedRect = m_shapeMap[child];
158 changedRect = changedRect.united(child->boundingRect());
159 m_shapeMap[child] = child->boundingRect();
160
161 QTransform matrix;
162 matrix.scale(m_resolutionProxy->xRes(), m_resolutionProxy->yRes());
163 changedRect = matrix.mapRect(changedRect);
164
165 requestUpdate(changedRect.toAlignedRect());
166}
167
QSharedPointer< KoShapeStrokeModel > KoShapeStrokeModelSP
void setInheritsTransform(const KoShape *shape, bool inherit) override
KisShapeSelection * m_shapeSelection
void containerChanged(KoShapeContainer *, KoShape::ChangeType) override
bool isClipped(const KoShape *child) const override
void setShapeSelection(KisShapeSelection *selection)
KisShapeSelectionModel(KisImageResolutionProxySP resolutionProxy, KisSelectionWSP selection, KisShapeSelection *shapeSelection)
void setClipped(const KoShape *child, bool clipping) override
KisImageResolutionProxySP resolutionProxy() const
QMap< KoShape *, QRectF > m_shapeMap
void remove(KoShape *child) override
void add(KoShape *child) override
void requestUpdate(const QRect &updateRect)
void childChanged(KoShape *child, KoShape::ChangeType type) override
bool inheritsTransform(const KoShape *shape) const override
QList< KoShape * > shapes() const override
void setResolutionProxy(KisImageResolutionProxySP newResolutionProxy)
KisImageResolutionProxySP m_resolutionProxy
void recalculateOutlineCache() override
KoShapeManager * shapeManager() const
void remove(KoShape *shape)
void addShape(KoShape *shape, KoShapeManager::Repaint repaint=PaintShapeOnAdd)
virtual QRectF boundingRect() const
Get the bounding box of the shape.
Definition KoShape.cpp:335
virtual void setStroke(KoShapeStrokeModelSP stroke)
Definition KoShape.cpp:1081
virtual void setBackground(QSharedPointer< KoShapeBackground > background)
Definition KoShape.cpp:918
ChangeType
Used by shapeChanged() to select which change was made.
Definition KoShape.h:95
@ ParentChanged
used after a setParent()
Definition KoShape.h:103
void requestCompressedProjectionUpdate(const QRect &rc)