r23565 by jghali - Refactor CUPS options dialog and print dialog

scribus-commit scribus-commit at lists.scribus.net
Wed Apr 8 19:00:47 UTC 2020


Author: jghali
Date: Wed Apr  8 19:00:47 2020
New Revision: 23565

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=23565
Log:
Refactor CUPS options dialog and print dialog

Modified:
    trunk/Scribus/scribus/ui/cupsoptions.cpp
    trunk/Scribus/scribus/ui/cupsoptions.h
    trunk/Scribus/scribus/ui/printdialog.cpp
    trunk/Scribus/scribus/ui/printdialog.h

Modified: trunk/Scribus/scribus/ui/cupsoptions.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23565&path=/trunk/Scribus/scribus/ui/cupsoptions.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/cupsoptions.cpp	(original)
+++ trunk/Scribus/scribus/ui/cupsoptions.cpp	Wed Apr  8 19:00:47 2020
@@ -50,12 +50,13 @@
 
 CupsOptions::CupsOptions(QWidget* parent, const QString& device) : QDialog( parent )
 {
-	FlagsOpt.clear();
 	setModal(true);
 	setWindowTitle( tr( "Printer Options" ) );
 	setWindowIcon(IconManager::instance().loadIcon("AppIcon.png"));
+	setSizeGripEnabled(true);
+
 	prefs = PrefsManager::instance().prefsFile->getContext("cups_options");
-	setSizeGripEnabled(true);
+
 	CupsOptionsLayout = new QVBoxLayout( this );
 	CupsOptionsLayout->setSpacing( 5 );
 	CupsOptionsLayout->setMargin( 10 );
@@ -87,8 +88,8 @@
 		cupsMarkOptions(ppd, dest->num_options, dest->options);
 		QStringList opts;
 		QString Marked;
-		KeyToText.clear();
-		KeyToDefault.clear();
+		m_keyToDataMap.clear();
+		m_keyToDefault.clear();
 		for (i = ppd->num_groups, group = ppd->groups; i > 0; i --, ++group)
 		{
 			int ix;
@@ -98,7 +99,7 @@
 			{
 				int j;
 				Marked = "";
-				struct OpData Daten;
+				struct OptionData optionData;
 				opts.clear();
 				for (j = option->num_choices, choice = option->choices; j > 0; j --, ++choice)
 				{
@@ -108,37 +109,37 @@
 				}
 				if (!Marked.isEmpty())
 				{
-					Table->setRowCount(Table->rowCount()+1);
-					Table->setItem(Table->rowCount()-1, 0, new QTableWidgetItem(QString(option->text)));
+					Table->setRowCount(Table->rowCount() + 1);
+					Table->setItem(Table->rowCount() - 1, 0, new QTableWidgetItem(QString(option->text)));
 					QComboBox *item = new QComboBox( this );
 					item->setEditable(false);
-					FlagsOpt.append(item);
-					Daten.Cnum = static_cast<int>(FlagsOpt.count()-1);
-					Daten.KeyW = QString(option->keyword);
-					KeyToText[QString(option->text)] = Daten;
+					m_optionCombos.append(item);
+					optionData.comboIndex = m_optionCombos.count() - 1;
+					optionData.keyword = QString(option->keyword);
+					m_keyToDataMap[QString(option->text)] = optionData;
 					item->addItems(opts);
 					int lastSelected = prefs->getInt(QString(option->text), 0);
 					if (lastSelected >= static_cast<int>(opts.count()))
 						lastSelected = 0;
 					item->setCurrentIndex(lastSelected);
-					KeyToDefault[QString(option->text)] = Marked;
-					Table->setCellWidget(Table->rowCount()-1, 1, item);
+					m_keyToDefault[QString(option->text)] = Marked;
+					Table->setCellWidget(Table->rowCount() - 1, 1, item);
 				}
 			}
 		}
 		ppdClose(ppd);
 		cupsFreeDests(num_dests, dests);
 	}
-	struct OpData Daten;
-
-	Table->setRowCount(Table->rowCount()+1);
-	Table->setItem(Table->rowCount()-1, 0, new QTableWidgetItem(QString( tr("Page Set"))));
+	struct OptionData optionData;
+
+	Table->setRowCount(Table->rowCount() + 1);
+	Table->setItem(Table->rowCount() - 1, 0, new QTableWidgetItem(QString( tr("Page Set"))));
 	QComboBox *item4 = new QComboBox( this );
 	item4->setEditable(false);
