- Timestamp:
- Apr 14, 2011, 9:30:23 PM (14 years ago)
- Location:
- trunk/src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/defaults.h
r161 r162 53 53 * \brief Default for "Use translucency effects" 54 54 */ 55 #ifdef Q_WS_WIN 55 #ifdef Q_WS_WIN32 56 56 # define DEF_USE_TRANSLUCENCY true 57 57 #else … … 78 78 //////// OUTPUT 79 79 80 //! Default for " Showsolution graph"81 #define DEF_ SHOW_GRAPH true80 //! Default for "Generate solution graph" 81 #define DEF_GENERATE_GRAPH true 82 82 //! Default for "Save solution graph as" 83 83 #define DEF_GRAPH_IMAGE_FORMAT "png" 84 84 //! Default for "Draw solution graph in higher quality" 85 85 #define DEF_HQ_GRAPH false 86 //! Default for "Embed solution graph into HTML" 87 #define DEF_EMBED_GRAPH_INTO_HTML false 88 //! Default solution graph size in centimeters (HQ size is this size * HQ_FACTOR) 89 #define DEF_GRAPH_WIDTH 4.5 86 90 //! Default for "Show solution steps' matrices for every solution step" 87 91 #define DEF_SHOW_MATRIX true -
trunk/src/globals.h
r158 r162 102 102 #define INFSTR "---" 103 103 104 //! Number of centimeters in 1 inch 105 #define CM_IN_INCH 2.54 106 //! Factor for high quality graph generation 107 #define HQ_FACTOR 2 108 104 109 // FUNCTIONS 105 110 /*! -
trunk/src/mainwindow.cpp
r161 r162 180 180 tabWidget->setCurrentIndex(0); 181 181 solutionText->clear(); 182 graph = QPicture(); 182 183 toggleSolutionActions(false); 183 184 QApplication::restoreOverrideCursor(); … … 274 275 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); 275 276 #ifndef QT_NO_PRINTER 276 if (selectedFile.endsWith(".pdf",Qt::CaseInsensitive)) { 277 QPrinter printer(QPrinter::HighResolution); 278 printer.setOutputFormat(QPrinter::PdfFormat); 279 printer.setOutputFileName(selectedFile); 280 solutionText->document()->print(&printer); 277 if (selectedFile.endsWith(".pdf", Qt::CaseInsensitive)) { 278 printer->setOutputFileName(selectedFile); 279 solutionText->document()->print(printer); 280 printer->setOutputFileName(QString()); 281 281 QApplication::restoreOverrideCursor(); 282 282 return; … … 293 293 QString format = settings->value("Output/GraphImageFormat", DEF_GRAPH_IMAGE_FORMAT).toString(); 294 294 #if !defined(NOSVG) 295 if (!QImageWriter::supportedImageFormats().contains(format.toAscii()) && (format != "svg")) {295 if (!QImageWriter::supportedImageFormats().contains(format.toAscii()) && (format != "svg")) { 296 296 #else // NOSVG 297 if (!QImageWriter::supportedImageFormats().contains(format.toAscii())) {297 if (!QImageWriter::supportedImageFormats().contains(format.toAscii())) { 298 298 #endif // NOSVG 299 format = DEF_GRAPH_IMAGE_FORMAT;300 settings->remove("Output/GraphImageFormat");301 }302 QString html = solutionText->document()->toHtml("UTF-8") ,303 img = fi.completeBaseName() + "." + format; 299 format = DEF_GRAPH_IMAGE_FORMAT; 300 settings->remove("Output/GraphImageFormat"); 301 } 302 QString html = solutionText->document()->toHtml("UTF-8"); 303 304 304 html.replace(QRegExp("font-family:([^;]*);"), "font-family:\\1, 'DejaVu Sans Mono', 'Courier New', Courier, monospace;"); 305 html.replace(QRegExp("<img\\s+src=\"tspsg://graph.pic\""), QString("<img src=\"%1\" alt=\"%2\"").arg(img, tr("Solution Graph"))); 306 305 306 if (!graph.isNull()) { 307 QString img = fi.completeBaseName() + "." + format; 308 bool embed = settings->value("Output/EmbedGraphIntoHTML", DEF_EMBED_GRAPH_INTO_HTML).toBool(); 309 QByteArray data; 310 QBuffer buf(&data); 311 if (!embed) { 312 html.replace(QRegExp("<img\\s+src=\"tspsg://graph.pic\""), QString("<img src=\"%1\" alt=\"%2\"").arg(img, tr("Solution Graph"))); 313 } 314 315 // Saving solution graph in SVG or supported raster format (depending on settings and SVG support) 316 #if !defined(NOSVG) 317 if (format == "svg") { 318 QSvgGenerator svg; 319 svg.setSize(QSize(graph.width() + 2, graph.height() + 2)); 320 svg.setResolution(graph.logicalDpiX()); 321 svg.setFileName(fi.path() + "/" + img); 322 svg.setTitle(tr("Solution Graph")); 323 svg.setDescription(tr("Generated with %1").arg(QCoreApplication::applicationName())); 324 QPainter p; 325 p.begin(&svg); 326 p.drawPicture(1, 1, graph); 327 p.end(); 328 } else { 329 #endif // NOSVG 330 QImage i(graph.width() + 2, graph.height() + 2, QImage::Format_ARGB32); 331 i.fill(0x00FFFFFF); 332 QPainter p; 333 p.begin(&i); 334 p.drawPicture(1, 1, graph); 335 p.end(); 336 QImageWriter pic; 337 if (embed) { 338 pic.setDevice(&buf); 339 pic.setFormat(format.toAscii()); 340 } else { 341 pic.setFileName(fi.path() + "/" + img); 342 } 343 if (pic.supportsOption(QImageIOHandler::Description)) { 344 pic.setText("Title", "Solution Graph"); 345 pic.setText("Software", QCoreApplication::applicationName()); 346 } 347 if (format == "png") 348 pic.setQuality(5); 349 else if (format == "jpeg") 350 pic.setQuality(80); 351 if (!pic.write(i)) { 352 QApplication::restoreOverrideCursor(); 353 QMessageBox::critical(this, tr("Solution Save"), tr("Unable to save the solution graph.\nError: %1").arg(pic.errorString())); 354 return; 355 } 356 #if !defined(NOSVG) 357 } 358 #endif // NOSVG 359 if (embed) { 360 html.replace(QRegExp("<img\\s+src=\"tspsg://graph.pic\""), QString("<img src=\"data:image/%1;base64,%2\" alt=\"%3\"").arg(format, data.toBase64(), tr("Solution Graph"))); 361 } 362 } 307 363 // Saving solution text as HTML 308 364 QTextStream ts(&file); … … 310 366 ts << html; 311 367 file.close(); 312 313 // Saving solution graph as SVG or PNG (depending on settings and SVG support)314 #if !defined(NOSVG)315 if (format == "svg") {316 QSvgGenerator svg;317 svg.setSize(QSize(graph.width() + 2, graph.height() + 2));318 svg.setResolution(graph.logicalDpiX());319 svg.setFileName(fi.path() + "/" + img);320 svg.setTitle(tr("Solution Graph"));321 svg.setDescription(tr("Generated with %1").arg(QCoreApplication::applicationName()));322 QPainter p;323 p.begin(&svg);324 p.drawPicture(1, 1, graph);325 p.end();326 } else {327 #endif // NOSVG328 QImage i(graph.width() + 2, graph.height() + 2, QImage::Format_ARGB32);329 i.fill(0x00FFFFFF);330 QPainter p;331 p.begin(&i);332 p.drawPicture(1, 1, graph);333 p.end();334 QImageWriter pic(fi.path() + "/" + img);335 if (pic.supportsOption(QImageIOHandler::Description)) {336 pic.setText("Title", "Solution Graph");337 pic.setText("Software", QCoreApplication::applicationName());338 }339 if (format == "png")340 pic.setQuality(5);341 else if (format == "jpeg")342 pic.setQuality(80);343 if (!pic.write(i)) {344 QApplication::restoreOverrideCursor();345 QMessageBox::critical(this, tr("Solution Save"), tr("Unable to save the solution graph.\nError: %1").arg(pic.errorString()));346 return;347 }348 #if !defined(NOSVG)349 }350 #endif // NOSVG351 368 } else { 352 369 QTextDocumentWriter dw(selectedFile); … … 743 760 tl = NULL; 744 761 } else { 745 // tl->SetProgressState(winId(), TBPF_INDETERMINATE);746 762 tl->SetProgressValue(winId(), 0, n * 2); 747 763 } … … 769 785 #ifdef Q_WS_WIN32 770 786 if (tl != NULL) { 771 // tl->SetProgressValue(winId(), n, n * 2);772 787 tl->SetProgressState(winId(), TBPF_ERROR); 773 788 } … … 818 833 819 834 QPainter pic; 820 if (settings->value("Output/ShowGraph", DEF_SHOW_GRAPH).toBool()) { 835 bool dograph = settings->value("Output/GenerateGraph", DEF_GENERATE_GRAPH).toBool(); 836 if (dograph) { 821 837 pic.begin(&graph); 822 838 pic.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform); 823 839 QFont font = qvariant_cast<QFont>(settings->value("Output/Font", QFont(DEF_FONT_FACE))); 824 //! \todo FIXME: Get rid of the "magic number" in the code. 825 font.setPixelSize(logicalDpiX() / 7); 840 font.setStyleHint(QFont::Monospace); 841 // Font size in pixels = graph node radius / 2.75. 842 // See MainWindow::drawNode() for graph node radius calcualtion description. 843 font.setPixelSize(logicalDpiX() * (settings->value("Output/GraphWidth", DEF_GRAPH_WIDTH).toReal() / CM_IN_INCH) / 4.5 / 2.75); 826 844 if (settings->value("Output/HQGraph", DEF_HQ_GRAPH).toBool()) { 827 845 font.setWeight(QFont::DemiBold); 828 font.setPixelSize(font.pixelSize() * 2);846 font.setPixelSize(font.pixelSize() * HQ_FACTOR); 829 847 } 830 848 pic.setFont(font); … … 832 850 if (settings->value("Output/HQGraph", DEF_HQ_GRAPH).toBool()) { 833 851 QPen pen = pic.pen(); 834 pen.setWidth( 2);852 pen.setWidth(HQ_FACTOR); 835 853 pic.setPen(pen); 836 854 } 837 855 pic.setBackgroundMode(Qt::OpaqueMode); 856 } else { 857 graph = QPicture(); 838 858 } 839 859 … … 847 867 cur.insertText(tr("Task:"), fmt_default); 848 868 outputMatrix(cur, matrix); 849 if ( settings->value("Output/ShowGraph", DEF_SHOW_GRAPH).toBool()) {869 if (dograph) { 850 870 #ifdef _T_T_L_ 851 871 _b_ _i_ _z_ _a_ _r_ _r_ _e_ … … 904 924 outputMatrix(cur, *step); 905 925 } 906 cur.insertBlock(fmt_paragraph); 926 if (step->alts.empty()) 927 cur.insertBlock(fmt_lastparagraph); 928 else 929 cur.insertBlock(fmt_paragraph); 907 930 cur.insertText(tr("Selected route %1 %2 part.").arg((step->next == SStep::RightBranch) ? tr("with") : tr("without")).arg(tr("(%1;%2)").arg(step->candidate.nRow + 1).arg(step->candidate.nCol + 1)), fmt_default); 908 931 if (!step->alts.empty()) { … … 914 937 alts += tr("(%1;%2)").arg(cand.nRow + 1).arg(cand.nCol + 1); 915 938 } 916 cur.insertBlock(fmt_ paragraph);939 cur.insertBlock(fmt_lastparagraph); 917 940 cur.insertText(tr("%n alternate candidate(s) for branching: %1.", "", step->alts.count()).arg(alts), fmt_altlist); 918 941 } 919 cur.insertBlock(fmt_paragraph);920 cur.insertText(" ", fmt_default);921 942 cur.endEditBlock(); 922 943 923 if ( settings->value("Output/ShowGraph", DEF_SHOW_GRAPH).toBool()) {944 if (dograph) { 924 945 if (step->prNode != NULL) 925 946 drawNode(pic, n, false, step->prNode); … … 947 968 cur.insertBlock(fmt_paragraph); 948 969 if (solver.isOptimal()) 949 cur.insertText(tr("Optimal path:") );970 cur.insertText(tr("Optimal path:"), fmt_default); 950 971 else 951 cur.insertText(tr("Resulting path:") );972 cur.insertText(tr("Resulting path:"), fmt_default); 952 973 953 974 cur.insertBlock(fmt_paragraph); 954 975 cur.insertText(" " + solver.getSortedPath(tr("City %1"))); 955 976 956 cur.insertBlock(fmt_paragraph); 977 if (solver.isOptimal()) 978 cur.insertBlock(fmt_paragraph); 979 else 980 cur.insertBlock(fmt_lastparagraph); 957 981 if (isInteger(step->price)) 958 982 cur.insertHtml("<p>" + tr("The price is <b>%n</b> unit(s).", "", qRound(step->price)) + "</p>"); … … 961 985 if (!solver.isOptimal()) { 962 986 cur.insertBlock(fmt_paragraph); 963 cur.insertText(" ");964 cur.insertBlock(fmt_paragraph);965 987 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>"); 966 988 } 967 989 cur.endEditBlock(); 968 990 969 if ( settings->value("Output/ShowGraph", DEF_SHOW_GRAPH).toBool()) {991 if (dograph) { 970 992 pic.end(); 971 993 … … 980 1002 img.setName("tspsg://graph.pic"); 981 1003 if (settings->value("Output/HQGraph", DEF_HQ_GRAPH).toBool()) { 982 img.setWidth(i.width() / 2);983 img.setHeight(i.height() / 2);1004 img.setWidth(i.width() / HQ_FACTOR); 1005 img.setHeight(i.height() / HQ_FACTOR); 984 1006 } else { 985 1007 img.setWidth(i.width()); … … 1167 1189 void MainWindow::drawNode(QPainter &pic, int nstep, bool left, SStep *step) 1168 1190 { 1169 qreal r; 1170 //! \todo FIXME: Get rid of the "magic numbers" in the code. 1191 qreal r; // Radius of graph node 1192 // We calculate r from the full graph width in centimeters: 1193 // r = width in pixels / 4.5. 1194 // width in pixels = DPI * width in inches. 1195 // width in inches = width in cm / cm in inch. 1196 r = logicalDpiX() * (settings->value("Output/GraphWidth", DEF_GRAPH_WIDTH).toReal() / CM_IN_INCH) / 4.5; 1171 1197 if (settings->value("Output/HQGraph", DEF_HQ_GRAPH).toBool()) 1172 r = logicalDpiX() / 1.27; 1173 else 1174 r = logicalDpiX() / 2.54; 1198 r *= HQ_FACTOR; 1175 1199 #ifdef Q_WS_S60 1176 1200 /*! \hack HACK: Solution graph on Symbian is visually larger than on … … 1247 1271 fmt_paragraph.setBottomMargin(0); 1248 1272 fmt_paragraph.setLeftMargin(10); 1273 1274 fmt_lastparagraph.setTopMargin(5); 1275 fmt_lastparagraph.setRightMargin(10); 1276 fmt_lastparagraph.setBottomMargin(15); 1277 fmt_lastparagraph.setLeftMargin(10); 1249 1278 1250 1279 fmt_table.setTopMargin(5); -
trunk/src/mainwindow.h
r161 r162 133 133 QTextTableFormat fmt_table; 134 134 QTextBlockFormat fmt_paragraph, 135 fmt_lastparagraph, 135 136 fmt_cell; 136 137 QTextCharFormat fmt_default, -
trunk/src/settingsdialog.cpp
r151 r162 76 76 hbox->addSpacing(10); 77 77 hbox->addWidget(cbHQGraph); 78 box->insertLayout(box->indexOf(cb ShowGraph) + 1, hbox);79 connect(cb ShowGraph, SIGNAL(toggled(bool)), cbHQGraph, SLOT(setEnabled(bool)));78 box->insertLayout(box->indexOf(cbGenerateGraph) + 2, hbox); 79 connect(cbGenerateGraph, SIGNAL(toggled(bool)), cbHQGraph, SLOT(setEnabled(bool))); 80 80 #endif 81 81 … … 147 147 cbUseTranslucency->setObjectName("cbUseTranslucency"); 148 148 #ifndef QT_NO_STATUSTIP 149 cbUseTranslucency->setStatusTip(tr(" Use translucent effect on the Main Window under Windows Vista and 7"));149 cbUseTranslucency->setStatusTip(tr("Make Main Window background translucent")); 150 150 #endif // QT_NO_STATUSTIP 151 151 cbUseTranslucency->setText(tr("Use translucency effects")); … … 174 174 labelHint->setObjectName("labelHint"); 175 175 labelHint->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred); 176 // labelHint->setMinimumSize(QSize(190,28)); 177 labelHint->setMinimumSize(QSize(0,28)); 178 labelHint->setMaximumSize(QSize(QWIDGETSIZE_MAX,28)); 176 labelHint->setMinimumSize(QSize(250, 28)); 177 labelHint->setMaximumSize(QSize(QWIDGETSIZE_MAX, 28)); 179 178 labelHint->setTextFormat(Qt::PlainText); 180 179 // labelHint->setAlignment(Qt::AlignLeft | Qt::AlignTop); … … 260 259 261 260 settings->beginGroup("Output"); 262 cb ShowGraph->setChecked(settings->value("ShowGraph", DEF_SHOW_GRAPH).toBool());261 cbGenerateGraph->setChecked(settings->value("GenerateGraph", DEF_GENERATE_GRAPH).toBool()); 263 262 264 263 #ifndef QT_NO_PRINTER 265 cbHQGraph->setEnabled(cb ShowGraph->isChecked());266 cbHQGraph->setChecked(settings->value("HQGraph", DEF_HQ_GRAPH && cbShowGraph->isChecked()).toBool());264 cbHQGraph->setEnabled(cbGenerateGraph->isChecked()); 265 cbHQGraph->setChecked(settings->value("HQGraph", DEF_HQ_GRAPH).toBool()); 267 266 #endif 268 267 … … 283 282 if (comboGraphImageFormat->currentIndex() < 0) 284 283 comboGraphImageFormat->setCurrentIndex(comboGraphImageFormat->findText(DEF_GRAPH_IMAGE_FORMAT, Qt::MatchFixedString)); 285 labelGraphImageFormat->setEnabled(cbShowGraph->isChecked()); 286 comboGraphImageFormat->setEnabled(cbShowGraph->isChecked()); 284 labelGraphImageFormat->setEnabled(cbGenerateGraph->isChecked()); 285 comboGraphImageFormat->setEnabled(cbGenerateGraph->isChecked()); 286 cbEmbedGraphIntoHTML->setChecked(settings->value("EmbedGraphIntoHTML", DEF_EMBED_GRAPH_INTO_HTML).toBool()); 287 cbEmbedGraphIntoHTML->setEnabled(cbGenerateGraph->isChecked()); 287 288 288 289 cbShowMatrix->setChecked(settings->value("ShowMatrix", DEF_SHOW_MATRIX).toBool()); … … 326 327 * \brief Indicates whether and how the translucency setting was changed 327 328 * \retval -1 the translucency was \em disabled. 328 * \retval 0 the translucency was <em>not changed</em>.329 * \retval 0 the translucency <em>didn't change</em>. 329 330 * \retval 1 the translucency was \em enabled. 330 331 */ … … 381 382 382 383 settings->beginGroup("Output"); 383 settings->setValue("ShowGraph", cbShowGraph->isChecked()); 384 settings->setValue("GenerateGraph", cbGenerateGraph->isChecked()); 385 if (cbGenerateGraph->isChecked()) { 384 386 #ifndef QT_NO_PRINTER 385 settings->setValue("HQGraph", cbShowGraph->isChecked() &&cbHQGraph->isChecked());387 settings->setValue("HQGraph", cbHQGraph->isChecked()); 386 388 #endif 387 if (cbShowGraph->isChecked()) { 388 if (comboGraphImageFormat->currentIndex() >= 0) 389 settings->setValue("GraphImageFormat", comboGraphImageFormat->currentText()); 390 else 391 settings->setValue("GraphImageFormat", DEF_GRAPH_IMAGE_FORMAT); 389 if (cbGenerateGraph->isChecked()) { 390 if (comboGraphImageFormat->currentIndex() >= 0) 391 settings->setValue("GraphImageFormat", comboGraphImageFormat->currentText()); 392 else 393 settings->setValue("GraphImageFormat", DEF_GRAPH_IMAGE_FORMAT); 394 } 395 settings->setValue("EmbedGraphIntoHTML", cbEmbedGraphIntoHTML->isChecked()); 392 396 } 393 397 settings->setValue("ShowMatrix", cbShowMatrix->isChecked());
Note: See TracChangeset
for help on using the changeset viewer.