-
Notifications
You must be signed in to change notification settings - Fork 1
/
qalarmpushbutton.cpp
87 lines (69 loc) · 2.19 KB
/
qalarmpushbutton.cpp
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
#include "qalarmpushbutton.h"
#include <QLayout>
QAlarmPushButton::QAlarmPushButton(const QString &title, QWidget *parent) :
QWidget(parent),
button(new QPushButton(this)),
label(new QAlarmLabel(title))
{
}
void QAlarmPushButton::setIcon(const QString &icon)
{
iconName = icon;
QSize s(164, 164);
setMinimumSize(s);
button->setMinimumSize(s);
button->setMaximumSize(s);
button->setIconSize(s);
button->setFocusPolicy(Qt::NoFocus);
button->setFlat(true);
button->setStyleSheet(
"QPushButton:pressed {"
"border-image: url(/etc/hildon/theme/images/164IconHighlight.png);"
"}");
button->setIcon(QIcon::fromTheme(iconName));
connect(button, SIGNAL(pressed()), this, SLOT(pressed()));
connect(button, SIGNAL(released()), this, SLOT(released()));
connect(button, SIGNAL(clicked()), this, SLOT(buttonClicked()));
setLayout(new QVBoxLayout);
setLabelPosition(QAlarmPushButton::Bottom);
}
void QAlarmPushButton::setLabelPosition(QAlarmPushButton::Position pos)
{
setUpdatesEnabled(false);
layout()->removeWidget(button);
layout()->removeWidget(label);
delete layout();
if (pos == QAlarmPushButton::Right)
{
setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Maximum);
setLayout(new QHBoxLayout);
layout()->setAlignment(Qt::AlignLeft | Qt::AlignTop);
layout()->setContentsMargins(32, 0, 32, 0);
layout()->setSpacing(32);
label->setAlignment(Qt::AlignJustify | Qt::AlignVCenter);
}
else
{
setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Expanding);
setLayout(new QVBoxLayout);
layout()->setAlignment(Qt::AlignHCenter | Qt::AlignTop);
layout()->setContentsMargins(0, 0, 0, 0);
layout()->setSpacing(0);
label->setAlignment(Qt::AlignHCenter | Qt::AlignTop);
}
layout()->addWidget(button);
layout()->addWidget(label);
setUpdatesEnabled(true);
}
void QAlarmPushButton::pressed()
{
button->setIcon(QIcon::fromTheme(iconName));
}
void QAlarmPushButton::released()
{
button->setIcon(QIcon::fromTheme(iconName + "_pressed"));
}
void QAlarmPushButton::buttonClicked()
{
emit clicked();
}