mirror of
https://github.com/projectM-visualizer/projectm.git
synced 2026-03-11 09:55:23 +00:00
click through the faces (doesn't really do anything tho)
git-svn-id: https://projectm.svn.sourceforge.net/svnroot/projectm/trunk@651 6778bc44-b910-0410-a7a0-be141de4315d
This commit is contained in:
@ -1,24 +1,78 @@
|
||||
#include "QPlaylistModel.hpp"
|
||||
#include <QIcon>
|
||||
|
||||
QPlaylistModel::QPlaylistModel(projectM & _projectM, QObject * parent):
|
||||
QAbstractTableModel(parent), m_projectM(_projectM) {
|
||||
m_ratings = QVector<int>(rowCount(), 3);
|
||||
}
|
||||
|
||||
|
||||
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));
|
||||
return true;
|
||||
}
|
||||
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::data ( const QModelIndex & index, int role = Qt::DisplayRole ) const {
|
||||
|
||||
if (role == Qt::DisplayRole)
|
||||
return QVariant(QString(m_projectM.getPresetName(index.row()).c_str()));
|
||||
else if (role == QPlaylistModel::URLInfoRole)
|
||||
return QVariant(QString(m_projectM.getPresetURL(index.row()).c_str()));
|
||||
return QVariant();
|
||||
switch (role) {
|
||||
case Qt::DisplayRole:
|
||||
if (index.column() == 0)
|
||||
return QVariant(QString(m_projectM.getPresetName(index.row()).c_str()));
|
||||
else
|
||||
return ratingToIcon(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()]);
|
||||
|
||||
case QPlaylistModel::URLInfoRole:
|
||||
return QVariant(QString(m_projectM.getPresetURL(index.row()).c_str()));
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
}
|
||||
|
||||
QVariant QPlaylistModel::headerData ( int section, Qt::Orientation orientation, int role) const {
|
||||
|
||||
if ((section == 0) && (role == Qt::DisplayRole))
|
||||
// if ((section == 0) && (role == Qt::SizeHintRole)) {
|
||||
// return QVariant(200);
|
||||
// } else if ((section == 1) && (role == Qt::SizeHintRole)) {
|
||||
// return QVariant(50);
|
||||
if ((section == 0) && (role == Qt::DisplayRole))
|
||||
return QString(tr("Preset"));
|
||||
else if ((section == 1) && (role == Qt::DisplayRole))
|
||||
return QString(tr("Rating"));
|
||||
else
|
||||
return QAbstractTableModel::headerData(section, orientation, role);
|
||||
}
|
||||
@ -32,14 +86,15 @@ int QPlaylistModel::columnCount ( const QModelIndex & parent = QModelIndex() ) c
|
||||
|
||||
// eventually add ratings here so size should be 2
|
||||
if (rowCount() > 0)
|
||||
return 1;
|
||||
return 2;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
void QPlaylistModel::appendRow (const QString & presetURL, const QString & presetName) {
|
||||
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();
|
||||
}
|
||||
|
||||
@ -47,11 +102,13 @@ void QPlaylistModel::appendRow (const QString & presetURL, const QString & prese
|
||||
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);
|
||||
m_projectM.clearPlaylist();
|
||||
m_ratings.clear();
|
||||
endRemoveRows();
|
||||
}
|
||||
|
||||
@ -26,6 +26,7 @@
|
||||
#include "libprojectM/projectM.hpp"
|
||||
|
||||
#include <QAbstractTableModel>
|
||||
#include <QVector>
|
||||
|
||||
class QPlaylistModel : public QAbstractTableModel
|
||||
{
|
||||
@ -33,10 +34,12 @@
|
||||
|
||||
public:
|
||||
static const int URLInfoRole = 1000;
|
||||
static const int RatingRole = 1001;
|
||||
QPlaylistModel(projectM & _projectM, QObject * parent = 0);
|
||||
~QPlaylistModel() { }
|
||||
bool setData(const QModelIndex & index, const QVariant & value, int role=Qt::EditRole);
|
||||
|
||||
void appendRow (const QString & presetURL, const QString & presetName);
|
||||
void appendRow (const QString & presetURL, const QString & presetName, int rating = 3);
|
||||
void removeRow (int index);
|
||||
QVariant headerData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
|
||||
|
||||
@ -48,7 +51,8 @@ int columnCount ( const QModelIndex & parent) const ;
|
||||
|
||||
|
||||
private:
|
||||
QVariant ratingToIcon(int rating) const;
|
||||
projectM & m_projectM;
|
||||
|
||||
QVector<int> m_ratings;
|
||||
};
|
||||
#endif
|
||||
|
||||
@ -48,10 +48,7 @@ QProjectM_MainWindow::QProjectM_MainWindow(const std::string & config_file)
|
||||
|
||||
connect(m_QProjectMWidget, SIGNAL(projectM_Initialized()), this, SLOT(postProjectM_Initialize()));
|
||||
|
||||
ui.tableView->setVerticalHeader(0);
|
||||
|
||||
// ui.tableView->setModel(playlistModel);
|
||||
|
||||
m_QProjectMWidget->makeCurrent();
|
||||
m_QProjectMWidget->setFocus();
|
||||
|
||||
@ -107,6 +104,17 @@ void QProjectM_MainWindow::postProjectM_Initialize() {
|
||||
connect(ui.tableView, SIGNAL(activated(const QModelIndex &)),
|
||||
this, SLOT(selectPlaylistItem(const QModelIndex &)));
|
||||
|
||||
connect(ui.tableView, SIGNAL(clicked(const QModelIndex &)),
|
||||
this, SLOT(changeRating(const QModelIndex &)));
|
||||
|
||||
}
|
||||
|
||||
void QProjectM_MainWindow::changeRating(const QModelIndex & index) {
|
||||
if (index.column() == 0)
|
||||
return;
|
||||
|
||||
playlistModel->setData
|
||||
(index, (playlistModel->data(index, QPlaylistModel::RatingRole).toInt()+1) % 6, QPlaylistModel::RatingRole);
|
||||
}
|
||||
|
||||
void QProjectM_MainWindow::keyReleaseEvent ( QKeyEvent * e ) {
|
||||
@ -198,7 +206,7 @@ void QProjectM_MainWindow::open()
|
||||
//playlistModel->setHeaderData(0, Qt::Horizontal, tr("Preset"));//, Qt::DisplayRole);
|
||||
}
|
||||
|
||||
|
||||
//void QAbstractItemView::clicked ( const QModelIndex & index ) [signal]
|
||||
void QProjectM_MainWindow::refreshPlaylist() {
|
||||
|
||||
StringPairVector * stringPairs = new StringPairVector();
|
||||
@ -211,23 +219,28 @@ void QProjectM_MainWindow::refreshPlaylist() {
|
||||
}
|
||||
historyHash.insert(QString(), stringPairs);
|
||||
|
||||
|
||||
QHeaderView * hHeader = new QHeaderView(Qt::Horizontal, this);
|
||||
QHeaderView * vHeader = new QHeaderView(Qt::Vertical, this);
|
||||
|
||||
//hHeader->
|
||||
hHeader->setClickable(false);
|
||||
hHeader->setSortIndicatorShown(false);
|
||||
//hHeader->setSortIndicator(1, Qt::AscendingOrder);
|
||||
hHeader->setStretchLastSection(true);
|
||||
|
||||
hHeader->setStretchLastSection(false);
|
||||
|
||||
ui.tableView->setVerticalHeader(vHeader);
|
||||
ui.tableView->setHorizontalHeader(hHeader);
|
||||
|
||||
hHeader->resizeSection(0, 200);
|
||||
hHeader->setResizeMode(0, QHeaderView::Stretch);
|
||||
hHeader->setResizeMode(1, QHeaderView::Fixed);
|
||||
hHeader->resizeSection(1, 25);
|
||||
|
||||
|
||||
// playlistModel->setHeaderData(0, Qt::Horizontal, tr("Preset"));//, Qt::DisplayRole);
|
||||
|
||||
vHeader->hide();
|
||||
|
||||
//playlistModel->setHeaderData(0, Qt::Vertical, 1000, Qt::SizeHintRole);
|
||||
// playlistModel->setHeaderData(0, Qt::Horizontal, 200, Qt::SizeHintRole);
|
||||
//playlistModel->setHeaderData(1, Qt::Horizontal, tr("Rating"));//, Qt::DisplayRole);
|
||||
//playlistModel->setHeaderData(2, Qt::Horizontal, tr("Preset"));//, Qt::DisplayRole);
|
||||
|
||||
|
||||
@ -224,6 +224,8 @@ private slots:
|
||||
void postProjectM_Initialize();
|
||||
void updatePlaylistSelection(bool hardCut, unsigned int index);
|
||||
void selectPlaylistItem(const QModelIndex & index);
|
||||
void changeRating(const QModelIndex & index);
|
||||
|
||||
void updateFilteredPlaylist(const QString & text);
|
||||
|
||||
private:
|
||||
|
||||
@ -1,5 +1,11 @@
|
||||
<RCC>
|
||||
<qresource prefix="/" >
|
||||
<file>images/icons/face0.png</file>
|
||||
<file>images/icons/face1.png</file>
|
||||
<file>images/icons/face2.png</file>
|
||||
<file>images/icons/face3.png</file>
|
||||
<file>images/icons/face4.png</file>
|
||||
<file>images/icons/face5.png</file>
|
||||
<file>images/icons/hi16-action-projectm_add_playlist.png</file>
|
||||
<file>images/icons/hi16-action-projectm_lock.png</file>
|
||||
<file>images/icons/hi16-action-projectm_playlist_clear.png</file>
|
||||
|
||||
Reference in New Issue
Block a user