-
Notifications
You must be signed in to change notification settings - Fork 1
/
qalarmdialog.h
128 lines (111 loc) · 2.9 KB
/
qalarmdialog.h
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
#ifndef ALARMLIST_H
#define ALARMLIST_H
#include <QDialog>
#include <QTreeView>
#include <QStandardItemModel>
#include <QLabel>
#include <QPushButton>
#include <QStyledItemDelegate>
#include <QMouseEvent>
#include <libalarm.h>
class QAlarmTreeView : public QTreeView
{
Q_OBJECT
public:
explicit QAlarmTreeView(QWidget *parent = 0) :
QTreeView(parent),
valid(false)
{
}
bool itemValid()
{
return valid;
}
protected:
void mousePressEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
QPoint pressPos;
bool valid;
};
class QAlarmTimeLabel : public QLabel
{
Q_OBJECT
public:
explicit QAlarmTimeLabel(QAlarmTreeView *view, QStandardItem *item,
QWidget *parent = 0) :
QLabel(parent),
view(view),
item(item),
emitClicked(false),
pressed(false)
{
}
Q_SIGNALS:
void clicked(const QModelIndex &modelIndex);
protected:
QAlarmTreeView *view;
QStandardItem *item;
bool emitClicked;
bool pressed;
void mousePressEvent(QMouseEvent *ev)
{
if (ev->buttons() == Qt::LeftButton)
pressed = emitClicked = true;
QLabel::mousePressEvent(ev);
}
void mouseMoveEvent(QMouseEvent *ev)
{
if (pressed)
{
if (emitClicked && !rect().contains(ev->pos()))
{
emitClicked = false;
view->selectionModel()->clearSelection();
}
else if (!emitClicked && rect().contains(ev->pos()))
emitClicked = true;
}
QLabel::mouseMoveEvent(ev);
}
void mouseReleaseEvent(QMouseEvent *ev)
{
QLabel::mouseReleaseEvent(ev);
pressed = false;
if (emitClicked)
{
emitClicked = false;
view->selectionModel()->clearSelection();
Q_EMIT clicked(item->model()->indexFromItem(item));
}
}
};
class QAlarmDialog : public QDialog
{
Q_OBJECT
public:
explicit QAlarmDialog(QWidget *parent = 0);
public Q_SLOTS:
void addAlarms();
void addAlarm(cookie_t cookie);
void sort();
Q_SIGNALS:
void nextAlarmChanged(const QStringList &) const;
private:
QLabel *label;
QPushButton* button;
QAlarmTreeView* view;
QStandardItemModel *model;
QStandardItem *alarmCheckboxItem(cookie_t cookie,
const alarm_event_t *ae) const;
void alarmTimeItem(const alarm_event_t *ae, QStandardItem *item) const;
QStandardItem *alarmTitleItem(const alarm_event_t *ae) const;
QStandardItem *alarmDaysItem(const alarm_event_t *ae) const;
time_t _addAlarm(cookie_t cookie);
void signalNextAlarm();
private Q_SLOTS:
void buttonClicked();
void viewClicked(const QModelIndex & modelIndex);
void getNextAlarm() const;
};
#endif // ALARMLIST_H