r14357 by cbradney - Allow new guides prefs pane to load/save values

scribus-commit scribus-commit at lists.scribus.net
Thu Nov 26 00:05:46 CET 2009


Revision: 14357
Author: cbradney
Date: 2009-11-25T13:45:41.247633Z
Commit message: Allow new guides prefs pane to load/save values

Changeset: 
M  /trunk/Scribus/scribus/ui/prefs_guides.cpp
M  /trunk/Scribus/scribus/ui/preferencesdialog.cpp
M  /trunk/Scribus/scribus/ui/prefs_guides.h
M  /trunk/Scribus/scribus/ui/prefs_guidesbase.ui

Diffs:
Index: scribus/ui/prefs_guides.cpp
===================================================================
--- scribus/ui/prefs_guides.cpp	(revision 14356)
+++ scribus/ui/prefs_guides.cpp	(revision 14357)
@@ -5,16 +5,170 @@
 for which a new license (GPL+exception) is in place.
 */
 
-#include "prefs_guides.h"
+#include <QColorDialog>
+#include "ui/prefs_guides.h"
+#include "prefsstructs.h"
+#include "scrspinbox.h"
+#include "units.h"
 
 Prefs_Guides::Prefs_Guides(QWidget* parent)
-	: QWidget(parent)
+	: Prefs_Pane(parent)
 {
 	setupUi(this);
+	languageChange();
 
+	connect(guideColorPushButton, SIGNAL(clicked()), this, SLOT(changeGuideColor()));
+	connect(marginColorPushButton, SIGNAL(clicked()), this, SLOT(changeMarginColor()));
+	connect(majorGridColorPushButton, SIGNAL(clicked()), this, SLOT(changeMajorColor()));
+	connect(minorGridColorPushButton, SIGNAL(clicked()), this, SLOT(changeMinorColor()));
+	connect(baselineGridColorPushButton, SIGNAL(clicked()), this, SLOT(changeBaselineColor()));
 }
 
 Prefs_Guides::~Prefs_Guides()
 {
 }
 
