• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

kstars

  • sources
  • kde-4.12
  • kdeedu
  • kstars
  • kstars
  • dialogs
exportimagedialog.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  exportimagedialog.cpp - K Desktop Planetarium
3  -------------------
4  begin : Mon Jun 13 2011
5  copyright : (C) 2011 by Rafał Kułaga
6  email : rl.kulaga@gmail.com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #include "exportimagedialog.h"
19 #include "kstars/kstars.h"
20 #include "kstars/skymap.h"
21 #include "../printing/legend.h"
22 #include "kstars/skyqpainter.h"
23 #include "../imageexporter.h"
24 
25 #include <kmessagebox.h>
26 #include <kurl.h>
27 
28 #include <QSvgGenerator>
29 #include <QDir>
30 #include <QDesktopWidget>
31 
32 
33 ExportImageDialogUI::ExportImageDialogUI(QWidget *parent)
34  : QFrame(parent)
35 {
36  setupUi(this);
37 }
38 
39 ExportImageDialog::ExportImageDialog(const QString &url, const QSize &size, ImageExporter *imgExporter)
40  : KDialog((QWidget*) KStars::Instance()), m_KStars(KStars::Instance()), m_Url(url), m_Size(size)
41 {
42  m_DialogUI = new ExportImageDialogUI(this);
43  setMainWidget(m_DialogUI);
44 
45  m_ImageExporter = ( ( imgExporter ) ? imgExporter : new ImageExporter( this ) );
46 
47  setWindowTitle(i18n("Export sky image"));
48 
49  setupWidgets();
50  setupConnections();
51 }
52 
53 void ExportImageDialog::switchLegendEnabled(bool enabled)
54 {
55  m_DialogUI->legendOrientationLabel->setEnabled(enabled);
56  m_DialogUI->legendOrientationComboBox->setEnabled(enabled);
57  m_DialogUI->legendTypeLabel->setEnabled(enabled);
58  m_DialogUI->legendTypeComboBox->setEnabled(enabled);
59  m_DialogUI->legendPositionLabel->setEnabled(enabled);
60  m_DialogUI->legendPositionComboBox->setEnabled(enabled);
61 }
62 
63 void ExportImageDialog::previewImage()
64 {
65  updateLegendSettings();
66  const Legend *legend = m_ImageExporter->getLegend();
67 
68  // Preview current legend settings on sky map
69  m_KStars->map()->setLegend( Legend( *legend ) );
70  m_KStars->map()->setPreviewLegend(true);
71 
72  // Update sky map
73  m_KStars->map()->forceUpdate(true);
74 
75  // Hide export dialog
76  hide();
77 }
78 
79 void ExportImageDialog::setupWidgets()
80 {
81  setButtons(KDialog::Ok | KDialog::Cancel | KDialog::User1);
82  setButtonText(KDialog::User1, i18n("Preview image"));
83  setButtonText(KDialog::Ok, i18n("Export image"));
84 
85  m_DialogUI->addLegendCheckBox->setChecked(true);
86 
87  m_DialogUI->legendOrientationComboBox->addItem(i18n("Horizontal"));
88  m_DialogUI->legendOrientationComboBox->addItem(i18n("Vertical"));
89 
90  QStringList types;
91  types << i18n("Full legend") << i18n("Scale with magnitudes chart") << i18n("Only scale")
92  << i18n("Only magnitudes") << i18n("Only symbols");
93  m_DialogUI->legendTypeComboBox->addItems(types);
94 
95  QStringList positions;
96  positions << i18n("Upper left corner") << i18n("Upper right corner") << i18n("Lower left corner")
97  << i18n("Lower right corner");
98  m_DialogUI->legendPositionComboBox->addItems(positions);
99 }
100 
101 void ExportImageDialog::setupConnections()
102 {
103  connect(this, SIGNAL(okClicked()), this, SLOT(exportImage()));
104  connect(this, SIGNAL(cancelClicked()), this, SLOT(close()));
105  connect(this, SIGNAL(user1Clicked()), this, SLOT(previewImage()));
106 
107  connect(m_DialogUI->addLegendCheckBox, SIGNAL(toggled(bool)), this, SLOT(switchLegendEnabled(bool)));
108  connect(m_DialogUI->addLegendCheckBox, SIGNAL(toggled(bool)), button(KDialog::User1), SLOT(setEnabled(bool)));
109 }
110 
111 void ExportImageDialog::updateLegendSettings()
112 {
113  Legend::LEGEND_ORIENTATION orientation = ( ( m_DialogUI->legendOrientationComboBox->currentIndex() == 1) ? Legend::LO_VERTICAL : Legend::LO_HORIZONTAL );
114 
115  Legend::LEGEND_TYPE type = static_cast<Legend::LEGEND_TYPE>(m_DialogUI->legendTypeComboBox->currentIndex());
116 
117  Legend::LEGEND_POSITION pos = static_cast<Legend::LEGEND_POSITION>(m_DialogUI->legendPositionComboBox->currentIndex());
118 
119  m_ImageExporter->setLegendProperties( type, orientation, pos );
120 }
121 
122 void ExportImageDialog::exportImage()
123 {
124  kDebug() << "Exporting sky image";
125  updateLegendSettings();
126  m_ImageExporter->includeLegend( m_DialogUI->addLegendCheckBox->isChecked() );
127  if( !m_ImageExporter->exportImage( m_Url ) ) {
128  KMessageBox::sorry( 0, m_ImageExporter->getLastErrorMessage(), i18n( "Could not export image" ) );
129  }
130 }
exportimagedialog.h
QWidget
KDialog
ImageExporter
Backends for exporting a sky image, either raster or vector, with a legend.
Definition: imageexporter.h:35
KStars
This is the main window for KStars.
Definition: kstars.h:94
Legend::LEGEND_POSITION
LEGEND_POSITION
Legend position enumeration.
Definition: legend.h:73
Legend::LO_HORIZONTAL
Definition: legend.h:66
ExportImageDialog::ExportImageDialog
ExportImageDialog(const QString &url, const QSize &size, ImageExporter *imgExporter=0)
short Default constructor.
Definition: exportimagedialog.cpp:39
skymap.h
Legend::LEGEND_TYPE
LEGEND_TYPE
Legend type enumeration.
Definition: legend.h:52
Legend::LEGEND_ORIENTATION
LEGEND_ORIENTATION
Legend orientation enumeration.
Definition: legend.h:64
Legend
Legend class is used for painting legends on class inheriting QPaintDevice.
Definition: legend.h:45
ExportImageDialogUI
Definition: exportimagedialog.h:32
skyqpainter.h
ExportImageDialogUI::ExportImageDialogUI
ExportImageDialogUI(QWidget *parent=0)
Definition: exportimagedialog.cpp:33
QFrame
kstars.h
Legend::LO_VERTICAL
Definition: legend.h:67
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:36:19 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kstars

Skip menu "kstars"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal