initial scrollwheel functionality, simplified position tracking slightly
parent
fd81de5040
commit
7b566929a2
2
notes
2
notes
|
@ -36,7 +36,7 @@ TODO {
|
|||
- shift+drag fine tuning
|
||||
- alt+drag to move reference point without changing value
|
||||
- global switch between horizontal and vertical
|
||||
scrollwheel support!
|
||||
> scrollwheel support!
|
||||
}
|
||||
|
||||
ping-pong for delay
|
||||
|
|
|
@ -118,12 +118,10 @@ void KnobGadget::paint(QPainter* painter, const QStyleOptionGraphicsItem*, QWidg
|
|||
}
|
||||
|
||||
namespace { // interaction tracking vars
|
||||
QPoint lastPos;
|
||||
int acc = 0;
|
||||
double trackVal;
|
||||
|
||||
inline double stepRound(double v, double s) { return std::round(v / s) * s; }
|
||||
//
|
||||
}
|
||||
|
||||
void KnobGadget::mousePressEvent(QGraphicsSceneMouseEvent* e) {
|
||||
|
@ -137,7 +135,6 @@ void KnobGadget::mousePressEvent(QGraphicsSceneMouseEvent* e) {
|
|||
else if (step > 0.0)
|
||||
trackVal = stepRound(trackVal, step);
|
||||
fSet(trackVal);
|
||||
lastPos = e->screenPos();
|
||||
} else if (e->button() == Qt::RightButton) {
|
||||
fSet(defaultVal);
|
||||
e->accept();
|
||||
|
@ -154,10 +151,10 @@ void KnobGadget::mouseReleaseEvent(QGraphicsSceneMouseEvent* e) {
|
|||
|
||||
void KnobGadget::mouseMoveEvent(QGraphicsSceneMouseEvent* e) {
|
||||
if (highlighted) {
|
||||
auto curPos = e->screenPos();
|
||||
auto curPos = e->pos().toPoint();
|
||||
auto lastPos = e->lastPos().toPoint();
|
||||
if (UIConfig::verticalKnobs) acc -= curPos.y() - lastPos.y();
|
||||
else acc += curPos.x() - lastPos.x();
|
||||
lastPos = curPos;
|
||||
|
||||
// handle accumulation math
|
||||
int sgn = acc < 0 ? -1 : 1;
|
||||
|
@ -170,7 +167,7 @@ void KnobGadget::mouseMoveEvent(QGraphicsSceneMouseEvent* e) {
|
|||
else if (mod.testFlag(Qt::ShiftModifier) && subStep > 0) {
|
||||
trackVal = stepRound(trackVal + subStep*diff, subStep);
|
||||
fSet(std::clamp(trackVal, min, max));
|
||||
} else {
|
||||
} else if (step > 0) {
|
||||
trackVal = stepRound(trackVal + step*diff, step);
|
||||
fSet(std::clamp(trackVal, min, max));
|
||||
}
|
||||
|
@ -178,6 +175,20 @@ void KnobGadget::mouseMoveEvent(QGraphicsSceneMouseEvent* e) {
|
|||
update();
|
||||
}
|
||||
|
||||
void KnobGadget::wheelEvent(QGraphicsSceneWheelEvent* e) {
|
||||
if (highlighted) return;
|
||||
auto d = e->delta()/120;
|
||||
auto mod = e->modifiers();
|
||||
if (mod.testFlag(Qt::ShiftModifier) && subStep > 0) {
|
||||
fSet(std::clamp(stepRound(get()+subStep*d, subStep), min, max));
|
||||
e->accept();
|
||||
} else if (step > 0) {
|
||||
fSet(std::clamp(stepRound(get()+step*d, step), min, max));
|
||||
e->accept();
|
||||
}
|
||||
update();
|
||||
}
|
||||
|
||||
void KnobGadget::contextMenuEvent(QGraphicsSceneContextMenuEvent* e) {
|
||||
e->accept();
|
||||
}
|
||||
|
|
|
@ -13,7 +13,6 @@ namespace Xybrid::UI {
|
|||
Q_OBJECT
|
||||
|
||||
bool highlighted = false;
|
||||
//double startVal;
|
||||
double lastVal = 0.0;
|
||||
bool dirty = true;
|
||||
|
||||
|
@ -53,6 +52,7 @@ namespace Xybrid::UI {
|
|||
void mousePressEvent(QGraphicsSceneMouseEvent*) override;
|
||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent*) override;
|
||||
void mouseMoveEvent(QGraphicsSceneMouseEvent*) override;
|
||||
void wheelEvent(QGraphicsSceneWheelEvent*) override;
|
||||
void contextMenuEvent(QGraphicsSceneContextMenuEvent*) override;
|
||||
|
||||
inline KnobGadget* setLabel(const QString& s) { label->setText(s); dirty = true; update(); return this; }
|
||||
|
|
Loading…
Reference in New Issue