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 #include <QToolTip>
8 #include "smalignselect.h"
9 
10 
SMAlignSelect(QWidget * parent)11 SMAlignSelect::SMAlignSelect(QWidget *parent)
12 	: AlignSelect(parent)
13 {
14 	parentButton = new QToolButton(this);
15 	parentButton->setCheckable( true );
16 	parentButton->setText( tr("P", "P as in Parent"));
17 	parentButton->setToolTip( tr("Use parent style's alignment instead of overriding it"));
18 	GroupAlignLayout->addWidget( parentButton );
19 	resize(minimumSizeHint());
20 	parentButton->hide();
21 }
22 
setStyle(int a,int d)23 void SMAlignSelect::setStyle(int a, int d)
24 {
25 	disconnect(this, SIGNAL(State(int)), this, SLOT(styleChanged()));
26 	disconnect(parentButton, SIGNAL(pressed()), this, SLOT(pbPressed()));
27 	setFont(false);
28 	m_hasParent = false;
29 	m_pStyle = 0;
30 	m_pDirection = 0;
31 	parentButton->hide();
32 	AlignSelect::setStyle(a, d);
33 }
34 
setStyle(int a,int d,bool isParentValue)35 void SMAlignSelect::setStyle(int a, int d, bool isParentValue)
36 {
37 	disconnect(this, SIGNAL(State(int)), this, SLOT(styleChanged()));
38 	disconnect(parentButton, SIGNAL(pressed()), this, SLOT(pbPressed()));
39 	m_hasParent = true;
40 	m_pStyle = a;
41 	m_pDirection = d;
42 	setFont(!isParentValue);
43 	if (isParentValue)
44 		parentButton->hide();
45 	else
46 		parentButton->show();
47 
48 	AlignSelect::setStyle(a, d);
49 	connect(this, SIGNAL(State(int)), this, SLOT(styleChanged()));
50 	connect(parentButton, SIGNAL(pressed()), this, SLOT(pbPressed()));
51 }
52 
setParentItem(int a,int d)53 void SMAlignSelect::setParentItem(int a, int d)
54 {
55 	m_hasParent = true;
56 	m_pStyle = a;
57 	m_pDirection = d;
58 }
59 
useParentValue()60 bool SMAlignSelect::useParentValue()
61 {
62 	bool ret = m_useParentStyle;
63 	m_useParentStyle = false;
64 	if (ret)
65 		setStyle(m_pStyle, m_pDirection, true);
66 
67 	return ret;
68 }
69 
setFont(bool wantBold)70 void SMAlignSelect::setFont(bool wantBold)
71 {
72 	QFont f(font());
73 	f.setBold(wantBold);
74 	parentButton->setFont(f);
75 }
76 
styleChanged()77 void SMAlignSelect::styleChanged()
78 {
79 	if (m_hasParent)
80 	{
81 		setFont(true);
82 		parentButton->show();
83 	}
84 }
85 
pbPressed()86 void SMAlignSelect::pbPressed()
87 {
88 	m_useParentStyle = true;
89 }
90