File indexing completed on 2024-05-26 04:34:35
0001 /* This file is part of the KDE project 0002 * 0003 SPDX-FileCopyrightText: 2017 Boudewijn Rempt <boud@valdyas.org> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #ifndef SVG_TEXT_TOOL 0009 #define SVG_TEXT_TOOL 0010 0011 #include "ui_WdgSvgTextOptionWidget.h" 0012 0013 #include <KConfigGroup> 0014 #include <KoToolBase.h> 0015 #include <QPushButton> 0016 #include <QFontComboBox> 0017 #include <QPointer> 0018 #include <QDoubleSpinBox> 0019 #include <QTimer> 0020 0021 #include <kis_signal_auto_connection.h> 0022 0023 #include "SvgTextCursor.h" 0024 0025 #include <memory> 0026 0027 class KoSelection; 0028 class SvgTextEditor; 0029 class KoSvgTextShape; 0030 class SvgTextCursor; 0031 class KoInteractionStrategy; 0032 class KUndo2Command; 0033 0034 class SvgTextTool : public KoToolBase 0035 { 0036 Q_OBJECT 0037 0038 friend class SvgCreateTextStrategy; 0039 0040 public: 0041 explicit SvgTextTool(KoCanvasBase *canvas); 0042 ~SvgTextTool() override; 0043 /// reimplemented from KoToolBase 0044 QRectF decorationsRect() const override; 0045 /// reimplemented from KoToolBase 0046 void paint(QPainter &gc, const KoViewConverter &converter) override; 0047 /// reimplemented from KoToolBase 0048 void mousePressEvent(KoPointerEvent *event) override; 0049 /// reimplemented from superclass 0050 void mouseDoubleClickEvent(KoPointerEvent *event) override; 0051 /// reimplemented from KoToolBase 0052 void mouseTripleClickEvent(KoPointerEvent *event) override; 0053 /// reimplemented from KoToolBase 0054 void mouseMoveEvent(KoPointerEvent *event) override; 0055 /// reimplemented from KoToolBase 0056 void mouseReleaseEvent(KoPointerEvent *event) override; 0057 0058 void keyPressEvent(QKeyEvent *event) override; 0059 void keyReleaseEvent(QKeyEvent *event) override; 0060 0061 void focusInEvent(QFocusEvent *event) override; 0062 void focusOutEvent(QFocusEvent *event) override; 0063 0064 /// reimplemented from KoToolBase 0065 void activate(const QSet<KoShape *> &shapes) override; 0066 /// reimplemented from KoToolBase 0067 void deactivate() override; 0068 0069 KisPopupWidgetInterface* popupWidget() override; 0070 0071 QVariant inputMethodQuery(Qt::InputMethodQuery query) const override; 0072 void inputMethodEvent(QInputMethodEvent *event) override; 0073 0074 /// reimplemented from superclass 0075 void copy() const override; 0076 /// reimplemented from superclass 0077 void deleteSelection() override; 0078 /// reimplemented from superclass 0079 bool paste() override; 0080 /// reimplemented from superclass 0081 bool hasSelection() override; 0082 0083 bool selectAll() override; 0084 0085 void deselect() override; 0086 /// reimplemented from superclass 0087 KoToolSelection * selection() override; 0088 0089 void requestStrokeEnd() override; 0090 void requestStrokeCancellation() override; 0091 0092 protected: 0093 /// reimplemented from KoToolBase 0094 virtual QWidget *createOptionWidget() override; 0095 0096 KoSelection *koSelection() const; 0097 KoSvgTextShape *selectedShape() const; 0098 0099 private: 0100 qreal grabSensitivityInPt() const; 0101 0102 QFont defaultFont() const; 0103 Qt::Alignment horizontalAlign() const; 0104 int writingMode() const; 0105 bool isRtl() const; 0106 0107 private Q_SLOTS: 0108 0109 void showEditor(); 0110 void showEditorSvgSource(); 0111 void slotTextEditorClosed(); 0112 void textUpdated(KoSvgTextShape *shape, const QString &svg, const QString &defs); 0113 0114 /** 0115 * @brief generateDefs 0116 * This generates a defs section with the appropriate 0117 * css and css strings assigned. This allows the artist 0118 * to select settings that new texts will be created with. 0119 * @return a string containing the defs. 0120 */ 0121 QString generateDefs(const QString &extraProperties = QString()); 0122 0123 /** 0124 * @brief storeDefaults 0125 * store default font and point size when they change. 0126 */ 0127 void storeDefaults(); 0128 0129 /** 0130 * @brief selectionChanged 0131 * called when the canvas selection is changed. 0132 */ 0133 void slotShapeSelectionChanged(); 0134 0135 /** 0136 * @brief updateCursor 0137 * update the canvas decorations in a particular update rect for the text cursor. 0138 * @param updateRect the rect to update in. 0139 */ 0140 void slotUpdateCursorDecoration(QRectF updateRect); 0141 0142 0143 private: 0144 enum class DragMode { 0145 None = 0, 0146 Create, 0147 Select, 0148 InlineSizeHandle, 0149 Move, 0150 }; 0151 enum class HighlightItem { 0152 None = 0, 0153 InlineSizeStartHandle, 0154 InlineSizeEndHandle, 0155 MoveBorder, 0156 }; 0157 0158 QPointer<SvgTextEditor> m_editor; 0159 QPointF m_lastMousePos; 0160 DragMode m_dragging {DragMode::None}; 0161 std::unique_ptr<KoInteractionStrategy> m_interactionStrategy; 0162 HighlightItem m_highlightItem {HighlightItem::None}; 0163 bool m_strategyAddingCommand {false}; 0164 0165 QButtonGroup *m_defAlignment {nullptr}; 0166 QButtonGroup *m_defWritingMode {nullptr}; 0167 QButtonGroup *m_defDirection {nullptr}; 0168 KConfigGroup m_configGroup; 0169 SvgTextCursor m_textCursor; 0170 KisSignalAutoConnectionsStore m_canvasConnections; 0171 0172 0173 QPainterPath m_hoveredShapeHighlightRect; 0174 0175 Ui_WdgSvgTextOptionWidget optionUi; 0176 0177 QCursor m_base_cursor; 0178 QCursor m_text_inline_horizontal; 0179 QCursor m_text_inline_vertical; 0180 QCursor m_text_on_path; 0181 QCursor m_text_in_shape; 0182 QCursor m_ibeam_vertical; 0183 QCursor m_ibeam_horizontal; 0184 QCursor m_ibeam_horizontal_done; 0185 0186 }; 0187 0188 #endif