comparison src/clickablelabel.h @ 523:d869e6a18f63

Make the text labels in the work status area squeezable for small window sizes. Fixes #329
author Chris Cannam
date Tue, 15 Nov 2011 16:02:18 +0000
parents b9c153e00e84
children 533519ebc0cb
comparison
equal deleted inserted replaced
522:43ddfa5e9fd0 523:d869e6a18f63
16 */ 16 */
17 17
18 #ifndef _CLICKABLE_LABEL_H_ 18 #ifndef _CLICKABLE_LABEL_H_
19 #define _CLICKABLE_LABEL_H_ 19 #define _CLICKABLE_LABEL_H_
20 20
21 #include <QLabel> 21 #include "squeezedlabel.h"
22 22
23 class ClickableLabel : public QLabel 23 #include <QMouseEvent>
24
25 class ClickableLabel : public SqueezedLabel
24 { 26 {
25 Q_OBJECT 27 Q_OBJECT
26 28
27 Q_PROPERTY(bool mouseUnderline READ mouseUnderline WRITE setMouseUnderline) 29 Q_PROPERTY(bool mouseUnderline READ mouseUnderline WRITE setMouseUnderline)
28 30
29 public: 31 public:
30 ClickableLabel(const QString &text, QWidget *parent = 0) : 32 ClickableLabel(const QString &text, QWidget *parent = 0) :
31 QLabel(text, parent), 33 SqueezedLabel(text, parent),
32 m_naturalText(text) 34 m_naturalText(text)
33 { } 35 { }
34 36
35 ClickableLabel(QWidget *parent = 0) : 37 ClickableLabel(QWidget *parent = 0) :
36 QLabel(parent) 38 SqueezedLabel(parent)
37 { } 39 { }
38 40
39 ~ClickableLabel() 41 ~ClickableLabel()
40 { } 42 { }
41 43
42 void setText(const QString &t) { 44 void setText(const QString &t) {
43 m_naturalText = t; 45 m_naturalText = t;
44 QLabel::setText(t); 46 SqueezedLabel::setText(t);
45 } 47 }
46 48
47 bool mouseUnderline() const { 49 bool mouseUnderline() const {
48 return m_mouseUnderline; 50 return m_mouseUnderline;
49 } 51 }
60 void clicked(); 62 void clicked();
61 63
62 protected: 64 protected:
63 virtual void enterEvent(QEvent *) { 65 virtual void enterEvent(QEvent *) {
64 if (m_mouseUnderline) { 66 if (m_mouseUnderline) {
65 QLabel::setText(tr("<u>%1</u>").arg(m_naturalText)); 67 SqueezedLabel::setText(tr("<u>%1</u>").arg(m_naturalText));
66 } 68 }
67 } 69 }
68 70
69 virtual void leaveEvent(QEvent *) { 71 virtual void leaveEvent(QEvent *) {
70 if (m_mouseUnderline) { 72 if (m_mouseUnderline) {
71 QLabel::setText(m_naturalText); 73 SqueezedLabel::setText(m_naturalText);
72 } 74 }
73 } 75 }
74 76
75 virtual void mousePressEvent(QMouseEvent *) { 77 virtual void mousePressEvent(QMouseEvent *ev) {
76 emit clicked(); 78 if (ev->button() == Qt::LeftButton) {
79 emit clicked();
80 } else {
81 SqueezedLabel::mousePressEvent(ev);
82 }
77 } 83 }
78 84
79 private: 85 private:
80 bool m_mouseUnderline; 86 bool m_mouseUnderline;
81 QString m_naturalText; 87 QString m_naturalText;