Chris@186: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@186: Chris@186: /* Chris@186: EasyMercurial Chris@186: Chris@186: Based on HgExplorer by Jari Korhonen Chris@186: Copyright (c) 2010 Jari Korhonen Chris@186: Copyright (c) 2010 Chris Cannam Chris@186: Copyright (c) 2010 Queen Mary, University of London Chris@186: Chris@186: This program is free software; you can redistribute it and/or Chris@186: modify it under the terms of the GNU General Public License as Chris@186: published by the Free Software Foundation; either version 2 of the Chris@186: License, or (at your option) any later version. See the file Chris@186: COPYING included with this distribution for more information. Chris@186: */ Chris@186: Chris@186: #ifndef _CLICKABLE_LABEL_H_ Chris@186: #define _CLICKABLE_LABEL_H_ Chris@186: Chris@186: #include Chris@186: Chris@186: class ClickableLabel : public QLabel Chris@186: { Chris@186: Q_OBJECT Chris@186: Chris@186: Q_PROPERTY(bool mouseUnderline READ mouseUnderline WRITE setMouseUnderline) Chris@186: Chris@186: public: Chris@186: ClickableLabel(const QString &text, QWidget *parent = 0) : Chris@186: QLabel(text, parent), Chris@186: m_naturalText(text) Chris@186: { } Chris@186: Chris@186: ClickableLabel(QWidget *parent = 0) : Chris@186: QLabel(parent) Chris@186: { } Chris@186: Chris@186: ~ClickableLabel() Chris@186: { } Chris@186: Chris@186: void setText(const QString &t) { Chris@186: m_naturalText = t; Chris@186: QLabel::setText(t); Chris@186: } Chris@186: Chris@186: bool mouseUnderline() const { Chris@186: return m_mouseUnderline; Chris@186: } Chris@186: Chris@186: void setMouseUnderline(bool mu) { Chris@186: m_mouseUnderline = mu; Chris@186: if (mu) setTextFormat(Qt::RichText); Chris@186: } Chris@186: Chris@186: signals: Chris@186: void clicked(); Chris@186: Chris@186: protected: Chris@186: virtual void enterEvent(QEvent *) { Chris@186: if (m_mouseUnderline) { Chris@186: QLabel::setText(tr("%1").arg(m_naturalText)); Chris@186: } Chris@186: } Chris@186: Chris@186: virtual void leaveEvent(QEvent *) { Chris@186: if (m_mouseUnderline) { Chris@186: QLabel::setText(m_naturalText); Chris@186: } Chris@186: } Chris@186: Chris@186: virtual void mousePressEvent(QMouseEvent *) { Chris@186: emit clicked(); Chris@186: } Chris@186: Chris@186: private: Chris@186: bool m_mouseUnderline; Chris@186: QString m_naturalText; Chris@186: }; Chris@186: Chris@186: #endif