summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBea Lam <bea.lam@nokia.com>2009-09-30 00:37:03 (GMT)
committerBea Lam <bea.lam@nokia.com>2009-09-30 00:37:03 (GMT)
commit906f5f6a825c500e4cc1d2d9c7be08444d394774 (patch)
tree01a542c030634e542323fa07db04bccd89044182
parent19aef645df1e24fa4d9513136c1fee8093173eb1 (diff)
parent4dc235f50a686d40bc63d7108027145f23d2c18a (diff)
downloadQt-906f5f6a825c500e4cc1d2d9c7be08444d394774.zip
Qt-906f5f6a825c500e4cc1d2d9c7be08444d394774.tar.gz
Qt-906f5f6a825c500e4cc1d2d9c7be08444d394774.tar.bz2
Merge branch 'kinetic-declarativeui' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
-rw-r--r--examples/declarative/focusscope/test4.qml75
-rw-r--r--src/declarative/fx/qfxflickable.cpp11
-rw-r--r--src/declarative/fx/qfxlistview.cpp35
-rw-r--r--src/declarative/fx/qfxlistview.h7
-rw-r--r--tests/auto/declarative/qfxtextedit/data/navigation.qml23
-rw-r--r--tests/auto/declarative/qfxtextedit/qfxtextedit.pro3
-rw-r--r--tests/auto/declarative/qfxtextedit/tst_qfxtextedit.cpp56
7 files changed, 199 insertions, 11 deletions
diff --git a/examples/declarative/focusscope/test4.qml b/examples/declarative/focusscope/test4.qml
new file mode 100644
index 0000000..f366543
--- /dev/null
+++ b/examples/declarative/focusscope/test4.qml
@@ -0,0 +1,75 @@
+import Qt 4.6
+
+Rectangle {
+ color: "white"
+ width: 800
+ height: 600
+
+ Keys.onDigit9Pressed: print("Error - Root")
+
+ FocusScope {
+ id: MyScope
+
+ Keys.onDigit9Pressed: print("Error - FocusScope")
+
+ Rectangle {
+ height: 120
+ width: 420
+
+ color: "transparent"
+ border.width: 5
+ border.color: MyScope.wantsFocus?"blue":"black"
+
+ Rectangle {
+ id: Item1
+ x: 10; y: 10
+ width: 100; height: 100; color: "green"
+ border.width: 5
+ border.color: wantsFocus?"blue":"black"
+ Keys.onDigit9Pressed: print("Error - Top Left");
+ KeyNavigation.right: Item2
+ focus: true
+
+ Rectangle {
+ width: 50; height: 50; anchors.centerIn: parent
+ color: parent.focus?"red":"transparent"
+ }
+ }
+
+ Rectangle {
+ id: Item2
+ x: 310; y: 10
+ width: 100; height: 100; color: "green"
+ border.width: 5
+ border.color: wantsFocus?"blue":"black"
+ KeyNavigation.left: Item1
+ Keys.onDigit9Pressed: print("Error - Top Right");
+
+ Rectangle {
+ width: 50; height: 50; anchors.centerIn: parent
+ color: parent.focus?"red":"transparent"
+ }
+ }
+ }
+ KeyNavigation.down: Item3
+ }
+
+ Text { x:100; y:170; text: "There should be no blue borders, or red squares.\nPressing \"9\" should do nothing.\nArrow keys should have no effect." }
+
+ Rectangle {
+ id: Item3
+ x: 10; y: 300
+ width: 100; height: 100; color: "green"
+ border.width: 5
+ border.color: wantsFocus?"blue":"black"
+
+ Keys.onDigit9Pressed: print("Error - Bottom Left");
+ KeyNavigation.up: MyScope
+
+ Rectangle {
+ width: 50; height: 50; anchors.centerIn: parent
+ color: parent.focus?"red":"transparent"
+ }
+ }
+
+}
diff --git a/src/declarative/fx/qfxflickable.cpp b/src/declarative/fx/qfxflickable.cpp
index 5c1cccf..a83ee66 100644
--- a/src/declarative/fx/qfxflickable.cpp
+++ b/src/declarative/fx/qfxflickable.cpp
@@ -744,12 +744,19 @@ void QFxFlickablePrivate::captureDelayedPress(QGraphicsSceneMouseEvent *event)
if (event->buttons() & i) {
Qt::MouseButton button = Qt::MouseButton(i);
delayedPressEvent->setButtonDownPos(button, event->buttonDownPos(button));
+ delayedPressEvent->setButtonDownScenePos(button, event->buttonDownScenePos(button));
+ delayedPressEvent->setButtonDownScreenPos(button, event->buttonDownScreenPos(button));
}
}
- delayedPressEvent->setScenePos(event->scenePos());
- delayedPressEvent->setLastScenePos(event->lastScenePos());
+ delayedPressEvent->setButtons(event->buttons());
+ delayedPressEvent->setButton(event->button());
delayedPressEvent->setPos(event->pos());
+ delayedPressEvent->setScenePos(event->scenePos());
+ delayedPressEvent->setScreenPos(event->screenPos());
delayedPressEvent->setLastPos(event->lastPos());
+ delayedPressEvent->setLastScenePos(event->lastScenePos());
+ delayedPressEvent->setLastScreenPos(event->lastScreenPos());
+ delayedPressEvent->setModifiers(event->modifiers());
delayedPressTimer.start(pressDelay, q);
}
diff --git a/src/declarative/fx/qfxlistview.cpp b/src/declarative/fx/qfxlistview.cpp
index 5de9bf3..3584892 100644
--- a/src/declarative/fx/qfxlistview.cpp
+++ b/src/declarative/fx/qfxlistview.cpp
@@ -1339,13 +1339,19 @@ qreal QFxListView::maxXExtent() const
void QFxListView::keyPressEvent(QKeyEvent *event)
{
Q_D(QFxListView);
+ QFxFlickable::keyPressEvent(event);
+ if (event->isAccepted())
+ return;
+
if (d->model && d->model->count() && d->interactive) {
if ((d->orient == Qt::Horizontal && event->key() == Qt::Key_Left)
|| (d->orient == Qt::Vertical && event->key() == Qt::Key_Up)) {
if (currentIndex() > 0 || (d->wrap && !event->isAutoRepeat())) {
d->moveReason = QFxListViewPrivate::Key;
- int index = currentIndex()-1;
- d->updateCurrent(index >= 0 ? index : d->model->count()-1);
+ decrementCurrentIndex();
+ event->accept();
+ return;
+ } else if (d->wrap) {
event->accept();
return;
}
@@ -1353,8 +1359,10 @@ void QFxListView::keyPressEvent(QKeyEvent *event)
|| (d->orient == Qt::Vertical && event->key() == Qt::Key_Down)) {
if (currentIndex() < d->model->count() - 1 || (d->wrap && !event->isAutoRepeat())) {
d->moveReason = QFxListViewPrivate::Key;
- int index = currentIndex()+1;
- d->updateCurrent(index < d->model->count() ? index : 0);
+ incrementCurrentIndex();
+ event->accept();
+ return;
+ } else if (d->wrap) {
event->accept();
return;
}
@@ -1362,7 +1370,24 @@ void QFxListView::keyPressEvent(QKeyEvent *event)
}
d->moveReason = QFxListViewPrivate::Other;
event->ignore();
- QFxFlickable::keyPressEvent(event);
+}
+
+void QFxListView::incrementCurrentIndex()
+{
+ Q_D(QFxListView);
+ if (currentIndex() < d->model->count() - 1 || d->wrap) {
+ int index = currentIndex()+1;
+ d->updateCurrent(index < d->model->count() ? index : 0);
+ }
+}
+
+void QFxListView::decrementCurrentIndex()
+{
+ Q_D(QFxListView);
+ if (currentIndex() > 0 || d->wrap) {
+ int index = currentIndex()-1;
+ d->updateCurrent(index >= 0 ? index : d->model->count()-1);
+ }
}
void QFxListView::componentComplete()
diff --git a/src/declarative/fx/qfxlistview.h b/src/declarative/fx/qfxlistview.h
index cc3d910..fc15967 100644
--- a/src/declarative/fx/qfxlistview.h
+++ b/src/declarative/fx/qfxlistview.h
@@ -50,9 +50,6 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Declarative)
-//### incrementCurrentIndex(), decrementCurrentIndex() slots
-//### default Keys.OnUp/DownPressed handler
-
class QFxVisualModel;
class QFxListViewAttached;
@@ -131,6 +128,10 @@ public:
static QFxListViewAttached *qmlAttachedProperties(QObject *);
+public Q_SLOTS:
+ void incrementCurrentIndex();
+ void decrementCurrentIndex();
+
Q_SIGNALS:
void countChanged();
void spacingChanged();
diff --git a/tests/auto/declarative/qfxtextedit/data/navigation.qml b/tests/auto/declarative/qfxtextedit/data/navigation.qml
new file mode 100644
index 0000000..5b8613f
--- /dev/null
+++ b/tests/auto/declarative/qfxtextedit/data/navigation.qml
@@ -0,0 +1,23 @@
+import Qt 4.6
+
+Rectangle {
+ property var myInput: Input
+
+ width: 800; height: 600; color: "blue"
+
+ Item {
+ id: FirstItem;
+ KeyNavigation.right: Input
+ }
+
+ TextEdit { id: Input; focus: true
+ KeyNavigation.left: FirstItem
+ KeyNavigation.right: LastItem
+ KeyNavigation.up: FirstItem
+ KeyNavigation.down: LastItem
+ }
+ Item {
+ id: LastItem
+ KeyNavigation.left: Input
+ }
+}
diff --git a/tests/auto/declarative/qfxtextedit/qfxtextedit.pro b/tests/auto/declarative/qfxtextedit/qfxtextedit.pro
index 59ab6e5..90546a4 100644
--- a/tests/auto/declarative/qfxtextedit/qfxtextedit.pro
+++ b/tests/auto/declarative/qfxtextedit/qfxtextedit.pro
@@ -1,3 +1,6 @@
load(qttest_p4)
contains(QT_CONFIG,declarative): QT += declarative gui
SOURCES += tst_qfxtextedit.cpp
+
+# Define SRCDIR equal to test's source directory
+DEFINES += SRCDIR=\\\"$$PWD\\\"
diff --git a/tests/auto/declarative/qfxtextedit/tst_qfxtextedit.cpp b/tests/auto/declarative/qfxtextedit/tst_qfxtextedit.cpp
index e38e0e7..7ab598f 100644
--- a/tests/auto/declarative/qfxtextedit/tst_qfxtextedit.cpp
+++ b/tests/auto/declarative/qfxtextedit/tst_qfxtextedit.cpp
@@ -1,4 +1,6 @@
#include <qtest.h>
+#include "../../../shared/util.h"
+#include <QFile>
#include <QTextDocument>
#include <QtDeclarative/qmlengine.h>
#include <QtDeclarative/qmlcontext.h>
@@ -6,6 +8,7 @@
#include <QtDeclarative/qmlcomponent.h>
#include <QtDeclarative/qfxtextedit.h>
#include <QFontMetrics>
+#include <QmlView>
class tst_qfxtextedit : public QObject
@@ -27,8 +30,12 @@ private slots:
void selection();
void cursorDelegate();
+ void navigation();
private:
+ void simulateKey(QmlView *, int key);
+ QmlView *createView(const QString &filename);
+
QStringList standard;
QStringList richText;
@@ -424,7 +431,6 @@ void tst_qfxtextedit::selection()
QVERIFY(textEditObject->selectedText().size() == 10);
}
-#include <QmlView>
void tst_qfxtextedit::cursorDelegate()
{
QmlView* view = new QmlView(0);
@@ -452,6 +458,54 @@ void tst_qfxtextedit::cursorDelegate()
QVERIFY(!textEditObject->findChild<QFxItem*>("cursorInstance"));
}
+/*
+TextEdit element should only handle left/right keys until the cursor reaches
+the extent of the text, then they should ignore the keys.
+*/
+void tst_qfxtextedit::navigation()
+{
+ QmlView *canvas = createView(SRCDIR "/data/navigation.qml");
+ canvas->execute();
+ canvas->show();
+
+ QVERIFY(canvas->root() != 0);
+
+ QFxItem *input = qobject_cast<QFxItem *>(qvariant_cast<QObject *>(canvas->root()->property("myInput")));
+
+ QVERIFY(input != 0);
+ QTRY_VERIFY(input->hasFocus() == true);
+ simulateKey(canvas, Qt::Key_Left);
+ QVERIFY(input->hasFocus() == false);
+ simulateKey(canvas, Qt::Key_Right);
+ QVERIFY(input->hasFocus() == true);
+ simulateKey(canvas, Qt::Key_Right);
+ QVERIFY(input->hasFocus() == false);
+ simulateKey(canvas, Qt::Key_Left);
+ QVERIFY(input->hasFocus() == true);
+}
+
+void tst_qfxtextedit::simulateKey(QmlView *view, int key)
+{
+ QKeyEvent press(QKeyEvent::KeyPress, key, 0);
+ QKeyEvent release(QKeyEvent::KeyRelease, key, 0);
+
+ QApplication::sendEvent(view, &press);
+ QApplication::sendEvent(view, &release);
+}
+
+QmlView *tst_qfxtextedit::createView(const QString &filename)
+{
+ QmlView *canvas = new QmlView(0);
+
+ QFile file(filename);
+ file.open(QFile::ReadOnly);
+ QString xml = file.readAll();
+ canvas->setQml(xml, filename);
+
+ return canvas;
+}
+
+
QTEST_MAIN(tst_qfxtextedit)
#include "tst_qfxtextedit.moc"