Change the queue manager to use a QTreeView instead of QListView so it doesn't repaint on drop.

This commit is contained in:
David Sansome 2010-07-11 21:27:36 +00:00
parent 9bc8d914af
commit 4bf9ee0a8e
6 changed files with 39 additions and 39 deletions

View File

@ -40,16 +40,16 @@ const float QueuedItemDelegate::kQueueOpacityLowerBound = 0.4;
const int PlaylistDelegateBase::kMinHeight = 19;
QueuedItemDelegate::QueuedItemDelegate(QObject *parent)
: QStyledItemDelegate(parent)
QueuedItemDelegate::QueuedItemDelegate(QObject *parent, int indicator_column)
: QStyledItemDelegate(parent),
indicator_column_(indicator_column)
{
}
void QueuedItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const {
QStyledItemDelegate::paint(painter, option, index);
if (index.column() == Playlist::Column_Title ||
index.column() == Queue::Column_CombinedArtistTitle) {
if (index.column() == indicator_column_) {
const int queue_pos = index.data(Playlist::Role_QueuePosition).toInt();
if (queue_pos != -1) {
float opacity = kQueueOpacitySteps - qMin(kQueueOpacitySteps, queue_pos);
@ -103,8 +103,7 @@ void QueuedItemDelegate::DrawBox(
}
int QueuedItemDelegate::queue_indicator_size(const QModelIndex& index) const {
if (index.column() == Playlist::Column_Title ||
index.column() == Queue::Column_CombinedArtistTitle) {
if (index.column() == indicator_column_) {
const int queue_pos = index.data(Playlist::Role_QueuePosition).toInt();
if (queue_pos != -1) {
return kQueueBoxLength + kQueueBoxBorder*2;

View File

@ -27,7 +27,7 @@
class QueuedItemDelegate : public QStyledItemDelegate {
public:
QueuedItemDelegate(QObject* parent);
QueuedItemDelegate(QObject* parent, int indicator_column = Playlist::Column_Title);
void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
void DrawBox(QPainter* painter, const QRect& line_rect,
const QFont& font, const QString& text, int width = -1) const;
@ -42,6 +42,8 @@ private:
static const QRgb kQueueBoxGradientColor2;
static const int kQueueOpacitySteps;
static const float kQueueOpacityLowerBound;
int indicator_column_;
};
class PlaylistDelegateBase : public QueuedItemDelegate {

View File

@ -68,14 +68,12 @@ void Queue::setSourceModel(QAbstractItemModel* source_model) {
void Queue::SourceDataChanged(const QModelIndex& top_left,
const QModelIndex& bottom_right) {
const int last_col = ColumnCount - 1;
for (int row = top_left.row() ; row <= bottom_right.row() ; ++row) {
QModelIndex proxy_index = mapFromSource(sourceModel()->index(row, 0));
if (!proxy_index.isValid())
continue;
emit dataChanged(proxy_index, proxy_index.sibling(proxy_index.row(), last_col));
emit dataChanged(proxy_index, proxy_index);
}
}
@ -105,8 +103,8 @@ int Queue::rowCount(const QModelIndex &parent) const {
return source_indexes_.count();
}
int Queue::columnCount(const QModelIndex &parent) const {
return ColumnCount;
int Queue::columnCount(const QModelIndex&) const {
return 1;
}
QVariant Queue::data(const QModelIndex& proxy_index, int role) const {
@ -116,19 +114,17 @@ QVariant Queue::data(const QModelIndex& proxy_index, int role) const {
case Playlist::Role_QueuePosition:
return proxy_index.row();
case Qt::DisplayRole:
if (proxy_index.column() == Column_CombinedArtistTitle) {
const QString artist = source_index.sibling(source_index.row(), Playlist::Column_Artist).data().toString();
const QString title = source_index.sibling(source_index.row(), Playlist::Column_Title).data().toString();
case Qt::DisplayRole: {
const QString artist = source_index.sibling(source_index.row(), Playlist::Column_Artist).data().toString();
const QString title = source_index.sibling(source_index.row(), Playlist::Column_Title).data().toString();
if (artist.isEmpty())
return title;
return artist + " - " + title;
}
// fallthrough
if (artist.isEmpty())
return title;
return artist + " - " + title;
}
default:
return source_index.data(role);
return QVariant();
}
}
@ -231,7 +227,7 @@ QMimeData* Queue::mimeData(const QModelIndexList& indexes) const {
QList<int> rows;
foreach (const QModelIndex& index, indexes) {
if (index.column() != Column_CombinedArtistTitle)
if (index.column() != 0)
continue;
rows << index.row();
@ -280,12 +276,14 @@ bool Queue::dropMimeData(const QMimeData* data, Qt::DropAction action, int row,
source_indexes << source_index;
}
const int insert_point = row == -1 ? source_indexes_.count() : row;
beginInsertRows(QModelIndex(), insert_point, insert_point + source_indexes.count() - 1);
for (int i=0 ; i<source_indexes.count() ; ++i) {
source_indexes_.insert(insert_point + i, source_indexes[i]);
if (!source_indexes.isEmpty()) {
const int insert_point = row == -1 ? source_indexes_.count() : row;
beginInsertRows(QModelIndex(), insert_point, insert_point + source_indexes.count() - 1);
for (int i=0 ; i<source_indexes.count() ; ++i) {
source_indexes_.insert(insert_point + i, source_indexes[i]);
}
endInsertRows();
}
endInsertRows();
}
return true;
@ -318,3 +316,7 @@ int Queue::TakeNext() {
return ret;
}
QVariant Queue::headerData(int section, Qt::Orientation orientation, int role) const {
return QVariant();
}

View File

@ -27,12 +27,6 @@ class Queue : public QAbstractProxyModel {
public:
Queue(QObject* parent = 0);
enum Columns {
Column_CombinedArtistTitle = Playlist::ColumnCount,
ColumnCount
};
static const char* kRowsMimetype;
// Query the queue
@ -59,6 +53,7 @@ public:
int rowCount(const QModelIndex &parent = QModelIndex()) const;
int columnCount(const QModelIndex &parent = QModelIndex()) const;
QVariant data(const QModelIndex& proxy_index, int role) const;
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
QStringList mimeTypes() const;
Qt::DropActions supportedDropActions() const;
QMimeData* mimeData(const QModelIndexList& indexes) const;

View File

@ -29,7 +29,7 @@ QueueManager::QueueManager(QWidget *parent)
current_playlist_(NULL)
{
ui_->setupUi(this);
ui_->list->setItemDelegate(new QueuedItemDelegate(this));
ui_->list->setItemDelegate(new QueuedItemDelegate(this, 0));
// Set icons on buttons
ui_->move_down->setIcon(IconLoader::Load("go-down"));
@ -76,7 +76,6 @@ void QueueManager::CurrentPlaylistChanged(Playlist* playlist) {
this, SLOT(PlaylistDestroyed()));
ui_->list->setModel(current_playlist_->queue());
ui_->list->setModelColumn(Queue::Column_CombinedArtistTitle);
connect(ui_->list->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)),
SLOT(UpdateButtonState()));

View File

@ -21,7 +21,7 @@
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QListView" name="list">
<widget class="QTreeView" name="list">
<property name="acceptDrops">
<bool>true</bool>
</property>
@ -46,9 +46,12 @@
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
<property name="uniformItemSizes">
<bool>true</bool>
<property name="rootIsDecorated">
<bool>false</bool>
</property>
<attribute name="headerVisible">
<bool>false</bool>
</attribute>
</widget>
</item>
<item>