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

  1. /*
  2.     This file is part of the KDE games library
  3.     Copyright (C) 2001,2002,2003 Nicolas Hadacek (hadacek@kde.org)
  4.  
  5.     This library is free software; you can redistribute it and/or
  6.     modify it under the terms of the GNU Library General Public
  7.     License version 2 as published by the Free Software Foundation.
  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. #ifndef __KGAMELCD_H
  21. #define __KGAMELCD_H
  22.  
  23. #include <qlcdnumber.h>
  24. #include <qvaluevector.h>
  25. #include <kdemacros.h>
  26.  
  27. class QLabel;
  28. class QTimer;
  29.  
  30. //-----------------------------------------------------------------------------
  31. /**
  32.  * This class is a visually enhanced @ref QLCDNumber:
  33.  * <ul>
  34.  * <li> It can show an additional string before the integer being
  35.  * displayed.</li>
  36.  * <li> Its foreground and background colors can easily be modified. </li>
  37.  * <li> It can be highlighted for a short time. </li>
  38.  * </ul>
  39.  *
  40.  * @since 3.2
  41.  */
  42. class KDE_EXPORT KGameLCD : public QLCDNumber
  43. {
  44.     Q_OBJECT
  45. public:
  46.     KGameLCD(uint nbDigits, QWidget *parent = 0, const char *name = 0);
  47.  
  48.     ~KGameLCD();
  49.  
  50.     /**
  51.      * Set the default background color.
  52.      */
  53.     void setDefaultBackgroundColor(const QColor &color);
  54.  
  55.     /**
  56.      * Set the default foreground color.
  57.      */
  58.     void setDefaultColor(const QColor &color);
  59.  
  60.     /**
  61.      * Set highlight color.
  62.      */
  63.     void setHighlightColor(const QColor &color);
  64.  
  65.     /**
  66.      * Set the string that will be displayed before the integer number to be
  67.      * displayed. By default this string is null.
  68.      */
  69.     void setLeadingString(const QString &s);
  70.  
  71.     /**
  72.      * Set the highlight duration in milliseconds. The default value is
  73.      * 800 milliseconds.
  74.      */
  75.     void setHighlightTime(uint time);
  76.  
  77.     /**
  78.      * Reset the foreground color to the default one.
  79.      */
  80.     void resetColor();
  81.  
  82.     /**
  83.      * Set the foreground color.
  84.      */
  85.     void setColor(const QColor &color);
  86.  
  87. public slots:
  88.     /**
  89.      * Highlight the LCD with the QColorGourp::HighlightedText color
  90.      * for a small time (setHighlightTime).
  91.      */
  92.     void highlight();
  93.  
  94.     /**
  95.      * Display the given integer with the (optionnal) leading string.
  96.      *
  97.      * Note: we cannot use display(int) since QLCDNumber::display is
  98.      * not virtual... And you cannot use QLCDNumber::intValue() to retrieve
  99.      * the given value.
  100.      */
  101.     void displayInt(int value);
  102.  
  103. private slots:
  104.     void timeout() { highlight(false); }
  105.  
  106. private:
  107.     QColor   _fgColor, _hlColor;
  108.     QString  _lead;
  109.     uint     _htime;
  110.     QTimer  *_timer;
  111.  
  112.     class KGameLCDPrivate;
  113.     KGameLCDPrivate *d;
  114.  
  115.     void highlight(bool light);
  116.  
  117. };
  118.  
  119. //-----------------------------------------------------------------------------
  120. /**
  121.  * This class is a digital clock widget. It has a maximum duration of
  122.  * 3599 seconds (one hour) and it gets updated every second.
  123.  *
  124.  * @since 3.2
  125.  */
  126. class KDE_EXPORT KGameLCDClock : public KGameLCD
  127. {
  128.     Q_OBJECT
  129. public:
  130.     KGameLCDClock(QWidget *parent = 0, const char *name = 0);
  131.  
  132.     ~KGameLCDClock();
  133.  
  134.     /**
  135.      * @return the total number of seconds elapsed.
  136.      */
  137.     uint seconds() const;
  138.  
  139.     /**
  140.      * @return the time as a string to be displayed: "mm:ss".
  141.      */
  142.     QString pretty() const;
  143.  
  144.     /**
  145.      * Set the time.
  146.      */
  147.     void setTime(uint seconds);
  148.  
  149.     /**
  150.      * Set the time (format should be "mm:ss").
  151.      */
  152.     void setTime(const QString &s);
  153.  
  154. public slots:
  155.     /**
  156.      * Stop the clock and reset it to zero.
  157.      */
  158.     virtual void reset();
  159.  
  160.     /**
  161.      * Stop the clock but do not reset it to zero.
  162.      */
  163.     virtual void stop();
  164.  
  165.     /**
  166.      * Start the clock from the current time.
  167.      */
  168.     virtual void start();
  169.  
  170. protected slots:
  171.     virtual void timeoutClock();
  172.  
  173. private:
  174.     QTimer *_timerClock;
  175.     uint    _sec, _min;
  176.  
  177.     class KGameLCDClockPrivate;
  178.     KGameLCDClockPrivate *d;
  179.  
  180.     void showTime();
  181. };
  182.  
  183. //-----------------------------------------------------------------------------
  184. /**
  185.  * This widget holds a list of @ref QLCDNumber arranged in a vertical layout.
  186.  * It also shows a label at the top of the list.
  187.  *
  188.  * @since 3.2
  189.  */
  190. class KDE_EXPORT KGameLCDList : public QWidget
  191. {
  192.     Q_OBJECT
  193. public:
  194.     /**
  195.      * Constructor.
  196.      *
  197.      * @param title is the content of the top label.
  198.      * @param parent passed to the QWidget constructor
  199.      * @param name passed to the QWidget constructor
  200.      */
  201.     KGameLCDList(const QString &title,
  202.                  QWidget *parent = 0, const char *name = 0);
  203.     KGameLCDList(QWidget *parent = 0, const char *name = 0);
  204.  
  205.     ~KGameLCDList();
  206.  
  207.     /**
  208.      * Append a QLCDNumber at the bottom of the list.
  209.      * The QLCDNumber should have the KGameLCDList as parent.
  210.      */
  211.     void append(QLCDNumber *lcd);
  212.     
  213.     /**
  214.      * Append a QLCDNumber at the bottom of the list.
  215.      * The QLCDNumber should have the KGameLCDList as parent.
  216.      */
  217.     void append(const QString &leading, QLCDNumber *lcd);
  218.  
  219.     /**
  220.      * Delete all @ref QLCDNumber and clear the list.
  221.      */
  222.     void clear();
  223.  
  224.     /**
  225.      * @return the title label.
  226.      */
  227.     QLabel *title() const { return _title; }
  228.  
  229.     /**
  230.      * @return the QLCDNumber at index @param i
  231.      */
  232.     QLCDNumber *lcd(uint i) const { return _lcds[i]; }
  233.     
  234.     /**
  235.      * @return the number of QLCDNumber in the list.
  236.      */
  237.     uint size() const { return _lcds.size(); }
  238.  
  239. private:
  240.     QLabel *_title;
  241.     QValueVector<QLCDNumber *> _lcds;
  242.  
  243.     class KGameLCDListPrivate;
  244.     KGameLCDListPrivate *d;
  245.  
  246.     void init(const QString &title);
  247. };
  248.  
  249. #endif
  250.