mirror of
https://github.com/projectM-visualizer/projectm.git
synced 2026-03-11 18:05:18 +00:00
work on playlist opening
git-svn-id: https://projectm.svn.sourceforge.net/svnroot/projectm/trunk@663 6778bc44-b910-0410-a7a0-be141de4315d
This commit is contained in:
@ -26,11 +26,3 @@ xsi:noNamespaceSchemaLocation="presetplaylist.xsd">
|
||||
</item>
|
||||
|
||||
</PresetPlaylist>
|
||||
|
||||
|
||||
/usr/share/projectM/presets/Aderrasi - Making Time (Swamp Mix).milk
|
||||
/usr/share/projectM/presets/Aderrasi - Potion of Spirits.milk
|
||||
|
||||
/usr/share/projectM/presets/Aderrasi - Spillswirl.milk
|
||||
/usr/share/projectM/presets/Aderrasi - What cannot be.milk
|
||||
/usr/share/projectM/presets/Aderrasi - What Cannot Be Undone.milk
|
||||
|
||||
@ -17,6 +17,7 @@ set(qprojectM_SRCS
|
||||
QProjectM_MainWindow.hpp
|
||||
ConfigFile.h ConfigFile.cpp
|
||||
QProjectMFileDialog.hpp
|
||||
QPlaylistFileDialog.hpp
|
||||
QPlaylistModel.cpp
|
||||
QPlaylistModel.hpp
|
||||
)
|
||||
@ -25,6 +26,7 @@ set(qprojectM_SRCS
|
||||
set(qprojectM_MOC_HDRS
|
||||
QProjectM_MainWindow.hpp
|
||||
QProjectMFileDialog.hpp
|
||||
QPlaylistFileDialog.hpp
|
||||
QPlaylistModel.hpp
|
||||
)
|
||||
|
||||
@ -48,10 +50,10 @@ qt4_wrap_cpp(qprojectM_MOC_SRCS ${qprojectM_MOC_HDRS})
|
||||
ADD_LIBRARY(qprojectM SHARED ${qprojectM_SRCS} ${qprojectM_RC_SRCS} ${qprojectM_MOC_SRCS} ${qprojectM_UIS_H})
|
||||
LINK_DIRECTORIES(${PROJECTM_LDFLAGS})
|
||||
|
||||
include_directories(${QT_INCLUDE_DIR} ${QT_QTGUI_INCLUDE_DIR} ${QT_QTOPENGL_INCLUDE_DIR} ${CMAKE_CURRENT_LIBRARY_DIR})
|
||||
include_directories(${QT_INCLUDE_DIR} ${QT_QTGUI_INCLUDE_DIR} ${QT_QTXML_INCLUDE_DIR} ${QT_QTOPENGL_INCLUDE_DIR} ${CMAKE_CURRENT_LIBRARY_DIR})
|
||||
|
||||
# link the "qprojectM" target against the Qt libraries. which libraries exactly, is defined by the "include(${QT_USE_FILE})" line above, which sets up this variable.
|
||||
target_link_libraries(qprojectM projectM ${QT_QTGUI_LIBRARIES} ${QT_QTOPENGL_LIBRARIES} ${QT_LIBRARIES})
|
||||
target_link_libraries(qprojectM projectM ${QT_QTGUI_LIBRARIES} ${QT_QTOPENGL_LIBRARIES} ${QT_QTXML_LIBRARIES} ${QT_LIBRARIES})
|
||||
|
||||
install(FILES QProjectM_MainWindow.hpp ui_QProjectM_MainWindow.h DESTINATION include/libprojectM)
|
||||
install(TARGETS qprojectM DESTINATION lib)
|
||||
|
||||
@ -1,138 +1,216 @@
|
||||
#include "QPlaylistModel.hpp"
|
||||
#include <QIcon>
|
||||
#include <QXmlStreamReader>
|
||||
#include <QtDebug>
|
||||
#include <QFileInfo>
|
||||
|
||||
QPlaylistModel::QPlaylistModel(projectM & _projectM, QObject * parent):
|
||||
QAbstractTableModel(parent), m_projectM(_projectM) {
|
||||
m_ratings = QVector<int>(rowCount(), 3);
|
||||
QPlaylistModel::QPlaylistModel ( projectM & _projectM, QObject * parent ) :
|
||||
QAbstractTableModel ( parent ), m_projectM ( _projectM )
|
||||
{
|
||||
m_ratings = QVector<int> ( rowCount(), 3 );
|
||||
}
|
||||
|
||||
|
||||
void QPlaylistModel::updateItemHighlights() {
|
||||
if (rowCount() == 0)
|
||||
void QPlaylistModel::updateItemHighlights()
|
||||
{
|
||||
if ( rowCount() == 0 )
|
||||
return;
|
||||
|
||||
emit(dataChanged(this->index(0,0), this->index(rowCount()-1,columnCount()-1)))
|
||||
;
|
||||
emit ( dataChanged ( this->index ( 0,0 ), this->index ( rowCount()-1,columnCount()-1 ) ) )
|
||||
;
|
||||
}
|
||||
|
||||
bool QPlaylistModel::setData(const QModelIndex & index, const QVariant & value, int role) {
|
||||
if (role == QPlaylistModel::RatingRole) {
|
||||
bool QPlaylistModel::setData ( const QModelIndex & index, const QVariant & value, int role )
|
||||
{
|
||||
if ( role == QPlaylistModel::RatingRole )
|
||||
{
|
||||
//QAbstractTableModel::setData(index, ratingToIcon(value.toInt()), Qt::DecorationRole);
|
||||
//std::cerr << "here" << std::endl;
|
||||
m_ratings[index.row()] = value.toInt();
|
||||
emit(dataChanged(index, index));
|
||||
m_ratings[index.row() ] = value.toInt();
|
||||
emit ( dataChanged ( index, index ) );
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return QAbstractTableModel::setData(index, value, role);
|
||||
|
||||
else
|
||||
return QAbstractTableModel::setData ( index, value, role );
|
||||
|
||||
}
|
||||
|
||||
QVariant QPlaylistModel::ratingToIcon(int rating) const {
|
||||
switch (rating) {
|
||||
case 0:
|
||||
return QVariant(QIcon(":/images/icons/face0.png"));
|
||||
case 1:
|
||||
return QVariant(QIcon(":/images/icons/face1.png"));
|
||||
case 2:
|
||||
return QVariant(QIcon(":/images/icons/face2.png"));
|
||||
case 3:
|
||||
return QVariant(QIcon(":/images/icons/face3.png"));
|
||||
case 4:
|
||||
return QVariant(QIcon(":/images/icons/face4.png"));
|
||||
case 5:
|
||||
return QVariant(QIcon(":/images/icons/face5.png"));
|
||||
default:
|
||||
return QVariant(QIcon(":/images/icons/face0.png"));
|
||||
QVariant QPlaylistModel::ratingToIcon ( int rating ) const
|
||||
{
|
||||
switch ( rating )
|
||||
{
|
||||
case 0:
|
||||
return QVariant ( QIcon ( ":/images/icons/face0.png" ) );
|
||||
case 1:
|
||||
return QVariant ( QIcon ( ":/images/icons/face1.png" ) );
|
||||
case 2:
|
||||
return QVariant ( QIcon ( ":/images/icons/face2.png" ) );
|
||||
case 3:
|
||||
return QVariant ( QIcon ( ":/images/icons/face3.png" ) );
|
||||
case 4:
|
||||
return QVariant ( QIcon ( ":/images/icons/face4.png" ) );
|
||||
case 5:
|
||||
return QVariant ( QIcon ( ":/images/icons/face5.png" ) );
|
||||
default:
|
||||
return QVariant ( QIcon ( ":/images/icons/face0.png" ) );
|
||||
}
|
||||
}
|
||||
|
||||
QVariant QPlaylistModel::data ( const QModelIndex & index, int role = Qt::DisplayRole ) const {
|
||||
|
||||
switch (role) {
|
||||
QVariant QPlaylistModel::data ( const QModelIndex & index, int role = Qt::DisplayRole ) const
|
||||
{
|
||||
|
||||
switch ( role )
|
||||
{
|
||||
case Qt::DisplayRole:
|
||||
if (index.column() == 0)
|
||||
return QVariant(QString(m_projectM.getPresetName(index.row()).c_str()));
|
||||
if ( index.column() == 0 )
|
||||
return QVariant ( QString ( m_projectM.getPresetName ( index.row() ).c_str() ) );
|
||||
else
|
||||
return ratingToIcon(m_ratings[index.row()]);
|
||||
return ratingToIcon ( m_ratings[index.row() ] );
|
||||
case Qt::ToolTip:
|
||||
if (index.column() == 0)
|
||||
return QVariant(QString(m_projectM.getPresetName(index.row()).c_str()));
|
||||
if ( index.column() == 0 )
|
||||
return QVariant ( QString ( m_projectM.getPresetName ( index.row() ).c_str() ) );
|
||||
else
|
||||
return QString("Current rating is %1 / 5").arg(m_ratings[index.row()]);
|
||||
case Qt::DecorationRole:
|
||||
if (index.column() == 1)
|
||||
return ratingToIcon(m_ratings[index.row()]);
|
||||
return QString ( "Current rating is %1 / 5" ).arg ( m_ratings[index.row() ] );
|
||||
case Qt::DecorationRole:
|
||||
if ( index.column() == 1 )
|
||||
return ratingToIcon ( m_ratings[index.row() ] );
|
||||
else
|
||||
return QVariant();
|
||||
case QPlaylistModel::RatingRole:
|
||||
return QVariant(m_ratings[index.row()]);
|
||||
return QVariant ( m_ratings[index.row() ] );
|
||||
|
||||
case Qt::BackgroundRole:
|
||||
|
||||
if (m_projectM.isPresetLocked() && (index.row() == m_projectM.selectedPresetIndex()))
|
||||
if ( m_projectM.isPresetLocked() && ( index.row() == m_projectM.selectedPresetIndex() ) )
|
||||
return Qt::red;
|
||||
if (!m_projectM.isPresetLocked() && (index.row() == m_projectM.selectedPresetIndex()))
|
||||
if ( !m_projectM.isPresetLocked() && ( index.row() == m_projectM.selectedPresetIndex() ) )
|
||||
return Qt::green;
|
||||
|
||||
|
||||
return Qt::white;
|
||||
|
||||
case QPlaylistModel::URLInfoRole:
|
||||
return QVariant(QString(m_projectM.getPresetURL(index.row()).c_str()));
|
||||
return QVariant ( QString ( m_projectM.getPresetURL ( index.row() ).c_str() ) );
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
}
|
||||
|
||||
QVariant QPlaylistModel::headerData ( int section, Qt::Orientation orientation, int role) const {
|
||||
QVariant QPlaylistModel::headerData ( int section, Qt::Orientation orientation, int role ) const
|
||||
{
|
||||
|
||||
if (orientation == Qt::Vertical)
|
||||
return QAbstractTableModel::headerData(section, orientation, role);
|
||||
if ( orientation == Qt::Vertical )
|
||||
return QAbstractTableModel::headerData ( section, orientation, role );
|
||||
|
||||
if ((section == 0) && (role == Qt::SizeHintRole))
|
||||
return QVariant(500);
|
||||
if ( ( section == 0 ) && ( role == Qt::SizeHintRole ) )
|
||||
return QVariant ( 500 );
|
||||
// if ((section == 1) && (role == Qt::SizeHintRole))
|
||||
// return QVariant(60);
|
||||
if ((section == 0) && (role == Qt::DisplayRole))
|
||||
return QString(tr("Preset"));
|
||||
if ((section == 1) && (role == Qt::DisplayRole))
|
||||
return QString(tr("Rating"));
|
||||
|
||||
return QAbstractTableModel::headerData(section, orientation, role);
|
||||
if ( ( section == 0 ) && ( role == Qt::DisplayRole ) )
|
||||
return QString ( tr ( "Preset" ) );
|
||||
if ( ( section == 1 ) && ( role == Qt::DisplayRole ) )
|
||||
return QString ( tr ( "Rating" ) );
|
||||
|
||||
return QAbstractTableModel::headerData ( section, orientation, role );
|
||||
}
|
||||
|
||||
int QPlaylistModel::rowCount ( const QModelIndex & parent) const {
|
||||
int QPlaylistModel::rowCount ( const QModelIndex & parent ) const
|
||||
{
|
||||
return m_projectM.getPlaylistSize();
|
||||
}
|
||||
|
||||
|
||||
int QPlaylistModel::columnCount ( const QModelIndex & parent) const {
|
||||
int QPlaylistModel::columnCount ( const QModelIndex & parent ) const
|
||||
{
|
||||
|
||||
// eventually add ratings here so size should be 2
|
||||
if (rowCount() > 0)
|
||||
if ( rowCount() > 0 )
|
||||
return 2;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
void QPlaylistModel::appendRow (const QString & presetURL, const QString & presetName, int rating) {
|
||||
beginInsertRows(QModelIndex(), rowCount(), rowCount());
|
||||
m_projectM.addPresetURL(presetURL.toStdString(), presetName.toStdString());
|
||||
m_ratings.push_back(rating);
|
||||
void QPlaylistModel::appendRow ( const QString & presetURL, const QString & presetName, int rating )
|
||||
{
|
||||
beginInsertRows ( QModelIndex(), rowCount(), rowCount() );
|
||||
m_projectM.addPresetURL ( presetURL.toStdString(), presetName.toStdString() );
|
||||
m_ratings.push_back ( rating );
|
||||
endInsertRows();
|
||||
}
|
||||
|
||||
|
||||
void QPlaylistModel::removeRow (int index) {
|
||||
beginRemoveRows(QModelIndex(), index, index);
|
||||
m_projectM.removePreset(index);
|
||||
m_ratings.remove(index);
|
||||
void QPlaylistModel::removeRow ( int index )
|
||||
{
|
||||
beginRemoveRows ( QModelIndex(), index, index );
|
||||
m_projectM.removePreset ( index );
|
||||
m_ratings.remove ( index );
|
||||
endRemoveRows();
|
||||
}
|
||||
|
||||
void QPlaylistModel::clear() {
|
||||
beginRemoveRows(QModelIndex(), 0, rowCount()-1);
|
||||
void QPlaylistModel::clear()
|
||||
{
|
||||
beginRemoveRows ( QModelIndex(), 0, rowCount()-1 );
|
||||
m_projectM.clearPlaylist();
|
||||
m_ratings.clear();
|
||||
endRemoveRows();
|
||||
}
|
||||
|
||||
void QPlaylistModel::readPlaylist ( const QString & file )
|
||||
{
|
||||
|
||||
QXmlStreamReader reader ( file );
|
||||
|
||||
QXmlStreamReader::TokenType token;
|
||||
|
||||
while ( !reader.atEnd() ) {
|
||||
token = reader.readNext();
|
||||
switch ( token )
|
||||
{
|
||||
case QXmlStreamReader::StartElement:
|
||||
qDebug() << "start elem:" << reader.name().toString();
|
||||
if (reader.name() == "item") {
|
||||
readPlaylistItem(reader);
|
||||
break;
|
||||
}
|
||||
|
||||
case QXmlStreamReader::NoToken:
|
||||
case QXmlStreamReader::Invalid:
|
||||
case QXmlStreamReader::StartDocument:
|
||||
case QXmlStreamReader::EndDocument:
|
||||
case QXmlStreamReader::EndElement:
|
||||
case QXmlStreamReader::Characters:
|
||||
case QXmlStreamReader::Comment:
|
||||
case QXmlStreamReader::DTD:
|
||||
case QXmlStreamReader::EntityReference:
|
||||
case QXmlStreamReader::ProcessingInstruction:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (reader.hasError()) {
|
||||
qDebug() << "error occurred: " << reader.error();
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
void QPlaylistModel::readPlaylistItem(QXmlStreamReader & reader) {
|
||||
|
||||
|
||||
QString url;
|
||||
int rating;
|
||||
|
||||
while (reader.readNext() != QXmlStreamReader::EndElement)
|
||||
if (reader.name() == "url") {
|
||||
reader.readNext();
|
||||
url = reader.text().toString();
|
||||
reader.readNext();
|
||||
} else if (reader.name() == "rating") {
|
||||
reader.readNext();
|
||||
rating = reader.text().toString().toInt();
|
||||
}
|
||||
else {
|
||||
/// throw a stream exception
|
||||
qDebug() << (reader.name().toString());
|
||||
throw 0;
|
||||
}
|
||||
this->appendRow(url, QFileInfo(url).fileName(), rating);
|
||||
}
|
||||
|
||||
@ -27,7 +27,7 @@
|
||||
|
||||
#include <QAbstractTableModel>
|
||||
#include <QVector>
|
||||
|
||||
class QXmlStreamReader;
|
||||
class QPlaylistModel : public QAbstractTableModel
|
||||
{
|
||||
Q_OBJECT // must include this if you use Qt signals/slots
|
||||
@ -50,10 +50,14 @@ QVariant data ( const QModelIndex & index, int role) const;
|
||||
int rowCount ( const QModelIndex & parent = QModelIndex()) const ;
|
||||
int columnCount ( const QModelIndex & parent= QModelIndex()) const ;
|
||||
|
||||
void readPlaylist(const QString & file);
|
||||
|
||||
public slots:
|
||||
void updateItemHighlights();
|
||||
|
||||
private:
|
||||
void readPlaylistItem(QXmlStreamReader & reader);
|
||||
|
||||
QVariant ratingToIcon(int rating) const;
|
||||
projectM & m_projectM;
|
||||
QVector<int> m_ratings;
|
||||
|
||||
@ -22,7 +22,7 @@
|
||||
#include <QtGui>
|
||||
#include "QProjectM_MainWindow.hpp"
|
||||
#include "QProjectMFileDialog.hpp"
|
||||
|
||||
#include "QPlaylistFileDialog.hpp"
|
||||
#include <QTextStream>
|
||||
#include <QCloseEvent>
|
||||
#include <QFileDialog>
|
||||
@ -30,7 +30,7 @@
|
||||
#include "QPlaylistModel.hpp"
|
||||
|
||||
QProjectM_MainWindow::QProjectM_MainWindow(const std::string & config_file)
|
||||
:m_QProjectMFileDialog(new QProjectMFileDialog(this)), oldPresetIndex(-1)
|
||||
:m_QProjectMFileDialog(new QProjectMFileDialog(this)), m_QPlaylistFileDialog(new QPlaylistFileDialog(this)), oldPresetIndex(-1)
|
||||
{
|
||||
|
||||
ui.setupUi(this);
|
||||
@ -46,6 +46,7 @@ QProjectM_MainWindow::QProjectM_MainWindow(const std::string & config_file)
|
||||
connect(ui.clearPresetList_PushButton, SIGNAL(pressed()),
|
||||
this, SLOT(clearPlaylist()));
|
||||
|
||||
|
||||
connect(m_QProjectMWidget, SIGNAL(projectM_Initialized()), this, SLOT(postProjectM_Initialize()));
|
||||
|
||||
|
||||
@ -210,7 +211,7 @@ void QProjectM_MainWindow::closeEvent(QCloseEvent *event)
|
||||
}
|
||||
|
||||
|
||||
void QProjectM_MainWindow::open()
|
||||
void QProjectM_MainWindow::addPresets()
|
||||
{
|
||||
|
||||
|
||||
@ -240,6 +241,28 @@ void QProjectM_MainWindow::open()
|
||||
//playlistModel->setHeaderData(0, Qt::Horizontal, tr("Preset"));//, Qt::DisplayRole);
|
||||
}
|
||||
|
||||
void QProjectM_MainWindow::openPlaylist()
|
||||
{
|
||||
|
||||
clearPlaylist();
|
||||
|
||||
if ( m_QPlaylistFileDialog->exec()) {
|
||||
const QStringList & files = m_QPlaylistFileDialog->selectedFiles();
|
||||
|
||||
for (QStringList::const_iterator pos = files.begin();
|
||||
pos != files.end(); ++pos) {
|
||||
if (*pos != "") {
|
||||
//QVector items;
|
||||
playlistModel->readPlaylist(*pos);
|
||||
|
||||
//for (QV
|
||||
//historyHash.insert(PlaylistItemMetaData(
|
||||
}
|
||||
}
|
||||
}
|
||||
//playlistModel->setHeaderData(0, Qt::Horizontal, tr("Preset"));//, Qt::DisplayRole);
|
||||
}
|
||||
|
||||
//void QAbstractItemView::clicked ( const QModelIndex & index ) [signal]
|
||||
void QProjectM_MainWindow::refreshPlaylist() {
|
||||
|
||||
@ -298,8 +321,8 @@ void QProjectM_MainWindow::createActions()
|
||||
|
||||
connect(ui.actionExit, SIGNAL(triggered()), this, SLOT(close()));
|
||||
|
||||
connect(ui.actionAddPresets, SIGNAL(triggered()), this, SLOT(open()));
|
||||
|
||||
connect(ui.actionAddPresets, SIGNAL(triggered()), this, SLOT(addPresets()));
|
||||
connect(ui.actionOpen_Play_List, SIGNAL(triggered()), this, SLOT(openPlaylist()));
|
||||
connect(ui.actionAbout_qprojectM, SIGNAL(triggered()), this, SLOT(about()));
|
||||
|
||||
//connect(ui.actionAbout_Qt, SIGNAL(triggered()), this, SLOT(aboutQt()));
|
||||
|
||||
@ -35,6 +35,7 @@
|
||||
class QAction;
|
||||
class QMenu;
|
||||
class QProjectMFileDialog;
|
||||
class QPlaylistFileDialog;
|
||||
class QPlaylistModel;
|
||||
|
||||
#include <iostream>
|
||||
@ -230,7 +231,8 @@ protected:
|
||||
|
||||
private slots:
|
||||
void clearPlaylist();
|
||||
void open();
|
||||
void addPresets();
|
||||
void openPlaylist();
|
||||
void about();
|
||||
void postProjectM_Initialize();
|
||||
void updatePlaylistSelection(bool hardCut, int index);
|
||||
@ -273,6 +275,7 @@ private:
|
||||
QString previousFilter;
|
||||
|
||||
QProjectMFileDialog * m_QProjectMFileDialog;
|
||||
QPlaylistFileDialog * m_QPlaylistFileDialog;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user