+void Prefs_Guides::languageChange()
+{
+	int i=guidePlacementComboBox->currentIndex();
+	guidePlacementComboBox->clear();
+	guidePlacementComboBox->addItem( tr ("In the Background") );
+	guidePlacementComboBox->addItem( tr ("In the Foreground") );
+	guidePlacementComboBox->setCurrentIndex(i<0?0:i);
+}
+
+void Prefs_Guides::restoreDefaults(struct ApplicationPrefs *prefsData)
+{
+	int docUnitIndex = prefsData->docSetupPrefs.docUnitIndex;
+	QString unitSuffix(unitGetSuffixFromIndex(docUnitIndex));
+	double unitRatio = unitGetRatioFromIndex(docUnitIndex);
+	int decimals = unitGetPrecisionFromIndex(docUnitIndex);
+	guidePlacementComboBox->setCurrentIndex(prefsData->guidesPrefs.guidePlacement ?0:1);
+	guideSnapDistanceSpinBox->setValue(prefsData->guidesPrefs.guideRad);
+	guideGrabRadiusSpinBox->setValue(prefsData->guidesPrefs.grabRadius);
+	visibilityGuidesCheckBox->setChecked(prefsData->guidesPrefs.guidesShown);
+	visibilityMarginsCheckBox->setChecked(prefsData->guidesPrefs.marginsShown);
+	visibilityGridCheckBox->setChecked(prefsData->guidesPrefs.gridShown);
+	visibilityBaselineGridCheckBox->setChecked(prefsData->guidesPrefs.baselineGridShown);
+	majorGridSpacingSpinBox->setMinimum(10 * unitRatio);
+	minorGridSpacingSpinBox->setMinimum(10 * unitRatio);
+	majorGridSpacingSpinBox->setMaximum(1000 * unitRatio);
+	minorGridSpacingSpinBox->setMaximum(1000 * unitRatio);
+	majorGridSpacingSpinBox->setDecimals( decimals );
+	minorGridSpacingSpinBox->setDecimals( decimals );
+	majorGridSpacingSpinBox->setSuffix( unitSuffix );
+	minorGridSpacingSpinBox->setSuffix( unitSuffix );
+	majorGridSpacingSpinBox->setValue(prefsData->guidesPrefs.majorGridSpacing  * unitRatio);
+	minorGridSpacingSpinBox->setValue(prefsData->guidesPrefs.minorGridSpacing  * unitRatio);
+	baselineGridSpacingSpinBox->setValue(prefsData->guidesPrefs.valueBaselineGrid);
+	baselineGridOffsetSpinBox->setValue(prefsData->guidesPrefs.offsetBaselineGrid);
+
+	QPixmap pm(100, 30);
+	pm.fill(prefsData->guidesPrefs.guideColor);
+	colorGuides = prefsData->guidesPrefs.guideColor;
+	guideColorPushButton->setText( QString::null );
+	guideColorPushButton->setIcon(pm);
+
+
+	pm.fill(prefsData->guidesPrefs.marginColor);
+	colorMargin = prefsData->guidesPrefs.marginColor;
+	marginColorPushButton->setText( QString::null );
+	marginColorPushButton->setIcon(pm);
+
+	pm.fill(prefsData->guidesPrefs.majorGridColor);
+	colorMajorGrid = prefsData->guidesPrefs.majorGridColor;
+	majorGridColorPushButton->setText( QString::null );
+	majorGridColorPushButton->setIcon(pm);
+
+	pm.fill(prefsData->guidesPrefs.minorGridColor);
+	colorMinorGrid = prefsData->guidesPrefs.minorGridColor;
+	minorGridColorPushButton->setText( QString::null );
+	minorGridColorPushButton->setIcon(pm);
+
+	pm.fill(prefsData->guidesPrefs.baselineGridColor);
+	colorBaselineGrid = prefsData->guidesPrefs.baselineGridColor;
+	baselineGridColorPushButton->setText( QString::null );
+	baselineGridColorPushButton->setIcon(pm);
+}
+
+void Prefs_Guides::saveGuiToPrefs(struct ApplicationPrefs *prefsData) const
+{
+	prefsData->guidesPrefs.guidePlacement=(guidePlacementComboBox->currentIndex()==0);
+	prefsData->guidesPrefs.guideRad=guideSnapDistanceSpinBox->value();
+	prefsData->guidesPrefs.grabRadius=guideGrabRadiusSpinBox->value();
+	prefsData->guidesPrefs.guidesShown=visibilityGuidesCheckBox->isChecked();
+	prefsData->guidesPrefs.marginsShown=visibilityMarginsCheckBox->isChecked();
+	prefsData->guidesPrefs.gridShown=visibilityGridCheckBox->isChecked();
+	prefsData->guidesPrefs.baselineGridShown=visibilityBaselineGridCheckBox->isChecked();
+	double unitRatio = unitGetRatioFromIndex(prefsData->docSetupPrefs.docUnitIndex);
+	prefsData->guidesPrefs.majorGridSpacing=majorGridSpacingSpinBox->value() / unitRatio;
+	prefsData->guidesPrefs.minorGridSpacing=minorGridSpacingSpinBox->value() / unitRatio;
+	prefsData->guidesPrefs.valueBaselineGrid=baselineGridSpacingSpinBox->value();
+	prefsData->guidesPrefs.offsetBaselineGrid=baselineGridOffsetSpinBox->value();
+	prefsData->guidesPrefs.guideColor=colorGuides;
+	prefsData->guidesPrefs.marginColor=colorMargin;
+	prefsData->guidesPrefs.majorGridColor=colorMajorGrid;
+	prefsData->guidesPrefs.minorGridColor=colorMinorGrid;
+	prefsData->guidesPrefs.baselineGridColor=colorBaselineGrid;
+}
+
+void Prefs_Guides::changeMajorColor()
+{
+	QColor newColor(QColorDialog::getColor(colorMajorGrid, this));
+	if (newColor.isValid())
+	{
+		QPixmap pm(54, 14);
+		pm.fill(newColor);
+		colorMajorGrid = newColor;
+		majorGridColorPushButton->setIcon(pm);
+	}
+}
+
+void Prefs_Guides::changeMinorColor()
+{
+	QColor newColor(QColorDialog::getColor(colorMinorGrid, this));
+	if (newColor.isValid())
+	{
+		QPixmap pm(54, 14);
+		pm.fill(newColor);
+		colorMinorGrid = newColor;
+		minorGridColorPushButton->setIcon(pm);
+	}
+}
+
+void Prefs_Guides::changeBaselineColor()
+{
+	QColor newColor(QColorDialog::getColor(colorBaselineGrid, this));
+	if (newColor.isValid())
+	{
+		QPixmap pm(54, 14);
+		pm.fill(newColor);
+		colorBaselineGrid = newColor;
+		baselineGridColorPushButton->setIcon(pm);
+	}
+}
+
+void Prefs_Guides::changeGuideColor()
+{
+	QColor newColor(QColorDialog::getColor(colorGuides, this));
+	if (newColor.isValid())
+	{
+		QPixmap pm(54, 14);
+		pm.fill(newColor);
+		colorGuides = newColor;
+		guideColorPushButton->setIcon(pm);
+	}
+}
+
+void Prefs_Guides::changeMarginColor()
+{
+	QColor newColor(QColorDialog::getColor(colorMargin, this));
+	if (newColor.isValid())
+	{
+		QPixmap pm(54, 14);
+		pm.fill(newColor);
+		colorMargin = newColor;
+		marginColorPushButton->setIcon(pm);
+	}
+}
+
Index: scribus/ui/prefs_guidesbase.ui
===================================================================
--- scribus/ui/prefs_guidesbase.ui	(revision 14356)
+++ scribus/ui/prefs_guidesbase.ui	(revision 14357)
@@ -62,7 +62,7 @@
             </widget>
            </item>
            <item row="0" column="1">
