chore: 格式化ElaWidgetTools代码

This commit is contained in:
sleepwithoutbz
2025-09-20 01:39:00 +08:00
parent d2fded145d
commit 4ab391f8a1
394 changed files with 10913 additions and 15860 deletions

View File

@@ -8,9 +8,7 @@
#include "ElaTheme.h"
#include "ElaToolBarPrivate.h"
#include "ElaToolBarStyle.h"
ElaToolBar::ElaToolBar(QWidget* parent)
: QToolBar(parent), d_ptr(new ElaToolBarPrivate())
{
ElaToolBar::ElaToolBar(QWidget *parent) : QToolBar(parent), d_ptr(new ElaToolBarPrivate()) {
Q_D(ElaToolBar);
d->q_ptr = this;
setObjectName("ElaToolBar");
@@ -21,58 +19,39 @@ ElaToolBar::ElaToolBar(QWidget* parent)
d->_themeMode = eTheme->getThemeMode();
connect(eTheme, &ElaTheme::themeModeChanged, this, [=](ElaThemeType::ThemeMode themeMode) {
d->_themeMode = themeMode;
if (this->isFloating())
{
if (this->isFloating()) {
update();
}
});
setAttribute(Qt::WA_TranslucentBackground);
connect(this, &ElaToolBar::topLevelChanged, this, [=](bool topLevel) {
if (topLevel)
{
if (topLevel) {
layout()->setContentsMargins(d->_shadowBorderWidth + 3, d->_shadowBorderWidth + 3, d->_shadowBorderWidth + 3, d->_shadowBorderWidth + 3);
}
else
{
} else {
layout()->setContentsMargins(3, 3, 3, 3);
}
});
}
ElaToolBar::ElaToolBar(const QString& title, QWidget* parent)
: ElaToolBar(parent)
{
setWindowTitle(title);
}
ElaToolBar::ElaToolBar(const QString &title, QWidget *parent) : ElaToolBar(parent) { setWindowTitle(title); }
ElaToolBar::~ElaToolBar()
{
delete this->style();
}
ElaToolBar::~ElaToolBar() { delete this->style(); }
void ElaToolBar::setToolBarSpacing(int spacing)
{
layout()->setSpacing(spacing);
}
void ElaToolBar::setToolBarSpacing(int spacing) { layout()->setSpacing(spacing); }
int ElaToolBar::getToolBarSpacing() const
{
return layout()->spacing();
}
int ElaToolBar::getToolBarSpacing() const { return layout()->spacing(); }
QAction* ElaToolBar::addElaIconAction(ElaIconType::IconName icon, const QString& text)
{
QAction* action = new QAction(text, this);
QAction *ElaToolBar::addElaIconAction(ElaIconType::IconName icon, const QString &text) {
QAction *action = new QAction(text, this);
action->setProperty("ElaIconType", QChar((unsigned short)icon));
action->setIcon(ElaIcon::getInstance()->getElaIcon(ElaIconType::Broom, 1));
addAction(action);
return action;
}
QAction* ElaToolBar::addElaIconAction(ElaIconType::IconName icon, const QString& text, const QKeySequence& shortcut)
{
QAction* action = new QAction(text, this);
QAction *ElaToolBar::addElaIconAction(ElaIconType::IconName icon, const QString &text, const QKeySequence &shortcut) {
QAction *action = new QAction(text, this);
action->setShortcut(shortcut);
action->setProperty("ElaIconType", QChar((unsigned short)icon));
action->setIcon(ElaIcon::getInstance()->getElaIcon(ElaIconType::Broom, 1));
@@ -80,32 +59,27 @@ QAction* ElaToolBar::addElaIconAction(ElaIconType::IconName icon, const QString&
return action;
}
void ElaToolBar::paintEvent(QPaintEvent* event)
{
void ElaToolBar::paintEvent(QPaintEvent *event) {
Q_D(ElaToolBar);
QPainter painter(this);
painter.save();
painter.setRenderHints(QPainter::Antialiasing);
if (isFloating())
{
if (isFloating()) {
// 高性能阴影
eTheme->drawEffectShadow(&painter, rect(), d->_shadowBorderWidth, 6);
//背景
// 背景
painter.setPen(ElaThemeColor(d->_themeMode, PopupBorder));
painter.setBrush(ElaThemeColor(d->_themeMode, DialogBase));
QRect foregroundRect(d->_shadowBorderWidth, d->_shadowBorderWidth, width() - 2 * d->_shadowBorderWidth, height() - 2 * d->_shadowBorderWidth);
painter.drawRoundedRect(foregroundRect, 5, 5);
QStyle* style = this->style();
QStyle *style = this->style();
QStyleOptionToolBar opt;
initStyleOption(&opt);
opt.rect = style->subElementRect(QStyle::SE_ToolBarHandle, &opt, this);
if (opt.rect.isValid())
{
if (opt.rect.isValid()) {
style->drawPrimitive(QStyle::PE_IndicatorToolBarHandle, &opt, &painter, this);
}
}
else
{
} else {
painter.setPen(Qt::NoPen);
painter.setBrush(Qt::transparent);
painter.drawRoundedRect(rect(), 5, 5);