From 718b046c4251c600d9ea2a5bd3c46b6a3a248b63 Mon Sep 17 00:00:00 2001 From: Andrei Date: Fri, 9 Mar 2018 19:59:50 +0300 Subject: [PATCH] added sliders --- SoundBand/Header.qml | 27 +++++++++++++++++++++++---- SoundBand/syncengine.cpp | 20 +++++++++++++++++++- SoundBand/syncengine.h | 22 +++++++++++++++++++++- 3 files changed, 63 insertions(+), 6 deletions(-) diff --git a/SoundBand/Header.qml b/SoundBand/Header.qml index a8da381..8eda38b 100644 --- a/SoundBand/Header.qml +++ b/SoundBand/Header.qml @@ -10,6 +10,8 @@ Item { property int currentSongId: 0 property string curentSongName: qsTr("Song is not selected") + property bool playState: false + function changeSong(id, name){ currentSongId = id; @@ -48,7 +50,7 @@ Item { GroupBox { id: groupBox - height: 100 + height: 120 padding: 0; anchors.left: parent.left anchors.leftMargin: 0 @@ -68,13 +70,18 @@ Item { width: parent.width/3 text: qsTr("<<") anchors.left: parent.left + + onCanceled: { + syncEngine.prev(); + } } Button { id: play width: parent.width/3 - text: qsTr("Play") + text: (playState)? qsTr("Pause"): qsTr("Play") anchors.left: prev.right + } Button { @@ -82,15 +89,24 @@ Item { width: parent.width/3 text: qsTr(">>") anchors.right: parent.right + + onCanceled: { + syncEngine.next(); + } } Slider { id: valume - value: 0.5 + from: 0 + to: 100 + value: syncEngine.getValume() width: parent.width / 4; anchors.bottom: progress.top anchors.top: next.bottom anchors.left: parent.left + onMoved: { + syncEngine.setValume(value); + } } Base.BaseText { @@ -107,10 +123,13 @@ Item { Slider { id: progress - value: 0.5 + value: syncEngine.pos anchors.bottom: parent.bottom anchors.left: parent.left anchors.right: parent.right + onMoved:{ + syncEngine.setPos(value); + } } } diff --git a/SoundBand/syncengine.cpp b/SoundBand/syncengine.cpp index 6645eb7..766d828 100644 --- a/SoundBand/syncengine.cpp +++ b/SoundBand/syncengine.cpp @@ -9,6 +9,12 @@ SyncEngine::SyncEngine() connect(sync, SIGNAL(networkStateChange()), this, SIGNAL(serversCountChanged())); connect(sync, SIGNAL(curentPlayListChanged()), this, SIGNAL(curentPlayListCountChanged())); + connect(sync, SIGNAL(seekChanged(qint64)), this, SLOT(seekChanged(qint64))); + +} + +void SyncEngine::seekChanged(qint64){ + emit posChanged(); } int SyncEngine::curentSongIndex()const{ @@ -158,12 +164,24 @@ const QString& SyncEngine::lastError() const{ return _lastError; } +void SyncEngine::setPos(double newPos){ + sync->jump(sync->getEndPoint() * newPos); +} + +void SyncEngine::setValume(int valume){ + sync->setValume(valume); +} + +int SyncEngine::getValume()const{ + return sync->getValume(); +} + double SyncEngine::pos()const{ if(!sync->seek()) return 0.0; - return sync->getEndPoint() / (double)sync->seek(); + return (double)sync->seek() / sync->getEndPoint(); } SyncEngine::~SyncEngine(){ diff --git a/SoundBand/syncengine.h b/SoundBand/syncengine.h index 644fccb..73f1380 100644 --- a/SoundBand/syncengine.h +++ b/SoundBand/syncengine.h @@ -13,7 +13,7 @@ class SyncEngine : public QObject { Q_OBJECT Q_PROPERTY(QString lastError READ lastError NOTIFY error) - Q_PROPERTY(double pos READ pos NOTIFY posChanged) + Q_PROPERTY(double pos READ pos WRITE setPos NOTIFY posChanged) Q_PROPERTY(int repeat READ repeat WRITE setRepeat NOTIFY repeatChanged) enum Repeat{noRepeat, oneMusic, allPlayList}; @@ -26,6 +26,9 @@ private: Repeat _repeat; QSettings settings; +private slots: + void seekChanged(qint64); + public: SyncEngine(); @@ -150,6 +153,23 @@ public slots: */ double pos()const; + /** + * @brief setPos + * @param newPos + */ + void setPos(double newPos); + + /** + * @brief setValume - set a new valume of playin a song + */ + void setValume(int); + + /** + * @brief getValume + * @return valune of song + */ + int getValume()const; + /** * @brief getServerList * @return list of servers