summaryrefslogtreecommitdiffstats
path: root/src/engine.h
blob: 06a6c8b213232e45543e0d49e7b878b30970a33e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/******************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt for Device Creation.
**
** $QT_BEGIN_LICENSE:COMM$
**
** 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.
**
** $QT_END_LICENSE$
**
******************************************************************************/
#ifndef ENGINE_H
#define ENGINE_H

#include <QQuickItem>
#include <QUrl>
#include <QSize>

#include <QColor>

class QQmlEngine;
class FpsCounter;
class QQuickWindow;

class Engine : public QQuickItem
{
    Q_OBJECT

    Q_PROPERTY(QString state READ state WRITE setState NOTIFY stateChanged)

    Q_PROPERTY(bool bootAnimationEnabled READ isBootAnimationEnabled WRITE setBootAnimationEnabled NOTIFY bootAnimationEnabledChanged)

    Q_PROPERTY(QUrl applicationMain READ applicationMain NOTIFY applicationMainChanged)
    Q_PROPERTY(QUrl applicationUrl READ applicationUrl NOTIFY applicationUrlChanged)
    Q_PROPERTY(QString applicationName READ applicationName NOTIFY applicationNameChanged)

    Q_PROPERTY(bool fpsEnabled READ isFpsEnabled WRITE setFpsEnabled NOTIFY fpsEnabledChanged)
    Q_PROPERTY(qreal fps READ fps NOTIFY fpsChanged)

    Q_PROPERTY(const QString qtVersion READ qtVersion)

    Q_PROPERTY(bool glAvailable READ glAvailable NOTIFY glAvailableChanged)

public:
    explicit Engine(QQuickItem *parent = 0);
    
    QString state() const { return m_state; }
    void setState(const QString &state);

    bool isFpsEnabled() const { return m_fps_enabled; }
    void setFpsEnabled(bool enabled);

    qreal fps() const { return m_fps; }

    bool isBootAnimationEnabled() const { return m_bootAnimationEnabled; }
    void setBootAnimationEnabled(bool enabled);

    QString qtVersion() const { return QT_VERSION_STR; }

    QUrl applicationUrl() const { return m_applicationUrl; }
    QUrl applicationMain() const { return m_applicationMain; }
    QString applicationName() const { return m_applicationName; }

    Q_INVOKABLE QUrl fromUserInput(const QString& userInput) { return QUrl::fromUserInput(userInput); }
    Q_INVOKABLE int sensibleButtonSize() const;
    Q_INVOKABLE int titleBarSize() const;
    Q_INVOKABLE int smallFontSize() const { return qMax<int>(m_dpcm * 0.4, 10); }
    Q_INVOKABLE int fontSize() const { return qMax<int>(m_dpcm * 0.6, 14); }
    Q_INVOKABLE int titleFontSize() const { return qMax<int>(m_dpcm * 0.9, 20); }
    Q_INVOKABLE int centimeter(int val = 1) const { return (m_dpcm * val); }
    Q_INVOKABLE int mm(int val) const { return (int)(m_dpcm * val * 0.1); }
    Q_INVOKABLE int screenWidth() const { return m_screenWidth; }
    Q_INVOKABLE int screenHeight() const { return m_screenHeight; }
    Q_INVOKABLE bool glAvailable() const { return m_glAvailable; }

protected:

signals:
    void stateChanged(const QString &state);
    void activeIconChanged(QQuickItem *item);
    void applicationUrlChanged(const QUrl &applicationUrl);
    void applicationMainChanged(const QUrl &applicationMain);
    void applicationNameChanged(const QString &applicationName);
    void bootAnimationEnabledChanged(bool enabled);
    void fpsChanged(qreal fps);
    void fpsEnabledChanged(bool enabled);
    void glAvailableChanged(bool available);

public slots:
    void markApplicationsModelReady() { m_apps_ready = true; updateReadyness(); }
    void markIntroAnimationDone() { m_intro_done = true; updateReadyness(); }

    void launchApplication(const QUrl &location, const QString &mainFile, const QString &name);
    void closeApplication();

    void setFps(qreal fps);

    bool fileExists(const QUrl &fileName);

private slots:
    void windowChanged(QQuickWindow *window);

private:
    void updateReadyness();
    void updateFPSCounter();

    QString m_state;

    QUrl m_applicationUrl;
    QUrl m_applicationMain;
    QString m_applicationName;

    QSize m_screenSize;
    qreal m_dpcm;
    int m_screenWidth, m_screenHeight;

    FpsCounter *m_fpsCounter;
    qreal m_fps;

    uint m_intro_done : 1;
    uint m_apps_ready : 1;
    uint m_fps_enabled : 1;
    uint m_bootAnimationEnabled : 1;
    bool m_glAvailable;
};

#endif // ENGINE_H