r22733 by jghali - cmdtext.cpp refactoring and consequent scribus/scribusdoc cleanups

scribus-commit scribus-commit at lists.scribus.net
Sun Oct 14 13:08:04 UTC 2018


Author: jghali
Date: Sun Oct 14 13:08:04 2018
New Revision: 22733

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=22733
Log:
cmdtext.cpp refactoring and consequent scribus/scribusdoc cleanups

Modified:
    trunk/Scribus/scribus/plugins/fontpreview/fontpreviewplugin.cpp
    trunk/Scribus/scribus/plugins/scriptplugin/cmdtext.cpp
    trunk/Scribus/scribus/scribus.cpp
    trunk/Scribus/scribus/scribus.h
    trunk/Scribus/scribus/scribusdoc.cpp
    trunk/Scribus/scribus/scribusdoc.h
    trunk/Scribus/scribus/ui/propertiespalette_text.cpp
    trunk/Scribus/scribus/ui/search.h

Modified: trunk/Scribus/scribus/plugins/fontpreview/fontpreviewplugin.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22733&path=/trunk/Scribus/scribus/plugins/fontpreview/fontpreviewplugin.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/fontpreview/fontpreviewplugin.cpp	(original)
+++ trunk/Scribus/scribus/plugins/fontpreview/fontpreviewplugin.cpp	Sun Oct 14 13:08:04 2018
@@ -100,7 +100,7 @@
 	if (dlg->exec() == QDialog::Accepted)
 	{
 		if  (target.isEmpty())
-			doc->scMW()->SetNewFont(dlg->getCurrentFont());
+			doc->itemSelection_SetFont(dlg->getCurrentFont());
 		else
 			m_runResult = dlg->getCurrentFont();
 	}

Modified: trunk/Scribus/scribus/plugins/scriptplugin/cmdtext.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22733&path=/trunk/Scribus/scribus/plugins/scriptplugin/cmdtext.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/scriptplugin/cmdtext.cpp	(original)
+++ trunk/Scribus/scribus/plugins/scriptplugin/cmdtext.cpp	Sun Oct 14 13:08:04 2018
@@ -438,14 +438,16 @@
 		PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set text alignment on a non-text frame.","python error").toLocal8Bit().constData());
 		return nullptr;
 	}
-	int Apm = ScCore->primaryMainWindow()->doc->appMode;
-	ScCore->primaryMainWindow()->doc->m_Selection->clear();
-	ScCore->primaryMainWindow()->doc->m_Selection->addItem(item);
+	
+	ScribusDoc* doc = ScCore->primaryMainWindow()->doc;
+	int oldAppMode  = ScCore->primaryMainWindow()->doc->appMode;
+
+	Selection tmpSelection(nullptr, false);
+	tmpSelection.addItem(item);
 	if (item->HasSel)
-		ScCore->primaryMainWindow()->doc->appMode = modeEdit;
-	ScCore->primaryMainWindow()->setNewAlignment(alignment);
-	ScCore->primaryMainWindow()->doc->appMode = Apm;
-	ScCore->primaryMainWindow()->view->Deselect();
+		doc->appMode = modeEdit;
+	doc->itemSelection_SetAlignment(alignment, &tmpSelection);
+	doc->appMode = oldAppMode;
 
 	Py_RETURN_NONE;
 }
@@ -471,14 +473,16 @@
 		PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set text direction on a non-text frame.","python error").toLocal8Bit().constData());
 		return nullptr;
 	}
-	int Apm = ScCore->primaryMainWindow()->doc->appMode;
-	ScCore->primaryMainWindow()->doc->m_Selection->clear();
-	ScCore->primaryMainWindow()->doc->m_Selection->addItem(item);
+
+	ScribusDoc* doc = ScCore->primaryMainWindow()->doc;
+	int oldAppMode = ScCore->primaryMainWindow()->doc->appMode;
+
+	Selection tmpSelection(nullptr, false);
+	tmpSelection.addItem(item);
 	if (item->HasSel)
