From 5ee3d28a02b2d92b6b35a3b340c05dc0682a49e8 Mon Sep 17 00:00:00 2001
From: Dawood albadi <dawood.albadi@gmail.com>
Date: Thu, 22 Mar 2018 12:06:36 +0400
Subject: [PATCH 1/1] add initial RTL binding direction

This patch adds RTL binding direction.
---
 .../scribus150format/scribus150format.cpp          |  2 +
 .../scribus150format/scribus150format_save.cpp     |  1 +
 scribus/prefsmanager.cpp                           |  3 +
 scribus/prefsstructs.h                             |  1 +
 scribus/scribus.cpp                                |  5 ++
 scribus/scribusdoc.cpp                             | 73 ++++++++++++++++++----
 scribus/scribusdoc.h                               |  2 +
 scribus/ui/newfile.cpp                             | 14 +++++
 scribus/ui/newfile.h                               |  3 +-
 scribus/ui/pagelayout.cpp                          | 18 ++++++
 scribus/ui/pagelayout.h                            |  3 +
 scribus/ui/pagepalette_pages.cpp                   | 11 ++++
 scribus/ui/pagepalette_pages.h                     |  1 +
 scribus/ui/prefs_documentsetup.cpp                 |  9 +++
 scribus/ui/prefs_documentsetup.h                   |  2 +-
 scribus/ui/prefs_documentsetupbase.ui              | 29 +++++++--
 16 files changed, 158 insertions(+), 19 deletions(-)

