1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
|
/* This file is part of the KDE libraries
Copyright (C) 1997 Martin Jones (mjones@kde.org)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
//----------------------------------------------------------------------
// KDE color selection dialog.
// layout management added Oct 1997 by Mario Weilguni
// <mweilguni@sime.com>
#ifndef KDELIBS_KCOLORDIALOG_H
#define KDELIBS_KCOLORDIALOG_H
#ifdef Q_WS_QWS
// FIXME(E): Do we need the KColorDialog extra functionality in Qt Embedded?
#include <tqcolordialog.h>
#define KColorDialog QColorDialog
#else //UNIX, WIN32
#include <kdialogbase.h>
#include <tqframe.h>
#include <tqpixmap.h>
#include <tqgridview.h>
#include "tdeselect.h"
class TQComboBox;
class TQLineEdit;
class TDEListBox;
class KPalette;
class KColorCells;
/**
* Widget for Hue/Saturation colour selection.
*
* The actual values can be fetched using the inherited xValue and yValue
* methods.
*
* \image html khsselector.png "KDE Hue/Saturation Selection Widget"
*
* @see KXYSelector, KValueSelector, KColorDialog
* @author Martin Jones (mjones@kde.org)
*/
class TDEUI_EXPORT KHSSelector : public KXYSelector
{
TQ_OBJECT
public:
/**
* Constructs a hue/saturation selection widget.
*/
KHSSelector( TQWidget *parent=0, const char *name=0 );
protected:
/**
* Draws the contents of the widget on a pixmap,
* which is used for buffering.
*/
virtual void drawPalette( TQPixmap *pixmap );
virtual void resizeEvent( TQResizeEvent * );
/**
* Reimplemented from KXYSelector. This drawing is
* buffered in a pixmap here. As real drawing
* routine, drawPalette() is used.
*/
virtual void drawContents( TQPainter *painter );
private:
void updateContents();
TQPixmap pixmap;
protected:
virtual void virtual_hook( int id, void* data );
private:
class KHSSelectorPrivate;
KHSSelectorPrivate *d;
};
class KValueSelectorPrivate;
/**
* Widget for color value selection.
*
* @see KHSSelector, KColorDialog
* @author Martin Jones (mjones@kde.org)
*/
class TDEUI_EXPORT KValueSelector : public TDESelector
{
TQ_OBJECT
public:
/**
* Constructs a widget for color selection.
*/
KValueSelector( TQWidget *parent=0, const char *name=0 );
/**
* Constructs a widget for color selection with a given orientation
*/
KValueSelector( Orientation o, TQWidget *parent = 0, const char *name = 0 );
int hue() const
{ return _hue; }
void setHue( int h )
{ _hue = h; }
int saturation() const
{ return _sat; }
void setSaturation( int s )
{ _sat = s; }
void updateContents();
protected:
/**
* Draws the contents of the widget on a pixmap,
* which is used for buffering.
*/
virtual void drawPalette( TQPixmap *pixmap );
virtual void resizeEvent( TQResizeEvent * );
/**
* Reimplemented from TDESelector. The drawing is
* buffered in a pixmap here. As real drawing
* routine, drawPalette() is used.
*/
virtual void drawContents( TQPainter *painter );
private:
int _hue;
int _sat;
TQPixmap pixmap;
protected:
virtual void virtual_hook( int id, void* data );
private:
class KValueSelectorPrivate;
KValueSelectorPrivate *d;
};
/**
* A color class that preserves both RGB and HSV values.
*
* This is
* unlike TQColor which only preserves RGB values and recalculates HSV
* values. The TQColor behavior leads to an accumulation of rounding
* errors when working in the HSV color space.
*
* @author Waldo Bastian <bastian@kde.org>
**/
class TDEUI_EXPORT KColor : public TQColor
{
public:
KColor();
KColor( const KColor &col);
KColor( const TQColor &col);
KColor& operator=( const KColor& col);
bool operator==( const KColor& col) const;
void setHsv(int _h, int _s, int _v);
void setRgb(int _r, int _g, int _b);
void rgb(int *_r, int *_g, int *_b) const;
void hsv(int *_h, int *_s, int *_v) const;
protected:
int h;
int s;
int v;
int r;
int g;
int b;
private:
class KColorPrivate;
KColorPrivate *d;
};
/**
* A color palette in table form.
*
* @author Waldo Bastian <bastian@kde.org>
**/
class TDEUI_EXPORT KPaletteTable : public TQWidget
{
TQ_OBJECT
public:
KPaletteTable( TQWidget *parent, int minWidth=210, int cols = 16);
~KPaletteTable();
void addToCustomColors( const TQColor &);
void addToRecentColors( const TQColor &);
TQString palette() const;
public slots:
void setPalette(const TQString &paletteName);
signals:
void colorSelected( const TQColor &, const TQString & );
void colorDoubleClicked( const TQColor &, const TQString & );
protected slots:
void slotColorCellSelected( int );
void slotColorCellDoubleClicked( int );
void slotColorTextSelected( const TQString &colorText );
void slotSetPalette( const TQString &_paletteName );
void slotShowNamedColorReadError( void );
protected:
void readNamedColor( void );
protected:
/// \deprecated
TQString i18n_customColors; /// ### KDE4: remove
/// \deprecated
TQString i18n_recentColors; /// ### KDE4: remove
TQString i18n_namedColors;
TQComboBox *combo;
KColorCells *cells;
TQScrollView *sv;
TDEListBox *mNamedColorList;
KPalette *mPalette;
int mMinWidth;
int mCols;
private:
virtual void setPalette(const TQPalette& p) { TQWidget::setPalette(p); }
protected:
virtual void virtual_hook( int id, void* data );
private:
class KPaletteTablePrivate;
KPaletteTablePrivate *d;
};
/**
* A table of editable color cells.
*
* @author Martin Jones <mjones@kde.org>
*/
class TDEUI_EXPORT KColorCells : public TQGridView
{
TQ_OBJECT
public:
KColorCells( TQWidget *parent, int rows, int cols );
~KColorCells();
void setColor( int colNum, const TQColor &col );
TQColor color( int indx ) const
{ return colors[indx]; }
int numCells() const
{ return numRows() * numCols(); }
void setShading(bool _shade) { shade = _shade; }
void setAcceptDrags(bool _acceptDrags) { acceptDrags = _acceptDrags; }
int getSelected() const
{ return selected; }
signals:
void colorSelected( int col );
void colorDoubleClicked( int col );
protected:
virtual void paintCell( TQPainter *painter, int row, int col );
virtual void resizeEvent( TQResizeEvent * );
virtual void mouseReleaseEvent( TQMouseEvent * );
virtual void mousePressEvent( TQMouseEvent * );
virtual void mouseMoveEvent( TQMouseEvent * );
virtual void dragEnterEvent( TQDragEnterEvent *);
virtual void dropEvent( TQDropEvent *);
virtual void mouseDoubleClickEvent( TQMouseEvent * );
int posToCell(const TQPoint &pos, bool ignoreBorders=false);
TQColor *colors;
bool inMouse;
TQPoint mPos;
int selected;
bool shade;
bool acceptDrags;
protected:
virtual void virtual_hook( int id, void* data );
private:
class KColorCellsPrivate;
KColorCellsPrivate *d;
};
/**
* @short A color displayer.
*
* The KColorPatch widget is a (usually small) widget showing
* a selected color e. g. in the KColorDialog. It
* automatically handles drag and drop from and on the widget.
*
*/
class TDEUI_EXPORT KColorPatch : public TQFrame
{
TQ_OBJECT
public:
KColorPatch( TQWidget *parent );
virtual ~KColorPatch();
void setColor( const TQColor &col );
signals:
void colorChanged( const TQColor&);
protected:
virtual void drawContents( TQPainter *painter );
virtual void mouseMoveEvent( TQMouseEvent * );
virtual void dragEnterEvent( TQDragEnterEvent *);
virtual void dropEvent( TQDropEvent *);
private:
TQColor color;
uint pixel;
int colContext;
protected:
virtual void virtual_hook( int id, void* data );
private:
class KColorPatchPrivate;
KColorPatchPrivate *d;
};
/**
* @short A color selection dialog.
*
* <b>Features:</b>\n
*
* @li Color selection from a wide range of palettes.
* @li Color selection from a palette of H vs S and V selectors.
* @li Direct input of HSV or RGB values.
* @li Saving of custom colors
*
* In most cases, you will want to use the static method KColorDialog::getColor().
* This pops up the dialog (with an initial selection provided by you), lets the
* user choose a color, and returns.
*
* Example:
*
* \code
* TQColor myColor;
* int result = KColorDialog::getColor( myColor );
* if ( result == KColorDialog::Accepted )
* ...
* \endcode
*
* @image html kcolordialog.png "KDE Color Dialog"
*
* The color dialog is really a collection of several widgets which can
* you can also use separately: the quadratic plane in the top left of
* the dialog is a KXYSelector. Right next to it is a KHSSelector
* for choosing hue/saturation.
*
* On the right side of the dialog you see a KPaletteTable showing
* up to 40 colors with a combo box which offers several predefined
* palettes or a palette configured by the user. The small field showing
* the currently selected color is a KColorPatch.
*
**/
class TDEUI_EXPORT KColorDialog : public KDialogBase
{
TQ_OBJECT
public:
/**
* Constructs a color selection dialog.
*/
KColorDialog( TQWidget *parent = 0L, const char *name = 0L,
bool modal = false );
/**
* Destroys the color selection dialog.
*/
~KColorDialog();
/**
* Returns the currently selected color.
**/
TQColor color() const;
/**
* Creates a modal color dialog, let the user choose a
* color, and returns when the dialog is closed.
*
* The selected color is returned in the argument @p theColor.
*
* @returns TQDialog::result().
*/
static int getColor( TQColor &theColor, TQWidget *parent=0L );
/**
* Creates a modal color dialog, lets the user choose a
* color, and returns when the dialog is closed.
*
* The selected color is returned in the argument @p theColor.
*
* This version takes a @p defaultColor argument, which sets the color
* selected by the "default color" checkbox. When this checkbox is checked,
* the invalid color (TQColor()) is returned into @p theColor.
*
* @returns TQDialog::result().
*/
static int getColor( TQColor &theColor, const TQColor& defaultColor, TQWidget *parent=0L );
/**
* Gets the color from the pixel at point p on the screen.
*/
static TQColor grabColor(const TQPoint &p);
/**
* Call this to make the dialog show a "Default Color" checkbox.
* If this checkbox is selected, the dialog will return an "invalid" color (TQColor()).
* This can be used to mean "the default text color", for instance,
* the one with the KDE text color on screen, but black when printing.
*/
void setDefaultColor( const TQColor& defaultCol );
/**
* @return the value passed to setDefaultColor
*/
TQColor defaultColor() const;
public slots:
/**
* Preselects a color.
*/
void setColor( const TQColor &col );
signals:
/**
* Emitted when a color is selected.
* Connect to this to monitor the color as it as selected if you are
* not running modal.
*/
void colorSelected( const TQColor &col );
private slots:
void slotRGBChanged( void );
void slotHSVChanged( void );
void slotHtmlChanged( void );
void slotHSChanged( int, int );
void slotVChanged( int );
void slotColorSelected( const TQColor &col );
void slotColorSelected( const TQColor &col, const TQString &name );
void slotColorDoubleClicked( const TQColor &col, const TQString &name );
void slotColorPicker();
void slotAddToCustomColors();
void slotDefaultColorClicked();
/**
* Write the settings of the dialog to config file.
**/
void slotWriteSettings();
private:
/**
* Read the settings for the dialog from config file.
**/
void readSettings();
void setRgbEdit( const KColor &col );
void setHsvEdit( const KColor &col );
void setHtmlEdit( const KColor &col );
void _setColor( const KColor &col, const TQString &name=TQString::null );
void showColor( const KColor &color, const TQString &name );
protected:
virtual void mouseReleaseEvent( TQMouseEvent * );
virtual void keyPressEvent( TQKeyEvent * );
virtual bool eventFilter( TQObject *obj, TQEvent *ev );
protected:
virtual void virtual_hook( int id, void* data );
private:
class KColorDialogPrivate;
KColorDialogPrivate *d;
};
#endif // !Q_WS_QWS
#endif // KDELIBS_KCOLORDIALOG_H
|