2018-08-23 20:43:44 -05:00
|
|
|
#include "slider-absoluteset-style.hpp"
|
|
|
|
#include "media-slider.hpp"
|
|
|
|
#include <QStyleFactory>
|
|
|
|
|
2020-09-05 23:06:47 -05:00
|
|
|
MediaSlider::MediaSlider(QWidget *parent) : SliderIgnoreScroll(parent)
|
2018-08-23 20:43:44 -05:00
|
|
|
{
|
2022-06-11 13:11:27 -05:00
|
|
|
installEventFilter(this);
|
2018-08-23 20:43:44 -05:00
|
|
|
setMouseTracking(true);
|
|
|
|
|
|
|
|
QString styleName = style()->objectName();
|
|
|
|
QStyle *style;
|
|
|
|
style = QStyleFactory::create(styleName);
|
|
|
|
if (!style) {
|
|
|
|
style = new SliderAbsoluteSetStyle();
|
|
|
|
} else {
|
|
|
|
style = new SliderAbsoluteSetStyle(style);
|
|
|
|
}
|
|
|
|
|
|
|
|
style->setParent(this);
|
|
|
|
this->setStyle(style);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MediaSlider::mouseMoveEvent(QMouseEvent *event)
|
|
|
|
{
|
2022-07-19 16:12:17 +02:00
|
|
|
int val = minimum() +
|
|
|
|
((maximum() - minimum()) * event->pos().x()) / width();
|
2018-08-23 20:43:44 -05:00
|
|
|
|
|
|
|
if (val > maximum())
|
|
|
|
val = maximum();
|
|
|
|
else if (val < minimum())
|
|
|
|
val = minimum();
|
|
|
|
|
|
|
|
emit mediaSliderHovered(val);
|
|
|
|
event->accept();
|
|
|
|
QSlider::mouseMoveEvent(event);
|
|
|
|
}
|
2022-06-11 13:11:27 -05:00
|
|
|
|
|
|
|
bool MediaSlider::eventFilter(QObject *obj, QEvent *event)
|
|
|
|
{
|
|
|
|
if (event->type() == QEvent::KeyPress) {
|
|
|
|
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
|
|
|
|
|
|
|
|
if (keyEvent->key() == Qt::Key_Up ||
|
|
|
|
keyEvent->key() == Qt::Key_Down) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (event->type() == QEvent::Wheel)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return QSlider::eventFilter(obj, event);
|
|
|
|
}
|