PageRenderTime 472ms CodeModel.GetById 127ms app.highlight 190ms RepoModel.GetById 63ms app.codeStats 16ms

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