mirror of
https://github.com/QuasarApp/SoundBand.git
synced 2025-05-13 23:49:33 +00:00
add first init methods into qml model
This commit is contained in:
parent
7569238ce4
commit
ca5a55ad76
@ -1,16 +1,32 @@
|
||||
import QtQuick 2.4
|
||||
import QtQuick.Controls 2.3
|
||||
|
||||
ListView {
|
||||
id: listView
|
||||
width: parent.width
|
||||
height: parent.height
|
||||
model: ListModel {
|
||||
|
||||
Item{
|
||||
function addItem(obj){
|
||||
model.append(obj);
|
||||
}
|
||||
|
||||
delegate: SongDelegate{
|
||||
|
||||
function removeItem(obj){
|
||||
model.remove(obj);
|
||||
}
|
||||
|
||||
function clear(){
|
||||
model.clear()
|
||||
}
|
||||
|
||||
ListView {
|
||||
id: listView
|
||||
width: parent.width
|
||||
height: parent.height
|
||||
|
||||
model: ListModel {
|
||||
id: model;
|
||||
|
||||
}
|
||||
|
||||
delegate: SongDelegate{
|
||||
|
||||
}
|
||||
anchors.fill: parent
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
import QtQuick 2.4
|
||||
import QtQuick 2.10
|
||||
import QtQuick.Controls 2.3
|
||||
|
||||
Item {
|
||||
@ -11,6 +11,7 @@ Item {
|
||||
anchors.bottom: groupBox.top
|
||||
anchors.left: parent.right
|
||||
source: "/image/res/logo.png"
|
||||
visible: true;
|
||||
}
|
||||
Text {
|
||||
id: songName
|
||||
|
@ -1,10 +1,22 @@
|
||||
import QtQuick 2.10
|
||||
import QtQuick.Controls 2.3
|
||||
import SyncEngine 1.0
|
||||
|
||||
Page {
|
||||
id: page
|
||||
width: 600
|
||||
height: 400
|
||||
|
||||
function onLoaded(){
|
||||
playListsControl.init();
|
||||
curentPlayList.init();
|
||||
}
|
||||
|
||||
SyncEngine{
|
||||
id: syncEngine
|
||||
|
||||
}
|
||||
|
||||
Header{
|
||||
id:header
|
||||
height: 300
|
||||
@ -12,8 +24,67 @@ Page {
|
||||
anchors.top: parent.top
|
||||
anchors.right: parent.right
|
||||
}
|
||||
CurentPlayList{
|
||||
id:curentPlayList
|
||||
|
||||
Item{
|
||||
|
||||
SwipeView {
|
||||
id: swipeView
|
||||
anchors.fill: parent
|
||||
currentIndex: 1
|
||||
|
||||
ServerListPage{
|
||||
id:serverListPage;
|
||||
}
|
||||
|
||||
CurentPlayList {
|
||||
id:curentPlayList;
|
||||
|
||||
function init(){
|
||||
var listOfSong = [];
|
||||
listOfSong = syncEngine.curentPlayList();
|
||||
|
||||
for(var i = 0; i < listOfSong.length; i++){
|
||||
var temp = Qt.createComponent("SongDelegate.qml");
|
||||
if(temp.status === Component.Ready){
|
||||
var obj = temp.createObject();
|
||||
var songName = listOfSong[i];
|
||||
obj.init(syncEngine.songImageByName(songName), songName);
|
||||
parent.addItem(obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PlayListsControl{
|
||||
id:playListsControl;
|
||||
|
||||
function init(){
|
||||
var playlists = [];
|
||||
playlists = syncEngine.allPlayLists();
|
||||
|
||||
for(var i = 0; i < playlists.length; i++){
|
||||
var temp = Qt.createComponent("PlayListDelegate.qml");
|
||||
if(temp.status === Component.Ready){
|
||||
var obj = temp.createObject();
|
||||
obj.init(playlists[i]);
|
||||
parent.addItem(obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
PageIndicator {
|
||||
id: indicator
|
||||
|
||||
count: swipeView.count
|
||||
currentIndex: swipeView.currentIndex
|
||||
|
||||
anchors.bottom: swipeView.bottom
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
}
|
||||
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.top: header.bottom
|
||||
|
@ -7,6 +7,11 @@ Item {
|
||||
width: 80
|
||||
height: 40
|
||||
property bool isSelected: false
|
||||
|
||||
function init(name){
|
||||
text.text = name;
|
||||
}
|
||||
|
||||
Row {
|
||||
id: row1
|
||||
spacing: 10
|
||||
@ -17,7 +22,8 @@ Item {
|
||||
}
|
||||
|
||||
Text {
|
||||
text: name
|
||||
id: text
|
||||
text: ""
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
font.bold: true
|
||||
}
|
||||
|
@ -4,6 +4,19 @@ import QtQuick.Controls 2.3
|
||||
Item {
|
||||
|
||||
property string name: "no selected"
|
||||
|
||||
function addItem(obj){
|
||||
model.append(obj);
|
||||
}
|
||||
|
||||
function removeItem(obj){
|
||||
model.remove(obj);
|
||||
}
|
||||
|
||||
function clear(){
|
||||
model.clear()
|
||||
}
|
||||
|
||||
Text{
|
||||
id:name
|
||||
height: 30
|
||||
@ -12,10 +25,12 @@ Item {
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
}
|
||||
|
||||
ListView {
|
||||
id: listView
|
||||
|
||||
model: ListModel {
|
||||
id: model
|
||||
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,18 @@ import QtQuick 2.4
|
||||
import QtQuick.Controls 2.3
|
||||
|
||||
Item {
|
||||
function addItem(obj){
|
||||
model.append(obj);
|
||||
}
|
||||
|
||||
function removeItem(obj){
|
||||
model.remove(obj);
|
||||
}
|
||||
|
||||
function clear(){
|
||||
model.clear()
|
||||
}
|
||||
|
||||
GroupBox {
|
||||
id: controlBox
|
||||
title: qsTr("Your playlists")
|
||||
@ -49,6 +61,7 @@ Item {
|
||||
}
|
||||
|
||||
model: ListModel {
|
||||
id: model;
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -3,18 +3,33 @@ import QtQuick 2.10
|
||||
Item {
|
||||
width: parent.width
|
||||
height: 40
|
||||
function init(image, name){
|
||||
img.source = image;
|
||||
text.text = name;
|
||||
}
|
||||
|
||||
signal clicked();
|
||||
Row {
|
||||
id: row1
|
||||
spacing: 10
|
||||
Image {
|
||||
id:img;
|
||||
width: 40
|
||||
height: 40
|
||||
}
|
||||
|
||||
Text {
|
||||
id:text
|
||||
text: name
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
font.bold: true
|
||||
}
|
||||
|
||||
MouseArea{
|
||||
anchors.fill: parent
|
||||
onClicked: {
|
||||
clicked();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,10 +20,7 @@ SongDelegate {
|
||||
active: parent.isSelected
|
||||
}
|
||||
|
||||
MouseArea{
|
||||
anchors.fill: parent
|
||||
onClicked: {
|
||||
isSelected = !isSelected;
|
||||
}
|
||||
onClicked: {
|
||||
isSelected = !isSelected;
|
||||
}
|
||||
}
|
||||
|
@ -2,34 +2,21 @@ import QtQuick 2.10
|
||||
import QtQuick.Controls 2.3
|
||||
|
||||
ApplicationWindow {
|
||||
|
||||
visible: true
|
||||
width: 340
|
||||
height: 480
|
||||
title: qsTr("Tabs")
|
||||
|
||||
SwipeView {
|
||||
id: swipeView
|
||||
Loader {
|
||||
id: core
|
||||
source: "MainPage.qml"
|
||||
anchors.fill: parent
|
||||
currentIndex: 1
|
||||
|
||||
ServerListPage{
|
||||
onLoaded: {
|
||||
item.onLoaded()
|
||||
}
|
||||
|
||||
MainPage {
|
||||
}
|
||||
|
||||
PlayListsControl{
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
PageIndicator {
|
||||
id: indicator
|
||||
|
||||
count: swipeView.count
|
||||
currentIndex: swipeView.currentIndex
|
||||
|
||||
anchors.bottom: swipeView.bottom
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
}
|
||||
}
|
||||
|
@ -1,2 +1,11 @@
|
||||
[Controls]
|
||||
Style=Imagine
|
||||
|
||||
[Universal]
|
||||
Theme=System
|
||||
Accent=Red
|
||||
|
||||
[Imagine]
|
||||
Theme=Light
|
||||
Accent=Teal
|
||||
Primary=BlueGrey
|
||||
|
@ -12,9 +12,9 @@ const QString& SyncEngine::curentSong()const{
|
||||
return sync->getCurentSong()->name;
|
||||
}
|
||||
|
||||
const QStringList& SyncEngine::curentPlayList(){
|
||||
QStringList SyncEngine::curentPlayList(){
|
||||
|
||||
QStringList &result = tempList;
|
||||
QStringList result;
|
||||
result.clear();
|
||||
|
||||
const QList<syncLib::SongHeader> *list = sync->getPlayList();
|
||||
@ -30,8 +30,8 @@ const QString& SyncEngine::curentPlayListName() const{
|
||||
return _curentPlayListName;
|
||||
}
|
||||
|
||||
const QStringList& SyncEngine::allPlayLists(){
|
||||
QStringList &result = tempList;
|
||||
QStringList SyncEngine::allPlayLists(){
|
||||
QStringList result;
|
||||
result.clear();
|
||||
|
||||
sqlApi->getPlayLists(result);
|
||||
@ -55,6 +55,14 @@ QPixmap SyncEngine::songImageById(int ) {
|
||||
return QPixmap(1, 1);
|
||||
}
|
||||
|
||||
QPixmap SyncEngine::songImageByName(const QString& name) {
|
||||
|
||||
_lastError = tr("This option not supported.");
|
||||
emit error();
|
||||
|
||||
return QPixmap(1, 1);
|
||||
}
|
||||
|
||||
bool SyncEngine::play(){
|
||||
try{
|
||||
return sync->play(sqlApi->getSongId(_curentPlayListName));
|
||||
@ -112,10 +120,10 @@ bool SyncEngine::listen(int index){
|
||||
}
|
||||
}
|
||||
|
||||
const QStringList& SyncEngine::getServerList(){
|
||||
QStringList SyncEngine::getServerList(){
|
||||
const QList<ETcpSocket*>& list = sync->getServersList();
|
||||
|
||||
tempList.clear();
|
||||
QStringList tempList;
|
||||
|
||||
for(ETcpSocket* socket : list){
|
||||
tempList.push_back(socket->peerName());
|
||||
|
@ -22,7 +22,6 @@ private:
|
||||
syncLib::MySql * sqlApi;
|
||||
QString _curentPlayListName;
|
||||
QString _lastError;
|
||||
QStringList tempList;
|
||||
Repeat _repeat;
|
||||
public:
|
||||
SyncEngine();
|
||||
@ -38,7 +37,7 @@ public slots:
|
||||
* @brief curentPlayList
|
||||
* @return return curent Play List
|
||||
*/
|
||||
const QStringList &curentPlayList();
|
||||
QStringList curentPlayList();
|
||||
|
||||
/**
|
||||
* @brief curentPlayListName
|
||||
@ -50,7 +49,7 @@ public slots:
|
||||
* @brief allPlayLists
|
||||
* @return names of all play lists
|
||||
*/
|
||||
const QStringList &allPlayLists();
|
||||
QStringList allPlayLists();
|
||||
|
||||
/**
|
||||
* @brief curentSongImage
|
||||
@ -65,6 +64,13 @@ public slots:
|
||||
*/
|
||||
QPixmap songImageById(int id);
|
||||
|
||||
/**
|
||||
* @brief songImageById
|
||||
* @param name - name of Song;
|
||||
* @return image of song
|
||||
*/
|
||||
QPixmap songImageByName(const QString & name);
|
||||
|
||||
/**
|
||||
* @brief play - play curent music
|
||||
* @return true if all done.
|
||||
@ -131,7 +137,7 @@ public slots:
|
||||
* @brief getServerList
|
||||
* @return list of servers
|
||||
*/
|
||||
const QStringList& getServerList();
|
||||
QStringList getServerList();
|
||||
|
||||
signals:
|
||||
|
||||
@ -158,6 +164,7 @@ signals:
|
||||
* This signal can be emitted when repeat state changed
|
||||
*/
|
||||
void repeatChanged();
|
||||
|
||||
};
|
||||
|
||||
#endif // SYNCENGINE_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user