From 08cca3e186748b6bcafc43e73622589b7e9925bf Mon Sep 17 00:00:00 2001 From: Claudio Maradonna Date: Wed, 23 Aug 2017 12:02:27 +0200 Subject: [PATCH] Now about page is good. Fixed BUG with play of bells --- harbour-boxing-timer.pro | 3 +- qml/harbour-boxing-timer.qml | 6 +- qml/pages/AboutPage.qml | 121 +++++++++++++++++++++++++++++++++++ qml/pages/PresetList.qml | 54 ++++++++++------ qml/pages/SettingsPage.qml | 26 ++------ qml/pages/TimerPage.qml | 7 +- qml/pages/js/helpers.js | 5 ++ src/boxingtimer.cpp | 14 ++-- src/boxingtimer.h | 5 ++ 9 files changed, 186 insertions(+), 55 deletions(-) create mode 100644 qml/pages/js/helpers.js diff --git a/harbour-boxing-timer.pro b/harbour-boxing-timer.pro index ca6693c..4547066 100644 --- a/harbour-boxing-timer.pro +++ b/harbour-boxing-timer.pro @@ -37,7 +37,8 @@ DISTFILES += \ qml/pages/PresetList.qml \ qml/pages/AboutPage.qml \ COPYING \ - rpm/harbour-boxing-timer.changes + rpm/harbour-boxing-timer.changes \ + qml/pages/js/helpers.js HEADERS += \ src/boxingtimer.h \ diff --git a/qml/harbour-boxing-timer.qml b/qml/harbour-boxing-timer.qml index e8ebd10..30227b4 100644 --- a/qml/harbour-boxing-timer.qml +++ b/qml/harbour-boxing-timer.qml @@ -30,7 +30,6 @@ import QtQuick 2.0 import Sailfish.Silica 1.0 -import QtMultimedia 5.0 import Pw.Unitoo.Backend 1.0 import "pages" @@ -42,10 +41,7 @@ ApplicationWindow { BoxingSettings { id: settings - onPresetChanged: { - boxingTimer.loadPreset(preset) - boxingTimer.status = BoxingTimer.Stop - } + onPresetChanged: boxingTimer.loadPreset(preset) } initialPage: firstPage diff --git a/qml/pages/AboutPage.qml b/qml/pages/AboutPage.qml index 841ee80..5c04ee7 100644 --- a/qml/pages/AboutPage.qml +++ b/qml/pages/AboutPage.qml @@ -2,5 +2,126 @@ import QtQuick 2.2 import Sailfish.Silica 1.0 Page { + id: aboutPage + SilicaFlickable { + anchors.fill: parent + + contentHeight: column.height + + Column { + id: column + + width: aboutPage.width + + spacing: Theme.paddingLarge + + PageHeader { title: qsTr("About") } + + Label { + anchors { + left: parent.left + right: parent.right + + leftMargin: Theme.paddingLarge + rightMargin: Theme.paddingLarge + } + + wrapMode: Text.Wrap + + font.pixelSize: Theme.fontSizeSmall + text: qsTr(" +\"Boxing Timer\" is a customizable timer for fighting sports like boxe. + +You can set duration, rest and number of rounds. If you set 0 rounds, timer loops and count number of rounds. + +You can save, load and delete your settings giving a name to them. + ") + } + + SectionHeader { text: qsTr("Developers") } + Label { + anchors { + left: parent.left + right: parent.right + + leftMargin: Theme.paddingLarge + rightMargin: Theme.paddingLarge + } + + wrapMode: Text.Wrap + + font.pixelSize: Theme.fontSizeSmall + text: qsTr(" +Copyright (C) 2017 Claudio Maradonna +Unitoo Team, Italy + ") + } + + Repeater { + model: ListModel { + ListElement { label: "Email" ; value: "claudio@unitoo.pw" } + ListElement { label: "Diaspora" ; value: "claudiounitoo@framasphere.org" } + ListElement { label: "Mastodon" ; value: "@unitoo" } + ListElement { label: "XMPP" ; value: "unitoo@fysh.in" } + } + + delegate: Row { + width: aboutPage.width + + spacing: Theme.paddingLarge + + Label { + width: parent.width * 0.2; height: 25 + + font.pixelSize: Theme.fontSizeTiny + text: label + + horizontalAlignment: Text.AlignRight + verticalAlignment: Text.AlignVCenter + + color: Theme.secondaryColor + } + + Label { + height: 30 + + font.pixelSize: Theme.fontSizeSmall + text: value + + verticalAlignment: Text.AlignVCenter + } + } + } + + SectionHeader { text: qsTr("License") } + Label { + anchors { + left: parent.left + right: parent.right + + leftMargin: Theme.paddingLarge + rightMargin: Theme.paddingLarge + } + + wrapMode: Text.Wrap + + font.pixelSize: Theme.fontSizeSmall + text: qsTr(" +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . + ") + } + } + } } diff --git a/qml/pages/PresetList.qml b/qml/pages/PresetList.qml index ee3cf67..2054c0c 100644 --- a/qml/pages/PresetList.qml +++ b/qml/pages/PresetList.qml @@ -1,6 +1,8 @@ import QtQuick 2.2 import Sailfish.Silica 1.0 +import "js/helpers.js" as Helper + Page { onStatusChanged: { if (status === PageStatus.Activating) { @@ -14,40 +16,54 @@ Page { Column { PageHeader { title: qsTr("Saved presets") } - width: parent.width + width: parent.width; height: parent.height + spacing: Theme.paddingLarge SilicaListView { id: presetsList - width: parent.width; height: 800 + width: parent.width; height: parent.height model: listModel - delegate: BackgroundItem { - width: parent.width - height: Theme.itemSizeSmall + delegate: ListItem { + width: parent.width - onClicked: { - settings.preset = presetsList.model.get(index).name + onClicked: { + settings.preset = presetsList.model.get(index).name - pageStack.pop(firstPage) - } + pageStack.pop(firstPage) + } - Label { - text: name + menu: ContextMenu { + MenuItem { + text: qsTr("Delete") - color: highlighted ? Theme.highlightColor : Theme.primaryColor + onClicked: { + settings.deletePreset(presetsList.model.get(index).name) - anchors { - left: parent.left - right: parent.right + if (settings.presetsList().length < 1) { + pageStack.popAttached() + } + } + } + } - verticalCenter: parent.verticalCenter + Label { + text: name - margins: Theme.paddingLarge - } - } + color: highlighted ? Theme.highlightColor : Theme.primaryColor + + anchors { + left: parent.left + right: parent.right + + verticalCenter: parent.verticalCenter + + margins: Theme.paddingLarge + } + } } ListModel { diff --git a/qml/pages/SettingsPage.qml b/qml/pages/SettingsPage.qml index 755e214..92fd4b0 100644 --- a/qml/pages/SettingsPage.qml +++ b/qml/pages/SettingsPage.qml @@ -33,6 +33,7 @@ import Sailfish.Silica 1.0 import Pw.Unitoo.Backend 1.0 import "js/converter.js" as Converter +import "js/helpers.js" as Helper Page { id: settingsPage @@ -46,17 +47,9 @@ Page { property int mRoundMs: settings.roundsMs property int mRestMs: settings.restMs - function pushPopPresetListPage() { - if (settings.presetsList().length > 0) { - pageStack.pushAttached(Qt.resolvedUrl("PresetList.qml")) - } else { - pageStack.popAttached() - } - } - onStatusChanged: { if (status === PageStatus.Active) { - pushPopPresetListPage(); + Helper.pushPresetListPage(); } } @@ -73,20 +66,11 @@ Page { roundsSlider.value, roundsTimeSlider.value, Converter.sToMs(restSlider.value) - ) + ) - pushPopPresetListPage(); - } - } - } + boxingTimer.loadPreset(presetName.text) - PushUpMenu { - MenuItem { - text: qsTr("Delete") - onClicked: { - settings.deletePreset(presetName.text) - - pushPopPresetListPage(); + Helper.pushPresetListPage(); } } } diff --git a/qml/pages/TimerPage.qml b/qml/pages/TimerPage.qml index b198ea5..44bf9e3 100644 --- a/qml/pages/TimerPage.qml +++ b/qml/pages/TimerPage.qml @@ -40,7 +40,6 @@ Page { SilicaFlickable { anchors.fill: parent - // PullDownMenu and PushUpMenu must be declared in SilicaFlickable, SilicaListView or SilicaGridView PullDownMenu { MenuItem { text: qsTr("About") @@ -80,12 +79,10 @@ Page { SectionHeader { text: boxingTimer.preset } Label { - id: labelTimer - width: parent.width horizontalAlignment: Text.AlignHCenter - font.pixelSize: 244 + font.pixelSize: Theme.fontSizeHuge * 3.3 text: boxingTimer.remainingTimeToString color: boxingTimer.status == BoxingTimer.Rest ? Theme.secondaryColor : Theme.primaryColor } @@ -115,7 +112,7 @@ Page { width: parent.width horizontalAlignment: Text.AlignHCenter - font.pixelSize: 196 + font.pixelSize: Theme.fontSizeHuge * 2.6 text: boxingTimer.roundsToString } } diff --git a/qml/pages/js/helpers.js b/qml/pages/js/helpers.js new file mode 100644 index 0000000..c3da63a --- /dev/null +++ b/qml/pages/js/helpers.js @@ -0,0 +1,5 @@ +function pushPresetListPage() { + if (settings.presetsList().length > 0) { + pageStack.pushAttached(Qt.resolvedUrl("../PresetList.qml")) + } +} diff --git a/src/boxingtimer.cpp b/src/boxingtimer.cpp index b120590..3242420 100644 --- a/src/boxingtimer.cpp +++ b/src/boxingtimer.cpp @@ -15,6 +15,10 @@ BoxingTimer::BoxingTimer() : this->settings = new BoxingSettings(); this->mRemainingMilliseconds = settings->getRoundMilliseconds(); + this->playBell = new QSound(":/audio/resources/play.wav"); + this->restBell = new QSound(":/audio/resources/rest.wav"); + this->stopBell = new QSound(":/audio/resources/stop.wav"); + QObject::connect(this, SIGNAL(statusChanged()), this, SLOT(applyStatus())); QObject::connect(this, SIGNAL(timeout()), this, SLOT(updateRemainingMilliseconds())); } @@ -149,6 +153,8 @@ const QString BoxingTimer::roundsToString() { void BoxingTimer::loadPreset(const QString &preset) { this->settings->setPreset(preset); + this->mRemainingMilliseconds = settings->getRoundMilliseconds(); + this->mStatus = Status::Stop; emit presetChanged(); emit roundsToStringChanged(); @@ -157,10 +163,10 @@ void BoxingTimer::loadPreset(const QString &preset) { void BoxingTimer::songsBell() { if (this->mStatus == Status::Start) { - QSound::play(":/audio/resources/play.wav"); - } else if (this->mStatus == Status::Rest || this->mStatus == Status::Pause) { - QSound::play(":/audio/resources/rest.wav"); + this->playBell->play(); + } else if (this->mStatus == Status::Rest) { + this->restBell->play(); } else if (this->mStatus == Status::Stop) { - QSound::play(":/audio/resources/stop.wav"); + this->stopBell->play(); } } diff --git a/src/boxingtimer.h b/src/boxingtimer.h index f7dc794..b5c186e 100644 --- a/src/boxingtimer.h +++ b/src/boxingtimer.h @@ -13,6 +13,7 @@ * @defgroup QML What interacts with view */ +class QSound; class BoxingSettings; /** @@ -157,6 +158,10 @@ class BoxingTimer : public QTimer { void setRemainingMilliseconds(const int &milliseconds); void setRound(const int &round); + QSound *playBell; + QSound *restBell; + QSound *stopBell; + void songsBell(); Status mStatus;