-	FlagsOpt.append(item4);
-	Daten.Cnum = static_cast<int>(FlagsOpt.count()-1);
-	Daten.KeyW = "page-set";
-	KeyToText["Page Set"] = Daten;
+	m_optionCombos.append(item4);
+	optionData.comboIndex = m_optionCombos.count() - 1;
+	optionData.keyword = "page-set";
+	m_keyToDataMap["Page Set"] = optionData;
 	item4->addItem( tr("All Pages"));
 	item4->addItem( tr("Even Pages only"));
 	item4->addItem( tr("Odd Pages only"));
@@ -146,16 +147,17 @@
 	if (lastSelected >= 3)
 		lastSelected = 0;
 	item4->setCurrentIndex(lastSelected);
-	KeyToDefault["Page Set"] = tr("All Pages");
-	Table->setCellWidget(Table->rowCount()-1, 1, item4);
-	Table->setRowCount(Table->rowCount()+1);
-	Table->setItem(Table->rowCount()-1, 0, new QTableWidgetItem(QString( tr("Mirror"))));
+	m_keyToDefault["Page Set"] = tr("All Pages");
+	Table->setCellWidget(Table->rowCount() - 1, 1, item4);
+	
+	Table->setRowCount(Table->rowCount() + 1);
+	Table->setItem(Table->rowCount() - 1, 0, new QTableWidgetItem(QString( tr("Mirror"))));
 	QComboBox *item2 = new QComboBox( this );
 	item2->setEditable(false);
-	FlagsOpt.append(item2);
-	Daten.Cnum = static_cast<int>(FlagsOpt.count()-1);
-	Daten.KeyW = "mirror";
-	KeyToText["Mirror"] = Daten;
+	m_optionCombos.append(item2);
+	optionData.comboIndex = m_optionCombos.count() - 1;
+	optionData.keyword = "mirror";
+	m_keyToDataMap["Mirror"] = optionData;
 	item2->addItem(CommonStrings::trNo);
 	item2->addItem(CommonStrings::trYes);
 	item2->setCurrentIndex(0);
@@ -163,16 +165,17 @@
 	if (lastSelected >= 2)
 		lastSelected = 0;
 	item2->setCurrentIndex(lastSelected);
-	KeyToDefault["Mirror"] = CommonStrings::trNo;
-	Table->setCellWidget(Table->rowCount()-1, 1, item2);
-	Table->setRowCount(Table->rowCount()+1);
-	Table->setItem(Table->rowCount()-1, 0, new QTableWidgetItem(QString( tr("Orientation"))));
+	m_keyToDefault["Mirror"] = CommonStrings::trNo;
+	Table->setCellWidget(Table->rowCount() - 1, 1, item2);
+	
+	Table->setRowCount(Table->rowCount() + 1);
+	Table->setItem(Table->rowCount() - 1, 0, new QTableWidgetItem(QString( tr("Orientation"))));
 	QComboBox *item5 = new QComboBox( this );
 	item5->setEditable(false);
-	FlagsOpt.append(item5);
-	Daten.Cnum = static_cast<int>(FlagsOpt.count()-1);
-	Daten.KeyW = "orientation";
-	KeyToText["Orientation"] = Daten;
+	m_optionCombos.append(item5);
+	optionData.comboIndex = m_optionCombos.count() - 1;
+	optionData.keyword = "orientation";
+	m_keyToDataMap["Orientation"] = optionData;
 	item5->addItem( tr("Portrait"));
 	item5->addItem( tr("Landscape"));
 	item5->setCurrentIndex(0);
@@ -180,28 +183,29 @@
 	if (lastSelected >= 2)
 		lastSelected = 0;
 	item5->setCurrentIndex(lastSelected);
-	KeyToDefault["Orientation"] = tr("Portrait");
-	Table->setCellWidget(Table->rowCount()-1, 1, item5);
-	Table->setRowCount(Table->rowCount()+1);
-	Table->setItem(Table->rowCount()-1, 0, new QTableWidgetItem(QString( tr("N-Up Printing"))));
+	m_keyToDefault["Orientation"] = tr("Portrait");
+	Table->setCellWidget(Table->rowCount() - 1, 1, item5);
+	
+	Table->setRowCount(Table->rowCount() + 1);
+	Table->setItem(Table->rowCount() - 1, 0, new QTableWidgetItem(QString( tr("N-Up Printing"))));
 	QComboBox *item3 = new QComboBox( this );
 	item3->setEditable(false);
