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., 51 Franklin Street, Fifth Floor, 00017 Boston, MA 02110-1301, 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 KDELIBS_KCOLORDIALOG_H 00026 #define KDELIBS_KCOLORDIALOG_H 00027 00028 #ifdef Q_WS_QWS 00029 // FIXME(E): Do we need the KColorDialog extra functionality in Qt Embedded? 00030 #include <tqcolordialog.h> 00031 #define KColorDialog QColorDialog 00032 #else //UNIX, WIN32 00033 #include <kdialogbase.h> 00034 #include <tqframe.h> 00035 #include <tqpixmap.h> 00036 #include <tqgridview.h> 00037 00038 #include "tdeselect.h" 00039 00040 class TQComboBox; 00041 class TQLineEdit; 00042 class TDEListBox; 00043 class KPalette; 00044 class KColorCells; 00045 00046 00058 class TDEUI_EXPORT KHSSelector : public KXYSelector 00059 { 00060 Q_OBJECT 00061 00062 public: 00066 KHSSelector( TQWidget *parent=0, const char *name=0 ); 00067 00068 protected: 00073 virtual void drawPalette( TQPixmap *pixmap ); 00074 virtual void resizeEvent( TQResizeEvent * ); 00075 00081 virtual void drawContents( TQPainter *painter ); 00082 00083 private: 00084 void updateContents(); 00085 TQPixmap 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 TDEUI_EXPORT KValueSelector : public TDESelector 00103 { 00104 Q_OBJECT 00105 00106 public: 00110 KValueSelector( TQWidget *parent=0, const char *name=0 ); 00114 KValueSelector( Orientation o, TQWidget *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( TQPixmap *pixmap ); 00132 virtual void resizeEvent( TQResizeEvent * ); 00133 00139 virtual void drawContents( TQPainter *painter ); 00140 00141 private: 00142 int _hue; 00143 int _sat; 00144 TQPixmap 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 TDEUI_EXPORT KColor : public TQColor 00165 { 00166 public: 00167 KColor(); 00168 KColor( const KColor &col); 00169 KColor( const TQColor &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 TDEUI_EXPORT KPaletteTable : public TQWidget 00199 { 00200 Q_OBJECT 00201 public: 00202 KPaletteTable( TQWidget *parent, int minWidth=210, int cols = 16); 00203 ~KPaletteTable(); 00204 void addToCustomColors( const TQColor &); 00205 void addToRecentColors( const TQColor &); 00206 TQString palette() const; 00207 public slots: 00208 void setPalette(const TQString &paletteName); 00209 signals: 00210 void colorSelected( const TQColor &, const TQString & ); 00211 void colorDoubleClicked( const TQColor &, const TQString & ); 00212 00213 protected slots: 00214 void slotColorCellSelected( int ); 00215 void slotColorCellDoubleClicked( int ); 00216 void slotColorTextSelected( const TQString &colorText ); 00217 void slotSetPalette( const TQString &_paletteName ); 00218 void slotShowNamedColorReadError( void ); 00219 00220 protected: 00221 void readNamedColor( void ); 00222 00223 protected: 00225 TQString i18n_customColors; 00226 00227 TQString i18n_recentColors; 00228 TQString i18n_namedColors; 00229 TQComboBox *combo; 00230 KColorCells *cells; 00231 TQScrollView *sv; 00232 TDEListBox *mNamedColorList; 00233 KPalette *mPalette; 00234 int mMinWidth; 00235 int mCols; 00236 00237 private: 00238 00239 virtual void setPalette(const TQPalette& p) { TQWidget::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 TDEUI_EXPORT KColorCells : public TQGridView 00254 { 00255 Q_OBJECT 00256 public: 00257 KColorCells( TQWidget *parent, int rows, int cols ); 00258 ~KColorCells(); 00259 00260 void setColor( int colNum, const TQColor &col ); 00261 TQColor 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( TQPainter *painter, int row, int col ); 00279 virtual void resizeEvent( TQResizeEvent * ); 00280 virtual void mouseReleaseEvent( TQMouseEvent * ); 00281 virtual void mousePressEvent( TQMouseEvent * ); 00282 virtual void mouseMoveEvent( TQMouseEvent * ); 00283 virtual void dragEnterEvent( TQDragEnterEvent *); 00284 virtual void dropEvent( TQDropEvent *); 00285 virtual void mouseDoubleClickEvent( TQMouseEvent * ); 00286 00287 int posToCell(const TQPoint &pos, bool ignoreBorders=false); 00288 00289 TQColor *colors; 00290 bool inMouse; 00291 TQPoint 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 TDEUI_EXPORT KColorPatch : public TQFrame 00312 { 00313 Q_OBJECT 00314 public: 00315 KColorPatch( TQWidget *parent ); 00316 virtual ~KColorPatch(); 00317 00318 void setColor( const TQColor &col ); 00319 00320 signals: 00321 void colorChanged( const TQColor&); 00322 00323 protected: 00324 virtual void drawContents( TQPainter *painter ); 00325 virtual void mouseMoveEvent( TQMouseEvent * ); 00326 virtual void dragEnterEvent( TQDragEnterEvent *); 00327 virtual void dropEvent( TQDropEvent *); 00328 00329 private: 00330 TQColor 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 TDEUI_EXPORT KColorDialog : public KDialogBase 00378 { 00379 Q_OBJECT 00380 00381 public: 00385 KColorDialog( TQWidget *parent = 0L, const char *name = 0L, 00386 bool modal = false ); 00390 ~KColorDialog(); 00391 00395 TQColor color() const; 00396 00405 static int getColor( TQColor &theColor, TQWidget *parent=0L ); 00406 00419 static int getColor( TQColor &theColor, const TQColor& defaultColor, TQWidget *parent=0L ); 00420 00424 static TQColor grabColor(const TQPoint &p); 00425 00432 void setDefaultColor( const TQColor& defaultCol ); 00433 00437 TQColor defaultColor() const; 00438 00439 public slots: 00443 void setColor( const TQColor &col ); 00444 00445 signals: 00451 void colorSelected( const TQColor &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 TQColor &col ); 00460 void slotColorSelected( const TQColor &col, const TQString &name ); 00461 void slotColorDoubleClicked( const TQColor &col, const TQString &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 TQString &name=TQString::null ); 00480 void showColor( const KColor &color, const TQString &name ); 00481 00482 protected: 00483 virtual void mouseReleaseEvent( TQMouseEvent * ); 00484 virtual void keyPressEvent( TQKeyEvent * ); 00485 virtual bool eventFilter( TQObject *obj, TQEvent *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