summaryrefslogtreecommitdiffstats
path: root/examples/statemachine/citizenquartz/clockdisplay.h
blob: e0ac8bb078f20fc79e8cba47a73e5db91bf2f926 (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
#ifndef CLOCKDISPLAY_H
#define CLOCKDISPLAY_H

#include <QObject>
#include <QGraphicsItem>
#include <QDateTime>

class ClockDisplay: public QObject, public QGraphicsItem
{
    Q_OBJECT
    Q_ENUMS(DisplayMode)
    Q_PROPERTY(DisplayMode displayMode READ displayMode WRITE setDisplayMode)
    Q_PROPERTY(QDateTime currentTime READ currentTime WRITE setCurrentTime)
    Q_PROPERTY(QTime alarm READ alarm WRITE setAlarm)
    Q_PROPERTY(bool alarmEnabled READ alarmEnabled WRITE setAlarmEnabled)
public:
    enum DisplayMode {
        CurrentTimeMode,        
        EditSecondMode,
        EditMinuteMode,
        EditHourMode,

        CurrentDateMode,
        EditMonthMode,
        EditDayMode,
        EditYearMode,

        AlarmMode,
        EditAlarmHourMode,
        EditAlarmTenMinuteMode,
        EditAlarmMinuteMode,

        ChimeMode,
        StopWatchMode,
        ModeCount
    };

    ClockDisplay(QGraphicsItem *parent = 0);
    virtual ~ClockDisplay();

    void setDisplayMode(DisplayMode displayMode) { m_displayMode = displayMode; update(); }
    DisplayMode displayMode() const { return m_displayMode; }

    QDateTime currentTime() const { return m_currentTime; }
    void setCurrentTime(const QDateTime &time) { m_currentTime = time; update(); }

    QTime alarm() const { return m_alarm; }
    void setAlarm(const QTime &time) { m_alarm = time; update(); }

    bool alarmEnabled() const { return m_alarmEnabled; }
    void setAlarmEnabled(bool enabled) { m_alarmEnabled = enabled; update(); }

    virtual QRectF boundingRect() const;
    virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *);

private slots:
    void toggleBlinkFlag();

private:
    void updateText();

    DisplayMode m_displayMode;

    QDateTime m_currentTime;
    QTime m_alarm;
    
    QGraphicsTextItem *m_text;
    QGraphicsPixmapItem *m_alarmSymbol;

    uint m_alarmEnabled : 1;
    uint m_blink : 1;
    uint m_reserved : 30; 
};

#endif