1
0
mirror of https://github.com/clementine-player/Clementine synced 2025-01-19 04:50:16 +01:00

Use QBasicTimer for the playlist glow as well

This commit is contained in:
David Sansome 2010-04-28 11:09:57 +00:00
parent 29a623739b
commit 299783d097
2 changed files with 12 additions and 9 deletions

View File

@ -39,7 +39,6 @@ const int PlaylistView::kDropIndicatorGradientWidth = 5;
PlaylistView::PlaylistView(QWidget *parent)
: QTreeView(parent),
glow_enabled_(false),
glow_timer_(new QTimer(this)),
glow_intensity_step_(0),
inhibit_autoscroll_timer_(new QTimer(this)),
inhibit_autoscroll_(false),
@ -59,9 +58,6 @@ PlaylistView::PlaylistView(QWidget *parent)
inhibit_autoscroll_timer_->setSingleShot(true);
connect(inhibit_autoscroll_timer_, SIGNAL(timeout()), SLOT(InhibitAutoscrollTimeout()));
glow_timer_->setInterval(1500 / kGlowIntensitySteps);
connect(glow_timer_, SIGNAL(timeout()), SLOT(GlowIntensityChanged()));
setAlternatingRowColors(true);
}
@ -204,6 +200,11 @@ void PlaylistView::drawRow(QPainter* painter, const QStyleOptionViewItem& option
QTreeView::drawRow(painter, opt, index);
}
void PlaylistView::timerEvent(QTimerEvent* event) {
if (event->timerId() == glow_timer_.timerId())
GlowIntensityChanged();
}
void PlaylistView::GlowIntensityChanged() {
glow_intensity_step_ = (glow_intensity_step_ + 1) % (kGlowIntensitySteps * 2);
@ -212,23 +213,23 @@ void PlaylistView::GlowIntensityChanged() {
void PlaylistView::StopGlowing() {
glow_enabled_ = false;
glow_timer_->stop();
glow_timer_.stop();
glow_intensity_step_ = kGlowIntensitySteps;
}
void PlaylistView::StartGlowing() {
glow_enabled_ = true;
if (isVisible())
glow_timer_->start();
glow_timer_.start(1500 / kGlowIntensitySteps, this);
}
void PlaylistView::hideEvent(QHideEvent*) {
glow_timer_->stop();
glow_timer_.stop();
}
void PlaylistView::showEvent(QShowEvent*) {
if (glow_enabled_)
glow_timer_->start();
glow_timer_.start(1500 / kGlowIntensitySteps, this);
MaybeAutoscroll();
}

View File

@ -21,6 +21,7 @@
#include "library.h"
#include <QTreeView>
#include <QBasicTimer>
class RadioLoadingIndicator;
@ -53,6 +54,7 @@ class PlaylistView : public QTreeView {
protected:
void hideEvent(QHideEvent* event);
void showEvent(QShowEvent* event);
void timerEvent(QTimerEvent *event);
void mousePressEvent(QMouseEvent *event);
void scrollContentsBy(int dx, int dy);
void paintEvent(QPaintEvent *event);
@ -83,7 +85,7 @@ class PlaylistView : public QTreeView {
QModelIndex PrevEditableIndex(const QModelIndex& current);
bool glow_enabled_;
QTimer* glow_timer_;
QBasicTimer glow_timer_;
int glow_intensity_step_;
QModelIndex last_current_item_;
QRect last_glow_rect_;