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 MESSAGEEDITOR_H |
5 | #define MESSAGEEDITOR_H |
6 | |
7 | #include "messagemodel.h" |
8 | |
9 | #include <QtCore/QLocale> |
10 | #include <QtCore/QTimer> |
11 | |
12 | #include <QtWidgets/QFrame> |
13 | #include <QtWidgets/QScrollArea> |
14 | |
15 | QT_BEGIN_NAMESPACE |
16 | |
17 | class QBoxLayout; |
18 | class QMainWindow; |
19 | class QTextEdit; |
20 | |
21 | class MessageEditor; |
22 | class FormatTextEdit; |
23 | class FormWidget; |
24 | class FormMultiWidget; |
25 | |
26 | struct MessageEditorData { |
27 | QWidget *container; |
28 | FormWidget *; |
29 | QList<FormMultiWidget *> transTexts; |
30 | QString invariantForm; |
31 | QString firstForm; |
32 | qreal fontSize; |
33 | bool pluralEditMode; |
34 | }; |
35 | |
36 | class MessageEditor : public QScrollArea |
37 | { |
38 | Q_OBJECT |
39 | |
40 | public: |
41 | MessageEditor(MultiDataModel *dataModel, QMainWindow *parent = 0); |
42 | ~MessageEditor(); |
43 | |
44 | void showNothing(); |
45 | void showMessage(const MultiDataIndex &index); |
46 | void setNumerusForms(int model, const QStringList &numerusForms); |
47 | bool eventFilter(QObject *, QEvent *) override; |
48 | void setNumerusTranslation(int model, const QString &translation, int numerus); |
49 | int activeModel() const { return (m_editors.size() != 1) ? m_currentModel : 0; } |
50 | void setEditorFocusForModel(int model); |
51 | void setUnfinishedEditorFocus(); |
52 | bool focusNextUnfinished(); |
53 | void setVisualizeWhitespace(bool value); |
54 | void setFontSize(const float fontSize); |
55 | float fontSize(); |
56 | |
57 | signals: |
58 | void translationChanged(const QStringList &translations); |
59 | void (const QString &); |
60 | void activeModelChanged(int model); |
61 | |
62 | void undoAvailable(bool avail); |
63 | void redoAvailable(bool avail); |
64 | #ifndef QT_NO_CLIPBOARD |
65 | void cutAvailable(bool avail); |
66 | void copyAvailable(bool avail); |
67 | void pasteAvailable(bool avail); |
68 | #endif |
69 | void beginFromSourceAvailable(bool enable); |
70 | |
71 | public slots: |
72 | void undo(); |
73 | void redo(); |
74 | #ifndef QT_NO_CLIPBOARD |
75 | void cut(); |
76 | void copy(); |
77 | void paste(); |
78 | #endif |
79 | void selectAll(); |
80 | void beginFromSource(); |
81 | void setEditorFocus(); |
82 | void setTranslation(int latestModel, const QString &translation); |
83 | void setLengthVariants(bool on); |
84 | void increaseFontSize(); |
85 | void decreaseFontSize(); |
86 | void resetFontSize(); |
87 | |
88 | private slots: |
89 | void editorCreated(QTextEdit *); |
90 | void editorDestroyed(); |
91 | void selectionChanged(QTextEdit *); |
92 | void resetHoverSelection(); |
93 | void emitTranslationChanged(QTextEdit *); |
94 | void (QTextEdit *); |
95 | #ifndef QT_NO_CLIPBOARD |
96 | void updateCanPaste(); |
97 | void clipboardChanged(); |
98 | #endif |
99 | void messageModelAppended(); |
100 | void messageModelDeleted(int model); |
101 | void allModelsDeleted(); |
102 | void setTargetLanguage(int model); |
103 | void reallyFixTabOrder(); |
104 | |
105 | private: |
106 | void setupEditorPage(); |
107 | void setEditingEnabled(int model, bool enabled); |
108 | bool focusNextUnfinished(int start); |
109 | void resetSelection(); |
110 | void grabFocus(QWidget *widget); |
111 | void trackFocus(QWidget *widget); |
112 | void activeModelAndNumerus(int *model, int *numerus) const; |
113 | QTextEdit *activeTranslation() const; |
114 | QTextEdit *activeOr1stTranslation() const; |
115 | QTextEdit *() const; |
116 | QTextEdit *activeEditor() const; |
117 | QTextEdit *activeOr1stEditor() const; |
118 | MessageEditorData *modelForWidget(const QObject *o); |
119 | int activeTranslationNumerus() const; |
120 | QStringList translations(int model) const; |
121 | void updateBeginFromSource(); |
122 | void updateUndoRedo(); |
123 | #ifndef QT_NO_CLIPBOARD |
124 | void updateCanCutCopy(); |
125 | #endif |
126 | void addPluralForm(int model, const QString &label, bool writable); |
127 | void fixTabOrder(); |
128 | QPalette paletteForModel(int model) const; |
129 | void applyFontSize(); |
130 | |
131 | MultiDataModel *m_dataModel; |
132 | |
133 | MultiDataIndex m_currentIndex; |
134 | int m_currentModel; |
135 | int m_currentNumerus; |
136 | |
137 | bool m_lengthVariants; |
138 | float m_fontSize; |
139 | |
140 | bool m_undoAvail; |
141 | bool m_redoAvail; |
142 | bool m_cutAvail; |
143 | bool m_copyAvail; |
144 | |
145 | bool m_clipboardEmpty; |
146 | bool m_visualizeWhitespace; |
147 | |
148 | QTextEdit *m_selectionHolder; |
149 | QWidget *m_focusWidget; |
150 | QBoxLayout *m_layout; |
151 | FormWidget *m_source; |
152 | FormWidget *m_pluralSource; |
153 | FormWidget *; |
154 | QList<MessageEditorData> m_editors; |
155 | |
156 | QTimer m_tabOrderTimer; |
157 | }; |
158 | |
159 | QT_END_NAMESPACE |
160 | |
161 | #endif // MESSAGEEDITOR_H |
162 | |