The inspector's width bounds were 75-100 average character widths, which on macOS (8 px) came to 600 px for content that needs 397. They are now measured: at least the panel's minimum size hint plus the scroll bar, at most a third more. CollapsibleSection reports its folded content's width in minimumSizeHint, so the panel keeps its width when a section opens. On a font change the measurement waits a turn, until the children have the new font. When shrinking the window would leave the image narrower than the inspector, the inspector folds away, with the magnifier if it shares the inspector's column; they come back once the image would still be at least as wide as the inspector (plus 40 px of hysteresis). Only a shrink folds, a dock shown by anyone else is no longer the window's to restore, and folded docks are saved as open. Measured on a 1920 px screen: folds at 1140 px, returns at 1260 px; at 960 px the image gets 620 px instead of ~145. Dark theme: disabled text is set explicitly (#858AAE, ~4.8:1 on the panels) instead of the derived colour, which was nearly the panel colour and made greyed-out fields look empty. The splash text is black in either theme: its message is rich text, which takes the palette's text colour rather than showMessage's. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
56 lines
1.9 KiB
C++
56 lines
1.9 KiB
C++
// SPDX-FileCopyrightText: 2026 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
#include "CollapsibleSection.h"
|
|
#include "../ViewerTheme.h"
|
|
|
|
#include <algorithm>
|
|
#include <QToolButton>
|
|
#include <QVBoxLayout>
|
|
|
|
CollapsibleSection::CollapsibleSection(const QString &title, QWidget *parent) : QWidget(parent) {
|
|
auto *v = new QVBoxLayout(this);
|
|
v->setContentsMargins(0, 0, 0, 0);
|
|
v->setSpacing(0);
|
|
|
|
header_ = new QToolButton(this);
|
|
header_->setText(title);
|
|
header_->setCheckable(true);
|
|
header_->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
|
|
header_->setArrowType(Qt::RightArrow);
|
|
header_->setCursor(Qt::PointingHandCursor);
|
|
header_->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
|
SetThemedStyleSheet(header_, [] {
|
|
return QString("QToolButton { color:%1; font-weight:bold; text-align:left;"
|
|
" padding:3px 6px 3px 6px; border:none;"
|
|
" border-left:3px solid #FA7268; border-bottom:1px solid #FA7268; background:transparent; }")
|
|
.arg(AccentTextColor().name());
|
|
});
|
|
|
|
content_ = new QWidget(this);
|
|
content_->setVisible(false);
|
|
|
|
v->addWidget(header_);
|
|
v->addWidget(content_);
|
|
|
|
connect(header_, &QToolButton::toggled, this, [this](bool on) {
|
|
content_->setVisible(on);
|
|
header_->setArrowType(on ? Qt::DownArrow : Qt::RightArrow);
|
|
});
|
|
}
|
|
|
|
void CollapsibleSection::setContentLayout(QLayout *layout) {
|
|
content_->setLayout(layout);
|
|
}
|
|
|
|
void CollapsibleSection::setExpanded(bool on) {
|
|
header_->setChecked(on);
|
|
}
|
|
|
|
QSize CollapsibleSection::minimumSizeHint() const {
|
|
// A hidden widget does not count towards its parent's layout, so the folded content is measured here.
|
|
QSize s = QWidget::minimumSizeHint();
|
|
s.setWidth(std::max(s.width(), content_->minimumSizeHint().width()));
|
|
return s;
|
|
}
|