2018-03-17 16:07:51 +01:00
|
|
|
// Copyright 2018 Dolphin Emulator Project
|
2021-07-05 03:22:19 +02:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2018-03-17 16:07:51 +01:00
|
|
|
|
2018-07-07 00:40:15 +02:00
|
|
|
#include "DolphinQt/QtUtils/WrapInScrollArea.h"
|
2018-03-17 16:07:51 +01:00
|
|
|
|
|
|
|
#include <QFrame>
|
|
|
|
#include <QLayout>
|
2018-05-02 20:08:46 +02:00
|
|
|
#include <QPalette>
|
2018-03-17 16:07:51 +01:00
|
|
|
#include <QScrollArea>
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
#include <QWidget>
|
|
|
|
|
2018-03-18 00:06:44 +01:00
|
|
|
QWidget* GetWrappedWidget(QWidget* wrapped_widget, QWidget* to_resize, int margin_width,
|
|
|
|
int margin_height)
|
2018-03-17 16:07:51 +01:00
|
|
|
{
|
|
|
|
auto* scroll = new QScrollArea;
|
|
|
|
scroll->setWidget(wrapped_widget);
|
|
|
|
scroll->setWidgetResizable(true);
|
|
|
|
scroll->setFrameStyle(QFrame::NoFrame);
|
|
|
|
|
|
|
|
if (to_resize != nullptr)
|
|
|
|
{
|
|
|
|
// For some reason width() is bigger than it needs to be.
|
2018-03-18 00:06:44 +01:00
|
|
|
auto min_size = wrapped_widget->minimumSizeHint();
|
|
|
|
int recommended_width = min_size.width() + margin_width;
|
|
|
|
int recommended_height = min_size.height() + margin_height;
|
2018-03-17 16:07:51 +01:00
|
|
|
|
|
|
|
to_resize->resize(std::max(recommended_width, to_resize->width()),
|
|
|
|
std::max(recommended_height, to_resize->height()));
|
|
|
|
}
|
|
|
|
|
2019-02-02 16:28:46 +01:00
|
|
|
scroll->viewport()->setAutoFillBackground(false);
|
|
|
|
wrapped_widget->setAutoFillBackground(false);
|
2018-05-02 20:08:46 +02:00
|
|
|
|
2018-03-17 16:07:51 +01:00
|
|
|
return scroll;
|
|
|
|
}
|
|
|
|
|
|
|
|
void WrapInScrollArea(QWidget* parent, QLayout* wrapped_layout, QWidget* to_resize)
|
|
|
|
{
|
|
|
|
if (to_resize == nullptr)
|
|
|
|
to_resize = parent;
|
|
|
|
|
|
|
|
auto* widget = new QWidget;
|
|
|
|
widget->setLayout(wrapped_layout);
|
|
|
|
|
2018-03-24 18:45:10 +01:00
|
|
|
auto* scroll_area = GetWrappedWidget(widget, to_resize, 0, 0);
|
2018-03-17 16:07:51 +01:00
|
|
|
|
|
|
|
auto* scroll_layout = new QVBoxLayout;
|
|
|
|
scroll_layout->addWidget(scroll_area);
|
2021-01-13 10:33:01 +01:00
|
|
|
scroll_layout->setContentsMargins(0, 0, 0, 0);
|
2018-03-17 16:07:51 +01:00
|
|
|
|
|
|
|
parent->setLayout(scroll_layout);
|
|
|
|
}
|