/src/libtomahawk/widgets/QueryLabel.h

http://github.com/tomahawk-player/tomahawk · C Header · 122 lines · 77 code · 28 blank · 17 comment · 0 complexity · 0398061a933bcd689355f886e921d7b7 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 QUERYLABEL_H
  19. #define QUERYLABEL_H
  20. #include <QLabel>
  21. #include <QTime>
  22. #include "Result.h"
  23. #include "Query.h"
  24. #include "Typedefs.h"
  25. #include "DllMacro.h"
  26. namespace Tomahawk
  27. {
  28. class ContextMenu;
  29. };
  30. class DLLEXPORT QueryLabel : public QLabel
  31. {
  32. Q_OBJECT
  33. public:
  34. enum DisplayType
  35. {
  36. None = 0,
  37. Artist = 1,
  38. Album = 2,
  39. Track = 4,
  40. };
  41. explicit QueryLabel( QWidget* parent = 0, Qt::WindowFlags flags = 0 );
  42. explicit QueryLabel( DisplayType type, QWidget* parent = 0, Qt::WindowFlags flags = 0 );
  43. explicit QueryLabel( const Tomahawk::result_ptr& result, DisplayType type = None, QWidget* parent = 0, Qt::WindowFlags flags = 0 );
  44. explicit QueryLabel( const Tomahawk::query_ptr& query, DisplayType type = None, QWidget* parent = 0, Qt::WindowFlags flags = 0 );
  45. virtual ~QueryLabel();
  46. QString text() const;
  47. Tomahawk::result_ptr result() const { return m_result; }
  48. Tomahawk::query_ptr query() const { return m_query; }
  49. Tomahawk::artist_ptr artist() const;
  50. Tomahawk::album_ptr album() const;
  51. DisplayType type() const { return m_type; }
  52. void setType( DisplayType type );
  53. Qt::TextElideMode elideMode() const;
  54. void setElideMode( Qt::TextElideMode mode );
  55. virtual QSize sizeHint() const;
  56. virtual QSize minimumSizeHint() const;
  57. void init();
  58. public slots:
  59. void clear();
  60. void setText( const QString& text );
  61. void setResult( const Tomahawk::result_ptr& result );
  62. void setQuery( const Tomahawk::query_ptr& query );
  63. void setArtist( const Tomahawk::artist_ptr& artist );
  64. void setAlbum( const Tomahawk::album_ptr& album );
  65. signals:
  66. void clicked();
  67. void textChanged( const QString& text );
  68. void resultChanged( const Tomahawk::result_ptr& result );
  69. void queryChanged( const Tomahawk::query_ptr& query );
  70. protected:
  71. virtual void contextMenuEvent( QContextMenuEvent* event );
  72. virtual void mousePressEvent( QMouseEvent* event );
  73. virtual void mouseReleaseEvent( QMouseEvent* event );
  74. virtual void mouseMoveEvent( QMouseEvent* event );
  75. virtual void leaveEvent( QEvent* event );
  76. virtual void changeEvent( QEvent* event );
  77. virtual void paintEvent( QPaintEvent* event );
  78. virtual void startDrag();
  79. private slots:
  80. void onResultChanged();
  81. private:
  82. QTime m_time;
  83. DisplayType m_type;
  84. QString m_text;
  85. Tomahawk::result_ptr m_result;
  86. Tomahawk::query_ptr m_query;
  87. Tomahawk::artist_ptr m_artist;
  88. Tomahawk::album_ptr m_album;
  89. Tomahawk::ContextMenu* m_contextMenu;
  90. Qt::TextElideMode m_mode;
  91. QPoint m_dragPos;
  92. bool m_hovering;
  93. };
  94. #endif // QUERYLABEL_H