r15220 by cbradney - #8392: Apply patch to allow resize for alignment

scribus-commit scribus-commit at lists.scribus.net
Fri Jun 18 00:50:37 CEST 2010


Revision: 15220
Author: cbradney
Date: 2010-06-17T22:45:10.627254Z
Commit message: #8392: Apply patch to allow resize for alignment

Changeset: 
M  /trunk/Scribus/scribus/prefsmanager.cpp
M  /trunk/Scribus/scribus/ui/aligndistribute.h
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 15219)
+++ scribus/scribusdoc.cpp	(revision 15220)
@@ -8819,9 +8819,68 @@
 	regionsChanged()->update(QRectF());
 }
 
+void ScribusDoc::itemSelection_AlignItemRight(int i, double newX, AlignMethod how)
+{
+	double diff=newX-AObjects[i].x2;
+	double width=AObjects[i].x2-AObjects[i].x1;
+	bool resize = (how == alignByResizing && diff > -width);
+	for (int j = 0; j < AObjects[i].Objects.count(); ++j)
+		if (!AObjects[i].Objects.at(j)->locked()) {
+			if (resize) {
+				AObjects[i].Objects.at(j)->resizeBy(diff, 0.0);
+				AObjects[i].Objects.at(j)->updateClip();
+			}
+			else AObjects[i].Objects.at(j)->moveBy(diff, 0.0);
+		}
+}
 
-void ScribusDoc::itemSelection_AlignLeftOut(AlignTo currAlignTo, double guidePosition)
+void ScribusDoc::itemSelection_AlignItemLeft(int i, double newX, AlignMethod how)
 {
+	double diff=newX-AObjects[i].x1;
+	double width=AObjects[i].x2-AObjects[i].x1;
+	bool resize = (how == alignByResizing && -diff > -width);
+	for (int j = 0; j < AObjects[i].Objects.count(); ++j)
+		if (!AObjects[i].Objects.at(j)->locked()) {
+			AObjects[i].Objects.at(j)->moveBy(diff, 0.0);
+			if (resize) {
+				AObjects[i].Objects.at(j)->resizeBy(-diff, 0.0);
+				AObjects[i].Objects.at(j)->updateClip();
+			}
+		}
+}
+
+void ScribusDoc::itemSelection_AlignItemBottom(int i, double newY, AlignMethod how)
+{
+	double diff=newY-AObjects[i].y2;
+	double height=AObjects[i].y2-AObjects[i].y1;
+	bool resize = (how == alignByResizing && diff > -height);
+	for (int j = 0; j < AObjects[i].Objects.count(); ++j)
+		if (!AObjects[i].Objects.at(j)->locked()) {
+			if (resize) {
+				AObjects[i].Objects.at(j)->resizeBy(0.0, diff);
+				AObjects[i].Objects.at(j)->updateClip();
+			}
+			else AObjects[i].Objects.at(j)->moveBy(0.0, diff);
+		}
+}
+
+void ScribusDoc::itemSelection_AlignItemTop(int i, double newY, AlignMethod how)
+{
+	double diff=newY-AObjects[i].y1;
+	double height=AObjects[i].y2-AObjects[i].y1;
+	bool resize = (how == alignByResizing && -diff > -height);
+	for (int j = 0; j < AObjects[i].Objects.count(); ++j)
+		if (!AObjects[i].Objects.at(j)->locked()) {
+			AObjects[i].Objects.at(j)->moveBy(0.0, diff);
+			if (resize) {
+				AObjects[i].Objects.at(j)->resizeBy(0.0, -diff);
+				AObjects[i].Objects.at(j)->updateClip();
+			}
+		}
+}
+
+void ScribusDoc::itemSelection_AlignLeftOut(AlignTo currAlignTo, AlignMethod currAlignMethod, double guidePosition)
+{
 	if (!startAlign())
 		return;
 	uint alignObjectsCount=AObjects.count();
@@ -8853,17 +8912,12 @@
 			break;
 	}
 	for (int i = loopStart; i <= loopEnd; ++i)
