[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-core-devel
Subject: Re: [PATCH] Open/Save dialog completion fix
From: Rafael =?iso-8859-15?q?Fern=E1ndez_L=F3pez?= <ereslibre () kde ! org>
Date: 2008-12-22 23:05:16
Message-ID: 200812230005.20332.ereslibre () kde ! org
[Download RAW message or body]
[Attachment #2 (multipart/mixed)]
Hi,
Didn't know that removing a reimplementation of a virtual method of the base
class was binary incompatible (but adding it is BC). Anyway, on the attached
patch I don't change keyPressEvent with keyReleaseEvent, I just add
keyReleaseEvent, keeping keyPressEvent just calling to the base class. This
makes it BC.
Regards,
Rafael Fernández López.
["kdelibs.diff" (text/x-patch)]
diff --git a/kdeui/widgets/klineedit.cpp b/kdeui/widgets/klineedit.cpp
index 5260c31..748d2b9 100644
--- a/kdeui/widgets/klineedit.cpp
+++ b/kdeui/widgets/klineedit.cpp
@@ -144,6 +144,8 @@ public:
KCompletionBox *completionBox;
+ QString m_oldText;
+
int overlap;
bool italicizePlaceholder:1;
@@ -649,7 +651,12 @@ void KLineEdit::resizeEvent( QResizeEvent * ev )
QLineEdit::resizeEvent(ev);
}
-void KLineEdit::keyPressEvent( QKeyEvent *e )
+void KLineEdit::keyPressEvent(QKeyEvent *e)
+{
+ QLineEdit::keyPressEvent(e);
+}
+
+void KLineEdit::keyReleaseEvent( QKeyEvent *e )
{
const int key = e->key() | e->modifiers();
@@ -750,12 +757,12 @@ void KLineEdit::keyPressEvent( QKeyEvent *e )
( e->key() == Qt::Key_Right || e->key() == Qt::Key_Left ) &&
e->modifiers()==Qt::NoButton )
{
- const QString old_txt = text();
+ const QString old_txt = d->m_oldText;
d->disableRestoreSelection = true;
const int start = selectionStart();
deselect();
- QLineEdit::keyPressEvent ( e );
+ QLineEdit::keyReleaseEvent ( e );
const int cPosition=cursorPosition();
setText(old_txt);
setCursorPosition(cPosition);
@@ -765,6 +772,7 @@ void KLineEdit::keyPressEvent( QKeyEvent *e )
setSelection(start, old_txt.length());
d->disableRestoreSelection = false;
+ d->m_oldText = text();
return;
}
@@ -811,7 +819,7 @@ void KLineEdit::keyPressEvent( QKeyEvent *e )
}
d->disableRestoreSelection = true;
- QLineEdit::keyPressEvent ( e );
+ QLineEdit::keyReleaseEvent ( e );
d->disableRestoreSelection = false;
QString txt = text();
@@ -842,6 +850,7 @@ void KLineEdit::keyPressEvent( QKeyEvent *e )
e->accept();
}
+ d->m_oldText = text();
return;
}
@@ -849,9 +858,9 @@ void KLineEdit::keyPressEvent( QKeyEvent *e )
else if (( mode == KGlobalSettings::CompletionPopup ||
mode == KGlobalSettings::CompletionPopupAuto ) &&
- noModifier && !e->text().isEmpty() )
+ noModifier )
{
- const QString old_txt = text();
+ const QString old_txt = d->m_oldText;
const bool hasUserSelection=d->userSelection;
const bool hadSelection=hasSelectedText();
bool cursorNotAtEnd=false;
@@ -865,8 +874,8 @@ void KLineEdit::keyPressEvent( QKeyEvent *e )
// as if there was no selection. After processing the key event, we
// can set the new autocompletion again.
if (hadSelection && !hasUserSelection && start>cPos &&
- ( (!keycode.isEmpty() && keycode.unicode()->isPrint()) ||
- e->key() == Qt::Key_Backspace || e->key() == Qt::Key_Delete ) )
+ ( !keycode.isEmpty() && (keycode.unicode()->isPrint() ||
+ e->key() == Qt::Key_Backspace || e->key() == Qt::Key_Delete ) ) )
{
del();
setCursorPosition(cPos);
@@ -876,17 +885,19 @@ void KLineEdit::keyPressEvent( QKeyEvent *e )
const int selectedLength=selectedText().length();
d->disableRestoreSelection = true;
- QLineEdit::keyPressEvent ( e );
+ QLineEdit::keyReleaseEvent ( e );
d->disableRestoreSelection = false;
+
if (( selectedLength != selectedText().length() ) && !hasUserSelection )
slotRestoreSelectionColors(); // and set userSelection to true
QString txt = text();
int len = txt.length();
if ( ( txt != old_txt || txt != e->text() ) && len/* && ( \
cursorPosition() == len || force )*/ &&
- ( (!keycode.isEmpty() && keycode.unicode()->isPrint()) ||
- e->key() == Qt::Key_Backspace || e->key() == Qt::Key_Delete) )
+ ( !keycode.isEmpty() && (keycode.unicode()->isPrint() ||
+ e->key() == Qt::Key_Backspace || e->key() == Qt::Key_Delete) ) &&
+ ( keycode.unicode()->category() != QChar::Symbol_Modifier || txt != \
old_txt ) ) {
if ( e->key() == Qt::Key_Backspace )
{
@@ -918,6 +929,7 @@ void KLineEdit::keyPressEvent( QKeyEvent *e )
else if (!len && d->completionBox && d->completionBox->isVisible())
d->completionBox->hide();
+ d->m_oldText = text();
return;
}
@@ -1007,10 +1019,12 @@ void KLineEdit::keyPressEvent( QKeyEvent *e )
const int selectedLength = selectedText().length();
// Let QLineEdit handle any other keys events.
- QLineEdit::keyPressEvent ( e );
+ QLineEdit::keyReleaseEvent ( e );
if ( selectedLength != selectedText().length() )
slotRestoreSelectionColors(); // and set userSelection to true
+
+ d->m_oldText = text();
}
void KLineEdit::mouseDoubleClickEvent( QMouseEvent* e )
diff --git a/kdeui/widgets/klineedit.h b/kdeui/widgets/klineedit.h
index 62514d2..a5173d2 100644
--- a/kdeui/widgets/klineedit.h
+++ b/kdeui/widgets/klineedit.h
@@ -518,6 +518,13 @@ protected:
/**
* Re-implemented for internal reasons. API not affected.
*
+ * See QLineEdit::keyReleaseEvent().
+ */
+ virtual void keyReleaseEvent( QKeyEvent * );
+
+ /**
+ * Re-implemented for internal reasons. API not affected.
+ *
* See QLineEdit::mousePressEvent().
*/
virtual void mousePressEvent( QMouseEvent * );
["signature.asc" (application/pgp-signature)]
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic