diff --git a/client/views/view_research.cpp b/client/views/view_research.cpp index 313f023509..2b60d6fe18 100644 --- a/client/views/view_research.cpp +++ b/client/views/view_research.cpp @@ -22,6 +22,8 @@ #include #include #include +#include +#include // common #include "game.h" @@ -301,6 +303,9 @@ science_report::science_report() : QWidget() scroll->setPalette(QPalette(QColor(215, 215, 215))); scroll->setWidget(res_diag); scroll->setSizePolicy(size_expanding_policy); + scroll->horizontalScrollBar()->setValue( + science_report::horizontalScrollValue); + scroll->verticalScrollBar()->setValue(science_report::verticalScrollValue); sci_layout->addWidget(scroll, 4, 0, 1, 10); QObject::connect(researching_combo, @@ -314,6 +319,16 @@ science_report::science_report() : QWidget() QOverload::of(&QComboBox::currentIndexChanged), this, &science_report::goal_tech_changed); + QScrollBar *horizontalScrollBar = scroll->horizontalScrollBar(); + QObject::connect(horizontalScrollBar, + QOverload::of(&QAbstractSlider::valueChanged), this, + &science_report::setHorizontalScrollValue); + + QScrollBar *verticalScrollBar = scroll->verticalScrollBar(); + QObject::connect(verticalScrollBar, + QOverload::of(&QAbstractSlider::valueChanged), this, + &science_report::setVerticalScrollValue); + setLayout(sci_layout); } @@ -570,6 +585,24 @@ void science_report::push_research() } } +/** + Set the backing field for the horizontal scroll value. This is used + to restore the scroll state when the view is reinstantiated. +*/ +void science_report::setHorizontalScrollValue(int value) +{ + science_report::horizontalScrollValue = value; +} + +/** + Set the backing field for the vertical scroll value. This is used + to restore the scroll state when the view is reinstantiated. +*/ +void science_report::setVerticalScrollValue(int value) +{ + science_report::verticalScrollValue = value; +} + /** Update the science report. */ diff --git a/client/views/view_research.h b/client/views/view_research.h index 57d551b8cb..06cdd15bc4 100644 --- a/client/views/view_research.h +++ b/client/views/view_research.h @@ -71,6 +71,8 @@ struct qlist_item { class science_report : public QWidget { Q_OBJECT + static inline int horizontalScrollValue; + static inline int verticalScrollValue; QComboBox *goal_combo; QComboBox *researching_combo; QPushButton *refresh_but; @@ -97,6 +99,8 @@ private slots: void current_tech_changed(int index); void goal_tech_changed(int index); void push_research(); + void setHorizontalScrollValue(int value); + void setVerticalScrollValue(int value); }; void popdown_science_report();