r23137 by jghali - Some refactoring related to printer margins retrieval

scribus-commit scribus-commit at lists.scribus.net
Mon Aug 19 05:37:04 UTC 2019


Author: jghali
Date: Mon Aug 19 05:37:03 2019
New Revision: 23137

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=23137
Log:
Some refactoring related to printer margins retrieval

Modified:
    trunk/Scribus/scribus/ui/marginwidget.cpp
    trunk/Scribus/scribus/ui/marginwidget.h
    trunk/Scribus/scribus/ui/newmarginwidget.cpp
    trunk/Scribus/scribus/ui/newmarginwidget.h
    trunk/Scribus/scribus/ui/useprintermarginsdialog.cpp
    trunk/Scribus/scribus/ui/useprintermarginsdialog.h
    trunk/Scribus/scribus/util_printer.cpp
    trunk/Scribus/scribus/util_printer.h

Modified: trunk/Scribus/scribus/ui/marginwidget.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23137&path=/trunk/Scribus/scribus/ui/marginwidget.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/marginwidget.cpp	(original)
+++ trunk/Scribus/scribus/ui/marginwidget.cpp	Mon Aug 19 05:37:03 2019
@@ -20,22 +20,22 @@
 
 
 MarginWidget::MarginWidget( QWidget* parent, const QString& /*title*/, const MarginStruct* margs, int unitIndex, bool showChangeAll, bool showBleeds) : QTabWidget(parent),
