Display current battery level and charging status - milestone achieved!

This commit is contained in:
Matti Viljanen 2019-01-05 17:15:32 +02:00
parent 5b99d11f3f
commit 18bf91fdce
5 changed files with 28 additions and 49 deletions

View file

@ -19,14 +19,13 @@ SOURCES += src/harbour-batterybuddy.cpp \
DISTFILES += qml/harbour-batterybuddy.qml \
qml/cover/CoverPage.qml \
qml/pages/FirstPage.qml \
qml/pages/SecondPage.qml \
rpm/harbour-batterybuddy.changes.in \
rpm/harbour-batterybuddy.changes.run.in \
rpm/harbour-batterybuddy.spec \
rpm/harbour-batterybuddy.yaml \
translations/*.ts \
harbour-batterybuddy.desktop
harbour-batterybuddy.desktop \
qml/pages/MainPage.qml
SAILFISHAPP_ICONS = 86x86 108x108 128x128 172x172

View file

@ -4,7 +4,7 @@ import "pages"
ApplicationWindow
{
initialPage: Component { FirstPage { } }
initialPage: Component { MainPage { } }
cover: Qt.resolvedUrl("cover/CoverPage.qml")
allowedOrientations: defaultAllowedOrientations
}

View file

@ -11,14 +11,6 @@ Page {
SilicaFlickable {
anchors.fill: parent
// PullDownMenu and PushUpMenu must be declared in SilicaFlickable, SilicaListView or SilicaGridView
PullDownMenu {
MenuItem {
text: qsTr("Show Page 2")
onClicked: pageStack.push(Qt.resolvedUrl("SecondPage.qml"))
}
}
// Tell SilicaFlickable the height of its content.
contentHeight: column.height
@ -30,13 +22,15 @@ Page {
width: page.width
spacing: Theme.paddingLarge
PageHeader {
title: qsTr("UI Template")
title: qsTr("Battery Buddy")
}
Label {
x: Theme.horizontalPageMargin
text: qsTr("Hello Sailors")
color: Theme.secondaryHighlightColor
font.pixelSize: Theme.fontSizeExtraLarge
DetailItem {
label: qsTr("Charge level")
value: battery.charge;
}
DetailItem {
label: qsTr("Charging")
value: battery.charging ? "yes" : "no";
}
}
}

View file

@ -1,30 +0,0 @@
import QtQuick 2.0
import Sailfish.Silica 1.0
Page {
id: page
// The effective value will be restricted by ApplicationWindow.allowedOrientations
allowedOrientations: Orientation.All
SilicaListView {
id: listView
model: 20
anchors.fill: parent
header: PageHeader {
title: qsTr("Nested Page")
}
delegate: BackgroundItem {
id: delegate
Label {
x: Theme.horizontalPageMargin
text: qsTr("Item") + " " + index
anchors.verticalCenter: parent.verticalCenter
color: delegate.highlighted ? Theme.highlightColor : Theme.primaryColor
}
onClicked: console.log("Clicked " + index)
}
VerticalScrollDecorator {}
}
}

View file

@ -4,6 +4,13 @@
#include <sailfishapp.h>
#include <QGuiApplication>
#include <QQmlContext>
#include <QQuickView>
#include <QQmlEngine>
#include "battery.h"
int main(int argc, char *argv[])
{
// SailfishApp::main() will display "qml/harbour-batterybuddy.qml", if you need more
@ -16,5 +23,14 @@ int main(int argc, char *argv[])
//
// To display the view, call "show()" (will show fullscreen on device).
return SailfishApp::main(argc, argv);
QGuiApplication* app = SailfishApp::application(argc, argv);
QQuickView* view = SailfishApp::createView();
Battery battery;
view->engine()->addImportPath("/usr/share/harbour-carbudget/qml");
view->rootContext()->setContextProperty("battery", &battery);
view->setSource(SailfishApp::pathTo("qml/harbour-batterybuddy.qml"));
view->showFullScreen();
return app->exec();
}