[PATCH] Print: provide means for profile layouting

Dirk Hohndel dirk at hohndel.org
Fri Sep 27 09:34:17 UTC 2013


My guess is this isn't related to your patch at all, but here's what
the print dialog looks like on my screen:



I am on a high dpi screen so I'm running Gnome3 with font size 120% or
something silly like that (whatever it is that
'accessibility->LargeText' gives you). We need to make sure we
correctly size the dialogs for situations like that....

/D

On Fri, 2013-09-27 at 19:06 +0300, Lubomir I. Ivanov wrote:

> From: "Lubomir I. Ivanov" <neolit123 at gmail.com>
> 
> printlayout.cpp(h):
> 
> This patch cleans some test code and adds the function
> printProfileDives() that accepts a number of dives
> per rows and columns. It can technically fit any number
> of dives on a page given the page size allows it. Both
> landscape and portrait layouts are supported.
> 
> It now replaces the old methods:
> printTwoDives()
> printSixDives()
> 
> Space is reserved for data tables that will be placed
> bellow profiles on a later stage.
> 
> Signed-off-by: Lubomir I. Ivanov <neolit123 at gmail.com>
> ---
> this version differs from the previous one as it uses the name:
> printProfileDives()
> ---
>  qt-ui/printlayout.cpp | 74 ++++++++++++++++++++++++++++++---------------------
>  qt-ui/printlayout.h   |  5 ++--
>  2 files changed, 46 insertions(+), 33 deletions(-)
> 
> diff --git a/qt-ui/printlayout.cpp b/qt-ui/printlayout.cpp
> index 7a4944e..3d09376 100644
> --- a/qt-ui/printlayout.cpp
> +++ b/qt-ui/printlayout.cpp
> @@ -26,6 +26,7 @@ PrintLayout::PrintLayout(PrintDialog *dialogPtr, QPrinter *printerPtr, struct op
>  {
>  	dialog = dialogPtr;
>  	printer = printerPtr;
> +	painter = NULL;
>  	printOptions = optionsPtr;
>  
>  	// table print settings
> @@ -52,10 +53,10 @@ void PrintLayout::print()
>  	setup();
>  	switch (printOptions->type) {
>  	case options::PRETTY:
> -		printSixDives();
> +		printProfileDives(3, 2);
>  		break;
>  	case options::TWOPERPAGE:
> -		printTwoDives();
> +		printProfileDives(2, 1);
>  		break;
>  	case options::TABLE:
>  		printTable();
> @@ -80,52 +81,65 @@ void PrintLayout::setup()
>  	scaledPageH = pageRect.height() / scaleY;
>  }
>  
> -// experimental
> -void PrintLayout::printSixDives() const
> +void PrintLayout::printProfileDives(int divesPerRow, int divesPerColumn)
>  {
> +	// setup a painter
> +	painter = new QPainter();
> +	painter->begin(printer);
> +	painter->setRenderHint(QPainter::Antialiasing);
> +	painter->setRenderHint(QPainter::SmoothPixmapTransform);
> +	painter->scale(scaleX, scaleY);
> +
> +	// setup the profile widget
>  	ProfileGraphicsView *profile = mainWindow()->graphics();
> -	QPainter painter;
> -	painter.begin(printer);
> -	painter.setRenderHint(QPainter::Antialiasing);
> -	// painter.setRenderHint(QPainter::HighQualityAntialiasing);
> -	painter.setRenderHint(QPainter::SmoothPixmapTransform);
> -	painter.scale(scaleX, scaleY);
> -
>  	profile->clear();
>  	profile->setPrintMode(true, !printOptions->color_selected);
>  	QSize originalSize = profile->size();
> -	profile->resize(scaledPageW, scaledPageH);
> -
> -	int i;
> +	// swap rows/col for landscape
> +	if (printer->orientation() == QPrinter::Landscape) {
> +		int swap = divesPerColumn;
> +		divesPerColumn = divesPerRow;
> +		divesPerRow = swap;
> +	}
> +	// estimate profile and table height and resize the widget
> +	const int scaledW = scaledPageW / divesPerColumn;
> +	const int scaledH = scaledPageH / divesPerRow;
> +	/* make the table 1/3 of the reserved height. potentially this could depend
> +	 * on orientation and other parameters as well. */
> +	const int tableHeight = scaledH / 3;
> +	profile->resize(scaledW, scaledH - tableHeight);
> +
> +	// plot the dives at specific rows and columns
> +	int i, row = 0, col = 0;
>  	struct dive *dive;
> -	bool firstPage = true;
>  	for_each_dive(i, dive) {
>  		if (!dive->selected && printOptions->print_selected)
>  			continue;
> -		// don't create a new page if still on first page
> -		if (!firstPage)
> -			printer->newPage();
> -		else
> -			firstPage = false;
> +		if (col == divesPerColumn) {
> +			col = 0;
> +			row++;
> +			if (row == divesPerRow) {
> +				row = 0;
> +				printer->newPage();
> +			}
> +		}
>  		profile->plot(dive, true);
>  		QPixmap pm = QPixmap::grabWidget(profile);
> -		QTransform transform;
> -		transform.rotate(270);
> -		pm = QPixmap(pm.transformed(transform));
> -		painter.drawPixmap(0, 0, pm);
> +		painter->drawPixmap(scaledW * col, scaledH * row, pm);
> +		/* TODO: table should be drawn here, preferably by another function */
> +		col++;
>  	}
> -	painter.end();
> +
> +	// cleanup
> +	painter->end();
> +	delete painter;
> +	painter = NULL;
>  	profile->setPrintMode(false);
>  	profile->resize(originalSize);
>  	profile->clear();
>  	profile->plot(current_dive, true);
>  }
>  
> -void PrintLayout::printTwoDives() const
> -{
> -	// nop
> -}
> -
>  void PrintLayout::printTable()
>  {
>  	// create and setup a table
> diff --git a/qt-ui/printlayout.h b/qt-ui/printlayout.h
> index ac363ab..79c1d65 100644
> --- a/qt-ui/printlayout.h
> +++ b/qt-ui/printlayout.h
> @@ -19,9 +19,9 @@ public:
>  private:
>  	PrintDialog *dialog;
>  	QPrinter *printer;
> +	QPainter *painter;
>  	struct options *printOptions;
>  
> -	QPainter *painter;
>  	int screenDpiX, screenDpiY, printerDpi, scaledPageW, scaledPageH;
>  	qreal scaleX, scaleY;
>  	QRect pageRect;
> @@ -31,8 +31,7 @@ private:
>  	unsigned int tablePrintHeadingBackground;
>  
>  	void setup();
> -	void printSixDives() const;
> -	void printTwoDives() const;
> +	void printProfileDives(int divesPerRow, int divesPerColumn);
>  	void printTable();
>  	void addTablePrintDataRow(TablePrintModel *model, int row, struct dive *dive) const;
>  	void addTablePrintHeadingRow(TablePrintModel *model, int row) const;


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.hohndel.org/pipermail/subsurface/attachments/20130927/7cff45fb/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: unknown-FPZH4W
Type: image/png
Size: 53571 bytes
Desc: not available
URL: <http://lists.hohndel.org/pipermail/subsurface/attachments/20130927/7cff45fb/attachment-0001.png>


More information about the subsurface mailing list