summaryrefslogtreecommitdiffstats
path: root/qt-ui/printoptions.cpp
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2015-07-28 07:27:30 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2015-07-28 07:27:30 -0700
commitf2e2be0f67146941d9a05815db2d1335a975765e (patch)
tree31813fc61ad44048baf72cd71e016b521bd6afbe /qt-ui/printoptions.cpp
parent7d0c6f895d813b366a3c9ff5b26ed3db1b2fba02 (diff)
parent01645d64b91b29878d6927dcf7cd5c2381e0bfaa (diff)
downloadsubsurface-f2e2be0f67146941d9a05815db2d1335a975765e.tar.gz
Merge branch 'custom-print' of github.com:neolit123/subsurface
Diffstat (limited to 'qt-ui/printoptions.cpp')
-rw-r--r--qt-ui/printoptions.cpp94
1 files changed, 63 insertions, 31 deletions
diff --git a/qt-ui/printoptions.cpp b/qt-ui/printoptions.cpp
index 0e6a0b320..1da95a94d 100644
--- a/qt-ui/printoptions.cpp
+++ b/qt-ui/printoptions.cpp
@@ -1,6 +1,10 @@
#include "printoptions.h"
#include "templateedit.h"
+#include "helpers.h"
+
#include <QDebug>
+#include <QFileDialog>
+#include <QMessageBox>
PrintOptions::PrintOptions(QWidget *parent, struct print_options *printOpt, struct template_options *templateOpt)
{
@@ -22,24 +26,26 @@ void PrintOptions::setup()
case print_options::DIVELIST:
ui.radioDiveListPrint->setChecked(true);
break;
- case print_options::TABLE:
- ui.radioTablePrint->setChecked(true);
- break;
case print_options::STATISTICS:
ui.radioStatisticsPrint->setChecked(true);
break;
}
- switch (printOptions->p_template) {
- case print_options::ONE_DIVE:
- ui.printTemplate->setCurrentIndex(0);
- break;
- case print_options::TWO_DIVE:
- ui.printTemplate->setCurrentIndex(1);
- break;
- case print_options::CUSTOM:
- ui.printTemplate->setCurrentIndex(2);
- break;
+
+ // insert existing templates in the UI and select the current template
+ qSort(grantlee_templates);
+ int current_index = 0, index = 0;
+ for (QList<QString>::iterator i = grantlee_templates.begin(); i != grantlee_templates.end(); ++i) {
+ if ((*i).compare(printOptions->p_template) == 0) {
+ current_index = index;
+ break;
+ }
+ index++;
+ }
+ ui.printTemplate->clear();
+ for (QList<QString>::iterator i = grantlee_templates.begin(); i != grantlee_templates.end(); ++i) {
+ ui.printTemplate->addItem((*i).split('.')[0], QVariant::fromValue(*i));
}
+ ui.printTemplate->setCurrentIndex(current_index);
// general print option checkboxes
if (printOptions->color_selected)
@@ -65,13 +71,6 @@ void PrintOptions::on_radioDiveListPrint_clicked(bool check)
}
}
-void PrintOptions::on_radioTablePrint_clicked(bool check)
-{
- if (check) {
- printOptions->type = print_options::TABLE;
- }
-}
-
void PrintOptions::on_radioStatisticsPrint_clicked(bool check)
{
if (check) {
@@ -93,17 +92,7 @@ void PrintOptions::printSelectedClicked(bool check)
void PrintOptions::on_printTemplate_currentIndexChanged(int index)
{
- switch(index){
- case 0:
- printOptions->p_template = print_options::ONE_DIVE;
- break;
- case 1:
- printOptions->p_template = print_options::TWO_DIVE;
- break;
- case 2:
- printOptions->p_template = print_options::CUSTOM;
- break;
- }
+ printOptions->p_template = ui.printTemplate->itemData(index).toString();
}
void PrintOptions::on_editButton_clicked()
@@ -112,3 +101,46 @@ void PrintOptions::on_editButton_clicked()
te.exec();
setup();
}
+
+void PrintOptions::on_importButton_clicked()
+{
+ QString filename = QFileDialog::getOpenFileName(this, tr("Import Template file"), "",
+ tr("HTML files (*.html)"));
+ if (filename.isEmpty())
+ return;
+ QFileInfo fileInfo(filename);
+ QFile::copy(filename, getSubsurfaceDataPath("printing_templates") + QDir::separator() + fileInfo.fileName());
+ printOptions->p_template = fileInfo.fileName();
+ find_all_templates();
+ setup();
+}
+
+void PrintOptions::on_exportButton_clicked()
+{
+ QString filename = QFileDialog::getSaveFileName(this, tr("Export Template files as"), "",
+ tr("HTML files (*.html)"));
+ if (filename.isEmpty())
+ return;
+ QFile::copy(getSubsurfaceDataPath("printing_templates") + QDir::separator() + getSelectedTemplate(), filename);
+}
+
+void PrintOptions::on_deleteButton_clicked()
+{
+ QString templateName = getSelectedTemplate();
+ QMessageBox msgBox;
+ msgBox.setText("This action cannot be undone!");
+ msgBox.setInformativeText("Delete '" + templateName + "' template?");
+ msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
+ msgBox.setDefaultButton(QMessageBox::Cancel);
+ if (msgBox.exec() == QMessageBox::Ok) {
+ QFile f(getSubsurfaceDataPath("printing_templates") + QDir::separator() + templateName);
+ f.remove();
+ find_all_templates();
+ setup();
+ }
+}
+
+QString PrintOptions::getSelectedTemplate()
+{
+ return ui.printTemplate->currentData().toString();
+}