diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/automationhelper.cpp | 91 | ||||
-rw-r--r-- | src/automationhelper.h | 47 | ||||
-rw-r--r-- | src/main.cpp | 2 | ||||
-rw-r--r-- | src/settingsmanager.cpp | 13 | ||||
-rw-r--r-- | src/settingsmanager.h | 6 |
5 files changed, 158 insertions, 1 deletions
diff --git a/src/automationhelper.cpp b/src/automationhelper.cpp new file mode 100644 index 0000000..b4c6a99 --- /dev/null +++ b/src/automationhelper.cpp @@ -0,0 +1,91 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt for Device Creation. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "automationhelper.h" +#include <QCoreApplication> +#include <QApplication> +#include <QQuickWindow> + +AutomationHelper::AutomationHelper(QObject* parent) : + QObject(parent) +{ +} + +/*! + * \brief Click center of given QQuickItem + * \param item Item to click + */ +void AutomationHelper::click(QQuickItem* item) +{ + QQuickWindow* window = item->window(); + if (!window) { + qWarning()<<"No window for item "<<item; + return; + } + + int centerX = static_cast<int>(item->width()/2); + int centerY = static_cast<int>(item->height()/2); + QPointF globalCoordinates = item->mapToGlobal(QPoint(centerX, centerY)); + QPointF windowCoordinates = window->mapFromGlobal(globalCoordinates.toPoint()); + + QMouseEvent pressEvent(QEvent::MouseButtonPress, windowCoordinates, windowCoordinates, windowCoordinates, + Qt::MouseButton::LeftButton, Qt::NoButton, Qt::NoModifier, Qt::MouseEventSynthesizedByApplication); + QMouseEvent releaseEvent(QEvent::MouseButtonRelease, windowCoordinates, windowCoordinates, windowCoordinates, + Qt::MouseButton::LeftButton, Qt::NoButton, Qt::NoModifier, Qt::MouseEventSynthesizedByApplication); + QApplication::instance()->sendEvent(window, &pressEvent); + QApplication::instance()->sendEvent(window, &releaseEvent); +} + +/*! + * \brief Click center of child item of given QQuickItem + * \param item Item which child to click + * \param childObjectName Object name of the child to click + */ +void AutomationHelper::clickChildObject(QQuickItem* item, QString childObjectName) +{ + QQuickItem* obj = findChildObject(item, childObjectName); + if (!obj) { + qWarning()<<"No such child "<<childObjectName<<" for "<<item; + return; + } + + click(obj); +} + +/*! + * \brief Find child item of given QQuickItem + * + * This function is needed for exposing findChildObject to QML + * \param item Item which child to find + * \param childObjectName Object name of the child to find + * \return found child + */ +QQuickItem* AutomationHelper::findChildObject(QQuickItem* item, QString childObjectName) +{ + return item->findChild<QQuickItem*>(childObjectName); +} diff --git a/src/automationhelper.h b/src/automationhelper.h new file mode 100644 index 0000000..8ed5000 --- /dev/null +++ b/src/automationhelper.h @@ -0,0 +1,47 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt for Device Creation. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef AUTOMATIONHELPER_H +#define AUTOMATIONHELPER_H + +#include <QObject> +#include <QQuickItem> + +class AutomationHelper : public QObject +{ + Q_OBJECT +public: + AutomationHelper(QObject *parent = 0); + +public slots: + void click(QQuickItem* item); + void clickChildObject(QQuickItem* item, QString childObjectName); + QQuickItem* findChildObject(QQuickItem* item, QString childObjectName); +}; + +#endif // AUTOMATIONHELPER_H diff --git a/src/main.cpp b/src/main.cpp index 4c41ca6..792351f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -51,6 +51,7 @@ #include "settingsmanager.h" #include "imageproviders.h" #include "circularindicator.h" +#include "automationhelper.h" void displayHelp(const char *appName) { @@ -121,6 +122,7 @@ int main(int argc, char **argv) qmlRegisterType<ApplicationsModel>("com.qtcompany.B2QtLauncher", 1, 0, "LauncherApplicationsModel"); qmlRegisterType<Engine>("com.qtcompany.B2QtLauncher", 1, 0, "LauncherEngine"); qmlRegisterType<CircularIndicator>("Circle", 1, 0, "CircularIndicator"); + qmlRegisterType<AutomationHelper>("AutomationHelper", 1, 0, "AutomationHelper"); QQmlApplicationEngine engine; SettingsManager settings; diff --git a/src/settingsmanager.cpp b/src/settingsmanager.cpp index 55e5def..e8dfc77 100644 --- a/src/settingsmanager.cpp +++ b/src/settingsmanager.cpp @@ -91,3 +91,16 @@ void SettingsManager::setRotationSelected(bool enabled) setValue("rotationSelected", enabled); emit rotationSelectedChanged(enabled); } + +bool SettingsManager::demoModeSelected() +{ + return getValue("demoModeSelected", false).toBool(); +} + +void SettingsManager::setDemoModeSelected(bool enabled) +{ + if (demoModeSelected() == enabled) + return; + setValue("demoModeSelected", enabled); + emit demoModeSelectedChanged(enabled); +} diff --git a/src/settingsmanager.h b/src/settingsmanager.h index cc41a0a..50a8900 100644 --- a/src/settingsmanager.h +++ b/src/settingsmanager.h @@ -36,7 +36,7 @@ class SettingsManager : public QObject { Q_OBJECT public: - explicit SettingsManager(QObject *parent = 0); + explicit SettingsManager(QObject *parent = nullptr); ~SettingsManager(); Q_INVOKABLE QVariant getValue(const QString& key, const QVariant &defaultValue); @@ -53,14 +53,18 @@ public: void setMouseSelected(bool enabled); Q_PROPERTY (bool rotationSelected READ rotationSelected WRITE setRotationSelected NOTIFY rotationSelectedChanged) + Q_PROPERTY (bool demoModeSelected READ demoModeSelected WRITE setDemoModeSelected NOTIFY demoModeSelectedChanged) bool rotationSelected(); void setRotationSelected(bool enabled); + bool demoModeSelected(); + void setDemoModeSelected(bool enabled); signals: void gridSelectedChanged(bool enabled); void mouseSelectedChanged(bool enabled); void rotationSelectedChanged(bool enabled); + void demoModeSelectedChanged(bool enabled); private: QSettings m_settings; |