-	FlagsOpt.append(item3);
-	Daten.Cnum = static_cast<int>(FlagsOpt.count()-1);
-	Daten.KeyW = "number-up";
-	KeyToText["N-Up Printing"] = Daten;
-	item3->addItem("1 "+ tr("Page per Sheet"));
-	item3->addItem("2 "+ tr("Pages per Sheet"));
-	item3->addItem("4 "+ tr("Pages per Sheet"));
-	item3->addItem("6 "+ tr("Pages per Sheet"));
-	item3->addItem("9 "+ tr("Pages per Sheet"));
+	m_optionCombos.append(item3);
+	optionData.comboIndex = m_optionCombos.count() - 1;
+	optionData.keyword = "number-up";
+	m_keyToDataMap["N-Up Printing"] = optionData;
+	item3->addItem("1 " + tr("Page per Sheet"));
+	item3->addItem("2 " + tr("Pages per Sheet"));
+	item3->addItem("4 " + tr("Pages per Sheet"));
+	item3->addItem("6 " + tr("Pages per Sheet"));
+	item3->addItem("9 " + tr("Pages per Sheet"));
 	item3->addItem("16 "+ tr("Pages per Sheet"));
 	lastSelected = prefs->getInt( tr("N-Up Printing"), 0);
 	if (lastSelected >= 6)
 		lastSelected = 0;
 	item3->setCurrentIndex(lastSelected);
-	KeyToDefault["N-Up Printing"] = "1 "+ tr("Page per Sheet");
-	Table->setCellWidget(Table->rowCount()-1, 1, item3);
+	m_keyToDefault["N-Up Printing"] = "1 "+ tr("Page per Sheet");
+	Table->setCellWidget(Table->rowCount() - 1, 1, item3);
 #endif
 	Table->resizeColumnsToContents();
 	CupsOptionsLayout->addWidget( Table );
@@ -239,3 +243,44 @@
 			prefs->set(Table->item(i, 0)->text(), combo->currentIndex());
 	}
 }
+
+QString CupsOptions::defaultOptionValue(const QString& optionKey) const
+{
+	QString defValue = m_keyToDefault.value(optionKey, QString());
+	return defValue;
+}
+
+bool CupsOptions::useDefaultValue(const QString& optionKey) const
+{
+	QString defValue = m_keyToDefault.value(optionKey, QString());
+	QString optValue = optionText(optionKey);
+	return (optValue == defValue);
+}
+
+int CupsOptions::optionIndex(const QString& optionKey) const
+{
+	if (!m_keyToDataMap.contains(optionKey))
+		return -1;
+	const OptionData& optionData = m_keyToDataMap[optionKey];
+
+	int comboIndex = optionData.comboIndex;
+	if (comboIndex < 0 || comboIndex >= m_optionCombos.count())
+		return -1;
+
+	QComboBox* optionCombo = m_optionCombos.at(comboIndex);
+	return optionCombo->currentIndex();
+}
+
+QString CupsOptions::optionText(const QString& optionKey) const
+{
+	if (!m_keyToDataMap.contains(optionKey))
+		return QString();
+	const OptionData& optionData = m_keyToDataMap[optionKey];
+
+	int comboIndex = optionData.comboIndex;
+	if (comboIndex < 0 || comboIndex >= m_optionCombos.count())
+		return QString();
+
+	QComboBox* optionCombo = m_optionCombos.at(comboIndex);
+	return optionCombo->currentText();
+}

Modified: trunk/Scribus/scribus/ui/cupsoptions.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23565&path=/trunk/Scribus/scribus/ui/cupsoptions.h
==============================================================================
--- trunk/Scribus/scribus/ui/cupsoptions.h	(original)
+++ trunk/Scribus/scribus/ui/cupsoptions.h	Wed Apr  8 19:00:47 2020
@@ -27,6 +27,9 @@
 #include <QDialog>
 #include <QMap>
 #include <QList>
+#include <QString>
+#include <QStringList>
+
 class QHBoxLayout;
 class QVBoxLayout;
 class QPushButton;
@@ -48,21 +51,34 @@
 public: 
 	CupsOptions(QWidget* parent, const QString& device);
 	~CupsOptions();
-	QPushButton* PushButton1;
-	QPushButton* PushButton2;
-	QTableWidget* Table;
-	struct OpData { 
-					int Cnum;
-					QString KeyW;
-				  };
-	QList<QComboBox*> FlagsOpt;
-	QMap<QString,OpData> KeyToText;
-	QMap<QString,QString> KeyToDefault;
+
+	struct OptionData
+	{ 
+		int comboIndex;
+		QString keyword;
+	};
+
+	QString defaultOptionValue(const QString& optionKey) const;
+	bool    useDefaultValue(const QString& optionKey) const;
+
+	const QMap<QString, OptionData>& options() const { return m_keyToDataMap; }
+	QStringList optionKeys() { return m_keyToDataMap.keys(); }
+
+	int     optionIndex(const QString& optionKey) const;
+	QString optionText(const QString& optionKey) const;
 
 protected:
