selector.hpp 4.07 KB
Newer Older
zorglub's avatar
zorglub committed
1
2
3
/*****************************************************************************
 * selector.hpp : Playlist source selector
 ****************************************************************************
4
 * Copyright (C) 2000-2009 the VideoLAN team
5
 * $Id$
zorglub's avatar
zorglub committed
6
7
 *
 * Authors: Clément Stenac <zorglub@videolan.org>
8
 *          Jean-Baptiste Kempf
zorglub's avatar
zorglub committed
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

#ifndef _PLSEL_H_
#define _PLSEL_H_

Christophe Mutricy's avatar
Christophe Mutricy committed
28
29
30
31
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

32
#include "qt4.hpp"
33
#include "util/customwidgets.hpp" /* QFramelessButton */
34

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
35
36
37
38
39
#include <QTreeWidget>

class QHBoxLayout;
class QPainter;
class QTreeWidgetItem;
40
class PlaylistWidget;
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
41
class QLabel;
zorglub's avatar
zorglub committed
42

43
44
enum SelectorItemType {
    CATEGORY_TYPE,
45
    SD_TYPE,
46
    PL_ITEM_TYPE,
47
    SQL_ML_TYPE,
48
49
50
51
52
53
};

enum SpecialData {
    IS_PODCAST = 1,
    IS_PL,
    IS_ML
54
55
};

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
56
enum {
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
57
58
59
60
61
62
63
    TYPE_ROLE = Qt::UserRole + 1,
    NAME_ROLE,           //QString
    LONGNAME_ROLE,       //QString
    PL_ITEM_ROLE,        //playlist_item_t*
    PL_ITEM_ID_ROLE,     //playlist_item_t->i_id
    IN_ITEM_ROLE,        //input_item_t->i_id
    SPECIAL_ROLE         //SpecialData
64
65
66
67
68
69
70
};

enum ItemAction {
    ADD_ACTION,
    RM_ACTION
};

jpd's avatar
jpd committed
71

72
class SelectorActionButton : public QFramelessButton
jpd's avatar
jpd committed
73
{
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
74
75
protected:
    virtual void paintEvent( QPaintEvent * );
jpd's avatar
jpd committed
76
77
};

78
79
class PLSelItem : public QWidget
{
François Cartegnie's avatar
François Cartegnie committed
80
    Q_OBJECT
81
82
public:
    PLSelItem( QTreeWidgetItem*, const QString& );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
83
84

    void setText( const QString& text ) { lbl->setText( text ); }
85
    QString text() const { return lbl->text(); }
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
86

87
88
    void addAction( ItemAction, const QString& toolTip = 0 );
    QTreeWidgetItem *treeItem() { return qitem; }
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
89

90
public slots:
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
91
92
93
    void showAction() { if( lblAction ) lblAction->show();  }
    void hideAction() { if( lblAction ) lblAction->hide(); }

94
95
private slots:
    void triggerAction() { emit action( this ); }
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
96

97
98
signals:
    void action( PLSelItem* );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
99

100
private:
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
101
102
103
    inline void enterEvent( QEvent* ){ showAction(); }
    inline void leaveEvent( QEvent* ){ hideAction(); }

104
    QTreeWidgetItem*     qitem;
105
    QFramelessButton* lblAction;
106
107
    QLabel*              lbl;
    QHBoxLayout*         layout;
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
108
109
};

110
Q_DECLARE_METATYPE( playlist_item_t *);
111
Q_DECLARE_METATYPE( input_item_t *);
112
class PLSelector: public QTreeWidget
zorglub's avatar
zorglub committed
113
{
François Cartegnie's avatar
François Cartegnie committed
114
    Q_OBJECT
zorglub's avatar
zorglub committed
115
public:
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
116
    PLSelector( QWidget *p, intf_thread_t *_p_intf );
zorglub's avatar
zorglub committed
117
    virtual ~PLSelector();
118
119

    void getCurrentSelectedItem( int *type, QString *name );
120

121
protected:
122
123
124
125
    virtual void drawBranches ( QPainter *, const QRect &, const QModelIndex & ) const;
    virtual void dragMoveEvent ( QDragMoveEvent * event );
    virtual bool dropMimeData ( QTreeWidgetItem *, int, const QMimeData *, Qt::DropAction );
    virtual QStringList mimeTypes () const;
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
126

zorglub's avatar
zorglub committed
127
private:
128
    void createItems();
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
129
130
    PLSelItem * addItem ( SelectorItemType type, const char* str,
            bool drop = false, QTreeWidgetItem* parentItem = 0 );
131
    PLSelItem * addPodcastItem( playlist_item_t *p_item );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
132

133
    inline PLSelItem * itemWidget( QTreeWidgetItem * );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
134
135
136
137
138

    intf_thread_t    *p_intf;
    QTreeWidgetItem  *podcastsParent;
    int               podcastsParentId;

zorglub's avatar
zorglub committed
139
private slots:
140
    void setSource( QTreeWidgetItem *item );
141
142
143
144
145
146
    void plItemAdded( int, int );
    void plItemRemoved( int );
    void inputItemUpdate( input_item_t * );
    void podcastAdd( PLSelItem* );
    void podcastRemove( PLSelItem* );

zorglub's avatar
zorglub committed
147
signals:
148
    void categoryActivated( playlist_item_t *, bool );
zorglub's avatar
zorglub committed
149
150
151
};

#endif