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

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