-	{
-		double diff=newX-AObjects[i].x2;
-		for (int j = 0; j < AObjects[i].Objects.count(); ++j)
-			if (!AObjects[i].Objects.at(j)->locked())
-				AObjects[i].Objects.at(j)->moveBy(diff, 0.0);
-	}
+		itemSelection_AlignItemRight(i, newX, currAlignMethod);
 	endAlign();
 }
 
 
-void ScribusDoc::itemSelection_AlignLeftIn(AlignTo currAlignTo, double guidePosition)
+void ScribusDoc::itemSelection_AlignLeftIn(AlignTo currAlignTo, AlignMethod currAlignMethod, double guidePosition)
 {
 	if (!startAlign())
 		return;
@@ -8896,17 +8950,12 @@
 			break;
 	}
 	for (int i = loopStart; i <= loopEnd; ++i)
-	{
-		double diff=newX-AObjects[i].x1;
-		for (int j = 0; j < AObjects[i].Objects.count(); ++j)
-			if (!AObjects[i].Objects.at(j)->locked())
-				AObjects[i].Objects.at(j)->moveBy(diff, 0.0);
-	}
+		itemSelection_AlignItemLeft(i, newX, currAlignMethod);
 	endAlign();
 }
 
 
-void ScribusDoc::itemSelection_AlignCenterHor(AlignTo currAlignTo, double guidePosition)
+void ScribusDoc::itemSelection_AlignCenterHor(AlignTo currAlignTo, AlignMethod currAlignMethod, double guidePosition)
 {
 	if (!startAlign())
 		return;
@@ -8960,7 +9009,7 @@
 }
 
 
-void ScribusDoc::itemSelection_AlignRightIn(AlignTo currAlignTo, double guidePosition)
+void ScribusDoc::itemSelection_AlignRightIn(AlignTo currAlignTo, AlignMethod currAlignMethod, double guidePosition)
 {
 	if (!startAlign())
 		return;
@@ -8995,17 +9044,12 @@
 			break;
 	}
 	for (int i = loopStart; i <= loopEnd; ++i)
-	{
-		double diff=newX-AObjects[i].x2;
-		for (int j = 0; j < AObjects[i].Objects.count(); ++j)
-			if (!AObjects[i].Objects.at(j)->locked())
-				AObjects[i].Objects.at(j)->moveBy(diff, 0.0);
-	}
+		itemSelection_AlignItemRight(i, newX, currAlignMethod);
 	endAlign();
 }
 
 
-void ScribusDoc::itemSelection_AlignRightOut(AlignTo currAlignTo, double guidePosition)
+void ScribusDoc::itemSelection_AlignRightOut(AlignTo currAlignTo, AlignMethod currAlignMethod, double guidePosition)
 {
 	if (!startAlign())
 		return;
@@ -9040,17 +9084,12 @@
 			break;
 	}
 	for (int i = loopStart; i <= loopEnd; ++i)
-	{
-		double diff=newX-AObjects[i].x1;
-		for (int j = 0; j < AObjects[i].Objects.count(); ++j)
-			if (!AObjects[i].Objects.at(j)->locked())
-				AObjects[i].Objects.at(j)->moveBy(diff, 0.0);
-	}
+		itemSelection_AlignItemLeft(i, newX, currAlignMethod);
 	endAlign();
 }
 
 
-void ScribusDoc::itemSelection_AlignTopOut(AlignTo currAlignTo, double guidePosition)
+void ScribusDoc::itemSelection_AlignTopOut(AlignTo currAlignTo, AlignMethod currAlignMethod, double guidePosition)
 {
 	if (!startAlign())
 		return;
@@ -9083,17 +9122,12 @@
 			break;
 	}
 	for (int i = loopStart; i <= loopEnd; ++i)
-	{
-		double diff=newY-AObjects[i].y2;
-		for (int j = 0; j < AObjects[i].Objects.count(); ++j)
-			if (!AObjects[i].Objects.at(j)->locked())
-				AObjects[i].Objects.at(j)->moveBy(0.0, diff);
-	}
+		itemSelection_AlignItemBottom(i, newY, currAlignMethod);
 	endAlign();
 }
 
 
