[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: branches/KDE/4.0/kdelibs/kdeui
From: David Faure <faure () kde ! org>
Date: 2008-06-02 13:31:46
Message-ID: 1212413506.325860.10993.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 815662 by dfaure:
Backport: Fix KTextEdit shortcuts triggering twice due to my bad ShortcutOverride \
handling. (#162768) And all unit tests from trunk.
M +2 -0 tests/CMakeLists.txt
A tests/kcombobox_unittest.cpp \
trunk/KDE/kdelibs/kdeui/tests/kcombobox_unittest.cpp#815644 [License: LGPL (v2+)] M \
+44 -43 tests/klineedit_unittest.cpp D tests/klineedit_unittest.h
A tests/ktextedit_unittest.cpp \
trunk/KDE/kdelibs/kdeui/tests/ktextedit_unittest.cpp#815633 [License: LGPL (v2+)] M \
+61 -7 widgets/ktextedit.cpp
--- branches/KDE/4.0/kdelibs/kdeui/tests/CMakeLists.txt #815661:815662
@@ -28,6 +28,8 @@
kglobalshortcuttest
kmainwindow_unittest
klineedit_unittest
+ ktextedit_unittest
+ kcombobox_unittest
kreplacetest
kshortcuttest
kstandardactiontest
--- branches/KDE/4.0/kdelibs/kdeui/tests/klineedit_unittest.cpp #815661:815662
@@ -18,52 +18,53 @@
Boston, MA 02110-1301, USA.
*/
-#include "qtest_kde.h"
+#include <QClipboard>
+#include <qtest_kde.h>
#include <qtestevent.h>
-#include "klineedit_unittest.h"
-#include <kcombobox.h>
-#include "klineedit_unittest.moc"
#include <klineedit.h>
-QTEST_KDEMAIN(KLineEdit_UnitTest, GUI)
-
-void KLineEdit_UnitTest::testReturnPressed()
+class KLineEdit_UnitTest : public QObject
{
- KLineEdit w;
- w.setText("Hello world");
- QSignalSpy qReturnPressedSpy(&w, SIGNAL(returnPressed()));
- QSignalSpy kReturnPressedSpy(&w, SIGNAL(returnPressed(QString)));
- QTest::keyClick(&w, Qt::Key_Return);
- QCOMPARE(qReturnPressedSpy.count(), 1);
- QCOMPARE(kReturnPressedSpy.count(), 1);
- QCOMPARE(kReturnPressedSpy[0][0].toString(), QString("Hello world"));
-}
+ Q_OBJECT
-void KLineEdit_UnitTest::testComboReturnPressed(bool ctorArg)
-{
- KComboBox w(ctorArg /*initial value for editable*/);
- w.setEditable(true);
- w.setCompletionMode( KGlobalSettings::CompletionPopup );
- w.addItem("Hello world");
- QVERIFY(w.lineEdit());
- QVERIFY(qobject_cast<KLineEdit*>(w.lineEdit()));
- // KLineEdit signals
- QSignalSpy qReturnPressedSpy(w.lineEdit(), SIGNAL(returnPressed()));
- QSignalSpy kReturnPressedSpy(w.lineEdit(), SIGNAL(returnPressed(QString)));
- // KComboBox signals
- QSignalSpy comboReturnPressedSpy(&w, SIGNAL(returnPressed()));
- QSignalSpy comboReturnPressedStringSpy(&w, SIGNAL(returnPressed(QString)));
- QTest::keyClick(&w, Qt::Key_Return);
- QCOMPARE(qReturnPressedSpy.count(), 1);
- QCOMPARE(kReturnPressedSpy.count(), 1);
- QCOMPARE(kReturnPressedSpy[0][0].toString(), QString("Hello world"));
- QCOMPARE(comboReturnPressedSpy.count(), 1);
- QCOMPARE(comboReturnPressedStringSpy.count(), 1);
- QCOMPARE(comboReturnPressedStringSpy[0][0].toString(), QString("Hello world"));
-}
+private Q_SLOTS:
+ void testPassword()
+ {
+ KLineEdit w;
+ w.setPasswordMode(true);
+ QTest::keyClick(&w, Qt::Key_1);
+ QTest::keyClick(&w, Qt::Key_2);
+ QTest::keyClick(&w, Qt::Key_3);
+ QCOMPARE(w.text(), QString("123"));
+ }
-void KLineEdit_UnitTest::testComboReturnPressed()
-{
- testComboReturnPressed(false);
- testComboReturnPressed(true);
-}
+ void testReturnPressed()
+ {
+ KLineEdit w;
+ w.setText("Hello world");
+ QSignalSpy qReturnPressedSpy(&w, SIGNAL(returnPressed()));
+ QSignalSpy kReturnPressedSpy(&w, SIGNAL(returnPressed(QString)));
+ QTest::keyClick(&w, Qt::Key_Return);
+ QCOMPARE(qReturnPressedSpy.count(), 1);
+ QCOMPARE(kReturnPressedSpy.count(), 1);
+ QCOMPARE(kReturnPressedSpy[0][0].toString(), QString("Hello world"));
+ }
+
+ void testPaste()
+ {
+ const QString origText = QApplication::clipboard()->text();
+ const QString pastedText = "Test paste from klineedit_unittest";
+ QApplication::clipboard()->setText(pastedText);
+ KLineEdit w;
+ w.setText("Hello world");
+ w.selectAll();
+ QTest::keyClick(&w, Qt::Key_V, Qt::ControlModifier);
+ QCOMPARE(w.text(), pastedText);
+ QApplication::clipboard()->setText(origText);
+ }
+
+};
+
+QTEST_KDEMAIN(KLineEdit_UnitTest, GUI)
+
+#include "klineedit_unittest.moc"
--- branches/KDE/4.0/kdelibs/kdeui/widgets/ktextedit.cpp #815661:815662
@@ -56,10 +56,15 @@
}
/**
- * Checks whether we should/should not consume a key used as
- * an accelerator.
+ * Checks whether we should/should not consume a key used as a shortcut.
+ * This makes it possible to handle shortcuts in the focused widget before any
+ * window-global QAction is triggered.
*/
- bool overrideShortcut (const QKeyEvent* e);
+ bool overrideShortcut(const QKeyEvent* e);
+ /**
+ * Actually handle a shortcut event.
+ */
+ bool handleShortcut(const QKeyEvent* e);
void slotSpellCheckDone( const QString &s );
@@ -182,7 +187,7 @@
return QTextEdit::event(ev);
}
-bool KTextEdit::Private::overrideShortcut(const QKeyEvent* event)
+bool KTextEdit::Private::handleShortcut(const QKeyEvent* event)
{
const int key = event->key() | event->modifiers();
@@ -260,9 +265,9 @@
if ( !text.isEmpty() )
parent->insertPlainText( text ); // TODO: check if this is html? (MiB)
return true;
- } else if ( event->modifiers() == Qt::ControlModifier &&
+ } else if (event->modifiers() == Qt::ControlModifier &&
(event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter) &&
- qobject_cast<KDialog*>( parent->topLevelWidget() ) ) {
+ qobject_cast<KDialog*>(parent->window()) ) {
// ignore Ctrl-Return so that KDialogs can close the dialog
return true;
}
@@ -457,9 +462,58 @@
setTextCursor (cursor);
}
+bool KTextEdit::Private::overrideShortcut(const QKeyEvent* event)
+{
+ const int key = event->key() | event->modifiers();
+
+ if ( KStandardShortcut::copy().contains( key ) ) {
+ return true;
+ } else if ( KStandardShortcut::paste().contains( key ) ) {
+ return true;
+ } else if ( KStandardShortcut::cut().contains( key ) ) {
+ return true;
+ } else if ( KStandardShortcut::undo().contains( key ) ) {
+ return true;
+ } else if ( KStandardShortcut::redo().contains( key ) ) {
+ return true;
+ } else if ( KStandardShortcut::deleteWordBack().contains( key ) ) {
+ return true;
+ } else if ( KStandardShortcut::deleteWordForward().contains( key ) ) {
+ return true;
+ } else if ( KStandardShortcut::backwardWord().contains( key ) ) {
+ return true;
+ } else if ( KStandardShortcut::forwardWord().contains( key ) ) {
+ return true;
+ } else if ( KStandardShortcut::next().contains( key ) ) {
+ return true;
+ } else if ( KStandardShortcut::prior().contains( key ) ) {
+ return true;
+ } else if ( KStandardShortcut::begin().contains( key ) ) {
+ return true;
+ } else if ( KStandardShortcut::end().contains( key ) ) {
+ return true;
+ } else if ( KStandardShortcut::beginningOfLine().contains( key ) ) {
+ return true;
+ } else if ( KStandardShortcut::endOfLine().contains( key ) ) {
+ return true;
+ } else if ( KStandardShortcut::pasteSelection().contains( key ) ) {
+ return true;
+ } else if (event->modifiers() == Qt::ControlModifier &&
+ (event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter) &&
+ qobject_cast<KDialog*>(parent->window()) ) {
+ // ignore Ctrl-Return so that KDialogs can close the dialog
+ return true;
+ }
+ return false;
+}
+
void KTextEdit::keyPressEvent( QKeyEvent *event )
{
- QTextEdit::keyPressEvent(event);
+ if (d->handleShortcut(event)) {
+ event->accept();
+ } else {
+ QTextEdit::keyPressEvent(event);
+ }
}
#include "ktextedit.moc"
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic