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 #ifndef KDELIBS_KCOLORDIALOG_H
00026 #define KDELIBS_KCOLORDIALOG_H
00027
00028 #ifdef Q_WS_QWS
00029
00030 #include <qcolordialog.h>
00031 #define KColorDialog QColorDialog
00032 #else //UNIX, WIN32
00033 #include <kdialogbase.h>
00034 #include <qframe.h>
00035 #include <qpixmap.h>
00036 #include <qgridview.h>
00037
00038 #include "kselect.h"
00039
00040 class QComboBox;
00041 class QLineEdit;
00042 class KListBox;
00043 class KPalette;
00044 class KColorCells;
00045
00046
00058 class KDEUI_EXPORT KHSSelector : public KXYSelector
00059 {
00060 Q_OBJECT
00061
00062 public:
00066 KHSSelector( QWidget *parent=0, const char *name=0 );
00067
00068 protected:
00073 virtual void drawPalette( QPixmap *pixmap );
00074 virtual void resizeEvent( QResizeEvent * );
00075
00081 virtual void drawContents( QPainter *painter );
00082
00083 private:
00084 void updateContents();
00085 QPixmap pixmap;
00086
00087 protected:
00088 virtual void virtual_hook( int id, void* data );
00089 private:
00090 class KHSSelectorPrivate;
00091 KHSSelectorPrivate *d;
00092 };
00093
00094
00095 class KValueSelectorPrivate;
00102 class KDEUI_EXPORT KValueSelector : public KSelector
00103 {
00104 Q_OBJECT
00105
00106 public:
00110 KValueSelector( QWidget *parent=0, const char *name=0 );
00114 KValueSelector( Orientation o, QWidget *parent = 0, const char *name = 0 );
00115
00116 int hue() const
00117 { return _hue; }
00118 void setHue( int h )
00119 { _hue = h; }
00120 int saturation() const
00121 { return _sat; }
00122 void setSaturation( int s )
00123 { _sat = s; }
00124
00125 void updateContents();
00126 protected:
00131 virtual void drawPalette( QPixmap *pixmap );
00132 virtual void resizeEvent( QResizeEvent * );
00133
00139 virtual void drawContents( QPainter *painter );
00140
00141 private:
00142 int _hue;
00143 int _sat;
00144 QPixmap pixmap;
00145
00146 protected:
00147 virtual void virtual_hook( int id, void* data );
00148 private:
00149 class KValueSelectorPrivate;
00150 KValueSelectorPrivate *d;
00151 };
00152
00153
00164 class KDEUI_EXPORT KColor : public QColor
00165 {
00166 public:
00167 KColor();
00168 KColor( const KColor &col);
00169 KColor( const QColor &col);
00170
00171 KColor& operator=( const KColor& col);
00172
00173 bool operator==( const KColor& col) const;
00174
00175 void setHsv(int _h, int _s, int _v);
00176 void setRgb(int _r, int _g, int _b);
00177
00178 void rgb(int *_r, int *_g, int *_b) const;
00179 void hsv(int *_h, int *_s, int *_v) const;
00180 protected:
00181 int h;
00182 int s;
00183 int v;
00184 int r;
00185 int g;
00186 int b;
00187
00188 private:
00189 class KColorPrivate;
00190 KColorPrivate *d;
00191 };
00192
00198 class KDEUI_EXPORT KPaletteTable : public QWidget
00199 {
00200 Q_OBJECT
00201 public:
00202 KPaletteTable( QWidget *parent, int minWidth=210, int cols = 16);
00203 ~KPaletteTable();
00204 void addToCustomColors( const QColor &);
00205 void addToRecentColors( const QColor &);
00206 QString palette() const;
00207 public slots:
00208 void setPalette(const QString &paletteName);
00209 signals:
00210 void colorSelected( const QColor &, const QString & );
00211 void colorDoubleClicked( const QColor &, const QString & );
00212
00213 protected slots:
00214 void slotColorCellSelected( int );
00215 void slotColorCellDoubleClicked( int );
00216 void slotColorTextSelected( const QString &colorText );
00217 void slotSetPalette( const QString &_paletteName );
00218 void slotShowNamedColorReadError( void );
00219
00220 protected:
00221 void readNamedColor( void );
00222
00223 protected:
00225 QString i18n_customColors;
00226
00227 QString i18n_recentColors;
00228 QString i18n_namedColors;
00229 QComboBox *combo;
00230 KColorCells *cells;
00231 QScrollView *sv;
00232 KListBox *mNamedColorList;
00233 KPalette *mPalette;
00234 int mMinWidth;
00235 int mCols;
00236
00237 private:
00238
00239 virtual void setPalette(const QPalette& p) { QWidget::setPalette(p); }
00240 protected:
00241 virtual void virtual_hook( int id, void* data );
00242 private:
00243 class KPaletteTablePrivate;
00244 KPaletteTablePrivate *d;
00245 };
00246
00247
00253 class KDEUI_EXPORT KColorCells : public QGridView
00254 {
00255 Q_OBJECT
00256 public:
00257 KColorCells( QWidget *parent, int rows, int cols );
00258 ~KColorCells();
00259
00260 void setColor( int colNum, const QColor &col );
00261 QColor color( int indx ) const
00262 { return colors[indx]; }
00263 int numCells() const
00264 { return numRows() * numCols(); }
00265
00266 void setShading(bool _shade) { shade = _shade; }
00267
00268 void setAcceptDrags(bool _acceptDrags) { acceptDrags = _acceptDrags; }
00269
00270 int getSelected() const
00271 { return selected; }
00272
00273 signals:
00274 void colorSelected( int col );
00275 void colorDoubleClicked( int col );
00276
00277 protected:
00278 virtual void paintCell( QPainter *painter, int row, int col );
00279 virtual void resizeEvent( QResizeEvent * );
00280 virtual void mouseReleaseEvent( QMouseEvent * );
00281 virtual void mousePressEvent( QMouseEvent * );
00282 virtual void mouseMoveEvent( QMouseEvent * );
00283 virtual void dragEnterEvent( QDragEnterEvent *);
00284 virtual void dropEvent( QDropEvent *);
00285 virtual void mouseDoubleClickEvent( QMouseEvent * );
00286
00287 int posToCell(const QPoint &pos, bool ignoreBorders=false);
00288
00289 QColor *colors;
00290 bool inMouse;
00291 QPoint mPos;
00292 int selected;
00293 bool shade;
00294 bool acceptDrags;
00295
00296 protected:
00297 virtual void virtual_hook( int id, void* data );
00298 private:
00299 class KColorCellsPrivate;
00300 KColorCellsPrivate *d;
00301 };
00302
00311 class KDEUI_EXPORT KColorPatch : public QFrame
00312 {
00313 Q_OBJECT
00314 public:
00315 KColorPatch( QWidget *parent );
00316 virtual ~KColorPatch();
00317
00318 void setColor( const QColor &col );
00319
00320 signals:
00321 void colorChanged( const QColor&);
00322
00323 protected:
00324 virtual void drawContents( QPainter *painter );
00325 virtual void mouseMoveEvent( QMouseEvent * );
00326 virtual void dragEnterEvent( QDragEnterEvent *);
00327 virtual void dropEvent( QDropEvent *);
00328
00329 private:
00330 QColor color;
00331 uint pixel;
00332 int colContext;
00333
00334 protected:
00335 virtual void virtual_hook( int id, void* data );
00336 private:
00337 class KColorPatchPrivate;
00338 KColorPatchPrivate *d;
00339 };
00340
00377 class KDEUI_EXPORT KColorDialog : public KDialogBase
00378 {
00379 Q_OBJECT
00380
00381 public:
00385 KColorDialog( QWidget *parent = 0L, const char *name = 0L,
00386 bool modal = false );
00390 ~KColorDialog();
00391
00395 QColor color() const;
00396
00405 static int getColor( QColor &theColor, QWidget *parent=0L );
00406
00419 static int getColor( QColor &theColor, const QColor& defaultColor, QWidget *parent=0L );
00420
00424 static QColor grabColor(const QPoint &p);
00425
00432 void setDefaultColor( const QColor& defaultCol );
00433
00437 QColor defaultColor() const;
00438
00439 public slots:
00443 void setColor( const QColor &col );
00444
00445 signals:
00451 void colorSelected( const QColor &col );
00452
00453 private slots:
00454 void slotRGBChanged( void );
00455 void slotHSVChanged( void );
00456 void slotHtmlChanged( void );
00457 void slotHSChanged( int, int );
00458 void slotVChanged( int );
00459 void slotColorSelected( const QColor &col );
00460 void slotColorSelected( const QColor &col, const QString &name );
00461 void slotColorDoubleClicked( const QColor &col, const QString &name );
00462 void slotColorPicker();
00463 void slotAddToCustomColors();
00464 void slotDefaultColorClicked();
00468 void slotWriteSettings();
00469
00470 private:
00474 void readSettings();
00475
00476 void setRgbEdit( const KColor &col );
00477 void setHsvEdit( const KColor &col );
00478 void setHtmlEdit( const KColor &col );
00479 void _setColor( const KColor &col, const QString &name=QString::null );
00480 void showColor( const KColor &color, const QString &name );
00481
00482 protected:
00483 virtual void mouseReleaseEvent( QMouseEvent * );
00484 virtual void keyPressEvent( QKeyEvent * );
00485 virtual bool eventFilter( QObject *obj, QEvent *ev );
00486
00487 protected:
00488 virtual void virtual_hook( int id, void* data );
00489 private:
00490 class KColorDialogPrivate;
00491 KColorDialogPrivate *d;
00492 };
00493
00494 #endif // !Q_WS_QWS
00495 #endif // KDELIBS_KCOLORDIALOG_H
00496