34 #include <tqcheckbox.h> 35 #include <tqcombobox.h> 36 #include <tqdrawutil.h> 42 #include <tqvalidator.h> 43 #include <tqpainter.h> 44 #include <tqpushbutton.h> 45 #include <tqspinbox.h> 48 #include <tdeapplication.h> 49 #include <tdeconfig.h> 50 #include <tdeglobal.h> 51 #include <tdeglobalsettings.h> 52 #include <kiconloader.h> 53 #include <klineedit.h> 54 #include <tdelistbox.h> 56 #include <tdemessagebox.h> 57 #include <kseparator.h> 59 #include <kimageeffect.h> 61 #include "kcolordialog.h" 62 #include "kcolordrag.h" 63 #include "kstaticdeleter.h" 72 typedef int (*QX11EventFilter) (XEvent*);
73 extern QX11EventFilter tqt_set_x11_event_filter (QX11EventFilter filter);
76 struct ColorPaletteNameType
78 const char* m_fileName;
79 const char* m_displayName;
82 const ColorPaletteNameType colorPaletteName[]=
84 {
"Recent_Colors",
I18N_NOOP2(
"palette name",
"* Recent Colors *" ) },
85 {
"Custom_Colors",
I18N_NOOP2(
"palette name",
"* Custom Colors *" ) },
86 {
"40.colors",
I18N_NOOP2(
"palette name",
"Forty Colors" ) },
87 {
"Rainbow.colors",
I18N_NOOP2(
"palette name",
"Rainbow Colors" ) },
88 {
"Royal.colors",
I18N_NOOP2(
"palette name",
"Royal Colors" ) },
89 {
"Web.colors",
I18N_NOOP2(
"palette name",
"Web Colors" ) },
93 const int recentColorIndex = 0;
94 const int customColorIndex = 1;
96 class KColorSpinBox :
public TQSpinBox
99 KColorSpinBox(
int minValue,
int maxValue,
int step, TQWidget* parent)
100 : TQSpinBox(minValue, maxValue, step, parent,
"kcolorspinbox")
104 virtual void valueChange()
107 emit valueChanged( value() );
108 emit valueChanged( currentValueText() );
114 #define STANDARD_PAL_SIZE 17 119 r = 0; g = 0; b = 0; h = 0; s = 0; v = 0;
122 KColor::KColor(
const KColor &col)
125 h = col.h; s = col.s; v = col.v;
126 r = col.r; g = col.g; b = col.b;
129 KColor::KColor(
const TQColor &col)
132 TQColor::getRgb(&r, &g, &b);
133 TQColor::getHsv(&h, &s, &v);
136 bool KColor::operator==(
const KColor& col)
const 138 return (h == col.h) && (s == col.s) && (v == col.v) &&
139 (r == col.r) && (g == col.g) && (b == col.b);
144 *(TQColor *)
this = col;
145 h = col.h; s = col.s; v = col.v;
146 r = col.r; g = col.g; b = col.b;
151 KColor::setHsv(
int _h,
int _s,
int _v)
153 h = _h; s = _s; v = _v;
154 TQColor::setHsv(h, s, v);
155 TQColor::rgb(&r, &g, &b);
159 KColor::setRgb(
int _r,
int _g,
int _b)
161 r = _r; g = _g; b = _b;
162 TQColor::setRgb(r, g, b);
163 TQColor::hsv(&h, &s, &v);
167 KColor::rgb(
int *_r,
int *_g,
int *_b)
const 169 *_r = r; *_g = g; *_b = b;
173 KColor::hsv(
int *_h,
int *_s,
int *_v)
const 175 *_h = h; *_s = s; *_v = v;
179 static TQColor *standardPalette = 0;
182 static void createStandardPalette()
184 if ( standardPalette )
187 spd.
setObject(standardPalette,
new TQColor [STANDARD_PAL_SIZE],
true);
191 standardPalette[i++] = Qt::red;
192 standardPalette[i++] = Qt::green;
193 standardPalette[i++] = Qt::blue;
194 standardPalette[i++] = Qt::cyan;
195 standardPalette[i++] = Qt::magenta;
196 standardPalette[i++] = Qt::yellow;
197 standardPalette[i++] = Qt::darkRed;
198 standardPalette[i++] = Qt::darkGreen;
199 standardPalette[i++] = Qt::darkBlue;
200 standardPalette[i++] = Qt::darkCyan;
201 standardPalette[i++] = Qt::darkMagenta;
202 standardPalette[i++] = Qt::darkYellow;
203 standardPalette[i++] = Qt::white;
204 standardPalette[i++] = Qt::lightGray;
205 standardPalette[i++] = Qt::gray;
206 standardPalette[i++] = Qt::darkGray;
207 standardPalette[i++] = Qt::black;
217 void KHSSelector::updateContents()
222 void KHSSelector::resizeEvent( TQResizeEvent * )
235 TQImage image( xSize, ySize, 32 );
240 for ( s = ySize-1; s >= 0; s-- )
242 p = (uint *) image.scanLine( ySize - s - 1 );
243 for( h = 0; h < xSize; h++ )
245 col.setHsv( 359*h/(xSize-1), 255*s/((ySize == 1) ? 1 : ySize-1), 192 );
251 if ( TQColor::numBitPlanes() <= 8 )
253 createStandardPalette();
256 pixmap->convertFromImage( image );
263 :
TDESelector( Qt::Vertical, parent, name ), _hue(0), _sat(0)
266 pixmap.setOptimization( TQPixmap::BestOptim );
274 pixmap.setOptimization( TQPixmap::BestOptim );
277 void KValueSelector::updateContents()
282 void KValueSelector::resizeEvent( TQResizeEvent * )
295 TQImage image( xSize, ySize, 32 );
302 for (
int v = 0; v < ySize; v++ )
304 p = (uint *) image.scanLine( ySize - v - 1 );
306 for(
int x = 0; x < xSize; x++ )
308 col.setHsv( _hue, _sat, 255*x/((xSize == 1) ? 1 : xSize-1) );
317 for (
int v = 0; v < ySize; v++ )
319 p = (uint *) image.scanLine( ySize - v - 1 );
320 col.setHsv( _hue, _sat, 255*v/((ySize == 1) ? 1 : ySize-1) );
322 for (
int i = 0; i < xSize; i++ )
327 if ( TQColor::numBitPlanes() <= 8 )
329 createStandardPalette();
332 pixmap->convertFromImage( image );
337 KColorCells::KColorCells( TQWidget *parent,
int rows,
int cols )
338 : TQGridView( parent )
343 colors =
new TQColor [ rows * cols ];
345 for (
int i = 0; i < rows * cols; i++ )
346 colors[i] = TQColor();
352 setAcceptDrops(
true);
354 setHScrollBarMode( AlwaysOff );
355 setVScrollBarMode( AlwaysOff );
356 viewport()->setBackgroundMode( PaletteBackground );
357 setBackgroundMode( PaletteBackground );
360 KColorCells::~KColorCells()
365 void KColorCells::setColor(
int colNum,
const TQColor &col )
367 colors[colNum] = col;
368 updateCell( colNum/numCols(), colNum%numCols() );
371 void KColorCells::paintCell( TQPainter *painter,
int row,
int col )
378 qDrawShadePanel( painter, 1, 1, cellWidth()-2,
379 cellHeight()-2, colorGroup(),
true, 1, &brush );
382 TQColor color = colors[ row * numCols() + col ];
383 if (!color.isValid())
386 color = backgroundColor();
389 painter->setPen( color );
390 painter->setBrush( TQBrush( color ) );
391 painter->drawRect( w, w, cellWidth()-w*2, cellHeight()-w*2 );
393 if ( row * numCols() + col == selected )
394 painter->drawWinFocusRect( w, w, cellWidth()-w*2, cellHeight()-w*2 );
397 void KColorCells::resizeEvent( TQResizeEvent * )
399 setCellWidth( width() / numCols() );
400 setCellHeight( height() / numRows() );
403 void KColorCells::mousePressEvent( TQMouseEvent *e )
409 int KColorCells::posToCell(
const TQPoint &pos,
bool ignoreBorders)
411 int row = pos.y() / cellHeight();
412 int col = pos.x() / cellWidth();
413 int cell = row * numCols() + col;
418 int x = pos.x() - col * cellWidth();
419 int y = pos.y() - row * cellHeight();
420 if ( (x < border) || (x > cellWidth()-border) ||
421 (y < border) || (y > cellHeight()-border))
427 void KColorCells::mouseMoveEvent( TQMouseEvent *e )
429 if( !(e->state() & Qt::LeftButton))
return;
433 if(e->x() > mPos.x()+delay || e->x() < mPos.x()-delay ||
434 e->y() > mPos.y()+delay || e->y() < mPos.y()-delay){
436 int cell = posToCell(mPos);
437 if ((cell != -1) && colors[cell].isValid())
446 void KColorCells::dragEnterEvent( TQDragEnterEvent *event)
451 void KColorCells::dropEvent( TQDropEvent *event)
455 int cell = posToCell(event->pos(),
true);
460 void KColorCells::mouseReleaseEvent( TQMouseEvent *e )
462 int cell = posToCell(mPos);
463 int currentCell = posToCell(e->pos());
467 if (currentCell != cell)
470 if ( (cell != -1) && (selected != cell) )
472 int prevSel = selected;
474 updateCell( prevSel/numCols(), prevSel%numCols() );
475 updateCell( cell/numCols(), cell%numCols() );
480 emit colorSelected( cell );
483 void KColorCells::mouseDoubleClickEvent( TQMouseEvent * )
485 int cell = posToCell(mPos);
488 emit colorDoubleClicked( cell );
494 KColorPatch::KColorPatch( TQWidget *parent ) : TQFrame( parent )
496 setFrameStyle( TQFrame::Panel | TQFrame::Sunken );
498 setAcceptDrops(
true);
501 KColorPatch::~KColorPatch()
504 TQColor::destroyAllocContext( colContext );
507 void KColorPatch::setColor(
const TQColor &col )
510 TQColor::destroyAllocContext( colContext );
511 colContext = TQColor::enterAllocContext();
512 color.setRgb( col.rgb() );
514 TQColor::leaveAllocContext();
518 painter.begin(
this );
523 void KColorPatch::drawContents( TQPainter *painter )
525 painter->setPen( color );
526 painter->setBrush( TQBrush( color ) );
530 void KColorPatch::mouseMoveEvent( TQMouseEvent *e )
533 if( !(e->state() & Qt::LeftButton))
return;
538 void KColorPatch::dragEnterEvent( TQDragEnterEvent *event)
543 void KColorPatch::dropEvent( TQDropEvent *event)
548 emit colorChanged( c);
552 class KPaletteTable::KPaletteTablePrivate
555 TQMap<TQString,TQColor> m_namedColorMap;
558 KPaletteTable::KPaletteTable( TQWidget *parent,
int minWidth,
int cols)
559 : TQWidget( parent ), cells(0), mPalette(0), mMinWidth(minWidth), mCols(cols)
561 d =
new KPaletteTablePrivate;
563 i18n_namedColors = i18n(
"Named Colors");
566 TQStringList paletteList;
569 for (
int i = 0; colorPaletteName[i].m_fileName; ++i )
571 diskPaletteList.remove( colorPaletteName[i].m_fileName );
572 paletteList.append( i18n(
"palette name", colorPaletteName[i].m_displayName ) );
574 paletteList += diskPaletteList;
575 paletteList.append( i18n_namedColors );
577 TQVBoxLayout *layout =
new TQVBoxLayout(
this );
579 combo =
new TQComboBox(
false,
this );
580 combo->insertStringList( paletteList );
581 layout->addWidget(combo);
583 sv =
new TQScrollView(
this );
584 TQSize cellSize = TQSize( mMinWidth, 120);
585 sv->setHScrollBarMode( TQScrollView::AlwaysOff);
586 sv->setVScrollBarMode( TQScrollView::AlwaysOn);
587 TQSize minSize = TQSize(sv->verticalScrollBar()->width(), 0);
588 minSize += TQSize(sv->frameWidth(), 0);
589 minSize += TQSize(cellSize);
590 sv->setFixedSize(minSize);
591 layout->addWidget(sv);
593 mNamedColorList =
new TDEListBox(
this,
"namedColorList", 0 );
594 mNamedColorList->setFixedSize(minSize);
595 mNamedColorList->hide();
596 layout->addWidget(mNamedColorList);
597 connect( mNamedColorList, TQT_SIGNAL(highlighted(
const TQString & )),
598 this, TQT_SLOT( slotColorTextSelected(
const TQString & )) );
600 setFixedSize( sizeHint());
601 connect( combo, TQT_SIGNAL(activated(
const TQString &)),
602 this, TQT_SLOT(slotSetPalette(
const TQString &)));
605 KPaletteTable::~KPaletteTable()
612 KPaletteTable::palette()
const 614 return combo->currentText();
618 static const char *
const *namedColorFilePath(
void )
624 static const char *
const path[] =
629 "/usr/share/X11/rgb.txt",
630 "/usr/X11R6/lib/X11/rgb.txt",
631 "/usr/openwin/lib/X11/rgb.txt",
641 KPaletteTable::readNamedColor(
void )
643 if( mNamedColorList->count() != 0 )
654 const char *
const *path = namedColorFilePath();
655 for(
int i=0; path[i]; ++i )
657 TQFile paletteFile( path[i] );
658 if( !paletteFile.open( IO_ReadOnly ) )
665 while( paletteFile.readLine( line, 100 ) != -1 )
667 int red, green, blue;
670 if( sscanf(line.ascii(),
"%d %d %d%n", &red, &green, &blue, &pos ) == 3 )
676 TQString name = line.mid(pos).stripWhiteSpace();
677 if( name.isNull() || name.find(
' ') != -1 ||
678 name.find(
"gray" ) != -1 || name.find(
"grey" ) != -1 )
683 const TQColor color ( red, green, blue );
684 if ( color.isValid() )
686 const TQString colorName( i18n(
"color", name.latin1() ) );
687 list.append( colorName );
688 d->m_namedColorMap[ colorName ] = color;
694 mNamedColorList->insertStringList( list );
698 if( mNamedColorList->count() == 0 )
707 TQTimer::singleShot( 10,
this, TQT_SLOT(slotShowNamedColorReadError()) );
713 KPaletteTable::slotShowNamedColorReadError(
void )
715 if( mNamedColorList->count() == 0 )
717 TQString msg = i18n(
"" 718 "Unable to read X11 RGB color strings. The following " 719 "file location(s) were examined:\n");
721 const char *
const *path = namedColorFilePath();
722 for(
int i=0; path[i]; ++i )
743 KPaletteTable::slotSetPalette(
const TQString &_paletteName )
745 setPalette( _paletteName );
746 if( mNamedColorList->isVisible() )
748 int item = mNamedColorList->currentItem();
749 mNamedColorList->setCurrentItem( item < 0 ? 0 : item );
750 slotColorTextSelected( mNamedColorList->currentText() );
754 slotColorCellSelected(0);
760 KPaletteTable::setPalette(
const TQString &_paletteName )
762 TQString paletteName( _paletteName);
763 if (paletteName.isEmpty())
764 paletteName = i18n_recentColors;
766 if (combo->currentText() != paletteName)
769 for(
int i = 0; i < combo->count(); i++)
771 if (combo->text(i) == paletteName)
773 combo->setCurrentItem(i);
780 combo->insertItem(paletteName);
781 combo->setCurrentItem(combo->count()-1);
786 for (
int i = 0; colorPaletteName[i].m_fileName; ++i )
788 if ( paletteName == i18n(
"palette name", colorPaletteName[i].m_displayName ) )
790 paletteName = colorPaletteName[i].m_fileName;
804 if( !mPalette || mPalette->name() != paletteName )
806 if( paletteName == i18n_namedColors )
809 mNamedColorList->show();
812 delete cells; cells = 0;
813 delete mPalette; mPalette = 0;
817 mNamedColorList->hide();
822 mPalette =
new KPalette(paletteName);
823 int rows = (mPalette->nrColors()+mCols-1) / mCols;
824 if (rows < 1) rows = 1;
825 cells =
new KColorCells( sv->viewport(), rows, mCols);
826 cells->setShading(
false);
827 cells->setAcceptDrags(
false);
828 TQSize cellSize = TQSize( mMinWidth, mMinWidth * rows / mCols);
829 cells->setFixedSize( cellSize );
830 for(
int i = 0; i < mPalette->nrColors(); i++)
832 cells->setColor( i, mPalette->color(i) );
834 connect( cells, TQT_SIGNAL( colorSelected(
int ) ),
835 TQT_SLOT( slotColorCellSelected(
int ) ) );
836 connect( cells, TQT_SIGNAL( colorDoubleClicked(
int ) ),
837 TQT_SLOT( slotColorCellDoubleClicked(
int ) ) );
838 sv->addChild( cells );
840 sv->updateScrollBars();
848 KPaletteTable::slotColorCellSelected(
int col )
850 if (!mPalette || (col >= mPalette->nrColors()))
852 emit colorSelected( mPalette->color(col), mPalette->colorName(col) );
856 KPaletteTable::slotColorCellDoubleClicked(
int col )
858 if (!mPalette || (col >= mPalette->nrColors()))
860 emit colorDoubleClicked( mPalette->color(col), mPalette->colorName(col) );
865 KPaletteTable::slotColorTextSelected(
const TQString &colorText )
867 emit colorSelected( d->m_namedColorMap[ colorText ], colorText );
872 KPaletteTable::addToCustomColors(
const TQColor &color)
874 setPalette(i18n(
"palette name", colorPaletteName[ customColorIndex ].m_displayName ));
875 mPalette->addColor( color );
879 setPalette(i18n(
"palette name", colorPaletteName[ customColorIndex ].m_displayName ));
883 KPaletteTable::addToRecentColors(
const TQColor &color)
889 bool recentIsSelected =
false;
890 if ( mPalette && mPalette->name() == colorPaletteName[ recentColorIndex ].m_fileName )
894 recentIsSelected =
true;
896 KPalette *recentPal =
new KPalette( colorPaletteName[ recentColorIndex ].m_fileName );
903 if (recentIsSelected)
904 setPalette( i18n(
"palette name", colorPaletteName[ recentColorIndex ].m_displayName ) );
907 class KColorDialog::KColorDialogPrivate {
910 TQString originalPalette;
918 KColorSpinBox *hedit;
919 KColorSpinBox *sedit;
920 KColorSpinBox *vedit;
921 KColorSpinBox *redit;
922 KColorSpinBox *gedit;
923 KColorSpinBox *bedit;
928 TQVBoxLayout* l_right;
929 TQGridLayout* tl_layout;
930 TQCheckBox *cbDefaultColor;
934 QX11EventFilter oldfilter;
940 :
KDialogBase( parent, name, modal, i18n(
"Select Color"),
941 modal ? Ok|Cancel : Close,
944 d =
new KColorDialogPrivate;
945 d->bRecursion =
true;
946 d->bColorPicking =
false;
950 d->cbDefaultColor = 0L;
951 connect(
this, TQT_SIGNAL(
okClicked(
void)),
this,TQT_SLOT(slotWriteSettings(
void)));
952 connect(
this, TQT_SIGNAL(
closeClicked(
void)),
this,TQT_SLOT(slotWriteSettings(
void)));
959 TQWidget *page =
new TQWidget(
this );
962 TQGridLayout *tl_layout =
new TQGridLayout( page, 3, 3, 0,
spacingHint() );
963 d->tl_layout = tl_layout;
970 TQVBoxLayout *l_left =
new TQVBoxLayout();
971 tl_layout->addLayout(l_left, 0, 0);
977 TQHBoxLayout *l_ltop =
new TQHBoxLayout();
978 l_left->addLayout(l_ltop);
981 l_left->addSpacing(10);
983 TQGridLayout *l_lbot =
new TQGridLayout(3, 6);
984 l_left->addLayout(TQT_TQLAYOUT(l_lbot));
990 d->hsSelector->setMinimumSize(140, 70);
991 l_ltop->addWidget(d->hsSelector, 8);
992 connect( d->hsSelector, TQT_SIGNAL( valueChanged(
int,
int ) ),
993 TQT_SLOT( slotHSChanged(
int,
int ) ) );
996 d->valuePal->setMinimumSize(26, 70);
997 l_ltop->addWidget(d->valuePal, 1);
998 connect( d->valuePal, TQT_SIGNAL( valueChanged(
int ) ),
999 TQT_SLOT( slotVChanged(
int ) ) );
1005 label =
new TQLabel( i18n(
"H:"), page );
1006 label->setAlignment(AlignRight | AlignVCenter);
1007 l_lbot->addWidget(label, 0, 2);
1008 d->hedit =
new KColorSpinBox( 0, 359, 1, page );
1009 d->hedit->setValidator(
new TQIntValidator( TQT_TQOBJECT(d->hedit) ) );
1010 l_lbot->addWidget(d->hedit, 0, 3);
1011 connect( d->hedit, TQT_SIGNAL( valueChanged(
int) ),
1012 TQT_SLOT( slotHSVChanged() ) );
1014 label =
new TQLabel( i18n(
"S:"), page );
1015 label->setAlignment(AlignRight | AlignVCenter);
1016 l_lbot->addWidget(label, 1, 2);
1017 d->sedit =
new KColorSpinBox( 0, 255, 1, page );
1018 d->sedit->setValidator(
new TQIntValidator( TQT_TQOBJECT(d->sedit) ) );
1019 l_lbot->addWidget(d->sedit, 1, 3);
1020 connect( d->sedit, TQT_SIGNAL( valueChanged(
int) ),
1021 TQT_SLOT( slotHSVChanged() ) );
1023 label =
new TQLabel( i18n(
"V:"), page );
1024 label->setAlignment(AlignRight | AlignVCenter);
1025 l_lbot->addWidget(label, 2, 2);
1026 d->vedit =
new KColorSpinBox( 0, 255, 1, page );
1027 d->vedit->setValidator(
new TQIntValidator( TQT_TQOBJECT(d->vedit) ) );
1028 l_lbot->addWidget(d->vedit, 2, 3);
1029 connect( d->vedit, TQT_SIGNAL( valueChanged(
int) ),
1030 TQT_SLOT( slotHSVChanged() ) );
1035 label =
new TQLabel( i18n(
"R:"), page );
1036 label->setAlignment(AlignRight | AlignVCenter);
1037 l_lbot->addWidget(label, 0, 4);
1038 d->redit =
new KColorSpinBox( 0, 255, 1, page );
1039 d->redit->setValidator(
new TQIntValidator( TQT_TQOBJECT(d->redit) ) );
1040 l_lbot->addWidget(d->redit, 0, 5);
1041 connect( d->redit, TQT_SIGNAL( valueChanged(
int) ),
1042 TQT_SLOT( slotRGBChanged() ) );
1044 label =
new TQLabel( i18n(
"G:"), page );
1045 label->setAlignment(AlignRight | AlignVCenter);
1046 l_lbot->addWidget( label, 1, 4);
1047 d->gedit =
new KColorSpinBox( 0, 255,1, page );
1048 d->gedit->setValidator(
new TQIntValidator( TQT_TQOBJECT(d->gedit) ) );
1049 l_lbot->addWidget(d->gedit, 1, 5);
1050 connect( d->gedit, TQT_SIGNAL( valueChanged(
int) ),
1051 TQT_SLOT( slotRGBChanged() ) );
1053 label =
new TQLabel( i18n(
"B:"), page );
1054 label->setAlignment(AlignRight | AlignVCenter);
1055 l_lbot->addWidget(label, 2, 4);
1056 d->bedit =
new KColorSpinBox( 0, 255, 1, page );
1057 d->bedit->setValidator(
new TQIntValidator( TQT_TQOBJECT(d->bedit) ) );
1058 l_lbot->addWidget(d->bedit, 2, 5);
1059 connect( d->bedit, TQT_SIGNAL( valueChanged(
int) ),
1060 TQT_SLOT( slotRGBChanged() ) );
1065 int w = d->hedit->fontMetrics().width(
"8888888");
1066 d->hedit->setFixedWidth(w);
1067 d->sedit->setFixedWidth(w);
1068 d->vedit->setFixedWidth(w);
1070 d->redit->setFixedWidth(w);
1071 d->gedit->setFixedWidth(w);
1072 d->bedit->setFixedWidth(w);
1077 d->l_right =
new TQVBoxLayout;
1078 tl_layout->addLayout(d->l_right, 0, 2);
1084 d->l_right->addWidget(d->table, 10);
1086 connect( d->table, TQT_SIGNAL(
colorSelected(
const TQColor &,
const TQString & ) ),
1087 TQT_SLOT( slotColorSelected(
const TQColor &,
const TQString & ) ) );
1091 TQT_SIGNAL( colorDoubleClicked(
const TQColor &,
const TQString & ) ),
1092 TQT_SLOT( slotColorDoubleClicked(
const TQColor &,
const TQString & ) )
1095 d->originalPalette = d->table->palette();
1100 d->l_right->addSpacing(10);
1102 TQHBoxLayout *l_hbox =
new TQHBoxLayout( d->l_right );
1107 TQPushButton *button =
new TQPushButton( page );
1108 button->setText(i18n(
"&Add to Custom Colors"));
1109 l_hbox->addWidget(button, 0, AlignLeft);
1110 connect( button, TQT_SIGNAL( clicked()), TQT_SLOT( slotAddToCustomColors()));
1115 button =
new TQPushButton( page );
1116 button->setPixmap( BarIcon(
"colorpicker"));
1117 l_hbox->addWidget(button, 0, AlignHCenter );
1118 connect( button, TQT_SIGNAL( clicked()), TQT_SLOT( slotColorPicker()));
1123 d->l_right->addSpacing(10);
1128 TQGridLayout *l_grid =
new TQGridLayout( d->l_right, 2, 3);
1130 l_grid->setColStretch(2, 1);
1132 label =
new TQLabel( page );
1133 label->setText(i18n(
"Name:"));
1134 l_grid->addWidget(TQT_TQWIDGET(label), 0, 1, Qt::AlignLeft);
1136 d->colorName =
new TQLabel( page );
1137 l_grid->addWidget(TQT_TQWIDGET(d->colorName), 0, 2, Qt::AlignLeft);
1139 label =
new TQLabel( page );
1140 label->setText(i18n(
"HTML:"));
1141 l_grid->addWidget(TQT_TQWIDGET(label), 1, 1, Qt::AlignLeft);
1144 d->htmlName->setMaxLength( 13 );
1145 d->htmlName->setText(
"#FFFFFF");
1146 w = d->htmlName->fontMetrics().width(TQString::fromLatin1(
"#DDDDDDD"));
1147 d->htmlName->setFixedWidth(w);
1148 l_grid->addWidget(TQT_TQWIDGET(d->htmlName), 1, 2, Qt::AlignLeft);
1150 connect( d->htmlName, TQT_SIGNAL( textChanged(
const TQString &) ),
1151 TQT_SLOT( slotHtmlChanged() ) );
1154 d->patch->setFixedSize(48, 48);
1155 l_grid->addMultiCellWidget(TQT_TQWIDGET(d->patch), 0, 1, 0, 0, Qt::AlignHCenter | Qt::AlignVCenter);
1156 connect( d->patch, TQT_SIGNAL( colorChanged(
const TQColor&)),
1157 TQT_SLOT(
setColor(
const TQColor&)));
1159 tl_layout->activate();
1160 page->setMinimumSize( page->sizeHint() );
1163 d->bRecursion =
false;
1164 d->bEditHsv =
false;
1165 d->bEditRgb =
false;
1166 d->bEditHtml =
false;
1170 col.setHsv( 0, 0, 255 );
1173 d->htmlName->installEventFilter(
this);
1174 d->hsSelector->installEventFilter(
this);
1175 d->hsSelector->setAcceptDrops(
true);
1181 if (d->bColorPicking)
1182 tqt_set_x11_event_filter(d->oldfilter);
1188 KColorDialog::eventFilter( TQObject *obj, TQEvent *ev )
1190 if ((TQT_BASE_OBJECT(obj) == TQT_BASE_OBJECT(d->htmlName)) || (TQT_BASE_OBJECT(obj) == TQT_BASE_OBJECT(d->hsSelector)))
1193 case TQEvent::DragEnter:
1194 case TQEvent::DragMove:
1195 case TQEvent::DragLeave:
1197 case TQEvent::DragResponse:
1198 tqApp->sendEvent(d->patch, ev);
1203 return KDialogBase::eventFilter(obj, ev);
1209 if ( !d->cbDefaultColor )
1214 d->l_right->addSpacing(10);
1219 d->cbDefaultColor =
new TQCheckBox( i18n(
"Default color" ),
mainWidget() );
1220 d->cbDefaultColor->setChecked(
true);
1222 d->l_right->addWidget( d->cbDefaultColor );
1224 mainWidget()->setMaximumSize( TQWIDGETSIZE_MAX, TQWIDGETSIZE_MAX );
1225 d->tl_layout->activate();
1229 connect( d->cbDefaultColor, TQT_SIGNAL( clicked() ), TQT_SLOT( slotDefaultColorClicked() ) );
1232 d->defaultColor = col;
1234 slotDefaultColorClicked();
1239 return d->defaultColor;
1242 void KColorDialog::slotDefaultColorClicked()
1244 if ( d->cbDefaultColor->isChecked() )
1246 d->selColor = d->defaultColor;
1247 showColor( d->selColor, i18n(
"-default-" ) );
1250 showColor( d->selColor, TQString::null );
1255 KColorDialog::readSettings()
1259 TQString palette = group.
readEntry(
"CurrentPalette");
1260 d->table->setPalette(palette);
1264 KColorDialog::slotWriteSettings()
1268 TQString palette = d->table->palette();
1270 (d->table->palette() == d->originalPalette))
1276 group.
writeEntry(
"CurrentPalette", d->table->palette());
1283 if ( d->cbDefaultColor && d->cbDefaultColor->isChecked() )
1285 if ( d->selColor.isValid() )
1286 d->table->addToRecentColors( d->selColor );
1301 if ( theColor.isValid() )
1303 int result = dlg.exec();
1305 if ( result == Accepted )
1307 theColor = dlg.
color();
1321 int result = dlg.exec();
1323 if ( result == Accepted )
1324 theColor = dlg.
color();
1329 void KColorDialog::slotRGBChanged(
void )
1331 if (d->bRecursion)
return;
1332 int red = d->redit->value();
1333 int grn = d->gedit->value();
1334 int blu = d->bedit->value();
1336 if ( red > 255 || red < 0 )
return;
1337 if ( grn > 255 || grn < 0 )
return;
1338 if ( blu > 255 || blu < 0 )
return;
1341 col.setRgb( red, grn, blu );
1344 d->bEditRgb =
false;
1347 void KColorDialog::slotHtmlChanged(
void )
1349 if (d->bRecursion || d->htmlName->text().isEmpty())
return;
1351 TQString strColor( d->htmlName->text() );
1354 if ( strColor[0] !=
'#' )
1356 bool signalsblocked = d->htmlName->signalsBlocked();
1357 d->htmlName->blockSignals(
true);
1358 strColor.prepend(
"#");
1359 d->htmlName->setText(strColor);
1360 d->htmlName->blockSignals(signalsblocked);
1363 const TQColor
color( strColor );
1365 if ( color.isValid() )
1368 d->bEditHtml =
true;
1370 d->bEditHtml =
false;
1374 void KColorDialog::slotHSVChanged(
void )
1376 if (d->bRecursion)
return;
1377 int hue = d->hedit->value();
1378 int sat = d->sedit->value();
1379 int val = d->vedit->value();
1381 if ( hue > 359 || hue < 0 )
return;
1382 if ( sat > 255 || sat < 0 )
return;
1383 if ( val > 255 || val < 0 )
return;
1386 col.setHsv( hue, sat, val );
1389 d->bEditHsv =
false;
1392 void KColorDialog::slotHSChanged(
int h,
int s )
1395 d->selColor.hsv(&_h, &_s, &v);
1399 col.setHsv( h, s, v );
1403 void KColorDialog::slotVChanged(
int v )
1406 d->selColor.hsv(&h, &s, &_v);
1408 col.setHsv( h, s, v );
1412 void KColorDialog::slotColorSelected(
const TQColor &color )
1417 void KColorDialog::slotAddToCustomColors( )
1419 d->table->addToCustomColors( d->selColor );
1422 void KColorDialog::slotColorSelected(
const TQColor &color,
const TQString &name )
1424 _setColor( color, name);
1427 void KColorDialog::slotColorDoubleClicked
1429 const TQColor & color,
1430 const TQString & name
1433 _setColor(color, name);
1437 void KColorDialog::_setColor(
const KColor &color,
const TQString &name)
1439 if (color.isValid())
1441 if (d->cbDefaultColor && d->cbDefaultColor->isChecked())
1442 d->cbDefaultColor->setChecked(
false);
1443 d->selColor =
color;
1447 if (d->cbDefaultColor && d->cbDefaultColor->isChecked())
1448 d->cbDefaultColor->setChecked(
true);
1449 d->selColor = d->defaultColor;
1452 showColor( d->selColor, name );
1458 void KColorDialog::showColor(
const KColor &color,
const TQString &name )
1460 d->bRecursion =
true;
1463 d->colorName->setText( i18n(
"-unnamed-"));
1465 d->colorName->setText( name );
1467 d->patch->setColor( color );
1469 setRgbEdit( color );
1470 setHsvEdit( color );
1471 setHtmlEdit( color );
1474 color.hsv( &h, &s, &v );
1475 d->hsSelector->setValues( h, s );
1476 d->valuePal->blockSignals(
true);
1477 d->valuePal->setHue( h );
1478 d->valuePal->setSaturation( s );
1479 d->valuePal->setValue( v );
1480 d->valuePal->updateContents();
1481 d->valuePal->blockSignals(
false);
1482 d->valuePal->repaint(
false );
1483 d->bRecursion =
false;
1487 static TQWidget *kde_color_dlg_widget = 0;
1490 static int kde_color_dlg_handler(XEvent *event)
1492 if (event->type == ButtonRelease)
1494 TQMouseEvent e( TQEvent::MouseButtonRelease, TQPoint(),
1495 TQPoint(event->xmotion.x_root, event->xmotion.y_root) , 0, 0 );
1496 TQApplication::sendEvent( kde_color_dlg_widget, &e );
1503 KColorDialog::slotColorPicker()
1505 d->bColorPicking =
true;
1507 d->oldfilter = tqt_set_x11_event_filter(kde_color_dlg_handler);
1509 kde_color_dlg_widget =
this;
1510 grabMouse( tqcrossCursor );
1515 KColorDialog::mouseReleaseEvent( TQMouseEvent *e )
1517 if (d->bColorPicking)
1519 d->bColorPicking =
false;
1521 tqt_set_x11_event_filter(d->oldfilter);
1526 _setColor(
grabColor( e->globalPos() ) );
1529 KDialogBase::mouseReleaseEvent( e );
1535 TQWidget *desktop = TQT_TQWIDGET(TQApplication::desktop());
1536 TQPixmap pm = TQPixmap::grabWindow( desktop->winId(), p.x(), p.y(), 1, 1);
1537 TQImage i = pm.convertToImage();
1538 return i.pixel(0,0);
1544 if (d->bColorPicking)
1546 if (e->key() == Key_Escape)
1548 d->bColorPicking =
false;
1550 tqt_set_x11_event_filter(d->oldfilter);
1562 void KColorDialog::setRgbEdit(
const KColor &col )
1564 if (d->bEditRgb)
return;
1566 col.rgb( &r, &g, &b );
1568 d->redit->setValue( r );
1569 d->gedit->setValue( g );
1570 d->bedit->setValue( b );
1573 void KColorDialog::setHtmlEdit(
const KColor &col )
1575 if (d->bEditHtml)
return;
1577 col.rgb( &r, &g, &b );
1580 num.sprintf(
"#%02X%02X%02X", r,g,b);
1581 d->htmlName->setText( num );
1585 void KColorDialog::setHsvEdit(
const KColor &col )
1587 if (d->bEditHsv)
return;
1589 col.hsv( &h, &s, &v );
1591 d->hedit->setValue( h );
1592 d->sedit->setValue( s );
1593 d->vedit->setValue( v );
1596 void KHSSelector::virtual_hook(
int id,
void* data )
1597 { KXYSelector::virtual_hook(
id, data ); }
1599 void KValueSelector::virtual_hook(
int id,
void* data )
1600 { TDESelector::virtual_hook(
id, data ); }
1602 void KPaletteTable::virtual_hook(
int,
void* )
1605 void KColorCells::virtual_hook(
int,
void* )
1608 void KColorPatch::virtual_hook(
int,
void* )
1611 void KColorDialog::virtual_hook(
int id,
void* data )
1612 { KDialogBase::virtual_hook(
id, data ); }
1615 #include "kcolordialog.moc" static bool decode(TQMimeSource *e, TQColor &col)
Decodes the MIME source e and puts the resulting color into col.
static TQImage & dither(TQImage &image, const TQColor *palette, int size)
int findColor(const TQColor &color) const
Widget for Hue/Saturation colour selection.
void colorSelected(const TQColor &col)
Emitted when a color is selected.
virtual void drawPalette(TQPixmap *pixmap)
Draws the contents of the widget on a pixmap, which is used for buffering.
TQColor color() const
Returns the currently selected color.
A color palette in table form.
virtual void drawPalette(TQPixmap *pixmap)
Draws the contents of the widget on a pixmap, which is used for buffering.
static int dndEventDelay()
void disableResize()
Convenience method.
TQRect contentsRect() const
void setRange(int minX, int minY, int maxX, int maxY)
Sets the range of possible values.
static int getColor(TQColor &theColor, TQWidget *parent=0L)
Creates a modal color dialog, let the user choose a color, and returns when the dialog is closed...
static void sorry(TQWidget *parent, const TQString &text, const TQString &caption=TQString::null, int options=Notify)
Display an "Sorry" dialog.
A dialog base class with standard buttons and predefined layouts.
KDE_DEPRECATED type * setObject(type *obj, bool isArray=false)
A drag-and-drop object for colors.
virtual void keyPressEvent(TQKeyEvent *)
Maps some keys to the actions buttons.
static int spacingHint()
Return the number of pixels you shall use between widgets inside a dialog according to the KDE standa...
static bool canDecode(TQMimeSource *e)
Returns true if the MIME source e contains a color object.
void writeEntry(const TQString &pKey, const TQString &pValue, bool bPersistent=true, bool bGlobal=false, bool bNLS=false)
Orientation orientation() const
void setMainWidget(TQWidget *widget)
Sets the main user definable widget.
void insertCatalogue(const TQString &catalog)
void setColor(const TQColor &col)
Preselects a color.
#define I18N_NOOP2(comment, x)
TQColor defaultColor() const
KHSSelector(TQWidget *parent=0, const char *name=0)
Constructs a hue/saturation selection widget.
A table of editable color cells.
Widget for color value selection.
A color class that preserves both RGB and HSV values.
virtual void drawContents(TQPainter *painter)
Reimplemented from TDESelector.
TQString readEntry(const TQString &pKey, const TQString &aDefault=TQString::null) const
void setDefaultColor(const TQColor &defaultCol)
Call this to make the dialog show a "Default Color" checkbox.
virtual void keyPressEvent(TQKeyEvent *e)
Maps some keys to the actions buttons.
An enhanced TQLineEdit widget for inputting text.
static TDELocale * locale()
virtual void drawContents(TQPainter *painter)
Reimplemented from KXYSelector.
A color selection dialog.
TQWidget * mainWidget()
Returns the main widget if any.
static TQStringList getPaletteList()
void okClicked()
The OK button was pressed.
bool hasDefault(const TQString &key) const
KColorDialog(TQWidget *parent=0L, const char *name=0L, bool modal=false)
Constructs a color selection dialog.
KXYSelector is the base class for other widgets which provides the ability to choose from a two-dimen...
TQRect contentsRect() const
KValueSelector(TQWidget *parent=0, const char *name=0)
Constructs a widget for color selection.
static TDEConfig * config()
A variant of TQListBox that honors KDE's system-wide settings.
void revertToDefault(const TQString &key)
~KColorDialog()
Destroys the color selection dialog.
int addColor(const TQColor &newColor, const TQString &newColorName=TQString::null)
TDESelector is the base class for other widgets which provides the ability to choose from a one-dimen...
void closeClicked()
The Close button was pressed.
static TQColor grabColor(const TQPoint &p)
Gets the color from the pixel at point p on the screen.