File indexing completed on 2024-05-12 16:33:20
0001 /* This file is part of the KDE project 0002 * Copyright (C) 2007,2011 Jan Hambrecht <jaham@gmx.net> 0003 * Copyright (C) 2008 Rob Buis <buis@kde.org> 0004 * 0005 * This library is free software; you can redistribute it and/or 0006 * modify it under the terms of the GNU Library General Public 0007 * License as published by the Free Software Foundation; either 0008 * version 2 of the License, or (at your option) any later version. 0009 * 0010 * This library is distributed in the hope that it will be useful, 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0013 * Library General Public License for more details. 0014 * 0015 * You should have received a copy of the GNU Library General Public License 0016 * along with this library; see the file COPYING.LIB. If not, write to 0017 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0018 * Boston, MA 02110-1301, USA. 0019 */ 0020 0021 #ifndef ARTISTICTEXTTOOL_H 0022 #define ARTISTICTEXTTOOL_H 0023 0024 #include "ArtisticTextShape.h" 0025 #include "ArtisticTextToolSelection.h" 0026 0027 #include <KoToolBase.h> 0028 #include <QTimer> 0029 0030 class QAction; 0031 class QActionGroup; 0032 class KoInteractionStrategy; 0033 0034 /// This is the tool for the artistic text shape. 0035 class ArtisticTextTool : public KoToolBase 0036 { 0037 Q_OBJECT 0038 public: 0039 explicit ArtisticTextTool(KoCanvasBase *canvas); 0040 ~ArtisticTextTool() override; 0041 0042 /// reimplemented 0043 void paint( QPainter &painter, const KoViewConverter &converter ) override; 0044 /// reimplemented 0045 void repaintDecorations() override; 0046 /// reimplemented 0047 void mousePressEvent( KoPointerEvent *event ) override ; 0048 /// reimplemented 0049 void mouseMoveEvent( KoPointerEvent *event ) override; 0050 /// reimplemented 0051 void mouseReleaseEvent( KoPointerEvent *event ) override; 0052 /// reimplemented 0053 void shortcutOverrideEvent(QKeyEvent *event) override; 0054 /// reimplemented 0055 void mouseDoubleClickEvent(KoPointerEvent *event) override; 0056 /// reimplemented 0057 void activate(ToolActivation toolActivation, const QSet<KoShape*> &shapes) override; 0058 /// reimplemented 0059 void deactivate() override; 0060 /// reimplemented 0061 QList<QPointer<QWidget> > createOptionWidgets() override; 0062 /// reimplemented 0063 void keyPressEvent(QKeyEvent *event) override; 0064 /// reimplemented 0065 KoToolSelection *selection() override; 0066 0067 /// reimplemented from superclass 0068 QVariant inputMethodQuery(Qt::InputMethodQuery query, const KoViewConverter &converter) const override; 0069 0070 /// Sets cursor for specified text shape it is the current text shape 0071 void setTextCursor(ArtisticTextShape *textShape, int textCursor); 0072 0073 /// Returns the current text cursor position 0074 int textCursor() const; 0075 0076 /** 0077 * Determines cursor position from specified mouse position. 0078 * @param mousePosition mouse position in document coordinates 0079 * @return cursor position, -1 means invalid cursor 0080 */ 0081 int cursorFromMousePosition(const QPointF &mousePosition); 0082 0083 protected: 0084 void enableTextCursor( bool enable ); 0085 void removeFromTextCursor( int from, unsigned int count ); 0086 void addToTextCursor( const QString &str ); 0087 0088 private Q_SLOTS: 0089 void detachPath(); 0090 void convertText(); 0091 void blinkCursor(); 0092 void textChanged(); 0093 void shapeSelectionChanged(); 0094 void setStartOffset(int offset); 0095 void toggleFontBold(bool enabled); 0096 void toggleFontItalic(bool enabled); 0097 void anchorChanged(QAction*); 0098 void setFontFamily(const QFont &font); 0099 void setFontSize(int size); 0100 void setSuperScript(); 0101 void setSubScript(); 0102 void selectAll(); 0103 void deselectAll(); 0104 0105 Q_SIGNALS: 0106 void shapeSelected(); 0107 0108 private: 0109 void updateActions(); 0110 void setTextCursorInternal( int textCursor ); 0111 void createTextCursorShape(); 0112 void updateTextCursorArea() const; 0113 void setCurrentShape(ArtisticTextShape *currentShape); 0114 0115 enum FontProperty { 0116 BoldProperty, 0117 ItalicProperty, 0118 FamilyProperty, 0119 SizeProperty 0120 }; 0121 0122 /// Changes the specified font property for the current text selection 0123 void changeFontProperty(FontProperty property, const QVariant &value); 0124 0125 /// Toggle sub and super script 0126 void toggleSubSuperScript(ArtisticTextRange::BaselineShift mode); 0127 0128 /// returns the transformation matrix for the text cursor 0129 QTransform cursorTransform() const; 0130 0131 /// Returns the offset handle shape for the current text shape 0132 QPainterPath offsetHandleShape(); 0133 0134 ArtisticTextToolSelection m_selection; ///< the tools selection 0135 ArtisticTextShape * m_currentShape; ///< the current text shape we are working on 0136 ArtisticTextShape * m_hoverText; ///< the text shape the mouse cursor is hovering over 0137 KoPathShape * m_hoverPath; ///< the path shape the mouse cursor is hovering over 0138 QPainterPath m_textCursorShape; ///< our visual text cursor representation 0139 bool m_hoverHandle; 0140 0141 QAction * m_detachPath; 0142 QAction * m_convertText; 0143 QAction * m_fontBold; 0144 QAction * m_fontItalic; 0145 QAction * m_superScript; 0146 QAction * m_subScript; 0147 QActionGroup * m_anchorGroup; 0148 0149 int m_textCursor; 0150 QTimer m_blinkingCursor; 0151 bool m_showCursor; 0152 QVector<QPointF> m_linefeedPositions; ///< offset positions for temporary line feeds 0153 KoInteractionStrategy *m_currentStrategy; 0154 }; 0155 0156 #endif // ARTISTICTEXTTOOL_H