Krita Source Code Documentation
Loading...
Searching...
No Matches
SvgTextCursor.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2023 Wolthera van Hövell tot Westerflier <griffinvalley@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7#ifndef SVGTEXTCURSOR_H
8#define SVGTEXTCURSOR_H
9
10#include <KoSvgTextShape.h>
11#include <KoSvgTextProperties.h>
13#include <KoToolSelection.h>
14#include <QPainter>
15#include <KoShape.h>
16#include "kritatoolsvgtext_export.h"
17
18class KoCanvasBase;
21class KUndo2Command;
22class QKeyEvent;
23class QInputMethodEvent;
24class QAction;
25
43class KRITATOOLSVGTEXT_EXPORT SvgTextCursor : public KoToolSelection, public KoSvgTextShape::TextCursorChangeListener
44{
45 Q_OBJECT
46public:
47 explicit SvgTextCursor(KoCanvasBase *canvas);
48
68
70
76
81 void setShape(KoSvgTextShape *textShape);
82
90 void setCaretSetting(int cursorWidth = 1, int cursorFlash = 1000, int cursorFlashLimit = 5000);
91
98 void setVisualMode(const bool visualMode = true);
99
104 void setPasteRichTextByDefault(const bool pasteRichText = true);
105
107 int getPos();
108
110 int getAnchor();
111
113 void setPos(int pos, int anchor);
114
116 void setPosToPoint(QPointF point, bool moveAnchor = true);
117
119 void moveCursor(MoveMode mode, bool moveAnchor = true);
120
122 void insertText(QString text);
123
125 void insertRichText(KoSvgTextShape *insert);
126
135 void removeText(MoveMode first, MoveMode second);
136
137 void removeLastCodePoint();
138
143 QPair<KoSvgTextProperties, KoSvgTextProperties> currentTextProperties() const;
144
146
147 void mergePropertiesIntoSelection(const KoSvgTextProperties props, const QSet<KoSvgTextProperties::PropertyId> removeProperties = QSet<KoSvgTextProperties::PropertyId>());
148
155 void removeSelection();
156
161 void copy() const;
169 bool paste();
170
171
172 void deselectText();
173
174 void paintDecorations(QPainter &gc, QColor selectionColor, int decorationThickness = 1);
175
176 QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
177 void inputMethodEvent(QInputMethodEvent *event);
178
179 // Reimplemented.
180 bool hasSelection() override;
181
184 void notifyShapeChanged(KoShape::ChangeType type, KoShape *shape) override;
185
188 void notifyCursorPosChanged(int pos, int anchor) override;
189
190 void notifyMarkupChanged() override;
191
193 void keyPressEvent(QKeyEvent *event);
194
196 bool isAddingCommand() const;
197
199 void focusIn();
200
202 void focusOut();
203
205 bool registerPropertyAction(QAction *action, const QString &name);
206
207 KoSvgTextPropertiesInterface *textPropertyInterface();
208
209Q_SIGNALS:
210
211 void updateCursorDecoration(QRectF updateRect);
213
215private Q_SLOTS:
216 void blinkCursor();
217 void stopBlinkCursor();
218
219 void updateInputMethodItemTransform();
220 void canvasResourceChanged(int key, const QVariant &value);
222 void propertyAction();
223
229
235 bool pastePlainText();
236
237private:
238
245 SvgTextRemoveCommand *removeSelectionImpl(bool allowCleanUp, KUndo2Command *parent = 0);
246
247
249 void updateCursor(bool firstUpdate = false);
250 void updateSelection();
251 void updateIMEDecoration();
252 void addCommandToUndoAdapter(KUndo2Command *cmd);
253
254 int moveModeResult(MoveMode &mode, int &pos, bool visual = false) const;
255 bool acceptableInput(const QKeyEvent *event) const;
256
257 void commitIMEPreEdit();
258
259 void updateCanvasResources();
260
261 struct Private;
262 const QScopedPointer<Private> d;
263};
264
267{
268public:
271 virtual QList<KoSvgTextProperties> getSelectedProperties() override;
272 virtual KoSvgTextProperties getInheritedProperties() override;
273 virtual void setPropertiesOnSelected(KoSvgTextProperties properties, QSet<KoSvgTextProperties::PropertyId> removeProperties = QSet<KoSvgTextProperties::PropertyId>()) override;
274 virtual bool spanSelection() override;
275 void emitSelectionChange();
276private:
277 struct Private;
278 const QScopedPointer<Private> d;
279};
280
282
283
284#endif // SVGTEXTCURSOR_H
float value(const T *src, size_t ch)
QVariant toggleProperty(SvgTextShortcutInfo info, QList< KoSvgTextProperties > currentProperties)
toggleProperty Handles toggling properties for getModifiedProperties split out to make code easier to...
ChangeType
Used by shapeChanged() to select which change was made.
Definition KoShape.h:95
The KoSvgTextPropertiesInterface class.
bool insertRichText(int pos, const KoSvgTextShape *richText)
insertRichText Insert rich text at the given cursor pos. This will first split contents at the given ...
QList< KoSvgTextProperties > propertiesForRange(const int startPos, const int endPos, bool inherited=false) const
propertiesForRange get the properties for a range.
bool insertText(int pos, QString text)
insertText Insert a text somewhere in the KoTextShape.
bool removeText(int &index, int &length)
removeText Where insert text explicitly uses a cursorposition, remove text uses a string index....
virtual bool hasSelection()
return true if the tool currently has something selected that can be copied or deleted.
Interface to interact with the text property manager.
const QScopedPointer< Private > d
Q_DECLARE_METATYPE(KisPaintopLodLimitations)
ShapeChangeListener so we can inform any text cursors that the cursor needs updating.
void notifyShapeChanged(ChangeType type, KoShape *shape) override
virtual void notifyCursorPosChanged(int pos, int anchor)=0
The SvgTextCursor class.
KoSvgTextShape * shape() const
Get the current text shape.
bool pasteRichText()
pasteRichText
bool isAddingCommand() const
the cursor is currently adding a command
const QScopedPointer< Private > d
void sigOpenGlyphPalette()
void selectionChanged()
void updateCursorDecoration(QRectF updateRect)