author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Mon, 03 May 2010 13:17:34 +0300 | |
changeset 19 | fcece45ef507 |
parent 18 | 2f34d5167611 |
child 30 | 5dc02b23752f |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the Qt Linguist of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
/* TRANSLATOR MainWindow |
|
43 |
||
44 |
This is the application's main window. |
|
45 |
*/ |
|
46 |
||
47 |
#include "mainwindow.h" |
|
48 |
||
49 |
#include "batchtranslationdialog.h" |
|
50 |
#include "errorsview.h" |
|
51 |
#include "finddialog.h" |
|
52 |
#include "formpreviewview.h" |
|
53 |
#include "globals.h" |
|
54 |
#include "messageeditor.h" |
|
55 |
#include "messagemodel.h" |
|
56 |
#include "phrasebookbox.h" |
|
57 |
#include "phrasemodel.h" |
|
58 |
#include "phraseview.h" |
|
59 |
#include "printout.h" |
|
60 |
#include "sourcecodeview.h" |
|
61 |
#include "statistics.h" |
|
62 |
#include "translatedialog.h" |
|
63 |
#include "translationsettingsdialog.h" |
|
64 |
||
65 |
#include <QAction> |
|
66 |
#include <QApplication> |
|
67 |
#include <QBitmap> |
|
68 |
#include <QCloseEvent> |
|
69 |
#include <QDebug> |
|
70 |
#include <QDesktopWidget> |
|
71 |
#include <QDockWidget> |
|
72 |
#include <QFile> |
|
73 |
#include <QFileDialog> |
|
74 |
#include <QFileInfo> |
|
75 |
#include <QHeaderView> |
|
76 |
#include <QInputDialog> |
|
77 |
#include <QItemDelegate> |
|
78 |
#include <QLabel> |
|
79 |
#include <QLayout> |
|
80 |
#include <QLibraryInfo> |
|
81 |
#include <QMenu> |
|
82 |
#include <QMenuBar> |
|
83 |
#include <QMessageBox> |
|
84 |
#include <QPrintDialog> |
|
85 |
#include <QPrinter> |
|
86 |
#include <QProcess> |
|
87 |
#include <QRegExp> |
|
88 |
#include <QSettings> |
|
89 |
#include <QSortFilterProxyModel> |
|
90 |
#include <QStackedWidget> |
|
91 |
#include <QStatusBar> |
|
92 |
#include <QTextStream> |
|
93 |
#include <QToolBar> |
|
94 |
#include <QUrl> |
|
95 |
#include <QWhatsThis> |
|
96 |
||
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
97 |
#include <ctype.h> |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
98 |
|
0 | 99 |
QT_BEGIN_NAMESPACE |
100 |
||
101 |
static const int MessageMS = 2500; |
|
102 |
||
103 |
enum Ending { |
|
104 |
End_None, |
|
105 |
End_FullStop, |
|
106 |
End_Interrobang, |
|
107 |
End_Colon, |
|
108 |
End_Ellipsis |
|
109 |
}; |
|
110 |
||
111 |
static bool hasFormPreview(const QString &fileName) |
|
112 |
{ |
|
113 |
return fileName.endsWith(QLatin1String(".ui")) |
|
114 |
|| fileName.endsWith(QLatin1String(".jui")); |
|
115 |
} |
|
116 |
||
117 |
static Ending ending(QString str, QLocale::Language lang) |
|
118 |
{ |
|
119 |
str = str.simplified(); |
|
120 |
if (str.isEmpty()) |
|
121 |
return End_None; |
|
122 |
||
123 |
switch (str.at(str.length() - 1).unicode()) { |
|
124 |
case 0x002e: // full stop |
|
125 |
if (str.endsWith(QLatin1String("..."))) |
|
126 |
return End_Ellipsis; |
|
127 |
else |
|
128 |
return End_FullStop; |
|
129 |
case 0x0589: // armenian full stop |
|
130 |
case 0x06d4: // arabic full stop |
|
131 |
case 0x3002: // ideographic full stop |
|
132 |
return End_FullStop; |
|
133 |
case 0x0021: // exclamation mark |
|
134 |
case 0x003f: // question mark |
|
135 |
case 0x00a1: // inverted exclamation mark |
|
136 |
case 0x00bf: // inverted question mark |
|
137 |
case 0x01c3: // latin letter retroflex click |
|
138 |
case 0x037e: // greek question mark |
|
139 |
case 0x061f: // arabic question mark |
|
140 |
case 0x203c: // double exclamation mark |
|
141 |
case 0x203d: // interrobang |
|
142 |
case 0x2048: // question exclamation mark |
|
143 |
case 0x2049: // exclamation question mark |
|
144 |
case 0x2762: // heavy exclamation mark ornament |
|
145 |
return End_Interrobang; |
|
146 |
case 0x003b: // greek 'compatibility' questionmark |
|
147 |
return lang == QLocale::Greek ? End_Interrobang : End_None; |
|
148 |
case 0x003a: // colon |
|
149 |
return End_Colon; |
|
150 |
case 0x2026: // horizontal ellipsis |
|
151 |
return End_Ellipsis; |
|
152 |
default: |
|
153 |
return End_None; |
|
154 |
} |
|
155 |
} |
|
156 |
||
157 |
||
158 |
class ContextItemDelegate : public QItemDelegate |
|
159 |
{ |
|
160 |
public: |
|
161 |
ContextItemDelegate(QObject *parent, MultiDataModel *model) : QItemDelegate(parent), m_dataModel(model) {} |
|
162 |
||
163 |
void paint(QPainter *painter, const QStyleOptionViewItem &option, |
|
164 |
const QModelIndex &index) const |
|
165 |
{ |
|
166 |
const QAbstractItemModel *model = index.model(); |
|
167 |
Q_ASSERT(model); |
|
168 |
||
169 |
if (!model->parent(index).isValid()) { |
|
170 |
if (index.column() - 1 == m_dataModel->modelCount()) { |
|
171 |
QStyleOptionViewItem opt = option; |
|
172 |
opt.font.setBold(true); |
|
173 |
QItemDelegate::paint(painter, opt, index); |
|
174 |
return; |
|
175 |
} |
|
176 |
} |
|
177 |
QItemDelegate::paint(painter, option, index); |
|
178 |
} |
|
179 |
||
180 |
private: |
|
181 |
MultiDataModel *m_dataModel; |
|
182 |
}; |
|
183 |
||
184 |
static const QVariant &pxObsolete() |
|
185 |
{ |
|
186 |
static const QVariant v = |
|
187 |
qVariantFromValue(QPixmap(QLatin1String(":/images/s_check_obsolete.png"))); |
|
188 |
return v; |
|
189 |
} |
|
190 |
||
191 |
||
192 |
class SortedMessagesModel : public QSortFilterProxyModel |
|
193 |
{ |
|
194 |
public: |
|
195 |
SortedMessagesModel(QObject *parent, MultiDataModel *model) : QSortFilterProxyModel(parent), m_dataModel(model) {} |
|
196 |
||
197 |
QVariant headerData(int section, Qt::Orientation orientation, int role) const |
|
198 |
{ |
|
199 |
if (role == Qt::DisplayRole && orientation == Qt::Horizontal) |
|
200 |
switch (section - m_dataModel->modelCount()) { |
|
201 |
case 0: return QString(); |
|
202 |
case 1: return MainWindow::tr("Source text"); |
|
203 |
case 2: return MainWindow::tr("Index"); |
|
204 |
} |
|
205 |
||
206 |
if (role == Qt::DecorationRole && orientation == Qt::Horizontal && section - 1 < m_dataModel->modelCount()) |
|
207 |
return pxObsolete(); |
|
208 |
||
209 |
return QVariant(); |
|
210 |
} |
|
211 |
||
212 |
private: |
|
213 |
MultiDataModel *m_dataModel; |
|
214 |
}; |
|
215 |
||
216 |
class SortedContextsModel : public QSortFilterProxyModel |
|
217 |
{ |
|
218 |
public: |
|
219 |
SortedContextsModel(QObject *parent, MultiDataModel *model) : QSortFilterProxyModel(parent), m_dataModel(model) {} |
|
220 |
||
221 |
QVariant headerData(int section, Qt::Orientation orientation, int role) const |
|
222 |
{ |
|
223 |
if (role == Qt::DisplayRole && orientation == Qt::Horizontal) |
|
224 |
switch (section - m_dataModel->modelCount()) { |
|
225 |
case 0: return QString(); |
|
226 |
case 1: return MainWindow::tr("Context"); |
|
227 |
case 2: return MainWindow::tr("Items"); |
|
228 |
case 3: return MainWindow::tr("Index"); |
|
229 |
} |
|
230 |
||
231 |
if (role == Qt::DecorationRole && orientation == Qt::Horizontal && section - 1 < m_dataModel->modelCount()) |
|
232 |
return pxObsolete(); |
|
233 |
||
234 |
return QVariant(); |
|
235 |
} |
|
236 |
||
237 |
private: |
|
238 |
MultiDataModel *m_dataModel; |
|
239 |
}; |
|
240 |
||
241 |
class FocusWatcher : public QObject |
|
242 |
{ |
|
243 |
public: |
|
244 |
FocusWatcher(MessageEditor *msgedit, QObject *parent) : QObject(parent), m_messageEditor(msgedit) {} |
|
245 |
||
246 |
protected: |
|
247 |
bool eventFilter(QObject *object, QEvent *event); |
|
248 |
||
249 |
private: |
|
250 |
MessageEditor *m_messageEditor; |
|
251 |
}; |
|
252 |
||
253 |
bool FocusWatcher::eventFilter(QObject *, QEvent *event) |
|
254 |
{ |
|
255 |
if (event->type() == QEvent::FocusIn) |
|
256 |
m_messageEditor->setEditorFocus(-1); |
|
257 |
return false; |
|
258 |
} |
|
259 |
||
260 |
MainWindow::MainWindow() |
|
261 |
: QMainWindow(0, Qt::Window), |
|
262 |
m_assistantProcess(0), |
|
263 |
m_printer(0), |
|
264 |
m_findMatchCase(Qt::CaseInsensitive), |
|
265 |
m_findIgnoreAccelerators(true), |
|
266 |
m_findWhere(DataModel::NoLocation), |
|
267 |
m_foundWhere(DataModel::NoLocation), |
|
268 |
m_translationSettingsDialog(0), |
|
269 |
m_settingCurrentMessage(false), |
|
270 |
m_fileActiveModel(-1), |
|
271 |
m_editActiveModel(-1), |
|
272 |
m_statistics(0) |
|
273 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
274 |
setUnifiedTitleAndToolBarOnMac(true); |
0 | 275 |
m_ui.setupUi(this); |
276 |
||
277 |
#ifndef Q_WS_MAC |
|
278 |
setWindowIcon(QPixmap(QLatin1String(":/images/appicon.png") )); |
|
279 |
#endif |
|
280 |
||
281 |
m_dataModel = new MultiDataModel(this); |
|
282 |
m_messageModel = new MessageModel(this, m_dataModel); |
|
283 |
||
284 |
// Set up the context dock widget |
|
285 |
m_contextDock = new QDockWidget(this); |
|
286 |
m_contextDock->setObjectName(QLatin1String("ContextDockWidget")); |
|
287 |
m_contextDock->setAllowedAreas(Qt::AllDockWidgetAreas); |
|
288 |
m_contextDock->setFeatures(QDockWidget::AllDockWidgetFeatures); |
|
289 |
m_contextDock->setWindowTitle(tr("Context")); |
|
290 |
m_contextDock->setAcceptDrops(true); |
|
291 |
m_contextDock->installEventFilter(this); |
|
292 |
||
293 |
m_sortedContextsModel = new SortedContextsModel(this, m_dataModel); |
|
294 |
m_sortedContextsModel->setSortRole(MessageModel::SortRole); |
|
295 |
m_sortedContextsModel->setSortCaseSensitivity(Qt::CaseInsensitive); |
|
296 |
m_sortedContextsModel->setSourceModel(m_messageModel); |
|
297 |
||
298 |
m_contextView = new QTreeView(this); |
|
299 |
m_contextView->setRootIsDecorated(false); |
|
300 |
m_contextView->setItemsExpandable(false); |
|
301 |
m_contextView->setUniformRowHeights(true); |
|
302 |
m_contextView->setAlternatingRowColors(true); |
|
303 |
m_contextView->setAllColumnsShowFocus(true); |
|
304 |
m_contextView->setItemDelegate(new ContextItemDelegate(this, m_dataModel)); |
|
305 |
m_contextView->setSortingEnabled(true); |
|
306 |
m_contextView->setWhatsThis(tr("This panel lists the source contexts.")); |
|
307 |
m_contextView->setModel(m_sortedContextsModel); |
|
308 |
m_contextView->header()->setMovable(false); |
|
309 |
m_contextView->setColumnHidden(0, true); |
|
310 |
m_contextView->header()->setStretchLastSection(false); |
|
311 |
||
312 |
m_contextDock->setWidget(m_contextView); |
|
313 |
||
314 |
// Set up the messages dock widget |
|
315 |
m_messagesDock = new QDockWidget(this); |
|
316 |
m_messagesDock->setObjectName(QLatin1String("StringsDockWidget")); |
|
317 |
m_messagesDock->setAllowedAreas(Qt::AllDockWidgetAreas); |
|
318 |
m_messagesDock->setFeatures(QDockWidget::AllDockWidgetFeatures); |
|
319 |
m_messagesDock->setWindowTitle(tr("Strings")); |
|
320 |
m_messagesDock->setAcceptDrops(true); |
|
321 |
m_messagesDock->installEventFilter(this); |
|
322 |
||
323 |
m_sortedMessagesModel = new SortedMessagesModel(this, m_dataModel); |
|
324 |
m_sortedMessagesModel->setSortRole(MessageModel::SortRole); |
|
325 |
m_sortedMessagesModel->setSortCaseSensitivity(Qt::CaseInsensitive); |
|
326 |
m_sortedMessagesModel->setSortLocaleAware(true); |
|
327 |
m_sortedMessagesModel->setSourceModel(m_messageModel); |
|
328 |
||
329 |
m_messageView = new QTreeView(m_messagesDock); |
|
330 |
m_messageView->setSortingEnabled(true); |
|
331 |
m_messageView->setRootIsDecorated(false); |
|
332 |
m_messageView->setUniformRowHeights(true); |
|
333 |
m_messageView->setAllColumnsShowFocus(true); |
|
334 |
m_messageView->setItemsExpandable(false); |
|
335 |
m_messageView->setModel(m_sortedMessagesModel); |
|
336 |
m_messageView->header()->setMovable(false); |
|
337 |
m_messageView->setColumnHidden(0, true); |
|
338 |
||
339 |
m_messagesDock->setWidget(m_messageView); |
|
340 |
||
341 |
// Set up main message view |
|
342 |
m_messageEditor = new MessageEditor(m_dataModel, this); |
|
343 |
m_messageEditor->setAcceptDrops(true); |
|
344 |
m_messageEditor->installEventFilter(this); |
|
345 |
// We can't call setCentralWidget(m_messageEditor), since it is already called in m_ui.setupUi() |
|
346 |
QBoxLayout *lout = new QBoxLayout(QBoxLayout::TopToBottom, m_ui.centralwidget); |
|
347 |
lout->addWidget(m_messageEditor); |
|
348 |
lout->setMargin(0); |
|
349 |
m_ui.centralwidget->setLayout(lout); |
|
350 |
||
351 |
// Set up the phrases & guesses dock widget |
|
352 |
m_phrasesDock = new QDockWidget(this); |
|
353 |
m_phrasesDock->setObjectName(QLatin1String("PhrasesDockwidget")); |
|
354 |
m_phrasesDock->setAllowedAreas(Qt::AllDockWidgetAreas); |
|
355 |
m_phrasesDock->setFeatures(QDockWidget::AllDockWidgetFeatures); |
|
356 |
m_phrasesDock->setWindowTitle(tr("Phrases and guesses")); |
|
357 |
||
358 |
m_phraseView = new PhraseView(m_dataModel, &m_phraseDict, this); |
|
359 |
m_phrasesDock->setWidget(m_phraseView); |
|
360 |
||
361 |
// Set up source code and form preview dock widget |
|
362 |
m_sourceAndFormDock = new QDockWidget(this); |
|
363 |
m_sourceAndFormDock->setObjectName(QLatin1String("SourceAndFormDock")); |
|
364 |
m_sourceAndFormDock->setAllowedAreas(Qt::AllDockWidgetAreas); |
|
365 |
m_sourceAndFormDock->setFeatures(QDockWidget::AllDockWidgetFeatures); |
|
366 |
m_sourceAndFormDock->setWindowTitle(tr("Sources and Forms")); |
|
367 |
m_sourceAndFormView = new QStackedWidget(this); |
|
368 |
m_sourceAndFormDock->setWidget(m_sourceAndFormView); |
|
369 |
//connect(m_sourceAndDock, SIGNAL(visibilityChanged(bool)), |
|
370 |
// m_sourceCodeView, SLOT(setActivated(bool))); |
|
371 |
m_formPreviewView = new FormPreviewView(0, m_dataModel); |
|
372 |
m_sourceCodeView = new SourceCodeView(0); |
|
373 |
m_sourceAndFormView->addWidget(m_sourceCodeView); |
|
374 |
m_sourceAndFormView->addWidget(m_formPreviewView); |
|
375 |
||
376 |
// Set up errors dock widget |
|
377 |
m_errorsDock = new QDockWidget(this); |
|
378 |
m_errorsDock->setObjectName(QLatin1String("ErrorsDockWidget")); |
|
379 |
m_errorsDock->setAllowedAreas(Qt::AllDockWidgetAreas); |
|
380 |
m_errorsDock->setFeatures(QDockWidget::AllDockWidgetFeatures); |
|
381 |
m_errorsDock->setWindowTitle(tr("Warnings")); |
|
382 |
m_errorsView = new ErrorsView(m_dataModel, this); |
|
383 |
m_errorsDock->setWidget(m_errorsView); |
|
384 |
||
385 |
// Arrange dock widgets |
|
386 |
setDockNestingEnabled(true); |
|
387 |
setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea); |
|
388 |
setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea); |
|
389 |
setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea); |
|
390 |
setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea); |
|
391 |
addDockWidget(Qt::LeftDockWidgetArea, m_contextDock); |
|
392 |
addDockWidget(Qt::TopDockWidgetArea, m_messagesDock); |
|
393 |
addDockWidget(Qt::BottomDockWidgetArea, m_phrasesDock); |
|
394 |
addDockWidget(Qt::TopDockWidgetArea, m_sourceAndFormDock); |
|
395 |
addDockWidget(Qt::BottomDockWidgetArea, m_errorsDock); |
|
396 |
//tabifyDockWidget(m_errorsDock, m_sourceAndFormDock); |
|
397 |
//tabifyDockWidget(m_sourceCodeDock, m_phrasesDock); |
|
398 |
||
399 |
// Allow phrases doc to intercept guesses shortcuts |
|
400 |
m_messageEditor->installEventFilter(m_phraseView); |
|
401 |
||
402 |
// Set up shortcuts for the dock widgets |
|
403 |
QShortcut *contextShortcut = new QShortcut(QKeySequence(Qt::Key_F6), this); |
|
404 |
connect(contextShortcut, SIGNAL(activated()), this, SLOT(showContextDock())); |
|
405 |
QShortcut *messagesShortcut = new QShortcut(QKeySequence(Qt::Key_F7), this); |
|
406 |
connect(messagesShortcut, SIGNAL(activated()), this, SLOT(showMessagesDock())); |
|
407 |
QShortcut *errorsShortcut = new QShortcut(QKeySequence(Qt::Key_F8), this); |
|
408 |
connect(errorsShortcut, SIGNAL(activated()), this, SLOT(showErrorDock())); |
|
409 |
QShortcut *sourceCodeShortcut = new QShortcut(QKeySequence(Qt::Key_F9), this); |
|
410 |
connect(sourceCodeShortcut, SIGNAL(activated()), this, SLOT(showSourceCodeDock())); |
|
411 |
QShortcut *phrasesShortcut = new QShortcut(QKeySequence(Qt::Key_F10), this); |
|
412 |
connect(phrasesShortcut, SIGNAL(activated()), this, SLOT(showPhrasesDock())); |
|
413 |
||
414 |
connect(m_phraseView, SIGNAL(phraseSelected(int,QString)), |
|
415 |
m_messageEditor, SLOT(setTranslation(int,QString))); |
|
416 |
connect(m_contextView->selectionModel(), |
|
417 |
SIGNAL(currentRowChanged(QModelIndex,QModelIndex)), |
|
418 |
this, SLOT(selectedContextChanged(QModelIndex,QModelIndex))); |
|
419 |
connect(m_messageView->selectionModel(), |
|
420 |
SIGNAL(currentRowChanged(QModelIndex,QModelIndex)), |
|
421 |
this, SLOT(selectedMessageChanged(QModelIndex,QModelIndex))); |
|
422 |
connect(m_contextView->selectionModel(), |
|
423 |
SIGNAL(currentColumnChanged(QModelIndex,QModelIndex)), |
|
424 |
SLOT(updateLatestModel(QModelIndex))); |
|
425 |
connect(m_messageView->selectionModel(), |
|
426 |
SIGNAL(currentColumnChanged(QModelIndex,QModelIndex)), |
|
427 |
SLOT(updateLatestModel(QModelIndex))); |
|
428 |
||
429 |
connect(m_messageEditor, SIGNAL(activeModelChanged(int)), SLOT(updateActiveModel(int))); |
|
430 |
||
431 |
m_translateDialog = new TranslateDialog(this); |
|
432 |
m_batchTranslateDialog = new BatchTranslationDialog(m_dataModel, this); |
|
433 |
m_findDialog = new FindDialog(this); |
|
434 |
||
435 |
setupMenuBar(); |
|
436 |
setupToolBars(); |
|
437 |
||
438 |
m_progressLabel = new QLabel(); |
|
439 |
statusBar()->addPermanentWidget(m_progressLabel); |
|
440 |
m_modifiedLabel = new QLabel(tr(" MOD ", "status bar: file(s) modified")); |
|
441 |
statusBar()->addPermanentWidget(m_modifiedLabel); |
|
442 |
||
443 |
modelCountChanged(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
444 |
initViewHeaders(); |
0 | 445 |
resetSorting(); |
446 |
||
447 |
connect(m_dataModel, SIGNAL(modifiedChanged(bool)), |
|
448 |
this, SLOT(setWindowModified(bool))); |
|
449 |
connect(m_dataModel, SIGNAL(modifiedChanged(bool)), |
|
450 |
m_modifiedLabel, SLOT(setVisible(bool))); |
|
451 |
connect(m_dataModel, SIGNAL(multiContextDataChanged(MultiDataIndex)), |
|
452 |
SLOT(updateProgress())); |
|
453 |
connect(m_dataModel, SIGNAL(messageDataChanged(MultiDataIndex)), |
|
454 |
SLOT(maybeUpdateStatistics(MultiDataIndex))); |
|
455 |
connect(m_dataModel, SIGNAL(translationChanged(MultiDataIndex)), |
|
456 |
SLOT(translationChanged(MultiDataIndex))); |
|
457 |
connect(m_dataModel, SIGNAL(languageChanged(int)), |
|
458 |
SLOT(updatePhraseDict(int))); |
|
459 |
||
460 |
setWindowModified(m_dataModel->isModified()); |
|
461 |
m_modifiedLabel->setVisible(m_dataModel->isModified()); |
|
462 |
||
463 |
connect(m_messageView, SIGNAL(clicked(QModelIndex)), |
|
464 |
this, SLOT(toggleFinished(QModelIndex))); |
|
465 |
connect(m_messageView, SIGNAL(activated(QModelIndex)), |
|
466 |
m_messageEditor, SLOT(setEditorFocus())); |
|
467 |
connect(m_contextView, SIGNAL(activated(QModelIndex)), |
|
468 |
m_messageView, SLOT(setFocus())); |
|
469 |
connect(m_messageEditor, SIGNAL(translationChanged(QStringList)), |
|
470 |
this, SLOT(updateTranslation(QStringList))); |
|
471 |
connect(m_messageEditor, SIGNAL(translatorCommentChanged(QString)), |
|
472 |
this, SLOT(updateTranslatorComment(QString))); |
|
473 |
connect(m_findDialog, SIGNAL(findNext(QString,DataModel::FindLocation,bool,bool)), |
|
474 |
this, SLOT(findNext(QString,DataModel::FindLocation,bool,bool))); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
475 |
connect(m_translateDialog, SIGNAL(requestMatchUpdate(bool&)), SLOT(updateTranslateHit(bool&))); |
0 | 476 |
connect(m_translateDialog, SIGNAL(activated(int)), SLOT(translate(int))); |
477 |
||
478 |
QSize as(qApp->desktop()->size()); |
|
479 |
as -= QSize(30, 30); |
|
480 |
resize(QSize(1000, 800).boundedTo(as)); |
|
481 |
show(); |
|
482 |
readConfig(); |
|
483 |
m_statistics = 0; |
|
484 |
||
485 |
connect(m_ui.actionLengthVariants, SIGNAL(toggled(bool)), |
|
486 |
m_messageEditor, SLOT(setLengthVariants(bool))); |
|
487 |
m_messageEditor->setLengthVariants(m_ui.actionLengthVariants->isChecked()); |
|
488 |
||
489 |
m_focusWatcher = new FocusWatcher(m_messageEditor, this); |
|
490 |
m_contextView->installEventFilter(m_focusWatcher); |
|
491 |
m_messageView->installEventFilter(m_focusWatcher); |
|
492 |
m_messageEditor->installEventFilter(m_focusWatcher); |
|
493 |
m_sourceAndFormView->installEventFilter(m_focusWatcher); |
|
494 |
m_phraseView->installEventFilter(m_focusWatcher); |
|
495 |
m_errorsView->installEventFilter(m_focusWatcher); |
|
496 |
} |
|
497 |
||
498 |
MainWindow::~MainWindow() |
|
499 |
{ |
|
500 |
writeConfig(); |
|
501 |
if (m_assistantProcess && m_assistantProcess->state() == QProcess::Running) { |
|
502 |
m_assistantProcess->terminate(); |
|
503 |
m_assistantProcess->waitForFinished(3000); |
|
504 |
} |
|
505 |
qDeleteAll(m_phraseBooks); |
|
506 |
delete m_dataModel; |
|
507 |
delete m_statistics; |
|
508 |
delete m_printer; |
|
509 |
} |
|
510 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
511 |
void MainWindow::initViewHeaders() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
512 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
513 |
m_contextView->header()->setResizeMode(1, QHeaderView::Stretch); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
514 |
m_contextView->header()->setResizeMode(2, QHeaderView::ResizeToContents); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
515 |
m_messageView->setColumnHidden(2, true); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
516 |
// last visible column auto-stretches |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
517 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
518 |
|
0 | 519 |
void MainWindow::modelCountChanged() |
520 |
{ |
|
521 |
int mc = m_dataModel->modelCount(); |
|
522 |
||
523 |
for (int i = 0; i < mc; ++i) { |
|
524 |
m_contextView->header()->setResizeMode(i + 1, QHeaderView::Fixed); |
|
525 |
m_contextView->header()->resizeSection(i + 1, 24); |
|
526 |
||
527 |
m_messageView->header()->setResizeMode(i + 1, QHeaderView::Fixed); |
|
528 |
m_messageView->header()->resizeSection(i + 1, 24); |
|
529 |
} |
|
530 |
||
531 |
if (!mc) { |
|
532 |
selectedMessageChanged(QModelIndex(), QModelIndex()); |
|
533 |
updateLatestModel(-1); |
|
534 |
} else { |
|
535 |
if (!m_contextView->currentIndex().isValid()) { |
|
536 |
// Ensure that something is selected |
|
537 |
m_contextView->setCurrentIndex(m_sortedContextsModel->index(0, 0)); |
|
538 |
} else { |
|
539 |
// Plug holes that turn up in the selection due to inserting columns |
|
540 |
m_contextView->selectionModel()->select(m_contextView->currentIndex(), |
|
541 |
QItemSelectionModel::SelectCurrent|QItemSelectionModel::Rows); |
|
542 |
m_messageView->selectionModel()->select(m_messageView->currentIndex(), |
|
543 |
QItemSelectionModel::SelectCurrent|QItemSelectionModel::Rows); |
|
544 |
} |
|
545 |
// Field insertions/removals are automatic, but not the re-fill |
|
546 |
m_messageEditor->showMessage(m_currentIndex); |
|
547 |
if (mc == 1) |
|
548 |
updateLatestModel(0); |
|
549 |
else if (m_currentIndex.model() >= mc) |
|
550 |
updateLatestModel(mc - 1); |
|
551 |
} |
|
552 |
||
553 |
m_contextView->setUpdatesEnabled(true); |
|
554 |
m_messageView->setUpdatesEnabled(true); |
|
555 |
||
556 |
updateProgress(); |
|
557 |
updateCaption(); |
|
558 |
||
559 |
m_ui.actionFind->setEnabled(m_dataModel->contextCount() > 0); |
|
560 |
m_ui.actionFindNext->setEnabled(false); |
|
561 |
||
562 |
m_formPreviewView->setSourceContext(-1, 0); |
|
563 |
} |
|
564 |
||
565 |
struct OpenedFile { |
|
566 |
OpenedFile(DataModel *_dataModel, bool _readWrite, bool _langGuessed) |
|
567 |
{ dataModel = _dataModel; readWrite = _readWrite; langGuessed = _langGuessed; } |
|
568 |
DataModel *dataModel; |
|
569 |
bool readWrite; |
|
570 |
bool langGuessed; |
|
571 |
}; |
|
572 |
||
573 |
bool MainWindow::openFiles(const QStringList &names, bool globalReadWrite) |
|
574 |
{ |
|
575 |
if (names.isEmpty()) |
|
576 |
return false; |
|
577 |
||
578 |
bool waitCursor = false; |
|
579 |
statusBar()->showMessage(tr("Loading...")); |
|
580 |
qApp->processEvents(); |
|
581 |
||
582 |
QList<OpenedFile> opened; |
|
583 |
bool closeOld = false; |
|
584 |
foreach (QString name, names) { |
|
585 |
if (!waitCursor) { |
|
586 |
QApplication::setOverrideCursor(Qt::WaitCursor); |
|
587 |
waitCursor = true; |
|
588 |
} |
|
589 |
||
590 |
bool readWrite = globalReadWrite; |
|
591 |
if (name.startsWith(QLatin1Char('='))) { |
|
592 |
name.remove(0, 1); |
|
593 |
readWrite = false; |
|
594 |
} |
|
595 |
QFileInfo fi(name); |
|
596 |
if (fi.exists()) // Make the loader error out instead of reading stdin |
|
597 |
name = fi.canonicalFilePath(); |
|
598 |
if (m_dataModel->isFileLoaded(name) >= 0) |
|
599 |
continue; |
|
600 |
||
601 |
bool langGuessed; |
|
602 |
DataModel *dm = new DataModel(m_dataModel); |
|
603 |
if (!dm->load(name, &langGuessed, this)) { |
|
604 |
delete dm; |
|
605 |
continue; |
|
606 |
} |
|
607 |
if (opened.isEmpty()) { |
|
608 |
if (!m_dataModel->isWellMergeable(dm)) { |
|
609 |
QApplication::restoreOverrideCursor(); |
|
610 |
waitCursor = false; |
|
611 |
switch (QMessageBox::information(this, tr("Loading File - Qt Linguist"), |
|
612 |
tr("The file '%1' does not seem to be related to the currently open file(s) '%2'.\n\n" |
|
613 |
"Close the open file(s) first?") |
|
614 |
.arg(DataModel::prettifyPlainFileName(name), m_dataModel->condensedSrcFileNames(true)), |
|
615 |
QMessageBox::Yes | QMessageBox::Default, |
|
616 |
QMessageBox::No, |
|
617 |
QMessageBox::Cancel | QMessageBox::Escape)) |
|
618 |
{ |
|
619 |
case QMessageBox::Cancel: |
|
620 |
delete dm; |
|
621 |
return false; |
|
622 |
case QMessageBox::Yes: |
|
623 |
closeOld = true; |
|
624 |
break; |
|
625 |
case QMessageBox::No: |
|
626 |
break; |
|
627 |
} |
|
628 |
} |
|
629 |
} else { |
|
630 |
if (!opened.first().dataModel->isWellMergeable(dm)) { |
|
631 |
QApplication::restoreOverrideCursor(); |
|
632 |
waitCursor = false; |
|
633 |
switch (QMessageBox::information(this, tr("Loading File - Qt Linguist"), |
|
634 |
tr("The file '%1' does not seem to be related to the file '%2'" |
|
635 |
" which is being loaded as well.\n\n" |
|
636 |
"Skip loading the first named file?") |
|
637 |
.arg(DataModel::prettifyPlainFileName(name), opened.first().dataModel->srcFileName(true)), |
|
638 |
QMessageBox::Yes | QMessageBox::Default, |
|
639 |
QMessageBox::No, |
|
640 |
QMessageBox::Cancel | QMessageBox::Escape)) |
|
641 |
{ |
|
642 |
case QMessageBox::Cancel: |
|
643 |
delete dm; |
|
644 |
foreach (const OpenedFile &op, opened) |
|
645 |
delete op.dataModel; |
|
646 |
return false; |
|
647 |
case QMessageBox::Yes: |
|
648 |
delete dm; |
|
649 |
continue; |
|
650 |
case QMessageBox::No: |
|
651 |
break; |
|
652 |
} |
|
653 |
} |
|
654 |
} |
|
655 |
opened.append(OpenedFile(dm, readWrite, langGuessed)); |
|
656 |
} |
|
657 |
||
658 |
if (closeOld) { |
|
659 |
if (waitCursor) { |
|
660 |
QApplication::restoreOverrideCursor(); |
|
661 |
waitCursor = false; |
|
662 |
} |
|
663 |
if (!closeAll()) { |
|
664 |
foreach (const OpenedFile &op, opened) |
|
665 |
delete op.dataModel; |
|
666 |
return false; |
|
667 |
} |
|
668 |
} |
|
669 |
||
670 |
foreach (const OpenedFile &op, opened) { |
|
671 |
if (op.langGuessed) { |
|
672 |
if (waitCursor) { |
|
673 |
QApplication::restoreOverrideCursor(); |
|
674 |
waitCursor = false; |
|
675 |
} |
|
676 |
if (!m_translationSettingsDialog) |
|
677 |
m_translationSettingsDialog = new TranslationSettingsDialog(this); |
|
678 |
m_translationSettingsDialog->setDataModel(op.dataModel); |
|
679 |
m_translationSettingsDialog->exec(); |
|
680 |
} |
|
681 |
} |
|
682 |
||
683 |
if (!waitCursor) |
|
684 |
QApplication::setOverrideCursor(Qt::WaitCursor); |
|
685 |
m_contextView->setUpdatesEnabled(false); |
|
686 |
m_messageView->setUpdatesEnabled(false); |
|
687 |
int totalCount = 0; |
|
688 |
foreach (const OpenedFile &op, opened) { |
|
689 |
m_phraseDict.append(QHash<QString, QList<Phrase *> >()); |
|
690 |
m_dataModel->append(op.dataModel, op.readWrite); |
|
691 |
if (op.readWrite) |
|
692 |
updatePhraseDictInternal(m_phraseDict.size() - 1); |
|
693 |
totalCount += op.dataModel->messageCount(); |
|
694 |
} |
|
695 |
statusBar()->showMessage(tr("%n translation unit(s) loaded.", 0, totalCount), MessageMS); |
|
696 |
modelCountChanged(); |
|
697 |
recentFiles().addFiles(m_dataModel->srcFileNames()); |
|
698 |
||
699 |
revalidate(); |
|
700 |
QApplication::restoreOverrideCursor(); |
|
701 |
return true; |
|
702 |
} |
|
703 |
||
704 |
RecentFiles &MainWindow::recentFiles() |
|
705 |
{ |
|
706 |
static RecentFiles recentFiles(10); |
|
707 |
return recentFiles; |
|
708 |
} |
|
709 |
||
710 |
const QString &MainWindow::resourcePrefix() |
|
711 |
{ |
|
712 |
#ifdef Q_WS_MAC |
|
713 |
static const QString prefix(QLatin1String(":/images/mac")); |
|
714 |
#else |
|
715 |
static const QString prefix(QLatin1String(":/images/win")); |
|
716 |
#endif |
|
717 |
return prefix; |
|
718 |
} |
|
719 |
||
720 |
void MainWindow::open() |
|
721 |
{ |
|
722 |
openFiles(pickTranslationFiles()); |
|
723 |
} |
|
724 |
||
725 |
void MainWindow::openAux() |
|
726 |
{ |
|
727 |
openFiles(pickTranslationFiles(), false); |
|
728 |
} |
|
729 |
||
730 |
void MainWindow::closeFile() |
|
731 |
{ |
|
732 |
int model = m_currentIndex.model(); |
|
733 |
if (model >= 0 && maybeSave(model)) { |
|
734 |
m_phraseDict.removeAt(model); |
|
735 |
m_contextView->setUpdatesEnabled(false); |
|
736 |
m_messageView->setUpdatesEnabled(false); |
|
737 |
m_dataModel->close(model); |
|
738 |
modelCountChanged(); |
|
739 |
} |
|
740 |
} |
|
741 |
||
742 |
bool MainWindow::closeAll() |
|
743 |
{ |
|
744 |
if (maybeSaveAll()) { |
|
745 |
m_phraseDict.clear(); |
|
746 |
m_contextView->setUpdatesEnabled(false); |
|
747 |
m_messageView->setUpdatesEnabled(false); |
|
748 |
m_dataModel->closeAll(); |
|
749 |
modelCountChanged(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
750 |
initViewHeaders(); |
0 | 751 |
recentFiles().closeGroup(); |
752 |
return true; |
|
753 |
} |
|
754 |
return false; |
|
755 |
} |
|
756 |
||
757 |
static QString fileFilters(bool allFirst) |
|
758 |
{ |
|
759 |
static const QString pattern(QLatin1String("%1 (*.%2);;")); |
|
760 |
QStringList allExtensions; |
|
761 |
QString filter; |
|
762 |
foreach (const Translator::FileFormat &format, Translator::registeredFileFormats()) { |
|
763 |
if (format.fileType == Translator::FileFormat::TranslationSource && format.priority >= 0) { |
|
764 |
filter.append(pattern.arg(format.description).arg(format.extension)); |
|
765 |
allExtensions.append(QLatin1String("*.") + format.extension); |
|
766 |
} |
|
767 |
} |
|
768 |
QString allFilter = QObject::tr("Translation files (%1);;").arg(allExtensions.join(QLatin1String(" "))); |
|
769 |
if (allFirst) |
|
770 |
filter.prepend(allFilter); |
|
771 |
else |
|
772 |
filter.append(allFilter); |
|
773 |
filter.append(QObject::tr("All files (*)")); |
|
774 |
return filter; |
|
775 |
} |
|
776 |
||
777 |
QStringList MainWindow::pickTranslationFiles() |
|
778 |
{ |
|
779 |
QString dir; |
|
780 |
if (!recentFiles().isEmpty()) |
|
781 |
dir = QFileInfo(recentFiles().lastOpenedFile()).path(); |
|
782 |
||
783 |
QString varFilt; |
|
784 |
if (m_dataModel->modelCount()) { |
|
785 |
QFileInfo mainFile(m_dataModel->srcFileName(0)); |
|
786 |
QString mainFileBase = mainFile.baseName(); |
|
787 |
int pos = mainFileBase.indexOf(QLatin1Char('_')); |
|
788 |
if (pos > 0) |
|
789 |
varFilt = tr("Related files (%1);;") |
|
790 |
.arg(mainFileBase.left(pos) + QLatin1String("_*.") + mainFile.completeSuffix()); |
|
791 |
} |
|
792 |
||
793 |
return QFileDialog::getOpenFileNames(this, tr("Open Translation Files"), dir, |
|
794 |
varFilt + |
|
795 |
fileFilters(true)); |
|
796 |
} |
|
797 |
||
798 |
void MainWindow::saveInternal(int model) |
|
799 |
{ |
|
800 |
QApplication::setOverrideCursor(Qt::WaitCursor); |
|
801 |
if (m_dataModel->save(model, this)) { |
|
802 |
updateCaption(); |
|
803 |
statusBar()->showMessage(tr("File saved."), MessageMS); |
|
804 |
} |
|
805 |
QApplication::restoreOverrideCursor(); |
|
806 |
} |
|
807 |
||
808 |
void MainWindow::saveAll() |
|
809 |
{ |
|
810 |
for (int i = 0; i < m_dataModel->modelCount(); ++i) |
|
811 |
if (m_dataModel->isModelWritable(i)) |
|
812 |
saveInternal(i); |
|
813 |
recentFiles().closeGroup(); |
|
814 |
} |
|
815 |
||
816 |
void MainWindow::save() |
|
817 |
{ |
|
818 |
if (m_currentIndex.model() < 0) |
|
819 |
return; |
|
820 |
||
821 |
saveInternal(m_currentIndex.model()); |
|
822 |
} |
|
823 |
||
824 |
void MainWindow::saveAs() |
|
825 |
{ |
|
826 |
if (m_currentIndex.model() < 0) |
|
827 |
return; |
|
828 |
||
829 |
QString newFilename = QFileDialog::getSaveFileName(this, QString(), m_dataModel->srcFileName(m_currentIndex.model()), |
|
830 |
fileFilters(false)); |
|
831 |
if (!newFilename.isEmpty()) { |
|
832 |
if (m_dataModel->saveAs(m_currentIndex.model(), newFilename, this)) { |
|
833 |
updateCaption(); |
|
834 |
statusBar()->showMessage(tr("File saved."), MessageMS); |
|
835 |
recentFiles().addFiles(m_dataModel->srcFileNames()); |
|
836 |
} |
|
837 |
} |
|
838 |
} |
|
839 |
||
840 |
void MainWindow::releaseAs() |
|
841 |
{ |
|
842 |
if (m_currentIndex.model() < 0) |
|
843 |
return; |
|
844 |
||
845 |
QFileInfo oldFile(m_dataModel->srcFileName(m_currentIndex.model())); |
|
846 |
QString newFilename = oldFile.path() + QLatin1String("/") |
|
847 |
+ oldFile.completeBaseName() + QLatin1String(".qm"); |
|
848 |
||
849 |
newFilename = QFileDialog::getSaveFileName(this, tr("Release"), newFilename, |
|
850 |
tr("Qt message files for released applications (*.qm)\nAll files (*)")); |
|
851 |
if (!newFilename.isEmpty()) { |
|
852 |
if (m_dataModel->release(m_currentIndex.model(), newFilename, false, false, SaveEverything, this)) |
|
853 |
statusBar()->showMessage(tr("File created."), MessageMS); |
|
854 |
} |
|
855 |
} |
|
856 |
||
857 |
void MainWindow::releaseInternal(int model) |
|
858 |
{ |
|
859 |
QFileInfo oldFile(m_dataModel->srcFileName(model)); |
|
860 |
QString newFilename = oldFile.path() + QLatin1Char('/') |
|
861 |
+ oldFile.completeBaseName() + QLatin1String(".qm"); |
|
862 |
||
863 |
if (!newFilename.isEmpty()) { |
|
864 |
if (m_dataModel->release(model, newFilename, false, false, SaveEverything, this)) |
|
865 |
statusBar()->showMessage(tr("File created."), MessageMS); |
|
866 |
} |
|
867 |
} |
|
868 |
||
869 |
// No-question |
|
870 |
void MainWindow::release() |
|
871 |
{ |
|
872 |
if (m_currentIndex.model() < 0) |
|
873 |
return; |
|
874 |
||
875 |
releaseInternal(m_currentIndex.model()); |
|
876 |
} |
|
877 |
||
878 |
void MainWindow::releaseAll() |
|
879 |
{ |
|
880 |
for (int i = 0; i < m_dataModel->modelCount(); ++i) |
|
881 |
if (m_dataModel->isModelWritable(i)) |
|
882 |
releaseInternal(i); |
|
883 |
} |
|
884 |
||
885 |
QPrinter *MainWindow::printer() |
|
886 |
{ |
|
887 |
if (!m_printer) |
|
888 |
m_printer = new QPrinter; |
|
889 |
return m_printer; |
|
890 |
} |
|
891 |
||
892 |
void MainWindow::print() |
|
893 |
{ |
|
894 |
int pageNum = 0; |
|
895 |
QPrintDialog dlg(printer(), this); |
|
896 |
if (dlg.exec()) { |
|
897 |
QApplication::setOverrideCursor(Qt::WaitCursor); |
|
898 |
printer()->setDocName(m_dataModel->condensedSrcFileNames(true)); |
|
899 |
statusBar()->showMessage(tr("Printing...")); |
|
900 |
PrintOut pout(printer()); |
|
901 |
||
902 |
for (int i = 0; i < m_dataModel->contextCount(); ++i) { |
|
903 |
MultiContextItem *mc = m_dataModel->multiContextItem(i); |
|
904 |
pout.vskip(); |
|
905 |
pout.setRule(PrintOut::ThickRule); |
|
906 |
pout.setGuide(mc->context()); |
|
907 |
pout.addBox(100, tr("Context: %1").arg(mc->context()), |
|
908 |
PrintOut::Strong); |
|
909 |
pout.flushLine(); |
|
910 |
pout.addBox(4); |
|
911 |
pout.addBox(92, mc->comment(), PrintOut::Emphasis); |
|
912 |
pout.flushLine(); |
|
913 |
pout.setRule(PrintOut::ThickRule); |
|
914 |
||
915 |
for (int j = 0; j < mc->messageCount(); ++j) { |
|
916 |
pout.setRule(PrintOut::ThinRule); |
|
917 |
bool printedSrc = false; |
|
918 |
QString comment; |
|
919 |
for (int k = 0; k < m_dataModel->modelCount(); ++k) { |
|
920 |
if (const MessageItem *m = mc->messageItem(k, j)) { |
|
921 |
if (!printedSrc) { |
|
922 |
pout.addBox(40, m->text()); |
|
923 |
pout.addBox(4); |
|
924 |
comment = m->comment(); |
|
925 |
printedSrc = true; |
|
926 |
} else { |
|
927 |
pout.addBox(44); // Maybe put the name of the translation here |
|
928 |
} |
|
929 |
if (m->message().isPlural() && m_dataModel->language(k) != QLocale::C) { |
|
930 |
QStringList transls = m->translations(); |
|
931 |
pout.addBox(40, transls.join(QLatin1String("\n"))); |
|
932 |
} else { |
|
933 |
pout.addBox(40, m->translation()); |
|
934 |
} |
|
935 |
pout.addBox(4); |
|
936 |
QString type; |
|
937 |
switch (m->message().type()) { |
|
938 |
case TranslatorMessage::Finished: |
|
939 |
type = tr("finished"); |
|
940 |
break; |
|
941 |
case TranslatorMessage::Unfinished: |
|
942 |
type = m->danger() ? tr("unresolved") : QLatin1String("unfinished"); |
|
943 |
break; |
|
944 |
case TranslatorMessage::Obsolete: |
|
945 |
type = tr("obsolete"); |
|
946 |
break; |
|
947 |
} |
|
948 |
pout.addBox(12, type, PrintOut::Normal, Qt::AlignRight); |
|
949 |
pout.flushLine(); |
|
950 |
} |
|
951 |
} |
|
952 |
if (!comment.isEmpty()) { |
|
953 |
pout.addBox(4); |
|
954 |
pout.addBox(92, comment, PrintOut::Emphasis); |
|
955 |
pout.flushLine(true); |
|
956 |
} |
|
957 |
||
958 |
if (pout.pageNum() != pageNum) { |
|
959 |
pageNum = pout.pageNum(); |
|
960 |
statusBar()->showMessage(tr("Printing... (page %1)") |
|
961 |
.arg(pageNum)); |
|
962 |
} |
|
963 |
} |
|
964 |
} |
|
965 |
pout.flushLine(true); |
|
966 |
QApplication::restoreOverrideCursor(); |
|
967 |
statusBar()->showMessage(tr("Printing completed"), MessageMS); |
|
968 |
} else { |
|
969 |
statusBar()->showMessage(tr("Printing aborted"), MessageMS); |
|
970 |
} |
|
971 |
} |
|
972 |
||
973 |
bool MainWindow::searchItem(const QString &searchWhat) |
|
974 |
{ |
|
975 |
if ((m_findWhere & m_foundWhere) == 0) |
|
976 |
return false; |
|
977 |
||
978 |
QString text = searchWhat; |
|
979 |
||
980 |
if (m_findIgnoreAccelerators) |
|
981 |
// FIXME: This removes too much. The proper solution might be too slow, though. |
|
982 |
text.remove(QLatin1Char('&')); |
|
983 |
||
984 |
int foundOffset = text.indexOf(m_findText, 0, m_findMatchCase); |
|
985 |
return foundOffset >= 0; |
|
986 |
} |
|
987 |
||
988 |
void MainWindow::findAgain() |
|
989 |
{ |
|
990 |
if (m_dataModel->contextCount() == 0) |
|
991 |
return; |
|
992 |
||
993 |
const QModelIndex &startIndex = m_messageView->currentIndex(); |
|
994 |
QModelIndex index = nextMessage(startIndex); |
|
995 |
||
996 |
while (index.isValid()) { |
|
997 |
QModelIndex realIndex = m_sortedMessagesModel->mapToSource(index); |
|
998 |
MultiDataIndex dataIndex = m_messageModel->dataIndex(realIndex, -1); |
|
999 |
bool hadMessage = false; |
|
1000 |
for (int i = 0; i < m_dataModel->modelCount(); ++i) { |
|
1001 |
if (MessageItem *m = m_dataModel->messageItem(dataIndex, i)) { |
|
1002 |
// Note: we do not look into plurals on grounds of them not |
|
1003 |
// containing anything much different from the singular. |
|
1004 |
if (hadMessage) { |
|
1005 |
m_foundWhere = DataModel::Translations; |
|
1006 |
if (!searchItem(m->translation())) |
|
1007 |
m_foundWhere = DataModel::NoLocation; |
|
1008 |
} else { |
|
1009 |
switch (m_foundWhere) { |
|
1010 |
case 0: |
|
1011 |
m_foundWhere = DataModel::SourceText; |
|
1012 |
// fall-through to search source text |
|
1013 |
case DataModel::SourceText: |
|
1014 |
if (searchItem(m->text())) |
|
1015 |
break; |
|
1016 |
if (searchItem(m->pluralText())) |
|
1017 |
break; |
|
1018 |
m_foundWhere = DataModel::Translations; |
|
1019 |
// fall-through to search translation |
|
1020 |
case DataModel::Translations: |
|
1021 |
if (searchItem(m->translation())) |
|
1022 |
break; |
|
1023 |
m_foundWhere = DataModel::Comments; |
|
1024 |
// fall-through to search comment |
|
1025 |
case DataModel::Comments: |
|
1026 |
if (searchItem(m->comment())) |
|
1027 |
break; |
|
1028 |
if (searchItem(m->extraComment())) |
|
1029 |
break; |
|
1030 |
m_foundWhere = DataModel::NoLocation; |
|
1031 |
// did not find the search string in this message |
|
1032 |
} |
|
1033 |
} |
|
1034 |
if (m_foundWhere != DataModel::NoLocation) { |
|
1035 |
setCurrentMessage(realIndex, i); |
|
1036 |
||
1037 |
// determine whether the search wrapped |
|
1038 |
const QModelIndex &c1 = m_sortedContextsModel->mapFromSource( |
|
1039 |
m_sortedMessagesModel->mapToSource(startIndex)).parent(); |
|
1040 |
const QModelIndex &c2 = m_sortedContextsModel->mapFromSource(realIndex).parent(); |
|
1041 |
const QModelIndex &m = m_sortedMessagesModel->mapFromSource(realIndex); |
|
1042 |
||
1043 |
if (c2.row() < c1.row() || (c1.row() == c2.row() && m.row() <= startIndex.row())) |
|
1044 |
statusBar()->showMessage(tr("Search wrapped."), MessageMS); |
|
1045 |
||
1046 |
m_findDialog->hide(); |
|
1047 |
return; |
|
1048 |
} |
|
1049 |
hadMessage = true; |
|
1050 |
} |
|
1051 |
} |
|
1052 |
||
1053 |
// since we don't search startIndex at the beginning, only now we have searched everything |
|
1054 |
if (index == startIndex) |
|
1055 |
break; |
|
1056 |
||
1057 |
index = nextMessage(index); |
|
1058 |
} |
|
1059 |
||
1060 |
qApp->beep(); |
|
1061 |
QMessageBox::warning(m_findDialog, tr("Qt Linguist"), |
|
1062 |
tr("Cannot find the string '%1'.").arg(m_findText)); |
|
1063 |
m_foundWhere = DataModel::NoLocation; |
|
1064 |
} |
|
1065 |
||
1066 |
void MainWindow::showBatchTranslateDialog() |
|
1067 |
{ |
|
1068 |
m_messageModel->blockSignals(true); |
|
1069 |
m_batchTranslateDialog->setPhraseBooks(m_phraseBooks, m_currentIndex.model()); |
|
1070 |
if (m_batchTranslateDialog->exec() != QDialog::Accepted) |
|
1071 |
m_messageModel->blockSignals(false); |
|
1072 |
// else signal finished() calls refreshItemViews() |
|
1073 |
} |
|
1074 |
||
1075 |
void MainWindow::showTranslateDialog() |
|
1076 |
{ |
|
1077 |
m_latestCaseSensitivity = -1; |
|
1078 |
QModelIndex idx = m_messageView->currentIndex(); |
|
1079 |
QModelIndex idx2 = m_sortedMessagesModel->index(idx.row(), m_currentIndex.model() + 1, idx.parent()); |
|
1080 |
m_messageView->setCurrentIndex(idx2); |
|
1081 |
QString fn = QFileInfo(m_dataModel->srcFileName(m_currentIndex.model())).baseName(); |
|
1082 |
m_translateDialog->setWindowTitle(tr("Search And Translate in '%1' - Qt Linguist").arg(fn)); |
|
1083 |
m_translateDialog->exec(); |
|
1084 |
} |
|
1085 |
||
1086 |
void MainWindow::updateTranslateHit(bool &hit) |
|
1087 |
{ |
|
1088 |
MessageItem *m; |
|
1089 |
hit = (m = m_dataModel->messageItem(m_currentIndex)) |
|
1090 |
&& !m->isObsolete() |
|
1091 |
&& m->compare(m_translateDialog->findText(), false, m_translateDialog->caseSensitivity()); |
|
1092 |
} |
|
1093 |
||
1094 |
void MainWindow::translate(int mode) |
|
1095 |
{ |
|
1096 |
QString findText = m_translateDialog->findText(); |
|
1097 |
QString replaceText = m_translateDialog->replaceText(); |
|
1098 |
bool markFinished = m_translateDialog->markFinished(); |
|
1099 |
Qt::CaseSensitivity caseSensitivity = m_translateDialog->caseSensitivity(); |
|
1100 |
||
1101 |
int translatedCount = 0; |
|
1102 |
||
1103 |
if (mode == TranslateDialog::TranslateAll) { |
|
1104 |
for (MultiDataModelIterator it(m_dataModel, m_currentIndex.model()); it.isValid(); ++it) { |
|
1105 |
MessageItem *m = it.current(); |
|
1106 |
if (m && !m->isObsolete() && m->compare(findText, false, caseSensitivity)) { |
|
1107 |
if (!translatedCount) |
|
1108 |
m_messageModel->blockSignals(true); |
|
1109 |
m_dataModel->setTranslation(it, replaceText); |
|
1110 |
m_dataModel->setFinished(it, markFinished); |
|
1111 |
++translatedCount; |
|
1112 |
} |
|
1113 |
} |
|
1114 |
if (translatedCount) { |
|
1115 |
refreshItemViews(); |
|
1116 |
QMessageBox::warning(m_translateDialog, tr("Translate - Qt Linguist"), |
|
1117 |
tr("Translated %n entry(s)", 0, translatedCount)); |
|
1118 |
} |
|
1119 |
} else { |
|
1120 |
if (mode == TranslateDialog::Translate) { |
|
1121 |
m_dataModel->setTranslation(m_currentIndex, replaceText); |
|
1122 |
m_dataModel->setFinished(m_currentIndex, markFinished); |
|
1123 |
} |
|
1124 |
||
1125 |
if (findText != m_latestFindText || caseSensitivity != m_latestCaseSensitivity) { |
|
1126 |
m_latestFindText = findText; |
|
1127 |
m_latestCaseSensitivity = caseSensitivity; |
|
1128 |
m_remainingCount = m_dataModel->messageCount(); |
|
1129 |
m_hitCount = 0; |
|
1130 |
} |
|
1131 |
||
1132 |
QModelIndex index = m_messageView->currentIndex(); |
|
1133 |
int prevRemained = m_remainingCount; |
|
1134 |
forever { |
|
1135 |
if (--m_remainingCount <= 0) { |
|
1136 |
if (!m_hitCount) |
|
1137 |
break; |
|
1138 |
m_remainingCount = m_dataModel->messageCount() - 1; |
|
1139 |
if (QMessageBox::question(m_translateDialog, tr("Translate - Qt Linguist"), |
|
1140 |
tr("No more occurrences of '%1'. Start over?").arg(findText), |
|
1141 |
QMessageBox::Yes|QMessageBox::No) != QMessageBox::Yes) |
|
1142 |
return; |
|
1143 |
m_remainingCount -= prevRemained; |
|
1144 |
} |
|
1145 |
||
1146 |
index = nextMessage(index); |
|
1147 |
||
1148 |
QModelIndex realIndex = m_sortedMessagesModel->mapToSource(index); |
|
1149 |
MultiDataIndex dataIndex = m_messageModel->dataIndex(realIndex, m_currentIndex.model()); |
|
1150 |
if (MessageItem *m = m_dataModel->messageItem(dataIndex)) { |
|
1151 |
if (!m->isObsolete() && m->compare(findText, false, caseSensitivity)) { |
|
1152 |
setCurrentMessage(realIndex, m_currentIndex.model()); |
|
1153 |
++translatedCount; |
|
1154 |
++m_hitCount; |
|
1155 |
break; |
|
1156 |
} |
|
1157 |
} |
|
1158 |
} |
|
1159 |
} |
|
1160 |
||
1161 |
if (!translatedCount) { |
|
1162 |
qApp->beep(); |
|
1163 |
QMessageBox::warning(m_translateDialog, tr("Translate - Qt Linguist"), |
|
1164 |
tr("Cannot find the string '%1'.").arg(findText)); |
|
1165 |
} |
|
1166 |
} |
|
1167 |
||
1168 |
void MainWindow::newPhraseBook() |
|
1169 |
{ |
|
1170 |
QString name = QFileDialog::getSaveFileName(this, tr("Create New Phrase Book"), |
|
1171 |
m_phraseBookDir, tr("Qt phrase books (*.qph)\nAll files (*)")); |
|
1172 |
if (!name.isEmpty()) { |
|
1173 |
PhraseBook pb; |
|
1174 |
if (!m_translationSettingsDialog) |
|
1175 |
m_translationSettingsDialog = new TranslationSettingsDialog(this); |
|
1176 |
m_translationSettingsDialog->setPhraseBook(&pb); |
|
1177 |
if (!m_translationSettingsDialog->exec()) |
|
1178 |
return; |
|
1179 |
m_phraseBookDir = QFileInfo(name).absolutePath(); |
|
1180 |
if (savePhraseBook(&name, pb)) { |
|
1181 |
if (openPhraseBook(name)) |
|
1182 |
statusBar()->showMessage(tr("Phrase book created."), MessageMS); |
|
1183 |
} |
|
1184 |
} |
|
1185 |
} |
|
1186 |
||
1187 |
bool MainWindow::isPhraseBookOpen(const QString &name) |
|
1188 |
{ |
|
1189 |
foreach(const PhraseBook *pb, m_phraseBooks) { |
|
1190 |
if (pb->fileName() == name) |
|
1191 |
return true; |
|
1192 |
} |
|
1193 |
||
1194 |
return false; |
|
1195 |
} |
|
1196 |
||
1197 |
void MainWindow::openPhraseBook() |
|
1198 |
{ |
|
1199 |
QString name = QFileDialog::getOpenFileName(this, tr("Open Phrase Book"), |
|
1200 |
m_phraseBookDir, tr("Qt phrase books (*.qph);;All files (*)")); |
|
1201 |
||
1202 |
if (!name.isEmpty()) { |
|
1203 |
m_phraseBookDir = QFileInfo(name).absolutePath(); |
|
1204 |
if (!isPhraseBookOpen(name)) { |
|
1205 |
if (PhraseBook *phraseBook = openPhraseBook(name)) { |
|
1206 |
int n = phraseBook->phrases().count(); |
|
1207 |
statusBar()->showMessage(tr("%n phrase(s) loaded.", 0, n), MessageMS); |
|
1208 |
} |
|
1209 |
} |
|
1210 |
} |
|
1211 |
} |
|
1212 |
||
1213 |
void MainWindow::closePhraseBook(QAction *action) |
|
1214 |
{ |
|
1215 |
PhraseBook *pb = m_phraseBookMenu[PhraseCloseMenu].value(action); |
|
1216 |
if (!maybeSavePhraseBook(pb)) |
|
1217 |
return; |
|
1218 |
||
1219 |
m_phraseBookMenu[PhraseCloseMenu].remove(action); |
|
1220 |
m_ui.menuClosePhraseBook->removeAction(action); |
|
1221 |
||
1222 |
QAction *act = m_phraseBookMenu[PhraseEditMenu].key(pb); |
|
1223 |
m_phraseBookMenu[PhraseEditMenu].remove(act); |
|
1224 |
m_ui.menuEditPhraseBook->removeAction(act); |
|
1225 |
||
1226 |
act = m_phraseBookMenu[PhrasePrintMenu].key(pb); |
|
1227 |
m_ui.menuPrintPhraseBook->removeAction(act); |
|
1228 |
||
1229 |
m_phraseBooks.removeOne(pb); |
|
1230 |
disconnect(pb, SIGNAL(listChanged()), this, SLOT(updatePhraseDicts())); |
|
1231 |
updatePhraseDicts(); |
|
1232 |
delete pb; |
|
1233 |
updatePhraseBookActions(); |
|
1234 |
} |
|
1235 |
||
1236 |
void MainWindow::editPhraseBook(QAction *action) |
|
1237 |
{ |
|
1238 |
PhraseBook *pb = m_phraseBookMenu[PhraseEditMenu].value(action); |
|
1239 |
PhraseBookBox box(pb, this); |
|
1240 |
box.exec(); |
|
1241 |
||
1242 |
updatePhraseDicts(); |
|
1243 |
} |
|
1244 |
||
1245 |
void MainWindow::printPhraseBook(QAction *action) |
|
1246 |
{ |
|
1247 |
PhraseBook *phraseBook = m_phraseBookMenu[PhrasePrintMenu].value(action); |
|
1248 |
||
1249 |
int pageNum = 0; |
|
1250 |
||
1251 |
QPrintDialog dlg(printer(), this); |
|
1252 |
if (dlg.exec()) { |
|
1253 |
printer()->setDocName(phraseBook->fileName()); |
|
1254 |
statusBar()->showMessage(tr("Printing...")); |
|
1255 |
PrintOut pout(printer()); |
|
1256 |
pout.setRule(PrintOut::ThinRule); |
|
1257 |
foreach (const Phrase *p, phraseBook->phrases()) { |
|
1258 |
pout.setGuide(p->source()); |
|
1259 |
pout.addBox(29, p->source()); |
|
1260 |
pout.addBox(4); |
|
1261 |
pout.addBox(29, p->target()); |
|
1262 |
pout.addBox(4); |
|
1263 |
pout.addBox(34, p->definition(), PrintOut::Emphasis); |
|
1264 |
||
1265 |
if (pout.pageNum() != pageNum) { |
|
1266 |
pageNum = pout.pageNum(); |
|
1267 |
statusBar()->showMessage(tr("Printing... (page %1)") |
|
1268 |
.arg(pageNum)); |
|
1269 |
} |
|
1270 |
pout.setRule(PrintOut::NoRule); |
|
1271 |
pout.flushLine(true); |
|
1272 |
} |
|
1273 |
pout.flushLine(true); |
|
1274 |
statusBar()->showMessage(tr("Printing completed"), MessageMS); |
|
1275 |
} else { |
|
1276 |
statusBar()->showMessage(tr("Printing aborted"), MessageMS); |
|
1277 |
} |
|
1278 |
} |
|
1279 |
||
1280 |
void MainWindow::addToPhraseBook() |
|
1281 |
{ |
|
1282 |
MessageItem *currentMessage = m_dataModel->messageItem(m_currentIndex); |
|
1283 |
Phrase *phrase = new Phrase(currentMessage->text(), currentMessage->translation(), QString()); |
|
1284 |
QStringList phraseBookList; |
|
1285 |
QHash<QString, PhraseBook *> phraseBookHash; |
|
1286 |
foreach (PhraseBook *pb, m_phraseBooks) { |
|
1287 |
if (pb->language() != QLocale::C && m_dataModel->language(m_currentIndex.model()) != QLocale::C) { |
|
1288 |
if (pb->language() != m_dataModel->language(m_currentIndex.model())) |
|
1289 |
continue; |
|
1290 |
if (pb->country() == m_dataModel->model(m_currentIndex.model())->country()) |
|
1291 |
phraseBookList.prepend(pb->friendlyPhraseBookName()); |
|
1292 |
else |
|
1293 |
phraseBookList.append(pb->friendlyPhraseBookName()); |
|
1294 |
} else { |
|
1295 |
phraseBookList.append(pb->friendlyPhraseBookName()); |
|
1296 |
} |
|
1297 |
phraseBookHash.insert(pb->friendlyPhraseBookName(), pb); |
|
1298 |
} |
|
1299 |
if (phraseBookList.isEmpty()) { |
|
1300 |
QMessageBox::warning(this, tr("Add to phrase book"), |
|
1301 |
tr("No appropriate phrasebook found.")); |
|
1302 |
} else if (phraseBookList.size() == 1) { |
|
1303 |
if (QMessageBox::information(this, tr("Add to phrase book"), |
|
1304 |
tr("Adding entry to phrasebook %1").arg(phraseBookList.at(0)), |
|
1305 |
QMessageBox::Ok | QMessageBox::Cancel, QMessageBox::Ok) |
|
1306 |
== QMessageBox::Ok) |
|
1307 |
phraseBookHash.value(phraseBookList.at(0))->append(phrase); |
|
1308 |
} else { |
|
1309 |
bool okPressed = false; |
|
1310 |
QString selection = QInputDialog::getItem(this, tr("Add to phrase book"), |
|
1311 |
tr("Select phrase book to add to"), |
|
1312 |
phraseBookList, 0, false, &okPressed); |
|
1313 |
if (okPressed) |
|
1314 |
phraseBookHash.value(selection)->append(phrase); |
|
1315 |
} |
|
1316 |
} |
|
1317 |
||
1318 |
void MainWindow::resetSorting() |
|
1319 |
{ |
|
1320 |
m_contextView->sortByColumn(-1, Qt::AscendingOrder); |
|
1321 |
m_messageView->sortByColumn(-1, Qt::AscendingOrder); |
|
1322 |
} |
|
1323 |
||
1324 |
void MainWindow::manual() |
|
1325 |
{ |
|
1326 |
if (!m_assistantProcess) |
|
1327 |
m_assistantProcess = new QProcess(); |
|
1328 |
||
1329 |
if (m_assistantProcess->state() != QProcess::Running) { |
|
1330 |
QString app = QLibraryInfo::location(QLibraryInfo::BinariesPath) + QDir::separator(); |
|
1331 |
#if !defined(Q_OS_MAC) |
|
1332 |
app += QLatin1String("assistant"); |
|
1333 |
#else |
|
1334 |
app += QLatin1String("Assistant.app/Contents/MacOS/Assistant"); |
|
1335 |
#endif |
|
1336 |
||
1337 |
m_assistantProcess->start(app, QStringList() << QLatin1String("-enableRemoteControl")); |
|
1338 |
if (!m_assistantProcess->waitForStarted()) { |
|
1339 |
QMessageBox::critical(this, tr("Qt Linguist"), |
|
1340 |
tr("Unable to launch Qt Assistant (%1)").arg(app)); |
|
1341 |
return; |
|
1342 |
} |
|
1343 |
} |
|
1344 |
||
1345 |
QTextStream str(m_assistantProcess); |
|
1346 |
str << QLatin1String("SetSource qthelp://com.trolltech.linguist.") |
|
1347 |
<< (QT_VERSION >> 16) << ((QT_VERSION >> 8) & 0xFF) |
|
1348 |
<< (QT_VERSION & 0xFF) |
|
1349 |
<< QLatin1String("/qdoc/linguist-manual.html") |
|
1350 |
<< QLatin1Char('\0') << endl; |
|
1351 |
} |
|
1352 |
||
1353 |
void MainWindow::about() |
|
1354 |
{ |
|
1355 |
QMessageBox box(this); |
|
1356 |
box.setTextFormat(Qt::RichText); |
|
1357 |
QString version = tr("Version %1"); |
|
1358 |
version = version.arg(QLatin1String(QT_VERSION_STR)); |
|
1359 |
||
1360 |
box.setText(tr("<center><img src=\":/images/splash.png\"/></img><p>%1</p></center>" |
|
1361 |
"<p>Qt Linguist is a tool for adding translations to Qt " |
|
1362 |
"applications.</p>" |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1363 |
"<p>Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)." |
0 | 1364 |
).arg(version)); |
1365 |
||
1366 |
box.setWindowTitle(QApplication::translate("AboutDialog", "Qt Linguist")); |
|
1367 |
box.setIcon(QMessageBox::NoIcon); |
|
1368 |
box.exec(); |
|
1369 |
} |
|
1370 |
||
1371 |
void MainWindow::aboutQt() |
|
1372 |
{ |
|
1373 |
QMessageBox::aboutQt(this, tr("Qt Linguist")); |
|
1374 |
} |
|
1375 |
||
1376 |
void MainWindow::setupPhrase() |
|
1377 |
{ |
|
1378 |
bool enabled = !m_phraseBooks.isEmpty(); |
|
1379 |
m_ui.menuClosePhraseBook->setEnabled(enabled); |
|
1380 |
m_ui.menuEditPhraseBook->setEnabled(enabled); |
|
1381 |
m_ui.menuPrintPhraseBook->setEnabled(enabled); |
|
1382 |
} |
|
1383 |
||
1384 |
void MainWindow::closeEvent(QCloseEvent *e) |
|
1385 |
{ |
|
1386 |
if (maybeSaveAll() && closePhraseBooks()) |
|
1387 |
e->accept(); |
|
1388 |
else |
|
1389 |
e->ignore(); |
|
1390 |
} |
|
1391 |
||
1392 |
bool MainWindow::maybeSaveAll() |
|
1393 |
{ |
|
1394 |
if (!m_dataModel->isModified()) |
|
1395 |
return true; |
|
1396 |
||
1397 |
switch (QMessageBox::information(this, tr("Qt Linguist"), |
|
1398 |
tr("Do you want to save the modified files?"), |
|
1399 |
QMessageBox::Yes | QMessageBox::Default, |
|
1400 |
QMessageBox::No, |
|
1401 |
QMessageBox::Cancel | QMessageBox::Escape)) |
|
1402 |
{ |
|
1403 |
case QMessageBox::Cancel: |
|
1404 |
return false; |
|
1405 |
case QMessageBox::Yes: |
|
1406 |
saveAll(); |
|
1407 |
return !m_dataModel->isModified(); |
|
1408 |
case QMessageBox::No: |
|
1409 |
break; |
|
1410 |
} |
|
1411 |
return true; |
|
1412 |
} |
|
1413 |
||
1414 |
bool MainWindow::maybeSave(int model) |
|
1415 |
{ |
|
1416 |
if (!m_dataModel->isModified(model)) |
|
1417 |
return true; |
|
1418 |
||
1419 |
switch (QMessageBox::information(this, tr("Qt Linguist"), |
|
1420 |
tr("Do you want to save '%1'?").arg(m_dataModel->srcFileName(model, true)), |
|
1421 |
QMessageBox::Yes | QMessageBox::Default, |
|
1422 |
QMessageBox::No, |
|
1423 |
QMessageBox::Cancel | QMessageBox::Escape)) |
|
1424 |
{ |
|
1425 |
case QMessageBox::Cancel: |
|
1426 |
return false; |
|
1427 |
case QMessageBox::Yes: |
|
1428 |
saveInternal(model); |
|
1429 |
return !m_dataModel->isModified(model); |
|
1430 |
case QMessageBox::No: |
|
1431 |
break; |
|
1432 |
} |
|
1433 |
return true; |
|
1434 |
} |
|
1435 |
||
1436 |
void MainWindow::updateCaption() |
|
1437 |
{ |
|
1438 |
QString cap; |
|
1439 |
bool enable = false; |
|
1440 |
bool enableRw = false; |
|
1441 |
for (int i = 0; i < m_dataModel->modelCount(); ++i) { |
|
1442 |
enable = true; |
|
1443 |
if (m_dataModel->isModelWritable(i)) { |
|
1444 |
enableRw = true; |
|
1445 |
break; |
|
1446 |
} |
|
1447 |
} |
|
1448 |
m_ui.actionSaveAll->setEnabled(enableRw); |
|
1449 |
m_ui.actionReleaseAll->setEnabled(enableRw); |
|
1450 |
m_ui.actionCloseAll->setEnabled(enable); |
|
1451 |
m_ui.actionPrint->setEnabled(enable); |
|
1452 |
m_ui.actionAccelerators->setEnabled(enable); |
|
1453 |
m_ui.actionEndingPunctuation->setEnabled(enable); |
|
1454 |
m_ui.actionPhraseMatches->setEnabled(enable); |
|
1455 |
m_ui.actionPlaceMarkerMatches->setEnabled(enable); |
|
1456 |
m_ui.actionResetSorting->setEnabled(enable); |
|
1457 |
||
1458 |
updateActiveModel(m_messageEditor->activeModel()); |
|
1459 |
// Ensure that the action labels get updated |
|
1460 |
m_fileActiveModel = m_editActiveModel = -2; |
|
1461 |
||
1462 |
if (!enable) |
|
1463 |
cap = tr("Qt Linguist[*]"); |
|
1464 |
else |
|
1465 |
cap = tr("%1[*] - Qt Linguist").arg(m_dataModel->condensedSrcFileNames(true)); |
|
1466 |
setWindowTitle(cap); |
|
1467 |
} |
|
1468 |
||
1469 |
void MainWindow::selectedContextChanged(const QModelIndex &sortedIndex, const QModelIndex &oldIndex) |
|
1470 |
{ |
|
1471 |
if (sortedIndex.isValid()) { |
|
1472 |
if (m_settingCurrentMessage) |
|
1473 |
return; // Avoid playing ping-pong with the current message |
|
1474 |
||
1475 |
QModelIndex sourceIndex = m_sortedContextsModel->mapToSource(sortedIndex); |
|
1476 |
if (m_messageModel->parent(currentMessageIndex()).row() == sourceIndex.row()) |
|
1477 |
return; |
|
1478 |
||
1479 |
QModelIndex contextIndex = setMessageViewRoot(sourceIndex); |
|
1480 |
const QModelIndex &firstChild = |
|
1481 |
m_sortedMessagesModel->index(0, sourceIndex.column(), contextIndex); |
|
1482 |
m_messageView->setCurrentIndex(firstChild); |
|
1483 |
} else if (oldIndex.isValid()) { |
|
1484 |
m_contextView->setCurrentIndex(oldIndex); |
|
1485 |
} |
|
1486 |
} |
|
1487 |
||
1488 |
/* |
|
1489 |
* Updates the message displayed in the message editor and related actions. |
|
1490 |
*/ |
|
1491 |
void MainWindow::selectedMessageChanged(const QModelIndex &sortedIndex, const QModelIndex &oldIndex) |
|
1492 |
{ |
|
1493 |
// Keep a valid selection whenever possible |
|
1494 |
if (!sortedIndex.isValid() && oldIndex.isValid()) { |
|
1495 |
m_messageView->setCurrentIndex(oldIndex); |
|
1496 |
return; |
|
1497 |
} |
|
1498 |
||
1499 |
QModelIndex index = m_sortedMessagesModel->mapToSource(sortedIndex); |
|
1500 |
if (index.isValid()) { |
|
1501 |
int model = (index.column() && (index.column() - 1 < m_dataModel->modelCount())) ? |
|
1502 |
index.column() - 1 : m_currentIndex.model(); |
|
1503 |
m_currentIndex = m_messageModel->dataIndex(index, model); |
|
1504 |
m_messageEditor->showMessage(m_currentIndex); |
|
1505 |
MessageItem *m = 0; |
|
1506 |
if (model >= 0 && (m = m_dataModel->messageItem(m_currentIndex))) { |
|
1507 |
if (m_dataModel->isModelWritable(model) && !m->isObsolete()) |
|
1508 |
m_phraseView->setSourceText(m_currentIndex.model(), m->text()); |
|
1509 |
else |
|
1510 |
m_phraseView->setSourceText(-1, QString()); |
|
1511 |
} else { |
|
1512 |
if (model < 0) { |
|
1513 |
model = m_dataModel->multiContextItem(m_currentIndex.context()) |
|
1514 |
->firstNonobsoleteMessageIndex(m_currentIndex.message()); |
|
1515 |
if (model >= 0) |
|
1516 |
m = m_dataModel->messageItem(m_currentIndex, model); |
|
1517 |
} |
|
1518 |
m_phraseView->setSourceText(-1, QString()); |
|
1519 |
} |
|
1520 |
if (m) { |
|
1521 |
if (hasFormPreview(m->fileName())) { |
|
1522 |
m_sourceAndFormView->setCurrentWidget(m_formPreviewView); |
|
1523 |
m_formPreviewView->setSourceContext(model, m); |
|
1524 |
} else { |
|
1525 |
m_sourceAndFormView->setCurrentWidget(m_sourceCodeView); |
|
1526 |
QDir dir = QFileInfo(m_dataModel->srcFileName(model)).dir(); |
|
1527 |
QString fileName = QDir::cleanPath(dir.absoluteFilePath(m->fileName())); |
|
1528 |
m_sourceCodeView->setSourceContext(fileName, m->lineNumber()); |
|
1529 |
} |
|
1530 |
m_errorsView->setEnabled(true); |
|
1531 |
} else { |
|
1532 |
m_sourceAndFormView->setCurrentWidget(m_sourceCodeView); |
|
1533 |
m_sourceCodeView->setSourceContext(QString(), 0); |
|
1534 |
m_errorsView->setEnabled(false); |
|
1535 |
} |
|
1536 |
updateDanger(m_currentIndex, true); |
|
1537 |
} else { |
|
1538 |
m_currentIndex = MultiDataIndex(); |
|
1539 |
m_messageEditor->showNothing(); |
|
1540 |
m_phraseView->setSourceText(-1, QString()); |
|
1541 |
m_sourceAndFormView->setCurrentWidget(m_sourceCodeView); |
|
1542 |
m_sourceCodeView->setSourceContext(QString(), 0); |
|
1543 |
} |
|
1544 |
||
1545 |
updatePhraseBookActions(); |
|
1546 |
m_ui.actionSelectAll->setEnabled(index.isValid()); |
|
1547 |
} |
|
1548 |
||
1549 |
void MainWindow::translationChanged(const MultiDataIndex &index) |
|
1550 |
{ |
|
1551 |
// We get that as a result of batch translation or search & translate, |
|
1552 |
// so the current model is known to match. |
|
1553 |
if (index != m_currentIndex) |
|
1554 |
return; |
|
1555 |
||
1556 |
m_messageEditor->showMessage(index); |
|
1557 |
updateDanger(index, true); |
|
1558 |
||
1559 |
MessageItem *m = m_dataModel->messageItem(index); |
|
1560 |
if (hasFormPreview(m->fileName())) |
|
1561 |
m_formPreviewView->setSourceContext(index.model(), m); |
|
1562 |
} |
|
1563 |
||
1564 |
// This and the following function operate directly on the messageitem, |
|
1565 |
// so the model does not emit modification notifications. |
|
1566 |
void MainWindow::updateTranslation(const QStringList &translations) |
|
1567 |
{ |
|
1568 |
MessageItem *m = m_dataModel->messageItem(m_currentIndex); |
|
1569 |
if (!m) |
|
1570 |
return; |
|
1571 |
if (translations == m->translations()) |
|
1572 |
return; |
|
1573 |
||
1574 |
m->setTranslations(translations); |
|
1575 |
if (hasFormPreview(m->fileName())) |
|
1576 |
m_formPreviewView->setSourceContext(m_currentIndex.model(), m); |
|
1577 |
updateDanger(m_currentIndex, true); |
|
1578 |
||
1579 |
if (m->isFinished()) |
|
1580 |
m_dataModel->setFinished(m_currentIndex, false); |
|
1581 |
else |
|
1582 |
m_dataModel->setModified(m_currentIndex.model(), true); |
|
1583 |
} |
|
1584 |
||
1585 |
void MainWindow::updateTranslatorComment(const QString &comment) |
|
1586 |
{ |
|
1587 |
MessageItem *m = m_dataModel->messageItem(m_currentIndex); |
|
1588 |
if (!m) |
|
1589 |
return; |
|
1590 |
if (comment == m->translatorComment()) |
|
1591 |
return; |
|
1592 |
||
1593 |
m->setTranslatorComment(comment); |
|
1594 |
||
1595 |
m_dataModel->setModified(m_currentIndex.model(), true); |
|
1596 |
} |
|
1597 |
||
1598 |
void MainWindow::refreshItemViews() |
|
1599 |
{ |
|
1600 |
m_messageModel->blockSignals(false); |
|
1601 |
m_contextView->update(); |
|
1602 |
m_messageView->update(); |
|
1603 |
setWindowModified(m_dataModel->isModified()); |
|
1604 |
m_modifiedLabel->setVisible(m_dataModel->isModified()); |
|
1605 |
updateStatistics(); |
|
1606 |
} |
|
1607 |
||
1608 |
void MainWindow::doneAndNext() |
|
1609 |
{ |
|
1610 |
int model = m_messageEditor->activeModel(); |
|
1611 |
if (model >= 0 && m_dataModel->isModelWritable(model)) |
|
1612 |
m_dataModel->setFinished(m_currentIndex, true); |
|
1613 |
||
1614 |
if (!m_messageEditor->focusNextUnfinished()) |
|
1615 |
nextUnfinished(); |
|
1616 |
} |
|
1617 |
||
1618 |
void MainWindow::toggleFinished(const QModelIndex &index) |
|
1619 |
{ |
|
1620 |
if (!index.isValid() || index.column() - 1 >= m_dataModel->modelCount() |
|
1621 |
|| !m_dataModel->isModelWritable(index.column() - 1) || index.parent() == QModelIndex()) |
|
1622 |
return; |
|
1623 |
||
1624 |
QModelIndex item = m_sortedMessagesModel->mapToSource(index); |
|
1625 |
MultiDataIndex dataIndex = m_messageModel->dataIndex(item); |
|
1626 |
MessageItem *m = m_dataModel->messageItem(dataIndex); |
|
1627 |
||
1628 |
if (!m || m->message().type() == TranslatorMessage::Obsolete) |
|
1629 |
return; |
|
1630 |
||
1631 |
m_dataModel->setFinished(dataIndex, !m->isFinished()); |
|
1632 |
} |
|
1633 |
||
1634 |
/* |
|
1635 |
* Receives a context index in the sorted messages model and returns the next |
|
1636 |
* logical context index in the same model, based on the sort order of the |
|
1637 |
* contexts in the sorted contexts model. |
|
1638 |
*/ |
|
1639 |
QModelIndex MainWindow::nextContext(const QModelIndex &index) const |
|
1640 |
{ |
|
1641 |
QModelIndex sortedContextIndex = m_sortedContextsModel->mapFromSource( |
|
1642 |
m_sortedMessagesModel->mapToSource(index)); |
|
1643 |
||
1644 |
int nextRow = sortedContextIndex.row() + 1; |
|
1645 |
if (nextRow >= m_sortedContextsModel->rowCount()) |
|
1646 |
nextRow = 0; |
|
1647 |
sortedContextIndex = m_sortedContextsModel->index(nextRow, index.column()); |
|
1648 |
||
1649 |
return m_sortedMessagesModel->mapFromSource( |
|
1650 |
m_sortedContextsModel->mapToSource(sortedContextIndex)); |
|
1651 |
} |
|
1652 |
||
1653 |
/* |
|
1654 |
* See nextContext. |
|
1655 |
*/ |
|
1656 |
QModelIndex MainWindow::prevContext(const QModelIndex &index) const |
|
1657 |
{ |
|
1658 |
QModelIndex sortedContextIndex = m_sortedContextsModel->mapFromSource( |
|
1659 |
m_sortedMessagesModel->mapToSource(index)); |
|
1660 |
||
1661 |
int prevRow = sortedContextIndex.row() - 1; |
|
1662 |
if (prevRow < 0) prevRow = m_sortedContextsModel->rowCount() - 1; |
|
1663 |
sortedContextIndex = m_sortedContextsModel->index(prevRow, index.column()); |
|
1664 |
||
1665 |
return m_sortedMessagesModel->mapFromSource( |
|
1666 |
m_sortedContextsModel->mapToSource(sortedContextIndex)); |
|
1667 |
} |
|
1668 |
||
1669 |
QModelIndex MainWindow::nextMessage(const QModelIndex ¤tIndex, bool checkUnfinished) const |
|
1670 |
{ |
|
1671 |
QModelIndex idx = currentIndex.isValid() ? currentIndex : m_sortedMessagesModel->index(0, 0); |
|
1672 |
do { |
|
1673 |
int row = 0; |
|
1674 |
QModelIndex par = idx.parent(); |
|
1675 |
if (par.isValid()) { |
|
1676 |
row = idx.row() + 1; |
|
1677 |
} else { // In case we are located on a top-level node |
|
1678 |
par = idx; |
|
1679 |
} |
|
1680 |
||
1681 |
if (row >= m_sortedMessagesModel->rowCount(par)) { |
|
1682 |
par = nextContext(par); |
|
1683 |
row = 0; |
|
1684 |
} |
|
1685 |
idx = m_sortedMessagesModel->index(row, idx.column(), par); |
|
1686 |
||
1687 |
if (!checkUnfinished) |
|
1688 |
return idx; |
|
1689 |
||
1690 |
QModelIndex item = m_sortedMessagesModel->mapToSource(idx); |
|
1691 |
MultiDataIndex index = m_messageModel->dataIndex(item, -1); |
|
1692 |
if (m_dataModel->multiMessageItem(index)->isUnfinished()) |
|
1693 |
return idx; |
|
1694 |
} while (idx != currentIndex); |
|
1695 |
return QModelIndex(); |
|
1696 |
} |
|
1697 |
||
1698 |
QModelIndex MainWindow::prevMessage(const QModelIndex ¤tIndex, bool checkUnfinished) const |
|
1699 |
{ |
|
1700 |
QModelIndex idx = currentIndex.isValid() ? currentIndex : m_sortedMessagesModel->index(0, 0); |
|
1701 |
do { |
|
1702 |
int row = idx.row() - 1; |
|
1703 |
QModelIndex par = idx.parent(); |
|
1704 |
if (!par.isValid()) { // In case we are located on a top-level node |
|
1705 |
par = idx; |
|
1706 |
row = -1; |
|
1707 |
} |
|
1708 |
||
1709 |
if (row < 0) { |
|
1710 |
par = prevContext(par); |
|
1711 |
row = m_sortedMessagesModel->rowCount(par) - 1; |
|
1712 |
} |
|
1713 |
idx = m_sortedMessagesModel->index(row, idx.column(), par); |
|
1714 |
||
1715 |
if (!checkUnfinished) |
|
1716 |
return idx; |
|
1717 |
||
1718 |
QModelIndex item = m_sortedMessagesModel->mapToSource(idx); |
|
1719 |
MultiDataIndex index = m_messageModel->dataIndex(item, -1); |
|
1720 |
if (m_dataModel->multiMessageItem(index)->isUnfinished()) |
|
1721 |
return idx; |
|
1722 |
} while (idx != currentIndex); |
|
1723 |
return QModelIndex(); |
|
1724 |
} |
|
1725 |
||
1726 |
void MainWindow::nextUnfinished() |
|
1727 |
{ |
|
1728 |
if (m_ui.actionNextUnfinished->isEnabled()) { |
|
1729 |
if (!next(true)) { |
|
1730 |
// If no Unfinished message is left, the user has finished the job. We |
|
1731 |
// congratulate on a job well done with this ringing bell. |
|
1732 |
statusBar()->showMessage(tr("No untranslated translation units left."), MessageMS); |
|
1733 |
qApp->beep(); |
|
1734 |
} |
|
1735 |
} |
|
1736 |
} |
|
1737 |
||
1738 |
void MainWindow::prevUnfinished() |
|
1739 |
{ |
|
1740 |
if (m_ui.actionNextUnfinished->isEnabled()) { |
|
1741 |
if (!prev(true)) { |
|
1742 |
// If no Unfinished message is left, the user has finished the job. We |
|
1743 |
// congratulate on a job well done with this ringing bell. |
|
1744 |
statusBar()->showMessage(tr("No untranslated translation units left."), MessageMS); |
|
1745 |
qApp->beep(); |
|
1746 |
} |
|
1747 |
} |
|
1748 |
} |
|
1749 |
||
1750 |
void MainWindow::prev() |
|
1751 |
{ |
|
1752 |
prev(false); |
|
1753 |
} |
|
1754 |
||
1755 |
void MainWindow::next() |
|
1756 |
{ |
|
1757 |
next(false); |
|
1758 |
} |
|
1759 |
||
1760 |
bool MainWindow::prev(bool checkUnfinished) |
|
1761 |
{ |
|
1762 |
QModelIndex index = prevMessage(m_messageView->currentIndex(), checkUnfinished); |
|
1763 |
if (index.isValid()) |
|
1764 |
setCurrentMessage(m_sortedMessagesModel->mapToSource(index)); |
|
1765 |
if (checkUnfinished) |
|
1766 |
m_messageEditor->setUnfinishedEditorFocus(); |
|
1767 |
else |
|
1768 |
m_messageEditor->setEditorFocus(); |
|
1769 |
return index.isValid(); |
|
1770 |
} |
|
1771 |
||
1772 |
bool MainWindow::next(bool checkUnfinished) |
|
1773 |
{ |
|
1774 |
QModelIndex index = nextMessage(m_messageView->currentIndex(), checkUnfinished); |
|
1775 |
if (index.isValid()) |
|
1776 |
setCurrentMessage(m_sortedMessagesModel->mapToSource(index)); |
|
1777 |
if (checkUnfinished) |
|
1778 |
m_messageEditor->setUnfinishedEditorFocus(); |
|
1779 |
else |
|
1780 |
m_messageEditor->setEditorFocus(); |
|
1781 |
return index.isValid(); |
|
1782 |
} |
|
1783 |
||
1784 |
void MainWindow::findNext(const QString &text, DataModel::FindLocation where, bool matchCase, bool ignoreAccelerators) |
|
1785 |
{ |
|
1786 |
if (text.isEmpty()) |
|
1787 |
return; |
|
1788 |
m_findText = text; |
|
1789 |
m_findWhere = where; |
|
1790 |
m_findMatchCase = matchCase ? Qt::CaseSensitive : Qt::CaseInsensitive; |
|
1791 |
m_findIgnoreAccelerators = ignoreAccelerators; |
|
1792 |
m_ui.actionFindNext->setEnabled(true); |
|
1793 |
findAgain(); |
|
1794 |
} |
|
1795 |
||
1796 |
void MainWindow::revalidate() |
|
1797 |
{ |
|
1798 |
for (MultiDataModelIterator it(m_dataModel, -1); it.isValid(); ++it) |
|
1799 |
updateDanger(it, false); |
|
1800 |
||
1801 |
if (m_currentIndex.isValid()) |
|
1802 |
updateDanger(m_currentIndex, true); |
|
1803 |
} |
|
1804 |
||
1805 |
QString MainWindow::friendlyString(const QString& str) |
|
1806 |
{ |
|
1807 |
QString f = str.toLower(); |
|
1808 |
f.replace(QRegExp(QString(QLatin1String("[.,:;!?()-]"))), QString(QLatin1String(" "))); |
|
1809 |
f.remove(QLatin1Char('&')); |
|
1810 |
return f.simplified(); |
|
1811 |
} |
|
1812 |
||
1813 |
void MainWindow::setupMenuBar() |
|
1814 |
{ |
|
1815 |
m_ui.actionAccelerators->setIcon(QIcon(resourcePrefix() + QLatin1String("/accelerator.png"))); |
|
1816 |
m_ui.actionOpenPhraseBook->setIcon(QIcon(resourcePrefix() + QLatin1String("/book.png"))); |
|
1817 |
m_ui.actionDoneAndNext->setIcon(QIcon(resourcePrefix() + QLatin1String("/doneandnext.png"))); |
|
1818 |
m_ui.actionCopy->setIcon(QIcon(resourcePrefix() + QLatin1String("/editcopy.png"))); |
|
1819 |
m_ui.actionCut->setIcon(QIcon(resourcePrefix() + QLatin1String("/editcut.png"))); |
|
1820 |
m_ui.actionPaste->setIcon(QIcon(resourcePrefix() + QLatin1String("/editpaste.png"))); |
|
1821 |
m_ui.actionOpen->setIcon(QIcon(resourcePrefix() + QLatin1String("/fileopen.png"))); |
|
1822 |
m_ui.actionOpenAux->setIcon(QIcon(resourcePrefix() + QLatin1String("/fileopen.png"))); |
|
1823 |
m_ui.actionSaveAll->setIcon(QIcon(resourcePrefix() + QLatin1String("/filesave.png"))); |
|
1824 |
m_ui.actionSave->setIcon(QIcon(resourcePrefix() + QLatin1String("/filesave.png"))); |
|
1825 |
m_ui.actionNext->setIcon(QIcon(resourcePrefix() + QLatin1String("/next.png"))); |
|
1826 |
m_ui.actionNextUnfinished->setIcon(QIcon(resourcePrefix() + QLatin1String("/nextunfinished.png"))); |
|
1827 |
m_ui.actionPhraseMatches->setIcon(QIcon(resourcePrefix() + QLatin1String("/phrase.png"))); |
|
1828 |
m_ui.actionEndingPunctuation->setIcon(QIcon(resourcePrefix() + QLatin1String("/punctuation.png"))); |
|
1829 |
m_ui.actionPrev->setIcon(QIcon(resourcePrefix() + QLatin1String("/prev.png"))); |
|
1830 |
m_ui.actionPrevUnfinished->setIcon(QIcon(resourcePrefix() + QLatin1String("/prevunfinished.png"))); |
|
1831 |
m_ui.actionPrint->setIcon(QIcon(resourcePrefix() + QLatin1String("/print.png"))); |
|
1832 |
m_ui.actionRedo->setIcon(QIcon(resourcePrefix() + QLatin1String("/redo.png"))); |
|
1833 |
m_ui.actionFind->setIcon(QIcon(resourcePrefix() + QLatin1String("/searchfind.png"))); |
|
1834 |
m_ui.actionUndo->setIcon(QIcon(resourcePrefix() + QLatin1String("/undo.png"))); |
|
1835 |
m_ui.actionPlaceMarkerMatches->setIcon(QIcon(resourcePrefix() + QLatin1String("/validateplacemarkers.png"))); |
|
1836 |
m_ui.actionWhatsThis->setIcon(QIcon(resourcePrefix() + QLatin1String("/whatsthis.png"))); |
|
1837 |
||
1838 |
// File menu |
|
1839 |
connect(m_ui.menuFile, SIGNAL(aboutToShow()), SLOT(fileAboutToShow())); |
|
1840 |
connect(m_ui.actionOpen, SIGNAL(triggered()), this, SLOT(open())); |
|
1841 |
connect(m_ui.actionOpenAux, SIGNAL(triggered()), this, SLOT(openAux())); |
|
1842 |
connect(m_ui.actionSaveAll, SIGNAL(triggered()), this, SLOT(saveAll())); |
|
1843 |
connect(m_ui.actionSave, SIGNAL(triggered()), this, SLOT(save())); |
|
1844 |
connect(m_ui.actionSaveAs, SIGNAL(triggered()), this, SLOT(saveAs())); |
|
1845 |
connect(m_ui.actionReleaseAll, SIGNAL(triggered()), this, SLOT(releaseAll())); |
|
1846 |
connect(m_ui.actionRelease, SIGNAL(triggered()), this, SLOT(release())); |
|
1847 |
connect(m_ui.actionReleaseAs, SIGNAL(triggered()), this, SLOT(releaseAs())); |
|
1848 |
connect(m_ui.actionPrint, SIGNAL(triggered()), this, SLOT(print())); |
|
1849 |
connect(m_ui.actionClose, SIGNAL(triggered()), this, SLOT(closeFile())); |
|
1850 |
connect(m_ui.actionCloseAll, SIGNAL(triggered()), this, SLOT(closeAll())); |
|
1851 |
connect(m_ui.actionExit, SIGNAL(triggered()), this, SLOT(close())); |
|
1852 |
||
1853 |
// Edit menu |
|
1854 |
connect(m_ui.menuEdit, SIGNAL(aboutToShow()), SLOT(editAboutToShow())); |
|
1855 |
||
1856 |
connect(m_ui.actionUndo, SIGNAL(triggered()), m_messageEditor, SLOT(undo())); |
|
1857 |
connect(m_messageEditor, SIGNAL(undoAvailable(bool)), m_ui.actionUndo, SLOT(setEnabled(bool))); |
|
1858 |
||
1859 |
connect(m_ui.actionRedo, SIGNAL(triggered()), m_messageEditor, SLOT(redo())); |
|
1860 |
connect(m_messageEditor, SIGNAL(redoAvailable(bool)), m_ui.actionRedo, SLOT(setEnabled(bool))); |
|
1861 |
||
1862 |
connect(m_ui.actionCopy, SIGNAL(triggered()), m_messageEditor, SLOT(copy())); |
|
1863 |
connect(m_messageEditor, SIGNAL(copyAvailable(bool)), m_ui.actionCopy, SLOT(setEnabled(bool))); |
|
1864 |
||
1865 |
connect(m_messageEditor, SIGNAL(cutAvailable(bool)), m_ui.actionCut, SLOT(setEnabled(bool))); |
|
1866 |
connect(m_ui.actionCut, SIGNAL(triggered()), m_messageEditor, SLOT(cut())); |
|
1867 |
||
1868 |
connect(m_messageEditor, SIGNAL(pasteAvailable(bool)), m_ui.actionPaste, SLOT(setEnabled(bool))); |
|
1869 |
connect(m_ui.actionPaste, SIGNAL(triggered()), m_messageEditor, SLOT(paste())); |
|
1870 |
||
1871 |
connect(m_ui.actionSelectAll, SIGNAL(triggered()), m_messageEditor, SLOT(selectAll())); |
|
1872 |
connect(m_ui.actionFind, SIGNAL(triggered()), m_findDialog, SLOT(find())); |
|
1873 |
connect(m_ui.actionFindNext, SIGNAL(triggered()), this, SLOT(findAgain())); |
|
1874 |
connect(m_ui.actionSearchAndTranslate, SIGNAL(triggered()), this, SLOT(showTranslateDialog())); |
|
1875 |
connect(m_ui.actionBatchTranslation, SIGNAL(triggered()), this, SLOT(showBatchTranslateDialog())); |
|
1876 |
connect(m_ui.actionTranslationFileSettings, SIGNAL(triggered()), this, SLOT(showTranslationSettings())); |
|
1877 |
||
1878 |
connect(m_batchTranslateDialog, SIGNAL(finished()), SLOT(refreshItemViews())); |
|
1879 |
||
1880 |
// Translation menu |
|
1881 |
// when updating the accelerators, remember the status bar |
|
1882 |
connect(m_ui.actionPrevUnfinished, SIGNAL(triggered()), this, SLOT(prevUnfinished())); |
|
1883 |
connect(m_ui.actionNextUnfinished, SIGNAL(triggered()), this, SLOT(nextUnfinished())); |
|
1884 |
connect(m_ui.actionNext, SIGNAL(triggered()), this, SLOT(next())); |
|
1885 |
connect(m_ui.actionPrev, SIGNAL(triggered()), this, SLOT(prev())); |
|
1886 |
connect(m_ui.actionDoneAndNext, SIGNAL(triggered()), this, SLOT(doneAndNext())); |
|
1887 |
connect(m_ui.actionBeginFromSource, SIGNAL(triggered()), m_messageEditor, SLOT(beginFromSource())); |
|
1888 |
connect(m_messageEditor, SIGNAL(beginFromSourceAvailable(bool)), m_ui.actionBeginFromSource, SLOT(setEnabled(bool))); |
|
1889 |
||
1890 |
// Phrasebook menu |
|
1891 |
connect(m_ui.actionNewPhraseBook, SIGNAL(triggered()), this, SLOT(newPhraseBook())); |
|
1892 |
connect(m_ui.actionOpenPhraseBook, SIGNAL(triggered()), this, SLOT(openPhraseBook())); |
|
1893 |
connect(m_ui.menuClosePhraseBook, SIGNAL(triggered(QAction*)), |
|
1894 |
this, SLOT(closePhraseBook(QAction*))); |
|
1895 |
connect(m_ui.menuEditPhraseBook, SIGNAL(triggered(QAction*)), |
|
1896 |
this, SLOT(editPhraseBook(QAction*))); |
|
1897 |
connect(m_ui.menuPrintPhraseBook, SIGNAL(triggered(QAction*)), |
|
1898 |
this, SLOT(printPhraseBook(QAction*))); |
|
1899 |
connect(m_ui.actionAddToPhraseBook, SIGNAL(triggered()), this, SLOT(addToPhraseBook())); |
|
1900 |
||
1901 |
// Validation menu |
|
1902 |
connect(m_ui.actionAccelerators, SIGNAL(triggered()), this, SLOT(revalidate())); |
|
1903 |
connect(m_ui.actionEndingPunctuation, SIGNAL(triggered()), this, SLOT(revalidate())); |
|
1904 |
connect(m_ui.actionPhraseMatches, SIGNAL(triggered()), this, SLOT(revalidate())); |
|
1905 |
connect(m_ui.actionPlaceMarkerMatches, SIGNAL(triggered()), this, SLOT(revalidate())); |
|
1906 |
||
1907 |
// View menu |
|
1908 |
connect(m_ui.actionResetSorting, SIGNAL(triggered()), this, SLOT(resetSorting())); |
|
1909 |
connect(m_ui.actionDisplayGuesses, SIGNAL(triggered()), m_phraseView, SLOT(toggleGuessing())); |
|
1910 |
connect(m_ui.actionStatistics, SIGNAL(triggered()), this, SLOT(toggleStatistics())); |
|
1911 |
connect(m_ui.menuView, SIGNAL(aboutToShow()), this, SLOT(updateViewMenu())); |
|
1912 |
m_ui.menuViewViews->addAction(m_contextDock->toggleViewAction()); |
|
1913 |
m_ui.menuViewViews->addAction(m_messagesDock->toggleViewAction()); |
|
1914 |
m_ui.menuViewViews->addAction(m_phrasesDock->toggleViewAction()); |
|
1915 |
m_ui.menuViewViews->addAction(m_sourceAndFormDock->toggleViewAction()); |
|
1916 |
m_ui.menuViewViews->addAction(m_errorsDock->toggleViewAction()); |
|
1917 |
||
1918 |
#if defined(Q_WS_MAC) |
|
1919 |
// Window menu |
|
1920 |
QMenu *windowMenu = new QMenu(tr("&Window"), this); |
|
1921 |
menuBar()->insertMenu(m_ui.menuHelp->menuAction(), windowMenu); |
|
1922 |
windowMenu->addAction(tr("Minimize"), this, |
|
1923 |
SLOT(showMinimized()), QKeySequence(tr("Ctrl+M"))); |
|
1924 |
#endif |
|
1925 |
||
1926 |
// Help |
|
1927 |
connect(m_ui.actionManual, SIGNAL(triggered()), this, SLOT(manual())); |
|
1928 |
connect(m_ui.actionAbout, SIGNAL(triggered()), this, SLOT(about())); |
|
1929 |
connect(m_ui.actionAboutQt, SIGNAL(triggered()), this, SLOT(aboutQt())); |
|
1930 |
connect(m_ui.actionWhatsThis, SIGNAL(triggered()), this, SLOT(onWhatsThis())); |
|
1931 |
||
1932 |
connect(m_ui.menuRecentlyOpenedFiles, SIGNAL(triggered(QAction*)), this, |
|
1933 |
SLOT(recentFileActivated(QAction*))); |
|
1934 |
||
1935 |
m_ui.actionManual->setWhatsThis(tr("Display the manual for %1.").arg(tr("Qt Linguist"))); |
|
1936 |
m_ui.actionAbout->setWhatsThis(tr("Display information about %1.").arg(tr("Qt Linguist"))); |
|
1937 |
m_ui.actionDoneAndNext->setShortcuts(QList<QKeySequence>() |
|
1938 |
<< QKeySequence(QLatin1String("Ctrl+Return")) |
|
1939 |
<< QKeySequence(QLatin1String("Ctrl+Enter"))); |
|
1940 |
||
1941 |
// Disable the Close/Edit/Print phrasebook menuitems if they are not loaded |
|
1942 |
connect(m_ui.menuPhrases, SIGNAL(aboutToShow()), this, SLOT(setupPhrase())); |
|
1943 |
||
1944 |
connect(m_ui.menuRecentlyOpenedFiles, SIGNAL(aboutToShow()), SLOT(setupRecentFilesMenu())); |
|
1945 |
} |
|
1946 |
||
1947 |
void MainWindow::updateActiveModel(int model) |
|
1948 |
{ |
|
1949 |
if (model >= 0) |
|
1950 |
updateLatestModel(model); |
|
1951 |
} |
|
1952 |
||
1953 |
// Arriving here implies that the messageEditor does not have focus |
|
1954 |
void MainWindow::updateLatestModel(const QModelIndex &index) |
|
1955 |
{ |
|
1956 |
if (index.column() && (index.column() - 1 < m_dataModel->modelCount())) |
|
1957 |
updateLatestModel(index.column() - 1); |
|
1958 |
} |
|
1959 |
||
1960 |
void MainWindow::updateLatestModel(int model) |
|
1961 |
{ |
|
1962 |
m_currentIndex = MultiDataIndex(model, m_currentIndex.context(), m_currentIndex.message()); |
|
1963 |
bool enable = false; |
|
1964 |
bool enableRw = false; |
|
1965 |
if (model >= 0) { |
|
1966 |
enable = true; |
|
1967 |
if (m_dataModel->isModelWritable(model)) |
|
1968 |
enableRw = true; |
|
1969 |
||
1970 |
if (m_currentIndex.isValid()) { |
|
1971 |
if (MessageItem *item = m_dataModel->messageItem(m_currentIndex)) { |
|
1972 |
if (hasFormPreview(item->fileName())) |
|
1973 |
m_formPreviewView->setSourceContext(model, item); |
|
1974 |
if (enableRw && !item->isObsolete()) |
|
1975 |
m_phraseView->setSourceText(model, item->text()); |
|
1976 |
else |
|
1977 |
m_phraseView->setSourceText(-1, QString()); |
|
1978 |
} else { |
|
1979 |
m_phraseView->setSourceText(-1, QString()); |
|
1980 |
} |
|
1981 |
} |
|
1982 |
} |
|
1983 |
m_ui.actionSave->setEnabled(enableRw); |
|
1984 |
m_ui.actionSaveAs->setEnabled(enableRw); |
|
1985 |
m_ui.actionRelease->setEnabled(enableRw); |
|
1986 |
m_ui.actionReleaseAs->setEnabled(enableRw); |
|
1987 |
m_ui.actionClose->setEnabled(enable); |
|
1988 |
m_ui.actionTranslationFileSettings->setEnabled(enableRw); |
|
1989 |
m_ui.actionSearchAndTranslate->setEnabled(enableRw); |
|
1990 |
// cut & paste - edit only |
|
1991 |
updatePhraseBookActions(); |
|
1992 |
updateStatistics(); |
|
1993 |
} |
|
1994 |
||
1995 |
// Note for *AboutToShow: Due to the delayed nature, only actions without shortcuts |
|
1996 |
// and representations outside the menu may be setEnabled()/setVisible() here. |
|
1997 |
||
1998 |
void MainWindow::fileAboutToShow() |
|
1999 |
{ |
|
2000 |
if (m_fileActiveModel != m_currentIndex.model()) { |
|
2001 |
// We rename the actions so the shortcuts need not be reassigned. |
|
2002 |
bool en; |
|
2003 |
if (m_dataModel->modelCount() > 1) { |
|
2004 |
if (m_currentIndex.model() >= 0) { |
|
2005 |
QString fn = QFileInfo(m_dataModel->srcFileName(m_currentIndex.model())).baseName(); |
|
2006 |
m_ui.actionSave->setText(tr("&Save '%1'").arg(fn)); |
|
2007 |
m_ui.actionSaveAs->setText(tr("Save '%1' &As...").arg(fn)); |
|
2008 |
m_ui.actionRelease->setText(tr("Release '%1'").arg(fn)); |
|
2009 |
m_ui.actionReleaseAs->setText(tr("Release '%1' As...").arg(fn)); |
|
2010 |
m_ui.actionClose->setText(tr("&Close '%1'").arg(fn)); |
|
2011 |
} else { |
|
2012 |
m_ui.actionSave->setText(tr("&Save")); |
|
2013 |
m_ui.actionSaveAs->setText(tr("Save &As...")); |
|
2014 |
m_ui.actionRelease->setText(tr("Release")); |
|
2015 |
m_ui.actionReleaseAs->setText(tr("Release As...")); |
|
2016 |
m_ui.actionClose->setText(tr("&Close")); |
|
2017 |
} |
|
2018 |
||
2019 |
m_ui.actionSaveAll->setText(tr("Save All")); |
|
2020 |
m_ui.actionReleaseAll->setText(tr("&Release All")); |
|
2021 |
m_ui.actionCloseAll->setText(tr("Close All")); |
|
2022 |
en = true; |
|
2023 |
} else { |
|
2024 |
m_ui.actionSaveAs->setText(tr("Save &As...")); |
|
2025 |
m_ui.actionReleaseAs->setText(tr("Release As...")); |
|
2026 |
||
2027 |
m_ui.actionSaveAll->setText(tr("&Save")); |
|
2028 |
m_ui.actionReleaseAll->setText(tr("&Release")); |
|
2029 |
m_ui.actionCloseAll->setText(tr("&Close")); |
|
2030 |
en = false; |
|
2031 |
} |
|
2032 |
m_ui.actionSave->setVisible(en); |
|
2033 |
m_ui.actionRelease->setVisible(en); |
|
2034 |
m_ui.actionClose->setVisible(en); |
|
2035 |
m_fileActiveModel = m_currentIndex.model(); |
|
2036 |
} |
|
2037 |
} |
|
2038 |
||
2039 |
void MainWindow::editAboutToShow() |
|
2040 |
{ |
|
2041 |
if (m_editActiveModel != m_currentIndex.model()) { |
|
2042 |
if (m_currentIndex.model() >= 0 && m_dataModel->modelCount() > 1) { |
|
2043 |
QString fn = QFileInfo(m_dataModel->srcFileName(m_currentIndex.model())).baseName(); |
|
2044 |
m_ui.actionTranslationFileSettings->setText(tr("Translation File &Settings for '%1'...").arg(fn)); |
|
2045 |
m_ui.actionBatchTranslation->setText(tr("&Batch Translation of '%1'...").arg(fn)); |
|
2046 |
m_ui.actionSearchAndTranslate->setText(tr("Search And &Translate in '%1'...").arg(fn)); |
|
2047 |
} else { |
|
2048 |
m_ui.actionTranslationFileSettings->setText(tr("Translation File &Settings...")); |
|
2049 |
m_ui.actionBatchTranslation->setText(tr("&Batch Translation...")); |
|
2050 |
m_ui.actionSearchAndTranslate->setText(tr("Search And &Translate...")); |
|
2051 |
} |
|
2052 |
m_editActiveModel = m_currentIndex.model(); |
|
2053 |
} |
|
2054 |
} |
|
2055 |
||
2056 |
void MainWindow::updateViewMenu() |
|
2057 |
{ |
|
2058 |
bool check = m_statistics ? m_statistics->isVisible() : false; |
|
2059 |
m_ui.actionStatistics->setChecked(check); |
|
2060 |
} |
|
2061 |
||
2062 |
void MainWindow::showContextDock() |
|
2063 |
{ |
|
2064 |
m_contextDock->show(); |
|
2065 |
m_contextDock->raise(); |
|
2066 |
} |
|
2067 |
||
2068 |
void MainWindow::showMessagesDock() |
|
2069 |
{ |
|
2070 |
m_messagesDock->show(); |
|
2071 |
m_messagesDock->raise(); |
|
2072 |
} |
|
2073 |
||
2074 |
void MainWindow::showPhrasesDock() |
|
2075 |
{ |
|
2076 |
m_phrasesDock->show(); |
|
2077 |
m_phrasesDock->raise(); |
|
2078 |
} |
|
2079 |
||
2080 |
void MainWindow::showSourceCodeDock() |
|
2081 |
{ |
|
2082 |
m_sourceAndFormDock->show(); |
|
2083 |
m_sourceAndFormDock->raise(); |
|
2084 |
} |
|
2085 |
||
2086 |
void MainWindow::showErrorDock() |
|
2087 |
{ |
|
2088 |
m_errorsDock->show(); |
|
2089 |
m_errorsDock->raise(); |
|
2090 |
} |
|
2091 |
||
2092 |
void MainWindow::onWhatsThis() |
|
2093 |
{ |
|
2094 |
QWhatsThis::enterWhatsThisMode(); |
|
2095 |
} |
|
2096 |
||
2097 |
void MainWindow::setupToolBars() |
|
2098 |
{ |
|
2099 |
QToolBar *filet = new QToolBar(this); |
|
2100 |
filet->setObjectName(QLatin1String("FileToolbar")); |
|
2101 |
filet->setWindowTitle(tr("File")); |
|
2102 |
this->addToolBar(filet); |
|
2103 |
m_ui.menuToolbars->addAction(filet->toggleViewAction()); |
|
2104 |
||
2105 |
QToolBar *editt = new QToolBar(this); |
|
2106 |
editt->setVisible(false); |
|
2107 |
editt->setObjectName(QLatin1String("EditToolbar")); |
|
2108 |
editt->setWindowTitle(tr("Edit")); |
|
2109 |
this->addToolBar(editt); |
|
2110 |
m_ui.menuToolbars->addAction(editt->toggleViewAction()); |
|
2111 |
||
2112 |
QToolBar *translationst = new QToolBar(this); |
|
2113 |
translationst->setObjectName(QLatin1String("TranslationToolbar")); |
|
2114 |
translationst->setWindowTitle(tr("Translation")); |
|
2115 |
this->addToolBar(translationst); |
|
2116 |
m_ui.menuToolbars->addAction(translationst->toggleViewAction()); |
|
2117 |
||
2118 |
QToolBar *validationt = new QToolBar(this); |
|
2119 |
validationt->setObjectName(QLatin1String("ValidationToolbar")); |
|
2120 |
validationt->setWindowTitle(tr("Validation")); |
|
2121 |
this->addToolBar(validationt); |
|
2122 |
m_ui.menuToolbars->addAction(validationt->toggleViewAction()); |
|
2123 |
||
2124 |
QToolBar *helpt = new QToolBar(this); |
|
2125 |
helpt->setVisible(false); |
|
2126 |
helpt->setObjectName(QLatin1String("HelpToolbar")); |
|
2127 |
helpt->setWindowTitle(tr("Help")); |
|
2128 |
this->addToolBar(helpt); |
|
2129 |
m_ui.menuToolbars->addAction(helpt->toggleViewAction()); |
|
2130 |
||
2131 |
||
2132 |
filet->addAction(m_ui.actionOpen); |
|
2133 |
filet->addAction(m_ui.actionSaveAll); |
|
2134 |
filet->addAction(m_ui.actionPrint); |
|
2135 |
filet->addSeparator(); |
|
2136 |
filet->addAction(m_ui.actionOpenPhraseBook); |
|
2137 |
||
2138 |
editt->addAction(m_ui.actionUndo); |
|
2139 |
editt->addAction(m_ui.actionRedo); |
|
2140 |
editt->addSeparator(); |
|
2141 |
editt->addAction(m_ui.actionCut); |
|
2142 |
editt->addAction(m_ui.actionCopy); |
|
2143 |
editt->addAction(m_ui.actionPaste); |
|
2144 |
editt->addSeparator(); |
|
2145 |
editt->addAction(m_ui.actionFind); |
|
2146 |
||
2147 |
translationst->addAction(m_ui.actionPrev); |
|
2148 |
translationst->addAction(m_ui.actionNext); |
|
2149 |
translationst->addAction(m_ui.actionPrevUnfinished); |
|
2150 |
translationst->addAction(m_ui.actionNextUnfinished); |
|
2151 |
translationst->addAction(m_ui.actionDoneAndNext); |
|
2152 |
||
2153 |
validationt->addAction(m_ui.actionAccelerators); |
|
2154 |
validationt->addAction(m_ui.actionEndingPunctuation); |
|
2155 |
validationt->addAction(m_ui.actionPhraseMatches); |
|
2156 |
validationt->addAction(m_ui.actionPlaceMarkerMatches); |
|
2157 |
||
2158 |
helpt->addAction(m_ui.actionWhatsThis); |
|
2159 |
} |
|
2160 |
||
2161 |
QModelIndex MainWindow::setMessageViewRoot(const QModelIndex &index) |
|
2162 |
{ |
|
2163 |
const QModelIndex &sortedContextIndex = m_sortedMessagesModel->mapFromSource(index); |
|
2164 |
const QModelIndex &trueContextIndex = m_sortedMessagesModel->index(sortedContextIndex.row(), 0); |
|
2165 |
if (m_messageView->rootIndex() != trueContextIndex) |
|
2166 |
m_messageView->setRootIndex(trueContextIndex); |
|
2167 |
return trueContextIndex; |
|
2168 |
} |
|
2169 |
||
2170 |
/* |
|
2171 |
* Updates the selected entries in the context and message views. |
|
2172 |
*/ |
|
2173 |
void MainWindow::setCurrentMessage(const QModelIndex &index) |
|
2174 |
{ |
|
2175 |
const QModelIndex &contextIndex = m_messageModel->parent(index); |
|
2176 |
if (!contextIndex.isValid()) |
|
2177 |
return; |
|
2178 |
||
2179 |
const QModelIndex &trueIndex = m_messageModel->index(contextIndex.row(), index.column(), QModelIndex()); |
|
2180 |
m_settingCurrentMessage = true; |
|
2181 |
m_contextView->setCurrentIndex(m_sortedContextsModel->mapFromSource(trueIndex)); |
|
2182 |
m_settingCurrentMessage = false; |
|
2183 |
||
2184 |
setMessageViewRoot(contextIndex); |
|
2185 |
m_messageView->setCurrentIndex(m_sortedMessagesModel->mapFromSource(index)); |
|
2186 |
} |
|
2187 |
||
2188 |
void MainWindow::setCurrentMessage(const QModelIndex &index, int model) |
|
2189 |
{ |
|
2190 |
const QModelIndex &theIndex = m_messageModel->index(index.row(), model + 1, index.parent()); |
|
2191 |
setCurrentMessage(theIndex); |
|
2192 |
m_messageEditor->setEditorFocus(model); |
|
2193 |
} |
|
2194 |
||
2195 |
QModelIndex MainWindow::currentContextIndex() const |
|
2196 |
{ |
|
2197 |
return m_sortedContextsModel->mapToSource(m_contextView->currentIndex()); |
|
2198 |
} |
|
2199 |
||
2200 |
QModelIndex MainWindow::currentMessageIndex() const |
|
2201 |
{ |
|
2202 |
return m_sortedMessagesModel->mapToSource(m_messageView->currentIndex()); |
|
2203 |
} |
|
2204 |
||
2205 |
PhraseBook *MainWindow::openPhraseBook(const QString& name) |
|
2206 |
{ |
|
2207 |
PhraseBook *pb = new PhraseBook(); |
|
2208 |
bool langGuessed; |
|
2209 |
if (!pb->load(name, &langGuessed)) { |
|
2210 |
QMessageBox::warning(this, tr("Qt Linguist"), |
|
2211 |
tr("Cannot read from phrase book '%1'.").arg(name)); |
|
2212 |
delete pb; |
|
2213 |
return 0; |
|
2214 |
} |
|
2215 |
if (langGuessed) { |
|
2216 |
if (!m_translationSettingsDialog) |
|
2217 |
m_translationSettingsDialog = new TranslationSettingsDialog(this); |
|
2218 |
m_translationSettingsDialog->setPhraseBook(pb); |
|
2219 |
m_translationSettingsDialog->exec(); |
|
2220 |
} |
|
2221 |
||
2222 |
m_phraseBooks.append(pb); |
|
2223 |
||
2224 |
QAction *a = m_ui.menuClosePhraseBook->addAction(pb->friendlyPhraseBookName()); |
|
2225 |
m_phraseBookMenu[PhraseCloseMenu].insert(a, pb); |
|
2226 |
a->setWhatsThis(tr("Close this phrase book.")); |
|
2227 |
||
2228 |
a = m_ui.menuEditPhraseBook->addAction(pb->friendlyPhraseBookName()); |
|
2229 |
m_phraseBookMenu[PhraseEditMenu].insert(a, pb); |
|
2230 |
a->setWhatsThis(tr("Enables you to add, modify, or delete" |
|
2231 |
" entries in this phrase book.")); |
|
2232 |
||
2233 |
a = m_ui.menuPrintPhraseBook->addAction(pb->friendlyPhraseBookName()); |
|
2234 |
m_phraseBookMenu[PhrasePrintMenu].insert(a, pb); |
|
2235 |
a->setWhatsThis(tr("Print the entries in this phrase book.")); |
|
2236 |
||
2237 |
connect(pb, SIGNAL(listChanged()), this, SLOT(updatePhraseDicts())); |
|
2238 |
updatePhraseDicts(); |
|
2239 |
updatePhraseBookActions(); |
|
2240 |
||
2241 |
return pb; |
|
2242 |
} |
|
2243 |
||
2244 |
bool MainWindow::savePhraseBook(QString *name, PhraseBook &pb) |
|
2245 |
{ |
|
2246 |
if (!name->contains(QLatin1Char('.'))) |
|
2247 |
*name += QLatin1String(".qph"); |
|
2248 |
||
2249 |
if (!pb.save(*name)) { |
|
2250 |
QMessageBox::warning(this, tr("Qt Linguist"), |
|
2251 |
tr("Cannot create phrase book '%1'.").arg(*name)); |
|
2252 |
return false; |
|
2253 |
} |
|
2254 |
return true; |
|
2255 |
} |
|
2256 |
||
2257 |
bool MainWindow::maybeSavePhraseBook(PhraseBook *pb) |
|
2258 |
{ |
|
2259 |
if (pb->isModified()) |
|
2260 |
switch (QMessageBox::information(this, tr("Qt Linguist"), |
|
2261 |
tr("Do you want to save phrase book '%1'?").arg(pb->friendlyPhraseBookName()), |
|
2262 |
QMessageBox::Yes | QMessageBox::Default, |
|
2263 |
QMessageBox::No, |
|
2264 |
QMessageBox::Cancel | QMessageBox::Escape)) |
|
2265 |
{ |
|
2266 |
case QMessageBox::Cancel: |
|
2267 |
return false; |
|
2268 |
case QMessageBox::Yes: |
|
2269 |
if (!pb->save(pb->fileName())) |
|
2270 |
return false; |
|
2271 |
break; |
|
2272 |
case QMessageBox::No: |
|
2273 |
break; |
|
2274 |
} |
|
2275 |
return true; |
|
2276 |
} |
|
2277 |
||
2278 |
bool MainWindow::closePhraseBooks() |
|
2279 |
{ |
|
2280 |
foreach(PhraseBook *phraseBook, m_phraseBooks) |
|
2281 |
if (!maybeSavePhraseBook(phraseBook)) |
|
2282 |
return false; |
|
2283 |
return true; |
|
2284 |
} |
|
2285 |
||
2286 |
void MainWindow::updateProgress() |
|
2287 |
{ |
|
2288 |
int numEditable = m_dataModel->getNumEditable(); |
|
2289 |
int numFinished = m_dataModel->getNumFinished(); |
|
2290 |
if (!m_dataModel->modelCount()) |
|
2291 |
m_progressLabel->setText(QString(QLatin1String(" "))); |
|
2292 |
else |
|
2293 |
m_progressLabel->setText(QString(QLatin1String(" %1/%2 ")) |
|
2294 |
.arg(numFinished).arg(numEditable)); |
|
2295 |
bool enable = numFinished != numEditable; |
|
2296 |
m_ui.actionPrevUnfinished->setEnabled(enable); |
|
2297 |
m_ui.actionNextUnfinished->setEnabled(enable); |
|
2298 |
m_ui.actionDoneAndNext->setEnabled(enable); |
|
2299 |
||
2300 |
m_ui.actionPrev->setEnabled(m_dataModel->contextCount() > 0); |
|
2301 |
m_ui.actionNext->setEnabled(m_dataModel->contextCount() > 0); |
|
2302 |
} |
|
2303 |
||
2304 |
void MainWindow::updatePhraseBookActions() |
|
2305 |
{ |
|
2306 |
bool phraseBookLoaded = (m_currentIndex.model() >= 0) && !m_phraseBooks.isEmpty(); |
|
2307 |
m_ui.actionBatchTranslation->setEnabled(m_dataModel->contextCount() > 0 && phraseBookLoaded |
|
2308 |
&& m_dataModel->isModelWritable(m_currentIndex.model())); |
|
2309 |
m_ui.actionAddToPhraseBook->setEnabled(currentMessageIndex().isValid() && phraseBookLoaded); |
|
2310 |
} |
|
2311 |
||
2312 |
void MainWindow::updatePhraseDictInternal(int model) |
|
2313 |
{ |
|
2314 |
QHash<QString, QList<Phrase *> > &pd = m_phraseDict[model]; |
|
2315 |
||
2316 |
pd.clear(); |
|
2317 |
foreach (PhraseBook *pb, m_phraseBooks) { |
|
2318 |
bool before; |
|
2319 |
if (pb->language() != QLocale::C && m_dataModel->language(model) != QLocale::C) { |
|
2320 |
if (pb->language() != m_dataModel->language(model)) |
|
2321 |
continue; |
|
2322 |
before = (pb->country() == m_dataModel->model(model)->country()); |
|
2323 |
} else { |
|
2324 |
before = false; |
|
2325 |
} |
|
2326 |
foreach (Phrase *p, pb->phrases()) { |
|
2327 |
QString f = friendlyString(p->source()); |
|
2328 |
if (f.length() > 0) { |
|
2329 |
f = f.split(QLatin1Char(' ')).first(); |
|
2330 |
if (!pd.contains(f)) { |
|
2331 |
pd.insert(f, QList<Phrase *>()); |
|
2332 |
} |
|
2333 |
if (before) |
|
2334 |
pd[f].prepend(p); |
|
2335 |
else |
|
2336 |
pd[f].append(p); |
|
2337 |
} |
|
2338 |
} |
|
2339 |
} |
|
2340 |
} |
|
2341 |
||
2342 |
void MainWindow::updatePhraseDict(int model) |
|
2343 |
{ |
|
2344 |
updatePhraseDictInternal(model); |
|
2345 |
m_phraseView->update(); |
|
2346 |
} |
|
2347 |
||
2348 |
void MainWindow::updatePhraseDicts() |
|
2349 |
{ |
|
2350 |
for (int i = 0; i < m_phraseDict.size(); ++i) |
|
2351 |
if (!m_dataModel->isModelWritable(i)) |
|
2352 |
m_phraseDict[i].clear(); |
|
2353 |
else |
|
2354 |
updatePhraseDictInternal(i); |
|
2355 |
revalidate(); |
|
2356 |
m_phraseView->update(); |
|
2357 |
} |
|
2358 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2359 |
static bool haveMnemonic(const QString &str) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2360 |
{ |
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2361 |
for (const ushort *p = (ushort *)str.constData();; ) { // Assume null-termination |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2362 |
ushort c = *p++; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2363 |
if (!c) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2364 |
break; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2365 |
if (c == '&') { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2366 |
c = *p++; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2367 |
if (!c) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2368 |
return false; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2369 |
// "Nobody" ever really uses these alt-space, and they are highly annoying |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2370 |
// because we get a lot of false positives. |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2371 |
if (c != '&' && c != ' ' && QChar(c).isPrint()) { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2372 |
const ushort *pp = p; |
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
2373 |
for (; *p < 256 && ::isalpha(*p); p++) ; |
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2374 |
if (pp == p || *p != ';') |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2375 |
return true; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2376 |
// This looks like a HTML &entity;, so ignore it. As a HTML string |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2377 |
// won't contain accels anyway, we can stop scanning here. |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2378 |
break; |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2379 |
} |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2380 |
} |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2381 |
} |
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2382 |
return false; |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2383 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2384 |
|
0 | 2385 |
void MainWindow::updateDanger(const MultiDataIndex &index, bool verbose) |
2386 |
{ |
|
2387 |
MultiDataIndex curIdx = index; |
|
2388 |
m_errorsView->clear(); |
|
2389 |
||
2390 |
QString source; |
|
2391 |
for (int mi = 0; mi < m_dataModel->modelCount(); ++mi) { |
|
2392 |
if (!m_dataModel->isModelWritable(mi)) |
|
2393 |
continue; |
|
2394 |
curIdx.setModel(mi); |
|
2395 |
MessageItem *m = m_dataModel->messageItem(curIdx); |
|
2396 |
if (!m || m->isObsolete()) |
|
2397 |
continue; |
|
2398 |
||
2399 |
bool danger = false; |
|
2400 |
if (m->message().isTranslated()) { |
|
2401 |
if (source.isEmpty()) { |
|
2402 |
source = m->pluralText(); |
|
2403 |
if (source.isEmpty()) |
|
2404 |
source = m->text(); |
|
2405 |
} |
|
2406 |
QStringList translations = m->translations(); |
|
2407 |
||
2408 |
// Truncated variants are permitted to be "denormalized" |
|
2409 |
for (int i = 0; i < translations.count(); ++i) { |
|
2410 |
int sep = translations.at(i).indexOf(QChar(Translator::BinaryVariantSeparator)); |
|
2411 |
if (sep >= 0) |
|
2412 |
translations[i].truncate(sep); |
|
2413 |
} |
|
2414 |
||
2415 |
if (m_ui.actionAccelerators->isChecked()) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2416 |
bool sk = haveMnemonic(source); |
0 | 2417 |
bool tk = true; |
2418 |
for (int i = 0; i < translations.count() && tk; ++i) { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2419 |
tk &= haveMnemonic(translations[i]); |
0 | 2420 |
} |
2421 |
||
2422 |
if (!sk && tk) { |
|
2423 |
if (verbose) |
|
2424 |
m_errorsView->addError(mi, ErrorsView::SuperfluousAccelerator); |
|
2425 |
danger = true; |
|
2426 |
} else if (sk && !tk) { |
|
2427 |
if (verbose) |
|
2428 |
m_errorsView->addError(mi, ErrorsView::MissingAccelerator); |
|
2429 |
danger = true; |
|
2430 |
} |
|
2431 |
} |
|
2432 |
if (m_ui.actionEndingPunctuation->isChecked()) { |
|
2433 |
bool endingok = true; |
|
2434 |
for (int i = 0; i < translations.count() && endingok; ++i) { |
|
2435 |
endingok &= (ending(source, m_dataModel->sourceLanguage(mi)) == |
|
2436 |
ending(translations[i], m_dataModel->language(mi))); |
|
2437 |
} |
|
2438 |
||
2439 |
if (!endingok) { |
|
2440 |
if (verbose) |
|
2441 |
m_errorsView->addError(mi, ErrorsView::PunctuationDiffer); |
|
2442 |
danger = true; |
|
2443 |
} |
|
2444 |
} |
|
2445 |
if (m_ui.actionPhraseMatches->isChecked()) { |
|
2446 |
QString fsource = friendlyString(source); |
|
2447 |
QString ftranslation = friendlyString(translations.first()); |
|
2448 |
QStringList lookupWords = fsource.split(QLatin1Char(' ')); |
|
2449 |
||
2450 |
bool phraseFound; |
|
2451 |
foreach (const QString &s, lookupWords) { |
|
2452 |
if (m_phraseDict[mi].contains(s)) { |
|
2453 |
phraseFound = true; |
|
2454 |
foreach (const Phrase *p, m_phraseDict[mi].value(s)) { |
|
2455 |
if (fsource == friendlyString(p->source())) { |
|
2456 |
if (ftranslation.indexOf(friendlyString(p->target())) >= 0) { |
|
2457 |
phraseFound = true; |
|
2458 |
break; |
|
2459 |
} else { |
|
2460 |
phraseFound = false; |
|
2461 |
} |
|
2462 |
} |
|
2463 |
} |
|
2464 |
if (!phraseFound) { |
|
2465 |
if (verbose) |
|
2466 |
m_errorsView->addError(mi, ErrorsView::IgnoredPhrasebook, s); |
|
2467 |
danger = true; |
|
2468 |
} |
|
2469 |
} |
|
2470 |
} |
|
2471 |
} |
|
2472 |
||
2473 |
if (m_ui.actionPlaceMarkerMatches->isChecked()) { |
|
2474 |
// Stores the occurence count of the place markers in the map placeMarkerIndexes. |
|
2475 |
// i.e. the occurence count of %1 is stored at placeMarkerIndexes[1], |
|
2476 |
// count of %2 is stored at placeMarkerIndexes[2] etc. |
|
2477 |
// In the first pass, it counts all place markers in the sourcetext. |
|
2478 |
// In the second pass it (de)counts all place markers in the translation. |
|
2479 |
// When finished, all elements should have returned to a count of 0, |
|
2480 |
// if not there is a mismatch |
|
2481 |
// between place markers in the source text and the translation text. |
|
2482 |
QHash<int, int> placeMarkerIndexes; |
|
2483 |
QString translation; |
|
2484 |
int numTranslations = translations.count(); |
|
2485 |
for (int pass = 0; pass < numTranslations + 1; ++pass) { |
|
2486 |
const QChar *uc_begin = source.unicode(); |
|
2487 |
const QChar *uc_end = uc_begin + source.length(); |
|
2488 |
if (pass >= 1) { |
|
2489 |
translation = translations[pass - 1]; |
|
2490 |
uc_begin = translation.unicode(); |
|
2491 |
uc_end = uc_begin + translation.length(); |
|
2492 |
} |
|
2493 |
const QChar *c = uc_begin; |
|
2494 |
while (c < uc_end) { |
|
2495 |
if (c->unicode() == '%') { |
|
2496 |
const QChar *escape_start = ++c; |
|
2497 |
while (c->isDigit()) |
|
2498 |
++c; |
|
2499 |
const QChar *escape_end = c; |
|
2500 |
bool ok = true; |
|
2501 |
int markerIndex = QString::fromRawData( |
|
2502 |
escape_start, escape_end - escape_start).toInt(&ok); |
|
2503 |
if (ok) |
|
2504 |
placeMarkerIndexes[markerIndex] += (pass == 0 ? numTranslations : -1); |
|
2505 |
} |
|
2506 |
++c; |
|
2507 |
} |
|
2508 |
} |
|
2509 |
||
2510 |
foreach (int i, placeMarkerIndexes) { |
|
2511 |
if (i != 0) { |
|
2512 |
if (verbose) |
|
2513 |
m_errorsView->addError(mi, ErrorsView::PlaceMarkersDiffer); |
|
2514 |
danger = true; |
|
2515 |
break; |
|
2516 |
} |
|
2517 |
} |
|
2518 |
||
2519 |
// Piggy-backed on the general place markers, we check the plural count marker. |
|
2520 |
if (m->message().isPlural()) { |
|
2521 |
for (int i = 0; i < numTranslations; ++i) |
|
2522 |
if (m_dataModel->model(mi)->countRefNeeds().at(i) |
|
2523 |
&& !translations[i].contains(QLatin1String("%n"))) { |
|
2524 |
if (verbose) |
|
2525 |
m_errorsView->addError(mi, ErrorsView::NumerusMarkerMissing); |
|
2526 |
danger = true; |
|
2527 |
break; |
|
2528 |
} |
|
2529 |
} |
|
2530 |
} |
|
2531 |
} |
|
2532 |
||
2533 |
if (danger != m->danger()) |
|
2534 |
m_dataModel->setDanger(curIdx, danger); |
|
2535 |
} |
|
2536 |
||
2537 |
if (verbose) |
|
2538 |
statusBar()->showMessage(m_errorsView->firstError()); |
|
2539 |
} |
|
2540 |
||
2541 |
void MainWindow::readConfig() |
|
2542 |
{ |
|
2543 |
QSettings config; |
|
2544 |
||
2545 |
QRect r(pos(), size()); |
|
2546 |
restoreGeometry(config.value(settingPath("Geometry/WindowGeometry")).toByteArray()); |
|
2547 |
restoreState(config.value(settingPath("MainWindowState")).toByteArray()); |
|
2548 |
||
2549 |
m_ui.actionAccelerators->setChecked( |
|
2550 |
config.value(settingPath("Validators/Accelerator"), true).toBool()); |
|
2551 |
m_ui.actionEndingPunctuation->setChecked( |
|
2552 |
config.value(settingPath("Validators/EndingPunctuation"), true).toBool()); |
|
2553 |
m_ui.actionPhraseMatches->setChecked( |
|
2554 |
config.value(settingPath("Validators/PhraseMatch"), true).toBool()); |
|
2555 |
m_ui.actionPlaceMarkerMatches->setChecked( |
|
2556 |
config.value(settingPath("Validators/PlaceMarkers"), true).toBool()); |
|
2557 |
m_ui.actionLengthVariants->setChecked( |
|
2558 |
config.value(settingPath("Options/LengthVariants"), false).toBool()); |
|
2559 |
||
2560 |
recentFiles().readConfig(); |
|
2561 |
||
2562 |
int size = config.beginReadArray(settingPath("OpenedPhraseBooks")); |
|
2563 |
for (int i = 0; i < size; ++i) { |
|
2564 |
config.setArrayIndex(i); |
|
2565 |
openPhraseBook(config.value(QLatin1String("FileName")).toString()); |
|
2566 |
} |
|
2567 |
config.endArray(); |
|
2568 |
} |
|
2569 |
||
2570 |
void MainWindow::writeConfig() |
|
2571 |
{ |
|
2572 |
QSettings config; |
|
2573 |
config.setValue(settingPath("Geometry/WindowGeometry"), |
|
2574 |
saveGeometry()); |
|
2575 |
config.setValue(settingPath("Validators/Accelerator"), |
|
2576 |
m_ui.actionAccelerators->isChecked()); |
|
2577 |
config.setValue(settingPath("Validators/EndingPunctuation"), |
|
2578 |
m_ui.actionEndingPunctuation->isChecked()); |
|
2579 |
config.setValue(settingPath("Validators/PhraseMatch"), |
|
2580 |
m_ui.actionPhraseMatches->isChecked()); |
|
2581 |
config.setValue(settingPath("Validators/PlaceMarkers"), |
|
2582 |
m_ui.actionPlaceMarkerMatches->isChecked()); |
|
2583 |
config.setValue(settingPath("Options/LengthVariants"), |
|
2584 |
m_ui.actionLengthVariants->isChecked()); |
|
2585 |
config.setValue(settingPath("MainWindowState"), |
|
2586 |
saveState()); |
|
2587 |
recentFiles().writeConfig(); |
|
2588 |
||
2589 |
config.beginWriteArray(settingPath("OpenedPhraseBooks"), |
|
2590 |
m_phraseBooks.size()); |
|
2591 |
for (int i = 0; i < m_phraseBooks.size(); ++i) { |
|
2592 |
config.setArrayIndex(i); |
|
2593 |
config.setValue(QLatin1String("FileName"), m_phraseBooks.at(i)->fileName()); |
|
2594 |
} |
|
2595 |
config.endArray(); |
|
2596 |
} |
|
2597 |
||
2598 |
void MainWindow::setupRecentFilesMenu() |
|
2599 |
{ |
|
2600 |
m_ui.menuRecentlyOpenedFiles->clear(); |
|
2601 |
foreach (const QStringList &strList, recentFiles().filesLists()) |
|
2602 |
if (strList.size() == 1) { |
|
2603 |
const QString &str = strList.first(); |
|
2604 |
m_ui.menuRecentlyOpenedFiles->addAction( |
|
2605 |
DataModel::prettifyFileName(str))->setData(str); |
|
2606 |
} else { |
|
2607 |
QMenu *menu = m_ui.menuRecentlyOpenedFiles->addMenu( |
|
2608 |
MultiDataModel::condenseFileNames( |
|
2609 |
MultiDataModel::prettifyFileNames(strList))); |
|
2610 |
menu->addAction(tr("All"))->setData(strList); |
|
2611 |
foreach (const QString &str, strList) |
|
2612 |
menu->addAction(DataModel::prettifyFileName(str))->setData(str); |
|
2613 |
} |
|
2614 |
} |
|
2615 |
||
2616 |
void MainWindow::recentFileActivated(QAction *action) |
|
2617 |
{ |
|
2618 |
openFiles(action->data().toStringList()); |
|
2619 |
} |
|
2620 |
||
2621 |
void MainWindow::toggleStatistics() |
|
2622 |
{ |
|
2623 |
if (m_ui.actionStatistics->isChecked()) { |
|
2624 |
if (!m_statistics) { |
|
2625 |
m_statistics = new Statistics(this); |
|
2626 |
connect(m_dataModel, SIGNAL(statsChanged(int,int,int,int,int,int)), |
|
2627 |
m_statistics, SLOT(updateStats(int,int,int,int,int,int))); |
|
2628 |
} |
|
2629 |
m_statistics->show(); |
|
2630 |
updateStatistics(); |
|
2631 |
} |
|
2632 |
else if (m_statistics) { |
|
2633 |
m_statistics->close(); |
|
2634 |
} |
|
2635 |
} |
|
2636 |
||
2637 |
void MainWindow::maybeUpdateStatistics(const MultiDataIndex &index) |
|
2638 |
{ |
|
2639 |
if (index.model() == m_currentIndex.model()) |
|
2640 |
updateStatistics(); |
|
2641 |
} |
|
2642 |
||
2643 |
void MainWindow::updateStatistics() |
|
2644 |
{ |
|
2645 |
// don't call this if stats dialog is not open |
|
2646 |
// because this can be slow... |
|
2647 |
if (!m_statistics || !m_statistics->isVisible() || m_currentIndex.model() < 0) |
|
2648 |
return; |
|
2649 |
||
2650 |
m_dataModel->model(m_currentIndex.model())->updateStatistics(); |
|
2651 |
} |
|
2652 |
||
2653 |
void MainWindow::showTranslationSettings(int model) |
|
2654 |
{ |
|
2655 |
if (!m_translationSettingsDialog) |
|
2656 |
m_translationSettingsDialog = new TranslationSettingsDialog(this); |
|
2657 |
m_translationSettingsDialog->setDataModel(m_dataModel->model(model)); |
|
2658 |
m_translationSettingsDialog->exec(); |
|
2659 |
} |
|
2660 |
||
2661 |
void MainWindow::showTranslationSettings() |
|
2662 |
{ |
|
2663 |
showTranslationSettings(m_currentIndex.model()); |
|
2664 |
} |
|
2665 |
||
2666 |
bool MainWindow::eventFilter(QObject *object, QEvent *event) |
|
2667 |
{ |
|
2668 |
if (event->type() == QEvent::DragEnter) { |
|
2669 |
QDragEnterEvent *e = static_cast<QDragEnterEvent*>(event); |
|
2670 |
if (e->mimeData()->hasFormat(QLatin1String("text/uri-list"))) { |
|
2671 |
e->acceptProposedAction(); |
|
2672 |
return true; |
|
2673 |
} |
|
2674 |
} else if (event->type() == QEvent::Drop) { |
|
2675 |
QDropEvent *e = static_cast<QDropEvent*>(event); |
|
2676 |
if (!e->mimeData()->hasFormat(QLatin1String("text/uri-list"))) |
|
2677 |
return false; |
|
2678 |
QStringList urls; |
|
2679 |
foreach (QUrl url, e->mimeData()->urls()) |
|
2680 |
if (!url.toLocalFile().isEmpty()) |
|
2681 |
urls << url.toLocalFile(); |
|
2682 |
if (!urls.isEmpty()) |
|
2683 |
openFiles(urls); |
|
2684 |
e->acceptProposedAction(); |
|
2685 |
return true; |
|
2686 |
} else if (event->type() == QEvent::KeyPress) { |
|
2687 |
if (static_cast<QKeyEvent *>(event)->key() == Qt::Key_Escape) { |
|
2688 |
if (object == m_messageEditor) |
|
2689 |
m_messageView->setFocus(); |
|
2690 |
else if (object == m_messagesDock) |
|
2691 |
m_contextView->setFocus(); |
|
2692 |
} |
|
2693 |
} |
|
2694 |
return false; |
|
2695 |
} |
|
2696 |
||
2697 |
QT_END_NAMESPACE |