UI: Recalculate scroll position after resize

This commit is contained in:
derrod 2023-04-05 11:23:45 +02:00 committed by Rodney
parent d277a7541f
commit e8541b9e27
2 changed files with 21 additions and 13 deletions

View file

@ -108,8 +108,8 @@ void OBSPropertiesView::ReloadProperties()
void OBSPropertiesView::RefreshProperties()
{
int h, v;
GetScrollPos(h, v);
int h, v, hend, vend;
GetScrollPos(h, v, hend, vend);
children.clear();
if (widget)
@ -136,9 +136,9 @@ void OBSPropertiesView::RefreshProperties()
setWidgetResizable(true);
setWidget(widget);
SetScrollPos(h, v);
setSizePolicy(mainPolicy);
adjustSize();
SetScrollPos(h, v, hend, vend);
lastFocused.clear();
if (lastWidget) {
@ -154,28 +154,36 @@ void OBSPropertiesView::RefreshProperties()
emit PropertiesRefreshed();
}
void OBSPropertiesView::SetScrollPos(int h, int v)
void OBSPropertiesView::SetScrollPos(int h, int v, int old_hend, int old_vend)
{
QScrollBar *scroll = horizontalScrollBar();
if (scroll)
scroll->setValue(h);
if (scroll) {
int hend = scroll->maximum() + scroll->pageStep();
scroll->setValue(h * hend / old_hend);
}
scroll = verticalScrollBar();
if (scroll)
scroll->setValue(v);
if (scroll) {
int vend = scroll->maximum() + scroll->pageStep();
scroll->setValue(v * vend / old_vend);
}
}
void OBSPropertiesView::GetScrollPos(int &h, int &v)
void OBSPropertiesView::GetScrollPos(int &h, int &v, int &hend, int &vend)
{
h = v = 0;
QScrollBar *scroll = horizontalScrollBar();
if (scroll)
if (scroll) {
h = scroll->value();
hend = scroll->maximum() + scroll->pageStep();
}
scroll = verticalScrollBar();
if (scroll)
if (scroll) {
v = scroll->value();
vend = scroll->maximum() + scroll->pageStep();
}
}
OBSPropertiesView::OBSPropertiesView(OBSData settings_, obs_object_t *obj,

View file

@ -137,8 +137,8 @@ private:
void resizeEvent(QResizeEvent *event) override;
void GetScrollPos(int &h, int &v);
void SetScrollPos(int h, int v);
void GetScrollPos(int &h, int &v, int &hend, int &vend);
void SetScrollPos(int h, int v, int old_hend, int old_vend);
private slots:
void RefreshProperties();