Disable trackslider popup on macos

This commit is contained in:
Jonas Kvinge 2019-07-30 22:11:09 +02:00
parent d34a323a81
commit 02cda47c28
2 changed files with 25 additions and 5 deletions

View File

@ -32,18 +32,24 @@
#include "core/timeconstants.h"
#include "core/utilities.h"
#include "tracksliderpopup.h"
#ifndef Q_OS_MACOS
# include "tracksliderpopup.h"
#endif
#include "tracksliderslider.h"
TrackSliderSlider::TrackSliderSlider(QWidget* parent)
: QSlider(parent),
#ifndef Q_OS_MACOS
popup_(new TrackSliderPopup(window())),
#endif
mouse_hover_seconds_(0) {
setMouseTracking(true);
#ifndef Q_OS_MACOS
popup_->hide();
connect(this, SIGNAL(valueChanged(int)), SLOT(UpdateDeltaTime()));
#endif
}
void TrackSliderSlider::mousePressEvent(QMouseEvent* e) {
@ -94,9 +100,11 @@ void TrackSliderSlider::mouseMoveEvent(QMouseEvent* e) {
mouse_hover_seconds_ = QStyle::sliderValueFromPosition(minimum() / kMsecPerSec, maximum() / kMsecPerSec, e->x() - slider_length / 2 - slider_min + 1, slider_max - slider_min);
#ifndef Q_OS_MACOS
popup_->SetText(Utilities::PrettyTime(mouse_hover_seconds_));
UpdateDeltaTime();
popup_->SetPopupPosition(mapTo(window(), QPoint(e->x(), rect().center().y())));
#endif
}
void TrackSliderSlider::wheelEvent(QWheelEvent *e) {
@ -111,18 +119,22 @@ void TrackSliderSlider::wheelEvent(QWheelEvent *e) {
void TrackSliderSlider::enterEvent(QEvent* e) {
QSlider::enterEvent(e);
#ifndef Q_OS_MACOS
if (isEnabled()) {
popup_->show();
}
#endif
}
void TrackSliderSlider::leaveEvent(QEvent* e) {
QSlider::leaveEvent(e);
#ifndef Q_OS_MACOS
// On some (but not all) systems, displaying the TrackSliderPopup
// generates a leaveEvent. Ensure that this leaveEvent is genuine.
if (!geometry().contains(mapFromGlobal(QCursor::pos()))) {
popup_->hide();
}
#endif
}
void TrackSliderSlider::keyPressEvent(QKeyEvent* event) {
@ -139,9 +151,11 @@ void TrackSliderSlider::keyPressEvent(QKeyEvent* event) {
}
}
#ifndef Q_OS_MACOS
void TrackSliderSlider::UpdateDeltaTime() {
if (popup_->isVisible()) {
int delta_seconds = mouse_hover_seconds_ - (value() / kMsecPerSec);
popup_->SetSmallText(Utilities::PrettyTimeDelta(delta_seconds));
}
}
#endif

View File

@ -33,7 +33,9 @@ class QEvent;
class QKeyEvent;
class QMouseEvent;
class QWheelEvent;
#ifndef Q_OS_MACOS
class TrackSliderPopup;
#endif
// It's the slider inside the TrackSliderSlider
class TrackSliderSlider : public QSlider {
@ -42,7 +44,7 @@ class TrackSliderSlider : public QSlider {
public:
TrackSliderSlider(QWidget* parent = nullptr);
signals:
signals:
void SeekForward();
void SeekBackward();
void Previous();
@ -57,11 +59,15 @@ signals:
void leaveEvent(QEvent*);
void keyPressEvent(QKeyEvent* event);
private slots:
private slots:
#ifndef Q_OS_MACOS
void UpdateDeltaTime();
#endif
private:
private:
#ifndef Q_OS_MACOS
TrackSliderPopup* popup_;
#endif
int mouse_hover_seconds_;
};