35 #include <tqdrawutil.h>
41 #include <tqlineedit.h>
42 #include <tqvalidator.h>
43 #include <tqpainter.h>
44 #include <tqpushbutton.h>
47 #include <tdeapplication.h>
48 #include <tdeconfig.h>
49 #include <tdeglobal.h>
50 #include <tdeglobalsettings.h>
51 #include <kiconloader.h>
52 #include <tdelistbox.h>
54 #include <tdemessagebox.h>
55 #include <kseparator.h>
57 #include <kimageeffect.h>
61 #include "kcolorcombo.h"
69 #define STANDARD_PAL_SIZE 17
71 static TQColor *standardPalette = 0;
73 static void createStandardPalette()
75 if ( standardPalette )
78 standardPalette =
new TQColor [STANDARD_PAL_SIZE];
82 standardPalette[i++] = TQt::red;
83 standardPalette[i++] = TQt::green;
84 standardPalette[i++] = TQt::blue;
85 standardPalette[i++] = TQt::cyan;
86 standardPalette[i++] = TQt::magenta;
87 standardPalette[i++] = TQt::yellow;
88 standardPalette[i++] = TQt::darkRed;
89 standardPalette[i++] = TQt::darkGreen;
90 standardPalette[i++] = TQt::darkBlue;
91 standardPalette[i++] = TQt::darkCyan;
92 standardPalette[i++] = TQt::darkMagenta;
93 standardPalette[i++] = TQt::darkYellow;
94 standardPalette[i++] = TQt::white;
95 standardPalette[i++] = TQt::lightGray;
96 standardPalette[i++] = TQt::gray;
97 standardPalette[i++] = TQt::darkGray;
98 standardPalette[i++] = TQt::black;
102 class KColorCombo::KColorComboPrivate
106 KColorComboPrivate(){}
107 ~KColorComboPrivate(){}
112 : TQComboBox( parent, name )
114 d=
new KColorComboPrivate();
115 d->showEmptyList=
false;
117 customColor.setRgb( 255, 255, 255 );
118 internalcolor.setRgb( 255, 255, 255 );
120 createStandardPalette();
124 connect(
this, TQ_SIGNAL(
activated(
int) ), TQ_SLOT( slotActivated(
int) ) );
125 connect(
this, TQ_SIGNAL(
highlighted(
int) ), TQ_SLOT( slotHighlighted(
int) ) );
129 KColorCombo::~KColorCombo()
139 d->showEmptyList=
false;
148 return internalcolor;
151 void KColorCombo::resizeEvent( TQResizeEvent *re )
153 TQComboBox::resizeEvent( re );
163 d->showEmptyList=
true;
167 void KColorCombo::slotActivated(
int index )
175 TQRect rect( 0, 0, width(), TQFontMetrics(painter.font()).height()+4);
176 TQPixmap pixmap( rect.width(), rect.height() );
178 if ( tqGray( customColor.rgb() ) < 128 )
179 pen.setColor( white );
181 pen.setColor( black );
183 painter.begin( &pixmap );
184 TQBrush brush( customColor );
185 painter.fillRect( rect, brush );
186 painter.setPen( pen );
187 painter.drawText( 2, TQFontMetrics(painter.font()).ascent()+2, i18n(
"Custom...") );
190 changeItem( pixmap, 0 );
194 internalcolor = customColor;
197 internalcolor = standardPalette[ index - 1 ];
202 void KColorCombo::slotHighlighted(
int index )
205 internalcolor = customColor;
207 internalcolor = standardPalette[ index - 1 ];
212 void KColorCombo::addColors()
216 TQRect rect( 0, 0, width(), TQFontMetrics(painter.font()).height()+4 );
217 TQPixmap pixmap( rect.width(), rect.height() );
221 if (d->showEmptyList)
return;
223 createStandardPalette();
225 for ( i = 0; i < STANDARD_PAL_SIZE; i++ )
226 if ( standardPalette[i] == internalcolor )
break;
228 if ( i == STANDARD_PAL_SIZE )
229 customColor = internalcolor;
231 if ( tqGray( customColor.rgb() ) < 128 )
232 pen.setColor( white );
234 pen.setColor( black );
236 painter.begin( &pixmap );
237 TQBrush brush( customColor );
238 painter.fillRect( rect, brush );
239 painter.setPen( pen );
240 painter.drawText( 2, TQFontMetrics(painter.font()).ascent()+2, i18n(
"Custom...") );
243 insertItem( pixmap );
246 for ( i = 0; i < STANDARD_PAL_SIZE; i++ )
248 painter.begin( &pixmap );
249 TQBrush brush( standardPalette[i] );
250 painter.fillRect( rect, brush );
253 insertItem( pixmap );
256 if ( standardPalette[i] == internalcolor )
257 setCurrentItem( i + 1 );
261 void KColorCombo::virtual_hook(
int,
void* )
264 #include "kcolorcombo.moc"
void showEmptyList()
Clear the color list and don't show it, till the next setColor() call.
void setColor(const TQColor &col)
Selects the color col.
void highlighted(const TQColor &col)
Emitted when a new item has been highlighted.
KColorCombo(TQWidget *parent, const char *name=0L)
Constructs a color combo box.
TQColor color() const
Returns the currently selected color.
void activated(const TQColor &col)
Emitted when a new color box has been selected.
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.
TDEAction * clear(const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name)
Clear the content of the focus widget.