-	QVBoxLayout* CupsOptionsLayout;
-	QHBoxLayout* Layout2;
+	QVBoxLayout*  CupsOptionsLayout;
+	QHBoxLayout*  Layout2;
+	QPushButton*  PushButton1;
+	QPushButton*  PushButton2;
+	QTableWidget* Table;
+
 	PrefsContext* prefs;
+	
+	QList<QComboBox*> m_optionCombos;
+	QMap<QString, OptionData> m_keyToDataMap;
+	QMap<QString, QString> m_keyToDefault;
 };
 
 #endif

Modified: trunk/Scribus/scribus/ui/printdialog.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23565&path=/trunk/Scribus/scribus/ui/printdialog.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/printdialog.cpp	(original)
+++ trunk/Scribus/scribus/ui/printdialog.cpp	Wed Apr  8 19:00:47 2020
@@ -41,36 +41,36 @@
 {
 	setupUi(this);
 	setModal(true);
-	cdia = nullptr;
+
 	m_doc = doc;
-	unit = doc->unitIndex();
-	unitRatio = unitGetRatioFromIndex(doc->unitIndex());
+	m_unit = doc->unitIndex();
+	m_unitRatio = unitGetRatioFromIndex(doc->unitIndex());
 	prefs = PrefsManager::instance().prefsFile->getContext("print_options");
-	DevMode = printOptions.devMode;
-	PrinterOpts = "";
+	m_devMode = printOptions.devMode;
+
 	setWindowIcon(IconManager::instance().loadIcon("AppIcon.png"));
 	pageNrButton->setIcon(IconManager::instance().loadIcon("ellipsis.png"));
 	printEngines->addItem( CommonStrings::trPostScript1 );
 	printEngines->addItem( CommonStrings::trPostScript2 );
 	printEngines->addItem( CommonStrings::trPostScript3 );
-	markLength->setNewUnit(unit);
-	markLength->setMinimum(1*unitRatio);
-	markLength->setMaximum(3000*unitRatio);
-	markOffset->setNewUnit(unit);
+	markLength->setNewUnit(m_unit);
+	markLength->setMinimum(1 * m_unitRatio);
+	markLength->setMaximum(3000 * m_unitRatio);
+	markOffset->setNewUnit(m_unit);
 	markOffset->setMinimum(0);
-	markOffset->setMaximum(3000*unitRatio);
-	BleedBottom->setNewUnit(unit);
+	markOffset->setMaximum(3000 * m_unitRatio);
+	BleedBottom->setNewUnit(m_unit);
 	BleedBottom->setMinimum(0);
-	BleedBottom->setMaximum(3000*unitRatio);
-	BleedLeft->setNewUnit(unit);
+	BleedBottom->setMaximum(3000 * m_unitRatio);
+	BleedLeft->setNewUnit(m_unit);
 	BleedLeft->setMinimum(0);
-	BleedLeft->setMaximum(3000*unitRatio);
-	BleedRight->setNewUnit(unit);
+	BleedLeft->setMaximum(3000 * m_unitRatio);
+	BleedRight->setNewUnit(m_unit);
 	BleedRight->setMinimum(0);
-	BleedRight->setMaximum(3000*unitRatio);
-	BleedTop->setNewUnit(unit);
+	BleedRight->setMaximum(3000 * m_unitRatio);
+	BleedTop->setNewUnit(m_unit);
 	BleedTop->setMinimum(0);
-	BleedTop->setMaximum(3000*unitRatio);
+	BleedTop->setMaximum(3000 * m_unitRatio);
 	previewButton->setEnabled(!previewDinUse);
 	// Fill printer list
 	QString printerName;
@@ -141,17 +141,17 @@
 #if defined(_WIN32)
 	if (!outputToFile())
 	{
-		DevMode = printOptions.devMode;
-		PrinterUtil::initDeviceSettings(PrintDest->currentText(), DevMode);
+		m_devMode = printOptions.devMode;
+		PrinterUtil::initDeviceSettings(PrintDest->currentText(), m_devMode);
 	}
 #endif
 
-	printEngineMap = PrinterUtil::getPrintEngineSupport(PrintDest->currentText(), outputToFile());
+	m_printEngineMap = PrinterUtil::getPrintEngineSupport(PrintDest->currentText(), outputToFile());
 	refreshPrintEngineBox();
 
-	bool ps1Supported = printEngineMap.contains(CommonStrings::trPostScript1);
-	bool ps2Supported = printEngineMap.contains(CommonStrings::trPostScript2);
-	bool ps3Supported = printEngineMap.contains(CommonStrings::trPostScript3);
+	bool ps1Supported = m_printEngineMap.contains(CommonStrings::trPostScript1);
+	bool ps2Supported = m_printEngineMap.contains(CommonStrings::trPostScript2);
+	bool ps3Supported = m_printEngineMap.contains(CommonStrings::trPostScript3);
 	bool psSupported  = (ps1Supported || ps2Supported || ps3Supported);
 	printEngines->setEnabled(psSupported || outputToFile());
 }
