Rev 18480 | Rev 18795 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
16546 | jghali | 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 | |||
17539 | jghali | 10 | #if defined(_MSC_VER) && !defined(_USE_MATH_DEFINES) |
16546 | jghali | 11 | #define _USE_MATH_DEFINES |
12 | #endif |
||
13 | #include <cmath> |
||
14 | #include "arrowchooser.h" |
||
15 | #include "commonstrings.h" |
||
16 | #include "dasheditor.h" |
||
17 | #include "pageitem.h" |
||
18 | #include "pageitem_textframe.h" |
||
19 | #include "sccolorengine.h" |
||
20 | #include "sccombobox.h" |
||
21 | #include "scribus.h" |
||
22 | #include "scribuscore.h" |
||
23 | #include "scraction.h" |
||
24 | #include "scribusview.h" |
||
25 | #include "selection.h" |
||
26 | #include "units.h" |
||
27 | #include "undomanager.h" |
||
28 | #include "util.h" |
||
29 | #include "util_icon.h" |
||
30 | #include "util_math.h" |
||
31 | #include "ui/propertiespalette_utils.h" |
||
32 | |||
33 | //using namespace std; |
||
34 | |||
35 | PropertiesPalette_Line::PropertiesPalette_Line( QWidget* parent) : QWidget(parent) |
||
36 | { |
||
37 | m_ScMW = 0; |
||
38 | m_doc = 0; |
||
39 | m_haveDoc = false; |
||
40 | m_haveItem = false; |
||
41 | m_lineMode = false; |
||
42 | m_unitRatio = 1.0; |
||
43 | |||
44 | setupUi(this); |
||
17383 | fschmid | 45 | setSizePolicy( QSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum)); |
16546 | jghali | 46 | |
47 | lineType->addItem( tr("Custom")); |
||
48 | |||
49 | lineModeLabel->setBuddy(lineMode); |
||
50 | lineTypeLabel->setBuddy(lineType); |
||
51 | |||
52 | startArrowLabel->setBuddy(startArrow); |
||
53 | endArrowLabel->setBuddy(endArrow); |
||
54 | |||
55 | startArrowScale->setMaximum( 300 ); |
||
56 | startArrowScale->setMinimum( 1 ); |
||
17420 | fschmid | 57 | startArrowScale->setDecimals(0); |
16546 | jghali | 58 | |
59 | endArrowScale->setMaximum( 300 ); |
||
60 | endArrowScale->setMinimum( 1 ); |
||
17420 | fschmid | 61 | endArrowScale->setDecimals(0); |
16546 | jghali | 62 | |
63 | lineWidthLabel->setBuddy(lineWidth); |
||
64 | lineJoinLabel->setBuddy(lineJoinStyle); |
||
65 | lineEndLabel->setBuddy(lineEndStyle); |
||
66 | |||
67 | lineStyles->setItemDelegate(new LineFormatItemDelegate); |
||
68 | lineStyles->addItem( "No Style" ); |
||
69 | |||
70 | languageChange(); |
||
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 ))); |
||
17420 | fschmid | 80 | connect(startArrowScale, SIGNAL(valueChanged(double)), this, SLOT(handleStartArrowScale(double ))); |
81 | connect(endArrowScale , SIGNAL(valueChanged(double)), this, SLOT(handleEndArrowScale(double ))); |
||
16546 | jghali | 82 | connect(lineStyles, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(handleLineStyle(QListWidgetItem*))); |
83 | } |
||
84 | |||
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 | |||
95 | PageItem* PropertiesPalette_Line::currentItemFromSelection() |
||
96 | { |
||
97 | PageItem *currentItem = NULL; |
||
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 | |||
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 | |||
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 = NULL; |
||
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 | |||
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 = NULL; |
||
162 | m_item = NULL; |
||
163 | |||
164 | updateLineStyles(0); |
||
165 | |||
166 | setEnabled(false); |
||
167 | } |
||
168 | |||
169 | void PropertiesPalette_Line::unsetItem() |
||
170 | { |
||
171 | m_haveItem = false; |
||
172 | m_item = NULL; |
||
173 | dashEditor->hide(); |
||
174 | handleSelectionChanged(); |
||
175 | } |
||
176 | |||
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 | { |
||
18138 | fschmid | 185 | setEnabled(true); |
16546 | jghali | 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() == NULL); |
||
202 | case PageItem::Line: |
||
203 | setEnabled(true); |
||
204 | lineMode->setEnabled(true); |
||
205 | break; |
||
206 | case PageItem::Arc: |
||
207 | case PageItem::ItemType1: |
||
208 | case PageItem::ItemType3: |
||
209 | case PageItem::Polygon: |
||
210 | case PageItem::PolyLine: |
||
211 | case PageItem::PathText: |
||
212 | case PageItem::RegularPolygon: |
||
213 | case PageItem::TextFrame: |
||
214 | setEnabled(true); |
||
215 | break; |
||
216 | case PageItem::Symbol: |
||
217 | setEnabled(false); |
||
218 | break; |
||
219 | } |
||
220 | } |
||
221 | if (currItem) |
||
222 | { |
||
223 | setCurrentItem(currItem); |
||
224 | } |
||
225 | updateGeometry(); |
||
18480 | jghali | 226 | //repaint(); |
16546 | jghali | 227 | } |
228 | |||
229 | void PropertiesPalette_Line::handleUpdateRequest(int updateFlags) |
||
230 | { |
||
231 | if (updateFlags & reqArrowStylesUpdate) |
||
232 | updateArrowStyles(); |
||
233 | if (updateFlags & reqLineStylesUpdate) |
||
234 | updateLineStyles(); |
||
235 | } |
||
236 | |||
237 | void PropertiesPalette_Line::setCurrentItem(PageItem *item) |
||
238 | { |
||
239 | if (!m_ScMW || m_ScMW->scriptIsRunning()) |
||
240 | return; |
||
241 | //CB We shouldnt really need to process this if our item is the same one |
||
242 | //maybe we do if the item has been changed by scripter.. but that should probably |
||
243 | //set some status if so. |
||
244 | //FIXME: This wont work until when a canvas deselect happens, m_item must be NULL. |
||
245 | //if (m_item == i) |
||
246 | // return; |
||
247 | |||
248 | if (!m_doc) |
||
249 | setDoc(item->doc()); |
||
250 | |||
251 | m_haveItem = false; |
||
252 | m_item = item; |
||
253 | |||
254 | lineStyles->blockSignals(true); |
||
255 | startArrow->blockSignals(true); |
||
256 | endArrow->blockSignals(true); |
||
257 | startArrowScale->blockSignals(true); |
||
258 | endArrowScale->blockSignals(true); |
||
259 | lineMode->blockSignals(true); |
||
260 | |||
261 | if ((m_item->asLine()) || (m_item->asPolyLine()) || (m_item->asSpiral())) |
||
262 | { |
||
263 | startArrow->setEnabled(true); |
||
264 | endArrow->setEnabled(true); |
||
265 | startArrow->setCurrentIndex(m_item->startArrowIndex()); |
||
266 | endArrow->setCurrentIndex(m_item->endArrowIndex()); |
||
267 | startArrowScale->setEnabled(true); |
||
268 | endArrowScale->setEnabled(true); |
||
269 | endArrowScale->setValue(m_item->endArrowScale()); |
||
270 | startArrowScale->setValue(m_item->startArrowScale()); |
||
271 | } |
||
272 | else |
||
273 | { |
||
274 | startArrow->setEnabled(false); |
||
275 | endArrow->setEnabled(false); |
||
276 | startArrowScale->setEnabled(false); |
||
277 | endArrowScale->setEnabled(false); |
||
278 | } |
||
279 | |||
280 | if (lineStyles->currentItem()) |
||
281 | lineStyles->currentItem()->setSelected(false); |
||
282 | |||
283 | bool setter = false; |
||
284 | if (m_item->NamedLStyle.isEmpty()) |
||
285 | { |
||
286 | setter = true; |
||
287 | QListWidgetItem *itemStl = NULL; |
||
288 | itemStl = lineStyles->item(0); |
||
289 | if (itemStl != NULL) |
||
290 | itemStl->setSelected(true); |
||
291 | } |
||
292 | else |
||
293 | { |
||
294 | QList<QListWidgetItem*> results (lineStyles->findItems(m_item->NamedLStyle, Qt::MatchFixedString|Qt::MatchCaseSensitive)); |
||
295 | if (results.count() > 0) |
||
296 | results[0]->setSelected(true); |
||
297 | setter = false; |
||
298 | } |
||
299 | |||
300 | lineType->setEnabled(setter); |
||
301 | lineWidth->setEnabled(setter); |
||
302 | lineJoinStyle->setEnabled(setter); |
||
303 | lineEndStyle->setEnabled(setter); |
||
304 | |||
305 | if (m_item->dashes().count() == 0) |
||
306 | dashEditor->hide(); |
||
307 | else |
||
308 | { |
||
309 | lineType->setCurrentIndex(37); |
||
310 | dashEditor->setDashValues(m_item->dashes(), qMax(m_item->lineWidth(), 0.001), m_item->dashOffset()); |
||
311 | dashEditor->show(); |
||
312 | } |
||
313 | |||
314 | if (m_lineMode) |
||
315 | lineMode->setCurrentIndex(1); |
||
316 | else |
||
317 | lineMode->setCurrentIndex(0); |
||
318 | |||
319 | lineStyles->blockSignals(false); |
||
320 | startArrow->blockSignals(false); |
||
321 | endArrow->blockSignals(false); |
||
322 | startArrowScale->blockSignals(false); |
||
323 | endArrowScale->blockSignals(false); |
||
324 | lineMode->blockSignals(false); |
||
325 | |||
17418 | fschmid | 326 | setter = false; |
16546 | jghali | 327 | |
328 | if ((m_item->isGroup()) && (!m_item->isSingleSel)) |
||
329 | { |
||
330 | setEnabled(false); |
||
331 | } |
||
332 | |||
333 | m_haveItem = true; |
||
334 | |||
335 | displayLineWidth(m_item->lineWidth()); |
||
336 | displayLineValues(m_item->lineStyle(), m_item->lineEnd(), m_item->lineJoin()); |
||
337 | |||
338 | if (m_item->asOSGFrame()) |
||
339 | { |
||
340 | setEnabled(false); |
||
341 | } |
||
342 | if (m_item->asSymbolFrame()) |
||
343 | { |
||
344 | setEnabled(false); |
||
345 | } |
||
346 | } |
||
347 | |||
348 | void PropertiesPalette_Line::updateArrowStyles() |
||
349 | { |
||
350 | updateArrowStyles(m_doc); |
||
351 | } |
||
352 | |||
353 | void PropertiesPalette_Line::updateArrowStyles(ScribusDoc *doc) |
||
354 | { |
||
355 | if (doc) |
||
356 | { |
||
357 | startArrow->rebuildList(&doc->arrowStyles()); |
||
358 | endArrow->rebuildList(&doc->arrowStyles()); |
||
359 | } |
||
360 | } |
||
361 | |||
362 | void PropertiesPalette_Line::updateLineStyles() |
||
363 | { |
||
364 | updateLineStyles(m_doc); |
||
365 | } |
||
366 | |||
367 | void PropertiesPalette_Line::updateLineStyles(ScribusDoc *dd) |
||
368 | { |
||
369 | if (!m_ScMW || m_ScMW->scriptIsRunning()) |
||
370 | return; |
||
371 | |||
372 | lineStyles->blockSignals(true); |
||
373 | lineStyles->clear(); |
||
374 | if (dd != 0) |
||
375 | { |
||
17400 | fschmid | 376 | QHash<QString,multiLine>::Iterator it; |
16546 | jghali | 377 | for (it = dd->MLineStyles.begin(); it != dd->MLineStyles.end(); ++it) |
378 | lineStyles->addItem( new LineFormatItem(dd, it.value(), it.key()) ); |
||
379 | lineStyles->sortItems(); |
||
380 | lineStyles->insertItem( 0, tr("No Style")); |
||
381 | if (lineStyles->currentItem()) |
||
382 | lineStyles->currentItem()->setSelected(false); |
||
383 | } |
||
384 | lineStyles->blockSignals(false); |
||
385 | } |
||
386 | |||
387 | void PropertiesPalette_Line::displayLineWidth(double s) |
||
388 | { |
||
389 | if (!m_ScMW || m_ScMW->scriptIsRunning()) |
||
390 | return; |
||
391 | lineWidth->showValue(s * m_unitRatio); |
||
392 | if (m_haveItem) |
||
393 | { |
||
394 | if (m_item->dashes().count() != 0) |
||
395 | { |
||
396 | dashEditor->blockSignals(true); |
||
397 | if (m_item->lineWidth() != 0.0) |
||
398 | { |
||
399 | dashEditor->setDashValues(m_item->dashes(), m_item->lineWidth(), m_item->dashOffset()); |
||
400 | dashEditor->setEnabled(true); |
||
401 | } |
||
402 | else |
||
403 | dashEditor->setEnabled(false); |
||
404 | dashEditor->blockSignals(false); |
||
405 | } |
||
406 | } |
||
407 | } |
||
408 | |||
409 | void PropertiesPalette_Line::displayLineValues(Qt::PenStyle p, Qt::PenCapStyle pc, Qt::PenJoinStyle pj) |
||
410 | { |
||
411 | if (!m_ScMW || m_ScMW->scriptIsRunning()) |
||
412 | return; |
||
413 | |||
414 | lineType->blockSignals(true); |
||
415 | dashEditor->blockSignals(true); |
||
416 | if (m_haveItem) |
||
417 | { |
||
418 | if (m_item->dashes().count() != 0) |
||
419 | { |
||
420 | lineType->setCurrentIndex(37); |
||
421 | dashEditor->setDashValues(m_item->dashes(), qMax(m_item->lineWidth(), 0.001), m_item->dashOffset()); |
||
422 | } |
||
423 | else |
||
424 | lineType->setCurrentIndex(static_cast<int>(p) - 1); |
||
425 | } |
||
426 | else |
||
427 | lineType->setCurrentIndex(static_cast<int>(p) - 1); |
||
428 | dashEditor->blockSignals(false); |
||
429 | lineType->blockSignals(false); |
||
430 | |||
431 | lineEndStyle->blockSignals(true); |
||
432 | switch (pc) |
||
433 | { |
||
434 | case Qt::FlatCap: |
||
435 | lineEndStyle->setCurrentIndex(0); |
||
436 | break; |
||
437 | case Qt::SquareCap: |
||
438 | lineEndStyle->setCurrentIndex(1); |
||
439 | break; |
||
440 | case Qt::RoundCap: |
||
441 | lineEndStyle->setCurrentIndex(2); |
||
442 | break; |
||
443 | default: |
||
444 | lineEndStyle->setCurrentIndex(0); |
||
445 | break; |
||
446 | } |
||
447 | lineEndStyle->blockSignals(false); |
||
448 | |||
449 | lineJoinStyle->blockSignals(true); |
||
450 | switch (pj) |
||
451 | { |
||
452 | case Qt::MiterJoin: |
||
453 | lineJoinStyle->setCurrentIndex(0); |
||
454 | break; |
||
455 | case Qt::BevelJoin: |
||
456 | lineJoinStyle->setCurrentIndex(1); |
||
457 | break; |
||
458 | case Qt::RoundJoin: |
||
459 | lineJoinStyle->setCurrentIndex(2); |
||
460 | break; |
||
461 | default: |
||
462 | lineJoinStyle->setCurrentIndex(0); |
||
463 | break; |
||
464 | } |
||
465 | lineJoinStyle->blockSignals(false); |
||
466 | } |
||
467 | |||
468 | void PropertiesPalette_Line::handleLineWidth() |
||
469 | { |
||
470 | if (!m_ScMW || m_ScMW->scriptIsRunning()) |
||
471 | return; |
||
472 | if ((m_haveDoc) && (m_haveItem)) |
||
473 | { |
||
474 | double oldL = m_item->lineWidth(); |
||
475 | m_doc->itemSelection_SetLineWidth(lineWidth->value() / m_unitRatio); |
||
476 | if (m_item->dashes().count() != 0) |
||
477 | { |
||
478 | if ((oldL != 0.0) && (m_item->lineWidth() != 0.0)) |
||
479 | { |
||
480 | for (int a = 0; a < m_item->DashValues.count(); a++) |
||
481 | { |
||
482 | m_item->DashValues[a] = m_item->DashValues[a] / oldL * m_item->lineWidth(); |
||
483 | } |
||
484 | m_item->setDashOffset(m_item->dashOffset() / oldL * m_item->lineWidth()); |
||
485 | } |
||
486 | if (m_item->lineWidth() != 0.0) |
||
487 | { |
||
488 | dashEditor->setDashValues(m_item->dashes(), m_item->lineWidth(), m_item->dashOffset()); |
||
489 | dashEditor->setEnabled((m_item->lineWidth() != 0.0)); |
||
490 | } |
||
491 | else |
||
492 | dashEditor->setEnabled(false); |
||
493 | } |
||
17057 | fschmid | 494 | m_doc->invalidateAll(); |
17038 | fschmid | 495 | m_doc->regionsChanged()->update(QRect()); |
16546 | jghali | 496 | } |
497 | } |
||
498 | |||
499 | void PropertiesPalette_Line::handleLineStyle() |
||
500 | { |
||
501 | if (!m_ScMW || m_ScMW->scriptIsRunning()) |
||
502 | return; |
||
503 | if ((m_haveDoc) && (m_haveItem)) |
||
504 | { |
||
505 | if (lineType->currentIndex() == 37) |
||
506 | { |
||
507 | if (m_item->dashes().count() == 0) |
||
508 | { |
||
509 | if ((m_item->lineStyle() == 0) || (m_item->lineStyle() == 1)) |
||
510 | { |
||
511 | m_item->DashValues.append(4.0 * qMax(m_item->lineWidth(), 1.0)); |
||
512 | m_item->DashValues.append(2.0 * qMax(m_item->lineWidth(), 1.0)); |
||
513 | } |
||
514 | else |
||
515 | getDashArray(m_item->lineStyle(), qMax(m_item->lineWidth(), 1.0), m_item->DashValues); |
||
516 | } |
||
517 | if (m_item->lineWidth() != 0.0) |
||
518 | dashEditor->setDashValues(m_item->dashes(), m_item->lineWidth(), m_item->dashOffset()); |
||
519 | else |
||
520 | { |
||
521 | dashEditor->setEnabled(false); |
||
522 | dashEditor->setDashValues(m_item->dashes(), 1.0, m_item->dashOffset()); |
||
523 | } |
||
524 | dashEditor->show(); |
||
525 | m_item->update(); |
||
526 | } |
||
527 | else |
||
528 | { |
||
529 | m_item->DashValues.clear(); |
||
530 | dashEditor->hide(); |
||
531 | m_doc->itemSelection_SetLineArt(static_cast<Qt::PenStyle>(lineType->currentIndex()+1)); |
||
532 | } |
||
533 | } |
||
534 | } |
||
535 | |||
536 | void PropertiesPalette_Line::handleLineJoin() |
||
537 | { |
||
538 | if (!m_ScMW || m_ScMW->scriptIsRunning()) |
||
539 | return; |
||
540 | if ((m_haveDoc) && (m_haveItem)) |
||
541 | { |
||
542 | Qt::PenJoinStyle c = Qt::MiterJoin; |
||
543 | switch (lineJoinStyle->currentIndex()) |
||
544 | { |
||
545 | case 0: |
||
546 | c = Qt::MiterJoin; |
||
547 | break; |
||
548 | case 1: |
||
549 | c = Qt::BevelJoin; |
||
550 | break; |
||
551 | case 2: |
||
552 | c = Qt::RoundJoin; |
||
553 | break; |
||
554 | } |
||
555 | m_doc->itemSelection_SetLineJoin(c); |
||
556 | } |
||
557 | } |
||
558 | |||
559 | void PropertiesPalette_Line::handleLineEnd() |
||
560 | { |
||
561 | if (!m_ScMW || m_ScMW->scriptIsRunning()) |
||
562 | return; |
||
563 | if ((m_haveDoc) && (m_haveItem)) |
||
564 | { |
||
565 | Qt::PenCapStyle c = Qt::FlatCap; |
||
566 | switch (lineEndStyle->currentIndex()) |
||
567 | { |
||
568 | case 0: |
||
569 | c = Qt::FlatCap; |
||
570 | break; |
||
571 | case 1: |
||
572 | c = Qt::SquareCap; |
||
573 | break; |
||
574 | case 2: |
||
575 | c = Qt::RoundCap; |
||
576 | break; |
||
577 | } |
||
578 | m_doc->itemSelection_SetLineEnd(c); |
||
579 | } |
||
580 | } |
||
581 | |||
582 | void PropertiesPalette_Line::handleLineMode() |
||
583 | { |
||
584 | if (!m_ScMW || m_ScMW->scriptIsRunning()) |
||
585 | return; |
||
586 | m_lineMode = (lineMode->currentIndex() == 1); |
||
587 | emit lineModeChanged(lineMode->currentIndex()); |
||
588 | } |
||
589 | |||
590 | void PropertiesPalette_Line::handleStartArrow(int id) |
||
591 | { |
||
592 | if (!m_haveDoc || !m_haveItem || !m_ScMW || m_ScMW->scriptIsRunning()) |
||
593 | return; |
||
594 | m_doc->itemSelection_ApplyArrowHead(id,-1); |
||
595 | } |
||
596 | |||
597 | void PropertiesPalette_Line::handleEndArrow(int id) |
||
598 | { |
||
599 | if (!m_haveDoc || !m_haveItem || !m_ScMW || m_ScMW->scriptIsRunning()) |
||
600 | return; |
||
601 | m_doc->itemSelection_ApplyArrowHead(-1, id); |
||
602 | } |
||
603 | |||
17420 | fschmid | 604 | void PropertiesPalette_Line::handleStartArrowScale(double sc) |
16546 | jghali | 605 | { |
606 | if (!m_haveDoc || !m_haveItem || !m_ScMW || m_ScMW->scriptIsRunning()) |
||
607 | return; |
||
17420 | fschmid | 608 | m_doc->itemSelection_ApplyArrowScale(static_cast<int>(sc), -1, NULL); |
16546 | jghali | 609 | } |
610 | |||
17420 | fschmid | 611 | void PropertiesPalette_Line::handleEndArrowScale(double sc) |
16546 | jghali | 612 | { |
613 | if (!m_haveDoc || !m_haveItem || !m_ScMW || m_ScMW->scriptIsRunning()) |
||
614 | return; |
||
17420 | fschmid | 615 | m_doc->itemSelection_ApplyArrowScale(-1, static_cast<int>(sc), NULL); |
16546 | jghali | 616 | } |
617 | |||
618 | void PropertiesPalette_Line::handleDashChange() |
||
619 | { |
||
620 | if (!m_ScMW || m_ScMW->scriptIsRunning()) |
||
621 | return; |
||
622 | if ((m_haveDoc) && (m_haveItem)) |
||
623 | { |
||
624 | if (m_item->lineWidth() != 0.0) |
||
625 | { |
||
626 | m_item->setDashes(dashEditor->getDashValues(m_item->lineWidth())); |
||
627 | m_item->setDashOffset(dashEditor->Offset->value() * m_item->lineWidth()); |
||
628 | } |
||
629 | m_item->update(); |
||
630 | } |
||
631 | } |
||
632 | |||
633 | void PropertiesPalette_Line::handleLineStyle(QListWidgetItem *widgetItem) |
||
634 | { |
||
635 | if (!m_doc || !m_ScMW || m_ScMW->scriptIsRunning() || !widgetItem) |
||
636 | return; |
||
637 | bool setter = (widgetItem->listWidget()->currentRow() == 0); |
||
638 | m_doc->itemSelection_SetNamedLineStyle(setter ? QString("") : widgetItem->text()); |
||
639 | lineType->setEnabled(setter); |
||
640 | lineWidth->setEnabled(setter); |
||
641 | lineJoinStyle->setEnabled(setter); |
||
642 | lineEndStyle->setEnabled(setter); |
||
643 | } |
||
644 | |||
645 | void PropertiesPalette_Line::languageChange() |
||
646 | { |
||
647 | int oldLineStyle = lineType->currentIndex(); |
||
648 | lineType->clear(); |
||
649 | lineType->updateList(); |
||
650 | lineType->addItem( tr("Custom")); |
||
651 | lineType->setCurrentIndex(oldLineStyle); |
||
652 | int oldLineMode=lineMode->currentIndex(); |
||
653 | lineMode->clear(); |
||
654 | lineMode->addItem( tr("Left Point")); |
||
655 | lineMode->addItem( tr("End Points")); |
||
656 | lineMode->setCurrentIndex(oldLineMode); |
||
657 | lineModeLabel->setText( tr("&Basepoint:")); |
||
658 | lineTypeLabel->setText( tr("T&ype of Line:")); |
||
659 | startArrowLabel->setText( tr("Start Arrow:")); |
||
660 | endArrowLabel->setText( tr("End Arrow:")); |
||
661 | startArrowScaleLabel->setText( tr("Scaling:")); |
||
662 | endArrowScaleLabel->setText( tr("Scaling:")); |
||
663 | if (m_haveDoc) |
||
664 | { |
||
665 | int arrowItem = startArrow->currentIndex(); |
||
666 | startArrow->rebuildList(&m_doc->arrowStyles()); |
||
667 | startArrow->setCurrentIndex(arrowItem); |
||
668 | arrowItem = endArrow->currentIndex(); |
||
669 | endArrow->rebuildList(&m_doc->arrowStyles()); |
||
670 | endArrow->setCurrentIndex(arrowItem); |
||
671 | } |
||
672 | lineWidthLabel->setText( tr("Line &Width:")); |
||
673 | lineJoinLabel->setText( tr("Ed&ges:")); |
||
674 | |||
675 | int oldLJoinStyle=lineJoinStyle->currentIndex(); |
||
676 | lineJoinStyle->clear(); |
||
677 | lineJoinStyle->addItem(loadIcon("16/stroke-join-miter.png"), tr("Miter Join")); |
||
678 | lineJoinStyle->addItem(loadIcon("16/stroke-join-bevel.png"), tr("Bevel Join")); |
||
679 | lineJoinStyle->addItem(loadIcon("16/stroke-join-round.png"), tr("Round Join")); |
||
680 | lineJoinStyle->setCurrentIndex(oldLJoinStyle); |
||
681 | |||
682 | int oldLEndStyle=lineEndStyle->currentIndex(); |
||
683 | lineEndStyle->clear(); |
||
684 | lineEndStyle->addItem(loadIcon("16/stroke-cap-butt.png"), tr("Flat Cap")); |
||
685 | lineEndStyle->addItem(loadIcon("16/stroke-cap-square.png"), tr("Square Cap")); |
||
686 | lineEndStyle->addItem(loadIcon("16/stroke-cap-round.png"), tr("Round Cap")); |
||
687 | lineEndStyle->setCurrentIndex(oldLEndStyle); |
||
688 | lineEndLabel->setText( tr("&Endings:")); |
||
689 | |||
690 | QString pctSuffix = tr(" %"); |
||
691 | startArrowScale->setSuffix(pctSuffix); |
||
692 | endArrowScale->setSuffix(pctSuffix); |
||
693 | |||
694 | QString ptSuffix = tr(" pt"); |
||
695 | QString suffix = (m_doc) ? unitGetSuffixFromIndex(m_doc->unitIndex()) : ptSuffix; |
||
696 | |||
697 | lineWidth->setSuffix(suffix); |
||
698 | lineWidth->setSpecialValueText( tr("Hairline")); |
||
699 | |||
700 | if(lineStyles->count() > 0) |
||
701 | lineStyles->item(0)->setText( tr("No Style") ); |
||
702 | |||
703 | lineMode->setToolTip( tr("Change settings for left or end points")); |
||
704 | lineType->setToolTip( tr("Pattern of line")); |
||
705 | lineWidth->setToolTip( tr("Thickness of line")); |
||
706 | lineJoinStyle->setToolTip( tr("Type of line joins")); |
||
707 | lineEndStyle->setToolTip( tr("Type of line end")); |
||
708 | lineStyles->setToolTip( tr("Line style of current object")); |
||
709 | startArrow->setToolTip( tr("Arrow head style for start of line")); |
||
710 | endArrow->setToolTip( tr("Arrow head style for end of line")); |
||
711 | startArrowScale->setToolTip( tr("Arrow head scale for start of line")); |
||
712 | endArrowScale->setToolTip( tr("Arrow head scale for end of line")); |
||
713 | } |
||
714 | |||
715 | void PropertiesPalette_Line::unitChange() |
||
716 | { |
||
717 | if (!m_doc) |
||
718 | return; |
||
719 | |||
720 | m_unitRatio = m_doc->unitRatio(); |
||
721 | m_unitIndex = m_doc->unitIndex(); |
||
722 | |||
723 | lineWidth->blockSignals(true); |
||
724 | lineWidth->setNewUnit( m_unitIndex ); |
||
725 | lineWidth->blockSignals(false); |
||
726 | } |