-		ScCore->primaryMainWindow()->doc->appMode = modeEdit;
-	ScCore->primaryMainWindow()->setNewDirection(direction);
-	ScCore->primaryMainWindow()->doc->appMode = Apm;
-	ScCore->primaryMainWindow()->view->Deselect();
+		doc->appMode = modeEdit;
+	doc->itemSelection_SetDirection(direction, &tmpSelection);
+	doc->appMode = oldAppMode;
 
 	Py_RETURN_NONE;
 }
@@ -505,14 +509,16 @@
 		PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set font size on a non-text frame.","python error").toLocal8Bit().constData());
 		return nullptr;
 	}
-	int Apm = ScCore->primaryMainWindow()->doc->appMode;
-	ScCore->primaryMainWindow()->doc->m_Selection->clear();
-	ScCore->primaryMainWindow()->doc->m_Selection->addItem(item);
+
+	ScribusDoc* doc = ScCore->primaryMainWindow()->doc;
+	int oldAppMode = ScCore->primaryMainWindow()->doc->appMode;
+
+	Selection tmpSelection(nullptr, false);
+	tmpSelection.addItem(item);
 	if (item->HasSel)
-		ScCore->primaryMainWindow()->doc->appMode = modeEdit;
-	ScCore->primaryMainWindow()->doc->itemSelection_SetFontSize(qRound(size * 10.0));
-	ScCore->primaryMainWindow()->doc->appMode = Apm;
-	ScCore->primaryMainWindow()->view->Deselect();
+		doc->appMode = modeEdit;
+	doc->itemSelection_SetFontSize(qRound(size * 10.0), &tmpSelection);
+	doc->appMode = oldAppMode;
 
 	Py_RETURN_NONE;
 }
@@ -535,14 +541,16 @@
 		PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set font feature on a non-text frame.","python error").toLocal8Bit().constData());
 		return nullptr;
 	}
-	int Apm = ScCore->primaryMainWindow()->doc->appMode;
-	ScCore->primaryMainWindow()->doc->m_Selection->clear();
-	ScCore->primaryMainWindow()->doc->m_Selection->addItem(item);
+
+	ScribusDoc* doc = ScCore->primaryMainWindow()->doc;
+	int oldAppMode = ScCore->primaryMainWindow()->doc->appMode;
+
+	Selection tmpSelection(nullptr, false);
+	tmpSelection.addItem(item);
 	if (item->HasSel)
-		ScCore->primaryMainWindow()->doc->appMode = modeEdit;
-	ScCore->primaryMainWindow()->doc->itemSelection_SetFontFeatures(QString::fromUtf8(fontfeature));
-	ScCore->primaryMainWindow()->doc->appMode = Apm;
-	ScCore->primaryMainWindow()->view->Deselect();
+		doc->appMode = modeEdit;
+	doc->itemSelection_SetFontFeatures(QString::fromUtf8(fontfeature), &tmpSelection);
+	doc->appMode = oldAppMode;
 
 	Py_RETURN_NONE;
 }
@@ -563,22 +571,22 @@
 		PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set font on a non-text frame.","python error").toLocal8Bit().constData());
 		return nullptr;
 	}
-	if (PrefsManager::instance()->appPrefs.fontPrefs.AvailFonts.contains(QString::fromUtf8(Font)))
-	{
-		int Apm = ScCore->primaryMainWindow()->doc->appMode;
-		ScCore->primaryMainWindow()->doc->m_Selection->clear();
-		ScCore->primaryMainWindow()->doc->m_Selection->addItem(item);
-		if (item->HasSel)
-			ScCore->primaryMainWindow()->doc->appMode = modeEdit;
-		ScCore->primaryMainWindow()->SetNewFont(QString::fromUtf8(Font));
-		ScCore->primaryMainWindow()->doc->appMode = Apm;
-		ScCore->primaryMainWindow()->view->Deselect();
-	}
-	else
-	{
-		PyErr_SetString(PyExc_ValueError, QObject::tr("Font not found.","python error").toLocal8Bit().constData());
-		return nullptr;
-	}
+	if (!PrefsManager::instance()->appPrefs.fontPrefs.AvailFonts.contains(QString::fromUtf8(Font)))
+	{
+		PyErr_SetString(PyExc_ValueError, QObject::tr("Font not found.", "python error").toLocal8Bit().constData());
+		return nullptr;
+	}
+
+	ScribusDoc* doc = ScCore->primaryMainWindow()->doc;
+	int oldAppMode = ScCore->primaryMainWindow()->doc->appMode;
+
+	Selection tmpSelection(nullptr, false);
+	tmpSelection.addItem(item);
+	if (item->HasSel)
+		doc->appMode = modeEdit;
+	doc->itemSelection_SetFont(QString::fromUtf8(Font), &tmpSelection);
+	doc->appMode = oldAppMode;
+
 	Py_RETURN_NONE;
 }
 
