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 <QEvent>
9
10 #include "iconmanager.h"
11 #include "scribusapp.h"
12 #include "styleselect.h"
13
StrikeValues(QWidget * parent)14 StrikeValues::StrikeValues( QWidget* parent ) : QFrame( parent )
15 {
16 group1Layout = new QGridLayout( this );
17 group1Layout->setSpacing(3);
18 group1Layout->setContentsMargins(3, 3, 3, 3);
19 group1Layout->setAlignment( Qt::AlignTop );
20 LPos = new ScrSpinBox( -0.1, 100, this, 0 );
21 LPos->setValue( -0.1 );
22 LPos->setWrapping(true);
23 LPosTxt = new QLabel( "Displacement:", this );
24 group1Layout->addWidget( LPos, 0, 1 );
25 group1Layout->addWidget( LPosTxt, 0 , 0 );
26 LWidth = new ScrSpinBox( -0.1, 100, this, 0 );
27 LWidth->setValue( -0.1 );
28 LWidth->setWrapping(true);
29 LWidthTxt = new QLabel( "Linewidth:", this );
30 group1Layout->addWidget( LWidth, 1, 1 );
31 group1Layout->addWidget( LWidthTxt, 1 , 0 );
32 languageChange();
33 }
34
languageChange()35 void StrikeValues::languageChange()
36 {
37 LPos->setSuffix( tr(" %"));
38 LPos->setSpecialValueText( tr( "Auto" ) );
39 LPosTxt->setText( tr("Displacement:"));
40 LWidth->setSuffix( tr(" %"));
41 LWidth->setSpecialValueText( tr( "Auto" ) );
42 LWidthTxt->setText( tr("Linewidth:"));
43 LPosTxt->adjustSize();
44 LWidthTxt->adjustSize();
45 }
46
UnderlineValues(QWidget * parent)47 UnderlineValues::UnderlineValues( QWidget* parent ) : QFrame( parent )
48 {
49 group1Layout = new QGridLayout(this);
50 group1Layout->setSpacing(3);
51 group1Layout->setContentsMargins(3, 3, 3, 3);
52 group1Layout->setAlignment( Qt::AlignTop );
53 LPos = new ScrSpinBox( -0.1, 100, this, 0 );
54 LPos->setValue( -0.1 );
55 LPos->setWrapping(true);
56 LPosTxt = new QLabel( "Displacement:", this );
57 group1Layout->addWidget( LPos, 0, 1 );
58 group1Layout->addWidget( LPosTxt, 0 , 0 );
59 LWidth = new ScrSpinBox( -0.1, 100, this, 0 );
60 LWidth->setValue( -0.1 );
61 LWidth->setWrapping(true);
62 LWidthTxt = new QLabel( "Linewidth:", this );
63 group1Layout->addWidget( LWidth, 1, 1 );
64 group1Layout->addWidget( LWidthTxt, 1 , 0 );
65 languageChange();
66 }
67
languageChange()68 void UnderlineValues::languageChange()
69 {
70 LPos->setSpecialValueText( tr("Auto") );
71 LPos->setSuffix( tr(" %"));
72 LPosTxt->setText( tr("Displacement:"));
73 LWidth->setSpecialValueText( tr("Auto") );
74 LWidth->setSuffix( tr(" %"));
75 LWidthTxt->setText( tr("Linewidth:"));
76 LPosTxt->adjustSize();
77 LWidthTxt->adjustSize();
78 }
79
OutlineValues(QWidget * parent)80 OutlineValues::OutlineValues( QWidget* parent ) : QFrame( parent )
81 {
82 group1Layout = new QGridLayout( this );
83 group1Layout->setSpacing(3);
84 group1Layout->setContentsMargins(3, 3, 3, 3);
85 group1Layout->setAlignment( Qt::AlignTop );
86 LWidth = new ScrSpinBox( 0, 100, this, 0 );
87 LWidth->setValue( 1 );
88 LWidthTxt = new QLabel( "Linewidth:", this );
89 group1Layout->addWidget( LWidth, 0, 1 );
90 group1Layout->addWidget( LWidthTxt, 0 , 0 );
91 languageChange();
92 }
93
languageChange()94 void OutlineValues::languageChange()
95 {
96 LWidth->setSuffix( tr(" %"));
97 LWidthTxt->setText( tr("Linewidth:"));
98 LWidthTxt->adjustSize();
99 }
100
ShadowValues(QWidget * parent)101 ShadowValues::ShadowValues( QWidget* parent ) : QFrame( parent )
102 {
103 group1Layout = new QGridLayout( this );
104 group1Layout->setSpacing(3);
105 group1Layout->setContentsMargins(3, 3, 3, 3);
106 group1Layout->setAlignment( Qt::AlignTop );
107 Xoffset = new ScrSpinBox( -100, 100, this, 0 );
108 Xoffset->setValue( 5 );
109 XoffsetTxt = new QLabel( "X-Offset", this );
110 group1Layout->addWidget( Xoffset, 0, 1 );
111 group1Layout->addWidget( XoffsetTxt, 0 , 0 );
112 Yoffset = new ScrSpinBox( -100, 100, this, 0 );
113 Yoffset->setValue( 5 );
114 YoffsetTxt = new QLabel( "Y-Offset", this );
115 group1Layout->addWidget( Yoffset, 1, 1 );
116 group1Layout->addWidget( YoffsetTxt, 1 , 0 );
117 languageChange();
118 }
119
languageChange()120 void ShadowValues::languageChange()
121 {
122 Xoffset->setSuffix( tr(" %"));
123 XoffsetTxt->setText( tr("X-Offset:"));
124 Yoffset->setSuffix( tr(" %"));
125 YoffsetTxt->setText( tr("Y-Offset:"));
126 XoffsetTxt->adjustSize();
127 YoffsetTxt->adjustSize();
128 }
129
StyleSelect(QWidget * parent)130 StyleSelect::StyleSelect(QWidget* parent) : QWidget(parent)
131 {
132 IconManager& im = IconManager::instance();
133 ssLayout = new QHBoxLayout(this);
134 ssLayout->setSpacing(3);
135 ssLayout->setContentsMargins(0, 0, 0, 0);
136
137 UnderlineVal = new UnderlineValues( nullptr );
138 UnderlinePop = new QMenu();
139 UnderlineValAct = new QWidgetAction(this);
140 UnderlineValAct->setDefaultWidget(UnderlineVal);
141 UnderlinePop->addAction(UnderlineValAct);
142 underlineButton = new QToolButton( this );
143 underlineButton->setText( "" );
144 underlineButton->setIcon(im.loadIcon("unter.png"));
145 underlineButton->setCheckable( true );
146 underlineButton->setMenu(UnderlinePop);
147 underlineButton->setPopupMode(QToolButton::DelayedPopup);
148 ssLayout->addWidget( underlineButton );
149 underlineWordButton = new QToolButton( this );
150 underlineWordButton->setText( "" );
151 underlineWordButton->setIcon(im.loadIcon("wordsOnly.png"));
152 underlineWordButton->setCheckable( true );
153 underlineWordButton->setMenu(UnderlinePop);
154 underlineWordButton->setPopupMode(QToolButton::DelayedPopup);
155 ssLayout->addWidget( underlineWordButton );
156
157 subscriptButton = new QToolButton( this );
158 subscriptButton->setText( "" );
159 subscriptButton->setIcon(im.loadIcon("tief.png"));
160 subscriptButton->setCheckable( true );
161 ssLayout->addWidget( subscriptButton );
162 superscriptButton = new QToolButton( this );
163 superscriptButton->setText( "" );
164 superscriptButton->setIcon(im.loadIcon("hoch.png"));
165 superscriptButton->setCheckable( true );
166 ssLayout->addWidget( superscriptButton );
167
168 allcapsButton = new QToolButton( this );
169 allcapsButton->setMaximumSize( QSize( 22, 22 ) );
170 allcapsButton->setText("");
171 allcapsButton->setIcon(im.loadIcon("AllCaps.png"));
172 allcapsButton->setCheckable( true );
173 ssLayout->addWidget( allcapsButton );
174 smallcapsButton = new QToolButton( this );
175 smallcapsButton->setText("");
176 smallcapsButton->setIcon(im.loadIcon("kapital.png"));
177 smallcapsButton->setCheckable( true );
178 ssLayout->addWidget( smallcapsButton );
179
180 StrikeVal = new StrikeValues( nullptr );
181 StrikePop = new QMenu();
182 StrikeValAct = new QWidgetAction(this);
183 StrikeValAct->setDefaultWidget(StrikeVal);
184 StrikePop->addAction(StrikeValAct);
185 strikeoutButton = new QToolButton( this );
186 strikeoutButton->setText( "" );
187 strikeoutButton->setIcon(im.loadIcon("strike.png"));
188 strikeoutButton->setCheckable( true );
189 strikeoutButton->setMenu(StrikePop);
190 strikeoutButton->setPopupMode(QToolButton::DelayedPopup);
191 ssLayout->addWidget( strikeoutButton );
192
193 OutlineVal = new OutlineValues( nullptr );
194 OutlinePop = new QMenu();
195 OutlineValAct = new QWidgetAction(this);
196 OutlineValAct->setDefaultWidget(OutlineVal);
197 OutlinePop->addAction(OutlineValAct);
198 outlineButton = new QToolButton( this );
199 outlineButton->setText( "" );
200 outlineButton->setIcon(im.loadIcon("outlined.png"));
201 outlineButton->setCheckable( true );
202 outlineButton->setMenu(OutlinePop);
203 outlineButton->setPopupMode(QToolButton::DelayedPopup);
204 ssLayout->addWidget( outlineButton );
205
206 ShadowVal = new ShadowValues( nullptr );
207 ShadowPop = new QMenu();
208 ShadowValAct = new QWidgetAction(this);
209 ShadowValAct->setDefaultWidget(ShadowVal);
210 ShadowPop->addAction(ShadowValAct);
211 shadowButton = new QToolButton( this );
212 shadowButton->setText( "" );
213 shadowButton->setIcon(im.loadIcon("shadow.png"));
214 shadowButton->setCheckable( true );
215 shadowButton->setMenu(ShadowPop);
216 shadowButton->setPopupMode(QToolButton::DelayedPopup);
217 ssLayout->addWidget( shadowButton );
218
219 QSize s(24,24);
220 underlineButton->setMinimumSize(s);
221 underlineWordButton->setMinimumSize(s);
222 subscriptButton->setMinimumSize(s);
223 superscriptButton->setMinimumSize(s);
224 smallcapsButton->setMinimumSize(s);
225 allcapsButton->setMinimumSize(s);
226 strikeoutButton->setMinimumSize(s);
227 outlineButton->setMinimumSize(s);
228 shadowButton->setMinimumSize(s);
229 underlineButton->setMaximumSize(s);
230 underlineWordButton->setMaximumSize(s);
231 subscriptButton->setMaximumSize(s);
232 superscriptButton->setMaximumSize(s);
233 smallcapsButton->setMaximumSize(s);
234 allcapsButton->setMaximumSize(s);
235 strikeoutButton->setMaximumSize(s);
236 outlineButton->setMaximumSize(s);
237 shadowButton->setMaximumSize(s);
238
239 languageChange();
240
241 connect(ScQApp, SIGNAL(iconSetChanged()), this, SLOT(iconSetChange()));
242
243 connect(allcapsButton, SIGNAL(clicked()), this, SLOT(setTypeStyle()));
244 connect(smallcapsButton, SIGNAL(clicked()), this, SLOT(setTypeStyle()));
245 connect(underlineButton, SIGNAL(clicked()), this, SLOT(setTypeStyle()));
246 connect(underlineWordButton, SIGNAL(clicked()), this, SLOT(setTypeStyle()));
247 connect(subscriptButton, SIGNAL(clicked()), this, SLOT(setTypeStyle()));
248 connect(strikeoutButton, SIGNAL(clicked()), this, SLOT(setTypeStyle()));
249 connect(superscriptButton, SIGNAL(clicked()), this, SLOT(setTypeStyle()));
250 connect(outlineButton, SIGNAL(clicked()), this, SLOT(setTypeStyle()));
251 connect(shadowButton, SIGNAL(clicked()), this, SLOT(setTypeStyle()));
252
253 resize(minimumSizeHint());
254 }
255
changeEvent(QEvent * e)256 void StyleSelect::changeEvent(QEvent *e)
257 {
258 if (e->type() == QEvent::LanguageChange)
259 {
260 languageChange();
261 }
262 else
263 QWidget::changeEvent(e);
264 }
265
iconSetChange()266 void StyleSelect::iconSetChange()
267 {
268 IconManager& im = IconManager::instance();
269
270 underlineButton->setIcon(im.loadIcon("unter.png"));
271 underlineWordButton->setIcon(im.loadIcon("wordsOnly.png"));
272 subscriptButton->setIcon(im.loadIcon("tief.png"));
273 superscriptButton->setIcon(im.loadIcon("hoch.png"));
274 allcapsButton->setIcon(im.loadIcon("AllCaps.png"));
275 smallcapsButton->setIcon(im.loadIcon("kapital.png"));
276 strikeoutButton->setIcon(im.loadIcon("strike.png"));
277 outlineButton->setIcon(im.loadIcon("outlined.png"));
278 shadowButton->setIcon(im.loadIcon("shadow.png"));
279
280 QSize s(24,24);
281 underlineButton->setMinimumSize(s);
282 underlineWordButton->setMinimumSize(s);
283 subscriptButton->setMinimumSize(s);
284 superscriptButton->setMinimumSize(s);
285 smallcapsButton->setMinimumSize(s);
286 allcapsButton->setMinimumSize(s);
287 strikeoutButton->setMinimumSize(s);
288 outlineButton->setMinimumSize(s);
289 shadowButton->setMinimumSize(s);
290 underlineButton->setMaximumSize(s);
291 underlineWordButton->setMaximumSize(s);
292 subscriptButton->setMaximumSize(s);
293 superscriptButton->setMaximumSize(s);
294 smallcapsButton->setMaximumSize(s);
295 allcapsButton->setMaximumSize(s);
296 strikeoutButton->setMaximumSize(s);
297 outlineButton->setMaximumSize(s);
298 shadowButton->setMaximumSize(s);
299 }
300
languageChange()301 void StyleSelect::languageChange()
302 {
303 ShadowVal->languageChange();
304 OutlineVal->languageChange();
305 UnderlineVal->languageChange();
306 StrikeVal->languageChange();
307
308 underlineButton->setToolTip("");
309 underlineWordButton->setToolTip("");
310 allcapsButton->setToolTip("");
311 smallcapsButton->setToolTip("");
312 subscriptButton->setToolTip("");
313 superscriptButton->setToolTip("");
314 strikeoutButton->setToolTip("");
315 outlineButton->setToolTip("");
316 shadowButton->setToolTip("");
317
318 underlineButton->setToolTip( "<qt>" + tr("Underline Text. Hold down the button momentarily to set line width and displacement options."));
319 underlineWordButton->setToolTip( "<qt>" + tr("Underline Words Only. Hold down the button momentarily to set line width and displacement options.") + "</qt>" );
320 allcapsButton->setToolTip( tr("All Caps"));
321 smallcapsButton->setToolTip( tr("Small Caps"));
322 subscriptButton->setToolTip( tr("Subscript"));
323 superscriptButton->setToolTip( tr("Superscript"));
324 strikeoutButton->setToolTip( "<qt>" + tr("Strike Out. Hold down the button momentarily to set line width and displacement options.") + "</qt>" );
325 outlineButton->setToolTip( "<qt>" + tr("Outline. Hold down the button momentarily to change the outline stroke width.") + "</qt>" );
326 shadowButton->setToolTip( "<qt>" + tr("Shadowed Text. Hold down the button momentarily to change the shadow offset values.") + "</qt>" );
327 }
328
setStyle(int s)329 void StyleSelect::setStyle(int s)
330 {
331 superscriptButton->setChecked(false);
332 subscriptButton->setChecked(false);
333 strikeoutButton->setChecked(false);
334 underlineButton->setChecked(false);
335 underlineWordButton->setChecked(false);
336 allcapsButton->setChecked(false);
337 smallcapsButton->setChecked(false);
338 outlineButton->setChecked(false);
339 shadowButton->setChecked(false);
340 if (s & 1)
341 superscriptButton->setChecked(true);
342 if (s & 2)
343 subscriptButton->setChecked(true);
344 if (s & 4)
345 outlineButton->setChecked(true);
346 if (s & 8)
347 underlineButton->setChecked(true);
348 if (s & 16)
349 strikeoutButton->setChecked(true);
350 if (s & 32)
351 allcapsButton->setChecked(true);
352 if (s & 64)
353 smallcapsButton->setChecked(true);
354 if (s & 256)
355 shadowButton->setChecked(true);
356 if (s & 512)
357 underlineWordButton->setChecked(true);
358 }
359
getStyle()360 int StyleSelect::getStyle()
361 {
362 int ret = 0;
363 if (superscriptButton->isChecked())
364 ret |= 1;
365 if (subscriptButton->isChecked())
366 ret |= 2;
367 if (outlineButton->isChecked())
368 ret |= 4;
369 if (underlineButton->isChecked())
370 ret |= 8;
371 if (strikeoutButton->isChecked())
372 ret |= 16;
373 if (allcapsButton->isChecked())
374 ret |= 32;
375 if (smallcapsButton->isChecked())
376 ret |= 64;
377 if (shadowButton->isChecked())
378 ret |= 256;
379 if (underlineWordButton->isChecked())
380 ret |= 512;
381 return ret;
382 }
383
setTypeStyle()384 void StyleSelect::setTypeStyle()
385 {
386 if (superscriptButton == sender())
387 subscriptButton->setChecked(false);
388 if (subscriptButton == sender())
389 superscriptButton->setChecked(false);
390 if (allcapsButton == sender())
391 smallcapsButton->setChecked(false);
392 if (smallcapsButton == sender())
393 allcapsButton->setChecked(false);
394 if (underlineWordButton == sender())
395 underlineButton->setChecked(false);
396 if (underlineButton == sender())
397 underlineWordButton->setChecked(false);
398 emit State(getStyle());
399 }
400
401