Skip to content

Commit

Permalink
Add playlist category found widget[912001]
Browse files Browse the repository at this point in the history
  • Loading branch information
Greedysky committed Feb 27, 2017
1 parent b964880 commit 6f8c9b2
Show file tree
Hide file tree
Showing 9 changed files with 300 additions and 19 deletions.
6 changes: 4 additions & 2 deletions TTKCore/musicCoreKits/MusicCoreKits.pri
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ HEADERS += \
$$PWD/musiccryptographichash.h \
$$PWD/musicbackgroundmanager.h \
$$PWD/musicsystemenvironment.h \
$$PWD/musicsemaphoreloop.h
$$PWD/musicsemaphoreloop.h \
$$PWD/musiccategoryconfigmanager.h

}

Expand All @@ -62,6 +63,7 @@ SOURCES += \
$$PWD/musiccryptographichash.cpp \
$$PWD/musicbackgroundmanager.cpp \
$$PWD/musicsystemenvironment.cpp \
$$PWD/musicsemaphoreloop.cpp
$$PWD/musicsemaphoreloop.cpp \
$$PWD/musiccategoryconfigmanager.cpp

}
38 changes: 38 additions & 0 deletions TTKCore/musicCoreKits/musiccategoryconfigmanager.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include "musiccategoryconfigmanager.h"

MusicCategoryConfigManager::MusicCategoryConfigManager(QObject *parent)
: MusicAbstractXml(parent)
{

}

QString MusicCategoryConfigManager::getClassName()
{
return staticMetaObject.className();
}

void MusicCategoryConfigManager::readCategoryConfig(PlaylistCategorys &records, const QString &key)
{
QDomNodeList nodes = m_ddom->elementsByTagName(key);
for(int i=0; i<nodes.count(); ++i)
{
QDomNode node = nodes.at(i);
QDomNodeList tagNodes = node.childNodes();
for(int j=0; j<tagNodes.count(); ++j)
{
PlaylistCategory category;
QDomNode tagNode = tagNodes.at(j);
category.m_category = tagNode.toElement().attribute("value");
QDomNodeList typeNodes = tagNode.childNodes();
for(int k=0; k<typeNodes.count(); ++k)
{
PlaylistCategoryItem item;
QDomNode typeNode = typeNodes.at(k);
item.m_name = typeNode.toElement().attribute("value");
item.m_id = typeNode.toElement().attribute("key");
category.m_items.append(item);
}
records.append(category);
}
}
}
66 changes: 66 additions & 0 deletions TTKCore/musicCoreKits/musiccategoryconfigmanager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#ifndef MUSICCATEGORYCONFIGMANAGER_H
#define MUSICCATEGORYCONFIGMANAGER_H

/* =================================================
* This file is part of the TTK Music Player project
* Copyright (c) 2015 - 2017 Greedysky Studio
* All rights reserved!
* Redistribution and use of the source code or any derivative
* works are strictly forbiden.
=================================================*/

#include "musicabstractxml.h"

typedef struct MUSIC_CORE_EXPORT PlaylistCategoryItem
{
QString m_id;
QString m_name;

PlaylistCategoryItem()
{

}

PlaylistCategoryItem(const QString &id, const QString &name)
{
m_id = id;
m_name = name;
}
}PlaylistCategoryItem;
TTK_DECLARE_LISTS(PlaylistCategoryItem)

typedef struct MUSIC_CORE_EXPORT PlaylistCategory
{
QString m_category;
PlaylistCategoryItems m_items;
}PlaylistCategory;
TTK_DECLARE_LISTS(PlaylistCategory)

/*! @brief The class of the category Config Manager.
* @author Greedysky <[email protected]>
*/
class MUSIC_CORE_EXPORT MusicCategoryConfigManager : public MusicAbstractXml
{
Q_OBJECT
public:
explicit MusicCategoryConfigManager(QObject *parent = 0);
/*!
* Object contsructor.
*/

static QString getClassName();
/*!
* Get class object name.
*/
inline bool readCategoryConfig(){ return readConfig(":/data/playlist"); }
/*!
* Read user datas from xml file by given name.
*/
void readCategoryConfig(PlaylistCategorys &records, const QString &key);
/*!
* Read user datas into xml file.
*/

};

#endif // MUSICCATEGORYCONFIGMANAGER_H
2 changes: 1 addition & 1 deletion TTKCore/musicWidgetCoreKits/musicfoundabstractwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ MusicFoundAbstractWidget::MusicFoundAbstractWidget(QWidget *parent)
m_statusLabel = new QLabel(tr("Loading Now ... "), m_mainWindow);
m_statusLabel->setStyleSheet(MusicUIObject::MFontStyle05 + MusicUIObject::MFontStyle01);

QHBoxLayout *mLayout = new QHBoxLayout(m_mainWindow);
QVBoxLayout *mLayout = new QVBoxLayout(m_mainWindow);
mLayout->addWidget(m_statusLabel, 0, Qt::AlignCenter);
m_mainWindow->setLayout(mLayout);
}
Expand Down
103 changes: 101 additions & 2 deletions TTKCore/musicWidgetKits/musicplaylistfoundcategorywidget.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,63 @@
#include "musicplaylistfoundcategorywidget.h"
#include "musicclickedlabel.h"
#include "musicuiobject.h"

#include <QLabel>
#include <QGridLayout>
#include <QPushButton>
#include <QSignalMapper>
#include <QScrollArea>

MusicPlaylistFoundCategoryItem::MusicPlaylistFoundCategoryItem(QWidget *parent)
: QWidget(parent)
{
setStyleSheet(QString());
}

QString MusicPlaylistFoundCategoryItem::getClassName()
{
return staticMetaObject.className();
}

