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" 75 typedef int (*QX11EventFilter) (XEvent*);
76 extern QX11EventFilter tqt_set_x11_event_filter (QX11EventFilter filter);
79 struct ColorPaletteNameType
81 const char* m_fileName;
82 const char* m_displayName;
85 const ColorPaletteNameType colorPaletteName[]=
87 {
"Recent_Colors",
I18N_NOOP2(
"palette name",
"* Recent Colors *" ) },
88 {
"Custom_Colors",
I18N_NOOP2(
"palette name",
"* Custom Colors *" ) },
89 {
"40.colors",
I18N_NOOP2(
"palette name",
"Forty Colors" ) },
90 {
"Rainbow.colors",
I18N_NOOP2(
"palette name",
"Rainbow Colors" ) },
91 {
"Royal.colors",
I18N_NOOP2(
"palette name",
"Royal Colors" ) },
92 {
"Web.colors",
I18N_NOOP2(
"palette name",
"Web Colors" ) },
96 const int recentColorIndex = 0;
97 const int customColorIndex = 1;
99 class KColorSpinBox :
public TQSpinBox
102 KColorSpinBox(
int minValue,
int maxValue,
int step, TQWidget* parent)
103 : TQSpinBox(minValue, maxValue, step, parent,
"kcolorspinbox")
107 virtual void valueChange()
110 emit valueChanged( value() );
111 emit valueChanged( currentValueText() );
117 #define STANDARD_PAL_SIZE 17 122 r = 0; g = 0; b = 0; h = 0; s = 0; v = 0;
125 KColor::KColor(
const KColor &col)
128 h = col.h; s = col.s; v = col.v;
129 r = col.r; g = col.g; b = col.b;
132 KColor::KColor(
const TQColor &col)
135 TQColor::getRgb(&r, &g, &b);
136 TQColor::getHsv(&h, &s, &v);
139 bool KColor::operator==(
const KColor& col)
const 141 return (h == col.h) && (s == col.s) && (v == col.v) &&
142 (r == col.r) && (g == col.g) && (b == col.b);
147 *(TQColor *)
this = col;
148 h = col.h; s = col.s; v = col.v;
149 r = col.r; g = col.g; b = col.b;
154 KColor::setHsv(
int _h,
int _s,
int _v)
156 h = _h; s = _s; v = _v;
157 TQColor::setHsv(h, s, v);
158 TQColor::rgb(&r, &g, &b);
162 KColor::setRgb(
int _r,
int _g,
int _b)
164 r = _r; g = _g; b = _b;
165 TQColor::setRgb(r, g, b);
166 TQColor::hsv(&h, &s, &v);
170 KColor::rgb(
int *_r,
int *_g,
int *_b)
const 172 *_r = r; *_g = g; *_b = b;
176 KColor::hsv(
int *_h,
int *_s,
int *_v)
const 178 *_h = h; *_s = s; *_v = v;
182 static TQColor *standardPalette = 0;
185 static void createStandardPalette()
187 if ( standardPalette )
190 spd.
setObject(standardPalette,
new TQColor [STANDARD_PAL_SIZE],
true);
194 standardPalette[i++] = Qt::red;
195 standardPalette[i++] = Qt::green;
196 standardPalette[i++] = Qt::blue;
197 standardPalette[i++] = Qt::cyan;
198 standardPalette[i++] = Qt::magenta;
199 standardPalette[i++] = Qt::yellow;
200 standardPalette[i++] = Qt::darkRed;
201 standardPalette[i++] = Qt::darkGreen;
202 standardPalette[i++] = Qt::darkBlue;
203 standardPalette[i++] = Qt::darkCyan;
204 standardPalette[i++] = Qt::darkMagenta;
205 standardPalette[i++] = Qt::darkYellow;
206 standardPalette[i++] = Qt::white;
207 standardPalette[i++] = Qt::lightGray;
208 standardPalette[i++] = Qt::gray;
209 standardPalette[i++] = Qt::darkGray;
210 standardPalette[i++] = Qt::black;
220 void KHSSelector::updateContents()
225 void KHSSelector::resizeEvent( TQResizeEvent * )
238 TQImage image( xSize, ySize, 32 );
243 for ( s = ySize-1; s >= 0; s-- )
245 p = (uint *) image.scanLine( ySize - s - 1 );
246 for( h = 0; h < xSize; h++ )
248 col.setHsv( 359*h/(xSize-1), 255*s/((ySize == 1) ? 1 : ySize-1), 192 );
254 if ( TQColor::numBitPlanes() <= 8 )
256 createStandardPalette();
259 pixmap->convertFromImage( image );
266 :
TDESelector( Qt::Vertical, parent, name ), _hue(0), _sat(0)
269 pixmap.setOptimization( TQPixmap::BestOptim );
277 pixmap.setOptimization( TQPixmap::BestOptim );
280 void KValueSelector::updateContents()
285 void KValueSelector::resizeEvent( TQResizeEvent * )
298 TQImage image( xSize, ySize, 32 );
305 for (
int v = 0; v < ySize; v++ )
307 p = (uint *) image.scanLine( ySize - v - 1 );
309 for(
int x = 0; x < xSize; x++ )
311 col.setHsv( _hue, _sat, 255*x/((xSize == 1) ? 1 : xSize-1) );
320 for (
int v = 0; v < ySize; v++ )
322 p = (uint *) image.scanLine( ySize - v - 1 );
323 col.setHsv( _hue, _sat, 255*v/((ySize == 1) ? 1 : ySize-1) );
325 for (
int i = 0; i < xSize; i++ )
330 if ( TQColor::numBitPlanes() <= 8 )
332 createStandardPalette();
335 pixmap->convertFromImage( image );
340 KColorCells::KColorCells( TQWidget *parent,
int rows,
int cols )
341 : TQGridView( parent )
346 colors =
new TQColor [ rows * cols ];
348 for (
int i = 0; i < rows * cols; i++ )
349 colors[i] = TQColor();
355 setAcceptDrops(
true);
357 setHScrollBarMode( AlwaysOff );
358 setVScrollBarMode( AlwaysOff );
359 viewport()->setBackgroundMode( PaletteBackground );
360 setBackgroundMode( PaletteBackground );
363 KColorCells::~KColorCells()
368 void KColorCells::setColor(
int colNum,
const TQColor &col )
370 colors[colNum] = col;
371 updateCell( colNum/numCols(), colNum%numCols() );
374 void KColorCells::paintCell( TQPainter *painter,
int row,
int col )
381 qDrawShadePanel( painter, 1, 1, cellWidth()-2,
382 cellHeight()-2, colorGroup(),
true, 1, &brush );
385 TQColor color = colors[ row * numCols() + col ];
386 if (!color.isValid())
389 color = backgroundColor();
392 painter->setPen( color );
393 painter->setBrush( TQBrush( color ) );
394 painter->drawRect( w, w, cellWidth()-w*2, cellHeight()-w*2 );
396 if ( row * numCols() + col == selected )
397 painter->drawWinFocusRect( w, w, cellWidth()-w*2, cellHeight()-w*2 );
400 void KColorCells::resizeEvent( TQResizeEvent * )
402 setCellWidth( width() / numCols() );
403 setCellHeight( height() / numRows() );
406 void KColorCells::mousePressEvent( TQMouseEvent *e )
412 int KColorCells::posToCell(
const TQPoint &pos,
bool ignoreBorders)
414 int row = pos.y() / cellHeight();
415 int col = pos.x() / cellWidth();
416 int cell = row * numCols() + col;
421 int x = pos.x() - col * cellWidth();
422 int y = pos.y() - row * cellHeight();
423 if ( (x < border) || (x > cellWidth()-border) ||
424 (y < border) || (y > cellHeight()-border))
430 void KColorCells::mouseMoveEvent( TQMouseEvent *e )
432 if( !(e->state() & Qt::LeftButton))
return;
436 if(e->x() > mPos.x()+delay || e->x() < mPos.x()-delay ||
437 e->y() > mPos.y()+delay || e->y() < mPos.y()-delay){
439 int cell = posToCell(mPos);
440 if ((cell != -1) && colors[cell].isValid())
449 void KColorCells::dragEnterEvent( TQDragEnterEvent *event)
454 void KColorCells::dropEvent( TQDropEvent *event)
458 int cell = posToCell(event->pos(),
true);
463 void KColorCells::mouseReleaseEvent( TQMouseEvent *e )
465 int cell = posToCell(mPos);
466 int currentCell = posToCell(e->pos());
470 if (currentCell != cell)
473 if ( (cell != -1) && (selected != cell) )
475 int prevSel = selected;
477 updateCell( prevSel/numCols(), prevSel%numCols() );
478 updateCell( cell/numCols(), cell%numCols() );
483 emit colorSelected( cell );
486 void KColorCells::mouseDoubleClickEvent( TQMouseEvent * )
488 int cell = posToCell(mPos);
491 emit colorDoubleClicked( cell );
497 KColorPatch::KColorPatch( TQWidget *parent ) : TQFrame( parent )
499 setFrameStyle( TQFrame::Panel | TQFrame::Sunken );
501 setAcceptDrops(
true);
504 KColorPatch::~KColorPatch()
507 TQColor::destroyAllocContext( colContext );
510 void KColorPatch::setColor(
const TQColor &col )
513 TQColor::destroyAllocContext( colContext );
514 colContext = TQColor::enterAllocContext();
515 color.setRgb( col.rgb() );
517 TQColor::leaveAllocContext();
521 painter.begin(
this );
526 void KColorPatch::drawContents( TQPainter *painter )
528 painter->setPen( color );
529 painter->setBrush( TQBrush( color ) );
533 void KColorPatch::mouseMoveEvent( TQMouseEvent *e )
536 if( !(e->state() & Qt::LeftButton))
return;
541 void KColorPatch::dragEnterEvent( TQDragEnterEvent *event)
546 void KColorPatch::dropEvent( TQDropEvent *event)
551 emit colorChanged( c);
555 class KPaletteTable::KPaletteTablePrivate
558 TQMap<TQString,TQColor> m_namedColorMap;
561 KPaletteTable::KPaletteTable( TQWidget *parent,
int minWidth,
int cols)
562 : TQWidget( parent ), cells(0), mPalette(0), mMinWidth(minWidth), mCols(cols)
564 d =
new KPaletteTablePrivate;
566 i18n_namedColors = i18n(
"Named Colors");
569 TQStringList paletteList;
572 for (
int i = 0; colorPaletteName[i].m_fileName; ++i )
574 diskPaletteList.remove( colorPaletteName[i].m_fileName );
575 paletteList.append( i18n(
"palette name", colorPaletteName[i].m_displayName ) );
577 paletteList += diskPaletteList;
578 paletteList.append( i18n_namedColors );
580 TQVBoxLayout *layout =
new TQVBoxLayout(
this );
582 combo =
new TQComboBox(
false,
this );
583 combo->insertStringList( paletteList );
584 layout->addWidget(combo);
586 sv =
new TQScrollView(
this );
587 TQSize cellSize = TQSize( mMinWidth, 120);
588 sv->setHScrollBarMode( TQScrollView::AlwaysOff);
589 sv->setVScrollBarMode( TQScrollView::AlwaysOn);
590 TQSize minSize = TQSize(sv->verticalScrollBar()->width(), 0);
591 minSize += TQSize(sv->frameWidth(), 0);
592 minSize += TQSize(cellSize);
593 sv->setFixedSize(minSize);
594 layout->addWidget(sv);
596 mNamedColorList =
new TDEListBox(
this,
"namedColorList", 0 );
597 mNamedColorList->setFixedSize(minSize);
598 mNamedColorList->hide();
599 layout->addWidget(mNamedColorList);
600 connect( mNamedColorList, TQT_SIGNAL(highlighted(
const TQString & )),
601 this, TQT_SLOT( slotColorTextSelected(
const TQString & )) );
603 setFixedSize( sizeHint());
604 connect( combo, TQT_SIGNAL(activated(
const TQString &)),
605 this, TQT_SLOT(slotSetPalette(
const TQString &)));
608 KPaletteTable::~KPaletteTable()
615 KPaletteTable::palette()
const 617 return combo->currentText();
621 static const char *
const *namedColorFilePath(
void )
627 static const char *
const path[] =
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.