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