r15237 by cbradney - #7981: Allow reverse distribution when distributing by a set value

scribus-commit scribus-commit at lists.scribus.net
Sun Jun 20 01:00:56 CEST 2010


Revision: 15237
Author: cbradney
Date: 2010-06-19T22:56:26.828092Z
Commit message: #7981: Allow reverse distribution when distributing by a set value

Changeset: 
M  /trunk/Scribus/scribus/scribusdoc.cpp
M  /trunk/Scribus/scribus/ui/aligndistribute.ui
M  /trunk/Scribus/scribus/scribusdoc.h
M  /trunk/Scribus/scribus/ui/aligndistribute.cpp

Diffs:
Index: scribus/scribusdoc.cpp
===================================================================
--- scribus/scribusdoc.cpp	(revision 15236)
+++ scribus/scribusdoc.cpp	(revision 15237)
@@ -9446,7 +9446,7 @@
 }
 
 
-void ScribusDoc::itemSelection_DistributeDistH(bool usingDistance, double distance)
+void ScribusDoc::itemSelection_DistributeDistH(bool usingDistance, double distance, bool reverseDistribute)
 {
 	if (!startAlign())
 		return;
@@ -9464,6 +9464,7 @@
 	uint left=X1sorted.begin().value();
 	uint right=X2sorted[X2sorted.keys().back()];
 	double minX=AObjects[left].x2;
+	double maxX=AObjects[right].x2;
 	double separation=0.0;
 	if (!usingDistance)
 	{
@@ -9484,21 +9485,48 @@
 	}
 	else
 		separation=value2pts(distance, unitIndex());
-	double currX=minX;
-	for ( QMap<double,uint>::Iterator it = X1sorted.begin(); it != X1sorted.end(); ++it )
+	if (!reverseDistribute)
 	{
-		if (it.value()==left)
-			continue;
-		if (it.value()==right && !usingDistance)
-			continue;
-		currX+=separation;
+		double currX=minX;
+		for ( QMap<double,uint>::Iterator it = X1sorted.begin(); it != X1sorted.end(); ++it )
+		{
+			if (it.value()==left)
+				continue;
+			if (it.value()==right && !usingDistance)
+				continue;
+			currX+=separation;
 
-		double diff=currX-AObjects[it.value()].x1;
-		for (int j = 0; j < AObjects[it.value()].Objects.count(); ++j)
-			if (!AObjects[it.value()].Objects.at(j)->locked())
-				AObjects[it.value()].Objects.at(j)->moveBy(diff, 0.0);
-		currX+=AObjects[it.value()].width;
+			double diff=currX-AObjects[it.value()].x1;
+			for (int j = 0; j < AObjects[it.value()].Objects.count(); ++j)
+				if (!AObjects[it.value()].Objects.at(j)->locked())
+					AObjects[it.value()].Objects.at(j)->moveBy(diff, 0.0);
+			currX+=AObjects[it.value()].width;
+		}
 	}
+	else
+	{
+		QMapIterator<double,uint> it(X1sorted);
+		it.toBack();
+		double currX=maxX;
+		while (it.hasPrevious())
+		{
+			it.previous();
+			if (it.value()==right)
+			{
+				currX-=AObjects[it.value()].width;
+				continue;
+			}
+			if (it.value()==left && !usingDistance)
+				continue;
+			currX-=separation;
+
+			double diff=currX-AObjects[it.value()].x2;
+			for (int j = 0; j < AObjects[it.value()].Objects.count(); ++j)
+				if (!AObjects[it.value()].Objects.at(j)->locked())
+					AObjects[it.value()].Objects.at(j)->moveBy(diff, 0.0);
+			currX-=AObjects[it.value()].width;
+		}
+	}
 	endAlign();
 }
 
@@ -9623,7 +9651,7 @@
 }
 
 
