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
48class KRITATOOLSVGTEXT_EXPORT SvgTextCursor : public KoToolSelection, public KoSvgTextShape::TextCursorChangeListener
49{
50 Q_OBJECT
51public:
52 explicit SvgTextCursor(KoCanvasBase *canvas);
53
73
95
97
103
108 void setShape(KoSvgTextShape *textShape);
109
117 void setCaretSetting(int cursorWidth = 1, int cursorFlash = 1000, int cursorFlashLimit = 5000, bool drawCursorInAdditionToSelection = false);
118
125 void setVisualMode(const bool visualMode = true);
126
131 void setPasteRichTextByDefault(const bool pasteRichText = true);
132
134 void setTypeSettingModeActive(bool activate);
135
137 int getPos();
138
140 int getAnchor();
141
143 void setPos(int pos, int anchor);
144
146 void setPosToPoint(QPointF point, bool moveAnchor = true);
147
149 TypeSettingModeHandle typeSettingHandleAtPos(const QRectF regionOfInterest);
150
152 void setTypeSettingHandleHovered(TypeSettingModeHandle hovered = TypeSettingModeHandle::NoHandle);
153
156 void setDrawTypeSettingHandle(bool draw);
157
159 void updateTypeSettingDecorFromShape();
160
162 QCursor cursorTypeForTypeSetting() const;
163
168 QString handleName(TypeSettingModeHandle handle) const;
169
176 bool setDominantBaselineFromHandle(const TypeSettingModeHandle handle);
177
184 int posForTypeSettingHandleAndRect(const TypeSettingModeHandle handle, const QRectF regionOfInterest);
185
187 void moveCursor(MoveMode mode, bool moveAnchor = true);
188
190 void insertText(QString text);
191
193 void insertRichText(KoSvgTextShape *insert, bool inheritPropertiesIfPossible = false);
194
203 void removeText(MoveMode first, MoveMode second);
204
212 void removeLastCodePoint();
213
218 QPair<KoSvgTextProperties, KoSvgTextProperties> currentTextProperties() const;
219
229 QList<KoSvgTextProperties> propertiesForShape() const;
230
242 void mergePropertiesIntoSelection(const KoSvgTextProperties props, const QSet<KoSvgTextProperties::PropertyId> removeProperties = QSet<KoSvgTextProperties::PropertyId>(), bool paragraphOnly = false, bool selectWord = false);
243
250 void removeSelection();
251
256 void copy() const;
264 bool paste();
265
267 void deselectText();
268
270 void paintDecorations(QPainter &gc, QColor selectionColor, int decorationThickness = 1, qreal handleRadius = 5.0);
271
273 QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
275 void inputMethodEvent(QInputMethodEvent *event);
276
277 // Reimplemented.
278 bool hasSelection() override;
279
282 void notifyShapeChanged(KoShape::ChangeType type, KoShape *shape) override;
283
286 void notifyCursorPosChanged(int pos, int anchor) override;
287
288 void notifyMarkupChanged() override;
289
291 void keyPressEvent(QKeyEvent *event);
292
293 void updateModifiers(const Qt::KeyboardModifiers modifiers);
294
296 bool isAddingCommand() const;
297
299 void focusIn();
300
302 void focusOut();
303
305 bool registerPropertyAction(QAction *action, const QString &name);
306
309 KoSvgTextPropertiesInterface *textPropertyInterface();
310
311Q_SIGNALS:
312
314 void updateCursorDecoration(QRectF updateRect);
317
320private Q_SLOTS:
322 void blinkCursor();
324 void stopBlinkCursor();
325
326 /*
327 * Called when the canvas view navigation changes,
328 * so we can ensure the input method widgets get aligned.
329 */
330 void updateInputMethodItemTransform();
332 void canvasResourceChanged(int key, const QVariant &value);
334 void propertyAction();
336 void clearFormattingAction();
337
343
349 bool pastePlainText();
350
356
358 void updateCanvasResources();
359
360private:
361
368 SvgTextRemoveCommand *removeSelectionImpl(bool allowCleanUp, KUndo2Command *parent = 0);
369
370
372 void updateCursor(bool firstUpdate = false);
373 void updateSelection();
374 void updateIMEDecoration();
375 void updateTypeSettingDecoration();
376
378 void addCommandToUndoAdapter(KUndo2Command *cmd);
379
381 int moveModeResult(const MoveMode mode, int &pos, bool visual = false) const;
382
386 bool acceptableInput(const QKeyEvent *event) const;
387
390 void commitIMEPreEdit();
391
392 struct Private;
393 const QScopedPointer<Private> d;
394};
395
398{
399public:
402 virtual QList<KoSvgTextProperties> getSelectedProperties() override;
403 virtual QList<KoSvgTextProperties> getCharacterProperties() override;
404 virtual KoSvgTextProperties getInheritedProperties() override;
405 virtual void setPropertiesOnSelected(KoSvgTextProperties properties, QSet<KoSvgTextProperties::PropertyId> removeProperties = QSet<KoSvgTextProperties::PropertyId>()) override;
406 virtual void setCharacterPropertiesOnSelected(KoSvgTextProperties properties, QSet<KoSvgTextProperties::PropertyId> removeProperties = QSet<KoSvgTextProperties::PropertyId>()) override;
407 virtual bool spanSelection() override;
408 virtual bool characterPropertiesEnabled() override;
409 void emitSelectionChange();
410 void emitCharacterSelectionChange();
411private:
412 struct Private;
413 const QScopedPointer<Private> d;
414};
415
417
418
419#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.