summaryrefslogtreecommitdiffstats
path: root/kmid/klcdnumber.h
blob: 8ee390da97b18c2d7c023a680766e52f9c7b0fb6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/**************************************************************************

    klcdnumber.h  - The KLCDNumber widget (displays a lcd number)
    Copyright (C) 1998  Antonio Larrosa Jimenez

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1307, USA.

    Send comments and bug fixes to larrosa@kde.org
    or to Antonio Larrosa, Rio Arnoya, 10 5B, 29006 Malaga, Spain

***************************************************************************/
#ifndef _klcdnumber_h_
#define _klcdnumber_h_

#include <qwidget.h>

class QPainter;
class KTriangleButton;
class QColor;

class KLCDNumber : public QWidget
{
    Q_OBJECT
protected:
    class digit {
public:
        digit()
         : up(false), nw(false), ne(false), md(false), 
           sw(false), se(false), bt(false) { } 
        digit( bool _up, bool _nw, bool _ne, 
               bool _md, bool _sw, bool _se, bool _bt)
         : up(_up), nw(_nw), ne(_ne), md(_md), 
           sw(_sw), se(_se), bt(_bt) { } 
        bool up;  
        bool nw;  
        bool ne;
        bool md;
        bool sw;
        bool se;
        bool bt;
    };
    /*
        up
        ---
     nw|   |ne
       |___|<------ md
       |   |
     sw|___|se
        bt
     */
    

    KLCDNumber::digit Digit[11];
/*
={
        / 0 /    {true,true,true,false,true,true,true},
        / 1 /    {false,false,true,false,false,true,false},
        / 2 /    {true,false,true,true,true,false,true},
        / 3 /    {true,false,true,true,false,true,true},
        / 4 /    {false,true,true,true,false,true,false},
        / 5 /    {true,true,false,true,false,true,true},
        / 6 /    {true,true,false,true,true,true,true},
        / 7 /    {true,false,true,false,false,true,false},
        / 8 /    {true,true,true,true,true,true,true},
        / 9 /    {true,true,true,true,false,true,true},
        /   /    {false,false,false,false,false,false,false}
    };*/
    
    int numDigits;
    bool setUserChangeValue;
    bool setUserDefaultValue;
    bool doubleclicked;

    QColor backgcolor;
    QColor LCDcolor;
    
    double value;
    double oldvalue;
    double defaultValue;

    double minValue;
    double maxValue;

    void drawVerticalBar(QPainter *qpaint,int x,int y,int w,int h,int d);
    void drawHorizBar(QPainter *qpaint,int x,int y,int w,int h,int d);
    void drawDigit(QPainter *qpaint,int x,int y,int w,int h,digit d);

    void initDigits(void);

public:
    KLCDNumber(int _numDigits,QWidget *parent,const char *name);
    KLCDNumber(bool _setUserChangeValue,int _numDigits,QWidget *parent,const char *name);

    void setUserSetDefaultValue(bool _userSetDefaultValue);
    void setDefaultValue(double v);
    
    void setValue(double v);
    double getValue(void) { return value; };
    double getOldValue(void) { return oldvalue; };

    double getMinValue(void) { return minValue;};
    double getMaxValue(void) { return maxValue;};
    void setRange(double min, double max);

    void setLCDBackgroundColor (int r,int g,int b);
    void setLCDColor (int r,int g,int b);

    void display (int v);
    void display (double v);

    QSize sizeHint ();
//    QSizePolicy sizePolicy();

protected:

    virtual void paintEvent ( QPaintEvent *e );
    virtual void resizeEvent ( QResizeEvent *e);
    virtual void mouseDoubleClickEvent (QMouseEvent *e);
    virtual void mousePressEvent (QMouseEvent *e);
    virtual void timerEvent(QTimerEvent *e);
    void defaultValueClicked();
    
    KTriangleButton *downBtn;
    KTriangleButton *upBtn;


    
public slots:

    void decreaseValue();
    void increaseValue();
    void decreaseValueFast();
    void increaseValueFast();

signals:

    void valueChanged(double v);
    
};

#endif