diff --git a/harbour-boxing-timer.qrc b/harbour-boxing-timer.qrc index 551e9dd..4672355 100644 --- a/harbour-boxing-timer.qrc +++ b/harbour-boxing-timer.qrc @@ -3,5 +3,6 @@ resources/play.wav resources/rest.wav resources/stop.wav + resources/inner.wav diff --git a/icons/108x108/harbour-boxing-timer.png b/icons/108x108/harbour-boxing-timer.png index ab10628..f0a535c 100644 Binary files a/icons/108x108/harbour-boxing-timer.png and b/icons/108x108/harbour-boxing-timer.png differ diff --git a/icons/128x128/harbour-boxing-timer.png b/icons/128x128/harbour-boxing-timer.png index 54375c5..001a9cc 100644 Binary files a/icons/128x128/harbour-boxing-timer.png and b/icons/128x128/harbour-boxing-timer.png differ diff --git a/icons/256x256/harbour-boxing-timer.png b/icons/256x256/harbour-boxing-timer.png index de79583..91c1936 100644 Binary files a/icons/256x256/harbour-boxing-timer.png and b/icons/256x256/harbour-boxing-timer.png differ diff --git a/icons/86x86/harbour-boxing-timer.png b/icons/86x86/harbour-boxing-timer.png index ad316d6..01054c4 100644 Binary files a/icons/86x86/harbour-boxing-timer.png and b/icons/86x86/harbour-boxing-timer.png differ diff --git a/qml/pages/SettingsPage.qml b/qml/pages/SettingsPage.qml index 0a7c4e3..696f42f 100644 --- a/qml/pages/SettingsPage.qml +++ b/qml/pages/SettingsPage.qml @@ -47,9 +47,22 @@ Page { property int mRoundMs: settings.roundsMs property int mRestMs: settings.restMs + property var mListOfInnerTimers: [] + onStatusChanged: { if (status === PageStatus.Active) { - Helper.pushPresetListPage(); + Helper.pushPresetListPage() + + var counter = 0 + for (var i = 0; i < settingsColumn.children.length; i++) { + if (settingsColumn.children[i].objectName === 'innerSlider') { +// if (counter in mListOfInnerTimers) { +// counter++ +// } else { +// settingsColumn.children[i].destroy() +// } + } + } } } @@ -65,7 +78,8 @@ Page { presetName.text, roundsSlider.value, roundsTimeSlider.value, - Converter.sToMs(restSlider.value) + Converter.sToMs(restSlider.value), + Helper.getListOfInnerTimers() ) boxingTimer.loadPreset(presetName.text) @@ -75,6 +89,20 @@ Page { } } + PushUpMenu { + MenuItem { + text: qsTr("Add inner time") + onClicked: Helper.addSliderForInnerTime() + } + + MenuItem { + text: qsTr("Remove last inner time") + onClicked: Helper.removeLastSliderFromInnerTimers() + + visible: mListOfInnerTimers.length + } + } + contentHeight: settingsColumn.height Column { @@ -136,6 +164,12 @@ Page { label: qsTr("Total rounds") } + + SectionHeader { + text: qsTr("Inner timers") + + visible: mListOfInnerTimers.length + } } } } diff --git a/qml/pages/js/helpers.js b/qml/pages/js/helpers.js index b023710..75baa6e 100644 --- a/qml/pages/js/helpers.js +++ b/qml/pages/js/helpers.js @@ -11,3 +11,64 @@ function playPauseTimer() { boxingTimer.restore() } } + +function addSliderForInnerTime(value) { + if (value === undefined) value = 5 + + var remainingTimeForInner = settingsPage.mRoundMs + var numberOfInnerTimers = settingsPage.mListOfInnerTimers.length + for (var i = 0; i < numberOfInnerTimers; i++) { + remainingTimeForInner -= settingsPage.mListOfInnerTimers[i].value + } + + if (remainingTimeForInner > 0) { + var number = parseInt(numberOfInnerTimers) + 1 + var id = "innerTime_" + number + var newSlider = Qt.createQmlObject( + "import QtQuick 2.2;" + + "import Sailfish.Silica 1.0;" + + "import 'converter.js' as Converter;" + + "Slider {" + + "id: " + id + ";" + + "objectName: 'innerSlider';" + + + "width: parent.width;" + + + "minimumValue: Converter.sToMs(5);" + + "maximumValue: "+ remainingTimeForInner +";" + + "stepSize: Converter.sToMs(5);" + + + "value: "+ value +";" + + "valueText: Converter.msToTime(value);" + + + "label: qsTr('Inner time "+ number +"');" + + "}", + settingsColumn, + "dynamicInnerTimerSlider" + ); + + var newArray = settingsPage.mListOfInnerTimers + newArray.push(newSlider); + settingsPage.mListOfInnerTimers = newArray; + } +} + +function removeLastSliderFromInnerTimers() { + var newArray = settingsPage.mListOfInnerTimers + var slider = newArray.pop() + + slider.destroy() + + settingsPage.mListOfInnerTimers = newArray +} + +function getListOfInnerTimers() { + var list = [] + + var timers = settingsPage.mListOfInnerTimers.length + for (var i = 0; i < timers; i++) { + list.push(settingsPage.mListOfInnerTimers[i].value) + } + + return list; +} diff --git a/resources/inner.wav b/resources/inner.wav new file mode 100644 index 0000000..d0dcf84 Binary files /dev/null and b/resources/inner.wav differ diff --git a/rpm/harbour-boxing-timer.spec b/rpm/harbour-boxing-timer.spec index 7e47705..08e7fd8 100644 --- a/rpm/harbour-boxing-timer.spec +++ b/rpm/harbour-boxing-timer.spec @@ -66,6 +66,9 @@ desktop-file-install --delete-original \ %{_bindir} %{_datadir}/%{name} %{_datadir}/applications/%{name}.desktop -%{_datadir}/icons/hicolor/*/apps/%{name}.png +%{_datadir}/icons/hicolor/86x86/apps/%{name}.png +%{_datadir}/icons/hicolor/108x108/apps/%{name}.png +%{_datadir}/icons/hicolor/128x128/apps/%{name}.png +%{_datadir}/icons/hicolor/256x256/apps/%{name}.png # >> files # << files diff --git a/rpm/harbour-boxing-timer.yaml b/rpm/harbour-boxing-timer.yaml index 010dbb1..5963cd1 100644 --- a/rpm/harbour-boxing-timer.yaml +++ b/rpm/harbour-boxing-timer.yaml @@ -39,7 +39,10 @@ Files: - '%{_bindir}' - '%{_datadir}/%{name}' - '%{_datadir}/applications/%{name}.desktop' - - '%{_datadir}/icons/hicolor/*/apps/%{name}.png' + - '%{_datadir}/icons/hicolor/86x86/apps/%{name}.png' + - '%{_datadir}/icons/hicolor/108x108/apps/%{name}.png' + - '%{_datadir}/icons/hicolor/128x128/apps/%{name}.png' + - '%{_datadir}/icons/hicolor/256x256/apps/%{name}.png' # For more information about yaml and what's supported in Sailfish OS # build system, please see https://wiki.merproject.org/wiki/Spectacle diff --git a/src/boxingsettings.cpp b/src/boxingsettings.cpp index 7f7e8a5..9d04bff 100644 --- a/src/boxingsettings.cpp +++ b/src/boxingsettings.cpp @@ -1,6 +1,7 @@ #include "boxingsettings.h" #include +#include BoxingSettings::BoxingSettings() : mRounds(DefaultRounds), @@ -46,17 +47,30 @@ void BoxingSettings::loadPreset() { this->mRounds = DefaultRounds; this->mRoundMilliseconds = DefaultRoundMilliseconds; this->mRestMilliseconds = DefaultRestMilliseconds; + this->mInnerTimers.clear(); } else { this->beginGroup(this->mPreset); this->mPresetName = this->value("name").toString(); this->mRounds = this->value("rounds").toInt(); this->mRoundMilliseconds = this->value("roundmilliseconds").toInt(); this->mRestMilliseconds = this->value("restmilliseconds").toInt(); + +// QList list = this->value("innerTimers").value>(); + this->mInnerTimers = this->value("innerTimers").value>(); + +//#ifdef QT_DEBUG +// qDebug() << list; +//#endif + +// foreach(QVariant v, list) { +// this->mInnerTimers.append(v.toInt()); +// } + this->endGroup(); } } -void BoxingSettings::savePreset(const QString &name, const int &rounds, const int &roundMilliseconds, const int &restMilliseconds) { +void BoxingSettings::savePreset(const QString &name, const int &rounds, const int &roundMilliseconds, const int &restMilliseconds, const QList &innerTimers) { QString strippedName = this->convertRichNameToGroup(name); this->beginGroup(strippedName); @@ -64,6 +78,12 @@ void BoxingSettings::savePreset(const QString &name, const int &rounds, const in this->setValue("rounds", rounds); this->setValue("roundmilliseconds", roundMilliseconds); this->setValue("restmilliseconds", restMilliseconds); + +#ifdef QT_DEBUG + qDebug() << innerTimers; +#endif + + this->setValue("innerTimers", QVariant::fromValue(innerTimers)); this->endGroup(); this->setPreset(strippedName); diff --git a/src/boxingsettings.h b/src/boxingsettings.h index 8117f2c..cb26473 100644 --- a/src/boxingsettings.h +++ b/src/boxingsettings.h @@ -4,6 +4,7 @@ #include #include #include +#include #ifdef QT_DEBUG #include @@ -25,6 +26,7 @@ class BoxingSettings : public QSettings { Q_PROPERTY(int rounds READ getRounds WRITE setRounds NOTIFY presetChanged) Q_PROPERTY(int roundsMs READ getRoundMilliseconds WRITE setRoundMilliseconds NOTIFY presetChanged) Q_PROPERTY(int restMs READ getRestMilliseconds WRITE setRestMilliseconds NOTIFY presetChanged) + Q_PROPERTY(QList innerTimers READ getInnerTimers NOTIFY presetChanged) /** @endcond */ /** @@ -78,7 +80,7 @@ class BoxingSettings : public QSettings { * * @brief Save or override settings about specific preset */ - Q_INVOKABLE void savePreset(const QString &name, const int &rounds, const int &roundMilliseconds, const int &restMilliseconds); + Q_INVOKABLE void savePreset(const QString &name, const int &rounds, const int &roundMilliseconds, const int &restMilliseconds, const QList &innerTimers); /** * @addtogroup QML @@ -115,6 +117,20 @@ class BoxingSettings : public QSettings { */ inline int getRestMilliseconds() { return this->mRestMilliseconds; } + /** + * @brief gerInnerTimers() + * + * @return the list of inner timers + */ + inline QList getInnerTimers() { return this->mInnerTimers; } + + /** + * @brief getInnerTimer(const int &index) + * + * @return the specific timer in milliseconds + */ + inline int getInnerTimer(const int &index) { return this->mInnerTimers.at(index); } + /** * @fn QString getPreset() * @@ -166,6 +182,8 @@ class BoxingSettings : public QSettings { int mRoundMilliseconds; int mRestMilliseconds; + QList mInnerTimers; + QString mPreset; QString mPresetName; diff --git a/src/boxingtimer.cpp b/src/boxingtimer.cpp index 3242420..3f4553f 100644 --- a/src/boxingtimer.cpp +++ b/src/boxingtimer.cpp @@ -8,16 +8,20 @@ BoxingTimer::BoxingTimer() : mRound(0), + mInnerRemainingMilliseconds(0), mStatus(Status::Stop), mOldStatus(Status::Default) { this->setTimerType(Qt::VeryCoarseTimer); this->settings = new BoxingSettings(); - this->mRemainingMilliseconds = settings->getRoundMilliseconds(); + this->mRemainingMilliseconds = this->settings->getRoundMilliseconds(); + + this->setInnerTimers(); this->playBell = new QSound(":/audio/resources/play.wav"); this->restBell = new QSound(":/audio/resources/rest.wav"); this->stopBell = new QSound(":/audio/resources/stop.wav"); + this->innerBell = new QSound(":/audio/resources/inner.wav"); QObject::connect(this, SIGNAL(statusChanged()), this, SLOT(applyStatus())); QObject::connect(this, SIGNAL(timeout()), this, SLOT(updateRemainingMilliseconds())); @@ -68,8 +72,10 @@ void BoxingTimer::applyStatus() { case Status::Reset: if (this->mOldStatus == Status::Start) { this->setRemainingMilliseconds(this->settings->getRoundMilliseconds()); + this->setInnerTimers(); } else if (this->mOldStatus == Status::Rest) { this->setRemainingMilliseconds(this->settings->getRestMilliseconds()); + this->setInnerTimers(); } if (this->isActive()) { @@ -109,11 +115,41 @@ void BoxingTimer::updateRemainingMilliseconds() { this->mStatus = Status::Start; this->setRemainingMilliseconds(this->settings->getRoundMilliseconds()); + this->setInnerTimers(); + this->nextRound(); } this->songsBell(); } + + this->updateInnerRemainingMilliseconds(); +} + +void BoxingTimer::updateInnerRemainingMilliseconds() { + if (this->mInnerTime >= 0 && this->mStatus == Status::Start) { + this->mInnerRemainingMilliseconds -= 1000; + + if (this->mInnerRemainingMilliseconds <= 0) { + if (++this->mInnerTime >= this->mNumberOfInnerTimers) { + this->mInnerTime = 0; + } + + this->mInnerRemainingMilliseconds = this->settings->getInnerTimer(this->mInnerTime); + + this->innerBell->play(); + } + } +} + +void BoxingTimer::setInnerTimers() { + this->mNumberOfInnerTimers = this->settings->getInnerTimers().size(); + + this->mInnerTime = -1; + if (this->mNumberOfInnerTimers > 0) { + this->mInnerTime = 0; + this->mInnerRemainingMilliseconds = this->settings->getInnerTimer(this->mInnerTime); + } } const QString BoxingTimer::remainingTimeToString() { @@ -156,6 +192,8 @@ void BoxingTimer::loadPreset(const QString &preset) { this->mRemainingMilliseconds = settings->getRoundMilliseconds(); this->mStatus = Status::Stop; + this->setInnerTimers(); + emit presetChanged(); emit roundsToStringChanged(); emit remainingTimeToStringChanged(); diff --git a/src/boxingtimer.h b/src/boxingtimer.h index d361481..b6a8321 100644 --- a/src/boxingtimer.h +++ b/src/boxingtimer.h @@ -155,17 +155,22 @@ class BoxingTimer : public QTimer { int mRoundsMilliseconds; int mRemainingMilliseconds; + int mInnerTime; + int mNumberOfInnerTimers; + int mInnerRemainingMilliseconds; + void setRemainingMilliseconds(const int &milliseconds); void setRound(const int &round); QSound *playBell; QSound *restBell; QSound *stopBell; + QSound *innerBell; /** * @fn void songsBell() * - * @brief Play the bell check actual status + * @brief Play the bell if status changes */ void songsBell(); @@ -181,6 +186,20 @@ class BoxingTimer : public QTimer { */ void nextRound(); + /** + * @fn void updateInnerRemainingMilliseconds() + * + * @brief Update remaining milliseconds of inner timer + */ + void updateInnerRemainingMilliseconds(); + + /** + * @fn void setInnerTimers() + * + * @brief Setup inner timers from settings + */ + void setInnerTimers(); + signals: void remainingTimeToStringChanged(); void roundsToStringChanged(); diff --git a/src/harbour-boxing-timer.cpp b/src/harbour-boxing-timer.cpp index 5d4bb31..4ed562f 100644 --- a/src/harbour-boxing-timer.cpp +++ b/src/harbour-boxing-timer.cpp @@ -29,6 +29,7 @@ */ #include +#include #include @@ -46,6 +47,8 @@ int main(int argc, char *argv[]) // // To display the view, call "show()" (will show fullscreen on device). + qRegisterMetaTypeStreamOperators>("QList"); + qmlRegisterType("Pw.Unitoo.Backend", 1, 0, "BoxingTimer"); qmlRegisterType("Pw.Unitoo.Backend", 1, 0, "BoxingSettings");