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 "propertywidget_advanced.h"
9
10 #include "appmodes.h"
11 #include "iconmanager.h"
12 #include "localemgr.h"
13 #include "pageitem_table.h"
14 #include "scribus.h"
15 #include "scribusapp.h"
16 #include "scribusdoc.h"
17 #include "selection.h"
18
PropertyWidget_Advanced(QWidget * parent)19 PropertyWidget_Advanced::PropertyWidget_Advanced(QWidget* parent) : QFrame(parent)
20 {
21 setupUi(this);
22
23 layout()->setAlignment(Qt::AlignLeft);
24
25 textBase->setValue(0);
26
27 scaleH->setValues(10, 400, 2, 100);
28 scaleV->setValues(10, 400, 2, 100);
29
30 minWordTrackingLabel->setBuddy(minWordTrackingSpinBox);
31 normWordTrackingLabel->setBuddy(normWordTrackingSpinBox);
32
33 minGlyphExtensionLabel->setBuddy(minGlyphExtSpinBox);
34 maxGlyphExtensionLabel->setBuddy(maxGlyphExtSpinBox);
35
36 iconSetChange();
37 languageChange();
38
39 connect(ScQApp, SIGNAL(iconSetChanged()), this, SLOT(iconSetChange()));
40 connect(ScQApp, SIGNAL(localeChanged()), this, SLOT(localeChange()));
41 }
42
setMainWindow(ScribusMainWindow * mw)43 void PropertyWidget_Advanced::setMainWindow(ScribusMainWindow *mw)
44 {
45 m_ScMW = mw;
46 }
47
setDoc(ScribusDoc * d)48 void PropertyWidget_Advanced::setDoc(ScribusDoc *d)
49 {
50 if((d == (ScribusDoc*) m_doc) || (m_ScMW && m_ScMW->scriptIsRunning()))
51 return;
52
53 if (m_doc)
54 {
55 disconnect(m_doc->m_Selection, SIGNAL(selectionChanged()), this, SLOT(handleSelectionChanged()));
56 disconnect(m_doc , SIGNAL(docChanged()) , this, SLOT(handleSelectionChanged()));
57 }
58
59 m_doc = d;
60 m_item = nullptr;
61
62 if (m_doc.isNull())
63 {
64 disconnectSignals();
65 return;
66 }
67
68 m_unitRatio = m_doc->unitRatio();
69 m_unitIndex = m_doc->unitIndex();
70
71 tracking->setValues( -300, 300, 2, 0);
72 minWordTrackingSpinBox->setValues(1, 100, 2, 100);
73 normWordTrackingSpinBox->setValues(1, 2000, 2, 100);
74 minGlyphExtSpinBox->setValues(90, 110, 2, 100);
75 maxGlyphExtSpinBox->setValues(90, 110, 2, 100);
76
77 connect(m_doc->m_Selection, SIGNAL(selectionChanged()), this, SLOT(handleSelectionChanged()));
78 connect(m_doc , SIGNAL(docChanged()) , this, SLOT(handleSelectionChanged()));
79 }
80
setCurrentItem(PageItem * item)81 void PropertyWidget_Advanced::setCurrentItem(PageItem *item)
82 {
83 if (!m_ScMW || m_ScMW->scriptIsRunning())
84 return;
85 //CB We shouldn't really need to process this if our item is the same one
86 //maybe we do if the item has been changed by scripter.. but that should probably
87 //set some status if so.
88 //FIXME: This won't work until when a canvas deselect happens, m_item must be nullptr.
89 //if (m_item == i)
90 // return;
91
92 if (item && m_doc.isNull())
93 setDoc(item->doc());
94
95 m_item = item;
96
97 disconnectSignals();
98 configureWidgets();
99
100 if (m_item)
101 {
102 if (m_item->isTextFrame() || m_item->isPathText() || m_item->isTable())
103 {
104 ParagraphStyle parStyle = m_item->itemText.defaultStyle();
105 if (m_doc->appMode == modeEdit || m_doc->appMode == modeEditTable)
106 m_item->currentTextProps(parStyle);
107 updateStyle(parStyle);
108 }
109 connectSignals();
110 }
111 }
112
connectSignals()113 void PropertyWidget_Advanced::connectSignals()
114 {
115 connect(textBase, SIGNAL(valueChanged(double)), this, SLOT(handleBaselineOffset()));
116 connect(tracking, SIGNAL(valueChanged(double)), this, SLOT(handleTracking()));
117 connect(scaleH , SIGNAL(valueChanged(double)), this, SLOT(handleTextScaleH()));
118 connect(scaleV , SIGNAL(valueChanged(double)), this, SLOT(handleTextScaleV()));
119 connect(minWordTrackingSpinBox , SIGNAL(valueChanged(double)), this, SLOT(handleMinWordTracking()) );
120 connect(normWordTrackingSpinBox, SIGNAL(valueChanged(double)), this, SLOT(handleNormWordTracking()) );
121 connect(minGlyphExtSpinBox , SIGNAL(valueChanged(double)), this, SLOT(handleMinGlyphExtension()) );
122 connect(maxGlyphExtSpinBox , SIGNAL(valueChanged(double)), this, SLOT(handleMaxGlyphExtension()) );
123 }
124
disconnectSignals()125 void PropertyWidget_Advanced::disconnectSignals()
126 {
127 disconnect(textBase, SIGNAL(valueChanged(double)), this, SLOT(handleBaselineOffset()));
128 disconnect(tracking, SIGNAL(valueChanged(double)), this, SLOT(handleTracking()));
129 disconnect(scaleH , SIGNAL(valueChanged(double)), this, SLOT(handleTextScaleH()));
130 disconnect(scaleV , SIGNAL(valueChanged(double)), this, SLOT(handleTextScaleV()));
131 disconnect(minWordTrackingSpinBox , SIGNAL(valueChanged(double)), this, SLOT(handleMinWordTracking()) );
132 disconnect(normWordTrackingSpinBox, SIGNAL(valueChanged(double)), this, SLOT(handleNormWordTracking()) );
133 disconnect(minGlyphExtSpinBox , SIGNAL(valueChanged(double)), this, SLOT(handleMinGlyphExtension()) );
134 disconnect(maxGlyphExtSpinBox , SIGNAL(valueChanged(double)), this, SLOT(handleMaxGlyphExtension()) );
135 }
136
configureWidgets()137 void PropertyWidget_Advanced::configureWidgets()
138 {
139 bool enabled = false;
140 if (m_item && m_doc)
141 {
142 if (m_item->isPathText() || m_item->isTextFrame() || m_item->isTable())
143 enabled = true;
144 if ((m_item->isGroup()) && (!m_item->isSingleSel))
145 enabled = false;
146 if (m_item->isOSGFrame() || m_item->isSymbol())
147 enabled = false;
148 if (m_doc->m_Selection->count() > 1)
149 enabled = false;
150 }
151 setEnabled(enabled);
152 }
153
handleSelectionChanged()154 void PropertyWidget_Advanced::handleSelectionChanged()
155 {
156 if (!m_doc || !m_ScMW || m_ScMW->scriptIsRunning())
157 return;
158
159 PageItem* currItem = currentItemFromSelection();
160 setCurrentItem(currItem);
161 updateGeometry();
162 }
163
showBaseLineOffset(double e)164 void PropertyWidget_Advanced::showBaseLineOffset(double e)
165 {
166 if (!m_ScMW || m_ScMW->scriptIsRunning())
167 return;
168 textBase->showValue(e / 10.0);
169 }
170
showTextScaleH(double e)171 void PropertyWidget_Advanced::showTextScaleH(double e)
172 {
173 if (!m_ScMW || m_ScMW->scriptIsRunning())
174 return;
175 scaleH->showValue(e / 10.0);
176 }
177
showTextScaleV(double e)178 void PropertyWidget_Advanced::showTextScaleV(double e)
179 {
180 if (!m_ScMW || m_ScMW->scriptIsRunning())
181 return;
182 scaleV->showValue(e / 10.0);
183 }
184
showTracking(double e)185 void PropertyWidget_Advanced::showTracking(double e)
186 {
187 if (!m_ScMW || m_ScMW->scriptIsRunning())
188 return;
189 tracking->showValue(e / 10.0);
190 }
191
handleBaselineOffset()192 void PropertyWidget_Advanced::handleBaselineOffset()
193 {
194 if (!m_doc || !m_item || !m_ScMW || m_ScMW->scriptIsRunning())
195 return;
196 PageItem *i2 = m_item;
197 if (m_doc->appMode == modeEditTable)
198 i2 = m_item->asTable()->activeCell().textFrame();
199 if (i2 != nullptr)
200 {
201 Selection tempSelection(this, false);
202 tempSelection.addItem(i2, true);
203 m_doc->itemSelection_SetBaselineOffset(qRound(textBase->value() * 10), &tempSelection);
204 }
205 }
206
handleMinWordTracking()207 void PropertyWidget_Advanced::handleMinWordTracking()
208 {
209 if (!m_doc || !m_item || !m_ScMW || m_ScMW->scriptIsRunning())
210 return;
211 PageItem *i2 = m_item;
212 if (m_doc->appMode == modeEditTable)
213 i2 = m_item->asTable()->activeCell().textFrame();
214 if (i2 != nullptr)
215 {
216 Selection tempSelection(this, false);
217 tempSelection.addItem(i2, true);
218 ParagraphStyle newStyle;
219 newStyle.setMinWordTracking(minWordTrackingSpinBox->value() / 100.0);
220 m_doc->itemSelection_ApplyParagraphStyle(newStyle, &tempSelection);
221 }
222 }
223
handleNormWordTracking()224 void PropertyWidget_Advanced::handleNormWordTracking()
225 {
226 if (!m_doc || !m_item || !m_ScMW || m_ScMW->scriptIsRunning())
227 return;
228 PageItem *i2 = m_item;
229 if (m_doc->appMode == modeEditTable)
230 i2 = m_item->asTable()->activeCell().textFrame();
231 if (i2 != nullptr)
232 {
233 Selection tempSelection(this, false);
234 tempSelection.addItem(i2, true);
235 ParagraphStyle newStyle;
236 newStyle.charStyle().setWordTracking(normWordTrackingSpinBox->value() / 100.0);
237 m_doc->itemSelection_ApplyParagraphStyle(newStyle, &tempSelection);
238 }
239 }
240
handleMinGlyphExtension()241 void PropertyWidget_Advanced::handleMinGlyphExtension()
242 {
243 if (!m_doc || !m_item || !m_ScMW || m_ScMW->scriptIsRunning())
244 return;
245 PageItem *i2 = m_item;
246 if (m_doc->appMode == modeEditTable)
247 i2 = m_item->asTable()->activeCell().textFrame();
248 if (i2 != nullptr)
249 {
250 Selection tempSelection(this, false);
251 tempSelection.addItem(i2, true);
252 ParagraphStyle newStyle;
253 newStyle.setMinGlyphExtension(minGlyphExtSpinBox->value() / 100.0);
254 m_doc->itemSelection_ApplyParagraphStyle(newStyle, &tempSelection);
255 }
256 }
257
handleMaxGlyphExtension()258 void PropertyWidget_Advanced::handleMaxGlyphExtension()
259 {
260 if (!m_doc || !m_item || !m_ScMW || m_ScMW->scriptIsRunning())
261 return;
262 PageItem *i2 = m_item;
263 if (m_doc->appMode == modeEditTable)
264 i2 = m_item->asTable()->activeCell().textFrame();
265 if (i2 != nullptr)
266 {
267 Selection tempSelection(this, false);
268 tempSelection.addItem(i2, true);
269 ParagraphStyle newStyle;
270 newStyle.setMaxGlyphExtension(maxGlyphExtSpinBox->value() / 100.0);
271 m_doc->itemSelection_ApplyParagraphStyle(newStyle, &tempSelection);
272 }
273 }
274
handleTextScaleH()275 void PropertyWidget_Advanced::handleTextScaleH()
276 {
277 if (!m_doc || !m_item || !m_ScMW || m_ScMW->scriptIsRunning())
278 return;
279 PageItem *i2 = m_item;
280 if (m_doc->appMode == modeEditTable)
281 i2 = m_item->asTable()->activeCell().textFrame();
282 if (i2 != nullptr)
283 {
284 Selection tempSelection(this, false);
285 tempSelection.addItem(i2, true);
286 m_doc->itemSelection_SetScaleH(qRound(scaleH->value() * 10), &tempSelection);
287 }
288 }
289
handleTextScaleV()290 void PropertyWidget_Advanced::handleTextScaleV()
291 {
292 if (!m_doc || !m_item || !m_ScMW || m_ScMW->scriptIsRunning())
293 return;
294 PageItem *i2 = m_item;
295 if (m_doc->appMode == modeEditTable)
296 i2 = m_item->asTable()->activeCell().textFrame();
297 if (i2 != nullptr)
298 {
299 Selection tempSelection(this, false);
300 tempSelection.addItem(i2, true);
301 m_doc->itemSelection_SetScaleV(qRound(scaleV->value() * 10), &tempSelection);
302 }
303 }
304
handleTracking()305 void PropertyWidget_Advanced::handleTracking()
306 {
307 if (!m_doc || !m_item || !m_ScMW || m_ScMW->scriptIsRunning())
308 return;
309 PageItem *i2 = m_item;
310 if (m_doc->appMode == modeEditTable)
311 i2 = m_item->asTable()->activeCell().textFrame();
312 if (i2 != nullptr)
313 {
314 Selection tempSelection(this, false);
315 tempSelection.addItem(i2, true);
316 m_doc->itemSelection_SetTracking(qRound(tracking->value() * 10.0), &tempSelection);
317 }
318 }
319
updateCharStyle(const CharStyle & charStyle)320 void PropertyWidget_Advanced::updateCharStyle(const CharStyle& charStyle)
321 {
322 if (!m_ScMW || m_ScMW->scriptIsRunning())
323 return;
324
325 showTextScaleH(charStyle.scaleH());
326 showTextScaleV(charStyle.scaleV());
327 showTracking(charStyle.tracking());
328 showBaseLineOffset(charStyle.baselineOffset());
329
330 normWordTrackingSpinBox->showValue(charStyle.wordTracking() * 100.0);
331 }
332
updateStyle(const ParagraphStyle & newCurrent)333 void PropertyWidget_Advanced::updateStyle(const ParagraphStyle& newCurrent)
334 {
335 if (!m_ScMW || m_ScMW->scriptIsRunning())
336 return;
337
338 const CharStyle& charStyle = newCurrent.charStyle();
339
340 showTextScaleH(charStyle.scaleH());
341 showTextScaleV(charStyle.scaleV());
342 showTracking(charStyle.tracking());
343 showBaseLineOffset(charStyle.baselineOffset());
344
345 minWordTrackingSpinBox->showValue(newCurrent.minWordTracking() * 100.0);
346 normWordTrackingSpinBox->showValue(newCurrent.charStyle().wordTracking() * 100.0);
347 minGlyphExtSpinBox->showValue(newCurrent.minGlyphExtension() * 100.0);
348 maxGlyphExtSpinBox->showValue(newCurrent.maxGlyphExtension() * 100.0);
349 }
350
changeEvent(QEvent * e)351 void PropertyWidget_Advanced::changeEvent(QEvent *e)
352 {
353 if (e->type() == QEvent::LanguageChange)
354 {
355 languageChange();
356 return;
357 }
358 QWidget::changeEvent(e);
359 }
360
iconSetChange()361 void PropertyWidget_Advanced::iconSetChange()
362 {
363 textBaseLabel->setPixmap(IconManager::instance().loadPixmap("textbase.png"));
364 trackingLabel->setPixmap(IconManager::instance().loadPixmap("textkern.png"));
365
366 scaleHLabel->setPixmap(IconManager::instance().loadPixmap("textscaleh.png"));
367 scaleVLabel->setPixmap(IconManager::instance().loadPixmap("textscalev.png"));
368 }
369
languageChange()370 void PropertyWidget_Advanced::languageChange()
371 {
372 retranslateUi(this);
373 }
374
localeChange()375 void PropertyWidget_Advanced::localeChange()
376 {
377 const QLocale& l(LocaleManager::instance().userPreferredLocale());
378 textBase->setLocale(l);
379 tracking->setLocale(l);
380 scaleH->setLocale(l);
381 scaleV->setLocale(l);
382 minWordTrackingSpinBox->setLocale(l);
383 normWordTrackingSpinBox->setLocale(l);
384 minGlyphExtSpinBox->setLocale(l);
385 maxGlyphExtSpinBox->setLocale(l);
386 }
387