r14221 by cbradney - Split PresetLayout class out from marginwidget.h/cpp

scribus-commit scribus-commit at lists.scribus.net
Sun Oct 25 00:10:27 CEST 2009


Revision: 14221
Author: cbradney
Date: 2009-10-24T18:44:03.188122Z
Commit message: Split PresetLayout class out from marginwidget.h/cpp

Changeset: 
M  /trunk/Scribus/scribus/ui/newmarginwidget.cpp
A  /trunk/Scribus/scribus/ui/marginpresetlayout.cpp
M  /trunk/Scribus/scribus/ui/prefs_documentsetup.cpp
M  /trunk/Scribus/scribus/ui/newmarginwidget.h
M  /trunk/Scribus/scribus/ui/marginwidget.cpp
A  /trunk/Scribus/scribus/ui/marginpresetlayout.h
M  /trunk/Scribus/scribus/ui/marginwidget.h

Diffs:
Index: scribus/ui/marginpresetlayout.cpp
===================================================================
--- scribus/ui/marginpresetlayout.cpp	(revision 0)
+++ scribus/ui/marginpresetlayout.cpp	(revision 14221)
@@ -0,0 +1,71 @@
+/*
+For general Scribus (>=1.3.2) copyright and licensing information please refer
+to the COPYING file provided with the program. Following this notice may exist
+a copyright and/or license notice that predates the release of Scribus 1.3.2
+for which a new license (GPL+exception) is in place.
+*/
+#include "marginpresetlayout.h"
+
+PresetLayout::PresetLayout(QWidget *parent) : QComboBox(parent)
+{
+	addItem( tr("None", "layout type"), PresetLayout::none);
+	addItem( tr("Gutenberg"), PresetLayout::gutenberg);
+	addItem( tr("Magazine"), PresetLayout::magazine);
+	addItem( tr("Fibonacci"), PresetLayout::fibonacci);
+	addItem( tr("Golden Mean"), PresetLayout::goldencut);
+	addItem( tr("Nine Parts"), PresetLayout::nineparts);
+	setCurrentIndex(PresetLayout::none);
+
+	this->setToolTip( "<qt>" + tr("When you have selected a Document Layout other than Single Page, you can select a predefined page layout here. 'None' leaves margins as is, Gutenberg sets margins classically. 'Magazine' sets all margins to the same value. Leading is Left/Inside value.") + "</qt>");
+}
+
+MarginStruct PresetLayout::getMargins(int index, double pageWidth, double pageHeight, double leftMargin)
+{
+	MarginStruct ret;
+
+	updateMargins = true;
+
+	switch (index)
+	{
+		case PresetLayout::magazine:
+			ret.Top = ret.Bottom = ret.Left = ret.Right = leftMargin;
+			break;
+		case PresetLayout::gutenberg:
+			{
+				double ratio = pageHeight / pageWidth;
+				ret.Left = leftMargin;
+				ret.Top = leftMargin * ratio;
+				ret.Right = leftMargin * 2.0;
+				ret.Bottom = ret.Right * ratio;
+			}
+			break;
+		case PresetLayout::fibonacci:
+			ret.Left = leftMargin;
+			ret.Top = leftMargin / 2.0 * 3.0;
+			ret.Right = leftMargin / 2.0 * 5.0;
+			ret.Bottom = leftMargin / 2.0 * 8.0;
+			break;
+		case PresetLayout::goldencut:
+			ret.Left = leftMargin;
+			ret.Top = leftMargin / 2.0 * 3.4;
+			ret.Right = leftMargin / 2.0 * 4.8;
+			ret.Bottom = leftMargin / 2.0 * 6.8;
+			break;
+		case PresetLayout::nineparts:
+			ret.Left = pageWidth / 9.0;
+			ret.Top = pageHeight / 9.0;
+			ret.Right = pageWidth / 9.0 * 2.0;
+			ret.Bottom = pageHeight / 9.0 * 2.0;
+			break;
+		default:
+			updateMargins = false;
+			ret.Top = ret.Bottom = ret.Left = ret.Right = -1.0;
+	}
+	return ret;
+}
+
+bool PresetLayout::needUpdate() const
+{
+	return updateMargins;
+}
+
Index: scribus/ui/newmarginwidget.h
===================================================================
--- scribus/ui/newmarginwidget.h	(revision 14220)
+++ scribus/ui/newmarginwidget.h	(revision 14221)
@@ -10,6 +10,7 @@
 
 #include "ui_newmarginwidgetbase.h"
 #include "scribusapi.h"
