slider: implemented value ladder

Allows finer control over value changes.
This commit is contained in:
itsmattkc
2020-06-14 03:56:18 +10:00
parent 49cf9f4458
commit 4c548bc6a5
10 changed files with 436 additions and 91 deletions
+3 -44
View File
@@ -57,66 +57,25 @@ SliderLabel::SliderLabel(QWidget *parent) :
void SliderLabel::mousePressEvent(QMouseEvent *e)
{
if (e->modifiers() & Qt::AltModifier) {
emit RequestReset();
} else {
#if defined(Q_OS_MAC)
CGAssociateMouseAndMouseCursorPosition(false);
CGDisplayHideCursor(kCGDirectMainDisplay);
CGGetLastMouseDelta(nullptr, nullptr);
#else
drag_start_ = QCursor::pos();
static_cast<QGuiApplication*>(QApplication::instance())->setOverrideCursor(Qt::BlankCursor);
#endif
emit drag_start();
dragging_ = true;
emit LabelPressed();
}
}
void SliderLabel::mouseMoveEvent(QMouseEvent *)
{
if (dragging_) {
int32_t x_mvmt, y_mvmt;
// Keep cursor in the same position
#if defined(Q_OS_MAC)
CGGetLastMouseDelta(&x_mvmt, &y_mvmt);
#else
QPoint current_pos = QCursor::pos();
x_mvmt = current_pos.x() - drag_start_.x();
y_mvmt = drag_start_.y() - current_pos.y();
QCursor::setPos(drag_start_);
#endif
emit dragged(x_mvmt + y_mvmt);
emit LabelMoved();
}
}
void SliderLabel::mouseReleaseEvent(QMouseEvent *)
{
if (dragging_) {
#if defined(Q_OS_MAC)
CGAssociateMouseAndMouseCursorPosition(true);
CGDisplayShowCursor(kCGDirectMainDisplay);
#else
static_cast<QGuiApplication*>(QApplication::instance())->restoreOverrideCursor();
#endif
emit drag_stop();
emit LabelReleased();
dragging_ = false;
}
}