kdeui Library API Documentation

kselect.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 // Selector widgets for KDE Color Selector, but probably useful for other
00021 // stuff also.
00022 
00023 #ifndef __KSELECT_H__
00024 #define __KSELECT_H__
00025 
00026 #include <qwidget.h>
00027 #include <qrangecontrol.h>
00028 #include <qpixmap.h>
00029 
00041 class KXYSelector : public QWidget
00042 {
00043   Q_OBJECT
00044 
00045 public:
00050   KXYSelector( QWidget *parent=0, const char *name=0 );
00054   ~KXYSelector();
00055 
00060   void setValues( int xPos, int yPos );
00064   void setRange( int minX, int minY, int maxX, int maxY );
00065 
00069   int xValue() const {  return xPos; }
00073   int yValue() const {  return yPos; }
00074 
00078   QRect contentsRect() const;
00079 
00080 signals:
00085   void valueChanged( int x, int y );
00086 
00087 protected:
00094   virtual void drawContents( QPainter * );
00099   virtual void drawCursor( QPainter *p, int xp, int yp );
00100 
00101   virtual void paintEvent( QPaintEvent *e );
00102   virtual void mousePressEvent( QMouseEvent *e );
00103   virtual void mouseMoveEvent( QMouseEvent *e );
00104   virtual void wheelEvent( QWheelEvent * );
00105 
00109   void valuesFromPosition( int x, int y, int& xVal, int& yVal ) const;
00110 
00111 private:
00112   void setPosition( int xp, int yp );
00113   int px;
00114   int py;
00115   int xPos;
00116   int yPos;
00117   int minX;
00118   int maxX;
00119   int minY;
00120   int maxY;
00121   QPixmap store;
00122 
00123 protected:
00124   virtual void virtual_hook( int id, void* data );
00125 private:
00126   class KXYSelectorPrivate;
00127   KXYSelectorPrivate *d;
00128 };
00129 
00130 
00140 class KSelector : public QWidget, public QRangeControl
00141 {
00142   Q_OBJECT
00143   Q_PROPERTY( int value READ value WRITE setValue )
00144   Q_PROPERTY( int minValue READ minValue WRITE setMinValue )
00145   Q_PROPERTY( int maxValue READ maxValue WRITE setMaxValue )
00146 public:
00147 
00151   KSelector( QWidget *parent=0, const char *name=0 );
00156   KSelector( Orientation o, QWidget *parent = 0L, const char *name = 0L );
00157   /*
00158    * Destructs the widget.
00159    */
00160   ~KSelector();
00161 
00165   Orientation orientation() const
00166   { return _orientation; }
00167 
00171   QRect contentsRect() const;
00172 
00177   void setIndent( bool i )
00178   { _indent = i; }
00182   bool indent() const
00183   { return _indent; }
00184 
00188   void setValue(int value)
00189   { QRangeControl::setValue(value); }
00190 
00194   int value() const
00195   { return QRangeControl::value(); }
00196 
00200   void setMinValue(int value)
00201   { QRangeControl::setMinValue(value); }
00202 
00206   int minValue() const
00207   { return QRangeControl::minValue(); }
00208 
00212   void setMaxValue(int value)
00213   { QRangeControl::setMaxValue(value); }
00214 
00218   int maxValue() const
00219   { return QRangeControl::maxValue(); }
00220 
00221 signals:
00226   void valueChanged( int value );
00227 
00228 protected:
00235   virtual void drawContents( QPainter * );
00243   virtual void drawArrow( QPainter *painter, bool show, const QPoint &pos );
00244 
00245   virtual void valueChange();
00246   virtual void paintEvent( QPaintEvent * );
00247   virtual void mousePressEvent( QMouseEvent *e );
00248   virtual void mouseMoveEvent( QMouseEvent *e );
00249   virtual void wheelEvent( QWheelEvent * );
00250 
00251 private:
00252   QPoint calcArrowPos( int val );
00253   void moveArrow( const QPoint &pos );
00254 
00255   Orientation _orientation;
00256   bool _indent;
00257 
00258 protected:
00259   virtual void virtual_hook( int id, void* data );
00260 private:
00261   class KSelectorPrivate;
00262   KSelectorPrivate *d;
00263 };
00264 
00265 
00274 class KGradientSelector : public KSelector
00275 {
00276   Q_OBJECT
00277 
00278   Q_PROPERTY( QColor firstColor READ firstColor WRITE setFirstColor )
00279   Q_PROPERTY( QColor secondColor READ secondColor WRITE setSecondColor )
00280   Q_PROPERTY( QString firstText READ firstText WRITE setFirstText )
00281   Q_PROPERTY( QString secondText READ secondText WRITE setSecondText )
00282 
00283 public:
00288   KGradientSelector( QWidget *parent=0, const char *name=0 );
00293   KGradientSelector( Orientation o, QWidget *parent=0, const char *name=0 );
00297   ~KGradientSelector();
00301   void setColors( const QColor &col1, const QColor &col2 )
00302   { color1 = col1; color2 = col2; update();}
00303   void setText( const QString &t1, const QString &t2 )
00304   { text1 = t1; text2 = t2; update(); }
00305 
00309   void setFirstColor( const QColor &col )
00310   { color1 = col; update(); }
00311   void setSecondColor( const QColor &col )
00312   { color2 = col; update(); }
00313 
00317   void setFirstText( const QString &t )
00318   { text1 = t; update(); }
00319   void setSecondText( const QString &t )
00320   { text2 = t; update(); }
00321 
00322   const QColor firstColor() const
00323   { return color1; }
00324   const QColor secondColor() const
00325   { return color2; }
00326 
00327   const QString firstText() const
00328   { return text1; }
00329   const QString secondText() const
00330   { return text2; }
00331 
00332 protected:
00333 
00334   virtual void drawContents( QPainter * );
00335   virtual QSize minimumSize() const
00336   { return sizeHint(); }
00337 
00338 private:
00339   void init();
00340   QColor color1;
00341   QColor color2;
00342   QString text1;
00343   QString text2;
00344 
00345 protected:
00346   virtual void virtual_hook( int id, void* data );
00347 private:
00348   class KGradientSelectorPrivate;
00349   KGradientSelectorPrivate *d;
00350 };
00351 
00352 
00353 #endif      // __KSELECT_H__
00354 
KDE Logo
This file is part of the documentation for kdeui Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sun May 16 22:02:08 2004 by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2003