+#include "scribusstructs.h"
 
 class SCRIBUS_API NewMarginWidget : public QWidget, Ui::NewMarginWidget
 {
@@ -19,10 +20,16 @@
 		NewMarginWidget(QWidget* parent=0);
 		~NewMarginWidget();
 
+		void setup(const MarginStruct& margs, int unitIndex=0, bool showPreset=true);
 		void setPageWidth(double);
 		void setPageHeight(double);
 		void setPageSize(const QString&);
 		void setNewUnitIndex(int);
+
+	protected:
+		MarginStruct marginData;
+		MarginStruct savedMarginData;
+		int savedPresetItem;
 };
 
 #endif // NEWMARGINWIDGET_H
Index: scribus/ui/newmarginwidget.cpp
===================================================================
--- scribus/ui/newmarginwidget.cpp	(revision 14220)
+++ scribus/ui/newmarginwidget.cpp	(revision 14221)
@@ -6,6 +6,10 @@
 */
 
 #include "newmarginwidget.h"
+#include "scrspinbox.h"
+#include "units.h"
+#include "ui/marginpresetlayout.h"
+#include "ui/useprintermarginsdialog.h"
 
 NewMarginWidget::NewMarginWidget(QWidget* parent)
 	: QWidget(parent)
@@ -18,6 +22,13 @@
 {
 }
 
+void NewMarginWidget::setup(const MarginStruct& margs, int unitIndex, bool showPreset)
+{
+	marginData=margs;
+	savedMarginData=margs;
+	savedPresetItem=PresetLayout::none;//we dont recheck if we are using a layout but always start at none
+}
+
 void NewMarginWidget::setPageWidth(double)
 {
 
Index: scribus/ui/marginwidget.cpp
===================================================================
--- scribus/ui/marginwidget.cpp	(revision 14220)
+++ scribus/ui/marginwidget.cpp	(revision 14221)
@@ -544,73 +544,6 @@
 	return BleedRight->value() / m_unitRatio;
 }
 
