Chris@186
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@186
|
2
|
Chris@186
|
3 /*
|
Chris@186
|
4 EasyMercurial
|
Chris@186
|
5
|
Chris@186
|
6 Based on HgExplorer by Jari Korhonen
|
Chris@186
|
7 Copyright (c) 2010 Jari Korhonen
|
Chris@186
|
8 Copyright (c) 2010 Chris Cannam
|
Chris@186
|
9 Copyright (c) 2010 Queen Mary, University of London
|
Chris@186
|
10
|
Chris@186
|
11 This program is free software; you can redistribute it and/or
|
Chris@186
|
12 modify it under the terms of the GNU General Public License as
|
Chris@186
|
13 published by the Free Software Foundation; either version 2 of the
|
Chris@186
|
14 License, or (at your option) any later version. See the file
|
Chris@186
|
15 COPYING included with this distribution for more information.
|
Chris@186
|
16 */
|
Chris@186
|
17
|
Chris@186
|
18 #ifndef _CLICKABLE_LABEL_H_
|
Chris@186
|
19 #define _CLICKABLE_LABEL_H_
|
Chris@186
|
20
|
Chris@186
|
21 #include <QLabel>
|
Chris@186
|
22
|
Chris@186
|
23 class ClickableLabel : public QLabel
|
Chris@186
|
24 {
|
Chris@186
|
25 Q_OBJECT
|
Chris@186
|
26
|
Chris@186
|
27 Q_PROPERTY(bool mouseUnderline READ mouseUnderline WRITE setMouseUnderline)
|
Chris@186
|
28
|
Chris@186
|
29 public:
|
Chris@186
|
30 ClickableLabel(const QString &text, QWidget *parent = 0) :
|
Chris@186
|
31 QLabel(text, parent),
|
Chris@186
|
32 m_naturalText(text)
|
Chris@186
|
33 { }
|
Chris@186
|
34
|
Chris@186
|
35 ClickableLabel(QWidget *parent = 0) :
|
Chris@186
|
36 QLabel(parent)
|
Chris@186
|
37 { }
|
Chris@186
|
38
|
Chris@186
|
39 ~ClickableLabel()
|
Chris@186
|
40 { }
|
Chris@186
|
41
|
Chris@186
|
42 void setText(const QString &t) {
|
Chris@186
|
43 m_naturalText = t;
|
Chris@186
|
44 QLabel::setText(t);
|
Chris@186
|
45 }
|
Chris@186
|
46
|
Chris@186
|
47 bool mouseUnderline() const {
|
Chris@186
|
48 return m_mouseUnderline;
|
Chris@186
|
49 }
|
Chris@186
|
50
|
Chris@186
|
51 void setMouseUnderline(bool mu) {
|
Chris@186
|
52 m_mouseUnderline = mu;
|
Chris@187
|
53 if (mu) {
|
Chris@187
|
54 setTextFormat(Qt::RichText);
|
Chris@187
|
55 setCursor(Qt::PointingHandCursor);
|
Chris@187
|
56 }
|
Chris@186
|
57 }
|
Chris@186
|
58
|
Chris@186
|
59 signals:
|
Chris@186
|
60 void clicked();
|
Chris@186
|
61
|
Chris@186
|
62 protected:
|
Chris@186
|
63 virtual void enterEvent(QEvent *) {
|
Chris@186
|
64 if (m_mouseUnderline) {
|
Chris@186
|
65 QLabel::setText(tr("<u>%1</u>").arg(m_naturalText));
|
Chris@186
|
66 }
|
Chris@186
|
67 }
|
Chris@186
|
68
|
Chris@186
|
69 virtual void leaveEvent(QEvent *) {
|
Chris@186
|
70 if (m_mouseUnderline) {
|
Chris@186
|
71 QLabel::setText(m_naturalText);
|
Chris@186
|
72 }
|
Chris@186
|
73 }
|
Chris@186
|
74
|
Chris@186
|
75 virtual void mousePressEvent(QMouseEvent *) {
|
Chris@186
|
76 emit clicked();
|
Chris@186
|
77 }
|
Chris@186
|
78
|
Chris@186
|
79 private:
|
Chris@186
|
80 bool m_mouseUnderline;
|
Chris@186
|
81 QString m_naturalText;
|
Chris@186
|
82 };
|
Chris@186
|
83
|
Chris@186
|
84 #endif
|