Mercurial > hg > easyhg
comparison clickablelabel.h @ 186:6c15700f4103
* Open local folder in Finder/Explorer/whatever when its path is clicked on
author | Chris Cannam |
---|---|
date | Mon, 20 Dec 2010 14:37:35 +0000 |
parents | |
children | 869825bc8bc4 |
comparison
equal
deleted
inserted
replaced
185:ec2baee80833 | 186:6c15700f4103 |
---|---|
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) 2010 Chris Cannam | |
9 Copyright (c) 2010 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) setTextFormat(Qt::RichText); | |
54 } | |
55 | |
56 signals: | |
57 void clicked(); | |
58 | |
59 protected: | |
60 virtual void enterEvent(QEvent *) { | |
61 if (m_mouseUnderline) { | |
62 QLabel::setText(tr("<u>%1</u>").arg(m_naturalText)); | |
63 } | |
64 } | |
65 | |
66 virtual void leaveEvent(QEvent *) { | |
67 if (m_mouseUnderline) { | |
68 QLabel::setText(m_naturalText); | |
69 } | |
70 } | |
71 | |
72 virtual void mousePressEvent(QMouseEvent *) { | |
73 emit clicked(); | |
74 } | |
75 | |
76 private: | |
77 bool m_mouseUnderline; | |
78 QString m_naturalText; | |
79 }; | |
80 | |
81 #endif |