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 "propertiespalette_line.h"
9 
10 #if defined(_MSC_VER) && !defined(_USE_MATH_DEFINES)
11 #define _USE_MATH_DEFINES
12 #endif
13 #include <cmath>
14 #include <QSignalBlocker>
15 
16 #include "arrowchooser.h"
17 #include "commonstrings.h"
18 #include "dasheditor.h"
19 #include "iconmanager.h"
20 #include "localemgr.h"
21 #include "pageitem.h"
22 #include "pageitem_textframe.h"
23 #include "sccolorengine.h"
24 #include "scraction.h"
25 #include "scribusapp.h"
26 #include "scribuscore.h"
27 #include "selection.h"
28 #include "ui/propertiespalette_utils.h"
29 #include "undomanager.h"
30 #include "units.h"
31 #include "util.h"
32 #include "util_math.h"
33 
34 
35 //using namespace std;
36 
PropertiesPalette_Line(QWidget * parent)37 PropertiesPalette_Line::PropertiesPalette_Line( QWidget* parent) : QWidget(parent)
38 {
39 	setupUi(this);
40 	setSizePolicy( QSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum));
41 
42 	lineType->addItem( tr("Custom"));
43 
44 	lineModeLabel->setBuddy(lineMode);
45 	lineTypeLabel->setBuddy(lineType);
46 
47 	startArrowLabel->setBuddy(startArrow);
48 	endArrowLabel->setBuddy(endArrow);
49 
50 	startArrow->setArrowDirection(ArrowDirection::StartArrow);
51 	startArrowScale->setMaximum(1000);
52 	startArrowScale->setMinimum(1);
53 	startArrowScale->setDecimals(0);
54 
55 	endArrow->setArrowDirection(ArrowDirection::EndArrow);
56 	endArrowScale->setMaximum(1000);
57 	endArrowScale->setMinimum(1);
58 	endArrowScale->setDecimals(0);
59 
60 	lineWidthLabel->setBuddy(lineWidth);
61 	lineJoinLabel->setBuddy(lineJoinStyle);
62 	lineEndLabel->setBuddy(lineEndStyle);
63 
64 	lineStyles->setItemDelegate(new LineStyleItemDelegate());
65 	lineStyles->addItem( "No Style" );
66 
67 	languageChange();
68 
69 	connect(ScQApp, SIGNAL(iconSetChanged()), this, SLOT(iconSetChange()));
70 	connect(ScQApp, SIGNAL(localeChanged()), this, SLOT(localeChange()));
71 
72 	connect(lineWidth, SIGNAL(valueChanged(double)), this, SLOT(handleLineWidth()));
73 	connect(lineType, SIGNAL(activated(int)), this, SLOT(handleLineStyle()));
74 	connect(lineJoinStyle, SIGNAL(activated(int)), this, SLOT(handleLineJoin()));
75 	connect(lineEndStyle, SIGNAL(activated(int)), this, SLOT(handleLineEnd()));
76 	connect(lineMode, SIGNAL(activated(int)), this, SLOT(handleLineMode()));
77 	connect(dashEditor, SIGNAL(dashChanged()), this, SLOT(handleDashChange()));
78 	connect(startArrow, SIGNAL(activated(int)), this, SLOT(handleStartArrow(int )));
79 	connect(endArrow, SIGNAL(activated(int)), this, SLOT(handleEndArrow(int )));
80 	connect(startArrowScale, SIGNAL(valueChanged(double)), this, SLOT(handleStartArrowScale(double )));
81 	connect(endArrowScale, SIGNAL(valueChanged(double)), this, SLOT(handleEndArrowScale(double )));
82 	connect(lineStyles, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(handleLineStyle(QListWidgetItem*)));
83 }
84 
changeEvent(QEvent * e)85 void PropertiesPalette_Line::changeEvent(QEvent *e)
86 {
87 	if (e->type() == QEvent::LanguageChange)
88 	{
89 		languageChange();
90 		return;
91 	}
92 	QWidget::changeEvent(e);
93 }
94 
currentItemFromSelection()95 PageItem* PropertiesPalette_Line::currentItemFromSelection()
96 {
97 	PageItem *currentItem = nullptr;
98 
99 	if (m_doc)
100 	{
101 		if (m_doc->m_Selection->count() > 1)
102 		{
103 			currentItem = m_doc->m_Selection->itemAt(0);
104 		}
105 		else if (m_doc->m_Selection->count() == 1)
106 		{
107 			currentItem = m_doc->m_Selection->itemAt(0);
108 		}
109 	}
110 
111 	return currentItem;
112 }
113 
setMainWindow(ScribusMainWindow * mw)114 void PropertiesPalette_Line::setMainWindow(ScribusMainWindow *mw)
115 {
116 	m_ScMW = mw;
117 
118 	connect(m_ScMW, SIGNAL(UpdateRequest(int)), this, SLOT(handleUpdateRequest(int)));
119 }
120 
setDoc(ScribusDoc * d)121 void PropertiesPalette_Line::setDoc(ScribusDoc *d)
122 {
123 	if((d == (ScribusDoc*) m_doc) || (m_ScMW && m_ScMW->scriptIsRunning()))
124 		return;
125 
126 	if (m_doc)
127 	{
128 		disconnect(m_doc->m_Selection, SIGNAL(selectionChanged()), this, SLOT(handleSelectionChanged()));
129 		disconnect(m_doc, SIGNAL(docChanged()), this, SLOT(handleSelectionChanged()));
130 	}
131 
132 	m_doc  = d;
133 	m_item = nullptr;
134 	m_unitRatio   = m_doc->unitRatio();
135 	m_unitIndex   = m_doc->unitIndex();
136 
137 	m_haveDoc  = true;
138 	m_haveItem = false;
139 
140 	lineWidth->setMaximum( 300 );
141 	lineWidth->setMinimum( 0 );
142 
143 	updateLineStyles(m_doc);
144 	startArrow->rebuildList(&m_doc->arrowStyles());
145 	endArrow->rebuildList(&m_doc->arrowStyles());
146 
147 	connect(m_doc->m_Selection, SIGNAL(selectionChanged()), this, SLOT(handleSelectionChanged()));
148 	connect(m_doc, SIGNAL(docChanged()), this, SLOT(handleSelectionChanged()));
149 }
150 
unsetDoc()151 void PropertiesPalette_Line::unsetDoc()
152 {
153 	if (m_doc)
154 	{
155 		disconnect(m_doc->m_Selection, SIGNAL(selectionChanged()), this, SLOT(handleSelectionChanged()));
156 		disconnect(m_doc, SIGNAL(docChanged()), this, SLOT(handleSelectionChanged()));
157 	}
158 
159 	m_haveDoc  = false;
160 	m_haveItem = false;
161 	m_doc   = nullptr;
162 	m_item  = nullptr;
163 
164 	updateLineStyles(nullptr);
165 
166 	setEnabled(false);
167 }
168 
unsetItem()169 void PropertiesPalette_Line::unsetItem()
170 {
171 	m_haveItem = false;
172 	m_item     = nullptr;
173 	dashEditor->hide();
174 	handleSelectionChanged();
175 }
176 
handleSelectionChanged()177 void PropertiesPalette_Line::handleSelectionChanged()
178 {
179 	if (!m_haveDoc || !m_ScMW || m_ScMW->scriptIsRunning())
180 		return;
181 
182 	PageItem* currItem = currentItemFromSelection();
183 	if (m_doc->m_Selection->count() > 1)
184 	{
185 		setEnabled(true);
186 	}
187 	else
188 	{
189 		int itemType = currItem ? (int) currItem->itemType() : -1;
190 		m_haveItem = (itemType != -1);
191 
192 		lineMode->setEnabled(false);
193 		switch (itemType)
194 		{
195 		case -1:
196 			setEnabled(false);
197 			break;
198 		case PageItem::ImageFrame:
199 		case PageItem::LatexFrame:
200 		case PageItem::OSGFrame:
201 			setEnabled(currItem->asOSGFrame() == nullptr);
202 			break;
203 		case PageItem::Line:
204 			setEnabled(true);
205 			lineMode->setEnabled(true);
206 			break;
207 		case PageItem::Arc:
208 		case PageItem::ItemType1:
209 		case PageItem::ItemType3:
210 		case PageItem::Polygon:
211 		case PageItem::PolyLine:
212 		case PageItem::PathText:
213 		case PageItem::RegularPolygon:
214 		case PageItem::TextFrame:
215 			setEnabled(true);
216 			break;
217 		case PageItem::Symbol:
218 			setEnabled(false);
219 			break;
220 		}
221 	}
222 	if (currItem)
223 	{
224 		setCurrentItem(currItem);
225 	}
226 	updateGeometry();
227 	//repaint();
228 }
229 
handleUpdateRequest(int updateFlags)230 void PropertiesPalette_Line::handleUpdateRequest(int updateFlags)
231 {
232 	if (updateFlags & reqArrowStylesUpdate)
233 		updateArrowStyles();
234 	if (updateFlags & reqLineStylesUpdate)
235 		updateLineStyles();
236 }
237 
setCurrentItem(PageItem * item)238 void PropertiesPalette_Line::setCurrentItem(PageItem *item)
239 {
240 	if (!m_ScMW || m_ScMW->scriptIsRunning())
241 		return;
242 	//CB We shouldn't really need to process this if our item is the same one
243 	//maybe we do if the item has been changed by scripter.. but that should probably
244 	//set some status if so.
245 	//FIXME: This won't work until when a canvas deselect happens, m_item must be nullptr.
246 	//if (m_item == i)
247 	//	return;
248 
249 	if (!m_doc)
250 		setDoc(item->doc());
251 
252 	m_haveItem = false;
253 	m_item = item;
254 
255 	lineStyles->blockSignals(true);
256 	startArrow->blockSignals(true);
257 	endArrow->blockSignals(true);
258 	startArrowScale->blockSignals(true);
259 	endArrowScale->blockSignals(true);
260 	lineMode->blockSignals(true);
261 
262 	if ((m_item->asLine()) || (m_item->asPolyLine()) || (m_item->asSpiral()))
263 	{
264 		startArrow->setEnabled(true);
265 		endArrow->setEnabled(true);
266 		startArrow->setCurrentIndex(m_item->startArrowIndex());
267 		endArrow->setCurrentIndex(m_item->endArrowIndex());
268 		startArrowScale->setEnabled(true);
269 		endArrowScale->setEnabled(true);
270 		endArrowScale->setValue(m_item->endArrowScale());
271 		startArrowScale->setValue(m_item->startArrowScale());
272 	}
273 	else
274 	{
275 		startArrow->setEnabled(false);
276 		endArrow->setEnabled(false);
277 		startArrowScale->setEnabled(false);
278 		endArrowScale->setEnabled(false);
279 	}
280 
281 	if (lineStyles->currentItem())
282 		lineStyles->currentItem()->setSelected(false);
283 
284 	bool setter = false;
285 	if (m_item->NamedLStyle.isEmpty())
286 	{
287 		setter = true;
288 		QListWidgetItem *itemStl = nullptr;
289 		itemStl = lineStyles->item(0);
290 		if (itemStl != nullptr)
291 			itemStl->setSelected(true);
292 	}
293 	else
294 	{
295 		QList<QListWidgetItem*> results (lineStyles->findItems(m_item->NamedLStyle, Qt::MatchFixedString|Qt::MatchCaseSensitive));
296 		if (results.count() > 0)
297 			results[0]->setSelected(true);
298 		setter = false;
299 	}
300 
301 	lineType->setEnabled(setter);
302 	lineWidth->setEnabled(setter);
303 	lineJoinStyle->setEnabled(setter);
304 	lineEndStyle->setEnabled(setter);
305 
306 	if (m_item->dashes().count() == 0)
307 		dashEditor->hide();
308 	else
309 	{
310 		lineType->setCurrentIndex(37);
311 		dashEditor->setDashValues(m_item->dashes(), qMax(m_item->lineWidth(), 0.001), m_item->dashOffset());
312 		dashEditor->show();
313 	}
314 
315 	if (m_lineMode)
316 		lineMode->setCurrentIndex(1);
317 	else
318 		lineMode->setCurrentIndex(0);
319 
320 	lineStyles->blockSignals(false);
321 	startArrow->blockSignals(false);
322 	endArrow->blockSignals(false);
323 	startArrowScale->blockSignals(false);
324 	endArrowScale->blockSignals(false);
325 	lineMode->blockSignals(false);
326 
327 	if ((m_item->isGroup()) && (!m_item->isSingleSel))
328 		setEnabled(false);
329 
330 	m_haveItem = true;
331 
332 	showLineWidth(m_item->lineWidth());
333 	showLineValues(m_item->lineStyle(), m_item->lineEnd(), m_item->lineJoin());
334 
335 	if (m_item->isOSGFrame())
336 		setEnabled(false);
337 	if (m_item->isSymbol())
338 		setEnabled(false);
339 }
340 
updateArrowStyles()341 void PropertiesPalette_Line::updateArrowStyles()
342 {
343 	updateArrowStyles(m_doc);
344 }
345 
updateArrowStyles(ScribusDoc * doc)346 void PropertiesPalette_Line::updateArrowStyles(ScribusDoc *doc)
347 {
348 	if (!doc)
349 		return;
350 	startArrow->rebuildList(&doc->arrowStyles());
351 	endArrow->rebuildList(&doc->arrowStyles());
352 }
353 
updateLineStyles()354 void PropertiesPalette_Line::updateLineStyles()
355 {
356 	updateLineStyles(m_doc);
357 }
358 
updateLineStyles(ScribusDoc * doc)359 void PropertiesPalette_Line::updateLineStyles(ScribusDoc *doc)
360 {
361 	if (!m_ScMW || m_ScMW->scriptIsRunning())
362 		return;
363 
364 	lineStyles->blockSignals(true);
365 	lineStyles->clear();
366 	if (doc != nullptr)
367 	{
368 		QHash<QString,multiLine>::Iterator it;
369 		for (it = doc->docLineStyles.begin(); it != doc->docLineStyles.end(); ++it)
370 			lineStyles->addItem( new LineStyleItem(doc, it.value(), it.key()) );
371 		lineStyles->sortItems();
372 		lineStyles->insertItem( 0, tr("No Style"));
373 		if (lineStyles->currentItem())
374 			lineStyles->currentItem()->setSelected(false);
375 	}
376 	lineStyles->blockSignals(false);
377 }
378 
showLineWidth(double s)379 void PropertiesPalette_Line::showLineWidth(double s)
380 {
381 	if (!m_ScMW || m_ScMW->scriptIsRunning())
382 		return;
383 	lineWidth->showValue(s * m_unitRatio);
384 	if (m_haveItem)
385 	{
386 		if (m_item->dashes().count() != 0)
387 		{
388 			dashEditor->blockSignals(true);
389 			if (m_item->lineWidth() != 0.0)
390 			{
391 				dashEditor->setDashValues(m_item->dashes(), m_item->lineWidth(), m_item->dashOffset());
392 				dashEditor->setEnabled(true);
393 			}
394 			else
395 				dashEditor->setEnabled(false);
396 			dashEditor->blockSignals(false);
397 		}
398 	}
399 }
400 
showLineValues(Qt::PenStyle p,Qt::PenCapStyle pc,Qt::PenJoinStyle pj)401 void PropertiesPalette_Line::showLineValues(Qt::PenStyle p, Qt::PenCapStyle pc, Qt::PenJoinStyle pj)
402 {
403 	if (!m_ScMW || m_ScMW->scriptIsRunning())
404 		return;
405 
406 	lineType->blockSignals(true);
407 	dashEditor->blockSignals(true);
408 	if (m_haveItem)
409 	{
410 		if (m_item->dashes().count() != 0)
411 		{
412 			lineType->setCurrentIndex(37);
413 			dashEditor->setDashValues(m_item->dashes(), qMax(m_item->lineWidth(), 0.001), m_item->dashOffset());
414 		}
415 		else
416 			lineType->setCurrentIndex(static_cast<int>(p) - 1);
417 	}
418 	else
419 		lineType->setCurrentIndex(static_cast<int>(p) - 1);
420 	dashEditor->blockSignals(false);
421 	lineType->blockSignals(false);
422 
423 	lineEndStyle->blockSignals(true);
424 	switch (pc)
425 	{
426 	case Qt::FlatCap:
427 		lineEndStyle->setCurrentIndex(0);
428 		break;
429 	case Qt::SquareCap:
430 		lineEndStyle->setCurrentIndex(1);
431 		break;
432 	case Qt::RoundCap:
433 		lineEndStyle->setCurrentIndex(2);
434 		break;
435 	default:
436 		lineEndStyle->setCurrentIndex(0);
437 		break;
438 	}
439 	lineEndStyle->blockSignals(false);
440 
441 	lineJoinStyle->blockSignals(true);
442 	switch (pj)
443 	{
444 	case Qt::MiterJoin:
445 		lineJoinStyle->setCurrentIndex(0);
446 		break;
447 	case Qt::BevelJoin:
448 		lineJoinStyle->setCurrentIndex(1);
449 		break;
450 	case Qt::RoundJoin:
451 		lineJoinStyle->setCurrentIndex(2);
452 		break;
453 	default:
454 		lineJoinStyle->setCurrentIndex(0);
455 		break;
456 	}
457 	lineJoinStyle->blockSignals(false);
458 }
459 
handleLineWidth()460 void PropertiesPalette_Line::handleLineWidth()
461 {
462 	if (!m_ScMW || m_ScMW->scriptIsRunning())
463 		return;
464 	if ((m_haveDoc) && (m_haveItem))
465 	{
466 		double oldL = m_item->lineWidth();
467 		m_doc->itemSelection_SetLineWidth(lineWidth->value() / m_unitRatio);
468 		if (m_item->dashes().count() != 0)
469 		{
470 			if ((oldL != 0.0) && (m_item->lineWidth() != 0.0))
471 			{
472 				for (int a = 0; a < m_item->DashValues.count(); a++)
473 				{
474 					m_item->DashValues[a] = m_item->DashValues[a] / oldL * m_item->lineWidth();
475 				}
476 				m_item->setDashOffset(m_item->dashOffset() / oldL * m_item->lineWidth());
477 			}
478 			if (m_item->lineWidth() != 0.0)
479 			{
480 				dashEditor->setDashValues(m_item->dashes(), m_item->lineWidth(), m_item->dashOffset());
481 				dashEditor->setEnabled((m_item->lineWidth() != 0.0));
482 			}
483 			else
484 				dashEditor->setEnabled(false);
485 		}
486 		m_doc->invalidateAll();
487 		m_doc->regionsChanged()->update(QRect());
488 	}
489 }
490 
handleLineStyle()491 void PropertiesPalette_Line::handleLineStyle()
492 {
493 	if (!m_ScMW || m_ScMW->scriptIsRunning())
494 		return;
495 	if ((m_haveDoc) && (m_haveItem))
496 	{
497 		if (lineType->currentIndex() == 37)
498 		{
499 			if (m_item->dashes().count() == 0)
500 			{
501 				if ((m_item->lineStyle() == 0) || (m_item->lineStyle() == 1))
502 				{
503 					m_item->DashValues.append(4.0 * qMax(m_item->lineWidth(), 1.0));
504 					m_item->DashValues.append(2.0 * qMax(m_item->lineWidth(), 1.0));
505 				}
506 				else
507 					getDashArray(m_item->lineStyle(), qMax(m_item->lineWidth(), 1.0), m_item->DashValues);
508 			}
509 			if (m_item->lineWidth() != 0.0)
510 				dashEditor->setDashValues(m_item->dashes(), m_item->lineWidth(), m_item->dashOffset());
511 			else
512 			{
513 				dashEditor->setEnabled(false);
514 				dashEditor->setDashValues(m_item->dashes(), 1.0, m_item->dashOffset());
515 			}
516 			dashEditor->show();
517 			m_item->update();
518 		}
519 		else
520 		{
521 			m_item->DashValues.clear();
522 			dashEditor->hide();
523 			m_doc->itemSelection_SetLineArt(static_cast<Qt::PenStyle>(lineType->currentIndex()+1));
524 		}
525 	}
526 }
527 
handleLineJoin()528 void PropertiesPalette_Line::handleLineJoin()
529 {
530 	if (!m_ScMW || m_ScMW->scriptIsRunning())
531 		return;
532 	if ((m_haveDoc) && (m_haveItem))
533 	{
534 		Qt::PenJoinStyle c = Qt::MiterJoin;
535 		switch (lineJoinStyle->currentIndex())
536 		{
537 		case 0:
538 			c = Qt::MiterJoin;
539 			break;
540 		case 1:
541 			c = Qt::BevelJoin;
542 			break;
543 		case 2:
544 			c = Qt::RoundJoin;
545 			break;
546 		}
547 		m_doc->itemSelection_SetLineJoin(c);
548 	}
549 }
550 
handleLineEnd()551 void PropertiesPalette_Line::handleLineEnd()
552 {
553 	if (!m_ScMW || m_ScMW->scriptIsRunning())
554 		return;
555 	if ((m_haveDoc) && (m_haveItem))
556 	{
557 		Qt::PenCapStyle c = Qt::FlatCap;
558 		switch (lineEndStyle->currentIndex())
559 		{
560 		case 0:
561 			c = Qt::FlatCap;
562 			break;
563 		case 1:
564 			c = Qt::SquareCap;
565 			break;
566 		case 2:
567 			c = Qt::RoundCap;
568 			break;
569 		}
570 		m_doc->itemSelection_SetLineEnd(c);
571 	}
572 }
573 
handleLineMode()574 void PropertiesPalette_Line::handleLineMode()
575 {
576 	if (!m_ScMW || m_ScMW->scriptIsRunning())
577 		return;
578 	m_lineMode = (lineMode->currentIndex() == 1);
579 	emit lineModeChanged(lineMode->currentIndex());
580 }
581 
handleStartArrow(int id)582 void PropertiesPalette_Line::handleStartArrow(int id)
583 {
584 	if (!m_haveDoc || !m_haveItem || !m_ScMW || m_ScMW->scriptIsRunning())
585 		return;
586 	m_doc->itemSelection_ApplyArrowHead(id,-1);
587 }
588 
handleEndArrow(int id)589 void PropertiesPalette_Line::handleEndArrow(int id)
590 {
591 	if (!m_haveDoc || !m_haveItem || !m_ScMW || m_ScMW->scriptIsRunning())
592 		return;
593 	m_doc->itemSelection_ApplyArrowHead(-1, id);
594 }
595 
handleStartArrowScale(double sc)596 void PropertiesPalette_Line::handleStartArrowScale(double sc)
597 {
598 	if (!m_haveDoc || !m_haveItem || !m_ScMW || m_ScMW->scriptIsRunning())
599 		return;
600 	m_doc->itemSelection_ApplyArrowScale(static_cast<int>(sc), -1, nullptr);
601 }
602 
handleEndArrowScale(double sc)603 void PropertiesPalette_Line::handleEndArrowScale(double sc)
604 {
605 	if (!m_haveDoc || !m_haveItem || !m_ScMW || m_ScMW->scriptIsRunning())
606 		return;
607 	m_doc->itemSelection_ApplyArrowScale(-1, static_cast<int>(sc), nullptr);
608 }
609 
handleDashChange()610 void PropertiesPalette_Line::handleDashChange()
611 {
612 	if (!m_ScMW || m_ScMW->scriptIsRunning())
613 		return;
614 	if ((m_haveDoc) && (m_haveItem))
615 	{
616 		if (m_item->lineWidth() != 0.0)
617 		{
618 			m_item->setDashes(dashEditor->getDashValues(m_item->lineWidth()));
619 			m_item->setDashOffset(dashEditor->Offset->value() * m_item->lineWidth());
620 		}
621 		m_item->update();
622 	}
623 }
624 
handleLineStyle(QListWidgetItem * widgetItem)625 void PropertiesPalette_Line::handleLineStyle(QListWidgetItem *widgetItem)
626 {
627 	if (!m_doc || !m_ScMW || m_ScMW->scriptIsRunning() || !widgetItem)
628 		return;
629 	bool setter = (widgetItem->listWidget()->currentRow() == 0);
630 	m_doc->itemSelection_SetNamedLineStyle(setter ? QString("") : widgetItem->text());
631 	lineType->setEnabled(setter);
632 	lineWidth->setEnabled(setter);
633 	lineJoinStyle->setEnabled(setter);
634 	lineEndStyle->setEnabled(setter);
635 }
636 
iconSetChange()637 void PropertiesPalette_Line::iconSetChange()
638 {
639 	IconManager& im = IconManager::instance();
640 
641 	QSignalBlocker lineJoinStyleBlocker(lineJoinStyle);
642 	int oldLJoinStyle = lineJoinStyle->currentIndex();
643 	lineJoinStyle->clear();
644 	lineJoinStyle->addItem(im.loadIcon("16/stroke-join-miter.png"), tr("Miter Join"));
645 	lineJoinStyle->addItem(im.loadIcon("16/stroke-join-bevel.png"), tr("Bevel Join"));
646 	lineJoinStyle->addItem(im.loadIcon("16/stroke-join-round.png"), tr("Round Join"));
647 	lineJoinStyle->setCurrentIndex(oldLJoinStyle);
648 
649 	QSignalBlocker lineEndStyleBlocker(lineEndStyle);
650 	int oldLEndStyle = lineEndStyle->currentIndex();
651 	lineEndStyle->clear();
652 	lineEndStyle->addItem(im.loadIcon("16/stroke-cap-butt.png"), tr("Flat Cap"));
653 	lineEndStyle->addItem(im.loadIcon("16/stroke-cap-square.png"), tr("Square Cap"));
654 	lineEndStyle->addItem(im.loadIcon("16/stroke-cap-round.png"), tr("Round Cap"));
655 	lineEndStyle->setCurrentIndex(oldLEndStyle);
656 	lineEndLabel->setText( tr("&Endings:"));
657 }
658 
languageChange()659 void PropertiesPalette_Line::languageChange()
660 {
661 	QSignalBlocker lineTypeBlocker(lineType);
662 	int oldLineStyle = lineType->currentIndex();
663 	lineType->clear();
664 	lineType->updateList();
665 	lineType->addItem( tr("Custom"));
666 	lineType->setCurrentIndex(oldLineStyle);
667 
668 	QSignalBlocker lineModeBlocker(lineMode);
669 	int oldLineMode = lineMode->currentIndex();
670 	lineMode->clear();
671 	lineMode->addItem( tr("Left Point"));
672 	lineMode->addItem( tr("End Points"));
673 	lineMode->setCurrentIndex(oldLineMode);
674 
675 	lineModeLabel->setText( tr("&Basepoint:"));
676 	lineTypeLabel->setText( tr("T&ype of Line:"));
677 	startArrowLabel->setText( tr("Start Arrow:"));
678 	endArrowLabel->setText( tr("End Arrow:"));
679 	startArrowScaleLabel->setText( tr("Scaling:"));
680 	endArrowScaleLabel->setText( tr("Scaling:"));
681 	if (m_haveDoc)
682 	{
683 		QSignalBlocker startArrowBlocker(startArrow);
684 		int arrowItem = startArrow->currentIndex();
685 		startArrow->rebuildList(&m_doc->arrowStyles());
686 		startArrow->setCurrentIndex(arrowItem);
687 		QSignalBlocker endArrowBlocker(endArrow);
688 		arrowItem = endArrow->currentIndex();
689 		endArrow->rebuildList(&m_doc->arrowStyles());
690 		endArrow->setCurrentIndex(arrowItem);
691 	}
692 	lineWidthLabel->setText( tr("Line &Width:"));
693 	lineJoinLabel->setText( tr("Ed&ges:"));
694 
695 	QSignalBlocker lineJoinStyleBlocker(lineJoinStyle);
696 	int oldLJoinStyle = lineJoinStyle->currentIndex();
697 	lineJoinStyle->clear();
698 	IconManager& im = IconManager::instance();
699 	lineJoinStyle->addItem(im.loadIcon("16/stroke-join-miter.png"), tr("Miter Join"));
700 	lineJoinStyle->addItem(im.loadIcon("16/stroke-join-bevel.png"), tr("Bevel Join"));
701 	lineJoinStyle->addItem(im.loadIcon("16/stroke-join-round.png"), tr("Round Join"));
702 	lineJoinStyle->setCurrentIndex(oldLJoinStyle);
703 
704 	QSignalBlocker lineEndStyleBlocker(lineEndStyle);
705 	int oldLEndStyle = lineEndStyle->currentIndex();
706 	lineEndStyle->clear();
707 	lineEndStyle->addItem(im.loadIcon("16/stroke-cap-butt.png"), tr("Flat Cap"));
708 	lineEndStyle->addItem(im.loadIcon("16/stroke-cap-square.png"), tr("Square Cap"));
709 	lineEndStyle->addItem(im.loadIcon("16/stroke-cap-round.png"), tr("Round Cap"));
710 	lineEndStyle->setCurrentIndex(oldLEndStyle);
711 	lineEndLabel->setText( tr("&Endings:"));
712 
713 	QString pctSuffix = tr(" %");
714 	startArrowScale->setSuffix(pctSuffix);
715 	endArrowScale->setSuffix(pctSuffix);
716 
717 	QString ptSuffix = tr(" pt");
718 	QString suffix = (m_doc) ? unitGetSuffixFromIndex(m_doc->unitIndex()) : ptSuffix;
719 
720 	lineWidth->setSuffix(suffix);
721 	lineWidth->setSpecialValueText( tr("Hairline"));
722 
723 	if(lineStyles->count() > 0)
724 		lineStyles->item(0)->setText( tr("No Style") );
725 
726 	lineMode->setToolTip( tr("Change settings for left or end points"));
727 	lineType->setToolTip( tr("Pattern of line"));
728 	lineWidth->setToolTip( tr("Thickness of line"));
729 	lineJoinStyle->setToolTip( tr("Type of line joins"));
730 	lineEndStyle->setToolTip( tr("Type of line end"));
731 	lineStyles->setToolTip( tr("Line style of current object"));
732 	startArrow->setToolTip( tr("Arrow head style for start of line"));
733 	endArrow->setToolTip( tr("Arrow head style for end of line"));
734 	startArrowScale->setToolTip( tr("Arrow head scale for start of line"));
735 	endArrowScale->setToolTip( tr("Arrow head scale for end of line"));
736 }
737 
unitChange()738 void PropertiesPalette_Line::unitChange()
739 {
740 	if (!m_doc)
741 		return;
742 
743 	m_unitRatio = m_doc->unitRatio();
744 	m_unitIndex = m_doc->unitIndex();
745 
746 	lineWidth->blockSignals(true);
747 	lineWidth->setNewUnit( m_unitIndex );
748 	lineWidth->blockSignals(false);
749 }
750 
localeChange()751 void PropertiesPalette_Line::localeChange()
752 {
753 	const QLocale& l(LocaleManager::instance().userPreferredLocale());
754 	lineWidth->setLocale(l);
755 }
756