00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <qlabel.h>
00022 #include <qlayout.h>
00023 #include <qtabwidget.h>
00024 #include <qwidget.h>
00025 #include <qcolor.h>
00026 #include <qtooltip.h>
00027 #include <qevent.h>
00028 #include <qptrlist.h>
00029
00030 #include <klocale.h>
00031 #include <KoMainWindow.h>
00032
00033 #include "karbon_part.h"
00034 #include "karbon_view.h"
00035 #include "karbon_factory.h"
00036 #include "karbon_resourceserver.h"
00037 #include "vcolor.h"
00038 #include "vcolorslider.h"
00039 #include "vselection.h"
00040 #include "vfillcmd.h"
00041 #include "vstrokecmd.h"
00042 #include "vcommand.h"
00043 #include "vobject.h"
00044
00045 #include "vcolordocker.h"
00046
00047 #include <ko_hsv_widget.h>
00048 #include <ko_cmyk_widget.h>
00049 #include <ko_rgb_widget.h>
00050 #include <koColor.h>
00051
00052 #include <kdebug.h>
00053
00054 VColorDocker::VColorDocker( KarbonPart* part, KarbonView* parent, const char* )
00055 : QWidget(), m_part ( part ), m_view( parent )
00056 {
00057 m_isStrokeDocker = false;
00058 setCaption( i18n( "Color Chooser" ) );
00059
00060 m_opacity = 1;
00061
00062 m_fillCmd = 0;
00063 m_strokeCmd = 0;
00064
00065 mTabWidget = new QTabWidget( this );
00066
00067
00068 mHSVWidget = new KoHSVWidget( mTabWidget );
00069 connect( mHSVWidget, SIGNAL( sigFgColorChanged( const QColor &) ), this, SLOT( updateFgColor( const QColor &) ) );
00070 connect( mHSVWidget, SIGNAL( sigBgColorChanged( const QColor &) ), this, SLOT( updateBgColor( const QColor &) ) );
00071 connect(this, SIGNAL(fgColorChanged(const QColor &)), mHSVWidget, SLOT(setFgColor(const QColor &)));
00072 connect(this, SIGNAL(bgColorChanged(const QColor &)), mHSVWidget, SLOT(setBgColor(const QColor &)));
00073 mTabWidget->addTab( mHSVWidget, i18n( "HSV" ) );
00074
00075
00076 mRGBWidget = new KoRGBWidget( mTabWidget );
00077 connect( mRGBWidget, SIGNAL( sigFgColorChanged( const QColor &) ), this, SLOT( updateFgColor( const QColor &) ) );
00078 connect( mRGBWidget, SIGNAL( sigBgColorChanged( const QColor &) ), this, SLOT( updateBgColor( const QColor &) ) );
00079 connect(this, SIGNAL(fgColorChanged(const QColor &)), mRGBWidget, SLOT(setFgColor(const QColor &)));
00080 connect(this, SIGNAL(bgColorChanged(const QColor &)), mRGBWidget, SLOT(setBgColor(const QColor &)));
00081 mTabWidget->addTab( mRGBWidget, i18n( "RGB" ) );
00082
00083
00084
00085
00086
00087
00088
00089
00090 mOpacity = new VColorSlider( i18n( "Opacity:" ), QColor( "white" ), QColor( "black" ), 0, 100, 100, this );
00091
00092 connect( mOpacity, SIGNAL( valueChanged ( int ) ), this, SLOT( updateOpacity() ) );
00093 QToolTip::add( mOpacity, i18n( "Alpha (opacity)" ) );
00094
00095 QVBoxLayout *mainWidgetLayout = new QVBoxLayout( this, 3 );
00096 mainWidgetLayout->addWidget( mTabWidget );
00097 mainWidgetLayout->addWidget( mOpacity );
00098 mainWidgetLayout->activate();
00099 setMaximumHeight( 174 );
00100 setMinimumWidth( 194 );
00101
00102 }
00103
00104 VColorDocker::~VColorDocker()
00105 {
00106 }
00107
00108 void VColorDocker::updateFgColor(const QColor &c)
00109 {
00110 mHSVWidget->blockSignals(true);
00111 mRGBWidget->blockSignals(true);
00112
00113
00114 m_oldColor = m_color;
00115
00116 m_color = c;
00117
00118 VColor v = VColor(c);
00119 v.setOpacity( m_opacity );
00120
00121 VCommandHistory* history = m_part->commandHistory();
00122 const QPtrList<VCommand>* commandList = history->commands();
00123 VStrokeCmd* command = dynamic_cast<VStrokeCmd*>(commandList->getLast());
00124
00125 if(command == 0 || m_strokeCmd == 0)
00126 {
00127 m_strokeCmd = new VStrokeCmd( &m_part->document(), v );
00128 m_part->addCommand( m_strokeCmd, true );
00129 }
00130 else
00131 {
00132
00133 QPtrList<VObject> VOldObjectList = command->getSelection()->objects();
00134 QPtrList<VObject> VNewObjectList = m_part->document().selection()->objects();
00135
00136 if( VOldObjectList == VNewObjectList )
00137 {
00138 m_strokeCmd->changeStroke(v);
00139 m_part->repaintAllViews();
00140 }
00141 else
00142 {
00143 m_strokeCmd = new VStrokeCmd( &m_part->document(), v );
00144 m_part->addCommand( m_strokeCmd, true );
00145 }
00146 }
00147
00148 emit fgColorChanged( c );
00149
00150 mHSVWidget->blockSignals(false);
00151 mRGBWidget->blockSignals(false);
00152
00153 }
00154
00155 void VColorDocker::updateBgColor(const QColor &c)
00156 {
00157 mHSVWidget->blockSignals(true);
00158 mRGBWidget->blockSignals(true);
00159
00160
00161 m_oldColor = m_color;
00162
00163 m_color = c;
00164
00165 VColor v = VColor(c);
00166 v.setOpacity( m_opacity );
00167
00168 VCommandHistory* history = m_part->commandHistory();
00169 const QPtrList<VCommand>* commandList = history->commands();
00170 VFillCmd* command = dynamic_cast<VFillCmd*>(commandList->getLast());
00171
00172 if(command == 0 || m_fillCmd == 0)
00173 {
00174 m_fillCmd = new VFillCmd( &m_part->document(), VFill(v) );
00175 m_part->addCommand( m_fillCmd, true );
00176 }
00177 else
00178 {
00179
00180 QPtrList<VObject> VOldObjectList = command->getSelection()->objects();
00181 QPtrList<VObject> VNewObjectList = m_part->document().selection()->objects();
00182
00183 if( VOldObjectList == VNewObjectList )
00184 {
00185 m_fillCmd->changeFill(VFill(v));
00186 m_part->repaintAllViews();
00187 }
00188 else
00189 {
00190 m_fillCmd = new VFillCmd( &m_part->document(), VFill(v) );
00191 m_part->addCommand( m_fillCmd, true );
00192 }
00193 }
00194
00195 emit bgColorChanged( c );
00196
00197 mHSVWidget->blockSignals(false);
00198 mRGBWidget->blockSignals(false);
00199
00200 }
00201
00202 void VColorDocker::updateOpacity()
00203 {
00204 m_opacity = mOpacity->value() / 100.0;
00205
00206 m_oldColor = m_color;
00207
00208 VColor c = VColor(m_color);
00209 c.setOpacity( m_opacity );
00210
00211 if ( isStrokeDocker() )
00212 m_part->addCommand( new VStrokeCmd( &m_part->document(), c ), true );
00213 else
00214 m_part->addCommand( new VFillCmd( &m_part->document(), VFill( c ) ), true );
00215 }
00216
00217 void
00218 VColorDocker::mouseReleaseEvent( QMouseEvent * )
00219 {
00220
00221 }
00222
00223 void VColorDocker::setFillDocker()
00224 {
00225 m_isStrokeDocker = false;
00226 }
00227
00228 void VColorDocker::setStrokeDocker()
00229 {
00230 m_isStrokeDocker = true;
00231 }
00232
00233 void VColorDocker::update()
00234 {
00235
00236 mHSVWidget->blockSignals(true);
00237 mRGBWidget->blockSignals(true);
00238
00239
00240 int objCnt = m_part->document().selection()->objects().count();
00241
00242 if( objCnt > 0 )
00243 {
00244 VObject *obj = m_part->document().selection()->objects().getFirst();
00245
00246 QColor fgColor = QColor(obj->stroke()->color());
00247 QColor bgColor = QColor(obj->fill()->color());
00248
00249 mHSVWidget->setFgColor(fgColor);
00250 mRGBWidget->setFgColor(fgColor);
00251
00252
00253 mHSVWidget->setBgColor(bgColor);
00254 mRGBWidget->setBgColor(bgColor);
00255
00256 }
00257
00258 mHSVWidget->blockSignals(false);
00259 mRGBWidget->blockSignals(false);
00260
00261 }
00262
00263 #include "vcolordocker.moc"
00264