2026-05-05 19:59:51 +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/>. *
|
|
|
|
|
* *
|
|
|
|
|
********************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "Section.h"
|
|
|
|
|
|
2026-05-06 10:47:03 +10:00
|
|
|
#include "Style.h"
|
2026-05-05 19:59:51 +10:00
|
|
|
|
|
|
|
|
#include <QFrame>
|
|
|
|
|
#include <QHBoxLayout>
|
2026-05-10 22:04:03 +10:00
|
|
|
#include <QSizePolicy>
|
2026-05-05 19:59:51 +10:00
|
|
|
#include <QToolButton>
|
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
|
|
|
|
|
namespace ifcinterface::components {
|
|
|
|
|
|
2026-05-06 21:35:12 +10:00
|
|
|
Section::Section(const QString& title, SectionHeaderMode header_mode, QWidget* parent)
|
2026-05-05 19:59:51 +10:00
|
|
|
: QWidget(parent)
|
|
|
|
|
{
|
|
|
|
|
setObjectName("panelSection");
|
2026-05-10 22:04:03 +10:00
|
|
|
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum);
|
2026-05-05 19:59:51 +10:00
|
|
|
auto* layout = new QVBoxLayout(this);
|
|
|
|
|
layout->setContentsMargins(0, 0, 0, 0);
|
2026-05-06 13:13:37 +10:00
|
|
|
layout->setSpacing(style::metrics::padding);
|
2026-05-05 19:59:51 +10:00
|
|
|
|
|
|
|
|
if (header_mode == SectionHeaderMode::Visible) {
|
|
|
|
|
auto* header = new QFrame(this);
|
|
|
|
|
header->setObjectName("panelSectionHeader");
|
2026-05-06 21:35:12 +10:00
|
|
|
header_layout_ = new QHBoxLayout(header);
|
|
|
|
|
header_layout_->setContentsMargins(0, 0, 0, 0);
|
|
|
|
|
header_layout_->setSpacing(style::metrics::padding);
|
|
|
|
|
|
|
|
|
|
toggle_button_ = new QToolButton(header);
|
|
|
|
|
toggle_button_->setObjectName("panelSectionHeaderButton");
|
|
|
|
|
toggle_button_->setText(title);
|
|
|
|
|
toggle_button_->setCheckable(true);
|
|
|
|
|
toggle_button_->setChecked(true);
|
|
|
|
|
toggle_button_->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
|
|
|
|
|
toggle_button_->setArrowType(Qt::DownArrow);
|
|
|
|
|
header_layout_->addWidget(toggle_button_);
|
|
|
|
|
header_layout_->addStretch(1);
|
2026-05-05 19:59:51 +10:00
|
|
|
|
|
|
|
|
layout->addWidget(header);
|
2026-05-06 21:35:12 +10:00
|
|
|
|
|
|
|
|
connect(toggle_button_, &QToolButton::toggled, this, [this](bool expanded) {
|
|
|
|
|
toggle_button_->setArrowType(expanded ? Qt::DownArrow : Qt::RightArrow);
|
2026-05-05 19:59:51 +10:00
|
|
|
body_->setVisible(expanded);
|
2026-05-10 22:04:03 +10:00
|
|
|
body_->setMaximumHeight(expanded ? QWIDGETSIZE_MAX : 0);
|
|
|
|
|
body_->setMinimumHeight(0);
|
|
|
|
|
setSizePolicy(QSizePolicy::Preferred,
|
|
|
|
|
body_expanding_ && expanded ? QSizePolicy::Expanding : QSizePolicy::Maximum);
|
|
|
|
|
updateGeometry();
|
2026-05-05 19:59:51 +10:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
body_ = new QWidget(this);
|
|
|
|
|
body_->setObjectName("panelSectionBody");
|
|
|
|
|
body_layout_ = new QVBoxLayout(body_);
|
2026-05-06 13:13:37 +10:00
|
|
|
body_layout_->setContentsMargins(style::metrics::section_body_padding,
|
|
|
|
|
0,
|
|
|
|
|
style::metrics::section_body_padding,
|
|
|
|
|
0);
|
|
|
|
|
body_layout_->setSpacing(style::metrics::padding);
|
2026-05-10 22:04:03 +10:00
|
|
|
body_->setMinimumHeight(0);
|
2026-05-05 19:59:51 +10:00
|
|
|
layout->addWidget(body_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Section::addBodyWidget(QWidget* widget) {
|
|
|
|
|
body_layout_->addWidget(widget);
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-06 21:35:12 +10:00
|
|
|
void Section::clearBody() {
|
|
|
|
|
while (auto* item = body_layout_->takeAt(0)) {
|
|
|
|
|
if (auto* widget = item->widget()) widget->deleteLater();
|
|
|
|
|
delete item;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Section::addHeaderWidget(QWidget* widget) {
|
|
|
|
|
if (!header_layout_) return;
|
|
|
|
|
header_layout_->addWidget(widget);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Section::isExpanded() const {
|
|
|
|
|
return !toggle_button_ || toggle_button_->isChecked();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Section::setExpanded(bool expanded) {
|
|
|
|
|
if (!toggle_button_) return;
|
|
|
|
|
toggle_button_->setChecked(expanded);
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-10 22:04:03 +10:00
|
|
|
void Section::setBodyExpanding(bool expanding) {
|
|
|
|
|
body_expanding_ = expanding;
|
|
|
|
|
body_->setSizePolicy(QSizePolicy::Preferred, expanding ? QSizePolicy::Expanding : QSizePolicy::Preferred);
|
|
|
|
|
body_layout_->setStretch(0, expanding ? 1 : 0);
|
|
|
|
|
setSizePolicy(QSizePolicy::Preferred,
|
|
|
|
|
expanding && isExpanded() ? QSizePolicy::Expanding : QSizePolicy::Maximum);
|
|
|
|
|
updateGeometry();
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-05 19:59:51 +10:00
|
|
|
} // namespace ifcinterface::components
|