@@ -603,15 +611,16 @@
 		PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set line spacing on a non-text frame.","python error").toLocal8Bit().constData());
 		return nullptr;
 	}
-	
-	int Apm = ScCore->primaryMainWindow()->doc->appMode;
-	ScCore->primaryMainWindow()->doc->m_Selection->clear();
-	ScCore->primaryMainWindow()->doc->m_Selection->addItem(item);
+
+	ScribusDoc* doc = ScCore->primaryMainWindow()->doc;
+	int oldAppMode = ScCore->primaryMainWindow()->doc->appMode;
+
+	Selection tmpSelection(nullptr, false);
+	tmpSelection.addItem(item);
 	if (item->HasSel)
-		ScCore->primaryMainWindow()->doc->appMode = modeEdit;
-	ScCore->primaryMainWindow()->doc->itemSelection_SetLineSpacing(w);
-	ScCore->primaryMainWindow()->doc->appMode = Apm;
-	ScCore->primaryMainWindow()->view->Deselect();
+		doc->appMode = modeEdit;
+	doc->itemSelection_SetLineSpacing(w, &tmpSelection);
+	doc->appMode = oldAppMode;
 		
 //	item->setLineSpacing(w);
 	Py_RETURN_NONE;
@@ -638,15 +647,16 @@
 		PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set line spacing mode on a non-text frame.","python error").toLocal8Bit().constData());
 		return nullptr;
 	}
-	
-	int Apm = ScCore->primaryMainWindow()->doc->appMode;
-	ScCore->primaryMainWindow()->doc->m_Selection->clear();
-	ScCore->primaryMainWindow()->doc->m_Selection->addItem(item);
+
+	ScribusDoc* doc = ScCore->primaryMainWindow()->doc;
+	int oldAppMode = ScCore->primaryMainWindow()->doc->appMode;
+
+	Selection tmpSelection(nullptr, false);
+	tmpSelection.addItem(item);
 	if (item->HasSel)
-		ScCore->primaryMainWindow()->doc->appMode = modeEdit;
-	ScCore->primaryMainWindow()->doc->itemSelection_SetLineSpacingMode(w);
-	ScCore->primaryMainWindow()->doc->appMode = Apm;
-	ScCore->primaryMainWindow()->view->Deselect();
+		doc->appMode = modeEdit;
+	doc->itemSelection_SetLineSpacingMode(w, &tmpSelection);
+	doc->appMode = oldAppMode;
 		
 	Py_RETURN_NONE;
 }
@@ -925,15 +935,16 @@
 		PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set character scaling on a non-text frame.","python error").toLocal8Bit().constData());
 		return nullptr;
 	}
-	
-	int Apm = ScCore->primaryMainWindow()->doc->appMode;
-	ScCore->primaryMainWindow()->doc->m_Selection->clear();
-	ScCore->primaryMainWindow()->doc->m_Selection->addItem(item);
+
+	ScribusDoc* doc = ScCore->primaryMainWindow()->doc;
+	int oldAppMode = ScCore->primaryMainWindow()->doc->appMode;
+
+	Selection tmpSelection(nullptr, false);
+	tmpSelection.addItem(item);
 	if (item->HasSel)
-		ScCore->primaryMainWindow()->doc->appMode = modeEdit;
-	ScCore->primaryMainWindow()->doc->itemSelection_SetScaleH(qRound(sc * 10));
-	ScCore->primaryMainWindow()->doc->appMode = Apm;
-	ScCore->primaryMainWindow()->view->Deselect();
+		doc->appMode = modeEdit;
+	doc->itemSelection_SetScaleH(qRound(sc * 10), &tmpSelection);
+	doc->appMode = oldAppMode;
 		
 	Py_RETURN_NONE;
 }
@@ -960,15 +971,16 @@
 		PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set character scaling on a non-text frame.","python error").toLocal8Bit().constData());
 		return nullptr;
 	}
-	
-	int Apm = ScCore->primaryMainWindow()->doc->appMode;
-	ScCore->primaryMainWindow()->doc->m_Selection->clear();
-	ScCore->primaryMainWindow()->doc->m_Selection->addItem(item);
+
+	ScribusDoc* doc = ScCore->primaryMainWindow()->doc;
+	int oldAppMode = ScCore->primaryMainWindow()->doc->appMode;
+
+	Selection tmpSelection(nullptr, false);
+	tmpSelection.addItem(item);
 	if (item->HasSel)
-		ScCore->primaryMainWindow()->doc->appMode = modeEdit;
-	ScCore->primaryMainWindow()->doc->itemSelection_SetScaleV(qRound(sc * 10));
-	ScCore->primaryMainWindow()->doc->appMode = Apm;
-	ScCore->primaryMainWindow()->view->Deselect();
+		doc->appMode = modeEdit;
+	doc->itemSelection_SetScaleV(qRound(sc * 10), &tmpSelection);
+	doc->appMode = oldAppMode;
 		
 	Py_RETURN_NONE;
 }

Modified: trunk/Scribus/scribus/scribus.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22733&path=/trunk/Scribus/scribus/scribus.cpp
==============================================================================
--- trunk/Scribus/scribus/scribus.cpp	(original)
+++ trunk/Scribus/scribus/scribus.cpp	Sun Oct 14 13:08:04 2018
@@ -6291,12 +6291,6 @@
 	doc->updateEndnotesFrames();
 }
 
-void ScribusMainWindow::SetNewFont(const QString& nf)
-{
-	setMainWindowActive();
-	doc->itemSetFont(nf);
-}
-
 void ScribusMainWindow::setItemFontSize(int fontSize)
 {
 	int fs=fontSize;
@@ -8486,8 +8480,6 @@
 	view->requestMode(modeEdit);
 	currItem->itemText.setCursorPosition(0);
 	SearchReplace* dia = new SearchReplace(this, doc, currItem);
-	connect(dia, SIGNAL(NewFont(const QString&)), this, SLOT(SetNewFont(const QString&)));
-	connect(dia, SIGNAL(NewAbs(int)), this, SLOT(setAlignmentValue(int)));
 	dia->exec();
 	dia->disconnect();
 	delete dia;

Modified: trunk/Scribus/scribus/scribus.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22733&path=/trunk/Scribus/scribus/scribus.h
==============================================================================
--- trunk/Scribus/scribus/scribus.h	(original)
+++ trunk/Scribus/scribus/scribus.h	Sun Oct 14 13:08:04 2018
@@ -457,9 +457,6 @@
 	void slotDocCh(bool reb = true);
 	/** Setzt die Abstufung */
 	//void setItemShade(int id);
-	/** Setzt den Font */
-	/** Korrigiert das FontMenu */
-	void SetNewFont(const QString& nf);
 	/** Setz die Zeichensatzgroesse */
 	void setItemFontSize(int fontSize);
 	void setItemLanguage(const QString& language);

Modified: trunk/Scribus/scribus/scribusdoc.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22733&path=/trunk/Scribus/scribus/scribusdoc.cpp
==============================================================================
--- trunk/Scribus/scribus/scribusdoc.cpp	(original)
+++ trunk/Scribus/scribus/scribusdoc.cpp	Sun Oct 14 13:08:04 2018
@@ -2441,7 +2441,6 @@
 
 bool ScribusDoc::AddFont(const QString& name, int fsize)
 {
-	bool ret = false;
 	if (UsedFonts.contains(name))
 		return true;
 
@@ -2450,8 +2449,8 @@
 
 	UsedFonts[name] = fsize;
 	(*AllFonts)[name].increaseUsage();
-	ret = true;
-	return ret;
+
+	return true;
 }
 
 
@@ -7826,8 +7825,6 @@
 	changed();
 }
 
-
-
 void ScribusDoc::itemSelection_SetLineSpacing(double w, Selection* customSelection)
 {
 	ParagraphStyle newStyle;
@@ -7835,11 +7832,35 @@
 	itemSelection_ApplyParagraphStyle(newStyle, customSelection);
 }
 
-void ScribusDoc::itemSelection_SetFont(const QString& fon, Selection* customSelection)
-{
+void ScribusDoc::itemSelection_SetFont(const QString& font, Selection* customSelection)
+{
+	Selection* itemSelection = (customSelection != nullptr) ? customSelection : m_Selection;
+	assert(itemSelection != nullptr);
+
+	uint selectedItemCount = itemSelection->count();
+	if (selectedItemCount == 0)
+		return;
+
+	QString newFont(font);
+	if (!UsedFonts.contains(newFont))
+	{
+		if (!AddFont(font))
+		{
+			PageItem *currItem = m_Selection->itemAt(0);
+			newFont = currItem->currentCharStyle().font().scName();
+		}
+	}
+
 	CharStyle newStyle;
-	newStyle.setFont((*AllFonts)[fon]);
+	newStyle.setFont((*AllFonts)[newFont]);
 	itemSelection_ApplyCharStyle(newStyle, customSelection, "FONT");
+}
+
+void ScribusDoc::itemSelection_SetFontSize(int size, Selection* customSelection)
+{
+	CharStyle newStyle;
+	newStyle.setFontSize(size);
+	itemSelection_ApplyCharStyle(newStyle, customSelection, "FONT_SIZE");
 }
 
 void ScribusDoc::itemSelection_SetFontFeatures(const QString& fontfeature, Selection* customSelection)
@@ -8872,39 +8893,6 @@
 	itemSelection_ApplyCharStyle(newStyle, customSelection, "LANGUAGE");
 }
 
