#include "extendedgroupbox.h"
ExtendedGroupBox::ExtendedGroupBox(QWidget *parent /*= nullptr*/, State state /*= STATE_NORMAL*/)
    : QGroupBox(parent)
{
    setCheckable(true);
    state_ = state;
    if (state_ == STATE_NORMAL)
    {
        //隐藏垂直边框
        setFlat(true);
    }
    connect(this, SIGNAL(clicked(bool)), this, SLOT(onChecked(bool)));
}

ExtendedGroupBox::ExtendedGroupBox(const QString &title, QWidget *parent /*= nullptr*/, State state /*= STATE_NORMAL*/)
    : QGroupBox(title, parent)
{
    setCheckable(true);
    state_ = state;
    if (state_ == STATE_NORMAL)
    {
        //隐藏垂直边框
        setFlat(true);
    }
  //  this->toggled();

    connect(this, SIGNAL(toggled(bool)), this, SLOT(onChecked(bool)));
}


void ExtendedGroupBox::onChecked(bool checked)
{
    if (checked)
    {
        //显示垂直边框
        QList<QWidget *> widgets = findChildren<QWidget *>();
        for (auto iter = widgets.begin(); iter != widgets.end(); ++iter)
        {
            (*iter)->setVisible(true);
        }
        state_ = STATE_EXPAND;
    }
    else
    {
        //隐藏垂直边框
        QList<QWidget *> widgets = findChildren<QWidget *>();
        for (auto iter = widgets.begin(); iter != widgets.end(); ++iter)
            (*iter)->setVisible(false);
//        QList<QLayout *> layouts = findChildren<QLayout *>();
//        for (auto iter1 = layouts.begin(); iter1 != layouts.end(); ++iter1)
//            (*iter1)->setVisible(false);

//        QLayout aa;
//        a->
        state_ = STATE_NORMAL;
    }
}

ExtendedGroupBox::State ExtendedGroupBox::getState() const
{
    return state_;
}
