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 "langmgr.h"
12 #include "prefsmanager.h"
13 #include "scribus.h"
14 #include "scribusapp.h"
15 #include "smcstylewidget.h"
16 #include "util.h"
17 #include "units.h"
18 
19 
SMCStyleWidget(QWidget * parent)20 SMCStyleWidget::SMCStyleWidget(QWidget *parent)
21 {
22 	setupUi(this);
23 
24 	iconSetChange();
25 
26 	fillColor_->setPixmapType(ColorCombo::fancyPixmaps);
27 	fillColor_->clear();
28 	fillColor_->addItem(CommonStrings::tr_NoneColor);
29 
30 	strokeColor_->setPixmapType(ColorCombo::fancyPixmaps);
31 	strokeColor_->clear();
32 	strokeColor_->addItem(CommonStrings::tr_NoneColor);
33 
34 	backColor_->setPixmapType(ColorCombo::fancyPixmaps);
35 	backColor_->clear();
36 	backColor_->addItem(CommonStrings::tr_NoneColor);
37 
38 	StrokeIcon->setEnabled(false);
39 	strokeShade_->setEnabled(false);
40 	strokeColor_->setEnabled(false);
41 	fontfeaturesSetting->resetFontFeatures();
42 
43 	hyphenCharLineEdit->setMaxLength(1);
44 
45 	connect(ScQApp, SIGNAL(iconSetChanged()), this, SLOT(iconSetChange()));
46 
47 	connect(effects_, SIGNAL(State(int)), this, SLOT(slotColorChange()));
48 	connect(fontFace_, SIGNAL(fontSelected(QString)), this, SLOT(slotEnableFontFeatures(QString)));
49 }
50 
changeEvent(QEvent * e)51 void SMCStyleWidget::changeEvent(QEvent *e)
52 {
53 	if (e->type() == QEvent::LanguageChange)
54 	{
55 		languageChange();
56 	}
57 	else
58 		QWidget::changeEvent(e);
59 }
60 
iconSetChange()61 void SMCStyleWidget::iconSetChange()
62 {
63 	IconManager& im = IconManager::instance();
64 
65 	fontSizeLabel_->setPixmap(im.loadPixmap("zeichen.png"));
66 	trackingLabel_->setPixmap(im.loadPixmap("textkern.png"));
67 	widthSpaceLabel->setPixmap(im.loadPixmap("spacewidth.png"));
68 	baselineOffsetLabel_->setPixmap(im.loadPixmap("textbase.png"));
69 	hscaleLabel_->setPixmap(im.loadPixmap("textscaleh.png"));
70 	vscaleLabel_->setPixmap(im.loadPixmap("textscalev.png"));
71 	FillIcon->setPixmap(im.loadPixmap("16/color-fill.png"));
72 	fillShadeLabel->setPixmap(im.loadPixmap("shade.png"));
73 	StrokeIcon->setPixmap(im.loadPixmap("16/color-stroke.png"));
74 	strokeShadeLabel->setPixmap(im.loadPixmap("shade.png"));
75 	backIcon->setPixmap(im.loadPixmap("16/color-fill.png"));
76 	backShadeLabel->setPixmap(im.loadPixmap("shade.png"));
77 }
78 
languageChange()79 void SMCStyleWidget::languageChange()
80 {
81 	QStringList languageList;
82 	LanguageManager::instance()->fillInstalledStringList(&languageList);
83 	fillLangComboFromList(languageList);
84 
85 	if (fillColor_->count() > 0)
86 	{
87 		bool sigBlocked = fillColor_->blockSignals(true);
88 		fillColor_->setItemText(0, CommonStrings::tr_NoneColor);
89 		fillColor_->blockSignals(sigBlocked);
90 	}
91 
92 	if (strokeColor_->count() > 0)
93 	{
94 		bool sigBlocked = strokeColor_->blockSignals(true);
95 		strokeColor_->setItemText(0, CommonStrings::tr_NoneColor);
96 		strokeColor_->blockSignals(sigBlocked);
97 	}
98 
99 	if (backColor_->count() > 0)
100 	{
101 		bool sigBlocked = backColor_->blockSignals(true);
102 		backColor_->setItemText(0, CommonStrings::tr_NoneColor);
103 		backColor_->blockSignals(sigBlocked);
104 	}
105 
106 	retranslateUi(this);
107 
108 	fontSizeLabel_->setToolTip(fontSize_->toolTip());
109 	trackingLabel_->setToolTip(tracking_->toolTip());
110 	widthSpaceLabel->setToolTip(widthSpaceSpin->toolTip());
111 	baselineOffsetLabel_->setToolTip(baselineOffset_->toolTip());
112 	hscaleLabel_->setToolTip(fontHScale_->toolTip());
113 	vscaleLabel_->setToolTip(fontVScale_->toolTip());
114 	FillIcon->setToolTip(fillColor_->toolTip());
115 	fillShadeLabel->setToolTip(fillShade_->toolTip());
116 	StrokeIcon->setToolTip(strokeColor_->toolTip());
117 	strokeShadeLabel->setToolTip(strokeShade_->toolTip());
118 	backIcon->setToolTip(backColor_->toolTip());
119 	backShadeLabel->setToolTip(backShade_->toolTip());
120 
121 // 	fontVScale_->setSuffix( tr(" %"));
122 // 	fontHScale_->setSuffix( tr(" %"));
123 // 	baselineOffset_->setSuffix( tr(" %"));
124 // 	tracking_->setSuffix( tr(" %"));
125 	fontSize_->setSuffix(unitGetSuffixFromIndex(0));
126 }
127 /*
128 void SMCStyleWidget::fillLangCombo(QMap<QString,QString> langMap)
129 {
130 	QStringList sortList;
131 	QMap<QString,QString>::Iterator it;
132 
133 	m_langMap = langMap;
134 
135 	language_->clear();
136 
137 	for (it = langMap.begin(); it != langMap.end(); ++it)
138 		sortList.push_back(it.value());
139 
140 	language_->addItems(sortQStringList(sortList));
141 
142 	QListView *tmpView = dynamic_cast<QListView*>(language_->view()); Q_ASSERT(tmpView);
143 	int tmpWidth = tmpView->sizeHintForColumn(0);
144 	if (tmpWidth > 0)
145 		tmpView->setMinimumWidth(tmpWidth + 24);
146 }
147 */
fillLangComboFromList(const QStringList & langList)148 void SMCStyleWidget::fillLangComboFromList(const QStringList& langList)
149 {
150 	language_->clear();
151 	language_->addItems(langList);
152 
153 	QListView *tmpView = qobject_cast<QListView*>(language_->view());
154 	Q_ASSERT(tmpView);
155 	int tmpWidth = tmpView->sizeHintForColumn(0);
156 	if (tmpWidth > 0)
157 		tmpView->setMinimumWidth(tmpWidth + 24);
158 }
159 
fillColorCombo(ColorList & colors)160 void SMCStyleWidget::fillColorCombo(ColorList &colors)
161 {
162 	fillColor_->clear();
163 	strokeColor_->clear();
164 	backColor_->clear();
165 
166 	fillColor_->setColors(colors, true);
167 	strokeColor_->setColors(colors, true);
168 	backColor_->setColors(colors, true);
169 	fillColor_->view()->setMinimumWidth(fillColor_->view()->maximumViewportSize().width()+24);
170 	strokeColor_->view()->setMinimumWidth(strokeColor_->view()->maximumViewportSize().width()+24);
171 	backColor_->view()->setMinimumWidth(backColor_->view()->maximumViewportSize().width()+24);
172 }
173 
handleUpdateRequest(int updateFlags)174 void SMCStyleWidget::handleUpdateRequest(int updateFlags)
175 {
176 	if (!m_Doc)
177 		return;
178 	if (updateFlags & reqColorsUpdate)
179 		fillColorCombo(m_Doc->PageColors);
180 }
181 
slotEnableFontFeatures(const QString & s)182 void SMCStyleWidget::slotEnableFontFeatures(const QString& s)
183 {
184 	const ScFace& font = PrefsManager::instance().appPrefs.fontPrefs.AvailFonts[s];
185 	fontfeaturesSetting->enableFontFeatures(font.fontFeatures());
186 }
187 
setDoc(ScribusDoc * doc)188 void SMCStyleWidget::setDoc(ScribusDoc *doc)
189 {
190 	if (m_Doc)
191 		disconnect(m_Doc->scMW(), SIGNAL(UpdateRequest(int)), this , SLOT(handleUpdateRequest(int)));
192 
193 	m_Doc = doc;
194 	if (!m_Doc)
195 		return;
196 
197 	QStringList languageList;
198 	LanguageManager::instance()->fillInstalledStringList(&languageList);
199 	fillLangComboFromList(languageList);
200 	fillColorCombo(m_Doc->PageColors);
201 	fontFace_->rebuildList(m_Doc);
202 
203 	connect(m_Doc->scMW(), SIGNAL(UpdateRequest(int)), this , SLOT(handleUpdateRequest(int)));
204 }
205 
show(CharStyle * cstyle,QList<CharStyle> & cstyles,const QString & defLang,int unitIndex)206 void SMCStyleWidget::show(CharStyle *cstyle, QList<CharStyle> &cstyles, const QString &defLang, int unitIndex)
207 {
208 	disconnect(effects_, SIGNAL(State(int)), this, SLOT(slotColorChange()));
209 	parentCombo->setEnabled(!cstyle->isDefaultStyle());
210 	const CharStyle *parent = dynamic_cast<const CharStyle*>(cstyle->parentStyle());
211 	bool hasParent =  cstyle->hasParent() && parent != nullptr && parent->hasName() && cstyle->parent() != "";
212 	if (hasParent)
213 	{
214 		fontSize_->setValue(cstyle->fontSize() / 10.0, cstyle->isInhFontSize());
215 		fontSize_->setParentValue(parent->fontSize() / 10.0);
216 
217 		fontHScale_->setValue(cstyle->scaleH() / 10.0, cstyle->isInhScaleH());
218 		fontHScale_->setParentValue(parent->scaleH() / 10.0);
219 
220 		fontVScale_->setValue(cstyle->scaleV() / 10.0, cstyle->isInhScaleV());
221 		fontVScale_->setParentValue(parent->scaleV() / 10.0);
222 
223 		baselineOffset_->setValue(cstyle->baselineOffset() / 10.0, cstyle->isInhBaselineOffset());
224 		baselineOffset_->setParentValue(parent->baselineOffset() / 10.0);
225 
226 		tracking_->setValue(cstyle->tracking() / 10.0, cstyle->isInhTracking());
227 		tracking_->setParentValue(parent->tracking() / 10.0);
228 
229 		widthSpaceSpin->setValue(cstyle->wordTracking() * 100.0 ,cstyle->isInhTracking());
230 		widthSpaceSpin->setParentValue(parent->wordTracking() * 100.0);
231 
232 		effects_->setStyle(static_cast<int>(cstyle->effects()), cstyle->isInhFeatures());
233 		effects_->setParentItem(static_cast<int>(parent->effects())); // FIXME
234 
235 		fillShade_->setValue(qRound(cstyle->fillShade()), cstyle->isInhFillShade());
236 		fillShade_->setParentValue(qRound(parent->fillShade()));
237 
238 		strokeShade_->setValue(qRound(cstyle->strokeShade()), cstyle->isInhStrokeShade());
239 		strokeShade_->setParentValue(qRound(parent->strokeShade()));
240 
241 		fillColor_->setCurrentText(cstyle->fillColor(), cstyle->isInhFillColor());
242 		fillColor_->setParentText(parent->fillColor());
243 
244 		strokeColor_->setCurrentText(cstyle->strokeColor(), cstyle->isInhStrokeColor());
245 		strokeColor_->setParentText(parent->strokeColor());
246 
247 		backColor_->setCurrentText(cstyle->backColor(), cstyle->isInhBackColor());
248 		backColor_->setParentText(parent->backColor());
249 
250 		backShade_->setValue(qRound(cstyle->backShade()), cstyle->isInhBackShade());
251 		backShade_->setParentValue(qRound(parent->backShade()));
252 
253 		fontFace_->setCurrentFont(cstyle->font().scName(), cstyle->isInhFont());
254 		fontFace_->setParentFont(parent->font().scName());
255 
256 		fontfeaturesSetting->setFontFeatures(cstyle->fontFeatures(), cstyle->font().fontFeatures());
257 		fontfeaturesSetting->setParentValue(parent->fontFeatures());
258 
259 		smallestWordSpinBox->setValue(cstyle->hyphenWordMin(), cstyle->isInhHyphenWordMin());
260 		smallestWordSpinBox->setParentValue(parent->hyphenWordMin());
261 
262 		uint hyphenChar = cstyle->hyphenChar();
263 		QString hyphenText;
264 		if (hyphenChar)
265 			hyphenText = QString::fromUcs4(&hyphenChar, 1);
266 		hyphenCharLineEdit->setValue(hyphenText, cstyle->isInhHyphenChar());
267 
268 		uint parentHyphenChar = parent->hyphenChar();
269 		QString parentHyphenText;
270 		if (parentHyphenChar)
271 			parentHyphenText = QString::fromUcs4(&parentHyphenChar, 1);
272 		hyphenCharLineEdit->setParentValue(parentHyphenText);
273 	}
274 	else
275 	{
276 		fontSize_->setValue(cstyle->fontSize() / 10.0);
277 		fontHScale_->setValue(cstyle->scaleH() / 10.0);
278 		fontVScale_->setValue(cstyle->scaleV() / 10.0);
279 		baselineOffset_->setValue(cstyle->baselineOffset() / 10.0);
280 		tracking_->setValue(cstyle->tracking() / 10.0);
281 		widthSpaceSpin->setValue(cstyle->wordTracking() * 100.0);
282 		effects_->setStyle(static_cast<int>(cstyle->effects()));
283 		fillShade_->setValue(qRound(cstyle->fillShade()));
284 		strokeShade_->setValue(qRound(cstyle->strokeShade()));
285 		fillColor_->setCurrentText(cstyle->fillColor());
286 		strokeColor_->setCurrentText(cstyle->strokeColor());
287 		backColor_->setCurrentText(cstyle->backColor());
288 		backShade_->setValue(qRound(cstyle->backShade()));
289 		fontFace_->setCurrentFont(cstyle->font().scName());
290 		fontfeaturesSetting->setFontFeatures(cstyle->fontFeatures(), cstyle->font().fontFeatures());
291 		smallestWordSpinBox->setValue(cstyle->hyphenWordMin());
292 
293 		uint hyphenChar = cstyle->hyphenChar();
294 		QString hyphenText;
295 		if (hyphenChar)
296 			hyphenText = QString::fromUcs4(&hyphenChar, 1);
297 		hyphenCharLineEdit->setValue(hyphenText);
298 	}
299 
300 	effects_->ShadowVal->Xoffset->setValue(cstyle->shadowXOffset() / 10.0);
301 	effects_->ShadowVal->Yoffset->setValue(cstyle->shadowYOffset() / 10.0);
302 	effects_->OutlineVal->LWidth->setValue(cstyle->outlineWidth() / 10.0);
303 	effects_->StrikeVal->LPos->setValue(cstyle->strikethruOffset() / 10.0);
304 	effects_->StrikeVal->LWidth->setValue(cstyle->strikethruWidth() / 10.0);
305 	effects_->UnderlineVal->LPos->setValue(cstyle->underlineOffset() / 10.0);
306 	effects_->UnderlineVal->LWidth->setValue(cstyle->underlineWidth() / 10.0);
307 	slotColorChange();
308 
309 	parentCombo->clear();
310 	parentCombo->addItem( cstyle->isDefaultStyle()? tr("A default style cannot be assigned a parent style") : "");
311 	if (!cstyle->isDefaultStyle())
312 	{
313 		for (int i = 0; i < cstyles.count(); ++i)
314 		{
315 			if (cstyles[i].name() != cstyle->name())
316 				parentCombo->addItem(cstyles[i].name());
317 		}
318 	}
319 
320 	if (cstyle->isDefaultStyle() || !hasParent)
321 		parentCombo->setCurrentIndex(0);
322 	else if (hasParent)
323 	{
324 		int index = 0;
325 		for (int i = 0; i < parentCombo->count(); ++i)
326 		{
327 			if (parentCombo->itemText(i) == cstyle->parentStyle()->name())
328 			{
329 				index = i;
330 				break;
331 			}
332 		}
333 		parentCombo->setCurrentIndex(index);
334 	}
335 
336 	QString defaultLang(defLang.isEmpty() ? "en_GB" : defLang);
337 	QString clang(cstyle->language().isEmpty() ? defaultLang : cstyle->language());
338 	QString plang;
339 	if (hasParent)
340 		plang = parent->language().isEmpty() ? defaultLang : parent->language();
341 
342 	int ci = -1, pi = -1, di = -1;
343 	QString tl = LanguageManager::instance()->getAbbrevFromLang(defaultLang, false);
344 	for (int i = 0; i < language_->count(); ++i)
345 	{
346 		QString ltAbbrev(LanguageManager::instance()->getAbbrevFromLang(language_->itemText(i), false));
347 		if (ltAbbrev == clang)
348 			ci = i;
349 		if (hasParent && ltAbbrev == plang)
350 			pi = i;
351 		if (ltAbbrev == defaultLang || ltAbbrev == tl)
352 			di = i;
353 	}
354 
355 	//qDebug() << QString("SMCStyleWidget::show(): deflan='%1'->'%2'").arg(defLang).arg(langMap_[defLang]);
356 	Q_ASSERT(di != -1);
357 
358 	if (hasParent)
359 	{
360 		if (ci == -1)
361 			language_->setCurrentItem(di, cstyle->isInhLanguage());
362 		else
363 			language_->setCurrentItem(ci, cstyle->isInhLanguage());
364 
365 		language_->setParentItem(pi);
366 	}
367 	else
368 	{
369 		if (ci == -1)
370 			language_->setCurrentIndex(di);
371 		else
372 			language_->setCurrentIndex(ci);
373 	}
374 
375 	connect(effects_, SIGNAL(State(int)), this, SLOT(slotColorChange()));
376 }
377 
show(QList<CharStyle * > & cstyles,QList<CharStyle> & cstylesAll,const QString & defLang,int unitIndex)378 void SMCStyleWidget::show(QList<CharStyle*> &cstyles, QList<CharStyle> &cstylesAll, const QString &defLang, int unitIndex)
379 {
380 // 	int decimals = unitGetDecimalsFromIndex(unitIndex);
381 // 	QString suffix = unitGetSuffixFromIndex(unitIndex);
382 
383 	if (cstyles.count() == 1)
384 		show(cstyles[0], cstylesAll, defLang, unitIndex);
385 	else if (cstyles.count() > 1)
386 	{
387 		showSizeAndPosition(cstyles);
388 		showEffects(cstyles);
389 		showColors(cstyles);
390 		showLanguage(cstyles, defLang);
391 		showSmallestWord(cstyles);
392 		showHyphenChar(cstyles);
393 		showParent(cstyles);
394 		showFontFeatures(cstyles);
395 	}
396 }
397 
showSizeAndPosition(const QList<CharStyle * > & cstyles)398 void SMCStyleWidget::showSizeAndPosition(const QList<CharStyle*> &cstyles)
399 {
400 	double d = -30000;
401 	for (int i = 0; i < cstyles.count(); ++i)
402 	{
403 		if (d != -30000 && cstyles[i]->fontSize() != d)
404 		{
405 			d = -30000;
406 			break;
407 		}
408 		d = cstyles[i]->fontSize();
409 	}
410 	if (d == -30000)
411 		fontSize_->clear();
412 	else
413 		fontSize_->setValue(d / 10.0);
414 
415 	d = -30000;
416 	for (int i = 0; i < cstyles.count(); ++i)
417 	{
418 		if (d != -30000 && cstyles[i]->scaleH() != d)
419 		{
420 			d = -30000;
421 			break;
422 		}
423 		d = cstyles[i]->scaleH();
424 	}
425 	if (d == -30000)
426 		fontHScale_->clear();
427 	else
428 		fontHScale_->setValue(d / 10.0);
429 
430 	d = -30000;
431 	for (int i = 0; i < cstyles.count(); ++i)
432 	{
433 		if (d != -30000 && cstyles[i]->scaleV() != d)
434 		{
435 			d = -30000;
436 			break;
437 		}
438 		d = cstyles[i]->scaleV();
439 	}
440 	if (d == -30000)
441 		fontVScale_->clear();
442 	else
443 		fontVScale_->setValue(d / 10.0);
444 
445 	d = -30000;
446 	for (int i = 0; i < cstyles.count(); ++i)
447 	{
448 		if (d != -30000 && cstyles[i]->baselineOffset() != d)
449 		{
450 			d = -30000;
451 			break;
452 		}
453 		d = cstyles[i]->baselineOffset();
454 	}
455 	if (d == -30000)
456 		baselineOffset_->clear();
457 	else
458 		baselineOffset_->setValue(d / 10.0);
459 
460 	d = -30000;
461 	for (int i = 0; i < cstyles.count(); ++i)
462 	{
463 		if (d != -30000 && cstyles[i]->tracking() != d)
464 		{
465 			d = -30000;
466 			break;
467 		}
468 		d = cstyles[i]->tracking();
469 	}
470 	if (d == -30000)
471 		tracking_->clear();
472 	else
473 		tracking_->setValue(d / 10.0);
474 
475 	d = -30000;
476 	for (int i = 0; i < cstyles.count(); ++i)
477 	{
478 		if (d != -30000 && cstyles[i]->wordTracking() != d)
479 		{
480 			d = -30000;
481 			break;
482 		}
483 		d = cstyles[i]->wordTracking();
484 	}
485 	if (d == -30000)
486 		widthSpaceSpin->clear();
487 	else
488 		widthSpaceSpin->setValue(d * 100.0);
489 }
490 
showEffects(const QList<CharStyle * > & cstyles)491 void SMCStyleWidget::showEffects(const QList<CharStyle*> &cstyles)
492 {
493 	int d = -30000;
494 	for (int i = 0; i < cstyles.count(); ++i)
495 	{
496 		if (d != -30000 && static_cast<int>(cstyles[i]->effects()) != d)
497 		{
498 			d = -30000;
499 			break;
500 		}
501 		d = static_cast<int>(cstyles[i]->effects());
502 	}
503 	if (d == -30000)
504 		effects_->setStyle(0);
505 	else
506 		effects_->setStyle(d);
507 
508 // 	TODO these things still missing:
509 // 		effects_->ShadowVal->Xoffset->setValue(cstyle->shadowXOffset() / 10.0);
510 // 		effects_->ShadowVal->Yoffset->setValue(cstyle->shadowYOffset() / 10.0);
511 // 		effects_->OutlineVal->LWidth->setValue(cstyle->outlineWidth() / 10.0);
512 // 		effects_->StrikeVal->LPos->setValue(cstyle->strikethruOffset() / 10.0);
513 // 		effects_->StrikeVal->LWidth->setValue(cstyle->strikethruWidth() / 10.0);
514 // 		effects_->UnderlineVal->LPos->setValue(cstyle->underlineOffset() / 10.0);
515 // 		effects_->UnderlineVal->LWidth->setValue(cstyle->underlineWidth() / 10.0);
516 }
517 
showColors(const QList<CharStyle * > & cstyles)518 void SMCStyleWidget::showColors(const QList<CharStyle*> &cstyles)
519 {
520 	strokeShade_->setEnabled(true);
521 	strokeColor_->setEnabled(true);
522 
523 	double d = -30000;
524 	for (int i = 0; i < cstyles.count(); ++i)
525 	{
526 		if (d != -30000 && cstyles[i]->fillShade() != d)
527 		{
528 			d = -30000;
529 			break;
530 		}
531 		d = cstyles[i]->fillShade();
532 	}
533 	if (d == -30000)
534 		fillShade_->setText( tr("Shade"));
535 	else
536 		fillShade_->setValue(qRound(d));
537 
538 	d = -30000;
539 	for (int i = 0; i < cstyles.count(); ++i)
540 	{
541 		if (d != -30000 && cstyles[i]->strokeShade() != d)
542 		{
543 			d = -30000;
544 			break;
545 		}
546 		d = cstyles[i]->strokeShade();
547 	}
548 	if (d == -30000)
549 	{
550 		strokeShade_->setValue(21);
551 		strokeShade_->setText( tr("Shade"));
552 	}
553 	else
554 		strokeShade_->setValue(qRound(d));
555 
556 	d = -30000;
557 	for (int i = 0; i < cstyles.count(); ++i)
558 	{
559 		if (d != -30000 && cstyles[i]->backShade() != d)
560 		{
561 			d = -30000;
562 			break;
563 		}
564 		d = cstyles[i]->backShade();
565 	}
566 	if (d == -30000)
567 	{
568 		backShade_->setValue(21);
569 		backShade_->setText( tr("Shade"));
570 	}
571 	else
572 		backShade_->setValue(qRound(d));
573 
574 	QString s;
575 	QString emptyString;
576 	for (int i = 0; i < cstyles.count(); ++i)
577 	{
578 		if (!s.isNull() && s != cstyles[i]->fillColor())
579 		{
580 			s = emptyString;
581 			break;
582 		}
583 		s = cstyles[i]->fillColor();
584 	}
585 	if (s.isEmpty())
586 	{
587 		if (fillColor_->itemText(fillColor_->count() - 1) != "")
588 			fillColor_->addItem("");
589 		fillColor_->setCurrentIndex(fillColor_->count() - 1);
590 	}
591 	else
592 		fillColor_->setCurrentText(s);
593 
594 	s = emptyString;
595 	for (int i = 0; i < cstyles.count(); ++i)
596 	{
597 		if (!s.isNull() && s != cstyles[i]->strokeColor())
598 		{
599 			s = emptyString;
600 			break;
601 		}
602 		s = cstyles[i]->strokeColor();
603 	}
604 	if (s.isEmpty())
605 	{
606 		if (strokeColor_->itemText(strokeColor_->count() - 1) != "")
607 			strokeColor_->addItem("");
608 		strokeColor_->setCurrentIndex(strokeColor_->count() - 1);
609 	}
610 	else
611 		strokeColor_->setCurrentText(s);
612 
613 	s = emptyString;
614 	for (int i = 0; i < cstyles.count(); ++i)
615 	{
616 		if (!s.isNull() && s != cstyles[i]->backColor())
617 		{
618 			s = emptyString;
619 			break;
620 		}
621 		s = cstyles[i]->backColor();
622 	}
623 	if (s.isEmpty())
624 	{
625 		if (backColor_->itemText(backColor_->count() - 1) != "")
626 			backColor_->addItem("");
627 		backColor_->setCurrentIndex(backColor_->count() - 1);
628 	}
629 	else
630 		backColor_->setCurrentText(s);
631 }
632 
showLanguage(const QList<CharStyle * > & cstyles,const QString & defLang)633 void SMCStyleWidget::showLanguage(const QList<CharStyle*> &cstyles, const QString &defLang)
634 {
635 	QString emptyString;
636 	QString s(cstyles[0]->language());
637 	for (int i = 0; i < cstyles.count(); ++i)
638 	{
639 		if (s != cstyles[i]->language())
640 		{
641 			s = emptyString;
642 			break;
643 		}
644 		s = cstyles[i]->language();
645 	}
646 	if (s.isEmpty())
647 	{
648 		if (language_->itemText(language_->count() - 1) != "")
649 			language_->addItem("");
650 		language_->setCurrentIndex(language_->count() - 1);
651 	}
652 	else
653 		setCurrentComboItem(language_, LanguageManager::instance()->getLangFromAbbrev(s));
654 }
655 
showSmallestWord(const QList<CharStyle * > & cstyles)656 void SMCStyleWidget::showSmallestWord(const QList<CharStyle *> &cstyles)
657 {
658 	int tmp = 0;
659 	int s(cstyles[0]->hyphenWordMin());
660 	for (int i = 0; i < cstyles.count(); ++i)
661 	{
662 		if (s != cstyles[i]->hyphenWordMin())
663 		{
664 			s = tmp;
665 			break;
666 		}
667 		s = cstyles[i]->hyphenWordMin();
668 	}
669 	smallestWordSpinBox->setValue(s);
670 }
671 
showHyphenChar(const QList<CharStyle * > & cstyles)672 void SMCStyleWidget::showHyphenChar(const QList<CharStyle *> &cstyles)
673 {
674 	uint empty = 0;
675 	uint ch(cstyles[0]->hyphenChar());
676 	for (int i = 0; i < cstyles.count(); ++i)
677 	{
678 		if (ch != cstyles[i]->hyphenChar())
679 		{
680 			ch = empty;
681 			break;
682 		}
683 		ch = cstyles[i]->hyphenChar();
684 	}
685 
686 	QString hyphenText;
687 	if (ch)
688 		hyphenText = QString::fromUcs4(&ch, 1);
689 	hyphenCharLineEdit->setValue(hyphenText);
690 }
691 
showParent(const QList<CharStyle * > & cstyles)692 void SMCStyleWidget::showParent(const QList<CharStyle*> &cstyles)
693 {
694 	parentCombo->setEnabled(false);
695 }
696 
showFontFeatures(const QList<CharStyle * > & cstyles)697 void SMCStyleWidget::showFontFeatures(const QList<CharStyle *> &cstyles)
698 {
699 	QString tmp;
700 	QStringList tmp2;
701 	QString fontfeatures(cstyles[0]->fontFeatures());
702 	QStringList featuresList(cstyles[0]->font().fontFeatures());
703 	for (int i = 0; i < cstyles.count(); ++i)
704 	{
705 		if (fontfeatures != cstyles[i]->fontFeatures())
706 		{
707 			fontfeatures = tmp;
708 			featuresList = tmp2;
709 			break;
710 		}
711 		fontfeatures = cstyles[i]->fontFeatures();
712 		featuresList = cstyles[i]->font().fontFeatures();
713 	}
714 	fontfeaturesSetting->setFontFeatures(fontfeatures, featuresList);
715 }
716 
clearAll()717 void SMCStyleWidget::clearAll()
718 {
719 
720 }
721 
slotColorChange()722 void SMCStyleWidget::slotColorChange()
723 {
724 	int s = effects_->getStyle();
725 	bool enabled= (s & 4) || (s & 256);
726 	StrokeIcon->setEnabled(enabled);
727 	strokeShade_->setEnabled(enabled);
728 	strokeColor_->setEnabled(enabled);
729 }
730 
731 
~SMCStyleWidget()732 SMCStyleWidget::~SMCStyleWidget()
733 {
734 
735 }
736