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 #include "shadebutton.h"
8 #include "query.h"
9
10
ShadeButton(QWidget * parent)11 ShadeButton::ShadeButton(QWidget* parent) : QToolButton(parent)
12 {
13 QString tmp[] = {"0 %", "10 %", "20 %", "30 %", "40 %", "50 %", "60 %", "70 %", "80 %", "90 %", "100 %"};
14 size_t array = sizeof(tmp) / sizeof(*tmp);
15 FillSh = new QMenu();
16 FillSh->addAction( tr("Other..."))->setCheckable(true);
17 for (uint a = 0; a < array; ++a)
18 FillSh->addAction(tmp[a])->setCheckable(true);
19 setMenu(FillSh);
20 setPopupMode(QToolButton::InstantPopup);
21 setText("100 %");
22 FillSh->actions().at(11)->setChecked(true);
23 connect( FillSh, SIGNAL(triggered(QAction *)), this, SLOT(setShade(QAction *)));
24 }
25
setShade(QAction * act)26 void ShadeButton::setShade(QAction *act)
27 {
28 bool ok = false;
29 int a;
30 int c;
31 int b = 100;
32 for (a = 0; a < FillSh->actions().count(); ++a)
33 {
34 FillSh->actions().at(a)->setChecked(false);
35 }
36 act->setChecked(true);
37 QList<QAction*> actList = FillSh->actions();
38 c = actList.indexOf(act);
39 if (c < 0)
40 return;
41 if (c > 0)
42 b = (c-1) * 10;
43
44 if (b > 100)
45 return; // no need for > 100%, fix needed by SM, Riku
46
47 if (c == 0)
48 {
49 Query dia(this, "New", 1, tr("&Shade:"), tr("Shade"));
50 if (dia.exec())
51 {
52 c = dia.getEditText().toInt(&ok);
53 if (ok)
54 b = qMax(qMin(c, 100),0);
55 else
56 b = 100;
57 }
58 else
59 return;
60 }
61 setText(QString::number(b)+" %");
62 emit clicked();
63 }
64
getValue()65 int ShadeButton::getValue()
66 {
67 int l = text().length();
68 QString tx = text().remove(l-2,2);
69 return tx.toInt();
70 }
71
setValue(int val)72 void ShadeButton::setValue(int val)
73 {
74 QList<QAction*> fillActions = FillSh->actions();
75 for (int a = 0; a < fillActions.count(); ++a)
76 {
77 fillActions[a]->setChecked(false);
78 }
79 if ((val % 10) == 0)
80 fillActions[val / 10 + 1]->setChecked(true);
81 else
82 fillActions[0]->setChecked(true);
83 setText(QString::number(val)+" %");
84 }
85
86
87