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
11 #include "iconmanager.h"
12 #include "numeration.h"
13 #include "smpstylewidget.h"
14 #include "scribus.h"
15 #include "scribusapp.h"
16 #include "units.h"
17 #include "util.h"
18 #include "ui/charselectenhanced.h"
19
isEqual(double a,double b)20 static bool isEqual(double a, double b)
21 {
22 Q_ASSERT(a > -21473 && b > -21473 && a < 21474 && b < 21474);
23 long al = static_cast<long>(10000 * a);
24 long bl = static_cast<long>(10000 * b);
25 return al == bl;
26 }
27
28
SMPStyleWidget(ScribusDoc * doc,StyleSet<CharStyle> * cstyles)29 SMPStyleWidget::SMPStyleWidget(ScribusDoc* doc, StyleSet<CharStyle> *cstyles) :
30 m_Doc(doc),
31 m_cstyles(cstyles)
32 {
33 setupUi(this);
34
35 //Not used yet
36 // optMarginCheckLeftProtruding->setVisible(false);
37
38 iconSetChange();
39
40 backColor_->setPixmapType(ColorCombo::fancyPixmaps);
41 backColor_->clear();
42 backColor_->addItem(CommonStrings::tr_NoneColor);
43
44 lineSpacingMode->addItem( tr("Fixed Linespacing"));
45 lineSpacingMode->addItem( tr("Automatic Linespacing"));
46 lineSpacingMode->addItem( tr("Align to Baseline Grid"));
47 connect(lineSpacingMode, SIGNAL(highlighted(int)), this, SLOT(slotLineSpacingModeChanged(int)));
48
49 lineSpacing->setSuffix(unitGetSuffixFromIndex(0));
50 spaceAbove->setSuffix(unitGetSuffixFromIndex(0));
51 spaceBelow->setSuffix(unitGetSuffixFromIndex(0));
52
53 // optMarginCombo->addItem(tr("None"), ParagraphStyle::OM_None);
54 // optMarginCombo->addItem(tr("Left Protruding"), ParagraphStyle::OM_LeftProtruding);
55 // optMarginCombo->addItem(tr("Right Protruding"), ParagraphStyle::OM_RightProtruding);
56 // optMarginCombo->addItem(tr("Left Hanging Punctuation"), ParagraphStyle::OM_LeftHangingPunct);
57 // optMarginCombo->addItem(tr("Right Hanging Punctuation"), ParagraphStyle::OM_RightHangingPunct);
58 // optMarginCombo->addItem(tr("Default"), ParagraphStyle::OM_Default);
59
60 parEffectOffset->setSuffix(unitGetSuffixFromIndex(0));
61
62 fillBulletStrEditCombo();
63
64 numStartSpin->setMinimum(1);
65 numStartSpin->setMaximum(9999);
66 numLevelSpin->setMinimum(1);
67 numLevelSpin->setMaximum(1);
68 fillNumRestartCombo();
69 dropCapLines->setMinimum(2);
70 dropCapLines->setMaximum(99);
71
72 minSpaceSpin->setSuffix(unitGetSuffixFromIndex(SC_PERCENT));
73 minGlyphExtSpin->setSuffix(unitGetSuffixFromIndex(SC_PERCENT));
74 maxGlyphExtSpin->setSuffix(unitGetSuffixFromIndex(SC_PERCENT));
75
76 connect(ScQApp, SIGNAL(iconSetChanged()), this, SLOT(iconSetChange()));
77
78 connect(optMarginDefaultButton, SIGNAL(clicked()), this, SLOT(slotDefaultOpticalMargins()));
79 if (m_Doc)
80 connect(m_Doc->scMW(), SIGNAL(UpdateRequest(int)), this , SLOT(handleUpdateRequest(int)));
81 m_enhanced = nullptr;
82 }
83
slotLineSpacingModeChanged(int i)84 void SMPStyleWidget::slotLineSpacingModeChanged(int i)
85 {
86 lineSpacing->setEnabled(i == 0);
87 }
88
changeEvent(QEvent * e)89 void SMPStyleWidget::changeEvent(QEvent *e)
90 {
91 if (e->type() == QEvent::LanguageChange)
92 {
93 languageChange();
94 }
95 else
96 QWidget::changeEvent(e);
97 }
98
iconSetChange()99 void SMPStyleWidget::iconSetChange()
100 {
101 IconManager& iconManager = IconManager::instance();
102
103 lineSpacingLabel->setPixmap(iconManager.loadPixmap("linespacing2.png"));
104 spaceAboveLabel->setPixmap(iconManager.loadPixmap("above.png") );
105 spaceBelowLabel->setPixmap(iconManager.loadPixmap("below.png") );
106 keepLabelStart->setPixmap(iconManager.loadPixmap("22/orphan.png") );
107 keepLabelEnd->setPixmap(iconManager.loadPixmap("22/widow.png") );
108 backIcon->setPixmap(iconManager.loadPixmap("16/color-fill.png"));
109 backShadeLabel->setPixmap(iconManager.loadPixmap("shade.png"));
110
111 bulletCharTableButton->setIcon(IconManager::instance().loadPixmap("22/insert-table.png"));
112 }
113
languageChange()114 void SMPStyleWidget::languageChange()
115 {
116 retranslateUi(this);
117 alignment->languageChange();
118 tabList->firstLineSpin->setToolTip( tr("First Line Indent"));
119 tabList->leftIndentSpin->setToolTip( tr("Left Indent"));
120 tabList->rightIndentSpin->setToolTip( tr("Right Indent"));
121
122 int oldLineSpacingModeIndex = lineSpacingMode->currentIndex();
123 bool lineSpacingModeBlocked = lineSpacingMode->blockSignals(true);
124 lineSpacingMode->clear();
125 lineSpacingMode->addItem( tr("Fixed Linespacing"));
126 lineSpacingMode->addItem( tr("Automatic Linespacing"));
127 lineSpacingMode->addItem( tr("Align to Baseline Grid"));
128 lineSpacingMode->setCurrentIndex(oldLineSpacingModeIndex);
129 lineSpacingMode->blockSignals(lineSpacingModeBlocked);
130
131 lineSpacing->setSuffix(unitGetSuffixFromIndex(0));
132 spaceAbove->setSuffix(unitGetSuffixFromIndex(0));
133 spaceBelow->setSuffix(unitGetSuffixFromIndex(0));
134
135 keepLinesStart->setSuffix( tr(" lines"));
136 keepLinesEnd->setSuffix( tr(" lines"));
137
138 int oldNumRestartIndex = numRestartCombo->currentIndex();
139 bool numRestartComboBlocked = numRestartCombo->blockSignals(true);
140 fillNumRestartCombo();
141 numRestartCombo->setCurrentIndex(oldNumRestartIndex);
142 numRestartCombo->blockSignals(numRestartComboBlocked);
143
144 /* #13455 stop making the font 2ce as big
145 QFont font1;
146 if (font1.pointSize())
147 font1.setPointSize(font1.pointSize() *2);
148 else if (font1.pixelSize())
149 font1.setPixelSize(font1.pixelSize() *2);
150 ((QComboBox*) bulletStrEdit)->setFont(font1);
151 (bulletStrEdit->lineEdit())->setFont(font1);
152 */
153
154 if (backColor_->count() > 0)
155 {
156 bool sigBlocked = backColor_->blockSignals(true);
157 backColor_->setItemText(0, CommonStrings::tr_NoneColor);
158 backColor_->blockSignals(sigBlocked);
159 }
160 }
161
unitChange(double oldRatio,double newRatio,int unitIndex)162 void SMPStyleWidget::unitChange(double oldRatio, double newRatio, int unitIndex)
163 {
164 parEffectOffset->setNewUnit(unitIndex);
165 tabList->unitChange(unitIndex);
166 }
167
setDoc(ScribusDoc * doc)168 void SMPStyleWidget::setDoc(ScribusDoc *doc)
169 {
170 if (m_Doc)
171 disconnect(m_Doc->scMW(), SIGNAL(UpdateRequest(int)), this , SLOT(handleUpdateRequest(int)));
172
173 m_Doc = doc;
174 if (m_Doc)
175 {
176 connect(m_Doc->scMW(), SIGNAL(UpdateRequest(int)), this , SLOT(handleUpdateRequest(int)));
177 fillColorCombo(m_Doc->PageColors);
178 fillNumerationsCombo();
179 }
180
181 cpage->setDoc(m_Doc);
182 }
183
fillColorCombo(ColorList & colors)184 void SMPStyleWidget::fillColorCombo(ColorList &colors)
185 {
186 backColor_->clear();
187 backColor_->setColors(colors, true);
188 backColor_->view()->setMinimumWidth(backColor_->view()->maximumViewportSize().width()+24);
189 }
190
fillBulletStrEditCombo()191 void SMPStyleWidget::fillBulletStrEditCombo()
192 {
193 bulletStrEdit->clear();
194 bulletStrEdit->addItem(QChar(0x2022));
195 bulletStrEdit->addItem("*");
196 bulletStrEdit->addItem(QChar(0x2013));
197 bulletStrEdit->setMinimumWidth(50);
198 if (bulletStrEdit->currentText().isEmpty())
199 bulletStrEdit->setEditText(QChar(0x2022));
200 }
201
fillNumerationsCombo()202 void SMPStyleWidget::fillNumerationsCombo()
203 {
204 QStringList numNames;
205 const auto numerationKeys = m_Doc->numerations.keys();
206 for (const QString& numName : numerationKeys)
207 {
208 if (numName.isEmpty())
209 continue;
210 numNames.append(numName);
211 }
212 numNames.sort();
213 numComboBox->clear();
214 numComboBox->insertItems(0, numNames);
215 numComboBox->setCurrentItem(0);
216 }
217
fillNumRestartCombo()218 void SMPStyleWidget::fillNumRestartCombo()
219 {
220 numRestartCombo->clear();
221 numRestartCombo->addItem(tr("Document"), static_cast<int>(NSRdocument));
222 numRestartCombo->addItem(tr("Story") , static_cast<int>(NSRstory));
223 }
224
checkParEffectState()225 void SMPStyleWidget::checkParEffectState()
226 {
227 bool enable = false;
228 if (dropCapsBox->isChecked() || bulletBox->isChecked() || numBox->isChecked())
229 enable = true;
230
231 parEffectCharStyleCombo->setEnabled(enable);
232 parEffectOffset->setEnabled(enable);
233 parEffectIndentBox->setEnabled(enable);
234 }
235
show(ParagraphStyle * pstyle,QList<ParagraphStyle> & pstyles,QList<CharStyle> & cstyles,int unitIndex,const QString & defLang)236 void SMPStyleWidget::show(ParagraphStyle *pstyle, QList<ParagraphStyle> &pstyles, QList<CharStyle> &cstyles, int unitIndex, const QString &defLang)
237 {
238 m_currPStyle = pstyle;
239 double unitRatio = unitGetRatioFromIndex(unitIndex);
240 parentCombo->setEnabled(!pstyle->isDefaultStyle());
241 const ParagraphStyle *parent = dynamic_cast<const ParagraphStyle*>(pstyle->parentStyle());
242 m_hasParent = pstyle->hasParent() && parent != nullptr && parent->hasName() && pstyle->parent() != "";
243
244 lineSpacingMode->clear();
245 lineSpacingMode->addItem( tr("Fixed Linespacing"));
246 lineSpacingMode->addItem( tr("Automatic Linespacing"));
247 lineSpacingMode->addItem( tr("Align to Baseline Grid"));
248
249 // optMarginCombo->clear();
250 // optMarginCombo->addItem(tr("None"), ParagraphStyle::OM_None);
251 // optMarginCombo->addItem(tr("Left Protruding"), ParagraphStyle::OM_LeftProtruding);
252 // optMarginCombo->addItem(tr("Right Protruding"), ParagraphStyle::OM_RightProtruding);
253 // optMarginCombo->addItem(tr("Left Hanging Punctuation"), ParagraphStyle::OM_LeftHangingPunct);
254 // optMarginCombo->addItem(tr("Right Hanging Punctuation"), ParagraphStyle::OM_RightHangingPunct);
255 // optMarginCombo->addItem(tr("Default"), ParagraphStyle::OM_Default);
256
257 // One could think it’s too much (aesthetic) or not enough (freedom)!
258 minSpaceSpin->setRange(1.0,100.0);
259 minGlyphExtSpin->setRange(90.0,100.0);
260 maxGlyphExtSpin->setRange(100.0,110.0);
261
262 maxConsecutiveCountSpinBox->clear();
263
264 //fillBulletStrEditCombo();
265 //fillNumerationsCombo();
266 //fillNumRestartCombo();
267
268 if (m_hasParent)
269 {
270 lineSpacingMode->setCurrentItem(pstyle->lineSpacingMode(), pstyle->isInhLineSpacingMode());
271 lineSpacingMode->setParentItem(parent->lineSpacingMode());
272
273 // optMarginCombo->setCurrentItemByData( pstyle->opticalMargins(), pstyle->isInhOpticalMargins() );
274 // optMarginCombo->setParentItem(optMarginCombo->getItemIndexForData( parent->opticalMargins()));
275 setOpticalMargins(pstyle->opticalMargins(), pstyle->isInhOpticalMargins(), parent);
276 connect(optMarginParentButton, SIGNAL(clicked()), this, SLOT(slotParentOpticalMargins()));
277
278 minSpaceSpin->setValue(pstyle->minWordTracking() * 100.0, pstyle->isInhMinWordTracking());
279 minSpaceSpin->setParentValue(parent->minWordTracking());
280 minGlyphExtSpin->setValue(pstyle->minGlyphExtension() * 100.0, pstyle->isInhMinGlyphExtension());
281 minGlyphExtSpin->setParentValue(parent->minGlyphExtension());
282 maxGlyphExtSpin->setValue(pstyle->maxGlyphExtension() * 100.0, pstyle->isInhMaxGlyphExtension());
283 maxGlyphExtSpin->setParentValue(parent->maxGlyphExtension());
284
285 maxConsecutiveCountSpinBox->setValue(pstyle->hyphenConsecutiveLines(), pstyle->isInhHyphenConsecutiveLines());
286 maxConsecutiveCountSpinBox->setParentValue(parent->hyphenConsecutiveLines());
287
288 lineSpacing->setValue(pstyle->lineSpacing(), pstyle->isInhLineSpacing());
289 lineSpacing->setParentValue(parent->lineSpacing());
290
291 spaceAbove->setValue(pstyle->gapBefore(), pstyle->isInhGapBefore());
292 spaceAbove->setParentValue(parent->gapBefore());
293
294 spaceBelow->setValue(pstyle->gapAfter(), pstyle->isInhGapAfter());
295 spaceBelow->setParentValue(parent->gapAfter());
296
297 alignment->setStyle(pstyle->alignment(), direction->getStyle(), pstyle->isInhAlignment());
298 alignment->setParentItem(parent->alignment(), direction->getStyle());
299
300 direction->setStyle(pstyle->direction());
301 direction->setParentItem(parent->direction());
302
303 bool hasParentTabs = pstyle->isInhTabValues();
304 QList<ParagraphStyle::TabRecord> tabs;
305 if (hasParentTabs)
306 tabs = QList<ParagraphStyle::TabRecord>(parent->tabValues());
307 else
308 tabs = pstyle->tabValues();
309
310 tabList->setTabs(tabs, unitIndex, hasParentTabs);
311 tabList->setParentTabs(parent->tabValues());
312
313 tabList->setLeftIndentValue(pstyle->leftMargin() * unitRatio,pstyle->isInhLeftMargin());
314 tabList->setParentLeftIndent(parent->leftMargin() * unitRatio);
315
316 tabList->setFirstLineValue(pstyle->firstIndent() * unitRatio, pstyle->isInhFirstIndent());
317 tabList->setParentFirstLine(parent->firstIndent() * unitRatio);
318
319 tabList->setRightIndentValue(pstyle->rightMargin() * unitRatio, pstyle->isInhRightMargin());
320 tabList->setParentRightIndent(parent->rightMargin() * unitRatio);
321
322 keepLinesStart->setValue (pstyle->keepLinesStart(), pstyle->isInhKeepLinesStart());
323 keepLinesEnd->setValue (pstyle->keepLinesEnd(), pstyle->isInhKeepLinesEnd());
324 keepTogether->setChecked (pstyle->keepTogether(), pstyle->isInhKeepTogether());
325 keepWithNext->setChecked (pstyle->keepWithNext(), pstyle->isInhKeepWithNext());
326 keepLinesStart->setParentValue (parent->keepLinesStart());
327 keepLinesEnd->setParentValue (parent->keepLinesEnd());
328 keepTogether->setParentValue (parent->keepTogether());
329 keepWithNext->setParentValue (parent->keepWithNext());
330
331 //Effects Gropup Box
332 m_parentDC = parent->hasDropCap();
333 m_parentBul = parent->hasBullet();
334 m_parentNum = parent->hasNum();
335 //parentParEffects_ = (m_parentDC || m_parentBul || m_parentNum);
336 if (pstyle->isInhHasDropCap() && pstyle->isInhHasBullet() && pstyle->isInhHasNum())
337 {
338 parentParEffectsButton->hide();
339 disconnect(parentParEffectsButton, SIGNAL(clicked()), this, SLOT(slotParentParEffects()));
340 }
341 else
342 {
343 parentParEffectsButton->show();
344 QFont f(font());
345 f.setBold(true);
346 parentParEffectsButton->setFont(f);
347 }
348 connect(parentParEffectsButton, SIGNAL(clicked()), this, SLOT(slotParentParEffects()));
349
350 dropCapsBox->setChecked(pstyle->hasDropCap());
351 setWidgetBoldFont(dropCapsBox, !pstyle->isInhHasDropCap());
352 dropCapLines->setValue(pstyle->dropCapLines(), pstyle->isInhDropCapLines());
353 dropCapLines->setParentValue(parent->dropCapLines());
354
355 parEffectOffset->setValue(pstyle->parEffectOffset() * unitRatio, pstyle->isInhParEffectOffset());
356 parEffectOffset->setParentValue(parent->parEffectOffset() * unitRatio);
357 parEffectIndentBox->setChecked(pstyle->parEffectIndent(),pstyle->isInhParEffectIndent());
358 parEffectIndentBox->setParentValue(parent->parEffectIndent());
359
360 bulletBox->setChecked(pstyle->hasBullet());
361 setWidgetBoldFont(bulletBox, !pstyle->isInhHasBullet());
362 bulletStrEdit->setEditText(pstyle->bulletStr());
363 setWidgetBoldFont(bulletCharLabel, !pstyle->isInhBulletStr());
364 numBox->setChecked(pstyle->hasNum());
365 setWidgetBoldFont(numBox, !pstyle->isInhHasNum());
366 QString numName = pstyle->numName();
367 if (numName.isEmpty())
368 numName = "default";
369 numComboBox->setCurrentItem(numComboBox->findText(numName), pstyle->isInhNumName());
370 if (!parent->numName().isEmpty())
371 numComboBox->setParentItem(numComboBox->findText(parent->numName()));
372 else
373 numComboBox->setParentItem(0);
374 numFormatCombo->setCurrentFormat((NumFormat) pstyle->numFormat());
375 numFormatCombo->setParentFormat((NumFormat) parent->numFormat());
376 numLevelSpin->setValue(pstyle->numLevel() +1, pstyle->isInhNumLevel());
377 NumStruct * numS = m_Doc->numerations.value(pstyle->numName());
378 if (numS)
379 numLevelSpin->setMaximum(numS->m_counters.count()+1);
380 else
381 numLevelSpin->setMaximum(1);
382 numLevelSpin->setParentValue(parent->numLevel()+1);
383 numPrefix->setText(pstyle->numPrefix());
384 setWidgetBoldFont(numPrefixLabel, !pstyle->isInhNumPrefix());
385 numSuffix->setText(pstyle->numSuffix());
386 setWidgetBoldFont(numSuffixLabel, !pstyle->isInhNumSuffix());
387 numStartSpin->setValue(pstyle->numStart(), pstyle->isInhNumStart());
388 numStartSpin->setParentValue(parent->numStart());
389 int numRestartIndex = numRestartCombo->findData(pstyle->numRestart());
390 numRestartCombo->setCurrentItem(numRestartIndex, pstyle->isInhNumRestart());
391 numRestartCombo->setParentItem(numRestartIndex);
392 numRestartOtherBox->setChecked(pstyle->numOther(), pstyle->isInhNumOther());
393 numRestartOtherBox->setParentValue(parent->numOther());
394 numRestartHigherBox->setChecked(pstyle->numHigher(), pstyle->isInhNumHigher());
395 numRestartHigherBox->setParentValue(parent->numHigher());
396
397 backColor_->setCurrentText(pstyle->backgroundColor(), pstyle->isInhBackgroundColor());
398 backColor_->setParentText(parent->backgroundColor());
399 backShade_->setValue(qRound(pstyle->backgroundShade()), pstyle->isInhBackgroundShade());
400 backShade_->setParentValue(qRound(parent->backgroundShade()));
401 }
402 else
403 {
404 lineSpacingMode->setCurrentIndex(pstyle->lineSpacingMode());
405 lineSpacing->setValue(pstyle->lineSpacing());
406 spaceAbove->setValue(pstyle->gapBefore());
407 spaceBelow->setValue(pstyle->gapAfter());
408 // optMarginCombo->setCurrentItemByData( pstyle->opticalMargins() );
409 setOpticalMargins(pstyle->opticalMargins());
410 optMarginParentButton->hide();
411 minSpaceSpin->setValue(pstyle->minWordTracking() * 100.0);
412 minGlyphExtSpin->setValue(pstyle->minGlyphExtension() * 100.0);
413 maxGlyphExtSpin->setValue(pstyle->maxGlyphExtension() * 100.0);
414 maxConsecutiveCountSpinBox->setValue(pstyle->hyphenConsecutiveLines());
415 parEffectOffset->setValue(pstyle->parEffectOffset() * unitRatio);
416 parEffectIndentBox->setChecked(pstyle->parEffectIndent());
417 parentParEffectsButton->hide();
418 disconnect(parentParEffectsButton, SIGNAL(clicked()), this, SLOT(slotParentParEffects()));
419 dropCapsBox->setChecked(pstyle->hasDropCap());
420 setWidgetBoldFont(dropCapsBox, false);
421 dropCapLines->setValue(pstyle->dropCapLines());
422 bulletBox->setChecked(pstyle->hasBullet());
423 setWidgetBoldFont(bulletBox, false);
424 bulletStrEdit->setEditText(pstyle->bulletStr());
425 setWidgetBoldFont(bulletCharLabel, false);
426 numBox->setChecked(pstyle->hasNum());
427 setWidgetBoldFont(numBox, false);
428 QString numName = pstyle->numName();
429 if (numName.isEmpty())
430 numName = "default";
431 numComboBox->setCurrentItem(numComboBox->findText(numName));
432 numNewLineEdit->clear();
433 numFormatCombo->setCurrentFormat((NumFormat) pstyle->numFormat());
434 numLevelSpin->setValue(pstyle->numLevel()+1);
435 NumStruct * numS = m_Doc->numerations.value(pstyle->numName());
436 if (numS)
437 numLevelSpin->setMaximum(numS->m_counters.count()+1);
438 else
439 numLevelSpin->setMaximum(1);
440 numPrefix->setText(pstyle->numPrefix());
441 setWidgetBoldFont(numPrefixLabel, false);
442 numSuffix->setText(pstyle->numSuffix());
443 setWidgetBoldFont(numSuffixLabel, false);
444 numStartSpin->setValue(pstyle->numStart());
445 int numRestartIndex = numRestartCombo->findData(pstyle->numRestart());
446 numRestartCombo->setCurrentItem((numRestartIndex >= 0) ? numRestartIndex : 0);
447 numRestartOtherBox->setChecked(pstyle->numOther());
448 numRestartHigherBox->setChecked(pstyle->numHigher());
449
450 alignment->setStyle(pstyle->alignment(), direction->getStyle());
451 tabList->setTabs(pstyle->tabValues(), unitIndex);
452 tabList->setLeftIndentValue(pstyle->leftMargin() * unitRatio);
453 tabList->setFirstLineValue(pstyle->firstIndent() * unitRatio);
454 tabList->setRightIndentValue(pstyle->rightMargin() * unitRatio);
455
456 direction->setStyle(pstyle->direction());
457
458 keepLinesStart->setValue (pstyle->keepLinesStart());
459 keepLinesEnd->setValue (pstyle->keepLinesEnd());
460 keepTogether->setChecked (pstyle->keepTogether());
461 keepWithNext->setChecked (pstyle->keepWithNext());
462 backColor_->setCurrentText(pstyle->backgroundColor());
463 backShade_->setValue(qRound(pstyle->backgroundShade()));
464 }
465
466 lineSpacing->setEnabled(pstyle->lineSpacingMode() == ParagraphStyle::FixedLineSpacing);
467 dropCapLines->setEnabled(pstyle->hasDropCap());
468
469 checkParEffectState();
470 parEffectCharStyleCombo->clear();
471 parEffectCharStyleCombo->addItem(tr("No Style"));
472 for (int i =0; i < cstyles.count(); i++)
473 parEffectCharStyleCombo->addItem(cstyles.at(i).name());
474 setCurrentComboItem(parEffectCharStyleCombo, pstyle->peCharStyleName().isEmpty() ? tr("No Style") : pstyle->peCharStyleName());
475
476 cpage->parentLabel->setText( tr("Based On:"));
477 cpage->show(&pstyle->charStyle(), cstyles, defLang, unitIndex);
478
479 parentCombo->clear();
480 parentCombo->addItem( pstyle->isDefaultStyle()? tr("A default style cannot be assigned a parent style") : "");
481 if (!pstyle->isDefaultStyle())
482 {
483 for (int i = 0; i < pstyles.count(); ++i)
484 {
485 if (pstyles[i].hasName() && pstyles[i].name() != pstyle->name())
486 parentCombo->addItem(pstyles[i].name());
487 }
488 }
489 if (pstyle->isDefaultStyle() || !m_hasParent)
490 parentCombo->setCurrentIndex(0);
491 else
492 {
493 int index = 0;
494 for (int i = 0; i < parentCombo->count(); ++i)
495 {
496 if (parentCombo->itemText(i) == parent->name())
497 {
498 index = i;
499 break;
500 }
501 }
502 parentCombo->setCurrentIndex(index);
503 }
504
505 connect(dropCapsBox, SIGNAL(toggled(bool)), this, SLOT(slotDropCap(bool)));
506 connect(bulletBox, SIGNAL(toggled(bool)), this, SLOT(slotBullets(bool)));
507 connect(numBox, SIGNAL(toggled(bool)), this, SLOT(slotNumbering(bool)));
508 }
509
show(QList<ParagraphStyle * > & pstyles,QList<ParagraphStyle> & pstylesAll,QList<CharStyle> & cstyles,int unitIndex,const QString & defLang)510 void SMPStyleWidget::show(QList<ParagraphStyle*> &pstyles, QList<ParagraphStyle> &pstylesAll, QList<CharStyle> &cstyles, int unitIndex, const QString &defLang)
511 {
512 if (pstyles.count() == 1)
513 show(pstyles[0], pstylesAll, cstyles, unitIndex, defLang);
514 else if (pstyles.count() > 1)
515 {
516 m_currPStyle = pstyles[0];
517 showLineSpacing(pstyles);
518 showSpaceAB(pstyles, unitIndex);
519 showDropCap(pstyles, cstyles, unitIndex);
520 showBullet(pstyles, cstyles, unitIndex);
521 showNumeration(pstyles, cstyles, unitIndex);
522 showAlignment(pstyles);
523 showDirection(pstyles);
524 showOpticalMargin(pstyles);
525 showMinSpace(pstyles);
526 showMinGlyphExt(pstyles);
527 showMaxGlyphExt(pstyles);
528 showConsecutiveLines(pstyles);
529 showTabs(pstyles, unitIndex);
530 showCStyle(pstyles, cstyles, defLang, unitIndex);
531 showParent(pstyles);
532 checkParEffectState();
533 showColors(pstyles);
534 }
535 }
536
showColors(const QList<ParagraphStyle * > & cstyles)537 void SMPStyleWidget::showColors(const QList<ParagraphStyle*> &cstyles)
538 {
539 double d = -30000;
540 for (int i = 0; i < cstyles.count(); ++i)
541 {
542 if (d != -30000 && cstyles[i]->backgroundShade() != d)
543 {
544 d = -30000;
545 break;
546 }
547 d = cstyles[i]->backgroundShade();
548 }
549 if (d == -30000)
550 {
551 backShade_->setValue(21);
552 backShade_->setText( tr("Shade"));
553 }
554 else
555 backShade_->setValue(qRound(d));
556
557 QString s;
558 QString emptyString;
559 for (int i = 0; i < cstyles.count(); ++i)
560 {
561 if (!s.isNull() && s != cstyles[i]->backgroundColor())
562 {
563 s = emptyString;
564 break;
565 }
566 s = cstyles[i]->backgroundColor();
567 }
568 if (s.isEmpty())
569 {
570 if (backColor_->itemText(backColor_->count() - 1) != "")
571 backColor_->addItem("");
572 backColor_->setCurrentIndex(backColor_->count() - 1);
573 }
574 else
575 backColor_->setCurrentText(s);
576 }
577
showLineSpacing(QList<ParagraphStyle * > & pstyles)578 void SMPStyleWidget::showLineSpacing(QList<ParagraphStyle*> &pstyles)
579 {
580 lineSpacingMode->clear();
581 lineSpacingMode->addItem( tr("Fixed Linespacing"));
582 lineSpacingMode->addItem( tr("Automatic Linespacing"));
583 lineSpacingMode->addItem( tr("Align to Baseline Grid"));
584
585 int tmpLP = -1;
586 for (int i = 0; i < pstyles.count(); ++i)
587 {
588 if (tmpLP != -1 && pstyles[i]->lineSpacingMode() != tmpLP)
589 {
590 tmpLP = -1;
591 break;
592 }
593 tmpLP = pstyles[i]->lineSpacingMode();
594 }
595
596 if (tmpLP == -1)
597 {
598 if (lineSpacingMode->itemText(lineSpacingMode->count() - 1) != "")
599 lineSpacingMode->addItem("");
600 lineSpacingMode->setCurrentIndex(lineSpacingMode->count() - 1);
601 }
602 else
603 lineSpacingMode->setCurrentIndex(tmpLP);
604
605 double tmpLS = -1.0;
606 for (int i = 0; i < pstyles.count(); ++i)
607 {
608 if (tmpLS > 0 && !isEqual(pstyles[i]->lineSpacing(), tmpLS))
609 {
610 tmpLS = -1.0;
611 break;
612 }
613 tmpLS = pstyles[i]->lineSpacing();
614 }
615 lineSpacing->setEnabled(true);
616 if (tmpLS < 0)
617 lineSpacing->clear();
618 else
619 lineSpacing->setValue(tmpLS);
620 }
621
showSpaceAB(QList<ParagraphStyle * > & pstyles,int unitIndex)622 void SMPStyleWidget::showSpaceAB(QList<ParagraphStyle*> &pstyles, int unitIndex)
623 {
624 // double unitRatio = unitGetRatioFromIndex(unitIndex);
625 double tmpA = -1.2;
626 for (int i = 0; i < pstyles.count(); ++i)
627 {
628 if (tmpA > -1.0 && !isEqual(pstyles[i]->gapBefore(), tmpA))
629 {
630 tmpA = -1.2;
631 break;
632 }
633 tmpA = pstyles[i]->gapBefore();
634 }
635
636 if (tmpA < 0)
637 spaceAbove->clear();
638 else
639 spaceAbove->setValue(tmpA);
640
641 tmpA = -1.2;
642 for (int i = 0; i < pstyles.count(); ++i)
643 {
644 if (tmpA > -1.0 && !isEqual(pstyles[i]->gapAfter(), tmpA))
645 {
646 tmpA = -1.2;
647 break;
648 }
649 }
650
651 if (tmpA < 0)
652 spaceBelow->clear();
653 else
654 spaceBelow->setValue(tmpA);
655 }
656
showDropCap(QList<ParagraphStyle * > & pstyles,QList<CharStyle> & cstyles,int unitIndex)657 void SMPStyleWidget::showDropCap(QList<ParagraphStyle*> &pstyles, QList<CharStyle> &cstyles, int unitIndex)
658 {
659 disconnectPESignals();
660 bool dc = pstyles[0]->hasDropCap();
661 for (int i = 0; i < pstyles.count(); ++i)
662 {
663 if (dc != pstyles[i]->hasDropCap())
664 {
665 dc = false;
666 break;
667 }
668 }
669 dropCapsBox->setChecked(dc);
670
671 int lines = -1;
672 for (int i = 0; i < pstyles.count(); ++i)
673 {
674 if (lines > -1 && pstyles[i]->dropCapLines() != lines)
675 {
676 lines = -1;
677 break;
678 }
679 lines = pstyles[i]->dropCapLines();
680 }
681 if (lines == -1)
682 dropCapLines->clear();
683 else
684 dropCapLines->setValue(lines);
685
686 dropCapsBox->setEnabled(true);
687 dropCapLines->setEnabled(true);
688 connectPESignals();
689 }
690
showBullet(QList<ParagraphStyle * > & pstyles,QList<CharStyle> & cstyles,int unitIndex)691 void SMPStyleWidget::showBullet(QList<ParagraphStyle *> &pstyles, QList<CharStyle> &cstyles, int unitIndex)
692 {
693 // double unitRatio = unitGetRatioFromIndex(unitIndex);
694
695 disconnectPESignals();
696 bool hb = pstyles[0]->hasBullet();
697 for (int i = 0; i < pstyles.count(); ++i)
698 {
699 if (hb != pstyles[i]->hasBullet())
700 {
701 hb = false;
702 break;
703 }
704 }
705 bulletBox->setChecked(hb);
706
707 QString chStr = pstyles[0]->bulletStr();
708 for (int i = 0; i < pstyles.count(); ++i)
709 {
710 if (chStr != pstyles[i]->bulletStr())
711 {
712 chStr.clear();
713 break;
714 }
715 chStr = pstyles[i]->bulletStr();
716 }
717 bulletStrEdit->setEditText(chStr);
718
719 connectPESignals();
720 bulletCharTableButton->setEnabled(true);
721 }
722
showNumeration(QList<ParagraphStyle * > & pstyles,QList<CharStyle> & cstyles,int unitIndex)723 void SMPStyleWidget::showNumeration(QList<ParagraphStyle *> &pstyles, QList<CharStyle> &cstyles, int unitIndex)
724 {
725 disconnectPESignals();
726 QString prefix = pstyles[0]->numPrefix();
727 for (int i = 0; i < pstyles.count(); ++i)
728 {
729 if (prefix != pstyles[i]->numPrefix())
730 {
731 prefix.clear();
732 break;
733 }
734 prefix = pstyles[i]->numPrefix();
735 }
736 numPrefix->setText(prefix);
737
738 QString suffix = pstyles[0]->numSuffix();
739 for (int i = 0; i < pstyles.count(); ++i)
740 {
741 if (suffix != pstyles[i]->numSuffix())
742 {
743 suffix.clear();
744 break;
745 }
746 suffix = pstyles[i]->numSuffix();
747 }
748 numSuffix->setText(suffix);
749
750 numFormatCombo->setEnabled(true);
751 numLevelSpin->setEnabled(true);
752 connectPESignals();
753 }
754
showAlignment(QList<ParagraphStyle * > & pstyles)755 void SMPStyleWidget::showAlignment(QList<ParagraphStyle*> &pstyles)
756 {
757 if (pstyles.isEmpty())
758 {
759 qDebug()<<"Warning showAlignment called with an empty list of styles";
760 return;
761 }
762 ParagraphStyle::AlignmentType a = pstyles[0]->alignment();
763 for (int i = 0; i < pstyles.count(); ++i)
764 {
765 if (a != pstyles[i]->alignment())
766 {
767 if (alignment->selectedId() > -1 && alignment->selectedId() < 5)
768 {
769 alignment->buttonGroup->setExclusive(false);
770 alignment->buttonGroup->button(alignment->selectedId())->toggle();
771 alignment->buttonGroup->setExclusive(true);
772 }
773 return;
774 }
775 }
776 alignment->setStyle(a, direction->getStyle());
777 }
778
showDirection(QList<ParagraphStyle * > & pstyles)779 void SMPStyleWidget::showDirection(QList<ParagraphStyle*> &pstyles)
780 {
781 if (pstyles.isEmpty())
782 {
783 qDebug()<<"Warning showDirection called with an empty list of styles";
784 return;
785 }
786 ParagraphStyle::DirectionType a = pstyles[0]->direction();
787 for (int i = 0; i < pstyles.count(); ++i)
788 {
789 if (a != pstyles[i]->direction())
790 {
791 if (direction->selectedId() > -1 && direction->selectedId() < 2)
792 {
793 direction->buttonGroup->setExclusive(false);
794 direction->buttonGroup->button(direction->selectedId())->toggle();
795 direction->buttonGroup->setExclusive(true);
796 }
797 return;
798 }
799 }
800 direction->setStyle(a);
801 }
802
showOpticalMargin(QList<ParagraphStyle * > & pstyles)803 void SMPStyleWidget::showOpticalMargin(QList< ParagraphStyle * > & pstyles)
804 {
805 if (pstyles.isEmpty())
806 {
807 qDebug()<<"Warning showOpticalMargin called with an empty list of styles";
808 return;
809 }
810
811 // optMarginCombo->clear();
812 // optMarginCombo->addItem(tr("None"), ParagraphStyle::OM_None);
813 // optMarginCombo->addItem(tr("Left Protruding"), ParagraphStyle::OM_LeftProtruding);
814 // optMarginCombo->addItem(tr("Right Protruding"), ParagraphStyle::OM_RightProtruding);
815 // optMarginCombo->addItem(tr("Left Hanging Punctuation"), ParagraphStyle::OM_LeftHangingPunct);
816 // optMarginCombo->addItem(tr("Right Hanging Punctuation"), ParagraphStyle::OM_RightHangingPunct);
817 // optMarginCombo->addItem(tr("Default"), ParagraphStyle::OM_Default);
818 //
819 // // the static cast should not be required if opticalMargins() would return OpticalMarginType. Why it does not? mystery
820 // ParagraphStyle::OpticalMarginType o( static_cast<ParagraphStyle::OpticalMarginType>(pstyles[0]->opticalMargins()) );
821 // for (int i = 0; i < pstyles.count(); ++i)
822 // {
823 // if (o != pstyles[i]->opticalMargins())
824 // {
825 // optMarginCombo->setCurrentItem(0);
826 // return;
827 // }
828 // }
829 // optMarginCombo->setCurrentItemByData(o);
830 setOpticalMargins(pstyles[0]->opticalMargins());
831 }
832
showMinSpace(QList<ParagraphStyle * > & pstyles)833 void SMPStyleWidget::showMinSpace(QList< ParagraphStyle * > & pstyles)
834 {
835 if (pstyles.isEmpty())
836 {
837 qDebug()<<"Warning showMinSpace called with an empty list of styles";
838 return;
839 }
840
841 double ms(pstyles[0]->minWordTracking());
842 for (int i = 0; i < pstyles.count(); ++i)
843 {
844 if (ms != pstyles[i]->minWordTracking())
845 {
846 minSpaceSpin->setValue(100.0);
847 return;
848 }
849 }
850 minSpaceSpin->setValue(ms * 100.0);
851 }
852
showMinGlyphExt(QList<ParagraphStyle * > & pstyles)853 void SMPStyleWidget::showMinGlyphExt(QList< ParagraphStyle * > & pstyles)
854 {
855 if (pstyles.isEmpty())
856 {
857 qDebug()<<"Warning showMinGlyphExt called with an empty list of styles";
858 return;
859 }
860
861 double mge(pstyles[0]->minGlyphExtension());
862 for (int i = 0; i < pstyles.count(); ++i)
863 {
864 if (mge != pstyles[i]->minGlyphExtension())
865 {
866 minGlyphExtSpin->setValue(100.0);
867 return;
868 }
869 }
870 minGlyphExtSpin->setValue(mge * 100.0);
871 }
872
showMaxGlyphExt(QList<ParagraphStyle * > & pstyles)873 void SMPStyleWidget::showMaxGlyphExt(QList< ParagraphStyle * > & pstyles)
874 {
875 if (pstyles.isEmpty())
876 {
877 qDebug()<<"Warning showMaxGlyphExt called with an empty list of styles";
878 return;
879 }
880
881 double mge(pstyles[0]->maxGlyphExtension());
882 for (int i = 0; i < pstyles.count(); ++i)
883 {
884 if (mge != pstyles[i]->maxGlyphExtension())
885 {
886 maxGlyphExtSpin->setValue(100.0);
887 return;
888 }
889 }
890 maxGlyphExtSpin->setValue(mge * 100.0);
891 }
892
showConsecutiveLines(QList<ParagraphStyle * > & pstyles)893 void SMPStyleWidget::showConsecutiveLines(QList<ParagraphStyle *> &pstyles)
894 {
895
896 if (pstyles.isEmpty())
897 {
898 qDebug()<<"Warning showConsecutiveLines called with an empty list of styles";
899 return;
900 }
901
902 double hyphenConsecutiveLines(pstyles[0]->hyphenConsecutiveLines());
903 for (int i = 0; i < pstyles.count(); ++i)
904 {
905 if (hyphenConsecutiveLines != pstyles[i]->hyphenConsecutiveLines())
906 {
907 maxConsecutiveCountSpinBox->setValue(0);
908 break;
909 }
910 }
911 maxConsecutiveCountSpinBox->setValue(hyphenConsecutiveLines);
912
913 }
914
915
showTabs(QList<ParagraphStyle * > & pstyles,int unitIndex)916 void SMPStyleWidget::showTabs(QList<ParagraphStyle*> &pstyles, int unitIndex)
917 {
918 double unitRatio = unitGetRatioFromIndex(unitIndex);
919 QList<ParagraphStyle::TabRecord> t = pstyles[0]->tabValues();
920 for (int i = 0; i < pstyles.count(); ++i)
921 {
922 if (t != pstyles[i]->tabValues())
923 {
924 t = QList<ParagraphStyle::TabRecord>();
925 break;
926 }
927 }
928 tabList->setTabs(t, unitIndex);
929
930 double l = -4000.0;
931 for (int i = 0; i < pstyles.count(); ++i)
932 {
933 if (l > -3800.0 && !isEqual(pstyles[i]->leftMargin(), l))
934 {
935 l = -4000.0;
936 break;
937 }
938 l = pstyles[i]->leftMargin();
939 }
940 if (l < -3800.0)
941 {
942 tabList->setLeftIndentValue(0.0);
943 tabList->leftIndentSpin->clear();
944 }
945 else
946 tabList->setLeftIndentValue(l * unitRatio);
947
948 l = -4000.0;
949 for (int i = 0; i < pstyles.count(); ++i)
950 {
951 if (l > -3800.0 && !isEqual(pstyles[i]->firstIndent(), l))
952 {
953 l = -4000.0;
954 break;
955 }
956 l = pstyles[i]->firstIndent();
957 }
958 if (l < -3800.0)
959 {
960 tabList->setFirstLineValue(0.0);
961 tabList->firstLineSpin->clear();
962 }
963 else
964 tabList->setFirstLineValue(l * unitRatio);
965
966 l = -4000.0;
967 for (int i = 0; i < pstyles.count(); ++i)
968 {
969 if (l > -3800.0 && !isEqual(pstyles[i]->rightMargin(), l))
970 {
971 l = -4000.0;
972 break;
973 }
974 l = pstyles[i]->rightMargin();
975 }
976 if (l < -3800.0)
977 {
978 tabList->setRightIndentData(0.0);
979 tabList->rightIndentSpin->clear();
980 }
981 else
982 tabList->setRightIndentValue(l * unitRatio);
983
984 }
985
showCStyle(QList<ParagraphStyle * > & pstyles,QList<CharStyle> & cstyles,const QString & defLang,int unitIndex)986 void SMPStyleWidget::showCStyle(QList<ParagraphStyle*> &pstyles, QList<CharStyle> &cstyles, const QString &defLang, int unitIndex)
987 {
988 cpage->parentLabel->setText( tr("Based On:"));
989
990 QList<CharStyle*> cstyle;
991 for (int i = 0; i < pstyles.count(); ++i)
992 cstyle << &pstyles[i]->charStyle();
993
994 cpage->show(cstyle, cstyles, defLang, unitIndex);
995 }
996
showParent(QList<ParagraphStyle * > & pstyles)997 void SMPStyleWidget::showParent(QList<ParagraphStyle*> &pstyles)
998 {
999 parentCombo->setEnabled(false);
1000
1001 // parentCombo->clear();
1002 // parentCombo->insertItem("");
1003 // for (uint i = 0; i < pstyles.count(); ++i)
1004 // {
1005 // if (pstyles[i].hasName() && pstyles[i].name() != pstyle->name())
1006 // parentCombo->insertItem(pstyles[i].name());
1007 // }
1008 //
1009 // if (hasParent_)
1010 // {
1011 // int index = 0;
1012 // for (int i = 0; i < parentCombo->count(); ++i)
1013 // {
1014 // if (parentCombo->text(i) == parent->name())
1015 // {
1016 // index = i;
1017 // break;
1018 // }
1019 // }
1020 // parentCombo->setCurrentItem(index);
1021 // }
1022 // else
1023 // parentCombo->setCurrentItem(0);
1024 }
1025
setOpticalMargins(int o,bool inhO,const ParagraphStyle * parent)1026 void SMPStyleWidget::setOpticalMargins(int o, bool inhO, const ParagraphStyle *parent)
1027 {
1028 ParagraphStyle::OpticalMarginType om( static_cast<ParagraphStyle::OpticalMarginType>(o) );
1029
1030 if (parent==nullptr)
1031 {
1032 if (om == ParagraphStyle::OM_Default)
1033 optMarginRadioBoth->setChecked(true);
1034 else if (om == ParagraphStyle::OM_LeftHangingPunct)
1035 optMarginRadioLeft->setChecked(true);
1036 else if (om == ParagraphStyle::OM_RightHangingPunct)
1037 optMarginRadioRight->setChecked(true);
1038 else
1039 optMarginRadioNone->setChecked(true);
1040 }
1041 else
1042 {
1043 optMarginParentButton->setVisible(!inhO);
1044
1045 if (om == ParagraphStyle::OM_Default)
1046 optMarginRadioBoth->setChecked(true,
1047 (parent->opticalMargins() == ParagraphStyle::OM_Default));
1048 else if (om == ParagraphStyle::OM_LeftHangingPunct)
1049 optMarginRadioLeft->setChecked(true,
1050 (parent->opticalMargins() == ParagraphStyle::OM_LeftHangingPunct));
1051 else if (om == ParagraphStyle::OM_RightHangingPunct)
1052 optMarginRadioRight->setChecked(true,
1053 (parent->opticalMargins() == ParagraphStyle::OM_RightHangingPunct));
1054 else
1055 optMarginRadioNone->setChecked(true,
1056 (parent->opticalMargins() == ParagraphStyle::OM_None));
1057
1058 optMarginRadioBoth->setParentValue(parent->opticalMargins() == ParagraphStyle::OM_Default);
1059 optMarginRadioLeft->setParentValue(parent->opticalMargins() == ParagraphStyle::OM_LeftHangingPunct);
1060 optMarginRadioRight->setParentValue(parent->opticalMargins() == ParagraphStyle::OM_RightHangingPunct);
1061 optMarginRadioNone->setParentValue(parent->opticalMargins() == ParagraphStyle::OM_None);
1062 }
1063 }
1064
1065
slotDefaultOpticalMargins()1066 void SMPStyleWidget::slotDefaultOpticalMargins()
1067 {
1068 optMarginRadioNone->setChecked(true);
1069 if (m_hasParent)
1070 optMarginParentButton->show();
1071 }
1072
slotParentOpticalMargins()1073 void SMPStyleWidget::slotParentOpticalMargins()
1074 {
1075 disconnect(optMarginParentButton, SIGNAL(clicked()), this, SLOT(slotParentOpticalMargins()));
1076 optMarginParentButton->hide();
1077 emit useParentOptMargins();
1078 connect(optMarginParentButton, SIGNAL(clicked()), this, SLOT(slotParentOpticalMargins()));
1079 }
1080
clearAll()1081 void SMPStyleWidget::clearAll()
1082 {
1083
1084 }
1085
slotDropCap(bool isOn)1086 void SMPStyleWidget::slotDropCap(bool isOn)
1087 {
1088 disconnectPESignals();
1089 if (isOn)
1090 {
1091 dropCapLines->setEnabled(true);
1092
1093 bulletBox->setChecked(false);
1094 bulletStrEdit->setEnabled(false);
1095 bulletCharTableButton->setEnabled(false);
1096
1097 numBox->setChecked(false);
1098 numFormatCombo->setEnabled(false);
1099 numLevelSpin->setEnabled(false);
1100 numComboBox->setEnabled(false);
1101 numRestartCombo->setEnabled(false);
1102 numNewLineEdit->setEnabled(false);
1103 }
1104 else
1105 dropCapLines->setEnabled(false);
1106 if (m_hasParent)
1107 parentParEffectsButton->show();
1108 checkParEffectState();
1109 connectPESignals();
1110 }
1111
slotBullets(bool isOn)1112 void SMPStyleWidget::slotBullets(bool isOn)
1113 {
1114 disconnectPESignals();
1115 if (isOn)
1116 {
1117 bulletStrEdit->setEnabled(true);
1118 if (bulletStrEdit->currentText().isEmpty())
1119 bulletStrEdit->setEditText(bulletStrEdit->itemText(0));
1120 bulletCharTableButton->setEnabled(true);
1121
1122 numBox->setChecked(false);
1123 numFormatCombo->setEnabled(false);
1124 numLevelSpin->setEnabled(false);
1125 numComboBox->setEnabled(false);
1126 numRestartCombo->setEnabled(false);
1127 numNewLineEdit->setEnabled(false);
1128
1129 dropCapsBox->setChecked(false);
1130 dropCapLines->setEnabled(false);
1131 }
1132 else
1133 {
1134 bulletStrEdit->setEnabled(false);
1135 bulletCharTableButton->setEnabled(false);
1136 }
1137 if (m_hasParent)
1138 parentParEffectsButton->show();
1139 checkParEffectState();
1140 connectPESignals();
1141 }
1142
insertSpecialChars(const QVector<uint> & charCodes)1143 void SMPStyleWidget::insertSpecialChars(const QVector<uint> &charCodes)
1144 {
1145 QString chars = QString::fromUcs4(charCodes.data(), charCodes.length());
1146 bulletStrEdit->lineEdit()->setText(chars);
1147 }
1148
slotNumbering(bool isOn)1149 void SMPStyleWidget::slotNumbering(bool isOn)
1150 {
1151 disconnectPESignals();
1152 if (isOn)
1153 {
1154 numFormatCombo->setEnabled(true);
1155 numLevelSpin->setEnabled(true);
1156 numComboBox->setEnabled(true);
1157 if (numComboBox->currentIndex() < 0)
1158 numComboBox->setCurrentIndex(0);
1159 numRestartCombo->setEnabled(true);
1160 numNewLineEdit->setEnabled(true);
1161
1162 bulletBox->setChecked(false);
1163 bulletStrEdit->setEnabled(false);
1164 bulletCharTableButton->setEnabled(false);
1165
1166 dropCapsBox->setChecked(false);
1167 dropCapLines->setEnabled(false);
1168 }
1169 else
1170 {
1171 numFormatCombo->setEnabled(false);
1172 numLevelSpin->setEnabled(false);
1173 }
1174 if (m_hasParent)
1175 parentParEffectsButton->show();
1176 checkParEffectState();
1177 connectPESignals();
1178 }
1179
slotParentParEffects()1180 void SMPStyleWidget::slotParentParEffects()
1181 {
1182 disconnectPESignals();
1183 parentParEffectsButton->hide();
1184 dropCapsBox->setChecked(m_parentDC);
1185 bulletBox->setChecked(m_parentBul);
1186 numBox->setChecked(m_parentNum);
1187 emit useParentParaEffects();
1188 connectPESignals();
1189 }
1190
~SMPStyleWidget()1191 SMPStyleWidget::~SMPStyleWidget()
1192 {
1193
1194 }
1195
openEnhanced()1196 void SMPStyleWidget::openEnhanced()
1197 {
1198 if (m_enhanced)
1199 return;
1200
1201 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
1202 m_enhanced = new CharSelectEnhanced(this);
1203 m_enhanced->setModal(true);
1204 connect(m_enhanced, SIGNAL(insertSpecialChars(const QVector<uint> &)), this, SLOT(insertSpecialChars(const QVector<uint> &)));
1205 connect(m_enhanced, SIGNAL(paletteShown(bool)), bulletCharTableButton, SLOT(setChecked(bool)));
1206 m_enhanced->setDoc(m_Doc);
1207 m_enhanced->setEnabled(true);
1208 QString styleName = parEffectCharStyleCombo->currentText();
1209 if (styleName != tr("No Style") && !styleName.isEmpty())
1210 {
1211 CharStyle chStyle = m_cstyles->get(styleName);
1212 setCurrentComboItem(m_enhanced->fontSelector, chStyle.font().scName());
1213 }
1214 else if (m_currPStyle)
1215 setCurrentComboItem(m_enhanced->fontSelector, m_currPStyle->charStyle().font().scName());
1216 m_enhanced->newFont(m_enhanced->fontSelector->currentIndex());
1217 m_enhanced->show();
1218 QApplication::restoreOverrideCursor();
1219 }
1220
closeEnhanced(bool show)1221 void SMPStyleWidget::closeEnhanced(bool show)
1222 {
1223 if (!m_enhanced || show)
1224 return;
1225 disconnect(m_enhanced, SIGNAL(insertSpecialChars(const QVector<uint> &)), this, SLOT(insertSpecialChars(const QVector<uint> &)));
1226 disconnect(m_enhanced, SIGNAL(paletteShown(bool)), bulletCharTableButton, SLOT(setChecked(bool)));
1227 m_enhanced->close();
1228 m_enhanced->deleteLater();
1229 m_enhanced = nullptr;
1230 }
1231
connectPESignals()1232 void SMPStyleWidget::connectPESignals()
1233 {
1234 connect(parentParEffectsButton, SIGNAL(clicked()), this, SLOT(slotParentParEffects()));
1235 connect(bulletBox, SIGNAL(toggled(bool)), this, SLOT(slotBullets(bool)));
1236 connect(numBox, SIGNAL(toggled(bool)), this, SLOT(slotNumbering(bool)));
1237 connect(dropCapsBox, SIGNAL(toggled(bool)), this, SLOT(slotDropCap(bool)));
1238 }
1239
disconnectPESignals()1240 void SMPStyleWidget::disconnectPESignals()
1241 {
1242 disconnect(parentParEffectsButton, SIGNAL(clicked()), this, SLOT(slotParentParEffects()));
1243 disconnect(bulletBox, SIGNAL(toggled(bool)), this, SLOT(slotBullets(bool)));
1244 disconnect(numBox, SIGNAL(toggled(bool)), this, SLOT(slotNumbering(bool)));
1245 disconnect(dropCapsBox, SIGNAL(toggled(bool)), this, SLOT(slotDropCap(bool)));
1246 }
1247
on_bulletCharTableButton_toggled(bool checked)1248 void SMPStyleWidget::on_bulletCharTableButton_toggled(bool checked)
1249 {
1250 if (m_enhanced && !checked)
1251 closeEnhanced();
1252 else if (!m_enhanced && checked)
1253 openEnhanced();
1254 }
1255
handleUpdateRequest(int updateFlags)1256 void SMPStyleWidget::handleUpdateRequest(int updateFlags)
1257 {
1258 if (!m_Doc)
1259 return;
1260 if (updateFlags & reqColorsUpdate)
1261 fillColorCombo(m_Doc->PageColors);
1262 if (updateFlags & reqNumUpdate)
1263 fillNumerationsCombo();
1264 }
1265