| 682 | } |
| 683 | |
| 684 | void TOPPASBase::exportAsImage() |
| 685 | { |
| 686 | TOPPASWidget* w = activeSubWindow_(); |
| 687 | TOPPASScene* s = w->getScene(); |
| 688 | |
| 689 | QString cp = current_path_.toQString(); |
| 690 | QString file_name = QFileDialog::getSaveFileName(w, tr("Save image"), cp, tr("Images (*.svg *.png *.jpg)")); |
| 691 | if (file_name == "") |
| 692 | { |
| 693 | return; |
| 694 | } |
| 695 | if (!file_name.endsWith(".svg", Qt::CaseInsensitive) && |
| 696 | !file_name.endsWith(".png", Qt::CaseInsensitive) && |
| 697 | !file_name.endsWith(".jpg", Qt::CaseInsensitive)) |
| 698 | { |
| 699 | file_name += ".svg"; |
| 700 | } |
| 701 | bool svg = file_name.endsWith(".svg"); |
| 702 | |
| 703 | QRectF items_bounding_rect = s->itemsBoundingRect(); |
| 704 | qreal wh_proportion = (qreal)(items_bounding_rect.width()) / (qreal)(items_bounding_rect.height()); |
| 705 | bool w_larger_than_h = wh_proportion > 1; |
| 706 | qreal x1 = 0; |
| 707 | qreal y1 = 0; |
| 708 | qreal x2, y2; |
| 709 | |
| 710 | qreal small_edge_length = svg ? 500 : 4000; |
| 711 | |
| 712 | if (w_larger_than_h) |
| 713 | { |
| 714 | x2 = wh_proportion * small_edge_length; |
| 715 | y2 = small_edge_length; |
| 716 | } |
| 717 | else |
| 718 | { |
| 719 | x2 = small_edge_length; |
| 720 | y2 = (1.0 / wh_proportion) * small_edge_length; |
| 721 | } |
| 722 | qreal width = x2 - x1; |
| 723 | qreal height = y2 - y1; |
| 724 | |
| 725 | if (svg) |
| 726 | { |
| 727 | QSvgGenerator svg_gen; |
| 728 | svg_gen.setFileName(file_name); |
| 729 | svg_gen.setSize(QSize(width, height)); |
| 730 | svg_gen.setViewBox(QRect(x1, y1, x2, y2)); |
| 731 | svg_gen.setTitle(tr("Title (TBD)")); |
| 732 | svg_gen.setDescription(tr("Description (TBD)")); |
| 733 | QPainter painter(&svg_gen); |
| 734 | s->render(&painter, QRectF(), items_bounding_rect); |
| 735 | } |
| 736 | else |
| 737 | { |
| 738 | QImage img(width, height, QImage::Format_RGB32); |
| 739 | img.fill(QColor(Qt::white).rgb()); |
| 740 | QPainter painter(&img); |
| 741 | s->render(&painter, QRectF(), items_bounding_rect); |
nothing calls this directly
no test coverage detected