kdeui Library API Documentation

kcolordialog.h

00001 /* This file is part of the KDE libraries
00002     Copyright (C) 1997 Martin Jones (mjones@kde.org)
00003 
00004     This library is free software; you can redistribute it and/or
00005     modify it under the terms of the GNU Library General Public
00006     License as published by the Free Software Foundation; either
00007     version 2 of the License, or (at your option) any later version.
00008 
00009     This library is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012     Library General Public License for more details.
00013 
00014     You should have received a copy of the GNU Library General Public License
00015     along with this library; see the file COPYING.LIB.  If not, write to
00016     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00017     Boston, MA 02111-1307, USA.
00018 */
00019 //----------------------------------------------------------------------
00020 // KDE color selection dialog.
00021 
00022 // layout management added Oct 1997 by Mario Weilguni
00023 // <mweilguni@sime.com>
00024 
00025 #ifndef __KCOLORDIALOG_H__
00026 #define __KCOLORDIALOG_H__
00027 
00028 #ifdef Q_WS_QWS
00029 // FIXME(E): Do we need the KColorDialog extra functionality in Qt Embedded?
00030 #include <qcolordialog.h>
00031 #define KColorDialog QColorDialog
00032 #else
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 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;
00103 class KValueSelector : public KSelector
00104 {
00105   Q_OBJECT
00106 
00107 public:
00111   KValueSelector( QWidget *parent=0, const char *name=0 );
00115   KValueSelector( Orientation o, QWidget *parent = 0, const char *name = 0 );
00116 
00117   int hue() const
00118         { return _hue; }
00119   void setHue( int h )
00120         { _hue = h; }
00121   int saturation() const
00122         { return _sat; }
00123   void setSaturation( int s )
00124         { _sat = s; }
00125 
00126   void updateContents();
00127 protected:
00132   virtual void drawPalette( QPixmap *pixmap );
00133   virtual void resizeEvent( QResizeEvent * );
00134 
00140   virtual void drawContents( QPainter *painter );
00141 
00142 private:
00143   int _hue;
00144   int _sat;
00145   QPixmap pixmap;
00146 
00147 protected:
00148   virtual void virtual_hook( int id, void* data );
00149 private:
00150   class KValueSelectorPrivate;
00151   KValueSelectorPrivate *d;
00152 };
00153 
00154 
00162 class KColor : public QColor
00163 {
00164 public:
00165   KColor();
00166   KColor( const KColor &col);
00167   KColor( const QColor &col);
00168 
00169   KColor& operator=( const KColor& col);
00170 
00171   bool operator==( const KColor& col) const;
00172 
00173   void setHsv(int _h, int _s, int _v);
00174   void setRgb(int _r, int _g, int _b);
00175 
00176   void rgb(int *_r, int *_g, int *_b) const;
00177   void hsv(int *_h, int *_s, int *_v) const;
00178 protected:
00179   int h;
00180   int s;
00181   int v;
00182   int r;
00183   int g;
00184   int b;
00185 
00186 private:
00187   class KColorPrivate;
00188   KColorPrivate *d;
00189 };
00190 
00196 class KPaletteTable : public QWidget
00197 {
00198   Q_OBJECT
00199 public:
00200   KPaletteTable( QWidget *parent, int minWidth=210, int cols = 16);
00201   ~KPaletteTable();
00202   void addToCustomColors( const QColor &);
00203   void addToRecentColors( const QColor &);
00204   QString palette() const;
00205 public slots:
00206   void setPalette(const QString &paletteName);
00207 signals:
00208   void colorSelected( const QColor &, const QString & );
00209   void colorDoubleClicked( const QColor &, const QString & );
00210 
00211 protected slots:
00212   void slotColorCellSelected( int );
00213   void slotColorCellDoubleClicked( int );
00214   void slotColorTextSelected( const QString &colorText );
00215   void slotSetPalette( const QString &_paletteName );
00216   void slotShowNamedColorReadError( void );
00217 
00218 protected:
00219   void readNamedColor( void );
00220 
00221 protected:
00222   QString i18n_customColors;
00223   QString i18n_recentColors;
00224   QString i18n_namedColors;
00225   QComboBox *combo;
00226   KColorCells *cells;
00227   QScrollView *sv;
00228   KListBox *mNamedColorList;
00229   KPalette *mPalette;
00230   int mMinWidth;
00231   int mCols;
00232 
00233 private:
00234 
00235   virtual void setPalette(const QPalette& p) { QWidget::setPalette(p); }
00236 protected:
00237   virtual void virtual_hook( int id, void* data );
00238 private:
00239   class KPaletteTablePrivate;
00240   KPaletteTablePrivate *d;
00241 };
00242 
00243 
00249 class KColorCells : public QGridView
00250 {
00251   Q_OBJECT
00252 public:
00253   KColorCells( QWidget *parent, int rows, int cols );
00254   ~KColorCells();
00255 
00256   void setColor( int colNum, const QColor &col );
00257   QColor color( int indx ) const
00258   { return colors[indx]; }
00259   int numCells() const
00260   { return numRows() * numCols(); }
00261 
00262   void setShading(bool _shade) { shade = _shade; }
00263 
00264   void setAcceptDrags(bool _acceptDrags) { acceptDrags = _acceptDrags; }
00265 
00266   int getSelected() const
00267   { return selected; }
00268 
00269   signals:
00270   void colorSelected( int col );
00271   void colorDoubleClicked( int col );
00272 
00273 protected:
00274   virtual void paintCell( QPainter *painter, int row, int col );
00275   virtual void resizeEvent( QResizeEvent * );
00276   virtual void mouseReleaseEvent( QMouseEvent * );
00277   virtual void mousePressEvent( QMouseEvent * );
00278   virtual void mouseMoveEvent( QMouseEvent * );
00279   virtual void dragEnterEvent( QDragEnterEvent *);
00280   virtual void dropEvent( QDropEvent *);
00281   virtual void mouseDoubleClickEvent( QMouseEvent * );
00282 
00283   int posToCell(const QPoint &pos, bool ignoreBorders=false);
00284 
00285   QColor *colors;
00286   bool inMouse;
00287   QPoint mPos;
00288   int   selected;
00289   bool shade;
00290   bool acceptDrags;
00291 
00292 protected:
00293   virtual void virtual_hook( int id, void* data );
00294 private:
00295   class KColorCellsPrivate;
00296   KColorCellsPrivate *d;
00297 };
00298 
00306 class KColorPatch : public QFrame
00307 {
00308   Q_OBJECT
00309 public:
00310   KColorPatch( QWidget *parent );
00311   virtual ~KColorPatch();
00312 
00313   void setColor( const QColor &col );
00314 
00315 signals:
00316   void colorChanged( const QColor&);
00317 
00318 protected:
00319   virtual void drawContents( QPainter *painter );
00320   virtual void mouseMoveEvent( QMouseEvent * );
00321   virtual void dragEnterEvent( QDragEnterEvent *);
00322   virtual void dropEvent( QDropEvent *);
00323 
00324 private:
00325   QColor color;
00326   uint pixel;
00327   int colContext;
00328 
00329 protected:
00330   virtual void virtual_hook( int id, void* data );
00331 private:
00332   class KColorPatchPrivate;
00333   KColorPatchPrivate *d;
00334 };
00335 
00373 class KColorDialog : public KDialogBase
00374 {
00375   Q_OBJECT
00376 
00377   public:
00381     KColorDialog( QWidget *parent = 0L, const char *name = 0L,
00382           bool modal = false );
00386     ~KColorDialog();
00387 
00391     QColor color() const;
00392 
00401     static int getColor( QColor &theColor, QWidget *parent=0L );
00402 
00415     static int getColor( QColor &theColor, const QColor& defaultColor, QWidget *parent=0L );
00416 
00420     static QColor grabColor(const QPoint &p);
00421 
00428     void setDefaultColor( const QColor& defaultCol );
00429 
00433     QColor defaultColor() const;
00434 
00435   public slots:
00439     void setColor( const QColor &col );
00440 
00441   signals:
00447     void colorSelected( const QColor &col );
00448 
00449   private slots:
00450     void slotRGBChanged( void );
00451     void slotHSVChanged( void );
00452     void slotHtmlChanged( void );
00453     void slotHSChanged( int, int );
00454     void slotVChanged( int );
00455     void slotColorSelected( const QColor &col );
00456     void slotColorSelected( const QColor &col, const QString &name );
00457     void slotColorDoubleClicked( const QColor &col, const QString &name );
00458     void slotColorPicker();
00459     void slotAddToCustomColors();
00460     void slotDefaultColorClicked();
00464     void slotWriteSettings();
00465 
00466   private:
00470     void readSettings();
00471 
00472     void setRgbEdit( const KColor &col );
00473     void setHsvEdit( const KColor &col );
00474     void setHtmlEdit( const KColor &col );
00475     void _setColor( const KColor &col, const QString &name=QString::null );
00476     void showColor( const KColor &color, const QString &name );
00477 
00478   protected:
00479     virtual void mouseReleaseEvent( QMouseEvent * );
00480     virtual void keyPressEvent( QKeyEvent * );
00481     virtual bool eventFilter( QObject *obj, QEvent *ev );
00482 
00483   protected:
00484     virtual void virtual_hook( int id, void* data );
00485   private:
00486     class KColorDialogPrivate;
00487     KColorDialogPrivate *d;
00488 };
00489 
00490 #endif      // Q_WS_QWS
00491 #endif      // __KCOLORDIALOG_H__
00492 
KDE Logo
This file is part of the documentation for kdeui Library Version 3.2.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Feb 4 12:34:15 2004 by doxygen 1.2.18 written by Dimitri van Heesch, © 1997-2003