21#include <tqgroupbox.h>
25#include <kcolordialog.h>
32#include "vselection.h"
37VColorTab::VColorTab(
const VColor &c, TQWidget* parent,
const char* name )
38 : TQTabWidget( parent, name )
40 TQGridLayout *mainLayout;
42 mRGBWidget =
new TQWidget(
this );
43 mainLayout =
new TQGridLayout( mRGBWidget, 3, 3 );
44 mColorSelector =
new KHSSelector( mRGBWidget );
45 mColorSelector->setMinimumHeight( 165 );
46 mColorSelector->setMinimumWidth( 165 );
47 connect( mColorSelector, TQ_SIGNAL( valueChanged(
int,
int ) ),
this, TQ_SLOT( slotHSChanged(
int,
int ) ) );
48 mainLayout->addMultiCellWidget(mColorSelector, 0, 2, 0, 0 );
51 mSelector =
new KGradientSelector( TQt::Vertical, mRGBWidget );
52 mSelector->setColors( TQColor(
"white" ), TQColor(
"black" ) );
53 mSelector->setMinimumWidth( 20 );
55 connect( mSelector, TQ_SIGNAL( valueChanged(
int ) ),
this, TQ_SLOT( slotVChanged(
int ) ) );
56 mainLayout->addMultiCellWidget( mSelector, 0, 2, 1, 1 );
59 TQGroupBox* groupbox =
new TQGroupBox( 2,TQt::Vertical, i18n(
"Reference" ), mRGBWidget );
60 new TQLabel( i18n(
"Old:" ), groupbox );
61 new TQLabel( i18n(
"New:" ), groupbox );
62 mOldColor =
new KColorPatch( groupbox );
63 mColorPreview =
new KColorPatch( groupbox );
66 mOldColor->setColor( color );
67 mColorPreview->setColor( color );
68 mainLayout->addWidget( groupbox, 0, 2 );
71 TQGroupBox* cgroupbox =
new TQGroupBox( 3,TQt::Vertical, i18n(
"Components" ), mRGBWidget );
74 new TQLabel( i18n(
"R:" ), cgroupbox );
75 new TQLabel( i18n(
"G:" ), cgroupbox );
76 new TQLabel( i18n(
"B:" ), cgroupbox );
77 mRed =
new KIntSpinBox( 0, 255, 1, 0, 10, cgroupbox );
78 mGreen =
new KIntSpinBox( 0, 255, 1, 0, 10, cgroupbox );
79 mBlue =
new KIntSpinBox( 0, 255, 1, 0, 10, cgroupbox );
80 connect( mRed, TQ_SIGNAL( valueChanged(
int) ),
this, TQ_SLOT( slotUpdateFromRGBSpinBoxes() ) );
81 connect( mGreen, TQ_SIGNAL( valueChanged(
int) ),
this, TQ_SLOT( slotUpdateFromRGBSpinBoxes() ) );
82 connect( mBlue, TQ_SIGNAL( valueChanged(
int) ),
this, TQ_SLOT( slotUpdateFromRGBSpinBoxes() ) );
85 new TQLabel( i18n(
"Hue:",
"H:" ), cgroupbox );
86 new TQLabel( i18n(
"Saturation:",
"S:" ), cgroupbox );
87 new TQLabel( i18n(
"Value:",
"V:" ), cgroupbox );
88 mHue =
new KIntSpinBox( 0, 359, 1, 0, 10, cgroupbox );
89 mSaturation =
new KIntSpinBox( 0, 255, 1, 0, 10, cgroupbox );
90 mValue =
new KIntSpinBox( 0, 255, 1, 0, 10, cgroupbox );
91 connect( mHue, TQ_SIGNAL( valueChanged(
int) ),
this, TQ_SLOT( slotUpdateFromHSVSpinBoxes() ) );
92 connect( mSaturation, TQ_SIGNAL( valueChanged(
int) ),
this, TQ_SLOT( slotUpdateFromHSVSpinBoxes() ) );
93 connect( mValue, TQ_SIGNAL( valueChanged(
int) ),
this, TQ_SLOT( slotUpdateFromHSVSpinBoxes() ) );
94 mainLayout->addWidget( cgroupbox, 1, 2 );
97 TQGroupBox* ogroupBox =
new TQGroupBox( 1,TQt::Vertical, i18n(
"Opacity" ), mRGBWidget );
98 mOpacity =
new KIntNumInput( 100, ogroupBox );
99 mOpacity->setRange( 0, 100, 1,
true );
100 mOpacity->setValue(
int( c.
opacity() * 100.0 ) );
101 mainLayout->addWidget( ogroupBox, 2, 2 );
103 mainLayout->setSpacing( 2 );
104 mainLayout->setMargin( 5 );
106 mainLayout->activate();
108 addTab( mRGBWidget, i18n(
"RGB" ) );
110 mRed->setValue( color.red() );
111 mGreen->setValue( color.green() );
112 mBlue->setValue( color.blue() );
115void VColorTab::slotUpdateFromRGBSpinBoxes()
117 TQColor color( mRed->value(), mGreen->value(), mBlue->value(), TQColor::Rgb );
118 mColorPreview->setColor( color );
119 mColorPreview->update();
122 mHue->blockSignals(
true );
123 mSaturation->blockSignals(
true );
124 mValue->blockSignals(
true );
127 color.hsv( &h, &s, &v );
129 mSaturation->setValue( s );
130 mValue->setValue( v );
133 mSelector->blockSignals(
true );
134 mColorSelector->setValues( h, s );
135 slotHSChanged( h, s );
136 mSelector->setValue(
static_cast<int>( (
float( mValue->value() ) / 255.0 ) * 99.0 ) );
137 mSelector->blockSignals(
false );
139 mHue->blockSignals(
false );
140 mSaturation->blockSignals(
false );
141 mValue->blockSignals(
false );
144void VColorTab::slotUpdateFromHSVSpinBoxes()
146 TQColor color( mHue->value(), mSaturation->value(), mValue->value(), TQColor::Hsv );
147 mColorPreview->setColor( color );
148 mColorPreview->update();
151 mSelector->blockSignals(
true );
152 mSelector->setValue(
static_cast<int>( (
float( mValue->value() ) / 255.0 ) * 99.0 ) );
153 mSelector->blockSignals(
false );
156 mRed->blockSignals(
true );
157 mGreen->blockSignals(
true );
158 mBlue->blockSignals(
true );
160 mRed->setValue( color.red() );
161 mGreen->setValue( color.green() );
162 mBlue->setValue( color.blue() );
164 mRed->blockSignals(
false );
165 mGreen->blockSignals(
false );
166 mBlue->blockSignals(
false );
171 kdDebug() <<
"VColorTab::slotApplyButtonPressed" << endl;
172 float r = mRed->value() / 255.0, g = mGreen->value() / 255.0, b = mBlue->value() / 255.0;
173 float op = mOpacity->value() / 100.0;
182void VColorTab::slotHSChanged(
int h,
int s )
186 mSaturation->setValue( s );
187 TQColor color1( h, s, 255, TQColor::Hsv );
188 TQColor color2( h, s, 0, TQColor::Hsv );
189 mSelector->setColors( color1, color2 );
192void VColorTab::slotVChanged(
int newVal )
195 mValue->setValue(
static_cast<int>(
float( newVal ) / 99.0 * 255.0 ) );
198#include "vcolortab.moc"
This class keeps track of color properties.
void set(float v1)
Sets the first color component.
void setOpacity(float opacity)
Sets the color opacity.
float opacity() const
Returns the color opacity.