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 connect( mHSVWidget, SIGNAL( sigModeChanged(KDualColorButton::DualColor) ), this, SLOT( updateMode( KDualColorButton::DualColor ) ) );
00074 mTabWidget->addTab( mHSVWidget, i18n( "HSV" ) );
00075
00076
00077 mRGBWidget = new KoRGBWidget( mTabWidget );
00078 connect( mRGBWidget, SIGNAL( sigFgColorChanged( const QColor &) ), this, SLOT( updateFgColor( const QColor &) ) );
00079 connect( mRGBWidget, SIGNAL( sigBgColorChanged( const QColor &) ), this, SLOT( updateBgColor( const QColor &) ) );
00080 connect(this, SIGNAL(fgColorChanged(const QColor &)), mRGBWidget, SLOT(setFgColor(const QColor &)));
00081 connect(this, SIGNAL(bgColorChanged(const QColor &)), mRGBWidget, SLOT(setBgColor(const QColor &)));
00082 connect( mRGBWidget, SIGNAL( sigModeChanged(KDualColorButton::DualColor) ), this, SLOT( updateMode( KDualColorButton::DualColor ) ) );
00083 mTabWidget->addTab( mRGBWidget, i18n( "RGB" ) );
00084
00085
00086
00087
00088
00089
00090
00091
00092 mOpacity = new VColorSlider( i18n( "Opacity:" ), QColor( "white" ), QColor( "black" ), 0, 100, 100, this );
00093
00094 connect( mOpacity, SIGNAL( valueChanged ( int ) ), this, SLOT( updateOpacity() ) );
00095 QToolTip::add( mOpacity, i18n( "Alpha (opacity)" ) );
00096
00097 QVBoxLayout *mainWidgetLayout = new QVBoxLayout( this, 3 );
00098 mainWidgetLayout->addWidget( mTabWidget );
00099 mainWidgetLayout->addWidget( mOpacity );
00100 mainWidgetLayout->activate();
00101 setMaximumHeight( 174 );
00102 setMinimumWidth( 194 );
00103
00104 }
00105
00106 VColorDocker::~VColorDocker()
00107 {
00108 }
00109
00110 void VColorDocker::updateFgColor(const QColor &c)
00111 {
00112 m_color = c;
00113
00114 VColor v = VColor(c);
00115 v.setOpacity( m_opacity );
00116
00117
00118 QPtrList<VObject> VNewObjectList = m_part->document().selection()->objects();
00119 if( ! VNewObjectList.count() )
00120 return;
00121
00122 mHSVWidget->blockSignals(true);
00123 mRGBWidget->blockSignals(true);
00124
00125
00126 VCommandHistory* history = m_part->commandHistory();
00127 const QPtrList<VCommand>* commandList = history->commands();
00128 VStrokeCmd* command = dynamic_cast<VStrokeCmd*>(commandList->getLast());
00129
00130 if(command == 0 || m_strokeCmd == 0)
00131 {
00132 m_strokeCmd = new VStrokeCmd( &m_part->document(), v );
00133 m_part->addCommand( m_strokeCmd, true );
00134 }
00135 else
00136 {
00137 QPtrList<VObject> VOldObjectList = command->getSelection()->objects();
00138
00139 if( VOldObjectList == VNewObjectList )
00140 {
00141 m_strokeCmd->changeStroke(v);
00142 m_part->repaintAllViews();
00143 }
00144 else
00145 {
00146 m_strokeCmd = new VStrokeCmd( &m_part->document(), v );
00147 m_part->addCommand( m_strokeCmd, true );
00148 }
00149 }
00150
00151 emit fgColorChanged( c );
00152
00153 mHSVWidget->blockSignals(false);
00154 mRGBWidget->blockSignals(false);
00155
00156 }
00157
00158 void VColorDocker::updateBgColor(const QColor &c)
00159 {
00160 m_color = c;
00161
00162 VColor v = VColor(c);
00163 v.setOpacity( m_opacity );
00164
00165
00166 QPtrList<VObject> VNewObjectList = m_part->document().selection()->objects();
00167 if( ! VNewObjectList.count() )
00168 return;
00169
00170 mHSVWidget->blockSignals(true);
00171 mRGBWidget->blockSignals(true);
00172
00173
00174 VCommandHistory* history = m_part->commandHistory();
00175 const QPtrList<VCommand>* commandList = history->commands();
00176 VFillCmd* command = dynamic_cast<VFillCmd*>(commandList->getLast());
00177
00178 if(command == 0 || m_fillCmd == 0)
00179 {
00180 m_fillCmd = new VFillCmd( &m_part->document(), VFill(v) );
00181 m_part->addCommand( m_fillCmd, true );
00182 }
00183 else
00184 {
00185 QPtrList<VObject> VOldObjectList = command->getSelection()->objects();
00186
00187 if( VOldObjectList == VNewObjectList )
00188 {
00189 m_fillCmd->changeFill(VFill(v));
00190 m_part->repaintAllViews();
00191 }
00192 else
00193 {
00194 m_fillCmd = new VFillCmd( &m_part->document(), VFill(v) );
00195 m_part->addCommand( m_fillCmd, true );
00196 }
00197 }
00198
00199 emit bgColorChanged( c );
00200
00201 mHSVWidget->blockSignals(false);
00202 mRGBWidget->blockSignals(false);
00203
00204 }
00205
00206 void VColorDocker::updateOpacity()
00207 {
00208 m_opacity = mOpacity->value() / 100.0;
00209
00210 VColor c = VColor(m_color);
00211 c.setOpacity( m_opacity );
00212
00213 if ( isStrokeDocker() )
00214 m_part->addCommand( new VStrokeCmd( &m_part->document(), c ), true );
00215 else
00216 m_part->addCommand( new VFillCmd( &m_part->document(), VFill( c ) ), true );
00217 }
00218
00219 void
00220 VColorDocker::mouseReleaseEvent( QMouseEvent * )
00221 {
00222
00223 }
00224
00225 void VColorDocker::setFillDocker()
00226 {
00227 m_isStrokeDocker = false;
00228 mHSVWidget->setMode( KDualColorButton::Background );
00229 mRGBWidget->setMode( KDualColorButton::Background );
00230 update();
00231 }
00232
00233 void VColorDocker::setStrokeDocker()
00234 {
00235 m_isStrokeDocker = true;
00236 mHSVWidget->setMode( KDualColorButton::Foreground );
00237 mRGBWidget->setMode( KDualColorButton::Foreground );
00238 update();
00239 }
00240
00241 void VColorDocker::update()
00242 {
00243 mHSVWidget->blockSignals(true);
00244 mRGBWidget->blockSignals(true);
00245
00246
00247 int objCnt = m_part->document().selection()->objects().count();
00248
00249 if( objCnt > 0 )
00250 {
00251 VObject *obj = m_part->document().selection()->objects().getFirst();
00252
00253 QColor fgColor = QColor(obj->stroke() ? obj->stroke()->color() : VColor() );
00254 QColor bgColor = QColor(obj->fill() ? obj->fill()->color() : VColor() );
00255
00256 mHSVWidget->setFgColor(fgColor);
00257 mRGBWidget->setFgColor(fgColor);
00258
00259
00260 mHSVWidget->setBgColor(bgColor);
00261 mRGBWidget->setBgColor(bgColor);
00262
00263
00264 if( m_isStrokeDocker )
00265 m_color = fgColor;
00266 else
00267 m_color = bgColor;
00268 }
00269
00270 mHSVWidget->blockSignals(false);
00271 mRGBWidget->blockSignals(false);
00272
00273 }
00274
00275 void VColorDocker::updateMode( KDualColorButton::DualColor s )
00276 {
00277 m_isStrokeDocker = (s == KDualColorButton::Foreground);
00278 update();
00279 emit modeChanged( s );
00280 }
00281
00282 #include "vcolordocker.moc"
00283