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