ソースを参照

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.
jp9000 10 年 前
コミット
efe31c9fe9
2 ファイル変更32 行追加0 行削除
  1. 29 0
      obs/properties-view.cpp
  2. 3 0
      obs/properties-view.hpp

+ 29 - 0
obs/properties-view.cpp

@@ -1,4 +1,5 @@
 #include <QFormLayout>
+#include <QScrollBar>
 #include <QLabel>
 #include <QCheckBox>
 #include <QFont>
@@ -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_)

+ 3 - 0
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();