21#include "koColorChooser.h"
26#include <tqtabwidget.h>
29#include <kiconloader.h>
30#include <kcolordialog.h>
32#include <koFrameButton.h>
33#include <koColorSlider.h>
35KoColorChooser::KoColorChooser(TQWidget *parent,
const char *name) : TQWidget(parent,
name)
38 m_tab =
new TQTabWidget(
this,
"KoColorChooser tab");
39 mGrid =
new TQGridLayout(
this, 3, 5);
40 mRGBWidget =
new RGBWidget(m_tab);
41 m_current = mRGBWidget;
42 m_tab -> addTab(mRGBWidget,
"RGB");
43 mHSVWidget =
new HSVWidget(m_tab);
44 m_tab -> addTab(mHSVWidget,
"HSV");
46 mCMYKWidget =
new TQWidget(m_tab);
47 m_tab -> addTab(mCMYKWidget,
"CMYK");
48 mLABWidget =
new LABWidget(m_tab);
49 m_tab -> addTab(mLABWidget,
"LAB");
51 mGreyWidget =
new GreyWidget(m_tab);
52 m_tab -> addTab(mGreyWidget, i18n(
"Gray"));
54 mColorSelector->setFixedHeight(20);
55 mGrid->addMultiCellWidget(m_tab, 0, 1, 0, 4);
56 mGrid->addMultiCellWidget(mColorSelector, 2, 2, 0, 4);
57 connect(mRGBWidget, TQ_SIGNAL(colorChanged(
const KoColor &)),
this, TQ_SLOT(childColorChanged(
const KoColor &)));
58 connect(mHSVWidget, TQ_SIGNAL(colorChanged(
const KoColor &)),
this, TQ_SLOT(childColorChanged(
const KoColor &)));
60 connect(mGreyWidget, TQ_SIGNAL(colorChanged(
const KoColor &)),
this, TQ_SLOT(childColorChanged(
const KoColor &)));
61 connect(mColorSelector, TQ_SIGNAL(valueChanged(
int,
int)),
this, TQ_SLOT(slotChangeXY(
int,
int)));
62 connect(m_tab, TQ_SIGNAL(currentChanged(TQWidget*)),
this, TQ_SLOT(slotCurrentChanged(TQWidget*)));
63 slotChangeColor(KoColor::black());
66void KoColorChooser::slotCurrentChanged(TQWidget *current)
68 m_current =
static_cast<ColorWidget*
>(current);
69 m_current -> slotChangeColor(mColor);
72void KoColorChooser::slotChangeXY(
int h,
int s)
74 KoColor c(h, s, 192, KoColor::csHSV);
76 m_current -> slotChangeColor(c);
79void KoColorChooser::slotChangeColor(
const TQColor &c)
81 slotChangeColor(KoColor(c));
84void KoColorChooser::childColorChanged(
const KoColor& c)
86 mColor.setRGB(c.R(), c.G(), c.B());
87 emit colorChanged(mColor);
90void KoColorChooser::slotChangeColor(
const KoColor &c)
93 m_current -> slotChangeColor(mColor);
94 mColorSelector->setValues(c.H(), c.S());
98RGBWidget::RGBWidget(TQWidget *parent) : ColorWidget(parent)
100 TQGridLayout *mGrid =
new TQGridLayout(
this, 4, 5);
105 mRSlider =
new KoColorSlider(
this);
106 mRSlider->setMaximumHeight(20);
107 mRSlider->slotSetRange(0, 255);
109 mGSlider =
new KoColorSlider(
this);
110 mGSlider->setMaximumHeight(20);
111 mGSlider->slotSetRange(0, 255);
113 mBSlider =
new KoColorSlider(
this);
114 mBSlider->setMaximumHeight(20);
115 mBSlider->slotSetRange(0, 255);
118 mRLabel =
new TQLabel(
"R",
this);
119 mRLabel->setFixedWidth(16);
120 mRLabel->setFixedHeight(20);
121 mGLabel =
new TQLabel(
"G",
this);
122 mGLabel->setFixedWidth(16);
123 mGLabel->setFixedHeight(20);
124 mBLabel =
new TQLabel(
"B",
this);
125 mBLabel->setFixedWidth(16);
126 mBLabel->setFixedHeight(20);
129 mRIn =
new TQSpinBox(0, 255, 1,
this);
130 mRIn->setFixedWidth(42);
131 mRIn->setFixedHeight(20);
132 mGIn =
new TQSpinBox(0, 255, 1,
this);
133 mGIn->setFixedWidth(42);
134 mGIn->setFixedHeight(20);
135 mBIn =
new TQSpinBox(0, 255, 1,
this);
136 mBIn->setFixedWidth(42);
137 mBIn->setFixedHeight(20);
139 mGrid->addMultiCellWidget(mColorPatch, 0, 4, 0, 0);
140 mGrid->addWidget(mRLabel, 1, 1);
141 mGrid->addWidget(mGLabel, 2, 1);
142 mGrid->addWidget(mBLabel, 3, 1);
143 mGrid->addMultiCellWidget(mRSlider, 1, 1, 2, 3);
144 mGrid->addMultiCellWidget(mGSlider, 2, 2, 2, 3);
145 mGrid->addMultiCellWidget(mBSlider, 3, 3, 2, 3);
146 mGrid->addWidget(mRIn, 1, 4);
147 mGrid->addWidget(mGIn, 2, 4);
148 mGrid->addWidget(mBIn, 3, 4);
150 connect(mColorPatch, TQ_SIGNAL(colorChanged(
const TQColor &)),
this, TQ_SLOT(slotPatchChanged(
const TQColor &)));
153 connect(mRSlider, TQ_SIGNAL(valueChanged(
int)),
this, TQ_SLOT(slotRSliderChanged(
int)));
154 connect(mGSlider, TQ_SIGNAL(valueChanged(
int)),
this, TQ_SLOT(slotGSliderChanged(
int)));
155 connect(mBSlider, TQ_SIGNAL(valueChanged(
int)),
this, TQ_SLOT(slotBSliderChanged(
int)));
158 connect(mRIn, TQ_SIGNAL(valueChanged(
int)),
this, TQ_SLOT(slotRInChanged(
int)));
159 connect(mGIn, TQ_SIGNAL(valueChanged(
int)),
this, TQ_SLOT(slotGInChanged(
int)));
160 connect(mBIn, TQ_SIGNAL(valueChanged(
int)),
this, TQ_SLOT(slotBInChanged(
int)));
163ColorWidget::ColorWidget(TQWidget *parent) : TQWidget(parent)
167ColorWidget::~ColorWidget()
171void ColorWidget::slotChangeColor(
const KoColor& c)
173 mColor.setRGB(c.R(), c.G(), c.B());
177void ColorWidget::slotChangeColor(
const TQColor& c)
183void RGBWidget::slotRefreshColor()
189 mRSlider->slotSetColor1(TQColor(0, g, b));
190 mRSlider->slotSetColor2(TQColor(255, g, b));
191 mRSlider->slotSetValue(r);
194 mGSlider->slotSetColor1(TQColor(r, 0, b));
195 mGSlider->slotSetColor2(TQColor(r, 255, b));
196 mGSlider->slotSetValue(g);
199 mBSlider->slotSetColor1(TQColor(r, g, 0));
200 mBSlider->slotSetColor2(TQColor(r, g, 255));
201 mBSlider->slotSetValue(b);
203 mColorPatch -> setColor(mColor.color());
206void RGBWidget::slotRSliderChanged(
int r)
211 mColor.setRGB(r, g, b);
213 emit colorChanged(KoColor(r, g, b, KoColor::csRGB));
216void RGBWidget::slotGSliderChanged(
int g)
221 mColor.setRGB(r, g, b);
223 emit colorChanged(KoColor( r, g, b, KoColor::csRGB));
226void RGBWidget::slotBSliderChanged(
int b)
231 mColor.setRGB(r, g, b);
233 emit colorChanged(KoColor(r, g, b, KoColor::csRGB));
236void RGBWidget::slotRInChanged(
int r)
241 mColor.setRGB(r, g, b);
243 emit colorChanged(KoColor(r, g, b, KoColor::csRGB));
246void RGBWidget::slotGInChanged(
int g)
251 mColor.setRGB(r, g, b);
253 emit colorChanged(KoColor(r, g, b, KoColor::csRGB));
256void RGBWidget::slotBInChanged(
int b)
261 mColor.setRGB(r, g, b);
263 emit colorChanged(KoColor(r, g, b, KoColor::csRGB));
266void RGBWidget::slotPatchChanged(
const TQColor& clr)
272 mColor.setRGB(r, g, b);
274 emit colorChanged(KoColor(r, g, b, KoColor::csRGB));
279HSVWidget::HSVWidget(TQWidget *parent): ColorWidget(parent)
281 TQGridLayout *mGrid =
new TQGridLayout(
this, 3, 3);
286 mHSlider =
new KoColorSlider(
this);
287 mHSlider->setMaximumHeight(20);
288 mHSlider->slotSetRange(0, 359);
290 mSSlider =
new KoColorSlider(
this);
291 mSSlider->setMaximumHeight(20);
292 mSSlider->slotSetRange(0, 255);
294 mVSlider =
new KoColorSlider(
this);
295 mVSlider->setMaximumHeight(20);
296 mVSlider->slotSetRange(0, 255);
299 mHLabel =
new TQLabel(
"H",
this);
300 mHLabel->setFixedWidth(16);
301 mHLabel->setFixedHeight(20);
302 mSLabel =
new TQLabel(
"S",
this);
303 mSLabel->setFixedWidth(16);
304 mSLabel->setFixedHeight(20);
305 mVLabel =
new TQLabel(
"V",
this);
306 mVLabel->setFixedWidth(16);
307 mVLabel->setFixedHeight(20);
310 mHIn =
new TQSpinBox(0, 359, 1,
this);
311 mHIn->setFixedWidth(42);
312 mHIn->setFixedHeight(20);
313 mSIn =
new TQSpinBox(0, 255, 1,
this);
314 mSIn->setFixedWidth(42);
315 mSIn->setFixedHeight(20);
316 mVIn =
new TQSpinBox(0, 255, 1,
this);
317 mVIn->setFixedWidth(42);
318 mVIn->setFixedHeight(20);
320 mGrid->addMultiCellWidget(mColorPatch, 0, 4, 0, 0);
321 mGrid->addWidget(mHLabel, 1, 1);
322 mGrid->addWidget(mSLabel, 2, 1);
323 mGrid->addWidget(mVLabel, 3, 1);
324 mGrid->addMultiCellWidget(mHSlider, 1, 1, 2, 3);
325 mGrid->addMultiCellWidget(mSSlider, 2, 2, 2, 3);
326 mGrid->addMultiCellWidget(mVSlider, 3, 3, 2, 3);
327 mGrid->addWidget(mHIn, 1, 4);
328 mGrid->addWidget(mSIn, 2, 4);
329 mGrid->addWidget(mVIn, 3, 4);
331 connect(mColorPatch, TQ_SIGNAL(colorChanged(
const TQColor &)),
this, TQ_SLOT(slotPatchChanged(
const TQColor &)));
334 connect(mHSlider, TQ_SIGNAL(valueChanged(
int)),
this, TQ_SLOT(slotHSliderChanged(
int)));
335 connect(mSSlider, TQ_SIGNAL(valueChanged(
int)),
this, TQ_SLOT(slotSSliderChanged(
int)));
336 connect(mVSlider, TQ_SIGNAL(valueChanged(
int)),
this, TQ_SLOT(slotVSliderChanged(
int)));
339 connect(mHIn, TQ_SIGNAL(valueChanged(
int)),
this, TQ_SLOT(slotHInChanged(
int)));
340 connect(mSIn, TQ_SIGNAL(valueChanged(
int)),
this, TQ_SLOT(slotSInChanged(
int)));
341 connect(mVIn, TQ_SIGNAL(valueChanged(
int)),
this, TQ_SLOT(slotVInChanged(
int)));
344void HSVWidget::slotRefreshColor()
350 mHSlider->slotSetColor1(KoColor(0, s, v, KoColor::csHSV).color());
351 mHSlider->slotSetColor2(KoColor(359, s, v, KoColor::csHSV).color());
352 mHSlider->slotSetValue(h);
355 mSSlider->slotSetColor1(KoColor(h, 0, v, KoColor::csHSV).color());
356 mSSlider->slotSetColor2(KoColor(h, 255, v, KoColor::csHSV).color());
357 mSSlider->slotSetValue(s);
360 mVSlider->slotSetColor1(KoColor(h, s, 0, KoColor::csHSV).color());
361 mVSlider->slotSetColor2(KoColor(h, s, 255, KoColor::csHSV).color());
362 mVSlider->slotSetValue(v);
364 mColorPatch -> setColor(mColor.color());
367void HSVWidget::slotHSliderChanged(
int h)
372 mColor.setHSV(h, s, v);
374 emit colorChanged(mColor);
377void HSVWidget::slotSSliderChanged(
int s)
382 mColor.setHSV(h, s, v);
384 emit colorChanged(mColor);
387void HSVWidget::slotVSliderChanged(
int v)
392 mColor.setHSV(h, s, v);
394 emit colorChanged(mColor);
397void HSVWidget::slotHInChanged(
int h)
402 mColor.setHSV(h, s, v);
404 emit colorChanged(mColor);
407void HSVWidget::slotSInChanged(
int s)
412 mColor.setHSV(h, s, v);
414 emit colorChanged(mColor);
417void HSVWidget::slotVInChanged(
int v)
422 mColor.setHSV(h, s, v);
424 emit colorChanged(mColor);
427void HSVWidget::slotPatchChanged(
const TQColor& clr)
433 mColor.setRGB(r, g, b);
435 emit colorChanged(mColor);
440GreyWidget::GreyWidget(TQWidget *parent): ColorWidget(parent)
442 TQGridLayout *mGrid =
new TQGridLayout(
this, 3, 3);
447 mVSlider =
new KoColorSlider(
this);
448 mVSlider->setMaximumHeight(20);
449 mVSlider->slotSetRange(0, 255);
450 mVSlider->slotSetColor1(TQColor(255, 255, 255));
451 mVSlider->slotSetColor2(TQColor(0, 0, 0));
454 mVLabel =
new TQLabel(
"K",
this);
455 mVLabel->setFixedWidth(18);
456 mVLabel->setFixedHeight(20);
459 mVIn =
new TQSpinBox(0, 255, 1,
this);
460 mVIn->setFixedWidth(42);
461 mVIn->setFixedHeight(20);
463 mGrid->addMultiCellWidget(mColorPatch, 0, 4, 0, 0);
464 mGrid->addWidget(mVLabel, 1, 1);
465 mGrid->addMultiCellWidget(mVSlider, 1, 1, 2, 3);
466 mGrid->addWidget(mVIn, 1, 4);
468 connect(mColorPatch, TQ_SIGNAL(colorChanged(
const TQColor &)),
this, TQ_SLOT(slotPatchChanged(
const TQColor &)));
471 connect(mVSlider, TQ_SIGNAL(valueChanged(
int)),
this, TQ_SLOT(slotVSliderChanged(
int)));
474 connect(mVIn, TQ_SIGNAL(valueChanged(
int)), mVSlider, TQ_SLOT(slotSetValue(
int)));
477void GreyWidget::slotRefreshColor()
479 double v = mColor.R() + mColor.G() + mColor.B();
482 mVIn->setValue(
static_cast<int>(v));
483 mVSlider->slotSetValue(
static_cast<int>(v));
484 mColorPatch -> setColor(mColor.color());
487void GreyWidget::slotVSliderChanged(
int v)
491 mColor.setRGB(v, v, v);
493 emit colorChanged(mColor);
496void GreyWidget::slotVInChanged(
int v)
500 mColor.setRGB(v, v, v);
502 emit colorChanged(mColor);
505void GreyWidget::slotPatchChanged(
const TQColor& clr)
507 int gray = tqGray(clr.red(), clr.green(), clr.blue());
509 mColor.setRGB(gray, gray, gray);
511 emit colorChanged(mColor);
514LABWidget::LABWidget(TQWidget *parent) : ColorWidget(parent)
516 TQGridLayout *mGrid =
new TQGridLayout(
this, 4, 5);
521 mLSlider =
new KoColorSlider(
this);
522 mLSlider->setMaximumHeight(20);
523 mLSlider->slotSetRange(0, 255);
525 mASlider =
new KoColorSlider(
this);
526 mASlider->setMaximumHeight(20);
527 mASlider->slotSetRange(0, 255);
529 mBSlider =
new KoColorSlider(
this);
530 mBSlider->setMaximumHeight(20);
531 mBSlider->slotSetRange(0, 255);
534 mLLabel =
new TQLabel(
"L",
this);
535 mLLabel->setFixedWidth(16);
536 mLLabel->setFixedHeight(20);
537 mALabel =
new TQLabel(
"A",
this);
538 mALabel->setFixedWidth(16);
539 mALabel->setFixedHeight(20);
540 mBLabel =
new TQLabel(
"B",
this);
541 mBLabel->setFixedWidth(16);
542 mBLabel->setFixedHeight(20);
545 mLIn =
new TQSpinBox(0, 255, 1,
this);
546 mLIn->setFixedWidth(42);
547 mLIn->setFixedHeight(20);
548 mAIn =
new TQSpinBox(0, 255, 1,
this);
549 mAIn->setFixedWidth(42);
550 mAIn->setFixedHeight(20);
551 mBIn =
new TQSpinBox(0, 255, 1,
this);
552 mBIn->setFixedWidth(42);
553 mBIn->setFixedHeight(20);
555 mGrid->addMultiCellWidget(mColorPatch, 0, 4, 0, 0);
556 mGrid->addWidget(mLLabel, 1, 1);
557 mGrid->addWidget(mALabel, 2, 1);
558 mGrid->addWidget(mBLabel, 3, 1);
559 mGrid->addMultiCellWidget(mLSlider, 1, 1, 2, 3);
560 mGrid->addMultiCellWidget(mASlider, 2, 2, 2, 3);
561 mGrid->addMultiCellWidget(mBSlider, 3, 3, 2, 3);
562 mGrid->addWidget(mLIn, 1, 4);
563 mGrid->addWidget(mAIn, 2, 4);
564 mGrid->addWidget(mBIn, 3, 4);
566 connect(mColorPatch, TQ_SIGNAL(colorChanged(
const TQColor &)),
this, TQ_SLOT(slotPatchChanged(
const TQColor &)));
569 connect(mLSlider, TQ_SIGNAL(valueChanged(
int)),
this, TQ_SLOT(slotLSliderChanged(
int)));
570 connect(mASlider, TQ_SIGNAL(valueChanged(
int)),
this, TQ_SLOT(slotASliderChanged(
int)));
571 connect(mBSlider, TQ_SIGNAL(valueChanged(
int)),
this, TQ_SLOT(slotBSliderChanged(
int)));
574 connect(mLIn, TQ_SIGNAL(valueChanged(
int)),
this, TQ_SLOT(slotLInChanged(
int)));
575 connect(mAIn, TQ_SIGNAL(valueChanged(
int)),
this, TQ_SLOT(slotAInChanged(
int)));
576 connect(mBIn, TQ_SIGNAL(valueChanged(
int)),
this, TQ_SLOT(slotBInChanged(
int)));
579void LABWidget::slotRefreshColor()
585 mLSlider->slotSetColor1(KoColor(0, a, b, KoColor::csLab).color());
586 mLSlider->slotSetColor2(KoColor(255, a, b, KoColor::csLab).color());
587 mLSlider->slotSetValue(l);
590 mASlider->slotSetColor1(KoColor(l, 0, b, KoColor::csLab).color());
591 mASlider->slotSetColor2(KoColor(l, 255, b, KoColor::csLab).color());
592 mASlider->slotSetValue(a);
595 mBSlider->slotSetColor1(KoColor(l, a, 0, KoColor::csLab).color());
596 mBSlider->slotSetColor2(KoColor(l, a, 255, KoColor::csLab).color());
597 mBSlider->slotSetValue(b);
599 mColorPatch -> setColor(mColor.color());
602void LABWidget::slotLSliderChanged(
int l)
607 mColor.setLab(l, a, b);
609 emit colorChanged(mColor);
613void LABWidget::slotASliderChanged(
int a)
618 mColor.setLab(l, a, b);
620 emit colorChanged(mColor);
623void LABWidget::slotBSliderChanged(
int b)
628 mColor.setLab(l, a, b);
630 emit colorChanged(mColor);
633void LABWidget::slotLInChanged(
int l)
638 mColor.setLab(l, a, b);
640 emit colorChanged(mColor);
643void LABWidget::slotAInChanged(
int a)
648 mColor.setLab(l, a, b);
650 emit colorChanged(mColor);
653void LABWidget::slotBInChanged(
int b)
658 mColor.setLab(l, a, b);
660 emit colorChanged(mColor);
663void LABWidget::slotPatchChanged(
const TQColor& clr)
669 mColor.setRGB(r, g, b);
671 emit colorChanged(mColor);
674#include "koColorChooser.moc"
const char * name(StdAction id)