1 | #include "ButtonLink.hpp" |
---|---|
2 | #include <QApplication> |
3 | #include <QStyle> |
4 | |
5 | ButtonLink::ButtonLink(QWidget *parent) |
6 | : QLabel(parent) |
7 | { |
8 | } |
9 | |
10 | ButtonLink::ButtonLink(const QString &text, QWidget *parent) |
11 | : QLabel(text, parent) |
12 | { |
13 | } |
14 | |
15 | ButtonLink::ButtonLink(const QString &text, const QVariant &data, QWidget *parent) |
16 | : QLabel(text, parent) |
17 | , mData(data) |
18 | { |
19 | setContentsMargins(QMargins()); |
20 | } |
21 | |
22 | void ButtonLink::mousePressEvent(QMouseEvent *e) |
23 | { |
24 | Q_UNUSED(e); |
25 | |
26 | if (isEnabled()) |
27 | mPressed = true; |
28 | } |
29 | |
30 | void ButtonLink::mouseReleaseEvent(QMouseEvent *event) |
31 | { |
32 | Q_UNUSED(event); |
33 | |
34 | if (isEnabled() && mPressed) |
35 | emit clicked(); |
36 | } |
37 | |
38 | void ButtonLink::enterEvent(QEvent *event) |
39 | { |
40 | Q_UNUSED(event); |
41 | |
42 | if (isEnabled()) |
43 | { |
44 | QApplication::setOverrideCursor(Qt::PointingHandCursor); |
45 | |
46 | QFont f = font(); |
47 | f.setUnderline(true); |
48 | setFont(f); |
49 | } |
50 | } |
51 | |
52 | void ButtonLink::leaveEvent(QEvent *event) |
53 | { |
54 | Q_UNUSED(event); |
55 | |
56 | if (isEnabled()) |
57 | { |
58 | QFont f = font(); |
59 | f.setUnderline(false); |
60 | setFont(f); |
61 | |
62 | QApplication::restoreOverrideCursor(); |
63 | } |
64 | } |
65 |