1 /**************************************************************************** 2 ** 3 ** Copyright (C) 2020 The Qt Company Ltd. 4 ** Contact: https://www.qt.io/licensing/ 5 ** 6 ** This file is part of Qt Creator. 7 ** 8 ** Commercial License Usage 9 ** Licensees holding valid commercial Qt licenses may use this file in 10 ** accordance with the commercial license agreement provided with the 11 ** Software or, alternatively, in accordance with the terms contained in 12 ** a written agreement between you and The Qt Company. For licensing terms 13 ** and conditions see https://www.qt.io/terms-conditions. For further 14 ** information use the contact form at https://www.qt.io/contact-us. 15 ** 16 ** GNU General Public License Usage 17 ** Alternatively, this file may be used under the terms of the GNU 18 ** General Public License version 3 as published by the Free Software 19 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 ** included in the packaging of this file. Please review the following 21 ** information to ensure the GNU General Public License requirements will 22 ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 ** 24 ****************************************************************************/ 25 26 #pragma once 27 28 #include <theme.h> 29 30 #include <QWidget> 31 #include <QToolBar> 32 #include <QList> 33 #include <QTextCharFormat> 34 #include <QTextList> 35 #include <QFontComboBox> 36 #include <QWidgetAction> 37 #include <QPointer> 38 39 namespace QmlDesigner { 40 41 namespace Ui { 42 class RichTextEditor; 43 } 44 45 template <class> 46 class FontWidgetActions; 47 48 class HyperlinkDialog; 49 50 class RichTextEditor : public QWidget 51 { 52 Q_OBJECT 53 54 public: 55 explicit RichTextEditor(QWidget *parent = nullptr); 56 ~RichTextEditor(); 57 58 void setPlainText(const QString &text); 59 QString plainText() const; 60 61 void setRichText(const QString &text); 62 QString richText() const; 63 64 void setTabChangesFocus(bool change); 65 66 void setImageActionVisible(bool change); 67 68 void setDocumentBaseUrl(const QUrl &url); 69 70 signals: 71 void insertingImage(QString &filePath); 72 void textChanged(QString text); 73 74 private slots: 75 void currentCharFormatChanged(const QTextCharFormat &format); 76 void cursorPositionChanged(); 77 void onTextChanged(); 78 private: 79 QIcon getIcon(Theme::Icon icon); 80 void mergeFormatOnWordOrSelection(const QTextCharFormat &format); 81 82 void fontChanged(const QFont &f); 83 void colorChanged(const QColor &c); 84 void alignmentChanged(Qt::Alignment a); 85 void styleChanged(const QTextCursor &cursor); 86 void tableChanged(const QTextCursor &cursor); 87 88 void setupEditActions(); 89 void setupTextActions(); 90 void setupImageActions(); 91 void setupHyperlinkActions(); 92 void setupAlignActions(); 93 void setupListActions(); 94 void setupFontActions(); 95 void setupTableActions(); 96 97 void textStyle(QTextListFormat::Style style); 98 99 void setTableActionsActive(bool active); //switches between "has table/has no table" ui setup 100 101 private: 102 QScopedPointer<Ui::RichTextEditor> ui; 103 QPointer<HyperlinkDialog> m_linkDialog; 104 105 QAction *m_actionTextBold; 106 QAction *m_actionTextItalic; 107 QAction *m_actionTextUnderline; 108 109 QAction *m_actionImage; 110 QAction *m_actionHyperlink; 111 112 QAction *m_actionAlignLeft; 113 QAction *m_actionAlignCenter; 114 QAction *m_actionAlignRight; 115 QAction *m_actionAlignJustify; 116 117 QAction *m_actionTextColor; 118 119 QAction *m_actionBulletList; 120 QAction *m_actionNumberedList; 121 122 QAction *m_actionTableSettings; 123 124 QAction *m_actionCreateTable; 125 QAction *m_actionRemoveTable; 126 127 QAction *m_actionAddRow; 128 QAction *m_actionAddColumn; 129 QAction *m_actionRemoveRow; 130 QAction *m_actionRemoveColumn; 131 132 QAction *m_actionMergeCells; 133 QAction *m_actionSplitRow; 134 QAction *m_actionSplitColumn; 135 136 QPointer<FontWidgetActions<QFontComboBox>> m_fontNameAction; 137 QPointer<FontWidgetActions<QComboBox>> m_fontSizeAction; 138 }; 139 140 } //namespace QmlDesigner 141