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@560: Copyright (c) 2012 Chris Cannam Chris@560: Copyright (c) 2012 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@523: #include "squeezedlabel.h" Chris@186: Chris@523: #include Chris@523: Chris@523: class ClickableLabel : public SqueezedLabel 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@523: SqueezedLabel(text, parent), Chris@186: m_naturalText(text) Chris@186: { } Chris@186: Chris@186: ClickableLabel(QWidget *parent = 0) : Chris@523: SqueezedLabel(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@523: SqueezedLabel::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@187: if (mu) { Chris@187: setTextFormat(Qt::RichText); Chris@187: setCursor(Qt::PointingHandCursor); Chris@187: } 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@523: SqueezedLabel::setText(tr("%1").arg(m_naturalText)); Chris@186: } Chris@186: } Chris@186: Chris@186: virtual void leaveEvent(QEvent *) { Chris@186: if (m_mouseUnderline) { Chris@523: SqueezedLabel::setText(m_naturalText); Chris@186: } Chris@186: } Chris@186: Chris@523: virtual void mousePressEvent(QMouseEvent *ev) { Chris@523: if (ev->button() == Qt::LeftButton) { Chris@523: emit clicked(); Chris@523: } else { Chris@523: SqueezedLabel::mousePressEvent(ev); Chris@523: } Chris@186: } Chris@186: Chris@186: private: Chris@186: bool m_mouseUnderline; Chris@186: QString m_naturalText; Chris@186: }; Chris@186: Chris@186: #endif