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#include <KisHandleStyle.h>
18
19class KoCanvasBase;
22class KUndo2Command;
23class QKeyEvent;
24class QInputMethodEvent;
25class QAction;
26
49class KRITATOOLSVGTEXT_EXPORT SvgTextCursor : public KoToolSelection, public KoSvgTextShape::TextCursorChangeListener
50{
51 Q_OBJECT
52public:
53 explicit SvgTextCursor(KoCanvasBase *canvas);
54
74
96
98
104
109 void setShape(KoSvgTextShape *textShape);
110
118 void setCaretSetting(int cursorWidth = 1, int cursorFlash = 1000, int cursorFlashLimit = 5000, bool drawCursorInAdditionToSelection = false);
119
126 void setVisualMode(const bool visualMode = true);
127
132 void setPasteRichTextByDefault(const bool pasteRichText = true);
133
135 void setTypeSettingModeActive(bool activate);
136
138 int getPos();
139
141 int getAnchor();
142
144 void setPos(int pos, int anchor);
145
147 void setPosToPoint(QPointF point, bool moveAnchor = true);
148
150 TypeSettingModeHandle typeSettingHandleAtPos(const QRectF regionOfInterest);
151
153 void setTypeSettingHandleHovered(TypeSettingModeHandle hovered = TypeSettingModeHandle::NoHandle);
154
157 void setDrawTypeSettingHandle(bool draw);
158
160 void updateTypeSettingDecorFromShape();
161
163 QCursor cursorTypeForTypeSetting() const;
164
169 QString handleName(TypeSettingModeHandle handle) const;
170
177 bool setDominantBaselineFromHandle(const TypeSettingModeHandle handle);
178
185 int posForTypeSettingHandleAndRect(const TypeSettingModeHandle handle, const QRectF regionOfInterest);
186
188 void moveCursor(MoveMode mode, bool moveAnchor = true);
189
191 void insertText(QString text);
192
194 void insertRichText(KoSvgTextShape *insert, bool inheritPropertiesIfPossible = false);
195
204 void removeText(MoveMode first, MoveMode second);
205
213 void removeLastCodePoint();
214
219 QPair<KoSvgTextProperties, KoSvgTextProperties> currentTextProperties() const;
220
230 QList<KoSvgTextProperties> propertiesForShape() const;
231
243 void mergePropertiesIntoSelection(const KoSvgTextProperties props, const QSet<KoSvgTextProperties::PropertyId> removeProperties = QSet<KoSvgTextProperties::PropertyId>(), bool paragraphOnly = false, bool selectWord = false);
244
251 void removeSelection();
252
257 void copy() const;
265 bool paste();
266
268 void deselectText();
269
271 void paintDecorations(QPainter &gc, QColor selectionColor, int decorationThickness = 1, qreal handleRadius = 5.0, KisHandlePalette handlePalette = KisHandlePalette());
272
274 QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
276 void inputMethodEvent(QInputMethodEvent *event);
277
278 // Reimplemented.
279 bool hasSelection() override;
280
283 void notifyShapeChanged(KoShape::ChangeType type, KoShape *shape) override;
284
287 void notifyCursorPosChanged(int pos, int anchor) override;
288
289 void notifyMarkupChanged() override;
290
292 void keyPressEvent(QKeyEvent *event);
293
294 void updateModifiers(const Qt::KeyboardModifiers modifiers);
295
297 bool isAddingCommand() const;
298
300 void focusIn();
301
303 void focusOut();
304
306 bool registerPropertyAction(QAction *action, const QString &name);
307
310 KoSvgTextPropertiesInterface *textPropertyInterface();
311
312Q_SIGNALS:
313
315 void updateCursorDecoration(QRectF updateRect);
318
321private Q_SLOTS:
323 void blinkCursor();
325 void stopBlinkCursor();
326
327 /*
328 * Called when the canvas view navigation changes,
329 * so we can ensure the input method widgets get aligned.
330 */
331 void updateInputMethodItemTransform();
333 void canvasResourceChanged(int key, const QVariant &value);
335 void propertyAction();
337 void clearFormattingAction();
338
344
350 bool pastePlainText();
351
357
359 void updateCanvasResources();
360
361private:
362
369 SvgTextRemoveCommand *removeSelectionImpl(bool allowCleanUp, KUndo2Command *parent = 0);
370
371
373 void updateCursor(bool firstUpdate = false);
374 void updateSelection();
375 void updateIMEDecoration();
376 void updateTypeSettingDecoration();
377
379 void addCommandToUndoAdapter(KUndo2Command *cmd);
380
382 int moveModeResult(const MoveMode mode, int &pos, bool visual = false) const;
383
387 bool acceptableInput(const QKeyEvent *event) const;
388
391 void commitIMEPreEdit();
392
393 struct Private;
394 const QScopedPointer<Private> d;
395};
396
399{
400public:
403 virtual QList<KoSvgTextProperties> getSelectedProperties() override;
404 virtual QList<KoSvgTextProperties> getCharacterProperties() override;
405 virtual KoSvgTextProperties getInheritedProperties() override;
406 virtual void setPropertiesOnSelected(KoSvgTextProperties properties, QSet<KoSvgTextProperties::PropertyId> removeProperties = QSet<KoSvgTextProperties::PropertyId>()) override;
407 virtual void setCharacterPropertiesOnSelected(KoSvgTextProperties properties, QSet<KoSvgTextProperties::PropertyId> removeProperties = QSet<KoSvgTextProperties::PropertyId>()) override;
408 virtual bool spanSelection() override;
409 virtual bool characterPropertiesEnabled() override;
410 void emitSelectionChange();
411 void emitCharacterSelectionChange();
412private:
413 struct Private;
414 const QScopedPointer<Private> d;
415};
416
418
419
420#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.