-	pageWidth(0.0),
-	pageHeight(0.0),
-	pageType(0)
-{
-	marginData=*margs;
-	savedMargins=*margs;
-	savedPresetItem=PresetLayout::none; //we don't recheck if we are using a layout but always start at none
-	facingPages = false;
-	useBleeds = showBleeds;
+	m_pageWidth(0.0),
+	m_pageHeight(0.0),
+	m_pageType(0)
+{
+	marginData = *margs;
+	m_savedMargins = *margs;
+	m_savedPresetItem = PresetLayout::none; //we don't recheck if we are using a layout but always start at none
+	m_facingPages = false;
+	m_useBleeds = showBleeds;
 	marginPage = new QWidget(this);
 
 	presetCombo = new PresetLayout(marginPage);
 	presetLabel = new QLabel( tr("Preset Layouts:"), marginPage);
 	presetLabel->setBuddy(presetCombo);
-	m_unitIndex=unitIndex;
-	m_unitRatio=unitGetRatioFromIndex(unitIndex);
+	m_unitIndex = unitIndex;
+	m_unitRatio = unitGetRatioFromIndex(unitIndex);
 	leftR = new ScrSpinBox( 0, 1000, marginPage, unitIndex );
 	rightR = new ScrSpinBox( 0, 1000, marginPage, unitIndex );
 	topR = new ScrSpinBox( 0, 1000, marginPage, unitIndex );
@@ -108,7 +108,7 @@
 
 	addTab(marginPage, tr("Margin Guides"));
 
-	if (useBleeds)
+	if (m_useBleeds)
 	{
 		bleedPage = new QWidget(this);
 		BleedGroupLayout = new QGridLayout( bleedPage );
@@ -234,11 +234,11 @@
 
 void MarginWidget::setFacingPages(bool facing, int pagetype)
 {
-	facingPages = facing;
-	pageType = pagetype;
+	m_facingPages = facing;
+	m_pageType = pagetype;
 	lText->setText(facing ? tr( "&Inside:" ) : tr( "&Left:" ));
 	rText->setText(facing ? tr( "O&utside:" ) : tr( "&Right:" ));
-	if (useBleeds)
+	if (m_useBleeds)
 	{
 		if (facing)
 		{
@@ -258,10 +258,10 @@
 {
 	rightR->setMaximum(qMax(0.0, width * m_unitRatio - leftR->value()));
 	leftR->setMaximum(qMax(0.0, width * m_unitRatio - rightR->value()));
-	pageWidth = width;
+	m_pageWidth = width;
 	topR->setMaximum(qMax(0.0, height * m_unitRatio - bottomR->value()));
 	bottomR->setMaximum(qMax(0.0, height * m_unitRatio - topR->value()));
-	pageHeight = height;
+	m_pageHeight = height;
 	setPreset();
 }
 
@@ -269,7 +269,7 @@
 {
 	rightR->setMaximum(qMax(0.0, width * m_unitRatio - leftR->value()));
 	leftR->setMaximum(qMax(0.0,width * m_unitRatio - rightR->value()));
-	pageWidth = width;
+	m_pageWidth = width;
 	setPreset();
 }
 
@@ -277,15 +277,15 @@
 {
 	topR->setMaximum(qMax(0.0, height * m_unitRatio - bottomR->value()));
 	bottomR->setMaximum(qMax(0.0,height * m_unitRatio - topR->value()));
-	pageHeight = height;
+	m_pageHeight = height;
 	setPreset();
 }
 
 void MarginWidget::setTop()
 {
 	double newVal=topR->value() / m_unitRatio;
-	bottomR->setMaximum(qMax(0.0, pageHeight * m_unitRatio - topR->value()));
-	if (linkMargins->isChecked() && savedPresetItem==PresetLayout::none)
+	bottomR->setMaximum(qMax(0.0, m_pageHeight * m_unitRatio - topR->value()));
+	if (linkMargins->isChecked() && m_savedPresetItem == PresetLayout::none)
 	{
 		marginData.set(newVal, newVal, newVal, newVal);
 		updateMarginSpinValues();
@@ -298,8 +298,8 @@
 void MarginWidget::setBottom()
 {
 	double newVal = bottomR->value() / m_unitRatio;
-	topR->setMaximum(qMax(0.0, pageHeight * m_unitRatio - bottomR->value()));
-	if (linkMargins->isChecked() && savedPresetItem==PresetLayout::none)
+	topR->setMaximum(qMax(0.0, m_pageHeight * m_unitRatio - bottomR->value()));
+	if (linkMargins->isChecked() && m_savedPresetItem == PresetLayout::none)
 	{
 		marginData.set(newVal, newVal, newVal, newVal);
 		updateMarginSpinValues();
@@ -312,8 +312,8 @@
 void MarginWidget::setLeft()
 {
 	double newVal = leftR->value() / m_unitRatio;
-	rightR->setMaximum(qMax(0.0, pageWidth * m_unitRatio - leftR->value()));
-	if (linkMargins->isChecked() && savedPresetItem==PresetLayout::none)
+	rightR->setMaximum(qMax(0.0, m_pageWidth * m_unitRatio - leftR->value()));
+	if (linkMargins->isChecked() && m_savedPresetItem == PresetLayout::none)
 	{
 		marginData.set(newVal, newVal, newVal, newVal);
 		updateMarginSpinValues();
@@ -326,8 +326,8 @@
 void MarginWidget::setRight()
 {
 	double newVal = rightR->value() / m_unitRatio;
-	leftR->setMaximum(qMax(0.0, pageWidth * m_unitRatio - rightR->value()));
-	if (linkMargins->isChecked() && savedPresetItem==PresetLayout::none)
+	leftR->setMaximum(qMax(0.0, m_pageWidth * m_unitRatio - rightR->value()));
+	if (linkMargins->isChecked() && m_savedPresetItem == PresetLayout::none)
 	{
 		marginData.set(newVal, newVal, newVal, newVal);
 		updateMarginSpinValues();
@@ -343,14 +343,14 @@
 	disconnect(bottomR, SIGNAL(valueChanged(double)), this, SLOT(setBottom()));
 	disconnect(leftR, SIGNAL(valueChanged(double)), this, SLOT(setLeft()));
 	disconnect(rightR, SIGNAL(valueChanged(double)), this, SLOT(setRight()));
-	m_unitIndex=newUnitIndex;
-	m_unitRatio=unitGetRatioFromIndex(newUnitIndex);
+	m_unitIndex = newUnitIndex;
+	m_unitRatio = unitGetRatioFromIndex(newUnitIndex);
 	topR->setNewUnit(newUnitIndex);
 	bottomR->setNewUnit(newUnitIndex);
 	leftR->setNewUnit(newUnitIndex);
 	rightR->setNewUnit(newUnitIndex);
 	
-	if (useBleeds)
+	if (m_useBleeds)
 	{
 		disconnect(BleedLeft, SIGNAL(valueChanged(double)), this, SLOT(changeBleeds()));
 		disconnect(BleedRight, SIGNAL(valueChanged(double)), this, SLOT(changeBleeds()));
@@ -377,28 +377,28 @@
 	disconnect(bottomR, SIGNAL(valueChanged(double)), this, SLOT(setBottom()));
 	disconnect(leftR, SIGNAL(valueChanged(double)), this, SLOT(setLeft()));
 	disconnect(rightR, SIGNAL(valueChanged(double)), this, SLOT(setRight()));
-	if (savedPresetItem==PresetLayout::none)
-		savedMargins=marginData;
+	if (m_savedPresetItem == PresetLayout::none)
+		m_savedMargins = marginData;
 	int item = presetCombo->currentIndex();
 
-	MarginStruct marg = presetCombo->getMargins(item, pageWidth, pageHeight, leftR->value() / m_unitRatio);
-	presetCombo->setEnabled(facingPages);
-
-	bool restoringValues=false;
-	if (item==PresetLayout::none && savedPresetItem!=PresetLayout::none)
-	{
-		marg=savedMargins;
-		restoringValues=true;
-	}
-	if (restoringValues || (presetCombo->needUpdate() && facingPages))
+	MarginStruct marg = presetCombo->getMargins(item, m_pageWidth, m_pageHeight, leftR->value() / m_unitRatio);
+	presetCombo->setEnabled(m_facingPages);
+
+	bool restoringValues = false;
+	if ((item == PresetLayout::none) && (m_savedPresetItem != PresetLayout::none))
+	{
+		marg = m_savedMargins;
+		restoringValues = true;
+	}
+	if (restoringValues || (presetCombo->needUpdate() && m_facingPages))
 	{
 		marginData.set(qMax(0.0, marg.top()), qMax(0.0, marg.left()), qMax(0.0, marg.bottom()), qMax(0.0, marg.right()));
 		updateMarginSpinValues();
 		
-		bottomR->setMaximum(qMax(0.0, pageHeight * m_unitRatio - topR->value()));
-		topR->setMaximum(qMax(0.0, pageHeight * m_unitRatio - bottomR->value()));
-		rightR->setMaximum(qMax(0.0, pageWidth * m_unitRatio - leftR->value()));
-		leftR->setMaximum(qMax(0.0, pageWidth * m_unitRatio - rightR->value()));
+		bottomR->setMaximum(qMax(0.0, m_pageHeight * m_unitRatio - topR->value()));
+		topR->setMaximum(qMax(0.0, m_pageHeight * m_unitRatio - bottomR->value()));
+		rightR->setMaximum(qMax(0.0, m_pageWidth * m_unitRatio - leftR->value()));
+		leftR->setMaximum(qMax(0.0, m_pageWidth * m_unitRatio - rightR->value()));
 		rightR->setEnabled(restoringValues);
 		topR->setEnabled(restoringValues);
 		bottomR->setEnabled(restoringValues);
@@ -409,48 +409,49 @@
 		topR->setEnabled(true);
 		bottomR->setEnabled(true);
 	}
-	if (pageType == 1)
+	if (m_pageType == 1)
 		rightR->setEnabled(false);
 	leftR->setEnabled(item != PresetLayout::nineparts);
-	if (item!=PresetLayout::none)
+	if (item != PresetLayout::none)
 		linkMargins->setChecked(false);
-	linkMargins->setEnabled(item==PresetLayout::none || !presetCombo->isEnabled());
+	linkMargins->setEnabled(item == PresetLayout::none || !presetCombo->isEnabled());
 	connect(topR, SIGNAL(valueChanged(double)), this, SLOT(setTop()));
 	connect(bottomR, SIGNAL(valueChanged(double)), this, SLOT(setBottom()));
 	connect(leftR, SIGNAL(valueChanged(double)), this, SLOT(setLeft()));
 	connect(rightR, SIGNAL(valueChanged(double)), this, SLOT(setRight()));
-	savedPresetItem=item;
+	m_savedPresetItem=item;
 }
 
 void MarginWidget::setPageSize(const QString& pageSize)
 {
-	m_pageSize=pageSize;
+	m_pageSize = pageSize;
 }
 
 void MarginWidget::setMarginsToPrinterMargins()
 {
-	UsePrinterMarginsDialog upm(parentWidget(), m_pageSize, unitGetRatioFromIndex(m_unitIndex), unitGetSuffixFromIndex(m_unitIndex));
-	if (upm.exec())
-	{
-		double t,b,l,r;
-		upm.getNewPrinterMargins(t,b,l,r);
-		presetCombo->setCurrentIndex(PresetLayout::none);
+	QSizeF pageDimensions(m_pageWidth, m_pageHeight);
+	UsePrinterMarginsDialog upm(parentWidget(), pageDimensions, m_pageSize, unitGetRatioFromIndex(m_unitIndex), unitGetSuffixFromIndex(m_unitIndex));
+	if (upm.exec() != QDialog::Accepted)
+		return;
+
+	double t, b, l, r;
+	upm.getNewPrinterMargins(t, b, l, r);
+	presetCombo->setCurrentIndex(PresetLayout::none);
 		
-		marginData.setTop(t);
-		marginData.setBottom(b);
-		marginData.setLeft(l);
-		marginData.setRight(r);
-		updateMarginSpinValues();
-
-		bottomR->setMaximum((qMax(0.0, pageHeight - t) * m_unitRatio));
-		topR->setMaximum((qMax(0.0, pageHeight - b) * m_unitRatio));
-		rightR->setMaximum((qMax(0.0, pageWidth - l) * m_unitRatio));
-		leftR->setMaximum((qMax(0.0, pageWidth - r) * m_unitRatio));
-
-		rightR->setEnabled(true);
-		topR->setEnabled(true);
-		bottomR->setEnabled(true);
-	}
+	marginData.setTop(t);
+	marginData.setBottom(b);
+	marginData.setLeft(l);
+	marginData.setRight(r);
+	updateMarginSpinValues();
+
+	bottomR->setMaximum((qMax(0.0, m_pageHeight - t) * m_unitRatio));
+	topR->setMaximum((qMax(0.0, m_pageHeight - b) * m_unitRatio));
+	rightR->setMaximum((qMax(0.0, m_pageWidth - l) * m_unitRatio));
+	leftR->setMaximum((qMax(0.0, m_pageWidth - r) * m_unitRatio));
+
+	rightR->setEnabled(true);
+	topR->setEnabled(true);
+	bottomR->setEnabled(true);
 }
 
 double MarginWidget::top() const
@@ -490,18 +491,18 @@
 void MarginWidget::setMarginPreset(int p)
 {
 	disconnect(presetCombo, SIGNAL(activated(int)), this, SLOT(setPreset()));
-	savedPresetItem = p;
+	m_savedPresetItem = p;
 	presetCombo->setCurrentIndex(p);
-	if (savedPresetItem==PresetLayout::none)
-		savedMargins=marginData;
+	if (m_savedPresetItem == PresetLayout::none)
+		m_savedMargins=marginData;
 	int item = presetCombo->currentIndex();
-	presetCombo->setEnabled(facingPages);
+	presetCombo->setEnabled(m_facingPages);
 	bool restoringValues=false;
-	if (item==PresetLayout::none && savedPresetItem!=PresetLayout::none)
+	if ((item == PresetLayout::none) && (m_savedPresetItem != PresetLayout::none))
 	{
 		restoringValues=true;
 	}
-	if (restoringValues || (presetCombo->needUpdate() && facingPages))
+	if (restoringValues || (presetCombo->needUpdate() && m_facingPages))
 	{
 		rightR->setEnabled(restoringValues);
 		topR->setEnabled(restoringValues);
@@ -513,7 +514,7 @@
 		topR->setEnabled(true);
 		bottomR->setEnabled(true);
 	}
-	if (pageType == 1)
+	if (m_pageType == 1)
 		rightR->setEnabled(false);
 	leftR->setEnabled(item != PresetLayout::nineparts);
 	if (item!=PresetLayout::none)

Modified: trunk/Scribus/scribus/ui/marginwidget.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23137&path=/trunk/Scribus/scribus/ui/marginwidget.h
==============================================================================
--- trunk/Scribus/scribus/ui/marginwidget.h	(original)
+++ trunk/Scribus/scribus/ui/marginwidget.h	Mon Aug 19 05:37:03 2019
@@ -145,9 +145,9 @@
 	double RandR;
 	*/
 	/*! \brief Internally used page width */
-	double pageWidth;
+	double m_pageWidth;
 	/*! \brief Internally used page height */
-	double pageHeight;
+	double m_pageHeight;
 
 public slots:
 	/*! \brief Recompute the values after spinbox change */
@@ -166,18 +166,20 @@
 
 protected:
 	void updateMarginSpinValues();
+
 	QGridLayout* GroupLayout;
 	QHBoxLayout* marginsForPagesLayout;
 	QGridLayout* BleedGroupLayout;
+
 	QString m_pageSize;
-	int m_unitIndex;
-	double m_unitRatio;
+	int     m_unitIndex;
+	double  m_unitRatio;
 	//! \brief if the outer facing palette points to the facing pages item
-	bool facingPages;
-	bool useBleeds;
-	int pageType;
-	MarginStruct savedMargins;
-	int savedPresetItem;
+	bool m_facingPages;
+	bool m_useBleeds;
+	int  m_pageType;
+	MarginStruct m_savedMargins;
+	int m_savedPresetItem;
 };
 
 #endif

Modified: trunk/Scribus/scribus/ui/newmarginwidget.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23137&path=/trunk/Scribus/scribus/ui/newmarginwidget.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/newmarginwidget.cpp	(original)
+++ trunk/Scribus/scribus/ui/newmarginwidget.cpp	Mon Aug 19 05:37:03 2019
@@ -13,8 +13,8 @@
 
 NewMarginWidget::NewMarginWidget(QWidget* parent)
 	: QWidget(parent),
-	savedPresetItem(PresetLayout::none),
-	facingPages(false),
+	m_savedPresetItem(PresetLayout::none),
+	m_facingPages(false),
 	m_flags(MarginWidgetFlags)
 {
 	setupUi(this);
@@ -22,9 +22,9 @@
 	m_unitIndex = 0;
 	m_unitRatio = 1.0;
 
-	pageWidth  = 0;
-	pageHeight = 0;
-	pageType = 0;
+	m_pageWidth  = 0;
+	m_pageHeight = 0;
+	m_pageType = 0;
 }
 
 NewMarginWidget::~NewMarginWidget()
@@ -33,10 +33,10 @@
 
 void NewMarginWidget::setup(const MarginStruct& margs, int layoutType, int unitIndex, int flags)
 {
-	marginData=savedMarginData=margs;
-	m_unitIndex=unitIndex;
-	m_unitRatio=unitGetRatioFromIndex(unitIndex);
-	m_flags=flags;
+	m_marginData = m_savedMarginData=margs;
+	m_unitIndex = unitIndex;
+	m_unitRatio = unitGetRatioFromIndex(unitIndex);
+	m_flags = flags;
 	leftMarginSpinBox->setMaximum(1000);
 	rightMarginSpinBox->setMaximum(1000);
 	topMarginSpinBox->setMaximum(1000);
@@ -101,7 +101,7 @@
 
 void NewMarginWidget::setNewValues(const MarginStruct& margs)
 {
-	marginData=savedMarginData=margs;
+	m_marginData = m_savedMarginData = margs;
 	updateMarginSpinValues();
 }
 
@@ -109,7 +109,7 @@
 {
 	leftMarginSpinBox->setMaximum(qMax(0.0, newWidth * m_unitRatio - rightMarginSpinBox->value()));
 	rightMarginSpinBox->setMaximum(qMax(0.0, newWidth * m_unitRatio - leftMarginSpinBox->value()));
-	pageWidth = newWidth;
+	m_pageWidth = newWidth;
 	setPreset();
 }
 
@@ -117,63 +117,63 @@
 {
 	topMarginSpinBox->setMaximum(qMax(0.0, newHeight * m_unitRatio - bottomMarginSpinBox->value()));
 	bottomMarginSpinBox->setMaximum(qMax(0.0,newHeight * m_unitRatio - topMarginSpinBox->value()));
-	pageHeight = newHeight;
+	m_pageHeight = newHeight;
 	setPreset();
 }
 
 void NewMarginWidget::setTop()
 {
 	double newVal=topMarginSpinBox->value() / m_unitRatio;
-	bottomMarginSpinBox->setMaximum(qMax(0.0, pageHeight * m_unitRatio - topMarginSpinBox->value()));
-	if (marginLinkButton->isChecked() && savedPresetItem==PresetLayout::none)
-	{
-		marginData.set(newVal, newVal, newVal, newVal);
-		updateMarginSpinValues();
-	}
-	else
-		marginData.setTop(newVal);
+	bottomMarginSpinBox->setMaximum(qMax(0.0, m_pageHeight * m_unitRatio - topMarginSpinBox->value()));
+	if (marginLinkButton->isChecked() && m_savedPresetItem == PresetLayout::none)
+	{
+		m_marginData.set(newVal, newVal, newVal, newVal);
+		updateMarginSpinValues();
+	}
+	else
+		m_marginData.setTop(newVal);
 	setPreset();
 }
 
 void NewMarginWidget::setBottom()
 {
 	double newVal = bottomMarginSpinBox->value() / m_unitRatio;
-	topMarginSpinBox->setMaximum(qMax(0.0, pageHeight * m_unitRatio - bottomMarginSpinBox->value()));
-	if (marginLinkButton->isChecked() && savedPresetItem==PresetLayout::none)
-	{
-		marginData.set(newVal, newVal, newVal, newVal);
-		updateMarginSpinValues();
-	}
-	else
-		marginData.setBottom(newVal);
+	topMarginSpinBox->setMaximum(qMax(0.0, m_pageHeight * m_unitRatio - bottomMarginSpinBox->value()));
+	if (marginLinkButton->isChecked() && m_savedPresetItem == PresetLayout::none)
+	{
+		m_marginData.set(newVal, newVal, newVal, newVal);
+		updateMarginSpinValues();
+	}
+	else
+		m_marginData.setBottom(newVal);
 	setPreset();
 }
 
 void NewMarginWidget::setLeft()
 {
 	double newVal = leftMarginSpinBox->value() / m_unitRatio;
-	rightMarginSpinBox->setMaximum(qMax(0.0, pageWidth * m_unitRatio - leftMarginSpinBox->value()));
-	if (marginLinkButton->isChecked() && savedPresetItem==PresetLayout::none)
-	{
-		marginData.set(newVal, newVal, newVal, newVal);
-		updateMarginSpinValues();
-	}
-	else
-		marginData.setLeft(newVal);
+	rightMarginSpinBox->setMaximum(qMax(0.0, m_pageWidth * m_unitRatio - leftMarginSpinBox->value()));
+	if (marginLinkButton->isChecked() && m_savedPresetItem == PresetLayout::none)
+	{
+		m_marginData.set(newVal, newVal, newVal, newVal);
+		updateMarginSpinValues();
+	}
+	else
+		m_marginData.setLeft(newVal);
 	setPreset();
 }
 
 void NewMarginWidget::setRight()
 {
 	double newVal = rightMarginSpinBox->value() / m_unitRatio;
-	leftMarginSpinBox->setMaximum(qMax(0.0, pageWidth * m_unitRatio - rightMarginSpinBox->value()));
-	if (marginLinkButton->isChecked() && savedPresetItem==PresetLayout::none)
-	{
-		marginData.set(newVal, newVal, newVal, newVal);
-		updateMarginSpinValues();
-	}
-	else
-		marginData.setRight(newVal);
+	leftMarginSpinBox->setMaximum(qMax(0.0, m_pageWidth * m_unitRatio - rightMarginSpinBox->value()));
+	if (marginLinkButton->isChecked() && m_savedPresetItem == PresetLayout::none)
+	{
+		m_marginData.set(newVal, newVal, newVal, newVal);
+		updateMarginSpinValues();
+	}
+	else
+		m_marginData.setRight(newVal);
 	setPreset();
 }
 
@@ -205,27 +205,28 @@
 	rightMarginSpinBox->blockSignals(true);
 	topMarginSpinBox->blockSignals(true);
 	bottomMarginSpinBox->blockSignals(true);
-	if (savedPresetItem==PresetLayout::none)
-		savedMarginData=marginData;
+	if (m_savedPresetItem == PresetLayout::none)
+		m_savedMarginData = m_marginData;
 	int item = presetLayoutComboBox->currentIndex();
 
-	MarginStruct marg = presetLayoutComboBox->getMargins(item, pageWidth, pageHeight, leftMarginSpinBox->value() / m_unitRatio);
-	facingPages ? presetLayoutComboBox->setEnabled(true) : presetLayoutComboBox->setEnabled(false);
-	bool restoringValues=false;
-	if (item==PresetLayout::none && savedPresetItem!=PresetLayout::none)
-	{
-		marg=savedMarginData;
-		restoringValues=true;
-	}
-	if (restoringValues || (presetLayoutComboBox->needUpdate() && facingPages))
-	{
-		marginData.set(qMax(0.0, marg.top()), qMax(0.0, marg.left()), qMax(0.0, marg.bottom()), qMax(0.0, marg.right()));
-		updateMarginSpinValues();
-
-		bottomMarginSpinBox->setMaximum(qMax(0.0, pageHeight * m_unitRatio - topMarginSpinBox->value()));
-		topMarginSpinBox->setMaximum(qMax(0.0, pageHeight * m_unitRatio - bottomMarginSpinBox->value()));
-		rightMarginSpinBox->setMaximum(qMax(0.0, pageWidth * m_unitRatio - leftMarginSpinBox->value()));
-		leftMarginSpinBox->setMaximum(qMax(0.0, pageWidth * m_unitRatio - rightMarginSpinBox->value()));
+	MarginStruct marg = presetLayoutComboBox->getMargins(item, m_pageWidth, m_pageHeight, leftMarginSpinBox->value() / m_unitRatio);
+	presetLayoutComboBox->setEnabled(m_facingPages);
+
+	bool restoringValues = false;
+	if (item == PresetLayout::none && m_savedPresetItem != PresetLayout::none)
+	{
+		marg = m_savedMarginData;
+		restoringValues = true;
+	}
+	if (restoringValues || (presetLayoutComboBox->needUpdate() && m_facingPages))
+	{
+		m_marginData.set(qMax(0.0, marg.top()), qMax(0.0, marg.left()), qMax(0.0, marg.bottom()), qMax(0.0, marg.right()));
+		updateMarginSpinValues();
+
+		bottomMarginSpinBox->setMaximum(qMax(0.0, m_pageHeight * m_unitRatio - topMarginSpinBox->value()));
+		topMarginSpinBox->setMaximum(qMax(0.0, m_pageHeight * m_unitRatio - bottomMarginSpinBox->value()));
+		rightMarginSpinBox->setMaximum(qMax(0.0, m_pageWidth * m_unitRatio - leftMarginSpinBox->value()));
+		leftMarginSpinBox->setMaximum(qMax(0.0, m_pageWidth * m_unitRatio - rightMarginSpinBox->value()));
 		rightMarginSpinBox->setEnabled(restoringValues);
 		topMarginSpinBox->setEnabled(restoringValues);
 		bottomMarginSpinBox->setEnabled(restoringValues);
@@ -236,22 +237,22 @@
 		topMarginSpinBox->setEnabled(true);
 		bottomMarginSpinBox->setEnabled(true);
 	}
-	if (pageType == 1)
+	if (m_pageType == 1)
 		rightMarginSpinBox->setEnabled(false);
 	leftMarginSpinBox->setEnabled(item != PresetLayout::nineparts);
-	if (item!=PresetLayout::none)
+	if (item != PresetLayout::none)
 		marginLinkButton->setChecked(false);
-	marginLinkButton->setEnabled(item==PresetLayout::none || !presetLayoutComboBox->isEnabled());
+	marginLinkButton->setEnabled(item == PresetLayout::none || !presetLayoutComboBox->isEnabled());
 	leftMarginSpinBox->blockSignals(false);
 	rightMarginSpinBox->blockSignals(false);
 	topMarginSpinBox->blockSignals(false);
 	bottomMarginSpinBox->blockSignals(false);
-	savedPresetItem=item;
+	m_savedPresetItem = item;
 }
 
 void NewMarginWidget::setPageSize(const QString& pageSize)
 {
-	m_pageSize=pageSize;
+	m_pageSize = pageSize;
 }
 
 
@@ -262,10 +263,10 @@
 	bool topBlocked = topMarginSpinBox->blockSignals(true);
 	bool bottomBlocked = bottomMarginSpinBox->blockSignals(true);
 
-	topMarginSpinBox->setValue(marginData.top() * m_unitRatio);
-	rightMarginSpinBox->setValue(marginData.right() * m_unitRatio);
-	bottomMarginSpinBox->setValue(marginData.bottom() * m_unitRatio);
-	leftMarginSpinBox->setValue(marginData.left() * m_unitRatio);
+	topMarginSpinBox->setValue(m_marginData.top() * m_unitRatio);
+	rightMarginSpinBox->setValue(m_marginData.right() * m_unitRatio);
+	bottomMarginSpinBox->setValue(m_marginData.bottom() * m_unitRatio);
+	leftMarginSpinBox->setValue(m_marginData.left() * m_unitRatio);
 
 	leftMarginSpinBox->blockSignals(leftBlocked);
 	rightMarginSpinBox->blockSignals(rightBlocked);
@@ -285,8 +286,8 @@
 		bottomMarginSpinBox->setValue(leftMarginSpinBox->value());
 		topMarginSpinBox->setValue(leftMarginSpinBox->value());
 		rightMarginSpinBox->setValue(leftMarginSpinBox->value());
-		double newVal=leftMarginSpinBox->value() / m_unitRatio;
-		marginData.set(newVal, newVal, newVal, newVal);
+		double newVal = leftMarginSpinBox->value() / m_unitRatio;
+		m_marginData.set(newVal, newVal, newVal, newVal);
 	}
 
 	leftMarginSpinBox->blockSignals(leftBlocked);
@@ -300,18 +301,19 @@
 	if ((m_flags & ShowPreset) == 0)
 		return;
 	presetLayoutComboBox->blockSignals(true);
-	savedPresetItem = p;
+	m_savedPresetItem = p;
 	presetLayoutComboBox->setCurrentIndex(p);
-	if (savedPresetItem==PresetLayout::none)
-		savedMarginData=marginData;
+	if (m_savedPresetItem == PresetLayout::none)
+		m_savedMarginData = m_marginData;
 	int item = presetLayoutComboBox->currentIndex();
-	facingPages ? presetLayoutComboBox->setEnabled(true) : presetLayoutComboBox->setEnabled(false);
-	bool restoringValues=false;
-	if (item==PresetLayout::none && savedPresetItem!=PresetLayout::none)
-	{
-		restoringValues=true;
-	}
-	if (restoringValues || (presetLayoutComboBox->needUpdate() && facingPages))
+	presetLayoutComboBox->setEnabled(m_facingPages);
+
+	bool restoringValues = false;
+	if ((item == PresetLayout::none) && (m_savedPresetItem != PresetLayout::none))
+	{
+		restoringValues = true;
+	}
+	if (restoringValues || (presetLayoutComboBox->needUpdate() && m_facingPages))
 	{
 		rightMarginSpinBox->setEnabled(restoringValues);
 		topMarginSpinBox->setEnabled(restoringValues);
@@ -323,19 +325,19 @@
 		topMarginSpinBox->setEnabled(true);
 		bottomMarginSpinBox->setEnabled(true);
 	}
-	if (pageType == 1)
+	if (m_pageType == 1)
 		rightMarginSpinBox->setEnabled(false);
 	leftMarginSpinBox->setEnabled(item != PresetLayout::nineparts);
-	if (item!=PresetLayout::none)
+	if (item != PresetLayout::none)
 		marginLinkButton->setChecked(false);
-	marginLinkButton->setEnabled(item==PresetLayout::none);
+	marginLinkButton->setEnabled(item == PresetLayout::none);
 	presetLayoutComboBox->blockSignals(false);
 }
 
-void NewMarginWidget::setFacingPages(bool facing, int pagetype)
-{
-	facingPages = facing;
-	pageType = pagetype;
+void NewMarginWidget::setFacingPages(bool facing, int pageType)
+{
+	m_facingPages = facing;
+	m_pageType = pageType;
 	leftMarginLabel->setText(facing ? tr( "&Inside:" ) : tr( "&Left:" ));
 	rightMarginLabel->setText(facing ? tr( "O&utside:" ) : tr( "&Right:" ));
 	setPreset();
@@ -343,24 +345,25 @@
 
 void NewMarginWidget::setMarginsToPrinterMargins()
 {
-	UsePrinterMarginsDialog upm(parentWidget(), m_pageSize, unitGetRatioFromIndex(m_unitIndex), unitGetSuffixFromIndex(m_unitIndex));
-	if (upm.exec())
-	{
-		double t,b,l,r;
-		upm.getNewPrinterMargins(t,b,l,r);
-		presetLayoutComboBox->setCurrentIndex(PresetLayout::none);
-		marginData.set(t,l,b,r);
-
-		updateMarginSpinValues();
-
-		bottomMarginSpinBox->setMaximum((qMax(0.0, pageHeight - t) * m_unitRatio));
-		topMarginSpinBox->setMaximum((qMax(0.0, pageHeight - b) * m_unitRatio));
-		rightMarginSpinBox->setMaximum((qMax(0.0, pageWidth - l) * m_unitRatio));
-		leftMarginSpinBox->setMaximum((qMax(0.0, pageWidth - r) * m_unitRatio));
-
-		rightMarginSpinBox->setEnabled(true);
-		topMarginSpinBox->setEnabled(true);
-		bottomMarginSpinBox->setEnabled(true);
-	}
-}
-
+	QSizeF pageDimensions(m_pageWidth, m_pageHeight);
+	UsePrinterMarginsDialog upm(parentWidget(), pageDimensions, m_pageSize, unitGetRatioFromIndex(m_unitIndex), unitGetSuffixFromIndex(m_unitIndex));
+	if (upm.exec() != QDialog::Accepted)
+		return;
+
+	double t, b, l, r;
+	upm.getNewPrinterMargins(t, b, l, r);
+	presetLayoutComboBox->setCurrentIndex(PresetLayout::none);
+	m_marginData.set(t, l, b, r);
+
+	updateMarginSpinValues();
+
+	bottomMarginSpinBox->setMaximum((qMax(0.0, m_pageHeight - t) * m_unitRatio));
+	topMarginSpinBox->setMaximum((qMax(0.0, m_pageHeight - b) * m_unitRatio));
+	rightMarginSpinBox->setMaximum((qMax(0.0, m_pageWidth - l) * m_unitRatio));
+	leftMarginSpinBox->setMaximum((qMax(0.0, m_pageWidth - r) * m_unitRatio));
+
+	rightMarginSpinBox->setEnabled(true);
+	topMarginSpinBox->setEnabled(true);
+	bottomMarginSpinBox->setEnabled(true);
+}
+

Modified: trunk/Scribus/scribus/ui/newmarginwidget.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23137&path=/trunk/Scribus/scribus/ui/newmarginwidget.h
==============================================================================
--- trunk/Scribus/scribus/ui/newmarginwidget.h	(original)
+++ trunk/Scribus/scribus/ui/newmarginwidget.h	Mon Aug 19 05:37:03 2019
@@ -30,7 +30,7 @@
 
 		void setup(const MarginStruct& margs, int layoutType, int unitIndex, int flags = MarginWidgetFlags);
 		/*! \brief Setup the labels by facing pages option */
-		void setFacingPages(bool facing, int pagetype = 0);
+		void setFacingPages(bool facing, int pageType = 0);
 		/*! \brief Setup the spinboxes properties (min/max value etc.) by width */
 		void setPageWidth(double);
 		/*! \brief Setup the spinboxes properties (min/max value etc.) by height */
@@ -41,7 +41,7 @@
 		void setNewValues(const MarginStruct& margs);
 		/*! \brief Setup the presetCombo without changing the margin values, only used by tabdocument */
 		void setMarginPreset(int p);
-		const MarginStruct & margins() const { return marginData; };
+		const MarginStruct & margins() const { return m_marginData; };
 
 	public slots:
 		void languageChange();
@@ -58,17 +58,17 @@
 	protected:
 		void updateMarginSpinValues();
 
-		MarginStruct marginData;
-		MarginStruct savedMarginData;
-		int savedPresetItem;
-		bool facingPages;
-		int m_flags;
-		int m_unitIndex;
+		MarginStruct m_marginData;
+		MarginStruct m_savedMarginData;
+		int    m_savedPresetItem;
+		bool   m_facingPages;
+		int    m_flags;
+		int    m_unitIndex;
 		double m_unitRatio;
 		QString m_pageSize;
-		double pageWidth;
-		double pageHeight;
-		int pageType;
+		double m_pageWidth;
+		double m_pageHeight;
+		int    m_pageType;
 };
 
 #endif // NEWMARGINWIDGET_H

Modified: trunk/Scribus/scribus/ui/useprintermarginsdialog.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23137&path=/trunk/Scribus/scribus/ui/useprintermarginsdialog.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/useprintermarginsdialog.cpp	(original)
+++ trunk/Scribus/scribus/ui/useprintermarginsdialog.cpp	Mon Aug 19 05:37:03 2019
@@ -27,23 +27,27 @@
 // useprintermarginsdialog.ui if you need to modify the layout,
 // widget properties, etc.
 
-UsePrinterMarginsDialog::UsePrinterMarginsDialog( QWidget* parent, const QString& pageSize, double unitRatio, const QString& suffix )
+UsePrinterMarginsDialog::UsePrinterMarginsDialog(QWidget* parent, const QSizeF& pageSize, const QString& pageSizeName, double unitRatio, const QString& suffix )
 	: QDialog(parent)
 {
 	setupUi(this);
-	m_ptsTopMargin=m_ptsBottomMargin=m_ptsLeftMargin=m_ptsRightMargin=0.0;
-	m_pageSize=pageSize;
-	m_unitRatio=unitRatio;
-	m_suffix=suffix;
-	QStringList printerNames=PrinterUtil::getPrinterNames();
+
+	m_margins = QMarginsF(0.0, 0.0, 0.0, 0.0);
+	m_pageSize = pageSize;
+	m_pageSizeName = pageSizeName;
+	m_unitRatio = unitRatio;
+	m_suffix = suffix;
+
+	QStringList printerNames = PrinterUtil::getPrinterNames();
 	printerComboBox->clear();
-	if (printerNames.count()>0 && !pageSize.isEmpty())
+	if (printerNames.count() > 0 && !pageSize.isEmpty())
 	{
 		printerComboBox->insertItems(0, printerNames);
 		getPrinterMarginValues(printerNames.first());
-		marginsGroupBox->setTitle( tr("Minimum Margins for Page Size %1").arg(pageSize));
+		marginsGroupBox->setTitle( tr("Minimum Margins for Page Size %1").arg(pageSizeName));
 		connect(printerComboBox, SIGNAL(activated(const QString&)), this, SLOT(getPrinterMarginValues(const QString&)));
 	}
+
 	connect(okButton, SIGNAL(clicked()), this, SLOT(accept()));
 	connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
 }
@@ -52,18 +56,18 @@
 {
 }
 
-void UsePrinterMarginsDialog::getNewPrinterMargins(double &topMargin,double &bottomMargin,double &leftMargin,double &rightMargin)
+void UsePrinterMarginsDialog::getNewPrinterMargins(double &topMargin, double &bottomMargin, double &leftMargin, double &rightMargin)
 {
-	topMargin=m_ptsTopMargin;
-	bottomMargin=m_ptsBottomMargin;
-	leftMargin=m_ptsLeftMargin;
-	rightMargin=m_ptsRightMargin;
+	topMargin = m_margins.top();
+	bottomMargin = m_margins.bottom();
+	leftMargin = m_margins.left();
+	rightMargin = m_margins.right();
 }
 
 void UsePrinterMarginsDialog::getPrinterMarginValues(const QString& printerName)
 {
-	m_ptsTopMargin=m_ptsBottomMargin=m_ptsLeftMargin=m_ptsRightMargin=0.0;
-	bool foundSize=PrinterUtil::getPrinterMarginValues(printerName, m_pageSize, m_ptsTopMargin, m_ptsBottomMargin, m_ptsLeftMargin, m_ptsRightMargin);
+	m_margins = QMarginsF(0.0, 0.0, 0.0, 0.0);
+	bool foundSize = PrinterUtil::getPrinterMarginValues(printerName, m_pageSize, m_margins);
 
 	topLineEdit->setEnabled(foundSize);
 	bottomLineEdit->setEnabled(foundSize);
@@ -71,8 +75,8 @@
 	rightLineEdit->setEnabled(foundSize);
 	okButton->setEnabled(foundSize);
 	
-	topLineEdit->setText(QString::number(m_ptsTopMargin * m_unitRatio,'g',4)+m_suffix);
-	bottomLineEdit->setText(QString::number(m_ptsBottomMargin * m_unitRatio,'g',4)+m_suffix);
-	leftLineEdit->setText(QString::number(m_ptsLeftMargin * m_unitRatio,'g',4)+m_suffix);
-	rightLineEdit->setText(QString::number(m_ptsRightMargin * m_unitRatio,'g',4)+m_suffix);	
+	topLineEdit->setText(QString::number(m_margins.top() * m_unitRatio,'g', 4) + m_suffix);
+	bottomLineEdit->setText(QString::number(m_margins.bottom() * m_unitRatio,'g', 4) + m_suffix);
+	leftLineEdit->setText(QString::number(m_margins.left() * m_unitRatio,'g', 4) + m_suffix);
+	rightLineEdit->setText(QString::number(m_margins.right() * m_unitRatio,'g', 4) + m_suffix);	
 }

Modified: trunk/Scribus/scribus/ui/useprintermarginsdialog.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23137&path=/trunk/Scribus/scribus/ui/useprintermarginsdialog.h
==============================================================================
--- trunk/Scribus/scribus/ui/useprintermarginsdialog.h	(original)
+++ trunk/Scribus/scribus/ui/useprintermarginsdialog.h	Mon Aug 19 05:37:03 2019
@@ -14,6 +14,9 @@
 #ifndef USEPRINTERMARGINSDIALOG_H
 #define USEPRINTERMARGINSDIALOG_H
 
+#include <QMarginsF>
+#include <QSizeF>
+
 #include "ui_useprintermarginsdialog.h"
 
 #include "scribusapi.h"
@@ -23,8 +26,9 @@
 	Q_OBJECT
 
 	public:
-		UsePrinterMarginsDialog(QWidget* parent, const QString& pageSize, double unitRatio, const QString& suffix);
+		UsePrinterMarginsDialog(QWidget* parent, const QSizeF& pageSize, const QString& pageSizeName, double unitRatio, const QString& suffix);
 		~UsePrinterMarginsDialog();
+
 		/**
 		 * Return the new printer sourced margins in PostScript points (72dpi).
 		 * @param topMargin 
@@ -32,15 +36,17 @@
 		 * @param leftMargin 
 		 * @param rightMargin 
 		 */
-		void getNewPrinterMargins(double &topMargin,double &bottomMargin,double &leftMargin,double &rightMargin);
+		void getNewPrinterMargins(double &topMargin, double &bottomMargin, double &leftMargin, double &rightMargin);
+
 	protected slots:
 		void getPrinterMarginValues(const QString& printerName);
 		
 	protected:
-		QString m_pageSize;
-		double m_unitRatio;
+		QSizeF  m_pageSize;
+		QString m_pageSizeName;
+		double  m_unitRatio;
 		QString m_suffix;
-		double m_ptsTopMargin,m_ptsBottomMargin,m_ptsLeftMargin,m_ptsRightMargin;
+		QMarginsF m_margins;
 };
 
 #endif

Modified: trunk/Scribus/scribus/util_printer.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23137&path=/trunk/Scribus/scribus/util_printer.cpp
==============================================================================
--- trunk/Scribus/scribus/util_printer.cpp	(original)
+++ trunk/Scribus/scribus/util_printer.cpp	Mon Aug 19 05:37:03 2019
@@ -83,21 +83,15 @@
 }
 #endif
 
-bool PrinterUtil::getPrinterMarginValues(const QString& printerName, const QString& pageSize, double& ptsTopMargin, double& ptsBottomMargin, double& ptsLeftMargin, double& ptsRightMargin)
+bool PrinterUtil::getPrinterMarginValues(const QString& printerName, const QSizeF& pageSize, QMarginsF& margins)
 {
-	bool retVal = false;
 	QPrinterInfo pInfo = QPrinterInfo::printerInfo(printerName);
-	if (!pInfo.isNull())
-	{
-		QPrinter printer(pInfo, QPrinter::HighResolution);
-		QMarginsF margs = printer.pageLayout().margins(QPageLayout::Point);
-		ptsTopMargin = margs.top();
-		ptsBottomMargin = margs.bottom();
-		ptsLeftMargin = margs.left();
-		ptsRightMargin = margs.right();
-		retVal = true;
-	}
-	return retVal;
+	if (pInfo.isNull())
+		return false;
+
+	QPrinter printer(pInfo, QPrinter::HighResolution);
+	margins = printer.pageLayout().margins(QPageLayout::Point);
+	return true;
 }
 
 PrintEngine PrinterUtil::getDefaultPrintEngine(const QString& printerName, bool toFile)

Modified: trunk/Scribus/scribus/util_printer.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23137&path=/trunk/Scribus/scribus/util_printer.h
==============================================================================
--- trunk/Scribus/scribus/util_printer.h	(original)
+++ trunk/Scribus/scribus/util_printer.h	Mon Aug 19 05:37:03 2019
@@ -10,6 +10,8 @@
 
 #include <QString>
 #include <QMap>
+#include <QMarginsF>
+#include <QSizeF>
 
 #include "scribusapi.h"
 #include "scribusstructs.h"
@@ -60,7 +62,7 @@
 		 * @param m_ptsRightMargin the page's right margin in points
 		\retval bool true on success
 		 */
-		static bool getPrinterMarginValues( const QString& printerName, const QString& pageSize, double& ptsTopMargin, double& m_ptsBottomMargin, double& m_ptsLeftMargin, double& m_ptsRightMargin);
+		static bool getPrinterMarginValues(const QString& printerName, const QSizeF& pageSize, QMarginsF& margins);
 		/**
 		 * @brief Get default print engine for a specific printer
 		 * @param printerName the printer name




More information about the scribus-commit mailing list