From kde-core-devel Fri Aug 23 21:25:46 2002 From: "Dawit A." Date: Fri, 23 Aug 2002 21:25:46 +0000 To: kde-core-devel Subject: PATCH:KLineEdit X-MARC-Message: https://marc.info/?l=kde-core-devel&m=103022455230516 MIME-Version: 1 Content-Type: multipart/mixed; boundary="--Boundary-00=_ahqZ9ndBJx9hHpR" --Boundary-00=_ahqZ9ndBJx9hHpR Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Since we are in a freeze, would anyone object to the following patch that=20 makes an insignificant change in terms of KLineEdit's functionality and adds one new member function ? The patch makes it possible for applications to set a flag, smartTextUpdate, which determines whether or not the current text in the lineedit needs to b= e=20 updated by comparing it with the new text. If the text has not changed, it= =20 will simply return without called QLineEdit::setText. The current default= =20 behavior is not changed and stays the way it is. Regards, Dawit A. --Boundary-00=_ahqZ9ndBJx9hHpR Content-Type: text/x-diff; charset="us-ascii"; name="klineedit.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="klineedit.diff" Index: klineedit.cpp =================================================================== RCS file: /home/kde/kdelibs/kdeui/klineedit.cpp,v retrieving revision 1.147 diff -u -p -b -B -w -r1.147 klineedit.cpp --- klineedit.cpp 2002/08/11 01:14:51 1.147 +++ klineedit.cpp 2002/08/24 21:19:10 @@ -47,21 +47,24 @@ class KLineEdit::KLineEditPrivate public: KLineEditPrivate() { - grabReturnKeyEvents = false; - handleURLDrops = true; completionBox = 0L; + handleURLDrops = true; + smartTextUpdate = false; + grabReturnKeyEvents = false; } ~KLineEditPrivate() { delete completionBox; } - bool grabReturnKeyEvents; + int squeezedEnd; + int squeezedStart; bool handleURLDrops; - KCompletionBox *completionBox; + bool smartTextUpdate; + bool grabReturnKeyEvents; + QString squeezedText; - int squeezedStart; - int squeezedEnd; + KCompletionBox *completionBox; }; @@ -86,6 +89,7 @@ void KLineEdit::init() { d = new KLineEditPrivate; possibleTripleClick = false; + // Enable the context menu by default. setContextMenuEnabled( true ); KCursor::setAutoHideCursor( this, true, true ); @@ -592,18 +596,25 @@ void KLineEdit::completionMenuActivated( switch ( id ) { case Default: - setCompletionMode( KGlobalSettings::completionMode() ); break; + setCompletionMode( KGlobalSettings::completionMode() ); + break; case NoCompletion: - setCompletionMode( KGlobalSettings::CompletionNone ); break; + setCompletionMode( KGlobalSettings::CompletionNone ); + break; case AutoCompletion: - setCompletionMode( KGlobalSettings::CompletionAuto ); break; + setCompletionMode( KGlobalSettings::CompletionAuto ); + break; case SemiAutoCompletion: - setCompletionMode( KGlobalSettings::CompletionMan ); break; + setCompletionMode( KGlobalSettings::CompletionMan ); + break; case ShellCompletion: - setCompletionMode( KGlobalSettings::CompletionShell ); break; + setCompletionMode( KGlobalSettings::CompletionShell ); + break; case PopupCompletion: - setCompletionMode( KGlobalSettings::CompletionPopup ); break; - default: return; + setCompletionMode( KGlobalSettings::CompletionPopup ); + break; + default: + return; } if ( oldMode != completionMode() ) @@ -700,7 +711,7 @@ bool KLineEdit::trapReturnKey() const void KLineEdit::setURL( const KURL& url ) { - QLineEdit::setText( url.prettyURL() ); + setText( url.prettyURL() ); } void KLineEdit::makeCompletionBox() @@ -829,6 +840,21 @@ void KLineEdit::clear() setText( QString::null ); } -void KLineEdit::virtual_hook( int id, void* data ) -{ KCompletionBase::virtual_hook( id, data ); } +void KLineEdit::setText (const QString & newText) +{ + if ( !d->smartTextUpdate || text().length() == 0 || newText != text() ) + { + QLineEdit::setText (newText); + return; + } +} +void KLineEdit::setEnableSmartTextUpdate (bool enable) +{ + d->smartTextUpdate = enable; +} + +void KLineEdit::virtual_hook( int id, void* data ) +{ + KCompletionBase::virtual_hook( id, data ); +} Index: klineedit.h =================================================================== RCS file: /home/kde/kdelibs/kdeui/klineedit.h,v retrieving revision 1.94 diff -u -p -b -B -w -r1.94 klineedit.h --- klineedit.h 2002/08/11 01:14:51 1.94 +++ klineedit.h 2002/08/24 21:19:10 @@ -250,6 +250,14 @@ public: bool trapReturnKey() const; /** + * Enables text update if and only if the new text is different + * from the current one. Otherwise, the call to setText is ignored. + * + * @param true enable smart text update, false otherwise. + */ + void setEnableSmartTextUpdate (bool); + + /** * Re-implemented for internal reasons. API not affected. * * @reimplemented @@ -380,6 +388,11 @@ public slots: * This can only be used with read-only line-edits. */ void setSqueezedText( const QString &text); + + /** + * Re-implemented for internal reasons. API is unaffected. + */ + virtual void setText (const QString &text); protected slots: --Boundary-00=_ahqZ9ndBJx9hHpR--