libkdepim Library API Documentation

clicklineedit.cpp

00001 /* 00002 This file is part of libkdepim. 00003 Copyright (c) 2004 Daniel Molkentin <molkentin@kde.org> 00004 based on code by Cornelius Schumacher <schumacher@kde.org> 00005 00006 This library is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU Library General Public 00008 License as published by the Free Software Foundation; either 00009 version 2 of the License, or (at your option) any later version. 00010 00011 This library is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 Library General Public License for more details. 00015 00016 You should have received a copy of the GNU Library General Public License 00017 along with this library; see the file COPYING.LIB. If not, write to 00018 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00019 Boston, MA 02111-1307, USA. 00020 */ 00021 00022 00023 #include "clicklineedit.h" 00024 00025 #include "qpainter.h" 00026 00027 using namespace KPIM; 00028 00029 ClickLineEdit::ClickLineEdit(QWidget *parent, const QString &msg, const char* name) : 00030 KLineEdit(parent, name) 00031 { 00032 mDrawClickMsg = true; 00033 setClickMessage( msg ); 00034 } 00035 00036 ClickLineEdit::~ClickLineEdit() {} 00037 00038 00039 void ClickLineEdit::setClickMessage( const QString &msg ) 00040 { 00041 mClickMessage = msg; 00042 repaint(); 00043 } 00044 00045 void ClickLineEdit::setText( const QString &txt ) 00046 { 00047 mDrawClickMsg = txt.isEmpty(); 00048 repaint(); 00049 KLineEdit::setText( txt ); 00050 } 00051 00052 void ClickLineEdit::drawContents( QPainter *p ) 00053 { 00054 KLineEdit::drawContents( p ); 00055 00056 if ( mDrawClickMsg == true && !hasFocus() ) { 00057 QPen tmp = p->pen(); 00058 p->setPen( gray ); 00059 QRect cr = contentsRect(); 00060 p->drawText( cr, AlignAuto|AlignVCenter, mClickMessage ); 00061 p->setPen( tmp ); 00062 } 00063 } 00064 00065 void ClickLineEdit::focusInEvent( QFocusEvent *ev ) 00066 { 00067 if ( mDrawClickMsg == true ) 00068 { 00069 mDrawClickMsg = false; 00070 repaint(); 00071 } 00072 QLineEdit::focusInEvent( ev ); 00073 } 00074 00075 void ClickLineEdit::focusOutEvent( QFocusEvent *ev ) 00076 { 00077 if ( text().isEmpty() ) 00078 { 00079 mDrawClickMsg = true; 00080 repaint(); 00081 } 00082 QLineEdit::focusOutEvent( ev ); 00083 } 00084 00085 #include "clicklineedit.moc"
KDE Logo
This file is part of the documentation for libkdepim Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Oct 1 15:18:55 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003