]> git.sesse.net Git - vlc/blob - modules/gui/qt4/util/searchlineedit.hpp
Qt: EPG gui self update
[vlc] / modules / gui / qt4 / util / searchlineedit.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 _SEARCHLINEEDIT_H_
28 #define _SEARCHLINEEDIT_H_
29
30 #include "qt4.hpp"
31 #include <QLineEdit>
32
33 #if HAS_QT47
34 class ClickLineEdit : public QLineEdit
35 {
36     Q_OBJECT
37 public:
38     ClickLineEdit( const QString &msg, QWidget *parent ) : QLineEdit( parent )
39     {
40         QLineEdit::setPlaceholderText ( msg );
41     }
42 };
43 #else
44 /**
45   This class provides a QLineEdit which contains a greyed-out hinting
46   text as long as the user didn't enter any text
47
48   @short LineEdit with customizable "Click here" text
49   @author Daniel Molkentin
50 */
51 class ClickLineEdit : public QLineEdit
52 {
53     Q_OBJECT
54     Q_PROPERTY( QString clickMessage READ placeholderText WRITE setPlaceholderText )
55 public:
56     ClickLineEdit( const QString &msg, QWidget *parent );
57     void setPlaceholderText( const QString &msg );
58     const QString& placeholderText() const { return mClickMessage; }
59     virtual void setText( const QString& txt );
60 protected:
61     virtual void paintEvent( QPaintEvent *e );
62     virtual void dropEvent( QDropEvent *ev );
63     virtual void focusInEvent( QFocusEvent *ev );
64     virtual void focusOutEvent( QFocusEvent *ev );
65 private:
66     QString mClickMessage;
67     bool mDrawClickMsg;
68 };
69 #endif
70
71 #ifndef Q_WS_MAC
72 class QFramelessButton;
73 class SearchLineEdit : public QLineEdit
74 {
75     Q_OBJECT
76 public:
77     SearchLineEdit( QWidget *parent = NULL );
78
79 private:
80     void resizeEvent ( QResizeEvent * event );
81     void focusInEvent( QFocusEvent *event );
82     void focusOutEvent( QFocusEvent *event );
83     void paintEvent( QPaintEvent *event );
84     void setMessageVisible( bool on );
85     QFramelessButton   *clearButton;
86     bool message;
87
88 public slots:
89     void clear();
90
91 private slots:
92     void updateText( const QString& );
93     void searchEditingFinished();
94
95 signals:
96     void searchDelayedChanged( const QString& );
97 };
98 #else
99
100 /* On Mac, we try to use the native NSSearchField */
101 #include <QMacCocoaViewContainer>
102
103 class SearchLineEdit : public QMacCocoaViewContainer
104 {
105     Q_OBJECT
106
107 public:
108     SearchLineEdit(QWidget *parent = 0);
109     virtual ~SearchLineEdit() {}
110
111     virtual QSize sizeHint() const { return QSize(150, 40); }
112
113 public slots:
114     void clear() {}
115
116 signals:
117     void searchDelayedChanged( const QString& );
118     void textEdited( const QString& );
119 };
120 #endif
121
122 #endif
123