mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-12 18:43:26 +00:00
791ff26697
Update Bonsai viewer headers to identify Bonsai and GPL licensing, add Bonsai Viewer documentation, and document debug output capture. Generated with the assistance of an AI coding tool.
141 lines
5.3 KiB
C++
141 lines
5.3 KiB
C++
// This file was generated with the assistance of an AI coding tool.
|
|
/********************************************************************************
|
|
* *
|
|
* This file is part of Bonsai. *
|
|
* *
|
|
* Bonsai is free software: you can redistribute it and/or modify *
|
|
* it under the terms of the GNU General Public License as published by *
|
|
* the Free Software Foundation, either version 3.0 of the License, or *
|
|
* (at your option) any later version. *
|
|
* *
|
|
* Bonsai is distributed in the hope that it will be useful, *
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
* GNU General Public License for more details. *
|
|
* *
|
|
* You should have received a copy of the GNU General Public License *
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
|
* *
|
|
********************************************************************************/
|
|
|
|
#include "Panel.h"
|
|
|
|
#include "Style.h"
|
|
#include "SvgIcon.h"
|
|
|
|
#include <QDockWidget>
|
|
#include <QFrame>
|
|
#include <QHBoxLayout>
|
|
#include <QLabel>
|
|
#include <QMenu>
|
|
#include <QScrollArea>
|
|
#include <QToolButton>
|
|
#include <QVBoxLayout>
|
|
|
|
namespace bonsaiviewer::components {
|
|
|
|
namespace {
|
|
|
|
class DockTitleBar : public QWidget {
|
|
public:
|
|
explicit DockTitleBar(const QString& title,
|
|
bool has_settings = false,
|
|
std::function<void()> on_settings = {},
|
|
QWidget* parent = nullptr)
|
|
: QWidget(parent)
|
|
{
|
|
auto* layout = new QHBoxLayout(this);
|
|
layout->setContentsMargins(10, 6, 6, 6);
|
|
layout->setSpacing(6);
|
|
|
|
auto* text = new QLabel(title.toUpper(), this);
|
|
text->setObjectName("panelTitleText");
|
|
|
|
layout->addWidget(text);
|
|
layout->addStretch(1);
|
|
if (has_settings) {
|
|
auto* settings = new QToolButton(this);
|
|
settings->setIcon(icons::makeSvgIcon(":/icons/settings.svg"));
|
|
settings->setAutoRaise(true);
|
|
settings->setCursor(Qt::ArrowCursor);
|
|
settings->setFixedSize(18, 18);
|
|
settings->setObjectName("panelTitleButton");
|
|
settings->setToolTip(QString("%1 settings").arg(title));
|
|
connect(settings, &QToolButton::clicked, this, [on_settings = std::move(on_settings)]() {
|
|
if (on_settings) on_settings();
|
|
});
|
|
layout->addWidget(settings);
|
|
}
|
|
}
|
|
};
|
|
|
|
} // namespace
|
|
|
|
Panel::Panel(const QString& title, QWidget* content, QWidget* parent, bool has_settings, bool scrollable)
|
|
: QDockWidget(title, parent)
|
|
{
|
|
auto* outer = new QFrame();
|
|
auto* outer_layout = new QVBoxLayout(outer);
|
|
outer_layout->setContentsMargins(style::metrics::padding,
|
|
style::metrics::padding,
|
|
style::metrics::padding,
|
|
style::metrics::padding);
|
|
outer_layout->setSpacing(0);
|
|
|
|
auto* frame = new QFrame(outer);
|
|
frame->setObjectName("panel");
|
|
auto* frame_layout = new QVBoxLayout(frame);
|
|
frame_layout->setContentsMargins(0, style::metrics::section_body_padding, 0, style::metrics::section_body_padding);
|
|
frame_layout->setSpacing(0);
|
|
|
|
if (scrollable) {
|
|
auto* scroll = new QScrollArea(frame);
|
|
scroll->setWidgetResizable(true);
|
|
scroll->setFrameShape(QFrame::NoFrame);
|
|
|
|
auto* scroll_body = new QWidget(scroll);
|
|
scroll_body->setObjectName("panelScrollBody");
|
|
body_layout_ = new QVBoxLayout(scroll_body);
|
|
body_layout_->setContentsMargins(0, 0, 0, 0);
|
|
body_layout_->setSpacing(style::metrics::section_body_padding);
|
|
body_layout_->setAlignment(Qt::AlignTop);
|
|
|
|
scroll->setWidget(scroll_body);
|
|
frame_layout->addWidget(scroll);
|
|
} else {
|
|
auto* body = new QWidget(frame);
|
|
body_layout_ = new QVBoxLayout(body);
|
|
body_layout_->setContentsMargins(0, 0, 0, 0);
|
|
body_layout_->setSpacing(style::metrics::section_body_padding);
|
|
body_layout_->setAlignment(Qt::AlignTop);
|
|
frame_layout->addWidget(body);
|
|
}
|
|
|
|
if (content) {
|
|
addBodyWidget(content);
|
|
}
|
|
outer_layout->addWidget(frame);
|
|
|
|
setObjectName(title);
|
|
setFeatures(QDockWidget::DockWidgetMovable |
|
|
QDockWidget::DockWidgetFloatable |
|
|
QDockWidget::DockWidgetClosable);
|
|
setTitleBarWidget(new DockTitleBar(title, has_settings, [this]() {
|
|
emit settingsRequested();
|
|
}, this));
|
|
setWidget(outer);
|
|
}
|
|
|
|
void Panel::addBodyWidget(QWidget* widget) {
|
|
body_layout_->addWidget(widget);
|
|
}
|
|
|
|
void Panel::clearBodyWidgets() {
|
|
while (auto* item = body_layout_->takeAt(0)) {
|
|
if (auto* widget = item->widget()) widget->deleteLater();
|
|
delete item;
|
|
}
|
|
}
|
|
|
|
} // namespace bonsaiviewer::components
|