comparison view/View.cpp @ 1203:ff042979331b 3.0-integration

Merge from branch svg, and thus (in some subrepos) from levelpanwidget
author Chris Cannam
date Mon, 19 Dec 2016 16:34:38 +0000
parents 6828735468c9
children c603aba61702
comparison
equal deleted inserted replaced
1185:f32828ea63d9 1203:ff042979331b
39 #include <QTextStream> 39 #include <QTextStream>
40 #include <QFont> 40 #include <QFont>
41 #include <QMessageBox> 41 #include <QMessageBox>
42 #include <QPushButton> 42 #include <QPushButton>
43 #include <QSettings> 43 #include <QSettings>
44 #include <QSvgGenerator>
44 45
45 #include <iostream> 46 #include <iostream>
46 #include <cassert> 47 #include <cassert>
47 #include <cmath> 48 #include <cmath>
48 49
2098 2099
2099 if (dw < (p1 - p0)) { 2100 if (dw < (p1 - p0)) {
2100 dx = p1 - 2 - dw; 2101 dx = p1 - 2 - dw;
2101 } 2102 }
2102 2103
2103 paint.drawText(sx, sy, startText); 2104 PaintAssistant::drawVisibleText(this, paint, sx, sy, startText,
2104 paint.drawText(ex, ey, endText); 2105 PaintAssistant::OutlinedText);
2105 paint.drawText(dx, dy, durationText); 2106 PaintAssistant::drawVisibleText(this, paint, ex, ey, endText,
2107 PaintAssistant::OutlinedText);
2108 PaintAssistant::drawVisibleText(this, paint, dx, dy, durationText,
2109 PaintAssistant::OutlinedText);
2106 if (durationBothEnds) { 2110 if (durationBothEnds) {
2107 paint.drawText(sx, dy, durationText); 2111 PaintAssistant::drawVisibleText(this, paint, sx, dy, durationText,
2112 PaintAssistant::OutlinedText);
2108 } 2113 }
2109 } 2114 }
2110 } 2115 }
2111 2116
2112 paint.restore(); 2117 paint.restore();
2455 update(); 2460 update();
2456 return true; 2461 return true;
2457 } 2462 }
2458 2463
2459 QImage * 2464 QImage *
2460 View::toNewImage() 2465 View::renderToNewImage()
2461 { 2466 {
2462 sv_frame_t f0 = getModelsStartFrame(); 2467 sv_frame_t f0 = getModelsStartFrame();
2463 sv_frame_t f1 = getModelsEndFrame(); 2468 sv_frame_t f1 = getModelsEndFrame();
2464 2469
2465 return toNewImage(f0, f1); 2470 return renderPartToNewImage(f0, f1);
2466 } 2471 }
2467 2472
2468 QImage * 2473 QImage *
2469 View::toNewImage(sv_frame_t f0, sv_frame_t f1) 2474 View::renderPartToNewImage(sv_frame_t f0, sv_frame_t f1)
2470 { 2475 {
2471 int x0 = int(f0 / getZoomLevel()); 2476 int x0 = int(f0 / getZoomLevel());
2472 int x1 = int(f1 / getZoomLevel()); 2477 int x1 = int(f1 / getZoomLevel());
2473 2478
2474 QImage *image = new QImage(x1 - x0, height(), QImage::Format_RGB32); 2479 QImage *image = new QImage(x1 - x0, height(), QImage::Format_RGB32);
2483 return image; 2488 return image;
2484 } 2489 }
2485 } 2490 }
2486 2491
2487 QSize 2492 QSize
2488 View::getImageSize() 2493 View::getRenderedImageSize()
2489 { 2494 {
2490 sv_frame_t f0 = getModelsStartFrame(); 2495 sv_frame_t f0 = getModelsStartFrame();
2491 sv_frame_t f1 = getModelsEndFrame(); 2496 sv_frame_t f1 = getModelsEndFrame();
2492 2497
2493 return getImageSize(f0, f1); 2498 return getRenderedPartImageSize(f0, f1);
2494 } 2499 }
2495 2500
2496 QSize 2501 QSize
2497 View::getImageSize(sv_frame_t f0, sv_frame_t f1) 2502 View::getRenderedPartImageSize(sv_frame_t f0, sv_frame_t f1)
2498 { 2503 {
2499 int x0 = int(f0 / getZoomLevel()); 2504 int x0 = int(f0 / getZoomLevel());
2500 int x1 = int(f1 / getZoomLevel()); 2505 int x1 = int(f1 / getZoomLevel());
2501 2506
2502 return QSize(x1 - x0, height()); 2507 return QSize(x1 - x0, height());
2508 }
2509
2510 bool
2511 View::renderToSvgFile(QString filename)
2512 {
2513 sv_frame_t f0 = getModelsStartFrame();
2514 sv_frame_t f1 = getModelsEndFrame();
2515
2516 return renderPartToSvgFile(filename, f0, f1);
2517 }
2518
2519 bool
2520 View::renderPartToSvgFile(QString filename, sv_frame_t f0, sv_frame_t f1)
2521 {
2522 int x0 = int(f0 / getZoomLevel());
2523 int x1 = int(f1 / getZoomLevel());
2524
2525 QSvgGenerator generator;
2526 generator.setFileName(filename);
2527 generator.setSize(QSize(x1 - x0, height()));
2528 generator.setViewBox(QRect(0, 0, x1 - x0, height()));
2529 generator.setTitle(tr("Exported image from %1")
2530 .arg(QApplication::applicationName()));
2531
2532 QPainter paint;
2533 paint.begin(&generator);
2534 bool result = render(paint, 0, f0, f1);
2535 paint.end();
2536 return result;
2503 } 2537 }
2504 2538
2505 void 2539 void
2506 View::toXml(QTextStream &stream, 2540 View::toXml(QTextStream &stream,
2507 QString indent, QString extraAttributes) const 2541 QString indent, QString extraAttributes) const