00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include <stdio.h>
00032 #include <stdlib.h>
00033
00034 #include <qcheckbox.h>
00035 #include <qcombobox.h>
00036 #include <qdrawutil.h>
00037 #include <qevent.h>
00038 #include <qfile.h>
00039 #include <qimage.h>
00040 #include <qlabel.h>
00041 #include <qlayout.h>
00042 #include <qlineedit.h>
00043 #include <qvalidator.h>
00044 #include <qpainter.h>
00045 #include <qpushbutton.h>
00046 #include <qspinbox.h>
00047 #include <qtimer.h>
00048
00049 #include <kapplication.h>
00050 #include <kconfig.h>
00051 #include <kglobal.h>
00052 #include <kglobalsettings.h>
00053 #include <kiconloader.h>
00054 #include <klistbox.h>
00055 #include <klocale.h>
00056 #include <kmessagebox.h>
00057 #include <kseparator.h>
00058 #include <kpalette.h>
00059 #include <kimageeffect.h>
00060
00061 #include "kcolordialog.h"
00062 #include "kcolordrag.h"
00063 #include "kstaticdeleter.h"
00064 #include <config.h>
00065 #include <kdebug.h>
00066
00067 #include "config.h"
00068 #ifdef Q_WS_X11
00069 #include <X11/Xlib.h>
00070
00071
00072 typedef int (*QX11EventFilter) (XEvent*);
00073 extern QX11EventFilter qt_set_x11_event_filter (QX11EventFilter filter);
00074 #endif
00075
00076 struct ColorPaletteNameType
00077 {
00078 const char* m_fileName;
00079 const char* m_displayName;
00080 };
00081
00082 const ColorPaletteNameType colorPaletteName[]=
00083 {
00084 { "Recent_Colors", I18N_NOOP2( "palette name", "* Recent Colors *" ) },
00085 { "Custom_Colors", I18N_NOOP2( "palette name", "* Custom Colors *" ) },
00086 { "40.colors", I18N_NOOP2( "palette name", "Forty Colors" ) },
00087 { "Rainbow.colors",I18N_NOOP2( "palette name", "Rainbow Colors" ) },
00088 { "Royal.colors", I18N_NOOP2( "palette name", "Royal Colors" ) },
00089 { "Web.colors", I18N_NOOP2( "palette name", "Web Colors" ) },
00090 { 0, 0 }
00091 };
00092
00093 const int recentColorIndex = 0;
00094 const int customColorIndex = 1;
00095
00096 class KColorSpinBox : public QSpinBox
00097 {
00098 public:
00099 KColorSpinBox(int minValue, int maxValue, int step, QWidget* parent)
00100 : QSpinBox(minValue, maxValue, step, parent, "kcolorspinbox")
00101 { }
00102
00103
00104 virtual void valueChange()
00105 {
00106 updateDisplay();
00107 emit valueChanged( value() );
00108 emit valueChanged( currentValueText() );
00109 }
00110
00111 };
00112
00113
00114 #define STANDARD_PAL_SIZE 17
00115
00116 KColor::KColor()
00117 : QColor()
00118 {
00119 r = 0; g = 0; b = 0; h = 0; s = 0; v = 0;
00120 }
00121
00122 KColor::KColor( const KColor &col)
00123 : QColor( col )
00124 {
00125 h = col.h; s = col.s; v = col.v;
00126 r = col.r; g = col.g; b = col.b;
00127 }
00128
00129 KColor::KColor( const QColor &col)
00130 : QColor( col )
00131 {
00132 QColor::getRgb(&r, &g, &b);
00133 QColor::getHsv(&h, &s, &v);
00134 }
00135
00136 bool KColor::operator==(const KColor& col) const
00137 {
00138 return (h == col.h) && (s == col.s) && (v == col.v) &&
00139 (r == col.r) && (g == col.g) && (b == col.b);
00140 }
00141
00142 KColor& KColor::operator=(const KColor& col)
00143 {
00144 *(QColor *)this = col;
00145 h = col.h; s = col.s; v = col.v;
00146 r = col.r; g = col.g; b = col.b;
00147 return *this;
00148 }
00149
00150 void
00151 KColor::setHsv(int _h, int _s, int _v)
00152 {
00153 h = _h; s = _s; v = _v;
00154 QColor::setHsv(h, s, v);
00155 QColor::rgb(&r, &g, &b);
00156 }
00157
00158 void
00159 KColor::setRgb(int _r, int _g, int _b)
00160 {
00161 r = _r; g = _g; b = _b;
00162 QColor::setRgb(r, g, b);
00163 QColor::hsv(&h, &s, &v);
00164 }
00165
00166 void
00167 KColor::rgb(int *_r, int *_g, int *_b) const
00168 {
00169 *_r = r; *_g = g; *_b = b;
00170 }
00171
00172 void
00173 KColor::hsv(int *_h, int *_s, int *_v) const
00174 {
00175 *_h = h; *_s = s; *_v = v;
00176 }
00177
00178
00179 static QColor *standardPalette = 0;
00180 static KStaticDeleter<QColor> spd;
00181
00182 static void createStandardPalette()
00183 {
00184 if ( standardPalette )
00185 return;
00186
00187 spd.setObject(standardPalette, new QColor [STANDARD_PAL_SIZE], true);
00188
00189 int i = 0;
00190
00191 standardPalette[i++] = Qt::red;
00192 standardPalette[i++] = Qt::green;
00193 standardPalette[i++] = Qt::blue;
00194 standardPalette[i++] = Qt::cyan;
00195 standardPalette[i++] = Qt::magenta;
00196 standardPalette[i++] = Qt::yellow;
00197 standardPalette[i++] = Qt::darkRed;
00198 standardPalette[i++] = Qt::darkGreen;
00199 standardPalette[i++] = Qt::darkBlue;
00200 standardPalette[i++] = Qt::darkCyan;
00201 standardPalette[i++] = Qt::darkMagenta;
00202 standardPalette[i++] = Qt::darkYellow;
00203 standardPalette[i++] = Qt::white;
00204 standardPalette[i++] = Qt::lightGray;
00205 standardPalette[i++] = Qt::gray;
00206 standardPalette[i++] = Qt::darkGray;
00207 standardPalette[i++] = Qt::black;
00208 }
00209
00210
00211 KHSSelector::KHSSelector( QWidget *parent, const char *name )
00212 : KXYSelector( parent, name )
00213 {
00214 setRange( 0, 0, 359, 255 );
00215 }
00216
00217 void KHSSelector::updateContents()
00218 {
00219 drawPalette(&pixmap);
00220 }
00221
00222 void KHSSelector::resizeEvent( QResizeEvent * )
00223 {
00224 updateContents();
00225 }
00226
00227 void KHSSelector::drawContents( QPainter *painter )
00228 {
00229 painter->drawPixmap( contentsRect().x(), contentsRect().y(), pixmap );
00230 }
00231
00232 void KHSSelector::drawPalette( QPixmap *pixmap )
00233 {
00234 int xSize = contentsRect().width(), ySize = contentsRect().height();
00235 QImage image( xSize, ySize, 32 );
00236 QColor col;
00237 int h, s;
00238 uint *p;
00239
00240 for ( s = ySize-1; s >= 0; s-- )
00241 {
00242 p = (uint *) image.scanLine( ySize - s - 1 );
00243 for( h = 0; h < xSize; h++ )
00244 {
00245 col.setHsv( 359*h/(xSize-1), 255*s/((ySize == 1) ? 1 : ySize-1), 192 );
00246 *p = col.rgb();
00247 p++;
00248 }
00249 }
00250
00251 if ( QColor::numBitPlanes() <= 8 )
00252 {
00253 createStandardPalette();
00254 KImageEffect::dither( image, standardPalette, STANDARD_PAL_SIZE );
00255 }
00256 pixmap->convertFromImage( image );
00257 }
00258
00259
00260
00261
00262 KValueSelector::KValueSelector( QWidget *parent, const char *name )
00263 : KSelector( KSelector::Vertical, parent, name ), _hue(0), _sat(0)
00264 {
00265 setRange( 0, 255 );
00266 pixmap.setOptimization( QPixmap::BestOptim );
00267 }
00268
00269 KValueSelector::KValueSelector(Orientation o, QWidget *parent, const char *name
00270 )
00271 : KSelector( o, parent, name), _hue(0), _sat(0)
00272 {
00273 setRange( 0, 255 );
00274 pixmap.setOptimization( QPixmap::BestOptim );
00275 }
00276
00277 void KValueSelector::updateContents()
00278 {
00279 drawPalette(&pixmap);
00280 }
00281
00282 void KValueSelector::resizeEvent( QResizeEvent * )
00283 {
00284 updateContents();
00285 }
00286
00287 void KValueSelector::drawContents( QPainter *painter )
00288 {
00289 painter->drawPixmap( contentsRect().x(), contentsRect().y(), pixmap );
00290 }
00291
00292 void KValueSelector::drawPalette( QPixmap *pixmap )
00293 {
00294 int xSize = contentsRect().width(), ySize = contentsRect().height();
00295 QImage image( xSize, ySize, 32 );
00296 QColor col;
00297 uint *p;
00298 QRgb rgb;
00299
00300 if ( orientation() == KSelector::Horizontal )
00301 {
00302 for ( int v = 0; v < ySize; v++ )
00303 {
00304 p = (uint *) image.scanLine( ySize - v - 1 );
00305
00306 for( int x = 0; x < xSize; x++ )
00307 {
00308 col.setHsv( _hue, _sat, 255*x/((xSize == 1) ? 1 : xSize-1) );
00309 rgb = col.rgb();
00310 *p++ = rgb;
00311 }
00312 }
00313 }
00314
00315 if( orientation() == KSelector::Vertical )
00316 {
00317 for ( int v = 0; v < ySize; v++ )
00318 {
00319 p = (uint *) image.scanLine( ySize - v - 1 );
00320 col.setHsv( _hue, _sat, 255*v/((ySize == 1) ? 1 : ySize-1) );
00321 rgb = col.rgb();
00322 for ( int i = 0; i < xSize; i++ )
00323 *p++ = rgb;
00324 }
00325 }
00326
00327 if ( QColor::numBitPlanes() <= 8 )
00328 {
00329 createStandardPalette();
00330 KImageEffect::dither( image, standardPalette, STANDARD_PAL_SIZE );
00331 }
00332 pixmap->convertFromImage( image );
00333 }
00334
00335
00336
00337 KColorCells::KColorCells( QWidget *parent, int rows, int cols )
00338 : QGridView( parent )
00339 {
00340 shade = true;
00341 setNumRows( rows );
00342 setNumCols( cols );
00343 colors = new QColor [ rows * cols ];
00344
00345 for ( int i = 0; i < rows * cols; i++ )
00346 colors[i] = QColor();
00347
00348 selected = 0;
00349 inMouse = false;
00350
00351
00352 setAcceptDrops( true);
00353
00354 setHScrollBarMode( AlwaysOff );
00355 setVScrollBarMode( AlwaysOff );
00356 viewport()->setBackgroundMode( PaletteBackground );
00357 setBackgroundMode( PaletteBackground );
00358 }
00359
00360 KColorCells::~KColorCells()
00361 {
00362 delete [] colors;
00363 }
00364
00365 void KColorCells::setColor( int colNum, const QColor &col )
00366 {
00367 colors[colNum] = col;
00368 updateCell( colNum/numCols(), colNum%numCols() );
00369 }
00370
00371 void KColorCells::paintCell( QPainter *painter, int row, int col )
00372 {
00373 QBrush brush;
00374 int w = 1;
00375
00376 if (shade)
00377 {
00378 qDrawShadePanel( painter, 1, 1, cellWidth()-2,
00379 cellHeight()-2, colorGroup(), true, 1, &brush );
00380 w = 2;
00381 }
00382 QColor color = colors[ row * numCols() + col ];
00383 if (!color.isValid())
00384 {
00385 if (!shade) return;
00386 color = backgroundColor();
00387 }
00388
00389 painter->setPen( color );
00390 painter->setBrush( QBrush( color ) );
00391 painter->drawRect( w, w, cellWidth()-w*2, cellHeight()-w*2 );
00392
00393 if ( row * numCols() + col == selected )
00394 painter->drawWinFocusRect( w, w, cellWidth()-w*2, cellHeight()-w*2 );
00395 }
00396
00397 void KColorCells::resizeEvent( QResizeEvent * )
00398 {
00399 setCellWidth( width() / numCols() );
00400 setCellHeight( height() / numRows() );
00401 }
00402
00403 void KColorCells::mousePressEvent( QMouseEvent *e )
00404 {
00405 inMouse = true;
00406 mPos = e->pos();
00407 }
00408
00409 int KColorCells::posToCell(const QPoint &pos, bool ignoreBorders)
00410 {
00411 int row = pos.y() / cellHeight();
00412 int col = pos.x() / cellWidth();
00413 int cell = row * numCols() + col;
00414
00415 if (!ignoreBorders)
00416 {
00417 int border = 2;
00418 int x = pos.x() - col * cellWidth();
00419 int y = pos.y() - row * cellHeight();
00420 if ( (x < border) || (x > cellWidth()-border) ||
00421 (y < border) || (y > cellHeight()-border))
00422 return -1;
00423 }
00424 return cell;
00425 }
00426
00427 void KColorCells::mouseMoveEvent( QMouseEvent *e )
00428 {
00429 if( !(e->state() & LeftButton)) return;
00430
00431 if(inMouse) {
00432 int delay = KGlobalSettings::dndEventDelay();
00433 if(e->x() > mPos.x()+delay || e->x() < mPos.x()-delay ||
00434 e->y() > mPos.y()+delay || e->y() < mPos.y()-delay){
00435
00436 int cell = posToCell(mPos);
00437 if ((cell != -1) && colors[cell].isValid())
00438 {
00439 KColorDrag *d = new KColorDrag( colors[cell], this);
00440 d->dragCopy();
00441 }
00442 }
00443 }
00444 }
00445
00446 void KColorCells::dragEnterEvent( QDragEnterEvent *event)
00447 {
00448 event->accept( acceptDrags && KColorDrag::canDecode( event));
00449 }
00450
00451 void KColorCells::dropEvent( QDropEvent *event)
00452 {
00453 QColor c;
00454 if( KColorDrag::decode( event, c)) {
00455 int cell = posToCell(event->pos(), true);
00456 setColor(cell,c);
00457 }
00458 }
00459
00460 void KColorCells::mouseReleaseEvent( QMouseEvent *e )
00461 {
00462 int cell = posToCell(mPos);
00463 int currentCell = posToCell(e->pos());
00464
00465
00466
00467 if (currentCell != cell)
00468 cell = -1;
00469
00470 if ( (cell != -1) && (selected != cell) )
00471 {
00472 int prevSel = selected;
00473 selected = cell;
00474 updateCell( prevSel/numCols(), prevSel%numCols() );
00475 updateCell( cell/numCols(), cell%numCols() );
00476 }
00477
00478 inMouse = false;
00479 if (cell != -1)
00480 emit colorSelected( cell );
00481 }
00482
00483 void KColorCells::mouseDoubleClickEvent( QMouseEvent * )
00484 {
00485 int cell = posToCell(mPos);
00486
00487 if (cell != -1)
00488 emit colorDoubleClicked( cell );
00489 }
00490
00491
00492
00493
00494 KColorPatch::KColorPatch( QWidget *parent ) : QFrame( parent )
00495 {
00496 setFrameStyle( QFrame::Panel | QFrame::Sunken );
00497 colContext = 0;
00498 setAcceptDrops( true);
00499 }
00500
00501 KColorPatch::~KColorPatch()
00502 {
00503 if ( colContext )
00504 QColor::destroyAllocContext( colContext );
00505 }
00506
00507 void KColorPatch::setColor( const QColor &col )
00508 {
00509 if ( colContext )
00510 QColor::destroyAllocContext( colContext );
00511 colContext = QColor::enterAllocContext();
00512 color.setRgb( col.rgb() );
00513 color.alloc();
00514 QColor::leaveAllocContext();
00515
00516 QPainter painter;
00517
00518 painter.begin( this );
00519 drawContents( &painter );
00520 painter.end();
00521 }
00522
00523 void KColorPatch::drawContents( QPainter *painter )
00524 {
00525 painter->setPen( color );
00526 painter->setBrush( QBrush( color ) );
00527 painter->drawRect( contentsRect() );
00528 }
00529
00530 void KColorPatch::mouseMoveEvent( QMouseEvent *e )
00531 {
00532
00533 if( !(e->state() & LeftButton)) return;
00534 KColorDrag *d = new KColorDrag( color, this);
00535 d->dragCopy();
00536 }
00537
00538 void KColorPatch::dragEnterEvent( QDragEnterEvent *event)
00539 {
00540 event->accept( KColorDrag::canDecode( event));
00541 }
00542
00543 void KColorPatch::dropEvent( QDropEvent *event)
00544 {
00545 QColor c;
00546 if( KColorDrag::decode( event, c)) {
00547 setColor( c);
00548 emit colorChanged( c);
00549 }
00550 }
00551
00552 class KPaletteTable::KPaletteTablePrivate
00553 {
00554 public:
00555 QMap<QString,QColor> m_namedColorMap;
00556 };
00557
00558 KPaletteTable::KPaletteTable( QWidget *parent, int minWidth, int cols)
00559 : QWidget( parent ), cells(0), mPalette(0), mMinWidth(minWidth), mCols(cols)
00560 {
00561 d = new KPaletteTablePrivate;
00562
00563 i18n_namedColors = i18n("Named Colors");
00564
00565 QStringList diskPaletteList = KPalette::getPaletteList();
00566 QStringList paletteList;
00567
00568
00569 for ( int i = 0; colorPaletteName[i].m_fileName; ++i )
00570 {
00571 diskPaletteList.remove( colorPaletteName[i].m_fileName );
00572 paletteList.append( i18n( "palette name", colorPaletteName[i].m_displayName ) );
00573 }
00574 paletteList += diskPaletteList;
00575 paletteList.append( i18n_namedColors );
00576
00577 QVBoxLayout *layout = new QVBoxLayout( this );
00578
00579 combo = new QComboBox( false, this );
00580 combo->insertStringList( paletteList );
00581 layout->addWidget(combo);
00582
00583 sv = new QScrollView( this );
00584 QSize cellSize = QSize( mMinWidth, 120);
00585 sv->setHScrollBarMode( QScrollView::AlwaysOff);
00586 sv->setVScrollBarMode( QScrollView::AlwaysOn);
00587 QSize minSize = QSize(sv->verticalScrollBar()->width(), 0);
00588 minSize += QSize(sv->frameWidth(), 0);
00589 minSize += QSize(cellSize);
00590 sv->setFixedSize(minSize);
00591 layout->addWidget(sv);
00592
00593 mNamedColorList = new KListBox( this, "namedColorList", 0 );
00594 mNamedColorList->setFixedSize(minSize);
00595 mNamedColorList->hide();
00596 layout->addWidget(mNamedColorList);
00597 connect( mNamedColorList, SIGNAL(highlighted( const QString & )),
00598 this, SLOT( slotColorTextSelected( const QString & )) );
00599
00600 setFixedSize( sizeHint());
00601 connect( combo, SIGNAL(activated(const QString &)),
00602 this, SLOT(slotSetPalette( const QString &)));
00603 }
00604
00605 KPaletteTable::~KPaletteTable()
00606 {
00607 delete mPalette;
00608 delete d;
00609 }
00610
00611 QString
00612 KPaletteTable::palette() const
00613 {
00614 return combo->currentText();
00615 }
00616
00617
00618 static const char * const *namedColorFilePath( void )
00619 {
00620
00621
00622
00623
00624 static const char * const path[] =
00625 {
00626 #ifdef X11_RGBFILE
00627 X11_RGBFILE,
00628 #endif
00629 "/usr/X11R6/lib/X11/rgb.txt",
00630 "/usr/openwin/lib/X11/rgb.txt",
00631 0
00632 };
00633 return path;
00634 }
00635
00636
00637
00638
00639 void
00640 KPaletteTable::readNamedColor( void )
00641 {
00642 if( mNamedColorList->count() != 0 )
00643 {
00644 return;
00645 }
00646
00647 KGlobal::locale()->insertCatalogue("kdelibs_colors");
00648
00649
00650
00651
00652
00653 const char * const *path = namedColorFilePath();
00654 for( int i=0; path[i]; ++i )
00655 {
00656 QFile paletteFile( path[i] );
00657 if( !paletteFile.open( IO_ReadOnly ) )
00658 {
00659 continue;
00660 }
00661
00662 QString line;
00663 QStringList list;
00664 while( paletteFile.readLine( line, 100 ) != -1 )
00665 {
00666 int red, green, blue;
00667 int pos = 0;
00668
00669 if( sscanf(line.ascii(), "%d %d %d%n", &red, &green, &blue, &pos ) == 3 )
00670 {
00671
00672
00673
00674
00675 QString name = line.mid(pos).stripWhiteSpace();
00676 if( name.isNull() || name.find(' ') != -1 ||
00677 name.find( "gray" ) != -1 || name.find( "grey" ) != -1 )
00678 {
00679 continue;
00680 }
00681
00682 const QColor color ( red, green, blue );
00683 if ( color.isValid() )
00684 {
00685 const QString colorName( i18n("color", name.latin1() ) );
00686 list.append( colorName );
00687 d->m_namedColorMap[ colorName ] = color;
00688 }
00689 }
00690 }
00691
00692 list.sort();
00693 mNamedColorList->insertStringList( list );
00694 break;
00695 }
00696
00697 if( mNamedColorList->count() == 0 )
00698 {
00699
00700
00701
00702
00703
00704
00705
00706 QTimer::singleShot( 10, this, SLOT(slotShowNamedColorReadError()) );
00707 }
00708 }
00709
00710
00711 void
00712 KPaletteTable::slotShowNamedColorReadError( void )
00713 {
00714 if( mNamedColorList->count() == 0 )
00715 {
00716 QString msg = i18n(""
00717 "Unable to read X11 RGB color strings. The following "
00718 "file location(s) were examined:\n");
00719
00720 const char * const *path = namedColorFilePath();
00721 for( int i=0; path[i]; ++i )
00722 {
00723 msg += path[i];
00724 msg += "\n";
00725 }
00726 KMessageBox::sorry( this, msg );
00727 }
00728 }
00729
00730
00731
00732
00733
00734
00735
00736
00737
00738
00739
00740
00741 void
00742 KPaletteTable::slotSetPalette( const QString &_paletteName )
00743 {
00744 setPalette( _paletteName );
00745 if( mNamedColorList->isVisible() )
00746 {
00747 int item = mNamedColorList->currentItem();
00748 mNamedColorList->setCurrentItem( item < 0 ? 0 : item );
00749 slotColorTextSelected( mNamedColorList->currentText() );
00750 }
00751 else
00752 {
00753 slotColorCellSelected(0);
00754 }
00755 }
00756
00757
00758 void
00759 KPaletteTable::setPalette( const QString &_paletteName )
00760 {
00761 QString paletteName( _paletteName);
00762 if (paletteName.isEmpty())
00763 paletteName = i18n_recentColors;
00764
00765 if (combo->currentText() != paletteName)
00766 {
00767 bool found = false;
00768 for(int i = 0; i < combo->count(); i++)
00769 {
00770 if (combo->text(i) == paletteName)
00771 {
00772 combo->setCurrentItem(i);
00773 found = true;
00774 break;
00775 }
00776 }
00777 if (!found)
00778 {
00779 combo->insertItem(paletteName);
00780 combo->setCurrentItem(combo->count()-1);
00781 }
00782 }
00783
00784
00785 for ( int i = 0; colorPaletteName[i].m_fileName; ++i )
00786 {
00787 if ( paletteName == i18n( "palette name", colorPaletteName[i].m_displayName ) )
00788 {
00789 paletteName = colorPaletteName[i].m_fileName;
00790 break;
00791 }
00792 }
00793
00794
00795
00796
00797
00798
00799
00800
00801
00802
00803 if( !mPalette || mPalette->name() != paletteName )
00804 {
00805 if( paletteName == i18n_namedColors )
00806 {
00807 sv->hide();
00808 mNamedColorList->show();
00809 readNamedColor();
00810
00811 delete cells; cells = 0;
00812 delete mPalette; mPalette = 0;
00813 }
00814 else
00815 {
00816 mNamedColorList->hide();
00817 sv->show();
00818
00819 delete cells;
00820 delete mPalette;
00821 mPalette = new KPalette(paletteName);
00822 int rows = (mPalette->nrColors()+mCols-1) / mCols;
00823 if (rows < 1) rows = 1;
00824 cells = new KColorCells( sv->viewport(), rows, mCols);
00825 cells->setShading(false);
00826 cells->setAcceptDrags(false);
00827 QSize cellSize = QSize( mMinWidth, mMinWidth * rows / mCols);
00828 cells->setFixedSize( cellSize );
00829 for( int i = 0; i < mPalette->nrColors(); i++)
00830 {
00831 cells->setColor( i, mPalette->color(i) );
00832 }
00833 connect( cells, SIGNAL( colorSelected( int ) ),
00834 SLOT( slotColorCellSelected( int ) ) );
00835 connect( cells, SIGNAL( colorDoubleClicked( int ) ),
00836 SLOT( slotColorCellDoubleClicked( int ) ) );
00837 sv->addChild( cells );
00838 cells->show();
00839 sv->updateScrollBars();
00840 }
00841 }
00842 }
00843
00844
00845
00846 void
00847 KPaletteTable::slotColorCellSelected( int col )
00848 {
00849 if (!mPalette || (col >= mPalette->nrColors()))
00850 return;
00851 emit colorSelected( mPalette->color(col), mPalette->colorName(col) );
00852 }
00853
00854 void
00855 KPaletteTable::slotColorCellDoubleClicked( int col )
00856 {
00857 if (!mPalette || (col >= mPalette->nrColors()))
00858 return;
00859 emit colorDoubleClicked( mPalette->color(col), mPalette->colorName(col) );
00860 }
00861
00862
00863 void
00864 KPaletteTable::slotColorTextSelected( const QString &colorText )
00865 {
00866 emit colorSelected( d->m_namedColorMap[ colorText ], colorText );
00867 }
00868
00869
00870 void
00871 KPaletteTable::addToCustomColors( const QColor &color)
00872 {
00873 setPalette(i18n( "palette name", colorPaletteName[ customColorIndex ].m_displayName ));
00874 mPalette->addColor( color );
00875 mPalette->save();
00876 delete mPalette;
00877 mPalette = 0;
00878 setPalette(i18n( "palette name", colorPaletteName[ customColorIndex ].m_displayName ));
00879 }
00880
00881 void
00882 KPaletteTable::addToRecentColors( const QColor &color)
00883 {
00884
00885
00886
00887
00888 bool recentIsSelected = false;
00889 if ( mPalette && mPalette->name() == colorPaletteName[ recentColorIndex ].m_fileName )
00890 {
00891 delete mPalette;
00892 mPalette = 0;
00893 recentIsSelected = true;
00894 }
00895 KPalette *recentPal = new KPalette( colorPaletteName[ recentColorIndex ].m_fileName );
00896 if (recentPal->findColor(color) == -1)
00897 {
00898 recentPal->addColor( color );
00899 recentPal->save();
00900 }
00901 delete recentPal;
00902 if (recentIsSelected)
00903 setPalette( i18n( "palette name", colorPaletteName[ recentColorIndex ].m_displayName ) );
00904 }
00905
00906 class KColorDialog::KColorDialogPrivate {
00907 public:
00908 KPaletteTable *table;
00909 QString originalPalette;
00910 bool bRecursion;
00911 bool bEditRgb;
00912 bool bEditHsv;
00913 bool bEditHtml;
00914 bool bColorPicking;
00915 QLabel *colorName;
00916 QLineEdit *htmlName;
00917 KColorSpinBox *hedit;
00918 KColorSpinBox *sedit;
00919 KColorSpinBox *vedit;
00920 KColorSpinBox *redit;
00921 KColorSpinBox *gedit;
00922 KColorSpinBox *bedit;
00923 KColorPatch *patch;
00924 KHSSelector *hsSelector;
00925 KPalette *palette;
00926 KValueSelector *valuePal;
00927 QVBoxLayout* l_right;
00928 QGridLayout* tl_layout;
00929 QCheckBox *cbDefaultColor;
00930 KColor defaultColor;
00931 KColor selColor;
00932 #ifdef Q_WS_X11
00933 QX11EventFilter oldfilter;
00934 #endif
00935 };
00936
00937
00938 KColorDialog::KColorDialog( QWidget *parent, const char *name, bool modal )
00939 :KDialogBase( parent, name, modal, i18n("Select Color"),
00940 modal ? Ok|Cancel : Close,
00941 Ok, true )
00942 {
00943 d = new KColorDialogPrivate;
00944 d->bRecursion = true;
00945 d->bColorPicking = false;
00946 #ifdef Q_WS_X11
00947 d->oldfilter = 0;
00948 #endif
00949 d->cbDefaultColor = 0L;
00950 connect( this, SIGNAL(okClicked(void)),this,SLOT(slotWriteSettings(void)));
00951 connect( this, SIGNAL(closeClicked(void)),this,SLOT(slotWriteSettings(void)));
00952
00953 QLabel *label;
00954
00955
00956
00957
00958 QWidget *page = new QWidget( this );
00959 setMainWidget( page );
00960
00961 QGridLayout *tl_layout = new QGridLayout( page, 3, 3, 0, spacingHint() );
00962 d->tl_layout = tl_layout;
00963 tl_layout->addColSpacing( 1, spacingHint() * 2 );
00964
00965
00966
00967
00968
00969 QVBoxLayout *l_left = new QVBoxLayout();
00970 tl_layout->addLayout(l_left, 0, 0);
00971
00972
00973
00974
00975
00976 QHBoxLayout *l_ltop = new QHBoxLayout();
00977 l_left->addLayout(l_ltop);
00978
00979
00980 l_left->addSpacing(10);
00981
00982 QGridLayout *l_lbot = new QGridLayout(3, 6);
00983 l_left->addLayout(l_lbot);
00984
00985
00986
00987
00988 d->hsSelector = new KHSSelector( page );
00989 d->hsSelector->setMinimumSize(140, 70);
00990 l_ltop->addWidget(d->hsSelector, 8);
00991 connect( d->hsSelector, SIGNAL( valueChanged( int, int ) ),
00992 SLOT( slotHSChanged( int, int ) ) );
00993
00994 d->valuePal = new KValueSelector( page );
00995 d->valuePal->setMinimumSize(26, 70);
00996 l_ltop->addWidget(d->valuePal, 1);
00997 connect( d->valuePal, SIGNAL( valueChanged( int ) ),
00998 SLOT( slotVChanged( int ) ) );
00999
01000
01001
01002
01003
01004 label = new QLabel( i18n("H:"), page );
01005 label->setAlignment(AlignRight | AlignVCenter);
01006 l_lbot->addWidget(label, 0, 2);
01007 d->hedit = new KColorSpinBox( 0, 359, 1, page );
01008 d->hedit->setValidator( new QIntValidator( d->hedit ) );
01009 l_lbot->addWidget(d->hedit, 0, 3);
01010 connect( d->hedit, SIGNAL( valueChanged(int) ),
01011 SLOT( slotHSVChanged() ) );
01012
01013 label = new QLabel( i18n("S:"), page );
01014 label->setAlignment(AlignRight | AlignVCenter);
01015 l_lbot->addWidget(label, 1, 2);
01016 d->sedit = new KColorSpinBox( 0, 255, 1, page );
01017 d->sedit->setValidator( new QIntValidator( d->sedit ) );
01018 l_lbot->addWidget(d->sedit, 1, 3);
01019 connect( d->sedit, SIGNAL( valueChanged(int) ),
01020 SLOT( slotHSVChanged() ) );
01021
01022 label = new QLabel( i18n("V:"), page );
01023 label->setAlignment(AlignRight | AlignVCenter);
01024 l_lbot->addWidget(label, 2, 2);
01025 d->vedit = new KColorSpinBox( 0, 255, 1, page );
01026 d->vedit->setValidator( new QIntValidator( d->vedit ) );
01027 l_lbot->addWidget(d->vedit, 2, 3);
01028 connect( d->vedit, SIGNAL( valueChanged(int) ),
01029 SLOT( slotHSVChanged() ) );
01030
01031
01032
01033
01034 label = new QLabel( i18n("R:"), page );
01035 label->setAlignment(AlignRight | AlignVCenter);
01036 l_lbot->addWidget(label, 0, 4);
01037 d->redit = new KColorSpinBox( 0, 255, 1, page );
01038 d->redit->setValidator( new QIntValidator( d->redit ) );
01039 l_lbot->addWidget(d->redit, 0, 5);
01040 connect( d->redit, SIGNAL( valueChanged(int) ),
01041 SLOT( slotRGBChanged() ) );
01042
01043 label = new QLabel( i18n("G:"), page );
01044 label->setAlignment(AlignRight | AlignVCenter);
01045 l_lbot->addWidget( label, 1, 4);
01046 d->gedit = new KColorSpinBox( 0, 255,1, page );
01047 d->gedit->setValidator( new QIntValidator( d->gedit ) );
01048 l_lbot->addWidget(d->gedit, 1, 5);
01049 connect( d->gedit, SIGNAL( valueChanged(int) ),
01050 SLOT( slotRGBChanged() ) );
01051
01052 label = new QLabel( i18n("B:"), page );
01053 label->setAlignment(AlignRight | AlignVCenter);
01054 l_lbot->addWidget(label, 2, 4);
01055 d->bedit = new KColorSpinBox( 0, 255, 1, page );
01056 d->bedit->setValidator( new QIntValidator( d->bedit ) );
01057 l_lbot->addWidget(d->bedit, 2, 5);
01058 connect( d->bedit, SIGNAL( valueChanged(int) ),
01059 SLOT( slotRGBChanged() ) );
01060
01061
01062
01063
01064 int w = d->hedit->fontMetrics().width("8888888");
01065 d->hedit->setFixedWidth(w);
01066 d->sedit->setFixedWidth(w);
01067 d->vedit->setFixedWidth(w);
01068
01069 d->redit->setFixedWidth(w);
01070 d->gedit->setFixedWidth(w);
01071 d->bedit->setFixedWidth(w);
01072
01073
01074
01075
01076 d->l_right = new QVBoxLayout;
01077 tl_layout->addLayout(d->l_right, 0, 2);
01078
01079
01080
01081
01082 d->table = new KPaletteTable( page );
01083 d->l_right->addWidget(d->table, 10);
01084
01085 connect( d->table, SIGNAL( colorSelected( const QColor &, const QString & ) ),
01086 SLOT( slotColorSelected( const QColor &, const QString & ) ) );
01087
01088 connect(
01089 d->table,
01090 SIGNAL( colorDoubleClicked( const QColor &, const QString & ) ),
01091 SLOT( slotColorDoubleClicked( const QColor &, const QString & ) )
01092 );
01093
01094 d->originalPalette = d->table->palette();
01095
01096
01097
01098
01099 d->l_right->addSpacing(10);
01100
01101 QHBoxLayout *l_hbox = new QHBoxLayout( d->l_right );
01102
01103
01104
01105
01106 QPushButton *button = new QPushButton( page );
01107 button->setText(i18n("&Add to Custom Colors"));
01108 l_hbox->addWidget(button, 0, AlignLeft);
01109 connect( button, SIGNAL( clicked()), SLOT( slotAddToCustomColors()));
01110
01111
01112
01113
01114 button = new QPushButton( page );
01115 button->setPixmap( BarIcon("colorpicker"));
01116 l_hbox->addWidget(button, 0, AlignHCenter );
01117 connect( button, SIGNAL( clicked()), SLOT( slotColorPicker()));
01118
01119
01120
01121
01122 d->l_right->addSpacing(10);
01123
01124
01125
01126
01127 QGridLayout *l_grid = new QGridLayout( d->l_right, 2, 3);
01128
01129 l_grid->setColStretch(2, 1);
01130
01131 label = new QLabel( page );
01132 label->setText(i18n("Name:"));
01133 l_grid->addWidget(label, 0, 1, AlignLeft);
01134
01135 d->colorName = new QLabel( page );
01136 l_grid->addWidget(d->colorName, 0, 2, AlignLeft);
01137
01138 label = new QLabel( page );
01139 label->setText(i18n("HTML:"));
01140 l_grid->addWidget(label, 1, 1, AlignLeft);
01141
01142 d->htmlName = new QLineEdit( page );
01143 d->htmlName->setMaxLength( 13 );
01144 d->htmlName->setText("#FFFFFF");
01145 w = d->htmlName->fontMetrics().width(QString::fromLatin1("#DDDDDDD"));
01146 d->htmlName->setFixedWidth(w);
01147 l_grid->addWidget(d->htmlName, 1, 2, AlignLeft);
01148
01149 connect( d->htmlName, SIGNAL( textChanged(const QString &) ),
01150 SLOT( slotHtmlChanged() ) );
01151
01152 d->patch = new KColorPatch( page );
01153 d->patch->setFixedSize(48, 48);
01154 l_grid->addMultiCellWidget(d->patch, 0, 1, 0, 0, AlignHCenter | AlignVCenter);
01155 connect( d->patch, SIGNAL( colorChanged( const QColor&)),
01156 SLOT( setColor( const QColor&)));
01157
01158 tl_layout->activate();
01159 page->setMinimumSize( page->sizeHint() );
01160
01161 readSettings();
01162 d->bRecursion = false;
01163 d->bEditHsv = false;
01164 d->bEditRgb = false;
01165 d->bEditHtml = false;
01166
01167 disableResize();
01168 KColor col;
01169 col.setHsv( 0, 0, 255 );
01170 _setColor( col );
01171
01172 d->htmlName->installEventFilter(this);
01173 d->hsSelector->installEventFilter(this);
01174 d->hsSelector->setAcceptDrops(true);
01175 }
01176
01177 KColorDialog::~KColorDialog()
01178 {
01179 #ifdef Q_WS_X11
01180 if (d->bColorPicking)
01181 qt_set_x11_event_filter(d->oldfilter);
01182 #endif
01183 delete d;
01184 }
01185
01186 bool
01187 KColorDialog::eventFilter( QObject *obj, QEvent *ev )
01188 {
01189 if ((obj == d->htmlName) || (obj == d->hsSelector))
01190 switch(ev->type())
01191 {
01192 case QEvent::DragEnter:
01193 case QEvent::DragMove:
01194 case QEvent::DragLeave:
01195 case QEvent::Drop:
01196 case QEvent::DragResponse:
01197 qApp->sendEvent(d->patch, ev);
01198 return true;
01199 default:
01200 break;
01201 }
01202 return KDialogBase::eventFilter(obj, ev);
01203 }
01204
01205 void
01206 KColorDialog::setDefaultColor( const QColor& col )
01207 {
01208 if ( !d->cbDefaultColor )
01209 {
01210
01211
01212
01213 d->l_right->addSpacing(10);
01214
01215
01216
01217
01218 d->cbDefaultColor = new QCheckBox( i18n( "Default color" ), mainWidget() );
01219 d->cbDefaultColor->setChecked(true);
01220
01221 d->l_right->addWidget( d->cbDefaultColor );
01222
01223 mainWidget()->setMaximumSize( QWIDGETSIZE_MAX, QWIDGETSIZE_MAX );
01224 d->tl_layout->activate();
01225 mainWidget()->setMinimumSize( mainWidget()->sizeHint() );
01226 disableResize();
01227
01228 connect( d->cbDefaultColor, SIGNAL( clicked() ), SLOT( slotDefaultColorClicked() ) );
01229 }
01230
01231 d->defaultColor = col;
01232
01233 slotDefaultColorClicked();
01234 }
01235
01236 QColor KColorDialog::defaultColor() const
01237 {
01238 return d->defaultColor;
01239 }
01240
01241 void KColorDialog::slotDefaultColorClicked()
01242 {
01243 if ( d->cbDefaultColor->isChecked() )
01244 {
01245 d->selColor = d->defaultColor;
01246 showColor( d->selColor, i18n( "-default-" ) );
01247 } else
01248 {
01249 showColor( d->selColor, QString::null );
01250 }
01251 }
01252
01253 void
01254 KColorDialog::readSettings()
01255 {
01256 KConfigGroup group( KGlobal::config(), "Colors" );
01257
01258 QString palette = group.readEntry("CurrentPalette");
01259 d->table->setPalette(palette);
01260 }
01261
01262 void
01263 KColorDialog::slotWriteSettings()
01264 {
01265 KConfigGroup group( KGlobal::config(), "Colors" );
01266
01267 QString palette = d->table->palette();
01268 if (!group.hasDefault("CurrentPalette") &&
01269 (d->table->palette() == d->originalPalette))
01270 {
01271 group.revertToDefault("CurrentPalette");
01272 }
01273 else
01274 {
01275 group.writeEntry("CurrentPalette", d->table->palette());
01276 }
01277 }
01278
01279 QColor
01280 KColorDialog::color() const
01281 {
01282 if ( d->cbDefaultColor && d->cbDefaultColor->isChecked() )
01283 return QColor();
01284 if ( d->selColor.isValid() )
01285 d->table->addToRecentColors( d->selColor );
01286 return d->selColor;
01287 }
01288
01289 void KColorDialog::setColor( const QColor &col )
01290 {
01291 _setColor( col );
01292 }
01293
01294
01295
01296
01297 int KColorDialog::getColor( QColor &theColor, QWidget *parent )
01298 {
01299 KColorDialog dlg( parent, "Color Selector", true );
01300 if ( theColor.isValid() )
01301 dlg.setColor( theColor );
01302 int result = dlg.exec();
01303
01304 if ( result == Accepted )
01305 {
01306 theColor = dlg.color();
01307 }
01308
01309 return result;
01310 }
01311
01312
01313
01314
01315 int KColorDialog::getColor( QColor &theColor, const QColor& defaultCol, QWidget *parent )
01316 {
01317 KColorDialog dlg( parent, "Color Selector", true );
01318 dlg.setDefaultColor( defaultCol );
01319 dlg.setColor( theColor );
01320 int result = dlg.exec();
01321
01322 if ( result == Accepted )
01323 theColor = dlg.color();
01324
01325 return result;
01326 }
01327
01328 void KColorDialog::slotRGBChanged( void )
01329 {
01330 if (d->bRecursion) return;
01331 int red = d->redit->value();
01332 int grn = d->gedit->value();
01333 int blu = d->bedit->value();
01334
01335 if ( red > 255 || red < 0 ) return;
01336 if ( grn > 255 || grn < 0 ) return;
01337 if ( blu > 255 || blu < 0 ) return;
01338
01339 KColor col;
01340 col.setRgb( red, grn, blu );
01341 d->bEditRgb = true;
01342 _setColor( col );
01343 d->bEditRgb = false;
01344 }
01345
01346 void KColorDialog::slotHtmlChanged( void )
01347 {
01348 if (d->bRecursion || d->htmlName->text().isEmpty()) return;
01349
01350 QString strColor( d->htmlName->text() );
01351
01352
01353 if ( strColor[0] != '#' )
01354 {
01355 bool signalsblocked = d->htmlName->signalsBlocked();
01356 d->htmlName->blockSignals(true);
01357 strColor.prepend("#");
01358 d->htmlName->setText(strColor);
01359 d->htmlName->blockSignals(signalsblocked);
01360 }
01361
01362 const QColor color( strColor );
01363
01364 if ( color.isValid() )
01365 {
01366 KColor col( color );
01367 d->bEditHtml = true;
01368 _setColor( col );
01369 d->bEditHtml = false;
01370 }
01371 }
01372
01373 void KColorDialog::slotHSVChanged( void )
01374 {
01375 if (d->bRecursion) return;
01376 int hue = d->hedit->value();
01377 int sat = d->sedit->value();
01378 int val = d->vedit->value();
01379
01380 if ( hue > 359 || hue < 0 ) return;
01381 if ( sat > 255 || sat < 0 ) return;
01382 if ( val > 255 || val < 0 ) return;
01383
01384 KColor col;
01385 col.setHsv( hue, sat, val );
01386 d->bEditHsv = true;
01387 _setColor( col );
01388 d->bEditHsv = false;
01389 }
01390
01391 void KColorDialog::slotHSChanged( int h, int s )
01392 {
01393 int _h, _s, v;
01394 d->selColor.hsv(&_h, &_s, &v);
01395 if (v < 0)
01396 v = 0;
01397 KColor col;
01398 col.setHsv( h, s, v );
01399 _setColor( col );
01400 }
01401
01402 void KColorDialog::slotVChanged( int v )
01403 {
01404 int h, s, _v;
01405 d->selColor.hsv(&h, &s, &_v);
01406 KColor col;
01407 col.setHsv( h, s, v );
01408 _setColor( col );
01409 }
01410
01411 void KColorDialog::slotColorSelected( const QColor &color )
01412 {
01413 _setColor( color );
01414 }
01415
01416 void KColorDialog::slotAddToCustomColors( )
01417 {
01418 d->table->addToCustomColors( d->selColor );
01419 }
01420
01421 void KColorDialog::slotColorSelected( const QColor &color, const QString &name )
01422 {
01423 _setColor( color, name);
01424 }
01425
01426 void KColorDialog::slotColorDoubleClicked
01427 (
01428 const QColor & color,
01429 const QString & name
01430 )
01431 {
01432 _setColor(color, name);
01433 accept();
01434 }
01435
01436 void KColorDialog::_setColor(const KColor &color, const QString &name)
01437 {
01438 if (color.isValid())
01439 {
01440 if (d->cbDefaultColor && d->cbDefaultColor->isChecked())
01441 d->cbDefaultColor->setChecked(false);
01442 d->selColor = color;
01443 }
01444 else
01445 {
01446 if (d->cbDefaultColor && d->cbDefaultColor->isChecked())
01447 d->cbDefaultColor->setChecked(true);
01448 d->selColor = d->defaultColor;
01449 }
01450
01451 showColor( d->selColor, name );
01452
01453 emit colorSelected( d->selColor );
01454 }
01455
01456
01457 void KColorDialog::showColor( const KColor &color, const QString &name )
01458 {
01459 d->bRecursion = true;
01460
01461 if (name.isEmpty())
01462 d->colorName->setText( i18n("-unnamed-"));
01463 else
01464 d->colorName->setText( name );
01465
01466 d->patch->setColor( color );
01467
01468 setRgbEdit( color );
01469 setHsvEdit( color );
01470 setHtmlEdit( color );
01471
01472 int h, s, v;
01473 color.hsv( &h, &s, &v );
01474 d->hsSelector->setValues( h, s );
01475 d->valuePal->blockSignals(true);
01476 d->valuePal->setHue( h );
01477 d->valuePal->setSaturation( s );
01478 d->valuePal->setValue( v );
01479 d->valuePal->updateContents();
01480 d->valuePal->blockSignals(false);
01481 d->valuePal->repaint( false );
01482 d->bRecursion = false;
01483 }
01484
01485
01486 static QWidget *kde_color_dlg_widget = 0;
01487
01488 #ifdef Q_WS_X11
01489 static int kde_color_dlg_handler(XEvent *event)
01490 {
01491 if (event->type == ButtonRelease)
01492 {
01493 QMouseEvent e( QEvent::MouseButtonRelease, QPoint(),
01494 QPoint(event->xmotion.x_root, event->xmotion.y_root) , 0, 0 );
01495 QApplication::sendEvent( kde_color_dlg_widget, &e );
01496 return true;
01497 }
01498 return false;
01499 }
01500 #endif
01501 void
01502 KColorDialog::slotColorPicker()
01503 {
01504 d->bColorPicking = true;
01505 #ifdef Q_WS_X11
01506 d->oldfilter = qt_set_x11_event_filter(kde_color_dlg_handler);
01507 #endif
01508 kde_color_dlg_widget = this;
01509 grabMouse( crossCursor );
01510 grabKeyboard();
01511 }
01512
01513 void
01514 KColorDialog::mouseReleaseEvent( QMouseEvent *e )
01515 {
01516 if (d->bColorPicking)
01517 {
01518 d->bColorPicking = false;
01519 #ifdef Q_WS_X11
01520 qt_set_x11_event_filter(d->oldfilter);
01521 d->oldfilter = 0;
01522 #endif
01523 releaseMouse();
01524 releaseKeyboard();
01525 _setColor( grabColor( e->globalPos() ) );
01526 return;
01527 }
01528 KDialogBase::mouseReleaseEvent( e );
01529 }
01530
01531 QColor
01532 KColorDialog::grabColor(const QPoint &p)
01533 {
01534 QWidget *desktop = QApplication::desktop();
01535 QPixmap pm = QPixmap::grabWindow( desktop->winId(), p.x(), p.y(), 1, 1);
01536 QImage i = pm.convertToImage();
01537 return i.pixel(0,0);
01538 }
01539
01540 void
01541 KColorDialog::keyPressEvent( QKeyEvent *e )
01542 {
01543 if (d->bColorPicking)
01544 {
01545 if (e->key() == Key_Escape)
01546 {
01547 d->bColorPicking = false;
01548 #ifdef Q_WS_X11
01549 qt_set_x11_event_filter(d->oldfilter);
01550 d->oldfilter = 0;
01551 #endif
01552 releaseMouse();
01553 releaseKeyboard();
01554 }
01555 e->accept();
01556 return;
01557 }
01558 KDialogBase::keyPressEvent( e );
01559 }
01560
01561 void KColorDialog::setRgbEdit( const KColor &col )
01562 {
01563 if (d->bEditRgb) return;
01564 int r, g, b;
01565 col.rgb( &r, &g, &b );
01566
01567 d->redit->setValue( r );
01568 d->gedit->setValue( g );
01569 d->bedit->setValue( b );
01570 }
01571
01572 void KColorDialog::setHtmlEdit( const KColor &col )
01573 {
01574 if (d->bEditHtml) return;
01575 int r, g, b;
01576 col.rgb( &r, &g, &b );
01577 QString num;
01578
01579 num.sprintf("#%02X%02X%02X", r,g,b);
01580 d->htmlName->setText( num );
01581 }
01582
01583
01584 void KColorDialog::setHsvEdit( const KColor &col )
01585 {
01586 if (d->bEditHsv) return;
01587 int h, s, v;
01588 col.hsv( &h, &s, &v );
01589
01590 d->hedit->setValue( h );
01591 d->sedit->setValue( s );
01592 d->vedit->setValue( v );
01593 }
01594
01595 void KHSSelector::virtual_hook( int id, void* data )
01596 { KXYSelector::virtual_hook( id, data ); }
01597
01598 void KValueSelector::virtual_hook( int id, void* data )
01599 { KSelector::virtual_hook( id, data ); }
01600
01601 void KPaletteTable::virtual_hook( int, void* )
01602 { }
01603
01604 void KColorCells::virtual_hook( int, void* )
01605 { }
01606
01607 void KColorPatch::virtual_hook( int, void* )
01608 { }
01609
01610 void KColorDialog::virtual_hook( int id, void* data )
01611 { KDialogBase::virtual_hook( id, data ); }
01612
01613
01614 #include "kcolordialog.moc"
01615