1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the Qt Linguist of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT |
21 | ** included in the packaging of this file. Please review the following |
22 | ** information to ensure the GNU General Public License requirements will |
23 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
24 | ** |
25 | ** $QT_END_LICENSE$ |
26 | ** |
27 | ****************************************************************************/ |
28 | |
29 | #ifndef MESSAGEEDITORWIDGETS_H |
30 | #define MESSAGEEDITORWIDGETS_H |
31 | |
32 | #include <QIcon> |
33 | #include <QImage> |
34 | #include <QLabel> |
35 | #include <QMap> |
36 | #include <QTextEdit> |
37 | #include <QUrl> |
38 | #include <QWidget> |
39 | |
40 | QT_BEGIN_NAMESPACE |
41 | |
42 | class QAbstractButton; |
43 | class QAction; |
44 | class ; |
45 | class QKeyEvent; |
46 | class ; |
47 | class QSizeF; |
48 | class QString; |
49 | class QVariant; |
50 | |
51 | class MessageHighlighter; |
52 | |
53 | /* |
54 | Automatically adapt height to document contents |
55 | */ |
56 | class ExpandingTextEdit : public QTextEdit |
57 | { |
58 | Q_OBJECT |
59 | |
60 | public: |
61 | ExpandingTextEdit(QWidget *parent = 0); |
62 | QSize sizeHint() const; |
63 | QSize minimumSizeHint() const; |
64 | |
65 | private slots: |
66 | void updateHeight(const QSizeF &documentSize); |
67 | void reallyEnsureCursorVisible(); |
68 | |
69 | private: |
70 | int m_minimumHeight; |
71 | }; |
72 | |
73 | /* |
74 | Format markup & control characters |
75 | */ |
76 | class FormatTextEdit : public ExpandingTextEdit |
77 | { |
78 | Q_OBJECT |
79 | public: |
80 | FormatTextEdit(QWidget *parent = 0); |
81 | ~FormatTextEdit(); |
82 | void setEditable(bool editable); |
83 | |
84 | signals: |
85 | void editorDestroyed(); |
86 | |
87 | public slots: |
88 | void setPlainText(const QString & text, bool userAction); |
89 | void setVisualizeWhitespace(bool value); |
90 | |
91 | private: |
92 | MessageHighlighter *m_highlighter; |
93 | }; |
94 | |
95 | /* |
96 | Displays text field & associated label |
97 | */ |
98 | class FormWidget : public QWidget |
99 | { |
100 | Q_OBJECT |
101 | public: |
102 | FormWidget(const QString &label, bool isEditable, QWidget *parent = 0); |
103 | void setLabel(const QString &label) { m_label->setText(label); } |
104 | void setTranslation(const QString &text, bool userAction = false); |
105 | void clearTranslation() { setTranslation(text: QString(), userAction: false); } |
106 | QString getTranslation() { return m_editor->toPlainText(); } |
107 | void setEditingEnabled(bool enable); |
108 | void setHideWhenEmpty(bool optional) { m_hideWhenEmpty = optional; } |
109 | FormatTextEdit *getEditor() { return m_editor; } |
110 | |
111 | signals: |
112 | void textChanged(QTextEdit *); |
113 | void selectionChanged(QTextEdit *); |
114 | void cursorPositionChanged(); |
115 | |
116 | private slots: |
117 | void slotSelectionChanged(); |
118 | void slotTextChanged(); |
119 | |
120 | private: |
121 | QLabel *m_label; |
122 | FormatTextEdit *m_editor; |
123 | bool m_hideWhenEmpty; |
124 | }; |
125 | |
126 | /* |
127 | Displays text fields & associated label |
128 | */ |
129 | class FormMultiWidget : public QWidget |
130 | { |
131 | Q_OBJECT |
132 | public: |
133 | FormMultiWidget(const QString &label, QWidget *parent = 0); |
134 | void setLabel(const QString &label) { m_label->setText(label); } |
135 | void setTranslation(const QString &text, bool userAction = false); |
136 | void clearTranslation() { setTranslation(text: QString(), userAction: false); } |
137 | QString getTranslation() const; |
138 | void setEditingEnabled(bool enable); |
139 | void setMultiEnabled(bool enable); |
140 | void setHideWhenEmpty(bool optional) { m_hideWhenEmpty = optional; } |
141 | const QList<FormatTextEdit *> &getEditors() const { return m_editors; } |
142 | |
143 | signals: |
144 | void editorCreated(QTextEdit *); |
145 | void textChanged(QTextEdit *); |
146 | void selectionChanged(QTextEdit *); |
147 | void cursorPositionChanged(); |
148 | |
149 | protected: |
150 | bool eventFilter(QObject *watched, QEvent *event); |
151 | |
152 | private slots: |
153 | void slotTextChanged(); |
154 | void slotSelectionChanged(); |
155 | void minusButtonClicked(); |
156 | void plusButtonClicked(); |
157 | |
158 | private: |
159 | void addEditor(int idx); |
160 | void updateLayout(); |
161 | QAbstractButton *makeButton(const QIcon &icon, const char *slot); |
162 | void insertEditor(int idx); |
163 | void deleteEditor(int idx); |
164 | |
165 | QLabel *m_label; |
166 | QList<FormatTextEdit *> m_editors; |
167 | QList<QWidget *> m_plusButtons; |
168 | QList<QAbstractButton *> m_minusButtons; |
169 | bool m_hideWhenEmpty; |
170 | bool m_multiEnabled; |
171 | QIcon m_plusIcon, m_minusIcon; |
172 | }; |
173 | |
174 | QT_END_NAMESPACE |
175 | |
176 | #endif // MESSAGEEDITORWIDGETS_H |
177 | |