Now about page is good. Fixed BUG with play of bells

This commit is contained in:
Claudio Maradonna 2017-08-23 12:02:27 +02:00
parent 01d5dd2f9c
commit 08cca3e186
9 changed files with 186 additions and 55 deletions

View File

@ -37,7 +37,8 @@ DISTFILES += \
qml/pages/PresetList.qml \ qml/pages/PresetList.qml \
qml/pages/AboutPage.qml \ qml/pages/AboutPage.qml \
COPYING \ COPYING \
rpm/harbour-boxing-timer.changes rpm/harbour-boxing-timer.changes \
qml/pages/js/helpers.js
HEADERS += \ HEADERS += \
src/boxingtimer.h \ src/boxingtimer.h \

View File

@ -30,7 +30,6 @@
import QtQuick 2.0 import QtQuick 2.0
import Sailfish.Silica 1.0 import Sailfish.Silica 1.0
import QtMultimedia 5.0
import Pw.Unitoo.Backend 1.0 import Pw.Unitoo.Backend 1.0
import "pages" import "pages"
@ -42,10 +41,7 @@ ApplicationWindow {
BoxingSettings { BoxingSettings {
id: settings id: settings
onPresetChanged: { onPresetChanged: boxingTimer.loadPreset(preset)
boxingTimer.loadPreset(preset)
boxingTimer.status = BoxingTimer.Stop
}
} }
initialPage: firstPage initialPage: firstPage

View File

@ -2,5 +2,126 @@ import QtQuick 2.2
import Sailfish.Silica 1.0 import Sailfish.Silica 1.0
Page { 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 <http://www.gnu.org/licenses/>.
")
}
}
}
} }

View File

