1 /**
2 * UGENE - Integrated Bioinformatics Tools.
3 * Copyright (C) 2008-2021 UniPro <ugene@unipro.ru>
4 * http://ugene.net
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19 * MA 02110-1301, USA.
20 */
21
22 #include "MaOverviewImageExportTask.h"
23
24 #include <QCheckBox>
25 #include <QPainter>
26 #include <QVBoxLayout>
27
28 #include <U2Core/U2SafePoints.h>
29
30 #include "MaGraphOverview.h"
31 #include "MaSimpleOverview.h"
32
33 namespace U2 {
34
MaOverviewImageExportToBitmapTask(MaSimpleOverview * simpleOverview,MaGraphOverview * graphOverview,const MaOverviewImageExportSettings & overviewSettings,const ImageExportTaskSettings & settings)35 MaOverviewImageExportToBitmapTask::MaOverviewImageExportToBitmapTask(MaSimpleOverview *simpleOverview,
36 MaGraphOverview *graphOverview,
37 const MaOverviewImageExportSettings &overviewSettings,
38 const ImageExportTaskSettings &settings)
39 : ImageExportTask(settings),
40 simpleOverview(simpleOverview),
41 graphOverview(graphOverview),
42 overviewSettings(overviewSettings) {
43 SAFE_POINT_EXT(simpleOverview != nullptr, setError(tr("Overview is NULL")), );
44 SAFE_POINT_EXT(graphOverview != nullptr, setError(tr("Graph overview is NULL")), );
45 CHECK_EXT(overviewSettings.exportGraphOverview || overviewSettings.exportSimpleOverview,
46 setError(tr("Nothing to export. ") + EXPORT_FAIL_MESSAGE.arg(settings.fileName)), );
47 }
48
run()49 void MaOverviewImageExportToBitmapTask::run() {
50 SAFE_POINT_EXT(settings.isBitmapFormat(),
51 setError(WRONG_FORMAT_MESSAGE.arg(settings.format).arg("MSAOverviewImageExportToBitmapTask")), );
52 QPixmap pixmap(settings.imageSize.width(), settings.imageSize.height());
53 QPainter p(&pixmap);
54
55 if (overviewSettings.exportSimpleOverview) {
56 QPixmap simpleOverviewPixmap = simpleOverview->getView();
57 p.drawPixmap(simpleOverview->rect(), simpleOverviewPixmap);
58 p.translate(0, simpleOverview->height());
59 }
60 if (overviewSettings.exportGraphOverview) {
61 QPixmap graphOverviewPixmap = graphOverview->getView();
62 p.drawPixmap(graphOverview->rect(), graphOverviewPixmap);
63 }
64 p.end();
65
66 CHECK_EXT(pixmap.save(settings.fileName, qPrintable(settings.format), settings.imageQuality), setError(tr("FAIL")), );
67 }
68
MaOverviewImageExportController(MaSimpleOverview * simpleOverview,MaGraphOverview * graphOverview)69 MaOverviewImageExportController::MaOverviewImageExportController(MaSimpleOverview *simpleOverview,
70 MaGraphOverview *graphOverview)
71 : ImageExportController(),
72 simpleOverview(simpleOverview),
73 graphOverview(graphOverview) {
74 SAFE_POINT(simpleOverview != nullptr, QObject::tr("Overview is NULL"), );
75 SAFE_POINT(graphOverview != nullptr, QObject::tr("Graph overview is NULL"), );
76 shortDescription = tr("Alignment overview");
77 initSettingsWidget();
78 }
79
getImageWidth() const80 int MaOverviewImageExportController::getImageWidth() const {
81 return graphOverview->width();
82 }
83
getImageHeight() const84 int MaOverviewImageExportController::getImageHeight() const {
85 int h = 0;
86 if (exportSimpleOverview->isChecked()) {
87 h += simpleOverview->height();
88 }
89 if (exportGraphOverview->isChecked()) {
90 h += graphOverview->height();
91 }
92 return h;
93 }
94
getExportToBitmapTask(const ImageExportTaskSettings & settings) const95 Task *MaOverviewImageExportController::getExportToBitmapTask(const ImageExportTaskSettings &settings) const {
96 MaOverviewImageExportSettings overviewSettings(exportSimpleOverview->isChecked(),
97 exportGraphOverview->isChecked());
98 // overview has fixed size
99 ImageExportTaskSettings copySettings = settings;
100 copySettings.imageSize = QSize(getImageWidth(), getImageHeight());
101 return new MaOverviewImageExportToBitmapTask(simpleOverview, graphOverview, overviewSettings, copySettings);
102 }
103
initSettingsWidget()104 void MaOverviewImageExportController::initSettingsWidget() {
105 settingsWidget = new QWidget();
106 exportSimpleOverview = new QCheckBox(QObject::tr("Export simple overview"), settingsWidget);
107 exportGraphOverview = new QCheckBox(QObject::tr("Export graph overview"), settingsWidget);
108
109 exportSimpleOverview->setObjectName("export_msa_simple_overview");
110 exportGraphOverview->setObjectName("export_msa_graph_overview");
111
112 QVBoxLayout *layout = new QVBoxLayout(settingsWidget);
113 layout->setSizeConstraint(QLayout::SetMinAndMaxSize);
114 layout->setContentsMargins(0, 0, 0, 0);
115
116 layout->addWidget(exportSimpleOverview);
117 layout->addWidget(exportGraphOverview);
118
119 if (!simpleOverview->isValid() || !simpleOverview->isVisible()) {
120 exportSimpleOverview->setDisabled(true);
121 } else {
122 exportSimpleOverview->setChecked(true);
123 }
124 exportGraphOverview->setChecked(true);
125
126 settingsWidget->setLayout(layout);
127 }
128
129 } // namespace U2
130