#include "monitorToolPage.h" #include #include #include #include #include #include MonitorToolPage::MonitorToolPage(QWidget *parent) : QWidget(parent), m_bIsExpanded(true), m_pLabel(nullptr), m_pPushButtonFold(nullptr), m_pContent(nullptr) { setAttribute(Qt::WA_StyledBackground); m_pPushButtonFold = new QPushButton(this); m_pLabel = new QLabel(this); m_pLabel->setFixedSize(20, 20); m_pLabel->setText("+"); QHBoxLayout *hLayout = new QHBoxLayout(m_pPushButtonFold); QVBoxLayout *vLayout = new QVBoxLayout(this); vLayout->setContentsMargins(0, 0, 0, 0); vLayout->setSpacing(2); vLayout->addWidget(m_pPushButtonFold); hLayout->setContentsMargins(0, 0, 5, 0); hLayout->addStretch(1); hLayout->addWidget(m_pLabel); connect(m_pPushButtonFold, &QPushButton::clicked, this, &MonitorToolPage::onPushButtonFoldClicked); } MonitorToolPage::~MonitorToolPage() { if(m_pContent) delete m_pContent; if(m_pPushButtonFold) delete m_pPushButtonFold; } void MonitorToolPage::addWidget(const QString &title, QWidget *widget) { if(!m_pContent) { m_pPushButtonFold->setText(title); layout()->addWidget(widget); m_pContent = widget; } } void MonitorToolPage::expand() { if(m_pContent) m_pContent->show(); m_bIsExpanded = true; m_pLabel->setText("-"); } void MonitorToolPage::collapse() { if(m_pContent) m_pContent->hide(); m_bIsExpanded = false; m_pLabel->setText("+"); } void MonitorToolPage::onPushButtonFoldClicked() { if (m_bIsExpanded) { collapse(); } else { expand(); } }