-void ScribusDoc::itemSelection_AlignTopIn(AlignTo currAlignTo, double guidePosition)
+void ScribusDoc::itemSelection_AlignTopIn(AlignTo currAlignTo, AlignMethod currAlignMethod, double guidePosition)
 {
 	if (!startAlign())
 		return;
@@ -9126,17 +9160,12 @@
 			break;
 	}
 	for (int i = loopStart; i <= loopEnd; ++i)
-	{
-		double diff=newY-AObjects[i].y1;
-		for (int j = 0; j < AObjects[i].Objects.count(); ++j)
-			if (!AObjects[i].Objects.at(j)->locked())
-				AObjects[i].Objects.at(j)->moveBy(0.0, diff);
-	}
+		itemSelection_AlignItemTop(i, newY, currAlignMethod);
 	endAlign();
 }
 
 
-void ScribusDoc::itemSelection_AlignCenterVer(AlignTo currAlignTo, double guidePosition)
+void ScribusDoc::itemSelection_AlignCenterVer(AlignTo currAlignTo, AlignMethod currAlignMethod, double guidePosition)
 {
 	if (!startAlign())
 		return;
@@ -9190,7 +9219,7 @@
 }
 
 
-void ScribusDoc::itemSelection_AlignBottomIn(AlignTo currAlignTo, double guidePosition)
+void ScribusDoc::itemSelection_AlignBottomIn(AlignTo currAlignTo, AlignMethod currAlignMethod, double guidePosition)
 {
 	if (!startAlign())
 		return;
@@ -9225,17 +9254,12 @@
 			break;
 	}
 	for (int i = loopStart; i <= loopEnd; ++i)
-	{
-		double diff=newY-AObjects[i].y2;
-		for (int j = 0; j < AObjects[i].Objects.count(); ++j)
-			if (!AObjects[i].Objects.at(j)->locked())
-				AObjects[i].Objects.at(j)->moveBy(0.0, diff);
-	}
+		itemSelection_AlignItemBottom(i, newY, currAlignMethod);
 	endAlign();
 }
 
 
-void ScribusDoc::itemSelection_AlignBottomOut(AlignTo currAlignTo, double guidePosition)
+void ScribusDoc::itemSelection_AlignBottomOut(AlignTo currAlignTo, AlignMethod currAlignMethod, double guidePosition)
 {
 	if (!startAlign())
 		return;
@@ -9270,12 +9294,7 @@
 			break;
 	}
 	for (int i = loopStart; i <= loopEnd; ++i)
-	{
-		double diff=newY-AObjects[i].y1;
-		for (int j = 0; j < AObjects[i].Objects.count(); ++j)
-			if (!AObjects[i].Objects.at(j)->locked())
-				AObjects[i].Objects.at(j)->moveBy(0.0, diff);
-	}
+		itemSelection_AlignItemTop(i, newY, currAlignMethod);
 	endAlign();
 }
 
Index: scribus/prefsmanager.cpp
===================================================================
--- scribus/prefsmanager.cpp	(revision 15219)
+++ scribus/prefsmanager.cpp	(revision 15220)
@@ -148,47 +148,6 @@
 	csm.initialiseDefaultPrefs(appPrefs);
 	csm.findPaletteLocations();
 	csm.findPalettes();
