mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-14 19:18:55 -07:00
dynamically resize scrollbar when zone view window is resized (#5228)
This commit is contained in:
parent
8cb1470643
commit
2d68393e07
2 changed files with 25 additions and 9 deletions
|
|
@ -101,7 +101,7 @@ ZoneViewWidget::ZoneViewWidget(Player *_player,
|
||||||
scrollBar->setMinimum(0);
|
scrollBar->setMinimum(0);
|
||||||
scrollBar->setSingleStep(20);
|
scrollBar->setSingleStep(20);
|
||||||
scrollBar->setPageStep(200);
|
scrollBar->setPageStep(200);
|
||||||
connect(scrollBar, SIGNAL(valueChanged(int)), this, SLOT(handleScrollBarChange(int)));
|
connect(scrollBar, &QScrollBar::valueChanged, this, &ZoneViewWidget::handleScrollBarChange);
|
||||||
scrollBarProxy = new ScrollableGraphicsProxyWidget;
|
scrollBarProxy = new ScrollableGraphicsProxyWidget;
|
||||||
scrollBarProxy->setWidget(scrollBar);
|
scrollBarProxy->setWidget(scrollBar);
|
||||||
zoneHBox->addItem(scrollBarProxy);
|
zoneHBox->addItem(scrollBarProxy);
|
||||||
|
|
@ -245,20 +245,35 @@ void ZoneViewWidget::moveEvent(QGraphicsSceneMoveEvent * /* event */)
|
||||||
setPos(scenePos);
|
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()
|
void ZoneViewWidget::resizeToZoneContents()
|
||||||
{
|
{
|
||||||
QRectF zoneRect = zone->getOptimumRect();
|
QRectF zoneRect = zone->getOptimumRect();
|
||||||
qreal totalZoneHeight = zoneRect.height();
|
qreal totalZoneHeight = zoneRect.height();
|
||||||
if (zoneRect.height() > 500)
|
|
||||||
zoneRect.setHeight(500);
|
qreal width = qMax(QGraphicsWidget::layout()->effectiveSizeHint(Qt::MinimumSize, QSizeF()).width(),
|
||||||
QSizeF newSize(qMax(QGraphicsWidget::layout()->effectiveSizeHint(Qt::MinimumSize, QSizeF()).width(),
|
zoneRect.width() + scrollBar->width() + 10);
|
||||||
zoneRect.width() + scrollBar->width() + 10),
|
|
||||||
zoneRect.height() + extraHeight + 10);
|
QSizeF maxSize(width, zoneRect.height() + extraHeight + 10);
|
||||||
setMaximumSize(newSize);
|
setMaximumSize(maxSize);
|
||||||
resize(newSize);
|
|
||||||
|
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));
|
zone->setGeometry(QRectF(0, -scrollBar->value(), zoneContainer->size().width(), totalZoneHeight));
|
||||||
scrollBar->setMaximum(totalZoneHeight - zoneRect.height());
|
|
||||||
|
|
||||||
if (layout())
|
if (layout())
|
||||||
layout()->invalidate();
|
layout()->invalidate();
|
||||||
|
|
|
||||||
|
|
@ -65,6 +65,7 @@ private slots:
|
||||||
void handleScrollBarChange(int value);
|
void handleScrollBarChange(int value);
|
||||||
void zoneDeleted();
|
void zoneDeleted();
|
||||||
void moveEvent(QGraphicsSceneMoveEvent * /* event */);
|
void moveEvent(QGraphicsSceneMoveEvent * /* event */);
|
||||||
|
void resizeEvent(QGraphicsSceneResizeEvent * /* event */);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ZoneViewWidget(Player *_player,
|
ZoneViewWidget(Player *_player,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue