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 #include <QToolTip>
10
11 #include "smlinestylewidget.h"
12 #include "colorcombo.h"
13 #include "iconmanager.h"
14 #include "linecombo.h"
15 #include "sccolorengine.h"
16 #include "scribusapp.h"
17 #include "scrspinbox.h"
18 #include "util_color.h"
19 #include "util.h"
20
21
SMLineStyleWidget()22 SMLineStyleWidget::SMLineStyleWidget()
23 {
24 setupUi(this);
25
26 colorCombo->setPixmapType(ColorCombo::fancyPixmaps);
27
28 addButton->setIcon(IconManager::instance().loadIcon("penciladd.png"));
29 removeButton->setIcon(IconManager::instance().loadIcon("pencilsub.png"));
30
31 lineWidth->setMinimum(0.0);
32 lineWidth->setMaximum(300.0);
33
34 fillEndCombo();
35 fillJoinCombo();
36
37 languageChange();
38
39 connect(ScQApp, SIGNAL(iconSetChanged()), this, SLOT(iconSetChange()));
40 }
41
changeEvent(QEvent * e)42 void SMLineStyleWidget::changeEvent(QEvent *e)
43 {
44 if (e->type() == QEvent::LanguageChange)
45 {
46 languageChange();
47 }
48 }
49
iconSetChange()50 void SMLineStyleWidget::iconSetChange()
51 {
52 IconManager& iconManager = IconManager::instance();
53
54 addButton->setIcon(iconManager.loadIcon("penciladd.png"));
55 removeButton->setIcon(iconManager.loadIcon("pencilsub.png"));
56
57 int oldEndComboIndex = endCombo->currentIndex();
58 bool endComboBlocked = endCombo->blockSignals(true);
59
60 int oldJoinComboIndex = joinCombo->currentIndex();
61 bool joinComboBlocked = joinCombo->blockSignals(true);
62
63 fillEndCombo();
64 fillJoinCombo();
65
66 endCombo->setCurrentIndex(oldEndComboIndex);
67 endCombo->blockSignals(endComboBlocked);
68
69 joinCombo->setCurrentIndex(oldJoinComboIndex);
70 joinCombo->blockSignals(joinComboBlocked);
71 }
72
languageChange()73 void SMLineStyleWidget::languageChange()
74 {
75 int oldEndComboIndex = endCombo->currentIndex();
76 bool endComboBlocked = endCombo->blockSignals(true);
77
78 int oldJoinComboIndex = joinCombo->currentIndex();
79 bool joinComboBlocked = joinCombo->blockSignals(true);
80
81 int oldLineListRow = lineStyles->currentRow();
82 bool lineListBlocked = lineStyles->blockSignals(true);
83
84 retranslateUi(this);
85 fillEndCombo();
86 fillJoinCombo();
87 updateLineList();
88
89 endCombo->setCurrentIndex(oldEndComboIndex);
90 endCombo->blockSignals(endComboBlocked);
91
92 joinCombo->setCurrentIndex(oldJoinComboIndex);
93 joinCombo->blockSignals(joinComboBlocked);
94
95 if (oldLineListRow >= 0)
96 lineStyles->setCurrentRow(oldLineListRow);
97 lineStyles->blockSignals(lineListBlocked);
98 }
99
100
unitChange(int unitIndex)101 void SMLineStyleWidget::unitChange(int unitIndex)
102 {
103 lineWidth->setNewUnit(unitIndex);
104 }
105
fillEndCombo()106 void SMLineStyleWidget::fillEndCombo()
107 {
108 IconManager& im = IconManager::instance();
109
110 endCombo->clear();
111 endCombo->addItem(im.loadIcon("ButtCap.png"), tr( "Flat Cap" ) );
112 endCombo->addItem(im.loadIcon("SquareCap.png"), tr( "Square Cap" ) );
113 endCombo->addItem(im.loadIcon("RoundCap.png"), tr( "Round Cap" ) );
114 }
115
fillJoinCombo()116 void SMLineStyleWidget::fillJoinCombo()
117 {
118 IconManager& im = IconManager::instance();
119
120 joinCombo->clear();
121 joinCombo->addItem(im.loadIcon("MiterJoin.png"), tr( "Miter Join" ) );
122 joinCombo->addItem(im.loadIcon("BevelJoin.png"), tr( "Bevel Join" ) );
123 joinCombo->addItem(im.loadIcon("RoundJoin.png"), tr( "Round Join" ) );
124 }
125
showStyle(const multiLine & lineStyle,ColorList & colorList,int subLine)126 void SMLineStyleWidget::showStyle(const multiLine &lineStyle, ColorList &colorList, int subLine)
127 {
128 // disconnect(lineStyles, SIGNAL(highlighted(int)), this, SLOT(slotEditNewLine(int)));
129 disconnect(lineStyles, SIGNAL(currentRowChanged(int)), this, SLOT(slotEditNewLine(int)));
130 m_currentStyle = lineStyle;
131 colorCombo->setColors(colorList, false);
132 m_colors = colorList;
133 updateLineList();
134 slotEditNewLine(subLine);
135 connect(lineStyles, SIGNAL(currentRowChanged(int)), this, SLOT(slotEditNewLine(int)));
136 }
137
slotEditNewLine(int i)138 void SMLineStyleWidget::slotEditNewLine(int i)
139 {
140 lineStyles->setCurrentRow(i);
141 // lineStyles->setSelected(i, true);
142 //currentLine_ = i;
143
144 // JG #5876 protect against broken line styles
145 // JG #6099 no current item selected
146 if (m_currentStyle.count() <= i || (i < 0))
147 return;
148
149 double unitRatio = lineWidth->unitRatio();
150
151 lineWidth->setValue(m_currentStyle[i].Width * unitRatio);
152 setCurrentComboItem(colorCombo, m_currentStyle[i].Color);
153 shadeBox->setValue(m_currentStyle[i].Shade);
154
155 dashCombo->setCurrentIndex(m_currentStyle[i].Dash - 1);
156 switch (static_cast<Qt::PenCapStyle>(m_currentStyle[i].LineEnd))
157 {
158 case Qt::FlatCap:
159 endCombo->setCurrentIndex(0);
160 break;
161 case Qt::SquareCap:
162 endCombo->setCurrentIndex(1);
163 break;
164 case Qt::RoundCap:
165 endCombo->setCurrentIndex(2);
166 break;
167 default:
168 endCombo->setCurrentIndex(0);
169 break;
170 }
171
172 switch (static_cast<Qt::PenJoinStyle>(m_currentStyle[i].LineJoin))
173 {
174 case Qt::MiterJoin:
175 joinCombo->setCurrentIndex(0);
176 break;
177 case Qt::BevelJoin:
178 joinCombo->setCurrentIndex(1);
179 break;
180 case Qt::RoundJoin:
181 joinCombo->setCurrentIndex(2);
182 break;
183 default:
184 joinCombo->setCurrentIndex(0);
185 break;
186 }
187 }
188
updateLineList()189 void SMLineStyleWidget::updateLineList()
190 {
191 QString tmp, tmp2;
192 lineStyles->clear();
193 QPixmap * pm2;
194 double unitRatio = lineWidth->unitRatio();
195 int decimals = lineWidth->decimals();
196 for (multiLine::iterator it = m_currentStyle.begin(); it != m_currentStyle.end(); ++it)
197 {
198 pm2 = getWidePixmap(getColor(it->Color, it->Shade));
199 tmp2 = " "+ tmp.setNum(it->Width * unitRatio, 'f', decimals) + lineWidth->suffix() + " ";
200 if (it->Dash < 6)
201 tmp2 += CommonStrings::translatePenStyleName(static_cast<Qt::PenStyle>(it->Dash)) + " ";
202 lineStyles->addItem(new QListWidgetItem(*pm2, tmp2, lineStyles));
203 }
204 }
205
getColor(const QString & name,int shade)206 QColor SMLineStyleWidget::getColor(const QString &name, int shade)
207 {
208 const ScColor& color = m_colors[name];
209 QColor tmpf = ScColorEngine::getDisplayColor(color, m_colors.document(), shade);
210 return tmpf;
211 }
212
~SMLineStyleWidget()213 SMLineStyleWidget::~SMLineStyleWidget()
214 {
215
216 }
217