Commit graph

35 commits

Author SHA1 Message Date
Gehad elrobey
69f2921ffa Printing: use the same code for both statistics and divelist print
- use the same generic code for both types of templates
- check for the printing type before generating the template
- remove unused printStatistics() method

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Gehad elrobey <gehadelrobey@gmail.com>
2015-08-22 18:36:19 +03:00
Gehad elrobey
c516421bc2 Printing: check the print type in the preview section
Preview output should be identical to the actual printing code, so
call the flow rendering method for all flow templates.

Also don't create new pages while rendering a one page preview, just
exit after the first page is full.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Gehad elrobey <gehadelrobey@gmail.com>
2015-08-22 18:33:36 +03:00
Gehad elrobey
13febc1eee Printing: fix uninialized border width
In flow rendering the border width is not initialized which causes
huge borders that blocks the page while previewing.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Gehad elrobey <gehadelrobey@gmail.com>
2015-08-22 18:33:26 +03:00
Gehad elrobey
afc697e797 Printing: refactor printing code
This section of the code is called only while rendering a flow layout
template, so move it to the flow layout function.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Gehad elrobey <gehadelrobey@gmail.com>
2015-08-22 18:32:53 +03:00
Gehad elrobey
67bfa9f968 Printing: use older Qt methods when calculating the ceil
Better portability for < Qt5.3.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Gehad elrobey <gehadelrobey@gmail.com>
2015-08-22 18:30:32 +03:00
Gehad elrobey
f3c5699714 Printing: remove silly white line at end of each page
QPrinter::pageRect() doesn't always return the correct value of the
printable area, which results in white horizontal lines of un-rendered
area at the bottom of each page, Use QPrinter::pageLayout() instead
which fixes the issue.

QPrinter::pageLayout() is added in QT 5.3, So use pageRect for previous
versions.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Gehad elrobey <gehadelrobey@gmail.com>
2015-08-15 15:05:26 +03:00
Gehad elrobey
5892fb5762 Printing: fill the QPainter background color before rendering
While rendering a dynamically sized view port, it may not fit the full
page size, But the background color should be the same for the whole
page, So fill the page background color with the template background
color before rendering.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Gehad elrobey <gehadelrobey@gmail.com>
2015-08-15 15:05:22 +03:00
Gehad elrobey
6a9c4cb9d7 Printing: don't break dives into successive pages
While rendering a template with "0" dives per page value, try to fit
as many dives per page but don't break a dive into 2 pages.

Use a dynamically sized view port to fit the rendered area only,
and don't render the full page.

All the Template elements that shouldn't be broken should have
the CSS class "dontbreak".

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Gehad elrobey <gehadelrobey@gmail.com>
2015-08-15 15:04:45 +03:00
Gehad elrobey
59eddc6259 Printing: export border to templates
As there is a problem with sizing the borders in QWebView, "vw" sizing is not
working as supposed with border-width, As a workaround we export border-width
dynamically, so that border-width is relatively the same for all page sizes.

The border-width is equal to the page width / 1000 which gives a nice range
for borders for A0 - A5 papers, Also prevent drawing zero pixel borders
and use 1 px borders as the minimum border.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Gehad elrobey <gehadelrobey@gmail.com>
2015-08-15 15:04:11 +03:00
Gehad elrobey
0ced68f15d Printing: fix scrolling bug by adding extra padding
This bug occurs in "table" and "flowlayout" templates, it takes place when
the size of the full web view to be rendered is not divisible by the size
of the view port (Page size), This issue is fixed by adding extra padding
to the bottom of the body so that the total body height is divisable
by the view port size.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Gehad elrobey <gehadelrobey@gmail.com>
2015-08-15 15:03:53 +03:00
Gehad elrobey
636c26feed Printing: hide scrollbar from QWebview to fix padding issue
The vertical scrollbar was causing a default margin at the right most of
the page which corrupted the page layout calculations. By hidding the
vertical scrollbar the issue is fixed.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Gehad elrobey <gehadelrobey@gmail.com>
2015-08-15 15:02:54 +03:00
Gehad elrobey
1a2f154cf4 Printing: add statistics print
Add statistics table print option.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Gehad elrobey <gehadelrobey@gmail.com>
2015-08-15 15:02:28 +03:00
Gehad elrobey
e2dcee55a3 Printing: use pageRect() to support old QT versions
While calculating the page size use QPrinter::pageRect instead of
QPrinter::pageLayout which is added in QT 5.3 and is not supported in
earlier versions.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Gehad elrobey <gehadelrobey@gmail.com>
2015-08-15 15:02:17 +03:00
Dirk Hohndel
4687f5d3b4 Printing: calculate a much more accurate font scale value
This simply uses the relative size of the profile. This can result in
truly tiny text in print, but at least it's consistent and logical.
We could add some minimum value there but I'm not sure that's the right
answer, either.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-07-29 12:24:18 -07:00
Dirk Hohndel
a4608f7c91 Printing: fix dive lookup for profile generation
The existing code (and templates) looked up dives by number and then used
that as index into the dive table. This worked exactly in one case: if all
dives were numbered consecutively starting with 1. While that is not an
entirely unreasonable case, it's of course not an acceptable assumption to
make.

This commit adds the necessary changes to instead look up dives by their
unique id. That's what it's there fore, after all.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-07-28 13:37:14 -07:00
Gehad elrobey
9fd5221666 Printing: get the number of pages from the full resolution
When we calculate the number of pages to print we need to check if the
template doesn't define the number of dives per one page, then render as
much dives as we can fit in one page. A dive can be broken into many
pages.