-            <widget class="QComboBox" name="comboBox"/>
+            <widget class="QComboBox" name="guidePlacementComboBox"/>
            </item>
            <item row="1" column="0">
             <widget class="QLabel" name="label_4">
@@ -72,7 +72,17 @@
             </widget>
            </item>
            <item row="1" column="1">
-            <widget class="ScrSpinBox" name="spinBox"/>
+            <widget class="ScrSpinBox" name="guideSnapDistanceSpinBox">
+             <property name="suffix">
+              <string> px</string>
+             </property>
+             <property name="minimum">
+              <number>1</number>
+             </property>
+             <property name="maximum">
+              <number>1000</number>
+             </property>
+            </widget>
            </item>
            <item row="2" column="0">
             <widget class="QLabel" name="label_3">
@@ -82,7 +92,17 @@
             </widget>
            </item>
            <item row="2" column="1">
-            <widget class="ScrSpinBox" name="spinBox_2"/>
+            <widget class="ScrSpinBox" name="guideGrabRadiusSpinBox">
+             <property name="suffix">
+              <string> px</string>
+             </property>
+             <property name="minimum">
+              <number>1</number>
+             </property>
+             <property name="maximum">
+              <number>1000</number>
+             </property>
+            </widget>
            </item>
           </layout>
          </item>
@@ -142,28 +162,28 @@
          <item>
           <layout class="QVBoxLayout" name="verticalLayout">
            <item>
-            <widget class="QCheckBox" name="checkBox_6">
+            <widget class="QCheckBox" name="visibilityGuidesCheckBox">
              <property name="text">
               <string>Guides</string>
              </property>
             </widget>
            </item>
            <item>
-            <widget class="QCheckBox" name="checkBox_2">
+            <widget class="QCheckBox" name="visibilityMarginsCheckBox">
              <property name="text">
               <string>Margins</string>
              </property>
             </widget>
            </item>
            <item>
-            <widget class="QCheckBox" name="checkBox_3">
+            <widget class="QCheckBox" name="visibilityGridCheckBox">
              <property name="text">
               <string>Page Grid</string>
              </property>
             </widget>
            </item>
            <item>
-            <widget class="QCheckBox" name="checkBox_4">
+            <widget class="QCheckBox" name="visibilityBaselineGridCheckBox">
              <property name="text">
               <string>Baseline Grid</string>
              </property>
@@ -337,9 +357,9 @@
             </widget>
            </item>
            <item row="0" column="1">
-            <widget class="QPushButton" name="pushButton_8">
+            <widget class="QPushButton" name="guideColorPushButton">
              <property name="text">
-              <string>PushButton</string>
+              <string/>
              </property>
             </widget>
            </item>
@@ -351,9 +371,9 @@
             </widget>
            </item>
            <item row="1" column="1">
