PageRenderTime 395ms CodeModel.GetById 110ms app.highlight 93ms RepoModel.GetById 109ms app.codeStats 1ms

/src/sourcetree/sourcedelegate.h

http://github.com/tomahawk-player/tomahawk
C++ Header | 88 lines | 53 code | 15 blank | 20 comment | 0 complexity | a6568b2add5094b404add25effd34ca9 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 *   Copyright 2011, Leo Franchi <lfranchi@kde.org>
 5 *   Copyright 2011, Michael Zanetti <mzanetti@kde.org>
 6 *   Copyright 2010-2012, Jeff Mitchell <jeff@tomahawk-player.org>
 7 *
 8 *   Tomahawk is free software: you can redistribute it and/or modify
 9 *   it under the terms of the GNU General Public License as published by
10 *   the Free Software Foundation, either version 3 of the License, or
11 *   (at your option) any later version.
12 *
13 *   Tomahawk is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#ifndef SOURCEDELEGATE_H
23#define SOURCEDELEGATE_H
24
25#include "SourceTreeView.h"
26#include "items/SourceTreeItem.h"
27
28#include <QStyledItemDelegate>
29#include <QPropertyAnimation>
30
31class AnimationHelper;
32
33class SourceDelegate : public QStyledItemDelegate
34{
35    Q_OBJECT
36public:
37    SourceDelegate( QAbstractItemView* parent = 0 );
38    ~SourceDelegate();
39
40    void hovered( const QModelIndex &index, const QMimeData *mimeData );
41    void dragLeaveEvent();
42
43    SourceTreeItem::DropType hoveredDropType() const;
44
45signals:
46    void clicked( const QModelIndex& idx );
47    void doubleClicked( const QModelIndex& idx );
48    void latchOn( const Tomahawk::source_ptr& idx );
49    void latchOff( const Tomahawk::source_ptr& idx );
50    void toggleRealtimeLatch( const Tomahawk::source_ptr& idx, bool realtime );
51
52protected:
53    virtual QSize sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const;
54    virtual void paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
55    virtual void updateEditorGeometry( QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
56    virtual int dropTypeCount( SourceTreeItem* item ) const;
57    virtual bool editorEvent( QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index );
58
59private slots:
60    void animationFinished( const QModelIndex& );
61
62private:
63    void paintDecorations( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
64    void paintCollection( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
65    void paintCategory( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
66    void paintGroup( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
67
68    QAbstractItemView* m_parent;
69    mutable int m_iconHeight;
70    QModelIndex m_dropHoverIndex;
71    QModelIndex m_newDropHoverIndex;
72    QMimeData *m_dropMimeData;
73    mutable SourceTreeItem::DropType m_hoveredDropType; // Hack to keep easily track of the current highlighted DropType in paint()
74    QMap< QModelIndex, AnimationHelper* > m_expandedMap;
75    QPixmap m_headphonesOn, m_headphonesOff, m_realtimeLocked, m_realtimeUnlocked, m_nowPlayingSpeaker, m_nowPlayingSpeakerDark, m_collaborativeOn;
76    qint64 m_lastClicked;
77    QMap< int, SourceTreeItem::DropType > m_dropTypeMap;
78    QMap< int, QString > m_dropTypeTextMap;
79    QMap< int, QPixmap > m_dropTypeImageMap;
80
81    mutable QHash< QPersistentModelIndex, QRect > m_trackRects;
82    mutable QHash< QPersistentModelIndex, QRect > m_headphoneRects;
83    mutable QHash< QPersistentModelIndex, QRect > m_lockRects;
84
85    mutable QLinearGradient m_gradient;
86};
87
88#endif // SOURCEDELEGATE_H