• 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
  • printing
foveditordialog.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  foveditordialog.cpp - K Desktop Planetarium
3  -------------------
4  begin : Fri Aug 12 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 "foveditordialog.h"
19 #include "printingwizard.h"
20 #include "kio/netaccess.h"
21 #include "ktemporaryfile.h"
22 #include "kfiledialog.h"
23 #include "kmessagebox.h"
24 
25 FovEditorDialogUI::FovEditorDialogUI(QWidget *parent) : QFrame(parent)
26 {
27  setupUi(this);
28 
29  setWindowTitle(i18n("Field of View Snapshot Browser"));
30 }
31 
32 FovEditorDialog::FovEditorDialog(PrintingWizard *wizard, QWidget *parent) : KDialog(parent),
33  m_ParentWizard(wizard), m_CurrentIndex(0)
34 {
35  m_EditorUi = new FovEditorDialogUI(this);
36  setMainWidget(m_EditorUi);
37  setButtons(KDialog::Close);
38 
39  setupWidgets();
40  setupConnections();
41 }
42 
43 void FovEditorDialog::slotNextFov()
44 {
45  slotSaveDescription();
46 
47  if(m_CurrentIndex < m_ParentWizard->getFovSnapshotList()->size() - 1)
48  {
49  m_CurrentIndex++;
50 
51  updateFovImage();
52  updateButtons();
53  updateDescriptions();
54  }
55 }
56 
57 void FovEditorDialog::slotPreviousFov()
58 {
59  slotSaveDescription();
60 
61  if(m_CurrentIndex > 0)
62  {
63  m_CurrentIndex--;
64 
65  updateFovImage();
66  updateButtons();
67  updateDescriptions();
68  }
69 }
70 
71 void FovEditorDialog::slotCaptureAgain()
72 {
73  hide();
74  m_ParentWizard->recaptureFov(m_CurrentIndex);
75 }
76 
77 void FovEditorDialog::slotDelete()
78 {
79  if(m_CurrentIndex > m_ParentWizard->getFovSnapshotList()->size() - 1)
80  {
81  return;
82  }
83 
84  delete m_ParentWizard->getFovSnapshotList()->at(m_CurrentIndex);
85  m_ParentWizard->getFovSnapshotList()->removeAt(m_CurrentIndex);
86 
87  if(m_CurrentIndex == m_ParentWizard->getFovSnapshotList()->size())
88  {
89  m_CurrentIndex--;
90  }
91 
92  updateFovImage();
93  updateButtons();
94  updateDescriptions();
95 }
96 
97 void FovEditorDialog::slotSaveDescription()
98 {
99  if(m_CurrentIndex < m_ParentWizard->getFovSnapshotList()->size())
100  {
101  m_ParentWizard->getFovSnapshotList()->at(m_CurrentIndex)->setDescription(m_EditorUi->descriptionEdit->text());
102  }
103 }
104 
105 void FovEditorDialog::slotSaveImage()
106 {
107  if(m_CurrentIndex >= m_ParentWizard->getFovSnapshotList()->size())
108  {
109  return;
110  }
111 
112  //If the filename string contains no "/" separators, assume the
113  //user wanted to place a file in their home directory.
114  QString url = KFileDialog::getSaveUrl(QDir::homePath(), "image/png image/jpeg image/gif image/x-portable-pixmap image/bmp").url();
115  KUrl fileUrl;
116  if(!url.contains("/"))
117  {
118  fileUrl = QDir::homePath() + '/' + url;
119  }
120 
121  else
122  {
123  fileUrl = url;
124  }
125 
126  KTemporaryFile tmpfile;
127  tmpfile.open();
128  QString fname;
129 
130  if(fileUrl.isValid())
131  {
132  if(fileUrl.isLocalFile())
133  {
134  fname = fileUrl.toLocalFile();
135  }
136 
137  else
138  {
139  fname = tmpfile.fileName();
140  }
141 
142  //Determine desired image format from filename extension
143  QString ext = fname.mid(fname.lastIndexOf(".") + 1);
144  // export as raster graphics
145  const char* format = "PNG";
146 
147  if(ext.toLower() == "png") {format = "PNG";}
148  else if(ext.toLower() == "jpg" || ext.toLower() == "jpeg" ) {format = "JPG";}
149  else if(ext.toLower() == "gif") {format = "GIF";}
150  else if(ext.toLower() == "pnm") {format = "PNM";}
151  else if(ext.toLower() == "bmp") {format = "BMP";}
152  else
153  {
154  kWarning() << i18n("Could not parse image format of %1; assuming PNG.", fname);
155  }
156 
157  if(!m_ParentWizard->getFovSnapshotList()->at(m_CurrentIndex)->getPixmap().save(fname, format))
158  {
159  kDebug() << i18n("Error: Unable to save image: %1 ", fname);
160  }
161 
162  else
163  {
164  kDebug() << i18n("Image saved to file: %1", fname);
165  }
166  }
167 
168  if(tmpfile.fileName() == fname)
169  {
170  //attempt to upload image to remote location
171  if(!KIO::NetAccess::upload(tmpfile.fileName(), fileUrl, this))
172  {
173  QString message = i18n( "Could not upload image to remote location: %1", fileUrl.prettyUrl() );
174  KMessageBox::sorry( 0, message, i18n( "Could not upload file" ) );
175  }
176  }
177 }
178 
179 void FovEditorDialog::setupWidgets()
180 {
181  if(m_ParentWizard->getFovSnapshotList()->size() > 0)
182  {
183  m_EditorUi->imageLabel->setPixmap(m_ParentWizard->getFovSnapshotList()->first()->getPixmap());
184  }
185 
186  updateButtons();
187  updateDescriptions();
188 }
189 
190 void FovEditorDialog::setupConnections()
191 {
192  connect(m_EditorUi->previousButton, SIGNAL(clicked()), this, SLOT(slotPreviousFov()));
193  connect(m_EditorUi->nextButton, SIGNAL(clicked()), this, SLOT(slotNextFov()));
194  connect(m_EditorUi->recaptureButton, SIGNAL(clicked()), this, SLOT(slotCaptureAgain()));
195  connect(m_EditorUi->deleteButton, SIGNAL(clicked()), this, SLOT(slotDelete()));
196  connect(m_EditorUi->descriptionEdit, SIGNAL(editingFinished()), this, SLOT(slotSaveDescription()));
197  connect(m_EditorUi->saveButton, SIGNAL(clicked()), this, SLOT(slotSaveImage()));
198 }
199 
200 void FovEditorDialog::updateButtons()
201 {
202  m_EditorUi->previousButton->setEnabled(m_CurrentIndex > 0);
203  m_EditorUi->nextButton->setEnabled(m_CurrentIndex < m_ParentWizard->getFovSnapshotList()->size() - 1);
204 }
205 
206 void FovEditorDialog::updateDescriptions()
207 {
208  if(m_ParentWizard->getFovSnapshotList()->size() == 0)
209  {
210  m_EditorUi->imageLabel->setText("No captured field of view images.");
211  m_EditorUi->fovInfoLabel->setText(QString());
212  m_EditorUi->recaptureButton->setEnabled(false);
213  m_EditorUi->deleteButton->setEnabled(false);
214  m_EditorUi->descriptionEdit->setEnabled(false);
215  m_EditorUi->saveButton->setEnabled(false);
216  }
217 
218  else
219  {
220  FOV *fov = m_ParentWizard->getFovSnapshotList()->at(m_CurrentIndex)->getFov();
221 
222  QString fovDescription = i18n("FOV (%1/%2): %3 (%4' x %5')",
223  QString::number(m_CurrentIndex + 1),
224  QString::number(m_ParentWizard->getFovSnapshotList()->size()),
225  fov->name(),
226  QString::number(fov->sizeX()),
227  QString::number(fov->sizeY()));
228 
229  m_EditorUi->fovInfoLabel->setText(fovDescription);
230 
231  m_EditorUi->descriptionEdit->setText(m_ParentWizard->getFovSnapshotList()->at(m_CurrentIndex)->getDescription());
232  }
233 }
234 
235 void FovEditorDialog::updateFovImage()
236 {
237  if(m_CurrentIndex < m_ParentWizard->getFovSnapshotList()->size())
238  {
239  m_EditorUi->imageLabel->setPixmap(m_ParentWizard->getFovSnapshotList()->at(m_CurrentIndex)->getPixmap());
240  }
241 }
FOV
class encapulating a Field-of-View symbol
Definition: fov.h:32
PrintingWizard::getFovSnapshotList
QList< FovSnapshot * > * getFovSnapshotList()
Get FovSnapshot list.
Definition: printingwizard.h:135
FOV::sizeX
float sizeX() const
Definition: fov.h:53
QWidget
KDialog
PrintingWizard
Class representing Printing Wizard for KStars printed documents (currently only finder charts)...
Definition: printingwizard.h:66
printingwizard.h
FOV::name
QString name() const
Definition: fov.h:46
FovEditorDialogUI
User interface for FOV Editor Dialog.
Definition: foveditordialog.h:30
PrintingWizard::recaptureFov
void recaptureFov(int idx)
Recapture FOV snapshot of passed index.
Definition: printingwizard.cpp:271
QFrame
foveditordialog.h
FOV::sizeY
float sizeY() const
Definition: fov.h:54
FovEditorDialog::FovEditorDialog
FovEditorDialog(PrintingWizard *wizard, QWidget *parent=0)
Constructor.
Definition: foveditordialog.cpp:32
FovEditorDialogUI::FovEditorDialogUI
FovEditorDialogUI(QWidget *parent=0)
Constructor.
Definition: foveditordialog.cpp:25
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