1 /*
2 For general Scribus (>=1.3.2) copyright and licensing information please refer
3 to the COPYING file provided with the program. Following this notice may exist
4 a copyright and/or license notice that predates the release of Scribus 1.3.2
5 for which a new license (GPL+exception) is in place.
6 */
7 
8 #include "smshadebutton.h"
9 
10 
SMShadeButton(QWidget * parent)11 SMShadeButton::SMShadeButton(QWidget *parent)
12 	: ShadeButton(parent)
13 {
14 
15 }
16 
setValue(int i)17 void SMShadeButton::setValue(int i)
18 {
19 	disconnect(this, SIGNAL(pressed()), this, SLOT(currentChanged()));
20 	setFont(false);
21 	m_hasParent = false;
22 	m_pValue = 0;
23 	ShadeButton::setValue(i);
24 }
25 
setValue(int i,bool isParentValue)26 void SMShadeButton::setValue(int i, bool isParentValue)
27 {
28 	disconnect(this, SIGNAL(pressed()), this, SLOT(currentChanged()));
29 	m_hasParent = true;
30 	m_pValue = i;
31 	setFont(!isParentValue);
32 	ShadeButton::setValue(i);
33 	connect(this, SIGNAL(pressed()), this, SLOT(currentChanged()));
34 }
35 
setParentValue(int i)36 void SMShadeButton::setParentValue(int i)
37 {
38 	m_hasParent = true;
39 	m_pValue = i;
40 }
41 
useParentValue()42 bool SMShadeButton::useParentValue()
43 {
44 	bool ret = m_useParentValue;
45 	m_useParentValue = false;
46 
47 	if (ret)
48 	{
49 		setValue(m_pValue, true);
50 		QList<QAction*> actList = FillSh->actions();
51 		if (actList.last()->text() == useParentValueText())
52 			FillSh->removeAction(actList.last());
53 	}
54 
55 	return ret;
56 }
57 
useParentValueText()58 QString SMShadeButton::useParentValueText()
59 {
60 	QString trText = tr("Use Parent Value");
61 	return trText;
62 }
63 
setFont(bool wantBold)64 void SMShadeButton::setFont(bool wantBold)
65 {
66 	QFont f(font());
67 	f.setBold(wantBold);
68 	FillSh->setFont(f);
69 	ShadeButton::setFont(f);
70 }
71 
currentChanged()72 void SMShadeButton::currentChanged()
73 {
74 	if (m_hasParent)
75 	{
76 		setFont(true);
77 		QString upv = useParentValueText();
78 		QList<QAction*> actList = FillSh->actions();
79 		if (actList.last()->text() != upv)
80 			FillSh->addAction(upv, this, SLOT(slotUseParent()));
81 	}
82 }
83 
slotUseParent()84 void SMShadeButton::slotUseParent()
85 {
86 	m_useParentValue = true;
87 	QList<QAction*> actList = FillSh->actions();
88 	if (actList.last()->text() == useParentValueText())
89 		FillSh->removeAction(actList.last());
90 	emit clicked();
91 }
92