UI: Make T-Bar unclickable

The T-Bar should only be draggable and not act on clicks.
This commit is contained in:
gxalpha
2023-02-23 19:37:03 +01:00
committed by Ryan Foster
parent 0fe28e9ceb
commit 78d195a5df
3 changed files with 58 additions and 1 deletions
+39
View File
@@ -94,3 +94,42 @@ QAccessible::Role VolumeAccessibleInterface::role() const
{
return QAccessible::Role::Slider;
}
void SliderIgnoreClick::mousePressEvent(QMouseEvent *event)
{
QStyleOptionSlider styleOption;
initStyleOption(&styleOption);
QRect handle = style()->subControlRect(QStyle::CC_Slider, &styleOption,
QStyle::SC_SliderHandle, this);
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
QPointF pointExact = event->position();
#endif
if (handle.contains(
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
QPoint(pointExact.x(), pointExact.y())
#else
// Ubuntu 20.04. Sigh.
QPoint(event->x(), event->y())
#endif
)) {
SliderIgnoreScroll::mousePressEvent(event);
dragging = true;
} else {
event->accept();
}
}
void SliderIgnoreClick::mouseReleaseEvent(QMouseEvent *event)
{
dragging = false;
SliderIgnoreScroll::mouseReleaseEvent(event);
}
void SliderIgnoreClick::mouseMoveEvent(QMouseEvent *event)
{
if (dragging) {
SliderIgnoreScroll::mouseMoveEvent(event);
} else {
event->accept();
}
}
+18
View File
@@ -5,6 +5,7 @@
#include <QInputEvent>
#include <QtCore/QObject>
#include <QAccessibleWidget>
#include <QStyleOptionSlider>
class SliderIgnoreScroll : public QSlider {
Q_OBJECT
@@ -49,3 +50,20 @@ protected:
virtual QAccessible::Role role() const override;
virtual QString text(QAccessible::Text t) const override;
};
class SliderIgnoreClick : public SliderIgnoreScroll {
public:
inline SliderIgnoreClick(Qt::Orientation orientation,
QWidget *parent = nullptr)
: SliderIgnoreScroll(orientation, parent)
{
}
protected:
virtual void mousePressEvent(QMouseEvent *event) override;
virtual void mouseReleaseEvent(QMouseEvent *event) override;
virtual void mouseMoveEvent(QMouseEvent *event) override;
private:
bool dragging = false;
};
+1 -1
View File
@@ -797,7 +797,7 @@ void OBSBasic::CreateProgramOptions()
mainButtonLayout->addWidget(transitionButton);
mainButtonLayout->addWidget(configTransitions);
tBar = new SliderIgnoreScroll(Qt::Horizontal);
tBar = new SliderIgnoreClick(Qt::Horizontal);
tBar->setMinimum(0);
tBar->setMaximum(T_BAR_PRECISION - 1);