View Issue Details

IDProjectCategoryView StatusLast Update
0015939ScribusGeneralpublic2019-11-14 19:50
Reporterale Assigned Toale  
PrioritynormalSeverityfeatureReproducibilityN/A
Status assignedResolutionopen 
Summary0015939: [PATCH] apply master page to pages with a given master page
Descriptionadd an option in "apply master page" to apply it to all pages with a specific "master page" (replace master page)
TagsNo tags attached.
PatchYes

Activities

ale

2019-11-14 19:49

manager   ~0047079

here is a patch:

- renames ui/applytemplatedialog.* to ui/applymasterpagedialog.* to match what it does *and* the name of the class inside.
- adds masterpage.* with the master utils function i've introduced in 0008115 (so that they can be used by both dialogs; please give feedback in 0015942 so that i can further improve this new file.. and maybe remove a few things from scribusdoc.cpp
- adds an .ui file for the dialog
- do not update the translation for a modal dialog (am i correct that we can extract the translations from the ui file?)
- use a scoped enum class for the page selection types (instead of int)
- allow to apply a master page only to pages with a specific master page

here is the merge request with appimage (soon):

https://gitlab.com/scribus/scribus/merge_requests/16
masterpage-replace.diff (41,323 bytes)   
diff --git a/scribus/CMakeLists.txt b/scribus/CMakeLists.txt
index 3a6e69b38..de8ff86bf 100644
--- a/scribus/CMakeLists.txt
+++ b/scribus/CMakeLists.txt
@@ -91,6 +91,7 @@ set(SCRIBUS_UI_SRC
 	ui/actionsearchdialog.ui
 	ui/aligndistribute.ui
 	ui/annot.ui
+	ui/applymasterpagedialogbase.ui
 	ui/arcvectorbase.ui
 	ui/arcwidgetbase.ui
 	ui/charselect.ui
@@ -256,6 +257,7 @@ set(SCRIBUS_MOC_CLASSES
 	iconmanager.h
 	latexhelpers.h
 	loadsaveplugin.h
+	masterpage.h
 	menumanager.h
 	navigator.h
 	notesstyles.h
@@ -317,7 +319,7 @@ set(SCRIBUS_MOC_CLASSES
 	ui/directionselect.h
 	ui/annot.h
 	ui/annota.h
-	ui/applytemplatedialog.h
+	ui/applymasterpagedialog.h
 	ui/arcwidget.h
 	ui/arcvectordialog.h
 	ui/arrowchooser.h
@@ -650,6 +652,7 @@ set(SCRIBUS_SOURCES
 	loadsaveplugin.cpp
 	localemgr.cpp
 	marks.cpp
+	masterpage.cpp
 	menumanager.cpp
 	mesh.cpp
 	navigator.cpp
@@ -820,7 +823,7 @@ set(SCRIBUS_SOURCES
 	ui/directionselect.cpp
 	ui/annot.cpp
 	ui/annota.cpp
-	ui/applytemplatedialog.cpp
+	ui/applymasterpagedialog.cpp
 	ui/arcwidget.cpp
 	ui/arcvectordialog.cpp
 	ui/arrowchooser.cpp
diff --git a/scribus/masterpage.cpp b/scribus/masterpage.cpp
new file mode 100644
index 000000000..8d53a4993
--- /dev/null
+++ b/scribus/masterpage.cpp
@@ -0,0 +1,66 @@
+/*
+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 "masterpage.h"
+
+#include <QString>
+#include <QStringList>
+
+#include "commonstrings.h"
+#include "scribusdoc.h"
+#include "util.h"
+
+MasterPage::MasterPage()
+{
+}
+
+// void MasterPage::setDoc(ScribusDoc* doc)
+// {
+// 	// TODO: to be done
+// }
+
+// void MasterPage::unsetDoc()
+// {
+// 	// TODO: to be done
+// }
+
+bool MasterPage::isReservedName(const QString& name)
+{
+	return name == CommonStrings::masterPageNormal ||
+		name == CommonStrings::trMasterPageNormal ||
+		name == CommonStrings::masterPageNormalLeft ||
+		name == CommonStrings::trMasterPageNormalLeft ||
+		name == CommonStrings::masterPageNormalMiddle ||
+		name == CommonStrings::trMasterPageNormalMiddle ||
+		name == CommonStrings::masterPageNormalRight ||
+		name == CommonStrings::trMasterPageNormalRight;
+}
+
+QString MasterPage::getNonReservedName(const QString& name)
+{
+	const QStringList reservedNames = {
+		CommonStrings::masterPageNormal,
+		CommonStrings::trMasterPageNormal,
+		CommonStrings::trMasterPageNormalLeft,
+		CommonStrings::trMasterPageNormalMiddle,
+		CommonStrings::trMasterPageNormalRight
+	};
+	return getUniqueName(name, reservedNames);
+}
+
+QString MasterPage::getTranslatedReservedName(const QString& name)
+{
+	if (name == CommonStrings::masterPageNormal)
+		return CommonStrings::trMasterPageNormal;
+	if (name == CommonStrings::masterPageNormalLeft)
+		return CommonStrings::trMasterPageNormalLeft;
+	if (name == CommonStrings::masterPageNormalMiddle)
+		return CommonStrings::trMasterPageNormalMiddle;
+	if (name == CommonStrings::masterPageNormalRight)
+		return CommonStrings::trMasterPageNormalRight;
+	return name;
+}
diff --git a/scribus/masterpage.h b/scribus/masterpage.h
new file mode 100644
index 000000000..c96f3d8b1
--- /dev/null
+++ b/scribus/masterpage.h
@@ -0,0 +1,43 @@
+/*
+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.
+*/
+/***************************************************************************
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ ***************************************************************************/
+#ifndef MASTERPAGE_H
+#define MASTERPAGE_H
+
+#include <QObject>
+
+class QString;
+
+class ScribusDoc;
+
+class MasterPage : public QObject
+{
+	Q_OBJECT
+
+public:
+	MasterPage();
+
+	// TODO: to be done
+	// void setDoc(ScribusDoc* doc);
+	// void unsetDoc();
+
+	static bool isReservedName(const QString& name);
+	static QString getNonReservedName(const QString& name);
+	/*!
+	 * \retval the current name or, if it's a standard one, the translated version
+	*/
+	static QString getTranslatedReservedName(const QString& name);
+};
+
+#endif // MASTERPAGE_H
diff --git a/scribus/scribus.cpp b/scribus/scribus.cpp
index 239ede923..bc9ae6e06 100644
--- a/scribus/scribus.cpp
+++ b/scribus/scribus.cpp
@@ -161,7 +161,7 @@ for which a new license (GPL+exception) is in place.
 #include "ui/aligndistribute.h"
 #include "ui/annot.h"
 #include "ui/annota.h"
-#include "ui/applytemplatedialog.h"
+#include "ui/applymasterpagedialog.h"
 #include "ui/arrowchooser.h"
 #include "ui/autoform.h"
 #include "ui/basepointwidget.h"
@@ -7733,40 +7733,44 @@ void ScribusMainWindow::ApplyMasterPage()
 {
 	Q_ASSERT(!doc->masterPageMode());
 
-	QScopedPointer<ApplyMasterPageDialog> dia(new ApplyMasterPageDialog(this));
-	dia->setup(doc, doc->currentPage()->masterPageName());
-	if (!dia->exec())
+	ApplyMasterPageDialog dia(this, doc);
+	if (!dia.exec())
 		return;
 
-	QString masterPageName(dia->getMasterPageName());
-	int pageSelection = dia->getPageSelection(); //0=current, 1=even, 2=odd, 3=all
-	if (pageSelection == 0) //current page only
+	QString masterPageName(dia.getSelectedName());
+	using Selection = ApplyMasterPageDialog::PagesSelection;
+	auto pageSelection = dia.getPageSelection();
+	if (pageSelection == Selection::current)
 		Apply_MasterPage(masterPageName, doc->currentPage()->pageNr(), false);
 	else
 	{
 		int startPage, endPage;
-		if (dia->usingRange())
+		if (dia.usingRange())
 		{
-			startPage = dia->getFromPage()-1; //Pages start from 0, not 1
-			endPage = dia->getToPage();
+			startPage = dia.getFromPage() - 1;
+			endPage = dia.getToPage();
 		}
 		else
 		{
-			startPage = pageSelection==1 ? 1 : 0; //if even, startPage is 1 (real page 2)
+			// if even, startPage is 1 (real page 2)
+			startPage = pageSelection == Selection::even ? 1 : 0;
 			endPage = doc->DocPages.count();
 		}
-		for (int pageNum = startPage; pageNum < endPage; ++pageNum)// +=pageStep)
+
+		const QString fromMasterPage = dia.getFromMasterPage();
+		for (int i = startPage; i < endPage; ++i)
 		{
-			//Increment by 1 and not 2 even for even/odd application as user
-			//can select to eg apply to even pages with a single odd page selected
-			if (pageSelection == 1 && (pageNum %2 != 0)) //Even, %2!=0 as 1st page is numbered 0
-				Apply_MasterPage(masterPageName, pageNum, false);
+			if (dia.usingMasterPage() &&
+				doc->DocPages.at(i)->masterPageName() != fromMasterPage)
+				continue;
+			if (pageSelection == Selection::even && (i %2 != 0))
+				Apply_MasterPage(masterPageName, i, false);
 			else
-			if (pageSelection == 2 && (pageNum %2 == 0)) //Odd, %2==0 as 1st page is numbered 0
-				Apply_MasterPage(masterPageName, pageNum, false);
+			if (pageSelection == Selection::odd && (i %2 == 0))
+				Apply_MasterPage(masterPageName, i, false);
 			else
-			if (pageSelection == 3) //All
-				Apply_MasterPage(masterPageName, pageNum, false);
+			if (pageSelection == Selection::all)
+				Apply_MasterPage(masterPageName, i, false);
 		}
 	}
 
diff --git a/scribus/ui/applymasterpagedialog.cpp b/scribus/ui/applymasterpagedialog.cpp
new file mode 100644
index 000000000..5e2c21cb5
--- /dev/null
+++ b/scribus/ui/applymasterpagedialog.cpp
@@ -0,0 +1,163 @@
+/*
+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.
+*/
+/***************************************************************************
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ ***************************************************************************/
+
+#include "applymasterpagedialog.h"
+
+#include "commonstrings.h"
+#include "masterpage.h"
+#include "scpage.h"
+#include "scribusdoc.h"
+#include "iconmanager.h"
+
+ApplyMasterPageDialog::ApplyMasterPageDialog(QWidget* parent, ScribusDoc* doc) :
+	QDialog(parent)
+{
+	setupUi(this);
+
+	setWindowIcon(IconManager::instance().loadIcon("AppIcon.png"));
+
+	pagesButtonGroup->setId(currentPageButton, static_cast<int>(PagesSelection::current));
+	pagesButtonGroup->setId(allPagesButton, static_cast<int>(PagesSelection::all));
+	pagesButtonGroup->setId(evenPagesButton, static_cast<int>(PagesSelection::even));
+	pagesButtonGroup->setId(oddPagesButton, static_cast<int>(PagesSelection::odd));
+
+	setup(doc);
+
+	connect(pagesButtonGroup, QOverload<int>::of(&QButtonGroup::buttonClicked), this, &ApplyMasterPageDialog::pagesButtonClicked);
+
+	connect(rangeFromSpinBox, QOverload<int>::of(&QSpinBox::valueChanged), this, &ApplyMasterPageDialog::checkRangeFrom);
+	connect(rangeToSpinBox, QOverload<int>::of(&QSpinBox::valueChanged), this, &ApplyMasterPageDialog::checkRangeTo);
+	connect(masterPagesFromCheckBox, &QCheckBox::toggled, this, &ApplyMasterPageDialog::enableMasterPagesFrom);
+	connect(rangeCheckBox, &QCheckBox::toggled, this, &ApplyMasterPageDialog::enableRange);
+
+	connect(okButton, &QPushButton::clicked, this, &ApplyMasterPageDialog::accept);
+	connect(cancelButton, &QPushButton::clicked, this, &ApplyMasterPageDialog::reject);
+}
+
+void ApplyMasterPageDialog::setup(ScribusDoc *doc)
+{
+	const auto current = doc->currentPage()->masterPageName();
+
+	for (const auto& key: doc->MasterNames.keys())
+	{
+		auto tr_name = MasterPage::getTranslatedReservedName(key);
+		masterPagesComboBox->addItem(tr_name, key);
+		masterPagesFromComboBox->addItem(tr_name, key);
+		if (current == key)
+		{
+			int n = masterPagesComboBox->count() - 1;
+			masterPagesComboBox->setCurrentIndex(n);
+			masterPagesFromComboBox->setCurrentIndex(n);
+		}
+	}
+
+	const unsigned int pagesCount = doc->Pages->count();
+	if (pagesCount < 2)
+		evenPagesButton->setEnabled(false);
+	rangeFromSpinBox->setMaximum(pagesCount);
+	rangeFromSpinBox->setValue(doc->currentPage()->pageNr() + 1);
+	rangeToSpinBox->setMaximum(pagesCount);
+	rangeToSpinBox->setValue(static_cast<int>(pagesCount));
+}
+
+QString ApplyMasterPageDialog::getSelectedName()
+{
+	return masterPagesComboBox->currentText();
+}
+
+ApplyMasterPageDialog::PagesSelection ApplyMasterPageDialog::getPageSelection()
+{
+	return static_cast<PagesSelection>(pagesButtonGroup->checkedId());
+}
+
+bool ApplyMasterPageDialog::usingRange()
+{
+	return pagesButtonGroup->checkedId() != static_cast<int>(PagesSelection::current) &&
+		rangeCheckBox->isChecked();
+}
+
+bool ApplyMasterPageDialog::usingMasterPage()
+{
+	return pagesButtonGroup->checkedId() != static_cast<int>(PagesSelection::current) &&
+		masterPagesFromCheckBox->isChecked();
+}
+
+int ApplyMasterPageDialog::getFromPage()
+{
+	assert(rangeCheckBox->isChecked());
+	return static_cast<int>(rangeFromSpinBox->value());
+}
+
+
+int ApplyMasterPageDialog::getToPage()
+{
+	assert(rangeCheckBox->isChecked());
+	return static_cast<int>(rangeToSpinBox->value());
+}
+
+QString ApplyMasterPageDialog::getFromMasterPage()
+{
+	if (!masterPagesFromCheckBox->isChecked())
+		return "";
+	return masterPagesFromComboBox->currentText();
+}
+
+void ApplyMasterPageDialog::pagesButtonClicked(int id)
+{
+	bool enabled = evenPagesButton->isEnabled() &&
+		!(static_cast<PagesSelection>(id) == PagesSelection::current);
+
+	masterPagesFromCheckBox->setEnabled(enabled);
+	masterPagesFromComboBox->setEnabled(enabled && masterPagesFromCheckBox->isChecked());
+	rangeCheckBox->setEnabled(enabled);
+	rangeFromSpinBox->setEnabled(enabled && rangeCheckBox->isChecked());
+	rangeToLabel->setEnabled(enabled);
+	rangeToSpinBox->setEnabled(enabled && rangeCheckBox->isChecked());
+}
+
+void ApplyMasterPageDialog::enableMasterPagesFrom(bool checked)
+{
+	masterPagesFromComboBox->setEnabled(checked);
+}
+
+void ApplyMasterPageDialog::enableRange(bool checked)
+{
+	rangeFromSpinBox->setEnabled(checked);
+	rangeToSpinBox->setEnabled(checked);
+}
+
+void ApplyMasterPageDialog::checkRangeFrom(int value)
+{
+	bool oldFromState = rangeFromSpinBox->blockSignals(true);
+	bool oldToState = rangeToSpinBox->blockSignals(true);
+
+	if (rangeFromSpinBox->value() > rangeToSpinBox->value())
+		rangeToSpinBox->setValue(rangeFromSpinBox->value());
+
+	rangeToSpinBox->blockSignals(oldToState);
+	rangeFromSpinBox->blockSignals(oldFromState);
+}
+
+void ApplyMasterPageDialog::checkRangeTo(int value)
+{
+	bool oldFromState = rangeFromSpinBox->blockSignals(true);
+	bool oldToState = rangeToSpinBox->blockSignals(true);
+
+	if (rangeToSpinBox->value() < rangeFromSpinBox->value())
+		rangeFromSpinBox->setValue(rangeToSpinBox->value());
+
+	rangeToSpinBox->blockSignals(oldToState);
+	rangeFromSpinBox->blockSignals(oldFromState);
+}
diff --git a/scribus/ui/applymasterpagedialog.h b/scribus/ui/applymasterpagedialog.h
new file mode 100644
index 000000000..0890e4d1f
--- /dev/null
+++ b/scribus/ui/applymasterpagedialog.h
@@ -0,0 +1,64 @@
+/*
+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.
+*/
+/***************************************************************************
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ ***************************************************************************/
+#ifndef APPLYMASTERPAGEDIALOG_H
+#define APPLYMASTERPAGEDIALOG_H
+
+#include "ui_applymasterpagedialogbase.h"
+
+#include <QDialog>
+#include <QString>
+
+#include "scribusapi.h"
+#include "scribusdoc.h"
+#include "scpage.h"
+#include "ui/scrspinbox.h"
+
+class ScribusDoc;
+
+class SCRIBUS_API ApplyMasterPageDialog : public QDialog, Ui::ApplyMasterPageDialogBase
+{
+	Q_OBJECT
+
+public:
+	enum class PagesSelection {
+		current,
+		even,
+		odd,
+		all
+	};
+
+	ApplyMasterPageDialog(QWidget* parent, ScribusDoc* doc);
+	~ApplyMasterPageDialog() = default;
+
+	QString getSelectedName();
+	PagesSelection getPageSelection();
+	bool usingRange();
+	bool usingMasterPage();
+	int getFromPage();
+	int getToPage();
+	QString getFromMasterPage();
+
+private:
+	void setup(ScribusDoc* doc);
+
+private slots:
+	void pagesButtonClicked(int id);
+	void enableMasterPagesFrom(bool checked);
+	void enableRange(bool checked);
+	void checkRangeFrom(int id);
+	void checkRangeTo(int id);
+};
+
+#endif // APPLYMASTERPAGEDIALOG_H
diff --git a/scribus/ui/applymasterpagedialogbase.ui b/scribus/ui/applymasterpagedialogbase.ui
new file mode 100644
index 000000000..a8363078c
--- /dev/null
+++ b/scribus/ui/applymasterpagedialogbase.ui
@@ -0,0 +1,257 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>ApplyMasterPageDialogBase</class>
+ <widget class="QDialog" name="ApplyMasterPageDialogBase">
+  <property name="windowModality">
+   <enum>Qt::ApplicationModal</enum>
+  </property>
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>274</width>
+    <height>256</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Dialog</string>
+  </property>
+  <layout class="QVBoxLayout" name="verticalLayout">
+   <item>
+    <layout class="QHBoxLayout" name="horizontalLayout">
+     <item>
+      <widget class="QLabel" name="applyLabel">
+       <property name="text">
+        <string>Apply &amp;Master Page</string>
+       </property>
+       <property name="buddy">
+        <cstring>masterPagesComboBox</cstring>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <widget class="QComboBox" name="masterPagesComboBox"/>
+     </item>
+     <item>
+      <widget class="QLabel" name="applyToLabel">
+       <property name="text">
+        <string>to</string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <spacer name="horizontalSpacer">
+       <property name="orientation">
+        <enum>Qt::Horizontal</enum>
+       </property>
+       <property name="sizeHint" stdset="0">
+        <size>
+         <width>40</width>
+         <height>20</height>
+        </size>
+       </property>
+      </spacer>
+     </item>
+    </layout>
+   </item>
+   <item>
+    <widget class="QGroupBox" name="groupBox">
+     <property name="title">
+      <string/>
+     </property>
+     <layout class="QVBoxLayout" name="verticalLayout_2">
+      <item>
+       <widget class="QRadioButton" name="currentPageButton">
+        <property name="text">
+         <string>Current &amp;Page</string>
+        </property>
+        <property name="checked">
+         <bool>true</bool>
+        </property>
+        <attribute name="buttonGroup">
+         <string notr="true">pagesButtonGroup</string>
+        </attribute>
+       </widget>
+      </item>
+      <item>
+       <widget class="QRadioButton" name="allPagesButton">
+        <property name="text">
+         <string>&amp;All Pages</string>
+        </property>
+        <property name="checked">
+         <bool>false</bool>
+        </property>
+        <attribute name="buttonGroup">
+         <string notr="true">pagesButtonGroup</string>
+        </attribute>
+       </widget>
+      </item>
+      <item>
+       <widget class="QRadioButton" name="evenPagesButton">
+        <property name="text">
+         <string>&amp;Even Pages</string>
+        </property>
+        <attribute name="buttonGroup">
+         <string notr="true">pagesButtonGroup</string>
+        </attribute>
+       </widget>
+      </item>
+      <item>
+       <widget class="QRadioButton" name="oddPagesButton">
+        <property name="text">
+         <string>O&amp;dd Pages</string>
+        </property>
+        <attribute name="buttonGroup">
+         <string notr="true">pagesButtonGroup</string>
+        </attribute>
+       </widget>
+      </item>
+     </layout>
+    </widget>
+   </item>
+   <item>
+    <layout class="QHBoxLayout" name="horizontalLayout_2">
+     <item>
+      <widget class="QCheckBox" name="masterPagesFromCheckBox">
+       <property name="enabled">
+        <bool>false</bool>
+       </property>
+       <property name="text">
+        <string>With Ma&amp;ster Page</string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <widget class="QComboBox" name="masterPagesFromComboBox">
+       <property name="enabled">
+        <bool>false</bool>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <spacer name="horizontalSpacer_3">
+       <property name="orientation">
+        <enum>Qt::Horizontal</enum>
+       </property>
+       <property name="sizeHint" stdset="0">
+        <size>
+         <width>40</width>
+         <height>20</height>
+        </size>
+       </property>
+      </spacer>
+     </item>
+    </layout>
+   </item>
+   <item>
+    <layout class="QHBoxLayout" name="horizontalLayout_3">
+     <item>
+      <widget class="QCheckBox" name="rangeCheckBox">
+       <property name="enabled">
+        <bool>false</bool>
+       </property>
+       <property name="text">
+        <string>&amp;Within Range</string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <widget class="QSpinBox" name="rangeFromSpinBox">
+       <property name="enabled">
+        <bool>false</bool>
+       </property>
+       <property name="minimum">
+        <number>1</number>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <widget class="QLabel" name="rangeToLabel">
+       <property name="enabled">
+        <bool>false</bool>
+       </property>
+       <property name="text">
+        <string>to</string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <widget class="QSpinBox" name="rangeToSpinBox">
+       <property name="enabled">
+        <bool>false</bool>
+       </property>
+       <property name="minimum">
+        <number>1</number>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <spacer name="horizontalSpacer_2">
+       <property name="orientation">
+        <enum>Qt::Horizontal</enum>
+       </property>
+       <property name="sizeHint" stdset="0">
+        <size>
+         <width>40</width>
+         <height>20</height>
+        </size>
+       </property>
+      </spacer>
+     </item>
+    </layout>
+   </item>
+   <item>
+    <spacer name="verticalSpacer">
+     <property name="orientation">
+      <enum>Qt::Vertical</enum>
+     </property>
+     <property name="sizeHint" stdset="0">
+      <size>
+       <width>20</width>
+       <height>40</height>
+      </size>
+     </property>
+    </spacer>
+   </item>
+   <item>
+    <layout class="QHBoxLayout" name="horizontalLayout_4">
+     <item>
+      <spacer name="horizontalSpacer_4">
+       <property name="orientation">
+        <enum>Qt::Horizontal</enum>
+       </property>
+       <property name="sizeHint" stdset="0">
+        <size>
+         <width>40</width>
+         <height>20</height>
+        </size>
+       </property>
+      </spacer>
+     </item>
+     <item>
+      <widget class="QPushButton" name="okButton">
+       <property name="text">
+        <string>&amp;Ok</string>
+       </property>
+       <property name="default">
+        <bool>true</bool>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <widget class="QPushButton" name="cancelButton">
+       <property name="text">
+        <string>&amp;Cancel</string>
+       </property>
+      </widget>
+     </item>
+    </layout>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections/>
+ <buttongroups>
+  <buttongroup name="pagesButtonGroup"/>
+ </buttongroups>
+</ui>
diff --git a/scribus/ui/applytemplatedialog.cpp b/scribus/ui/applytemplatedialog.cpp
deleted file mode 100644
index 5fc56c9ee..000000000
--- a/scribus/ui/applytemplatedialog.cpp
+++ /dev/null
@@ -1,290 +0,0 @@
-/*
-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.
-*/
-/***************************************************************************
- *                                                                         *
- *   This program is free software; you can redistribute it and/or modify  *
- *   it under the terms of the GNU General Public License as published by  *
- *   the Free Software Foundation; either version 2 of the License, or     *
- *   (at your option) any later version.                                   *
- *                                                                         *
- ***************************************************************************/
-#include "applytemplatedialog.h"
-
-#include <QCheckBox>
-#include <QComboBox>
-#include <QEvent>
-#include <QGroupBox>
-#include <QHBoxLayout>
-#include <QLabel>
-#include <QPushButton>
-#include <QRadioButton>
-#include <QSpacerItem>
-#include <QSpinBox>
-#include <QToolTip>
-#include <QVBoxLayout>
-
-#include "commonstrings.h"
-#include "scpage.h"
-#include "scribusdoc.h"
-#include "iconmanager.h"
-
-enum {
-    CurrentPage,
-    EvenPages,
-    OddPages,
-    AllPages
-};
-
-/*
- *  Constructs a ApplyMasterPageDialog as a child of 'parent', with the
- *  name 'name' and widget flags set to 'f'.
- *
- *  The dialog will by default be modeless, unless you set 'modal' to
- *  true to construct a modal dialog.
- */
-ApplyMasterPageDialog::ApplyMasterPageDialog( QWidget* parent ) : QDialog( parent )
-{
-	setModal(true);
-	setWindowTitle( tr( "Possible Hyphenation" ));
-	setWindowIcon(IconManager::instance().loadIcon("AppIcon.png"));
-	ApplyMasterPageDialogLayout = new QVBoxLayout(this);
-	ApplyMasterPageDialogLayout->setMargin(10);
-	ApplyMasterPageDialogLayout->setSpacing(5);
-
-	templateNameLayout = new QHBoxLayout;
-	templateNameLayout->setMargin(0);
-	templateNameLayout->setSpacing(5);
-
-	masterPageLabel = new QLabel( this );
-	templateNameLayout->addWidget( masterPageLabel );
-	spacer2 = new QSpacerItem( 1, 1, QSizePolicy::Expanding, QSizePolicy::Minimum );
-	templateNameLayout->addItem( spacer2 );
-
-	masterPageComboBox = new QComboBox(this);
-	masterPageComboBox->setEditable(false);
-	templateNameLayout->addWidget( masterPageComboBox );
-	ApplyMasterPageDialogLayout->addLayout( templateNameLayout );
-
-	applyToPageButtonGroup = new QGroupBox(this);
-	applyToPageButtonGroup->setMinimumSize( QSize( 250, 0 ) );
-	applyToPageButtonGroupLayout = new QVBoxLayout(applyToPageButtonGroup);
-	applyToPageButtonGroupLayout->setSpacing( 5 );
-	applyToPageButtonGroupLayout->setMargin( 10 );
-
-	currentPageRadioButton = new QRadioButton( applyToPageButtonGroup );
-	currentPageRadioButton->setChecked( true );
-	applyToPageButtonGroupLayout->addWidget( currentPageRadioButton );
-
-	evenPagesRadioButton = new QRadioButton( applyToPageButtonGroup );
-	applyToPageButtonGroupLayout->addWidget( evenPagesRadioButton );
-
-	oddPagesRadioButton = new QRadioButton( applyToPageButtonGroup );
-	applyToPageButtonGroupLayout->addWidget( oddPagesRadioButton );
-
-	allPagesRadioButton = new QRadioButton( applyToPageButtonGroup );
-	applyToPageButtonGroupLayout->addWidget( allPagesRadioButton );
-
-	rangeLayout = new QHBoxLayout;
-	rangeLayout->setSpacing( 5 );
-	rangeLayout->setMargin( 0 );
-
-	useRangeCheckBox = new QCheckBox( applyToPageButtonGroup );
-	useRangeCheckBox->setEnabled( false );	
-	rangeLayout->addWidget( useRangeCheckBox );
-
-	fromPageSpinBox = new ScrSpinBox( applyToPageButtonGroup );
-	fromPageSpinBox->setEnabled( false );
-	fromPageSpinBox->setMinimum( 1 );
-	fromPageSpinBox->setDecimals(0);
-	fromPageSpinBox->setSuffix("");
-	rangeLayout->addWidget( fromPageSpinBox );
-
-	toPageLabel = new QLabel( applyToPageButtonGroup );
-	rangeLayout->addWidget( toPageLabel );
-
-	toPageSpinBox = new ScrSpinBox( applyToPageButtonGroup );
-	toPageSpinBox->setEnabled( false );
-	toPageSpinBox->setMinimum( 1 );
-	toPageSpinBox->setDecimals(0);
-	toPageSpinBox->setSuffix("");
-	rangeLayout->addWidget( toPageSpinBox );
-	spacer3 = new QSpacerItem( 1, 1, QSizePolicy::Expanding, QSizePolicy::Minimum );
-	rangeLayout->addItem( spacer3 );
-	applyToPageButtonGroupLayout->addLayout( rangeLayout );
-	ApplyMasterPageDialogLayout->addWidget( applyToPageButtonGroup );
-
-	layout8 = new QHBoxLayout;
-	layout8->setSpacing( 5 );
-	layout8->setMargin( 0 );
-	spacer1 = new QSpacerItem( 1, 1, QSizePolicy::Expanding, QSizePolicy::Minimum );
-	layout8->addItem( spacer1 );
-
-	okButton = new QPushButton( this );
-	layout8->addWidget( okButton );
-
-	cancelButton = new QPushButton( this );
-	layout8->addWidget( cancelButton );
-	ApplyMasterPageDialogLayout->addLayout( layout8 );
-	languageChange();
-	resize( QSize(272, 230).expandedTo(minimumSizeHint()) );
-
-	// signals and slots connections
-	connect( useRangeCheckBox, SIGNAL( toggled(bool) ), this, SLOT( enableRange(bool) ) );
-	connect( currentPageRadioButton, SIGNAL( clicked() ), this, SLOT( singleSelectable() ) );
-	connect( evenPagesRadioButton, SIGNAL( clicked() ), this, SLOT( rangeSelectable() ) );
-	connect( oddPagesRadioButton, SIGNAL( clicked() ), this, SLOT( rangeSelectable() ) );
-	connect( allPagesRadioButton, SIGNAL( clicked() ), this, SLOT( rangeSelectable() ) );
-	connect( fromPageSpinBox, SIGNAL( valueChanged(double) ), this, SLOT( checkRangeFrom() ) );
-	connect( toPageSpinBox, SIGNAL( valueChanged(double) ), this, SLOT( checkRangeTo() ) );
-	connect( okButton, SIGNAL( clicked() ), this, SLOT( accept() ) );
-	connect( cancelButton, SIGNAL( clicked() ), this, SLOT( reject() ) );
-
-	// buddies
-	masterPageLabel->setBuddy( masterPageComboBox );
-}
-
-/*
- *  Destroys the object and frees any allocated resources
- */
-ApplyMasterPageDialog::~ApplyMasterPageDialog()
-{
-	// no need to delete child widgets, Qt does it all for us
-}
-
-void ApplyMasterPageDialog::setup(ScribusDoc *doc, QString Nam)
-{
-	QString na = Nam == CommonStrings::masterPageNormal ? CommonStrings::trMasterPageNormal : Nam, in;
-	int cc = 0;
-	for (QMap<QString,int>::Iterator it = doc->MasterNames.begin(); it != doc->MasterNames.end(); ++it)
-	{
-		in = it.key() == CommonStrings::masterPageNormal ? CommonStrings::trMasterPageNormal : it.key();
-		masterPageComboBox->addItem(in, it.key());
-		if (in == na)
-			masterPageComboBox->setCurrentIndex(cc);
-		++cc;
-	}
-	const unsigned int docPagesCount = doc->Pages->count();
-	if (docPagesCount < 2)
-		evenPagesRadioButton->setEnabled(false);
-	fromPageSpinBox->setMaximum(docPagesCount);
-	fromPageSpinBox->setValue(doc->currentPage()->pageNr()+1);
-	toPageSpinBox->setMaximum(docPagesCount);
-	toPageSpinBox->setValue(static_cast<int>(docPagesCount));
-}
-
-
-QString ApplyMasterPageDialog::getMasterPageName()
-{
-	int currentIndex = masterPageComboBox->currentIndex();
-	return masterPageComboBox->itemData(currentIndex).toString();
-}
-
-
-int ApplyMasterPageDialog::getPageSelection()
-{
-	if (currentPageRadioButton->isChecked())
-		return CurrentPage;
-	if (evenPagesRadioButton->isChecked())
-		return EvenPages;
-	if (oddPagesRadioButton->isChecked())
-		return OddPages;
-	return AllPages;
-}
-
-void ApplyMasterPageDialog::checkRangeFrom()
-{
-	disconnect(fromPageSpinBox, SIGNAL(valueChanged(double)), this, SLOT(checkRangeFrom()));
-	disconnect(toPageSpinBox, SIGNAL(valueChanged(double)), this, SLOT(checkRangeTo()));
-	if (fromPageSpinBox->value() > toPageSpinBox->value())
-		toPageSpinBox->setValue(fromPageSpinBox->value());
-	connect(fromPageSpinBox, SIGNAL(valueChanged(double)), this, SLOT(checkRangeFrom()));
-	connect(toPageSpinBox, SIGNAL(valueChanged(double)), this, SLOT(checkRangeTo()));
-}
-
-void ApplyMasterPageDialog::checkRangeTo()
-{
-	disconnect(fromPageSpinBox, SIGNAL(valueChanged(double)), this, SLOT(checkRangeFrom()));
-	disconnect(toPageSpinBox, SIGNAL(valueChanged(double)), this, SLOT(checkRangeTo()));
-	if (toPageSpinBox->value() < fromPageSpinBox->value())
-		fromPageSpinBox->setValue(toPageSpinBox->value());
-	connect(fromPageSpinBox, SIGNAL(valueChanged(double)), this, SLOT(checkRangeFrom()));
-	connect(toPageSpinBox, SIGNAL(valueChanged(double)), this, SLOT(checkRangeTo()));
-}
-
-void ApplyMasterPageDialog::enableRange( bool enabled )
-{
-	fromPageSpinBox->setEnabled(enabled);
-	toPageSpinBox->setEnabled(enabled);
-}
-
-void ApplyMasterPageDialog::rangeSelectable()
-{
-	useRangeCheckBox->setEnabled(true);
-	enableRange(useRangeCheckBox->isChecked());
-}
-
-void ApplyMasterPageDialog::singleSelectable()
-{
-	useRangeCheckBox->setEnabled(false);
-	fromPageSpinBox->setEnabled(false);
-	toPageSpinBox->setEnabled(false);
-}
-
-
-bool ApplyMasterPageDialog::usingRange()
-{
-	return useRangeCheckBox->isChecked();
-}
-
-
-int ApplyMasterPageDialog::getFromPage()
-{
-	if (useRangeCheckBox->isChecked())
-		return static_cast<int>(fromPageSpinBox->value());
-	return -1;
-}
-
-
-int ApplyMasterPageDialog::getToPage()
-{
-	if (useRangeCheckBox->isChecked())
-		return static_cast<int>(toPageSpinBox->value());
-	return -1;
-}
-
-void ApplyMasterPageDialog::changeEvent(QEvent *e)
-{
-	if (e->type() == QEvent::LanguageChange)
-	{
-		languageChange();
-	}
-	else
-		QWidget::changeEvent(e);
-}
-
-void ApplyMasterPageDialog::languageChange()
-{
-	setWindowTitle( tr( "Apply Master Page" ) );
-	masterPageLabel->setText( tr( "&Master Page:" ) );
-	applyToPageButtonGroup->setTitle( tr( "Apply to" ) );
-	currentPageRadioButton->setText( tr( "Current &Page" ) );
-	currentPageRadioButton->setShortcut( QKeySequence( tr( "Alt+P" ) ) );
-	evenPagesRadioButton->setText( tr( "&Even Pages" ) );
-	evenPagesRadioButton->setShortcut( QKeySequence( tr( "Alt+E" ) ) );
-	oddPagesRadioButton->setText( tr( "O&dd Pages" ) );
-	oddPagesRadioButton->setShortcut( QKeySequence( tr( "Alt+D" ) ) );
-	allPagesRadioButton->setText( tr( "&All Pages" ) );
-	allPagesRadioButton->setShortcut( QKeySequence( tr( "Alt+A" ) ) );
-	useRangeCheckBox->setText( tr( "&Within Range" ) );
-	useRangeCheckBox->setShortcut( QKeySequence( tr( "Alt+W" ) ) );
-	useRangeCheckBox->setToolTip( "<qt>" + tr( "Apply the selected master page to even, odd or all pages within the following range") + "</qt>" );
-	toPageLabel->setText( tr( "to" ) );
-	okButton->setText( CommonStrings::tr_OK );
-	okButton->setShortcut( QKeySequence( tr( "Alt+O" ) ) );
-	cancelButton->setText( CommonStrings::tr_Cancel );
-	cancelButton->setShortcut( QKeySequence( tr( "Alt+C" ) ) );
-}
diff --git a/scribus/ui/applytemplatedialog.h b/scribus/ui/applytemplatedialog.h
deleted file mode 100644
index 2ca5d02d3..000000000
--- a/scribus/ui/applytemplatedialog.h
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
-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.
-*/
-/***************************************************************************
- *                                                                         *
- *   This program is free software; you can redistribute it and/or modify  *
- *   it under the terms of the GNU General Public License as published by  *
- *   the Free Software Foundation; either version 2 of the License, or     *
- *   (at your option) any later version.                                   *
- *                                                                         *
- ***************************************************************************/
-#ifndef APPLYMASTERPAGEDIALOG_H
-#define APPLYMASTERPAGEDIALOG_H
-
-#include <QDialog>
-#include <QString>
-
-#include "scribusapi.h"
-#include "scribusdoc.h"
-#include "scpage.h"
-#include "ui/scrspinbox.h"
-
-class QCheckBox;
-class QComboBox;
-class QEvent;
-class QGroupBox;
-class QHBoxLayout;
-class QLabel;
-class QPushButton;
-class QRadioButton;
-class QSpacerItem;
-class QVBoxLayout;
-
-class SCRIBUS_API ApplyMasterPageDialog : public QDialog
-{
-	Q_OBJECT
-
-public:
-	ApplyMasterPageDialog( QWidget* parent = 0 );
-	~ApplyMasterPageDialog();
-	
-	virtual void changeEvent(QEvent *e);
-
-	QLabel* masterPageLabel;
-	QComboBox* masterPageComboBox;
-	QGroupBox* applyToPageButtonGroup;
-	QRadioButton* currentPageRadioButton;
-	QRadioButton* evenPagesRadioButton;
-	QRadioButton* oddPagesRadioButton;
-	QRadioButton* allPagesRadioButton;
-	QCheckBox* useRangeCheckBox;
-	ScrSpinBox* fromPageSpinBox;
-	QLabel* toPageLabel;
-	ScrSpinBox* toPageSpinBox;
-	QPushButton* okButton;
-	QPushButton* cancelButton;
-
-	virtual void setup( ScribusDoc * view, QString Nam );
-	virtual QString getMasterPageName();
-	virtual int getPageSelection();
-	virtual bool usingRange();
-	virtual int getFromPage();
-	virtual int getToPage();
-
-protected:
-	QVBoxLayout* ApplyMasterPageDialogLayout;
-	QHBoxLayout* templateNameLayout;
-	QSpacerItem* spacer2;
-	QVBoxLayout* applyToPageButtonGroupLayout;
-	QHBoxLayout* rangeLayout;
-	QSpacerItem* spacer3;
-	QHBoxLayout* layout8;
-	QSpacerItem* spacer1;
-
-protected slots:
-	virtual void languageChange();
-
-private slots:
-	virtual void checkRangeFrom();
-	virtual void checkRangeTo();
-	virtual void enableRange( bool enabled );
-	virtual void rangeSelectable();
-	virtual void singleSelectable();
-
-};
-
-#endif // APPLYMASTERPAGEDIALOG_H
diff --git a/scribus/ui/pagepalette_masterpages.cpp b/scribus/ui/pagepalette_masterpages.cpp
index 8490292a4..c439277b5 100644
--- a/scribus/ui/pagepalette_masterpages.cpp
+++ b/scribus/ui/pagepalette_masterpages.cpp
@@ -26,6 +26,7 @@ for which a new license (GPL+exception) is in place.
 #include "canvasmode.h"
 #include "commonstrings.h"
 #include "iconmanager.h"
+#include "masterpage.h"
 #include "mergedoc.h"
 #include "newtemp.h"
 #include "pagestructs.h"
@@ -154,7 +155,7 @@ void PagePalette_MasterPages::deleteMasterPage()
 	{
 		m_currentPage = delItem->text();
 
-		if (isReservedName(m_currentPage))
+		if (MasterPage::isReservedName(m_currentPage))
 			continue;
 
 		QString extraWarn = "";
@@ -213,7 +214,7 @@ void PagePalette_MasterPages::duplicateMasterPage()
 	if (name.isEmpty())
 		return;
 
-	name = getNonReservedName(name);
+	name = MasterPage::getNonReservedName(name);
 	name = getUniqueName(name, m_doc->MasterNames);
 
 	PrefsManager& prefsManager = PrefsManager::instance();
@@ -322,7 +323,7 @@ void PagePalette_MasterPages::newMasterPage()
 	if (name.isEmpty())
 		return;
 
-	name = getNonReservedName(name);
+	name = MasterPage::getNonReservedName(name);
 	name = getUniqueName(name, m_doc->MasterNames);
 
 	m_doc->setCurrentPage(m_doc->addMasterPage(nr, name));
@@ -457,7 +458,7 @@ void PagePalette_MasterPages::updateMasterPageList(QString masterPageName)
 			mpName = CommonStrings::trMasterPageNormal;
 		QListWidgetItem* mpItem = new QListWidgetItem(mpName);
 
-		if (!isReservedName(mpName))
+		if (!MasterPage::isReservedName(mpName))
 			mpItem->setFlags(mpItem->flags() |= Qt::ItemIsEditable);
 		else
 			mpItem->setFlags(mpItem->flags() &= ~Qt::ItemIsEditable);
@@ -504,7 +505,7 @@ void PagePalette_MasterPages::renameMasterPage(QListWidgetItem * item)
 	//		masterPageListBox->blockSignals(sigBlocked);
 	// }
 
-	if (newName.isEmpty() || isReservedName(newName) ||
+	if (newName.isEmpty() || MasterPage::isReservedName(newName) ||
 		!m_doc->MasterNames.contains(oldName) ||
 		m_doc->MasterNames.contains(newName))
 	{
@@ -538,43 +539,3 @@ void PagePalette_MasterPages::changeEvent(QEvent *e)
 
 	QWidget::changeEvent(e);
 }
-
-// FIXME: move to a new masterpages.h
-bool PagePalette_MasterPages::isReservedName(const QString& name) const
-{
-	return name == CommonStrings::masterPageNormal ||
-		name == CommonStrings::trMasterPageNormal ||
-		name == CommonStrings::masterPageNormalLeft ||
-		name == CommonStrings::trMasterPageNormalLeft ||
-		name == CommonStrings::masterPageNormalMiddle ||
-		name == CommonStrings::trMasterPageNormalMiddle ||
-		name == CommonStrings::masterPageNormalRight ||
-		name == CommonStrings::trMasterPageNormalRight;
-}
-
-// FIXME: move to a new masterpages.h
-QString PagePalette_MasterPages::getNonReservedName(const QString& name) const
-{
-	const QStringList reservedNames = {
-		CommonStrings::masterPageNormal,
-		CommonStrings::trMasterPageNormal,
-		CommonStrings::trMasterPageNormalLeft,
-		CommonStrings::trMasterPageNormalMiddle,
-		CommonStrings::trMasterPageNormalRight
-	};
-	return getUniqueName(name, reservedNames);
-}
-
-// FIXME: move to a new masterpages.h
-QString PagePalette_MasterPages::getTranslatedReservedName(const QString& name) const
-{
-	if (name == CommonStrings::masterPageNormal)
-		return CommonStrings::trMasterPageNormal;
-	if (name == CommonStrings::masterPageNormalLeft)
-		return CommonStrings::trMasterPageNormalLeft;
-	if (name == CommonStrings::masterPageNormalMiddle)
-		return CommonStrings::trMasterPageNormalMiddle;
-	if (name == CommonStrings::masterPageNormalRight)
-		return CommonStrings::trMasterPageNormalRight;
-	return name;
-}
diff --git a/scribus/ui/pagepalette_masterpages.h b/scribus/ui/pagepalette_masterpages.h
index 9939e4b60..6aead7bc4 100644
--- a/scribus/ui/pagepalette_masterpages.h
+++ b/scribus/ui/pagepalette_masterpages.h
@@ -53,13 +53,6 @@ protected:
 
 	void changeEvent(QEvent *e) override;
 
-	bool isReservedName(const QString& name) const;
-	QString getNonReservedName(const QString& name) const;
-	/*!
-	 * \retval the current name or, if it's a standard one, the translated version
-	*/
-	QString getTranslatedReservedName(const QString& name) const;
-
 private slots:
 	void duplicateMasterPage();
 	void deleteMasterPage();
masterpage-replace.diff (41,323 bytes)   

Issue History

Date Modified Username Field Change
2019-11-13 08:14 ale New Issue
2019-11-13 08:14 ale Assigned To => ale
2019-11-13 08:14 ale Status new => assigned
2019-11-13 09:19 jghali Severity minor => feature
2019-11-14 19:49 ale File Added: masterpage-replace.diff
2019-11-14 19:49 ale Note Added: 0047079
2019-11-14 19:50 ale Summary apply master page to pages with a given master page => [PATCH] apply master page to pages with a given master page
2019-11-14 19:50 ale Patch No => Yes