Re: Prototype for customizable printing support.

2015-04-27 Thread Lubomir I. Ivanov
On 21 April 2015 at 21:48, Gehad gehadelro...@gmail.com wrote:

 Lubomir,

 I have attached a new series of cleaner patches, and I have considered
 your remarks.


hey Gehad.
thanks, i will review the patches when i get some free time.

lubomir
--
___
subsurface mailing list
subsurface@subsurface-divelog.org
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface


Re: Prototype for customizable printing support.

2015-04-21 Thread Gehad
On 04/19/2015 10:43 PM, Lubomir I. Ivanov wrote:
 On 16 April 2015 at 01:14, Gehad Elrobey gehadelro...@gmail.com wrote:
 Hello all,

 As we are approaching gsoc community bonding period so I thought that a
 small prototype may be the best way to discuss my thoughts with the
 community.
 I sent a group of patches with a very small but full working prototype.

 - I added Grantlee library to subsurface code base (thanks for the cmake
 build environment it made my life much easier as I don't know qmake at all)
 - I create a simple Grantlee template that prints two dives per page.
 - the TemplateLayout class iterates the selected dives and interface with
 Grantlee backend.
 - QWebview and QPainter are used to render the html file living in a
 QTemporaryFile object.
 - finally I added the print using templates option in the print dialog.

 Note: I tested this on Linux only, so there may be problems on other
 platforms.
 also many exceptions still need to be handled this is only a fast prototype
 for discussion.

 So you may test this and tell me what do you think?
 
 
 hello Gehad,
 
 here are some generic comments on the patches (+ some more important
 structural ones!).
 i won't be able to provide more until i'm able to build; for some
 reason that UIC error still pops out (the one i explained in the the
 previous email).
 

Lubomir,

I have attached a new series of cleaner patches, and I have considered
your remarks.

 
 0001
 
 it won't be a bad idea to use the same/similar coding style across all
 formats, being HTML, XML, CSS, JS.
 this includes whitespace indentation of realtabs, spaces after : in
 class properties, etc.
 

Fixed in the attached patches.

 
 0002
 this patch should be split into more...
 
 diff --git a/printer.cpp b/printer.cpp
 
 for the Printer class, have you considered our plans to use the same
 backend for the facebook share?
 

I plan to add a new constructor to the Printer class with other paint
devices, also different options can be set for each rendering device.

 +#define A4_300DPI_WIDTH 2480
 +#define A4_300DPI_HIGHT 3508
 
 i don't think we need to hardcode A4 or any other page sizes in the
 render related class files. the class files should be able to render
 to any size.
 what the printer setup (user setup) returns is of importance and what
 we are interested in.
 

I am going to add TemplateEdit class that will handle the user setup and
extra printing settings which I didn't implement yet, so these values
exist in this prototype only.

 +QWebView *webView;
 
 global variables are not really desired, that should be a member of some 
 class.
 
 + int Pages = ceil( (float)
 webView-page()-mainFrame()-contentsSize().rheight() /
 A4_300DPI_HIGHT);
 + for (int i =0; i  Pages;i++) {
 
 coding style in the for() loop.
 
 +void Printer::print()
 +{
 + QUrl qurl(file:///tmp/dives.html);
 
 there is no such path on Windows. we should avoid temporary files and
 load the HTML from memory.
 
 diff --git a/printer.h b/printer.h
 
 +public:
 + Printer() {
 +
 + }
 
 we should not have definitions in the header even if the constructor
 is empty. this is code for the .cpp file.
 
 +private:
 + void putFrame(QRect box, QRect viewPort, QPainter *painter);
 +private
 +slots:
 + void render(bool ok);
 
 coding style!  accessors groups should be separated by new lines,
 ideally. the extra private before slots: is redundant.
 
 diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.c
 ...
 + Printer *p = new Printer();
 + p-print();
   PrintDialog dlg(this);
 
 i don't like the fact that MainWindow is aware of the existence of the
 Printer class. it should only know of PrintDialog, where an instance
 of Printer should be maintained (if that is the structure we keep on
 using. please see bellow).
 

Fixed in the attached patches

 
 0004
 
 diff --git a/printer.cpp b/printer.cpp
 
 - QPrinter printer;
 - printer.setOutputFormat(QPrinter::PdfFormat);
 - printer.setOutputFileName(/home/dive.pdf);
 - printer.setFullPage(true);
 - printer.setOrientation(QPrinter::Portrait);
 - printer.setPaperSize(QPrinter::A4);
 - printer.setPrintRange(QPrinter::AllPages);
 - printer.setResolution(300);
 -
 
 using an existing instance should have been the case in the first
 place. this patch removes code which was previously added in the
 series. it would be best to rebase the series.
 
 in the train of though for using existing render targets (e.g.
 QPrinter) i'm sure we can use QPaintDevice pointers as the rendering
 class should not care if said target is a QPrinter or a QPixmap (for
 the facebook) share. my point here is that the Printer class (or
 DivePrinter, or PrintLayout) should be a class which renders dives on
 surface / render target and only cares about it's dimensions. ideally,
 Printer should not be aware if the render target is a QPrinter.

as I mentioned above I think social network sharing and prints will be
handled slightly different 

Re: Prototype for customizable printing support.

2015-04-19 Thread Lubomir I. Ivanov
On 16 April 2015 at 01:14, Gehad Elrobey gehadelro...@gmail.com wrote:
 Hello all,

 As we are approaching gsoc community bonding period so I thought that a
 small prototype may be the best way to discuss my thoughts with the
 community.
 I sent a group of patches with a very small but full working prototype.

 - I added Grantlee library to subsurface code base (thanks for the cmake
 build environment it made my life much easier as I don't know qmake at all)
 - I create a simple Grantlee template that prints two dives per page.
 - the TemplateLayout class iterates the selected dives and interface with
 Grantlee backend.
 - QWebview and QPainter are used to render the html file living in a
 QTemporaryFile object.
 - finally I added the print using templates option in the print dialog.

 Note: I tested this on Linux only, so there may be problems on other
 platforms.
 also many exceptions still need to be handled this is only a fast prototype
 for discussion.

 So you may test this and tell me what do you think?


hello Gehad,

here are some generic comments on the patches (+ some more important
structural ones!).
i won't be able to provide more until i'm able to build; for some
reason that UIC error still pops out (the one i explained in the the
previous email).


0001

it won't be a bad idea to use the same/similar coding style across all
formats, being HTML, XML, CSS, JS.
this includes whitespace indentation of realtabs, spaces after : in
class properties, etc.


0002
this patch should be split into more...

diff --git a/printer.cpp b/printer.cpp

for the Printer class, have you considered our plans to use the same
backend for the facebook share?

+#define A4_300DPI_WIDTH 2480
+#define A4_300DPI_HIGHT 3508

i don't think we need to hardcode A4 or any other page sizes in the
render related class files. the class files should be able to render
to any size.
what the printer setup (user setup) returns is of importance and what
we are interested in.

+QWebView *webView;

global variables are not really desired, that should be a member of some class.

+ int Pages = ceil( (float)
webView-page()-mainFrame()-contentsSize().rheight() /
A4_300DPI_HIGHT);
+ for (int i =0; i  Pages;i++) {

coding style in the for() loop.

+void Printer::print()
+{
+ QUrl qurl(file:///tmp/dives.html);

there is no such path on Windows. we should avoid temporary files and
load the HTML from memory.

diff --git a/printer.h b/printer.h

+public:
+ Printer() {
+
+ }

we should not have definitions in the header even if the constructor
is empty. this is code for the .cpp file.

+private:
+ void putFrame(QRect box, QRect viewPort, QPainter *painter);
+private
+slots:
+ void render(bool ok);

coding style!  accessors groups should be separated by new lines,
ideally. the extra private before slots: is redundant.

diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.c
...
+ Printer *p = new Printer();
+ p-print();
  PrintDialog dlg(this);

i don't like the fact that MainWindow is aware of the existence of the
Printer class. it should only know of PrintDialog, where an instance
of Printer should be maintained (if that is the structure we keep on
using. please see bellow).


0003

diff --git a/display.h b/display.h
...
- ONEPERPAGE
+ ONEPERPAGE,
+ TEMPLATEBASED

not sure if this is the naming way to go. since all current layouts
will become template based, the one where the user has better control
of what is printed should be called either CUSTOM or USERDEFINED.

diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp

- Printer *p = new Printer();
- p-print();
  PrintDialog dlg(this);

amends code added in the previous patch...basically, it should not be
added in the previous patch in the first place.
git rebase -i HEAD~N is quite handy.

diff --git a/qt-ui/printlayout.cpp b/qt-ui/printlayout.cpp
...

we need to remove the old printlayout code completely, eventually. i
suggest the following important aspect here...
keep the old printlayout and printdialog, add a new Subsurface macro
e.g. NEW_PRINTING and use it where needed (like we do with NO_MARBLE).

this way if Subsurface insert_new_version_here comes out we can
toggle OFF the macro and release the build without the WIP, new
printing stack.
what i mean by remove the old printlayout code completely is that we
can keep the class but it should contain only the Grantlee powered
code. there is a bit of decision making here to decide what class will
handle the rendering e.g. Printer vs PrintLayout vs DivePrinter
etc...i guess Printer will suffice.


0004

diff --git a/printer.cpp b/printer.cpp

- QPrinter printer;
- printer.setOutputFormat(QPrinter::PdfFormat);
- printer.setOutputFileName(/home/dive.pdf);
- printer.setFullPage(true);
- printer.setOrientation(QPrinter::Portrait);
- printer.setPaperSize(QPrinter::A4);
- printer.setPrintRange(QPrinter::AllPages);
- printer.setResolution(300);
-

using an existing 

Re: Prototype for customizable printing support.

2015-04-16 Thread Lubomir I. Ivanov
On 16 April 2015 at 01:33, Lubomir I. Ivanov neolit...@gmail.com wrote:
 On 16 April 2015 at 01:14, Gehad Elrobey gehadelro...@gmail.com wrote:
 Hello all,

 As we are approaching gsoc community bonding period so I thought that a
 small prototype may be the best way to discuss my thoughts with the
 community.
 I sent a group of patches with a very small but full working prototype.

 - I added Grantlee library to subsurface code base (thanks for the cmake
 build environment it made my life much easier as I don't know qmake at all)
 - I create a simple Grantlee template that prints two dives per page.
 - the TemplateLayout class iterates the selected dives and interface with
 Grantlee backend.
 - QWebview and QPainter are used to render the html file living in a
 QTemporaryFile object.
 - finally I added the print using templates option in the print dialog.

 Note: I tested this on Linux only, so there may be problems on other
 platforms.
 also many exceptions still need to be handled this is only a fast prototype
 for discussion.

 So you may test this and tell me what do you think?



i've reached an error when trying the patches:

[ 22%] Building CXX object CMakeFiles/subsurface_corelib.dir/printer.cpp.obj
In file included from C:\dev\subsurface\templatelayout.h:8:0,
 from C:\dev\subsurface\printer.cpp:2:
C:/dev/subsurface/qt-ui/mainwindow.h:15:27: fatal error: ui_mainwindow.h: No suc
h file or directory
 #include ui_mainwindow.h
   ^

the obvious reason for that is that UIC has not generated the said file yet.
no idea why it happens in this particular case, as i'm able to build
the current master with cmake.

i have comments on the the patches themself, but will leave that for
the weekend.
my advice would be to take your time with the project as some mentors
(including me) are quite busy.
i think we should try to take advantage of the full timeline as much
as possible.

lubomir
--
___
subsurface mailing list
subsurface@subsurface-divelog.org
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface


Re: Prototype for customizable printing support.

2015-04-15 Thread Lubomir I. Ivanov
On 16 April 2015 at 01:14, Gehad Elrobey gehadelro...@gmail.com wrote:
 Hello all,

 As we are approaching gsoc community bonding period so I thought that a
 small prototype may be the best way to discuss my thoughts with the
 community.
 I sent a group of patches with a very small but full working prototype.

 - I added Grantlee library to subsurface code base (thanks for the cmake
 build environment it made my life much easier as I don't know qmake at all)
 - I create a simple Grantlee template that prints two dives per page.
 - the TemplateLayout class iterates the selected dives and interface with
 Grantlee backend.
 - QWebview and QPainter are used to render the html file living in a
 QTemporaryFile object.
 - finally I added the print using templates option in the print dialog.

 Note: I tested this on Linux only, so there may be problems on other
 platforms.
 also many exceptions still need to be handled this is only a fast prototype
 for discussion.

 So you may test this and tell me what do you think?


cool, will test that as soon as i get the cmake setup and grantlee working.

lubomir
--
___
subsurface mailing list
subsurface@subsurface-divelog.org
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface


Prototype for customizable printing support.

2015-04-15 Thread Gehad Elrobey
Hello all,

As we are approaching gsoc community bonding period so I thought that a
small prototype may be the best way to discuss my thoughts with the
community.
I sent a group of patches with a very small but full working prototype.

- I added Grantlee library to subsurface code base (thanks for the cmake
build environment it made my life much easier as I don't know qmake at all)
- I create a simple Grantlee template that prints two dives per page.
- the TemplateLayout class iterates the selected dives and interface with
Grantlee backend.
- QWebview and QPainter are used to render the html file living in a
QTemporaryFile object.
- finally I added the print using templates option in the print dialog.

Note: I tested this on Linux only, so there may be problems on other
platforms.
also many exceptions still need to be handled this is only a fast prototype
for discussion.

So you may test this and tell me what do you think?

-- 
regards,
Gehad
From d274d487dd500d50788517fd42787937c18398cd Mon Sep 17 00:00:00 2001
From: Gehad elrobey gehadelro...@gmail.com
Date: Wed, 15 Apr 2015 21:00:19 +0200
Subject: [PATCH 1/9] Create two dives per page grantlee template

Signed-off-by: Gehad elrobey gehadelro...@gmail.com
---
 printing_templates/base.html | 86 
 1 file changed, 86 insertions(+)
 create mode 100644 printing_templates/base.html

diff --git a/printing_templates/base.html b/printing_templates/base.html
new file mode 100644
index 000..b38cb19
--- /dev/null
+++ b/printing_templates/base.html
@@ -0,0 +1,86 @@
+html
+head
+style
+body {
+background-color:white;
+padding:0px;
+margin:0px;
+}
+
+h1 {
+font-size: 0.9cm;
+float:left;
+}
+
+.class1{
+	width:96%;
+	height:50%;
+	margin-left:2%;
+	margin-right:2%;
+	margin-top:0;
+	margin-bottom:0;
+	overflow:hidden;
+	border-width:0px;
+	page-break-inside: avoid;
+}
+
+.table_class{
+	overflow:hidden;
+	max-width:44%;
+	min-width:44%;
+	box-shadow: 5px 5px 5px #88;
+}
+
+.g{
+	background-color:#CfC7C5;
+	overflow:hidden;
+}
+
+/style
+/head
+
+body
+{% block main_rows %}
+  {% for dive in dives %}
+		div class=class1
+			div style=height:85%;border-style:solid;padding:0.5%;margin-top:1%;margin-bottom:1%;overflow: hidden;
+div style=width:52%;float:left;
+	table class=table_class border=1 style=margin:1.5%;float:left;
+		tr
+			td class=gh1 Dive No. /h1/tdtdh1 {{ dive.number }} /h1/td
+		/tr
+		tr
+			td class=gh1 Date /h1/tdtdh1 {{ dive.date }} /h1/td
+		/tr
+		tr
+			td class=gh1 Location /h1/tdtdh1{{ dive.location }}/h1/td
+		/tr
+		tr
+			td class=gh1 Max depth /h1/tdtdh1 {{ dive.depth }} /h1/td
+		/tr
+		tr
+			td class=gh1 Duration /h1/tdtdh1 {{ dive.duration }} /h1/td
+		/tr
+		tr
+			td class=gh1 Dive Master /h1/tdtdh1{{ dive.divemaster }}/h1/td
+		/tr
+	/table
+	table class=table_class border=1 style=margin:1.5%;width:47%;float:left;
+		tr
+			td class=gh1 Notes /h1/td
+		/tr
+		tr
+			tdh1-/h1/td
+		/tr
+	/table
+/div
+div class=diveprofile style=width:40%;height:50%;margin:1.5%;float:right;border-style:solid;padding:3mm;
+	h1Dive profile area/h1
+/div
+			/div
+		/div
+  {% endfor %}
+{% endblock %}
+/body
+
+/html
-- 
1.9.1

From 74b123112b68c929a949a2201ed10539451cce50 Mon Sep 17 00:00:00 2001
From: Gehad elrobey gehadelro...@gmail.com
Date: Sun, 12 Apr 2015 19:19:26 +0200
Subject: [PATCH 2/9] Add Printer class that holds the rendering logic.

Render Html pages into a QWebView then print it using QPainter. the
Printer::print() is called that prepare the HTML file to be rendered by
the QWebView.
Printer::render() will do the rendering task.

Signed-off-by: Gehad elrobey gehadelro...@gmail.com
---
 CMakeLists.txt   |  1 +
 printer.cpp  | 72 
 printer.h| 21 +++
 qt-ui/mainwindow.cpp |  3 +++
 subsurface.pro   |  6 +++--
 5 files changed, 101 insertions(+), 2 deletions(-)
 create mode 100644 printer.cpp
 create mode 100644 printer.h

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2f6d713..4d42987 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -195,6 +195,7 @@ SET(SUBSURFACE_CORE_LIB_SRCS
 	configuredivecomputer.cpp
 	configuredivecomputerthreads.cpp
 	divesitehelpers.cpp
+	printer.cpp
 	${PLATFORM_SRC}
 )
 
diff --git a/printer.cpp b/printer.cpp
new file mode 100644
index 000..d861057
--- /dev/null
+++ b/printer.cpp
@@ -0,0 +1,72 @@
+#include printer.h
+
+#include QPrintDialog
+#include QPrinter
+#include QtWebKitWidgets
+#include QUrl
+#include QPrintDialog
+#include QWebElement
+#include QWebElementCollection
+
+#define A4_300DPI_WIDTH 2480
+#define A4_300DPI_HIGHT 3508
+
+QWebView *webView;
+
+void Printer::putFrame(QRect box, QRect viewPort, QPainter *painter)
+{
+	if(!viewPort.contains(box))
+		return;
+
+	int x = box.x() - viewPort.x();
+	int y =