Krita Source Code Documentation
Loading...
Searching...
No Matches
SvgTextTool.cpp
Go to the documentation of this file.
1/* This file is part of the KDE project
2
3 SPDX-FileCopyrightText: 2017 Boudewijn Rempt <boud@valdyas.org>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8#include "SvgTextTool.h"
10#include "KoSvgTextShape.h"
16#include "SvgInlineSizeHelper.h"
17#include "SvgMoveTextCommand.h"
18#include "SvgMoveTextStrategy.h"
20#include "SvgTextEditor.h"
23#include "SvgTextShortCuts.h"
30
31#include <QPainterPath>
32#include <QDesktopServices>
33#include <QApplication>
34#include <QStyle>
35#include <QDockWidget>
36#include <QQuickItem>
37#include <QActionGroup>
38
39#include <klocalizedstring.h>
40
41#include <KisPart.h>
42#include <kis_canvas2.h>
43#include <KSharedConfig>
44#include "kis_assert.h"
46
47#include <KoFileDialog.h>
48#include <KoIcon.h>
49#include <KoCanvasBase.h>
50#include <KoCanvasController.h>
51#include <KoSelection.h>
52#include <KoShapeManager.h>
53#include <KoShapeController.h>
54#include <KoShapeRegistry.h>
55#include <KoShapeFactoryBase.h>
56#include <KoPointerEvent.h>
57#include <KoProperties.h>
59#include "KoToolManager.h"
60#include <KoShapeFillWrapper.h>
62#include <KoPathShape.h>
63#include <KoPathSegment.h>
64
66#include <KoCssStylePreset.h>
68#include <KoColorBackground.h>
69#include <KisResourceModel.h>
70
72#include <KisViewManager.h>
73#include <KisQQuickWidget.h>
74#include <QQmlError>
75#include <KisMainWindow.h>
76
78#include "kis_tool_utils.h"
79#include "kis_debug.h"
82
83#ifdef Q_OS_ANDROID
84#include <QMenuBar>
85#endif
86
87
89
90constexpr double INLINE_SIZE_DASHES_PATTERN_A = 4.0;
91constexpr double INLINE_SIZE_DASHES_PATTERN_B = 8.0;
93constexpr double INLINE_SIZE_HANDLE_THICKNESS = 1.0;
94
95
96static bool debugEnabled()
97{
98 static const bool debugEnabled = !qEnvironmentVariableIsEmpty("KRITA_DEBUG_TEXTTOOL");
99 return debugEnabled;
100}
101
103 : KoToolBase(canvas)
104 , m_optionManager(new SvgTextToolOptionsManager(this))
105 , m_textCursor(canvas)
106 , m_textOutlineHelper(new KoSvgTextShapeOutlineHelper(canvas))
107{
108 // TODO: figure out whether we should use system config for this, Windows and GTK have values for it, but Qt and MacOS don't(?).
109 const int cursorFlashLimit = 5000;
110 const bool enableCursorWithSelection = QApplication::style()->styleHint(QStyle::SH_BlinkCursorWhenTextSelected);
111 m_textCursor.setCaretSetting(QApplication::style()->pixelMetric(QStyle::PM_TextCursorWidth)
112 , qApp->cursorFlashTime()
113 , cursorFlashLimit
114 , enableCursorWithSelection);
115 connect(&m_textCursor, SIGNAL(updateCursorDecoration(QRectF)), this, SLOT(slotUpdateCursorDecoration(QRectF)));
116
117 Q_FOREACH(const QString name, SvgTextShortCuts::possibleActions()) {
118 QAction *a = action(name);
120 dbgTools << "registered" << name << a->shortcut();
121 }
122 }
123
124 const QStringList extraActions = {
125 "svg_insert_special_character",
126 "svg_paste_rich_text",
127 "svg_paste_plain_text",
128 "svg_remove_transforms_from_range",
129 "svg_clear_formatting"
130 };
131 connect(&m_textCursor, SIGNAL(sigOpenGlyphPalette()), this, SLOT(showGlyphPalette()));
132 Q_FOREACH (const QString name, extraActions) {
133 QAction *a = action(name);
134 if (a) {
136 qWarning() << "could not register" << name << a->shortcut();
137 }
138 }
139 }
140
142 QActionGroup *textTypeActions = new QActionGroup(this);
143 addMappedAction(m_textTypeSignalsMapper.data(), "text_type_preformatted", KoSvgTextShape::PreformattedText, textTypeActions);
144 addMappedAction(m_textTypeSignalsMapper.data(), "text_type_inline_wrap", KoSvgTextShape::InlineWrap, textTypeActions);
145 addMappedAction(m_textTypeSignalsMapper.data(), "text_type_pre_positioned", KoSvgTextShape::PrePositionedText, textTypeActions);
146
148 QActionGroup *typeSettingActions = new QActionGroup(this);
149 addMappedAction(m_typeSettingMovementMapper.data(), "svg_type_setting_move_selection_start_down_1_px", Qt::Key_Down, typeSettingActions);
150 addMappedAction(m_typeSettingMovementMapper.data(), "svg_type_setting_move_selection_start_up_1_px", Qt::Key_Up, typeSettingActions);
151 addMappedAction(m_typeSettingMovementMapper.data(), "svg_type_setting_move_selection_start_left_1_px", Qt::Key_Left, typeSettingActions);
152 addMappedAction(m_typeSettingMovementMapper.data(), "svg_type_setting_move_selection_start_right_1_px", Qt::Key_Right, typeSettingActions);
153
154 m_textOutlineHelper->setDrawBoundingRect(false);
155 m_textOutlineHelper->setDrawTextWrappingArea(true);
156
157 connect(&m_textCursor, SIGNAL(selectionChanged()), this, SLOT(updateTextPathHelper()));
158
159 m_base_cursor = QCursor(QIcon(":/tool_text_basic.svg").pixmap(32), 7, 7);
160 m_text_inline_horizontal = QCursor(QIcon(":/tool_text_inline_horizontal.svg").pixmap(32), 7, 7);
161 m_text_inline_vertical = QCursor(QIcon(":/tool_text_inline_vertical.svg").pixmap(32), 7, 7);
162 m_text_on_path = QCursor(QIcon(":/tool_text_on_path.svg").pixmap(32), 7, 7);
163 m_text_in_shape = QCursor(QIcon(":/tool_text_in_shape.svg").pixmap(32), 7, 7);
164 m_ibeam_horizontal = QCursor(QIcon(":/tool_text_i_beam_horizontal.svg").pixmap(22), 11, 11);
165 m_ibeam_vertical = QCursor(QIcon(":/tool_text_i_beam_vertical.svg").pixmap(22), 11, 11);
166 m_ibeam_horizontal_done = QCursor(QIcon(":/tool_text_i_beam_horizontal_done.svg").pixmap(22), 5, 11);
167}
168
170{
171 if(m_editor) {
172 m_editor->close();
173 }
174 if(m_glyphPalette) {
175 m_glyphPalette->close();
176 }
177}
178
179void SvgTextTool::activate(const QSet<KoShape *> &shapes)
180{
181 KoToolBase::activate(shapes);
182 m_canvasConnections.addConnection(canvas()->selectedShapesProxy(), SIGNAL(selectionChanged()), this, SLOT(slotShapeSelectionChanged()));
183
184 KisCanvas2 *canvas2 = qobject_cast<KisCanvas2 *>(this->canvas());
185 if (canvas2) {
186 canvas2->setCurrentShapeManagerOwnerShape(nullptr);
188 QDockWidget *docker = canvas2->viewManager()->mainWindow()->dockWidget("TextProperties");
189 if (docker && m_optionManager) {
190 m_optionManager->setTextPropertiesOpen(docker->isVisible());
191 }
192 }
193
194 connect(m_textTypeSignalsMapper.data(), SIGNAL(mapped(int)), this, SLOT(slotConvertType(int)));
195 connect(m_typeSettingMovementMapper.data(), SIGNAL(mapped(int)), this, SLOT(slotMoveTextSelection(int)));
196
199
201}
202
204{
207 m_textCursor.setShape(nullptr);
208 const KisCanvas2 *canvas2 = qobject_cast<const KisCanvas2 *>(this->canvas());
209 if (canvas2) {
211 }
212 // Exiting text editing mode is handled by requestStrokeEnd
213 disconnect(m_textTypeSignalsMapper.data(), 0, this, 0);
214 disconnect(m_typeSettingMovementMapper.data(), 0, this, 0);
215
216 m_hoveredShapeHighlightRect = QPainterPath();
217
219}
220
222{
223 return nullptr;
224}
225
226QVariant SvgTextTool::inputMethodQuery(Qt::InputMethodQuery query) const
227{
228 if (canvas()) {
229 return m_textCursor.inputMethodQuery(query);
230 } else {
231 return KoToolBase::inputMethodQuery(query);
232 }
233}
234
235void SvgTextTool::inputMethodEvent(QInputMethodEvent *event)
236{
238 inputMethodEvent(event);
239}
240
242{
243 KisQQuickWidget *optionWidget = new KisQQuickWidget();
244 optionWidget->setMinimumWidth(100);
245 optionWidget->setMinimumHeight(100);
246
247 optionWidget->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
248 optionWidget->setSource(QUrl("qrc:/SvgTextToolOptions.qml"));
249
250 m_optionManager->optionsModel()->setConfigName(this->toolId());
251 m_optionManager->setShowDebug(debugEnabled());
252 if (optionWidget->errors().isEmpty()) {
253 optionWidget->rootObject()->setProperty("manager", QVariant::fromValue(m_optionManager.data()));
254 optionWidget->connectMinimumHeightToRootObject();
255 } else {
256 qWarning() << optionWidget->errors();
257 }
258
259
260 connect(m_optionManager.data(), SIGNAL(openTextEditor()), SLOT(showEditor()));
261 connect(m_optionManager.data(), SIGNAL(openGlyphPalette()), SLOT(showGlyphPalette()));
262
263 connect(m_optionManager.data(), SIGNAL(convertTextType(int)), SLOT(slotConvertType(int)));
264 connect(m_optionManager.data(), SIGNAL(typeSettingModeChanged()), SLOT(slotUpdateTypeSettingMode()));
265 connect(m_optionManager->optionsModel(), SIGNAL(useVisualBidiCursorChanged(bool)), this, SLOT(slotUpdateVisualCursor()));
266 connect(m_optionManager->optionsModel(), SIGNAL(pasteRichtTextByDefaultChanged(bool)), this, SLOT(slotUpdateTextPasteBehaviour()));
267 const KisCanvas2 *canvas2 = qobject_cast<const KisCanvas2 *>(this->canvas());
268 if (canvas2 && canvas2->viewManager()->mainWindow()) {
269 QDockWidget *docker = canvas2->viewManager()->mainWindow()->dockWidget("TextProperties");
270 m_optionManager->setShowTextPropertyButton((docker));
271 if (docker) {
272 optionWidget->setPalette(docker->palette());
273 m_optionManager->setTextPropertiesOpen(docker->isVisible());
274 connect(m_optionManager.data(), &SvgTextToolOptionsManager::openTextPropertiesDocker, docker, [docker](){
275 docker->setVisible(!docker->isVisible());
276 });
277 // Once we have docker toggling actions, we should revisit this.
278 }
279 }
283
284
285 return optionWidget;
286}
287
295
297{
299 KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(canvas()->selectedShapesProxy(), 0);
300
302 if (shapes.isEmpty()) return 0;
303
304 KoSvgTextShape *textShape = dynamic_cast<KoSvgTextShape*>(shapes.first());
305
306 return textShape;
307}
308
310{
311 KoSvgTextShape *shape = selectedShape();
312 if (!shape) return;
313
314 if (!m_editor) {
315 m_editor = new SvgTextEditor(QApplication::activeWindow());
316 m_editor->setWindowTitle(i18nc("@title:window", "Krita - Edit Text"));
317 m_editor->setWindowModality(Qt::ApplicationModal);
318 m_editor->setAttribute( Qt::WA_QuitOnClose, false );
319
320 connect(m_editor, SIGNAL(textUpdated(KoSvgTextShape*,QString,QString)), SLOT(textUpdated(KoSvgTextShape*,QString,QString)));
321
322 m_editor->activateWindow(); // raise on creation only
323 }
324 if (!m_editor->isVisible()) {
325 m_editor->setInitialShape(shape);
326#ifdef Q_OS_ANDROID
327 // for window manager
328 m_editor->setWindowFlags(Qt::Dialog);
329 m_editor->menuBar()->setNativeMenuBar(false);
330#endif
331 m_editor->show();
332 }
333}
334
335void SvgTextTool::textUpdated(KoSvgTextShape *shape, const QString &svg, const QString &defs)
336{
337 SvgTextChangeCommand *cmd = new SvgTextChangeCommand(shape, svg, defs);
338 canvas()->addCommand(cmd);
339}
340
342{
343 if (!m_glyphPalette) {
344 m_glyphPalette = new GlyphPaletteDialog(QApplication::activeWindow());
345 m_glyphPalette->setAttribute( Qt::WA_QuitOnClose, false );
346
347 connect(&m_textCursor, SIGNAL(selectionChanged()), this, SLOT(updateGlyphPalette()));
348 connect(m_glyphPalette, SIGNAL(signalInsertRichText(KoSvgTextShape*, bool)), this, SLOT(insertRichText(KoSvgTextShape*, bool)));
349
350 m_glyphPalette->activateWindow();
351 }
352 if (!m_glyphPalette->isVisible()) {
353 m_glyphPalette->show();
355 }
356}
357
359{
360 if (m_glyphPalette && m_glyphPalette->isVisible()) {
361 QString grapheme = QString();
362 if (m_textCursor.shape()) {
363 int pos = m_textCursor.getPos();
364 int pos2 = pos > 0? m_textCursor.shape()->posLeft(pos, false): m_textCursor.shape()->posRight(pos, false);
365 int start = m_textCursor.shape()->indexForPos(qMin(pos, pos2));
366 int end = m_textCursor.shape()->indexForPos(qMax(pos, pos2));
367 grapheme = m_textCursor.shape()->plainText().mid(start, end-start);
368 }
369 m_glyphPalette->setGlyphModelFromProperties(m_textCursor.currentTextProperties(), grapheme);
370 }
371}
372
377
378void SvgTextTool::insertRichText(KoSvgTextShape *richText, bool replaceLastGlyph)
379{
380 if (replaceLastGlyph) {
383 }
384 m_textCursor.insertRichText(richText, true);
385}
386
388{
389 QStringList propStrings;
390 QMap<QString, QString> paraProps = properties.convertParagraphProperties();
391 for (auto it = paraProps.constBegin(); it != paraProps.constEnd(); it++) {
392 propStrings.append(QString("%1: %2;").arg(it.key()).arg(it.value()));
393 }
394 paraProps = properties.convertToSvgTextAttributes();
395 for (auto it = paraProps.constBegin(); it != paraProps.constEnd(); it++) {
396 propStrings.append(QString("%1: %2;").arg(it.key()).arg(it.value()));
397 }
398
399 return QString("<defs>\n <style>\n text {\n %1\n }\n </style>\n</defs>").arg(propStrings.join("\n "));
400}
401
403{
404 const bool useCurrent = m_optionManager->optionsModel()->useCurrentTextProperties();
405 const QString presetName = m_optionManager->optionsModel()->cssStylePresetName();
406
408 if (useCurrent || presetName.isEmpty()) {
410 props = textData.commonProperties;
411 } else {
413 QVector<KoResourceSP> res = model->resourcesForName(presetName);
414 if (res.first()) {
415 KoCssStylePresetSP style = res.first().staticCast<KoCssStylePreset>();
416 qreal dpi = 72;
417 KisCanvas2 *canvas2 = qobject_cast<KisCanvas2 *>(this->canvas());
418 if (canvas2) {
419 dpi = canvas2->image()->xRes() * 72.0;
420 }
421 if (style) {
422 props = style->properties(dpi, true);
423 }
424 }
425 }
426
427 QColor fontColor = (canvas()->resourceManager()->isUsingOtherColor()
428 ? canvas()->resourceManager()->backgroundColor()
429 : canvas()->resourceManager()->foregroundColor()).toQColor();
431 bg->setColor(fontColor);
433 props.setProperty(KoSvgTextProperties::FillId, QVariant::fromValue(bgProp));
434 return props;
435}
436
438{
440 if (shapes.size() == 1) {
441 KoSvgTextShape *textShape = selectedShape();
442 if (!textShape) {
444 return;
445 }
446 } else if (shapes.size() > 1) {
447 KoSvgTextShape *foundTextShape = nullptr;
448
449 Q_FOREACH (KoShape *shape, shapes) {
450 KoSvgTextShape *textShape = dynamic_cast<KoSvgTextShape*>(shape);
451 if (textShape) {
452 foundTextShape = textShape;
453 break;
454 }
455 }
456
458 if (foundTextShape) {
459 koSelection()->select(foundTextShape);
460 }
461 return;
462 }
463 KoSvgTextShape *const shape = selectedShape();
464 if (shape != m_textCursor.shape() || shape == nullptr) {
465 m_textCursor.setShape(shape);
467 if (shape) {
468 setTextMode(true);
469 } else {
470 setTextMode(false);
471 }
472 }
474}
475
477{
479}
480
485
487{
488 return m_textCursor.paste();
489}
490
495
502
507
512
514{
515 if (!isActivated()) return;
519 m_interactionStrategy->cancelInteraction();
520 m_interactionStrategy = nullptr;
521 useCursor(Qt::ArrowCursor);
523 }
524 }
525}
526
535
537{
538 if (canvas()) {
539 canvas()->updateCanvas(updateRect);
540 }
541}
542
544 KoSvgTextShape *shape = selectedShape();
545 if (shape) {
546 if (index == shape->textType()) return;
548 KUndo2Command *parentCommand = new KUndo2Command();
551 KoSvgConvertTextTypeCommand *cmd = new KoSvgConvertTextTypeCommand(shape, type, m_textCursor.getPos(), parentCommand);
552 parentCommand->setText(cmd->text());
556 canvas()->addCommand(parentCommand);
558 }
559}
560
562{
563 m_textCursor.setVisualMode(m_optionManager->optionsModel()->useVisualBidiCursor());
564}
565
567{
568 m_textCursor.setPasteRichTextByDefault(m_optionManager->optionsModel()->pasteRichtTextByDefault());
569}
570
572{
573 KoSvgTextShape *shape = selectedShape();
574 QActionGroup *typeConvertGroup = action("text_type_preformatted")->actionGroup();
575 if (typeConvertGroup) {
576 typeConvertGroup->setExclusive(true);
577 Q_FOREACH (QAction *a, typeConvertGroup->actions()) {
578 a->setCheckable(true);
579 }
580 }
581 if (m_optionManager) {
582 if (shape) {
583 m_optionManager->convertToTextType(int(shape->textType()));
584 if (typeConvertGroup) {
585 typeConvertGroup->setEnabled(true);
586 }
587 action("text_type_preformatted")->setChecked(shape->textType() == KoSvgTextShape::PreformattedText);
588 action("text_type_pre_positioned")->setChecked(shape->textType() == KoSvgTextShape::PrePositionedText);
589 action("text_type_inline_wrap")->setChecked(shape->textType() == KoSvgTextShape::InlineWrap);
590
591 } else {
592 m_optionManager->convertToTextType(-1);
593 if (typeConvertGroup) {
594 typeConvertGroup->setEnabled(false);
595 }
596 }
597 const bool enableTypeSetting = (m_optionManager->typeSettingMode() && shape && (shape->textType() == KoSvgTextShape::PreformattedText ||shape->textType() == KoSvgTextShape::PrePositionedText));
598 QActionGroup *svgTypeSettingGroup = action("svg_type_setting_move_selection_start_down_1_px")->actionGroup();
599 if (svgTypeSettingGroup) {
600 svgTypeSettingGroup->setEnabled(enableTypeSetting);
601 }
603 }
604}
605
607{
608 KoSvgTextShape *shape = selectedShape();
609 if (!shape) return;
610 QPointF offset;
611 // test type setting mode.
612 if (index == Qt::Key_Down) {
613 offset = QPointF(0, 1);
614 } else if (index == Qt::Key_Up) {
615 offset = QPointF(0, -1);
616 } else if (index == Qt::Key_Right) {
617 offset = QPointF(-1, 0);
618 } else if (index == Qt::Key_Left) {
619 offset = QPointF(1, 0);
620 } else {
621 return;
622 }
623 const KisCanvas2 *canvas2 = qobject_cast<const KisCanvas2 *>(this->canvas());
624 if (canvas2) {
625 offset = canvas2->coordinatesConverter()->imageToDocumentTransform().map(offset);
626 }
627 KUndo2Command *parentCommand = new KUndo2Command();
631 parentCommand->setText(cmd->text());
632 canvas()->addCommand(parentCommand);
633}
634
640
642{
644 if (!node->isEditable(true)) {
645 KisCanvas2 * kiscanvas = static_cast<KisCanvas2*>(canvas());
646 if (kiscanvas) {
647 QString message = KisToolUtils::nodeEditableMessage(node);
648 kiscanvas->viewManager()->showFloatingMessage(message, KisIconUtils::loadIcon("object-locked"));
649 }
650 return false;
651 }
652 return true;
653}
654
656{
657 QRectF rect;
658 KoSvgTextShape *const shape = selectedShape();
659 if (shape) {
660 rect |= shape->boundingRect();
661
662 const QPointF anchor = shape->absoluteTransformation().map(QPointF());
663 rect |= kisGrowRect(QRectF(anchor, anchor), handleRadius());
664
665 qreal pxlToPt = canvas()->viewConverter()->viewToDocumentX(1.0);
667
668 if (std::optional<InlineSizeInfo> info = InlineSizeInfo::fromShape(shape, length * pxlToPt)) {
669 rect |= kisGrowRect(info->boundingRect(), handleRadius() * 2);
670 }
671
672 if (canvas()->snapGuide()->isSnapping()) {
673 rect |= canvas()->snapGuide()->boundingRect();
674 }
675 }
676
677 rect |= m_hoveredShapeHighlightRect.boundingRect();
678
679 rect |= m_textOutlineHelper->decorationRect();
680 rect |= m_textOnPathHelper.decorationRect(canvas()->viewConverter()->documentToView());
681
682 return rect;
683}
684
685void SvgTextTool::paint(QPainter &gc, const KoViewConverter &converter)
686{
687 if (!isActivated()) return;
688
691
693 m_interactionStrategy->paint(gc, converter, canvas()->displayRendererInterface());
694 }
695
696 KoSvgTextShape *shape = selectedShape();
697 if (shape) {
698 KisHandlePainterHelper handlePainter =
700
702 handlePainter.setHandleStyle(KisHandleStyle::primarySelection(handlePalette));
703 QPainterPath path;
704 path.addRect(shape->outlineRect());
705 handlePainter.drawPath(path);
706 }
707
708 qreal pxlToPt = canvas()->viewConverter()->viewToDocumentX(1.0);
710 if (std::optional<InlineSizeInfo> info = InlineSizeInfo::fromShape(shape, length * pxlToPt)) {
711 handlePainter.setHandleStyle(KisHandleStyle::secondarySelection(handlePalette));
712 handlePainter.drawConnectionLine(info->baselineLineLocal());
713
717 }
719 handlePainter.drawHandleLine(info->startLineLocal());
720 handlePainter.drawHandleLine(info->startLineDashes(), INLINE_SIZE_HANDLE_THICKNESS, dashPattern, INLINE_SIZE_DASHES_PATTERN_A);
721
722 handlePainter.setHandleStyle(KisHandleStyle::secondarySelection(handlePalette));
726 }
727 handlePainter.drawHandleLine(info->endLineLocal());
728 handlePainter.drawHandleLine(info->endLineDashes(), INLINE_SIZE_HANDLE_THICKNESS, dashPattern, INLINE_SIZE_DASHES_PATTERN_A);
729 }
730
732 handlePainter.setHandleStyle(KisHandleStyle::highlightedPrimaryHandles(handlePalette));
733 } else {
734 handlePainter.setHandleStyle(KisHandleStyle::primarySelection(handlePalette));
735 }
736 handlePainter.drawHandleCircle(QPointF(), KoToolBase::handleRadius() * 0.75);
737 }
738
739 m_textOutlineHelper->setDecorationThickness(decorationThickness());
740 m_textOutlineHelper->setHandleRadius(handleRadius());
741 m_textOutlineHelper->paint(&gc, converter);
744 m_textOnPathHelper.paint(&gc, converter, handlePalette);
745 gc.setTransform(converter.documentToView(), true);
746 {
748 if (!m_hoveredShapeHighlightRect.isEmpty()) {
750 QPainterPath path;
751 path.addPath(m_hoveredShapeHighlightRect);
752 handlePainter.drawPath(path);
753 }
754 }
755 if (shape) {
756 m_textCursor.paintDecorations(gc, systemPalette.color(QPalette::Highlight), decorationThickness(), handleRadius(), handlePalette);
757 }
759 gc.save();
760 canvas()->snapGuide()->paint(gc, converter, canvas()->displayRendererInterface());
761 gc.restore();
762 }
763
764 // Paint debug outline
765 if (debugEnabled() && shape) {
766 gc.save();
767 using Element = KoSvgTextShape::DebugElement;
768 KoSvgTextShape::DebugElements el{};
769 if (m_optionManager->showCharacterDebug()) {
770 el |= Element::CharBbox;
771 }
772 if (m_optionManager->showLineDebug()) {
773 el |= Element::LineBox;
774 }
775
776 gc.setTransform(shape->absoluteTransformation(), true);
777 shape->paintDebug(gc, el);
778 gc.restore();
779 }
780}
781
783{
784 // When using touch drawing, we only ever receive move events after the
785 // finger has pressed down. We have to issue an artificial move here so that
786 // the tool's state is updated properly to handle the press.
787 if (event->isTouchEvent()) {
788 mouseMoveEvent(event);
789 }
790
791 if (!nodeEditable()) {
792 event->accept();
793 return;
794 }
795
796 KisHandlePalette handlePalette;
797 KisCanvas2* kisCanvas = dynamic_cast<KisCanvas2*>(canvas());
798 if (kisCanvas) {
799 handlePalette = kisCanvas->displayColorConverter()->handlePaletteForDisplayColorSpace();
800 }
801
803
804 if (selectedShape) {
805 if (m_textOutlineHelper->contourModeButtonHovered(event->point)) {
806 m_textOutlineHelper->toggleTextContourMode(selectedShape);
807 event->accept();
808 canvas()->canvasController()->toolManager()->switchToolRequested("InteractionTool");
809 return;
810 }
811
814 if (handle != SvgTextCursor::NoHandle) {
819 }
820 event->accept();
821 return;
822 }
826 m_textOutlineHelper->setDrawTextWrappingArea(false);
827 event->accept();
828 return;
829 } else if (m_textOnPathHelper.hitTest(event->point, canvas()->viewConverter()->viewToDocument())) {
833 event->accept();
834 return;
838 event->accept();
839 return;
843 event->accept();
844 return;
848 event->accept();
849 return;
850 }
851 }
852
853 KoSvgTextShape *hoveredShape = dynamic_cast<KoSvgTextShape *>(canvas()->shapeManager()->shapeAt(event->point));
854 KoPathShape *hoveredFlowShape = dynamic_cast<KoPathShape *>(canvas()->shapeManager()->shapeAt(event->point));
855 QString shapeType;
856 QPainterPath hoverPath = KisToolUtils::shapeHoverInfoCrossLayer(canvas(), event->point, shapeType);
857 bool crossLayerPossible = !hoverPath.isEmpty() && shapeType == KoSvgTextShape_SHAPEID;
858
859 if (!selectedShape && !hoveredShape && !hoveredFlowShape && !crossLayerPossible) {
860 QPointF point = canvas()->snapGuide()->snap(event->point, event->modifiers());
861 m_interactionStrategy.reset(new SvgCreateTextStrategy(this, point));
863 event->accept();
864 } else if (hoveredShape) {
865 if (hoveredShape != selectedShape) {
867 canvas()->shapeManager()->selection()->select(hoveredShape);
868 m_hoveredShapeHighlightRect = QPainterPath();
869 }
870 m_interactionStrategy.reset(new SvgSelectTextStrategy(this, &m_textCursor, event->point, event->modifiers()));
872 event->accept();
873 } else if (hoveredFlowShape) {
874 QPointF point = canvas()->snapGuide()->snap(event->point, event->modifiers());
875 m_interactionStrategy.reset(new SvgCreateTextStrategy(this, point, hoveredFlowShape));
877 event->accept();
878 } else if (crossLayerPossible) {
880 m_interactionStrategy.reset(new SvgSelectTextStrategy(this, &m_textCursor, event->point, event->modifiers()));
882 m_hoveredShapeHighlightRect = QPainterPath();
883 } else {
885 }
886 event->accept();
887 } else { // if there's a selected shape but no hovered shape...
889 event->accept();
890 }
891
893}
894
895static inline Qt::CursorShape angleToCursor(const QVector2D unit)
896{
897 constexpr float SIN_PI_8 = 0.382683432;
898 if (unit.y() < SIN_PI_8 && unit.y() > -SIN_PI_8) {
899 return Qt::SizeHorCursor;
900 } else if (unit.x() < SIN_PI_8 && unit.x() > -SIN_PI_8) {
901 return Qt::SizeVerCursor;
902 } else if ((unit.x() > 0 && unit.y() > 0) || (unit.x() < 0 && unit.y() < 0)) {
903 return Qt::SizeFDiagCursor;
904 } else {
905 return Qt::SizeBDiagCursor;
906 }
907}
908
909static inline Qt::CursorShape lineToCursor(const QLineF line, const KoCanvasBase *const canvas)
910{
911 const KisCanvas2 *const canvas2 = qobject_cast<const KisCanvas2 *>(canvas);
912 KIS_ASSERT(canvas2);
913 const KisCoordinatesConverter *const converter = canvas2->coordinatesConverter();
914 QLineF wdgLine = converter->flakeToWidget(line);
915 return angleToCursor(QVector2D(wdgLine.p2() - wdgLine.p1()).normalized());
916}
917
919{
920 m_lastMousePos = event->point;
921 m_hoveredShapeHighlightRect = QPainterPath();
923
925 m_interactionStrategy->handleMouseMove(event->point, event->modifiers());
928 if (c && c->draggingInlineSize() && !c->hasWrappingShape()) {
929 if (this->writingMode() == KoSvgText::HorizontalTB) {
931 } else {
933 }
934 } else {
936 }
937 } else if (m_dragging == DragMode::Select && this->selectedShape()) {
939 // Todo: replace with something a little less hacky.
940 if (selectedShape->writingMode() == KoSvgText::HorizontalTB) {
942 } else {
944 }
945 } else if (m_dragging != DragMode::InShapeOffset) {
946 useCursor(Qt::ArrowCursor);
947 }
948 event->accept();
949 } else {
951
953 QCursor cursor = m_base_cursor;
954 if (selectedShape) {
956 const qreal sensitivity = grabSensitivityInPt();
957
960 if (handle != SvgTextCursor::NoHandle) {
963 }
964
966 if (std::optional<InlineSizeInfo> info = InlineSizeInfo::fromShape(selectedShape)) {
967 const QPolygonF zone = info->endLineGrabRect(sensitivity);
968 const QPolygonF startZone = info->startLineGrabRect(sensitivity);
969 if (zone.containsPoint(event->point, Qt::OddEvenFill)) {
971 cursor = lineToCursor(info->baselineLine(), canvas());
972 } else if (startZone.containsPoint(event->point, Qt::OddEvenFill)){
974 cursor = lineToCursor(info->baselineLine(), canvas());
975 }
976 }
977 }
978
980 const QPolygonF textOutline = selectedShape->absoluteTransformation().map(selectedShape->outlineRect());
981 const QPolygonF moveBorderRegion = selectedShape->absoluteTransformation().map(kisGrowRect(selectedShape->outlineRect(),
982 sensitivity * 2));
983 if (moveBorderRegion.containsPoint(event->point, Qt::OddEvenFill) && !textOutline.containsPoint(event->point, Qt::OddEvenFill)) {
985 cursor = Qt::SizeAllCursor;
986 }
987 }
988 }
989
990 QString shapeType;
991 bool isHorizontal = true;
992 const KoSvgTextShape *hoveredShape = dynamic_cast<KoSvgTextShape *>(canvas()->shapeManager()->shapeAt(event->point));
993 const KoPathShape *hoveredFlowShape = dynamic_cast<KoPathShape *>(canvas()->shapeManager()->shapeAt(event->point));
994 QPainterPath hoverPath = KisToolUtils::shapeHoverInfoCrossLayer(canvas(), event->point, shapeType, &isHorizontal);
995
996 bool textAreasHovered = false;
997 if (m_textOnPathHelper.hitTest(event->point, canvas()->viewConverter()->viewToDocument()) ) {
998 cursor = Qt::ArrowCursor;
999 } else if(std::optional<QPointF> offsetVector = SvgChangeTextPaddingMarginStrategy::hitTest(selectedShape, event->point, grabSensitivityInPt())) {
1000 cursor = lineToCursor(QLineF(QPointF(0, 0), offsetVector.value()).normalVector(), canvas());
1001 textAreasHovered = true;
1002 } else if (selectedShape && selectedShape == hoveredShape && m_highlightItem == HighlightItem::None) {
1005 } else {
1007 }
1008 } else if (hoveredShape && m_highlightItem == HighlightItem::None) {
1009 if (!hoveredShape->textWrappingAreas().isEmpty()) {
1010 Q_FOREACH(QPainterPath path, hoveredShape->textWrappingAreas()) {
1011 m_hoveredShapeHighlightRect.addPath(hoveredShape->absoluteTransformation().map(path));
1012 }
1013 } else {
1014 m_hoveredShapeHighlightRect.addRect(hoveredShape->boundingRect());
1015 }
1016 if (hoveredShape->writingMode() == KoSvgText::HorizontalTB) {
1018 } else {
1020 }
1021 } else if (hoveredFlowShape) {
1022 m_hoveredShapeHighlightRect.addPath(hoveredFlowShape->absoluteTransformation().map(hoveredFlowShape->outline()));
1023 if (hoveredFlowShape->segmentAtPoint(event->point, handleGrabRect(event->point)).isValid()) {
1025 } else {
1027 }
1028 } else if (!hoverPath.isEmpty() && shapeType == KoSvgTextShape_SHAPEID && m_highlightItem == HighlightItem::None) {
1029 m_hoveredShapeHighlightRect = hoverPath;
1030 if (isHorizontal) {
1032 } else {
1034 }
1035 }
1036 m_textOutlineHelper->setTextAreasHovered(textAreasHovered);
1038 event->ignore();
1039 }
1040
1042}
1043
1045{
1047 m_interactionStrategy->finishInteraction(event->modifiers());
1048 KUndo2Command *const command = m_interactionStrategy->createCommand();
1049 if (command) {
1051 canvas()->addCommand(command);
1053 }
1054 m_interactionStrategy = nullptr;
1057 }
1059 m_textOutlineHelper->setDrawTextWrappingArea(true);
1062 event->accept();
1063 } else {
1065 }
1066 event->accept();
1067}
1068
1069void SvgTextTool::keyPressEvent(QKeyEvent *event)
1070{
1072 && (event->key() == Qt::Key_Control || event->key() == Qt::Key_Alt || event->key() == Qt::Key_Shift
1073 || event->key() == Qt::Key_Meta)) {
1074 m_interactionStrategy->handleMouseMove(m_lastMousePos, event->modifiers());
1075 event->accept();
1076 return;
1077 } else if (event->key() == Qt::Key_Escape) {
1079 } else if (selectedShape()) {
1081 }
1082
1083 event->ignore();
1084}
1085
1086void SvgTextTool::keyReleaseEvent(QKeyEvent *event)
1087{
1088 m_textCursor.updateModifiers(event->modifiers());
1090 && (event->key() == Qt::Key_Control || event->key() == Qt::Key_Alt || event->key() == Qt::Key_Shift
1091 || event->key() == Qt::Key_Meta)) {
1092 m_interactionStrategy->handleMouseMove(m_lastMousePos, event->modifiers());
1093 event->accept();
1094 } else {
1095 event->ignore();
1096 }
1097}
1098
1099void SvgTextTool::focusInEvent(QFocusEvent *event)
1100{
1102 event->accept();
1103}
1104
1105void SvgTextTool::focusOutEvent(QFocusEvent *event)
1106{
1108 event->accept();
1109}
1110
1112{
1113 if (canvas()->shapeManager()->shapeAt(event->point) != selectedShape()) {
1114 event->ignore(); // allow the event to be used by another
1115 return;
1116 } else {
1117 m_textCursor.setPosToPoint(event->point, true);
1120 }
1121 const QRectF updateRect = std::exchange(m_hoveredShapeHighlightRect, QPainterPath()).boundingRect();
1122 canvas()->updateCanvas(kisGrowRect(updateRect, 100));
1123 event->accept();
1124}
1125
1127{
1128 if (canvas()->shapeManager()->shapeAt(event->point) == selectedShape()) {
1129 // TODO: Consider whether we want to use sentence based selection instead:
1130 // QTextBoundaryFinder allows us to find sentences if necessary.
1133 event->accept();
1134 }
1135}
1136
1138{
1139 const int sensitivity = grabSensitivity();
1140 return canvas()->viewConverter()->viewToDocumentX(sensitivity);
1141}
1142
1148
1149void SvgTextTool::addMappedAction(KisSignalMapper *mapper, const QString &actionName, const int value, QActionGroup *group)
1150{
1151 QAction *a = action(actionName);
1152 if (a) {
1153 connect(a, SIGNAL(triggered()), mapper, SLOT(map()));
1154 mapper->setMapping(a, value);
1155 m_textCursor.registerPropertyAction(a, actionName);
1156 if (group && !a->actionGroup()) {
1157 group->addAction(a);
1158 }
1159 }
1160}
1161
qreal length(const QPointF &vec)
Definition Ellipse.cc:82
float value(const T *src, size_t ch)
#define KoSvgTextShape_SHAPEID
constexpr double INLINE_SIZE_DASHES_PATTERN_A
static Qt::CursorShape lineToCursor(const QLineF line, const KoCanvasBase *const canvas)
constexpr int INLINE_SIZE_DASHES_PATTERN_LENGTH
Size of the hidden part of the inline-size handle dashes.
constexpr double INLINE_SIZE_HANDLE_THICKNESS
Total amount of trailing dashes on inline-size handles.
constexpr double INLINE_SIZE_DASHES_PATTERN_B
Size of the visible part of the inline-size handle dashes.
static Qt::CursorShape angleToCursor(const QVector2D unit)
static bool debugEnabled()
Linethickness.
The GlyphPaletteDialog class.
void setText(const KUndo2MagicString &text)
The KisAllresourcesModel class provides access to the cache database for a particular resource type....
QVector< KoResourceSP > resourcesForName(const QString &name) const
KisDisplayColorConverter displayColorConverter
KisCoordinatesConverter * coordinatesConverter
void setCurrentShapeManagerOwnerShape(KoShape *source) override
sets the group shape that is supposed to be "entered"
KisImageWSP image() const
KisViewManager * viewManager() const
_Private::Traits< T >::Result flakeToWidget(const T &obj) const
KisHandlePalette handlePaletteForDisplayColorSpace() const
handlePaletteForDisplayColorSpace
The KisHandlePainterHelper class is a special helper for painting handles around objects....
void drawPath(const QPainterPath &path)
void drawConnectionLine(const QLineF &line)
void setHandleStyle(const KisHandleStyle &style)
void drawHandleLine(const QLineF &line, qreal width=1.0, QVector< qreal > dashPattern={}, qreal dashOffset=0.0)
void drawHandleCircle(const QPointF &center, qreal radius)
static KisHandleStyle & partiallyHighlightedPrimaryHandles(KisHandlePalette palette=KisHandlePalette())
static KisHandleStyle & highlightedPrimaryHandlesWithSolidOutline(KisHandlePalette palette=KisHandlePalette())
static KisHandleStyle & secondarySelection(KisHandlePalette palette=KisHandlePalette())
static KisHandleStyle & primarySelection(KisHandlePalette palette=KisHandlePalette())
static KisHandleStyle & highlightedPrimaryHandles(KisHandlePalette palette=KisHandlePalette())
double xRes() const
QDockWidget * dockWidget(const QString &id)
The PopupWidgetInterface abstract class defines the basic interface that will be used by all popup wi...
The KisQQuickWidget class.
void connectMinimumHeightToRootObject()
connectMinimumHeightToRootObject By default we scale rootObject to widget, but in some situations we ...
static KisAllResourcesModel * resourceModel(const QString &resourceType)
void addConnection(Sender sender, Signal signal, Receiver receiver, Method method, Qt::ConnectionType type=Qt::AutoConnection)
The KisSignalMapper class bundles signals from identifiable senders.
void setMapping(QObject *sender, int id)
void setTextPropertiesInterface(KoSvgTextPropertiesInterface *interface)
setTextPropertiesInterface set the text properties interface. This should be done on tool activation....
KisMainWindow * mainWindow() const
KisTextPropertiesManager * textPropertyManager() const
void showFloatingMessage(const QString &message, const QIcon &icon, int timeout=4500, KisFloatingMessage::Priority priority=KisFloatingMessage::Medium, int alignment=Qt::AlignCenter|Qt::TextWordWrap)
shows a floating message in the top right corner of the canvas
KoSnapGuide * snapGuide
virtual KoShapeManager * shapeManager() const =0
virtual const KoViewConverter * viewConverter() const =0
virtual void updateCanvas(const QRectF &rc)=0
virtual KoColorDisplayRendererInterface * displayRendererInterface() const
displayRendererInterface The display renderer interface has a number of color conversion functions wh...
virtual void addCommand(KUndo2Command *command)=0
QPointer< KoCanvasResourceProvider > resourceManager
KoCanvasController * canvasController() const
virtual KoSelectedShapesProxy * selectedShapesProxy() const =0
selectedShapesProxy() is a special interface for keeping a persistent connections to selectionChanged...
QPointer< KoToolManager > toolManager
A simple solid color shape background.
virtual KisHandlePalette handlePaletteForDisplayColorSpace() const =0
handlePaletteForDisplayColorSpace
virtual QPalette systemPaletteForDisplayColorSpace() const =0
systemPaletteForDisplayColorSpace
The KoCssStylePreset class.
bool isValid() const
Returns if segment is valid, e.g. has two valid points.
The position of a path point within a path shape.
Definition KoPathShape.h:63
KoPathSegment segmentAtPoint(const QPointF &point, const QRectF &grabRoi) const
QPainterPath outline() const override
reimplemented
bool isTouchEvent() const
Qt::KeyboardModifiers modifiers() const
QPointF point
The point in document coordinates.
virtual KoSelection * selection()=0
void deselectAll()
clear the selections list
void select(KoShape *shape)
const QList< KoShape * > selectedEditableShapes() const
KoShape * shapeAt(const QPointF &position, KoFlake::ShapeSelection selection=KoFlake::ShapeOnTop, bool omitHiddenShapes=true)
KoSelection * selection
QTransform absoluteTransformation() const
Definition KoShape.cpp:330
static KisHandlePainterHelper createHandlePainterHelperView(QPainter *painter, KoShape *shape, const KoViewConverter &converter, qreal handleRadius=0.0, int decorationThickness=1)
Definition KoShape.cpp:980
void paint(QPainter &painter, const KoViewConverter &converter, const KoColorDisplayRendererInterface *displayRenderer)
paints the guide
QPointF snap(const QPointF &mousePosition, Qt::KeyboardModifiers modifiers)
snaps the mouse position, returns if mouse was snapped
QRectF boundingRect()
returns the bounding rect of the guide
The SvgConvertTextTypeCommand class This command allows textshapes to be converted between preformatt...
@ FillId
KoSvgText::BackgroundProperty.
@ WritingModeId
KoSvgText::WritingMode.
QMap< QString, QString > convertToSvgTextAttributes() const
QMap< QString, QString > convertParagraphProperties() const
convertParagraphProperties some properties only apply to the root shape, so we write those separately...
void setProperty(PropertyId id, const QVariant &value)
QVariant propertyOrDefault(PropertyId id) const
static void removeContourShapesFromFlow(KoSvgTextShape *textShape, KUndo2Command *parent, bool textInShape, bool textPaths)
removeContourShapesFromFlow Create a command to remove all contour shapes of a certain type from the ...
The KoSvgTextShapeOutlineHelper class helper class that draws the text outlines and contour mode butt...
int posLeft(int pos, bool visual=false)
QRectF boundingRect() const override
Get the bounding box of the shape.
QList< QPainterPath > textWrappingAreas() const
textWrappingAreas The text wrapping areas are computed from shapesInside() and shapesSubtract(),...
int indexForPos(int pos) const
indexForPos get the string index for a given cursor position.
@ PreformattedText
Text-on-Path falls under this or PrePositionedText depending on collapse of lines.
@ TextInShape
Uses shape-inside to wrap and preserves spaces.
@ InlineWrap
Uses inline size to wrap and preserves spaces.
TextType textType() const
textType This enum gives an indication of what kind of text this shape is. The different text types a...
int posRight(int pos, bool visual=false)
void paintDebug(QPainter &painter, DebugElements elements) const
KoSvgText::WritingMode writingMode() const
writingMode There's a number of places we need to check the writing mode to provide proper controls.
QRectF outlineRect() const override
KoCanvasBase * canvas() const
Returns the canvas the tool is working on.
void selectionChanged(bool hasSelection)
Q_INVOKABLE QString toolId() const
QCursor cursor() const
return the last emitted cursor
int grabSensitivity() const
Convenience function to get the current grab sensitivity.
void setTextMode(bool value)
virtual void repaintDecorations()
int handleRadius() const
Convenience function to get the current handle radius.
void useCursor(const QCursor &cursor)
virtual void activate(const QSet< KoShape * > &shapes)
QRectF handleGrabRect(const QPointF &position) const
virtual void deactivate()
QAction * action(const QString &name) const
bool isActivated() const
virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const
int decorationThickness() const
decorationThickness The minimum thickness for tool decoration lines, this is derived from the screen ...
virtual qreal viewToDocumentX(qreal viewX) const
virtual QPointF documentToView(const QPointF &documentPoint) const
static std::optional< QPointF > hitTest(KoSvgTextShape *shape, const QPointF &mousePos, const qreal grabSensitivityInPts)
hitTest Tests whether the current mouse position is over a text wrapping area, and if so,...
QRectF decorationRect(const QTransform documentToView) const
decorationRect
void setShape(KoSvgTextShape *shape)
setShape Set the shape for which to draw the text path.
bool hitTest(QPointF mouseInPts, const QTransform viewToDocument)
hitTest
void setPos(int pos)
setPos the the position of the cursor, where the text path is sought. A single text shape can have mu...
void paint(QPainter *painter, const KoViewConverter &converter, KisHandlePalette handlePalette)
paint Paint the handles for the text path.
static QStringList possibleActions()
The SvgTextToolOptionsManager class.
void openTextPropertiesDocker(bool open)
void activate(const QSet< KoShape * > &shapes) override
reimplemented from KoToolBase
void mouseTripleClickEvent(KoPointerEvent *event) override
reimplemented from KoToolBase
void copy() const override
reimplemented from superclass
bool selectAll() override
selectAll select all data the tool can select.
KisSignalAutoConnectionsStore m_canvasConnections
~SvgTextTool() override
void requestStrokeCancellation() override
void inputMethodEvent(QInputMethodEvent *event) override
QScopedPointer< KisSignalMapper > m_textTypeSignalsMapper
void mouseMoveEvent(KoPointerEvent *event) override
reimplemented from KoToolBase
std::unique_ptr< KoInteractionStrategy > m_interactionStrategy
void keyPressEvent(QKeyEvent *event) override
void requestStrokeEnd() override
void slotTextTypeUpdated()
slotTextTypeUpdated Update the text type in the tool options.
QPointer< GlyphPaletteDialog > m_glyphPalette
QScopedPointer< SvgTextToolOptionsManager > m_optionManager
bool nodeEditable()
nodeEditable
QCursor m_base_cursor
KoSelection * koSelection() const
DragMode m_dragging
void mouseReleaseEvent(KoPointerEvent *event) override
reimplemented from KoToolBase
void slotUpdateVisualCursor()
slotUpdateVisualCursor update the visual cursor mode on the text cursor.
QString generateDefs(const KoSvgTextProperties &properties=KoSvgTextProperties())
generateDefs This generates a defs section with the appropriate css and css strings assigned.
qreal grabSensitivityInPt() const
void deleteSelection() override
reimplemented from superclass
QCursor m_text_inline_horizontal
QCursor m_ibeam_horizontal
KoSvgTextShape * selectedShape() const
QPointF m_lastMousePos
QCursor m_ibeam_horizontal_done
SvgTextTool(KoCanvasBase *canvas)
QVariant inputMethodQuery(Qt::InputMethodQuery query) const override
void slotShapeSelectionChanged()
selectionChanged called when the canvas selection is changed.
void showGlyphPalette()
showGlyphPalette Shows the glyph palette dialog.
QCursor m_text_inline_vertical
QPainterPath m_hoveredShapeHighlightRect
void focusInEvent(QFocusEvent *event) override
bool hasSelection() override
reimplemented from superclass
SvgTextOnPathDecorationHelper m_textOnPathHelper
KoSvgTextProperties propertiesForNewText() const
propertiesForNewText get the text properties that should be used for new text.
void updateGlyphPalette()
updateGlyphPalette update the glyph palette dialog from the current selection.
void mouseDoubleClickEvent(KoPointerEvent *event) override
reimplemented from superclass
bool m_strategyAddingCommand
KisPopupWidgetInterface * popupWidget() override
HighlightItem m_highlightItem
void focusOutEvent(QFocusEvent *event) override
void updateTextPathHelper()
KoToolSelection * selection() override
reimplemented from superclass
void slotUpdateTextPasteBehaviour()
slotUpdateTextPasteBehaviour update the default text paste behaviour.
void deselect() override
deselect the tool should clear the selection if it has one.
QCursor m_ibeam_vertical
virtual QWidget * createOptionWidget() override
reimplemented from KoToolBase
void insertRichText(KoSvgTextShape *richText, bool replaceLastGlyph=false)
insertRichText Insert a rich text shape, used by the glyph palette..
QCursor m_text_in_shape
void textUpdated(KoSvgTextShape *shape, const QString &svg, const QString &defs)
void deactivate() override
reimplemented from KoToolBase
void mousePressEvent(KoPointerEvent *event) override
reimplemented from KoToolBase
void slotUpdateCursorDecoration(QRectF updateRect)
updateCursor update the canvas decorations in a particular update rect for the text cursor.
QCursor m_text_on_path
void showEditor()
friend class SvgChangeTextPathInfoStrategy
Definition SvgTextTool.h:40
friend class SvgCreateTextStrategy
Definition SvgTextTool.h:39
QScopedPointer< KisSignalMapper > m_typeSettingMovementMapper
void slotMoveTextSelection(int index)
slotMoveTextSelection Move the start of the selection in typesetting mode by image 1 pix.
void paint(QPainter &gc, const KoViewConverter &converter) override
reimplemented from KoToolBase
SvgTextCursor m_textCursor
KoSvgText::WritingMode writingMode() const
QScopedPointer< KoSvgTextShapeOutlineHelper > m_textOutlineHelper
QRectF decorationsRect() const override
reimplemented from KoToolBase
bool paste() override
reimplemented from superclass
void slotUpdateTypeSettingMode()
slotUpdateTypeSettingMode Enable typesetting mode from the tool options.
void slotConvertType(int index)
slotConvertType
void addMappedAction(KisSignalMapper *mapper, const QString &actionName, const int value, QActionGroup *group=nullptr)
QPointer< SvgTextEditor > m_editor
void keyReleaseEvent(QKeyEvent *event) override
The SvgTextTypeSettingStrategy class This class encompasses the typesetting mode.
#define KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(cond, val)
Definition kis_assert.h:129
#define KIS_ASSERT(cond)
Definition kis_assert.h:33
#define dbgTools
Definition kis_debug.h:52
T kisGrowRect(const T &rect, U offset)
Definition kis_global.h:186
QIcon loadIcon(const QString &name)
bool selectShapeCrossLayer(KoCanvasBase *canvas, const QPointF &point, const QString &shapeType, bool skipCurrentShapes)
selectShapeCrossLayer Tries to select a shape under the cursor regardless of which layer it is on,...
QString nodeEditableMessage(KisNodeSP node, bool blockedNoIndirectPainting)
nodeEditableMessage
QPainterPath shapeHoverInfoCrossLayer(KoCanvasBase *canvas, const QPointF &point, QString &shapeType, bool *isHorizontal, bool skipCurrentShapes)
shapeHoverInfoCrossLayer get hover info of shapes on all layers.
@ SvgTextPropertyData
KoSvgTextPropertyDataStruct.
@ HorizontalTB
Definition KoSvgText.h:38
const QString CssStyles
bool isEditable(bool checkVisibility=true) const
The KoSvgTextPropertyData struct.
KoSvgTextProperties commonProperties
The properties common between all the selected text.
BackgroundProperty is a special wrapper around KoShapeBackground for managing it in KoSvgTextProperti...
Definition KoSvgText.h:714
void setTypeSettingHandleHovered(TypeSettingModeHandle hovered=TypeSettingModeHandle::NoHandle)
Set a given typesetting handle as hovered, so it will be drawn as such.
void setVisualMode(const bool visualMode=true)
setVisualMode set whether the navigation mode is visual or logical. This right now primarily affects ...
void keyPressEvent(QKeyEvent *event)
Handle the cursor-related key events.
KoSvgTextPropertiesInterface * textPropertyInterface()
int getAnchor()
Get the current selection anchor. This is the same as position, unless there's a selection.
QPair< KoSvgTextProperties, KoSvgTextProperties > currentTextProperties() const
currentTextProperties
void deselectText()
Deselect all text. This effectively makes anchor the same as pos.
bool hasSelection() override
return true if the tool currently has something selected that can be copied or deleted.
void setCaretSetting(int cursorWidth=1, int cursorFlash=1000, int cursorFlashLimit=5000, bool drawCursorInAdditionToSelection=false)
setCaretSetting Set the caret settings for the cursor. Qt has some standard functionality associated,...
void setPos(int pos, int anchor)
Set the pos and the anchor.
TypeSettingModeHandle
Handles used by type setting mode.
void setPosToPoint(QPointF point, bool moveAnchor=true)
Set the pos from a point. This currently does a search inside the text shape.
QCursor cursorTypeForTypeSetting() const
Return appropriate typeSetting cursor;.
void moveCursor(MoveMode mode, bool moveAnchor=true)
Move the cursor, and, if you don't want a selection, move the anchor.
void setPasteRichTextByDefault(const bool pasteRichText=true)
setPasteRichText
QVariant inputMethodQuery(Qt::InputMethodQuery query) const
Process an input method query and return the requested result.
void removeSelection()
removeSelection if there's a selection, creates a text-removal command.
void setTypeSettingModeActive(bool activate)
Set type setting mode active.
bool setDominantBaselineFromHandle(const TypeSettingModeHandle handle)
setDominantBaselineFromHandle Set the dominant baseline from a given handle.
void paintDecorations(QPainter &gc, QColor selectionColor, int decorationThickness=1, qreal handleRadius=5.0, KisHandlePalette handlePalette=KisHandlePalette())
Paint all decorations and blinkingcursors.
int getPos()
Get the current position.
void focusOut()
Stops blinking cursor.
TypeSettingModeHandle typeSettingHandleAtPos(const QRectF regionOfInterest)
Get typeSettingMode handle for text;.
bool registerPropertyAction(QAction *action, const QString &name)
Register an action.
void focusIn()
Turns on blinking cursor.
void setDrawTypeSettingHandle(bool draw)
bool paste()
paste pastes plain text in the clipboard at pos. Uses pasteRichTextByDefault to determine whether to ...
void updateTypeSettingDecorFromShape()
Update the type setting decorations.
void updateModifiers(const Qt::KeyboardModifiers modifiers)
void setShape(KoSvgTextShape *textShape)
setShape
void insertRichText(KoSvgTextShape *insert, bool inheritPropertiesIfPossible=false)
Insert rich text at getPos();.
KoSvgTextShape * shape
void copy() const
copy copies plain text into the clipboard between anchor and pos.