1
0
mirror of https://github.com/clementine-player/Clementine synced 2025-01-31 03:27:40 +01:00

Update the track slider popup delta time when the track position changes.

This commit is contained in:
David Sansome 2011-02-21 22:25:04 +00:00
parent 107b7b54f9
commit a39cccd059
3 changed files with 22 additions and 5 deletions

View File

@ -422,6 +422,7 @@ set(HEADERS
widgets/stretchheaderview.h
widgets/trackslider.h
widgets/tracksliderpopup.h
widgets/tracksliderslider.h
widgets/widgetfadehelper.h
)

View File

@ -26,9 +26,12 @@
TrackSliderSlider::TrackSliderSlider(QWidget* parent)
: QSlider(parent),
popup_(new TrackSliderPopup(window()))
popup_(new TrackSliderPopup(window())),
mouse_hover_seconds_(0)
{
setMouseTracking(true);
connect(this, SIGNAL(valueChanged(int)), SLOT(UpdateDeltaTime()));
}
void TrackSliderSlider::mousePressEvent(QMouseEvent* e) {
@ -71,13 +74,12 @@ void TrackSliderSlider::mouseMoveEvent(QMouseEvent* e) {
int slider_min = gr.x();
int slider_max = gr.right() - slider_length + 1;
int seconds = QStyle::sliderValueFromPosition(
mouse_hover_seconds_ = QStyle::sliderValueFromPosition(
minimum(), maximum(), e->x() - slider_length/2 - slider_min + 1,
slider_max - slider_min);
int delta_seconds = seconds - value();
popup_->SetText(Utilities::PrettyTime(seconds));
popup_->SetSmallText(Utilities::PrettyTimeDelta(delta_seconds));
popup_->SetText(Utilities::PrettyTime(mouse_hover_seconds_));
UpdateDeltaTime();
popup_->SetPopupPosition(mapTo(window(), QPoint(
e->x(), rect().center().y())));
}
@ -93,3 +95,10 @@ void TrackSliderSlider::leaveEvent(QEvent* e) {
QSlider::leaveEvent(e);
popup_->hide();
}
void TrackSliderSlider::UpdateDeltaTime() {
if (popup_->isVisible()) {
int delta_seconds = mouse_hover_seconds_ - value();
popup_->SetSmallText(Utilities::PrettyTimeDelta(delta_seconds));
}
}

View File

@ -24,6 +24,8 @@ class TrackSliderPopup;
// It's the slider inside the TrackSliderSlider
class TrackSliderSlider : public QSlider {
Q_OBJECT
public:
TrackSliderSlider(QWidget* parent = 0);
@ -34,8 +36,13 @@ protected:
void enterEvent(QEvent*);
void leaveEvent(QEvent*);
private slots:
void UpdateDeltaTime();
private:
TrackSliderPopup* popup_;
int mouse_hover_seconds_;
};
#endif // TRACKSLIDERSLIDER_H