2011-04-27 10:05:43 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
|
|
|
** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
|
|
|
** All rights reserved.
|
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
|
|
**
|
|
|
|
** This file is part of the test suite of the Qt Toolkit.
|
|
|
|
**
|
|
|
|
** $QT_BEGIN_LICENSE:LGPL$
|
|
|
|
** GNU Lesser General Public License Usage
|
2011-05-24 11:43:28 +00:00
|
|
|
** This file may be used 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. Please review the following information to ensure the GNU Lesser
|
|
|
|
** General Public License version 2.1 requirements will be met:
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
2011-05-24 11:43:28 +00:00
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
2011-04-27 10:05:43 +00:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
**
|
2011-05-24 11:43:28 +00:00
|
|
|
** GNU General Public License Usage
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU General
|
|
|
|
** Public License version 3.0 as published by the Free Software Foundation
|
|
|
|
** and appearing in the file LICENSE.GPL included in the packaging of this
|
|
|
|
** file. Please review the following information to ensure the GNU General
|
|
|
|
** Public License version 3.0 requirements will be met:
|
|
|
|
** http://www.gnu.org/copyleft/gpl.html.
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
2011-05-24 11:43:28 +00:00
|
|
|
** Other Usage
|
|
|
|
** Alternatively, this file may be used in accordance with the terms and
|
|
|
|
** conditions contained in a signed written agreement between you and Nokia.
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
|
|
|
**
|
|
|
|
**
|
|
|
|
**
|
|
|
|
**
|
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <qtest.h>
|
|
|
|
#include <QtDeclarative/qdeclarativecomponent.h>
|
|
|
|
#include <QtDeclarative/qdeclarativeengine.h>
|
2011-10-14 08:51:42 +00:00
|
|
|
#include <QtDeclarative/qquickitem.h>
|
|
|
|
#include <QtDeclarative/qquickview.h>
|
2011-09-28 08:16:51 +00:00
|
|
|
#include <QtGui/qinputpanel.h>
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
class tst_qdeclarativeapplication : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
tst_qdeclarativeapplication();
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void active();
|
|
|
|
void layoutDirection();
|
2011-09-28 08:16:51 +00:00
|
|
|
void inputPanel();
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
QDeclarativeEngine engine;
|
|
|
|
};
|
|
|
|
|
|
|
|
tst_qdeclarativeapplication::tst_qdeclarativeapplication()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_qdeclarativeapplication::active()
|
|
|
|
{
|
|
|
|
QDeclarativeComponent component(&engine);
|
2011-07-11 03:47:51 +00:00
|
|
|
component.setData("import QtQuick 2.0; Item { property bool active: Qt.application.active }", QUrl::fromLocalFile(""));
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickItem *item = qobject_cast<QQuickItem *>(component.create());
|
2011-04-27 10:05:43 +00:00
|
|
|
QVERIFY(item);
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickView view;
|
2011-07-11 03:47:51 +00:00
|
|
|
item->setParentItem(view.rootObject());
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
// not active
|
|
|
|
QVERIFY(!item->property("active").toBool());
|
2011-09-21 11:02:38 +00:00
|
|
|
QCOMPARE(item->property("active").toBool(), QGuiApplication::activeWindow() != 0);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
// active
|
|
|
|
view.show();
|
2011-09-09 12:50:48 +00:00
|
|
|
view.requestActivateWindow();
|
|
|
|
QTest::qWait(50);
|
2011-10-19 05:04:15 +00:00
|
|
|
QEXPECT_FAIL("", "QTBUG-21573", Abort);
|
2011-10-14 08:51:42 +00:00
|
|
|
QTRY_COMPARE(view.status(), QQuickView::Ready);
|
2011-09-21 11:02:38 +00:00
|
|
|
QCOMPARE(item->property("active").toBool(), QGuiApplication::activeWindow() != 0);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2011-10-19 05:04:15 +00:00
|
|
|
#if 0
|
|
|
|
// QGuiApplication has no equivalent of setActiveWindow(0). QTBUG-21573
|
|
|
|
// Is this different to clearing the active state of the window or can it be removed?
|
|
|
|
// On Mac, setActiveWindow(0) on mac does not deactivate the current application,
|
|
|
|
// must switch to a different app or hide the current app to trigger this
|
2011-04-27 10:05:43 +00:00
|
|
|
// on mac, setActiveWindow(0) on mac does not deactivate the current application
|
|
|
|
// (you have to switch to a different app or hide the current app to trigger this)
|
2011-10-19 05:04:15 +00:00
|
|
|
|
|
|
|
// not active again
|
|
|
|
QGuiApplication::setActiveWindow(0);
|
2011-04-27 10:05:43 +00:00
|
|
|
QVERIFY(!item->property("active").toBool());
|
2011-09-21 11:02:38 +00:00
|
|
|
QCOMPARE(item->property("active").toBool(), QGuiApplication::activeWindow() != 0);
|
2011-04-27 10:05:43 +00:00
|
|
|
#endif
|
2011-10-19 05:04:15 +00:00
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void tst_qdeclarativeapplication::layoutDirection()
|
|
|
|
{
|
2011-09-21 11:02:38 +00:00
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
QDeclarativeComponent component(&engine);
|
2011-07-11 03:47:51 +00:00
|
|
|
component.setData("import QtQuick 2.0; Item { property bool layoutDirection: Qt.application.layoutDirection }", QUrl::fromLocalFile(""));
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickItem *item = qobject_cast<QQuickItem *>(component.create());
|
2011-04-27 10:05:43 +00:00
|
|
|
QVERIFY(item);
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickView view;
|
2011-07-11 03:47:51 +00:00
|
|
|
item->setParentItem(view.rootObject());
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
// not mirrored
|
|
|
|
QCOMPARE(Qt::LayoutDirection(item->property("layoutDirection").toInt()), Qt::LeftToRight);
|
|
|
|
|
|
|
|
// mirrored
|
2011-09-21 11:02:38 +00:00
|
|
|
QGuiApplication::setLayoutDirection(Qt::RightToLeft);
|
2011-10-19 05:04:15 +00:00
|
|
|
QEXPECT_FAIL("", "QTBUG-21573", Abort);
|
2011-04-27 10:05:43 +00:00
|
|
|
QCOMPARE(Qt::LayoutDirection(item->property("layoutDirection").toInt()), Qt::RightToLeft);
|
|
|
|
|
|
|
|
// not mirrored again
|
2011-09-21 11:02:38 +00:00
|
|
|
QGuiApplication::setLayoutDirection(Qt::LeftToRight);
|
2011-04-27 10:05:43 +00:00
|
|
|
QCOMPARE(Qt::LayoutDirection(item->property("layoutDirection").toInt()), Qt::LeftToRight);
|
|
|
|
}
|
|
|
|
|
2011-09-28 08:16:51 +00:00
|
|
|
void tst_qdeclarativeapplication::inputPanel()
|
|
|
|
{
|
|
|
|
QDeclarativeComponent component(&engine);
|
|
|
|
component.setData("import QtQuick 2.0; Item { property variant inputPanel: Qt.application.inputPanel }", QUrl::fromLocalFile(""));
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickItem *item = qobject_cast<QQuickItem *>(component.create());
|
2011-09-28 08:16:51 +00:00
|
|
|
QVERIFY(item);
|
2011-10-14 08:51:42 +00:00
|
|
|
QQuickView view;
|
2011-09-28 08:16:51 +00:00
|
|
|
item->setParentItem(view.rootObject());
|
|
|
|
|
|
|
|
// check that the inputPanel property maches with application's input panel
|
|
|
|
QCOMPARE(qvariant_cast<QObject*>(item->property("inputPanel")), qApp->inputPanel());
|
|
|
|
}
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
QTEST_MAIN(tst_qdeclarativeapplication)
|
|
|
|
|
|
|
|
#include "tst_qdeclarativeapplication.moc"
|