@@ -159,28 +159,27 @@
 PrintDialog::~PrintDialog()
 {
 #ifdef HAVE_CUPS
-	delete cdia;
+	delete m_cupsOptions;
 #endif
-	cdia = nullptr;
+	m_cupsOptions = nullptr;
 }
 
 void PrintDialog::SetOptions()
 {
 #ifdef HAVE_CUPS
-	PrinterOpts = "";
-	if (!cdia)
-		cdia = new CupsOptions(this, PrintDest->currentText());
-	if (!cdia->exec())
-	{
-		delete cdia; // if options was canceled delete dia 
-		cdia = nullptr;    // so that getoptions() in the okButtonClicked() will get
+	if (!m_cupsOptions)
+		m_cupsOptions = new CupsOptions(this, PrintDest->currentText());
+	if (!m_cupsOptions->exec())
+	{
+		delete m_cupsOptions; // if options was canceled delete dia 
+		m_cupsOptions = nullptr;    // so that getoptions() in the okButtonClicked() will get
 		             // the default values from the last successful run
 	}
 
 #elif defined(_WIN32)
 	bool done;
 	Qt::HANDLE handle = nullptr;
-	DEVMODEW* devMode = (DEVMODEW*) DevMode.data();
+	DEVMODEW* devMode = (DEVMODEW*) m_devMode.data();
 	// Retrieve the selected printer
 	QString printerS = PrintDest->currentText(); 
 	// Get a printer handle
@@ -188,7 +187,7 @@
 	if (!done)
 		return;
 	// Merge stored settings, prompt user and return user settings
-	DocumentPropertiesW((HWND) winId(), handle, (LPWSTR) printerS.utf16(), (DEVMODEW*) DevMode.data(), (DEVMODEW*) DevMode.data(), 
+	DocumentPropertiesW((HWND) winId(), handle, (LPWSTR) printerS.utf16(), (DEVMODEW*) m_devMode.data(), (DEVMODEW*) m_devMode.data(), 
 						DM_IN_BUFFER | DM_IN_PROMPT | DM_OUT_BUFFER);
 	// Free the printer handle
 	ClosePrinter(handle);
@@ -205,60 +204,67 @@
 #endif
 }
 
-void PrintDialog::getOptions()
+QString PrintDialog::getOptions()
 {
 #ifdef HAVE_CUPS
-	PrinterOpts = "";
-	if (!cdia)
-		cdia = new CupsOptions(this, PrintDest->currentText());
-	struct CupsOptions::OpData daten;
-	QMap<QString,CupsOptions::OpData>::Iterator it;
-	for (it = cdia->KeyToText.begin(); it != cdia->KeyToText.end(); ++it)
-	{
-		if (cdia->KeyToDefault[it.key()] == cdia->FlagsOpt.at(it.value().Cnum)->currentText())
+	QString printerOptions;
+	if (!m_cupsOptions)
+		m_cupsOptions = new CupsOptions(this, PrintDest->currentText());
+
+	auto printOptions = m_cupsOptions->options();
+	for (auto it = printOptions.begin(); it != printOptions.end(); ++it)
+	{
+		const QString& optionKey = it.key();
+		const CupsOptions::OptionData& printOption = it.value(); 
+		if (m_cupsOptions->useDefaultValue(optionKey))
 			continue;
 
-		if (it.value().KeyW == "mirror")
-			PrinterOpts += " -o mirror";
-		else if (it.value().KeyW == "page-set")
+		if (printOption.keyword == "mirror")
+			printerOptions += " -o mirror";
+		else if (printOption.keyword == "page-set")
 		{
-			PrinterOpts += " -o " + it.value().KeyW + "=";
-			if (cdia->FlagsOpt.at(it.value().Cnum)->currentIndex() == 1)
-				PrinterOpts += "even";
-			else
-				PrinterOpts += "odd";
+			int pageSetIndex = m_cupsOptions->optionIndex(optionKey);
+			if (pageSetIndex > 0)
+			{
+				printerOptions += " -o " + printOption.keyword + "=";
+				printerOptions += (pageSetIndex == 1) ? "even" : "odd";
+			}
 		}
-		else if (it.value().KeyW == "number-up")
+		else if (printOption.keyword == "number-up")
 		{
-			PrinterOpts += " -o " + it.value().KeyW + "=";
-			switch (cdia->FlagsOpt.at(it.value().Cnum)->currentIndex())
+			printerOptions += " -o " + printOption.keyword + "=";
+			switch (m_cupsOptions->optionIndex(optionKey))
 			{
+				case 0:
+					printerOptions += "1";
+					break;
 				case 1:
-					PrinterOpts += "2";
+					printerOptions += "2";
 					break;
 				case 2:
-					PrinterOpts += "4";
+					printerOptions += "4";
 					break;
 				case 3:
-					PrinterOpts += "6";
+					printerOptions += "6";
 					break;
 				case 4:
-					PrinterOpts += "9";
+					printerOptions += "9";
 					break;
 				case 5:
-					PrinterOpts += "16";
+					printerOptions += "16";
 					break;
 			}
 		}
-		else if (it.value().KeyW == "orientation")
-			PrinterOpts += " -o landscape";
+		else if (printOption.keyword == "orientation")
+			printerOptions += " -o landscape";
 		else
 		{
-			PrinterOpts += " -o " +
-				it.value().KeyW+"="+cdia->FlagsOpt.at(it.value().Cnum)->currentText();
+			printerOptions += " -o " + printOption.keyword + "=" + m_cupsOptions->optionText(optionKey);
 		}
 	}
+	return printerOptions;
 #endif
+	return QString();
 }
 
 void PrintDialog::SelComm()
@@ -284,7 +290,7 @@
 
 void PrintDialog::SelEngine(const QString& eng)
 {
-	prefs->set("CurrentPrnEngine", printEngineMap[printEngines->currentText()]);
+	prefs->set("CurrentPrnEngine", m_printEngineMap[printEngines->currentText()]);
 	bool psSupported = outputToFile();
 	psSupported |= (eng == CommonStrings::trPostScript1);
 	psSupported |= (eng == CommonStrings::trPostScript2);
@@ -314,7 +320,7 @@
 #if defined(_WIN32)
 	if (!toFile)
 	{
-		if (!PrinterUtil::getDefaultSettings(PrintDest->currentText(), DevMode))
+		if (!PrinterUtil::getDefaultSettings(PrintDest->currentText(), m_devMode))
 			qWarning( tr("Failed to retrieve printer settings").toLatin1().data() );
 	}
 #endif
@@ -335,15 +341,15 @@
 	}
 
 	// Get page description language supported by the selected printer
-	printEngineMap = PrinterUtil::getPrintEngineSupport(prn, toFile);
+	m_printEngineMap = PrinterUtil::getPrintEngineSupport(prn, toFile);
 	refreshPrintEngineBox();
 
 	prefs->set("CurrentPrn", prn);
-	prefs->set("CurrentPrnEngine", printEngineMap[printEngines->currentText()]);
+	prefs->set("CurrentPrnEngine", m_printEngineMap[printEngines->currentText()]);
 	
-	bool ps1Supported = printEngineMap.contains(CommonStrings::trPostScript1);
-	bool ps2Supported = printEngineMap.contains(CommonStrings::trPostScript2);
-	bool ps3Supported = printEngineMap.contains(CommonStrings::trPostScript3);
+	bool ps1Supported = m_printEngineMap.contains(CommonStrings::trPostScript1);
+	bool ps2Supported = m_printEngineMap.contains(CommonStrings::trPostScript2);
+	bool ps3Supported = m_printEngineMap.contains(CommonStrings::trPostScript3);
 	bool psSupported  = (ps1Supported || ps2Supported || ps3Supported);
 	if (psSupported || toFile)
 	{
@@ -436,12 +442,8 @@
 	}
 	else
 		m_doc->Print_Options.useAltPrintCommand = false;
-#ifdef HAVE_CUPS
-	m_doc->Print_Options.printerOptions = PrinterOpts;
-#else
-	m_doc->Print_Options.printerOptions.clear();
-#endif
-	m_doc->Print_Options.devMode = DevMode;
+	m_doc->Print_Options.printerOptions = getOptions();
+	m_doc->Print_Options.devMode = m_devMode;
 }
 
 void PrintDialog::okButtonClicked()
@@ -540,24 +542,24 @@
 	docBleeds->setChecked(m_doc->Print_Options.useDocBleeds);
 	if (docBleeds->isChecked())
 	{
-		BleedTop->setValue(m_doc->bleeds()->top()*unitRatio);
-		BleedBottom->setValue(m_doc->bleeds()->bottom()*unitRatio);
-		BleedRight->setValue(m_doc->bleeds()->right()*unitRatio);
-		BleedLeft->setValue(m_doc->bleeds()->left()*unitRatio);
+		BleedTop->setValue(m_doc->bleeds()->top() * m_unitRatio);
+		BleedBottom->setValue(m_doc->bleeds()->bottom() * m_unitRatio);
+		BleedRight->setValue(m_doc->bleeds()->right() * m_unitRatio);
+		BleedLeft->setValue(m_doc->bleeds()->left() * m_unitRatio);
 	}
 	else
 	{
-		BleedTop->setValue(m_doc->Print_Options.bleeds.top()*unitRatio);
-		BleedBottom->setValue(m_doc->Print_Options.bleeds.bottom()*unitRatio);
-		BleedRight->setValue(m_doc->Print_Options.bleeds.right()*unitRatio);
-		BleedLeft->setValue(m_doc->Print_Options.bleeds.left()*unitRatio);
+		BleedTop->setValue(m_doc->Print_Options.bleeds.top() * m_unitRatio);
+		BleedBottom->setValue(m_doc->Print_Options.bleeds.bottom() * m_unitRatio);
+		BleedRight->setValue(m_doc->Print_Options.bleeds.right() * m_unitRatio);
+		BleedLeft->setValue(m_doc->Print_Options.bleeds.left() * m_unitRatio);
 	}
 	BleedTop->setEnabled(!docBleeds->isChecked());
 	BleedBottom->setEnabled(!docBleeds->isChecked());
 	BleedRight->setEnabled(!docBleeds->isChecked());
 	BleedLeft->setEnabled(!docBleeds->isChecked());
-	markLength->setValue(m_doc->Print_Options.markLength*unitRatio);
-	markOffset->setValue(m_doc->Print_Options.markOffset*unitRatio);
+	markLength->setValue(m_doc->Print_Options.markLength * m_unitRatio);
+	markOffset->setValue(m_doc->Print_Options.markOffset * m_unitRatio);
 	cropMarks->setChecked(m_doc->Print_Options.cropMarks);
 	bleedMarks->setChecked(m_doc->Print_Options.bleedMarks);
 	registrationMarks->setChecked(m_doc->Print_Options.registrationMarks);
@@ -642,7 +644,7 @@
 
 PrintEngine PrintDialog::printEngine()
 {
-	return printEngineMap[printEngines->currentText()];
+	return m_printEngineMap[printEngines->currentText()];
 }
 
 bool PrintDialog::doDev()
@@ -674,21 +676,21 @@
 {
 	if (docBleeds->isChecked())
 	{
-		prefs->set("BleedTop", BleedTop->value() / unitRatio);
-		prefs->set("BleedBottom", BleedBottom->value() / unitRatio);
-		prefs->set("BleedRight", BleedRight->value() / unitRatio);
-		prefs->set("BleedLeft", BleedLeft->value() / unitRatio);
-		BleedTop->setValue(m_doc->bleeds()->top()*unitRatio);
-		BleedBottom->setValue(m_doc->bleeds()->bottom()*unitRatio);
-		BleedRight->setValue(m_doc->bleeds()->right()*unitRatio);
-		BleedLeft->setValue(m_doc->bleeds()->left()*unitRatio);
+		prefs->set("BleedTop", BleedTop->value() / m_unitRatio);
+		prefs->set("BleedBottom", BleedBottom->value() / m_unitRatio);
+		prefs->set("BleedRight", BleedRight->value() / m_unitRatio);
+		prefs->set("BleedLeft", BleedLeft->value() / m_unitRatio);
+		BleedTop->setValue(m_doc->bleeds()->top() * m_unitRatio);
+		BleedBottom->setValue(m_doc->bleeds()->bottom() * m_unitRatio);
+		BleedRight->setValue(m_doc->bleeds()->right() * m_unitRatio);
+		BleedLeft->setValue(m_doc->bleeds()->left() * m_unitRatio);
 	}
 	else
 	{
-		BleedTop->setValue(prefs->getDouble("BleedTop",0.0)*unitRatio);
-		BleedBottom->setValue(prefs->getDouble("BleedBottom",0.0)*unitRatio);
-		BleedRight->setValue(prefs->getDouble("BleedRight",0.0)*unitRatio);
-		BleedLeft->setValue(prefs->getDouble("BleedLeft",0.0)*unitRatio);
+		BleedTop->setValue(prefs->getDouble("BleedTop",0.0) * m_unitRatio);
+		BleedBottom->setValue(prefs->getDouble("BleedBottom",0.0) * m_unitRatio);
+		BleedRight->setValue(prefs->getDouble("BleedRight",0.0) * m_unitRatio);
+		BleedLeft->setValue(prefs->getDouble("BleedLeft",0.0) * m_unitRatio);
 	}
 	bool isChecked = docBleeds->isChecked();
 	prefs->set("UseDocBleeds", isChecked);
@@ -718,9 +720,9 @@
 {
 	int index = 0, oldPDLIndex = -1;
 	QString oldPDL  = printEngines->currentText();
-	PrintEngineMap::Iterator it, itEnd = printEngineMap.end();
+	PrintEngineMap::Iterator it, itEnd = m_printEngineMap.end();
 	printEngines->clear();
-	for (it = printEngineMap.begin(); it != itEnd; ++it)
+	for (it = m_printEngineMap.begin(); it != itEnd; ++it)
 	{
 		printEngines->addItem(it.key());
 		if (it.key() == oldPDL)
@@ -740,13 +742,13 @@
 
 void PrintDialog::setPrintEngine(PrintEngine pdl)
 {
-	QString pdlString = printEngineMap.key(pdl, "");
+	QString pdlString = m_printEngineMap.key(pdl, "");
 	int itemIndex = printEngines->findText(pdlString);
 	if (itemIndex >= 0)
 		printEngines->setCurrentIndex(itemIndex);
 	else if (printEngines->count() > 0)
 	{
-		pdlString = printEngineMap.key(PostScript3, "");
+		pdlString = m_printEngineMap.key(PostScript3, "");
 		itemIndex = printEngines->findText(pdlString);
 		if (itemIndex >= 0)
 			printEngines->setCurrentIndex(itemIndex);

Modified: trunk/Scribus/scribus/ui/printdialog.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23565&path=/trunk/Scribus/scribus/ui/printdialog.h
==============================================================================
--- trunk/Scribus/scribus/ui/printdialog.h	(original)
+++ trunk/Scribus/scribus/ui/printdialog.h	Wed Apr  8 19:00:47 2020
@@ -26,6 +26,7 @@
 public:
 	PrintDialog( QWidget* parent, ScribusDoc* doc, const PrintOptions& printOptions, bool gcr, const QStringList& spots);
 	~PrintDialog();
+
 	QString printerName();
 	QString outputFileName();
 	bool outputToFile();
@@ -33,7 +34,6 @@
 	bool outputSeparations();
 	QString separationName();
 	QStringList allSeparations();
-	QString PrinterOpts;
 	bool color();
 	bool mirrorHorizontal();
 	bool mirrorVertical();
@@ -45,7 +45,6 @@
 	bool doPrintAll();
 	bool doPrintCurrentPage();
 	QString getPageString();
-	QByteArray DevMode;
 
 public slots:
 	void setMinMax(int min, int max, int cur);
@@ -67,18 +66,21 @@
 	void previewButtonClicked();
 
 protected:
-	ScribusDoc*  m_doc;
-	PrintEngineMap printEngineMap;
-	PrefsContext* prefs;
-	void setStoredValues(const QString& fileName, bool gcr);
-	CupsOptions *cdia;
-	int    unit;
-	double unitRatio;
-	void   getOptions();
-	void   getDefaultPrintOptions(PrintOptions& options, bool gcr);
-	void   storeValues();
-	void   refreshPrintEngineBox();
-	void   setPrintEngine(PrintEngine engine);
+	ScribusDoc*    m_doc;
+	PrintEngineMap m_printEngineMap;
+	PrefsContext*  prefs { nullptr };
+	CupsOptions*   m_cupsOptions { nullptr };
+	int            m_unit { 0 };
+	double         m_unitRatio { 1 };
+	
+	QByteArray m_devMode; // Buffer for storing storing printer options on Windows
+
+	QString getOptions();
+	void    getDefaultPrintOptions(PrintOptions& options, bool gcr);
+	void    storeValues();
+	void    refreshPrintEngineBox();
+	void    setPrintEngine(PrintEngine engine);
+	void    setStoredValues(const QString& fileName, bool gcr);
 };
 
 #endif // PRINTDIALOG_H




More information about the scribus-commit mailing list