PageRenderTime 102ms CodeModel.GetById 40ms app.highlight 6ms RepoModel.GetById 54ms app.codeStats 0ms

/src/libtomahawk/widgets/ElidedLabel.h

http://github.com/tomahawk-player/tomahawk
C Header | 81 lines | 47 code | 17 blank | 17 comment | 0 complexity | 84bb42617b8cc9285e8923fbd89d4470 MD5 | raw file
 1/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
 2 *
 3 *   Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
 4 *
 5 *   Tomahawk is free software: you can redistribute it and/or modify
 6 *   it under the terms of the GNU General Public License as published by
 7 *   the Free Software Foundation, either version 3 of the License, or
 8 *   (at your option) any later version.
 9 *
10 *   Tomahawk is distributed in the hope that it will be useful,
11 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
12 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 *   GNU General Public License for more details.
14 *
15 *   You should have received a copy of the GNU General Public License
16 *   along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#ifndef ELIDEDLABEL_H
20#define ELIDEDLABEL_H
21
22#include <QFrame>
23#include <QTime>
24
25#include "DllMacro.h"
26
27class DLLEXPORT ElidedLabel : public QFrame
28{
29    Q_OBJECT
30    Q_PROPERTY( QString text READ text WRITE setText NOTIFY textChanged )
31    Q_PROPERTY( Qt::Alignment alignment READ alignment WRITE setAlignment )
32    Q_PROPERTY( Qt::TextElideMode elideMode READ elideMode WRITE setElideMode )
33
34public:
35    explicit ElidedLabel( QWidget* parent = 0, Qt::WindowFlags flags = 0 );
36    explicit ElidedLabel( const QString& text, QWidget* parent = 0, Qt::WindowFlags flags = 0 );
37    virtual ~ElidedLabel();
38
39    QString text() const;
40
41    Qt::Alignment alignment() const;
42    void setAlignment( Qt::Alignment alignment );
43
44    Qt::TextElideMode elideMode() const;
45    void setElideMode( Qt::TextElideMode mode );
46
47    void setFont( const QFont& font );
48
49    void setMargin( int margin );
50    int margin() const;
51
52    virtual QSize sizeHint() const;
53    virtual QSize minimumSizeHint() const;
54
55    void init( const QString& txt = QString() );
56    void updateLabel();
57
58public slots:
59    void setText( const QString& text );
60    void setWordWrap( bool b ) { m_multiLine = b; }
61
62signals:
63    void clicked();
64    void textChanged( const QString& text );
65
66protected:
67    virtual void changeEvent( QEvent* event );
68    virtual void mousePressEvent( QMouseEvent* event );
69    virtual void mouseReleaseEvent( QMouseEvent* event );
70    virtual void paintEvent( QPaintEvent* event );
71
72private:
73    QTime m_time;
74    QString m_text;
75    Qt::Alignment m_align;
76    Qt::TextElideMode m_mode;
77    int m_margin;
78    bool m_multiLine;
79};
80
81#endif // ELIDEDLABEL_H