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

@@ -6,51 +6,37 @@
#include <QStyleOption>
#include "ElaTheme.h"
ElaTabBarStyle::ElaTabBarStyle(QStyle* style)
{
ElaTabBarStyle::ElaTabBarStyle(QStyle *style) {
_themeMode = eTheme->getThemeMode();
connect(eTheme, &ElaTheme::themeModeChanged, this, [=](ElaThemeType::ThemeMode themeMode) {
_themeMode = themeMode;
});
connect(eTheme, &ElaTheme::themeModeChanged, this, [=](ElaThemeType::ThemeMode themeMode) { _themeMode = themeMode; });
}
ElaTabBarStyle::~ElaTabBarStyle()
{
}
ElaTabBarStyle::~ElaTabBarStyle() {}
void ElaTabBarStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption* opt, QPainter* p, const QWidget* w) const
{
void ElaTabBarStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p, const QWidget *w) const {
// qDebug() << pe << opt->rect;
switch (pe)
{
case QStyle::PE_FrameTabBarBase:
{
//底边线
switch (pe) {
case QStyle::PE_FrameTabBarBase: {
// 底边线
return;
}
case QStyle::PE_IndicatorArrowLeft:
{
case QStyle::PE_IndicatorArrowLeft: {
return;
}
case QStyle::PE_IndicatorArrowRight:
{
case QStyle::PE_IndicatorArrowRight: {
return;
}
case QStyle::PE_PanelButtonTool:
{
//左侧隐藏图标
case QStyle::PE_PanelButtonTool: {
// 左侧隐藏图标
return;
}
case QStyle::PE_IndicatorTabTear:
{
case QStyle::PE_IndicatorTabTear: {
return;
}
case QStyle::PE_IndicatorTabClose:
{
case QStyle::PE_IndicatorTabClose: {
p->save();
p->setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing);
if (opt->state.testFlag(QStyle::State_MouseOver))
{
if (opt->state.testFlag(QStyle::State_MouseOver)) {
p->setPen(Qt::NoPen);
p->setBrush(ElaThemeColor(_themeMode, BasicHoverAlpha));
p->drawRoundedRect(opt->rect, 2, 2);
@@ -63,32 +49,26 @@ void ElaTabBarStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption* opt,
p->restore();
return;
}
default:
{
default: {
break;
}
}
QProxyStyle::drawPrimitive(pe, opt, p, w);
}
void ElaTabBarStyle::drawControl(ControlElement element, const QStyleOption* option, QPainter* painter, const QWidget* widget) const
{
int margin = 9;
void ElaTabBarStyle::drawControl(ControlElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const {
int margin = 9;
int topRadius = 7;
switch (element)
{
case QStyle::CE_TabBarTabShape:
{
//背景绘制
if (const QStyleOptionTab* topt = qstyleoption_cast<const QStyleOptionTab*>(option))
{
switch (element) {
case QStyle::CE_TabBarTabShape: {
// 背景绘制
if (const QStyleOptionTab *topt = qstyleoption_cast<const QStyleOptionTab *>(option)) {
QRect tabRect = topt->rect;
painter->save();
painter->setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing);
painter->setPen(Qt::NoPen);
if (topt->state.testFlag(QStyle::State_Selected))
{
//选中背景绘制
if (topt->state.testFlag(QStyle::State_Selected)) {
// 选中背景绘制
tabRect.setLeft(tabRect.left() - margin);
tabRect.setRight(tabRect.right() + margin + 1);
painter->setBrush(ElaThemeColor(_themeMode, BasicSelectedAlpha));
@@ -109,15 +89,10 @@ void ElaTabBarStyle::drawControl(ControlElement element, const QStyleOption* opt
painter->setPen(Qt::NoPen);
painter->setBrush(ElaThemeColor(_themeMode, PrimaryNormal));
painter->drawRoundedRect(QRectF(tabRect.left() + margin + 7, tabRect.y() + 7, 3, tabRect.height() - 14), 2, 2);
}
else
{
if (topt->state.testFlag(QStyle::State_MouseOver))
{
} else {
if (topt->state.testFlag(QStyle::State_MouseOver)) {
painter->setBrush(ElaThemeColor(_themeMode, BasicHoverAlpha));
}
else
{
} else {
painter->setBrush(Qt::transparent);
}
tabRect.setHeight(tabRect.height() + 10);
@@ -128,36 +103,29 @@ void ElaTabBarStyle::drawControl(ControlElement element, const QStyleOption* opt
return;
}
}
case QStyle::CE_TabBarTabLabel:
{
//文字和图标绘制
if (const QStyleOptionTab* topt = qstyleoption_cast<const QStyleOptionTab*>(option))
{
case QStyle::CE_TabBarTabLabel: {
// 文字和图标绘制
if (const QStyleOptionTab *topt = qstyleoption_cast<const QStyleOptionTab *>(option)) {
QRect textRect = subElementRect(QStyle::SE_TabBarTabText, topt, widget);
textRect.setLeft(textRect.left() + 10);
painter->save();
painter->setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform);
//图标绘制
// 图标绘制
QIcon icon = topt->icon;
if (!icon.isNull())
{
QRectF iconRect(topt->rect.x() + 15, textRect.center().y() - (qreal)topt->iconSize.height() / 2 + 1, topt->iconSize.width(), topt->iconSize.height());
if (!icon.isNull()) {
QRectF iconRect(topt->rect.x() + 15, textRect.center().y() - (qreal)topt->iconSize.height() / 2 + 1, topt->iconSize.width(),
topt->iconSize.height());
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
QPixmap iconPix = icon.pixmap(topt->iconSize, painter->device()->devicePixelRatio(),
(topt->state & State_Enabled) ? QIcon::Normal
: QIcon::Disabled,
(topt->state & State_Selected) ? QIcon::On
: QIcon::Off);
(topt->state & State_Enabled) ? QIcon::Normal : QIcon::Disabled,
(topt->state & State_Selected) ? QIcon::On : QIcon::Off);
#else
QPixmap iconPix = icon.pixmap(topt->iconSize,
(topt->state & State_Enabled) ? QIcon::Normal
: QIcon::Disabled,
(topt->state & State_Selected) ? QIcon::On
: QIcon::Off);
QPixmap iconPix = icon.pixmap(topt->iconSize, (topt->state & State_Enabled) ? QIcon::Normal : QIcon::Disabled,
(topt->state & State_Selected) ? QIcon::On : QIcon::Off);
#endif
painter->drawPixmap(iconRect.x(), iconRect.y(), iconPix);
}
//文字绘制
// 文字绘制
painter->setPen(ElaThemeColor(_themeMode, BasicText));
QString text = painter->fontMetrics().elidedText(topt->text, Qt::ElideRight, textRect.width());
painter->drawText(textRect, Qt::AlignLeft | Qt::AlignVCenter | Qt::TextDontClip, text);
@@ -165,8 +133,7 @@ void ElaTabBarStyle::drawControl(ControlElement element, const QStyleOption* opt
return;
}
}
default:
{
default: {
break;
}
}
@@ -174,33 +141,25 @@ void ElaTabBarStyle::drawControl(ControlElement element, const QStyleOption* opt
QProxyStyle::drawControl(element, option, painter, widget);
}
QSize ElaTabBarStyle::sizeFromContents(ContentsType type, const QStyleOption* option, const QSize& size, const QWidget* widget) const
{
switch (type)
{
case CT_TabBarTab:
{
QSize ElaTabBarStyle::sizeFromContents(ContentsType type, const QStyleOption *option, const QSize &size, const QWidget *widget) const {
switch (type) {
case CT_TabBarTab: {
return QSize(220, 35);
}
default:
{
default: {
break;
}
}
return QProxyStyle::sizeFromContents(type, option, size, widget);
}
QRect ElaTabBarStyle::subElementRect(SubElement element, const QStyleOption* option, const QWidget* widget) const
{
switch (element)
{
QRect ElaTabBarStyle::subElementRect(SubElement element, const QStyleOption *option, const QWidget *widget) const {
switch (element) {
case QStyle::SE_TabBarScrollLeftButton:
case QStyle::SE_TabBarScrollRightButton:
{
case QStyle::SE_TabBarScrollRightButton: {
return QRect();
}
default:
{
default: {
break;
}
}