From e99439eccad143fe2073d4dc2eee4182d1c60900 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Sun, 19 May 2013 04:39:57 +0200 Subject: [PATCH] some more work on start by year --- data/qml/stations/CreateByYear.qml | 76 +++++++++++-------- data/qml/stations/StationCreatorPage1.qml | 1 + data/qml/stations/StationItem.qml | 1 + data/qml/tomahawkimports/DoubleSlider.qml | 16 ++-- .../playlist/dynamic/GeneratorInterface.h | 2 + .../dynamic/echonest/EchonestGenerator.cpp | 12 +++ .../dynamic/echonest/EchonestGenerator.h | 2 + .../dynamic/widgets/DynamicQmlWidget.cpp | 20 +++++ .../dynamic/widgets/DynamicQmlWidget.h | 2 + 9 files changed, 91 insertions(+), 41 deletions(-) diff --git a/data/qml/stations/CreateByYear.qml b/data/qml/stations/CreateByYear.qml index 5e1461668..ae9f15a69 100644 --- a/data/qml/stations/CreateByYear.qml +++ b/data/qml/stations/CreateByYear.qml @@ -8,9 +8,14 @@ Item { signal done(string text) - function createStation(artist) { - mainView.startStationFromArtist(artist) - root.done(artist) + function createStationFromYear(year) { + mainView.startStationFromYear(year) + root.done(year) + } + + function createStationFromTo(yearFrom, yearTo) { + mainView.startStationFromTo(yearFrom, yearTo) + root.done(yearFrom + " to " + yearTo) } Column { @@ -27,53 +32,58 @@ Item { } Row { - height: artistInputField.height + height: yearInputField.height width: parent.width spacing: defaultFontHeight * 0.5 + Text { + text: "Year:" + color: "white" + anchors.verticalCenter: parent.verticalCenter + } + InputField { - id: artistInputField + id: yearInputField width: parent.width - createFromInputButton.width - parent.spacing onAccepted: createStation(text) } - - PushButton { - id: createFromInputButton - text: "Go!" - enabled: artistInputField.text.length > 2 - onClicked: createStation(artistInputField.text) - } } -// Item { -// height: parent.height - headerText.height - artistInputField.height - parent.spacing * 3 -// width: parent.width -// ArtistView { -// id: artistView -// height: parent.height -// width: parent.width -// model: artistChartsModel -// clip: true -// delegateHeight: defaultFontHeight * 6 - -// onItemClicked: { -// createStation(artistChartsModel.itemFromIndex(index).artistName); -// } -// } -// ScrollBar { -// listView: artistView -// } -// } - DoubleSlider { + id: yearSlider width: parent.width - height: defaultFontHeight * 2 + height: defaultFontHeight * 4 min: 1960 max: new Date().getFullYear() lowerSliderPos: 1990 upperSliderPos: 2010 minMaxLabelsVisible: false + opacity: yearInputField.text.length > 0 ? 0.3 : 1 + + Behavior on opacity { + NumberAnimation { duration: 200 } + } + } + + PushButton { + id: createFromInputButton + text: "Go!" + enabled: yearInputField.text.length == 0 || (yearInputField.text >= yearSlider.min && yearInputField.text <= yearSlider.max) + anchors.horizontalCenter: parent.horizontalCenter + onClicked: { + if (yearInputField.text.length > 0) { + createStationFromYear(yearInputField.text) + } else { + createStationFromTo(yearSlider.lowerSliderPos, yearSlider.upperSliderPos) + } + } + + // TODO: move some disabled look/animation to the button itself + opacity: enabled ? 1 : 0.3 + Behavior on opacity { + NumberAnimation { duration: 200 } + } } } } diff --git a/data/qml/stations/StationCreatorPage1.qml b/data/qml/stations/StationCreatorPage1.qml index 826d69d69..ca1aed727 100644 --- a/data/qml/stations/StationCreatorPage1.qml +++ b/data/qml/stations/StationCreatorPage1.qml @@ -15,6 +15,7 @@ Item { anchors.centerIn: parent width: root.width * 9 / 10 height: cellHeight + interactive: false cellWidth: (width - 1) / 3 cellHeight: cellWidth //* 10 / 16 diff --git a/data/qml/stations/StationItem.qml b/data/qml/stations/StationItem.qml index 9d7804a0a..77bec8c46 100644 --- a/data/qml/stations/StationItem.qml +++ b/data/qml/stations/StationItem.qml @@ -65,6 +65,7 @@ Item { anchors.centerIn: parent height: defaultFontHeight * 4 width: height +// count: 12 opacity: mainView.loading ? 1 : 0 running: mainView.loading diff --git a/data/qml/tomahawkimports/DoubleSlider.qml b/data/qml/tomahawkimports/DoubleSlider.qml index 08061b96e..2ac2c64a8 100644 --- a/data/qml/tomahawkimports/DoubleSlider.qml +++ b/data/qml/tomahawkimports/DoubleSlider.qml @@ -28,8 +28,8 @@ Item { property int steps: root.max - root.min + 1 - property int sliderHeight: root.height - property int sliderWidth: root.height / 2 + property int sliderHeight: root.height / 3 + property int sliderWidth: sliderHeight / 2 } Row { @@ -47,7 +47,7 @@ Item { Item { id: sliderRect - height: root.height + height: root.height / 4 property int maxWidth: parent.width - (minText.visible ? minText.width : 0) - (maxText.visible ? maxText.width : 0) - parent.spacing * 2 width: maxWidth - (maxWidth % priv.steps) anchors.horizontalCenter: parent.horizontalCenter @@ -64,7 +64,7 @@ Item { Rectangle { id: sliderBase - height: root.height / 1.5 + height: parent.height width: parent.width + defaultFontHeight * 1.5 color: "white" radius: height / 2 @@ -131,7 +131,7 @@ Item { id: lowerSlider height: priv.sliderHeight width: priv.sliderWidth - anchors.top: root.top + anchors.verticalCenter: sliderBase.verticalCenter radius: height/4 border.color: "black" border.width: 2 @@ -170,9 +170,9 @@ Item { Rectangle { id: upperSlider - height: root.height - width: height / 2 - anchors.top: root.top + height: priv.sliderHeight + width: priv.sliderWidth + anchors.verticalCenter: sliderBase.verticalCenter radius: height / 4 border.color: "black" border.width: 2 diff --git a/src/libtomahawk/playlist/dynamic/GeneratorInterface.h b/src/libtomahawk/playlist/dynamic/GeneratorInterface.h index 3a6d7fbdf..4eb217ee4 100644 --- a/src/libtomahawk/playlist/dynamic/GeneratorInterface.h +++ b/src/libtomahawk/playlist/dynamic/GeneratorInterface.h @@ -114,6 +114,8 @@ public: virtual bool startFromTrack( const Tomahawk::query_ptr& query ) = 0; virtual bool startFromArtist( const Tomahawk::artist_ptr& artist ) = 0; virtual bool startFromGenre( const QString& genre ) = 0; + virtual bool startFromYear( int year ) = 0; + virtual bool startFromTo( int yearFrom, int yearTo) = 0; signals: void error( const QString& title, const QString& body); diff --git a/src/libtomahawk/playlist/dynamic/echonest/EchonestGenerator.cpp b/src/libtomahawk/playlist/dynamic/echonest/EchonestGenerator.cpp index 9edac4ccc..056a4b526 100644 --- a/src/libtomahawk/playlist/dynamic/echonest/EchonestGenerator.cpp +++ b/src/libtomahawk/playlist/dynamic/echonest/EchonestGenerator.cpp @@ -309,6 +309,18 @@ EchonestGenerator::startFromGenre( const QString& genre ) return true; } +bool EchonestGenerator::startFromYear(int year) +{ + //TODO: libechonest doesn't support filtering for year yet... + return false; +} + +bool EchonestGenerator::startFromTo(int yearFrom, int yearTo) +{ + //TODO: libechonest doesn't support filtering for year yet... + return false; +} + void EchonestGenerator::doGenerate( const Echonest::DynamicPlaylist::PlaylistParams& paramsIn ) diff --git a/src/libtomahawk/playlist/dynamic/echonest/EchonestGenerator.h b/src/libtomahawk/playlist/dynamic/echonest/EchonestGenerator.h index 4375a5153..7fb77cd43 100644 --- a/src/libtomahawk/playlist/dynamic/echonest/EchonestGenerator.h +++ b/src/libtomahawk/playlist/dynamic/echonest/EchonestGenerator.h @@ -83,6 +83,8 @@ public: virtual bool startFromTrack( const Tomahawk::query_ptr& query ); virtual bool startFromArtist( const Tomahawk::artist_ptr& artist ); virtual bool startFromGenre( const QString& genre ); + virtual bool startFromYear( int year ); + virtual bool startFromTo( int yearFrom, int yearTo ); static QStringList styles(); static QStringList moods(); diff --git a/src/libtomahawk/playlist/dynamic/widgets/DynamicQmlWidget.cpp b/src/libtomahawk/playlist/dynamic/widgets/DynamicQmlWidget.cpp index 0b5c1edd4..3c783d3ca 100644 --- a/src/libtomahawk/playlist/dynamic/widgets/DynamicQmlWidget.cpp +++ b/src/libtomahawk/playlist/dynamic/widgets/DynamicQmlWidget.cpp @@ -168,6 +168,26 @@ void DynamicQmlWidget::startStationFromGenre(const QString &genre) emit configuredChanged(); } +void DynamicQmlWidget::startStationFromYear(int year) +{ + tDebug() << "should start startion from year" << year; + m_model->clear(); + m_playNextResolved = true; + m_playlist->generator()->startFromYear( year ); + emit loadingChanged(); + emit configuredChanged(); +} + +void DynamicQmlWidget::startStationFromTo(int yearFrom, int yearTo) +{ + tDebug() << "should start startion from years" << yearFrom << "to" << yearTo; + m_model->clear(); + m_playNextResolved = true; + m_playlist->generator()->startFromTo( yearFrom, yearTo ); + emit loadingChanged(); + emit configuredChanged(); +} + void DynamicQmlWidget::currentIndexChanged() { tDebug() << "current index is" << m_model->currentItem().row(); diff --git a/src/libtomahawk/playlist/dynamic/widgets/DynamicQmlWidget.h b/src/libtomahawk/playlist/dynamic/widgets/DynamicQmlWidget.h index c5a0ceac7..bf77e4b78 100644 --- a/src/libtomahawk/playlist/dynamic/widgets/DynamicQmlWidget.h +++ b/src/libtomahawk/playlist/dynamic/widgets/DynamicQmlWidget.h @@ -74,6 +74,8 @@ public slots: void pause(); void startStationFromArtist(const QString &artist); void startStationFromGenre(const QString &genre); + void startStationFromYear(int year); + void startStationFromTo(int yearFrom, int yearTo); private slots: void currentIndexChanged();