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 QLabel;
27class QMenu;
28class QPrinter;
29class QIcon;
30class QSortFilterProxyModel;
31class QStackedWidget;
32class QTableView;
33class QTreeView;
34
36class ErrorsView;
37class FocusWatcher;
38class HelpClient;
40#ifndef Q_OS_WASM
42#endif // Q_OS_WASM
43class MessageEditor;
44class PhraseView;
45class SourceCodeView;
46class Statistics;
47class TranslateDialog;
51
52enum class HelpClientType : quint8;
53
54class MainWindow : public QMainWindow
55{
57public:
60
61 explicit MainWindow(HelpClientType helpClientType);
63
64 bool openFiles(const QStringList &names);
65
66 static QString description();
67
68protected:
69 void readConfig();
70 void writeConfig();
71 void closeEvent(QCloseEvent *) override;
72 bool eventFilter(QObject *object, QEvent *event) override;
73
74private slots:
75 void done();
76 void doneAndNext();
77 void prev();
78 void next();
79 void recentFileActivated(QAction *action);
80 void setupRecentFilesMenu();
81 void open();
82 void openAux();
83 void saveAll();
84 void save();
85 void saveAs();
86 void releaseAll();
87 void release();
88 void releaseAs();
89 void closeFile();
90 bool closeAll();
91 void showTranslateDialog();
92 void showBatchTranslateDialog();
93 void showTranslationSettings();
94 void updateTranslateHit(bool &hit);
95 void translate(int mode);
96 void newPhraseBook();
97 void openPhraseBook();
98 void closePhraseBook(QAction *action);
99 void editPhraseBook(QAction *action);
100 void addToPhraseBook();
101 void manual();
102 void resetSorting();
103 void about();
104 void aboutQt();
105
106 void fileAboutToShow();
107 void editAboutToShow();
108
109 void showContextDock();
110 void showMessagesDock();
111 void showPhrasesDock();
112 void showSourceCodeDock();
113 void showErrorDock();
114
115 void setupPhrase();
116 bool maybeSaveAll();
117 bool maybeSave(int model);
118 void updateProgress();
119 void maybeUpdateStatistics(const MultiDataIndex &);
120 void translationChanged(const MultiDataIndex &);
121 void updateCaption();
122 void updateLatestModel(const QModelIndex &index);
123 void selectedContextChanged(const QModelIndex &sortedIndex, const QModelIndex &oldIndex);
124 void selectedLabelChanged(const QModelIndex &sortedIndex, const QModelIndex &oldIndex);
125 void selectedMessageChanged(const QModelIndex &sortedIndex, const QModelIndex &oldIndex);
126 void setCurrentMessageFromGuess(int modelIndex, const Candidate &tm);
127 void contextAndLabelTabChanged();
128
129 // To synchronize from the message editor to the model ...
130 void updateTranslation(const QStringList &translations);
131 void updateTranslatorComment(const QString &comment);
132
133 void updateVisibleColumns();
134 void updateActiveModel(int);
135 void refreshItemViews();
136 void toggleFinished(const QModelIndex &index);
137 void openMachineTranslateDialog();
138 void prevUnfinished();
139 void nextUnfinished();
140 void findNext(const QString &text, DataModel::FindLocation where,
141 FindDialog::FindOptions options, int statusFilter);
142 void revalidate();
143 void showStatistics();
144#ifndef Q_OS_WASM
145 void toggleQmlPreview();
146#endif // Q_OS_WASM
147 void toggleVisualizeWhitespace();
148 void onWhatsThis();
149 void updatePhraseDicts();
150 void updatePhraseDict(int model);
151
152#if QT_CONFIG(printsupport)
153 void print();
155#endif
156
157private:
158
159 friend class SortedGroupsModel;
160 QModelIndex nextGroup(const QModelIndex &index) const;
161 QModelIndex prevGroup(const QModelIndex &index) const;
162 QModelIndex firstMessage() const;
163 QModelIndex nextMessage(const QModelIndex &currentIndex, bool checkUnfinished = false) const;
164 QModelIndex prevMessage(const QModelIndex &currentIndex, bool checkUnfinished = false) const;
165 bool doNext(bool checkUnfinished);
166 bool doPrev(bool checkUnfinished);
167 void findAgain(FindDirection direction = FindNext);
168
169 void updateStatistics();
170 void initViewHeaders();
171 void modelCountChanged();
172 void setupMenuBar();
173 void setupToolBars();
174 void setCurrentMessage(const QModelIndex &index);
175 void setCurrentMessage(const QModelIndex &index, int model);
176 QModelIndex setMessageViewRoot(const QModelIndex &index);
177 QModelIndex currentMessageIndex() const;
178 PhraseBook *doOpenPhraseBook(const QString &name);
179 bool isPhraseBookOpen(const QString &name);
180 bool savePhraseBook(QString *name, PhraseBook &pb);
181 bool maybeSavePhraseBook(PhraseBook *phraseBook);
182 bool maybeSavePhraseBooks();
183 void pickTranslationFiles();
184 void doShowTranslationSettings(int model);
185 void doUpdateLatestModel(int model);
186 void updateSourceView(int model, MessageItem *item);
187 void updatePhraseBookActions();
188 void updatePhraseDictInternal(int model);
189 void releaseInternal(int model);
190 void saveInternal(int model);
191
192#if QT_CONFIG(printsupport)
193 QPrinter *printer();
194#endif
195
196 // FIXME: move to DataModel
197 void updateDanger(const MultiDataIndex &index, bool verbose);
198 void updateIcons();
199 bool searchItem(DataModel::FindLocation where, const QString &searchWhat);
200
201 std::unique_ptr<HelpClient> m_helpClient;
202
203 QTreeView *m_contextView;
204 QTreeView *m_labelView;
205 QTreeView *m_messageView;
206 MultiDataModel *m_dataModel;
207 MessageModel *m_idBasedMessageModel;
208 MessageModel *m_textBasedMessageModel;
209 MessageModel *m_activeMessageModel;
210 QSortFilterProxyModel *m_sortedContextsModel;
211 QSortFilterProxyModel *m_sortedLabelsModel;
212 QSortFilterProxyModel *m_activeSortedGroupsModel;
213 QSortFilterProxyModel *m_sortedIdBasedMessagesModel;
214 QSortFilterProxyModel *m_sortedTextBasedMessagesModel;
215 QSortFilterProxyModel *m_activeSortedMessagesModel;
216 MessageEditor *m_messageEditor;
217 PhraseView *m_phraseView;
218 QStackedWidget *m_sourceAndFormView;
219 QTabWidget *m_contextAndLabelView;
220 SourceCodeView *m_sourceCodeView;
221 UiFormPreviewView *m_uiFormPreviewView;
222#ifndef Q_OS_WASM
223 QmlFormPreviewView *m_qmlFormPreviewView;
224#endif // Q_OS_WASM
225 ErrorsView *m_errorsView;
226 QLabel *m_progressLabel;
227 QLabel *m_modifiedLabel;
228 FocusWatcher *m_focusWatcher;
229 QString m_phraseBookDir;
230 // model : keyword -> list of appropriate phrases in the phrasebooks
232 QList<PhraseBook *> m_phraseBooks;
233 QMap<QAction *, PhraseBook *> m_phraseBookMenu[3];
234#if QT_CONFIG(printsupport)
235 QPrinter *m_printer = nullptr;
236#endif
237
238 FindDialog *m_findDialog;
239 QString m_findText;
240 FindDialog::FindOptions m_findOptions;
241 int m_findStatusFilter = -1;
242 DataModel::FindLocation m_findWhere;
243
244 TranslateDialog *m_translateDialog;
245 QString m_latestFindText;
246 int m_latestCaseSensitivity;
247 QModelIndex m_searchIndex;
248 int m_hitCount;
249
250 BatchTranslationDialog *m_batchTranslateDialog;
251 TranslationSettingsDialog *m_translationSettingsDialog;
252
253 bool m_settingCurrentMessage;
254 std::optional<TranslationType> m_activeTranslationType;
255 int m_fileActiveModel;
256 int m_editActiveModel;
257 MultiDataIndex m_currentIndex;
258 QDockWidget *m_contextAndLabelDock;
259 QDockWidget *m_messagesDock;
260 QDockWidget *m_phrasesDock;
261 QDockWidget *m_sourceAndFormDock;
262 QDockWidget *m_errorsDock;
263
264 Ui::MainWindow m_ui; // menus and actions
265 Statistics *m_statistics;
266 RecentFiles m_recentFiles;
267 MachineTranslationDialog *m_machineTranslationDialog = 0;
268 bool m_globalReadWrite = true;
269#ifdef Q_OS_WASM
271#endif // Q_OS_WASM
272};
273
274QT_END_NAMESPACE
275
276#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:16
Combined button and popup list for selecting options.
int main(int argc, char *argv[])
[ctor_close]