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 | |
19 | QT_BEGIN_NAMESPACE |
20 | |
21 | class QPixmap; |
22 | class QAction; |
23 | class QDialog; |
24 | class QLabel; |
25 | class ; |
26 | class QPrinter; |
27 | class QProcess; |
28 | class QIcon; |
29 | class QSortFilterProxyModel; |
30 | class QStackedWidget; |
31 | class QTableView; |
32 | class QTreeView; |
33 | |
34 | class BatchTranslationDialog; |
35 | class ErrorsView; |
36 | class FocusWatcher; |
37 | class FormPreviewView; |
38 | class MessageEditor; |
39 | class PhraseView; |
40 | class SourceCodeView; |
41 | class Statistics; |
42 | class TranslateDialog; |
43 | class TranslationSettingsDialog; |
44 | |
45 | class MainWindow : public QMainWindow |
46 | { |
47 | Q_OBJECT |
48 | public: |
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 | |
59 | public slots: |
60 | void updateViewMenu(); |
61 | |
62 | protected: |
63 | void readConfig(); |
64 | void writeConfig(); |
65 | void closeEvent(QCloseEvent *) override; |
66 | bool eventFilter(QObject *object, QEvent *event) override; |
67 | |
68 | private 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 &); |
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 | |
141 | private: |
142 | QModelIndex nextContext(const QModelIndex &index) const; |
143 | QModelIndex prevContext(const QModelIndex &index) const; |
144 | QModelIndex nextMessage(const QModelIndex ¤tIndex, bool checkUnfinished = false) const; |
145 | QModelIndex prevMessage(const QModelIndex ¤tIndex, 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 | |
234 | QT_END_NAMESPACE |
235 | |
236 | #endif |
237 | |