mirror of
https://github.com/clementine-player/Clementine
synced 2024-12-17 03:45:56 +01:00
Cache the playlist tree pixmap while the user is dragging stuff over it, making the repeated repaints less expensive.
This commit is contained in:
parent
c701c49004
commit
dafedbf00c
@ -411,6 +411,7 @@ void PlaylistView::scrollContentsBy(int dx, int dy) {
|
|||||||
if (dx) {
|
if (dx) {
|
||||||
InvalidateCachedCurrentPixmap();
|
InvalidateCachedCurrentPixmap();
|
||||||
}
|
}
|
||||||
|
cached_tree_ = QPixmap();
|
||||||
|
|
||||||
QTreeView::scrollContentsBy(dx, dy);
|
QTreeView::scrollContentsBy(dx, dy);
|
||||||
|
|
||||||
@ -456,11 +457,28 @@ void PlaylistView::JumpToCurrentlyPlayingTrack() {
|
|||||||
|
|
||||||
void PlaylistView::paintEvent(QPaintEvent* event) {
|
void PlaylistView::paintEvent(QPaintEvent* event) {
|
||||||
// Reimplemented to draw the drop indicator
|
// Reimplemented to draw the drop indicator
|
||||||
QPainter p(viewport());
|
// When the user is dragging some stuff over the playlist paintEvent gets
|
||||||
drawTree(&p, event->region());
|
// called for the entire viewport every time the user moves the mouse.
|
||||||
|
// The drawTree is kinda expensive, so we cache the result and draw from the
|
||||||
|
// cache while the user is dragging. The cached pixmap gets invalidated in
|
||||||
|
// dragLeaveEvent, dropEvent and scrollContentsBy.
|
||||||
|
|
||||||
if (drop_indicator_row_ == -1)
|
QPainter p(viewport());
|
||||||
|
|
||||||
|
if (drop_indicator_row_ != -1) {
|
||||||
|
if (cached_tree_.isNull()) {
|
||||||
|
cached_tree_ = QPixmap(size());
|
||||||
|
cached_tree_.fill(Qt::transparent);
|
||||||
|
|
||||||
|
QPainter cache_painter(&cached_tree_);
|
||||||
|
drawTree(&cache_painter, event->region());
|
||||||
|
}
|
||||||
|
|
||||||
|
p.drawPixmap(0, 0, cached_tree_);
|
||||||
|
} else {
|
||||||
|
drawTree(&p, event->region());
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Find the y position of the drop indicator
|
// Find the y position of the drop indicator
|
||||||
QModelIndex drop_index = model()->index(drop_indicator_row_, 0);
|
QModelIndex drop_index = model()->index(drop_indicator_row_, 0);
|
||||||
@ -516,12 +534,19 @@ void PlaylistView::dragMoveEvent(QDragMoveEvent *event) {
|
|||||||
drop_indicator_row_ = index.isValid() ? index.row() : 0;
|
drop_indicator_row_ = index.isValid() ? index.row() : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PlaylistView::dragEnterEvent(QDragEnterEvent *event) {
|
||||||
|
QTreeView::dragEnterEvent(event);
|
||||||
|
cached_tree_ = QPixmap();
|
||||||
|
}
|
||||||
|
|
||||||
void PlaylistView::dragLeaveEvent(QDragLeaveEvent *event) {
|
void PlaylistView::dragLeaveEvent(QDragLeaveEvent *event) {
|
||||||
QTreeView::dragLeaveEvent(event);
|
QTreeView::dragLeaveEvent(event);
|
||||||
|
cached_tree_ = QPixmap();
|
||||||
drop_indicator_row_ = -1;
|
drop_indicator_row_ = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlaylistView::dropEvent(QDropEvent *event) {
|
void PlaylistView::dropEvent(QDropEvent *event) {
|
||||||
QTreeView::dropEvent(event);
|
QTreeView::dropEvent(event);
|
||||||
|
cached_tree_ = QPixmap();
|
||||||
drop_indicator_row_ = -1;
|
drop_indicator_row_ = -1;
|
||||||
}
|
}
|
||||||
|
@ -61,6 +61,7 @@ class PlaylistView : public QTreeView {
|
|||||||
void scrollContentsBy(int dx, int dy);
|
void scrollContentsBy(int dx, int dy);
|
||||||
void paintEvent(QPaintEvent *event);
|
void paintEvent(QPaintEvent *event);
|
||||||
void dragMoveEvent(QDragMoveEvent *event);
|
void dragMoveEvent(QDragMoveEvent *event);
|
||||||
|
void dragEnterEvent(QDragEnterEvent *event);
|
||||||
void dragLeaveEvent(QDragLeaveEvent *event);
|
void dragLeaveEvent(QDragLeaveEvent *event);
|
||||||
void dropEvent(QDropEvent *event);
|
void dropEvent(QDropEvent *event);
|
||||||
|
|
||||||
@ -112,6 +113,7 @@ class PlaylistView : public QTreeView {
|
|||||||
QRect cached_current_row_rect_;
|
QRect cached_current_row_rect_;
|
||||||
int cached_current_row_row_;
|
int cached_current_row_row_;
|
||||||
|
|
||||||
|
QPixmap cached_tree_;
|
||||||
int drop_indicator_row_;
|
int drop_indicator_row_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user