Chris@523: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@523: Chris@523: /* Chris@523: EasyMercurial Chris@523: Chris@523: Based on HgExplorer by Jari Korhonen Chris@523: Copyright (c) 2010 Jari Korhonen Chris@644: Copyright (c) 2013 Chris Cannam Chris@644: Copyright (c) 2013 Queen Mary, University of London Chris@523: Chris@523: This program is free software; you can redistribute it and/or Chris@523: modify it under the terms of the GNU General Public License as Chris@523: published by the Free Software Foundation; either version 2 of the Chris@523: License, or (at your option) any later version. See the file Chris@523: COPYING included with this distribution for more information. Chris@523: */ Chris@523: Chris@523: /* Chris@523: This file adapted from Rosegarden, a sequencer and musical Chris@560: notation editor. Copyright 2000-2012 the Rosegarden development Chris@523: team. Chris@523: Chris@523: Adapted from KDE 4.2.0, this code originally Copyright (c) 2000 Chris@523: Ronny Standtke. Chris@523: */ Chris@523: Chris@523: #ifndef _SQUEEZED_LABEL_H_ Chris@523: #define _SQUEEZED_LABEL_H_ Chris@523: Chris@523: #include Chris@523: Chris@523: class SqueezedLabelPrivate; Chris@523: Chris@523: /** Chris@523: * @short A replacement for QLabel that squeezes its text Chris@523: * Chris@523: * A label class that squeezes its text into the label Chris@523: * Chris@523: * If the text is too long to fit into the label it is divided into Chris@523: * remaining left and right parts which are separated by three dots. Chris@523: */ Chris@523: Chris@523: class SqueezedLabel : public QLabel Chris@523: { Chris@523: Q_OBJECT Chris@523: Q_PROPERTY(Qt::TextElideMode textElideMode READ textElideMode WRITE setTextElideMode) Chris@523: Chris@523: public: Chris@523: /** Chris@523: * Default constructor. Chris@523: */ Chris@523: explicit SqueezedLabel(QWidget *parent = 0); Chris@523: explicit SqueezedLabel(const QString &text, QWidget *parent = 0); Chris@523: Chris@523: virtual ~SqueezedLabel(); Chris@523: Chris@523: virtual QSize minimumSizeHint() const; Chris@523: virtual QSize sizeHint() const; Chris@523: /** Chris@523: * Overridden for internal reasons; the API remains unaffected. Chris@523: */ Chris@523: virtual void setAlignment(Qt::Alignment); Chris@523: Chris@523: /** Chris@523: * Returns the text elide mode. Chris@523: */ Chris@523: Qt::TextElideMode textElideMode() const; Chris@523: Chris@523: /** Chris@523: * Sets the text elide mode. Chris@523: * @param mode The text elide mode. Chris@523: */ Chris@523: void setTextElideMode(Qt::TextElideMode mode); Chris@523: Chris@523: public Q_SLOTS: Chris@523: /** Chris@523: * Sets the text. Note that this is not technically a reimplementation of QLabel::setText(), Chris@523: * which is not virtual (in Qt 4.3). Therefore, you may need to cast the object to Chris@523: * SqueezedLabel in some situations: Chris@523: * \Example Chris@523: * \code Chris@523: * SqueezedLabel* squeezed = new SqueezedLabel("text", parent); Chris@523: * QLabel* label = squeezed; Chris@523: * label->setText("new text"); // this will not work Chris@523: * squeezed->setText("new text"); // works as expected Chris@523: * static_cast(label)->setText("new text"); // works as expected Chris@523: * \endcode Chris@523: * @param mode The new text. Chris@523: */ Chris@523: void setText(const QString &text); Chris@523: /** Chris@523: * Clears the text. Same remark as above. Chris@523: * Chris@523: */ Chris@523: void clear(); Chris@523: Chris@523: protected: Chris@523: /** Chris@523: * Called when widget is resized Chris@523: */ Chris@523: void resizeEvent(QResizeEvent *); Chris@523: /** Chris@523: * \reimp Chris@523: */ Chris@523: void contextMenuEvent(QContextMenuEvent*); Chris@523: /** Chris@523: * does the dirty work Chris@523: */ Chris@523: void squeezeTextToLabel(); Chris@523: Chris@523: private slots: Chris@523: void _k_copyFullText(); Chris@523: Chris@523: private: Chris@523: QString fullText; Chris@523: Qt::TextElideMode elideMode; Chris@523: }; Chris@523: Chris@523: Chris@523: #endif