dynamically resize scrollbar when zone view window is resized (#5228)
Some checks failed
Build Web / React (Node ${{matrix.node_version}}) (16) (push) Waiting to run
Build Web / React (Node ${{matrix.node_version}}) (lts/*) (push) Waiting to run
Build Desktop / Configure (push) Has been cancelled
Build Desktop / ${{matrix.distro}} ${{matrix.version}} (Debian, DEB, 12) (push) Has been cancelled
Build Desktop / ${{matrix.distro}} ${{matrix.version}} (Debian, DEB, skip, 11) (push) Has been cancelled
Build Desktop / ${{matrix.distro}} ${{matrix.version}} (Fedora, RPM, 41) (push) Has been cancelled
Build Desktop / ${{matrix.distro}} ${{matrix.version}} (Fedora, RPM, skip, 40) (push) Has been cancelled
Build Desktop / ${{matrix.distro}} ${{matrix.version}} (Ubuntu, DEB, 24.04) (push) Has been cancelled
Build Desktop / ${{matrix.distro}} ${{matrix.version}} (Ubuntu, DEB, skip, 20.04) (push) Has been cancelled
Build Desktop / ${{matrix.distro}} ${{matrix.version}} (Ubuntu, DEB, skip, 22.04) (push) Has been cancelled
Build Desktop / ${{matrix.distro}} ${{matrix.version}} (yes, Arch, skip) (push) Has been cancelled
Build Desktop / macOS ${{matrix.target}}${{ matrix.soc == 'Intel' && ' Intel' || '' }}${{ matrix.type == 'Debug' && ' Debug' || '' }} (3, 1, macos-14, Apple, 14, Release, 15.4) (push) Has been cancelled
Build Desktop / macOS ${{matrix.target}}${{ matrix.soc == 'Intel' && ' Intel' || '' }}${{ matrix.type == 'Debug' && ' Debug' || '' }} (3, macos-14, Apple, 14, Debug, 15.4) (push) Has been cancelled
Build Desktop / macOS ${{matrix.target}}${{ matrix.soc == 'Intel' && ' Intel' || '' }}${{ matrix.type == 'Debug' && ' Debug' || '' }} (4, 1, macos-13, Intel, 13, Release, 14.3.1) (push) Has been cancelled
Build Desktop / Windows ${{matrix.target}} (msvc2019_64, 5.15.*, 7) (push) Has been cancelled
Build Desktop / Windows ${{matrix.target}} (msvc2019_64, qtimageformats qtmultimedia qtwebsockets, 6.5.*, 10) (push) Has been cancelled

This commit is contained in:
RickyRister
2024-12-09 11:01:37 -08:00
committed by GitHub
parent 8cb1470643
commit 2d68393e07
2 changed files with 25 additions and 9 deletions

View File

@@ -101,7 +101,7 @@ ZoneViewWidget::ZoneViewWidget(Player *_player,
scrollBar->setMinimum(0);
scrollBar->setSingleStep(20);
scrollBar->setPageStep(200);
connect(scrollBar, SIGNAL(valueChanged(int)), this, SLOT(handleScrollBarChange(int)));
connect(scrollBar, &QScrollBar::valueChanged, this, &ZoneViewWidget::handleScrollBarChange);
scrollBarProxy = new ScrollableGraphicsProxyWidget;
scrollBarProxy->setWidget(scrollBar);
zoneHBox->addItem(scrollBarProxy);
@@ -245,20 +245,35 @@ void ZoneViewWidget::moveEvent(QGraphicsSceneMoveEvent * /* event */)
setPos(scenePos);
}
void ZoneViewWidget::resizeEvent(QGraphicsSceneResizeEvent *event)
{
if (!zone)
return;
// We need to manually resize the scroll bar whenever the window gets resized
qreal totalZoneHeight = zone->getOptimumRect().height();
qreal newWindowHeight = event->newSize().height();
qreal newZoneHeight = newWindowHeight - extraHeight - 10;
scrollBar->setMaximum(totalZoneHeight - newZoneHeight);
}
void ZoneViewWidget::resizeToZoneContents()
{
QRectF zoneRect = zone->getOptimumRect();
qreal totalZoneHeight = zoneRect.height();
if (zoneRect.height() > 500)
zoneRect.setHeight(500);
QSizeF newSize(qMax(QGraphicsWidget::layout()->effectiveSizeHint(Qt::MinimumSize, QSizeF()).width(),
zoneRect.width() + scrollBar->width() + 10),
zoneRect.height() + extraHeight + 10);
setMaximumSize(newSize);
resize(newSize);
qreal width = qMax(QGraphicsWidget::layout()->effectiveSizeHint(Qt::MinimumSize, QSizeF()).width(),
zoneRect.width() + scrollBar->width() + 10);
QSizeF maxSize(width, zoneRect.height() + extraHeight + 10);
setMaximumSize(maxSize);
qreal initialZoneHeight = qMin(zoneRect.height(), 500.0);
QSizeF initialSize(width, initialZoneHeight + extraHeight + 10);
resize(initialSize);
zone->setGeometry(QRectF(0, -scrollBar->value(), zoneContainer->size().width(), totalZoneHeight));
scrollBar->setMaximum(totalZoneHeight - zoneRect.height());
if (layout())
layout()->invalidate();

View File

@@ -65,6 +65,7 @@ private slots:
void handleScrollBarChange(int value);
void zoneDeleted();
void moveEvent(QGraphicsSceneMoveEvent * /* event */);
void resizeEvent(QGraphicsSceneResizeEvent * /* event */);
public:
ZoneViewWidget(Player *_player,