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 "alignselect.h"
9 
10 #include <QEvent>
11 #include <QPixmap>
12 #include <QToolTip>
13 
14 #include "iconmanager.h"
15 #include "scribusapp.h"
16 
AlignSelect(QWidget * parent)17 AlignSelect::AlignSelect(QWidget* parent) : QWidget(parent)
18 {
19 	selected = 0;
20 
21 	IconManager& im = IconManager::instance();
22 	buttonGroup = new QButtonGroup(this);
23 
24 	GroupAlignLayout = new QHBoxLayout( this );
25 	GroupAlignLayout->setSpacing(3);
26 	GroupAlignLayout->setContentsMargins(0, 0, 0, 0);
27 
28 	TextL = new QToolButton( this );
29 	TextL->setIcon(im.loadIcon("16/format-justify-left.png"));
30 	TextL->setCheckable( true );
31 	TextL->setChecked( true );
32 	GroupAlignLayout->addWidget( TextL );
33 	buttonGroup->addButton(TextL, 0);
34 
35 	TextC = new QToolButton( this );
36 	TextC->setIcon(im.loadIcon("16/format-justify-center.png"));
37 	TextC->setCheckable( true );
38 	GroupAlignLayout->addWidget( TextC );
39 	buttonGroup->addButton(TextC, 1);
40 
41 	TextR = new QToolButton( this );
42 	TextR->setIcon(im.loadIcon("16/format-justify-right.png"));
43 	TextR->setCheckable( true );
44 	GroupAlignLayout->addWidget( TextR );
45 	buttonGroup->addButton(TextR, 2);
46 
47 	TextB = new QToolButton( this );
48 	TextB->setIcon(im.loadIcon("16/format-justify-fill-block.png"));
49 	TextB->setCheckable( true );
50 	GroupAlignLayout->addWidget( TextB );
51 	buttonGroup->addButton(TextB, 3);
52 
53 	TextF = new QToolButton( this );
54 	TextF->setIcon(im.loadIcon("16/format-justify-fill.png"));
55 	TextF->setCheckable( true );
56 	GroupAlignLayout->addWidget( TextF );
57 	buttonGroup->addButton(TextF, 4);
58 	resize(minimumSizeHint());
59 
60 	connect(ScQApp, SIGNAL(iconSetChanged()), this, SLOT(iconSetChange()));
61 	connect(buttonGroup, SIGNAL(buttonClicked(int)), this, SLOT(setTypeStyle(int)));
62 }
63 
setStyle(int s,int d)64 void AlignSelect::setStyle(int s, int d)
65 {
66 	if ((s >= 0) && (s < 5))
67 		buttonGroup->button(s)->setChecked(true);
68 
69 	if (d == ParagraphStyle::RTL)
70 		TextB->setIcon(IconManager::instance().loadIcon("16/format-justify-fill-block-right.png"));
71 	else
72 		TextB->setIcon(IconManager::instance().loadIcon("16/format-justify-fill-block.png"));
73 }
74 
getStyle()75 int AlignSelect::getStyle()
76 {
77 	int ret = 0;
78 	if (TextL->isChecked())
79 		ret = 0;
80 	if (TextR->isChecked())
81 		ret = 2;
82 	if (TextC->isChecked())
83 		ret = 1;
84 	if (TextB->isChecked())
85 		ret = 3;
86 	if (TextF->isChecked())
87 		ret = 4;
88 	return ret;
89 }
90 
setTypeStyle(int a)91 void AlignSelect::setTypeStyle(int a)
92 {
93 	selected = a;
94 	emit State(a);
95 }
96 
selectedId()97 int AlignSelect::selectedId()
98 {
99 	return selected;
100 }
101 
changeEvent(QEvent * e)102 void AlignSelect::changeEvent(QEvent *e)
103 {
104 	if (e->type() == QEvent::LanguageChange)
105 		languageChange();
106 	else
107 		QWidget::changeEvent(e);
108 }
109 
iconSetChange()110 void AlignSelect::iconSetChange()
111 {
112 	IconManager& im = IconManager::instance();
113 
114 	TextL->setIcon(im.loadIcon("16/format-justify-left.png"));
115 	TextC->setIcon(im.loadIcon("16/format-justify-center.png"));
116 	TextR->setIcon(im.loadIcon("16/format-justify-right.png"));
117 	TextB->setIcon(im.loadIcon("16/format-justify-fill-block.png"));
118 	TextF->setIcon(im.loadIcon("16/format-justify-fill.png"));
119 }
120 
languageChange()121 void AlignSelect::languageChange()
122 {
123 	TextL->setToolTip( tr("Align Text Left"));
124 	TextR->setToolTip( tr("Align Text Right"));
125 	TextC->setToolTip( tr("Align Text Center"));
126 	TextB->setToolTip( tr("Align Text Justified"));
127 	TextF->setToolTip( tr("Align Text Forced Justified"));
128 }
129