on xenial help sign in
added MusicPreview
698ed61Michael Zanetti
Dash/Music/MusicPreview.qmlnew file+175
@@ -0,0 +1,175 @@
1+/*
2+ * Copyright (C) 2013 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+import QtQuick 2.0
18+import QtMultimedia 5.0
19+import Ubuntu.Components 0.1
20+import Ubuntu.Components.ListItems 0.1
21+import ".."
22+import "../Generic"
23+import "../../Components"
24+import "../Previews"
25+
26+GenericPreview {
27+ id: root
28+
29+ previewImages: previewImageComponent
30+ header: headerComponent
31+ description: descriptionComponent
32+
33+ Component {
34+ id: previewImageComponent
35+ LazyImage {
36+ height: units.gu(22)
37+ scaleTo: "height"
38+ source: previewData ? previewData.image : ""
39+ initialHeight: height
40+ initialWidth: height
41+ }
42+ }
43+
44+ Component {
45+ id: headerComponent
46+ Header {
47+ title: previewData.title
48+ subtitle: previewData.subtitle
49+ }
50+ }
51+
52+ Component {
53+ id: descriptionComponent
54+
55+ Column {
56+ height: childrenRect.height
57+
58+ Repeater {
59+ id: trackRepeater
60+
61+ model: previewData.tracks
62+
63+ signal stopPlayback()
64+
65+ delegate: Item {
66+ objectName: "trackItem" + index
67+ width: parent.width
68+ height: units.gu(5)
69+ Row {
70+ id: trackRow
71+ width: parent.width
72+ spacing: units.gu(1)
73+ property int column1Width: units.gu(3)
74+ property int column2Width: width - (2 * spacing) - column1Width - column3Width
75+ property int column3Width: units.gu(4)
76+ anchors.verticalCenter: parent.verticalCenter
77+
78+ UbuntuShape {
79+ id: playButtonShape
80+ width: trackRow.column1Width
81+ height: width
82+ Icon {
83+ width: units.gu(2)
84+ height: width
85+ anchors.centerIn: playButtonShape
86+ name: audioPlayer.playbackState == Audio.PlayingState ? "media-playback-pause" : "media-playback-start"
87+ color: "white"
88+ opacity: .9
89+ }
90+ MouseArea {
91+ anchors.fill: parent
92+ onClicked: {
93+ if (audioPlayer.playbackState == Audio.PlayingState) {
94+ audioPlayer.pause();
95+ } else if (audioPlayer.playbackState == Audio.PausedState){
96+ audioPlayer.play();
97+ } else {
98+ trackRepeater.stopPlayback();
99+ audioPlayer.play();
100+ }
101+ }
102+ }
103+ }
104+
105+ Label {
106+ objectName: "trackTitleLabel"
107+ fontSize: "small"
108+ opacity: 0.9
109+ color: "white"
110+ horizontalAlignment: Text.AlignLeft
111+ anchors.verticalCenter: parent.verticalCenter
112+ width: parent.column2Width
113+ text: title
114+ style: Text.Raised
115+ styleColor: "black"
116+ elide: Text.ElideRight
117+
118+ // FIXME: get color values from design
119+ UbuntuShape {
120+ color: "#66000000"
121+ anchors {
122+ left: parent.left
123+ top: parent.bottom
124+ right: parent.right
125+ topMargin: units.dp(3)
126+ }
127+ height: units.dp(2)
128+ visible: audioPlayer.playbackState != Audio.StoppedState
129+
130+ UbuntuShape {
131+ color: "#dd4814"
132+ anchors.fill: parent
133+ anchors.rightMargin: parent.width - (parent.width * audioPlayer.percent / 100)
134+ }
135+ }
136+ }
137+ Label {
138+ id: valueLabel
139+ objectName: "timeLabel"
140+ fontSize: "small"
141+ opacity: 0.9
142+ color: "white"
143+ anchors.verticalCenter: parent.verticalCenter
144+ horizontalAlignment: Text.AlignRight
145+ width: parent.column3Width
146+ text: length
147+ style: Text.Raised
148+ styleColor: "black"
149+ }
150+ }
151+
152+ ThinDivider {
153+ anchors {
154+ left: parent.left
155+ bottom: parent.bottom
156+ right: parent.right
157+ }
158+ }
159+
160+ Audio {
161+ id: audioPlayer
162+ source: uri
163+ property real percent: audioPlayer.position * 100 / audioPlayer.duration
164+ onPositionChanged: print("got percent", percent, position, duration)
165+
166+ }
167+ Connections {
168+ target: trackRepeater
169+ onStopPlayback: audioPlayer.stop();
170+ }
171+ }
172+ }
173+ }
174+ }
175+}
Dash/PreviewDelegateMapper.qml+1
@@ -23,6 +23,7 @@ QtObject {
23 property var previewDelegateMapping: {"preview-generic": genericPreview,
23 property var previewDelegateMapping: {"preview-generic": genericPreview,
24 "preview-application": appPreview,
24 "preview-application": appPreview,
25 "preview-movie": "Movie/MoviePreview.qml",
25 "preview-movie": "Movie/MoviePreview.qml",
26+ "preview-music": "Music/MusicPreview.qml",
26 }
27 }
27 }
28 }
28
29
plugins/Unity/CMakeLists.txt+1
@@ -39,6 +39,7 @@ set(QMLPLUGIN_SRC
39 genericpreview.cpp
39 genericpreview.cpp
40 moviepreview.cpp
40 moviepreview.cpp
41 musicpreview.cpp
41 musicpreview.cpp
42+ musicpreviewtrackmodel.cpp
42 preview.cpp
43 preview.cpp
43 previewaction.cpp
44 previewaction.cpp
44 previewinfohint.cpp
45 previewinfohint.cpp
plugins/Unity/musicpreview.cpp+4−5
@@ -18,16 +18,15 @@
18 */
18 */
19
19
20#include "musicpreview.h"
20#include "musicpreview.h"
21−#include <QDebug>
21+#include "musicpreviewtrackmodel.h"
22
22
23−// dee-qt
24−#include "deelistmodel.h"
23+#include <QDebug>
25
24
26MusicPreview::MusicPreview(QObject *parent):
25MusicPreview::MusicPreview(QObject *parent):
27 Preview(parent),
26 Preview(parent),
28 m_unityMusicPreview(nullptr)
27 m_unityMusicPreview(nullptr)
29{
28{
30− m_tracks = new DeeListModel(this);
29+ m_tracks = new MusicPreviewTrackModel(this);
31}
30}
32
31
33void MusicPreview::setUnityPreview(unity::dash::Preview::Ptr unityPreview)
32void MusicPreview::setUnityPreview(unity::dash::Preview::Ptr unityPreview)
@@ -40,7 +39,7 @@ void MusicPreview::setUnityPreview(unity::dash::Preview::Ptr unityPreview)
40 Q_EMIT tracksChanged();
39 Q_EMIT tracksChanged();
41}
40}
42
41
43−DeeListModel* MusicPreview::tracks() const
42+MusicPreviewTrackModel *MusicPreview::tracks() const
44{
43{
45 if (m_unityMusicPreview == nullptr) {
44 if (m_unityMusicPreview == nullptr) {
46 qWarning() << "Preview not set";
45 qWarning() << "Preview not set";
plugins/Unity/musicpreview.h+4−4
@@ -30,18 +30,18 @@
30// libunity-core
30// libunity-core
31#include <UnityCore/MusicPreview.h>
31#include <UnityCore/MusicPreview.h>
32
32
33−class DeeListModel;
33+class MusicPreviewTrackModel;
34
34
35class Q_DECL_EXPORT MusicPreview: public Preview
35class Q_DECL_EXPORT MusicPreview: public Preview
36{
36{
37 Q_OBJECT
37 Q_OBJECT
38
38
39− Q_PROPERTY(DeeListModel* tracks READ tracks NOTIFY tracksChanged)
39+ Q_PROPERTY(MusicPreviewTrackModel* tracks READ tracks NOTIFY tracksChanged)
40
40
41public:
41public:
42 explicit MusicPreview(QObject *parent = 0);
42 explicit MusicPreview(QObject *parent = 0);
43
43
44− DeeListModel* tracks() const;
44+ MusicPreviewTrackModel* tracks() const;
45
45
46Q_SIGNALS:
46Q_SIGNALS:
47 void tracksChanged();
47 void tracksChanged();
@@ -54,7 +54,7 @@ private Q_SLOTS:
54
54
55private:
55private:
56 unity::dash::MusicPreview::Ptr m_unityMusicPreview;
56 unity::dash::MusicPreview::Ptr m_unityMusicPreview;
57− DeeListModel *m_tracks;
57+ MusicPreviewTrackModel *m_tracks;
58};
58};
59
59
60Q_DECLARE_METATYPE(MusicPreview *)
60Q_DECLARE_METATYPE(MusicPreview *)
plugins/Unity/musicpreviewtrackmodel.cppnew file+71
@@ -0,0 +1,71 @@
1+/*
2+ * Copyright (C) 2013 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ *
16+ * Authors:
17+ * Michael Zanetti <michael.zanetti@canonical.com>
18+ */
19+
20+#include "musicpreviewtrackmodel.h"
21+
22+#include <QTime>
23+
24+// TODO: use something from libunity once it's public
25+enum ResultsColumn {
26+ URI,
27+ TRACK_NO,
28+ TITLE,
29+ LENGTH,
30+ PLAY_STATE,
31+ PROGRESS
32+};
33+
34+MusicPreviewTrackModel::MusicPreviewTrackModel(QObject *parent): DeeListModel(parent)
35+{
36+ m_roles.insert(RoleUri, "uri");
37+ m_roles.insert(RoleTrackNo, "trackNo");
38+ m_roles.insert(RoleTitle, "title");
39+ m_roles.insert(RoleLength, "length");
40+ m_roles.insert(RolePlayState, "playState");
41+ m_roles.insert(RoleProgress, "progress");
42+}
43+
44+QVariant MusicPreviewTrackModel::data(const QModelIndex &index, int role) const
45+{
46+ switch(role) {
47+ case RoleUri:
48+ return DeeListModel::data(index, ResultsColumn::URI);
49+ case RoleTrackNo:
50+ return DeeListModel::data(index, ResultsColumn::TRACK_NO);
51+ case RoleTitle:
52+ return DeeListModel::data(index, ResultsColumn::TITLE);
53+ case RoleLength: {
54+ QTime length = QTime(0,0).addSecs(DeeListModel::data(index, ResultsColumn::LENGTH).toInt());
55+ if (length.hour() > 0) {
56+ return length.toString("h:mm:ss");
57+ }
58+ return length.toString("m:ss");
59+ }
60+ case RolePlayState:
61+ return DeeListModel::data(index, ResultsColumn::PLAY_STATE);
62+ case RoleProgress:
63+ return DeeListModel::data(index, ResultsColumn::PROGRESS);
64+ }
65+ return QVariant();
66+}
67+
68+QHash<int, QByteArray> MusicPreviewTrackModel::roleNames() const
69+{
70+ return m_roles;
71+}
plugins/Unity/musicpreviewtrackmodel.hnew file+51
@@ -0,0 +1,51 @@
1+/*
2+ * Copyright (C) 2013 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ *
16+ * Authors:
17+ * Michael Zanetti <michael.zanetti@canonical.com>
18+ */
19+
20+#ifndef MUSICPREVIEWTRACKMODEL_H
21+#define MUSICPREVIEWTRACKMODEL_H
22+
23+#include "deelistmodel.h"
24+
25+class Q_DECL_EXPORT MusicPreviewTrackModel : public DeeListModel
26+{
27+ Q_OBJECT
28+ Q_ENUMS(Roles)
29+
30+public:
31+ explicit MusicPreviewTrackModel(QObject* parent = 0);
32+
33+ enum Roles {
34+ RoleUri,
35+ RoleTrackNo,
36+ RoleTitle,
37+ RoleLength,
38+ RolePlayState,
39+ RoleProgress
40+ };
41+
42+ QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
43+
44+ QHash<int, QByteArray> roleNames() const;
45+
46+private:
47+ QHash<int, QByteArray> m_roles;
48+};
49+
50+#endif // MUSICPREVIEWTRACKMODEL_H
51+
plugins/Unity/plugin.cpp+2
@@ -36,6 +36,7 @@
36#include "bottombarvisibilitycommunicatorshell.h"
36#include "bottombarvisibilitycommunicatorshell.h"
37#include "genericoptionsmodel.h"
37#include "genericoptionsmodel.h"
38#include "result.h"
38#include "result.h"
39+#include "musicpreviewtrackmodel.h"
39
40
40// libqtdee
41// libqtdee
41#include "deelistmodel.h"
42#include "deelistmodel.h"
@@ -58,6 +59,7 @@ void UnityPlugin::registerTypes(const char *uri)
58 qmlRegisterUncreatableType<CategoryResults>(uri, 0, 1, "CategoryResults", "Can't create new Category Results in QML. Get them from Categories instance.");
59 qmlRegisterUncreatableType<CategoryResults>(uri, 0, 1, "CategoryResults", "Can't create new Category Results in QML. Get them from Categories instance.");
59 qmlRegisterType<DeeListModel>(uri, 0, 1, "DeeListModel");
60 qmlRegisterType<DeeListModel>(uri, 0, 1, "DeeListModel");
60 qmlRegisterUncreatableType<BottomBarVisibilityCommunicatorShell>(uri, 0, 1, "BottomBarVisibilityCommunicatorShell", "Can't create BottomBarVisibilityCommunicatorShell");
61 qmlRegisterUncreatableType<BottomBarVisibilityCommunicatorShell>(uri, 0, 1, "BottomBarVisibilityCommunicatorShell", "Can't create BottomBarVisibilityCommunicatorShell");
62+ qmlRegisterType<MusicPreviewTrackModel>(uri, 0, 1, "MusicPreviewTrackModel");
61}
63}
62
64
63void UnityPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
65void UnityPlugin::initializeEngine(QQmlEngine *engine, const char *uri)