-void ScribusDoc::itemSetFont(const QString &newFont)
-{
-	QString nf2(newFont);
-	if (!UsedFonts.contains(newFont))
-	{
-		if (!AddFont(newFont))
-		{
-			if (m_Selection->count() != 0)
-			{
-				PageItem *currItem = m_Selection->itemAt(0);
-				nf2 = currItem->currentCharStyle().font().scName();
-			}
-		}
-	}
-	PageItem *i2 = m_Selection->itemAt(0);
-	if (appMode == modeEditTable)
-		i2 = m_Selection->itemAt(0)->asTable()->activeCell().textFrame();
-	if (i2 != nullptr)
-	{
-		Selection tempSelection(this, false);
-		tempSelection.addItem(i2, true);
-		itemSelection_SetFont(nf2, &tempSelection);
-	}
-	m_View->DrawNew();
-}
-
-void ScribusDoc::itemSelection_SetFontSize(int size, Selection* customSelection)
-{
-	CharStyle newStyle;
-	newStyle.setFontSize(size);
-	itemSelection_ApplyCharStyle(newStyle, customSelection, "FONT_SIZE");
-}
-
 void ScribusDoc::itemSelection_ToggleBookMark(Selection *customSelection)
 {
 	Selection* itemSelection = (customSelection!=nullptr) ? customSelection : m_Selection;

Modified: trunk/Scribus/scribus/scribusdoc.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22733&path=/trunk/Scribus/scribus/scribusdoc.h
==============================================================================
--- trunk/Scribus/scribus/scribusdoc.h	(original)
+++ trunk/Scribus/scribus/scribusdoc.h	Sun Oct 14 13:08:04 2018
@@ -1064,8 +1064,9 @@
 	void itemSelection_SetLineSpacing(double w, Selection* customSelection = nullptr);
 	void itemSelection_SetLineSpacingMode(int w, Selection* customSelection = nullptr);
 	void itemSelection_SetLanguage(const QString& w, Selection* customSelection = nullptr);
-	void itemSetFont(const QString& newFont);
-	void itemSelection_SetFont(const QString& fon, Selection* customSelection = nullptr);
+	void itemSelection_SetFont(const QString& font, Selection* customSelection = nullptr);
+	void itemSelection_SetFontSize(int size, Selection* customSelection = nullptr);
+	void itemSelection_SetFontFeatures(const QString& fontfeature, Selection* customSelection = nullptr);
 	void itemSelection_SetParBackgroundColor(QString farbe, Selection* customSelection = nullptr);
 	void itemSelection_SetParBackgroundShade(int sha, Selection* customSelection = nullptr);
 	void itemSelection_SetBackgroundColor(QString farbe, Selection* customSelection = nullptr);
@@ -1089,7 +1090,6 @@
 	void itemSelection_SetCompressionMethod(int cmIndex, Selection* customSelection = nullptr);
 	void itemSelection_SetCompressionQuality(int cqIndex, Selection* customSelection = nullptr);
 	void itemSelection_SetTracking(int us, Selection* customSelection = nullptr);
-	void itemSelection_SetFontSize(int size, Selection* customSelection = nullptr);
 	void MirrorPolyH(PageItem *currItem);
 	void MirrorPolyV(PageItem *currItem);
 	bool getItem(PageItem **currItem, int nr = -1);
@@ -1457,7 +1457,6 @@
 	//! Delete the items in the current selection. When force is true, we do not warn the user and make SE happy too. Force is used from @sa Page::restorePageItemCreation
 	void itemSelection_DeleteItem(Selection* customSelection = nullptr, bool forceDeletion=false);
 	void itemSelection_SetItemFillTransparency(double t);
-	void itemSelection_SetFontFeatures(const QString& fontfeature, Selection* customSelection = nullptr);
 	void itemSelection_SetHyphenWordMin(int wordMin, Selection* customSelection = nullptr);
 	void itemSelection_SetHyphenConsecutiveLines(int consecutiveLines, Selection* customSelection = nullptr);
 	void itemSelection_SetHyphenChar(uint hyphenChar, Selection* customSelection = nullptr);

Modified: trunk/Scribus/scribus/ui/propertiespalette_text.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22733&path=/trunk/Scribus/scribus/ui/propertiespalette_text.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/propertiespalette_text.cpp	(original)
+++ trunk/Scribus/scribus/ui/propertiespalette_text.cpp	Sun Oct 14 13:08:04 2018
@@ -649,11 +649,13 @@
 	}
 }
 
-void PropertiesPalette_Text::handleTextFont(const QString& c)
+void PropertiesPalette_Text::handleTextFont(const QString& font)
 {
 	if (!m_haveDoc || !m_haveItem || !m_ScMW || m_ScMW->scriptIsRunning())
 		return;
-	m_ScMW->SetNewFont(c);
+	Selection tempSelection(this, false);
+	tempSelection.addItem(m_item, true);
+	m_doc->itemSelection_SetFont(font, &tempSelection);
 }
 
 void PropertiesPalette_Text::doClearCStyle()

Modified: trunk/Scribus/scribus/ui/search.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22733&path=/trunk/Scribus/scribus/ui/search.h
==============================================================================
--- trunk/Scribus/scribus/ui/search.h	(original)
+++ trunk/Scribus/scribus/ui/search.h	Sun Oct 14 13:08:04 2018
@@ -120,10 +120,6 @@
 	virtual void writePrefs();
 	virtual void clear();
 
-signals:
-	void NewFont(const QString&);
-	void NewAbs(int);
-
 protected:
 	PageItem*   m_item;
 	ScribusDoc* m_doc;




More information about the scribus-commit mailing list