diff options
author | Jarno Malmari <ext-jarno.malmari@nokia.com> | 2010-12-31 09:08:08 +0200 |
---|---|---|
committer | Pekka Vuorela <pekka.ta.vuorela@nokia.com> | 2011-01-05 17:29:18 +0200 |
commit | 0940ea05991df96ada11845d9d5fea7aa0769de6 (patch) | |
tree | 028967a3f2febab8c1537894a2aff7e4e1d0a736 /tests | |
parent | 2440ae8e7e969db0fb52082d136795ec97638f0d (diff) |
Changes: Disable panning while text magnifier is in use.
RevBy: Pekka Vuorela
Details: MTextMagnifier, or rather its overlay parent, grabs the
pan gesture and by consuming it the gesture never reaches pannable
widgets.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/tests.pro | 1 | ||||
-rw-r--r-- | tests/ut_mtextmagnifier/.gitignore | 2 | ||||
-rw-r--r-- | tests/ut_mtextmagnifier/mtextmagnifierstyle.h | 31 | ||||
-rw-r--r-- | tests/ut_mtextmagnifier/ut_mtextmagnifier.cpp | 117 | ||||
-rw-r--r-- | tests/ut_mtextmagnifier/ut_mtextmagnifier.h | 52 | ||||
-rw-r--r-- | tests/ut_mtextmagnifier/ut_mtextmagnifier.pro | 15 |
6 files changed, 218 insertions, 0 deletions
diff --git a/tests/tests.pro b/tests/tests.pro index 4befe738..f8893d40 100644 --- a/tests/tests.pro +++ b/tests/tests.pro @@ -75,6 +75,7 @@ SUBDIRS = \ ut_msliderview \ ut_mtextedit \ ut_mtexteditview \ + ut_mtextmagnifier \ ut_mthemedaemonprotocol \ ut_mtheme \ ut_mtoolbar \ diff --git a/tests/ut_mtextmagnifier/.gitignore b/tests/ut_mtextmagnifier/.gitignore new file mode 100644 index 00000000..2f9f8340 --- /dev/null +++ b/tests/ut_mtextmagnifier/.gitignore @@ -0,0 +1,2 @@ +ut_mtextmagnifier + diff --git a/tests/ut_mtextmagnifier/mtextmagnifierstyle.h b/tests/ut_mtextmagnifier/mtextmagnifierstyle.h new file mode 100644 index 00000000..3730b0d7 --- /dev/null +++ b/tests/ut_mtextmagnifier/mtextmagnifierstyle.h @@ -0,0 +1,31 @@ +#ifndef MTEXTMAGNIFIERSTYLE_H +#define MTEXTMAGNIFIERSTYLE_H + +#include <MWidgetStyle> + +class QString; +class MWidgetController; + +class MTextMagnifierStyle +{ +public: + qreal magnification() const { return 0.0; } + QPixmap *magnifierMask() const { return 0; } + QPixmap *magnifierFrame() const { return 0; } + QPointF visualOffset() const { return QPointF(); } + +}static gMagnifierStyle; + +class MTextMagnifierStyleContainer : public MWidgetStyleContainer +{ +public: + void initialize(const QString &, const QString &, const MWidgetController *){} + void setModeDefault() const {} + const MTextMagnifierStyle* operator->() const + { + return &gMagnifierStyle; + } +}; + + +#endif // MTEXTMAGNIFIERSTYLE_H diff --git a/tests/ut_mtextmagnifier/ut_mtextmagnifier.cpp b/tests/ut_mtextmagnifier/ut_mtextmagnifier.cpp new file mode 100644 index 00000000..4e8a13c2 --- /dev/null +++ b/tests/ut_mtextmagnifier/ut_mtextmagnifier.cpp @@ -0,0 +1,117 @@ +/*************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (directui@nokia.com) +** +** This file is part of libmeegotouch. +** +** If you have questions regarding the use of this file, please contact +** Nokia at directui@nokia.com. +** +** This library is free software; you can redistribute it and/or +** modify it under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation +** and appearing in the file LICENSE.LGPL included in the packaging +** of this file. +** +****************************************************************************/ + +#include "ut_mtextmagnifier.h" +#include "views/mtextmagnifier.h" + +#include <QEvent> +#include <QGraphicsWidget> +#include <QMetaType> +#include <QPainter> +#include <QPanGesture> +#include <QSignalSpy> + +#include <MApplication> +#include <MApplicationWindow> +#include <MCancelEvent> +#include <MScene> + +namespace { + Qt::GestureState gGestureState = Qt::GestureStarted; +} + +Qt::GestureState QGesture::state() const +{ + return gGestureState; +} + +void Ut_MTextMagnifier::initTestCase() +{ + static int dummyArgc = 1; + static char *dummyArgv[1] = { (char *) "./ut_mtextmagnifier" }; + MApplication::setLoadMInputContext(false); + m_app = new MApplication(dummyArgc, dummyArgv); + m_appWindow = new MApplicationWindow; + + magnifiedWidget = new QGraphicsWidget; + m_appWindow->scene()->addItem(magnifiedWidget); +} + +void Ut_MTextMagnifier::cleanupTestCase() +{ + delete magnifiedWidget; + magnifiedWidget = 0; + delete m_appWindow; + m_appWindow = 0; + delete m_app; + m_app = 0; +} + + +void Ut_MTextMagnifier::init() +{ + subject = new MTextMagnifier(*magnifiedWidget); +} + + +void Ut_MTextMagnifier::cleanup() +{ + delete subject; + subject = 0; +} + +void Ut_MTextMagnifier::testMagnifierConsumesPanGesture_data() +{ + QTest::addColumn<Qt::GestureState>("gestureState"); + QTest::addColumn<bool>("wasConsumed"); + + // This is needs to work to prevent panning while magnifier is shown. + QTest::newRow("gesture started") << Qt::GestureStarted << true; + + // Other gesture states should be ignored. + QTest::newRow("gesture canceled") << Qt::GestureCanceled << false; + QTest::newRow("gesture updated") << Qt::GestureUpdated << false; + QTest::newRow("gesture finished") << Qt::GestureFinished << false; +} + +void Ut_MTextMagnifier::testMagnifierConsumesPanGesture() +{ + QFETCH(Qt::GestureState, gestureState); + QFETCH(bool, wasConsumed); + + subject->appear(); + QVERIFY(subject->isAppeared()); + + // Create gesture object and put it inside an event. + QPanGesture panGesture; + gGestureState = gestureState; + + QList<QGesture *> gestures; + gestures << &panGesture; + QGestureEvent event(gestures); + event.setAccepted(Qt::PanGesture, false); + + // It is actually overlay who gets the event. + subject->overlay.gestureEvent(&event); + + QCOMPARE(event.isAccepted(Qt::PanGesture), wasConsumed); +} + +QTEST_APPLESS_MAIN(Ut_MTextMagnifier) + diff --git a/tests/ut_mtextmagnifier/ut_mtextmagnifier.h b/tests/ut_mtextmagnifier/ut_mtextmagnifier.h new file mode 100644 index 00000000..d1c0acb8 --- /dev/null +++ b/tests/ut_mtextmagnifier/ut_mtextmagnifier.h @@ -0,0 +1,52 @@ +/*************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (directui@nokia.com) +** +** This file is part of libmeegotouch. +** +** If you have questions regarding the use of this file, please contact +** Nokia at directui@nokia.com. +** +** This library is free software; you can redistribute it and/or +** modify it under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation +** and appearing in the file LICENSE.LGPL included in the packaging +** of this file. +** +****************************************************************************/ + +#ifndef UT_MTEXTMAGNIFIER_H +#define UT_MTEXTMAGNIFIER_H + +#include <QObject> +#include <QtTest/QtTest> + +class MApplication; +class MApplicationWindow; +class MTextMagnifier; +class QGraphicsWidget; + +class Ut_MTextMagnifier : public QObject +{ + Q_OBJECT + +private slots: + void init(); + void cleanup(); + void initTestCase(); + void cleanupTestCase(); + + void testMagnifierConsumesPanGesture_data(); + void testMagnifierConsumesPanGesture(); + +private: + MApplication *m_app; + MApplicationWindow *m_appWindow; + MTextMagnifier *subject; + QGraphicsWidget *magnifiedWidget; +}; + +#endif + diff --git a/tests/ut_mtextmagnifier/ut_mtextmagnifier.pro b/tests/ut_mtextmagnifier/ut_mtextmagnifier.pro new file mode 100644 index 00000000..c8cb03b4 --- /dev/null +++ b/tests/ut_mtextmagnifier/ut_mtextmagnifier.pro @@ -0,0 +1,15 @@ +include(../common_top.pri) +TARGET = ut_mtextmagnifier + +INCLUDEPATH += $$MSRCDIR + +SOURCES += \ + ut_mtextmagnifier.cpp \ + $$MSRCDIR/views/mtextmagnifier.cpp + +HEADERS += \ + ut_mtextmagnifier.h \ + mtextmagnifierstyle.h \ + $$MSRCDIR/views/mtextmagnifier.h + +include(../common_bot.pri) |