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                           transparencypalette.cpp  -  description
9                              -------------------
10     begin                : Tue Nov 17 2009
11     copyright            : (C) 2009 by Franz Schmid
12     email                : Franz.Schmid@altmuehlnet.de
13  ***************************************************************************/
14 
15 /***************************************************************************
16  *                                                                         *
17  *   This program is free software; you can redistribute it and/or modify  *
18  *   it under the terms of the GNU General Public License as published by  *
19  *   the Free Software Foundation; either version 2 of the License, or     *
20  *   (at your option) any later version.                                   *
21  *                                                                         *
22  ***************************************************************************/
23 
24 #include "transparencypalette.h"
25 #include "sccolorengine.h"
26 #include "scpainter.h"
27 #include "scpattern.h"
28 #include "scribus.h"
29 #include "iconmanager.h"
30 #include "util.h"
31 #include "util_math.h"
32 
TransparencyPalette(QWidget * parent)33 TransparencyPalette::TransparencyPalette(QWidget* parent) : QWidget(parent)
34 {
35 	TGradDia = new GradientVectorDialog(this->parentWidget());
36 	TGradDia->hide();
37 	setupUi(this);
38 	editLineSelector->setIcon(IconManager::instance().loadIcon("16/color-stroke.png"));
39 	editFillSelector->setIcon(IconManager::instance().loadIcon("16/color-fill.png"));
40 	editFillSelector->setChecked(true);
41 	strokeOpacity->setDecimals(0);
42 	fillOpacity->setDecimals(0);
43 	editFillSelectorButton();
44 
45 	connect(editLineSelector, SIGNAL(clicked()), this, SLOT(editLineSelectorButton()));
46 	connect(editFillSelector, SIGNAL(clicked()), this, SLOT(editFillSelectorButton()));
47 	connect(strokeOpacity, SIGNAL(valueChanged(double)), this, SLOT(slotTransS(double)));
48 	connect(fillOpacity, SIGNAL(valueChanged(double)), this, SLOT(slotTransF(double)));
49 	connect(blendModeFill, SIGNAL(activated(int)), this, SIGNAL(NewBlend(int)));
50 	connect(blendModeStroke, SIGNAL(activated(int)), this, SIGNAL(NewBlendS(int)));
51 	connect(namedGradient, SIGNAL(activated(const QString &)), this, SLOT(setNamedGradient(const QString &)));
52 	connect(gradEdit, SIGNAL(gradientChanged()), this, SIGNAL(gradientChanged()));
53 	connect(gradEditButton, SIGNAL(clicked()), this, SLOT(editGradientVector()));
54 	connect(TGradDia, SIGNAL(NewSpecial(double,double,double,double,double,double,double,double,double,double)), this, SIGNAL(NewSpecial(double,double,double,double,double,double,double,double,double,double)));
55 	connect(TGradDia, SIGNAL(paletteShown(bool)), this, SLOT(setActiveGradDia(bool)));
56 	connect(gradientType, SIGNAL(activated(int)), this, SLOT(slotGradType(int)));
57 	connect(tabWidget, SIGNAL(currentChanged(int)), this, SLOT(slotGrad(int)));
58 	connect(patternBox, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(selectPattern(QListWidgetItem*)));
59 	connect(editPatternProps, SIGNAL(clicked()), this, SLOT(changePatternProps()));
60 	connect(transpCalcGradient, SIGNAL(clicked()), this, SLOT(switchGradientMode()));
61 	connect(transpCalcPattern, SIGNAL(clicked()), this, SLOT(switchPatternMode()));
62 	connect(usePatternInverted, SIGNAL(clicked()), this, SLOT(switchPatternMode()));
63 }
64 
connectSignals()65 void TransparencyPalette::connectSignals()
66 {
67 	connect(gradEdit, SIGNAL(gradientChanged()), this, SIGNAL(gradientChanged()));
68 	connect(namedGradient, SIGNAL(activated(const QString &)), this, SLOT(setNamedGradient(const QString &)));
69 	connect(tabWidget, SIGNAL(currentChanged(int)), this, SLOT(slotGrad(int)));
70 	connect(gradientType, SIGNAL(activated(int)), this, SLOT(slotGradType(int)));
71 	connect(transpCalcGradient, SIGNAL(clicked()), this, SLOT(switchGradientMode()));
72 	connect(transpCalcPattern, SIGNAL(clicked()), this, SLOT(switchPatternMode()));
73 	connect(usePatternInverted, SIGNAL(clicked()), this, SLOT(switchPatternMode()));
74 }
75 
disconnectSignals()76 void TransparencyPalette::disconnectSignals()
77 {
78 	disconnect(gradEdit, SIGNAL(gradientChanged()), this, SIGNAL(gradientChanged()));
79 	disconnect(namedGradient, SIGNAL(activated(const QString &)), this, SLOT(setNamedGradient(const QString &)));
80 	disconnect(tabWidget, SIGNAL(currentChanged(int)), this, SLOT(slotGrad(int)));
81 	disconnect(gradientType, SIGNAL(activated(int)), this, SLOT(slotGradType(int)));
82 	disconnect(transpCalcGradient, SIGNAL(clicked()), this, SLOT(switchGradientMode()));
83 	disconnect(transpCalcPattern, SIGNAL(clicked()), this, SLOT(switchPatternMode()));
84 	disconnect(usePatternInverted, SIGNAL(clicked()), this, SLOT(switchPatternMode()));
85 }
86 
setCurrentItem(PageItem * item)87 void TransparencyPalette::setCurrentItem(PageItem* item)
88 {
89 	currentItem = item;
90 	disconnectSignals();
91 
92 	if (!currentItem || !currentDoc)
93 		return;
94 
95 	if (currentItem->isGroup())
96 		hideSelectionButtons();
97 	else
98 		showSelectionButtons();
99 
100 	setActTrans(currentItem->fillTransparency(), currentItem->lineTransparency());
101 	setActBlend(currentItem->fillBlendmode(), currentItem->lineBlendmode());
102 	gradEdit->setGradient(currentItem->mask_gradient);
103 	if (!currentItem->gradientMask().isEmpty())
104 	{
105 		setCurrentComboItem(namedGradient, currentItem->gradientMask());
106 		gradEdit->setGradientEditable(false);
107 	}
108 	else
109 	{
110 		namedGradient->setCurrentIndex(0);
111 		gradEdit->setGradientEditable(true);
112 	}
113 	if (currentItem->maskType() == 0)
114 		tabWidget->setCurrentIndex(0);
115 	else if ((currentItem->maskType() == 1) || (currentItem->maskType() == 2) || (currentItem->maskType() == 4) || (currentItem->maskType() == 5))
116 		tabWidget->setCurrentIndex(1);
117 	else
118 		tabWidget->setCurrentIndex(2);
119 	if (patternList->isEmpty())
120 		tabWidget->setTabEnabled(2, false);
121 	else
122 		tabWidget->setTabEnabled(2, true);
123 	transpCalcGradient->setChecked(false);
124 	transpCalcPattern->setChecked(false);
125 	usePatternInverted->setChecked(false);
126 	if ((currentItem->maskType() == 4) || (currentItem->maskType() == 5))
127 		transpCalcGradient->setChecked(true);
128 	if ((currentItem->maskType() == 6) || (currentItem->maskType() == 7))
129 		transpCalcPattern->setChecked(true);
130 	if ((currentItem->maskType() == 7) || (currentItem->maskType() == 8))
131 		usePatternInverted->setChecked(true);
132 	if ((currentItem->maskType() == 1) || (currentItem->maskType() == 4))
133 		gradientType->setCurrentIndex(0);
134 	else if ((currentItem->maskType() == 2) || (currentItem->maskType() == 5))
135 		gradientType->setCurrentIndex(1);
136 	if(TGradDia && gradEditButton->isChecked())
137 		TGradDia->setValues(currentItem->GrMaskStartX, currentItem->GrMaskStartY, currentItem->GrMaskEndX, currentItem->GrMaskEndY, currentItem->GrMaskFocalX, currentItem->GrMaskFocalY, currentItem->GrMaskScale, currentItem->GrMaskSkew, 0, 0);
138 	double patternScaleX, patternScaleY, patternOffsetX, patternOffsetY, patternRotation, patternSkewX, patternSkewY;
139 	bool mirrorX, mirrorY;
140 	currentItem->maskTransform(patternScaleX, patternScaleY, patternOffsetX, patternOffsetY, patternRotation, patternSkewX, patternSkewY);
141 	currentItem->maskFlip(mirrorX, mirrorY);
142 	setActPattern(currentItem->patternMask(), patternScaleX, patternScaleY, patternOffsetX, patternOffsetY, patternRotation, patternSkewX, patternSkewY, mirrorX, mirrorY);
143 
144 	connectSignals();
145 }
146 
setDocument(ScribusDoc * doc)147 void TransparencyPalette::setDocument(ScribusDoc* doc)
148 {
149 	this->disconnect(SIGNAL(NewTrans(double)));
150 	this->disconnect(SIGNAL(NewTransS(double)));
151 	this->disconnect(SIGNAL(NewGradient(int)));
152 	this->disconnect(SIGNAL(NewBlend(int)));
153 	this->disconnect(SIGNAL(NewBlendS(int)));
154 	this->disconnect(SIGNAL(NewPattern(QString)));
155 	this->disconnect(SIGNAL(NewPatternProps(double,double,double,double,double,double,double,bool,bool)));
156 
157 	if (currentDoc)
158 	{
159 		disconnect(currentDoc->scMW(), SIGNAL(UpdateRequest(int)), this, nullptr);
160 	}
161 
162 	currentDoc = doc;
163 
164 	if (doc != nullptr)
165 	{
166 		gradEdit->setColors(doc->PageColors);
167 		currentUnit = doc->unitIndex();
168 
169 		updateColorList();
170 
171 		connect(this, SIGNAL(NewTrans(double)), doc, SLOT(itemSelection_SetItemFillTransparency(double)));
172 		connect(this, SIGNAL(NewTransS(double)), doc, SLOT(itemSelection_SetItemLineTransparency(double)));
173 		connect(this, SIGNAL(NewBlend(int)), doc, SLOT(itemSelection_SetItemFillBlend(int)));
174 		connect(this, SIGNAL(NewBlendS(int)), doc, SLOT(itemSelection_SetItemLineBlend(int)));
175 		connect(this, SIGNAL(NewGradient(int)), doc, SLOT(itemSelection_SetItemGradMask(int)));
176 		connect(this, SIGNAL(NewPattern(QString)), doc, SLOT(itemSelection_SetItemPatternMask(QString)));
177 		connect(this, SIGNAL(NewPatternProps(double,double,double,double,double,double,double,bool,bool)), doc, SLOT(itemSelection_SetItemPatternMaskProps(double,double,double,double,double,double,double,bool,bool)));
178 		connect(doc->scMW(), SIGNAL(UpdateRequest(int)), this, SLOT(handleUpdateRequest(int)));
179 	}
180 }
181 
handleUpdateRequest(int updateFlags)182 void TransparencyPalette::handleUpdateRequest(int updateFlags)
183 {
184 	if (updateFlags & reqColorsUpdate)
185 		updateColorList();
186 }
187 
updateColorList()188 void TransparencyPalette::updateColorList()
189 {
190 	if (!currentDoc)
191 		return;
192 
193 	if (currentItem)
194 		disconnectSignals();
195 
196 	this->setColors(currentDoc->PageColors);
197 	this->setPatterns(&currentDoc->docPatterns);
198 	this->setGradients(&currentDoc->docGradients);
199 
200 	if (currentItem)
201 		setCurrentItem(currentItem);
202 }
203 
showSelectionButtons()204 void TransparencyPalette::showSelectionButtons()
205 {
206 	editLineSelector->show();
207 	editLineSelector->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
208 	editFillSelector->show();
209 	editFillSelector->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
210 }
hideSelectionButtons()211 void TransparencyPalette::hideSelectionButtons()
212 {
213 	editLineSelector->hide();
214 	editLineSelector->setSizePolicy(QSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored));
215 	editFillSelector->hide();
216 	editFillSelector->setSizePolicy(QSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored));
217 	stackedWidget->setCurrentIndex(1);
218 	editFillSelector->setChecked(true);
219 }
220 
updateFromItem()221 void TransparencyPalette::updateFromItem()
222 {
223 	setCurrentItem(currentItem);
224 }
225 
updateCList()226 void TransparencyPalette::updateCList()
227 {
228 	gradEdit->setColors(colorList);
229 }
230 
updateGradientList()231 void TransparencyPalette::updateGradientList()
232 {
233 	disconnect(namedGradient, SIGNAL(activated(const QString &)), this, SLOT(setNamedGradient(const QString &)));
234 	namedGradient->clear();
235 	namedGradient->setIconSize(QSize(48, 12));
236 	namedGradient->addItem( tr("Custom"));
237 	QStringList patK = gradientList->keys();
238 	patK.sort();
239 	for (int i = 0; i < patK.count(); i++)
240 	{
241 		VGradient gr = gradientList->value(patK[i]);
242 		QImage pixm(48, 12, QImage::Format_ARGB32_Premultiplied);
243 		QPainter pb;
244 		QBrush b(QColor(205,205,205), IconManager::instance().loadPixmap("testfill.png"));
245 		pb.begin(&pixm);
246 		pb.fillRect(0, 0, 48, 12, b);
247 		pb.end();
248 		ScPainter *p = new ScPainter(&pixm, 48, 12);
249 		p->setPen(Qt::black, 1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin);
250 		p->setFillMode(ScPainter::Gradient);
251 		p->fill_gradient = gr;
252 		p->setGradient(VGradient::linear, FPoint(0,6), FPoint(48, 6), FPoint(0,0), 1, 0);
253 		p->drawRect(0, 0, 48, 12);
254 		p->end();
255 		delete p;
256 		QPixmap pm;
257 		pm = QPixmap::fromImage(pixm);
258 		namedGradient->addItem(pm, patK[i]);
259 	}
260 	connect(namedGradient, SIGNAL(activated(const QString&)), this, SLOT(setNamedGradient(const QString&)));
261 }
262 
setGradients(QHash<QString,VGradient> * docGradients)263 void TransparencyPalette::setGradients(QHash<QString, VGradient> *docGradients)
264 {
265 	gradientList = docGradients;
266 	updateGradientList();
267 }
268 
setColors(const ColorList & newColorList)269 void TransparencyPalette::setColors(const ColorList& newColorList)
270 {
271 	colorList.clear();
272 	colorList = newColorList;
273 	updateCList();
274 }
275 
slotGrad(int number)276 void TransparencyPalette::slotGrad(int number)
277 {
278 	if (number == 1)
279 	{
280 		disconnect(namedGradient, SIGNAL(activated(const QString &)), this, SLOT(setNamedGradient(const QString &)));
281 		if (!currentItem->gradientMask().isEmpty())
282 		{
283 			setCurrentComboItem(namedGradient, currentItem->gradientMask());
284 			gradEdit->setGradient(gradientList->value(currentItem->gradientMask()));
285 			gradEdit->setGradientEditable(false);
286 		}
287 		else
288 		{
289 			namedGradient->setCurrentIndex(0);
290 			gradEdit->setGradient(currentItem->mask_gradient);
291 			gradEdit->setGradientEditable(true);
292 		}
293 		if (gradientType->currentIndex() == 0)
294 		{
295 			if (transpCalcGradient->isChecked())
296 				emit NewGradient(GradMask_LinearLumAlpha);
297 			else
298 				emit NewGradient(GradMask_Linear);
299 		}
300 		else
301 		{
302 			if (transpCalcGradient->isChecked())
303 				emit NewGradient(GradMask_RadialLumAlpha);
304 			else
305 				emit NewGradient(GradMask_Radial);
306 		}
307 		connect(namedGradient, SIGNAL(activated(const QString &)), this, SLOT(setNamedGradient(const QString &)));
308 	}
309 	else if (number == 2)
310 	{
311 		if (transpCalcPattern->isChecked())
312 		{
313 			if (usePatternInverted->isChecked())
314 				emit NewGradient(GradMask_PatternLumAlphaInverted);
315 			else
316 				emit NewGradient(GradMask_PatternLumAlpha);
317 		}
318 		else
319 		{
320 			if (usePatternInverted->isChecked())
321 				emit NewGradient(GradMask_PatternInverted);
322 			else
323 				emit NewGradient(GradMask_Pattern);
324 		}
325 	}
326 	else
327 		emit NewGradient(GradMask_None);
328 }
329 
slotGradType(int type)330 void TransparencyPalette::slotGradType(int type)
331 {
332 	if (type == 0)
333 	{
334 		if (transpCalcGradient->isChecked())
335 			emit NewGradient(GradMask_LinearLumAlpha);
336 		else
337 			emit NewGradient(GradMask_Linear);
338 	}
339 	else
340 	{
341 		if (transpCalcGradient->isChecked())
342 			emit NewGradient(GradMask_RadialLumAlpha);
343 		else
344 			emit NewGradient(GradMask_Radial);
345 	}
346 }
347 
setNamedGradient(const QString & name)348 void TransparencyPalette::setNamedGradient(const QString &name)
349 {
350 	if (namedGradient->currentIndex() == 0)
351 	{
352 		gradEdit->setGradient(currentItem->mask_gradient);
353 		currentItem->setGradientMask("");
354 		gradEdit->setGradientEditable(true);
355 	}
356 	else
357 	{
358 		gradEdit->setGradient(gradientList->value(name));
359 		gradEdit->setGradientEditable(false);
360 		currentItem->setGradientMask(name);
361 	}
362 	if (gradientType->currentIndex() == 0)
363 	{
364 		if (transpCalcGradient->isChecked())
365 			emit NewGradient(GradMask_LinearLumAlpha);
366 		else
367 			emit NewGradient(GradMask_Linear);
368 	}
369 	else
370 	{
371 		if (transpCalcGradient->isChecked())
372 			emit NewGradient(GradMask_RadialLumAlpha);
373 		else
374 			emit NewGradient(GradMask_Radial);
375 	}
376 }
377 
switchGradientMode()378 void TransparencyPalette::switchGradientMode()
379 {
380 	if (gradientType->currentIndex() == 0)
381 	{
382 		if (transpCalcGradient->isChecked())
383 			emit NewGradient(GradMask_LinearLumAlpha);
384 		else
385 			emit NewGradient(GradMask_Linear);
386 	}
387 	else
388 	{
389 		if (transpCalcGradient->isChecked())
390 			emit NewGradient(GradMask_RadialLumAlpha);
391 		else
392 			emit NewGradient(GradMask_Radial);
393 	}
394 }
395 
switchPatternMode()396 void TransparencyPalette::switchPatternMode()
397 {
398 	if (transpCalcPattern->isChecked())
399 	{
400 		if (usePatternInverted->isChecked())
401 			emit NewGradient(GradMask_PatternLumAlphaInverted);
402 		else
403 			emit NewGradient(GradMask_PatternLumAlpha);
404 	}
405 	else
406 	{
407 		if (usePatternInverted->isChecked())
408 			emit NewGradient(GradMask_PatternInverted);
409 		else
410 			emit NewGradient(GradMask_Pattern);
411 	}
412 }
413 
editGradientVector()414 void TransparencyPalette::editGradientVector()
415 {
416 	if (gradEditButton->isChecked())
417 	{
418 		TGradDia->unitChange(currentDoc->unitIndex());
419 		TGradDia->setValues(currentItem->GrMaskStartX, currentItem->GrMaskStartY, currentItem->GrMaskEndX, currentItem->GrMaskEndY, currentItem->GrMaskFocalX, currentItem->GrMaskFocalY, currentItem->GrMaskScale, currentItem->GrMaskSkew, 0, 0);
420 		if ((currentItem->GrMask == GradMask_Linear) || (currentItem->GrMask == GradMask_LinearLumAlpha))
421 			TGradDia->selectLinear();
422 		else
423 			TGradDia->selectRadial();
424 		TGradDia->show();
425 	}
426 	else
427 	{
428 		TGradDia->hide();
429 	}
430 	emit editGradient();
431 }
432 
setActiveGradDia(bool active)433 void TransparencyPalette::setActiveGradDia(bool active)
434 {
435 	if (!active)
436 	{
437 		gradEditButton->setChecked(false);
438 		emit editGradient();
439 	}
440 }
441 
setSpecialGradient(double x1,double y1,double x2,double y2,double fx,double fy,double sg,double sk)442 void TransparencyPalette::setSpecialGradient(double x1, double y1, double x2, double y2, double fx, double fy, double sg, double sk)
443 {
444 	if (TGradDia)
445 		TGradDia->setValues(x1, y1, x2, y2, fx, fy, sg, sk, 0, 0);
446 }
447 
hideEditedPatterns(QStringList names)448 void TransparencyPalette::hideEditedPatterns(QStringList names)
449 {
450 	for (int a = 0; a < names.count(); a++)
451 	{
452 		QList<QListWidgetItem*> items = patternBox->findItems(names[a], Qt::MatchExactly);
453 		if (items.count() > 0)
454 			items[0]->setHidden(true);
455 	}
456 }
457 
updatePatternList()458 void TransparencyPalette::updatePatternList()
459 {
460 	disconnect(patternBox, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(selectPattern(QListWidgetItem*)));
461 	patternBox->clear();
462 	patternBox->setIconSize(QSize(48, 48));
463 	QStringList patK = patternList->keys();
464 	patK.sort();
465 	for (int a = 0; a < patK.count(); a++)
466 	{
467 		ScPattern sp = patternList->value(patK[a]);
468 		QPixmap pm;
469 		if (sp.getPattern()->width() >= sp.getPattern()->height())
470 			pm=QPixmap::fromImage(sp.getPattern()->scaledToWidth(48, Qt::SmoothTransformation));
471 		else
472 			pm=QPixmap::fromImage(sp.getPattern()->scaledToHeight(48, Qt::SmoothTransformation));
473 		QPixmap pm2(48, 48);
474 		pm2.fill(palette().color(QPalette::Base));
475 		QPainter p;
476 		p.begin(&pm2);
477 		p.drawPixmap(24 - pm.width() / 2, 24 - pm.height() / 2, pm);
478 		p.end();
479 		QListWidgetItem *item = new QListWidgetItem(pm2, patK[a], patternBox);
480 		item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
481 	}
482 	patternBox->clearSelection();
483 	connect(patternBox, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(selectPattern(QListWidgetItem*)));
484 }
485 
setPatterns(QHash<QString,ScPattern> * docPatterns)486 void TransparencyPalette::setPatterns(QHash<QString, ScPattern> *docPatterns)
487 {
488 	patternList = docPatterns;
489 	updatePatternList();
490 }
491 
selectPattern(QListWidgetItem * c)492 void TransparencyPalette::selectPattern(QListWidgetItem *c)
493 {
494 	if (c == nullptr)
495 		return;
496 	emit NewPattern(c->text());
497 }
498 
setActPattern(const QString & pattern,double scaleX,double scaleY,double offsetX,double offsetY,double rotation,double skewX,double skewY,bool mirrorX,bool mirrorY)499 void TransparencyPalette::setActPattern(const QString& pattern, double scaleX, double scaleY, double offsetX, double offsetY, double rotation, double skewX, double skewY, bool mirrorX, bool mirrorY)
500 {
501 	disconnect(patternBox, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(selectPattern(QListWidgetItem*)));
502 	QList<QListWidgetItem*> itl = patternBox->findItems(pattern, Qt::MatchExactly);
503 	if (itl.count() != 0)
504 	{
505 		QListWidgetItem *it = itl[0];
506 		patternBox->setCurrentItem(it);
507 	}
508 	else
509 		patternBox->clearSelection();
510 	m_Pattern_scaleX = scaleX;
511 	m_Pattern_scaleY = scaleX;
512 	m_Pattern_offsetX = offsetX;
513 	m_Pattern_offsetY = offsetY;
514 	m_Pattern_rotation = rotation;
515 	m_Pattern_skewX = skewX;
516 	m_Pattern_skewY = skewY;
517 	m_Pattern_mirrorX = mirrorX;
518 	m_Pattern_mirrorY = mirrorY;
519 	connect(patternBox, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(selectPattern(QListWidgetItem*)));
520 }
521 
changePatternProps()522 void TransparencyPalette::changePatternProps()
523 {
524 	PatternPropsDialog *dia = new PatternPropsDialog(this, currentUnit, false);
525 	dia->spinXscaling->setValue(m_Pattern_scaleX);
526 	dia->spinYscaling->setValue(m_Pattern_scaleY);
527 	if (m_Pattern_scaleX == m_Pattern_scaleY)
528 		dia->keepScaleRatio->setChecked(true);
529 	dia->spinXoffset->setValue(m_Pattern_offsetX);
530 	dia->spinYoffset->setValue(m_Pattern_offsetY);
531 	dia->spinAngle->setValue(m_Pattern_rotation);
532 	double asina = atan(m_Pattern_skewX);
533 	dia->spinXSkew->setValue(asina / (M_PI / 180.0));
534 	double asinb = atan(m_Pattern_skewY);
535 	dia->spinYSkew->setValue(asinb / (M_PI / 180.0));
536 	dia->FlipH->setChecked(m_Pattern_mirrorX);
537 	dia->FlipV->setChecked(m_Pattern_mirrorY);
538 	connect(dia, SIGNAL(NewPatternProps(double,double,double,double,double,double,double,bool,bool)), this, SIGNAL(NewPatternProps(double,double,double,double,double,double,double,bool,bool)));
539 	dia->exec();
540 	m_Pattern_scaleX = dia->spinXscaling->value();
541 	m_Pattern_scaleY = dia->spinYscaling->value();
542 	m_Pattern_offsetX = dia->spinXoffset->value();
543 	m_Pattern_offsetY = dia->spinYoffset->value();
544 	m_Pattern_rotation = dia->spinAngle->value();
545 	double a    = M_PI / 180.0 * dia->spinXSkew->value();
546 	double b    = M_PI / 180.0 * dia->spinYSkew->value();
547 	double sina = tan(a);
548 	double sinb = tan(b);
549 	m_Pattern_skewX = sina;
550 	m_Pattern_skewY = sinb;
551 	m_Pattern_mirrorX = dia->FlipH->isChecked();
552 	m_Pattern_mirrorY = dia->FlipV->isChecked();
553 	delete dia;
554 }
555 
setActTrans(double val,double val2)556 void TransparencyPalette::setActTrans(double val, double val2)
557 {
558 	disconnect(strokeOpacity, SIGNAL(valueChanged(double)), this, SLOT(slotTransS(double)));
559 	disconnect(fillOpacity, SIGNAL(valueChanged(double)), this, SLOT(slotTransF(double)));
560 	strokeOpacity->setValue(qRound(100 - (val2 * 100)));
561 	fillOpacity->setValue(qRound(100 - (val * 100)));
562 	connect(strokeOpacity, SIGNAL(valueChanged(double)), this, SLOT(slotTransS(double)));
563 	connect(fillOpacity, SIGNAL(valueChanged(double)), this, SLOT(slotTransF(double)));
564 }
565 
setActBlend(int val,int val2)566 void TransparencyPalette::setActBlend(int val, int val2)
567 {
568 	disconnect(blendModeFill, SIGNAL(activated(int)), this, SIGNAL(NewBlend(int)));
569 	disconnect(blendModeStroke, SIGNAL(activated(int)), this, SIGNAL(NewBlendS(int)));
570 	blendModeFill->setCurrentIndex(val);
571 	blendModeStroke->setCurrentIndex(val2);
572 	connect(blendModeFill, SIGNAL(activated(int)), this, SIGNAL(NewBlend(int)));
573 	connect(blendModeStroke, SIGNAL(activated(int)), this, SIGNAL(NewBlendS(int)));
574 }
575 
slotTransS(double val)576 void TransparencyPalette::slotTransS(double val)
577 {
578 	emit NewTransS((100 - val) / 100.0);
579 }
580 
slotTransF(double val)581 void TransparencyPalette::slotTransF(double val)
582 {
583 	emit NewTrans((100 - val) / 100.0);
584 }
585 
editLineSelectorButton()586 void TransparencyPalette::editLineSelectorButton()
587 {
588 	if (editLineSelector->isChecked())
589 	{
590 		stackedWidget->setCurrentIndex(0);
591 		editFillSelector->setChecked(false);
592 	}
593 	updateFromItem();
594 }
595 
editFillSelectorButton()596 void TransparencyPalette::editFillSelectorButton()
597 {
598 	if (editFillSelector->isChecked())
599 	{
600 		stackedWidget->setCurrentIndex(1);
601 		editLineSelector->setChecked(false);
602 	}
603 	updateFromItem();
604 }
605 
unitChange(double,double,int unitIndex)606 void TransparencyPalette::unitChange(double, double, int unitIndex)
607 {
608 	if (TGradDia)
609 		TGradDia->unitChange(unitIndex);
610 	currentUnit = unitIndex;
611 }
612 
613