home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / kselect.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-10-10  |  9.4 KB  |  374 lines

  1. /* This file is part of the KDE libraries
  2.     Copyright (C) 1997 Martin Jones (mjones@kde.org)
  3.  
  4.     This library is free software; you can redistribute it and/or
  5.     modify it under the terms of the GNU Library General Public
  6.     License as published by the Free Software Foundation; either
  7.     version 2 of the License, or (at your option) any later version.
  8.  
  9.     This library is distributed in the hope that it will be useful,
  10.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12.     Library General Public License for more details.
  13.  
  14.     You should have received a copy of the GNU Library General Public License
  15.     along with this library; see the file COPYING.LIB.  If not, write to
  16.     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  17.     Boston, MA 02110-1301, USA.
  18. */
  19. //-----------------------------------------------------------------------------
  20. // Selector widgets for KDE Color Selector, but probably useful for other
  21. // stuff also.
  22.  
  23. #ifndef __KSELECT_H__
  24. #define __KSELECT_H__
  25.  
  26. #include <qwidget.h>
  27. #include <qrangecontrol.h>
  28. #include <qpixmap.h>
  29.  
  30. #include <kdelibs_export.h>
  31.  
  32. /**
  33.  * KXYSelector is the base class for other widgets which
  34.  * provides the ability to choose from a two-dimensional
  35.  * range of values. The currently chosen value is indicated
  36.  * by a cross. An example is the KHSSelector which
  37.  * allows to choose from a range of colors, and which is
  38.  * used in KColorDialog.
  39.  *
  40.  * A custom drawing routine for the widget surface has
  41.  * to be provided by the subclass.
  42.  */
  43. class KDEUI_EXPORT KXYSelector : public QWidget
  44. {
  45.   Q_OBJECT
  46.   Q_PROPERTY( int xValue READ xValue WRITE setXValue )
  47.   Q_PROPERTY( int yValue READ yValue WRITE setYValue )
  48.   
  49. public:
  50.   /**
  51.    * Constructs a two-dimensional selector widget which
  52.    * has a value range of [0..100] in both directions.
  53.    */
  54.   KXYSelector( QWidget *parent=0, const char *name=0 );
  55.   /**
  56.    * Destructs the widget.
  57.    */
  58.   ~KXYSelector();
  59.  
  60.   /**
  61.    * Sets the current values in horizontal and
  62.    * vertical direction.
  63.    * @param xPos the horizontal value
  64.    * @param yPos the veritcal value
  65.    */
  66.   void setValues( int xPos, int yPos );
  67.   
  68.   /**
  69.    * Sets the current horizontal value
  70.    * @param xPos the horizontal value
  71.    */
  72.   void setXValue( int xPos );
  73.   
  74.   /**
  75.    * Sets the current vertical value
  76.    * @param yPos the veritcal value
  77.    */
  78.   void setYValue( int yPos );
  79.   
  80.   /**
  81.    * Sets the range of possible values.
  82.    */
  83.   void setRange( int minX, int minY, int maxX, int maxY );
  84.  
  85.   /**
  86.    * @return the current value in horizontal direction.
  87.    */
  88.   int xValue() const {    return xPos; }
  89.   /**
  90.    * @return the current value in vertical direction.
  91.    */
  92.   int yValue() const {    return yPos; }
  93.  
  94.   /**
  95.    * @return the rectangle on which subclasses should draw.
  96.    */
  97.   QRect contentsRect() const;
  98.  
  99. signals:
  100.   /**
  101.    * This signal is emitted whenever the user chooses a value,
  102.    * e.g. by clicking with the mouse on the widget.
  103.    */
  104.   void valueChanged( int x, int y );
  105.  
  106. protected:
  107.   /**
  108.    * Override this function to draw the contents of the widget.
  109.    * The default implementation does nothing.
  110.    *
  111.    * Draw within contentsRect() only.
  112.    */
  113.   virtual void drawContents( QPainter * );
  114.   /**
  115.    * Override this function to draw the cursor which
  116.    * indicates the currently selected value pair.
  117.    */
  118.   virtual void drawCursor( QPainter *p, int xp, int yp );
  119.  
  120.   virtual void paintEvent( QPaintEvent *e );
  121.   virtual void mousePressEvent( QMouseEvent *e );
  122.   virtual void mouseMoveEvent( QMouseEvent *e );
  123.   virtual void wheelEvent( QWheelEvent * );
  124.  
  125.   /**
  126.    * Converts a pixel position to its corresponding values.
  127.    */
  128.   void valuesFromPosition( int x, int y, int& xVal, int& yVal ) const;
  129.  
  130. private:
  131.   void setPosition( int xp, int yp );
  132.   int px;
  133.   int py;
  134.   int xPos;
  135.   int yPos;
  136.   int minX;
  137.   int maxX;
  138.   int minY;
  139.   int maxY;
  140.   QPixmap store;
  141.  
  142. protected:
  143.   virtual void virtual_hook( int id, void* data );
  144. private:
  145.   class KXYSelectorPrivate;
  146.   KXYSelectorPrivate *d;
  147. };
  148.  
  149.  
  150. /**
  151.  * KSelector is the base class for other widgets which
  152.  * provides the ability to choose from a one-dimensional
  153.  * range of values. An example is the KGradientSelector
  154.  * which allows to choose from a range of colors.
  155.  *
  156.  * A custom drawing routine for the widget surface has
  157.  * to be provided by the subclass.
  158.  */
  159. class KDEUI_EXPORT KSelector : public QWidget, public QRangeControl
  160. {
  161.   Q_OBJECT
  162.   Q_PROPERTY( int value READ value WRITE setValue )
  163.   Q_PROPERTY( int minValue READ minValue WRITE setMinValue )
  164.   Q_PROPERTY( int maxValue READ maxValue WRITE setMaxValue )
  165. public:
  166.  
  167.   /**
  168.    * Constructs a horizontal one-dimensional selection widget.
  169.    */
  170.   KSelector( QWidget *parent=0, const char *name=0 );
  171.   /**
  172.    * Constructs a one-dimensional selection widget with
  173.    * a given orientation.
  174.    */
  175.   KSelector( Orientation o, QWidget *parent = 0L, const char *name = 0L );
  176.   /*
  177.    * Destructs the widget.
  178.    */
  179.   ~KSelector();
  180.  
  181.   /**
  182.    * @return the orientation of the widget.
  183.    */
  184.   Orientation orientation() const
  185.   {    return _orientation; }
  186.  
  187.   /**
  188.    * @return the rectangle on which subclasses should draw.
  189.    */
  190.   QRect contentsRect() const;
  191.  
  192.   /**
  193.    * Sets the indent option of the widget to i.
  194.    * This determines whether a shaded frame is drawn.
  195.    */
  196.   void setIndent( bool i )
  197.   {    _indent = i; }
  198.   /**
  199.    * @return whether the indent option is set.
  200.    */
  201.   bool indent() const
  202.   {    return _indent; }
  203.  
  204.   /**
  205.    * Sets the value.
  206.    */
  207.   void setValue(int value)
  208.   { QRangeControl::setValue(value); }
  209.  
  210.   /**
  211.    * @returns the value.
  212.    */
  213.   int value() const
  214.   { return QRangeControl::value(); }
  215.  
  216.   /**
  217.    * Sets the min value.
  218.    */
  219.   void setMinValue(int value)
  220.   { QRangeControl::setMinValue(value); }
  221.  
  222.   /**
  223.    * @return the min value.
  224.    */
  225.   int minValue() const
  226.   { return QRangeControl::minValue(); }
  227.  
  228.   /**
  229.    * Sets the max value.
  230.    */
  231.   void setMaxValue(int value)
  232.   { QRangeControl::setMaxValue(value); }
  233.  
  234.   /**
  235.    * @return the max value.
  236.    */
  237.   int maxValue() const
  238.   { return QRangeControl::maxValue(); }
  239.  
  240. signals:
  241.   /**
  242.    * This signal is emitted whenever the user chooses a value,
  243.    * e.g. by clicking with the mouse on the widget.
  244.    */
  245.   void valueChanged( int value );
  246.  
  247. protected:
  248.   /**
  249.    * Override this function to draw the contents of the control.
  250.    * The default implementation does nothing.
  251.    *
  252.    * Draw only within contentsRect().
  253.    */
  254.   virtual void drawContents( QPainter * );
  255.   /**
  256.    * Override this function to draw the cursor which
  257.    * indicates the current value. This function is
  258.    * always called twice, once with argument show=false
  259.    * to clear the old cursor, once with argument show=true
  260.    * to draw the new one.
  261.    */
  262.   virtual void drawArrow( QPainter *painter, bool show, const QPoint &pos );
  263.  
  264.   virtual void valueChange();
  265.   virtual void paintEvent( QPaintEvent * );
  266.   virtual void mousePressEvent( QMouseEvent *e );
  267.   virtual void mouseMoveEvent( QMouseEvent *e );
  268.   virtual void wheelEvent( QWheelEvent * );
  269.  
  270. private:
  271.   QPoint calcArrowPos( int val );
  272.   void moveArrow( const QPoint &pos );
  273.  
  274.   Orientation _orientation;
  275.   bool _indent;
  276.  
  277. protected:
  278.   virtual void virtual_hook( int id, void* data );
  279. private:
  280.   class KSelectorPrivate;
  281.   KSelectorPrivate *d;
  282. };
  283.  
  284.  
  285. /**
  286.  * The KGradientSelector widget allows the user to choose
  287.  * from a one-dimensional range of colors which is given as a
  288.  * gradient between two colors provided by the programmer.
  289.  *
  290.  * \image html kgradientselector.png "KDE Gradient Selector Widget"
  291.  *
  292.  **/
  293. class KDEUI_EXPORT KGradientSelector : public KSelector
  294. {
  295.   Q_OBJECT
  296.  
  297.   Q_PROPERTY( QColor firstColor READ firstColor WRITE setFirstColor )
  298.   Q_PROPERTY( QColor secondColor READ secondColor WRITE setSecondColor )
  299.   Q_PROPERTY( QString firstText READ firstText WRITE setFirstText )
  300.   Q_PROPERTY( QString secondText READ secondText WRITE setSecondText )
  301.  
  302. public:
  303.   /**
  304.    * Constructs a horizontal color selector which
  305.    * contains a gradient between white and black.
  306.    */
  307.   KGradientSelector( QWidget *parent=0, const char *name=0 );
  308.   /**
  309.    * Constructs a colors selector with orientation o which
  310.    * contains a gradient between white and black.
  311.    */
  312.   KGradientSelector( Orientation o, QWidget *parent=0, const char *name=0 );
  313.   /**
  314.    * Destructs the widget.
  315.    */
  316.   ~KGradientSelector();
  317.   /**
  318.    * Sets the two colors which span the gradient.
  319.    */
  320.   void setColors( const QColor &col1, const QColor &col2 )
  321.   {    color1 = col1; color2 = col2; update();}
  322.   void setText( const QString &t1, const QString &t2 )
  323.   {    text1 = t1; text2 = t2; update(); }
  324.  
  325.   /**
  326.    * Set each color on its own.
  327.    */
  328.   void setFirstColor( const QColor &col )
  329.   { color1 = col; update(); }
  330.   void setSecondColor( const QColor &col )
  331.   { color2 = col; update(); }
  332.  
  333.   /**
  334.    * Set each description on its own
  335.    */
  336.   void setFirstText( const QString &t )
  337.   { text1 = t; update(); }
  338.   void setSecondText( const QString &t )
  339.   { text2 = t; update(); }
  340.  
  341.   const QColor firstColor() const
  342.   { return color1; }
  343.   const QColor secondColor() const
  344.   { return color2; }
  345.  
  346.   const QString firstText() const
  347.   { return text1; }
  348.   const QString secondText() const
  349.   { return text2; }
  350.  
  351. protected:
  352.  
  353.   virtual void drawContents( QPainter * );
  354.   virtual QSize minimumSize() const
  355.   { return sizeHint(); }
  356.  
  357. private:
  358.   void init();
  359.   QColor color1;
  360.   QColor color2;
  361.   QString text1;
  362.   QString text2;
  363.  
  364. protected:
  365.   virtual void virtual_hook( int id, void* data );
  366. private:
  367.   class KGradientSelectorPrivate;
  368.   KGradientSelectorPrivate *d;
  369. };
  370.  
  371.  
  372. #endif        // __KSELECT_H__
  373.  
  374.