• 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
pwizprint.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  pwizprint.cpp - K Desktop Planetarium
3  -------------------
4  begin : Wed Aug 3 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 "pwizprint.h"
19 
20 #include "printingwizard.h"
21 #include "finderchart.h"
22 #include "loggingform.h"
23 #include "kfiledialog.h"
24 #include "kmessagebox.h"
25 #include "kstars.h"
26 #include "ktemporaryfile.h"
27 #include "kio/netaccess.h"
28 #include "QPrintPreviewDialog"
29 #include "QPrinter"
30 #include "QPrintDialog"
31 #include "QPointer"
32 
33 PWizPrintUI::PWizPrintUI(PrintingWizard *wizard, QWidget *parent) : QFrame(parent),
34  m_ParentWizard(wizard)
35 {
36  setupUi(this);
37 
38  connect(previewButton, SIGNAL(clicked()), this, SLOT(slotPreview()));
39  connect(printButton, SIGNAL(clicked()), this, SLOT(slotPrint()));
40  connect(exportButton, SIGNAL(clicked()), this, SLOT(slotExport()));
41 }
42 
43 void PWizPrintUI::slotPreview()
44 {
45  QPointer<QPrintPreviewDialog> previewDlg( new QPrintPreviewDialog( m_ParentWizard->getPrinter()
46  , KStars::Instance() ) );
47  connect(previewDlg, SIGNAL(paintRequested(QPrinter*)), SLOT(slotPrintPreview(QPrinter*)));
48  previewDlg->exec();
49  delete previewDlg;
50 }
51 
52 void PWizPrintUI::slotPrintPreview(QPrinter *printer)
53 {
54  printDocument(printer);
55 }
56 
57 void PWizPrintUI::slotPrint()
58 {
59  QPointer<QPrintDialog> dialog( new QPrintDialog( m_ParentWizard->getPrinter()
60  , KStars::Instance() ) );
61  if(dialog->exec() == QDialog::Accepted)
62  {
63  printDocument(m_ParentWizard->getPrinter());
64  }
65  delete dialog;
66 }
67 
68 void PWizPrintUI::printDocument(QPrinter *printer)
69 {
70  m_ParentWizard->getFinderChart()->print(printer);
71 }
72 
73 void PWizPrintUI::slotExport()
74 {
75  KUrl url = KFileDialog::getSaveUrl(QDir::homePath(), "application/pdf application/postscript application/vnd.oasis.opendocument.text");
76  //User cancelled file selection dialog - abort image export
77  if(url.isEmpty())
78  {
79  return;
80  }
81 
82  //Warn user if file exists!
83  if(QFile::exists(url.path()))
84  {
85  int r=KMessageBox::warningContinueCancel(parentWidget(),
86  i18n( "A file named \"%1\" already exists. Overwrite it?" , url.fileName()),
87  i18n( "Overwrite File?" ),
88  KStandardGuiItem::overwrite() );
89  if(r == KMessageBox::Cancel)
90  return;
91  }
92 
93  QString urlStr = url.url();
94  if(!urlStr.contains("/"))
95  {
96  urlStr = QDir::homePath() + '/' + urlStr;
97  }
98 
99  KTemporaryFile tmpfile;
100  tmpfile.open();
101  QString fname;
102 
103  if(url.isValid())
104  {
105  if(url.isLocalFile())
106  {
107  fname = url.toLocalFile();
108  }
109 
110  else
111  {
112  fname = tmpfile.fileName();
113  }
114 
115  //Determine desired image format from filename extension
116  QString ext = fname.mid(fname.lastIndexOf(".") + 1);
117  if(ext == "pdf" || ext == "ps") {
118  m_ParentWizard->getFinderChart()->writePsPdf(fname);
119  } else if(ext == "odt") {
120  m_ParentWizard->getFinderChart()->writeOdt(fname);
121  } else {
122  return;
123  }
124 
125  if(tmpfile.fileName() == fname)
126  {
127  //attempt to upload image to remote location
128  if(!KIO::NetAccess::upload(tmpfile.fileName(), url, this))
129  {
130  QString message = i18n( "Could not upload file to remote location: %1", url.prettyUrl() );
131  KMessageBox::sorry( 0, message, i18n( "Could not upload file" ) );
132  }
133  }
134  }
135 }
QWidget
KStars::Instance
static KStars * Instance()
Definition: kstars.h:125
KStarsDocument::writePsPdf
void writePsPdf(const QString &fname)
Write contents of the document to the Postscript/PDF file.
Definition: kstarsdocument.cpp:54
PrintingWizard::getPrinter
QPrinter * getPrinter()
Get printer used by Printing Wizard.
Definition: printingwizard.h:117
loggingform.h
PrintingWizard::getFinderChart
FinderChart * getFinderChart()
Get used FinderChart document.
Definition: printingwizard.h:123
pwizprint.h
PrintingWizard
Class representing Printing Wizard for KStars printed documents (currently only finder charts)...
Definition: printingwizard.h:66
printingwizard.h
finderchart.h
PWizPrintUI::PWizPrintUI
PWizPrintUI(PrintingWizard *wizard, QWidget *parent=0)
Constructor.
Definition: pwizprint.cpp:33
QFrame
KStarsDocument::writeOdt
bool writeOdt(const QString &fname)
Write contents of the document to Open Document Text file.
Definition: kstarsdocument.cpp:48
kstars.h
KStarsDocument::print
void print(QPrinter *printer)
Print contents of the document.
Definition: kstarsdocument.cpp:43
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:36:20 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