aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Gehad elrobey <gehadelrobey@gmail.com>2015-05-30 15:32:15 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2015-06-04 10:08:09 -0700
commita820688aeb02d7a9fa1f7b0af1d0c96058da4e4f (patch)
tree81b60ef55c616c0ae677b49fb6ab9d5c0053180c
parent231f90bd268b0b4e930772d295368180d118339d (diff)
downloadsubsurface-a820688aeb02d7a9fa1f7b0af1d0c96058da4e4f.tar.gz
Printing: Add progress updating ability to print dialog
The progress bar shows the progress of both the rendering part and the templating part, unfortunately we can't check the progress of Grantlee templating engine so the progess bar doesn't have a constant pace it stops a little around 20%. Signed-off-by: Gehad elrobey <gehadelrobey@gmail.com> Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--printer.cpp11
-rw-r--r--printer.h7
-rw-r--r--qt-ui/printdialog.cpp1
-rw-r--r--templatelayout.cpp21
-rw-r--r--templatelayout.h4
5 files changed, 42 insertions, 2 deletions
diff --git a/printer.cpp b/printer.cpp
index 01c1f5546..5d340055e 100644
--- a/printer.cpp
+++ b/printer.cpp
@@ -17,6 +17,7 @@ Printer::Printer(QPrinter *printer)
printer->setPaperSize(QPrinter::A4);
printer->setPrintRange(QPrinter::AllPages);
printer->setResolution(300);
+ done = 0;
}
void Printer::render()
@@ -33,15 +34,25 @@ void Printer::render()
for (int i = 0; i < Pages; i++) {
webView->page()->mainFrame()->render(&painter, QWebFrame::ContentsLayer);
webView->page()->mainFrame()->scroll(0, A4_300DPI_HIGHT);
+ //rendering progress is 4/5 of total work
+ emit(progessUpdated((i * 80.0 / Pages) + done));
if (i < Pages - 1)
printer->newPage();
}
painter.end();
}
+//value: ranges from 0 : 100 and shows the progress of the templating engine
+void Printer::templateProgessUpdated(int value)
+{
+ done = value / 5; //template progess if 1/5 of total work
+ emit progessUpdated(done);
+}
+
void Printer::print()
{
TemplateLayout t;
+ connect(&t, SIGNAL(progressUpdated(int)), this, SLOT(templateProgessUpdated(int)));
webView = new QWebView();
webView->setHtml(t.generate());
render();
diff --git a/printer.h b/printer.h
index 3b574d126..1974d46c1 100644
--- a/printer.h
+++ b/printer.h
@@ -11,10 +11,17 @@ private:
QPrinter *printer;
QWebView *webView;
void render();
+ int done;
+
+private slots:
+ void templateProgessUpdated(int value);
public:
Printer(QPrinter *printer);
void print();
+
+signals:
+ void progessUpdated(int value);
};
#endif //PRINTER_H
diff --git a/qt-ui/printdialog.cpp b/qt-ui/printdialog.cpp
index ae119cc3d..909b0b598 100644
--- a/qt-ui/printdialog.cpp
+++ b/qt-ui/printdialog.cpp
@@ -96,6 +96,7 @@ void PrintDialog::printClicked(void)
if (printDialog.exec() == QDialog::Accepted) {
switch (printOptions.type) {
case print_options::DIVELIST:
+ connect(printer, SIGNAL(progessUpdated(int)), progressBar, SLOT(setValue(int)));
printer->print();
break;
case print_options::TABLE:
diff --git a/templatelayout.cpp b/templatelayout.cpp
index f2d72403b..a5d4b2329 100644
--- a/templatelayout.cpp
+++ b/templatelayout.cpp
@@ -10,10 +10,26 @@ TemplateLayout::TemplateLayout()
TemplateLayout::~TemplateLayout()
{
delete m_engine;
-};
+}
+
+int TemplateLayout::getTotalWork()
+{
+ int dives = 0, i;
+ struct dive *dive;
+ for_each_dive (i, dive) {
+ //TODO check for exporting selected dives only
+ if (!dive->selected)
+ continue;
+ dives++;
+ }
+ return dives;
+}
QString TemplateLayout::generate()
{
+ int progress = 0;
+ int totalWork = getTotalWork();
+
QString htmlContent;
m_engine = new Grantlee::Engine(this);
@@ -35,6 +51,8 @@ QString TemplateLayout::generate()
continue;
Dive d(dive);
diveList.append(QVariant::fromValue(d));
+ progress++;
+ emit progressUpdated(progress * 100.0 / totalWork);
}
mapping.insert("dives", diveList);
@@ -52,7 +70,6 @@ QString TemplateLayout::generate()
qDebug() << "Can't render template";
return htmlContent;
}
-
return htmlContent;
}
diff --git a/templatelayout.h b/templatelayout.h
index 763473796..db2fb30d3 100644
--- a/templatelayout.h
+++ b/templatelayout.h
@@ -13,6 +13,10 @@ public:
private:
Grantlee::Engine *m_engine;
+ int getTotalWork();
+
+signals:
+ void progressUpdated(int value);
};
class Dive {