1 /*****************************************************************************
2 * customwidgets.cpp: Custom widgets
3 ****************************************************************************
4 * Copyright (C) 2006 the VideoLAN team
5 * Copyright (C) 2004 Daniel Molkentin <molkentin@kde.org>
6 * $Id: qvlcframe.hpp 16283 2006-08-17 18:16:09Z zorglub $
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
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.
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.
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. *****************************************************************************/
26 #include "customwidgets.hpp"
30 #include <QColorGroup>
33 ClickLineEdit::ClickLineEdit( const QString &msg, QWidget *parent) : QLineEdit( parent )
36 setClickMessage( msg );
39 void ClickLineEdit::setClickMessage( const QString &msg )
46 void ClickLineEdit::setText( const QString &txt )
48 mDrawClickMsg = txt.isEmpty();
50 QLineEdit::setText( txt );
53 void ClickLineEdit::paintEvent( QPaintEvent *pe )
56 QLineEdit::paintEvent( pe );
57 if ( mDrawClickMsg == true && !hasFocus() ) {
59 p.setPen( palette().color( QPalette::Disabled, QPalette::Text ) );
60 QRect cr = contentsRect();
61 // Add two pixel margin on the left side
62 cr.setLeft( cr.left() + 3 );
63 p.drawText( cr, Qt::AlignLeft | Qt::AlignVCenter, mClickMessage );
68 void ClickLineEdit::dropEvent( QDropEvent *ev )
70 mDrawClickMsg = false;
71 QLineEdit::dropEvent( ev );
75 void ClickLineEdit::focusInEvent( QFocusEvent *ev )
77 if ( mDrawClickMsg == true ) {
78 mDrawClickMsg = false;
81 QLineEdit::focusInEvent( ev );
85 void ClickLineEdit::focusOutEvent( QFocusEvent *ev )
87 if ( text().isEmpty() ) {
91 QLineEdit::focusOutEvent( ev );