-            <widget class="QPushButton" name="pushButton_7">
+            <widget class="QPushButton" name="marginColorPushButton">
              <property name="text">
-              <string>PushButton</string>
+              <string/>
              </property>
             </widget>
            </item>
@@ -365,9 +385,9 @@
             </widget>
            </item>
            <item row="2" column="1">
-            <widget class="QPushButton" name="pushButton_10">
+            <widget class="QPushButton" name="majorGridColorPushButton">
              <property name="text">
-              <string>PushButton</string>
+              <string/>
              </property>
             </widget>
            </item>
@@ -379,9 +399,9 @@
             </widget>
            </item>
            <item row="3" column="1">
-            <widget class="QPushButton" name="pushButton_9">
+            <widget class="QPushButton" name="minorGridColorPushButton">
              <property name="text">
-              <string>PushButton</string>
+              <string/>
              </property>
             </widget>
            </item>
@@ -393,9 +413,9 @@
             </widget>
            </item>
            <item row="4" column="1">
-            <widget class="QPushButton" name="pushButton_6">
+            <widget class="QPushButton" name="baselineGridColorPushButton">
              <property name="text">
-              <string>PushButton</string>
+              <string/>
              </property>
             </widget>
            </item>
@@ -440,7 +460,6 @@
       <zorder>line_4</zorder>
       <zorder></zorder>
       <zorder></zorder>
-      <zorder></zorder>
       <zorder>label_7</zorder>
       <zorder>label_6</zorder>
      </widget>
Index: scribus/ui/prefs_guides.h
===================================================================
--- scribus/ui/prefs_guides.h	(revision 14356)
+++ scribus/ui/prefs_guides.h	(revision 14357)
@@ -9,15 +9,35 @@
 #define PREFS_GUIDES_H
 
 #include "ui_prefs_guidesbase.h"
+#include "prefs_pane.h"
 #include "scribusapi.h"
 
-class SCRIBUS_API Prefs_Guides : public QWidget, Ui::Prefs_Guides
+class SCRIBUS_API Prefs_Guides : public Prefs_Pane, Ui::Prefs_Guides
 {
 	Q_OBJECT
 
 	public:
 		Prefs_Guides(QWidget* parent=0);
 		~Prefs_Guides();
+		virtual void restoreDefaults(struct ApplicationPrefs *prefsData);
+		virtual void saveGuiToPrefs(struct ApplicationPrefs *prefsData) const;
+
+	public slots:
+		void languageChange();
+
+	protected slots:
+		virtual void changeMajorColor();
+		virtual void changeMinorColor();
+		virtual void changeBaselineColor();
+		virtual void changeGuideColor();
+		virtual void changeMarginColor();
+
+	protected:
+		QColor colorGuides;
+		QColor colorMargin;
+		QColor colorMajorGrid;
+		QColor colorMinorGrid;
+		QColor colorBaselineGrid;
 };
 
 #endif // PREFS_GUIDES_H
Index: scribus/ui/preferencesdialog.cpp
===================================================================
--- scribus/ui/preferencesdialog.cpp	(revision 14356)
+++ scribus/ui/preferencesdialog.cpp	(revision 14357)
@@ -113,6 +113,7 @@
 	prefs_UserInterface->restoreDefaults(&localPrefs);
 	prefs_Paths->restoreDefaults(&localPrefs);
 	prefs_DocumentSetup->restoreDefaults(&localPrefs);
+	prefs_Guides->restoreDefaults(&localPrefs);
 	prefs_Typography->restoreDefaults(&localPrefs);
 	prefs_OperatorTools->restoreDefaults(&localPrefs);
 	prefs_ColorManagement->restoreDefaults(&localPrefs);
@@ -127,6 +128,7 @@
 	prefs_UserInterface->saveGuiToPrefs(&localPrefs);
 	prefs_Paths->saveGuiToPrefs(&localPrefs);
 	prefs_DocumentSetup->saveGuiToPrefs(&localPrefs);
+	prefs_Guides->saveGuiToPrefs(&localPrefs);
 	prefs_Typography->saveGuiToPrefs(&localPrefs);
 	prefs_OperatorTools->saveGuiToPrefs(&localPrefs);
 	prefs_ColorManagement->saveGuiToPrefs(&localPrefs);




More information about the scribus-commit mailing list