1 | /* |
---|
2 | * TSPSG: TSP Solver and Generator |
---|
3 | * Copyright (C) 2007-2011 Lёppa <contacts[at]oleksii[dot]name> |
---|
4 | * |
---|
5 | * $Id: mainwindow.cpp 157 2011-03-22 20:31:18Z laleppa $ |
---|
6 | * $URL: https://tspsg.svn.sourceforge.net/svnroot/tspsg/trunk/src/mainwindow.cpp $ |
---|
7 | * |
---|
8 | * This file is part of TSPSG. |
---|
9 | * |
---|
10 | * TSPSG is free software: you can redistribute it and/or modify |
---|
11 | * it under the terms of the GNU General Public License as published by |
---|
12 | * the Free Software Foundation, either version 3 of the License, or |
---|
13 | * (at your option) any later version. |
---|
14 | * |
---|
15 | * TSPSG is distributed in the hope that it will be useful, |
---|
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
18 | * GNU General Public License for more details. |
---|
19 | * |
---|
20 | * You should have received a copy of the GNU General Public License |
---|
21 | * along with TSPSG. If not, see <http://www.gnu.org/licenses/>. |
---|
22 | */ |
---|
23 | |
---|
24 | #include "mainwindow.h" |
---|
25 | |
---|
26 | #ifdef Q_WS_WIN32 |
---|
27 | # include "shobjidl.h" |
---|
28 | #endif |
---|
29 | |
---|
30 | #ifdef _T_T_L_ |
---|
31 | #include "_.h" |
---|
32 | _C_ _R_ _Y_ _P_ _T_ |
---|
33 | #endif |
---|
34 | |
---|
35 | /*! |
---|
36 | * \brief Class constructor. |
---|
37 | * \param parent Main Window parent widget. |
---|
38 | * |
---|
39 | * Initializes Main Window and creates its layout based on target OS. |
---|
40 | * Loads TSPSG settings and opens a task file if it was specified as a commandline parameter. |
---|
41 | */ |
---|
42 | MainWindow::MainWindow(QWidget *parent) |
---|
43 | : QMainWindow(parent) |
---|
44 | { |
---|
45 | settings = new QSettings(QSettings::IniFormat, QSettings::UserScope, "TSPSG", "tspsg", this); |
---|
46 | |
---|
47 | if (settings->contains("Style")) { |
---|
48 | QStyle *s = QStyleFactory::create(settings->value("Style").toString()); |
---|
49 | if (s != NULL) |
---|
50 | QApplication::setStyle(s); |
---|
51 | else |
---|
52 | settings->remove("Style"); |
---|
53 | } |
---|
54 | |
---|
55 | loadLanguage(); |
---|
56 | setupUi(); |
---|
57 | setAcceptDrops(true); |
---|
58 | |
---|
59 | initDocStyleSheet(); |
---|
60 | |
---|
61 | #ifndef QT_NO_PRINTER |
---|
62 | printer = new QPrinter(QPrinter::HighResolution); |
---|
63 | #endif // QT_NO_PRINTER |
---|
64 | |
---|
65 | #ifdef Q_WS_WINCE_WM |
---|
66 | currentGeometry = QApplication::desktop()->availableGeometry(0); |
---|
67 | // We need to react to SIP show/hide and resize the window appropriately |
---|
68 | connect(QApplication::desktop(), SIGNAL(workAreaResized(int)), SLOT(desktopResized(int))); |
---|
69 | #endif // Q_WS_WINCE_WM |
---|
70 | connect(actionFileNew, SIGNAL(triggered()), SLOT(actionFileNewTriggered())); |
---|
71 | connect(actionFileOpen, SIGNAL(triggered()), SLOT(actionFileOpenTriggered())); |
---|
72 | connect(actionFileSave, SIGNAL(triggered()), SLOT(actionFileSaveTriggered())); |
---|
73 | connect(actionFileSaveAsTask, SIGNAL(triggered()), SLOT(actionFileSaveAsTaskTriggered())); |
---|
74 | connect(actionFileSaveAsSolution, SIGNAL(triggered()), SLOT(actionFileSaveAsSolutionTriggered())); |
---|
75 | #ifndef QT_NO_PRINTER |
---|
76 | connect(actionFilePrintPreview, SIGNAL(triggered()), SLOT(actionFilePrintPreviewTriggered())); |
---|
77 | connect(actionFilePrint, SIGNAL(triggered()), SLOT(actionFilePrintTriggered())); |
---|
78 | #endif // QT_NO_PRINTER |
---|
79 | #ifndef HANDHELD |
---|
80 | connect(actionSettingsToolbarsConfigure, SIGNAL(triggered()), SLOT(actionSettingsToolbarsConfigureTriggered())); |
---|
81 | #endif // HANDHELD |
---|
82 | connect(actionSettingsPreferences, SIGNAL(triggered()), SLOT(actionSettingsPreferencesTriggered())); |
---|
83 | if (actionHelpCheck4Updates != NULL) |
---|
84 | connect(actionHelpCheck4Updates, SIGNAL(triggered()), SLOT(actionHelpCheck4UpdatesTriggered())); |
---|
85 | connect(actionSettingsLanguageAutodetect, SIGNAL(triggered(bool)), SLOT(actionSettingsLanguageAutodetectTriggered(bool))); |
---|
86 | connect(groupSettingsLanguageList, SIGNAL(triggered(QAction *)), SLOT(groupSettingsLanguageListTriggered(QAction *))); |
---|
87 | connect(actionSettingsStyleSystem, SIGNAL(triggered(bool)), SLOT(actionSettingsStyleSystemTriggered(bool))); |
---|
88 | connect(groupSettingsStyleList, SIGNAL(triggered(QAction*)), SLOT(groupSettingsStyleListTriggered(QAction*))); |
---|
89 | connect(actionHelpOnlineSupport, SIGNAL(triggered()), SLOT(actionHelpOnlineSupportTriggered())); |
---|
90 | connect(actionHelpReportBug, SIGNAL(triggered()), SLOT(actionHelpReportBugTriggered())); |
---|
91 | connect(actionHelpAboutQt, SIGNAL(triggered()), qApp, SLOT(aboutQt())); |
---|
92 | connect(actionHelpAbout, SIGNAL(triggered()), SLOT(actionHelpAboutTriggered())); |
---|
93 | |
---|
94 | connect(buttonSolve, SIGNAL(clicked()), SLOT(buttonSolveClicked())); |
---|
95 | connect(buttonRandom, SIGNAL(clicked()), SLOT(buttonRandomClicked())); |
---|
96 | connect(buttonBackToTask, SIGNAL(clicked()), SLOT(buttonBackToTaskClicked())); |
---|
97 | connect(spinCities, SIGNAL(valueChanged(int)), SLOT(spinCitiesValueChanged(int))); |
---|
98 | |
---|
99 | #ifndef HANDHELD |
---|
100 | // Centering main window |
---|
101 | QRect rect = geometry(); |
---|
102 | rect.moveCenter(QApplication::desktop()->availableGeometry(this).center()); |
---|
103 | setGeometry(rect); |
---|
104 | if (settings->value("SavePos", DEF_SAVEPOS).toBool()) { |
---|
105 | // Loading of saved window state |
---|
106 | settings->beginGroup("MainWindow"); |
---|
107 | restoreGeometry(settings->value("Geometry").toByteArray()); |
---|
108 | restoreState(settings->value("State").toByteArray()); |
---|
109 | settings->endGroup(); |
---|
110 | } |
---|
111 | #endif // HANDHELD |
---|
112 | |
---|
113 | tspmodel = new CTSPModel(this); |
---|
114 | taskView->setModel(tspmodel); |
---|
115 | connect(tspmodel, SIGNAL(numCitiesChanged(int)), SLOT(numCitiesChanged(int))); |
---|
116 | connect(tspmodel, SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)), SLOT(dataChanged(const QModelIndex &, const QModelIndex &))); |
---|
117 | connect(tspmodel, SIGNAL(layoutChanged()), SLOT(dataChanged())); |
---|
118 | if ((QCoreApplication::arguments().count() > 1) && (tspmodel->loadTask(QCoreApplication::arguments().at(1)))) |
---|
119 | setFileName(QCoreApplication::arguments().at(1)); |
---|
120 | else { |
---|
121 | setFileName(); |
---|
122 | spinCities->setValue(settings->value("NumCities",DEF_NUM_CITIES).toInt()); |
---|
123 | spinCitiesValueChanged(spinCities->value()); |
---|
124 | } |
---|
125 | setWindowModified(false); |
---|
126 | |
---|
127 | if (actionHelpCheck4Updates != NULL) { |
---|
128 | if (!settings->contains("Check4Updates/Enabled")) { |
---|
129 | QApplication::setOverrideCursor(QCursor(Qt::ArrowCursor)); |
---|
130 | settings->setValue("Check4Updates/Enabled", |
---|
131 | QMessageBox::question(this, QCoreApplication::applicationName(), |
---|
132 | tr("Would you like %1 to automatically check for updates every %n day(s)?", "", settings->value("Check4Updates/Interval", DEF_UPDATE_CHECK_INTERVAL).toInt()).arg(QCoreApplication::applicationName()), |
---|
133 | QMessageBox::Yes | QMessageBox::No |
---|
134 | ) == QMessageBox::Yes |
---|
135 | ); |
---|
136 | QApplication::restoreOverrideCursor(); |
---|
137 | } |
---|
138 | if ((settings->value("Check4Updates/Enabled", DEF_CHECK_FOR_UPDATES).toBool()) |
---|
139 | && (QDate(qvariant_cast<QDate>(settings->value("Check4Updates/LastAttempt"))).daysTo(QDate::currentDate()) >= settings->value("Check4Updates/Interval", DEF_UPDATE_CHECK_INTERVAL).toInt())) { |
---|
140 | check4Updates(true); |
---|
141 | } |
---|
142 | } |
---|
143 | } |
---|
144 | |
---|
145 | MainWindow::~MainWindow() |
---|
146 | { |
---|
147 | #ifndef QT_NO_PRINTER |
---|
148 | delete printer; |
---|
149 | #endif |
---|
150 | } |
---|
151 | |
---|
152 | /* Privates **********************************************************/ |
---|
153 | |
---|
154 | void MainWindow::actionFileNewTriggered() |
---|
155 | { |
---|
156 | if (!maybeSave()) |
---|
157 | return; |
---|
158 | QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); |
---|
159 | tspmodel->clear(); |
---|
160 | setFileName(); |
---|
161 | setWindowModified(false); |
---|
162 | tabWidget->setCurrentIndex(0); |
---|
163 | solutionText->clear(); |
---|
164 | toggleSolutionActions(false); |
---|
165 | QApplication::restoreOverrideCursor(); |
---|
166 | } |
---|
167 | |
---|
168 | void MainWindow::actionFileOpenTriggered() |
---|
169 | { |
---|
170 | if (!maybeSave()) |
---|
171 | return; |
---|
172 | |
---|
173 | QStringList filters(tr("All Supported Formats") + " (*.tspt *.zkt)"); |
---|
174 | filters.append(tr("%1 Task Files").arg("TSPSG") + " (*.tspt)"); |
---|
175 | filters.append(tr("%1 Task Files").arg("ZKomModRd") + " (*.zkt)"); |
---|
176 | filters.append(tr("All Files") + " (*)"); |
---|
177 | |
---|
178 | QString file; |
---|
179 | if ((fileName == tr("Untitled") + ".tspt") && settings->value("SaveLastUsed", DEF_SAVE_LAST_USED).toBool()) |
---|
180 | file = settings->value(OS"/LastUsed/TaskLoadPath").toString(); |
---|
181 | else |
---|
182 | file = QFileInfo(fileName).path(); |
---|
183 | QFileDialog::Options opts = settings->value("UseNativeDialogs", DEF_USE_NATIVE_DIALOGS).toBool() ? QFileDialog::Options() : QFileDialog::DontUseNativeDialog; |
---|
184 | file = QFileDialog::getOpenFileName(this, tr("Task Load"), file, filters.join(";;"), NULL, opts); |
---|
185 | if (file.isEmpty() || !QFileInfo(file).isFile()) |
---|
186 | return; |
---|
187 | if (settings->value("SaveLastUsed", DEF_SAVE_LAST_USED).toBool()) |
---|
188 | settings->setValue(OS"/LastUsed/TaskLoadPath", QFileInfo(file).path()); |
---|
189 | |
---|
190 | if (!tspmodel->loadTask(file)) |
---|
191 | return; |
---|
192 | setFileName(file); |
---|
193 | tabWidget->setCurrentIndex(0); |
---|
194 | setWindowModified(false); |
---|
195 | solutionText->clear(); |
---|
196 | toggleSolutionActions(false); |
---|
197 | } |
---|
198 | |
---|
199 | bool MainWindow::actionFileSaveTriggered() |
---|
200 | { |
---|
201 | if ((fileName == tr("Untitled") + ".tspt") || !fileName.endsWith(".tspt", Qt::CaseInsensitive)) |
---|
202 | return saveTask(); |
---|
203 | else |
---|
204 | if (tspmodel->saveTask(fileName)) { |
---|
205 | setWindowModified(false); |
---|
206 | return true; |
---|
207 | } else |
---|
208 | return false; |
---|
209 | } |
---|
210 | |
---|
211 | void MainWindow::actionFileSaveAsTaskTriggered() |
---|
212 | { |
---|
213 | saveTask(); |
---|
214 | } |
---|
215 | |
---|
216 | void MainWindow::actionFileSaveAsSolutionTriggered() |
---|
217 | { |
---|
218 | static QString selectedFile; |
---|
219 | if (selectedFile.isEmpty()) { |
---|
220 | if (settings->value("SaveLastUsed", DEF_SAVE_LAST_USED).toBool()) { |
---|
221 | selectedFile = settings->value(OS"/LastUsed/SolutionSavePath").toString(); |
---|
222 | } |
---|
223 | } else |
---|
224 | selectedFile = QFileInfo(selectedFile).path(); |
---|
225 | if (!selectedFile.isEmpty()) |
---|
226 | selectedFile.append("/"); |
---|
227 | if (fileName == tr("Untitled") + ".tspt") { |
---|
228 | #ifndef QT_NO_PRINTER |
---|
229 | selectedFile += "solution.pdf"; |
---|
230 | #else |
---|
231 | selectedFile += "solution.html"; |
---|
232 | #endif // QT_NO_PRINTER |
---|
233 | } else { |
---|
234 | #ifndef QT_NO_PRINTER |
---|
235 | selectedFile += QFileInfo(fileName).completeBaseName() + ".pdf"; |
---|
236 | #else |
---|
237 | selectedFile += QFileInfo(fileName).completeBaseName() + ".html"; |
---|
238 | #endif // QT_NO_PRINTER |
---|
239 | } |
---|
240 | |
---|
241 | QStringList filters; |
---|
242 | #ifndef QT_NO_PRINTER |
---|
243 | filters.append(tr("PDF Files") + " (*.pdf)"); |
---|
244 | #endif |
---|
245 | filters.append(tr("HTML Files") + " (*.html *.htm)"); |
---|
246 | filters.append(tr("OpenDocument Files") + " (*.odt)"); |
---|
247 | filters.append(tr("All Files") + " (*)"); |
---|
248 | |
---|
249 | QFileDialog::Options opts(settings->value("UseNativeDialogs", DEF_USE_NATIVE_DIALOGS).toBool() ? QFileDialog::Options() : QFileDialog::DontUseNativeDialog); |
---|
250 | QString file = QFileDialog::getSaveFileName(this, QString(), selectedFile, filters.join(";;"), NULL, opts); |
---|
251 | if (file.isEmpty()) |
---|
252 | return; |
---|
253 | selectedFile = file; |
---|
254 | if (settings->value("SaveLastUsed", DEF_SAVE_LAST_USED).toBool()) |
---|
255 | settings->setValue(OS"/LastUsed/SolutionSavePath", QFileInfo(selectedFile).path()); |
---|
256 | QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); |
---|
257 | #ifndef QT_NO_PRINTER |
---|
258 | if (selectedFile.endsWith(".pdf",Qt::CaseInsensitive)) { |
---|
259 | QPrinter printer(QPrinter::HighResolution); |
---|
260 | printer.setOutputFormat(QPrinter::PdfFormat); |
---|
261 | printer.setOutputFileName(selectedFile); |
---|
262 | solutionText->document()->print(&printer); |
---|
263 | QApplication::restoreOverrideCursor(); |
---|
264 | return; |
---|
265 | } |
---|
266 | #endif |
---|
267 | if (selectedFile.endsWith(".htm", Qt::CaseInsensitive) || selectedFile.endsWith(".html", Qt::CaseInsensitive)) { |
---|
268 | QFile file(selectedFile); |
---|
269 | if (!file.open(QFile::WriteOnly)) { |
---|
270 | QApplication::restoreOverrideCursor(); |
---|
271 | QMessageBox::critical(this, tr("Solution Save"), tr("Unable to save the solution.\nError: %1").arg(file.errorString())); |
---|
272 | return; |
---|
273 | } |
---|
274 | QFileInfo fi(selectedFile); |
---|
275 | QString format = settings->value("Output/GraphImageFormat", DEF_GRAPH_IMAGE_FORMAT).toString(); |
---|
276 | #if !defined(NOSVG) |
---|
277 | if (!QImageWriter::supportedImageFormats().contains(format.toAscii()) && (format != "svg")) { |
---|
278 | #else // NOSVG |
---|
279 | if (!QImageWriter::supportedImageFormats().contains(format.toAscii())) { |
---|
280 | #endif // NOSVG |
---|
281 | format = DEF_GRAPH_IMAGE_FORMAT; |
---|
282 | settings->remove("Output/GraphImageFormat"); |
---|
283 | } |
---|
284 | QString html = solutionText->document()->toHtml("UTF-8"), |
---|
285 | img = fi.completeBaseName() + "." + format; |
---|
286 | html.replace(QRegExp("font-family:([^;]*);"), "font-family:\\1, 'DejaVu Sans Mono', 'Courier New', Courier, monospace;"); |
---|
287 | html.replace(QRegExp("<img\\s+src=\"tspsg://graph.pic\""), QString("<img src=\"%1\" alt=\"%2\"").arg(img, tr("Solution Graph"))); |
---|
288 | |
---|
289 | // Saving solution text as HTML |
---|
290 | QTextStream ts(&file); |
---|
291 | ts.setCodec(QTextCodec::codecForName("UTF-8")); |
---|
292 | ts << html; |
---|
293 | file.close(); |
---|
294 | |
---|
295 | // Saving solution graph as SVG or PNG (depending on settings and SVG support) |
---|
296 | #if !defined(NOSVG) |
---|
297 | if (format == "svg") { |
---|
298 | QSvgGenerator svg; |
---|
299 | svg.setSize(QSize(graph.width() + 2, graph.height() + 2)); |
---|
300 | svg.setResolution(graph.logicalDpiX()); |
---|
301 | svg.setFileName(fi.path() + "/" + img); |
---|
302 | svg.setTitle(tr("Solution Graph")); |
---|
303 | svg.setDescription(tr("Generated with %1").arg(QCoreApplication::applicationName())); |
---|
304 | QPainter p; |
---|
305 | p.begin(&svg); |
---|
306 | p.drawPicture(1, 1, graph); |
---|
307 | p.end(); |
---|
308 | } else { |
---|
309 | #endif // NOSVG |
---|
310 | QImage i(graph.width() + 2, graph.height() + 2, QImage::Format_ARGB32); |
---|
311 | i.fill(0x00FFFFFF); |
---|
312 | QPainter p; |
---|
313 | p.begin(&i); |
---|
314 | p.drawPicture(1, 1, graph); |
---|
315 | p.end(); |
---|
316 | QImageWriter pic(fi.path() + "/" + img); |
---|
317 | if (pic.supportsOption(QImageIOHandler::Description)) { |
---|
318 | pic.setText("Title", "Solution Graph"); |
---|
319 | pic.setText("Software", QCoreApplication::applicationName()); |
---|
320 | } |
---|
321 | if (format == "png") |
---|
322 | pic.setQuality(5); |
---|
323 | else if (format == "jpeg") |
---|
324 | pic.setQuality(80); |
---|
325 | if (!pic.write(i)) { |
---|
326 | QApplication::restoreOverrideCursor(); |
---|
327 | QMessageBox::critical(this, tr("Solution Save"), tr("Unable to save the solution graph.\nError: %1").arg(pic.errorString())); |
---|
328 | return; |
---|
329 | } |
---|
330 | #if !defined(NOSVG) |
---|
331 | } |
---|
332 | #endif // NOSVG |
---|
333 | } else { |
---|
334 | QTextDocumentWriter dw(selectedFile); |
---|
335 | if (!selectedFile.endsWith(".odt",Qt::CaseInsensitive)) |
---|
336 | dw.setFormat("plaintext"); |
---|
337 | if (!dw.write(solutionText->document())) |
---|
338 | QMessageBox::critical(this, tr("Solution Save"), tr("Unable to save the solution.\nError: %1").arg(dw.device()->errorString())); |
---|
339 | } |
---|
340 | QApplication::restoreOverrideCursor(); |
---|
341 | } |
---|
342 | |
---|
343 | #ifndef QT_NO_PRINTER |
---|
344 | void MainWindow::actionFilePrintPreviewTriggered() |
---|
345 | { |
---|
346 | QPrintPreviewDialog ppd(printer, this); |
---|
347 | connect(&ppd,SIGNAL(paintRequested(QPrinter *)),SLOT(printPreview(QPrinter *))); |
---|
348 | ppd.exec(); |
---|
349 | } |
---|
350 | |
---|
351 | void MainWindow::actionFilePrintTriggered() |
---|
352 | { |
---|
353 | QPrintDialog pd(printer,this); |
---|
354 | if (pd.exec() != QDialog::Accepted) |
---|
355 | return; |
---|
356 | QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); |
---|
357 | solutionText->print(printer); |
---|
358 | QApplication::restoreOverrideCursor(); |
---|
359 | } |
---|
360 | #endif // QT_NO_PRINTER |
---|
361 | |
---|
362 | void MainWindow::actionSettingsPreferencesTriggered() |
---|
363 | { |
---|
364 | SettingsDialog sd(this); |
---|
365 | if (sd.exec() != QDialog::Accepted) |
---|
366 | return; |
---|
367 | if (sd.colorChanged() || sd.fontChanged()) { |
---|
368 | if (!solutionText->document()->isEmpty() && sd.colorChanged()) |
---|
369 | QMessageBox::information(this, tr("Settings Changed"), tr("You have changed color settings.\nThey will be applied to the next solution output.")); |
---|
370 | initDocStyleSheet(); |
---|
371 | } |
---|
372 | if (sd.translucencyChanged() != 0) |
---|
373 | toggleTranclucency(sd.translucencyChanged() == 1); |
---|
374 | } |
---|
375 | |
---|
376 | void MainWindow::actionSettingsLanguageAutodetectTriggered(bool checked) |
---|
377 | { |
---|
378 | if (checked) { |
---|
379 | settings->remove("Language"); |
---|
380 | QMessageBox::information(this, tr("Language change"), tr("Language will be autodetected on the next %1 start.").arg(QCoreApplication::applicationName())); |
---|
381 | } else |
---|
382 | settings->setValue("Language", groupSettingsLanguageList->checkedAction()->data().toString()); |
---|
383 | } |
---|
384 | |
---|
385 | void MainWindow::groupSettingsLanguageListTriggered(QAction *action) |
---|
386 | { |
---|
387 | #ifndef Q_WS_MAEMO_5 |
---|
388 | if (actionSettingsLanguageAutodetect->isChecked()) |
---|
389 | actionSettingsLanguageAutodetect->trigger(); |
---|
390 | #endif |
---|
391 | bool untitled = (fileName == tr("Untitled") + ".tspt"); |
---|
392 | if (loadLanguage(action->data().toString())) { |
---|
393 | QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); |
---|
394 | settings->setValue("Language",action->data().toString()); |
---|
395 | retranslateUi(); |
---|
396 | if (untitled) |
---|
397 | setFileName(); |
---|
398 | #ifndef HANDHELD |
---|
399 | if (QtWin::isCompositionEnabled() && settings->value("UseTranslucency", DEF_USE_TRANSLUCENCY).toBool()) { |
---|
400 | toggleStyle(labelVariant, true); |
---|
401 | toggleStyle(labelCities, true); |
---|
402 | } |
---|
403 | #endif |
---|
404 | QApplication::restoreOverrideCursor(); |
---|
405 | if (!solutionText->document()->isEmpty()) |
---|
406 | QMessageBox::information(this, tr("Settings Changed"), tr("You have changed the application language.\nTo get current solution output in the new language\nyou need to re-run the solution process.")); |
---|
407 | } |
---|
408 | } |
---|
409 | |
---|
410 | void MainWindow::actionSettingsStyleSystemTriggered(bool checked) |
---|
411 | { |
---|
412 | if (checked) { |
---|
413 | settings->remove("Style"); |
---|
414 | QMessageBox::information(this, tr("Style Change"), tr("To apply the default style you need to restart %1.").arg(QCoreApplication::applicationName())); |
---|
415 | } else { |
---|
416 | settings->setValue("Style", groupSettingsStyleList->checkedAction()->text()); |
---|
417 | } |
---|
418 | } |
---|
419 | |
---|
420 | void MainWindow::groupSettingsStyleListTriggered(QAction *action) |
---|
421 | { |
---|
422 | QStyle *s = QStyleFactory::create(action->text()); |
---|
423 | if (s != NULL) { |
---|
424 | QApplication::setStyle(s); |
---|
425 | settings->setValue("Style", action->text()); |
---|
426 | actionSettingsStyleSystem->setChecked(false); |
---|
427 | } |
---|
428 | } |
---|
429 | |
---|
430 | #ifndef HANDHELD |
---|
431 | void MainWindow::actionSettingsToolbarsConfigureTriggered() |
---|
432 | { |
---|
433 | QtToolBarDialog dlg(this); |
---|
434 | dlg.setToolBarManager(toolBarManager); |
---|
435 | dlg.exec(); |
---|
436 | QToolButton *tb = static_cast<QToolButton *>(toolBarMain->widgetForAction(actionFileSave)); |
---|
437 | if (tb != NULL) { |
---|
438 | tb->setMenu(menuFileSaveAs); |
---|
439 | tb->setPopupMode(QToolButton::MenuButtonPopup); |
---|
440 | tb->resize(tb->sizeHint()); |
---|
441 | } |
---|
442 | |
---|
443 | loadToolbarList(); |
---|
444 | } |
---|
445 | #endif // HANDHELD |
---|
446 | |
---|
447 | void MainWindow::actionHelpCheck4UpdatesTriggered() |
---|
448 | { |
---|
449 | if (!hasUpdater()) { |
---|
450 | QMessageBox::warning(this, tr("Unsupported Feature"), tr("Sorry, but this feature is not supported on your platform\nor support for this feature was not installed.")); |
---|
451 | return; |
---|
452 | } |
---|
453 | |
---|
454 | check4Updates(); |
---|
455 | } |
---|
456 | |
---|
457 | void MainWindow::actionHelpAboutTriggered() |
---|
458 | { |
---|
459 | QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); |
---|
460 | |
---|
461 | QString title; |
---|
462 | title += QString("<b>%1</b><br>").arg(QCoreApplication::applicationName()); |
---|
463 | title += QString("%1: <b>%2</b><br>").arg(tr("Version"), QCoreApplication::applicationVersion()); |
---|
464 | #ifndef HANDHELD |
---|
465 | title += QString("<b>© 2007-%1 <a href=\"http://%2/\">%3</a></b><br>").arg(QDate::currentDate().toString("yyyy"), QCoreApplication::organizationDomain(), QCoreApplication::organizationName()); |
---|
466 | #endif // HANDHELD |
---|
467 | title += QString("<b><a href=\"http://tspsg.info/\">http://tspsg.info/</a></b>"); |
---|
468 | |
---|
469 | QString about; |
---|
470 | about += QString("%1: <b>%2</b><br>").arg(tr("Target OS (ARCH)"), PLATFROM); |
---|
471 | #ifndef STATIC_BUILD |
---|
472 | about += QString("%1 (%2):<br>").arg(tr("Qt library"), tr("shared")); |
---|
473 | about += QString(" %1: <b>%2</b><br>").arg(tr("Build time"), QT_VERSION_STR); |
---|
474 | about += QString(" %1: <b>%2</b><br>").arg(tr("Runtime"), qVersion()); |
---|
475 | #else |
---|
476 | about += QString("%1: <b>%2</b> (%3)<br>").arg(tr("Qt library"), QT_VERSION_STR, tr("static")); |
---|
477 | #endif // STATIC_BUILD |
---|
478 | about += tr("Buid <b>%1</b>, built on <b>%2</b> at <b>%3</b> with <b>%4</b> compiler.").arg(BUILD_NUMBER).arg(__DATE__).arg(__TIME__).arg(COMPILER) + "<br>"; |
---|
479 | about += QString("%1: <b>%2</b><br>").arg(tr("Algorithm"), CTSPSolver::getVersionId()); |
---|
480 | about += "<br>"; |
---|
481 | about += tr("This program is free software: you can redistribute it and/or modify<br>\n" |
---|
482 | "it under the terms of the GNU General Public License as published by<br>\n" |
---|
483 | "the Free Software Foundation, either version 3 of the License, or<br>\n" |
---|
484 | "(at your option) any later version.<br>\n" |
---|
485 | "<br>\n" |
---|
486 | "This program is distributed in the hope that it will be useful,<br>\n" |
---|
487 | "but WITHOUT ANY WARRANTY; without even the implied warranty of<br>\n" |
---|
488 | "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the<br>\n" |
---|
489 | "GNU General Public License for more details.<br>\n" |
---|
490 | "<br>\n" |
---|
491 | "You should have received a copy of the GNU General Public License<br>\n" |
---|
492 | "along with TSPSG. If not, see <a href=\"http://www.gnu.org/licenses/\">www.gnu.org/licenses/</a>."); |
---|
493 | |
---|
494 | QString credits; |
---|
495 | credits += tr("%1 was created using <b>Qt framework</b> licensed " |
---|
496 | "under the terms of the GNU Lesser General Public License,<br>\n" |
---|
497 | "see <a href=\"http://qt.nokia.com/\">qt.nokia.com</a><br>\n" |
---|
498 | "<br>\n" |
---|
499 | "Most icons used in %1 are part of <b>Oxygen Icons</b> project " |
---|
500 | "licensed according to the GNU Lesser General Public License,<br>\n" |
---|
501 | "see <a href=\"http://www.oxygen-icons.org/\">www.oxygen-icons.org</a><br>\n" |
---|
502 | "<br>\n" |
---|
503 | "Country flag icons used in %1 are part of the free " |
---|
504 | "<b>Flag Icons</b> collection created by <b>IconDrawer</b>,<br>\n" |
---|
505 | "see <a href=\"http://www.icondrawer.com/\">www.icondrawer.com</a><br>\n" |
---|
506 | "<br>\n" |
---|
507 | "%1 comes with the default \"embedded\" font <b>DejaVu LGC Sans " |
---|
508 | "Mono</b> from the <b>DejaVu fonts</b> licensed under a Free license</a>,<br>\n" |
---|
509 | "see <a href=\"http://dejavu-fonts.org/\">dejavu-fonts.org</a>") |
---|
510 | .arg("TSPSG"); |
---|
511 | |
---|
512 | QFile f(":/files/COPYING"); |
---|
513 | f.open(QIODevice::ReadOnly); |
---|
514 | |
---|
515 | QString translation = QCoreApplication::translate("--------", "AUTHORS %1", "Please, provide translator credits here. %1 will be replaced with VERSION"); |
---|
516 | if ((translation != "AUTHORS %1") && (translation.contains("%1"))) { |
---|
517 | QString about = QCoreApplication::translate("--------", "VERSION", "Please, provide your translation version here."); |
---|
518 | if (about != "VERSION") |
---|
519 | translation = translation.arg(about); |
---|
520 | } |
---|
521 | |
---|
522 | QDialog *dlg = new QDialog(this); |
---|
523 | QLabel *lblIcon = new QLabel(dlg), |
---|
524 | *lblTitle = new QLabel(dlg); |
---|
525 | #ifdef HANDHELD |
---|
526 | QLabel *lblSubTitle = new QLabel(QString("<b>© 2007-%1 <a href=\"http://%2/\">%3</a></b>").arg(QDate::currentDate().toString("yyyy"), QCoreApplication::organizationDomain(), QCoreApplication::organizationName()), dlg); |
---|
527 | #endif // HANDHELD |
---|
528 | QTabWidget *tabs = new QTabWidget(dlg); |
---|
529 | QTextBrowser *txtAbout = new QTextBrowser(dlg); |
---|
530 | QTextBrowser *txtLicense = new QTextBrowser(dlg); |
---|
531 | QTextBrowser *txtCredits = new QTextBrowser(dlg); |
---|
532 | QVBoxLayout *vb = new QVBoxLayout(); |
---|
533 | QHBoxLayout *hb1 = new QHBoxLayout(), |
---|
534 | *hb2 = new QHBoxLayout(); |
---|
535 | QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Ok, Qt::Horizontal, dlg); |
---|
536 | |
---|
537 | lblTitle->setOpenExternalLinks(true); |
---|
538 | lblTitle->setText(title); |
---|
539 | lblTitle->setAlignment(Qt::AlignTop); |
---|
540 | lblTitle->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); |
---|
541 | #ifndef HANDHELD |
---|
542 | lblTitle->setStyleSheet(QString("QLabel {background-color: %1; border-color: %2; border-width: 1px; border-style: solid; border-radius: 4px; padding: 1px;}").arg(palette().alternateBase().color().name(), palette().shadow().color().name())); |
---|
543 | #endif // HANDHELD |
---|
544 | |
---|
545 | lblIcon->setPixmap(QPixmap(":/images/tspsg.png").scaledToHeight(lblTitle->sizeHint().height(), Qt::SmoothTransformation)); |
---|
546 | lblIcon->setAlignment(Qt::AlignVCenter); |
---|
547 | #ifndef HANDHELD |
---|
548 | lblIcon->setStyleSheet(QString("QLabel {background-color: white; border-color: %1; border-width: 1px; border-style: solid; border-radius: 4px; padding: 1px;}").arg(palette().windowText().color().name())); |
---|
549 | #endif // HANDHELD |
---|
550 | |
---|
551 | hb1->addWidget(lblIcon); |
---|
552 | hb1->addWidget(lblTitle); |
---|
553 | |
---|
554 | txtAbout->setWordWrapMode(QTextOption::NoWrap); |
---|
555 | txtAbout->setOpenExternalLinks(true); |
---|
556 | txtAbout->setHtml(about); |
---|
557 | txtAbout->moveCursor(QTextCursor::Start); |
---|
558 | txtAbout->setFrameShape(QFrame::NoFrame); |
---|
559 | |
---|
560 | // txtCredits->setWordWrapMode(QTextOption::NoWrap); |
---|
561 | txtCredits->setOpenExternalLinks(true); |
---|
562 | txtCredits->setHtml(credits); |
---|
563 | txtCredits->moveCursor(QTextCursor::Start); |
---|
564 | txtCredits->setFrameShape(QFrame::NoFrame); |
---|
565 | |
---|
566 | txtLicense->setWordWrapMode(QTextOption::NoWrap); |
---|
567 | txtLicense->setOpenExternalLinks(true); |
---|
568 | txtLicense->setText(f.readAll()); |
---|
569 | txtLicense->moveCursor(QTextCursor::Start); |
---|
570 | txtLicense->setFrameShape(QFrame::NoFrame); |
---|
571 | |
---|
572 | bb->button(QDialogButtonBox::Ok)->setCursor(QCursor(Qt::PointingHandCursor)); |
---|
573 | bb->button(QDialogButtonBox::Ok)->setIcon(GET_ICON("dialog-ok")); |
---|
574 | |
---|
575 | hb2->addWidget(bb); |
---|
576 | |
---|
577 | #ifdef Q_WS_WINCE_WM |
---|
578 | vb->setMargin(3); |
---|
579 | #endif // Q_WS_WINCE_WM |
---|
580 | vb->addLayout(hb1); |
---|
581 | #ifdef HANDHELD |
---|
582 | vb->addWidget(lblSubTitle); |
---|
583 | #endif // HANDHELD |
---|
584 | |
---|
585 | tabs->addTab(txtAbout, tr("About")); |
---|
586 | tabs->addTab(txtLicense, tr("License")); |
---|
587 | tabs->addTab(txtCredits, tr("Credits")); |
---|
588 | if (translation != "AUTHORS %1") { |
---|
589 | QTextBrowser *txtTranslation = new QTextBrowser(dlg); |
---|
590 | // txtTranslation->setWordWrapMode(QTextOption::NoWrap); |
---|
591 | txtTranslation->setOpenExternalLinks(true); |
---|
592 | txtTranslation->setText(translation); |
---|
593 | txtTranslation->moveCursor(QTextCursor::Start); |
---|
594 | txtTranslation->setFrameShape(QFrame::NoFrame); |
---|
595 | |
---|
596 | tabs->addTab(txtTranslation, tr("Translation")); |
---|
597 | } |
---|
598 | #ifndef HANDHELD |
---|
599 | tabs->setStyleSheet(QString("QTabWidget::pane {background-color: %1; border-color: %3; border-width: 1px; border-style: solid; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; padding: 1px;} QTabBar::tab {background-color: %2; border-color: %3; border-width: 1px; border-style: solid; border-bottom: none; border-top-left-radius: 4px; border-top-right-radius: 4px; padding: 2px 6px;} QTabBar::tab:selected {background-color: %4;} QTabBar::tab:!selected {margin-top: 1px;}").arg(palette().base().color().name(), palette().button().color().name(), palette().shadow().color().name(), palette().light().color().name())); |
---|
600 | #endif // HANDHELD |
---|
601 | |
---|
602 | vb->addWidget(tabs); |
---|
603 | vb->addLayout(hb2); |
---|
604 | |
---|
605 | dlg->setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint); |
---|
606 | dlg->setWindowTitle(tr("About %1").arg(QCoreApplication::applicationName())); |
---|
607 | dlg->setWindowIcon(GET_ICON("help-about")); |
---|
608 | |
---|
609 | dlg->setLayout(vb); |
---|
610 | |
---|
611 | connect(bb, SIGNAL(accepted()), dlg, SLOT(accept())); |
---|
612 | |
---|
613 | #ifndef HANDHELD |
---|
614 | // Adding some eyecandy |
---|
615 | if (QtWin::isCompositionEnabled()) { |
---|
616 | QtWin::enableBlurBehindWindow(dlg, true); |
---|
617 | } |
---|
618 | #endif // HANDHELD |
---|
619 | |
---|
620 | #ifndef HANDHELD |
---|
621 | dlg->resize(450, 350); |
---|
622 | #endif |
---|
623 | QApplication::restoreOverrideCursor(); |
---|
624 | |
---|
625 | dlg->exec(); |
---|
626 | |
---|
627 | delete dlg; |
---|
628 | } |
---|
629 | |
---|
630 | void MainWindow::buttonBackToTaskClicked() |
---|
631 | { |
---|
632 | tabWidget->setCurrentIndex(0); |
---|
633 | } |
---|
634 | |
---|
635 | void MainWindow::buttonRandomClicked() |
---|
636 | { |
---|
637 | QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); |
---|
638 | tspmodel->randomize(); |
---|
639 | QApplication::restoreOverrideCursor(); |
---|
640 | } |
---|
641 | |
---|
642 | void MainWindow::buttonSolveClicked() |
---|
643 | { |
---|
644 | TMatrix matrix; |
---|
645 | QList<double> row; |
---|
646 | int n = spinCities->value(); |
---|
647 | bool ok; |
---|
648 | for (int r = 0; r < n; r++) { |
---|
649 | row.clear(); |
---|
650 | for (int c = 0; c < n; c++) { |
---|
651 | row.append(tspmodel->index(r,c).data(Qt::UserRole).toDouble(&ok)); |
---|
652 | if (!ok) { |
---|
653 | QMessageBox::critical(this, tr("Data error"), tr("Error in cell [Row %1; Column %2]: Invalid data format.").arg(r + 1).arg(c + 1)); |
---|
654 | return; |
---|
655 | } |
---|
656 | } |
---|
657 | matrix.append(row); |
---|
658 | } |
---|
659 | |
---|
660 | QProgressDialog pd(this); |
---|
661 | QProgressBar *pb = new QProgressBar(&pd); |
---|
662 | pb->setAlignment(Qt::AlignCenter); |
---|
663 | pb->setFormat(tr("%v of %1 parts found").arg(n)); |
---|
664 | pd.setBar(pb); |
---|
665 | QPushButton *cancel = new QPushButton(&pd); |
---|
666 | cancel->setIcon(GET_ICON("dialog-cancel")); |
---|
667 | cancel->setText(QCoreApplication::translate("QProgressDialog", "Cancel", "No need to translate this. This translation will be taken from Qt translation files.")); |
---|
668 | pd.setCancelButton(cancel); |
---|
669 | pd.setMaximum(n); |
---|
670 | pd.setAutoReset(false); |
---|
671 | pd.setLabelText(tr("Calculating optimal route...")); |
---|
672 | pd.setWindowTitle(tr("Solution Progress")); |
---|
673 | pd.setWindowModality(Qt::ApplicationModal); |
---|
674 | pd.setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint); |
---|
675 | pd.show(); |
---|
676 | |
---|
677 | #ifdef Q_WS_WIN32 |
---|
678 | HRESULT hr = CoCreateInstance(CLSID_TaskbarList, NULL, CLSCTX_INPROC_SERVER, IID_ITaskbarList3, (LPVOID*)&tl); |
---|
679 | if (SUCCEEDED(hr)) { |
---|
680 | hr = tl->HrInit(); |
---|
681 | if (FAILED(hr)) { |
---|
682 | tl->Release(); |
---|
683 | tl = NULL; |
---|
684 | } else { |
---|
685 | // tl->SetProgressState(winId(), TBPF_INDETERMINATE); |
---|
686 | tl->SetProgressValue(winId(), 0, n * 2); |
---|
687 | } |
---|
688 | } |
---|
689 | #endif |
---|
690 | |
---|
691 | CTSPSolver solver; |
---|
692 | solver.setCleanupOnCancel(false); |
---|
693 | connect(&solver, SIGNAL(routePartFound(int)), &pd, SLOT(setValue(int))); |
---|
694 | connect(&pd, SIGNAL(canceled()), &solver, SLOT(cancel())); |
---|
695 | #ifdef Q_WS_WIN32 |
---|
696 | if (tl != NULL) |
---|
697 | connect(&solver, SIGNAL(routePartFound(int)), SLOT(solverRoutePartFound(int))); |
---|
698 | #endif |
---|
699 | SStep *root = solver.solve(n, matrix); |
---|
700 | #ifdef Q_WS_WIN32 |
---|
701 | if (tl != NULL) |
---|
702 | disconnect(&solver, SIGNAL(routePartFound(int)), this, SLOT(solverRoutePartFound(int))); |
---|
703 | #endif |
---|
704 | disconnect(&solver, SIGNAL(routePartFound(int)), &pd, SLOT(setValue(int))); |
---|
705 | disconnect(&pd, SIGNAL(canceled()), &solver, SLOT(cancel())); |
---|
706 | if (!root) { |
---|
707 | pd.reset(); |
---|
708 | if (!solver.wasCanceled()) { |
---|
709 | #ifdef Q_WS_WIN32 |
---|
710 | if (tl != NULL) { |
---|
711 | // tl->SetProgressValue(winId(), n, n * 2); |
---|
712 | tl->SetProgressState(winId(), TBPF_ERROR); |
---|
713 | } |
---|
714 | #endif |
---|
715 | QApplication::alert(this); |
---|
716 | QMessageBox::warning(this, tr("Solution Result"), tr("Unable to find a solution.\nMaybe, this task has no solution.")); |
---|
717 | } |
---|
718 | pd.setLabelText(tr("Memory cleanup...")); |
---|
719 | pd.setMaximum(0); |
---|
720 | pd.setCancelButton(NULL); |
---|
721 | pd.show(); |
---|
722 | #ifdef Q_WS_WIN32 |
---|
723 | if (tl != NULL) |
---|
724 | tl->SetProgressState(winId(), TBPF_INDETERMINATE); |
---|
725 | #endif |
---|
726 | QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents); |
---|
727 | |
---|
728 | #ifndef QT_NO_CONCURRENT |
---|
729 | QFuture<void> f = QtConcurrent::run(&solver, &CTSPSolver::cleanup, false); |
---|
730 | while (!f.isFinished()) { |
---|
731 | QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents); |
---|
732 | } |
---|
733 | #else |
---|
734 | solver.cleanup(true); |
---|
735 | #endif |
---|
736 | pd.reset(); |
---|
737 | #ifdef Q_WS_WIN32 |
---|
738 | if (tl != NULL) { |
---|
739 | tl->SetProgressState(winId(), TBPF_NOPROGRESS); |
---|
740 | tl->Release(); |
---|
741 | tl = NULL; |
---|
742 | } |
---|
743 | #endif |
---|
744 | return; |
---|
745 | } |
---|
746 | pb->setFormat(tr("Generating header")); |
---|
747 | pd.setLabelText(tr("Generating solution output...")); |
---|
748 | pd.setMaximum(solver.getTotalSteps() + 1); |
---|
749 | pd.setValue(0); |
---|
750 | |
---|
751 | #ifdef Q_WS_WIN32 |
---|
752 | if (tl != NULL) |
---|
753 | tl->SetProgressValue(winId(), spinCities->value(), spinCities->value() + solver.getTotalSteps() + 1); |
---|
754 | #endif |
---|
755 | |
---|
756 | solutionText->clear(); |
---|
757 | solutionText->setDocumentTitle(tr("Solution of Variant #%1 Task").arg(spinVariant->value())); |
---|
758 | |
---|
759 | QPainter pic; |
---|
760 | if (settings->value("Output/ShowGraph", DEF_SHOW_GRAPH).toBool()) { |
---|
761 | pic.begin(&graph); |
---|
762 | pic.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform); |
---|
763 | QFont font = qvariant_cast<QFont>(settings->value("Output/Font", QFont(DEF_FONT_FACE, 9))); |
---|
764 | if (settings->value("Output/HQGraph", DEF_HQ_GRAPH).toBool()) { |
---|
765 | font.setWeight(QFont::DemiBold); |
---|
766 | font.setPointSizeF(font.pointSizeF() * 2); |
---|
767 | } |
---|
768 | pic.setFont(font); |
---|
769 | pic.setBrush(QBrush(QColor(Qt::white))); |
---|
770 | if (settings->value("Output/HQGraph", DEF_HQ_GRAPH).toBool()) { |
---|
771 | QPen pen = pic.pen(); |
---|
772 | pen.setWidth(2); |
---|
773 | pic.setPen(pen); |
---|
774 | } |
---|
775 | pic.setBackgroundMode(Qt::OpaqueMode); |
---|
776 | } |
---|
777 | |
---|
778 | QTextDocument *doc = solutionText->document(); |
---|
779 | QTextCursor cur(doc); |
---|
780 | |
---|
781 | cur.beginEditBlock(); |
---|
782 | cur.setBlockFormat(fmt_paragraph); |
---|
783 | cur.insertText(tr("Variant #%1 Task").arg(spinVariant->value()), fmt_default); |
---|
784 | cur.insertBlock(fmt_paragraph); |
---|
785 | cur.insertText(tr("Task:")); |
---|
786 | outputMatrix(cur, matrix); |
---|
787 | if (settings->value("Output/ShowGraph", DEF_SHOW_GRAPH).toBool()) { |
---|
788 | #ifdef _T_T_L_ |
---|
789 | _b_ _i_ _z_ _a_ _r_ _r_ _e_ |
---|
790 | #endif |
---|
791 | drawNode(pic, 0); |
---|
792 | } |
---|
793 | cur.insertHtml("<hr>"); |
---|
794 | cur.insertBlock(fmt_paragraph); |
---|
795 | int imgpos = cur.position(); |
---|
796 | cur.insertText(tr("Variant #%1 Solution").arg(spinVariant->value()), fmt_default); |
---|
797 | cur.endEditBlock(); |
---|
798 | |
---|
799 | SStep *step = root; |
---|
800 | int c = n = 1; |
---|
801 | pb->setFormat(tr("Generating step %v")); |
---|
802 | while ((step->next != SStep::NoNextStep) && (c < spinCities->value())) { |
---|
803 | if (pd.wasCanceled()) { |
---|
804 | pd.setLabelText(tr("Memory cleanup...")); |
---|
805 | pd.setMaximum(0); |
---|
806 | pd.setCancelButton(NULL); |
---|
807 | pd.show(); |
---|
808 | QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents); |
---|
809 | #ifdef Q_WS_WIN32 |
---|
810 | if (tl != NULL) |
---|
811 | tl->SetProgressState(winId(), TBPF_INDETERMINATE); |
---|
812 | #endif |
---|
813 | #ifndef QT_NO_CONCURRENT |
---|
814 | QFuture<void> f = QtConcurrent::run(&solver, &CTSPSolver::cleanup, false); |
---|
815 | while (!f.isFinished()) { |
---|
816 | QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents); |
---|
817 | } |
---|
818 | #else |
---|
819 | solver.cleanup(true); |
---|
820 | #endif |
---|
821 | solutionText->clear(); |
---|
822 | toggleSolutionActions(false); |
---|
823 | #ifdef Q_WS_WIN32 |
---|
824 | if (tl != NULL) { |
---|
825 | tl->SetProgressState(winId(), TBPF_NOPROGRESS); |
---|
826 | tl->Release(); |
---|
827 | tl = NULL; |
---|
828 | } |
---|
829 | #endif |
---|
830 | return; |
---|
831 | } |
---|
832 | pd.setValue(n); |
---|
833 | #ifdef Q_WS_WIN32 |
---|
834 | if (tl != NULL) |
---|
835 | tl->SetProgressValue(winId(), spinCities->value() + n, spinCities->value() + solver.getTotalSteps() + 1); |
---|
836 | #endif |
---|
837 | |
---|
838 | cur.beginEditBlock(); |
---|
839 | cur.insertBlock(fmt_paragraph); |
---|
840 | cur.insertText(tr("Step #%1").arg(n)); |
---|
841 | if (settings->value("Output/ShowMatrix", DEF_SHOW_MATRIX).toBool() && (!settings->value("Output/UseShowMatrixLimit", DEF_USE_SHOW_MATRIX_LIMIT).toBool() || (settings->value("Output/UseShowMatrixLimit", DEF_USE_SHOW_MATRIX_LIMIT).toBool() && (spinCities->value() <= settings->value("Output/ShowMatrixLimit", DEF_SHOW_MATRIX_LIMIT).toInt())))) { |
---|
842 | outputMatrix(cur, *step); |
---|
843 | } |
---|
844 | cur.insertBlock(fmt_paragraph); |
---|
845 | cur.insertText(tr("Selected route %1 %2 part.").arg((step->next == SStep::RightBranch) ? tr("with") : tr("without")).arg(tr("(%1;%2)").arg(step->candidate.nRow + 1).arg(step->candidate.nCol + 1)), fmt_default); |
---|
846 | if (!step->alts.empty()) { |
---|
847 | SStep::SCandidate cand; |
---|
848 | QString alts; |
---|
849 | foreach(cand, step->alts) { |
---|
850 | if (!alts.isEmpty()) |
---|
851 | alts += ", "; |
---|
852 | alts += tr("(%1;%2)").arg(cand.nRow + 1).arg(cand.nCol + 1); |
---|
853 | } |
---|
854 | cur.insertBlock(fmt_paragraph); |
---|
855 | cur.insertText(tr("%n alternate candidate(s) for branching: %1.", "", step->alts.count()).arg(alts), fmt_altlist); |
---|
856 | } |
---|
857 | cur.insertBlock(fmt_paragraph); |
---|
858 | cur.insertText(" ", fmt_default); |
---|
859 | cur.endEditBlock(); |
---|
860 | |
---|
861 | if (settings->value("Output/ShowGraph", DEF_SHOW_GRAPH).toBool()) { |
---|
862 | if (step->prNode != NULL) |
---|
863 | drawNode(pic, n, false, step->prNode); |
---|
864 | if (step->plNode != NULL) |
---|
865 | drawNode(pic, n, true, step->plNode); |
---|
866 | } |
---|
867 | n++; |
---|
868 | |
---|
869 | if (step->next == SStep::RightBranch) { |
---|
870 | c++; |
---|
871 | step = step->prNode; |
---|
872 | } else if (step->next == SStep::LeftBranch) { |
---|
873 | step = step->plNode; |
---|
874 | } else |
---|
875 | break; |
---|
876 | } |
---|
877 | pb->setFormat(tr("Generating footer")); |
---|
878 | pd.setValue(n); |
---|
879 | #ifdef Q_WS_WIN32 |
---|
880 | if (tl != NULL) |
---|
881 | tl->SetProgressValue(winId(), spinCities->value() + n, spinCities->value() + solver.getTotalSteps() + 1); |
---|
882 | #endif |
---|
883 | |
---|
884 | cur.beginEditBlock(); |
---|
885 | cur.insertBlock(fmt_paragraph); |
---|
886 | if (solver.isOptimal()) |
---|
887 | cur.insertText(tr("Optimal path:")); |
---|
888 | else |
---|
889 | cur.insertText(tr("Resulting path:")); |
---|
890 | |
---|
891 | cur.insertBlock(fmt_paragraph); |
---|
892 | cur.insertText(" " + solver.getSortedPath(tr("City %1"))); |
---|
893 | |
---|
894 | cur.insertBlock(fmt_paragraph); |
---|
895 | if (isInteger(step->price)) |
---|
896 | cur.insertHtml("<p>" + tr("The price is <b>%n</b> unit(s).", "", qRound(step->price)) + "</p>"); |
---|
897 | else |
---|
898 | cur.insertHtml("<p>" + tr("The price is <b>%1</b> units.").arg(step->price, 0, 'f', settings->value("Task/FractionalAccuracy", DEF_FRACTIONAL_ACCURACY).toInt()) + "</p>"); |
---|
899 | if (!solver.isOptimal()) { |
---|
900 | cur.insertBlock(fmt_paragraph); |
---|
901 | cur.insertText(" "); |
---|
902 | cur.insertBlock(fmt_paragraph); |
---|
903 | cur.insertHtml("<p>" + tr("<b>WARNING!!!</b><br>This result is a record, but it may not be optimal.<br>Iterations need to be continued to check whether this result is optimal or get an optimal one.") + "</p>"); |
---|
904 | } |
---|
905 | cur.endEditBlock(); |
---|
906 | |
---|
907 | if (settings->value("Output/ShowGraph", DEF_SHOW_GRAPH).toBool()) { |
---|
908 | pic.end(); |
---|
909 | |
---|
910 | QImage i(graph.width() + 2, graph.height() + 2, QImage::Format_RGB32); |
---|
911 | i.fill(0xFFFFFF); |
---|
912 | pic.begin(&i); |
---|
913 | pic.drawPicture(1, 1, graph); |
---|
914 | pic.end(); |
---|
915 | doc->addResource(QTextDocument::ImageResource, QUrl("tspsg://graph.pic"), i); |
---|
916 | |
---|
917 | QTextImageFormat img; |
---|
918 | img.setName("tspsg://graph.pic"); |
---|
919 | if (settings->value("Output/HQGraph", DEF_HQ_GRAPH).toBool()) { |
---|
920 | img.setWidth(i.width() / 2); |
---|
921 | img.setHeight(i.height() / 2); |
---|
922 | } else { |
---|
923 | img.setWidth(i.width()); |
---|
924 | img.setHeight(i.height()); |
---|
925 | } |
---|
926 | |
---|
927 | cur.setPosition(imgpos); |
---|
928 | cur.insertImage(img, QTextFrameFormat::FloatRight); |
---|
929 | } |
---|
930 | |
---|
931 | if (settings->value("Output/ScrollToEnd", DEF_SCROLL_TO_END).toBool()) { |
---|
932 | // Scrolling to the end of the text. |
---|
933 | solutionText->moveCursor(QTextCursor::End); |
---|
934 | } else |
---|
935 | solutionText->moveCursor(QTextCursor::Start); |
---|
936 | |
---|
937 | pd.setLabelText(tr("Memory cleanup...")); |
---|
938 | pd.setMaximum(0); |
---|
939 | pd.setCancelButton(NULL); |
---|
940 | QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents); |
---|
941 | #ifdef Q_WS_WIN32 |
---|
942 | if (tl != NULL) |
---|
943 | tl->SetProgressState(winId(), TBPF_INDETERMINATE); |
---|
944 | #endif |
---|
945 | #ifndef QT_NO_CONCURRENT |
---|
946 | QFuture<void> f = QtConcurrent::run(&solver, &CTSPSolver::cleanup, false); |
---|
947 | while (!f.isFinished()) { |
---|
948 | QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents); |
---|
949 | } |
---|
950 | #else |
---|
951 | solver.cleanup(true); |
---|
952 | #endif |
---|
953 | toggleSolutionActions(); |
---|
954 | tabWidget->setCurrentIndex(1); |
---|
955 | #ifdef Q_WS_WIN32 |
---|
956 | if (tl != NULL) { |
---|
957 | tl->SetProgressState(winId(), TBPF_NOPROGRESS); |
---|
958 | tl->Release(); |
---|
959 | tl = NULL; |
---|
960 | } |
---|
961 | #endif |
---|
962 | |
---|
963 | pd.reset(); |
---|
964 | QApplication::alert(this, 3000); |
---|
965 | } |
---|
966 | |
---|
967 | void MainWindow::dataChanged() |
---|
968 | { |
---|
969 | setWindowModified(true); |
---|
970 | } |
---|
971 | |
---|
972 | void MainWindow::dataChanged(const QModelIndex &tl, const QModelIndex &br) |
---|
973 | { |
---|
974 | setWindowModified(true); |
---|
975 | if (settings->value("Autosize", DEF_AUTOSIZE).toBool()) { |
---|
976 | for (int k = tl.row(); k <= br.row(); k++) |
---|
977 | taskView->resizeRowToContents(k); |
---|
978 | for (int k = tl.column(); k <= br.column(); k++) |
---|
979 | taskView->resizeColumnToContents(k); |
---|
980 | } |
---|
981 | } |
---|
982 | |
---|
983 | #ifdef Q_WS_WINCE_WM |
---|
984 | void MainWindow::changeEvent(QEvent *ev) |
---|
985 | { |
---|
986 | if ((ev->type() == QEvent::ActivationChange) && isActiveWindow()) |
---|
987 | desktopResized(0); |
---|
988 | |
---|
989 | QWidget::changeEvent(ev); |
---|
990 | } |
---|
991 | |
---|
992 | void MainWindow::desktopResized(int screen) |
---|
993 | { |
---|
994 | if ((screen != 0) || !isActiveWindow()) |
---|
995 | return; |
---|
996 | |
---|
997 | QRect availableGeometry = QApplication::desktop()->availableGeometry(0); |
---|
998 | if (currentGeometry != availableGeometry) { |
---|
999 | QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); |
---|
1000 | /*! |
---|
1001 | * \hack HACK: This hack checks whether \link QDesktopWidget::availableGeometry() availableGeometry()\endlink's \c top + \c hegiht = \link QDesktopWidget::screenGeometry() screenGeometry()\endlink's \c height. |
---|
1002 | * If \c true, the window gets maximized. If we used \c setGeometry() in this case, the bottom of the |
---|
1003 | * window would end up being behind the soft buttons. Is this a bug in Qt or Windows Mobile? |
---|
1004 | */ |
---|
1005 | if ((availableGeometry.top() + availableGeometry.height()) == QApplication::desktop()->screenGeometry().height()) { |
---|
1006 | setWindowState(windowState() | Qt::WindowMaximized); |
---|
1007 | } else { |
---|
1008 | if (windowState() & Qt::WindowMaximized) |
---|
1009 | setWindowState(windowState() ^ Qt::WindowMaximized); |
---|
1010 | setGeometry(availableGeometry); |
---|
1011 | } |
---|
1012 | currentGeometry = availableGeometry; |
---|
1013 | QApplication::restoreOverrideCursor(); |
---|
1014 | } |
---|
1015 | } |
---|
1016 | #endif // Q_WS_WINCE_WM |
---|
1017 | |
---|
1018 | void MainWindow::numCitiesChanged(int nCities) |
---|
1019 | { |
---|
1020 | blockSignals(true); |
---|
1021 | spinCities->setValue(nCities); |
---|
1022 | blockSignals(false); |
---|
1023 | } |
---|
1024 | |
---|
1025 | #ifndef QT_NO_PRINTER |
---|
1026 | void MainWindow::printPreview(QPrinter *printer) |
---|
1027 | { |
---|
1028 | solutionText->print(printer); |
---|
1029 | } |
---|
1030 | #endif // QT_NO_PRINTER |
---|
1031 | |
---|
1032 | #ifdef Q_WS_WIN32 |
---|
1033 | void MainWindow::solverRoutePartFound(int n) |
---|
1034 | { |
---|
1035 | tl->SetProgressValue(winId(), n, spinCities->value() * 2); |
---|
1036 | } |
---|
1037 | #endif // Q_WS_WIN32 |
---|
1038 | |
---|
1039 | void MainWindow::spinCitiesValueChanged(int n) |
---|
1040 | { |
---|
1041 | QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); |
---|
1042 | int count = tspmodel->numCities(); |
---|
1043 | tspmodel->setNumCities(n); |
---|
1044 | if ((n > count) && settings->value("Autosize", DEF_AUTOSIZE).toBool()) |
---|
1045 | for (int k = count; k < n; k++) { |
---|
1046 | taskView->resizeColumnToContents(k); |
---|
1047 | taskView->resizeRowToContents(k); |
---|
1048 | } |
---|
1049 | QApplication::restoreOverrideCursor(); |
---|
1050 | } |
---|
1051 | |
---|
1052 | void MainWindow::check4Updates(bool silent) |
---|
1053 | { |
---|
1054 | #ifdef Q_WS_WIN32 |
---|
1055 | if (silent) |
---|
1056 | QProcess::startDetached("updater/Update.exe -name=\"TSPSG: TSP Solver and Generator\" -check=\"freeupdate\" -silentcheck"); |
---|
1057 | else { |
---|
1058 | QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); |
---|
1059 | QProcess::execute("updater/Update.exe -name=\"TSPSG: TSP Solver and Generator\" -check=\"freeupdate\""); |
---|
1060 | QApplication::restoreOverrideCursor(); |
---|
1061 | } |
---|
1062 | #else |
---|
1063 | Q_UNUSED(silent) |
---|
1064 | #endif |
---|
1065 | settings->setValue("Check4Updates/LastAttempt", QDate::currentDate().toString(Qt::ISODate)); |
---|
1066 | } |
---|
1067 | |
---|
1068 | void MainWindow::closeEvent(QCloseEvent *ev) |
---|
1069 | { |
---|
1070 | if (!maybeSave()) { |
---|
1071 | ev->ignore(); |
---|
1072 | return; |
---|
1073 | } |
---|
1074 | if (!settings->value("SettingsReset", false).toBool()) { |
---|
1075 | settings->setValue("NumCities", spinCities->value()); |
---|
1076 | |
---|
1077 | // Saving Main Window state |
---|
1078 | #ifndef HANDHELD |
---|
1079 | if (settings->value("SavePos", DEF_SAVEPOS).toBool()) { |
---|
1080 | settings->beginGroup("MainWindow"); |
---|
1081 | settings->setValue("Geometry", saveGeometry()); |
---|
1082 | settings->setValue("State", saveState()); |
---|
1083 | settings->setValue("Toolbars", toolBarManager->saveState()); |
---|
1084 | settings->endGroup(); |
---|
1085 | } |
---|
1086 | #else |
---|
1087 | settings->setValue("MainWindow/ToolbarVisible", toolBarMain->isVisible()); |
---|
1088 | #endif // HANDHELD |
---|
1089 | } else { |
---|
1090 | settings->remove("SettingsReset"); |
---|
1091 | } |
---|
1092 | |
---|
1093 | QMainWindow::closeEvent(ev); |
---|
1094 | } |
---|
1095 | |
---|
1096 | void MainWindow::dragEnterEvent(QDragEnterEvent *ev) |
---|
1097 | { |
---|
1098 | if (ev->mimeData()->hasUrls() && (ev->mimeData()->urls().count() == 1)) { |
---|
1099 | QFileInfo fi(ev->mimeData()->urls().first().toLocalFile()); |
---|
1100 | if ((fi.suffix() == "tspt") || (fi.suffix() == "zkt")) |
---|
1101 | ev->acceptProposedAction(); |
---|
1102 | } |
---|
1103 | } |
---|
1104 | |
---|
1105 | void MainWindow::drawNode(QPainter &pic, int nstep, bool left, SStep *step) |
---|
1106 | { |
---|
1107 | int r; |
---|
1108 | if (settings->value("Output/HQGraph", DEF_HQ_GRAPH).toBool()) |
---|
1109 | r = logicalDpiX() / 1.27; |
---|
1110 | else |
---|
1111 | r = logicalDpiX() / 2.54; |
---|
1112 | qreal x, y; |
---|
1113 | if (step != NULL) |
---|
1114 | x = left ? r : r * 3.5; |
---|
1115 | else |
---|
1116 | x = r * 2.25; |
---|
1117 | y = r * (3 * nstep + 1); |
---|
1118 | |
---|
1119 | #ifdef _T_T_L_ |
---|
1120 | if (nstep == -481124) { |
---|
1121 | _t_t_l_(pic, r, x); |
---|
1122 | return; |
---|
1123 | } |
---|
1124 | #endif |
---|
1125 | |
---|
1126 | pic.drawEllipse(QPointF(x, y), r, r); |
---|
1127 | |
---|
1128 | if (step != NULL) { |
---|
1129 | QFont font; |
---|
1130 | if (left) { |
---|
1131 | font = pic.font(); |
---|
1132 | font.setStrikeOut(true); |
---|
1133 | pic.setFont(font); |
---|
1134 | } |
---|
1135 | pic.drawText(QRectF(x - r, y - r, r * 2, r * 2), Qt::AlignCenter, tr("(%1;%2)").arg(step->pNode->candidate.nRow + 1).arg(step->pNode->candidate.nCol + 1) + "\n"); |
---|
1136 | if (left) { |
---|
1137 | font.setStrikeOut(false); |
---|
1138 | pic.setFont(font); |
---|
1139 | } |
---|
1140 | if (step->price != INFINITY) { |
---|
1141 | pic.drawText(QRectF(x - r, y - r, r * 2, r * 2), Qt::AlignCenter, isInteger(step->price) ? QString("\n%1").arg(step->price) : QString("\n%1").arg(step->price, 0, 'f', settings->value("Task/FractionalAccuracy", DEF_FRACTIONAL_ACCURACY).toInt())); |
---|
1142 | } else { |
---|
1143 | pic.drawText(QRectF(x - r, y - r, r * 2, r * 2), Qt::AlignCenter, "\n"INFSTR); |
---|
1144 | } |
---|
1145 | } else { |
---|
1146 | pic.drawText(QRectF(x - r, y - r, r * 2, r * 2), Qt::AlignCenter, tr("Root")); |
---|
1147 | } |
---|
1148 | |
---|
1149 | if (nstep == 1) { |
---|
1150 | pic.drawLine(QPointF(x, y - r), QPointF(r * 2.25, y - 2 * r)); |
---|
1151 | } else if (nstep > 1) { |
---|
1152 | pic.drawLine(QPointF(x, y - r), QPointF((step->pNode->pNode->next == SStep::RightBranch) ? r * 3.5 : r, y - 2 * r)); |
---|
1153 | } |
---|
1154 | |
---|
1155 | } |
---|
1156 | |
---|
1157 | void MainWindow::dropEvent(QDropEvent *ev) |
---|
1158 | { |
---|
1159 | if (maybeSave() && tspmodel->loadTask(ev->mimeData()->urls().first().toLocalFile())) { |
---|
1160 | setFileName(ev->mimeData()->urls().first().toLocalFile()); |
---|
1161 | tabWidget->setCurrentIndex(0); |
---|
1162 | setWindowModified(false); |
---|
1163 | solutionText->clear(); |
---|
1164 | toggleSolutionActions(false); |
---|
1165 | |
---|
1166 | ev->setDropAction(Qt::CopyAction); |
---|
1167 | ev->accept(); |
---|
1168 | } |
---|
1169 | } |
---|
1170 | |
---|
1171 | void MainWindow::initDocStyleSheet() |
---|
1172 | { |
---|
1173 | solutionText->document()->setDefaultFont(qvariant_cast<QFont>(settings->value("Output/Font", QFont(DEF_FONT_FACE, DEF_FONT_SIZE)))); |
---|
1174 | |
---|
1175 | fmt_paragraph.setTopMargin(0); |
---|
1176 | fmt_paragraph.setRightMargin(10); |
---|
1177 | fmt_paragraph.setBottomMargin(0); |
---|
1178 | fmt_paragraph.setLeftMargin(10); |
---|
1179 | |
---|
1180 | fmt_table.setTopMargin(5); |
---|
1181 | fmt_table.setRightMargin(10); |
---|
1182 | fmt_table.setBottomMargin(5); |
---|
1183 | fmt_table.setLeftMargin(10); |
---|
1184 | fmt_table.setBorder(0); |
---|
1185 | fmt_table.setBorderStyle(QTextFrameFormat::BorderStyle_None); |
---|
1186 | fmt_table.setCellSpacing(5); |
---|
1187 | |
---|
1188 | fmt_cell.setAlignment(Qt::AlignHCenter); |
---|
1189 | |
---|
1190 | settings->beginGroup("Output/Colors"); |
---|
1191 | |
---|
1192 | QColor color = qvariant_cast<QColor>(settings->value("Text", DEF_TEXT_COLOR)); |
---|
1193 | QColor hilight; |
---|
1194 | if (color.value() < 192) |
---|
1195 | hilight.setHsv(color.hue(), color.saturation(), 127 + qRound(color.value() / 2)); |
---|
1196 | else |
---|
1197 | hilight.setHsv(color.hue(), color.saturation(), color.value() / 2); |
---|
1198 | |
---|
1199 | solutionText->document()->setDefaultStyleSheet(QString("* {color: %1;}").arg(color.name())); |
---|
1200 | fmt_default.setForeground(QBrush(color)); |
---|
1201 | |
---|
1202 | fmt_selected.setForeground(QBrush(qvariant_cast<QColor>(settings->value("Selected", DEF_SELECTED_COLOR)))); |
---|
1203 | fmt_selected.setFontWeight(QFont::Bold); |
---|
1204 | |
---|
1205 | fmt_alternate.setForeground(QBrush(qvariant_cast<QColor>(settings->value("Alternate", DEF_ALTERNATE_COLOR)))); |
---|
1206 | fmt_alternate.setFontWeight(QFont::Bold); |
---|
1207 | fmt_altlist.setForeground(QBrush(hilight)); |
---|
1208 | |
---|
1209 | settings->endGroup(); |
---|
1210 | |
---|
1211 | solutionText->setTextColor(color); |
---|
1212 | } |
---|
1213 | |
---|
1214 | void MainWindow::loadLangList() |
---|
1215 | { |
---|
1216 | QMap<QString, QStringList> langlist; |
---|
1217 | QFileInfoList langs; |
---|
1218 | QFileInfo lang; |
---|
1219 | QStringList language, dirs; |
---|
1220 | QTranslator t; |
---|
1221 | QDir dir; |
---|
1222 | dir.setFilter(QDir::Files); |
---|
1223 | dir.setNameFilters(QStringList("tspsg_*.qm")); |
---|
1224 | dir.setSorting(QDir::NoSort); |
---|
1225 | |
---|
1226 | dirs << PATH_L10N << ":/l10n"; |
---|
1227 | foreach (QString dirname, dirs) { |
---|
1228 | dir.setPath(dirname); |
---|
1229 | if (dir.exists()) { |
---|
1230 | langs = dir.entryInfoList(); |
---|
1231 | for (int k = 0; k < langs.size(); k++) { |
---|
1232 | lang = langs.at(k); |
---|
1233 | if (lang.completeBaseName().compare("tspsg_en", Qt::CaseInsensitive) && !langlist.contains(lang.completeBaseName().mid(6)) && t.load(lang.completeBaseName(), dirname)) { |
---|
1234 | |
---|
1235 | language.clear(); |
---|
1236 | language.append(lang.completeBaseName().mid(6)); |
---|
1237 | language.append(t.translate("--------", "COUNTRY", "Please, provide an ISO 3166-1 alpha-2 country code for this translation language here (eg., UA).").toLower()); |
---|
1238 | language.append(t.translate("--------", "LANGNAME", "Please, provide a native name of your translation language here.")); |
---|
1239 | language.append(t.translate("MainWindow", "Set application language to %1", "").arg(language.at(2))); |
---|
1240 | |
---|
1241 | langlist.insert(language.at(0), language); |
---|
1242 | } |
---|
1243 | } |
---|
1244 | } |
---|
1245 | } |
---|
1246 | |
---|
1247 | QAction *a; |
---|
1248 | foreach (language, langlist) { |
---|
1249 | a = menuSettingsLanguage->addAction(language.at(2)); |
---|
1250 | #ifndef QT_NO_STATUSTIP |
---|
1251 | a->setStatusTip(language.at(3)); |
---|
1252 | #endif |
---|
1253 | #if QT_VERSION >= 0x040600 |
---|
1254 | a->setIcon(QIcon::fromTheme(QString("flag-%1").arg(language.at(1)), QIcon(QString(":/images/icons/l10n/flag-%1.png").arg(language.at(1))))); |
---|
1255 | #else |
---|
1256 | a->setIcon(QIcon(QString(":/images/icons/l10n/flag-%1.png").arg(language.at(1)))); |
---|
1257 | #endif |
---|
1258 | a->setData(language.at(0)); |
---|
1259 | a->setCheckable(true); |
---|
1260 | a->setActionGroup(groupSettingsLanguageList); |
---|
1261 | if (settings->value("Language", QLocale::system().name()).toString().startsWith(language.at(0))) |
---|
1262 | a->setChecked(true); |
---|
1263 | } |
---|
1264 | } |
---|
1265 | |
---|
1266 | bool MainWindow::loadLanguage(const QString &lang) |
---|
1267 | { |
---|
1268 | // i18n |
---|
1269 | bool ad = false; |
---|
1270 | QString lng = lang; |
---|
1271 | if (lng.isEmpty()) { |
---|
1272 | ad = settings->value("Language").toString().isEmpty(); |
---|
1273 | lng = settings->value("Language", QLocale::system().name()).toString(); |
---|
1274 | } |
---|
1275 | static QTranslator *qtTranslator; // Qt library translator |
---|
1276 | if (qtTranslator) { |
---|
1277 | qApp->removeTranslator(qtTranslator); |
---|
1278 | delete qtTranslator; |
---|
1279 | qtTranslator = NULL; |
---|
1280 | } |
---|
1281 | static QTranslator *translator; // Application translator |
---|
1282 | if (translator) { |
---|
1283 | qApp->removeTranslator(translator); |
---|
1284 | delete translator; |
---|
1285 | translator = NULL; |
---|
1286 | } |
---|
1287 | |
---|
1288 | if (lng == "en") |
---|
1289 | return true; |
---|
1290 | |
---|
1291 | // Trying to load system Qt library translation... |
---|
1292 | qtTranslator = new QTranslator(this); |
---|
1293 | if (qtTranslator->load("qt_" + lng, QLibraryInfo::location(QLibraryInfo::TranslationsPath))) |
---|
1294 | qApp->installTranslator(qtTranslator); |
---|
1295 | else { |
---|
1296 | // No luck. Let's try to load a bundled one. |
---|
1297 | if (qtTranslator->load("qt_" + lng, PATH_L10N)) { |
---|
1298 | // We have a translation in the localization direcotry. |
---|
1299 | qApp->installTranslator(qtTranslator); |
---|
1300 | } else if (qtTranslator->load("qt_" + lng, ":/l10n")) { |
---|
1301 | // We have a translation "built-in" into application resources. |
---|
1302 | qApp->installTranslator(qtTranslator); |
---|
1303 | } else { |
---|
1304 | // Qt library translation unavailable for this language. |
---|
1305 | delete qtTranslator; |
---|
1306 | qtTranslator = NULL; |
---|
1307 | } |
---|
1308 | } |
---|
1309 | |
---|
1310 | // Now let's load application translation. |
---|
1311 | translator = new QTranslator(this); |
---|
1312 | if (translator->load("tspsg_" + lng, PATH_L10N)) { |
---|
1313 | // We have a translation in the localization directory. |
---|
1314 | qApp->installTranslator(translator); |
---|
1315 | } else if (translator->load("tspsg_" + lng, ":/l10n")) { |
---|
1316 | // We have a translation "built-in" into application resources. |
---|
1317 | qApp->installTranslator(translator); |
---|
1318 | } else { |
---|
1319 | delete translator; |
---|
1320 | translator = NULL; |
---|
1321 | if (!ad) { |
---|
1322 | settings->remove("Language"); |
---|
1323 | QApplication::setOverrideCursor(QCursor(Qt::ArrowCursor)); |
---|
1324 | QMessageBox::warning(isVisible() ? this : NULL, tr("Language Change"), tr("Unable to load the translation language.\nFalling back to autodetection.")); |
---|
1325 | QApplication::restoreOverrideCursor(); |
---|
1326 | } |
---|
1327 | return false; |
---|
1328 | } |
---|
1329 | return true; |
---|
1330 | } |
---|
1331 | |
---|
1332 | void MainWindow::loadStyleList() |
---|
1333 | { |
---|
1334 | menuSettingsStyle->clear(); |
---|
1335 | QStringList styles = QStyleFactory::keys(); |
---|
1336 | menuSettingsStyle->insertAction(NULL, actionSettingsStyleSystem); |
---|
1337 | actionSettingsStyleSystem->setChecked(!settings->contains("Style")); |
---|
1338 | menuSettingsStyle->addSeparator(); |
---|
1339 | QAction *a; |
---|
1340 | foreach (QString style, styles) { |
---|
1341 | a = menuSettingsStyle->addAction(style); |
---|
1342 | a->setData(false); |
---|
1343 | #ifndef QT_NO_STATUSTIP |
---|
1344 | a->setStatusTip(tr("Set application style to %1").arg(style)); |
---|
1345 | #endif |
---|
1346 | a->setCheckable(true); |
---|
1347 | a->setActionGroup(groupSettingsStyleList); |
---|
1348 | if ((style == settings->value("Stlye").toString()) |
---|
1349 | #ifndef Q_WS_MAEMO_5 |
---|
1350 | || QString(QApplication::style()->metaObject()->className()).contains(QRegExp(QString("^Q?%1(Style)?$").arg(QRegExp::escape(style)), Qt::CaseInsensitive)) |
---|
1351 | #endif |
---|
1352 | ) { |
---|
1353 | a->setChecked(true); |
---|
1354 | } |
---|
1355 | } |
---|
1356 | } |
---|
1357 | |
---|
1358 | void MainWindow::loadToolbarList() |
---|
1359 | { |
---|
1360 | menuSettingsToolbars->clear(); |
---|
1361 | #ifndef HANDHELD |
---|
1362 | menuSettingsToolbars->insertAction(NULL, actionSettingsToolbarsConfigure); |
---|
1363 | menuSettingsToolbars->addSeparator(); |
---|
1364 | QList<QToolBar *> list = toolBarManager->toolBars(); |
---|
1365 | foreach (QToolBar *t, list) { |
---|
1366 | menuSettingsToolbars->insertAction(NULL, t->toggleViewAction()); |
---|
1367 | } |
---|
1368 | #else // HANDHELD |
---|
1369 | menuSettingsToolbars->insertAction(NULL, toolBarMain->toggleViewAction()); |
---|
1370 | #endif // HANDHELD |
---|
1371 | } |
---|
1372 | |
---|
1373 | bool MainWindow::maybeSave() |
---|
1374 | { |
---|
1375 | if (!isWindowModified()) |
---|
1376 | return true; |
---|
1377 | int res = QMessageBox::warning(this, tr("Unsaved Changes"), tr("Would you like to save changes in the current task?"), QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel); |
---|
1378 | if (res == QMessageBox::Save) |
---|
1379 | return actionFileSaveTriggered(); |
---|
1380 | else if (res == QMessageBox::Cancel) |
---|
1381 | return false; |
---|
1382 | else |
---|
1383 | return true; |
---|
1384 | } |
---|
1385 | |
---|
1386 | void MainWindow::outputMatrix(QTextCursor &cur, const TMatrix &matrix) |
---|
1387 | { |
---|
1388 | int n = spinCities->value(); |
---|
1389 | QTextTable *table = cur.insertTable(n, n, fmt_table); |
---|
1390 | |
---|
1391 | for (int r = 0; r < n; r++) { |
---|
1392 | for (int c = 0; c < n; c++) { |
---|
1393 | cur = table->cellAt(r, c).firstCursorPosition(); |
---|
1394 | cur.setBlockFormat(fmt_cell); |
---|
1395 | cur.setBlockCharFormat(fmt_default); |
---|
1396 | if (matrix.at(r).at(c) == INFINITY) |
---|
1397 | cur.insertText(INFSTR); |
---|
1398 | else |
---|
1399 | cur.insertText(isInteger(matrix.at(r).at(c)) ? QString("%1").arg(matrix.at(r).at(c)) : QString("%1").arg(matrix.at(r).at(c), 0, 'f', settings->value("Task/FractionalAccuracy", DEF_FRACTIONAL_ACCURACY).toInt())); |
---|
1400 | } |
---|
1401 | QCoreApplication::processEvents(); |
---|
1402 | } |
---|
1403 | cur.movePosition(QTextCursor::End); |
---|
1404 | } |
---|
1405 | |
---|
1406 | void MainWindow::outputMatrix(QTextCursor &cur, const SStep &step) |
---|
1407 | { |
---|
1408 | int n = spinCities->value(); |
---|
1409 | QTextTable *table = cur.insertTable(n, n, fmt_table); |
---|
1410 | |
---|
1411 | for (int r = 0; r < n; r++) { |
---|
1412 | for (int c = 0; c < n; c++) { |
---|
1413 | cur = table->cellAt(r, c).firstCursorPosition(); |
---|
1414 | cur.setBlockFormat(fmt_cell); |
---|
1415 | if (step.matrix.at(r).at(c) == INFINITY) |
---|
1416 | cur.insertText(INFSTR, fmt_default); |
---|
1417 | else if ((r == step.candidate.nRow) && (c == step.candidate.nCol)) |
---|
1418 | cur.insertText(isInteger(step.matrix.at(r).at(c)) ? QString("%1").arg(step.matrix.at(r).at(c)) : QString("%1").arg(step.matrix.at(r).at(c), 0, 'f', settings->value("Task/FractionalAccuracy", DEF_FRACTIONAL_ACCURACY).toInt()), fmt_selected); |
---|
1419 | else { |
---|
1420 | SStep::SCandidate cand; |
---|
1421 | cand.nRow = r; |
---|
1422 | cand.nCol = c; |
---|
1423 | if (step.alts.contains(cand)) |
---|
1424 | cur.insertText(isInteger(step.matrix.at(r).at(c)) ? QString("%1").arg(step.matrix.at(r).at(c)) : QString("%1").arg(step.matrix.at(r).at(c), 0, 'f', settings->value("Task/FractionalAccuracy", DEF_FRACTIONAL_ACCURACY).toInt()), fmt_alternate); |
---|
1425 | else |
---|
1426 | cur.insertText(isInteger(step.matrix.at(r).at(c)) ? QString("%1").arg(step.matrix.at(r).at(c)) : QString("%1").arg(step.matrix.at(r).at(c), 0, 'f', settings->value("Task/FractionalAccuracy", DEF_FRACTIONAL_ACCURACY).toInt()), fmt_default); |
---|
1427 | } |
---|
1428 | } |
---|
1429 | QCoreApplication::processEvents(); |
---|
1430 | } |
---|
1431 | |
---|
1432 | cur.movePosition(QTextCursor::End); |
---|
1433 | } |
---|
1434 | |
---|
1435 | void MainWindow::retranslateUi(bool all) |
---|
1436 | { |
---|
1437 | if (all) |
---|
1438 | Ui_MainWindow::retranslateUi(this); |
---|
1439 | |
---|
1440 | loadStyleList(); |
---|
1441 | loadToolbarList(); |
---|
1442 | |
---|
1443 | #ifndef QT_NO_PRINTER |
---|
1444 | actionFilePrintPreview->setText(tr("P&rint Preview...")); |
---|
1445 | #ifndef QT_NO_TOOLTIP |
---|
1446 | actionFilePrintPreview->setToolTip(tr("Preview solution results")); |
---|
1447 | #endif // QT_NO_TOOLTIP |
---|
1448 | #ifndef QT_NO_STATUSTIP |
---|
1449 | actionFilePrintPreview->setStatusTip(tr("Preview current solution results before printing")); |
---|
1450 | actionFileExit->setStatusTip(tr("Exit %1").arg(QCoreApplication::applicationName())); |
---|
1451 | #endif // QT_NO_STATUSTIP |
---|
1452 | |
---|
1453 | actionFilePrint->setText(tr("&Print...")); |
---|
1454 | #ifndef QT_NO_TOOLTIP |
---|
1455 | actionFilePrint->setToolTip(tr("Print solution")); |
---|
1456 | #endif // QT_NO_TOOLTIP |
---|
1457 | #ifndef QT_NO_STATUSTIP |
---|
1458 | actionFilePrint->setStatusTip(tr("Print current solution results")); |
---|
1459 | #endif // QT_NO_STATUSTIP |
---|
1460 | actionFilePrint->setShortcut(tr("Ctrl+P")); |
---|
1461 | #endif // QT_NO_PRINTER |
---|
1462 | |
---|
1463 | #ifndef HANDHELD |
---|
1464 | actionSettingsToolbarsConfigure->setText(tr("Configure...")); |
---|
1465 | #ifndef QT_NO_STATUSTIP |
---|
1466 | actionSettingsToolbarsConfigure->setStatusTip(tr("Customize toolbars")); |
---|
1467 | #endif // QT_NO_STATUSTIP |
---|
1468 | #endif // HANDHELD |
---|
1469 | |
---|
1470 | #ifndef QT_NO_STATUSTIP |
---|
1471 | actionHelpReportBug->setStatusTip(tr("Report about a bug in %1").arg(QCoreApplication::applicationName())); |
---|
1472 | #endif // QT_NO_STATUSTIP |
---|
1473 | if (actionHelpCheck4Updates != NULL) { |
---|
1474 | actionHelpCheck4Updates->setText(tr("Check for &Updates...")); |
---|
1475 | #ifndef QT_NO_STATUSTIP |
---|
1476 | actionHelpCheck4Updates->setStatusTip(tr("Check for %1 updates").arg(QCoreApplication::applicationName())); |
---|
1477 | #endif // QT_NO_STATUSTIP |
---|
1478 | } |
---|
1479 | #ifndef QT_NO_STATUSTIP |
---|
1480 | actionHelpAbout->setStatusTip(tr("About %1").arg(QCoreApplication::applicationName())); |
---|
1481 | #endif // QT_NO_STATUSTIP |
---|
1482 | } |
---|
1483 | |
---|
1484 | bool MainWindow::saveTask() { |
---|
1485 | QStringList filters(tr("%1 Task File").arg("TSPSG") + " (*.tspt)"); |
---|
1486 | filters.append(tr("All Files") + " (*)"); |
---|
1487 | QString file; |
---|
1488 | if ((fileName == tr("Untitled") + ".tspt") && settings->value("SaveLastUsed", DEF_SAVE_LAST_USED).toBool()) { |
---|
1489 | file = settings->value(OS"/LastUsed/TaskSavePath").toString(); |
---|
1490 | if (!file.isEmpty()) |
---|
1491 | file.append("/"); |
---|
1492 | file.append(fileName); |
---|
1493 | } else if (fileName.endsWith(".tspt", Qt::CaseInsensitive)) |
---|
1494 | file = fileName; |
---|
1495 | else |
---|
1496 | file = QFileInfo(fileName).path() + "/" + QFileInfo(fileName).completeBaseName() + ".tspt"; |
---|
1497 | |
---|
1498 | QFileDialog::Options opts = settings->value("UseNativeDialogs", DEF_USE_NATIVE_DIALOGS).toBool() ? QFileDialog::Options() : QFileDialog::DontUseNativeDialog; |
---|
1499 | file = QFileDialog::getSaveFileName(this, tr("Task Save"), file, filters.join(";;"), NULL, opts); |
---|
1500 | if (file.isEmpty()) |
---|
1501 | return false; |
---|
1502 | else if (settings->value("SaveLastUsed", DEF_SAVE_LAST_USED).toBool()) |
---|
1503 | settings->setValue(OS"/LastUsed/TaskSavePath", QFileInfo(file).path()); |
---|
1504 | |
---|
1505 | if (tspmodel->saveTask(file)) { |
---|
1506 | setFileName(file); |
---|
1507 | setWindowModified(false); |
---|
1508 | return true; |
---|
1509 | } |
---|
1510 | return false; |
---|
1511 | } |
---|
1512 | |
---|
1513 | void MainWindow::setFileName(const QString &fileName) |
---|
1514 | { |
---|
1515 | this->fileName = fileName; |
---|
1516 | setWindowTitle(QString("%1[*] - %2").arg(QFileInfo(fileName).completeBaseName()).arg(QCoreApplication::applicationName())); |
---|
1517 | } |
---|
1518 | |
---|
1519 | void MainWindow::setupUi() |
---|
1520 | { |
---|
1521 | Ui_MainWindow::setupUi(this); |
---|
1522 | |
---|
1523 | // File Menu |
---|
1524 | actionFileNew->setIcon(GET_ICON("document-new")); |
---|
1525 | actionFileOpen->setIcon(GET_ICON("document-open")); |
---|
1526 | actionFileSave->setIcon(GET_ICON("document-save")); |
---|
1527 | #ifndef HANDHELD |
---|
1528 | menuFileSaveAs->setIcon(GET_ICON("document-save-as")); |
---|
1529 | #endif |
---|
1530 | actionFileExit->setIcon(GET_ICON("application-exit")); |
---|
1531 | // Settings Menu |
---|
1532 | #ifndef HANDHELD |
---|
1533 | menuSettingsLanguage->setIcon(GET_ICON("preferences-desktop-locale")); |
---|
1534 | #if QT_VERSION >= 0x040600 |
---|
1535 | actionSettingsLanguageEnglish->setIcon(QIcon::fromTheme("flag-gb", QIcon(":/images/icons/l10n/flag-gb.png"))); |
---|
1536 | #else // QT_VERSION >= 0x040600 |
---|
1537 | actionSettingsLanguageEnglish->setIcon(QIcon(":/images/icons/l10n/flag-gb.png")); |
---|
1538 | #endif // QT_VERSION >= 0x040600 |
---|
1539 | menuSettingsStyle->setIcon(GET_ICON("preferences-desktop-theme")); |
---|
1540 | #endif // HANDHELD |
---|
1541 | actionSettingsPreferences->setIcon(GET_ICON("preferences-system")); |
---|
1542 | // Help Menu |
---|
1543 | #ifndef HANDHELD |
---|
1544 | actionHelpContents->setIcon(GET_ICON("help-contents")); |
---|
1545 | actionHelpContextual->setIcon(GET_ICON("help-contextual")); |
---|
1546 | actionHelpOnlineSupport->setIcon(GET_ICON("applications-internet")); |
---|
1547 | actionHelpReportBug->setIcon(GET_ICON("tools-report-bug")); |
---|
1548 | actionHelpAbout->setIcon(GET_ICON("help-about")); |
---|
1549 | actionHelpAboutQt->setIcon(QIcon(":/images/icons/"ICON_SIZE"/qtlogo."ICON_FORMAT)); |
---|
1550 | #endif |
---|
1551 | // Buttons |
---|
1552 | buttonRandom->setIcon(GET_ICON("roll")); |
---|
1553 | buttonSolve->setIcon(GET_ICON("dialog-ok")); |
---|
1554 | buttonSaveSolution->setIcon(GET_ICON("document-save-as")); |
---|
1555 | buttonBackToTask->setIcon(GET_ICON("go-previous")); |
---|
1556 | |
---|
1557 | // action->setIcon(GET_ICON("")); |
---|
1558 | |
---|
1559 | #if QT_VERSION >= 0x040600 |
---|
1560 | setToolButtonStyle(Qt::ToolButtonFollowStyle); |
---|
1561 | #endif |
---|
1562 | |
---|
1563 | #ifndef HANDHELD |
---|
1564 | QStatusBar *statusbar = new QStatusBar(this); |
---|
1565 | statusbar->setObjectName("statusbar"); |
---|
1566 | setStatusBar(statusbar); |
---|
1567 | #endif // HANDHELD |
---|
1568 | |
---|
1569 | #ifdef Q_WS_WINCE_WM |
---|
1570 | menuBar()->setDefaultAction(menuFile->menuAction()); |
---|
1571 | |
---|
1572 | QScrollArea *scrollArea = new QScrollArea(this); |
---|
1573 | scrollArea->setFrameShape(QFrame::NoFrame); |
---|
1574 | scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
---|
1575 | scrollArea->setWidgetResizable(true); |
---|
1576 | scrollArea->setWidget(tabWidget); |
---|
1577 | setCentralWidget(scrollArea); |
---|
1578 | #else |
---|
1579 | setCentralWidget(tabWidget); |
---|
1580 | #endif // Q_WS_WINCE_WM |
---|
1581 | |
---|
1582 | //! \hack HACK: A little hack for toolbar icons to have a sane size. |
---|
1583 | #if defined(HANDHELD) && !defined(Q_WS_MAEMO_5) |
---|
1584 | #ifdef Q_WS_S60 |
---|
1585 | toolBarMain->setIconSize(QSize(logicalDpiX() / 5, logicalDpiY() / 5)); |
---|
1586 | #else |
---|
1587 | toolBarMain->setIconSize(QSize(logicalDpiX() / 4, logicalDpiY() / 4)); |
---|
1588 | #endif // Q_WS_S60 |
---|
1589 | #endif // HANDHELD && !Q_WS_MAEMO_5 |
---|
1590 | QToolButton *tb = static_cast<QToolButton *>(toolBarMain->widgetForAction(actionFileSave)); |
---|
1591 | if (tb != NULL) { |
---|
1592 | tb->setMenu(menuFileSaveAs); |
---|
1593 | tb->setPopupMode(QToolButton::MenuButtonPopup); |
---|
1594 | } |
---|
1595 | |
---|
1596 | // solutionText->document()->setDefaultFont(settings->value("Output/Font", QFont(DEF_FONT_FAMILY, DEF_FONT_SIZE)).value<QFont>()); |
---|
1597 | solutionText->setWordWrapMode(QTextOption::WordWrap); |
---|
1598 | |
---|
1599 | #ifndef QT_NO_PRINTER |
---|
1600 | actionFilePrintPreview = new QAction(this); |
---|
1601 | actionFilePrintPreview->setObjectName("actionFilePrintPreview"); |
---|
1602 | actionFilePrintPreview->setEnabled(false); |
---|
1603 | actionFilePrintPreview->setIcon(GET_ICON("document-print-preview")); |
---|
1604 | |
---|
1605 | actionFilePrint = new QAction(this); |
---|
1606 | actionFilePrint->setObjectName("actionFilePrint"); |
---|
1607 | actionFilePrint->setEnabled(false); |
---|
1608 | actionFilePrint->setIcon(GET_ICON("document-print")); |
---|
1609 | |
---|
1610 | menuFile->insertAction(actionFileExit,actionFilePrintPreview); |
---|
1611 | menuFile->insertAction(actionFileExit,actionFilePrint); |
---|
1612 | menuFile->insertSeparator(actionFileExit); |
---|
1613 | |
---|
1614 | toolBarMain->insertAction(actionSettingsPreferences, actionFilePrint); |
---|
1615 | #endif // QT_NO_PRINTER |
---|
1616 | |
---|
1617 | groupSettingsLanguageList = new QActionGroup(this); |
---|
1618 | #ifdef Q_WS_MAEMO_5 |
---|
1619 | groupSettingsLanguageList->addAction(actionSettingsLanguageAutodetect); |
---|
1620 | #endif |
---|
1621 | actionSettingsLanguageEnglish->setData("en"); |
---|
1622 | actionSettingsLanguageEnglish->setActionGroup(groupSettingsLanguageList); |
---|
1623 | loadLangList(); |
---|
1624 | actionSettingsLanguageAutodetect->setChecked(settings->value("Language", "").toString().isEmpty()); |
---|
1625 | |
---|
1626 | actionSettingsStyleSystem->setData(true); |
---|
1627 | groupSettingsStyleList = new QActionGroup(this); |
---|
1628 | #ifdef Q_WS_MAEMO_5 |
---|
1629 | groupSettingsStyleList->addAction(actionSettingsStyleSystem); |
---|
1630 | #endif |
---|
1631 | |
---|
1632 | #ifndef HANDHELD |
---|
1633 | actionSettingsToolbarsConfigure = new QAction(this); |
---|
1634 | actionSettingsToolbarsConfigure->setIcon(GET_ICON("configure-toolbars")); |
---|
1635 | #endif // HANDHELD |
---|
1636 | |
---|
1637 | if (hasUpdater()) { |
---|
1638 | actionHelpCheck4Updates = new QAction(this); |
---|
1639 | actionHelpCheck4Updates->setIcon(GET_ICON("system-software-update")); |
---|
1640 | actionHelpCheck4Updates->setEnabled(hasUpdater()); |
---|
1641 | menuHelp->insertAction(actionHelpAboutQt, actionHelpCheck4Updates); |
---|
1642 | menuHelp->insertSeparator(actionHelpAboutQt); |
---|
1643 | } else |
---|
1644 | actionHelpCheck4Updates = NULL; |
---|
1645 | |
---|
1646 | spinCities->setMaximum(MAX_NUM_CITIES); |
---|
1647 | |
---|
1648 | #ifndef HANDHELD |
---|
1649 | toolBarManager = new QtToolBarManager; |
---|
1650 | toolBarManager->setMainWindow(this); |
---|
1651 | QString cat = toolBarMain->windowTitle(); |
---|
1652 | toolBarManager->addToolBar(toolBarMain, cat); |
---|
1653 | #ifndef QT_NO_PRINTER |
---|
1654 | toolBarManager->addAction(actionFilePrintPreview, cat); |
---|
1655 | #endif // QT_NO_PRINTER |
---|
1656 | toolBarManager->addAction(actionHelpContents, cat); |
---|
1657 | toolBarManager->addAction(actionHelpContextual, cat); |
---|
1658 | // toolBarManager->addAction(action, cat); |
---|
1659 | toolBarManager->restoreState(settings->value("MainWindow/Toolbars").toByteArray()); |
---|
1660 | #else |
---|
1661 | toolBarMain->setVisible(settings->value("MainWindow/ToolbarVisible", true).toBool()); |
---|
1662 | #endif // HANDHELD |
---|
1663 | |
---|
1664 | retranslateUi(false); |
---|
1665 | |
---|
1666 | #ifndef HANDHELD |
---|
1667 | // Adding some eyecandy |
---|
1668 | if (QtWin::isCompositionEnabled() && settings->value("UseTranslucency", DEF_USE_TRANSLUCENCY).toBool()) { |
---|
1669 | toggleTranclucency(true); |
---|
1670 | } |
---|
1671 | #endif // HANDHELD |
---|
1672 | } |
---|
1673 | |
---|
1674 | void MainWindow::toggleSolutionActions(bool enable) |
---|
1675 | { |
---|
1676 | buttonSaveSolution->setEnabled(enable); |
---|
1677 | actionFileSaveAsSolution->setEnabled(enable); |
---|
1678 | solutionText->setEnabled(enable); |
---|
1679 | #ifndef QT_NO_PRINTER |
---|
1680 | actionFilePrint->setEnabled(enable); |
---|
1681 | actionFilePrintPreview->setEnabled(enable); |
---|
1682 | #endif // QT_NO_PRINTER |
---|
1683 | } |
---|
1684 | |
---|
1685 | void MainWindow::toggleTranclucency(bool enable) |
---|
1686 | { |
---|
1687 | #ifndef HANDHELD |
---|
1688 | toggleStyle(labelVariant, enable); |
---|
1689 | toggleStyle(labelCities, enable); |
---|
1690 | toggleStyle(statusBar(), enable); |
---|
1691 | tabWidget->setDocumentMode(enable); |
---|
1692 | QtWin::enableBlurBehindWindow(this, enable); |
---|
1693 | #else |
---|
1694 | Q_UNUSED(enable); |
---|
1695 | #endif // HANDHELD |
---|
1696 | } |
---|
1697 | |
---|
1698 | void MainWindow::actionHelpOnlineSupportTriggered() |
---|
1699 | { |
---|
1700 | QDesktopServices::openUrl(QUrl("http://tspsg.info/goto/support")); |
---|
1701 | } |
---|
1702 | |
---|
1703 | void MainWindow::actionHelpReportBugTriggered() |
---|
1704 | { |
---|
1705 | QDesktopServices::openUrl(QUrl("http://tspsg.info/goto/bugtracker")); |
---|
1706 | } |
---|