@ -1,6 +1,8 @@
import QtQuick 2.2 import QtQuick 2.2
import Sailfish.Silica 1.0 import Sailfish.Silica 1.0
import "js/helpers.js" as Helper
Page { Page {
onStatusChanged: { onStatusChanged: {
if (status === PageStatus.Activating) { if (status === PageStatus.Activating) {
@ -14,40 +16,54 @@ Page {
Column { Column {
PageHeader { title: qsTr("Saved presets") } PageHeader { title: qsTr("Saved presets") }
width: parent.width width: parent.width; height: parent.height
spacing: Theme.paddingLarge spacing: Theme.paddingLarge
SilicaListView { SilicaListView {
id: presetsList id: presetsList
width: parent.width; height: 800 width: parent.width; height: parent.height
model: listModel model: listModel
delegate: BackgroundItem { delegate: ListItem {
width: parent.width width: parent.width
height: Theme.itemSizeSmall
onClicked: { onClicked: {
settings.preset = presetsList.model.get(index).name settings.preset = presetsList.model.get(index).name
pageStack.pop(firstPage) pageStack.pop(firstPage)
} }
Label { menu: ContextMenu {
text: name MenuItem {
text: qsTr("Delete")
color: highlighted ? Theme.highlightColor : Theme.primaryColor onClicked: {
settings.deletePreset(presetsList.model.get(index).name)
anchors { if (settings.presetsList().length < 1) {
left: parent.left pageStack.popAttached()
right: parent.right }
}
}
}
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 { ListModel {

View File

@ -33,6 +33,7 @@ import Sailfish.Silica 1.0
import Pw.Unitoo.Backend 1.0 import Pw.Unitoo.Backend 1.0
import "js/converter.js" as Converter import "js/converter.js" as Converter
import "js/helpers.js" as Helper
Page { Page {
id: settingsPage id: settingsPage
@ -46,17 +47,9 @@ Page {
property int mRoundMs: settings.roundsMs property int mRoundMs: settings.roundsMs
property int mRestMs: settings.restMs property int mRestMs: settings.restMs
function pushPopPresetListPage() {
if (settings.presetsList().length > 0) {
pageStack.pushAttached(Qt.resolvedUrl("PresetList.qml"))
} else {
pageStack.popAttached()
}
}
onStatusChanged: { onStatusChanged: {
if (status === PageStatus.Active) { if (status === PageStatus.Active) {
pushPopPresetListPage(); Helper.pushPresetListPage();
} }
} }
@ -73,20 +66,11 @@ Page {
roundsSlider.value, roundsSlider.value,
roundsTimeSlider.value, roundsTimeSlider.value,
Converter.sToMs(restSlider.value) Converter.sToMs(restSlider.value)
) )
pushPopPresetListPage(); boxingTimer.loadPreset(presetName.text)
}
}
}
PushUpMenu { Helper.pushPresetListPage();
MenuItem {
text: qsTr("Delete")
onClicked: {
settings.deletePreset(presetName.text)
pushPopPresetListPage();
} }
} }
} }

View File

@ -40,7 +40,6 @@ Page {
SilicaFlickable { SilicaFlickable {
anchors.fill: parent anchors.fill: parent
// PullDownMenu and PushUpMenu must be declared in SilicaFlickable, SilicaListView or SilicaGridView
PullDownMenu { PullDownMenu {
MenuItem { MenuItem {
text: qsTr("About") text: qsTr("About")
@ -80,12 +79,10 @@ Page {
SectionHeader { text: boxingTimer.preset } SectionHeader { text: boxingTimer.preset }
Label { Label {
id: labelTimer
width: parent.width width: parent.width
horizontalAlignment: Text.AlignHCenter horizontalAlignment: Text.AlignHCenter
font.pixelSize: 244 font.pixelSize: Theme.fontSizeHuge * 3.3
text: boxingTimer.remainingTimeToString text: boxingTimer.remainingTimeToString
color: boxingTimer.status == BoxingTimer.Rest ? Theme.secondaryColor : Theme.primaryColor color: boxingTimer.status == BoxingTimer.Rest ? Theme.secondaryColor : Theme.primaryColor
} }
@ -115,7 +112,7 @@ Page {
width: parent.width width: parent.width
horizontalAlignment: Text.AlignHCenter horizontalAlignment: Text.AlignHCenter
font.pixelSize: 196 font.pixelSize: Theme.fontSizeHuge * 2.6
text: boxingTimer.roundsToString text: boxingTimer.roundsToString
} }
} }

5
qml/pages/js/helpers.js Normal file
View File

@ -0,0 +1,5 @@
function pushPresetListPage() {
if (settings.presetsList().length > 0) {
pageStack.pushAttached(Qt.resolvedUrl("../PresetList.qml"))
}
}

View File

@ -15,6 +15,10 @@ BoxingTimer::BoxingTimer() :
this->settings = new BoxingSettings(); this->settings = new BoxingSettings();
this->mRemainingMilliseconds = settings->getRoundMilliseconds(); 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(statusChanged()), this, SLOT(applyStatus()));
QObject::connect(this, SIGNAL(timeout()), this, SLOT(updateRemainingMilliseconds())); QObject::connect(this, SIGNAL(timeout()), this, SLOT(updateRemainingMilliseconds()));
} }
@ -149,6 +153,8 @@ const QString BoxingTimer::roundsToString() {
void BoxingTimer::loadPreset(const QString &preset) { void BoxingTimer::loadPreset(const QString &preset) {
this->settings->setPreset(preset); this->settings->setPreset(preset);
this->mRemainingMilliseconds = settings->getRoundMilliseconds();
this->mStatus = Status::Stop;
emit presetChanged(); emit presetChanged();
emit roundsToStringChanged(); emit roundsToStringChanged();
@ -157,10 +163,10 @@ void BoxingTimer::loadPreset(const QString &preset) {
void BoxingTimer::songsBell() { void BoxingTimer::songsBell() {
if (this->mStatus == Status::Start) { if (this->mStatus == Status::Start) {
QSound::play(":/audio/resources/play.wav"); this->playBell->play();
} else if (this->mStatus == Status::Rest || this->mStatus == Status::Pause) { } else if (this->mStatus == Status::Rest) {
QSound::play(":/audio/resources/rest.wav"); this->restBell->play();
} else if (this->mStatus == Status::Stop) { } else if (this->mStatus == Status::Stop) {
QSound::play(":/audio/resources/stop.wav"); this->stopBell->play();
} }
} }

View File

@ -13,6 +13,7 @@
* @defgroup QML What interacts with view * @defgroup QML What interacts with view
*/ */
class QSound;
class BoxingSettings; class BoxingSettings;
/** /**
@ -157,6 +158,10 @@ class BoxingTimer : public QTimer {
void setRemainingMilliseconds(const int &milliseconds); void setRemainingMilliseconds(const int &milliseconds);
void setRound(const int &round); void setRound(const int &round);
QSound *playBell;
QSound *restBell;
QSound *stopBell;
void songsBell(); void songsBell();
Status mStatus; Status mStatus;