karbon

vcolortab.cc

00001 /* This file is part of the KDE project
00002    Copyright (C) 2001, The Karbon Developers
00003    Copyright (C) 2002, The Karbon Developers
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #include <qgroupbox.h>
00022 #include <qlabel.h>
00023 #include <qlayout.h>
00024 
00025 #include <kcolordialog.h>
00026 #include <klocale.h>
00027 #include <knuminput.h>
00028 
00029 #include "vcolor.h"
00030 #include "vfillcmd.h"
00031 #include "vcolortab.h"
00032 #include "vselection.h"
00033 
00034 #include <kdebug.h>
00035 
00036 
00037 VColorTab::VColorTab( const VColor &c, QWidget* parent, const char* name )
00038     : QTabWidget( parent, name )
00039 {
00040     QGridLayout *mainLayout;
00041 
00042     mRGBWidget = new QWidget( this );
00043     mainLayout = new QGridLayout( mRGBWidget, 3, 3 );
00044     mColorSelector = new KHSSelector( mRGBWidget );
00045     mColorSelector->setMinimumHeight( 165 );
00046     mColorSelector->setMinimumWidth( 165 );
00047     connect( mColorSelector, SIGNAL( valueChanged( int, int ) ), this, SLOT( slotHSChanged( int, int ) ) );
00048     mainLayout->addMultiCellWidget(mColorSelector, 0, 2, 0, 0 );
00049 
00050     //Selector
00051     mSelector = new KGradientSelector( KSelector::Vertical, mRGBWidget );
00052     mSelector->setColors( QColor( "white" ), QColor( "black" ) );
00053     mSelector->setMinimumWidth( 20 );
00054     //TODO: Make it autochange color if the solid-filled object is selected (also for QSpinBoxes)
00055     connect( mSelector, SIGNAL( valueChanged( int ) ), this, SLOT( slotVChanged( int ) ) );
00056     mainLayout->addMultiCellWidget( mSelector, 0, 2, 1, 1 );
00057 
00058     //Reference
00059     QGroupBox* groupbox = new QGroupBox( 2, Vertical, i18n( "Reference" ), mRGBWidget );
00060     new QLabel( i18n( "Old:" ), groupbox );
00061     new QLabel( i18n( "New:" ), groupbox );
00062     mOldColor = new KColorPatch( groupbox );
00063     mColorPreview = new KColorPatch( groupbox );
00064 
00065     QColor color( c );
00066     mOldColor->setColor( color );
00067     mColorPreview->setColor( color );
00068     mainLayout->addWidget( groupbox, 0, 2 );
00069 
00070     //Components
00071     QGroupBox* cgroupbox = new QGroupBox( 3, Vertical, i18n( "Components" ), mRGBWidget );
00072 
00073     //--->RGB
00074     new QLabel( i18n( "R:" ), cgroupbox );
00075     new QLabel( i18n( "G:" ), cgroupbox );
00076     new QLabel( i18n( "B:" ), cgroupbox );
00077     mRed = new KIntSpinBox( 0, 255, 1, 0, 10, cgroupbox );
00078     mGreen = new KIntSpinBox( 0, 255, 1, 0, 10, cgroupbox );
00079     mBlue = new KIntSpinBox( 0, 255, 1, 0, 10, cgroupbox );
00080     connect( mRed, SIGNAL( valueChanged(int) ), this, SLOT( slotUpdateFromRGBSpinBoxes() ) );
00081     connect( mGreen, SIGNAL( valueChanged(int) ), this, SLOT( slotUpdateFromRGBSpinBoxes() ) );
00082     connect( mBlue, SIGNAL( valueChanged(int) ), this, SLOT( slotUpdateFromRGBSpinBoxes() ) );
00083 
00084     //--->HSV
00085     new QLabel( i18n( "Hue:", "H:" ), cgroupbox );
00086     new QLabel( i18n( "Saturation:", "S:" ), cgroupbox );
00087     new QLabel( i18n( "Value:", "V:" ), cgroupbox );
00088     mHue = new KIntSpinBox( 0, 359, 1, 0, 10, cgroupbox );
00089     mSaturation = new KIntSpinBox( 0, 255, 1, 0, 10, cgroupbox );
00090     mValue = new KIntSpinBox( 0, 255, 1, 0, 10, cgroupbox );
00091     connect( mHue, SIGNAL( valueChanged(int) ), this, SLOT( slotUpdateFromHSVSpinBoxes() ) );
00092     connect( mSaturation, SIGNAL( valueChanged(int) ), this, SLOT( slotUpdateFromHSVSpinBoxes() ) );
00093     connect( mValue, SIGNAL( valueChanged(int) ), this, SLOT( slotUpdateFromHSVSpinBoxes() ) );
00094     mainLayout->addWidget( cgroupbox, 1, 2 );
00095 
00096     //--->Opacity
00097     QGroupBox* ogroupBox = new QGroupBox( 1, Vertical, i18n( "Opacity" ), mRGBWidget );
00098     mOpacity = new KIntNumInput( 100, ogroupBox );
00099     mOpacity->setRange( 0, 100, 1, true );
00100     mOpacity->setValue( int( c.opacity() * 100.0 ) );
00101     mainLayout->addWidget( ogroupBox, 2, 2 );
00102 
00103     mainLayout->setSpacing( 2 );
00104     mainLayout->setMargin( 5 );
00105 
00106     mainLayout->activate();
00107 
00108     addTab( mRGBWidget, i18n( "RGB" ) );
00109 
00110     mRed->setValue( color.red() );
00111     mGreen->setValue( color.green() );
00112     mBlue->setValue( color.blue() );
00113 }
00114 
00115 void VColorTab::slotUpdateFromRGBSpinBoxes()
00116 {
00117     QColor color( mRed->value(), mGreen->value(), mBlue->value(), QColor::Rgb );
00118     mColorPreview->setColor( color );
00119     mColorPreview->update();
00120 
00121     // set HSV
00122     mHue->blockSignals( true );
00123     mSaturation->blockSignals( true );
00124     mValue->blockSignals( true );
00125 
00126     int h, s, v;
00127     color.hsv( &h, &s, &v );
00128     mHue->setValue( h );
00129     mSaturation->setValue( s );
00130     mValue->setValue( v );
00131 
00132     // update gradient selector
00133     mSelector->blockSignals( true );
00134     mColorSelector->setValues( h, s );
00135     slotHSChanged( h, s );
00136     mSelector->setValue( static_cast<int>( ( float( mValue->value() ) / 255.0 ) * 99.0 ) );
00137     mSelector->blockSignals( false );
00138 
00139     mHue->blockSignals( false );
00140     mSaturation->blockSignals( false );
00141     mValue->blockSignals( false );
00142 }
00143 
00144 void VColorTab::slotUpdateFromHSVSpinBoxes()
00145 {
00146     QColor color( mHue->value(), mSaturation->value(), mValue->value(), QColor::Hsv );
00147     mColorPreview->setColor( color );
00148     mColorPreview->update();
00149 
00150     // update gradient selector
00151     mSelector->blockSignals( true );
00152     mSelector->setValue( static_cast<int>( ( float( mValue->value() ) / 255.0 ) * 99.0 ) );
00153     mSelector->blockSignals( false );
00154 
00155     // set RGB
00156     mRed->blockSignals( true );
00157     mGreen->blockSignals( true );
00158     mBlue->blockSignals( true );
00159 
00160     mRed->setValue( color.red() );
00161     mGreen->setValue( color.green() );
00162     mBlue->setValue( color.blue() );
00163 
00164     mRed->blockSignals( false );
00165     mGreen->blockSignals( false );
00166     mBlue->blockSignals( false );
00167 }
00168 
00169 VColor VColorTab::Color()
00170 {
00171     kdDebug() << "VColorTab::slotApplyButtonPressed" << endl;
00172     float r = mRed->value() / 255.0, g = mGreen->value() / 255.0, b = mBlue->value() / 255.0;
00173     float op = mOpacity->value() / 100.0;
00174 
00175     VColor c;
00176     c.set( r, g, b );
00177     c.setOpacity( op );
00178 
00179     return c;
00180 }
00181 
00182 void VColorTab::slotHSChanged( int h, int s )
00183 {
00184     //QColor color( mHue->value(), mSaturation->value(), newVal, QColor::Hsv );
00185     mHue->setValue( h );
00186     mSaturation->setValue( s );
00187     QColor color1( h, s, 255, QColor::Hsv );
00188     QColor color2( h, s, 0, QColor::Hsv );
00189     mSelector->setColors( color1, color2 );
00190 }
00191 
00192 void VColorTab::slotVChanged( int newVal )
00193 {
00194     //QColor color( mHue->value(), mSaturation->value(), newVal, QColor::Hsv );
00195     mValue->setValue( static_cast<int>( float( newVal ) / 99.0 * 255.0 ) );
00196 }
00197 
00198 #include "vcolortab.moc"
00199 
KDE Home | KDE Accessibility Home | Description of Access Keys