Signed-off-by: Gehad elrobey <gehadelrobey@gmail.com>
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2015-07-28 11:37:12 +03:00
Gehad elrobey
cea79b4e0a Printing: transfer profile to QImage if grayscale
Signed-off-by: Gehad elrobey <gehadelrobey@gmail.com>
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2015-07-20 15:28:57 +03:00
Gehad elrobey
d4382c7c4b Printing: add preview to TemplateEdit dialog
Show QPixmap in QLabel, Use Printer class to render the Preview on
the QPixmap.

Signed-off-by: Gehad elrobey <gehadelrobey@gmail.com>
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2015-07-20 15:28:03 +03:00
Gehad elrobey
3a69638366 Printing: check for different printing modes
Add PRINT/PREVIEW print modes, check for printing modes before
casting.

We must pass a QPaintDevice with type QPixmap for previewing and
with type QPrinter for actual printing.

Signed-off-by: Gehad elrobey <gehadelrobey@gmail.com>
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2015-07-20 15:27:56 +03:00
Gehad elrobey
142fd950c8 Printing: change QPrinter to parent class QPaintDevice
Use general class QPaintDevice to be used for printing and
previewing instances, printing uses a QPrinter object while
previewing uses a QPixmap instance. We use static_cast to use the
needed object.

Signed-off-by: Gehad elrobey <gehadelrobey@gmail.com>
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2015-07-20 15:27:41 +03:00
Gehad elrobey
4e1a5d954b Printing: refactoring printer class
- Render specific number of pages only.
- Move printer related code to print().

Signed-off-by: Gehad elrobey <gehadelrobey@gmail.com>
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2015-07-20 15:27:39 +03:00
Gehad elrobey
51e36fa158 Printing: handle memory leak in printer class
Don't initialize new webview each time we print.
Delete the QWebView object in the destructor.

Signed-off-by: Gehad elrobey <gehadelrobey@gmail.com>
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2015-07-20 15:27:36 +03:00
Gehad elrobey
815072d2ae Printing: retrieve number of dives per page from the template file
Add special data attribute 'data-numberofdives' in the template <body> with
the number of dives per page.
This is standard HTML5 specification so it won't corrupt the template file.
Any template that will be used for printing must contain this attribute to
assure correct output.

Signed-off-by: Gehad elrobey <gehadelrobey@gmail.com>
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2015-07-05 21:01:53 +03:00
Gehad elrobey
bc80fc8849 Printing: pass the template_options struct to TemplateLayout
The template_options struct needs to be passed to TemplateLayout
constructor.

Signed-off-by: Gehad elrobey <gehadelrobey@gmail.com>
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2015-07-05 21:00:40 +03:00
Gehad elrobey
fcde03e849 Printing: choose printing color mode 'color/greyscale'
We can have color printouts only if the printer supports color
prints, the user selected 'print in colors' from the print dialog and
the default printer settings (Operating system wise) is to print in
colors, Otherwise the prints will be in greyscale.

Signed-off-by: Gehad elrobey <gehadelrobey@gmail.com>
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2015-07-05 20:58:33 +03:00
Gehad elrobey
5981cf170f Printing: make dive profile scale dependant on the page size and DPI
Use setFontPrintScale() to change the font scale of the dive profile as a ratio of
the full resolution, font = (pageWidth * dpi) / fontvalue

Signed-off-by: Gehad elrobey <gehadelrobey@gmail.com>
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2015-07-05 20:58:29 +03:00
Gehad elrobey
1faa198020 Printing: print all dives if 'print selected' is unchecked
User can choose either to print all dives or print selected dives only.

Signed-off-by: Gehad elrobey <gehadelrobey@gmail.com>
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2015-07-05 20:58:24 +03:00
Dirk Hohndel
1ecc9b0cc0 Address uninitialized member warnings
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-06-22 10:57:51 -07:00
Gehad elrobey
554e64c43f Printing: add support for printing on any page size
Make page size and orientation customizable. The user can select
any page size and orientation and then the rendering resolution will
be calculated based on the selected preferences and the printer DPI.
The HTML templates must be responsive, also the font-size must be based
on the viewport width so that we don't lose quality.

Signed-off-by: Gehad elrobey <gehadelrobey@gmail.com>
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2015-06-19 21:41:58 +03:00
Gehad elrobey
6c54781e17 Printing: use selected print preferences while printing
Having a pointer to the printing_options struct, it should be
used to privide the selected options while printing.

Print options used ATM:
- number of dives per page
- template file name
- print in colors

Signed-off-by: Gehad elrobey <gehadelrobey@gmail.com>
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2015-06-19 21:41:58 +03:00
Gehad elrobey
60c5e3cf25 Printing: pass the print_options struct to TemplateLayout and Printer
As the print_options struct is needed by both TemplateLayout and Printer
class, it can be passed to their constructor.

Signed-off-by: Gehad elrobey <gehadelrobey@gmail.com>
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2015-06-19 21:41:57 +03:00
Gehad elrobey
cd30e11672 Printing: render the dive profile on top of QWebView
We render the dive profile over the QWebView to the QPainter. This helps
us not to save the SVG images to disk and then render them again to the
webview.

Signed-off-by: Gehad elrobey <gehadelrobey@gmail.com>
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2015-06-19 21:41:56 +03:00
Gehad elrobey
1040f0d4e5 Printing: fix rendering bug for odd number of dives
Odd number of dives needs extra space from the buttom, so that when we
scroll to the last page extra whitespace is shown under the last dive
frame, this is fixed by adding a default footer to the base template.

Signed-off-by: Gehad elrobey <gehadelrobey@gmail.com>
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2015-06-19 21:41:56 +03:00
Gehad elrobey
a820688aeb 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>
2015-06-04 10:08:09 -07:00
Gehad elrobey
6de5cfb7a4 Printing: 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 <gehadelrobey@gmail.com>
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-06-04 10:07:35 -07:00