-	/*
-	QString pfadC = ScPaths::instance().libDir()+"swatches/";
-	QString pfadC2 = pfadC + "Scribus_X11.txt";
-	QFile fiC(pfadC2);
-	if (!fiC.exists())
-	{
-		appPrefs.colorPrefs.DColors.insert("White", ScColor(0, 0, 0, 0));
-		appPrefs.colorPrefs.DColors.insert("Black", ScColor(0, 0, 0, 255));
-		appPrefs.colorPrefs.DColors.insert("Blue", ScColor(255, 255, 0, 0));
-		appPrefs.colorPrefs.DColors.insert("Cyan", ScColor(255, 0, 0, 0));
-		appPrefs.colorPrefs.DColors.insert("Green", ScColor(255, 0, 255, 0));
-		appPrefs.colorPrefs.DColors.insert("Red", ScColor(0, 255, 255, 0));
-		appPrefs.colorPrefs.DColors.insert("Yellow", ScColor(0, 0, 255, 0));
-		appPrefs.colorPrefs.DColors.insert("Magenta", ScColor(0, 255, 0, 0));
-		appPrefs.colorPrefs.DColorSet = "Scribus_Small";
-	}
-	else
-	{
-		if (fiC.open(IO_ReadOnly))
-		{
-			QString ColorEn, Cname;
-			int Rval, Gval, Bval;
-			QTextStream tsC(&fiC);
-			ColorEn = tsC.readLine();
-			while (!tsC.atEnd())
-			{
-				ColorEn = tsC.readLine();
-				QTextStream CoE(&ColorEn, IO_ReadOnly);
-				CoE >> Rval;
-				CoE >> Gval;
-				CoE >> Bval;
-				CoE >> Cname;
-				ScColor tmp;
-				tmp.setColorRGB(Rval, Gval, Bval);
-				appPrefs.colorPrefs.DColors.insert(Cname, tmp);
-			}
-			fiC.close();
-		}
-		appPrefs.colorPrefs.DColorSet = "X11 RGB-Set";
-	}
-	*/
 
 	appPrefs.uiPrefs.wheelJump = 40;
 	/** Set Default window position and size to sane default values which should work on every screen */
Index: scribus/scribusdoc.h
===================================================================
--- scribus/scribusdoc.h	(revision 15219)
+++ scribus/scribusdoc.h	(revision 15220)
@@ -863,6 +863,7 @@
 	void updateAllItemQColors();
 	//! @brief Some internal align tools
 	typedef enum {alignFirst, alignLast, alignPage, alignMargins, alignGuide, alignSelection } AlignTo;
+	typedef enum {alignByMoving, alignByResizing } AlignMethod;
 	void buildAlignItemList(Selection* customSelection=0);
 	bool startAlign();
 	void endAlign();
@@ -1230,16 +1231,21 @@
 	void itemSelection_SetImageScale(double x, double y, Selection* customSelection=0);
 	void itemSelection_SetImageScaleAndOffset(double ox, double oy, double sx, double sy, Selection* customSelection=0);
 	void itemSelection_SetImageRotation(double rot, Selection* customSelection=0);
-	void itemSelection_AlignLeftOut(AlignTo currAlignTo, double guidePosition);
-	void itemSelection_AlignRightOut(AlignTo currAlignTo, double guidePosition);
-	void itemSelection_AlignBottomIn(AlignTo currAlignTo, double guidePosition);
-	void itemSelection_AlignRightIn(AlignTo currAlignTo, double guidePosition);
-	void itemSelection_AlignBottomOut(AlignTo currAlignTo, double guidePosition);
-	void itemSelection_AlignCenterHor(AlignTo currAlignTo, double guidePosition);
-	void itemSelection_AlignLeftIn(AlignTo currAlignTo, double guidePosition);
-	void itemSelection_AlignCenterVer(AlignTo currAlignTo, double guidePosition);
-	void itemSelection_AlignTopOut(AlignTo currAlignTo, double guidePosition);
-	void itemSelection_AlignTopIn(AlignTo currAlignTo, double guidePosition);
+	void itemSelection_AlignItemLeft(int i, double newX, AlignMethod how);
+	void itemSelection_AlignItemRight(int i, double newX, AlignMethod how);
+	void itemSelection_AlignItemTop(int i, double newY, AlignMethod how);
+	void itemSelection_AlignItemBottom(int i, double newY, AlignMethod how);
+	void itemSelection_AlignLeftOut(AlignTo currAlignTo, AlignMethod currAlignMethod, double guidePosition);
+	void itemSelection_AlignRightOut(AlignTo currAlignTo, AlignMethod currAlignMethod, double guidePosition);
+	void itemSelection_AlignBottomIn(AlignTo currAlignTo, AlignMethod currAlignMethod, double guidePosition);
+	void itemSelection_AlignRightIn(AlignTo currAlignTo, AlignMethod currAlignMethod, double guidePosition);
+	void itemSelection_AlignBottomOut(AlignTo currAlignTo, AlignMethod currAlignMethod, double guidePosition);
+	void itemSelection_AlignCenterHor(AlignTo currAlignTo, AlignMethod currAlignMethod, double guidePosition);
+	void itemSelection_AlignLeftIn(AlignTo currAlignTo, AlignMethod currAlignMethod, double guidePosition);
+	void itemSelection_AlignCenterVer(AlignTo currAlignTo, AlignMethod currAlignMethod, double guidePosition);
+	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_DistributeAcrossPage(bool useMargins=false);
 	void itemSelection_DistributeRight();