diff --git a/scribus/plugins/fileloader/scribus150format/scribus150format.cpp b/scribus/plugins/fileloader/scribus150format/scribus150format.cpp
index 7633b85..e8d7cac 100644
--- a/scribus/plugins/fileloader/scribus150format/scribus150format.cpp
+++ b/scribus/plugins/fileloader/scribus150format/scribus150format.cpp
@@ -2027,6 +2027,7 @@ void Scribus150Format::readDocAttributes(ScribusDoc* doc, ScXmlStreamAttributes&
 {
 	m_Doc->setPageSize(attrs.valueAsString("PAGESIZE"));
 	m_Doc->setPageOrientation(attrs.valueAsInt("ORIENTATION", 0));
+	m_Doc->setBinding(attrs.valueAsInt("PAGEBINDING", 0));
 	m_Doc->FirstPnum  = attrs.valueAsInt("FIRSTNUM", 1);
 	m_Doc->setPagePositioning(attrs.valueAsInt("BOOK", 0));
 
@@ -6143,6 +6144,7 @@ bool Scribus150Format::loadPage(const QString & fileName, int pageNumber, bool M
 				ss->set("LEFT_OLD", newPage->LeftPg);
 				ss->set("NAME_OLD", newPage->pageName());
 				ss->set("ORIENTATION_OLD", newPage->orientation());
+				ss->set("BINDING_OLD", newPage);
 				ss->set("SIZE_OLD", newPage->m_pageSize);
 				ss->set("WIDTH_OLD", newPage->width());
 				ss->set("HEIGHT_OLD", newPage->height());
diff --git a/scribus/plugins/fileloader/scribus150format/scribus150format_save.cpp b/scribus/plugins/fileloader/scribus150format/scribus150format_save.cpp
index 2336488..18d2f2c 100644
--- a/scribus/plugins/fileloader/scribus150format/scribus150format_save.cpp
+++ b/scribus/plugins/fileloader/scribus150format/scribus150format_save.cpp
@@ -225,6 +225,7 @@ bool Scribus150Format::saveFile(const QString & fileName, const FileFormat & /*
 	docu.writeAttribute("BleedRight"  , m_Doc->bleeds()->right());
 	docu.writeAttribute("BleedBottom" , m_Doc->bleeds()->bottom());
 	docu.writeAttribute("ORIENTATION" , m_Doc->pageOrientation());
+	docu.writeAttribute("PAGEBINDING" , m_Doc->pageBiding());
 	docu.writeAttribute("PAGESIZE"    , m_Doc->pageSize());
 	docu.writeAttribute("FIRSTNUM"    , m_Doc->FirstPnum);
 	docu.writeAttribute("BOOK"        , m_Doc->pagePositioning());
diff --git a/scribus/prefsmanager.cpp b/scribus/prefsmanager.cpp
index a953315..9d9d4db 100644
--- a/scribus/prefsmanager.cpp
+++ b/scribus/prefsmanager.cpp
@@ -327,6 +327,7 @@ void PrefsManager::initDefaults()
 		appPrefs.docSetupPrefs.language = "en_GB";
 	appPrefs.docSetupPrefs.pageSize = LocaleManager::instance()->pageSizeForLocale(ScQApp->currGUILanguage());
 	appPrefs.docSetupPrefs.pageOrientation = 0;
+	appPrefs.docSetupPrefs.binding = 0;
 	PageSize defaultPageSize(appPrefs.docSetupPrefs.pageSize);
 	appPrefs.docSetupPrefs.pageWidth = defaultPageSize.width();
 	appPrefs.docSetupPrefs.pageHeight = defaultPageSize.height();
@@ -1398,6 +1399,7 @@ bool PrefsManager::WritePref(QString ho)
 	deDocumentSetup.setAttribute("Language",appPrefs.docSetupPrefs.language);
 	deDocumentSetup.setAttribute("UnitIndex",appPrefs.docSetupPrefs.docUnitIndex);
 	deDocumentSetup.setAttribute("PageSize",appPrefs.docSetupPrefs.pageSize);
+	deDocumentSetup.setAttribute("PageBinding",appPrefs.docSetupPrefs.binding);
 	deDocumentSetup.setAttribute("PageOrientation",appPrefs.docSetupPrefs.pageOrientation);
 	deDocumentSetup.setAttribute("PageWidth",ScCLocale::toQStringC(appPrefs.docSetupPrefs.pageWidth));
 	deDocumentSetup.setAttribute("PageHeight",ScCLocale::toQStringC(appPrefs.docSetupPrefs.pageHeight));
@@ -2009,6 +2011,7 @@ bool PrefsManager::ReadPref(QString ho)
 				appPrefs.docSetupPrefs.language = "en_GB";
 			appPrefs.docSetupPrefs.docUnitIndex = dc.attribute("UnitIndex", "0").toInt();
 			appPrefs.docSetupPrefs.pageSize = dc.attribute("PageSize","A4");
+			appPrefs.docSetupPrefs.binding = dc.attribute("PageBinding", "0").toInt();
 			appPrefs.docSetupPrefs.pageOrientation = dc.attribute("PageOrientation", "0").toInt();
 			appPrefs.docSetupPrefs.pageWidth   = ScCLocale::toDoubleC(dc.attribute("PageWidth"), 595.0);
 			appPrefs.docSetupPrefs.pageHeight  = ScCLocale::toDoubleC(dc.attribute("PageHeight"), 842.0);
diff --git a/scribus/prefsstructs.h b/scribus/prefsstructs.h
index fa1c5d6..6a9138b 100644
--- a/scribus/prefsstructs.h
+++ b/scribus/prefsstructs.h
@@ -183,6 +183,7 @@ struct DocumentSetupPrefs
 	bool AutoSaveLocation;
 	QString AutoSaveDir;
 	bool saveCompressed;
+	int binding;
 };
 
 //Guides
diff --git a/scribus/scribus.cpp b/scribus/scribus.cpp
index 1f66046..fbcb48b 100644
--- a/scribus/scribus.cpp
+++ b/scribus/scribus.cpp
@@ -2117,6 +2117,7 @@ void ScribusMainWindow::startUpDialog()
 		{
 			int facingPages = dia->choosenLayout();
 			int firstPage = dia->firstPage->currentIndex();
+			int bind = dia->bind->currentIndex();
 			docSet = dia->startDocSetup->isChecked();
 			double topMargin = dia->marginGroup->top();
 			double bottomMargin = dia->marginGroup->bottom();
@@ -2141,11 +2142,13 @@ void ScribusMainWindow::startUpDialog()
 			doc->setPageSetFirstPage(facingPages, firstPage);
 			doc->bleeds()->set(dia->bleedTop(), dia->bleedLeft(), dia->bleedBottom(), dia->bleedRight());
 			HaveNewDoc();
+			doc->setBinding(bind);
 			doc->reformPages(true);
 			// Don's disturb user with "save?" dialog just after new doc
 			// doc changing should be rewritten maybe... maybe later...
 			doc->setModified(false);
 			updateActiveWindowCaption(doc->DocName);
+
 		}
 		else if (dia->tabSelected() == NewDoc::NewFromTemplateTab)
 		{
@@ -2199,6 +2202,7 @@ bool ScribusMainWindow::slotFileNew()
 	{
 		int facingPages = dia->choosenLayout();
 		int firstPage = dia->firstPage->currentIndex();
+		int bind = dia->bind->currentIndex();
 		docSet = dia->startDocSetup->isChecked();
 		double topMargin = dia->marginGroup->top();
 		double bottomMargin = dia->marginGroup->bottom();
@@ -2232,6 +2236,7 @@ bool ScribusMainWindow::slotFileNew()
 			doc->setModified(false);
 			updateActiveWindowCaption(doc->DocName);
 		}
+		doc->setBinding(bind);
 	}
 	delete dia;
 	if (docSet)
diff --git a/scribus/scribusdoc.cpp b/scribus/scribusdoc.cpp
index 26d475f..09b04cc 100644
--- a/scribus/scribusdoc.cpp
+++ b/scribus/scribusdoc.cpp
@@ -6266,15 +6266,28 @@ struct oldPageVar
 // without running this monster
 void ScribusDoc::reformPages(bool moveObjects)
 {
+	//	 m_binding = m_docPrefsData.docSetupPrefs.binding;
 	QMap<uint, oldPageVar> pageTable;
 	struct oldPageVar oldPg;
 	int counter = pageSets()[m_docPrefsData.docSetupPrefs.pagePositioning].FirstPage;
 	int rowcounter = 0;
-	double maxYPos=0.0, maxXPos=0.0;
-	double currentXPos=m_docPrefsData.displayPrefs.scratch.left(), currentYPos=m_docPrefsData.displayPrefs.scratch.top(), lastYPos=Pages->at(0)->initialHeight();
-//	currentXPos += (pageWidth+pageSets[currentPageLayout].GapHorizontal) * counter;
-	currentXPos += (m_docPrefsData.docSetupPrefs.pageWidth+m_docPrefsData.displayPrefs.pageGapHorizontal) * counter;
-
+	double maxYPos=0.0, maxXPos=0.0, currentXPos = 0.0, currentYPos = 0.0, lastYPos = 0.0;
+	if (m_docPrefsData.docSetupPrefs.binding == 1)
+	{
+		currentXPos=m_docPrefsData.displayPrefs.scratch.left() + m_docPrefsData.docSetupPrefs.pageWidth;
+		currentYPos=m_docPrefsData.displayPrefs.scratch.top();
+		lastYPos=Pages->at(0)->initialHeight();
+		//	currentXPos += (pageWidth+pageSets[currentPageLayout].GapHorizontal) * counter;
+		currentXPos -= (m_docPrefsData.docSetupPrefs.pageWidth+m_docPrefsData.displayPrefs.pageGapHorizontal) * counter;
+	}
+	else
+	{
+		currentXPos = m_docPrefsData.displayPrefs.scratch.left();
+		currentYPos=m_docPrefsData.displayPrefs.scratch.top();
+		lastYPos=Pages->at(0)->initialHeight();
+		//      currentXPos += (pageWidth+pageSets[currentPageLayout].GapHorizontal) * counter;
+		currentXPos += (m_docPrefsData.docSetupPrefs.pageWidth+m_docPrefsData.displayPrefs.pageGapHorizontal) * counter;
+	}
 	lastYPos = Pages->at(0)->initialHeight();
 	ScPage* page;
 	int docPageCount=Pages->count();
@@ -6314,29 +6327,63 @@ void ScribusDoc::reformPages(bool moveObjects)
 			page->setYOffset(currentYPos);
 			if (counter < pageSets()[m_docPrefsData.docSetupPrefs.pagePositioning].Columns-1)
 			{
-				currentXPos += page->width() + m_docPrefsData.displayPrefs.pageGapHorizontal;
+				if (m_docPrefsData.docSetupPrefs.binding == 1)
+				{
+					currentXPos -= page->width() + m_docPrefsData.displayPrefs.pageGapHorizontal;
+				}
+				else
+				{
+					currentXPos += page->width() + m_docPrefsData.displayPrefs.pageGapHorizontal;
+				}
 				lastYPos = qMax(lastYPos, page->height());
 				if (counter == 0)
 				{
-					page->Margins.setLeft(page->initialMargins.right());
-					page->Margins.setRight(page->initialMargins.left());
+					if (m_docPrefsData.docSetupPrefs.binding == 1)
+					{
+						page->Margins.setLeft(page->initialMargins.left());
+						page->Margins.setRight(page->initialMargins.right());
+					}
+					else
+					{
+						page->Margins.setLeft(page->initialMargins.right());
+						page->Margins.setRight(page->initialMargins.left());
+					}
 				}
 				else
 				{
-					page->Margins.setLeft(page->initialMargins.left());
-					page->Margins.setRight(page->initialMargins.left());
+					if (m_docPrefsData.docSetupPrefs.binding == 1)
+					{
+						page->Margins.setLeft(page->initialMargins.right());
+						page->Margins.setRight(page->initialMargins.right());
+					}
+					else
+					{
+						page->Margins.setLeft(page->initialMargins.left());
+						page->Margins.setRight(page->initialMargins.left());
+					}
 				}
 			}
 			else
 			{
-				currentXPos = m_docPrefsData.displayPrefs.scratch.left();
+				if (m_docPrefsData.docSetupPrefs.binding == 1)
+					currentXPos = m_docPrefsData.displayPrefs.scratch.left() + m_docPrefsData.docSetupPrefs.pageWidth;
+				else
+					currentXPos = m_docPrefsData.displayPrefs.scratch.left();
 				if (pageSets()[m_docPrefsData.docSetupPrefs.pagePositioning].Columns > 1)
 					currentYPos += qMax(lastYPos, page->height())+m_docPrefsData.displayPrefs.pageGapVertical;
 				else
 					currentYPos += page->height()+m_docPrefsData.displayPrefs.pageGapVertical;
 				lastYPos = 0;
-				page->Margins.setRight(page->initialMargins.right());
-				page->Margins.setLeft(page->initialMargins.left());
+				if (m_docPrefsData.docSetupPrefs.binding == 1)
+				{
+					page->Margins.setRight(page->initialMargins.left());
+					page->Margins.setLeft(page->initialMargins.right());
+				}
+				else
+				{
+					page->Margins.setRight(page->initialMargins.right());
+					page->Margins.setLeft(page->initialMargins.left());
+				}
 			}
 			counter++;
 			if (counter > pageSets()[m_docPrefsData.docSetupPrefs.pagePositioning].Columns-1)
diff --git a/scribus/scribusdoc.h b/scribus/scribusdoc.h
index e3ace25..3ae10fd 100644
--- a/scribus/scribusdoc.h
+++ b/scribus/scribusdoc.h
@@ -188,7 +188,9 @@ public:
 	const QString& language() const { return m_docPrefsData.docSetupPrefs.language; }
 	void setLanguage(const QString& s) { m_docPrefsData.docSetupPrefs.language=s; }
 	int pageOrientation() const { return m_docPrefsData.docSetupPrefs.pageOrientation; }
+	int pageBiding() const {return m_docPrefsData.docSetupPrefs.binding; }
 	void setPageOrientation(int o) { m_docPrefsData.docSetupPrefs.pageOrientation=o; }
+	void setBinding(int x) {m_docPrefsData.docSetupPrefs.binding = x; }
 	int pagePositioning() const { return m_docPrefsData.docSetupPrefs.pagePositioning; }
 	void setPagePositioning(int p) { m_docPrefsData.docSetupPrefs.pagePositioning=p; }
 	double pageHeight() const { return m_docPrefsData.docSetupPrefs.pageHeight; }
diff --git a/scribus/ui/newfile.cpp b/scribus/ui/newfile.cpp
index 03b8192..3c673a8 100644
--- a/scribus/ui/newfile.cpp
+++ b/scribus/ui/newfile.cpp
@@ -290,6 +290,13 @@ void NewDoc::createNewDocPage()
 	pageCountLabel->setBuddy(pageCountSpinBox);
 	optionsGroupBoxLayout->addRow( pageCountLabel, pageCountSpinBox);
 
+	layoutLabel2 = new QLabel( optionsGroupBox );
+	layoutLabel2->setText( tr( "Binding Direction:" ) );
+	bind = new ScComboBox( optionsGroupBox );
+	bind->clear();
+	bind->setCurrentIndex(prefsManager->appPrefs.docSetupPrefs.binding);
+	optionsGroupBoxLayout->addRow( layoutLabel2, bind );
+
 	layoutLabel1 = new QLabel( optionsGroupBox );
 	layoutLabel1->setText( tr( "First Page is:" ) );
 	firstPage = new ScComboBox( optionsGroupBox );
@@ -464,12 +471,19 @@ void NewDoc::selectItem(uint nr)
 		{
 			firstPage->addItem(CommonStrings::translatePageSetLocString((*pNames)));
 		}
+		bind->setEnabled(true);
+		bind->addItem(tr("Left To Right"));
+		bind->addItem(tr("Right To Left"));
+
+
 	}
 	else
 	{
 		firstPage->clear();
 		firstPage->addItem(" ");
 		firstPage->setEnabled(false);
+		bind->clear();
+		bind->setEnabled(false);
 	}
 	layoutsView->setCurrentRow(nr);
 	layoutsView->item(nr)->setSelected(true);
diff --git a/scribus/ui/newfile.h b/scribus/ui/newfile.h
index 57e75e8..33ddf1a 100644
--- a/scribus/ui/newfile.h
+++ b/scribus/ui/newfile.h
@@ -75,6 +75,8 @@ public:
 	QFrame* newDocFrame;
 	PageLayoutsWidget* layoutsView;
 	QLabel* layoutLabel1;
+	QLabel* layoutLabel2;
+	ScComboBox* bind;
 	ScComboBox* firstPage;
 	QGroupBox* pageSizeGroupBox;
 	MarginWidget* marginGroup;
@@ -151,7 +153,6 @@ public slots:
 	void gotoDesktopDirectory();
 	void gotoHomeDirectory();
 	void openFileDialogFileClicked(const QString &path);
-
 protected:
 	QVBoxLayout* TabbedNewDocLayout;
 	QHBoxLayout* Layout1;
diff --git a/scribus/ui/pagelayout.cpp b/scribus/ui/pagelayout.cpp
index 471716b..4238e8b 100644
--- a/scribus/ui/pagelayout.cpp
+++ b/scribus/ui/pagelayout.cpp
@@ -78,6 +78,11 @@ PageLayouts::PageLayouts(QWidget* parent)  : QGroupBox( parent )
 	layoutsCombo = new ScComboBox( this );
 	layoutGroupLayout->addWidget( layoutsCombo );
 
+	layoutLable2 = new QLabel( this );
+	layoutGroupLayout->addWidget( layoutLable2 );
+	bind = new ScComboBox( this );
+	layoutGroupLayout->addWidget( bind );
+
 	layoutLabel1 = new QLabel( this );
 	layoutGroupLayout->addWidget( layoutLabel1 );
 	firstPage = new ScComboBox( this );
@@ -87,6 +92,7 @@ PageLayouts::PageLayouts(QWidget* parent)  : QGroupBox( parent )
 
 	connect(layoutsCombo, SIGNAL(activated(int)), this, SLOT(itemSelected(int)));
 	connect(firstPage, SIGNAL(activated(int)), this, SIGNAL(selectedFirstPage(int)));
+	connect(bind, SIGNAL(activated(int)), this, SIGNAL(selectBinding(int)));
 }
 
 PageLayouts::PageLayouts(QWidget* parent, QList<PageSet> pSets, bool mode)  : QGroupBox( parent )
@@ -106,6 +112,10 @@ PageLayouts::PageLayouts(QWidget* parent, QList<PageSet> pSets, bool mode)  : QG
 		layoutsCombo = new ScComboBox( this );
 		layoutGroupLayout->addWidget( layoutsCombo );
 	}
+	layoutLable2 = new QLabel( this );
+	layoutGroupLayout->addWidget( layoutLable2 );
+	bind = new ScComboBox( this );
+	layoutGroupLayout->addWidget( bind );
 	layoutLabel1 = new QLabel( this );
 	layoutGroupLayout->addWidget( layoutLabel1 );
 	firstPage = new ScComboBox( this );
@@ -158,6 +168,10 @@ void PageLayouts::selectItem(uint nr)
 	disconnect(firstPage, SIGNAL(activated(int)), this, SIGNAL(selectedFirstPage(int)));
 	if (nr > 0)
 	{
+		bind->setEnabled(true);
+		bind->clear();
+		bind->addItem(tr("Left To Right"));
+		bind->addItem(tr("Right To Left"));
 		firstPage->setEnabled(true);
 		firstPage->clear();
 		QStringList::Iterator pNames;
@@ -168,6 +182,8 @@ void PageLayouts::selectItem(uint nr)
 	}
 	else
 	{
+		bind->clear();
+		bind->setEnabled(false);
 		firstPage->clear();
 		firstPage->addItem(" ");
 		firstPage->setEnabled(false);
@@ -293,6 +309,8 @@ void PageLayouts::languageChange()
 		firstPage->setCurrentIndex(currFirstPageIndex);
 		connect(firstPage, SIGNAL(activated(int)), this, SIGNAL(selectedFirstPage(int)));
 	}
+	layoutLable2->setText( tr( "Binding Direction: " ));
+	bind->setCurrentIndex(bind->currentIndex());
 	layoutLabel1->setText( tr( "First Page is:" ) );
 
 	QString layoutText( tr( "Number of pages to show side-by-side on the canvas. Often used for allowing items to be placed across page spreads." ) );
diff --git a/scribus/ui/pagelayout.h b/scribus/ui/pagelayout.h
index 3dc0220..3943af8 100644
--- a/scribus/ui/pagelayout.h
+++ b/scribus/ui/pagelayout.h
@@ -51,6 +51,8 @@ public:
 	QLabel* layoutLabel1;
 	ScComboBox* firstPage;
 	QList<PageSet> pageSets;
+	QLabel* layoutLable2;
+	ScComboBox* bind;
 
 public slots:
 	void itemSelected(QListWidgetItem* ic);
@@ -59,6 +61,7 @@ public slots:
 signals:
 	void selectedLayout(int);
 	void selectedFirstPage(int);
+	void selectBinding(int);
 
 private:
 	void itemSelectedPost(int chosen);
diff --git a/scribus/ui/pagepalette_pages.cpp b/scribus/ui/pagepalette_pages.cpp
index 0f2471d..132f6fa 100644
--- a/scribus/ui/pagepalette_pages.cpp
+++ b/scribus/ui/pagepalette_pages.cpp
@@ -70,6 +70,7 @@ PagePalette_Pages::PagePalette_Pages(QWidget* parent) : QWidget(parent)
 	connect(masterPageList, SIGNAL(thumbnailChanged()), this, SLOT(rebuildMasters()));
 	connect(masterPageList, SIGNAL(DelMaster(QString)), this, SLOT(deleteMasterPage(QString)));
 
+	connect(pageLayout, SIGNAL(selectBinding(int))     , this, SLOT(handleBinging(int)));
 	connect(pageLayout, SIGNAL(selectedLayout(int ))   , this, SLOT(handlePageLayout(int )));
 	connect(pageLayout, SIGNAL(selectedFirstPage(int )), this, SLOT(handleFirstPage(int )));
 	connect(pageView  , SIGNAL(Click(int, int, int))   , this, SLOT(pageView_gotoPage(int, int, int)));
@@ -164,6 +165,15 @@ void PagePalette_Pages::enablePalette(const bool enabled)
 	pageLayout->setEnabled(enabled);
 }
 
+void PagePalette_Pages::handleBinging(int bind)
+{
+	currView->Doc->setBinding(bind);
+	currView->reformPages();
+	currView->DrawNew();
+	currView->GotoPage(currView->Doc->currentPageNumber());
+	rebuildPages();
+}
+
 void PagePalette_Pages::handlePageLayout(int layout)
 {
 	pageLayout->selectFirstP(currView->Doc->pageSets()[layout].FirstPage);
@@ -227,6 +237,7 @@ void PagePalette_Pages::rebuildPages()
 	pageLayout->updateLayoutSelector(currView->Doc->pageSets());
 	pageLayout->selectItem(currView->Doc->pagePositioning());
 	pageLayout->firstPage->setCurrentIndex(currView->Doc->pageSets()[currView->Doc->pagePositioning()].FirstPage);
+	pageLayout->bind->setCurrentIndex(currView->Doc->pageBiding());
 	pageView->MaxC = currView->Doc->DocPages.count()-1;
 	int counter = currView->Doc->pageSets()[currView->Doc->pagePositioning()].FirstPage;
 	int cols = currView->Doc->pageSets()[currView->Doc->pagePositioning()].Columns;
diff --git a/scribus/ui/pagepalette_pages.h b/scribus/ui/pagepalette_pages.h
index a4b3a1b..f56714d 100644
--- a/scribus/ui/pagepalette_pages.h
+++ b/scribus/ui/pagepalette_pages.h
@@ -50,6 +50,7 @@ public slots:
 	void markPage(uint nr);
 	void selMasterPage();
 	void languageChange();
+	void handleBinging(int);
 
 private slots:
 	void pageView_applyMasterPage(QString masterpageName, int pageIndex);
diff --git a/scribus/ui/prefs_documentsetup.cpp b/scribus/ui/prefs_documentsetup.cpp
index dcbd757..9540080 100644
--- a/scribus/ui/prefs_documentsetup.cpp
+++ b/scribus/ui/prefs_documentsetup.cpp
@@ -171,6 +171,7 @@ void Prefs_DocumentSetup::restoreDefaults(struct ApplicationPrefs *prefsData)
 			break;
 	}
 	setupPageSets();
+	bind->setCurrentIndex(prefsData->docSetupPrefs.binding);
 
 	layoutFirstPageIsComboBox->setCurrentIndex(prefsData->pageSets[prefsData->docSetupPrefs.pagePositioning].FirstPage);
 
@@ -221,6 +222,7 @@ void Prefs_DocumentSetup::saveGuiToPrefs(struct ApplicationPrefs *prefsData) con
 	prefsData->docSetupPrefs.pagePositioning=pageLayoutButtonGroup->checkedId();
 	prefsData->pageSets[prefsData->docSetupPrefs.pagePositioning].FirstPage=layoutFirstPageIsComboBox->currentIndex();
 
+	prefsData->docSetupPrefs.binding = bind->currentIndex();
 	prefsData->docSetupPrefs.margins=marginsWidget->margins();
 	prefsData->docSetupPrefs.bleeds=bleedsWidget->margins();
 	prefsData->docSetupPrefs.saveCompressed=saveCompressedCheckBox->isChecked();
@@ -246,8 +248,13 @@ void Prefs_DocumentSetup::setupPageSets()
 	int i=layoutFirstPageIsComboBox->currentIndex();
 	int currIndex=pageLayoutButtonGroup->checkedId()<0?0:pageLayoutButtonGroup->checkedId();
 	layoutFirstPageIsComboBox->clear();
+	bind->clear();
 	if (currIndex>0 && currIndex<pageSets.count())
 	{
+		bind->setEnabled(true);
+		bind->addItem(tr("Left To Right"));
+		bind->addItem(tr("Right To Left"));
+//		bind->setCurrentIndex(PrefsManager.);
 		layoutFirstPageIsComboBox->setEnabled(true);
 		for(QStringList::Iterator pNames = pageSets[currIndex].pageNames.begin(); pNames != pageSets[currIndex].pageNames.end(); ++pNames )
 			layoutFirstPageIsComboBox->addItem(CommonStrings::translatePageSetLocString(*pNames));
@@ -255,6 +262,8 @@ void Prefs_DocumentSetup::setupPageSets()
 	}
 	else
 	{
+		bind->clear();
+		bind->setEnabled(false);
 		layoutFirstPageIsComboBox->addItem(" ");
 		layoutFirstPageIsComboBox->setCurrentIndex(0);
 		layoutFirstPageIsComboBox->setEnabled(false);
diff --git a/scribus/ui/prefs_documentsetup.h b/scribus/ui/prefs_documentsetup.h
index 16e4fb0..1a04f2a 100644
--- a/scribus/ui/prefs_documentsetup.h
+++ b/scribus/ui/prefs_documentsetup.h
@@ -12,9 +12,9 @@ for which a new license (GPL+exception) is in place.
 #include "prefs_pane.h"
 #include "scribusapi.h"
 #include "scribusstructs.h"
+//#include "scribusdoc.h"
 
 class ScribusDoc;
-
 class SCRIBUS_API Prefs_DocumentSetup : public Prefs_Pane, Ui::Prefs_DocumentSetup
 {
 	Q_OBJECT
diff --git a/scribus/ui/prefs_documentsetupbase.ui b/scribus/ui/prefs_documentsetupbase.ui
index 6cbc951..00c7a93 100644
--- a/scribus/ui/prefs_documentsetupbase.ui
+++ b/scribus/ui/prefs_documentsetupbase.ui
@@ -38,7 +38,7 @@
    <item>
     <widget class="QTabWidget" name="tabWidget">
      <property name="currentIndex">
-      <number>0</number>
+      <number>1</number>
      </property>
      <widget class="QWidget" name="sizeTab">
       <attribute name="title">
@@ -247,7 +247,7 @@
        </item>
        <item>
         <layout class="QFormLayout" name="pageLayoutLayout">
-         <item row="4" column="0">
+         <item row="7" column="0">
           <widget class="QLabel" name="layoutFirstPageIsLabel">
            <property name="text">
             <string>First Page is:</string>
@@ -257,7 +257,7 @@
            </property>
           </widget>
          </item>
-         <item row="4" column="1">
+         <item row="7" column="1">
           <widget class="QComboBox" name="layoutFirstPageIsComboBox">
            <property name="sizeAdjustPolicy">
             <enum>QComboBox::AdjustToContents</enum>
@@ -307,6 +307,27 @@
            </attribute>
           </widget>
          </item>
+         <item row="4" column="1">
+          <widget class="QComboBox" name="bind">
+           <item>
+            <property name="text">
+             <string>Left To Right</string>
+            </property>
+           </item>
+           <item>
+            <property name="text">
+             <string>Right To Left</string>
+            </property>
+           </item>
+          </widget>
+         </item>
+         <item row="4" column="0">
+          <widget class="QLabel" name="bindLable">
+           <property name="text">
+            <string>Binding Direction:</string>
+           </property>
+          </widget>
+         </item>
         </layout>
        </item>
        <item>
@@ -349,7 +370,7 @@
             <x>0</x>
             <y>0</y>
             <width>458</width>
-            <height>540</height>
+            <height>546</height>
            </rect>
           </property>
           <layout class="QVBoxLayout" name="verticalLayout_5">
-- 
2.7.4

