comparison src/clickablelabel.h @ 370:b9c153e00e84

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