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