annotate src/clickablelabel.h @ 633:db62a0cb3037

* Added setting to specify that diff command should be run once for each selected file, rather than passing all file names to diff command (p4merge doesn't like being given many files)
author Sam Izzo <sam@humbug.net>
date Mon, 27 Aug 2012 01:26:57 +1000
parents 533519ebc0cb
children ae67ea0af696
rev   line source
Chris@186 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@186 2
Chris@186 3 /*
Chris@186 4 EasyMercurial
Chris@186 5
Chris@186 6 Based on HgExplorer by Jari Korhonen
Chris@186 7 Copyright (c) 2010 Jari Korhonen
Chris@560 8 Copyright (c) 2012 Chris Cannam
Chris@560 9 Copyright (c) 2012 Queen Mary, University of London
Chris@186 10
Chris@186 11 This program is free software; you can redistribute it and/or
Chris@186 12 modify it under the terms of the GNU General Public License as
Chris@186 13 published by the Free Software Foundation; either version 2 of the
Chris@186 14 License, or (at your option) any later version. See the file
Chris@186 15 COPYING included with this distribution for more information.
Chris@186 16 */
Chris@186 17
Chris@186 18 #ifndef _CLICKABLE_LABEL_H_
Chris@186 19 #define _CLICKABLE_LABEL_H_
Chris@186 20
Chris@523 21 #include "squeezedlabel.h"
Chris@186 22
Chris@523 23 #include <QMouseEvent>
Chris@523 24
Chris@523 25 class ClickableLabel : public SqueezedLabel
Chris@186 26 {
Chris@186 27 Q_OBJECT
Chris@186 28
Chris@186 29 Q_PROPERTY(bool mouseUnderline READ mouseUnderline WRITE setMouseUnderline)
Chris@186 30
Chris@186 31 public:
Chris@186 32 ClickableLabel(const QString &text, QWidget *parent = 0) :
Chris@523 33 SqueezedLabel(text, parent),
Chris@186 34 m_naturalText(text)
Chris@186 35 { }
Chris@186 36
Chris@186 37 ClickableLabel(QWidget *parent = 0) :
Chris@523 38 SqueezedLabel(parent)
Chris@186 39 { }
Chris@186 40
Chris@186 41 ~ClickableLabel()
Chris@186 42 { }
Chris@186 43
Chris@186 44 void setText(const QString &t) {
Chris@186 45 m_naturalText = t;
Chris@523 46 SqueezedLabel::setText(t);
Chris@186 47 }
Chris@186 48
Chris@186 49 bool mouseUnderline() const {
Chris@186 50 return m_mouseUnderline;
Chris@186 51 }
Chris@186 52
Chris@186 53 void setMouseUnderline(bool mu) {
Chris@186 54 m_mouseUnderline = mu;
Chris@187 55 if (mu) {
Chris@187 56 setTextFormat(Qt::RichText);
Chris@187 57 setCursor(Qt::PointingHandCursor);
Chris@187 58 }
Chris@186 59 }
Chris@186 60
Chris@186 61 signals:
Chris@186 62 void clicked();
Chris@186 63
Chris@186 64 protected:
Chris@186 65 virtual void enterEvent(QEvent *) {
Chris@186 66 if (m_mouseUnderline) {
Chris@523 67 SqueezedLabel::setText(tr("<u>%1</u>").arg(m_naturalText));
Chris@186 68 }
Chris@186 69 }
Chris@186 70
Chris@186 71 virtual void leaveEvent(QEvent *) {
Chris@186 72 if (m_mouseUnderline) {
Chris@523 73 SqueezedLabel::setText(m_naturalText);
Chris@186 74 }
Chris@186 75 }
Chris@186 76
Chris@523 77 virtual void mousePressEvent(QMouseEvent *ev) {
Chris@523 78 if (ev->button() == Qt::LeftButton) {
Chris@523 79 emit clicked();
Chris@523 80 } else {
Chris@523 81 SqueezedLabel::mousePressEvent(ev);
Chris@523 82 }
Chris@186 83 }
Chris@186 84
Chris@186 85 private:
Chris@186 86 bool m_mouseUnderline;
Chris@186 87 QString m_naturalText;
Chris@186 88 };
Chris@186 89
Chris@186 90 #endif