[qet] [1920] Page setup parameters are now saved in the application configuration after the user has accepted the print preview and restored before the user has chosen a printer .

[ Thread Index | Date Index | More lists.tuxfamily.org/qet Archives ]


Revision: 1920
Author:   xavier
Date:     2012-08-05 02:23:13 +0200 (Sun, 05 Aug 2012)
Log Message:
-----------
Page setup parameters are now saved in the application configuration after the user has accepted the print preview and restored before the user has chosen a printer.

Modified Paths:
--------------
    trunk/sources/diagramprintdialog.cpp
    trunk/sources/diagramprintdialog.h

Modified: trunk/sources/diagramprintdialog.cpp
===================================================================
--- trunk/sources/diagramprintdialog.cpp	2012-07-31 18:56:08 UTC (rev 1919)
+++ trunk/sources/diagramprintdialog.cpp	2012-08-05 00:23:13 UTC (rev 1920)
@@ -20,6 +20,7 @@
 #include <math.h>
 #include "diagramschooser.h"
 #include "exportproperties.h"
+#include "qetapp.h"
 #include "qeticons.h"
 #include "qetmessagebox.h"
 
@@ -104,6 +105,7 @@
 	
 	// prise en compte du nom du document
 	if (!doc_name_.isEmpty()) printer_ -> setDocName(doc_name_);
+	printer_ -> setCreator(QString("QElectroTech %1").arg(QET::displayedVersion));
 	
 	// affichage d'un premier dialogue demandant a l'utilisateur le type
 	// d'impression qu'il souhaite effectuer
@@ -127,6 +129,7 @@
 		printer_ -> setOutputFormat(QPrinter::PostScriptFormat);
 		printer_ -> setOutputFileName(filepath_field_ -> text());
 	}
+	loadPageSetupForCurrentPrinter();
 	
 	// Apercu avant impression
 #if defined Q_WS_X11
@@ -145,6 +148,8 @@
 	dc -> setSelectedAllDiagrams();
 	if (preview_dialog.exec() == QDialog::Rejected) return;
 	
+	savePageSetupForCurrentPrinter();
+	
 	// effectue l'impression en elle-meme
 	print(
 		dc -> selectedDiagrams(),
@@ -505,3 +510,98 @@
 		diagram -> applyProperties(state_exportProperties);
 	}
 }
+
+/**
+	Save parameters set in the "page setup" dialog into the QElectroTech
+	configuration. Key/values pairs are associated to the printer for which
+	they have been set.
+*/
+void DiagramPrintDialog::savePageSetupForCurrentPrinter() {
+	QSettings &settings = QETApp::settings();
+	QString printer_section = settingsSectionName(printer_);
+	
+	while (!settings.group().isEmpty()) settings.endGroup();
+	settings.beginGroup("printers");
+	settings.beginGroup(printer_section);
+	
+	settings.setValue("orientation", printer_ -> orientation() == QPrinter::Portrait ? "portrait" : "landscape");
+	settings.setValue("papersize", int(printer_ -> paperSize()));
+	if (printer_ -> paperSize() == QPrinter::Custom) {
+		QSizeF size = printer_ -> paperSize(QPrinter::Millimeter);
+		settings.setValue("customwidthmm", size.width());
+		settings.setValue("customheightmm", size.height());
+	} else {
+		settings.remove("customwidthmm");
+		settings.remove("customheightmm");
+	}
+	qreal left, top, right, bottom;
+	printer_ -> getPageMargins(&left, &top, &right, &bottom, QPrinter::Millimeter);
+	settings.setValue("marginleft", left);
+	settings.setValue("margintop", top);
+	settings.setValue("marginright", right);
+	settings.setValue("marginbottom", bottom);
+	settings.setValue("fullpage", printer_ -> fullPage() ? "true" : "false");
+	settings.endGroup();
+	settings.endGroup();
+	settings.sync();
+}
+
+
+/**
+	Load parameters previously set in the "page setup" dialog for the current
+	printer, if any.
+*/
+void DiagramPrintDialog::loadPageSetupForCurrentPrinter() {
+	QSettings &settings = QETApp::settings();
+	QString printer_section = settingsSectionName(printer_);
+	
+	while (!settings.group().isEmpty()) settings.endGroup();
+	settings.beginGroup("printers");
+	if (!settings.childGroups().contains(printer_section)) return;
+	
+	settings.beginGroup(printer_section);
+	if (settings.contains("orientation")) {
+		QString value = settings.value("orientation", "landscape").toString();
+		printer_ -> setOrientation(value == "landscape" ? QPrinter::Landscape : QPrinter::Portrait);
+	}
+	if (settings.contains("papersize")) {
+		int value = settings.value("papersize", QPrinter::A4).toInt();
+		if (value == QPrinter::Custom) {
+			bool w_ok, h_ok;
+			int w = settings.value("customwidthmm", -1).toInt(&w_ok);
+			int h = settings.value("customheightmm", -1).toInt(&h_ok);
+			if (w_ok && h_ok && w != -1 && h != -1) {
+				printer_ -> setPaperSize(QSizeF(w, h), QPrinter::Millimeter);
+			}
+		} else if (value < QPrinter::Custom) {
+			printer_ -> setPaperSize(static_cast<QPrinter::PaperSize>(value));
+		}
+	}
+	
+	qreal margins[4];
+	printer_ -> getPageMargins(&margins[0], &margins[1], &margins[2], &margins[3], QPrinter::Millimeter);
+	QStringList margins_names(QStringList() << "left" << "top" << "right" << "bottom");
+	for (int i = 0 ; i < 4 ; ++ i) {
+		bool conv_ok;
+		qreal value = settings.value("margin" + margins_names.at(i), -1.0).toReal(&conv_ok);
+		if (conv_ok && value != -1.0) margins[i] = value;
+	}
+	printer_ -> setPageMargins(margins[0], margins[1], margins[2], margins[3], QPrinter::Millimeter);
+	printer_ -> setFullPage(settings.setValue("fullpage", "false") == "true");
+}
+
+/**
+	@return a section name for use with QSettings in order to store parameters
+	related to \a printer.
+*/
+QString DiagramPrintDialog::settingsSectionName(const QPrinter *printer) {
+	QPrinter::OutputFormat printer_format = printer -> outputFormat();
+	if (printer_format == QPrinter::NativeFormat) {
+		return(printer -> printerName().replace(" ", "_"));
+	} else if (printer_format == QPrinter::PdfFormat) {
+		return("QET_PDF_Printing");
+	} else if (printer_format == QPrinter::PostScriptFormat) {
+		return("QET_PS_Printing");
+	}
+	return(QString());
+}

Modified: trunk/sources/diagramprintdialog.h
===================================================================
--- trunk/sources/diagramprintdialog.h	2012-07-31 18:56:08 UTC (rev 1919)
+++ trunk/sources/diagramprintdialog.h	2012-08-05 00:23:13 UTC (rev 1920)
@@ -51,6 +51,9 @@
 	void buildPrintTypeDialog();
 	void buildDialog();
 	void saveReloadDiagramParameters(Diagram *, const ExportProperties, bool);
+	void savePageSetupForCurrentPrinter();
+	void loadPageSetupForCurrentPrinter();
+	QString settingsSectionName(const QPrinter *);
 	
 	private slots:
 	void print(const QList<Diagram *> &, bool, const ExportProperties);


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/