Index: scribus/ui/aligndistribute.ui
===================================================================
--- scribus/ui/aligndistribute.ui	(revision 15219)
+++ scribus/ui/aligndistribute.ui	(revision 15220)
@@ -91,6 +91,22 @@
            <item row="0" column="1">
             <widget class="QComboBox" name="alignRelativeToCombo"/>
            </item>
+           <item row="2" column="0" >
+            <widget class="QLabel" name="alignMoveOrResizeLabel" >
+             <property name="text" >
+              <string>&amp;Align Sides By:</string>
+             </property>
+             <property name="wordWrap" >
+              <bool>false</bool>
+             </property>
+             <property name="buddy" >
+              <cstring>alignMoveOrResizeCombo</cstring>
+             </property>
+            </widget>
+           </item>
+           <item row="2" column="1" >
+            <widget class="QComboBox" name="alignMoveOrResizeCombo" />
+           </item>
           </layout>
          </item>
          <item>
Index: scribus/ui/aligndistribute.h
===================================================================
--- scribus/ui/aligndistribute.h	(revision 15219)
+++ scribus/ui/aligndistribute.h	(revision 15220)
@@ -101,11 +101,13 @@
 	void swapRight();
 	
 	void alignToChanged(int);
+	void alignMethodChanged(int);
 
 private:
 	void init();
 	UndoManager *undoManager;
 	ScribusDoc::AlignTo currAlignTo;
+	ScribusDoc::AlignMethod currAlignMethod;
 	QList<AlignObjs> *alignObjects;
 	ScribusDoc *currDoc;
 	qreal unitRatio;
Index: scribus/ui/aligndistribute.cpp
===================================================================
--- scribus/ui/aligndistribute.cpp	(revision 15219)
+++ scribus/ui/aligndistribute.cpp	(revision 15220)
@@ -102,6 +102,13 @@
 	alignRelativeToCombo->setCurrentIndex(alignComboValue);
 	alignRelativeToCombo->setToolTip( tr( "<qt>Align relative to the:<ul><li>First selected item</li><li>Second Selected Item</li><li>The current page</li><li>The margins of the current page</li><li>A Guide</li><li>The selection</ul></qt>" ) );
 	alignToChanged(alignComboValue);
+	alignMoveOrResizeLabel->setText( tr( "&Align Sides By:" ) );
+	int alignMethodValue=alignMoveOrResizeCombo->currentIndex();
+	alignMoveOrResizeCombo->clear();
+	alignMoveOrResizeCombo->addItem( tr("Moving (Preserve Size)") );
+	alignMoveOrResizeCombo->addItem( tr("Resizing (Preserve Opposite Side)") );
+	alignMoveOrResizeCombo->setToolTip( tr( "<qt>When aligning one side of an item:<ul><li>Always move the other side too (preserve existing width and height), or </li><li>Keep the other side fixed (resize the item instead of moving it) whenever possible</li></ul></qt>" ));
+	alignMethodChanged(alignMethodValue);
 	alignGuideLineEdit->setToolTip( tr( "The location of the selected guide to align to" ) );
 	alignLeftOutToolButton->setText( QString::null );
 	alignLeftOutToolButton->setToolTip( tr( "Align right sides of items to left side of anchor" ) );
@@ -231,7 +238,9 @@
 	
 	alignRelativeToCombo->setCurrentIndex(0);
 	alignToChanged(0);
