Changeset View
Changeset View
Standalone View
Standalone View
libs/flake/KoSelection.h
Show First 20 Lines • Show All 42 Lines • ▼ Show 20 Line(s) | |||||
43 | * Note that a single shape can be selected in one view, and not in | 43 | * Note that a single shape can be selected in one view, and not in | ||
44 | * another, and that in a single view, more than one selection can be | 44 | * another, and that in a single view, more than one selection can be | ||
45 | * present. So selections should not be seen as singletons, or as | 45 | * present. So selections should not be seen as singletons, or as | ||
46 | * something completely transient. | 46 | * something completely transient. | ||
47 | * | 47 | * | ||
48 | * A selection, however, should not be selectable. We need to think | 48 | * A selection, however, should not be selectable. We need to think | ||
49 | * a little about the interaction here. | 49 | * a little about the interaction here. | ||
50 | */ | 50 | */ | ||
51 | class KRITAFLAKE_EXPORT KoSelection : public QObject, public KoShape | 51 | class KRITAFLAKE_EXPORT KoSelection : public QObject, public KoShape, public KoShape::ShapeChangeListener | ||
52 | { | 52 | { | ||
53 | Q_OBJECT | 53 | Q_OBJECT | ||
54 | 54 | | |||
55 | public: | 55 | public: | ||
56 | 56 | | |||
57 | KoSelection(); | 57 | KoSelection(); | ||
58 | virtual ~KoSelection(); | 58 | virtual ~KoSelection(); | ||
59 | 59 | | |||
60 | virtual void paint(QPainter &painter, const KoViewConverter &converter, KoShapePaintingContext &paintcontext); | 60 | void paint(QPainter &painter, const KoViewConverter &converter, KoShapePaintingContext &paintcontext) override; | ||
61 | void setSize(const QSizeF &size) override; | ||||
62 | QSizeF size() const override; | ||||
63 | QRectF outlineRect() const override; | ||||
64 | QRectF boundingRect() const override; | ||||
61 | 65 | | |||
62 | /** | 66 | /** | ||
63 | * Adds a shape to the selection. | 67 | * Adds a shape to the selection. | ||
64 | * | 68 | * | ||
65 | * If the shape is a KoShapeGroup all of its child shapes are automatically added | 69 | * If the shape is a KoShapeGroup all of its child shapes are automatically added | ||
66 | * to the selection. | 70 | * to the selection. | ||
67 | * If the shape has no parent or is not a KoShapeGroup, only the given shape is | 71 | * If the shape has no parent or is not a KoShapeGroup, only the given shape is | ||
68 | * added to the selection. | 72 | * added to the selection. | ||
69 | * If the given shape is a child of a KoShapeGroup and recursive selection is enabled | 73 | * If the given shape is a child of a KoShapeGroup and recursive selection is enabled | ||
70 | * the all parents and their child shapes up to the toplevel KoShapeGroup are added to | 74 | * the all parents and their child shapes up to the toplevel KoShapeGroup are added to | ||
71 | * the selection. | 75 | * the selection. | ||
72 | * | 76 | * | ||
73 | * @param shape the shape to add to the selection | 77 | * @param shape the shape to add to the selection | ||
74 | * @param recursive enables recursively selecting shapes of parent groups | 78 | * @param recursive enables recursively selecting shapes of parent groups | ||
75 | */ | 79 | */ | ||
76 | void select(KoShape *shape, bool recursive = true); | 80 | void select(KoShape *shape); | ||
77 | 81 | | |||
78 | /** | 82 | /** | ||
79 | * Removes a selected shape. | 83 | * Removes a selected shape. | ||
80 | * | 84 | * | ||
81 | * If the shape is a KoShapeGroup all of its child shapes are automatically removed | 85 | * If the shape is a KoShapeGroup all of its child shapes are automatically removed | ||
82 | * from the selection. | 86 | * from the selection. | ||
83 | * If the shape has no parent or is not a KoShapeGroup, only the given shape is | 87 | * If the shape has no parent or is not a KoShapeGroup, only the given shape is | ||
84 | * removed from the selection. | 88 | * removed from the selection. | ||
85 | * If the given shape is a child of a KoShapeGroup and recursive selection is enabled | 89 | * If the given shape is a child of a KoShapeGroup and recursive selection is enabled | ||
86 | * the all parents and their child shape up to the toplevel KoShapeGroup are removed | 90 | * the all parents and their child shape up to the toplevel KoShapeGroup are removed | ||
87 | * from the selection. | 91 | * from the selection. | ||
88 | * | 92 | * | ||
89 | * @param shape the shape to remove from the selection | 93 | * @param shape the shape to remove from the selection | ||
90 | * @param recursive enables recursively deselecting shapes of parent groups | 94 | * @param recursive enables recursively deselecting shapes of parent groups | ||
91 | */ | 95 | */ | ||
92 | void deselect(KoShape *shape, bool recursive = true); | 96 | void deselect(KoShape *shape); | ||
93 | 97 | | |||
94 | /// clear the selections list | 98 | /// clear the selections list | ||
95 | void deselectAll(); | 99 | void deselectAll(); | ||
96 | 100 | | |||
97 | /** | 101 | /** | ||
98 | * Return the list of selected shapes | 102 | * Return the list of selected shapes | ||
99 | * @return the list of selected shapes | 103 | * @return the list of selected shapes | ||
100 | * @param strip if StrippedSelection, the returned list will not include any children | 104 | * @param strip if StrippedSelection, the returned list will not include any children | ||
101 | * of a container shape if the container-parent is itself also in the set. | 105 | * of a container shape if the container-parent is itself also in the set. | ||
102 | */ | 106 | */ | ||
103 | const QList<KoShape*> selectedShapes(KoFlake::SelectionType strip = KoFlake::FullSelection) const; | 107 | const QList<KoShape*> selectedShapes() const; | ||
108 | | ||||
109 | /** | ||||
110 | * Same as selectedShapes() but only for editable shapes. Used by | ||||
111 | * the algorithms that modify the image | ||||
112 | */ | ||||
113 | const QList<KoShape*> selectedEditableShapes() const; | ||||
114 | | ||||
115 | /** | ||||
116 | * Same as selectedEditableShapes() but also includes shapes delegates. | ||||
117 | * Used for | ||||
118 | */ | ||||
119 | const QList<KoShape*> selectedEditableShapesAndDelegates() const; | ||||
104 | 120 | | |||
105 | /** | 121 | /** | ||
106 | * Return the first selected shape, or 0 if there is nothing selected. | 122 | * Return the first selected shape, or 0 if there is nothing selected. | ||
107 | * @param strip if StrippedSelection, the returned list will not include any children | 123 | * @param strip if StrippedSelection, the returned list will not include any children | ||
108 | * of a grouped shape if the group-parent is itself also in the set. | 124 | * of a grouped shape if the group-parent is itself also in the set. | ||
109 | */ | 125 | */ | ||
110 | KoShape *firstSelectedShape(KoFlake::SelectionType strip = KoFlake::FullSelection) const; | 126 | KoShape *firstSelectedShape() const; | ||
111 | 127 | | |||
112 | /// return true if the shape is selected | 128 | /// return true if the shape is selected | ||
113 | bool isSelected(const KoShape *shape) const; | 129 | bool isSelected(const KoShape *shape) const; | ||
114 | 130 | | |||
115 | /// return the selection count, i.e. the number of all selected shapes | 131 | /// return the selection count, i.e. the number of all selected shapes | ||
116 | int count() const; | 132 | int count() const; | ||
117 | 133 | | |||
118 | virtual bool hitTest(const QPointF &position) const; | 134 | virtual bool hitTest(const QPointF &position) const; | ||
119 | 135 | | |||
120 | virtual QRectF boundingRect() const; | | |||
121 | | ||||
122 | /** | 136 | /** | ||
123 | * Sets the currently active layer. | 137 | * Sets the currently active layer. | ||
124 | * @param layer the new active layer | 138 | * @param layer the new active layer | ||
125 | */ | 139 | */ | ||
126 | void setActiveLayer(KoShapeLayer *layer); | 140 | void setActiveLayer(KoShapeLayer *layer); | ||
127 | 141 | | |||
128 | /** | 142 | /** | ||
129 | * Returns a currently active layer. | 143 | * Returns a currently active layer. | ||
130 | * | 144 | * | ||
131 | * @return the currently active layer, or zero if there is none | 145 | * @return the currently active layer, or zero if there is none | ||
132 | */ | 146 | */ | ||
133 | KoShapeLayer *activeLayer() const; | 147 | KoShapeLayer *activeLayer() const; | ||
134 | 148 | | |||
135 | /// Updates the size and position of the selection | 149 | void notifyShapeChanged(ChangeType type, KoShape *shape); | ||
136 | void updateSizeAndPosition(); | | |||
137 | 150 | | |||
138 | Q_SIGNALS: | 151 | Q_SIGNALS: | ||
139 | /// emitted when the selection is changed | 152 | /// emitted when the selection is changed | ||
140 | void selectionChanged(); | 153 | void selectionChanged(); | ||
141 | 154 | | |||
142 | /// emitted when the current layer is changed | 155 | /// emitted when the current layer is changed | ||
143 | void currentLayerChanged(const KoShapeLayer *layer); | 156 | void currentLayerChanged(const KoShapeLayer *layer); | ||
144 | 157 | | |||
145 | private: | 158 | private: | ||
146 | virtual void saveOdf(KoShapeSavingContext &) const; | 159 | virtual void saveOdf(KoShapeSavingContext &) const; | ||
147 | virtual bool loadOdf(const KoXmlElement &, KoShapeLoadingContext &); | 160 | virtual bool loadOdf(const KoXmlElement &, KoShapeLoadingContext &); | ||
148 | 161 | | |||
149 | Q_PRIVATE_SLOT(d_func(), void selectionChangedEvent()) | | |||
150 | Q_DECLARE_PRIVATE_D(KoShape::d_ptr, KoSelection) | 162 | Q_DECLARE_PRIVATE_D(KoShape::d_ptr, KoSelection) | ||
151 | }; | 163 | }; | ||
152 | 164 | | |||
153 | #endif | 165 | #endif |