source: trunk/tools/shared/qtgradienteditor/qtgradientstopscontroller.cpp@ 158

Last change on this file since 158 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 26.2 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the tools applications of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you are unsure which license is appropriate for your use, please
37** contact the sales department at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42/*
43TRANSLATOR qdesigner_internal::QtGradientStopsController
44*/
45
46#include "qtgradientstopscontroller.h"
47#include "ui_qtgradienteditor.h"
48#include "qtgradientstopsmodel.h"
49
50#include <QtCore/QTimer>
51
52QT_BEGIN_NAMESPACE
53
54class QtGradientStopsControllerPrivate
55{
56 QtGradientStopsController *q_ptr;
57 Q_DECLARE_PUBLIC(QtGradientStopsController)
58public:
59 typedef QMap<qreal, QColor> PositionColorMap;
60 typedef QMap<qreal, QtGradientStop *> PositionStopMap;
61
62 void slotHsvClicked();
63 void slotRgbClicked();
64
65 void slotCurrentStopChanged(QtGradientStop *stop);
66 void slotStopMoved(QtGradientStop *stop, qreal newPos);
67 void slotStopsSwapped(QtGradientStop *stop1, QtGradientStop *stop2);
68 void slotStopChanged(QtGradientStop *stop, const QColor &newColor);
69 void slotStopSelected(QtGradientStop *stop, bool selected);
70 void slotStopAdded(QtGradientStop *stop);
71 void slotStopRemoved(QtGradientStop *stop);
72 void slotUpdatePositionSpinBox();
73
74 void slotChangeColor(const QColor &color);
75 void slotChangeHue(const QColor &color);
76 void slotChangeSaturation(const QColor &color);
77 void slotChangeValue(const QColor &color);
78 void slotChangeAlpha(const QColor &color);
79 void slotChangeHue(int color);
80 void slotChangeSaturation(int color);
81 void slotChangeValue(int color);
82 void slotChangeAlpha(int color);
83 void slotChangePosition(double value);
84
85 void slotChangeZoom(int value);
86 void slotZoomIn();
87 void slotZoomOut();
88 void slotZoomAll();
89 void slotZoomChanged(double zoom);
90
91 void enableCurrent(bool enable);
92 void setColorSpinBoxes(const QColor &color);
93 PositionColorMap stopsData(const PositionStopMap &stops) const;
94 QGradientStops makeGradientStops(const PositionColorMap &data) const;
95 void updateZoom(double zoom);
96
97 QtGradientStopsModel *m_model;
98 QColor::Spec m_spec;
99
100 Ui::QtGradientEditor *m_ui;
101};
102
103void QtGradientStopsControllerPrivate::enableCurrent(bool enable)
104{
105 m_ui->positionLabel->setEnabled(enable);
106 m_ui->colorLabel->setEnabled(enable);
107 m_ui->hLabel->setEnabled(enable);
108 m_ui->sLabel->setEnabled(enable);
109 m_ui->vLabel->setEnabled(enable);
110 m_ui->aLabel->setEnabled(enable);
111 m_ui->hueLabel->setEnabled(enable);
112 m_ui->saturationLabel->setEnabled(enable);
113 m_ui->valueLabel->setEnabled(enable);
114 m_ui->alphaLabel->setEnabled(enable);
115
116 m_ui->positionSpinBox->setEnabled(enable);
117 m_ui->colorButton->setEnabled(enable);
118
119 m_ui->hueColorLine->setEnabled(enable);
120 m_ui->saturationColorLine->setEnabled(enable);
121 m_ui->valueColorLine->setEnabled(enable);
122 m_ui->alphaColorLine->setEnabled(enable);
123
124 m_ui->hueSpinBox->setEnabled(enable);
125 m_ui->saturationSpinBox->setEnabled(enable);
126 m_ui->valueSpinBox->setEnabled(enable);
127 m_ui->alphaSpinBox->setEnabled(enable);
128}
129
130QtGradientStopsControllerPrivate::PositionColorMap QtGradientStopsControllerPrivate::stopsData(const PositionStopMap &stops) const
131{
132 PositionColorMap data;
133 PositionStopMap::ConstIterator itStop = stops.constBegin();
134 while (itStop != stops.constEnd()) {
135 QtGradientStop *stop = itStop.value();
136 data[stop->position()] = stop->color();
137
138 ++itStop;
139 }
140 return data;
141}
142
143QGradientStops QtGradientStopsControllerPrivate::makeGradientStops(const PositionColorMap &data) const
144{
145 QGradientStops stops;
146 PositionColorMap::ConstIterator itData = data.constBegin();
147 while (itData != data.constEnd()) {
148 stops << QPair<qreal, QColor>(itData.key(), itData.value());
149
150 ++itData;
151 }
152 return stops;
153}
154
155void QtGradientStopsControllerPrivate::updateZoom(double zoom)
156{
157 m_ui->gradientStopsWidget->setZoom(zoom);
158 m_ui->zoomSpinBox->blockSignals(true);
159 m_ui->zoomSpinBox->setValue(qRound(zoom * 100));
160 m_ui->zoomSpinBox->blockSignals(false);
161 bool zoomInEnabled = true;
162 bool zoomOutEnabled = true;
163 bool zoomAllEnabled = true;
164 if (zoom <= 1) {
165 zoomAllEnabled = false;
166 zoomOutEnabled = false;
167 } else if (zoom >= 100) {
168 zoomInEnabled = false;
169 }
170 m_ui->zoomInButton->setEnabled(zoomInEnabled);
171 m_ui->zoomOutButton->setEnabled(zoomOutEnabled);
172 m_ui->zoomAllButton->setEnabled(zoomAllEnabled);
173}
174
175void QtGradientStopsControllerPrivate::slotHsvClicked()
176{
177 QString h = QApplication::translate("qdesigner_internal::QtGradientStopsController", "H", 0, QApplication::UnicodeUTF8);
178 QString s = QApplication::translate("qdesigner_internal::QtGradientStopsController", "S", 0, QApplication::UnicodeUTF8);
179 QString v = QApplication::translate("qdesigner_internal::QtGradientStopsController", "V", 0, QApplication::UnicodeUTF8);
180
181 m_ui->hLabel->setText(h);
182 m_ui->sLabel->setText(s);
183 m_ui->vLabel->setText(v);
184
185 h = QApplication::translate("qdesigner_internal::QtGradientStopsController", "Hue", 0, QApplication::UnicodeUTF8);
186 s = QApplication::translate("qdesigner_internal::QtGradientStopsController", "Sat", 0, QApplication::UnicodeUTF8);
187 v = QApplication::translate("qdesigner_internal::QtGradientStopsController", "Val", 0, QApplication::UnicodeUTF8);
188
189 const QString hue = QApplication::translate("qdesigner_internal::QtGradientStopsController", "Hue", 0, QApplication::UnicodeUTF8);
190 const QString saturation = QApplication::translate("qdesigner_internal::QtGradientStopsController", "Saturation", 0, QApplication::UnicodeUTF8);
191 const QString value = QApplication::translate("qdesigner_internal::QtGradientStopsController", "Value", 0, QApplication::UnicodeUTF8);
192
193 m_ui->hLabel->setToolTip(hue);
194 m_ui->hueLabel->setText(h);
195 m_ui->hueColorLine->setToolTip(hue);
196 m_ui->hueColorLine->setColorComponent(QtColorLine::Hue);
197
198 m_ui->sLabel->setToolTip(saturation);
199 m_ui->saturationLabel->setText(s);
200 m_ui->saturationColorLine->setToolTip(saturation);
201 m_ui->saturationColorLine->setColorComponent(QtColorLine::Saturation);
202
203 m_ui->vLabel->setToolTip(value);
204 m_ui->valueLabel->setText(v);
205 m_ui->valueColorLine->setToolTip(value);
206 m_ui->valueColorLine->setColorComponent(QtColorLine::Value);
207
208 setColorSpinBoxes(m_ui->colorButton->color());
209}
210
211void QtGradientStopsControllerPrivate::slotRgbClicked()
212{
213 QString r = QApplication::translate("qdesigner_internal::QtGradientStopsController", "R", 0, QApplication::UnicodeUTF8);
214 QString g = QApplication::translate("qdesigner_internal::QtGradientStopsController", "G", 0, QApplication::UnicodeUTF8);
215 QString b = QApplication::translate("qdesigner_internal::QtGradientStopsController", "B", 0, QApplication::UnicodeUTF8);
216
217 m_ui->hLabel->setText(r);
218 m_ui->sLabel->setText(g);
219 m_ui->vLabel->setText(b);
220
221 QString red = QApplication::translate("qdesigner_internal::QtGradientStopsController", "Red", 0, QApplication::UnicodeUTF8);
222 QString green = QApplication::translate("qdesigner_internal::QtGradientStopsController", "Green", 0, QApplication::UnicodeUTF8);
223 QString blue = QApplication::translate("qdesigner_internal::QtGradientStopsController", "Blue", 0, QApplication::UnicodeUTF8);
224
225 m_ui->hLabel->setToolTip(red);
226 m_ui->hueLabel->setText(red);
227 m_ui->hueColorLine->setToolTip(red);
228 m_ui->hueColorLine->setColorComponent(QtColorLine::Red);
229
230 m_ui->sLabel->setToolTip(green);
231 m_ui->saturationLabel->setText(green);
232 m_ui->saturationColorLine->setToolTip(green);
233 m_ui->saturationColorLine->setColorComponent(QtColorLine::Green);
234
235 m_ui->vLabel->setToolTip(blue);
236 m_ui->valueLabel->setText(blue);
237 m_ui->valueColorLine->setToolTip(blue);
238 m_ui->valueColorLine->setColorComponent(QtColorLine::Blue);
239
240 setColorSpinBoxes(m_ui->colorButton->color());
241}
242
243void QtGradientStopsControllerPrivate::setColorSpinBoxes(const QColor &color)
244{
245 m_ui->hueSpinBox->blockSignals(true);
246 m_ui->saturationSpinBox->blockSignals(true);
247 m_ui->valueSpinBox->blockSignals(true);
248 m_ui->alphaSpinBox->blockSignals(true);
249 if (m_ui->hsvRadioButton->isChecked()) {
250 if (m_ui->hueSpinBox->maximum() != 359)
251 m_ui->hueSpinBox->setMaximum(359);
252 if (m_ui->hueSpinBox->value() != color.hue())
253 m_ui->hueSpinBox->setValue(color.hue());
254 if (m_ui->saturationSpinBox->value() != color.saturation())
255 m_ui->saturationSpinBox->setValue(color.saturation());
256 if (m_ui->valueSpinBox->value() != color.value())
257 m_ui->valueSpinBox->setValue(color.value());
258 } else {
259 if (m_ui->hueSpinBox->maximum() != 255)
260 m_ui->hueSpinBox->setMaximum(255);
261 if (m_ui->hueSpinBox->value() != color.red())
262 m_ui->hueSpinBox->setValue(color.red());
263 if (m_ui->saturationSpinBox->value() != color.green())
264 m_ui->saturationSpinBox->setValue(color.green());
265 if (m_ui->valueSpinBox->value() != color.blue())
266 m_ui->valueSpinBox->setValue(color.blue());
267 }
268 m_ui->alphaSpinBox->setValue(color.alpha());
269 m_ui->hueSpinBox->blockSignals(false);
270 m_ui->saturationSpinBox->blockSignals(false);
271 m_ui->valueSpinBox->blockSignals(false);
272 m_ui->alphaSpinBox->blockSignals(false);
273}
274
275void QtGradientStopsControllerPrivate::slotCurrentStopChanged(QtGradientStop *stop)
276{
277 if (!stop) {
278 enableCurrent(false);
279 return;
280 }
281 enableCurrent(true);
282
283 QTimer::singleShot(0, q_ptr, SLOT(slotUpdatePositionSpinBox()));
284
285 m_ui->colorButton->setColor(stop->color());
286 m_ui->hueColorLine->setColor(stop->color());
287 m_ui->saturationColorLine->setColor(stop->color());
288 m_ui->valueColorLine->setColor(stop->color());
289 m_ui->alphaColorLine->setColor(stop->color());
290 setColorSpinBoxes(stop->color());
291}
292
293void QtGradientStopsControllerPrivate::slotStopMoved(QtGradientStop *stop, qreal newPos)
294{
295 QTimer::singleShot(0, q_ptr, SLOT(slotUpdatePositionSpinBox()));
296
297 PositionColorMap stops = stopsData(m_model->stops());
298 stops.remove(stop->position());
299 stops[newPos] = stop->color();
300
301 QGradientStops gradStops = makeGradientStops(stops);
302 emit q_ptr->gradientStopsChanged(gradStops);
303}
304
305void QtGradientStopsControllerPrivate::slotStopsSwapped(QtGradientStop *stop1, QtGradientStop *stop2)
306{
307 QTimer::singleShot(0, q_ptr, SLOT(slotUpdatePositionSpinBox()));
308
309 PositionColorMap stops = stopsData(m_model->stops());
310 const qreal pos1 = stop1->position();
311 const qreal pos2 = stop2->position();
312 stops[pos1] = stop2->color();
313 stops[pos2] = stop1->color();
314
315 QGradientStops gradStops = makeGradientStops(stops);
316 emit q_ptr->gradientStopsChanged(gradStops);
317}
318
319void QtGradientStopsControllerPrivate::slotStopAdded(QtGradientStop *stop)
320{
321 PositionColorMap stops = stopsData(m_model->stops());
322 stops[stop->position()] = stop->color();
323
324 QGradientStops gradStops = makeGradientStops(stops);
325 emit q_ptr->gradientStopsChanged(gradStops);
326}
327
328void QtGradientStopsControllerPrivate::slotStopRemoved(QtGradientStop *stop)
329{
330 PositionColorMap stops = stopsData(m_model->stops());
331 stops.remove(stop->position());
332
333 QGradientStops gradStops = makeGradientStops(stops);
334 emit q_ptr->gradientStopsChanged(gradStops);
335}
336
337void QtGradientStopsControllerPrivate::slotStopChanged(QtGradientStop *stop, const QColor &newColor)
338{
339 if (m_model->currentStop() == stop) {
340 m_ui->colorButton->setColor(newColor);
341 m_ui->hueColorLine->setColor(newColor);
342 m_ui->saturationColorLine->setColor(newColor);
343 m_ui->valueColorLine->setColor(newColor);
344 m_ui->alphaColorLine->setColor(newColor);
345 setColorSpinBoxes(newColor);
346 }
347
348 PositionColorMap stops = stopsData(m_model->stops());
349 stops[stop->position()] = newColor;
350
351 QGradientStops gradStops = makeGradientStops(stops);
352 emit q_ptr->gradientStopsChanged(gradStops);
353}
354
355void QtGradientStopsControllerPrivate::slotStopSelected(QtGradientStop *stop, bool selected)
356{
357 Q_UNUSED(stop)
358 Q_UNUSED(selected)
359 QTimer::singleShot(0, q_ptr, SLOT(slotUpdatePositionSpinBox()));
360}
361
362void QtGradientStopsControllerPrivate::slotUpdatePositionSpinBox()
363{
364 QtGradientStop *current = m_model->currentStop();
365 if (!current)
366 return;
367
368 qreal min = 0.0;
369 qreal max = 1.0;
370 const qreal pos = current->position();
371
372 QtGradientStop *first = m_model->firstSelected();
373 QtGradientStop *last = m_model->lastSelected();
374
375 if (first && last) {
376 const qreal minPos = pos - first->position() - 0.0004999;
377 const qreal maxPos = pos + 1.0 - last->position() + 0.0004999;
378
379 if (max > maxPos)
380 max = maxPos;
381 if (min < minPos)
382 min = minPos;
383
384 if (first->position() == 0.0)
385 min = pos;
386 if (last->position() == 1.0)
387 max = pos;
388 }
389
390 const int spinMin = qRound(m_ui->positionSpinBox->minimum() * 1000);
391 const int spinMax = qRound(m_ui->positionSpinBox->maximum() * 1000);
392
393 const int newMin = qRound(min * 1000);
394 const int newMax = qRound(max * 1000);
395
396 m_ui->positionSpinBox->blockSignals(true);
397 if (spinMin != newMin || spinMax != newMax) {
398 m_ui->positionSpinBox->setRange((double)newMin / 1000, (double)newMax / 1000);
399 }
400 if (m_ui->positionSpinBox->value() != pos)
401 m_ui->positionSpinBox->setValue(pos);
402 m_ui->positionSpinBox->blockSignals(false);
403}
404
405void QtGradientStopsControllerPrivate::slotChangeColor(const QColor &color)
406{
407 QtGradientStop *stop = m_model->currentStop();
408 if (!stop)
409 return;
410 m_model->changeStop(stop, color);
411 QList<QtGradientStop *> stops = m_model->selectedStops();
412 QListIterator<QtGradientStop *> itStop(stops);
413 while (itStop.hasNext()) {
414 QtGradientStop *s = itStop.next();
415 if (s != stop)
416 m_model->changeStop(s, color);
417 }
418}
419
420void QtGradientStopsControllerPrivate::slotChangeHue(const QColor &color)
421{
422 QtGradientStop *stop = m_model->currentStop();
423 if (!stop)
424 return;
425 m_model->changeStop(stop, color);
426 QList<QtGradientStop *> stops = m_model->selectedStops();
427 QListIterator<QtGradientStop *> itStop(stops);
428 while (itStop.hasNext()) {
429 QtGradientStop *s = itStop.next();
430 if (s != stop) {
431 QColor c = s->color();
432 if (m_ui->hsvRadioButton->isChecked())
433 c.setHsvF(color.hueF(), c.saturationF(), c.valueF(), c.alphaF());
434 else
435 c.setRgbF(color.redF(), c.greenF(), c.blueF(), c.alphaF());
436 m_model->changeStop(s, c);
437 }
438 }
439}
440
441void QtGradientStopsControllerPrivate::slotChangeHue(int color)
442{
443 QColor c = m_ui->hueColorLine->color();
444 if (m_ui->hsvRadioButton->isChecked())
445 c.setHsvF((qreal)color / 360.0, c.saturationF(), c.valueF(), c.alphaF());
446 else
447 c.setRed(color);
448 slotChangeHue(c);
449}
450
451void QtGradientStopsControllerPrivate::slotChangeSaturation(const QColor &color)
452{
453 QtGradientStop *stop = m_model->currentStop();
454 if (!stop)
455 return;
456 m_model->changeStop(stop, color);
457 QList<QtGradientStop *> stops = m_model->selectedStops();
458 QListIterator<QtGradientStop *> itStop(stops);
459 while (itStop.hasNext()) {
460 QtGradientStop *s = itStop.next();
461 if (s != stop) {
462 QColor c = s->color();
463 if (m_ui->hsvRadioButton->isChecked()) {
464 c.setHsvF(c.hueF(), color.saturationF(), c.valueF(), c.alphaF());
465 int hue = c.hue();
466 if (hue == 360 || hue == -1)
467 c.setHsvF(0.0, c.saturationF(), c.valueF(), c.alphaF());
468 } else {
469 c.setRgbF(c.redF(), color.greenF(), c.blueF(), c.alphaF());
470 }
471 m_model->changeStop(s, c);
472 }
473 }
474}
475
476void QtGradientStopsControllerPrivate::slotChangeSaturation(int color)
477{
478 QColor c = m_ui->saturationColorLine->color();
479 if (m_ui->hsvRadioButton->isChecked())
480 c.setHsvF(c.hueF(), (qreal)color / 255, c.valueF(), c.alphaF());
481 else
482 c.setGreen(color);
483 slotChangeSaturation(c);
484}
485
486void QtGradientStopsControllerPrivate::slotChangeValue(const QColor &color)
487{
488 QtGradientStop *stop = m_model->currentStop();
489 if (!stop)
490 return;
491 m_model->changeStop(stop, color);
492 QList<QtGradientStop *> stops = m_model->selectedStops();
493 QListIterator<QtGradientStop *> itStop(stops);
494 while (itStop.hasNext()) {
495 QtGradientStop *s = itStop.next();
496 if (s != stop) {
497 QColor c = s->color();
498 if (m_ui->hsvRadioButton->isChecked()) {
499 c.setHsvF(c.hueF(), c.saturationF(), color.valueF(), c.alphaF());
500 int hue = c.hue();
501 if (hue == 360 || hue == -1)
502 c.setHsvF(0.0, c.saturationF(), c.valueF(), c.alphaF());
503 } else {
504 c.setRgbF(c.redF(), c.greenF(), color.blueF(), c.alphaF());
505 }
506 m_model->changeStop(s, c);
507 }
508 }
509}
510
511void QtGradientStopsControllerPrivate::slotChangeValue(int color)
512{
513 QColor c = m_ui->valueColorLine->color();
514 if (m_ui->hsvRadioButton->isChecked())
515 c.setHsvF(c.hueF(), c.saturationF(), (qreal)color / 255, c.alphaF());
516 else
517 c.setBlue(color);
518 slotChangeValue(c);
519}
520
521void QtGradientStopsControllerPrivate::slotChangeAlpha(const QColor &color)
522{
523 QtGradientStop *stop = m_model->currentStop();
524 if (!stop)
525 return;
526 m_model->changeStop(stop, color);
527 QList<QtGradientStop *> stops = m_model->selectedStops();
528 QListIterator<QtGradientStop *> itStop(stops);
529 while (itStop.hasNext()) {
530 QtGradientStop *s = itStop.next();
531 if (s != stop) {
532 QColor c = s->color();
533 if (m_ui->hsvRadioButton->isChecked()) {
534 c.setHsvF(c.hueF(), c.saturationF(), c.valueF(), color.alphaF());
535 int hue = c.hue();
536 if (hue == 360 || hue == -1)
537 c.setHsvF(0.0, c.saturationF(), c.valueF(), c.alphaF());
538 } else {
539 c.setRgbF(c.redF(), c.greenF(), c.blueF(), color.alphaF());
540 }
541 m_model->changeStop(s, c);
542 }
543 }
544}
545
546void QtGradientStopsControllerPrivate::slotChangeAlpha(int color)
547{
548 QColor c = m_ui->alphaColorLine->color();
549 if (m_ui->hsvRadioButton->isChecked())
550 c.setHsvF(c.hueF(), c.saturationF(), c.valueF(), (qreal)color / 255);
551 else
552 c.setAlpha(color);
553 slotChangeAlpha(c);
554}
555
556void QtGradientStopsControllerPrivate::slotChangePosition(double value)
557{
558 QtGradientStop *stop = m_model->currentStop();
559 if (!stop)
560 return;
561
562 m_model->moveStops(value);
563}
564
565void QtGradientStopsControllerPrivate::slotChangeZoom(int value)
566{
567 updateZoom(value / 100.0);
568}
569
570void QtGradientStopsControllerPrivate::slotZoomIn()
571{
572 double newZoom = m_ui->gradientStopsWidget->zoom() * 2;
573 if (newZoom > 100)
574 newZoom = 100;
575 updateZoom(newZoom);
576}
577
578void QtGradientStopsControllerPrivate::slotZoomOut()
579{
580 double newZoom = m_ui->gradientStopsWidget->zoom() / 2;
581 if (newZoom < 1)
582 newZoom = 1;
583 updateZoom(newZoom);
584}
585
586void QtGradientStopsControllerPrivate::slotZoomAll()
587{
588 updateZoom(1);
589}
590
591void QtGradientStopsControllerPrivate::slotZoomChanged(double zoom)
592{
593 updateZoom(zoom);
594}
595
596QtGradientStopsController::QtGradientStopsController(QObject *parent)
597 : QObject(parent)
598{
599 d_ptr = new QtGradientStopsControllerPrivate();
600 d_ptr->q_ptr = this;
601
602 d_ptr->m_spec = QColor::Hsv;
603}
604
605void QtGradientStopsController::setUi(Ui::QtGradientEditor *ui)
606{
607 d_ptr->m_ui = ui;
608
609 d_ptr->m_ui->hueColorLine->setColorComponent(QtColorLine::Hue);
610 d_ptr->m_ui->saturationColorLine->setColorComponent(QtColorLine::Saturation);
611 d_ptr->m_ui->valueColorLine->setColorComponent(QtColorLine::Value);
612 d_ptr->m_ui->alphaColorLine->setColorComponent(QtColorLine::Alpha);
613
614 d_ptr->m_model = new QtGradientStopsModel(this);
615 d_ptr->m_ui->gradientStopsWidget->setGradientStopsModel(d_ptr->m_model);
616 connect(d_ptr->m_model, SIGNAL(currentStopChanged(QtGradientStop *)),
617 this, SLOT(slotCurrentStopChanged(QtGradientStop *)));
618 connect(d_ptr->m_model, SIGNAL(stopMoved(QtGradientStop *, qreal)),
619 this, SLOT(slotStopMoved(QtGradientStop *, qreal)));
620 connect(d_ptr->m_model, SIGNAL(stopsSwapped(QtGradientStop *, QtGradientStop *)),
621 this, SLOT(slotStopsSwapped(QtGradientStop *, QtGradientStop *)));
622 connect(d_ptr->m_model, SIGNAL(stopChanged(QtGradientStop *, const QColor &)),
623 this, SLOT(slotStopChanged(QtGradientStop *, const QColor &)));
624 connect(d_ptr->m_model, SIGNAL(stopSelected(QtGradientStop *, bool)),
625 this, SLOT(slotStopSelected(QtGradientStop *, bool)));
626 connect(d_ptr->m_model, SIGNAL(stopAdded(QtGradientStop *)),
627 this, SLOT(slotStopAdded(QtGradientStop *)));
628 connect(d_ptr->m_model, SIGNAL(stopRemoved(QtGradientStop *)),
629 this, SLOT(slotStopRemoved(QtGradientStop *)));
630
631 connect(d_ptr->m_ui->hueColorLine, SIGNAL(colorChanged(const QColor &)),
632 this, SLOT(slotChangeHue(const QColor &)));
633 connect(d_ptr->m_ui->saturationColorLine, SIGNAL(colorChanged(const QColor &)),
634 this, SLOT(slotChangeSaturation(const QColor &)));
635 connect(d_ptr->m_ui->valueColorLine, SIGNAL(colorChanged(const QColor &)),
636 this, SLOT(slotChangeValue(const QColor &)));
637 connect(d_ptr->m_ui->alphaColorLine, SIGNAL(colorChanged(const QColor &)),
638 this, SLOT(slotChangeAlpha(const QColor &)));
639 connect(d_ptr->m_ui->colorButton, SIGNAL(colorChanged(const QColor &)),
640 this, SLOT(slotChangeColor(const QColor &)));
641
642 connect(d_ptr->m_ui->hueSpinBox, SIGNAL(valueChanged(int)),
643 this, SLOT(slotChangeHue(int)));
644 connect(d_ptr->m_ui->saturationSpinBox, SIGNAL(valueChanged(int)),
645 this, SLOT(slotChangeSaturation(int)));
646 connect(d_ptr->m_ui->valueSpinBox, SIGNAL(valueChanged(int)),
647 this, SLOT(slotChangeValue(int)));
648 connect(d_ptr->m_ui->alphaSpinBox, SIGNAL(valueChanged(int)),
649 this, SLOT(slotChangeAlpha(int)));
650
651 connect(d_ptr->m_ui->positionSpinBox, SIGNAL(valueChanged(double)),