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