r23658 by jghali - Second fix for style combos: display implicitly inherited styles in brackets

scribus-commit scribus-commit at lists.scribus.net
Sun Apr 26 17:48:02 UTC 2020


Author: jghali
Date: Sun Apr 26 17:48:02 2020
New Revision: 23658

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=23658
Log:
Second fix for style combos: display implicitly inherited styles in brackets

Modified:
    trunk/Scribus/scribus/ui/propertiespalette_text.cpp
    trunk/Scribus/scribus/ui/stylecombos.cpp
    trunk/Scribus/scribus/ui/stylecombos.h

Modified: trunk/Scribus/scribus/ui/propertiespalette_text.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23658&path=/trunk/Scribus/scribus/ui/propertiespalette_text.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/propertiespalette_text.cpp	(original)
+++ trunk/Scribus/scribus/ui/propertiespalette_text.cpp	Sun Apr 26 17:48:02 2020
@@ -475,9 +475,9 @@
 	bool blocked = lineSpacing->blockSignals(true);
 	if (mode > 0)
 	{
-		if (mode==1)
+		if (mode == 1)
 			lineSpacing->setSpecialValueText( tr( "Auto" ) );
-		if (mode==2)
+		if (mode == 2)
 			lineSpacing->setSpecialValueText( tr( "Baseline" ) );
 		lineSpacing->setMinimum(0);
 		lineSpacing->setValue(0);
@@ -527,7 +527,31 @@
 	showFontSize(charStyle.fontSize());
 	showLanguage(charStyle.language());
 
+	if (m_item)
+	{
+		QString defaultParStyle = m_item->itemText.defaultStyle().parent();
+		if (defaultParStyle.isEmpty())
+			defaultParStyle = CommonStrings::DefaultParagraphStyle;
+		paraStyleCombo->setDefaultStyle(defaultParStyle);
+	}
 	showParStyle(newCurrent.parent());
+
+	if (m_item)
+	{
+		QString defaultCharStyle;
+		if (!newCurrent.parent().isEmpty())
+		{
+			const ParagraphStyle& paraStyle = m_doc->paragraphStyles().get(newCurrent.parent());
+			defaultCharStyle = paraStyle.charStyle().parent();
+			if (defaultCharStyle.isEmpty())
+				defaultCharStyle = CommonStrings::DefaultCharacterStyle;
+		}
+		if (defaultCharStyle.isEmpty())
+			defaultCharStyle = m_item->itemText.defaultStyle().charStyle().parent();
+		if (defaultCharStyle.isEmpty())
+			defaultCharStyle = CommonStrings::DefaultCharacterStyle;
+		charStyleCombo->setDefaultStyle(defaultCharStyle);
+	}
 	showCharStyle(charStyle.parent());
 
 	bool tmp = m_haveItem;

Modified: trunk/Scribus/scribus/ui/stylecombos.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23658&path=/trunk/Scribus/scribus/ui/stylecombos.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/stylecombos.cpp	(original)
+++ trunk/Scribus/scribus/ui/stylecombos.cpp	Sun Apr 26 17:48:02 2020
@@ -21,6 +21,7 @@
  *                                                                         *
  ***************************************************************************/
 
+#include "commonstrings.h"
 #include "scribusdoc.h"
 #include "stylecombos.h"
 
@@ -32,7 +33,9 @@
 ParaStyleComboBox::ParaStyleComboBox(QWidget* parent) : QComboBox(parent)
 {
 	setEditable(false);
-	addItem( tr("[Inherited Style]") );
+	m_defaultStyle = CommonStrings::DefaultParagraphStyle;
+
+	addItem( firstItemString() );
 	addItem( CommonStrings::trDefaultParagraphStyle );
 	connect(this, SIGNAL(activated(int)), this, SLOT(selectedStyle(int)));
 }
@@ -48,6 +51,16 @@
 	return currStyleName;
 }
 
