Update collapsible group interface for signals/slots

This commit is contained in:
Dan Paulat 2023-06-30 00:12:46 -05:00
parent 1e4e2ba1b4
commit b0375c4790
2 changed files with 15 additions and 21 deletions

View file

@ -15,7 +15,6 @@ public:
~CollapsibleGroupImpl() = default; ~CollapsibleGroupImpl() = default;
void Initialize(); void Initialize();
void SetExpanded(bool expanded);
const QIcon kCollapsedIcon_ { const QIcon kCollapsedIcon_ {
":/res/icons/font-awesome-6/square-caret-right-regular.svg"}; ":/res/icons/font-awesome-6/square-caret-right-regular.svg"};
@ -60,10 +59,10 @@ void CollapsibleGroupImpl::Initialize()
self_->ui->titleButton, self_->ui->titleButton,
&QAbstractButton::clicked, &QAbstractButton::clicked,
self_, self_,
[this]() { SetExpanded(!expanded_); }, [this]() { self_->SetExpanded(!expanded_); },
Qt::DirectConnection); Qt::DirectConnection);
self_->Expand(); self_->SetExpanded(true);
} }
QLayout* CollapsibleGroup::GetContentsLayout() QLayout* CollapsibleGroup::GetContentsLayout()
@ -81,28 +80,21 @@ void CollapsibleGroup::SetTitle(const QString& title)
ui->titleButton->setText(title); ui->titleButton->setText(title);
} }
void CollapsibleGroup::Collapse() void CollapsibleGroup::SetExpanded(bool expanded)
{
// Update the title frame
p->SetExpanded(false);
}
void CollapsibleGroup::Expand()
{
// Update the title frame
p->SetExpanded(true);
}
void CollapsibleGroupImpl::SetExpanded(bool expanded)
{ {
// Update icon // Update icon
self_->ui->titleButton->setIcon(kIcon_.at(expanded)); ui->titleButton->setIcon(p->kIcon_.at(expanded));
// Update contents visibility // Update contents visibility
self_->ui->contentsFrame->setVisible(expanded); ui->contentsFrame->setVisible(expanded);
// Update internal state // Update internal state
expanded_ = expanded; if (p->expanded_ != expanded)
{
p->expanded_ = expanded;
Q_EMIT StateChanged(expanded);
}
} }
} // namespace ui } // namespace ui

View file

@ -30,8 +30,10 @@ public:
void SetTitle(const QString& title); void SetTitle(const QString& title);
public slots: public slots:
void Collapse(); void SetExpanded(bool expanded);
void Expand();
signals:
void StateChanged(bool expanded);
private: private:
friend class CollapsibleGroupImpl; friend class CollapsibleGroupImpl;