~mpredotka/mini-maker/MiniMakerFA

« back to all changes in this revision

Viewing changes to MiniMakerFF/Main.qml

  • Committer: Michal Predotka
  • Date: 2016-06-22 21:54:31 UTC
  • Revision ID: mpredotka@gmail.com-20160622215431-tqyb17nda9nkkhu3
Initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import QtQuick 2.4
 
2
import Ubuntu.Components 1.3
 
3
import QtQuick.Window 2.2
 
4
import Qt.labs.settings 1.0
 
5
import "Storage.js" as Storage
 
6
 
 
7
Window {
 
8
    id: main_window
 
9
 
 
10
    property bool isPlayScreen: false
 
11
    property bool isShowScreen: false
 
12
    property bool isAboutScreen: false
 
13
    property string backgroundImg: "backs/background1.svg"
 
14
    property bool menuPanelVisible: false
 
15
    property bool backPanelVisible: false
 
16
    property bool binPanelVisible: false
 
17
    property bool hasSnaps: false
 
18
    property int panelHeight: Math.min(main_window.height / 8, units.gu(15))
 
19
 
 
20
    function createElementObjects(x, y, img, widthStart, sMin, sMax)
 
21
    {
 
22
        var component = Qt.createComponent("Element.qml");
 
23
        var element = component.createObject(play_field, {"x": x, "y": y, "elemImg": img, "widthStart": widthStart, "elemMinScale": sMin, "elemMaxScale": sMax});
 
24
 
 
25
        if (element == null) {
 
26
            // Error Handling
 
27
            console.log("Error creating object");
 
28
        }
 
29
    }
 
30
 
 
31
    function recreateElementObjects(iurl, x, y, scale, mirror, width)
 
32
    {
 
33
        var component = Qt.createComponent("ShowElement.qml");
 
34
        var element = component.createObject(screen_loader.item.back_listview.currentItem, {"elemImg": iurl, "x": x, "y": y, "scale": scale, "isMirror": mirror, "widthStart": width });
 
35
 
 
36
        if (element == null) {
 
37
            // Error Handling
 
38
            console.log("Error creating object");
 
39
        }
 
40
    }
 
41
 
 
42
    function createSnapImage(imgSource)
 
43
    {
 
44
        var component = Qt.createComponent("SnapImage.qml")
 
45
        var newSnap = component.createObject(main_window, {"img_source": imgSource,"img_width": play_field.width, "img_height": play_field.height})
 
46
 
 
47
        if (element == null) {
 
48
            // Error Handling
 
49
            console.log("Error creating object");
 
50
        }
 
51
    }
 
52
 
 
53
    visibility: Window.FullScreen
 
54
    title: "Mini Maker"
 
55
    width: units.gu(100)
 
56
    height: units.gu(60)
 
57
    minimumWidth: units.gu(60)
 
58
    minimumHeight: units.gu(40)
 
59
 
 
60
    Component.onCompleted: {
 
61
        Storage.createSnapsTable()
 
62
        Storage.createBacksTable()
 
63
    }
 
64
 
 
65
    Settings {
 
66
        id: settings
 
67
 
 
68
        property alias gotSnaps: main_window.hasSnaps
 
69
        property alias backgroundImg: main_window.backgroundImg
 
70
    }
 
71
 
 
72
    MainView {
 
73
        applicationName: "minimakerff.mivoligo"
 
74
        anchors.fill: parent
 
75
 
 
76
        MouseArea {
 
77
            enabled: isPlayScreen
 
78
            anchors.fill: parent
 
79
            anchors.topMargin: panelHeight
 
80
            onClicked: {
 
81
                menuPanelVisible = false
 
82
                backPanelVisible = false
 
83
            }
 
84
        }
 
85
 
 
86
        Loader {
 
87
            active: binPanelVisible
 
88
            width: parent.width
 
89
            height: panelHeight
 
90
            source: "BinPanel.qml"
 
91
        }
 
92
 
 
93
        Image {
 
94
            id: start_screen_background
 
95
 
 
96
            scale: 2
 
97
            visible: !isPlayScreen && !isAboutScreen
 
98
            source: "ui/start-back.svg"
 
99
            sourceSize.height: parent.height
 
100
            height: parent.height
 
101
            anchors {
 
102
                bottom: parent.bottom
 
103
                horizontalCenter: parent.horizontalCenter
 
104
            }
 
105
            Component.onCompleted: NumberAnimation {target: start_screen_background; property: "scale"; easing.type: Easing.OutCubic; to: 1; duration: 1000}
 
106
        }
 
107
 
 
108
        Component {
 
109
            id: play_background_comp
 
110
 
 
111
            Image {
 
112
                source: backgroundImg
 
113
                sourceSize.height: main_window.height - panelHeight
 
114
                fillMode: Image.PreserveAspectCrop
 
115
            }
 
116
        }
 
117
 
 
118
        Loader {
 
119
            id: play_back_loader
 
120
 
 
121
            active: isPlayScreen
 
122
            anchors {
 
123
                fill: parent
 
124
                topMargin: panelHeight
 
125
            }
 
126
            sourceComponent: play_background_comp
 
127
        }
 
128
 
 
129
        Item {
 
130
            id: play_field
 
131
 
 
132
            visible: isPlayScreen
 
133
            anchors.fill: parent
 
134
            anchors.topMargin: panelHeight
 
135
        }
 
136
 
 
137
        Loader {
 
138
            id: element_panel_loader
 
139
 
 
140
            active: isPlayScreen
 
141
            width: parent.width
 
142
            height: panelHeight
 
143
            source: "ElementsPanel.qml"
 
144
        }
 
145
 
 
146
        Loader {
 
147
            id: screen_loader
 
148
 
 
149
            anchors.fill: parent
 
150
            source: {
 
151
                if(isShowScreen) {
 
152
                    "ShowScreen.qml"
 
153
                }
 
154
                else if (isAboutScreen) {
 
155
                    "AboutPage.qml"
 
156
                }
 
157
                else if (!isPlayScreen) {
 
158
                    "StartScreen.qml"
 
159
                }
 
160
                else {""}
 
161
            }
 
162
        }
 
163
 
 
164
        Rectangle {
 
165
            id: flash
 
166
 
 
167
            anchors.centerIn: parent
 
168
            color: "white"
 
169
            width: 0
 
170
            height: 0
 
171
        }
 
172
    }
 
173
}
 
174