-void ScribusDoc::itemSelection_DistributeDistV(bool usingDistance, double distance)
+void ScribusDoc::itemSelection_DistributeDistV(bool usingDistance, double distance, bool reverseDistribute)
 {
 	if (!startAlign())
 		return;
@@ -9641,6 +9669,7 @@
 	uint top=Y1sorted.begin().value();
 	uint bottom=Y2sorted[Y2sorted.keys().back()];
 	double minY=AObjects[top].y2;
+	double maxY=AObjects[bottom].y2;
 	double separation=0.0;
 	if (!usingDistance)
 	{
@@ -9661,21 +9690,48 @@
 	}
 	else
 		separation=value2pts(distance, unitIndex());
-	double currY=minY;
-	for ( QMap<double,uint>::Iterator it = Y1sorted.begin(); it != Y1sorted.end(); ++it )
+	if (!reverseDistribute)
 	{
-		if (it.value()==top)
-			continue;
-		if (it.value()==bottom && !usingDistance)
-			continue;
-		currY+=separation;
+		double currY=minY;
+		for ( QMap<double,uint>::Iterator it = Y1sorted.begin(); it != Y1sorted.end(); ++it )
+		{
+			if (it.value()==top)
+				continue;
+			if (it.value()==bottom && !usingDistance)
+				continue;
+			currY+=separation;
 
-		double diff=currY-AObjects[it.value()].y1;
-		for (int j = 0; j < AObjects[it.value()].Objects.count(); ++j)
-			if (!AObjects[it.value()].Objects.at(j)->locked())
-				AObjects[it.value()].Objects.at(j)->moveBy(0.0,diff);
-		currY+=AObjects[it.value()].height;
+			double diff=currY-AObjects[it.value()].y1;
+			for (int j = 0; j < AObjects[it.value()].Objects.count(); ++j)
+				if (!AObjects[it.value()].Objects.at(j)->locked())
+					AObjects[it.value()].Objects.at(j)->moveBy(0.0,diff);
+			currY+=AObjects[it.value()].height;
+		}
 	}
+	else
+	{
+		QMapIterator<double,uint> it(Y1sorted);
+		it.toBack();
+		double currY=maxY;
+		while (it.hasPrevious())
+		{
+			it.previous();
+			if (it.value()==bottom)
+			{
+				currY-=AObjects[it.value()].height;
+				continue;
+			}
+			if (it.value()==top && !usingDistance)
+				continue;
+			currY-=separation;
+
+			double diff=currY-AObjects[it.value()].y2;
+			for (int j = 0; j < AObjects[it.value()].Objects.count(); ++j)
+				if (!AObjects[it.value()].Objects.at(j)->locked())
+					AObjects[it.value()].Objects.at(j)->moveBy(0.0, diff);
+			currY-=AObjects[it.value()].height;
+		}
+	}
 	endAlign();
 	usingDistance=false;
 }
Index: scribus/scribusdoc.h
===================================================================
--- scribus/scribusdoc.h	(revision 15236)
+++ scribus/scribusdoc.h	(revision 15237)
@@ -1248,12 +1248,12 @@
 	void itemSelection_AlignTopOut(AlignTo currAlignTo, AlignMethod currAlignMethod, double guidePosition);
 	void itemSelection_AlignTopIn(AlignTo currAlignTo, AlignMethod currAlignMethod, double guidePosition);
 
-	void itemSelection_DistributeDistH(bool usingDistance=false, double distance=0.0);
+	void itemSelection_DistributeDistH(bool usingDistance=false, double distance=0.0, bool reverseDistribute=false);
 	void itemSelection_DistributeAcrossPage(bool useMargins=false);
 	void itemSelection_DistributeRight();
 	void itemSelection_DistributeBottom();
 	void itemSelection_DistributeCenterH();
-	void itemSelection_DistributeDistV(bool usingDistance=false, double distance=0.0);
+	void itemSelection_DistributeDistV(bool usingDistance=false, double distance=0.0, bool reverseDistribute=false);
 	void itemSelection_DistributeDownPage(bool useMargins=false);
 	void itemSelection_DistributeLeft();
 	void itemSelection_DistributeCenterV();
Index: scribus/ui/aligndistribute.ui
===================================================================
--- scribus/ui/aligndistribute.ui	(revision 15236)
+++ scribus/ui/aligndistribute.ui	(revision 15237)
@@ -9,8 +9,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>262</width>
-    <height>218</height>
+    <width>253</width>
+    <height>272</height>
    </rect>
   </property>
   <property name="minimumSize">
