78 lines
2.0 KiB
C++
78 lines
2.0 KiB
C++
|
|
#include "ToolPage.h"
|
||
|
|
|
||
|
|
#include <QDebug>
|
||
|
|
#include <QFormLayout>
|
||
|
|
#include <QHBoxLayout>
|
||
|
|
#include <QVBoxLayout>
|
||
|
|
#include <QLabel>
|
||
|
|
#include <QPushButton>
|
||
|
|
|
||
|
|
ToolPage::ToolPage(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->setPixmap(QPixmap(":/images/icon_down_arrow.png").scaled(m_pLabel->size(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
|
||
|
|
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, &ToolPage::onPushButtonFoldClicked);
|
||
|
|
}
|
||
|
|
|
||
|
|
ToolPage::~ToolPage()
|
||
|
|
{
|
||
|
|
if(m_pContent)
|
||
|
|
delete m_pContent;
|
||
|
|
if(m_pPushButtonFold)
|
||
|
|
delete m_pPushButtonFold;
|
||
|
|
}
|
||
|
|
|
||
|
|
void ToolPage::addWidget(const QString &title, QWidget *widget)
|
||
|
|
{
|
||
|
|
if(!m_pContent)
|
||
|
|
{
|
||
|
|
m_pPushButtonFold->setText(title);
|
||
|
|
layout()->addWidget(widget);
|
||
|
|
m_pContent = widget;
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
void ToolPage::expand()
|
||
|
|
{
|
||
|
|
if(m_pContent)
|
||
|
|
m_pContent->show();
|
||
|
|
m_bIsExpanded = true;
|
||
|
|
m_pLabel->setPixmap(QPixmap(":/images/icon_down_arrow.png").scaled(m_pLabel->size(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
|
||
|
|
}
|
||
|
|
|
||
|
|
void ToolPage::collapse()
|
||
|
|
{
|
||
|
|
if(m_pContent)
|
||
|
|
m_pContent->hide();
|
||
|
|
m_bIsExpanded = false;
|
||
|
|
m_pLabel->setPixmap(QPixmap(":/images/icon_left_arrow.png").scaled(m_pLabel->size(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
|
||
|
|
}
|
||
|
|
|
||
|
|
void ToolPage::onPushButtonFoldClicked()
|
||
|
|
{
|
||
|
|
if (m_bIsExpanded) {
|
||
|
|
collapse();
|
||
|
|
} else {
|
||
|
|
expand();
|
||
|
|
}
|
||
|
|
}
|