karbon

vcolortab.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2001, The Karbon Developers
3 Copyright (C) 2002, The Karbon Developers
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19*/
20
21#include <tqgroupbox.h>
22#include <tqlabel.h>
23#include <tqlayout.h>
24
25#include <kcolordialog.h>
26#include <tdelocale.h>
27#include <knuminput.h>
28
29#include "vcolor.h"
30#include "vfillcmd.h"
31#include "vcolortab.h"
32#include "vselection.h"
33
34#include <kdebug.h>
35
36
37VColorTab::VColorTab( const VColor &c, TQWidget* parent, const char* name )
38 : TQTabWidget( parent, name )
39{
40 TQGridLayout *mainLayout;
41
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 );
49
50 //Selector
51 mSelector = new KGradientSelector( TQt::Vertical, mRGBWidget );
52 mSelector->setColors( TQColor( "white" ), TQColor( "black" ) );
53 mSelector->setMinimumWidth( 20 );
54 //TODO: Make it autochange color if the solid-filled object is selected (also for TQSpinBoxes)
55 connect( mSelector, TQ_SIGNAL( valueChanged( int ) ), this, TQ_SLOT( slotVChanged( int ) ) );
56 mainLayout->addMultiCellWidget( mSelector, 0, 2, 1, 1 );
57
58 //Reference
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 );
64
65 TQColor color( c );
66 mOldColor->setColor( color );
67 mColorPreview->setColor( color );
68 mainLayout->addWidget( groupbox, 0, 2 );
69
70 //Components
71 TQGroupBox* cgroupbox = new TQGroupBox( 3,TQt::Vertical, i18n( "Components" ), mRGBWidget );
72
73 //--->RGB
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() ) );
83
84 //--->HSV
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 );
95
96 //--->Opacity
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 );
102
103 mainLayout->setSpacing( 2 );
104 mainLayout->setMargin( 5 );
105
106 mainLayout->activate();
107
108 addTab( mRGBWidget, i18n( "RGB" ) );
109
110 mRed->setValue( color.red() );
111 mGreen->setValue( color.green() );
112 mBlue->setValue( color.blue() );
113}
114
115void VColorTab::slotUpdateFromRGBSpinBoxes()
116{
117 TQColor color( mRed->value(), mGreen->value(), mBlue->value(), TQColor::Rgb );
118 mColorPreview->setColor( color );
119 mColorPreview->update();
120
121 // set HSV
122 mHue->blockSignals( true );
123 mSaturation->blockSignals( true );
124 mValue->blockSignals( true );
125
126 int h, s, v;
127 color.hsv( &h, &s, &v );
128 mHue->setValue( h );
129 mSaturation->setValue( s );
130 mValue->setValue( v );
131
132 // update gradient selector
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 );
138
139 mHue->blockSignals( false );
140 mSaturation->blockSignals( false );
141 mValue->blockSignals( false );
142}
143
144void VColorTab::slotUpdateFromHSVSpinBoxes()
145{
146 TQColor color( mHue->value(), mSaturation->value(), mValue->value(), TQColor::Hsv );
147 mColorPreview->setColor( color );
148 mColorPreview->update();
149
150 // update gradient selector
151 mSelector->blockSignals( true );
152 mSelector->setValue( static_cast<int>( ( float( mValue->value() ) / 255.0 ) * 99.0 ) );
153 mSelector->blockSignals( false );
154
155 // set RGB
156 mRed->blockSignals( true );
157 mGreen->blockSignals( true );
158 mBlue->blockSignals( true );
159
160 mRed->setValue( color.red() );
161 mGreen->setValue( color.green() );
162 mBlue->setValue( color.blue() );
163
164 mRed->blockSignals( false );
165 mGreen->blockSignals( false );
166 mBlue->blockSignals( false );
167}
168
169VColor VColorTab::Color()
170{
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;
174
175 VColor c;
176 c.set( r, g, b );
177 c.setOpacity( op );
178
179 return c;
180}
181
182void VColorTab::slotHSChanged( int h, int s )
183{
184 //TQColor color( mHue->value(), mSaturation->value(), newVal, TQColor::Hsv );
185 mHue->setValue( h );
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 );
190}
191
192void VColorTab::slotVChanged( int newVal )
193{
194 //TQColor color( mHue->value(), mSaturation->value(), newVal, TQColor::Hsv );
195 mValue->setValue( static_cast<int>( float( newVal ) / 99.0 * 255.0 ) );
196}
197
198#include "vcolortab.moc"
199
This class keeps track of color properties.
Definition vcolor.h:41
void set(float v1)
Sets the first color component.
Definition vcolor.h:91
void setOpacity(float opacity)
Sets the color opacity.
Definition vcolor.h:138
float opacity() const
Returns the color opacity.
Definition vcolor.h:131