+QString ParaStyleComboBox::firstItemString()
+{
+	QString itemString;
+	if (m_defaultStyle.isEmpty() || m_defaultStyle == CommonStrings::DefaultParagraphStyle)
+		itemString = "[" + CommonStrings::trDefaultParagraphStyle + "]";
+	else
+		itemString = "[" + m_defaultStyle + "]";
+	return itemString;
+}
+
 void ParaStyleComboBox::changeEvent(QEvent *e)
 {
 	if (e->type() == QEvent::LanguageChange)
@@ -74,6 +87,17 @@
 {
 	m_doc = newCurrentDoc;
 	updateStyleList();
+}
+
+void ParaStyleComboBox::setDefaultStyle(const QString& defStyle)
+{
+	QString defStyleName = defStyle;
+	if (defStyle == CommonStrings::trDefaultParagraphStyle)
+		defStyleName = CommonStrings::DefaultParagraphStyle;
+	m_defaultStyle = defStyleName;
+
+	if (this->count() > 0)
+		setItemText(0, firstItemString());
 }
 
 void ParaStyleComboBox::setStyle(const QString& name)
@@ -81,7 +105,7 @@
 	QString parStyleName = name;
 	if (parStyleName == CommonStrings::DefaultParagraphStyle)
 		parStyleName = CommonStrings::trDefaultParagraphStyle;
-	setCurrentComboItem(this, parStyleName.isEmpty() ? tr("[Inherited Style]") : parStyleName);
+	setCurrentComboItem(this, parStyleName.isEmpty() ? firstItemString()  : parStyleName);
 }
 
 void ParaStyleComboBox::updateStyleList()
