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 "buttonicon.h"
8 
9 #include <QPixmap>
10 #include <QGridLayout>
11 #include <QHBoxLayout>
12 #include <QVBoxLayout>
13 #include <QSpacerItem>
14 #include <QComboBox>
15 #include <QGroupBox>
16 #include <QSlider>
17 #include <QPushButton>
18 #include <QLabel>
19 
20 #include "scfonts.h"
21 #include "scribusstructs.h"
22 #include "pageitem.h"
23 #include "iconmanager.h"
24 
ButtonIcon(QWidget * parent,PageItem * ite)25 ButtonIcon::ButtonIcon(QWidget* parent, PageItem* ite) : QDialog( parent )
26 {
27 	Item = ite;
28 	setModal(true);
29 	setWindowTitle( tr( "Icon Placement" ) );
30 	setWindowIcon(IconManager::instance().loadPixmap("AppIcon.png"));
31 	ButtonIconLayout = new QVBoxLayout( this );
32 	ButtonIconLayout->setContentsMargins(9, 9, 9, 9);
33 	ButtonIconLayout->setSpacing(6);
34 	Layout1 = new QGridLayout;
35 	Layout1->setContentsMargins(0, 0, 0, 0);
36 	Layout1->setSpacing(6);
37 	TextLabel1_2 = new QLabel( this );
38 	TextLabel1_2->setText( tr( "Layout:" ) );
39 	Layout1->addWidget( TextLabel1_2, 0, 0 );
40 	Place = new QComboBox(this);
41 	QString tmp_pla[] = { tr("Caption only"), tr("Icon only"), tr("Caption below Icon"), tr("Caption above Icon"),
42 	                      tr("Caption right to Icon"), tr("Caption left to Icon"), tr("Caption overlays Icon")};
43 	size_t array_pla = sizeof(tmp_pla) / sizeof(*tmp_pla);
44 	/* PFJ - 29/02/04 - Changed from uint to int and var name */
45 	for (uint prop = 0; prop < array_pla; ++prop)
46 		Place->addItem(tmp_pla[prop]);
47 	Place->setEditable(false);
48 	Layout1->addWidget( Place, 0, 1 );
49 	TextLabel1 = new QLabel( this );
50 	TextLabel1->setText( tr( "Scale:" ) );
51 	Layout1->addWidget( TextLabel1, 1, 0 );
52 	ScaleW = new QComboBox(this);
53 	/* PFJ - 29/02/04 - Changed to QString/size_t/for style. It saves a small
54 						of time during the setup */
55 	QString scalew[] = { tr("Always"), tr("When Icon is too small"),
56 	                    tr("When Icon is too big"), tr("Never")};
57 	size_t scalewArray = sizeof(scalew) / sizeof(*scalew);
58 	for (uint prop = 0; prop < scalewArray; ++prop)
59 		ScaleW->addItem(scalew[prop]);
60 	ScaleW->setEditable(false);
61 	Layout1->addWidget( ScaleW, 1, 1 );
62 	TextLabel2 = new QLabel( this );
63 	TextLabel2->setText( tr( "Scale How:" ) );
64 	Layout1->addWidget( TextLabel2, 2, 0 );
65 	ScaleH = new QComboBox(this);
66 	ScaleH->addItem( tr( "Proportional" ) );
67 	ScaleH->addItem( tr( "Non Proportional" ) );
68 	ScaleH->setEditable(false);
69 	Layout1->addWidget( ScaleH, 2, 1 );
70 	ButtonIconLayout->addLayout( Layout1 );
71 	QSpacerItem* spacer = new QSpacerItem( 0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding );
72 	ButtonIconLayout->addItem( spacer );
73 	Layout5 = new QHBoxLayout;
74 	Layout5->setContentsMargins(0, 0, 0, 0);
75 	Layout5->setSpacing(6);
76 	QSpacerItem* spacer_2 = new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum );
77 	Layout5->addItem( spacer_2 );
78 	Layout3 = new QGridLayout;
79 	Layout3->setContentsMargins(0, 0, 0, 0);
80 	Layout3->setSpacing(6);
81 	GroupButton = new QGroupBox( this );
82 	GroupButton->setMinimumSize( QSize( 150, 150 ) );
83 	GroupButton->setMaximumSize( QSize( 150, 150 ) );
84 	GroupButton->setTitle( "" );
85 	TextLabel3 = new QLabel( GroupButton );
86 	TextLabel3->setGeometry( QRect( 50, 50, 48, 48 ) );
87 	TextLabel3->setFrameShape( QLabel::Box );
88 	TextLabel3->setFrameShadow( QLabel::Raised );
89 	TextLabel3->setLineWidth( 1 );
90 	TextLabel3->setText( tr( "Icon" ) );
91 	Layout3->addWidget( GroupButton, 0, 0 );
92 	SliderX = new QSlider( this );
93 	SliderX->setMaximum( 1000 );
94 	SliderX->setValue( 500 );
95 	SliderX->setOrientation( Qt::Horizontal );
96 	SliderX->setTickPosition(QSlider::TicksLeft);
97 	SliderX->setTickInterval( 100 );
98 	Layout3->addWidget( SliderX, 1, 0 );
99 	SliderY = new QSlider( this );
100 	SliderY->setMaximum( 1000 );
101 	SliderY->setValue( 500 );
102 	SliderY->setOrientation( Qt::Vertical );
103 	SliderY->setTickPosition(QSlider::TicksLeft);
104 	SliderY->setTickInterval( 100 );
105 	SliderY->setInvertedAppearance(true);
106 	Layout3->addWidget( SliderY, 0, 1 );
107 	Layout5->addLayout( Layout3 );
108 	QSpacerItem* spacer_3 = new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum );
109 	Layout5->addItem( spacer_3 );
110 	ButtonIconLayout->addLayout( Layout5 );
111 	QSpacerItem* spacer_4 = new QSpacerItem( 0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding );
112 	ButtonIconLayout->addItem( spacer_4 );
113 	Layout4 = new QHBoxLayout;
114 	Layout4->setContentsMargins(0, 0, 0, 0);
115 	Layout4->setSpacing(6);
116 	OK = new QPushButton( this );
117 	OK->setText( tr( "OK" ) );
118 	OK->setDefault( true );
119 	Layout4->addWidget( OK );
120 	Cancel = new QPushButton( this );
121 	Cancel->setText( tr( "Cancel" ) );
122 	Layout4->addWidget( Cancel );
123 	Reset = new QPushButton( this );
124 	Reset->setText( tr( "Reset" ) );
125 	Layout4->addWidget( Reset );
126 	ButtonIconLayout->addLayout( Layout4 );
127 
128 	SetAllVals();
129 
130 	connect(ScaleW, SIGNAL(activated(int)), this, SLOT(SetScaleHow(int)));
131 	connect(SliderX, SIGNAL(valueChanged(int)), this, SLOT(MoveIconX(int)));
132 	connect(SliderY, SIGNAL(valueChanged(int)), this, SLOT(MoveIconY(int)));
133 	connect(Cancel, SIGNAL(clicked()), this, SLOT(reject()));
134 	connect(OK, SIGNAL(clicked()), this, SLOT(accept()));
135 	connect(Reset, SIGNAL(clicked()), this, SLOT(SetAllVals()));
136 }
137 
MoveIconY(int y)138 void ButtonIcon::MoveIconY(int y)
139 {
140 	TextLabel3->setGeometry(QRect(static_cast<int>(SliderX->value() / 1000.0 * 100),
141 	                              static_cast<int>(y / 1000.0 * 100), 48, 48));
142 	IcPlaceY = y / 1000.0;
143 }
144 
MoveIconX(int x)145 void ButtonIcon::MoveIconX(int x)
146 {
147 	TextLabel3->setGeometry(QRect(static_cast<int>(x / 1000.0 * 100),
148 	                              static_cast<int>(SliderY->value() / 1000.0 * 100), 48, 48));
149 	IcPlaceX = x / 1000.0;
150 }
151 
SetAllVals()152 void ButtonIcon::SetAllVals()
153 {
154 	Place->setCurrentIndex(Item->annotation().IPlace());
155 	ScaleW->setCurrentIndex(Item->annotation().ScaleW());
156 	ScaleH->setCurrentIndex(Item->imageXScale() != Item->imageYScale() ? 1 : 0);
157 	SetScaleHow(ScaleW->currentIndex());
158 	SliderX->setValue(static_cast<int>(Item->imageXOffset() / (Item->width() - Item->pixm.width()) * 1000));
159 	SliderY->setValue(static_cast<int>(Item->imageYOffset() / (Item->height() - Item->pixm.height()) * 1000));
160 	TextLabel3->setGeometry(QRect(static_cast<int>(SliderX->value() / 1000.0 * 100),
161 	                              static_cast<int>(SliderY->value() / 1000.0 * 100), 48, 48));
162 }
163 
SetScaleHow(int s)164 void ButtonIcon::SetScaleHow(int s)
165 {
166 	bool setter = s == 3;
167 	GroupButton->setEnabled(setter);
168 	TextLabel3->setEnabled(setter);
169 	SliderX->setEnabled(setter);
170 	SliderY->setEnabled(setter);
171 	IcScaleH = s;
172 }
173