[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    Merge of clicklineedit class into kdelibs 3.5.4
From:       Stephan Binner <binner () kde ! org>
Date:       2006-06-12 12:13:47
Message-ID: 200606121413.48400.binner () kde ! org
[Download RAW message or body]

Hello,

I would like to see the functionality of the ClickLineEdit class as used in 
libkdepim, as copy in Amarok and being merged in trunk since January merged
in kdelibs 3.5.4. It would allow many easy usability improvements like [1].

Comments? :-)

Bye,
   Steve

[1] http://developer.kde.org/~binner/searchbar-clickmessage.diff

["klineedit-setclickmessage.diff" (text/x-diff)]

Index: klineedit.cpp
===================================================================
--- klineedit.cpp	(revision 550560)
+++ klineedit.cpp	(working copy)
@@ -26,6 +26,7 @@
 */
 
 #include <qclipboard.h>
+#include <qpainter.h>
 #include <qtimer.h>
 
 #include <kconfig.h>
@@ -93,6 +94,9 @@
     BackgroundMode bgMode;
     QString squeezedText;
     KCompletionBox *completionBox;
+
+    QString mClickMessage;
+    bool mDrawClickMsg:1;
 };
 
 bool KLineEdit::KLineEditPrivate::backspacePerformsCompletion = false;
@@ -139,6 +143,8 @@
       d->previousHighlightedTextColor=p.color(QPalette::Normal,QColorGroup::HighlightedText);
     if ( !d->previousHighlightColor.isValid() )
       d->previousHighlightColor=p.color(QPalette::Normal,QColorGroup::Highlight);
+
+    d->mDrawClickMsg = false;
 }
 
 void KLineEdit::setCompletionMode( KGlobalSettings::Completion mode )
@@ -303,6 +309,9 @@
 
 void KLineEdit::setText( const QString& text )
 {
+    d->mDrawClickMsg = text.isEmpty() && !d->mClickMessage.isEmpty();
+    repaint();
+
     if( d->enableSqueezedText && isReadOnly() )
     {
         d->squeezedText = text;
@@ -939,8 +948,25 @@
     }
 }
 
+void KLineEdit::drawContents( QPainter *p )
+{
+    QLineEdit::drawContents( p );
+
+    if ( d->mDrawClickMsg && !hasFocus() ) {
+        QPen tmp = p->pen();
+        p->setPen( palette().color( QPalette::Disabled, QColorGroup::Text ) );
+        QRect cr = contentsRect();
+
+        // Add two pixel margin on the left side
+        cr.rLeft() += 3;
+        p->drawText( cr, AlignAuto | AlignVCenter, d->mClickMessage );
+        p->setPen( tmp );
+    }
+}
+
 void KLineEdit::dropEvent(QDropEvent *e)
 {
+    d->mDrawClickMsg = false;
     KURL::List urlList;
     if( d->handleURLDrops && KURLDrag::decode( e, urlList ) )
     {
@@ -1298,6 +1324,11 @@
 
 void KLineEdit::focusInEvent( QFocusEvent* ev)
 {
+    if ( d->mDrawClickMsg ) {
+        d->mDrawClickMsg = false;
+        repaint();
+    }
+
     // Don't selectAll() in QLineEdit::focusInEvent if selection exists
     if ( ev->reason() == QFocusEvent::Tab && inputMask().isNull() && hasSelectedText() )
         return;
@@ -1305,10 +1336,31 @@
     QLineEdit::focusInEvent(ev);
 }
 
+void KLineEdit::focusOutEvent( QFocusEvent* ev)
+{
+    if ( text().isEmpty() && !d->mClickMessage.isEmpty() ) {
+        d->mDrawClickMsg = true;
+        repaint();
+    }
+    QLineEdit::focusOutEvent( ev );
+}
+
 bool KLineEdit::autoSuggest() const
 {
     return d->autoSuggest;
 }
 
+void KLineEdit::setClickMessage( const QString &msg )
+{
+    d->mClickMessage = msg;
+    repaint();
+}
+
+QString KLineEdit::clickMessage() const
+{
+    return d->mClickMessage;
+}
+
+
 void KLineEdit::virtual_hook( int id, void* data )
 { KCompletionBase::virtual_hook( id, data ); }
Index: klineedit.h
===================================================================
--- klineedit.h	(revision 550560)
+++ klineedit.h	(working copy)
@@ -151,6 +151,8 @@
     Q_PROPERTY( bool urlDropsEnabled READ isURLDropsEnabled WRITE setURLDropsEnabled )
     Q_PROPERTY( bool trapEnterKeyEvent READ trapReturnKey WRITE setTrapReturnKey )
     Q_PROPERTY( bool enableSqueezedText READ isSqueezedTextEnabled WRITE setEnableSqueezedText )
+    // @since 3.5.4
+    Q_PROPERTY( QString clickMessage READ clickMessage WRITE setClickMessage )
 
 public:
 
@@ -326,6 +328,20 @@
     */
     void setCompletionBox( KCompletionBox *box );
 
+    /**
+     * This makes the line edit display a grayed-out hinting text as long as
+     * the user didn't enter any text. It is often used as indication about
+     * the purpose of the line edit.
+     * @since 3.5.4
+    */
+    void setClickMessage( const QString &msg );
+
+    /**
+     * @return the message set with setClickMessage
+     * @since 3.5.4
+    */
+    QString clickMessage() const;
+
 signals:
 
     /**
@@ -524,6 +540,13 @@
     virtual QPopupMenu *createPopupMenu();
 
     /**
+    * Re-implemented for internal reasons.  API not affected.
+    *
+    * See QFrame::drawContents().
+    */
+    virtual void drawContents( QPainter *p );
+
+    /**
     * Re-implemented to handle URI drops.
     *
     * See QLineEdit::dropEvent().
@@ -561,6 +584,13 @@
     virtual void focusInEvent( QFocusEvent* );
 
     /**
+    * Re-implemented for internal reasons.  API not affected.
+    *
+    * See QLineEdit::focusOutEvent().
+    */
+    virtual void focusOutEvent( QFocusEvent* );
+
+    /**
      * Whether in current state text should be auto-suggested
      * @since 3.4
     */


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic