Files
IfcOpenShell/src/interface/components/Panel.cpp
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

139 lines
5.3 KiB
C++
Raw Normal View History

2026-05-05 18:02:02 +10:00
// This file was generated with the assistance of an AI coding tool.
/********************************************************************************
* *
* This file is part of IfcOpenShell. *
* *
* IfcOpenShell is free software: you can redistribute it and/or modify *
* it under the terms of the Lesser 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. *
* *
* IfcOpenShell 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 *
* Lesser GNU General Public License for more details. *
* *
* You should have received a copy of the Lesser GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* *
********************************************************************************/
2026-05-06 10:47:03 +10:00
#include "Panel.h"
2026-05-05 18:02:02 +10:00
2026-05-06 10:47:03 +10:00
#include "Style.h"
2026-05-05 18:02:02 +10:00
#include "SvgIcon.h"
#include <QDockWidget>
#include <QFrame>
#include <QHBoxLayout>
#include <QLabel>
#include <QMenu>
2026-05-06 12:36:28 +10:00
#include <QScrollArea>
2026-05-05 18:02:02 +10:00
#include <QToolButton>
#include <QVBoxLayout>
2026-05-06 10:47:03 +10:00
namespace ifcinterface::components {
2026-05-05 18:02:02 +10:00
namespace {
class DockTitleBar : public QWidget {
public:
2026-05-09 22:00:19 +10:00
explicit DockTitleBar(const QString& title,
bool has_settings = false,
std::function<void()> on_settings = {},
QWidget* parent = nullptr)
2026-05-05 18:02:02 +10:00
: QWidget(parent)
{
auto* layout = new QHBoxLayout(this);
layout->setContentsMargins(10, 6, 6, 6);
layout->setSpacing(6);
auto* text = new QLabel(title.toUpper(), this);
2026-05-06 13:13:37 +10:00
text->setObjectName("panelTitleText");
2026-05-05 18:02:02 +10:00
layout->addWidget(text);
layout->addStretch(1);
if (has_settings) {
auto* settings = new QToolButton(this);
2026-05-06 21:35:12 +10:00
settings->setIcon(icons::makeSvgIcon(":/icons/settings.svg"));
2026-05-05 18:02:02 +10:00
settings->setAutoRaise(true);
settings->setCursor(Qt::ArrowCursor);
settings->setFixedSize(18, 18);
2026-05-06 13:13:37 +10:00
settings->setObjectName("panelTitleButton");
2026-05-05 18:02:02 +10:00
settings->setToolTip(QString("%1 settings").arg(title));
2026-05-09 22:00:19 +10:00
connect(settings, &QToolButton::clicked, this, [on_settings = std::move(on_settings)]() {
if (on_settings) on_settings();
2026-05-05 18:02:02 +10:00
});
layout->addWidget(settings);
}
}
};
} // namespace
2026-05-06 12:36:28 +10:00
Panel::Panel(const QString& title, QWidget* content, QWidget* parent, bool has_settings, bool scrollable)
2026-05-06 10:47:03 +10:00
: QDockWidget(title, parent)
{
2026-05-05 18:02:02 +10:00
auto* outer = new QFrame();
auto* outer_layout = new QVBoxLayout(outer);
2026-05-06 10:47:03 +10:00
outer_layout->setContentsMargins(style::metrics::padding,
style::metrics::padding,
style::metrics::padding,
style::metrics::padding);
2026-05-05 18:02:02 +10:00
outer_layout->setSpacing(0);
auto* frame = new QFrame(outer);
2026-05-06 10:47:03 +10:00
frame->setObjectName("panel");
auto* frame_layout = new QVBoxLayout(frame);
2026-05-06 13:13:37 +10:00
frame_layout->setContentsMargins(0, style::metrics::section_body_padding, 0, style::metrics::section_body_padding);
2026-05-06 10:47:03 +10:00
frame_layout->setSpacing(0);
2026-05-06 12:36:28 +10:00
if (scrollable) {
auto* scroll = new QScrollArea(frame);
scroll->setWidgetResizable(true);
scroll->setFrameShape(QFrame::NoFrame);
auto* scroll_body = new QWidget(scroll);
scroll_body->setObjectName("panelScrollBody");
2026-05-07 12:21:55 +10:00
body_layout_ = new QVBoxLayout(scroll_body);
body_layout_->setContentsMargins(0, 0, 0, 0);
2026-05-07 14:12:27 +10:00
body_layout_->setSpacing(style::metrics::section_body_padding);
2026-05-06 12:36:28 +10:00
scroll->setWidget(scroll_body);
frame_layout->addWidget(scroll);
} else {
2026-05-07 12:21:55 +10:00
auto* body = new QWidget(frame);
body_layout_ = new QVBoxLayout(body);
body_layout_->setContentsMargins(0, 0, 0, 0);
2026-05-07 14:12:27 +10:00
body_layout_->setSpacing(style::metrics::section_body_padding);
2026-05-07 12:21:55 +10:00
frame_layout->addWidget(body);
}
if (content) {
body_layout_->addWidget(content);
2026-05-06 12:36:28 +10:00
}
2026-05-05 18:02:02 +10:00
outer_layout->addWidget(frame);
2026-05-06 10:47:03 +10:00
setObjectName(title);
setFeatures(QDockWidget::DockWidgetMovable |
QDockWidget::DockWidgetFloatable |
QDockWidget::DockWidgetClosable);
2026-05-09 22:00:19 +10:00
setTitleBarWidget(new DockTitleBar(title, has_settings, [this]() {
emit settingsRequested();
}, this));
2026-05-06 10:47:03 +10:00
setWidget(outer);
2026-05-05 18:02:02 +10:00
}
2026-05-07 12:21:55 +10:00
void Panel::addBodyWidget(QWidget* widget) {
body_layout_->addWidget(widget);
}
2026-05-07 14:12:27 +10:00
void Panel::clearBodyWidgets() {
while (auto* item = body_layout_->takeAt(0)) {
if (auto* widget = item->widget()) widget->deleteLater();
delete item;
}
}
2026-05-06 10:47:03 +10:00
} // namespace ifcinterface::components