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