]> git.sesse.net Git - vlc/blob - modules/gui/qt4/util/customwidgets.hpp
Qt4: replace Podcast add / remove buttons with plain icons
[vlc] / modules / gui / qt4 / util / customwidgets.hpp
1 /*****************************************************************************
2  * customwidgets.h: Custom widgets
3  ****************************************************************************
4  * Copyright (C) 2006 the VideoLAN team
5  * Copyright (C) 2004 Daniel Molkentin <molkentin@kde.org>
6  * $Id$
7  *
8  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
9  * The "ClickLineEdit" control is based on code by  Daniel Molkentin
10  * <molkentin@kde.org> for libkdepim
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 2 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
25  *****************************************************************************/
26
27 #ifndef _CUSTOMWIDGETS_H_
28 #define _CUSTOMWIDGETS_H_
29
30 #include <QLineEdit>
31 #include <QLabel>
32 #include <QIcon>
33
34 /**
35   This class provides a QLineEdit which contains a greyed-out hinting
36   text as long as the user didn't enter any text
37
38   @short LineEdit with customizable "Click here" text
39   @author Daniel Molkentin
40 */
41 class ClickLineEdit : public QLineEdit
42 {
43     Q_OBJECT
44     Q_PROPERTY( QString clickMessage READ clickMessage WRITE setClickMessage )
45 public:
46     ClickLineEdit( const QString &msg, QWidget *parent );
47     virtual ~ClickLineEdit() {};
48     void setClickMessage( const QString &msg );
49     QString clickMessage() const { return mClickMessage; }
50     virtual void setText( const QString& txt );
51 protected:
52     virtual void paintEvent( QPaintEvent *e );
53     virtual void dropEvent( QDropEvent *ev );
54     virtual void focusInEvent( QFocusEvent *ev );
55     virtual void focusOutEvent( QFocusEvent *ev );
56 private:
57     QString mClickMessage;
58     bool mDrawClickMsg;
59 };
60
61 class QToolButton;
62 class SearchLineEdit : public QFrame
63 {
64     Q_OBJECT
65 public:
66     SearchLineEdit( QWidget *parent );
67
68 private:
69     ClickLineEdit *searchLine;
70     QToolButton   *clearButton;
71
72 private slots:
73     void updateText( const QString& );
74
75 signals:
76     void textChanged( const QString& );
77 };
78
79 class QVLCIconLabel : public QLabel
80 {
81     Q_OBJECT
82 public:
83     QVLCIconLabel( const QIcon&, QWidget *parent = 0 );
84     void setIcon( const QIcon& );
85 signals:
86     void clicked();
87 protected:
88     virtual void enterEvent( QEvent * );
89     virtual void leaveEvent( QEvent * );
90     virtual void mouseReleaseEvent( QMouseEvent * );
91 private:
92     inline QSize pixmapSize( QIcon::Mode = QIcon::Normal, QIcon::State = QIcon::Off );
93     QIcon icon;
94 };
95
96 /*****************************************************************
97  * Custom views
98  *****************************************************************/
99 #include <QMouseEvent>
100 #include <QTreeView>
101 #include <QCursor>
102 #include <QPoint>
103 #include <QModelIndex>
104
105 /**
106   Special QTreeView that can emit rightClicked()
107   */
108 class QVLCTreeView : public QTreeView
109 {
110     Q_OBJECT;
111 public:
112     void mouseReleaseEvent( QMouseEvent* e )
113     {
114         if( e->button() & Qt::RightButton )
115             return; /* Do NOT forward to QTreeView!! */
116         QTreeView::mouseReleaseEvent( e );
117     }
118
119     void mousePressEvent( QMouseEvent* e )
120     {
121         if( e->button() & Qt::RightButton )
122         {
123             QModelIndex index = indexAt( QPoint( e->x(), e->y() ) );
124             if( index.isValid() )
125                 setSelection( visualRect( index ), QItemSelectionModel::ClearAndSelect );
126             emit rightClicked( index, QCursor::pos() );
127             return;
128         }
129         if( e->button() & Qt::LeftButton )
130         {
131             if( !indexAt( QPoint( e->x(), e->y() ) ).isValid() )
132                 clearSelection();
133         }
134         QTreeView::mousePressEvent( e );
135     }
136
137 signals:
138     void rightClicked( QModelIndex, QPoint  );
139 };
140
141 /* VLC Key/Wheel hotkeys interactions */
142
143 class QKeyEvent;
144 class QWheelEvent;
145
146 int qtKeyModifiersToVLC( QInputEvent* e );
147 int qtEventToVLCKey( QKeyEvent *e );
148 int qtWheelEventToVLCKey( QWheelEvent *e );
149 QString VLCKeyToString( int val );
150
151 #endif
152