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 / kgameprogress.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-10-10  |  6.3 KB  |  256 lines

  1. /* This file is part of the KDE libraries
  2.    Copyright (C) 1996 Martynas Kunigelis
  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 version 2 as published by the Free Software Foundation.
  7.  
  8.    This library is distributed in the hope that it will be useful,
  9.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  11.    Library General Public License for more details.
  12.  
  13.    You should have received a copy of the GNU Library General Public License
  14.    along with this library; see the file COPYING.LIB.  If not, write to
  15.    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  16.    Boston, MA 02110-1301, USA.
  17. */
  18. /*****************************************************************************
  19. *                                                                            *
  20. *  KGameProgress -- progress indicator widget for KDE by Martynas Kunigelis  *
  21. *                                                                            *
  22. *****************************************************************************/
  23.  
  24. #ifndef _KPROGRES_H
  25. #define _KPROGRES_H "$Id: kgameprogress.h 465369 2005-09-29 14:33:08Z mueller $"
  26.  
  27. #include <qframe.h>
  28. #include <qrangecontrol.h>
  29. #include <kdemacros.h>
  30. /**
  31.  * @short A progress indicator widget.
  32.  *
  33.  * KGameProgress is derived from QFrame and QRangeControl, so
  34.  * you can use all the methods from those classes. The only difference
  35.  * is that setValue() is now made a slot, so you can connect
  36.  * stuff to it.
  37.  *
  38.  * None of the constructors take line step and page step as arguments,
  39.  * so by default they're set to 1 and 10 respectively.
  40.  *
  41.  * The Blocked style ignores the textEnabled() setting and displays
  42.  * no text, since it looks truly ugly (and for other reasons). Signal
  43.  * percentageChanged() is emitted whenever the value changes so you
  44.  * can set up a different widget to display the current percentage complete
  45.  * and connect the signal to it.
  46.  *
  47.  * @author Martynas Kunigelis
  48.  * @version $Id: kgameprogress.h 465369 2005-09-29 14:33:08Z mueller $
  49.  */
  50. class KDE_EXPORT KGameProgress : public QFrame, public QRangeControl
  51. {
  52.   Q_OBJECT
  53.   Q_ENUMS( BarStyle )
  54.   Q_PROPERTY( int value READ value WRITE setValue)
  55.   Q_PROPERTY( BarStyle barStyle READ barStyle WRITE setBarStyle )
  56.   Q_PROPERTY( QColor barColor READ barColor WRITE setBarColor )
  57.   Q_PROPERTY( QPixmap barPixmap READ barPixmap WRITE setBarPixmap )
  58.   Q_PROPERTY( Orientation orientation READ orientation WRITE setOrientation )
  59.   Q_PROPERTY( bool textEnabled READ textEnabled WRITE setTextEnabled )
  60.  
  61. public:
  62.   /**
  63.    * Possible values for bar style.
  64.    *
  65.    * @p Solid means one continuous progress bar, @p Blocked means a
  66.    * progress bar made up of several blocks.
  67.    */
  68.   enum BarStyle { Solid, Blocked };
  69.  
  70.   /**
  71.    * Construct a horizontal progress bar.
  72.    */
  73.   KGameProgress(QWidget *parent=0, const char *name=0);
  74.  
  75.   /**
  76.    * Construct a progress bar with orientation @p orient.
  77.    */
  78.   KGameProgress(Orientation orient, QWidget *parent=0, const char *name=0);
  79.  
  80.   /**
  81.    * Construct a progress bar with minimum, maximum and initial values.
  82.    */
  83.   KGameProgress(int minValue, int maxValue, int value, Orientation,
  84.                 QWidget *parent=0, const char *name=0);
  85.  
  86.   /**
  87.    * Destruct the progress bar.
  88.    */
  89.   ~KGameProgress();
  90.  
  91.   /**
  92.    * Set the progress bar style.
  93.    *
  94.    * Allowed values are @p Solid and @p Blocked.
  95.    */
  96.   void setBarStyle(BarStyle style);
  97.  
  98.   /**
  99.    * Set the color of the progress bar.
  100.    */
  101.   void setBarColor(const QColor &);
  102.  
  103.   /**
  104.    * Set a pixmap to be shown in the progress bar.
  105.    */
  106.   void setBarPixmap(const QPixmap &);
  107.  
  108.   /**
  109.    * Set the orientation of the progress bar.
  110.    *
  111.    * Allowed values are @p Horizontal and @p Vertical.
  112.    */
  113.   void setOrientation(Orientation);
  114.  
  115.   /**
  116.    * If this is set to @p true, the progress text will be displayed.
  117.    *
  118.    */
  119.   void setTextEnabled(bool);
  120.  
  121.   /**
  122.    * Retrieve the bar style.
  123.    *
  124.    * @see setBarStyle()
  125.    */
  126.   BarStyle barStyle() const;
  127.  
  128.   /**
  129.    * Retrieve the bar color.
  130.    * @see setBarColor()
  131.    */
  132.   const QColor &barColor() const;
  133.  
  134.   /**
  135.    * Retrieve the bar pixmap.
  136.    *
  137.    * @see setBarPixmap()
  138.    */
  139.   const QPixmap *barPixmap() const;
  140.  
  141.   /**
  142.    * Retrive the current status
  143.    *
  144.    * @see setValue()
  145.    */
  146.   int value() const { return QRangeControl::value(); }
  147.   /**
  148.    * Retrive the orientation of the progress bar.
  149.    *
  150.    * @see setOrientation()
  151.    */
  152.   Orientation orientation() const;
  153.  
  154.   /**
  155.    * Returns @p true if progress text will be displayed,
  156.    * @p false otherwise.
  157.    *
  158.    * @see setFormat()
  159.    */
  160.   bool textEnabled() const;
  161.  
  162.   /**
  163.    */
  164.   virtual QSize sizeHint() const;
  165.  
  166.   /**
  167.    */
  168.   virtual QSize minimumSizeHint() const;
  169.  
  170.   /**
  171.    */
  172.   virtual QSizePolicy sizePolicy() const;
  173.  
  174.   /**
  175.    * Retrieve the current format for printing status text.
  176.    * @see setFormat()
  177.    */
  178.   QString format() const;
  179.  
  180. public slots:
  181.  
  182.   /**
  183.    * Set the format of the text to use to display status.
  184.    *
  185.    * The default format is "%p%" (which looks like "42%".)
  186.    *
  187.    * @param format %p is replaced by percentage done, %v is replaced by actual
  188.    * value, %m is replaced by the maximum value.
  189.    */
  190.   void setFormat(const QString & format);
  191.  
  192.   /**
  193.    * Set the current value of the progress bar to @p value.
  194.    *
  195.    * This must be a number in the range 0..100.
  196.    */
  197.   void setValue(int value);
  198.  
  199.   /**
  200.    * Advance the progress bar by @p prog.
  201.    *
  202.    * This method is
  203.    * provided for convenience and is equivalent with
  204.    * setValue(value()+prog).
  205.    */
  206.   void advance(int prog);
  207.  
  208. signals:
  209.   /**
  210.    * Emitted when the state of the progress bar changes.
  211.    */
  212.   void percentageChanged(int);
  213.  
  214. protected:
  215.   /**
  216.    */
  217.   void valueChange();
  218.   /**
  219.    */
  220.   void rangeChange();
  221.   /**
  222.    */
  223.   void styleChange( QStyle& );
  224.   /**
  225.    */
  226.   void paletteChange( const QPalette & );
  227.   /**
  228.    */
  229.   void drawContents( QPainter * );
  230.  
  231. private slots:
  232.   void paletteChange();
  233.  
  234. private:
  235.   QPixmap  *bar_pixmap;
  236.   bool      use_supplied_bar_color;
  237.   QColor    bar_color;
  238.   QColor    bar_text_color;
  239.   QColor    text_color;
  240.   QRect     fr;
  241.   BarStyle  bar_style;
  242.   Orientation orient;
  243.   bool      text_enabled;
  244.   QString   format_;
  245.   void      initialize();
  246.   int       recalcValue(int);
  247.   void      drawText(QPainter *);
  248.   void      adjustStyle();
  249.  
  250.   class KGameProgressPrivate;
  251.   KGameProgressPrivate *d;
  252. };
  253.  
  254.  
  255. #endif
  256.