2
* Copyright (c) 2006 Casper Boemann (cbr@boemann.dk)
4
* This library is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU Library General Public
6
* License as published by the Free Software Foundation; either
7
* version 2 of the License, or (at your option) any later version.
9
* This library is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
* Library General Public License for more details.
14
* You should have received a copy of the GNU Library General Public License
15
* along with this library; see the file COPYING.LIB. If not, write to
16
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17
* Boston, MA 02110-1301, USA.
20
#include "KoUniColorChooser.h"
22
#include <kselector.h>
26
#include <QRadioButton>
28
#include <QGridLayout>
29
#include <kcolordialog.h>
35
#include "KoColorSpaceRegistry.h"
36
#include "KoXYColorSelector.h"
37
#include "KoColorSlider.h"
38
#include "KoColorPatch.h"
39
#include "KoColorSpace.h"
40
#include <KoColorModelStandardIds.h>
42
KoUniColorChooser::KoUniColorChooser(QWidget *parent, bool opacitySlider) : super(parent), m_showOpacitySlider(opacitySlider)
44
m_xycolorselector = new KoXYColorSelector(rgbColorSpace(), this);
45
m_xycolorselector->setFixedSize(137, 137);
47
m_colorSlider = new KoColorSlider(Qt::Vertical, this);
48
m_colorSlider->setFixedSize(25, 118);
50
m_colorpatch = new KoColorPatch(this);
51
m_colorpatch->setFixedSize(18, 18);
53
/* setup channel labels */
56
m_HLabel = new QLabel("H:", this);
57
//m_HLabel->setFixedSize(10, 18);
58
m_HLabel->setEnabled(false);
59
m_SLabel = new QLabel("S:", this);
60
//m_SLabel->setFixedSize(10, 18);
61
m_SLabel->setEnabled(false);
62
m_VLabel = new QLabel("V:", this);
63
//m_VLabel->setFixedSize(10, 18);
64
m_VLabel->setEnabled(false);
67
m_RLabel = new QLabel("R:", this);
68
//m_RLabel->setFixedSize(10, 18);
69
m_GLabel = new QLabel("G:", this);
70
//m_GLabel->setFixedSize(10, 18);
71
m_BLabel = new QLabel("B:", this);
72
//m_BLabel->setFixedSize(10, 18);
75
if ( cmykColorSpace() ) {
76
m_CLabel = new QLabel("C:", this);
77
//m_CLabel->setFixedSize(10, 18);
78
m_MLabel = new QLabel("M:", this);
79
// m_MLabel->setFixedSize(10, 18);
80
m_YLabel = new QLabel("Y:", this);
81
//m_YLabel->setFixedSize(10, 18);
82
m_KLabel = new QLabel("K:", this);
83
//m_KLabel->setFixedSize(10, 18);
87
m_LLabel = new QLabel("L:", this);
88
//m_LLabel->setFixedSize(10, 18);
89
m_aLabel = new QLabel("a:", this);
90
//m_aLabel->setFixedSize(10, 18);
91
m_bLabel = new QLabel("b:", this);
92
//m_bLabel->setFixedSize(10, 18);
94
/* setup sradio buttons */
95
m_HRB = new QRadioButton(this);
96
m_SRB = new QRadioButton(this);
97
m_VRB = new QRadioButton(this);
99
m_RRB = new QRadioButton(this);
100
m_GRB = new QRadioButton(this);
101
m_BRB = new QRadioButton(this);
103
m_LRB = new QRadioButton(this);
104
m_aRB = new QRadioButton(this);
105
m_bRB = new QRadioButton(this);
108
m_HIn = new QSpinBox(this);
109
m_HIn->setMinimum(0);
110
m_HIn->setMaximum(359); // Is this correct? 359?
111
m_HIn->setSingleStep(1);
112
// m_HIn->setFixedSize(40, 18);
113
m_HIn->setFocusPolicy( Qt::ClickFocus );
114
m_HIn->setToolTip( i18n( "Hue" ) );
115
m_HIn->setEnabled(false);
117
m_SIn = new QSpinBox(this);
118
m_SIn->setMinimum(0);
119
m_SIn->setMaximum(255);
120
m_SIn->setSingleStep(1);
121
//m_SIn->setFixedSize(40, 18);
122
m_SIn->setFocusPolicy( Qt::ClickFocus );
123
m_SIn->setToolTip( i18n( "Saturation" ) );
124
m_SIn->setEnabled(false);
126
m_VIn = new QSpinBox(this);
127
m_VIn->setMinimum(0);
128
m_VIn->setMaximum(255);
129
m_VIn->setSingleStep(1);
130
//m_VIn->setFixedSize(40, 18);
131
m_VIn->setFocusPolicy( Qt::ClickFocus );
132
m_VIn->setToolTip( i18n( "Value (brightness)" ) );
133
m_VIn->setEnabled(false);
135
m_RIn = new QSpinBox(this);
136
m_RIn->setMinimum(0);
137
m_RIn->setMaximum(255);
138
m_RIn->setSingleStep(1);
139
//m_RIn->setFixedSize(40, 18);
140
m_RIn->setFocusPolicy( Qt::ClickFocus );
141
m_RIn->setToolTip( i18n( "Red" ) );
143
m_GIn = new QSpinBox(this);
144
m_GIn->setMinimum(0);
145
m_GIn->setMaximum(255);
146
m_GIn->setSingleStep(1);
147
//m_GIn->setFixedSize(40, 18);
148
m_GIn->setFocusPolicy( Qt::ClickFocus );
149
m_GIn->setToolTip( i18n( "Green" ) );
151
m_BIn = new QSpinBox(this);
152
m_BIn->setMinimum(0);
153
m_BIn->setMaximum(255);
154
m_BIn->setSingleStep(1);
155
//m_BIn->setFixedSize(40, 18);
156
m_BIn->setFocusPolicy( Qt::ClickFocus );
157
m_BIn->setToolTip( i18n( "Blue" ) );
159
if ( cmykColorSpace() ) {
160
m_CIn = new QSpinBox(this);
161
m_CIn->setMinimum(0);
162
m_CIn->setMaximum(255);
163
m_CIn->setSingleStep(1);
164
//m_CIn->setFixedSize(40, 18);
165
m_CIn->setFocusPolicy( Qt::ClickFocus );
166
m_CIn->setToolTip( i18n( "Cyan" ) );
168
m_MIn = new QSpinBox(this);
169
m_MIn->setMinimum(0);
170
m_MIn->setMaximum(255);
171
m_MIn->setSingleStep(1);
172
//m_MIn->setFixedSize(40, 18);
173
m_MIn->setFocusPolicy( Qt::ClickFocus );
174
m_MIn->setToolTip( i18n( "Magenta" ) );
176
m_YIn = new QSpinBox(this);
177
m_YIn->setMinimum(0);
178
m_YIn->setMaximum(255);
179
m_YIn->setSingleStep(1);
180
//m_YIn->setFixedSize(40, 18);
181
m_YIn->setFocusPolicy( Qt::ClickFocus );
182
m_YIn->setToolTip( i18n( "Yellow" ) );
184
m_KIn = new QSpinBox(this);
185
m_KIn->setMinimum(0);
186
m_KIn->setMaximum(255);
187
m_KIn->setSingleStep(1);
188
//m_KIn->setFixedSize(40, 18);
189
m_KIn->setFocusPolicy( Qt::ClickFocus );
190
m_KIn->setToolTip( i18n( "Black" ) );
193
m_LIn = new QSpinBox(this);
194
m_LIn->setMinimum(0);
195
m_LIn->setMaximum(100);
196
m_LIn->setSingleStep(1);
197
//m_LIn->setFixedSize(40, 18);
198
m_LIn->setFocusPolicy( Qt::ClickFocus );
199
m_LIn->setToolTip( i18n( "Lightness" ) );
201
m_aIn = new QSpinBox(this);
202
m_aIn->setMinimum(0);
203
m_aIn->setMaximum(255);
204
m_aIn->setSingleStep(1);
205
//m_aIn->setFixedSize(40, 18);
206
m_aIn->setFocusPolicy( Qt::ClickFocus );
207
m_aIn->setToolTip( i18n( "Green to magenta*" ) );
209
m_bIn = new QSpinBox(this);
210
m_bIn->setMinimum(0);
211
m_bIn->setMaximum(255);
212
m_bIn->setSingleStep(1);
213
//m_bIn->setFixedSize(40, 18);
214
m_bIn->setFocusPolicy( Qt::ClickFocus );
215
m_bIn->setToolTip( i18n( "Blue to yellow" ) );
217
if(m_showOpacitySlider)
219
m_opacityLabel = new QLabel(i18n( "Opacity:" ), this);
221
m_opacitySlider = new KoColorSlider(Qt::Horizontal, this);
222
m_opacitySlider->setFixedHeight(25);
223
m_opacitySlider->setRange(0, 100);
225
m_opacityIn = new QSpinBox(this);
226
m_opacityIn->setRange(0, 100);
227
m_opacityIn->setSingleStep(1);
228
m_opacityIn->setFixedSize(40, 18);
229
m_opacityIn->setFocusPolicy( Qt::ClickFocus );
231
connect(m_opacitySlider, SIGNAL(valueChanged(int)), this, SLOT(slotOpacityChanged(int)));
232
connect(m_opacityIn, SIGNAL(valueChanged(int)), this, SLOT(slotOpacityChanged(int)));
235
/* connect spin box */
236
connect(m_HIn, SIGNAL(valueChanged(int)), this, SLOT(slotHSVChanged()));
237
connect(m_SIn, SIGNAL(valueChanged(int)), this, SLOT(slotHSVChanged()));
238
connect(m_VIn, SIGNAL(valueChanged(int)), this, SLOT(slotHSVChanged()));
240
connect(m_RIn, SIGNAL(valueChanged(int)), this, SLOT(slotRGBChanged()));
241
connect(m_GIn, SIGNAL(valueChanged(int)), this, SLOT(slotRGBChanged()));
242
connect(m_BIn, SIGNAL(valueChanged(int)), this, SLOT(slotRGBChanged()));
244
/* connect radio buttons */
245
connect(m_HRB, SIGNAL(toggled(bool)), this, SLOT(slotHSelected(bool)));
246
connect(m_SRB, SIGNAL(toggled(bool)), this, SLOT(slotSSelected(bool)));
247
connect(m_VRB, SIGNAL(toggled(bool)), this, SLOT(slotVSelected(bool)));
249
connect(m_RRB, SIGNAL(toggled(bool)), this, SLOT(slotRSelected(bool)));
250
connect(m_GRB, SIGNAL(toggled(bool)), this, SLOT(slotGSelected(bool)));
251
connect(m_BRB, SIGNAL(toggled(bool)), this, SLOT(slotBSelected(bool)));
254
connect(m_xycolorselector, SIGNAL(valueChanged(int,int)), this, SLOT(slotXYChanged(int,int)));
257
connect(m_colorSlider, SIGNAL(valueChanged(int)), this, SLOT(slotSliderChanged(int)));
259
m_RRB->setChecked(true);
266
void KoUniColorChooser::doComplexLayout()
268
QGridLayout *mGrid = new QGridLayout;
269
QGridLayout *mGrowGrid = new QGridLayout;
271
mGrid->setSpacing(1);
274
mGrid->addWidget(m_xycolorselector, 0, 0, -1, 1, Qt::AlignTop);
276
mGrid->addWidget(m_colorpatch, 0, 1, 1, 4, Qt::AlignCenter);
278
mGrid->addWidget(m_colorSlider, 1, 1, -1, 1, Qt::AlignTop);
280
mGrid->addWidget(m_HRB, 1, 2, Qt::AlignCenter);
281
mGrid->addWidget(m_SRB, 2, 2, Qt::AlignCenter);
282
mGrid->addWidget(m_VRB, 3, 2, Qt::AlignCenter);
284
mGrid->addWidget(m_RRB, 5, 2, Qt::AlignCenter);
285
mGrid->addWidget(m_GRB, 6, 2, Qt::AlignCenter);
286
mGrid->addWidget(m_BRB, 7, 2, Qt::AlignCenter);
288
mGrid->addWidget(m_LRB, 5, 6, Qt::AlignCenter);
289
mGrid->addWidget(m_aRB, 6, 6, Qt::AlignCenter);
290
mGrid->addWidget(m_bRB, 7, 6, Qt::AlignCenter);
292
mGrid->addWidget(m_HLabel, 1, 3, Qt::AlignTop);
293
mGrid->addWidget(m_SLabel, 2, 3, Qt::AlignTop);
294
mGrid->addWidget(m_VLabel, 3, 3, Qt::AlignTop);
296
mGrid->addWidget(m_RLabel, 5, 3, Qt::AlignTop);
297
mGrid->addWidget(m_GLabel, 6, 3, Qt::AlignTop);
298
mGrid->addWidget(m_BLabel, 7, 3, Qt::AlignTop);
300
if ( cmykColorSpace() ) {
301
mGrid->addWidget(m_CLabel, 0, 7, Qt::AlignTop);
302
mGrid->addWidget(m_MLabel, 1, 7, Qt::AlignTop);
303
mGrid->addWidget(m_YLabel, 2, 7, Qt::AlignTop);
304
mGrid->addWidget(m_KLabel, 3, 7, Qt::AlignTop);
308
mGrid->addWidget(m_LLabel, 5, 7, Qt::AlignTop);
309
mGrid->addWidget(m_aLabel, 6, 7, Qt::AlignTop);
310
mGrid->addWidget(m_bLabel, 7, 7, Qt::AlignTop);
312
mGrid->addWidget(m_HIn, 1, 4, Qt::AlignTop);
313
mGrid->addWidget(m_SIn, 2, 4, Qt::AlignTop);
314
mGrid->addWidget(m_VIn, 3, 4, Qt::AlignTop);
316
mGrid->addWidget(m_RIn, 5, 4, Qt::AlignTop);
317
mGrid->addWidget(m_GIn, 6, 4, Qt::AlignTop);
318
mGrid->addWidget(m_BIn, 7, 4, Qt::AlignTop);
320
if ( cmykColorSpace() ) {
321
mGrid->addWidget(m_CIn, 0, 8, Qt::AlignTop);
322
mGrid->addWidget(m_MIn, 1, 8, Qt::AlignTop);
323
mGrid->addWidget(m_YIn, 2, 8, Qt::AlignTop);
324
mGrid->addWidget(m_KIn, 3, 8, Qt::AlignTop);
327
mGrid->addWidget(m_LIn, 5, 8, Qt::AlignTop);
328
mGrid->addWidget(m_aIn, 6, 8, Qt::AlignTop);
329
mGrid->addWidget(m_bIn, 7, 8, Qt::AlignTop);
331
if(m_showOpacitySlider)
333
mGrid->addItem( new QSpacerItem( 4, 4, QSizePolicy::Fixed, QSizePolicy::Fixed), 8, 5 );
335
mGrid->addWidget(m_opacityLabel, 9, 0, Qt::AlignRight | Qt::AlignTop);
336
mGrid->addWidget(m_opacitySlider, 9, 1, 1, 7, Qt::AlignTop);
337
mGrid->addWidget(m_opacityIn, 9, 8, Qt::AlignTop);
340
mGrid->addItem( new QSpacerItem( 4, 4, QSizePolicy::Fixed, QSizePolicy::Fixed), 4, 5 );
342
mGrowGrid->addLayout(mGrid, 0, 0);
343
mGrowGrid->setSpacing(0);
344
mGrowGrid->setMargin(0);
345
mGrowGrid->addItem( new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Expanding ), 1, 1 );
347
setLayout(mGrowGrid);
350
void KoUniColorChooser::doSimpleLayout()
352
m_HRB->setVisible( false );
353
m_SRB->setVisible( false );
354
m_VRB->setVisible( false );
356
m_RRB->setVisible( false );
357
m_GRB->setVisible( false );
358
m_BRB->setVisible( false );
360
m_LRB->setVisible( false );
361
m_aRB->setVisible( false );
362
m_bRB->setVisible( false );
364
m_HLabel->setVisible( false );
365
m_SLabel->setVisible( false );
366
m_VLabel->setVisible( false );
368
m_RLabel->setVisible( false );
369
m_GLabel->setVisible( false );
370
m_BLabel->setVisible( false );
372
if ( cmykColorSpace() ) {
373
m_CLabel->setVisible( false );
374
m_MLabel->setVisible( false );
375
m_YLabel->setVisible( false );
376
m_KLabel->setVisible( false );
380
m_LLabel->setVisible( false );
381
m_aLabel->setVisible( false );
382
m_bLabel->setVisible( false );
384
m_HIn->setVisible( false );
385
m_SIn->setVisible( false );
386
m_VIn->setVisible( false );
388
m_RIn->setVisible( false );
389
m_GIn->setVisible( false );
390
m_BIn->setVisible( false );
392
if ( cmykColorSpace() ) {
393
m_CIn->setVisible( false );
394
m_MIn->setVisible( false );
395
m_YIn->setVisible( false );
396
m_KIn->setVisible( false );
399
m_LIn->setVisible( false );
400
m_aIn->setVisible( false );
401
m_bIn->setVisible( false );
403
if(m_showOpacitySlider)
405
m_opacityLabel->setVisible( false );
406
m_opacityIn->setVisible( false );
409
QGridLayout * layout = new QGridLayout;
411
layout->setSpacing( 5 );
413
if( m_showOpacitySlider )
415
m_opacitySlider->setFixedSize( 137, 25 );
416
m_opacitySlider->setToolTip( i18n( "Opacity" ) );
417
m_colorSlider->setFixedSize( 25, 137 );
419
layout->addWidget(m_xycolorselector, 0, 0, 1, 1 );
420
layout->addWidget(m_colorSlider, 0, 1, 1, 1 );
421
layout->addWidget(m_colorpatch, 1, 1, 1, 1, Qt::AlignLeft|Qt::AlignTop);
422
layout->addWidget(m_opacitySlider, 1, 0, 1, 1);
426
m_colorSlider->setFixedSize( 25, 115 );
427
layout->addWidget(m_xycolorselector, 0, 0, 2, 1 );
428
layout->addWidget(m_colorSlider, 0, 1, 1, 1 );
429
layout->addWidget(m_colorpatch, 1, 1, 1, 1, Qt::AlignLeft|Qt::AlignTop);
432
layout->setColumnStretch( 0, 1 );
433
layout->setColumnStretch( 1, 0 );
434
layout->setColumnStretch( 2, 1 );
435
layout->setRowStretch( 0, 1 );
436
layout->setRowStretch( 1, 0 );
437
layout->setRowStretch( 2, 1 );
442
void KoUniColorChooser::changeLayout( LayoutType type )
457
KoColor KoUniColorChooser::color()
459
return m_currentColor;
462
void KoUniColorChooser::setColor(const KoColor & c)
466
updateSelectorsCurrent();
467
m_colorpatch->setColor(m_currentColor);
470
void KoUniColorChooser::slotHSVChanged()
473
HSVtoRGB(m_HIn->value(), m_SIn->value(), m_VIn->value(), data+2, data+1, data);
474
data[3] = m_currentColor.colorSpace()->opacityU8(m_currentColor.data());
475
m_currentColor.setColor(data, rgbColorSpace());
477
updateSelectorsCurrent();
481
void KoUniColorChooser::slotRGBChanged()
484
data[2] = m_RIn->value();
485
data[1] = m_GIn->value();
486
data[0] = m_BIn->value();
487
data[3] = m_currentColor.colorSpace()->opacityU8(m_currentColor.data());
488
m_currentColor.setColor(data, rgbColorSpace());
490
updateSelectorsCurrent();
494
void KoUniColorChooser::slotSliderChanged(int v)
497
data[3] = m_currentColor.colorSpace()->opacityU8(m_currentColor.data());
498
switch(m_activeChannel)
501
HSVtoRGB(v, m_SIn->value(), m_VIn->value(), data+2, data+1, data);
502
m_currentColor.setColor(data, rgbColorSpace());
505
HSVtoRGB(m_HIn->value(), v, m_VIn->value(), data+2, data+1, data);
506
m_currentColor.setColor(data, rgbColorSpace());
509
HSVtoRGB(m_HIn->value(), m_SIn->value(), v, data+2, data+1, data);
510
m_currentColor.setColor(data, rgbColorSpace());
514
data[1] = m_GIn->value();
515
data[0] = m_BIn->value();
516
m_currentColor.setColor(data, rgbColorSpace());
519
data[2] = m_RIn->value();
521
data[0] = m_BIn->value();
522
m_currentColor.setColor(data, rgbColorSpace());
525
data[2] = m_RIn->value();
526
data[1] = m_GIn->value();
528
m_currentColor.setColor(data, rgbColorSpace());
531
//slotRSelected(true);
534
//slotGSelected(true);
537
//slotBSelected(true);
541
updateSelectorsCurrent();
545
void KoUniColorChooser::slotXYChanged(int u, int v)
548
data[3] = m_currentColor.colorSpace()->opacityU8(m_currentColor.data());
549
switch(m_activeChannel)
552
HSVtoRGB(m_HIn->value(), u, v, data+2, data+1, data);
553
m_currentColor.setColor(data, rgbColorSpace());
556
HSVtoRGB(u, m_SIn->value(), v, data+2, data+1, data);
557
m_currentColor.setColor(data, rgbColorSpace());
560
HSVtoRGB(u, v, m_VIn->value(), data+2, data+1, data);
561
m_currentColor.setColor(data, rgbColorSpace());
564
data[2] = m_RIn->value();
567
m_currentColor.setColor(data, rgbColorSpace());
571
data[1] = m_GIn->value();
573
m_currentColor.setColor(data, rgbColorSpace());
578
data[0] = m_BIn->value();
579
m_currentColor.setColor(data, rgbColorSpace());
589
updateSelectorsCurrent();
593
void KoUniColorChooser::slotOpacityChanged(int o)
595
qreal opacity = o / 100.0;
596
m_currentColor.colorSpace()->setOpacity(m_currentColor.data(), opacity, 1);
601
void KoUniColorChooser::slotHSelected(bool s)
605
m_activeChannel = CHANNEL_H;
610
void KoUniColorChooser::slotSSelected(bool s)
614
m_activeChannel = CHANNEL_S;
619
void KoUniColorChooser::slotVSelected(bool s)
623
m_activeChannel = CHANNEL_V;
628
void KoUniColorChooser::slotRSelected(bool s)
632
m_activeChannel = CHANNEL_R;
637
void KoUniColorChooser::slotGSelected(bool s)
641
m_activeChannel = CHANNEL_G;
646
void KoUniColorChooser::slotBSelected(bool s)
650
m_activeChannel = CHANNEL_B;
655
void KoUniColorChooser::updateSelectorsR()
657
//kDebug(30004)() <<"R selected";
660
data[2] = m_RIn->value();
664
KoColor topleft(data, rgbColorSpace());
667
KoColor topright(data, rgbColorSpace());
670
KoColor bottomleft(data, rgbColorSpace());
673
KoColor bottomright(data, rgbColorSpace());
675
m_xycolorselector->setColors(topleft,topright,bottomleft,bottomright);
678
data[1] = m_GIn->value();
679
data[0] = m_BIn->value();
680
KoColor mincolor(data, rgbColorSpace());
682
KoColor maxcolor(data, rgbColorSpace());
684
m_colorSlider->setColors(mincolor, maxcolor);
686
m_xycolorselector->blockSignals(true);
687
m_colorSlider->blockSignals(true);
688
m_xycolorselector->setValues(m_BIn->value(), m_GIn->value());
689
m_colorSlider->setValue(m_RIn->value());
690
m_xycolorselector->blockSignals(false);
691
m_colorSlider->blockSignals(false);
694
void KoUniColorChooser::updateSelectorsG()
696
//kDebug(30004)() <<"G selected";
700
data[1] = m_GIn->value();
703
KoColor topleft(data, rgbColorSpace());
706
KoColor topright(data, rgbColorSpace());
709
KoColor bottomleft(data, rgbColorSpace());
712
KoColor bottomright(data, rgbColorSpace());
714
m_xycolorselector->setColors(topleft,topright,bottomleft,bottomright);
716
data[2] = m_RIn->value();
718
data[0] = m_BIn->value();
719
KoColor mincolor(data, rgbColorSpace());
721
KoColor maxcolor(data, rgbColorSpace());
723
m_colorSlider->setColors(mincolor, maxcolor);
725
m_xycolorselector->blockSignals(true);
726
m_colorSlider->blockSignals(true);
727
m_xycolorselector->setValues(m_BIn->value(), m_RIn->value());
728
m_colorSlider->setValue(m_GIn->value());
729
m_xycolorselector->blockSignals(false);
730
m_colorSlider->blockSignals(false);
733
void KoUniColorChooser::updateSelectorsB()
735
//kDebug(30004)() <<"B selected";
740
data[0] = m_BIn->value();
742
KoColor topleft(data, rgbColorSpace());
745
KoColor topright(data, rgbColorSpace());
748
KoColor bottomleft(data, rgbColorSpace());
751
KoColor bottomright(data, rgbColorSpace());
753
m_xycolorselector->setColors(topleft,topright,bottomleft,bottomright);
755
data[2] = m_RIn->value();
756
data[1] = m_GIn->value();
758
KoColor mincolor(data, rgbColorSpace());
760
KoColor maxcolor(data, rgbColorSpace());
762
m_colorSlider->setColors(mincolor, maxcolor);
764
m_xycolorselector->blockSignals(true);
765
m_colorSlider->blockSignals(true);
766
m_xycolorselector->setValues(m_RIn->value(), m_GIn->value());
767
m_colorSlider->setValue(m_BIn->value());
768
m_xycolorselector->blockSignals(false);
769
m_colorSlider->blockSignals(false);
772
void KoUniColorChooser::updateSelectorsCurrent()
774
switch(m_activeChannel)
795
//updateSelectorsL();
798
//updateSelectorsa();
801
//updateSelectorsb();
806
void KoUniColorChooser::announceColor()
808
m_colorpatch->setColor(m_currentColor);
810
emit sigColorChanged(m_currentColor);
813
void KoUniColorChooser::updateValues()
816
m_HIn->blockSignals(true);
817
m_SIn->blockSignals(true);
818
m_VIn->blockSignals(true);
819
m_RIn->blockSignals(true);
820
m_GIn->blockSignals(true);
821
m_BIn->blockSignals(true);
823
if (cmykColorSpace()) {
824
m_CIn->blockSignals(true);
825
m_MIn->blockSignals(true);
826
m_YIn->blockSignals(true);
827
m_KIn->blockSignals(true);
830
m_LIn->blockSignals(true);
831
m_aIn->blockSignals(true);
832
m_bIn->blockSignals(true);
835
KoOldColor color = m_fgColor;
845
tmpColor = m_currentColor;
846
tmpColor.convertTo(rgbColorSpace());
847
m_RIn->setValue(tmpColor.data()[2]);
848
m_GIn->setValue(tmpColor.data()[1]);
849
m_BIn->setValue(tmpColor.data()[0]);
851
if(m_showOpacitySlider)
853
m_opacitySlider->blockSignals(true);
854
m_opacityIn->blockSignals(true);
856
KoColor minColor = tmpColor;
857
tmpColor.colorSpace()->setOpacity(minColor.data(), OPACITY_TRANSPARENT_U8, 1);
858
KoColor maxColor = tmpColor;
859
tmpColor.colorSpace()->setOpacity(maxColor.data(), OPACITY_OPAQUE_U8, 1);
861
m_opacitySlider->setColors(minColor, maxColor);
862
m_opacitySlider->setValue(tmpColor.opacityF() * 100 );
863
m_opacityIn->setValue(tmpColor.opacityF() * 100 );
865
m_opacityIn->blockSignals(false);
866
m_opacitySlider->blockSignals(false);
869
tmpColor = m_currentColor;
870
tmpColor.convertTo(labColorSpace());
871
m_LIn->setValue(((quint16 *)tmpColor.data())[0]/(256*256/100));
872
m_aIn->setValue(((quint16 *)tmpColor.data())[1]/256);
873
m_bIn->setValue(((quint16 *)tmpColor.data())[2]/256);
875
if ( cmykColorSpace() ) {
876
tmpColor = m_currentColor;
877
tmpColor.convertTo(cmykColorSpace());
878
m_CIn->setValue((tmpColor.data()[0]*100)/255);
879
m_MIn->setValue((tmpColor.data()[1]*100/255));
880
m_YIn->setValue((tmpColor.data()[2]*100)/255);
881
m_KIn->setValue((tmpColor.data()[3]*100)/255);
884
m_HIn->blockSignals(false);
885
m_SIn->blockSignals(false);
886
m_VIn->blockSignals(false);
887
m_RIn->blockSignals(false);
888
m_GIn->blockSignals(false);
889
m_BIn->blockSignals(false);
891
if (cmykColorSpace()) {
892
m_CIn->blockSignals(false);
893
m_MIn->blockSignals(false);
894
m_YIn->blockSignals(false);
895
m_KIn->blockSignals(false);
898
m_LIn->blockSignals(false);
899
m_aIn->blockSignals(false);
900
m_bIn->blockSignals(false);
903
const KoColorSpace *KoUniColorChooser::rgbColorSpace()
905
return KoColorSpaceRegistry::instance()->rgb8();
908
const KoColorSpace *KoUniColorChooser::labColorSpace()
910
return KoColorSpaceRegistry::instance()->lab16();
913
const KoColorSpace *KoUniColorChooser::cmykColorSpace()
915
return KoColorSpaceRegistry::instance()->colorSpace( CMYKAColorModelID.id(), Integer8BitsColorDepthID.id(), 0);
918
void KoUniColorChooser::RGBtoHSV(int R, int G, int B, int *H, int *S, int *V)
920
unsigned int max = R;
921
unsigned int min = R;
922
unsigned char maxValue = 0; // r = 0, g = 1, b = 2
924
// find maximum and minimum RGB values
925
if(static_cast<unsigned int>(G) > max)
930
if(static_cast<unsigned int>(B) > max)
936
if(static_cast<unsigned int>(G) < min)
938
if(static_cast<unsigned int>(B) < min )
941
int delta = max - min;
943
*S = max ? (510 * delta + max) / ( 2 * max) : 0; // saturation
947
*H = -1; // undefined hue
954
*H = (120 * (G - B) + delta) / (2 * delta);
956
*H = (120 * (G - B + delta) + delta) / (2 * delta) + 300;
960
*H = 120 + (120 * (B - R) + delta) / (2 * delta);
962
*H = 60 + (120 * (B - R + delta) + delta) / (2 * delta);
966
*H = 240 + (120 * (R - G) + delta) / (2 * delta);
968
*H = 180 + (120 * (R - G + delta) + delta) / (2 * delta);
974
void KoUniColorChooser::HSVtoRGB(int H, int S, int V, quint8 *R, quint8 *G, quint8 *B)
978
if(S != 0 && H != -1) // chromatic
980
if(H >= 360) // angle > 360
983
unsigned int f = H % 60;
985
unsigned int p = static_cast<unsigned int>(2*V*(255-S)+255)/510;
990
q = static_cast<unsigned int>(2 * V * (15300 - S * f) + 15300) / 30600;
994
*R = static_cast<quint8>(q);
995
*G = static_cast<quint8>(V);
996
*B = static_cast<quint8>(p);
999
*R = static_cast<quint8>(p);
1000
*G = static_cast<quint8>(q);
1001
*B = static_cast<quint8>(V);
1004
*R = static_cast<quint8>(V);
1005
*G = static_cast<quint8>(p);
1006
*B = static_cast<quint8>(q);
1012
t = static_cast<unsigned int>(2 * V * (15300 - (S * (60 - f))) + 15300) / 30600;
1016
*R = static_cast<quint8>(V);
1017
*G = static_cast<quint8>(t);
1018
*B = static_cast<quint8>(p);
1021
*R = static_cast<quint8>(p);
1022
*G = static_cast<quint8>(V);
1023
*B = static_cast<quint8>(t);
1026
*R = static_cast<quint8>(t);
1027
*G = static_cast<quint8>(p);
1028
*B = static_cast<quint8>(V);
1035
#include <KoUniColorChooser.moc>