From efe31c9fe97b96cbea39e53fd4b1eaf205b857e8 Mon Sep 17 00:00:00 2001 From: jp9000 Date: Wed, 4 Feb 2015 01:59:12 -0800 Subject: [PATCH] UI: Keep prop. view scroll positions if modified If the properties view is scrolled down or right and a widget triggers it to repaint, it would reset its scroll position, making editing a bit awkward. This simply saved/restores the position before and after rebuilding the properties view. --- obs/properties-view.cpp | 29 +++++++++++++++++++++++++++++ obs/properties-view.hpp | 3 +++ 2 files changed, 32 insertions(+) diff --git a/obs/properties-view.cpp b/obs/properties-view.cpp index aca053d4a..17220763b 100644 --- a/obs/properties-view.cpp +++ b/obs/properties-view.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -54,6 +55,9 @@ void OBSPropertiesView::ReloadProperties() void OBSPropertiesView::RefreshProperties() { + int h, v; + GetScrollPos(h, v); + children.clear(); if (widget) widget->deleteLater(); @@ -79,6 +83,7 @@ void OBSPropertiesView::RefreshProperties() setWidgetResizable(true); setWidget(widget); + SetScrollPos(h, v); setSizePolicy(mainPolicy); lastFocused.clear(); @@ -88,6 +93,30 @@ void OBSPropertiesView::RefreshProperties() } } +void OBSPropertiesView::SetScrollPos(int h, int v) +{ + QScrollBar *scroll = horizontalScrollBar(); + if (scroll) + scroll->setValue(h); + + scroll = verticalScrollBar(); + if (scroll) + scroll->setValue(v); +} + +void OBSPropertiesView::GetScrollPos(int &h, int &v) +{ + h = v = 0; + + QScrollBar *scroll = horizontalScrollBar(); + if (scroll) + h = scroll->value(); + + scroll = verticalScrollBar(); + if (scroll) + v = scroll->value(); +} + OBSPropertiesView::OBSPropertiesView(OBSData settings_, void *obj_, PropertiesReloadCallback reloadCallback, PropertiesUpdateCallback callback_, int minSize_) diff --git a/obs/properties-view.hpp b/obs/properties-view.hpp index 5e0fe91b2..718fa1467 100644 --- a/obs/properties-view.hpp +++ b/obs/properties-view.hpp @@ -84,6 +84,9 @@ private: void resizeEvent(QResizeEvent *event) override; + void GetScrollPos(int &h, int &v); + void SetScrollPos(int h, int v); + public slots: void ReloadProperties(); void RefreshProperties();