-
-/*
- * presets
- */
-PresetLayout::PresetLayout(QWidget *parent) : QComboBox(parent)
-{
-	addItem( tr("None", "layout type"), PresetLayout::none);
-	addItem( tr("Gutenberg"), PresetLayout::gutenberg);
-	addItem( tr("Magazine"), PresetLayout::magazine);
-	addItem( tr("Fibonacci"), PresetLayout::fibonacci);
-	addItem( tr("Golden Mean"), PresetLayout::goldencut);
-	addItem( tr("Nine Parts"), PresetLayout::nineparts);
-	setCurrentIndex(PresetLayout::none);
-
-	this->setToolTip( "<qt>" + tr("When you have selected a Document Layout other than Single Page, you can select a predefined page layout here. 'None' leaves margins as is, Gutenberg sets margins classically. 'Magazine' sets all margins to the same value. Leading is Left/Inside value.") + "</qt>");
-}
-
-MarginStruct PresetLayout::getMargins(int index, double pageWidth, double pageHeight, double leftMargin)
-{
-	MarginStruct ret;
-
-	updateMargins = true;
-
-	switch (index)
-	{
-		case PresetLayout::magazine:
-			ret.Top = ret.Bottom = ret.Left = ret.Right = leftMargin;
-			break;
-		case PresetLayout::gutenberg:
-			{
-				double ratio = pageHeight / pageWidth;
-				ret.Left = leftMargin;
-				ret.Top = leftMargin * ratio;
-				ret.Right = leftMargin * 2.0;
-				ret.Bottom = ret.Right * ratio;
-			}
-			break;
-		case PresetLayout::fibonacci:
-			ret.Left = leftMargin;
-			ret.Top = leftMargin / 2.0 * 3.0;
-			ret.Right = leftMargin / 2.0 * 5.0;
-			ret.Bottom = leftMargin / 2.0 * 8.0;
-			break;
-		case PresetLayout::goldencut:
-			ret.Left = leftMargin;
-			ret.Top = leftMargin / 2.0 * 3.4;
-			ret.Right = leftMargin / 2.0 * 4.8;
-			ret.Bottom = leftMargin / 2.0 * 6.8;
-			break;
-		case PresetLayout::nineparts:
-			ret.Left = pageWidth / 9.0;
-			ret.Top = pageHeight / 9.0;
-			ret.Right = pageWidth / 9.0 * 2.0;
-			ret.Bottom = pageHeight / 9.0 * 2.0;
-			break;
-		default:
-			updateMargins = false;
-			ret.Top = ret.Bottom = ret.Left = ret.Right = -1.0;
-	}
-	return ret;
-}
-
-bool PresetLayout::needUpdate() const
-{
-	return updateMargins;
-}
-
 const MarginStruct & MarginWidget::margins() const
 {
 	return marginData;
Index: scribus/ui/marginpresetlayout.h
===================================================================
--- scribus/ui/marginpresetlayout.h	(revision 0)
+++ scribus/ui/marginpresetlayout.h	(revision 14221)
@@ -0,0 +1,56 @@
+/*
+For general Scribus (>=1.3.2) copyright and licensing information please refer
+to the COPYING file provided with the program. Following this notice may exist
+a copyright and/or license notice that predates the release of Scribus 1.3.2
+for which a new license (GPL+exception) is in place.
+*/
+#ifndef MARGINPRESETLAYOUT_H
+#define MARGINPRESETLAYOUT_H
+
+#include "scribusapi.h"
+#include "scribusstructs.h"
+
+#include <QComboBox>
+
+/*! \brief This is inherited QComboBox widget used in MarginWidget as "Preset List".
+It contains functionality for margins setting in various ways.
+\author Petr Vanek, <petr at yarpen.cz>
+*/
+class SCRIBUS_API PresetLayout: public QComboBox
+{
+	Q_OBJECT
+
+public:
+	/*! \brief QComboBox like constructor. Values/names are set here. Tooltip etc. too. */
+	PresetLayout(QWidget *parent = 0);
+	~PresetLayout(){};
+
+	/*! \brief Compute the margins here.
+	\param index selected item
+	\param pageWidth width of the page. Taken from NewDoc dialog.
+	\param pageHeight height of the page. Taken from NewDoc dialog.
+	\param leftMargin leadin margin value. The others margins are set in various ratios related to this one.
+	*/
+	MarginStruct getMargins(int index, double pageWidth, double pageHeight, double leftMargin);
+
+	/*! \brief Integerized indexes for tr() strings*/
+	enum presetID
+	{
+		none = 0,
+		gutenberg = 1,
+		magazine = 2,
+		fibonacci = 3,
+		goldencut = 4,
+		nineparts = 5
+	};
+
+	/*! \brief returns updateMargins value */
+	bool needUpdate() const;
+
+private:
+	/*! \brief Flag if is needed to recompute values and disable widgets */
+	bool updateMargins;
+};
+
+
+#endif
Index: scribus/ui/marginwidget.h
===================================================================
--- scribus/ui/marginwidget.h	(revision 14220)
+++ scribus/ui/marginwidget.h	(revision 14221)
@@ -13,6 +13,7 @@
 #include <QComboBox>
 #include <QTabWidget>
 #include "linkbutton.h"
+#include "marginpresetlayout.h"
 class QCheckBox;
 class QPushButton;
 class QLabel;
@@ -21,47 +22,6 @@
 class ScrSpinBox;
 
 
-/*! \brief This is inherited QComboBox widget used in MarginWidget as "Preset List".
-It contains functionality for margins setting in various ways.
-\author Petr Vanek, <petr at yarpen.cz>
-*/
-class SCRIBUS_API PresetLayout: public QComboBox
-{
-	Q_OBJECT
-
-public:
-	/*! \brief QComboBox like constructor. Values/names are set here. Tooltip etc. too. */
-	PresetLayout(QWidget *parent = 0);
-	~PresetLayout(){};
-
-	/*! \brief Compute the margins here.
-	\param index selected item
-	\param pageWidth width of the page. Taken from NewDoc dialog.
-	\param pageHeight height of the page. Taken from NewDoc dialog.
-	\param leftMargin leadin margin value. The others margins are set in various ratios related to this one.
-	*/
-	MarginStruct getMargins(int index, double pageWidth, double pageHeight, double leftMargin);
-
-	/*! \brief Integerized indexes for tr() strings*/
-	enum presetID
-	{
-		none = 0,
-		gutenberg = 1,
-		magazine = 2,
-		fibonacci = 3,
-		goldencut = 4,
-		nineparts = 5
-	};
-
-	/*! \brief returns updateMargins value */
-	bool needUpdate() const;
-
-private:
-	/*! \brief Flag if is needed to recompute values and disable widgets */
-	bool updateMargins;
-};
-
-
 /*! \brief Widget for Margins setting.
 Used e.g. in "New Doc Dialog" or "Preferences".
 */
Index: scribus/ui/prefs_documentsetup.cpp
===================================================================
--- scribus/ui/prefs_documentsetup.cpp	(revision 14220)
+++ scribus/ui/prefs_documentsetup.cpp	(revision 14221)
@@ -134,10 +134,6 @@
 	marginGroup->setMarginPreset(prefsData->docSetupPrefs.marginPreset);
 	GroupAS->setChecked( prefsData->docSetupPrefs.AutoSave );
 	ASTime->setValue(prefsData->docSetupPrefs.AutoSaveTime / 1000 / 60);
-	connect(pageWidth, SIGNAL(valueChanged(double)), this, SLOT(setPageWidth(double)));
-	connect(pageHeight, SIGNAL(valueChanged(double)), this, SLOT(setPageHeight(double)));
-	connect(pageOrientationComboBox, SIGNAL(activated(int)), this, SLOT(setOrien(int)));
-	connect(pageSizeComboBox, SIGNAL(activated(const QString &)), this, SLOT(setPageSize()));
 	*/
 	unitChange();
 }
@@ -206,17 +202,8 @@
 	setSize(pageSizeComboBox->currentText());
 	pageWidthSpinBox->blockSignals(true);
 	pageHeightSpinBox->blockSignals(true);
-	if (orientation == 0)
+	if ((orientation==0 && pageSizeComboBox->currentText() == CommonStrings::trCustomPageSize) || orientation!=0)
 	{
-		if (pageSizeComboBox->currentText() == CommonStrings::trCustomPageSize)
-		{
-			double w = pageWidthSpinBox->value(), h = pageHeightSpinBox->value();
-			pageWidthSpinBox->setValue((orientation == portraitPage) ? qMin(w, h) : qMax(w, h));
-			pageHeightSpinBox->setValue((orientation == portraitPage) ? qMax(w, h) : qMin(w, h));
-		}
-	}
-	else
-	{
 		double w = pageWidthSpinBox->value(), h = pageHeightSpinBox->value();
 		pageWidthSpinBox->setValue((orientation == portraitPage) ? qMin(w, h) : qMax(w, h));
 		pageHeightSpinBox->setValue((orientation == portraitPage) ? qMax(w, h) : qMin(w, h));




More information about the scribus-commit mailing list