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