Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
mainwindow.h
Go to the documentation of this file.
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 MAINWINDOW_H
5#define MAINWINDOW_H
6
7#include "phrase.h"
8#include "ui_mainwindow.h"
9#include "recentfiles.h"
10#include "messagemodel.h"
11#include "finddialog.h"
12
13#include <QtCore/private/qconfig_p.h>
14
15#include <QtCore/QHash>
16#include <QtCore/QMap>
17#include <QtCore/QLocale>
18
19#include <QtWidgets/QMainWindow>
20
22
23class QPixmap;
24class QAction;
25class QDialog;
26class QFrame;
27class QLabel;
28class QMenu;
29class QPrinter;
30class QIcon;
31class QSortFilterProxyModel;
32class QStackedWidget;
33class QTableView;
34class QTreeView;
35
37class ErrorsView;
38class FocusWatcher;
39class HelpClient;
41#ifndef Q_OS_WASM
43#endif // Q_OS_WASM
44class MessageEditor;
45class PhraseView;
46class SourceCodeView;
47class Statistics;
48class TranslateDialog;
52
53enum class HelpClientType : quint8;
54
55class MainWindow : public QMainWindow
56{
58public:
61
62 explicit MainWindow(HelpClientType helpClientType);
64
65 bool openFiles(const QStringList &names);
66
67 static QString description();
68
69protected:
70 void readConfig();
71 void writeConfig();
72 void closeEvent(QCloseEvent *) override;
73 bool eventFilter(QObject *object, QEvent *event) override;
74
75private slots:
76 void done();
77 void doneAndNext();
78 void prev();
79 void next();
80 void recentFileActivated(QAction *action);
81 void setupRecentFilesMenu();
82 void open();
83 void openAux();
84 void saveAll();
85 void save();
86 void saveAs();
87 void releaseAll();
88 void release();
89 void releaseAs();
90 void closeFile();
91 bool closeAll();
92 void showTranslateDialog();
93 void showBatchTranslateDialog();
94 void showTranslationSettings();
95 void updateTranslateHit(bool &hit);
96 void translate(int mode);
97 void newPhraseBook();
98 void openPhraseBook();
99 void closePhraseBook(QAction *action);
100 void editPhraseBook(QAction *action);
101 void addToPhraseBook();
102 void manual();
103 void resetSorting();
104 void about();
105 void aboutQt();
106
107 void fileAboutToShow();
108 void editAboutToShow();
109
110 void showContextDock();
111 void showMessagesDock();
112 void showPhrasesDock();
113 void showSourceCodeDock();
114 void showErrorDock();
115
116 void setupPhrase();
117 bool maybeSaveAll();
118 bool maybeSave(int model);
119 void updateProgress();
120 void maybeUpdateStatistics(const MultiDataIndex &);
121 void translationChanged(const MultiDataIndex &);
122 void updateCaption();
123 void updateLatestModel(const QModelIndex &index);
124 void selectedContextChanged(const QModelIndex &sortedIndex, const QModelIndex &oldIndex);
125 void selectedLabelChanged(const QModelIndex &sortedIndex, const QModelIndex &oldIndex);
126 void selectedMessageChanged(const QModelIndex &sortedIndex, const QModelIndex &oldIndex);
127 void setCurrentMessageFromGuess(int modelIndex, const Candidate &tm);
128 void contextAndLabelTabChanged();
129
130 // To synchronize from the message editor to the model ...
131 void updateTranslation(const QStringList &translations);
132 void updateTranslatorComment(const QString &comment);
133
134 void updateVisibleColumns();
135 void updateActiveModel(int);
136 void refreshItemViews();
137 void toggleFinished(const QModelIndex &index);
138 void openMachineTranslateDialog();
139 void prevUnfinished();
140 void nextUnfinished();
141 void findNext(const QString &text, DataModel::FindLocation where,
142 FindDialog::FindOptions options, int statusFilter);
143 void revalidate();
144 void showStatistics();
145#ifndef Q_OS_WASM
146 void toggleQmlPreview();
147#endif // Q_OS_WASM
148 void toggleFormPreview();
149 void enablePreviewFromBanner();
150 void toggleVisualizeWhitespace();
151 void onWhatsThis();
152 void updatePhraseDicts();
153 void updatePhraseDict(int model);
154
155#if QT_CONFIG(printsupport)
156 void print();
158#endif
159
160private:
161
162 friend class SortedGroupsModel;
163 QModelIndex nextGroup(const QModelIndex &index) const;
164 QModelIndex prevGroup(const QModelIndex &index) const;
165 QModelIndex firstMessage() const;
166 QModelIndex nextMessage(const QModelIndex &currentIndex, bool checkUnfinished = false) const;
167 QModelIndex prevMessage(const QModelIndex &currentIndex, bool checkUnfinished = false) const;
168 bool doNext(bool checkUnfinished);
169 bool doPrev(bool checkUnfinished);
170 void findAgain(FindDirection direction = FindNext);
171
172 void updateStatistics();
173 void initViewHeaders();
174 void modelCountChanged();
175 void setupMenuBar();
176 void setupToolBars();
177 void setCurrentMessage(const QModelIndex &index);
178 void setCurrentMessage(const QModelIndex &index, int model);
179 QModelIndex setMessageViewRoot(const QModelIndex &index);
180 QModelIndex currentMessageIndex() const;
181 PhraseBook *doOpenPhraseBook(const QString &name);
182 bool isPhraseBookOpen(const QString &name);
183 bool savePhraseBook(QString *name, PhraseBook &pb);
184 bool maybeSavePhraseBook(PhraseBook *phraseBook);
185 bool maybeSavePhraseBooks();
186 void pickTranslationFiles();
187 void doShowTranslationSettings(int model);
188 void doUpdateLatestModel(int model);
189 void updateSourceView(int model, MessageItem *item);
190 void updatePreviewBanner(const QString &fileName);
191 void refreshFormPreview();
192 bool askPreviewActivation(bool isQml);
193 QString previewFilePath(int model, const QString &fileName) const;
194 bool hasUiFormPreview(int model, const QString &fileName) const;
195#ifndef Q_OS_WASM
196 bool hasQmlFormPreview(int model, const QString &fileName) const;
197#endif // Q_OS_WASM
198 void updatePhraseBookActions();
199 void updatePhraseDictInternal(int model);
200 void releaseInternal(int model);
201 void saveInternal(int model);
202
203#if QT_CONFIG(printsupport)
204 QPrinter *printer();
205#endif
206
207 // FIXME: move to DataModel
208 void updateDanger(const MultiDataIndex &index, bool verbose);
209 void updateIcons();
210 bool searchItem(DataModel::FindLocation where, const QString &searchWhat);
211
212 std::unique_ptr<HelpClient> m_helpClient;
213
214 QTreeView *m_contextView;
215 QTreeView *m_labelView;
216 QTreeView *m_messageView;
217 MultiDataModel *m_dataModel;
218 MessageModel *m_idBasedMessageModel;
219 MessageModel *m_textBasedMessageModel;
220 MessageModel *m_activeMessageModel;
221 QSortFilterProxyModel *m_sortedContextsModel;
222 QSortFilterProxyModel *m_sortedLabelsModel;
223 QSortFilterProxyModel *m_activeSortedGroupsModel;
224 QSortFilterProxyModel *m_sortedIdBasedMessagesModel;
225 QSortFilterProxyModel *m_sortedTextBasedMessagesModel;
226 QSortFilterProxyModel *m_activeSortedMessagesModel;
227 MessageEditor *m_messageEditor;
228 PhraseView *m_phraseView;
229 QStackedWidget *m_sourceAndFormView;
230 QTabWidget *m_contextAndLabelView;
231 SourceCodeView *m_sourceCodeView;
232 QWidget *m_sourceCodeContainer;
233 QFrame *m_previewBanner;
234 QLabel *m_previewBannerLabel;
235 // Files the user allowed to preview once, without turning on the action.
236 QString m_uiPreviewOnceFile;
237 QString m_qmlPreviewOnceFile;
238 UiFormPreviewView *m_uiFormPreviewView;
239#ifndef Q_OS_WASM
240 QmlFormPreviewView *m_qmlFormPreviewView;
241#endif // Q_OS_WASM
242 ErrorsView *m_errorsView;
243 QLabel *m_progressLabel;
244 QLabel *m_modifiedLabel;
245 FocusWatcher *m_focusWatcher;
246 QString m_phraseBookDir;
247 // model : keyword -> list of appropriate phrases in the phrasebooks
249 QList<PhraseBook *> m_phraseBooks;
250 QMap<QAction *, PhraseBook *> m_phraseBookMenu[3];
251#if QT_CONFIG(printsupport)
252 QPrinter *m_printer = nullptr;
253#endif
254
255 FindDialog *m_findDialog;
256 QString m_findText;
257 FindDialog::FindOptions m_findOptions;
258 int m_findStatusFilter = -1;
259 DataModel::FindLocation m_findWhere;
260
261 TranslateDialog *m_translateDialog;
262 QString m_latestFindText;
263 int m_latestCaseSensitivity;
264 QModelIndex m_searchIndex;
265 int m_hitCount;
266
267 BatchTranslationDialog *m_batchTranslateDialog;
268 TranslationSettingsDialog *m_translationSettingsDialog;
269
270 bool m_settingCurrentMessage;
271 std::optional<TranslationType> m_activeTranslationType;
272 int m_fileActiveModel;
273 int m_editActiveModel;
274 MultiDataIndex m_currentIndex;
275 QDockWidget *m_contextAndLabelDock;
276 QDockWidget *m_messagesDock;
277 QDockWidget *m_phrasesDock;
278 QDockWidget *m_sourceAndFormDock;
279 QDockWidget *m_errorsDock;
280
281 Ui::MainWindow m_ui; // menus and actions
282 Statistics *m_statistics;
283 RecentFiles m_recentFiles;
284 MachineTranslationDialog *m_machineTranslationDialog = 0;
285 bool m_globalReadWrite = true;
286#ifdef Q_OS_WASM
288#endif // Q_OS_WASM
289};
290
291QT_END_NAMESPACE
292
293#endif
~MainWindow() override
MainWindow(HelpClientType helpClientType)
void writeConfig()
static QString description()
void closeEvent(QCloseEvent *e) override
This event handler is called with the given event when Qt receives a window close request for a top-l...
bool openFiles(const QStringList &names)
bool eventFilter(QObject *obj, QEvent *ev) override
Filters events if this object has been installed as an event filter for the watched object.
void readConfig()
HelpClientType
Definition helpclient.h:17
Combined button and popup list for selecting options.
int main(int argc, char *argv[])
[ctor_close]