@@ -248,7 +248,7 @@
          <property name="sizeHint" stdset="0">
           <size>
            <width>20</width>
-           <height>40</height>
+           <height>0</height>
           </size>
          </property>
         </spacer>
@@ -259,10 +259,7 @@
       <attribute name="title">
        <string>Distribute</string>
       </attribute>
-      <layout class="QVBoxLayout">
-       <property name="margin">
-        <number>0</number>
-       </property>
+      <layout class="QVBoxLayout" name="verticalLayout_2">
        <item>
         <layout class="QHBoxLayout">
          <item>
@@ -494,6 +491,49 @@
         </layout>
        </item>
        <item>
+        <layout class="QHBoxLayout" name="horizontalLayout_2">
+         <item>
+          <spacer name="spacer">
+           <property name="orientation">
+            <enum>Qt::Horizontal</enum>
+           </property>
+           <property name="sizeType">
+            <enum>QSizePolicy::Expanding</enum>
+           </property>
+           <property name="sizeHint" stdset="0">
+            <size>
+             <width>40</width>
+             <height>20</height>
+            </size>
+           </property>
+          </spacer>
+         </item>
+         <item>
+          <widget class="QCheckBox" name="reverseDistributionCheckBox">
+           <property name="text">
+            <string>Reverse Distribution</string>
+           </property>
+          </widget>
+         </item>
+         <item>
+          <spacer name="spacer_2">
+           <property name="orientation">
+            <enum>Qt::Horizontal</enum>
+           </property>
+           <property name="sizeType">
+            <enum>QSizePolicy::Expanding</enum>
+           </property>
+           <property name="sizeHint" stdset="0">
+            <size>
+             <width>40</width>
+             <height>20</height>
+            </size>
+           </property>
+          </spacer>
+         </item>
+        </layout>
+       </item>
+       <item>
         <spacer>
          <property name="orientation">
           <enum>Qt::Vertical</enum>
@@ -504,7 +544,7 @@
          <property name="sizeHint" stdset="0">
           <size>
            <width>20</width>
-           <height>16</height>
+           <height>0</height>
           </size>
          </property>
         </spacer>
@@ -568,7 +608,7 @@
          <property name="sizeHint" stdset="0">
           <size>
            <width>20</width>
-           <height>40</height>
+           <height>0</height>
           </size>
          </property>
         </spacer>
Index: scribus/ui/aligndistribute.cpp
===================================================================
--- scribus/ui/aligndistribute.cpp	(revision 15236)
+++ scribus/ui/aligndistribute.cpp	(revision 15237)
@@ -165,6 +165,8 @@
 
 	distributeDistLabel->setText( tr( "&Distance:" ) );
 	distributeDistSpinBox->setToolTip( tr( "Distribute the items with the distance specified" ) );
+
+	reverseDistributionCheckBox->setToolTip( tr("When distributing by a set distance, reverse the direction of the distribution of items") );
 	
 	guideInfoTextNone = tr("None Selected");
 
@@ -352,7 +354,7 @@
 void AlignDistributePalette::distributeDistH(bool usingDistance)
 {
 	if (currDoc!=NULL)
-		currDoc->itemSelection_DistributeDistH(usingDistance, distributeDistSpinBox->value());
+		currDoc->itemSelection_DistributeDistH(usingDistance, distributeDistSpinBox->value(), reverseDistributionCheckBox->isChecked());
 }
 
 void AlignDistributePalette::distributeDistValH()
@@ -408,7 +410,7 @@
 void AlignDistributePalette::distributeDistV(bool usingDistance)
 {
 	if (currDoc!=NULL)
-		currDoc->itemSelection_DistributeDistV(usingDistance, distributeDistSpinBox->value());
+		currDoc->itemSelection_DistributeDistV(usingDistance, distributeDistSpinBox->value(), reverseDistributionCheckBox->isChecked());
 }
 
 void AlignDistributePalette::distributeDistValV()




More information about the scribus-commit mailing list