Skip to content

Commit

Permalink
Align properties in different categories.
Browse files Browse the repository at this point in the history
  • Loading branch information
leozide committed Dec 31, 2023
1 parent ef43c15 commit 8eec575
Show file tree
Hide file tree
Showing 5 changed files with 266 additions and 190 deletions.
98 changes: 58 additions & 40 deletions common/lc_collapsiblewidget.cpp
Original file line number Diff line number Diff line change
@@ -1,55 +1,29 @@
#include "lc_global.h"
#include "lc_collapsiblewidget.h"

QImage lcCollapsibleWidget::mExpandedIcon;
QImage lcCollapsibleWidget::mCollapsedIcon;
QImage lcCollapsibleWidgetButton::mExpandedIcon;
QImage lcCollapsibleWidgetButton::mCollapsedIcon;

lcCollapsibleWidget::lcCollapsibleWidget(const QString& Title, QWidget* Parent)
: QWidget(Parent)
lcCollapsibleWidgetButton::lcCollapsibleWidgetButton(const QString& Title, QWidget* Parent)
: QToolButton(Parent)
{
QVBoxLayout* Layout = new QVBoxLayout(this);
// Layout->setSpacing(0);
Layout->setContentsMargins(0, 0, 0, 0);

QHBoxLayout* TitleLayout = new QHBoxLayout();
TitleLayout->setContentsMargins(0, 0, 0, 0);
Layout->addLayout(TitleLayout);

mTitleButton = new QToolButton(this);
mTitleButton->setText(Title);
mTitleButton->setAutoRaise(true);
mTitleButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
mTitleButton->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Maximum);
TitleLayout->addWidget(mTitleButton);

connect(mTitleButton, SIGNAL(clicked()), this, SLOT(TitleClicked()));

mChildWidget = new QWidget(this);
Layout->addWidget(mChildWidget);
setText(Title);
setAutoRaise(true);
setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Maximum);

UpdateIcon();
}

void lcCollapsibleWidget::TitleClicked()
{
mExpanded = !mExpanded;
mChildWidget->setVisible(mExpanded);
UpdateIcon();
connect(this, &QToolButton::clicked, this, &lcCollapsibleWidgetButton::Clicked);
}

void lcCollapsibleWidget::Collapse()
void lcCollapsibleWidgetButton::Collapse()
{
if (mExpanded)
TitleClicked();
}

void lcCollapsibleWidget::SetChildLayout(QLayout* Layout)
{
Layout->setContentsMargins(12, 0, 0, 0);
mChildWidget->setLayout(Layout);
Clicked();
}

void lcCollapsibleWidget::UpdateIcon()
void lcCollapsibleWidgetButton::UpdateIcon()
{
if (mExpanded)
{
Expand All @@ -66,7 +40,7 @@ void lcCollapsibleWidget::UpdateIcon()
mExpandedIcon = Image;
}

mTitleButton->setIcon(QPixmap::fromImage(mExpandedIcon));
setIcon(QPixmap::fromImage(mExpandedIcon));
}
else
{
Expand All @@ -83,6 +57,50 @@ void lcCollapsibleWidget::UpdateIcon()
mCollapsedIcon = Image;
}

mTitleButton->setIcon(QPixmap::fromImage(mCollapsedIcon));
setIcon(QPixmap::fromImage(mCollapsedIcon));
}
}

void lcCollapsibleWidgetButton::Clicked()
{
mExpanded = !mExpanded;
UpdateIcon();

emit StateChanged(mExpanded);
}

lcCollapsibleWidget::lcCollapsibleWidget(const QString& Title, QWidget* Parent)
: QWidget(Parent)
{
QVBoxLayout* Layout = new QVBoxLayout(this);
// Layout->setSpacing(0);
Layout->setContentsMargins(0, 0, 0, 0);

QHBoxLayout* TitleLayout = new QHBoxLayout();
TitleLayout->setContentsMargins(0, 0, 0, 0);
Layout->addLayout(TitleLayout);

mTitleButton = new lcCollapsibleWidgetButton(Title, this);
TitleLayout->addWidget(mTitleButton);

connect(mTitleButton, &lcCollapsibleWidgetButton::StateChanged, this, &lcCollapsibleWidget::ButtonStateChanged);

mChildWidget = new QWidget(this);
Layout->addWidget(mChildWidget);
}

void lcCollapsibleWidget::ButtonStateChanged(bool Expanded)
{
mChildWidget->setVisible(Expanded);
}

void lcCollapsibleWidget::Collapse()
{
mTitleButton->Collapse();
}

void lcCollapsibleWidget::SetChildLayout(QLayout* Layout)
{
Layout->setContentsMargins(12, 0, 0, 0);
mChildWidget->setLayout(Layout);
}
30 changes: 24 additions & 6 deletions common/lc_collapsiblewidget.h
Original file line number Diff line number Diff line change
@@ -1,25 +1,43 @@
#pragma once

class lcCollapsibleWidget : public QWidget
class lcCollapsibleWidgetButton : public QToolButton
{
Q_OBJECT

public:
lcCollapsibleWidget(const QString& RootTitle, QWidget* Parent = nullptr);
lcCollapsibleWidgetButton(const QString& Title, QWidget* Parent = nullptr);

void Collapse();
void SetChildLayout(QLayout* Layout);

signals:
void StateChanged(bool Expanded);

protected slots:
void TitleClicked();
void Clicked();

protected:
void UpdateIcon();

QToolButton* mTitleButton = nullptr;
QWidget* mChildWidget = nullptr;
bool mExpanded = true;

static QImage mExpandedIcon;
static QImage mCollapsedIcon;
};

class lcCollapsibleWidget : public QWidget
{
Q_OBJECT

public:
lcCollapsibleWidget(const QString& RootTitle, QWidget* Parent = nullptr);

void Collapse();
void SetChildLayout(QLayout* Layout);

protected slots:
void ButtonStateChanged(bool Expanded);

protected:
lcCollapsibleWidgetButton* mTitleButton = nullptr;
QWidget* mChildWidget = nullptr;
};
Loading

0 comments on commit 8eec575

Please sign in to comment.