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