162 lines
5.6 KiB
QML
162 lines
5.6 KiB
QML
import QtQuick 2.7
|
|
import QtQuick.Layouts 1.3
|
|
import Lomiri.Components 1.3
|
|
import Lomiri.Components.Popups 1.3
|
|
import io.thp.pyotherside 1.4
|
|
|
|
MainView {
|
|
id: root
|
|
applicationName: "fortunecookie.darklithium"
|
|
width: units.gu(45)
|
|
height: units.gu(75)
|
|
theme.name: "Lomiri.Components.Themes.SuruDark"
|
|
|
|
// ====================================================================
|
|
// 1. PYTHON-MODUL (STANDARD 1.7)
|
|
// ====================================================================
|
|
Python {
|
|
id: py
|
|
Component.onCompleted: {
|
|
addImportPath(Qt.resolvedUrl("../src"));
|
|
importModule("fortunecookie", function() {
|
|
console.log("Python-Modul fortunecookie geladen");
|
|
// Initialisierung
|
|
currentFortuneLabel.text = py.call_sync("fortunecookie.get_initial_fortune", []);
|
|
cookieImage.source = "assets/cookie_closed.png";
|
|
fortuneOpened = false;
|
|
});
|
|
}
|
|
}
|
|
|
|
// ====================================================================
|
|
// 2. APP-ZUSTAND (STANDARD 1.7)
|
|
// ====================================================================
|
|
property bool fortuneOpened: false
|
|
property string currentFortune: ""
|
|
property bool musicPlaying: false
|
|
|
|
// ====================================================================
|
|
// 3. HAUPTSEITE
|
|
// ====================================================================
|
|
Page {
|
|
id: mainPage
|
|
anchors.fill: parent
|
|
|
|
// Header
|
|
header: PageHeader {
|
|
title: "Fortune Cookie"
|
|
}
|
|
|
|
// ================================================================
|
|
// COOKIE & SPRUCH
|
|
// ================================================================
|
|
|
|
// Cookie-Image (zentral)
|
|
Image {
|
|
id: cookieImage
|
|
anchors.centerIn: parent
|
|
width: units.gu(30)
|
|
height: units.gu(30)
|
|
source: fortuneOpened ? "assets/cookie_open.png" : "assets/cookie_closed.png"
|
|
|
|
// Wisch-Geste nach oben
|
|
MouseArea {
|
|
anchors.fill: parent
|
|
property real startY: 0
|
|
|
|
onPressed: {
|
|
startY = mouseY
|
|
}
|
|
|
|
onReleased: {
|
|
// Ende der Geste - pruufen ob nach oben gewischt
|
|
if (mouseY < startY - units.gu(2)) {
|
|
// Wisch nach oben -> Cookie oeffnen
|
|
py.call("fortunecookie.open_fortune", [], function() {
|
|
fortuneOpened = true;
|
|
currentFortune = py.call_sync("fortunecookie.get_current_fortune", []);
|
|
currentFortuneLabel.text = currentFortune;
|
|
cookieImage.source = "assets/cookie_open.png";
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
// Tap auf Cookie (wenn geschlossen)
|
|
MouseArea {
|
|
anchors.fill: parent
|
|
hoverEnabled: true
|
|
|
|
onClicked: {
|
|
if (!fortuneOpened) {
|
|
// Cookie oeffnen (gleiche Funktion wie Wisch nach oben)
|
|
py.call("fortunecookie.open_fortune", [], function() {
|
|
fortuneOpened = true;
|
|
currentFortune = py.call_sync("fortunecookie.get_current_fortune", []);
|
|
currentFortuneLabel.text = currentFortune;
|
|
cookieImage.source = "assets/cookie_open.png";
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Fortune-Text (erscheint nach dem Oeffnen)
|
|
Label {
|
|
id: currentFortuneLabel
|
|
anchors {
|
|
top: cookieImage.bottom
|
|
topMargin: units.gu(2)
|
|
left: parent.left
|
|
right: parent.right
|
|
leftMargin: units.gu(2)
|
|
rightMargin: units.gu(2)
|
|
}
|
|
text: ""
|
|
fontSize: "large"
|
|
horizontalAlignment: Text.AlignHCenter
|
|
visible: fortuneOpened
|
|
wrapMode: Text.WordWrap
|
|
|
|
// Tap auf Spruch -> neuer Cookie
|
|
MouseArea {
|
|
anchors.fill: parent
|
|
|
|
onClicked: {
|
|
py.call("fortunecookie.get_new_fortune", [], function() {
|
|
fortuneOpened = false;
|
|
currentFortune = py.call_sync("fortunecookie.get_current_fortune", []);
|
|
currentFortuneLabel.text = currentFortune;
|
|
cookieImage.source = "assets/cookie_closed.png";
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
// ================================================================
|
|
// MUSIK BUTTON (rechts unten)
|
|
// ================================================================
|
|
Button {
|
|
id: musicButton
|
|
anchors {
|
|
right: parent.right
|
|
bottom: parent.bottom
|
|
margins: units.gu(2)
|
|
}
|
|
width: units.gu(8)
|
|
height: units.gu(8)
|
|
text: musicPlaying ? "\uD83D\uDD07" : "\uD83D\uDD0A"
|
|
fontSize: "x-large"
|
|
|
|
onClicked: {
|
|
if (musicPlaying) {
|
|
py.call("fortunecookie.stop_music", []);
|
|
} else {
|
|
py.call("fortunecookie.start_music", []);
|
|
}
|
|
musicPlaying = !musicPlaying;
|
|
}
|
|
}
|
|
}
|
|
}
|