1 /*
2 Copyright (C) 2011 Elvis Stansvik <elvstone@gmail.com>
3
4 For general Scribus (>=1.3.2) copyright and licensing information please refer
5 to the COPYING file provided with the program. Following this notice may exist
6 a copyright and/or license notice that predates the release of Scribus 1.3.2
7 for which a new license (GPL+exception) is in place.
8 */
9
10 #include "iconmanager.h"
11 #include "scribus.h"
12 #include "scribusapp.h"
13 #include "smtablestylewidget.h"
14
SMTableStyleWidget(QWidget * parent)15 SMTableStyleWidget::SMTableStyleWidget(QWidget *parent)
16 {
17 setupUi(this);
18
19 fillColor->setPixmapType(ColorCombo::fancyPixmaps);
20 fillColor->addItem(CommonStrings::tr_NoneColor);
21
22 iconSetChange();
23
24 connect(ScQApp, SIGNAL(iconSetChanged()), this, SLOT(iconSetChange()));
25 }
26
~SMTableStyleWidget()27 SMTableStyleWidget::~SMTableStyleWidget()
28 {
29 }
30
changeEvent(QEvent * e)31 void SMTableStyleWidget::changeEvent(QEvent *e)
32 {
33 if (e->type() == QEvent::LanguageChange)
34 languageChange();
35 else
36 QWidget::changeEvent(e);
37 }
38
iconSetChange()39 void SMTableStyleWidget::iconSetChange()
40 {
41 fillColorIcon->setPixmap(IconManager::instance().loadPixmap("16/color-fill.png"));
42 fillShadeLabel->setPixmap(IconManager::instance().loadPixmap("shade.png") );
43 }
44
handleUpdateRequest(int updateFlags)45 void SMTableStyleWidget::handleUpdateRequest(int updateFlags)
46 {
47 if (!m_Doc)
48 return;
49 if (updateFlags & reqColorsUpdate)
50 fillFillColorCombo(m_Doc->PageColors);
51 }
52
setDoc(ScribusDoc * doc)53 void SMTableStyleWidget::setDoc(ScribusDoc* doc)
54 {
55 if (m_Doc)
56 disconnect(m_Doc->scMW(), SIGNAL(UpdateRequest(int)), this , SLOT(handleUpdateRequest(int)));
57
58 m_Doc = doc;
59 if (!m_Doc)
60 return;
61
62 fillFillColorCombo(m_Doc->PageColors);
63 connect(m_Doc->scMW(), SIGNAL(UpdateRequest(int)), this , SLOT(handleUpdateRequest(int)));
64 }
65
show(TableStyle * tableStyle,QList<TableStyle> & tableStyles,const QString & defLang,int unitIndex)66 void SMTableStyleWidget::show(TableStyle *tableStyle, QList<TableStyle> &tableStyles, const QString &defLang, int unitIndex)
67 {
68 Q_ASSERT(tableStyle);
69 if (!tableStyle)
70 return;
71 parentCombo->setEnabled(!tableStyle->isDefaultStyle());
72 const TableStyle *parent = dynamic_cast<const TableStyle*>(tableStyle->parentStyle());
73 bool hasParent = tableStyle->hasParent() && parent != nullptr && parent->hasName() && tableStyle->parent() != "";
74 if (hasParent)
75 {
76 fillColor->setCurrentText(tableStyle->fillColor(), tableStyle->isInhFillColor());
77 fillColor->setParentText(parent->fillColor());
78 fillShade->setValue(qRound(tableStyle->fillShade()), tableStyle->isInhFillShade());
79 fillShade->setParentValue(qRound(parent->fillShade()));
80 }
81 else
82 {
83 fillColor->setCurrentText(tableStyle->fillColor());
84 fillShade->setValue(qRound(tableStyle->fillShade()));
85 }
86 parentCombo->clear();
87 parentCombo->addItem( tableStyle->isDefaultStyle()? tr("A default style cannot be assigned a parent style") : "");
88 if (!tableStyle->isDefaultStyle())
89 {
90 for (int i = 0; i < tableStyles.count(); ++i)
91 {
92 if (tableStyles[i].name() != tableStyle->name())
93 parentCombo->addItem(tableStyles[i].name());
94 }
95 }
96
97 if (tableStyle->isDefaultStyle() || !hasParent)
98 parentCombo->setCurrentIndex(0);
99 else if (hasParent)
100 {
101 int index = 0;
102 for (int i = 0; i < parentCombo->count(); ++i)
103 {
104 if (parentCombo->itemText(i) == tableStyle->parentStyle()->name())
105 {
106 index = i;
107 break;
108 }
109 }
110 parentCombo->setCurrentIndex(index);
111 }
112 }
113
show(QList<TableStyle * > & tableStyles,QList<TableStyle> & tableStylesAll,const QString & defaultLanguage,int unitIndex)114 void SMTableStyleWidget::show(QList<TableStyle*> &tableStyles, QList<TableStyle> &tableStylesAll, const QString &defaultLanguage, int unitIndex)
115 {
116 if (tableStyles.count() == 1)
117 show(tableStyles[0], tableStylesAll, defaultLanguage, unitIndex);
118 else if (tableStyles.count() > 1)
119 {
120 showColors(tableStyles);
121 parentCombo->setEnabled(false);
122 }
123 }
124
showColors(const QList<TableStyle * > & tableStyles)125 void SMTableStyleWidget::showColors(const QList<TableStyle*> &tableStyles)
126 {
127 double d = -30000;
128 for (int i = 0; i < tableStyles.count(); ++i)
129 {
130 if (d != -30000 && tableStyles[i]->fillShade() != d)
131 {
132 d = -30000;
133 break;
134 }
135 d = tableStyles[i]->fillShade();
136 }
137 if (d == -30000)
138 fillShade->setText( tr("Shade"));
139 else
140 fillShade->setValue(qRound(d));
141 QString s;
142 QString emptyString;
143 for (int i = 0; i < tableStyles.count(); ++i)
144 {
145 if (!s.isNull() && s != tableStyles[i]->fillColor())
146 {
147 s = emptyString;
148 break;
149 }
150 s = tableStyles[i]->fillColor();
151 }
152 if (s.isEmpty())
153 {
154 if (fillColor->itemText(fillColor->count() - 1) != "")
155 fillColor->addItem("");
156 fillColor->setCurrentIndex(fillColor->count() - 1);
157 }
158 else
159 fillColor->setCurrentText(s);
160 }
161
languageChange()162 void SMTableStyleWidget::languageChange()
163 {
164 retranslateUi(this);
165
166 if (fillColor->count() > 0)
167 {
168 bool fillColorBlocked = fillColor->blockSignals(true);
169 fillColor->setItemText(0, CommonStrings::tr_NoneColor);
170 fillColor->blockSignals(fillColorBlocked);
171 }
172 }
173
fillFillColorCombo(ColorList & colors)174 void SMTableStyleWidget::fillFillColorCombo(ColorList &colors)
175 {
176 fillColor->clear();
177
178 fillColor->setColors(colors, true);
179 fillColor->view()->setMinimumWidth(fillColor->view()->maximumViewportSize().width()+24);
180 }
181
182
183