@@ -95,7 +119,7 @@
 	if (m_doc != nullptr)
 	{
 		QStringList st;
-		addItem( tr("[Inherited Style]") );
+		addItem( firstItemString()  );
 		addItem( CommonStrings::trDefaultParagraphStyle );
 		for (int i = 0; i < m_doc->paragraphStyles().count(); ++i)
 		{
@@ -140,7 +164,9 @@
 CharStyleComboBox::CharStyleComboBox(QWidget* parent) : QComboBox(parent)
 {
 	setEditable(false);
-	addItem( tr("[Inherited Style]") );
+	m_defaultStyle = CommonStrings::DefaultCharacterStyle;
+
+	addItem( firstItemString()  );
 	addItem( CommonStrings::trDefaultCharacterStyle );
 	connect(this, SIGNAL(activated(int)), this, SLOT(selectedStyle(int)));
 }
@@ -156,6 +182,16 @@
 	return currStyleName;
 }
 
+QString CharStyleComboBox::firstItemString()
+{
+	QString itemString;
+	if (m_defaultStyle.isEmpty() || m_defaultStyle == CommonStrings::DefaultCharacterStyle)
+		itemString = "[" + CommonStrings::trDefaultCharacterStyle + "]";
+	else
+		itemString = "[" + m_defaultStyle + "]";
+	return itemString;
+}
+
 void CharStyleComboBox::changeEvent(QEvent *e)
 {
 	if (e->type() == QEvent::LanguageChange)
@@ -182,6 +218,17 @@
 {
 	m_doc = newCurrentDoc;
 	updateStyleList();
+}
+
+void CharStyleComboBox::setDefaultStyle(const QString& defStyle)
+{
+	QString defStyleName = defStyle;
+	if (defStyle == CommonStrings::trDefaultCharacterStyle)
+		defStyleName = CommonStrings::DefaultCharacterStyle;
+	m_defaultStyle = defStyleName;
+
+	if (this->count() > 0)
+		setItemText(0, firstItemString());
 }
 
 void CharStyleComboBox::setStyle(const QString& name)
@@ -189,7 +236,7 @@
 	QString charStyleName = name;
 	if (charStyleName == CommonStrings::DefaultCharacterStyle)
 		charStyleName = CommonStrings::trDefaultCharacterStyle;
-	setCurrentComboItem(this, charStyleName.isEmpty() ? tr("[Inherited Style]") : charStyleName);
+	setCurrentComboItem(this, charStyleName.isEmpty() ? firstItemString()  : charStyleName);
 }
 
 void CharStyleComboBox::updateStyleList()
@@ -203,7 +250,7 @@
 	if (m_doc != nullptr)
 	{
 		QStringList st;
-		addItem( tr("[Inherited Style]") );
+		addItem( firstItemString()  );
 		addItem( CommonStrings::trDefaultCharacterStyle );
 		for (int i = 0; i < m_doc->charStyles().count(); ++i)
 		{
@@ -248,7 +295,9 @@
 CellStyleComboBox::CellStyleComboBox(QWidget* parent) : QComboBox(parent)
 {
 	setEditable(false);
-	addItem( tr("[Inherited Style]") );
+	m_defaultStyle = CommonStrings::DefaultCellStyle;
+
+	addItem( firstItemString()  );
 	addItem( CommonStrings::trDefaultCellStyle );
 	connect(this, SIGNAL(activated(int)), this, SLOT(selectedStyle(int)));
 }
@@ -264,6 +313,16 @@
 	return currStyleName;
 }
 
+QString CellStyleComboBox::firstItemString()
+{
+	QString itemString;
+	if (m_defaultStyle.isEmpty() || m_defaultStyle == CommonStrings::DefaultCellStyle)
+		itemString = "[" + CommonStrings::trDefaultCellStyle + "]";
+	else
+		itemString = "[" + m_defaultStyle + "]";
+	return itemString;
+}
+
 void CellStyleComboBox::changeEvent(QEvent *e)
 {
 	if (e->type() == QEvent::LanguageChange)
@@ -290,6 +349,17 @@
 {
 	m_doc = newCurrentDoc;
 	updateStyleList();
+}
+
+void CellStyleComboBox::setDefaultStyle(const QString& defStyle)
+{
+	QString defStyleName = defStyle;
+	if (defStyle == CommonStrings::trDefaultCellStyle)
+		defStyleName = CommonStrings::DefaultCellStyle;
+	m_defaultStyle = defStyleName;
+
+	if (this->count() > 0)
+		setItemText(0, firstItemString());
 }
 
 void CellStyleComboBox::setStyle(const QString& name)
@@ -297,7 +367,7 @@
 	QString cellStyleName = name;
 	if (cellStyleName == CommonStrings::DefaultCellStyle)
 		cellStyleName = CommonStrings::trDefaultCellStyle;
-	setCurrentComboItem(this, cellStyleName.isEmpty() ? tr("[Inherited Style]") : cellStyleName);
+	setCurrentComboItem(this, cellStyleName.isEmpty() ? firstItemString()  : cellStyleName);
 }
 
 void CellStyleComboBox::updateStyleList()
@@ -311,7 +381,7 @@
 	if (m_doc != nullptr)
 	{
 		QStringList st;
-		addItem( tr("[Inherited Style]") );
+		addItem( firstItemString()  );
 		addItem( CommonStrings::trDefaultCellStyle  );
 		for (int i = 0; i < m_doc->cellStyles().count(); ++i)
 		{
@@ -353,7 +423,9 @@
 TableStyleComboBox::TableStyleComboBox(QWidget* parent) : QComboBox(parent)
 {
 	setEditable(false);
-	addItem( tr("[Inherited Style]") );
+	m_defaultStyle = CommonStrings::DefaultTableStyle;
+
+	addItem( firstItemString()  );
 	addItem( CommonStrings::trDefaultTableStyle );
 	connect(this, SIGNAL(activated(int)), this, SLOT(selectedStyle(int)));
 }
@@ -369,6 +441,16 @@
 	return currStyleName;
 }
 
+QString TableStyleComboBox::firstItemString()
+{
+	QString itemString;
+	if (m_defaultStyle.isEmpty() || m_defaultStyle == CommonStrings::DefaultTableStyle)
+		itemString = "[" + CommonStrings::trDefaultTableStyle + "]";
+	else
+		itemString = "[" + m_defaultStyle + "]";
+	return itemString;
+}
+
 void TableStyleComboBox::changeEvent(QEvent *e)
 {
 	if (e->type() == QEvent::LanguageChange)
@@ -395,6 +477,17 @@
 {
 	m_doc = newCurrentDoc;
 	updateStyleList();
+}
+
+void TableStyleComboBox::setDefaultStyle(const QString& defStyle)
+{
+	QString defStyleName = defStyle;
+	if (defStyle == CommonStrings::trDefaultTableStyle)
+		defStyleName = CommonStrings::DefaultTableStyle;
+	m_defaultStyle = defStyleName;
+
+	if (this->count() > 0)
+		setItemText(0, firstItemString());
 }
 
 void TableStyleComboBox::setStyle(const QString& name)
@@ -402,7 +495,7 @@
 	QString tableStyleName = name;
 	if (tableStyleName == CommonStrings::DefaultTableStyle)
 		tableStyleName = CommonStrings::trDefaultTableStyle;
-	setCurrentComboItem(this, tableStyleName.isEmpty() ? tr("[Inherited Style]") : tableStyleName);
+	setCurrentComboItem(this, tableStyleName.isEmpty() ? firstItemString()  : tableStyleName);
 }
 
 void TableStyleComboBox::updateStyleList()
@@ -416,7 +509,7 @@
 	if (m_doc != nullptr)
 	{
 		QStringList st;
-		addItem( tr("[Inherited Style]") );
+		addItem( firstItemString()  );
 		addItem( CommonStrings::trDefaultTableStyle );
 		for (int i = 0; i < m_doc->tableStyles().count(); ++i)
 		{

Modified: trunk/Scribus/scribus/ui/stylecombos.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23658&path=/trunk/Scribus/scribus/ui/stylecombos.h
==============================================================================
--- trunk/Scribus/scribus/ui/stylecombos.h	(original)
+++ trunk/Scribus/scribus/ui/stylecombos.h	Sun Apr 26 17:48:02 2020
@@ -44,6 +44,9 @@
 	~ParaStyleComboBox() {};
 
 	QString currentStyle() const;
+
+	const QString& defaultStyle() const { return m_defaultStyle; }
+	void setDefaultStyle(const QString& defStyle);
 	
 public slots:
 	void setDoc(ScribusDoc *newCurrentDoc);
@@ -52,6 +55,9 @@
 
 protected:
 	ScribusDoc *m_doc { nullptr };
+	QString m_defaultStyle;
+
+	QString firstItemString();
 
 	void changeEvent(QEvent *e) override;
 	void languageChange();
@@ -72,6 +78,9 @@
 	~CharStyleComboBox() {};
 
 	QString currentStyle() const;
+
+	const QString& defaultStyle() const { return m_defaultStyle; }
+	void setDefaultStyle(const QString& defStyle);
 	
 public slots:
 	void setDoc(ScribusDoc *newCurrentDoc);
@@ -80,6 +89,9 @@
 
 protected:
 	ScribusDoc *m_doc { nullptr };
+	QString m_defaultStyle;
+
+	QString firstItemString();
 
 	void changeEvent(QEvent *e) override;
 	void languageChange();
@@ -101,6 +113,9 @@
 
 	QString currentStyle() const;
 
+	const QString& defaultStyle() const { return m_defaultStyle; }
+	void setDefaultStyle(const QString& defStyle);
+
 public slots:
 	void setDoc(ScribusDoc *newCurrentDoc);
 	void setStyle(const QString& name);
@@ -108,6 +123,9 @@
 
 protected:
 	ScribusDoc *m_doc { nullptr };
+	QString m_defaultStyle;
+
+	QString firstItemString();
 
 	void changeEvent(QEvent *e) override;
 	void languageChange();
@@ -129,6 +147,9 @@
 
 	QString currentStyle() const;
 
+	const QString& defaultStyle() const { return m_defaultStyle; }
+	void setDefaultStyle(const QString& defStyle);
+
 public slots:
 	void setDoc(ScribusDoc *newCurrentDoc);
 	void setStyle(const QString& name);
@@ -136,6 +157,9 @@
 
 protected:
 	ScribusDoc *m_doc { nullptr };
+	QString m_defaultStyle;
+
+	QString firstItemString();
 
 	void changeEvent(QEvent *e) override;
 	void languageChange();




More information about the scribus-commit mailing list