/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. #ifndef ELIDEDLABEL_H
  19. #define ELIDEDLABEL_H
  20. #include <QFrame>
  21. #include <QTime>
  22. #include "DllMacro.h"
  23. class DLLEXPORT ElidedLabel : public QFrame
  24. {
  25. Q_OBJECT
  26. Q_PROPERTY( QString text READ text WRITE setText NOTIFY textChanged )
  27. Q_PROPERTY( Qt::Alignment alignment READ alignment WRITE setAlignment )
  28. Q_PROPERTY( Qt::TextElideMode elideMode READ elideMode WRITE setElideMode )
  29. public:
  30. explicit ElidedLabel( QWidget* parent = 0, Qt::WindowFlags flags = 0 );
  31. explicit ElidedLabel( const QString& text, QWidget* parent = 0, Qt::WindowFlags flags = 0 );
  32. virtual ~ElidedLabel();
  33. QString text() const;
  34. Qt::Alignment alignment() const;
  35. void setAlignment( Qt::Alignment alignment );
  36. Qt::TextElideMode elideMode() const;
  37. void setElideMode( Qt::TextElideMode mode );
  38. void setFont( const QFont& font );
  39. void setMargin( int margin );
  40. int margin() const;
  41. virtual QSize sizeHint() const;
  42. virtual QSize minimumSizeHint() const;
  43. void init( const QString& txt = QString() );
  44. void updateLabel();
  45. public slots:
  46. void setText( const QString& text );
  47. void setWordWrap( bool b ) { m_multiLine = b; }
  48. signals:
  49. void clicked();
  50. void textChanged( const QString& text );
  51. protected:
  52. virtual void changeEvent( QEvent* event );
  53. virtual void mousePressEvent( QMouseEvent* event );
  54. virtual void mouseReleaseEvent( QMouseEvent* event );
  55. virtual void paintEvent( QPaintEvent* event );
  56. private:
  57. QTime m_time;
  58. QString m_text;
  59. Qt::Alignment m_align;
  60. Qt::TextElideMode m_mode;
  61. int m_margin;
  62. bool m_multiLine;
  63. };
  64. #endif // ELIDEDLABEL_H