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
90
92
98
103 void setShape(KoSvgTextShape *textShape);
104
112 void setCaretSetting(int cursorWidth = 1, int cursorFlash = 1000, int cursorFlashLimit = 5000, bool drawCursorInAdditionToSelection = false);
113
120 void setVisualMode(const bool visualMode = true);
121
126 void setPasteRichTextByDefault(const bool pasteRichText = true);
127
129 void setTypeSettingModeActive(bool activate);
130
132 int getPos();
133
135 int getAnchor();
136
138 void setPos(int pos, int anchor);
139
141 void setPosToPoint(QPointF point, bool moveAnchor = true);
142
144 TypeSettingModeHandle typeSettingHandleAtPos(const QRectF regionOfInterest);
145
147 void setTypeSettingHandleHovered(TypeSettingModeHandle hovered = TypeSettingModeHandle::NoHandle);
148
151 void setDrawTypeSettingHandle(bool draw);
152
154 void updateTypeSettingDecorFromShape();
155
157 QCursor cursorTypeForTypeSetting() const;
158
163 QString handleName(TypeSettingModeHandle handle) const;
164
171 bool setDominantBaselineFromHandle(const TypeSettingModeHandle handle);
172
179 int posForTypeSettingHandleAndRect(const TypeSettingModeHandle handle, const QRectF regionOfInterest);
180
182 void moveCursor(MoveMode mode, bool moveAnchor = true);
183
185 void insertText(QString text);
186
188 void insertRichText(KoSvgTextShape *insert, bool inheritPropertiesIfPossible = false);
189
198 void removeText(MoveMode first, MoveMode second);
199
207 void removeLastCodePoint();
208
213 QPair<KoSvgTextProperties, KoSvgTextProperties> currentTextProperties() const;
214
224 QList<KoSvgTextProperties> propertiesForShape() const;
225
237 void mergePropertiesIntoSelection(const KoSvgTextProperties props, const QSet<KoSvgTextProperties::PropertyId> removeProperties = QSet<KoSvgTextProperties::PropertyId>(), bool paragraphOnly = false, bool selectWord = false);
238
245 void removeSelection();
246
251 void copy() const;
259 bool paste();
260
262 void deselectText();
263
265 void paintDecorations(QPainter &gc, QColor selectionColor, int decorationThickness = 1, qreal handleRadius = 5.0);
266
268 QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
270 void inputMethodEvent(QInputMethodEvent *event);
271
272 // Reimplemented.
273 bool hasSelection() override;
274
277 void notifyShapeChanged(KoShape::ChangeType type, KoShape *shape) override;
278
281 void notifyCursorPosChanged(int pos, int anchor) override;
282
283 void notifyMarkupChanged() override;
284
286 void keyPressEvent(QKeyEvent *event);
287
288 void updateModifiers(const Qt::KeyboardModifiers modifiers);
289
291 bool isAddingCommand() const;
292
294 void focusIn();
295
297 void focusOut();
298
300 bool registerPropertyAction(QAction *action, const QString &name);
301
304 KoSvgTextPropertiesInterface *textPropertyInterface();
305
306Q_SIGNALS:
307
309 void updateCursorDecoration(QRectF updateRect);
312
315private Q_SLOTS:
317 void blinkCursor();
319 void stopBlinkCursor();
320
321 /*
322 * Called when the canvas view navigation changes,
323 * so we can ensure the input method widgets get aligned.
324 */
325 void updateInputMethodItemTransform();
327 void canvasResourceChanged(int key, const QVariant &value);
329 void propertyAction();
331 void clearFormattingAction();
332
338
344 bool pastePlainText();
345
351
353 void updateCanvasResources();
354
355private:
356
363 SvgTextRemoveCommand *removeSelectionImpl(bool allowCleanUp, KUndo2Command *parent = 0);
364
365
367 void updateCursor(bool firstUpdate = false);
368 void updateSelection();
369 void updateIMEDecoration();
370 void updateTypeSettingDecoration();
371
373 void addCommandToUndoAdapter(KUndo2Command *cmd);
374
376 int moveModeResult(const MoveMode mode, int &pos, bool visual = false) const;
377
381 bool acceptableInput(const QKeyEvent *event) const;
382
385 void commitIMEPreEdit();
386
387 struct Private;
388 const QScopedPointer<Private> d;
389};
390
393{
394public:
397 virtual QList<KoSvgTextProperties> getSelectedProperties() override;
398 virtual QList<KoSvgTextProperties> getCharacterProperties() override;
399 virtual KoSvgTextProperties getInheritedProperties() override;
400 virtual void setPropertiesOnSelected(KoSvgTextProperties properties, QSet<KoSvgTextProperties::PropertyId> removeProperties = QSet<KoSvgTextProperties::PropertyId>()) override;
401 virtual void setCharacterPropertiesOnSelected(KoSvgTextProperties properties, QSet<KoSvgTextProperties::PropertyId> removeProperties = QSet<KoSvgTextProperties::PropertyId>()) override;
402 virtual bool spanSelection() override;
403 virtual bool characterPropertiesEnabled() override;
404 void emitSelectionChange();
405 void emitCharacterSelectionChange();
406private:
407 struct Private;
408 const QScopedPointer<Private> d;
409};
410
412
413
414#endif // SVGTEXTCURSOR_H
float value(const T *src, size_t ch)
ChangeType
Used by shapeChanged() to select which change was made.
Definition KoShape.h:92
The KoSvgTextPropertiesInterface class.
void removeTransformsFromRange(const int startPos, const int endPos)
QList< KoSvgTextProperties > propertiesForRange(const int startPos, const int endPos, bool inherited=false) const
propertiesForRange get the properties for a range.
bool insertRichText(int pos, const KoSvgTextShape *richText, bool inheritPropertiesIfPossible=false)
insertRichText Insert rich text at the given cursor pos. This will first split contents at the given ...
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()
Called by actions, tells the parent tool to open the glyph palette.
TypeSettingModeHandle
Handles used by type setting mode.
@ BaselineAlphabetic
Baselines.
@ BaselineShift
The text properties handles.
void selectionChanged()
Sents an update selection was changed.
void updateCursorDecoration(QRectF updateRect)
Sents an update to the parent tool to update it's decorations.