From a39cccd05982c2ea9d00c4a73367d456a92c5a41 Mon Sep 17 00:00:00 2001 From: David Sansome Date: Mon, 21 Feb 2011 22:25:04 +0000 Subject: [PATCH] Update the track slider popup delta time when the track position changes. --- src/CMakeLists.txt | 1 + src/widgets/tracksliderslider.cpp | 19 ++++++++++++++----- src/widgets/tracksliderslider.h | 7 +++++++ 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a04dad315..795641171 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -422,6 +422,7 @@ set(HEADERS widgets/stretchheaderview.h widgets/trackslider.h widgets/tracksliderpopup.h + widgets/tracksliderslider.h widgets/widgetfadehelper.h ) diff --git a/src/widgets/tracksliderslider.cpp b/src/widgets/tracksliderslider.cpp index 316c222cb..7c6779624 100644 --- a/src/widgets/tracksliderslider.cpp +++ b/src/widgets/tracksliderslider.cpp @@ -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)); + } +} diff --git a/src/widgets/tracksliderslider.h b/src/widgets/tracksliderslider.h index 190449afd..decaf1816 100644 --- a/src/widgets/tracksliderslider.h +++ b/src/widgets/tracksliderslider.h @@ -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