- Timestamp:
- Apr 27, 2010, 9:12:55 AM (15 years ago)
- Location:
- trunk/src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/defaults.h
r107 r109 67 67 //! Default for "Show solution graph" 68 68 #define DEF_SHOW_GRAPH true 69 /*! 70 * \def DEF_GRAPH_IMAGE_FORMAT 71 * \brief Default for "Save solution graph as" 72 */ 73 #if !defined(NOSVG) && (QT_VERSION >= 0x040500) 74 #define DEF_GRAPH_IMAGE_FORMAT "svg" 75 #else 76 #define DEF_GRAPH_IMAGE_FORMAT "png" 77 #endif // NOSVG && QT_VERSION >= 0x040500 69 78 //! Default for "Show solution steps' matrices for every solution step" 70 79 #define DEF_SHOW_MATRIX true -
trunk/src/globals.h
r108 r109 32 32 #include <QtCore> 33 33 #include <QtGui> 34 #include <QtSvg> 34 #if !defined(NOSVG) && (QT_VERSION >= 0x040500) 35 #include <QtSvg> 36 #endif // NOSVG && QT_VERSION >= 0x040500 35 37 36 38 // Version info -
trunk/src/main.cpp
r108 r109 33 33 #endif 34 34 35 #ifdef STATIC_BUILD36 Q_IMPORT_PLUGIN(qjpeg)37 Q_IMPORT_PLUGIN(qsvg)38 #endif35 //#ifdef STATIC_BUILD 36 // Q_IMPORT_PLUGIN(qjpeg) 37 // Q_IMPORT_PLUGIN(qtiff) 38 //#endif 39 39 40 40 int main(int argc, char *argv[]) … … 47 47 app.setOrganizationName("Oleksii \"Lёppa\" Serdiuk"); 48 48 app.setOrganizationDomain("oleksii.name"); 49 app.setApplicationName("TSPSG ");49 app.setApplicationName("TSPSG: TSP Solver and Generator"); 50 50 app.setApplicationVersion(BUILD_VERSION); 51 51 -
trunk/src/mainwindow.cpp
r108 r109 226 226 } 227 227 QFileInfo fi(selectedFile); 228 QString format = settings->value("Output/GraphImageFormat", DEF_GRAPH_IMAGE_FORMAT).toString(); 229 #if !defined(NOSVG) && (QT_VERSION >= 0x040500) 230 if (!QImageWriter::supportedImageFormats().contains(format.toAscii()) && (format != "svg")) { 231 #else // NOSVG && QT_VERSION >= 0x040500 232 if (!QImageWriter::supportedImageFormats().contains(format.toAscii())) { 233 #endif // NOSVG && QT_VERSION >= 0x040500 234 format = DEF_GRAPH_IMAGE_FORMAT; 235 settings->remove("Output/GraphImageFormat"); 236 } 228 237 QString html = solutionText->document()->toHtml("UTF-8"), 229 img = fi.completeBaseName() + ".svg"; 230 html.replace(QRegExp("<img\\s+src=\"tspsg://graph.pic\""), QString("<img src=\"%1\" width=\"%2\" height=\"%3\" alt=\"%4\"").arg(img).arg(graph.width() + 1).arg(graph.height() + 1).arg(tr("Solution Graph"))); 238 img = fi.completeBaseName() + "." + format; 239 html.replace(QRegExp("<img\\s+src=\"tspsg://graph.pic\""), QString("<img src=\"%1\" width=\"%2\" height=\"%3\" alt=\"%4\"").arg(img).arg(graph.width() + 2).arg(graph.height() + 2).arg(tr("Solution Graph"))); 240 231 241 // Saving solution text as HTML 232 242 QTextStream ts(&file); … … 234 244 ts << html; 235 245 file.close(); 236 // Saving solution graph as SVG 246 247 // Saving solution graph as SVG or PNG (depending on settings and SVG support) 248 #if !defined(NOSVG) && (QT_VERSION >= 0x040500) 249 if (format == "svg") { 237 250 QSvgGenerator svg; 238 svg.setFileName(fi.path() + "/" + img); 239 svg.setTitle(tr("Solution Graph")); 251 svg.setSize(QSize(graph.width(), graph.height())); 252 svg.setResolution(graph.logicalDpiX()); 253 svg.setFileName(fi.path() + "/" + img); 254 svg.setTitle(tr("Solution Graph")); 255 svg.setDescription(tr("Generated with %1").arg(QApplication::applicationName())); 240 256 QPainter p; 241 p.begin(&svg); 242 graph.play(&p); 243 p.end(); 257 p.begin(&svg); 258 p.drawPicture(1, 1, graph); 259 p.end(); 260 } else { 261 #endif // NOSVG && QT_VERSION >= 0x040500 262 QImage i(graph.width() + 2, graph.height() + 2, QImage::Format_ARGB32); 263 i.fill(0x00FFFFFF); 264 QPainter p; 265 p.begin(&i); 266 p.drawPicture(1, 1, graph); 267 p.end(); 268 QImageWriter pic(fi.path() + "/" + img); 269 if (pic.supportsOption(QImageIOHandler::Description)) { 270 pic.setText("Title", "Solution Graph"); 271 pic.setText("Software", QApplication::applicationName()); 272 } 273 if (format == "png") 274 pic.setQuality(5); 275 else if (format == "jpeg") 276 pic.setQuality(80); 277 if (!pic.write(i)) { 278 QApplication::restoreOverrideCursor(); 279 QMessageBox::critical(this, tr("Solution Save"), tr("Unable to save the solution graph.\nError: %1").arg(pic.errorString())); 280 return; 281 } 282 #if !defined(NOSVG) && (QT_VERSION >= 0x040500) 283 } 284 #endif // NOSVG && QT_VERSION >= 0x040500 244 285 245 286 // Qt < 4.5 has no QTextDocumentWriter class … … 351 392 title += QString("<b>TSPSG<br>TSP Solver and Generator</b><br>"); 352 393 #else 353 title += QString("<b> TSPSG: TSP Solver and Generator</b><br>");394 title += QString("<b>%1</b><br>").arg(QApplication::applicationName()); 354 395 #endif // HANDHELD 355 396 title += QString("%1: <b>%2</b><br>").arg(tr("Version"), QApplication::applicationVersion()); … … 536 577 pic.begin(&graph); 537 578 pic.setRenderHint(QPainter::Antialiasing); 579 pic.setFont(settings->value("Output/Font", QFont(DEF_FONT_FAMILY, 9)).value<QFont>()); 580 pic.setBrush(QBrush(QColor(Qt::white))); 581 pic.setBackgroundMode(Qt::OpaqueMode); 538 582 } 539 583 … … 805 849 pic.setFont(font); 806 850 } 807 pic.setBackgroundMode(Qt::OpaqueMode);808 851 if (step->price != INFINITY) { 809 852 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())); … … 811 854 pic.drawText(QRectF(x - r, y - r, r * 2, r * 2), Qt::AlignCenter, "\n"INFSTR); 812 855 } 813 pic.setBackgroundMode(Qt::TransparentMode);814 856 } else { 815 857 pic.drawText(QRectF(x - r, y - r, r * 2, r * 2), Qt::AlignCenter, tr("Root")); -
trunk/src/settingsdialog.cpp
r107 r109 195 195 settings->beginGroup("Output"); 196 196 cbShowGraph->setChecked(settings->value("ShowGraph", DEF_SHOW_GRAPH).toBool()); 197 198 #if !defined(NOSVG) && (QT_VERSION >= 0x040500) 199 comboGraphImageFormat->addItem("svg"); 200 #endif // NOSVG && QT_VERSION >= 0x040500 201 // We create a whitelist of formats, supported by the most popular web browsers according to 202 // http://en.wikipedia.org/wiki/Comparison_of_web_browsers#Image_format_support 203 // + TIFF format (there are plugins to support it). 204 QStringList whitelist; 205 whitelist << "bmp" << "jpeg" << "png" << "tiff" << "xbm"; 206 foreach (QByteArray format, QImageWriter::supportedImageFormats()) { 207 if (whitelist.contains(format)) 208 comboGraphImageFormat->addItem(format); 209 } 210 comboGraphImageFormat->model()->sort(0); 211 comboGraphImageFormat->setCurrentIndex(comboGraphImageFormat->findText(settings->value("GraphImageFormat", DEF_GRAPH_IMAGE_FORMAT).toString(), Qt::MatchFixedString)); 212 if (comboGraphImageFormat->currentIndex() < 0) 213 comboGraphImageFormat->setCurrentIndex(comboGraphImageFormat->findText(DEF_GRAPH_IMAGE_FORMAT, Qt::MatchFixedString)); 214 labelGraphImageFormat->setEnabled(cbShowGraph->isChecked()); 215 comboGraphImageFormat->setEnabled(cbShowGraph->isChecked()); 216 197 217 cbShowMatrix->setChecked(settings->value("ShowMatrix", DEF_SHOW_MATRIX).toBool()); 198 218 cbCitiesLimit->setEnabled(cbShowMatrix->isChecked()); … … 252 272 settings->setValue("SettingsReset", true); 253 273 QDialog::accept(); 254 QMessageBox::information(this , tr("Settings Reset"), tr("All settings where successfully reset to their defaults.\nIt is recommended to restart the application now."));274 QMessageBox::information(this->parentWidget(), tr("Settings Reset"), tr("All settings where successfully reset to their defaults.\nIt is recommended to restart the application now.")); 255 275 return; 256 276 } else … … 282 302 settings->beginGroup("Output"); 283 303 settings->setValue("ShowGraph", cbShowGraph->isChecked()); 304 if (cbShowGraph->isChecked()) { 305 if (comboGraphImageFormat->currentIndex() >= 0) 306 settings->setValue("GraphImageFormat", comboGraphImageFormat->currentText()); 307 else 308 settings->setValue("GraphImageFormat", DEF_GRAPH_IMAGE_FORMAT); 309 } 284 310 settings->setValue("ShowMatrix", cbShowMatrix->isChecked()); 285 311 settings->setValue("UseShowMatrixLimit", cbShowMatrix->isChecked() && cbCitiesLimit->isChecked());
Note: See TracChangeset
for help on using the changeset viewer.