Rev 1803 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1803 | subik | 1 | /* $Id: cwdialog.cpp 1804 2005-03-30 14:35:38Z subik $ */ |
1767 | subik | 2 | #include "cwdialog.h" |
3 | |||
4 | #include <qvariant.h> |
||
5 | #include <qcombobox.h> |
||
6 | #include <qheader.h> |
||
7 | #include <qlistview.h> |
||
8 | #include <qlayout.h> |
||
9 | #include <qtooltip.h> |
||
10 | #include <qwhatsthis.h> |
||
11 | #include <qpushbutton.h> |
||
12 | #include <qspinbox.h> |
||
1769 | subik | 13 | #include <qpainter.h> |
1767 | subik | 14 | |
1803 | subik | 15 | #include <prefsfile.h> |
16 | |||
17 | extern PrefsFile *prefsFile; |
||
18 | extern ScribusApp *ScApp; |
||
19 | |||
20 | ColorWheelDialog::ColorWheelDialog(QWidget* parent, const char* name, bool modal, WFlags fl) |
||
21 | : QDialog(parent, name, modal, fl) |
||
1767 | subik | 22 | { |
1803 | subik | 23 | if (!name) |
24 | setName("ColorWheelDialog"); |
||
1767 | subik | 25 | |
1803 | subik | 26 | formLayout = new QGridLayout(this, 1, 1, 11, 6, "formLayout"); |
27 | mainLayout = new QHBoxLayout(0, 0, 6, "mainLayout"); |
||
28 | wheelLayout = new QVBoxLayout(0, 0, 6, "wheelLayout"); |
||
1767 | subik | 29 | |
1803 | subik | 30 | colorWheel = new ColorWheel(this, "colorWheel"); |
1767 | subik | 31 | colorWheel->setFrameShape(QFrame::Box); |
32 | colorWheel->setMinimumSize(QSize(300, 300)); |
||
33 | colorWheel->setMaximumSize(QSize(300, 300)); |
||
34 | wheelLayout->addWidget(colorWheel); |
||
35 | colorWheel->paintWheel(QValueVector<QPoint>()); |
||
36 | |||
1769 | subik | 37 | previewLabel = new QLabel(this, "previewLabel"); |
38 | previewLabel->setFrameShape(QFrame::Box); |
||
39 | previewLabel->setMinimumSize(QSize(300, 120)); |
||
40 | previewLabel->setMaximumSize(QSize(300, 120)); |
||
41 | wheelLayout->addWidget(previewLabel); |
||
1767 | subik | 42 | |
1803 | subik | 43 | spacer1 = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding); |
1767 | subik | 44 | wheelLayout->addItem(spacer1); |
45 | mainLayout->addLayout(wheelLayout); |
||
46 | |||
1803 | subik | 47 | listLayout = new QVBoxLayout(0, 0, 6, "listLayout"); |
1767 | subik | 48 | |
49 | typeLabel = new QLabel(this, "typeLabel"); |
||
50 | listLayout->addWidget(typeLabel); |
||
1803 | subik | 51 | typeCombo = new QComboBox(FALSE, this, "typeCombo"); |
1767 | subik | 52 | listLayout->addWidget(typeCombo); |
53 | |||
1769 | subik | 54 | angleLabel = new QLabel(this, "angleLabel"); |
1803 | subik | 55 | angleLayout = new QHBoxLayout(0, 0, 6, "angleLayout"); |
1769 | subik | 56 | angleLayout->addWidget(angleLabel); |
57 | |||
58 | angleSpin = new QSpinBox(this, "angleSpin"); |
||
59 | angleSpin->setValue(15); |
||
60 | angleSpin->setMinValue(0); |
||
61 | angleSpin->setMaxValue(365); |
||
62 | angleLayout->addWidget(angleSpin); |
||
63 | listLayout->addLayout(angleLayout); |
||
64 | |||
1803 | subik | 65 | colorList = new QListView(this, "colorList"); |
1767 | subik | 66 | listLayout->addWidget(colorList); |
67 | |||
1803 | subik | 68 | buttonLayout = new QHBoxLayout(0, 0, 6, "buttonLayout"); |
1767 | subik | 69 | addButton = new QPushButton(this, "addButton"); |
70 | buttonLayout->addWidget(addButton); |
||
71 | cancelButton = new QPushButton(this, "cancelButton"); |
||
72 | buttonLayout->addWidget(cancelButton); |
||
73 | |||
74 | listLayout->addLayout(buttonLayout); |
||
75 | mainLayout->addLayout(listLayout); |
||
76 | formLayout->addLayout(mainLayout, 0, 0); |
||
77 | |||
78 | languageChange(); |
||
1803 | subik | 79 | resize(QSize(600, 480).expandedTo(minimumSizeHint())); |
80 | clearWState(WState_Polished); |
||
1767 | subik | 81 | |
82 | // setup combobox |
||
83 | typeCombo->insertItem(colorWheel->getTypeDescription(colorWheel->Monochromatic), colorWheel->Monochromatic); |
||
84 | typeCombo->insertItem(colorWheel->getTypeDescription(colorWheel->Analogous), colorWheel->Analogous); |
||
85 | typeCombo->insertItem(colorWheel->getTypeDescription(colorWheel->Complementary), colorWheel->Complementary); |
||
86 | typeCombo->insertItem(colorWheel->getTypeDescription(colorWheel->Split), colorWheel->Split); |
||
87 | typeCombo->insertItem(colorWheel->getTypeDescription(colorWheel->Triadic), colorWheel->Triadic); |
||
88 | typeCombo->insertItem(colorWheel->getTypeDescription(colorWheel->Tetradic), colorWheel->Tetradic); |
||
1803 | subik | 89 | |
90 | // preferences |
||
91 | prefs = prefsFile->getPluginContext("colorwheel"); |
||
92 | typeCombo->setCurrentItem(prefs->getInt("cw_type", 0)); |
||
93 | angleSpin->setValue(prefs->getInt("cw_angle", 15)); |
||
1804 | subik | 94 | colorWheel->angle = angleSpin->value(); |
1803 | subik | 95 | QValueVector<QPoint> vp; |
96 | int x = prefs->getInt("cw_x", 0); |
||
97 | int y = prefs->getInt("cw_y", 0); |
||
98 | vp.append(QPoint(x, y)); |
||
99 | colorWheel->actualPoint = QPoint(x, y); |
||
100 | colorWheel->actualRgb = QColor(prefs->getInt("cw_r", 0), prefs->getInt("cw_g", 0), prefs->getInt("cw_b", 0)).rgb(); |
||
101 | colorWheel->paintWheel(vp); |
||
102 | |||
103 | // actions |
||
1767 | subik | 104 | typeCombo_activated(typeCombo->currentItem()); |
1803 | subik | 105 | // signals and slots connections |
1767 | subik | 106 | connect(typeCombo, SIGNAL(activated(int)), this, SLOT(typeCombo_activated(int))); |
107 | connect(colorWheel, SIGNAL(clicked(int, const QPoint&)), this, SLOT(colorWheel_clicked(int, const QPoint&))); |
||
108 | colorWheel_clicked(0, QPoint(0, 0)); |
||
109 | connect(angleSpin, SIGNAL(valueChanged(int)), this, SLOT(angleSpin_valueChanged(int))); |
||
110 | connect(addButton, SIGNAL(clicked()), this, SLOT(addButton_clicked())); |
||
111 | connect(cancelButton, SIGNAL(clicked()), this, SLOT(cancelButton_clicked())); |
||
112 | } |
||
113 | |||
114 | /* |
||
115 | * Destroys the object and frees any allocated resources |
||
116 | */ |
||
117 | ColorWheelDialog::~ColorWheelDialog() |
||
118 | { |
||
1803 | subik | 119 | // no need to delete child widgets, Qt does it all for us |
120 | // preferences |
||
121 | prefs->set("cw_type", typeCombo->currentItem()); |
||
122 | prefs->set("cw_angle", angleSpin->value()); |
||
123 | prefs->set("cw_x", colorWheel->actualPoint.x()); |
||
124 | prefs->set("cw_y", colorWheel->actualPoint.y()); |
||
125 | prefs->set("cw_r", qRed(colorWheel->actualRgb)); |
||
126 | prefs->set("cw_g", qGreen(colorWheel->actualRgb)); |
||
127 | prefs->set("cw_b", qBlue(colorWheel->actualRgb)); |
||
1767 | subik | 128 | } |
129 | |||
130 | /* |
||
131 | * Sets the strings of the subwidgets using the current |
||
132 | * language. |
||
133 | */ |
||
134 | void ColorWheelDialog::languageChange() |
||
135 | { |
||
136 | setCaption(tr("Color Wheel")); |
||
137 | colorList->addColumn(tr("Color")); |
||
138 | colorList->addColumn(tr("Name")); |
||
1803 | subik | 139 | colorList->addColumn(tr("C")); |
140 | colorList->addColumn(tr("M")); |
||
141 | colorList->addColumn(tr("Y")); |
||
142 | colorList->addColumn(tr("K")); |
||
143 | colorList->setSorting(1); |
||
1767 | subik | 144 | typeLabel->setText(tr("Select Method:")); |
145 | angleLabel->setText(tr("Angle (0 - 365 degrees):")); |
||
146 | addButton->setText(tr("&Add Colors")); |
||
147 | cancelButton->setText(tr("&Cancel")); |
||
1804 | subik | 148 | // tips |
149 | QToolTip::add(addButton, "<qt>" + tr("Appends created colors into socument colors") + "</qt>"); |
||
150 | QToolTip::add(cancelButton, "<qt>" + tr("Leave colors untouched") + "</qt>"); |
||
151 | QToolTip::add(angleSpin, "<qt>" + tr("Difference between selected value and counted ones. See documentation for more info") + "</qt>"); |
||
152 | QToolTip::add(colorWheel, "<qt>" + tr("Click the wheel to get base color") + "</qt>"); |
||
153 | QToolTip::add(previewLabel, "<qt>" + tr("Here you have the sample color schema") + "</qt>"); |
||
154 | QToolTip::add(typeCombo, "<qt>" + tr("Select one of the method to create color schema. See documentation for more info") + "</qt>"); |
||
155 | QToolTip::add(colorList, "<qt>" + tr("Here you have the color of your chosen color schema") + "</qt>"); |
||
1767 | subik | 156 | } |
157 | |||
158 | void ColorWheelDialog::fillColorList() |
||
159 | { |
||
160 | colorList->clear(); |
||
1803 | subik | 161 | for (ColorList::iterator it = colorWheel->colorList.begin(); it != colorWheel->colorList.end(); ++it) |
1767 | subik | 162 | { |
1803 | subik | 163 | int c, m, y, k; |
1767 | subik | 164 | QListViewItem *item = new QListViewItem(colorList); |
1769 | subik | 165 | item->setPixmap(0, colorWheel->sample(it.data().getRGBColor())); |
1803 | subik | 166 | item->setText(1, it.key()); |
167 | it.data().getCMYK(&c, &m, &y, &k); |
||
168 | item->setText(2, QString("%1").arg(c)); |
||
169 | item->setText(3, QString("%1").arg(m)); |
||
170 | item->setText(4, QString("%1").arg(y)); |
||
171 | item->setText(5, QString("%1").arg(k)); |
||
1767 | subik | 172 | } |
173 | } |
||
174 | |||
175 | void ColorWheelDialog::typeCombo_activated(int index) |
||
176 | { |
||
177 | colorList->clear(); |
||
178 | if (index == colorWheel->Monochromatic) |
||
179 | { |
||
180 | angleSpin->setEnabled(false); |
||
1769 | subik | 181 | angleLabel->setEnabled(false); |
1767 | subik | 182 | colorWheel->makeMonochromatic(); |
183 | } |
||
184 | if (index == colorWheel->Analogous) |
||
185 | { |
||
186 | angleSpin->setEnabled(true); |
||
1769 | subik | 187 | angleLabel->setEnabled(true); |
1767 | subik | 188 | colorWheel->makeAnalogous(); |
189 | } |
||
190 | if (index == colorWheel->Complementary) |
||
191 | { |
||
192 | angleSpin->setEnabled(false); |
||
1769 | subik | 193 | angleLabel->setEnabled(false); |
1767 | subik | 194 | colorWheel->makeComplementary(); |
195 | } |
||
196 | if (index == colorWheel->Split) |
||
197 | { |
||
198 | angleSpin->setEnabled(true); |
||
1769 | subik | 199 | angleLabel->setEnabled(true); |
1767 | subik | 200 | colorWheel->makeSplit(); |
201 | } |
||
202 | if (index == colorWheel->Triadic) |
||
203 | { |
||
204 | angleSpin->setEnabled(false); //TODO |
||
1769 | subik | 205 | angleLabel->setEnabled(false); |
1767 | subik | 206 | colorWheel->makeTriadic(); |
207 | } |
||
208 | if (index == colorWheel->Tetradic) |
||
209 | { |
||
210 | angleSpin->setEnabled(false); //TODO |
||
1769 | subik | 211 | angleLabel->setEnabled(false); |
1767 | subik | 212 | colorWheel->makeTetradic(); |
213 | } |
||
214 | fillColorList(); |
||
1769 | subik | 215 | setPreview(); |
1767 | subik | 216 | } |
217 | |||
218 | void ColorWheelDialog::colorWheel_clicked(int, const QPoint&) |
||
219 | { |
||
220 | typeCombo_activated(typeCombo->currentItem()); |
||
221 | } |
||
222 | |||
223 | void ColorWheelDialog::angleSpin_valueChanged(int value) |
||
224 | { |
||
225 | colorWheel->angle = value; |
||
226 | typeCombo_activated(typeCombo->currentItem()); |
||
227 | } |
||
228 | |||
229 | void ColorWheelDialog::addButton_clicked() |
||
230 | { |
||
1803 | subik | 231 | QString status("<qt><h2>" + tr("Merging colors") + "</h2><p>"); |
232 | for (ColorList::iterator it = colorWheel->colorList.begin(); it != colorWheel->colorList.end(); ++it) |
||
233 | { |
||
234 | if (ScApp->doc->PageColors.contains(it.key())) |
||
235 | status += "<b>" + tr("Error: ") + "</b>" + tr(QString("Color %1 exists already!").arg(it.key())) + "<br/>"; |
||
236 | else |
||
237 | { |
||
238 | status += tr(QString("Color %1 appended.").arg(it.key())) + "<br/>"; |
||
239 | ScApp->doc->PageColors[it.key()] = it.data(); |
||
240 | } |
||
241 | } |
||
242 | status += "<p>" + tr("Use <i>Edit/Colors...</i> for more color management.") + "</p></qt>"; |
||
243 | QMessageBox::information(this, tr("Color Merging"), status); |
||
1767 | subik | 244 | accept(); |
245 | } |
||
246 | |||
247 | |||
248 | void ColorWheelDialog::cancelButton_clicked() |
||
249 | { |
||
250 | reject(); |
||
251 | } |
||
1769 | subik | 252 | |
253 | void ColorWheelDialog::setPreview() |
||
254 | { |
||
255 | int x = previewLabel->width(); |
||
256 | int y = previewLabel->height(); |
||
257 | QValueList<CMYKColor> cols = colorWheel->colorList.values(); |
||
258 | int xstep = x / cols.count(); |
||
259 | QPixmap pm = QPixmap(x, y); |
||
260 | QPainter *p = new QPainter(&pm); |
||
261 | QFontMetrics fm = p->fontMetrics(); |
||
262 | |||
263 | pm.fill(Qt::white); |
||
264 | p->setPen(Qt::white); |
||
265 | p->drawRect(0, 0, x, y); |
||
266 | for (uint i = 0; i < cols.count(); ++i) |
||
267 | { |
||
268 | p->setPen(cols[i].getRGBColor()); |
||
269 | p->setBrush(cols[i].getRGBColor()); |
||
270 | p->drawRect(i * xstep, 0, xstep, y); |
||
271 | } |
||
272 | p->setPen(Qt::black); |
||
273 | p->setBrush(Qt::black); |
||
274 | p->drawText(15, 5 + fm.height(), "Lorem ipsum dolor sit amet"); |
||
275 | p->setPen(Qt::white); |
||
276 | p->setBrush(Qt::white); |
||
277 | p->drawText(25, y - 5 - fm.height(), "Lorem ipsum dolor sit amet"); |
||
278 | p->end(); |
||
279 | delete(p); |
||
280 | previewLabel->clear(); |
||
281 | previewLabel->setPixmap(pm); |
||
282 | } |