comparison view/View.cpp @ 1202:6828735468c9 svg

Implement "Export SVG file..."
author Chris Cannam
date Mon, 19 Dec 2016 16:32:34 +0000
parents 54e6be7ebe11
children c603aba61702
comparison
equal deleted inserted replaced
1201:a68c25ba1153 1202:6828735468c9
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
2459 update(); 2460 update();
2460 return true; 2461 return true;
2461 } 2462 }
2462 2463
2463 QImage * 2464 QImage *
2464 View::toNewImage() 2465 View::renderToNewImage()
2465 { 2466 {
2466 sv_frame_t f0 = getModelsStartFrame(); 2467 sv_frame_t f0 = getModelsStartFrame();
2467 sv_frame_t f1 = getModelsEndFrame(); 2468 sv_frame_t f1 = getModelsEndFrame();
2468 2469
2469 return toNewImage(f0, f1); 2470 return renderPartToNewImage(f0, f1);
2470 } 2471 }
2471 2472
2472 QImage * 2473 QImage *
2473 View::toNewImage(sv_frame_t f0, sv_frame_t f1) 2474 View::renderPartToNewImage(sv_frame_t f0, sv_frame_t f1)
2474 { 2475 {
2475 int x0 = int(f0 / getZoomLevel()); 2476 int x0 = int(f0 / getZoomLevel());
2476 int x1 = int(f1 / getZoomLevel()); 2477 int x1 = int(f1 / getZoomLevel());
2477 2478
2478 QImage *image = new QImage(x1 - x0, height(), QImage::Format_RGB32); 2479 QImage *image = new QImage(x1 - x0, height(), QImage::Format_RGB32);
2487 return image; 2488 return image;
2488 } 2489 }
2489 } 2490 }
2490 2491
2491 QSize 2492 QSize
2492 View::getImageSize() 2493 View::getRenderedImageSize()
2493 { 2494 {
2494 sv_frame_t f0 = getModelsStartFrame(); 2495 sv_frame_t f0 = getModelsStartFrame();
2495 sv_frame_t f1 = getModelsEndFrame(); 2496 sv_frame_t f1 = getModelsEndFrame();
2496 2497
2497 return getImageSize(f0, f1); 2498 return getRenderedPartImageSize(f0, f1);
2498 } 2499 }
2499 2500
2500 QSize 2501 QSize
2501 View::getImageSize(sv_frame_t f0, sv_frame_t f1) 2502 View::getRenderedPartImageSize(sv_frame_t f0, sv_frame_t f1)
2502 { 2503 {
2503 int x0 = int(f0 / getZoomLevel()); 2504 int x0 = int(f0 / getZoomLevel());
2504 int x1 = int(f1 / getZoomLevel()); 2505 int x1 = int(f1 / getZoomLevel());
2505 2506
2506 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;
2507 } 2537 }
2508 2538
2509 void 2539 void
2510 View::toXml(QTextStream &stream, 2540 View::toXml(QTextStream &stream,
2511 QString indent, QString extraAttributes) const 2541 QString indent, QString extraAttributes) const