void MusicPlaylistFoundCategoryItem::setCategory(const PlaylistCategory &category)
{
m_category = category;

QHBoxLayout *layout = new QHBoxLayout(this);
QLabel *label = new QLabel(category.m_category, this);
label->setFixedSize(80, 20);
layout->addWidget(label, 0, Qt::AlignTop);

QWidget *item = new QWidget(this);
QGridLayout *itemlayout = new QGridLayout(item);
itemlayout->setContentsMargins(0, 0, 0, 0);

QSignalMapper *group = new QSignalMapper(this);
connect(group, SIGNAL(mapped(int)), SLOT(buttonClicked(int)));

for(int i=0; i<m_category.m_items.count(); ++i)
{
MusicClickedLabel *l = new MusicClickedLabel(m_category.m_items[i].m_name, item);
l->setFixedSize(70, 20);
connect(l, SIGNAL(clicked()), group, SLOT(map()));
group->setMapping(l, i);
itemlayout->addWidget(l, i/6, i%6, Qt::AlignLeft);
}
item->setLayout(itemlayout);

layout->addWidget(item, 0, Qt::AlignTop);
setLayout(layout);
}

void MusicPlaylistFoundCategoryItem::buttonClicked(int index)
{
if(0 <= index && index < m_category.m_items.count())
{
emit categoryChanged(m_category.m_items[index]);
}
}


MusicPlaylistFoundCategoryWidget::MusicPlaylistFoundCategoryWidget(QWidget *parent)
: MusicToolMenuWidget(parent)
{
Expand All @@ -20,6 +77,41 @@ QString MusicPlaylistFoundCategoryWidget::getClassName()
return staticMetaObject.className();
}

void MusicPlaylistFoundCategoryWidget::setCategory(const QString &server, QObject *obj)
{
PlaylistCategorys categorys;
MusicCategoryConfigManager manager;
manager.readCategoryConfig();
manager.readCategoryConfig(categorys, server);

QVBoxLayout *layout = new QVBoxLayout(m_containWidget);
QWidget *containWidget = new QWidget(m_containWidget);
QVBoxLayout *containLayout = new QVBoxLayout(containWidget);
containWidget->setLayout(containLayout);

QScrollArea *scrollArea = new QScrollArea(this);
scrollArea->setStyleSheet(MusicUIObject::MScrollBarStyle01);
scrollArea->setWidgetResizable(true);
scrollArea->setFrameShape(QFrame::NoFrame);
scrollArea->setAlignment(Qt::AlignLeft);
scrollArea->setWidget(containWidget);
layout->addWidget(scrollArea);

foreach(const PlaylistCategory &category, categorys)
{
MusicPlaylistFoundCategoryItem *item = new MusicPlaylistFoundCategoryItem(this);
connect(item, SIGNAL(categoryChanged(PlaylistCategoryItem)), obj, SLOT(categoryChanged(PlaylistCategoryItem)));
item->setCategory(category);
containLayout->addWidget(item);
}
m_containWidget->setLayout(layout);
}

void MusicPlaylistFoundCategoryWidget::closeMenu()
{
m_menu->close();
}

void MusicPlaylistFoundCategoryWidget::popupMenu()
{
m_menu->exec( mapToGlobal(QPoint(0, 0)) );
Expand All @@ -29,9 +121,16 @@ void MusicPlaylistFoundCategoryWidget::initWidget()
{
setFixedSize(100, 30);
setTranslucentBackground();
setStyleSheet(MusicUIObject::MBorderStyle04 + MusicUIObject::MBackgroundStyle17);
m_menu->setStyleSheet(MusicUIObject::MMenuStyle05);
setText(tr("All"));

QString style = MusicUIObject::MBorderStyle04 + MusicUIObject::MBackgroundStyle17;
setObjectName("mianWidget");
setStyleSheet(QString("#mianWidget{%1}").arg(style));

m_containWidget->setFixedSize(600, 370);
m_containWidget->setObjectName("containWidget");
m_containWidget->setStyleSheet(QString("#containWidget{%1}").arg(style));

m_menu->setStyleSheet(MusicUIObject::MMenuStyle05);

}
50 changes: 50 additions & 0 deletions TTKCore/musicWidgetKits/musicplaylistfoundcategorywidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,48 @@
=================================================*/

#include "musictoolmenuwidget.h"
#include "musiccategoryconfigmanager.h"

/*! @brief The class of the playlist music found category item.
* @author Greedysky <[email protected]>
*/
class MUSIC_WIDGET_EXPORT MusicPlaylistFoundCategoryItem : public QWidget
{
Q_OBJECT
public:
explicit MusicPlaylistFoundCategoryItem(QWidget *parent = 0);
/*!
* Object contsructor.
*/

static QString getClassName();
/*!
* Get class object name.
*/

void setCategory(const PlaylistCategory &category);
/*!
* Set current category.
*/

Q_SIGNALS:
void categoryChanged(const PlaylistCategoryItem &category);
/*!
* Current category changed.
*/

public Q_SLOTS:
void buttonClicked(int index);
/*!
* Current category item clicked.
*/

protected:
PlaylistCategory m_category;

};



/*! @brief The class of the playlist music found category widget.
* @author Greedysky <[email protected]>
Expand All @@ -28,6 +70,14 @@ class MUSIC_WIDGET_EXPORT MusicPlaylistFoundCategoryWidget : public MusicToolMen
/*!
* Get class object name.
*/
void setCategory(const QString &server, QObject *obj);
/*!
* Set current category by input server.
*/
void closeMenu();
/*!
* Close the menu dialog.
*/

public Q_SLOTS:
void popupMenu();
Expand Down
Loading

0 comments on commit 6f8c9b2

Please sign in to comment.