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