[2bbe924ad8] | 1 | /*! |
---|
| 2 | * \file globals.h |
---|
[0af510a462] | 3 | * \author Copyright © 2007-2012 Oleksii Serdiuk <contacts[at]oleksii[dot]name> |
---|
[2bbe924ad8] | 4 | * |
---|
[7ba743d983] | 5 | * $Id: $Format:%h %ai %an$ $ |
---|
| 6 | * $URL: http://tspsg.info/ $ |
---|
[2bbe924ad8] | 7 | * |
---|
| 8 | * \brief Contains TSPSG global defines. |
---|
| 9 | * |
---|
| 10 | * <b>TSPSG: TSP Solver and Generator</b> |
---|
| 11 | * |
---|
| 12 | * This file is part of TSPSG. |
---|
| 13 | * |
---|
| 14 | * TSPSG is free software: you can redistribute it and/or modify |
---|
| 15 | * it under the terms of the GNU General Public License as published by |
---|
| 16 | * the Free Software Foundation, either version 3 of the License, or |
---|
| 17 | * (at your option) any later version. |
---|
| 18 | * |
---|
| 19 | * TSPSG is distributed in the hope that it will be useful, |
---|
| 20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 22 | * GNU General Public License for more details. |
---|
| 23 | * |
---|
| 24 | * You should have received a copy of the GNU General Public License |
---|
| 25 | * along with TSPSG. If not, see <http://www.gnu.org/licenses/>. |
---|
| 26 | */ |
---|
| 27 | |
---|
| 28 | #ifndef GLOBALS_H |
---|
| 29 | #define GLOBALS_H |
---|
| 30 | |
---|
| 31 | // INCLUDES |
---|
| 32 | #include <QtCore> |
---|
[356169a3d3] | 33 | #if QT_VERSION < QT_VERSION_CHECK(4,5,0) |
---|
[9eb63a1598] | 34 | # error You are using Qt version < 4.5 but minimum required version is 4.5.0. Compilation aborted. |
---|
[2a436ea693] | 35 | #endif |
---|
[89e5214692] | 36 | #if defined(Q_OS_WINCE_WM) || defined(Q_OS_SYMBIAN) || defined(Q_WS_MAEMO_5) || defined(Q_WS_SIMULATOR) |
---|
[9eb63a1598] | 37 | //! This is defined on handheld devices (e.g., Windows Mobile, Symbian). |
---|
| 38 | # define HANDHELD |
---|
| 39 | # define QT_NO_STATUSTIP |
---|
[2a436ea693] | 40 | #endif |
---|
[2bbe924ad8] | 41 | #include <QtGui> |
---|
[9adbc413c7] | 42 | #if defined(QT_NO_SVG) && !defined(NOSVG) |
---|
[9eb63a1598] | 43 | # define NOSVG |
---|
[9adbc413c7] | 44 | #endif |
---|
[2a436ea693] | 45 | #if !defined(NOSVG) |
---|
[9eb63a1598] | 46 | # include <QtSvg> |
---|
[2a436ea693] | 47 | #endif // NOSVG |
---|
[356169a3d3] | 48 | #if QT_VERSION >= QT_VERSION_CHECK(5,0,0) |
---|
| 49 | # include <QtConcurrent> |
---|
| 50 | # include <QtPrintSupport> |
---|
| 51 | #endif |
---|
[7bb19df196] | 52 | |
---|
| 53 | #ifndef HANDHELD |
---|
[9eb63a1598] | 54 | # include "qttoolbardialog.h" |
---|
[7bb19df196] | 55 | #endif |
---|
[2bbe924ad8] | 56 | |
---|
| 57 | // Version info |
---|
| 58 | #include "version.h" |
---|
| 59 | // OS and ARCH detection |
---|
| 60 | #include "os.h" |
---|
| 61 | // TSPSG Defaults |
---|
| 62 | #include "defaults.h" |
---|
| 63 | // TSPSolver |
---|
| 64 | #include "tspsolver.h" |
---|
[b8a2a118c4] | 65 | #ifndef HANDHELD |
---|
| 66 | // Eyecandy |
---|
[9eb63a1598] | 67 | # include "qtwin.h" |
---|
[b8a2a118c4] | 68 | #endif // HANDHELD |
---|
[2bbe924ad8] | 69 | |
---|
| 70 | // DEFINES |
---|
| 71 | //! Maximum available number of cities |
---|
| 72 | #define MAX_NUM_CITIES 50 |
---|
| 73 | //! Maximum allowed value for random generation limits |
---|
| 74 | #define MAX_RAND_VALUE 1000 |
---|
| 75 | |
---|
| 76 | // Paths |
---|
| 77 | /*! |
---|
| 78 | * \def PATH_L10N |
---|
| 79 | * \brief Path to internationalization files. |
---|
| 80 | */ |
---|
| 81 | #ifndef PATH_L10N |
---|
[9eb63a1598] | 82 | # define PATH_L10N "l10n" |
---|
[2bbe924ad8] | 83 | #endif // PATH_L10N |
---|
| 84 | /*! |
---|
| 85 | * \def PATH_DOCS |
---|
| 86 | * \brief Bath to documentation files. |
---|
| 87 | */ |
---|
| 88 | #ifndef PATH_DOCS |
---|
[9eb63a1598] | 89 | # define PATH_DOCS "help" |
---|
[2bbe924ad8] | 90 | #endif // PATH_DOCS |
---|
| 91 | |
---|
| 92 | //! TSPSG Task file signature - letters \c TSPT |
---|
| 93 | #define TSPT quint32(0x54535054) |
---|
| 94 | //! TSPSG Task file version |
---|
| 95 | #define TSPT_VERSION quint8(1) |
---|
| 96 | //! TSPSG Task file metadata version |
---|
| 97 | #define TSPT_META_VERSION quint8(1) |
---|
| 98 | //! TSPSG Task file metadata size in bytes (incl. version) |
---|
| 99 | #define TSPT_META_SIZE 2 |
---|
| 100 | //! ZKomModRd Task file signature - letters \c ZK |
---|
| 101 | #define ZKT quint16(0x5A4B) |
---|
| 102 | //! ZKomModRd Task file version |
---|
| 103 | #define ZKT_VERSION quint8(1) |
---|
| 104 | |
---|
| 105 | //! This string represents infinite value in the table |
---|
| 106 | #define INFSTR "---" |
---|
| 107 | |
---|
[8f2427aaf0] | 108 | //! Number of centimeters in 1 inch |
---|
| 109 | #define CM_IN_INCH 2.54 |
---|
| 110 | //! Factor for high quality graph generation |
---|
| 111 | #define HQ_FACTOR 2 |
---|
| 112 | |
---|
[2bbe924ad8] | 113 | // FUNCTIONS |
---|
| 114 | /*! |
---|
| 115 | * \brief Checks whether \a x contains an integer value. |
---|
| 116 | * \param x A value to check. |
---|
| 117 | * \return \c true if \a x countains an integer, oherwise \c false. |
---|
| 118 | */ |
---|
| 119 | inline bool isInteger(double x) |
---|
| 120 | { |
---|
| 121 | double i; |
---|
[9eb63a1598] | 122 | return (modf(x, &i) == 0.0); |
---|
[2bbe924ad8] | 123 | } |
---|
| 124 | |
---|
[f5c945d7ac] | 125 | /*! |
---|
| 126 | * \brief Checks whether the updater app is installed/available. |
---|
| 127 | * \return \c true if updater app is available, oherwise \c false. |
---|
| 128 | * \note The updater app is only available under Windows at this moment. |
---|
| 129 | * On other systems this function always returns \c false. |
---|
| 130 | */ |
---|
| 131 | inline bool hasUpdater() |
---|
| 132 | { |
---|
[89e5214692] | 133 | #ifdef Q_OS_WIN32 |
---|
[9eb63a1598] | 134 | return QFile::exists("updater/Update.exe"); |
---|
[89e5214692] | 135 | #else // Q_OS_WIN32 |
---|
[9eb63a1598] | 136 | return false; |
---|
[89e5214692] | 137 | #endif // Q_OS_WIN32 |
---|
[f5c945d7ac] | 138 | } |
---|
| 139 | |
---|
[b26dc16dcf] | 140 | /*! |
---|
| 141 | * \brief Converts \a in into Base64 format with lines wrapped at 64 characters. |
---|
| 142 | * \param in A byte array to be converted. |
---|
| 143 | * \return Converted byte array. |
---|
| 144 | */ |
---|
| 145 | inline QByteArray toWrappedBase64(const QByteArray &in) |
---|
| 146 | { |
---|
| 147 | QByteArray out, base64(in.toBase64()); |
---|
| 148 | for (int i = 0; i <= base64.size() - 64; i += 64) { |
---|
| 149 | out.append(QByteArray::fromRawData(base64.data() + i, 64)).append('\n'); |
---|
| 150 | } |
---|
| 151 | if (int rest = base64.size() % 64) |
---|
| 152 | out.append(QByteArray::fromRawData(base64.data() + base64.size() - rest, rest)); |
---|
| 153 | return out; |
---|
| 154 | } |
---|
| 155 | |
---|
[b8a2a118c4] | 156 | #ifndef HANDHELD |
---|
[2bbe924ad8] | 157 | /*! |
---|
| 158 | * \brief Enables or disables a mask for the \a widget. |
---|
| 159 | * \param widget A widget to toggle mask on. |
---|
| 160 | * \param enable Set to \c true to enable mask or \c false to disable it. |
---|
| 161 | * |
---|
| 162 | * This function is used to enable an outlined font effect for \c QLabel with a static text. |
---|
| 163 | */ |
---|
| 164 | void toggleStyle(QWidget *widget, bool enable); |
---|
[b8a2a118c4] | 165 | #endif // HANDHELD |
---|
[2bbe924ad8] | 166 | |
---|
[cac8759dba] | 167 | #ifndef DOXYGEN_EXCLUDE |
---|
| 168 | |
---|
[a885c3d9d2] | 169 | #ifndef QT_NO_PRINTER |
---|
| 170 | Q_DECLARE_METATYPE(QPrinter::PageSize) |
---|
| 171 | Q_DECLARE_METATYPE(QPrinter::Orientation) |
---|
| 172 | #endif |
---|
| 173 | |
---|
[cac8759dba] | 174 | #ifdef HANDHELD |
---|
[d97db6d321] | 175 | # define ICON_SIZE "48x48" |
---|
[9eb63a1598] | 176 | # define ICON_FORMAT "png" |
---|
[cac8759dba] | 177 | #else |
---|
[9eb63a1598] | 178 | # define ICON_SIZE "128x128" |
---|
| 179 | # define ICON_FORMAT "png" |
---|
[cac8759dba] | 180 | #endif |
---|
| 181 | |
---|
[356169a3d3] | 182 | #if QT_VERSION >= QT_VERSION_CHECK(4,6,0) |
---|
[9eb63a1598] | 183 | # define GET_ICON(x) QIcon::fromTheme(x, QIcon(":/images/icons/"ICON_SIZE"/"x"."ICON_FORMAT)) |
---|
[2a436ea693] | 184 | #else |
---|
[9eb63a1598] | 185 | # define GET_ICON(x) QIcon(":/images/icons/"ICON_SIZE"/"x"."ICON_FORMAT) |
---|
[fec08a47e5] | 186 | // No QVariant::toReal() member in Qt < 4.6 |
---|
| 187 | // A quick hack to maintain compatibility with Qt 4.5.x |
---|
| 188 | # define toReal toDouble |
---|
[2a436ea693] | 189 | #endif |
---|
| 190 | |
---|
[2bbe924ad8] | 191 | // Sanity checks |
---|
| 192 | // Check that default number of cities is sane (<= MAX_NUM_CITIES) |
---|
| 193 | #if DEF_NUM_CITIES > MAX_NUM_CITIES |
---|
[9eb63a1598] | 194 | # undef DEF_NUM_CITIES |
---|
| 195 | # define DEF_NUM_CITIES MAX_NUM_CITIES |
---|
[2bbe924ad8] | 196 | #endif |
---|
| 197 | // Check that maximum for random generation is sane (<= MAX_RAND_VALUE) |
---|
| 198 | #if DEF_RAND_MAX > MAX_RAND_VALUE |
---|
[9eb63a1598] | 199 | # undef DEF_RAND_MAX |
---|
| 200 | # define DEF_RAND_MAX MAX_RAND_VALUE |
---|
[2bbe924ad8] | 201 | #endif |
---|
| 202 | // Check that DEF_RAND_MIN <= DEF_RAND_MAX |
---|
| 203 | #if DEF_RAND_MIN > DEF_RAND_MAX |
---|
[9eb63a1598] | 204 | # undef DEF_RAND_MIN |
---|
| 205 | # define DEF_RAND_MIN DEF_RAND_MAX |
---|
[2bbe924ad8] | 206 | #endif |
---|
| 207 | |
---|
[cac8759dba] | 208 | #endif // DOXYGEN_EXCLUDE |
---|
| 209 | |
---|
[2bbe924ad8] | 210 | #endif // GLOBALS_H |
---|