20 #include "kio/netaccess.h"
21 #include "ktemporaryfile.h"
22 #include "kfiledialog.h"
23 #include "kmessagebox.h"
29 setWindowTitle(i18n(
"Field of View Snapshot Browser"));
33 m_ParentWizard(wizard), m_CurrentIndex(0)
36 setMainWidget(m_EditorUi);
37 setButtons(KDialog::Close);
43 void FovEditorDialog::slotNextFov()
45 slotSaveDescription();
47 if(m_CurrentIndex < m_ParentWizard->getFovSnapshotList()->size() - 1)
57 void FovEditorDialog::slotPreviousFov()
59 slotSaveDescription();
61 if(m_CurrentIndex > 0)
71 void FovEditorDialog::slotCaptureAgain()
77 void FovEditorDialog::slotDelete()
97 void FovEditorDialog::slotSaveDescription()
99 if(m_CurrentIndex < m_ParentWizard->getFovSnapshotList()->size())
101 m_ParentWizard->
getFovSnapshotList()->at(m_CurrentIndex)->setDescription(m_EditorUi->descriptionEdit->text());
105 void FovEditorDialog::slotSaveImage()
114 QString url = KFileDialog::getSaveUrl(QDir::homePath(),
"image/png image/jpeg image/gif image/x-portable-pixmap image/bmp").url();
116 if(!url.contains(
"/"))
118 fileUrl = QDir::homePath() +
'/' + url;
126 KTemporaryFile tmpfile;
130 if(fileUrl.isValid())
132 if(fileUrl.isLocalFile())
134 fname = fileUrl.toLocalFile();
139 fname = tmpfile.fileName();
143 QString ext = fname.mid(fname.lastIndexOf(
".") + 1);
145 const char* format =
"PNG";
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";}
154 kWarning() << i18n(
"Could not parse image format of %1; assuming PNG.", fname);
157 if(!m_ParentWizard->
getFovSnapshotList()->at(m_CurrentIndex)->getPixmap().save(fname, format))
159 kDebug() << i18n(
"Error: Unable to save image: %1 ", fname);
164 kDebug() << i18n(
"Image saved to file: %1", fname);
168 if(tmpfile.fileName() == fname)
171 if(!KIO::NetAccess::upload(tmpfile.fileName(), fileUrl,
this))
173 QString message = i18n(
"Could not upload image to remote location: %1", fileUrl.prettyUrl() );
174 KMessageBox::sorry( 0, message, i18n(
"Could not upload file" ) );
179 void FovEditorDialog::setupWidgets()
183 m_EditorUi->imageLabel->setPixmap(m_ParentWizard->
getFovSnapshotList()->first()->getPixmap());
187 updateDescriptions();
190 void FovEditorDialog::setupConnections()
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()));
200 void FovEditorDialog::updateButtons()
202 m_EditorUi->previousButton->setEnabled(m_CurrentIndex > 0);
203 m_EditorUi->nextButton->setEnabled(m_CurrentIndex < m_ParentWizard->getFovSnapshotList()->size() - 1);
206 void FovEditorDialog::updateDescriptions()
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);
222 QString fovDescription = i18n(
"FOV (%1/%2): %3 (%4' x %5')",
223 QString::number(m_CurrentIndex + 1),
226 QString::number(fov->
sizeX()),
227 QString::number(fov->
sizeY()));
229 m_EditorUi->fovInfoLabel->setText(fovDescription);
231 m_EditorUi->descriptionEdit->setText(m_ParentWizard->
getFovSnapshotList()->at(m_CurrentIndex)->getDescription());
235 void FovEditorDialog::updateFovImage()
237 if(m_CurrentIndex < m_ParentWizard->getFovSnapshotList()->size())
239 m_EditorUi->imageLabel->setPixmap(m_ParentWizard->
getFovSnapshotList()->at(m_CurrentIndex)->getPixmap());
class encapulating a Field-of-View symbol
QList< FovSnapshot * > * getFovSnapshotList()
Get FovSnapshot list.
Class representing Printing Wizard for KStars printed documents (currently only finder charts)...
User interface for FOV Editor Dialog.
void recaptureFov(int idx)
Recapture FOV snapshot of passed index.
FovEditorDialog(PrintingWizard *wizard, QWidget *parent=0)
Constructor.
FovEditorDialogUI(QWidget *parent=0)
Constructor.