mirror of
https://github.com/obsproject/obs-studio.git
synced 2026-09-19 09:41:32 +08:00
UI: Allow zoom with the scroll wheel
Adds the ability to zoom into the preview when fixed scaling mode is enabled. (Edit by Jim: Also now saves zoom and scroll position) Closes jp9000/obs-studio#917
This commit is contained in:
@@ -382,8 +382,7 @@ void OBSBasicPreview::GetStretchHandleData(const vec2 &pos)
|
||||
|
||||
void OBSBasicPreview::keyPressEvent(QKeyEvent *event)
|
||||
{
|
||||
if (GetScalingMode() == ScalingMode::Window ||
|
||||
event->isAutoRepeat()) {
|
||||
if (!IsFixedScaling() || event->isAutoRepeat()) {
|
||||
OBSQTDisplay::keyPressEvent(event);
|
||||
return;
|
||||
}
|
||||
@@ -415,9 +414,23 @@ void OBSBasicPreview::keyReleaseEvent(QKeyEvent *event)
|
||||
OBSQTDisplay::keyReleaseEvent(event);
|
||||
}
|
||||
|
||||
void OBSBasicPreview::wheelEvent(QWheelEvent *event)
|
||||
{
|
||||
if (scrollMode && IsFixedScaling()
|
||||
&& event->orientation() == Qt::Vertical) {
|
||||
if (event->delta() > 0)
|
||||
SetScalingLevel(scalingLevel + 1);
|
||||
else if (event->delta() < 0)
|
||||
SetScalingLevel(scalingLevel - 1);
|
||||
emit DisplayResized();
|
||||
}
|
||||
|
||||
OBSQTDisplay::wheelEvent(event);
|
||||
}
|
||||
|
||||
void OBSBasicPreview::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
if (scrollMode && GetScalingMode() != ScalingMode::Window &&
|
||||
if (scrollMode && IsFixedScaling() &&
|
||||
event->button() == Qt::LeftButton) {
|
||||
setCursor(Qt::ClosedHandCursor);
|
||||
scrollingFrom.x = event->x();
|
||||
@@ -1205,3 +1218,15 @@ void OBSBasicPreview::ResetScrollingOffset()
|
||||
{
|
||||
vec2_zero(&scrollingOffset);
|
||||
}
|
||||
|
||||
void OBSBasicPreview::SetScalingLevel(int32_t newScalingLevelVal) {
|
||||
float newScalingAmountVal = pow(ZOOM_SENSITIVITY, float(newScalingLevelVal));
|
||||
scalingLevel = newScalingLevelVal;
|
||||
SetScalingAmount(newScalingAmountVal);
|
||||
}
|
||||
|
||||
void OBSBasicPreview::SetScalingAmount(float newScalingAmountVal) {
|
||||
scrollingOffset.x *= newScalingAmountVal / scalingAmount;
|
||||
scrollingOffset.y *= newScalingAmountVal / scalingAmount;
|
||||
scalingAmount = newScalingAmountVal;
|
||||
}
|
||||
Reference in New Issue
Block a user