Kstars

exportimagedialog.cpp
1/*
2 SPDX-FileCopyrightText: 2011 Rafał Kułaga <rl.kulaga@gmail.com>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#include "exportimagedialog.h"
8
9#include "imageexporter.h"
10#include "kstars.h"
11#include "skymap.h"
12#include "skyqpainter.h"
13#include "ksnotification.h"
14#include "printing/legend.h"
15
16#include <KMessageBox>
17
18//#include <QDesktopWidget>
19#include <QDir>
20#include <QPushButton>
21#include <QtSvg/QSvgGenerator>
22
23ExportImageDialogUI::ExportImageDialogUI(QWidget *parent) : QFrame(parent)
24{
25 setupUi(this);
26}
27
29 : QDialog((QWidget *)KStars::Instance()), m_KStars(KStars::Instance()), m_Url(url), m_Size(size)
30{
31#ifdef Q_OS_MACOS
33#endif
34 m_DialogUI = new ExportImageDialogUI(this);
35
36 QVBoxLayout *mainLayout = new QVBoxLayout;
37 mainLayout->addWidget(m_DialogUI);
38 setLayout(mainLayout);
39
41 mainLayout->addWidget(buttonBox);
42 connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
43 connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
44
45 connect(buttonBox, SIGNAL(accepted()), this, SLOT(exportImage()));
46 connect(buttonBox, SIGNAL(rejected()), this, SLOT(close()));
47
48 QPushButton *previewB = new QPushButton(i18n("Preview image"));
49 buttonBox->addButton(previewB, QDialogButtonBox::ActionRole);
50 connect(previewB, SIGNAL(clicked()), this, SLOT(previewImage()));
51
52 connect(m_DialogUI->addLegendCheckBox, SIGNAL(toggled(bool)), this, SLOT(switchLegendEnabled(bool)));
53 connect(m_DialogUI->addLegendCheckBox, SIGNAL(toggled(bool)), previewB, SLOT(setEnabled(bool)));
54
55 m_ImageExporter = ((imgExporter) ? imgExporter : new ImageExporter(this));
56
57 setWindowTitle(i18nc("@title:window", "Export sky image"));
58
59 setupWidgets();
60}
61
62void ExportImageDialog::switchLegendEnabled(bool enabled)
63{
64 m_DialogUI->legendOrientationLabel->setEnabled(enabled);
65 m_DialogUI->legendOrientationComboBox->setEnabled(enabled);
66 m_DialogUI->legendTypeLabel->setEnabled(enabled);
67 m_DialogUI->legendTypeComboBox->setEnabled(enabled);
68 m_DialogUI->legendPositionLabel->setEnabled(enabled);
69 m_DialogUI->legendPositionComboBox->setEnabled(enabled);
70}
71
72void ExportImageDialog::previewImage()
73{
74 updateLegendSettings();
75 const Legend *legend = m_ImageExporter->getLegend();
76
77 // Preview current legend settings on sky map
78 m_KStars->map()->setLegend(Legend(*legend));
79 m_KStars->map()->setPreviewLegend(true);
80
81 // Update sky map
82 m_KStars->map()->forceUpdate(true);
83
84 // Hide export dialog
85 hide();
86}
87
88void ExportImageDialog::setupWidgets()
89{
90 m_DialogUI->addLegendCheckBox->setChecked(true);
91
92 m_DialogUI->legendOrientationComboBox->addItem(i18n("Horizontal"));
93 m_DialogUI->legendOrientationComboBox->addItem(i18n("Vertical"));
94
95 QStringList types;
96 types << i18n("Full legend") << i18n("Scale with magnitudes chart") << i18n("Only scale") << i18n("Only magnitudes")
97 << i18n("Only symbols");
98 m_DialogUI->legendTypeComboBox->addItems(types);
99
100 QStringList positions;
101 positions << i18n("Upper left corner") << i18n("Upper right corner") << i18n("Lower left corner")
102 << i18n("Lower right corner");
103 m_DialogUI->legendPositionComboBox->addItems(positions);
104}
105
106void ExportImageDialog::updateLegendSettings()
107{
108 Legend::LEGEND_ORIENTATION orientation =
109 ((m_DialogUI->legendOrientationComboBox->currentIndex() == 1) ? Legend::LO_VERTICAL : Legend::LO_HORIZONTAL);
110
111 Legend::LEGEND_TYPE type = static_cast<Legend::LEGEND_TYPE>(m_DialogUI->legendTypeComboBox->currentIndex());
112
113 Legend::LEGEND_POSITION pos =
114 static_cast<Legend::LEGEND_POSITION>(m_DialogUI->legendPositionComboBox->currentIndex());
115
116 m_ImageExporter->setLegendProperties(type, orientation, pos);
117}
118
119void ExportImageDialog::exportImage()
120{
121 qDebug() << Q_FUNC_INFO << "Exporting sky image";
122 updateLegendSettings();
123 m_ImageExporter->includeLegend(m_DialogUI->addLegendCheckBox->isChecked());
124 if (!m_ImageExporter->exportImage(m_Url))
125 {
126 KSNotification::sorry(m_ImageExporter->getLastErrorMessage(), i18n("Could not export image"));
127 }
128}
ExportImageDialog(const QString &url, const QSize &size, ImageExporter *imgExporter=nullptr)
short Default constructor.
Backends for exporting a sky image, either raster or vector, with a legend.
QString getLastErrorMessage() const
void includeLegend(bool include)
Include legend?
void setLegendProperties(Legend::LEGEND_TYPE type, Legend::LEGEND_ORIENTATION orientation, Legend::LEGEND_POSITION position, int alpha=160, bool include=true)
Set the legend properties.
bool exportImage(QString url)
Exports an image with the defined settings.
Legend * getLegend()
This is the main window for KStars.
Definition kstars.h:89
SkyMap * map() const
Definition kstars.h:139
void forceUpdate(bool now=false)
Recalculates the positions of objects in the sky, and then repaints the sky map.
Definition skymap.cpp:1186
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
Type type(const QSqlDatabase &db)
void addWidget(QWidget *widget, int stretch, Qt::Alignment alignment)
virtual void accept()
void accepted()
virtual void reject()
void rejected()
QPushButton * addButton(StandardButton button)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
bool close()
void setEnabled(bool)
void hide()
void setLayout(QLayout *layout)
void setWindowFlags(Qt::WindowFlags type)
void setWindowTitle(const QString &)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:04:45 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.