Changeset 109 in tspsg-svn for trunk/src/mainwindow.cpp
- Timestamp:
- Apr 27, 2010, 9:12:55 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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"));
Note: See TracChangeset
for help on using the changeset viewer.