+	alignMethodChanged(0);
 	connect(alignRelativeToCombo, SIGNAL(activated(int)), this, SLOT(alignToChanged(int)));
+	connect(alignMoveOrResizeCombo, SIGNAL(activated(int)), this, SLOT(alignMethodChanged(int)));
 	
 	unitRatio=1.0;
 	guideDirection=-1;
@@ -263,63 +272,63 @@
 void AlignDistributePalette::alignLeftOut()
 {
 	if (currDoc!=NULL)
-		currDoc->itemSelection_AlignLeftOut(currAlignTo, guidePosition);
+		currDoc->itemSelection_AlignLeftOut(currAlignTo, currAlignMethod, guidePosition);
 }
 
 void AlignDistributePalette::alignLeftIn()
 {
 	if (currDoc!=NULL)
-		currDoc->itemSelection_AlignLeftIn(currAlignTo, guidePosition);
+		currDoc->itemSelection_AlignLeftIn(currAlignTo, currAlignMethod, guidePosition);
 }
 
 void AlignDistributePalette::alignCenterHor()
 {
 	if (currDoc!=NULL)
-		currDoc->itemSelection_AlignCenterHor(currAlignTo, guidePosition);
+		currDoc->itemSelection_AlignCenterHor(currAlignTo, currAlignMethod, guidePosition);
 }
 
 void AlignDistributePalette::alignRightIn()
 {
 	if (currDoc!=NULL)
-		currDoc->itemSelection_AlignRightIn(currAlignTo, guidePosition);
+		currDoc->itemSelection_AlignRightIn(currAlignTo, currAlignMethod, guidePosition);
 }
 
 void AlignDistributePalette::alignRightOut()
 {
 	if (currDoc!=NULL)
-		currDoc->itemSelection_AlignRightOut(currAlignTo, guidePosition);
+		currDoc->itemSelection_AlignRightOut(currAlignTo, currAlignMethod, guidePosition);
 }
 
 void AlignDistributePalette::alignTopOut()
 {
 	if (currDoc!=NULL)
-		currDoc->itemSelection_AlignTopOut(currAlignTo, guidePosition);
+		currDoc->itemSelection_AlignTopOut(currAlignTo, currAlignMethod, guidePosition);
 }
 
 void AlignDistributePalette::alignTopIn()
 {
 	if (currDoc!=NULL)
-		currDoc->itemSelection_AlignTopIn(currAlignTo, guidePosition);
+		currDoc->itemSelection_AlignTopIn(currAlignTo, currAlignMethod, guidePosition);
 }
 
 
 void AlignDistributePalette::alignCenterVer()
 {
 	if (currDoc!=NULL)
-		currDoc->itemSelection_AlignCenterVer(currAlignTo, guidePosition);
+		currDoc->itemSelection_AlignCenterVer(currAlignTo, currAlignMethod, guidePosition);
 }
 
 
 void AlignDistributePalette::alignBottomIn()
 {
 	if (currDoc!=NULL)
-		currDoc->itemSelection_AlignBottomIn(currAlignTo, guidePosition);
+		currDoc->itemSelection_AlignBottomIn(currAlignTo, currAlignMethod, guidePosition);
 }
 
 void AlignDistributePalette::alignBottomOut()
 {
 	if (currDoc!=NULL)
-		currDoc->itemSelection_AlignBottomOut(currAlignTo, guidePosition);
+		currDoc->itemSelection_AlignBottomOut(currAlignTo, currAlignMethod, guidePosition);
 }
 
 void AlignDistributePalette::distributeLeft()
@@ -426,6 +435,11 @@
 	currAlignTo = ScribusDoc::AlignTo(newAlignTo);
 	enableGuideButtons();
 }
+void AlignDistributePalette::alignMethodChanged(int newAlignMethod)
+{
+	currAlignMethod = ScribusDoc::AlignMethod(newAlignMethod);
+	enableGuideButtons();
+}
 
 void AlignDistributePalette::setGuide(int direction, qreal position)
 {




More information about the scribus-commit mailing list