Automatically scroll to the currently playing song whenever (it changes || the window is shown) && (the user hasn't done anything for 1 minute). Fixes issue #124
This commit is contained in:
parent
f10873e9b8
commit
0cd8f42ea5
|
@ -31,6 +31,7 @@
|
||||||
|
|
||||||
const char* PlaylistView::kSettingsGroup = "Playlist";
|
const char* PlaylistView::kSettingsGroup = "Playlist";
|
||||||
const int PlaylistView::kGlowIntensitySteps = 32;
|
const int PlaylistView::kGlowIntensitySteps = 32;
|
||||||
|
const int PlaylistView::kAutoscrollGraceTimeout = 60; // seconds
|
||||||
|
|
||||||
|
|
||||||
PlaylistView::PlaylistView(QWidget *parent)
|
PlaylistView::PlaylistView(QWidget *parent)
|
||||||
|
@ -38,6 +39,8 @@ PlaylistView::PlaylistView(QWidget *parent)
|
||||||
glow_enabled_(false),
|
glow_enabled_(false),
|
||||||
glow_timer_(new QTimer(this)),
|
glow_timer_(new QTimer(this)),
|
||||||
glow_intensity_step_(0),
|
glow_intensity_step_(0),
|
||||||
|
inhibit_autoscroll_timer_(new QTimer(this)),
|
||||||
|
inhibit_autoscroll_(false),
|
||||||
row_height_(-1),
|
row_height_(-1),
|
||||||
currenttrack_play_(":currenttrack_play.png"),
|
currenttrack_play_(":currenttrack_play.png"),
|
||||||
currenttrack_pause_(":currenttrack_pause.png")
|
currenttrack_pause_(":currenttrack_pause.png")
|
||||||
|
@ -48,6 +51,10 @@ PlaylistView::PlaylistView(QWidget *parent)
|
||||||
connect(header(), SIGNAL(sectionResized(int,int,int)), SLOT(SaveGeometry()));
|
connect(header(), SIGNAL(sectionResized(int,int,int)), SLOT(SaveGeometry()));
|
||||||
connect(header(), SIGNAL(sectionMoved(int,int,int)), SLOT(SaveGeometry()));
|
connect(header(), SIGNAL(sectionMoved(int,int,int)), SLOT(SaveGeometry()));
|
||||||
|
|
||||||
|
inhibit_autoscroll_timer_->setInterval(kAutoscrollGraceTimeout * 1000);
|
||||||
|
inhibit_autoscroll_timer_->setSingleShot(true);
|
||||||
|
connect(inhibit_autoscroll_timer_, SIGNAL(timeout()), SLOT(InhibitAutoscrollTimeout()));
|
||||||
|
|
||||||
glow_timer_->setInterval(1500 / kGlowIntensitySteps);
|
glow_timer_->setInterval(1500 / kGlowIntensitySteps);
|
||||||
connect(glow_timer_, SIGNAL(timeout()), SLOT(GlowIntensityChanged()));
|
connect(glow_timer_, SIGNAL(timeout()), SLOT(GlowIntensityChanged()));
|
||||||
|
|
||||||
|
@ -211,6 +218,7 @@ void PlaylistView::hideEvent(QHideEvent*) {
|
||||||
void PlaylistView::showEvent(QShowEvent*) {
|
void PlaylistView::showEvent(QShowEvent*) {
|
||||||
if (glow_enabled_)
|
if (glow_enabled_)
|
||||||
glow_timer_->start();
|
glow_timer_->start();
|
||||||
|
MaybeAutoscroll();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CompareSelectionRanges(const QItemSelectionRange& a, const QItemSelectionRange& b) {
|
bool CompareSelectionRanges(const QItemSelectionRange& a, const QItemSelectionRange& b) {
|
||||||
|
@ -320,3 +328,39 @@ void PlaylistView::closeEditor(QWidget* editor, QAbstractItemDelegate::EndEditHi
|
||||||
QTreeView::closeEditor(editor, hint);
|
QTreeView::closeEditor(editor, hint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PlaylistView::mousePressEvent(QMouseEvent *event) {
|
||||||
|
QTreeView::mousePressEvent(event);
|
||||||
|
inhibit_autoscroll_ = true;
|
||||||
|
inhibit_autoscroll_timer_->start();
|
||||||
|
}
|
||||||
|
|
||||||
|
void PlaylistView::scrollContentsBy(int dx, int dy) {
|
||||||
|
QTreeView::scrollContentsBy(dx, dy);
|
||||||
|
inhibit_autoscroll_ = true;
|
||||||
|
inhibit_autoscroll_timer_->start();
|
||||||
|
}
|
||||||
|
|
||||||
|
void PlaylistView::InhibitAutoscrollTimeout() {
|
||||||
|
// For 1 minute after the user clicks on or scrolls the playlist we promise
|
||||||
|
// not to automatically scroll the view to keep up with a track change.
|
||||||
|
inhibit_autoscroll_ = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PlaylistView::dataChanged(const QModelIndex&, const QModelIndex&) {
|
||||||
|
MaybeAutoscroll();
|
||||||
|
}
|
||||||
|
|
||||||
|
void PlaylistView::MaybeAutoscroll() {
|
||||||
|
Playlist* playlist = qobject_cast<Playlist*>(model());
|
||||||
|
Q_ASSERT(playlist);
|
||||||
|
|
||||||
|
if (inhibit_autoscroll_)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (playlist->current_index() == -1)
|
||||||
|
return;
|
||||||
|
|
||||||
|
QModelIndex current = playlist->index(playlist->current_index(), 0);
|
||||||
|
scrollTo(current, QAbstractItemView::PositionAtCenter);
|
||||||
|
}
|
||||||
|
|
|
@ -53,19 +53,27 @@ class PlaylistView : public QTreeView {
|
||||||
protected:
|
protected:
|
||||||
void hideEvent(QHideEvent* event);
|
void hideEvent(QHideEvent* event);
|
||||||
void showEvent(QShowEvent* event);
|
void showEvent(QShowEvent* event);
|
||||||
|
void mousePressEvent(QMouseEvent *event);
|
||||||
|
void scrollContentsBy(int dx, int dy);
|
||||||
|
|
||||||
|
protected slots:
|
||||||
|
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void LoadGeometry();
|
void LoadGeometry();
|
||||||
void SaveGeometry();
|
void SaveGeometry();
|
||||||
void GlowIntensityChanged();
|
void GlowIntensityChanged();
|
||||||
|
void InhibitAutoscrollTimeout();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void ReloadBarPixmaps();
|
void ReloadBarPixmaps();
|
||||||
QList<QPixmap> LoadBarPixmap(const QString& filename);
|
QList<QPixmap> LoadBarPixmap(const QString& filename);
|
||||||
|
void MaybeAutoscroll();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static const char* kSettingsGroup;
|
static const char* kSettingsGroup;
|
||||||
static const int kGlowIntensitySteps;
|
static const int kGlowIntensitySteps;
|
||||||
|
static const int kAutoscrollGraceTimeout;
|
||||||
|
|
||||||
QList<int> GetEditableColumns();
|
QList<int> GetEditableColumns();
|
||||||
QModelIndex NextEditableIndex(const QModelIndex& current);
|
QModelIndex NextEditableIndex(const QModelIndex& current);
|
||||||
|
@ -77,6 +85,9 @@ class PlaylistView : public QTreeView {
|
||||||
QModelIndex last_current_item_;
|
QModelIndex last_current_item_;
|
||||||
QRect last_glow_rect_;
|
QRect last_glow_rect_;
|
||||||
|
|
||||||
|
QTimer* inhibit_autoscroll_timer_;
|
||||||
|
bool inhibit_autoscroll_;
|
||||||
|
|
||||||
int row_height_; // Used to invalidate the currenttrack_bar pixmaps
|
int row_height_; // Used to invalidate the currenttrack_bar pixmaps
|
||||||
QList<QPixmap> currenttrack_bar_left_;
|
QList<QPixmap> currenttrack_bar_left_;
|
||||||
QList<QPixmap> currenttrack_bar_mid_;
|
QList<QPixmap> currenttrack_bar_mid_;
|
||||||
|
|
Loading…
Reference in New Issue