chore: 格式化ElaWidgetTools代码
This commit is contained in:
@@ -4,11 +4,9 @@
|
||||
|
||||
#include <QPainter>
|
||||
#include <QPropertyAnimation>
|
||||
ElaDrawerContainer::ElaDrawerContainer(QWidget* parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
ElaDrawerContainer::ElaDrawerContainer(QWidget *parent) : QWidget(parent) {
|
||||
_pBorderRadius = 6;
|
||||
_pOpacity = 0;
|
||||
_pOpacity = 0;
|
||||
_pContainerPix = QPixmap();
|
||||
setObjectName("ElaDrawerContainer");
|
||||
setStyleSheet("#ElaDrawerContainer{background-color:transparent;}");
|
||||
@@ -28,61 +26,45 @@ ElaDrawerContainer::ElaDrawerContainer(QWidget* parent)
|
||||
_mainLayout->addWidget(_containerWidget);
|
||||
|
||||
_themeMode = eTheme->getThemeMode();
|
||||
connect(eTheme, &ElaTheme::themeModeChanged, this, [=](ElaThemeType::ThemeMode themeMode) {
|
||||
_themeMode = themeMode;
|
||||
});
|
||||
connect(eTheme, &ElaTheme::themeModeChanged, this, [=](ElaThemeType::ThemeMode themeMode) { _themeMode = themeMode; });
|
||||
}
|
||||
|
||||
ElaDrawerContainer::~ElaDrawerContainer()
|
||||
{
|
||||
}
|
||||
ElaDrawerContainer::~ElaDrawerContainer() {}
|
||||
|
||||
void ElaDrawerContainer::addWidget(QWidget* widget)
|
||||
{
|
||||
if (!widget || _drawerWidgetList.contains(widget))
|
||||
{
|
||||
void ElaDrawerContainer::addWidget(QWidget *widget) {
|
||||
if (!widget || _drawerWidgetList.contains(widget)) {
|
||||
return;
|
||||
}
|
||||
_containerLayout->addWidget(widget);
|
||||
_drawerWidgetList.append(widget);
|
||||
}
|
||||
|
||||
void ElaDrawerContainer::removeWidget(QWidget* widget)
|
||||
{
|
||||
if (!widget)
|
||||
{
|
||||
void ElaDrawerContainer::removeWidget(QWidget *widget) {
|
||||
if (!widget) {
|
||||
return;
|
||||
}
|
||||
_containerLayout->removeWidget(widget);
|
||||
_drawerWidgetList.removeOne(widget);
|
||||
}
|
||||
|
||||
void ElaDrawerContainer::doDrawerAnimation(bool isExpand)
|
||||
{
|
||||
if (_containerLayout->count() == 0)
|
||||
{
|
||||
void ElaDrawerContainer::doDrawerAnimation(bool isExpand) {
|
||||
if (_containerLayout->count() == 0) {
|
||||
return;
|
||||
}
|
||||
_containerWidget->setVisible(true);
|
||||
_isShowBorder = true;
|
||||
if (isExpand)
|
||||
{
|
||||
if (isExpand) {
|
||||
setFixedHeight(_calculateContainerMinimumHeight());
|
||||
}
|
||||
_pContainerPix = grab(rect());
|
||||
QPropertyAnimation* opacityAnimation = new QPropertyAnimation(this, "pOpacity");
|
||||
connect(opacityAnimation, &QPropertyAnimation::valueChanged, this, [=](const QVariant& value) {
|
||||
update();
|
||||
});
|
||||
_pContainerPix = grab(rect());
|
||||
QPropertyAnimation *opacityAnimation = new QPropertyAnimation(this, "pOpacity");
|
||||
connect(opacityAnimation, &QPropertyAnimation::valueChanged, this, [=](const QVariant &value) { update(); });
|
||||
connect(opacityAnimation, &QPropertyAnimation::finished, this, [=]() {
|
||||
_pContainerPix = QPixmap();
|
||||
if (isExpand)
|
||||
{
|
||||
if (isExpand) {
|
||||
_containerWidget->setVisible(true);
|
||||
_isShowBorder = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
setFixedHeight(0);
|
||||
}
|
||||
});
|
||||
@@ -95,13 +77,11 @@ void ElaDrawerContainer::doDrawerAnimation(bool isExpand)
|
||||
_isShowBorder = false;
|
||||
}
|
||||
|
||||
void ElaDrawerContainer::paintEvent(QPaintEvent* event)
|
||||
{
|
||||
void ElaDrawerContainer::paintEvent(QPaintEvent *event) {
|
||||
QPainter painter(this);
|
||||
painter.save();
|
||||
painter.setRenderHints(QPainter::Antialiasing);
|
||||
if (_isShowBorder)
|
||||
{
|
||||
if (_isShowBorder) {
|
||||
// 背景绘制
|
||||
painter.setPen(ElaThemeColor(_themeMode, BasicBorder));
|
||||
painter.setBrush(ElaThemeColor(_themeMode, BasicBaseAlpha));
|
||||
@@ -109,26 +89,22 @@ void ElaDrawerContainer::paintEvent(QPaintEvent* event)
|
||||
painter.drawRoundedRect(foregroundRect, _pBorderRadius, _pBorderRadius);
|
||||
// 分割线绘制
|
||||
int drawerHeight = 0;
|
||||
for (int i = 0; i < _drawerWidgetList.count() - 1; i++)
|
||||
{
|
||||
QWidget* drawerWidget = _drawerWidgetList[i];
|
||||
for (int i = 0; i < _drawerWidgetList.count() - 1; i++) {
|
||||
QWidget *drawerWidget = _drawerWidgetList[i];
|
||||
drawerHeight += drawerWidget->height();
|
||||
painter.drawLine(0, drawerHeight, width(), drawerHeight);
|
||||
}
|
||||
}
|
||||
if (!_pContainerPix.isNull())
|
||||
{
|
||||
if (!_pContainerPix.isNull()) {
|
||||
painter.setOpacity(_pOpacity);
|
||||
painter.drawPixmap(QRect(0, -height() * (1 - _pOpacity), width(), height()), _pContainerPix);
|
||||
}
|
||||
painter.restore();
|
||||
}
|
||||
|
||||
int ElaDrawerContainer::_calculateContainerMinimumHeight() const
|
||||
{
|
||||
int ElaDrawerContainer::_calculateContainerMinimumHeight() const {
|
||||
int minimumHeight = 0;
|
||||
for (auto widget: _drawerWidgetList)
|
||||
{
|
||||
for (auto widget : _drawerWidgetList) {
|
||||
minimumHeight += widget->minimumHeight();
|
||||
}
|
||||
minimumHeight = std::max(100, minimumHeight);
|
||||
|
||||
Reference in New Issue
Block a user