libkdepim
clicklineedit.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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( palette().color( QPalette::Disabled, QColorGroup::Text ) );
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"
|