1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3
4#ifndef MESSAGEEDITORWIDGETS_H
5#define MESSAGEEDITORWIDGETS_H
6
7#include <QAbstractButton>
8#include <QIcon>
9#include <QImage>
10#include <QLabel>
11#include <QMap>
12#include <QTextEdit>
13#include <QUrl>
14#include <QWidget>
15
16QT_BEGIN_NAMESPACE
17
18class QAction;
19class QContextMenuEvent;
20class QKeyEvent;
21class QMenu;
22class QSizeF;
23class QString;
24class QVariant;
25
26class MessageHighlighter;
27
28/*
29 Automatically adapt height to document contents
30 */
31class ExpandingTextEdit : public QTextEdit
32{
33 Q_OBJECT
34
35public:
36 ExpandingTextEdit(QWidget *parent = 0);
37 QSize sizeHint() const override;
38 QSize minimumSizeHint() const override;
39
40private slots:
41 void updateHeight(const QSizeF &documentSize);
42 void reallyEnsureCursorVisible();
43
44private:
45 int m_minimumHeight;
46};
47
48/*
49 Format markup & control characters
50*/
51class FormatTextEdit : public ExpandingTextEdit
52{
53 Q_OBJECT
54public:
55 FormatTextEdit(QWidget *parent = 0);
56 ~FormatTextEdit();
57 void setEditable(bool editable);
58
59signals:
60 void editorDestroyed();
61
62public slots:
63 void setPlainText(const QString & text, bool userAction);
64 void setVisualizeWhitespace(bool value);
65
66private:
67 MessageHighlighter *m_highlighter;
68};
69
70/*
71 Displays text field & associated label
72*/
73class FormWidget : public QWidget
74{
75 Q_OBJECT
76public:
77 FormWidget(const QString &label, bool isEditable, QWidget *parent = 0);
78 void setLabel(const QString &label) { m_label->setText(label); }
79 void setTranslation(const QString &text, bool userAction = false);
80 void clearTranslation() { setTranslation(text: QString(), userAction: false); }
81 QString getTranslation() { return m_editor->toPlainText(); }
82 void setEditingEnabled(bool enable);
83 void setHideWhenEmpty(bool optional) { m_hideWhenEmpty = optional; }
84 FormatTextEdit *getEditor() { return m_editor; }
85
86signals:
87 void textChanged(QTextEdit *);
88 void selectionChanged(QTextEdit *);
89 void cursorPositionChanged();
90
91private slots:
92 void slotSelectionChanged();
93 void slotTextChanged();
94
95private:
96 QLabel *m_label;
97 FormatTextEdit *m_editor;
98 bool m_hideWhenEmpty;
99};
100
101/*
102 Displays text fields & associated label
103*/
104class FormMultiWidget : public QWidget
105{
106 Q_OBJECT
107public:
108 FormMultiWidget(const QString &label, QWidget *parent = 0);
109 void setLabel(const QString &label) { m_label->setText(label); }
110 void setTranslation(const QString &text, bool userAction = false);
111 void clearTranslation() { setTranslation(text: QString(), userAction: false); }
112 QString getTranslation() const;
113 void setEditingEnabled(bool enable);
114 void setMultiEnabled(bool enable);
115 void setHideWhenEmpty(bool optional) { m_hideWhenEmpty = optional; }
116 const QList<FormatTextEdit *> &getEditors() const { return m_editors; }
117
118signals:
119 void editorCreated(QTextEdit *);
120 void textChanged(QTextEdit *);
121 void selectionChanged(QTextEdit *);
122 void cursorPositionChanged();
123
124protected:
125 bool eventFilter(QObject *watched, QEvent *event) override;
126
127private slots:
128 void slotTextChanged();
129 void slotSelectionChanged();
130 void minusButtonClicked();
131 void plusButtonClicked();
132
133private:
134 void addEditor(int idx);
135 void updateLayout();
136
137 template<typename Func>
138 QAbstractButton *makeButton(const QIcon &icon, Func slot)
139 {
140 auto *button = makeButton(icon);
141 connect(button, &QAbstractButton::clicked,
142 this, slot);
143 return button;
144 }
145 QAbstractButton *makeButton(const QIcon &icon);
146 void insertEditor(int idx);
147 void deleteEditor(int idx);
148
149 QLabel *m_label;
150 QList<FormatTextEdit *> m_editors;
151 QList<QWidget *> m_plusButtons;
152 QList<QAbstractButton *> m_minusButtons;
153 bool m_hideWhenEmpty;
154 bool m_multiEnabled;
155 QIcon m_plusIcon, m_minusIcon;
156};
157
158QT_END_NAMESPACE
159
160#endif // MESSAGEEDITORWIDGETS_H
161

source code of qttools/src/linguist/linguist/messageeditorwidgets.h