summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndras Becsi <andras.becsi@theqtcompany.com>2015-07-30 20:40:38 +0200
committerAndras Becsi <andras.becsi@theqtcompany.com>2015-08-12 17:22:03 +0200
commit8e0d455a73278fd223bcb863de778019c74caaa3 (patch)
tree1f02916bd7caf94e4fc60e2b507fb4b74c1f6bc5 /src
parentdd4d6530713c7a7ab52910b977929fb984981697 (diff)
Factor out utils.h to engine.h and cpp
Diffstat (limited to 'src')
-rw-r--r--src/browserwindow.cpp4
-rw-r--r--src/engine.cpp (renamed from src/utils.h)77
-rw-r--r--src/engine.h103
-rw-r--r--src/main.cpp2
-rw-r--r--src/src.pro8
-rw-r--r--src/touchmockingapplication.cpp2
6 files changed, 118 insertions, 78 deletions
diff --git a/src/browserwindow.cpp b/src/browserwindow.cpp
index 7e4e4ff..410dc44 100644
--- a/src/browserwindow.cpp
+++ b/src/browserwindow.cpp
@@ -36,7 +36,7 @@
****************************************************************************/
#include "browserwindow.h"
-#include "utils.h"
+#include "engine.h"
#include <QList>
#include <QQmlContext>
@@ -78,7 +78,7 @@ BrowserWindow::BrowserWindow(QWindow *)
setResizeMode(QQuickView::SizeRootObjectToView);
setColor(Qt::black);
- engine()->rootContext()->setContextProperty("engine", new Utils(this));
+ engine()->rootContext()->setContextProperty("engine", new Engine(this));
setSource(QUrl("qrc:///qml/BrowserWindow.qml"));
}
diff --git a/src/utils.h b/src/engine.cpp
index 04c181e..84b0c0e 100644
--- a/src/utils.h
+++ b/src/engine.cpp
@@ -35,72 +35,9 @@
**
****************************************************************************/
-#ifndef UTILS_H
-#define UTILS_H
+#include "engine.h"
-#include <QtCore/QEvent>
-#include <QtCore/QFileInfo>
-#include <QtCore/QUrl>
-#include <QtGui/QColor>
-#include <QtQuick/QQuickItemGrabResult>
-
-namespace utils {
-inline bool isTouchEvent(const QEvent* event)
-{
- switch (event->type()) {
- case QEvent::TouchBegin:
- case QEvent::TouchUpdate:
- case QEvent::TouchEnd:
- return true;
- default:
- return false;
- }
-}
-
-inline bool isMouseEvent(const QEvent* event)
-{
- switch (event->type()) {
- case QEvent::MouseButtonPress:
- case QEvent::MouseMove:
- case QEvent::MouseButtonRelease:
- case QEvent::MouseButtonDblClick:
- return true;
- default:
- return false;
- }
-}
-
-inline int randomColor()
-{
- return qrand() % 255;
-}
-
-}
-
-class Utils : public QObject {
- Q_OBJECT
-
- Q_PROPERTY(QObject * rootWindow READ rootWindow FINAL CONSTANT)
-
-public:
- Utils(QObject *parent)
- : QObject(parent)
- {
- qsrand(255);
- }
- QObject *rootWindow()
- {
- return parent();
- }
-
- Q_INVOKABLE static QUrl fromUserInput(const QString& userInput);
- Q_INVOKABLE static QString domainFromString(const QString& urlString);
- Q_INVOKABLE static QString randomColor();
- Q_INVOKABLE static QString colorForIcon(QQuickItemGrabResult *result);
- Q_INVOKABLE static QString oppositeColor(const QString & color);
-};
-
-inline QUrl Utils::fromUserInput(const QString& userInput)
+QUrl Engine::fromUserInput(const QString& userInput)
{
QFileInfo fileInfo(userInput);
if (fileInfo.exists())
@@ -108,18 +45,18 @@ inline QUrl Utils::fromUserInput(const QString& userInput)
return QUrl::fromUserInput(userInput);
}
-inline QString Utils::domainFromString(const QString& urlString)
+QString Engine::domainFromString(const QString& urlString)
{
return QUrl::fromUserInput(urlString).host();
}
-inline QString Utils::randomColor()
+QString Engine::randomColor()
{
QColor color(utils::randomColor(), utils::randomColor(), utils::randomColor());
return color.name();
}
-inline QString Utils::colorForIcon(QQuickItemGrabResult *result)
+QString Engine::colorForIcon(QQuickItemGrabResult *result)
{
QImage image = result->image();
int hue = 0;
@@ -149,10 +86,8 @@ inline QString Utils::colorForIcon(QQuickItemGrabResult *result)
return QColor::fromHsv(hue, saturation, value).name();
}
-inline QString Utils::oppositeColor(const QString &color)
+QString Engine::oppositeColor(const QString &color)
{
const QColor c(QColor(color).toHsv());
return QColor::fromHsv(c.hue(), c.saturation(), c.value() < 127 ? 255 : c.value() - 100).name();
}
-
-#endif // UTILS_H
diff --git a/src/engine.h b/src/engine.h
new file mode 100644
index 0000000..36cb561
--- /dev/null
+++ b/src/engine.h
@@ -0,0 +1,103 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the QtBrowser project.
+**
+** $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 http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://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 2 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPLv2 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
+**
+** 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.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef ENGINE_H
+#define ENGINE_H
+
+#include <QtCore/QEvent>
+#include <QtCore/QFileInfo>
+#include <QtCore/QUrl>
+#include <QtGui/QColor>
+#include <QtQuick/QQuickItemGrabResult>
+
+namespace utils {
+inline bool isTouchEvent(const QEvent* event)
+{
+ switch (event->type()) {
+ case QEvent::TouchBegin:
+ case QEvent::TouchUpdate:
+ case QEvent::TouchEnd:
+ return true;
+ default:
+ return false;
+ }
+}
+
+inline bool isMouseEvent(const QEvent* event)
+{
+ switch (event->type()) {
+ case QEvent::MouseButtonPress:
+ case QEvent::MouseMove:
+ case QEvent::MouseButtonRelease:
+ case QEvent::MouseButtonDblClick:
+ return true;
+ default:
+ return false;
+ }
+}
+
+inline int randomColor()
+{
+ return qrand() % 255;
+}
+
+}
+
+class Engine : public QObject {
+ Q_OBJECT
+
+ Q_PROPERTY(QObject * rootWindow READ rootWindow FINAL CONSTANT)
+
+public:
+ Engine(QObject *parent)
+ : QObject(parent)
+ {
+ qsrand(255);
+ }
+ QObject *rootWindow()
+ {
+ return parent();
+ }
+
+ Q_INVOKABLE static QUrl fromUserInput(const QString& userInput);
+ Q_INVOKABLE static QString domainFromString(const QString& urlString);
+ Q_INVOKABLE static QString randomColor();
+ Q_INVOKABLE static QString colorForIcon(QQuickItemGrabResult *result);
+ Q_INVOKABLE static QString oppositeColor(const QString & color);
+};
+
+#endif // ENGINE_H
diff --git a/src/main.cpp b/src/main.cpp
index d35578d..d9e81f3 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -42,7 +42,7 @@
#include <QtWebEngine/qtwebengineglobal.h>
#include "touchmockingapplication.h"
-#include "utils.h"
+#include "engine.h"
#include "touchtracker.h"
int main(int argc, char **argv)
diff --git a/src/src.pro b/src/src.pro
index f70fb48..898d53d 100644
--- a/src/src.pro
+++ b/src/src.pro
@@ -7,12 +7,14 @@ CONFIG -= app_bundle
SOURCES = main.cpp \
touchmockingapplication.cpp \
browserwindow.cpp \
- touchtracker.cpp
+ touchtracker.cpp \
+ engine.cpp
-HEADERS = utils.h \
+HEADERS = \
touchmockingapplication.h \
browserwindow.h \
- touchtracker.h
+ touchtracker.h \
+ engine.h
OTHER_FILES = \
qml/assets/UIButton.qml \
diff --git a/src/touchmockingapplication.cpp b/src/touchmockingapplication.cpp
index d57c570..4819b01 100644
--- a/src/touchmockingapplication.cpp
+++ b/src/touchmockingapplication.cpp
@@ -44,7 +44,7 @@
#include <QMouseEvent>
#include <QTouchEvent>
-#include "utils.h"
+#include "engine.h"
using namespace utils;