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

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