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/QHash>
14#include <QtCore/QMap>
15#include <QtCore/QLocale>
16
17#include <QtWidgets/QMainWindow>
18
19QT_BEGIN_NAMESPACE
20
21class QPixmap;
22class QAction;
23class QDialog;
24class QLabel;
25class QMenu;
26class QPrinter;
27class QProcess;
28class QIcon;
29class QSortFilterProxyModel;
30class QStackedWidget;
31class QTableView;
32class QTreeView;
33
34class BatchTranslationDialog;
35class ErrorsView;
36class FocusWatcher;
37class FormPreviewView;
38class MessageEditor;
39class PhraseView;
40class SourceCodeView;
41class Statistics;
42class TranslateDialog;
43class TranslationSettingsDialog;
44
45class MainWindow : public QMainWindow
46{
47 Q_OBJECT
48public:
49 enum {PhraseCloseMenu, PhraseEditMenu, PhrasePrintMenu};
50 enum FindDirection {FindNext, FindPrev};
51
52 MainWindow();
53 ~MainWindow();
54
55 bool openFiles(const QStringList &names, bool readWrite = true);
56 static RecentFiles &recentFiles();
57 static QString friendlyString(const QString &str);
58
59public slots:
60 void updateViewMenu();
61
62protected:
63 void readConfig();
64 void writeConfig();
65 void closeEvent(QCloseEvent *) override;
66 bool eventFilter(QObject *object, QEvent *event) override;
67
68private slots:
69 void done();
70 void doneAndNext();
71 void prev();
72 void next();
73 void recentFileActivated(QAction *action);
74 void setupRecentFilesMenu();
75 void open();
76 void openAux();
77 void saveAll();
78 void save();
79 void saveAs();
80 void releaseAll();
81 void release();
82 void releaseAs();
83 void print();
84 void closeFile();
85 bool closeAll();
86 void showTranslateDialog();
87 void showBatchTranslateDialog();
88 void showTranslationSettings();
89 void updateTranslateHit(bool &hit);
90 void translate(int mode);
91 void newPhraseBook();
92 void openPhraseBook();
93 void closePhraseBook(QAction *action);
94 void editPhraseBook(QAction *action);
95 void printPhraseBook(QAction *action);
96 void addToPhraseBook();
97 void manual();
98 void resetSorting();
99 void about();
100 void aboutQt();
101
102 void fileAboutToShow();
103 void editAboutToShow();
104
105 void showContextDock();
106 void showMessagesDock();
107 void showPhrasesDock();
108 void showSourceCodeDock();
109 void showErrorDock();
110
111 void setupPhrase();
112 bool maybeSaveAll();
113 bool maybeSave(int model);
114 void updateProgress();
115 void maybeUpdateStatistics(const MultiDataIndex &);
116 void translationChanged(const MultiDataIndex &);
117 void updateCaption();
118 void updateLatestModel(const QModelIndex &index);
119 void selectedContextChanged(const QModelIndex &sortedIndex, const QModelIndex &oldIndex);
120 void selectedMessageChanged(const QModelIndex &sortedIndex, const QModelIndex &oldIndex);
121 void setCurrentMessageFromGuess(int modelIndex, const Candidate &tm);
122
123 // To synchronize from the message editor to the model ...
124 void updateTranslation(const QStringList &translations);
125 void updateTranslatorComment(const QString &comment);
126
127 void updateActiveModel(int);
128 void refreshItemViews();
129 void toggleFinished(const QModelIndex &index);
130 void prevUnfinished();
131 void nextUnfinished();
132 void findNext(const QString &text, DataModel::FindLocation where,
133 FindDialog::FindOptions options, int statusFilter);
134 void revalidate();
135 void toggleStatistics();
136 void toggleVisualizeWhitespace();
137 void onWhatsThis();
138 void updatePhraseDicts();
139 void updatePhraseDict(int model);
140
141private:
142 QModelIndex nextContext(const QModelIndex &index) const;
143 QModelIndex prevContext(const QModelIndex &index) const;
144 QModelIndex nextMessage(const QModelIndex &currentIndex, bool checkUnfinished = false) const;
145 QModelIndex prevMessage(const QModelIndex &currentIndex, bool checkUnfinished = false) const;
146 bool doNext(bool checkUnfinished);
147 bool doPrev(bool checkUnfinished);
148 void findAgain(FindDirection direction = FindNext);
149
150 void updateStatistics();
151 void initViewHeaders();
152 void modelCountChanged();
153 void setupMenuBar();
154 void setupToolBars();
155 void setCurrentMessage(const QModelIndex &index);
156 void setCurrentMessage(const QModelIndex &index, int model);
157 QModelIndex setMessageViewRoot(const QModelIndex &index);
158 QModelIndex currentContextIndex() const;
159 QModelIndex currentMessageIndex() const;
160 PhraseBook *doOpenPhraseBook(const QString &name);
161 bool isPhraseBookOpen(const QString &name);
162 bool savePhraseBook(QString *name, PhraseBook &pb);
163 bool maybeSavePhraseBook(PhraseBook *phraseBook);
164 bool maybeSavePhraseBooks();
165 QStringList pickTranslationFiles();
166 void doShowTranslationSettings(int model);
167 void doUpdateLatestModel(int model);
168 void updateSourceView(int model, MessageItem *item);
169 void updatePhraseBookActions();
170 void updatePhraseDictInternal(int model);
171 void releaseInternal(int model);
172 void saveInternal(int model);
173
174 QPrinter *printer();
175
176 // FIXME: move to DataModel
177 void updateDanger(const MultiDataIndex &index, bool verbose);
178
179 bool searchItem(DataModel::FindLocation where, const QString &searchWhat);
180
181 QProcess *m_assistantProcess;
182 QTreeView *m_contextView;
183 QTreeView *m_messageView;
184 MultiDataModel *m_dataModel;
185 MessageModel *m_messageModel;
186 QSortFilterProxyModel *m_sortedContextsModel;
187 QSortFilterProxyModel *m_sortedMessagesModel;
188 MessageEditor *m_messageEditor;
189 PhraseView *m_phraseView;
190 QStackedWidget *m_sourceAndFormView;
191 SourceCodeView *m_sourceCodeView;
192 FormPreviewView *m_formPreviewView;
193 ErrorsView *m_errorsView;
194 QLabel *m_progressLabel;
195 QLabel *m_modifiedLabel;
196 FocusWatcher *m_focusWatcher;
197 QString m_phraseBookDir;
198 // model : keyword -> list of appropriate phrases in the phrasebooks
199 QList<QHash<QString, QList<Phrase *> > > m_phraseDict;
200 QList<PhraseBook *> m_phraseBooks;
201 QMap<QAction *, PhraseBook *> m_phraseBookMenu[3];
202 QPrinter *m_printer;
203
204 FindDialog *m_findDialog;
205 QString m_findText;
206 FindDialog::FindOptions m_findOptions;
207 int m_findStatusFilter = -1;
208 DataModel::FindLocation m_findWhere;
209
210 TranslateDialog *m_translateDialog;
211 QString m_latestFindText;
212 int m_latestCaseSensitivity;
213 int m_remainingCount;
214 int m_hitCount;
215
216 BatchTranslationDialog *m_batchTranslateDialog;
217 TranslationSettingsDialog *m_translationSettingsDialog;
218
219 bool m_settingCurrentMessage;
220 int m_fileActiveModel;
221 int m_editActiveModel;
222 MultiDataIndex m_currentIndex;
223
224 QDockWidget *m_contextDock;
225 QDockWidget *m_messagesDock;
226 QDockWidget *m_phrasesDock;
227 QDockWidget *m_sourceAndFormDock;
228 QDockWidget *m_errorsDock;
229
230 Ui::MainWindow m_ui; // menus and actions
231 Statistics *m_statistics;
232};
233
234QT_END_NAMESPACE
235
236#endif
237

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