From 6e7056feb07ee9605824df2ae67d76513082535e Mon Sep 17 00:00:00 2001 From: deepin-ci-robot Date: Fri, 25 Oct 2024 08:07:25 +0000 Subject: [PATCH] sync: from linuxdeepin/dtkwidget Synchronize source files from linuxdeepin/dtkwidget. Source-pull-request: https://github.com/linuxdeepin/dtkwidget/pull/614 --- include/widgets/dstyle.h | 11 ++- src/widgets/dbuttonbox.cpp | 45 +++++++--- src/widgets/dfloatingmessage.cpp | 31 +++++-- src/widgets/dindeterminateprogressbar.cpp | 23 ++++- src/widgets/dlistview.cpp | 2 +- src/widgets/dmessagemanager.cpp | 103 ++++++++++++++++------ src/widgets/dsearchedit.cpp | 79 ++++++++++------- src/widgets/dstyle.cpp | 54 ++++++++---- src/widgets/dswitchbutton.cpp | 12 ++- 9 files changed, 255 insertions(+), 105 deletions(-) diff --git a/include/widgets/dstyle.h b/include/widgets/dstyle.h index 75573379..d947138c 100644 --- a/include/widgets/dstyle.h +++ b/include/widgets/dstyle.h @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -19,9 +20,17 @@ QT_BEGIN_NAMESPACE class QTextLayout; QT_END_NAMESPACE +#define ENABLE_ANIMATIONS DGuiApplicationHelper::testAttribute(DGuiApplicationHelper::HasAnimations) +#define ENABLE_ANIMATION_BUTTONBOX (!qEnvironmentVariableIsSet("DTK_DISABLE_ANIMATION_BUTTONBOX")) +#define ENABLE_ANIMATION_MESSAGE (!qEnvironmentVariableIsSet("DTK_DISABLE_ANIMATION_MESSAGE")) +#define ENABLE_ANIMATION_LISTVIEWBOUNCE (!qEnvironmentVariableIsSet("DTK_DISABLE_ANIMATION_LISTVIREBOUNCE")) +#define ENABLE_ANIMATION_SEARCH (!qEnvironmentVariableIsSet("DTK_DISABLE_ANIMATION_SEARCH")) +#define ENABLE_ANIMATION_SWITCHBUTTON (!qEnvironmentVariableIsSet("DTK_DISABLE_ANIMATION_SWITCHBUTTON")) +#define ENABLE_ANIMATION_PROGRESSBAR (!qEnvironmentVariableIsSet("DTK_DISABLE_ANIMATION_PROGRESSBAR")) +#define ENABLE_ANIMATION_RADIOBUTTON (!qEnvironmentVariableIsSet("DTK_DISABLE_ANIMATION_RADIOBUTTON")) +#define ENABLE_ANIMATION_CHECKBOX (!qEnvironmentVariableIsSet("DTK_DISABLE_ANIMATION_CHECKBOX")) DWIDGET_BEGIN_NAMESPACE - DGUI_USE_NAMESPACE namespace DDrawUtils diff --git a/src/widgets/dbuttonbox.cpp b/src/widgets/dbuttonbox.cpp index d90cf735..50505773 100644 --- a/src/widgets/dbuttonbox.cpp +++ b/src/widgets/dbuttonbox.cpp @@ -299,7 +299,10 @@ void DButtonBoxButton::paintEvent(QPaintEvent *e) DStylePainter p(this); DStyleOptionButtonBoxButton option; initStyleOption(&option); - option.palette.setColor(QPalette::HighlightedText, this->palette().highlight().color()); + + if (ENABLE_ANIMATIONS && ENABLE_ANIMATION_BUTTONBOX) + option.palette.setColor(QPalette::HighlightedText, this->palette().highlight().color()); + p.drawControl(DStyle::CE_ButtonBoxButton, option); } @@ -363,10 +366,13 @@ DButtonBoxPrivate::DButtonBoxPrivate(DButtonBox *qq) , m_hoverId(-1) , m_checkedId(-1) , m_pressId(-1) - , m_hoverAnimation(new QVariantAnimation(qq)) - , m_checkMoveAnimation(new QVariantAnimation(qq)) + , m_hoverAnimation(nullptr) + , m_checkMoveAnimation(nullptr) { - + if (ENABLE_ANIMATIONS && ENABLE_ANIMATION_BUTTONBOX) { + m_hoverAnimation = new QVariantAnimation(qq); + m_checkMoveAnimation = new QVariantAnimation(qq); + } } void DButtonBoxPrivate::init() @@ -380,14 +386,17 @@ void DButtonBoxPrivate::init() q->connect(group, SIGNAL(buttonPressed(QAbstractButton*)), q, SIGNAL(buttonPressed(QAbstractButton*))); q->connect(group, SIGNAL(buttonReleased(QAbstractButton*)), q, SIGNAL(buttonReleased(QAbstractButton*))); q->connect(group, SIGNAL(buttonToggled(QAbstractButton*, bool)), q, SIGNAL(buttonToggled(QAbstractButton*, bool))); - q->connect(m_hoverAnimation, &QVariantAnimation::valueChanged, q, [q]() { - q->update(); - }); - q->connect(m_checkMoveAnimation, &QVariantAnimation::valueChanged, q, [q]() { - q->update(); - }); - m_hoverAnimation->setDuration(HOVER_ANI_DURATION); - m_checkMoveAnimation->setDuration(CHECK_ANI_DURATION); + + if (ENABLE_ANIMATIONS && ENABLE_ANIMATION_BUTTONBOX) { + q->connect(m_hoverAnimation, &QVariantAnimation::valueChanged, q, [q]() { + q->update(); + }); + q->connect(m_checkMoveAnimation, &QVariantAnimation::valueChanged, q, [q]() { + q->update(); + }); + m_hoverAnimation->setDuration(HOVER_ANI_DURATION); + m_checkMoveAnimation->setDuration(CHECK_ANI_DURATION); + } layout = new QHBoxLayout(q); layout->setContentsMargins(0, 0, 0, 0); @@ -506,7 +515,9 @@ void DButtonBox::setButtonList(const QList &list, bool check d->group->addButton(button); button->setCheckable(checkable); - button->installEventFilter(this); + + if (ENABLE_ANIMATIONS && ENABLE_ANIMATION_BUTTONBOX) + button->installEventFilter(this); } } @@ -616,6 +627,11 @@ void DButtonBox::paintEvent(QPaintEvent *e) opt.state |= QStyle::State_Active; } + if (!ENABLE_ANIMATIONS || !ENABLE_ANIMATION_BUTTONBOX) { + p.drawControl(QStyle::CE_PushButtonBevel, opt); + return; + } + bool isDarkType = DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::DarkType; int radius = DStyle::pixelMetric(style(), DStyle::PM_FrameRadius); QColor background; @@ -706,6 +722,9 @@ void DButtonBox::paintEvent(QPaintEvent *e) bool DButtonBox::eventFilter(QObject *o, QEvent *e) { + if (!ENABLE_ANIMATIONS || !ENABLE_ANIMATION_BUTTONBOX) + return QWidget::eventFilter(o, e); + D_D(DButtonBox); for (int i = 0; i < buttonList().size(); ++i) { if (o == buttonList().at(i)) { diff --git a/src/widgets/dfloatingmessage.cpp b/src/widgets/dfloatingmessage.cpp index c581f289..fd3aaa48 100644 --- a/src/widgets/dfloatingmessage.cpp +++ b/src/widgets/dfloatingmessage.cpp @@ -55,17 +55,23 @@ void DFloatingMessagePrivate::init() iconButton->setIconSize(DSizeModeHelper::element(QSize(20, 20), QSize(30, 30))); hBoxLayout->addWidget(iconButton); - hBoxLayout->addSpacing(10); + + if (ENABLE_ANIMATIONS && ENABLE_ANIMATION_MESSAGE) + hBoxLayout->addSpacing(10); + hBoxLayout->addWidget(labMessage); if (notifyType == DFloatingMessage::MessageType::TransientType) { //临时消息 timer = new QTimer(q); timer->setInterval(4000); timer->setSingleShot(true); - q->connect(timer, &QTimer::timeout, q, [q]() { - q->close(); - Q_EMIT q->messageClosed(); - }); + if (ENABLE_ANIMATIONS && ENABLE_ANIMATION_MESSAGE) + q->connect(timer, &QTimer::timeout, q, [q]() { + q->close(); + Q_EMIT q->messageClosed(); + }); + else + q->connect(timer, &QTimer::timeout, q, &DFloatingMessage::close); } else { //常驻消息 content = nullptr; closeButton = new DDialogCloseButton(q); @@ -74,12 +80,19 @@ void DFloatingMessagePrivate::init() hBoxLayout->addWidget(closeButton); q->connect(closeButton, &DIconButton::clicked, q, &DFloatingMessage::closeButtonClicked); - q->connect(closeButton, &DIconButton::clicked, q, [q]() { - q->close(); - Q_EMIT q->messageClosed(); - }); + + if(ENABLE_ANIMATIONS && ENABLE_ANIMATION_MESSAGE) + q->connect(closeButton, &DIconButton::clicked, q, [q]() { + q->close(); + Q_EMIT q->messageClosed(); + }); + else + q->connect(closeButton, &DIconButton::clicked, q, &DFloatingMessage::close); } + if (!ENABLE_ANIMATIONS || !ENABLE_ANIMATION_MESSAGE) + return; + auto effect = new QGraphicsDropShadowEffect(q); effect->setColor(QColor(0, 0, 0, 0.1 * 255)); effect->setBlurRadius(20); diff --git a/src/widgets/dindeterminateprogressbar.cpp b/src/widgets/dindeterminateprogressbar.cpp index e0d04d4d..7835a590 100644 --- a/src/widgets/dindeterminateprogressbar.cpp +++ b/src/widgets/dindeterminateprogressbar.cpp @@ -22,9 +22,14 @@ DIndeterminateProgressbarPrivate::DIndeterminateProgressbarPrivate(DIndeterminat , m_sliderWidget(new QWidget(qq)) , m_timer(new QTimer(qq)) , m_leftToRight(true) - , m_spotWidget(new QWidget(qq)) - , m_animation(new QPropertyAnimation(m_spotWidget, "pos", qq)) + , m_spotWidget(nullptr) + , m_animation(nullptr) { + if (!ENABLE_ANIMATIONS && !ENABLE_ANIMATION_PROGRESSBAR) + return; + + m_spotWidget = new QWidget(qq); + m_animation = new QPropertyAnimation(m_spotWidget, "pos", qq); } DIndeterminateProgressbar::DIndeterminateProgressbar(QWidget *parent) @@ -32,8 +37,11 @@ DIndeterminateProgressbar::DIndeterminateProgressbar(QWidget *parent) , DObject(*new DIndeterminateProgressbarPrivate(this)) { D_D(DIndeterminateProgressbar); - d->m_spotWidget->setFixedSize(SPOT_WIDGET_WIDTH, height()); - d->m_spotWidget->move(-SPOT_WIDGET_WIDTH, 0); + + if (ENABLE_ANIMATIONS && ENABLE_ANIMATION_PROGRESSBAR) { + d->m_spotWidget->setFixedSize(SPOT_WIDGET_WIDTH, height()); + d->m_spotWidget->move(-SPOT_WIDGET_WIDTH, 0); + } d->m_sliderWidget->setFixedWidth(150); d->m_sliderWidget->move(0, 0); @@ -60,6 +68,10 @@ void DIndeterminateProgressbar::resizeEvent(QResizeEvent *e) { D_D(DIndeterminateProgressbar); d->m_sliderWidget->setFixedHeight(height()); + + if (!ENABLE_ANIMATIONS || !ENABLE_ANIMATION_PROGRESSBAR) + QWidget::resizeEvent(e); + d->m_spotWidget->setFixedSize(SPOT_WIDGET_WIDTH, height()); d->m_animation->setStartValue(QPoint(-SPOT_WIDGET_WIDTH, 0)); @@ -111,6 +123,9 @@ void DIndeterminateProgressbar::paintEvent(QPaintEvent *e) p.setPen(pen); p.drawRoundedRect(d->m_sliderWidget->geometry(), radius, radius); + if (!ENABLE_ANIMATIONS || !ENABLE_ANIMATION_PROGRESSBAR) + return; + if (d->m_sliderWidget->width() < d->m_spotWidget->width() / 2) return; diff --git a/src/widgets/dlistview.cpp b/src/widgets/dlistview.cpp index 8b7bff3d..d1b6ffd6 100644 --- a/src/widgets/dlistview.cpp +++ b/src/widgets/dlistview.cpp @@ -198,7 +198,7 @@ DListView::DListView(QWidget *parent) : DObject(*new DListViewPrivate(this)) { d_func()->init(); - if (!qEnvironmentVariableIsSet("DTK_DISABLE_LISTVIEW_ANIMATION")) { + if (ENABLE_ANIMATIONS && ENABLE_ANIMATION_SEARCH) { auto ani = new DBounceAnimation(this); ani->setAnimationTarget(this); ani->setAniMationEnable(true); diff --git a/src/widgets/dmessagemanager.cpp b/src/widgets/dmessagemanager.cpp index f5147241..3d475c37 100644 --- a/src/widgets/dmessagemanager.cpp +++ b/src/widgets/dmessagemanager.cpp @@ -122,11 +122,19 @@ static void sendMessage_helper(DMessageManager *manager, QWidget *par, IconType DMessageManagerPrivate::DMessageManagerPrivate(DMessageManager *qq) : DObjectPrivate(qq) - , m_aniGeometry(new QPropertyAnimation(qq)) - , m_aniOpacity(new QPropertyAnimation(qq)) - , m_aniGroup(new QParallelAnimationGroup(qq)) - , m_label(new ImageLabel) + , m_aniGeometry(nullptr) + , m_aniOpacity(nullptr) + , m_aniGroup(nullptr) + , m_label(nullptr) { + if (!ENABLE_ANIMATIONS || !ENABLE_ANIMATION_MESSAGE) + return; + + m_aniGeometry = new QPropertyAnimation(qq); + m_aniOpacity = new QPropertyAnimation(qq); + m_aniGroup = new QParallelAnimationGroup(qq); + m_label = new ImageLabel; + m_aniGeometry->setPropertyName("geometry"); m_aniGeometry->setDuration(ANIMATION_DURATION); m_aniGeometry->setEasingCurve(QEasingCurve::OutCubic); @@ -187,14 +195,20 @@ void DMessageManager::sendMessage(QWidget *par, DFloatingMessage *floMsg) layout->setContentsMargins(0, 0, 0, 0); layout->setDirection(QBoxLayout::BottomToTop); } - - if (content->layout()->count() >= 1) { - content->layout()->itemAt(content->layout()->count() - 1)->widget()->hide(); - delete content->layout()->takeAt(content->layout()->count() - 1); + if (ENABLE_ANIMATIONS && ENABLE_ANIMATION_MESSAGE) { + if (content->layout()->count() >= 1) { + content->layout()->itemAt(content->layout()->count() - 1)->widget()->hide(); + delete content->layout()->takeAt(content->layout()->count() - 1); + } + } else { + content->show(); } static_cast(content->layout())->addWidget(floMsg, 0, Qt::AlignHCenter); + if (!ENABLE_ANIMATIONS || !ENABLE_ANIMATION_MESSAGE) + return; + // 限制通知消息的最大宽度 for (DFloatingMessage *message : content->findChildren(QString(), Qt::FindDirectChildrenOnly)) { message->setMaximumWidth(par->rect().marginsRemoved(content->contentsMargins()).width()); @@ -214,31 +228,35 @@ void DMessageManager::sendMessage(QWidget *par, DFloatingMessage *floMsg) d->m_label->setParent(par); d->m_label->setAlignment(Qt::AlignCenter); d->m_label->setContentsMargins(MARGIN, 0, MARGIN, 0); - d->m_label->setPixmap(floMsg->grab()); + + if (floMsg && !floMsg->grab().isNull()) + d->m_label->setPixmap(floMsg->grab()); + d->m_label->setScaledContents(true); d->m_label->show(); d->m_aniGeometry->setTargetObject(d->m_label); d->m_aniOpacity->setTargetObject(d->m_label); d->m_aniGeometry->setStartValue(QRect(par->rect().center().x(), par->rect().bottom(), 0, 0)); d->m_aniGeometry->setEndValue(content->geometry()); + d->m_aniGroup->setDirection(QAbstractAnimation::Forward); d->m_aniGroup->start(); - connect(d->m_aniGroup, &QPropertyAnimation::finished, this, [d, content]() { - if (d->m_aniGroup->direction() == QAbstractAnimation::Backward) { - d->m_aniGroup->setDirection(QAbstractAnimation::Forward); - } else { - content->show(); - } + connect(d->m_aniGroup, &QPropertyAnimation::finished, this, [d, this, content]() { + content->show(); d->m_label->hide(); + disconnect(d->m_aniGroup, &QPropertyAnimation::finished, this, nullptr); }); - connect(floMsg, &DFloatingMessage::messageClosed, [=, this]() { + connect(floMsg, &DFloatingMessage::messageClosed, [=]() { d->m_aniGeometry->setStartValue(QRect(par->rect().center().x(), par->rect().bottom(), 0, 0)); d->m_aniGeometry->setEndValue(content->geometry()); - d->m_label->setPixmap(floMsg->grab()); - d->m_aniGroup->setDirection(QAbstractAnimation::Backward); + if (floMsg && !floMsg->grab().isNull()) + d->m_label->setPixmap(floMsg->grab()); + d->m_label->show(); + d->m_aniGroup->setDirection(QAbstractAnimation::Backward); d->m_aniGroup->start(); + content->hide(); }); } @@ -287,20 +305,47 @@ bool DMessageManager::setContentMargens(QWidget *par, const QMargins &margins) */ bool DMessageManager::eventFilter(QObject *watched, QEvent *event) { - if (event->type() == QEvent::Resize) { - if (auto content = watched->findChild(D_MESSAGE_MANAGER_CONTENT, Qt::FindDirectChildrenOnly)) { + bool isOnlyResizeEvent = ENABLE_ANIMATIONS && ENABLE_ANIMATION_MESSAGE ? event->type() == QEvent::Resize : event->type() == QEvent::LayoutRequest || event->type() == QEvent::Resize; - auto par = qobject_cast(watched); + if (isOnlyResizeEvent) { + if (ENABLE_ANIMATIONS && ENABLE_ANIMATION_MESSAGE) { + if (auto content = watched->findChild(D_MESSAGE_MANAGER_CONTENT, Qt::FindDirectChildrenOnly)) { - for (DFloatingMessage *message : content->findChildren(QString(), Qt::FindDirectChildrenOnly)) { - message->setMaximumWidth(par->rect().marginsRemoved(content->contentsMargins()).width()); - message->setMinimumHeight(message->sizeHint().height()); - } + auto par = qobject_cast(watched); + + for (DFloatingMessage *message : content->findChildren(QString(), Qt::FindDirectChildrenOnly)) { + message->setMaximumWidth(par->rect().marginsRemoved(content->contentsMargins()).width()); + message->setMinimumHeight(message->sizeHint().height()); + } - QRect geometry(QPoint(0, 0), content->sizeHint()); - geometry.moveCenter(par->rect().center()); - geometry.moveBottom(par->rect().bottom() - MESSGAE_HEIGHT); - content->setGeometry(geometry); + QRect geometry(QPoint(0, 0), content->sizeHint()); + geometry.moveCenter(par->rect().center()); + geometry.moveBottom(par->rect().bottom() - MESSGAE_HEIGHT); + content->setGeometry(geometry); + } + } else { + if (QWidget *widget = qobject_cast(watched)) { + QWidget *content; + + if (widget->objectName() == D_MESSAGE_MANAGER_CONTENT) { + content = widget; + } else { + content = widget->findChild(D_MESSAGE_MANAGER_CONTENT, Qt::FindDirectChildrenOnly); + } + + QWidget *par = content->parentWidget(); + + // 限制通知消息的最大宽度 + for (DFloatingMessage *message : content->findChildren(QString(), Qt::FindDirectChildrenOnly)) { + message->setMaximumWidth(par->rect().marginsRemoved(content->contentsMargins()).width()); + message->setMinimumHeight(message->sizeHint().height()); + } + + QRect geometry(QPoint(0, 0), content->sizeHint()); + geometry.moveCenter(par->rect().center()); + geometry.moveBottom(par->rect().bottom()); + content->setGeometry(geometry); + } } } else if (event->type() == QEvent::ChildRemoved) { // 如果是通知消息被删除的事件 diff --git a/src/widgets/dsearchedit.cpp b/src/widgets/dsearchedit.cpp index 35acfdcd..734c14de 100644 --- a/src/widgets/dsearchedit.cpp +++ b/src/widgets/dsearchedit.cpp @@ -273,11 +273,14 @@ DSearchEditPrivate::DSearchEditPrivate(DSearchEdit *q) , action(nullptr) , iconWidget(nullptr) , label(nullptr) - , animation(new QPropertyAnimation) + , animation(nullptr) { - animation->setPropertyName("pos"); - animation->setEasingCurve(QEasingCurve::OutCubic); - animation->setDuration(ANI_DURATION); + if (ENABLE_ANIMATIONS && ENABLE_ANIMATION_SEARCH) { + animation = new QPropertyAnimation; + animation->setPropertyName("pos"); + animation->setEasingCurve(QEasingCurve::OutCubic); + animation->setDuration(ANI_DURATION); + } } DSearchEditPrivate::~DSearchEditPrivate() @@ -384,31 +387,58 @@ void DSearchEditPrivate::_q_toEditMode(bool focus) { D_Q(DSearchEdit); - if (animation->state() == QPropertyAnimation::Running) - return; + if (ENABLE_ANIMATIONS && ENABLE_ANIMATION_SEARCH) { + if (animation->state() == QPropertyAnimation::Running) + return; - auto textMargins = q->lineEdit()->textMargins(); - QMargins marginsInAnimation(HIDE_CURSOR_MARGIN, 0, 0, 0); + auto textMargins = q->lineEdit()->textMargins(); + QMargins marginsInAnimation(HIDE_CURSOR_MARGIN, 0, 0, 0); + + if (!animation->parent()) + animation->setParent(iconWidget); + + animation->setTargetObject(iconWidget); + animation->setStartValue(QPoint(q->lineEdit()->geometry().center().x() - iconWidget->width() / 2, iconWidget->pos().y())); + animation->setEndValue(QPoint(10, iconWidget->pos().y())); + + q->connect(animation, &QPropertyAnimation::finished, q, [q, this, textMargins]() { + q->lineEdit()->setTextMargins(textMargins); + if (animation->direction() == QPropertyAnimation::Direction::Forward) { + iconWidget->setVisible(false); + action->setVisible(true); + lineEdit->setPlaceholderText(placeholderText); + } else { + iconWidget->setVisible(true); + lineEdit->setPlaceholderText(QString()); + iconWidget->move(QPoint(q->lineEdit()->geometry().center().x() - iconWidget->width() / 2, iconWidget->pos().y())); + } + }); - if (!animation->parent()) - animation->setParent(iconWidget); + if (!q->lineEdit()->text().isEmpty()) + return; - animation->setTargetObject(iconWidget); - animation->setStartValue(QPoint(q->lineEdit()->geometry().center().x() - iconWidget->width() / 2, iconWidget->pos().y())); - animation->setEndValue(QPoint(0, iconWidget->pos().y())); + if (focus) { + animation->setDirection(QPropertyAnimation::Direction::Forward); + } else { + action->setVisible(false); + animation->setDirection(QPropertyAnimation::Direction::Backward); + } - q->connect(animation, &QPropertyAnimation::finished, q, [q, this, textMargins]() { - q->lineEdit()->setTextMargins(textMargins); - if (animation->direction() == QPropertyAnimation::Direction::Forward) { + iconWidget->setVisible(true); + q->lineEdit()->setTextMargins(marginsInAnimation); + animation->start(); + } else { + if (focus || !q->lineEdit()->text().isEmpty()) { action->setVisible(true); iconWidget->setVisible(false); lineEdit->setPlaceholderText(placeholderText); } else { + action->setVisible(false); iconWidget->setVisible(true); lineEdit->setPlaceholderText(QString()); - iconWidget->move(QPoint(q->lineEdit()->geometry().center().x() - iconWidget->width() / 2, iconWidget->pos().y())); } - }); + + } #ifdef ENABLE_AI //Focus disappears, clear voice check @@ -418,19 +448,6 @@ void DSearchEditPrivate::_q_toEditMode(bool focus) } #endif - if (!q->lineEdit()->text().isEmpty()) - return; - - if (focus) { - animation->setDirection(QPropertyAnimation::Direction::Forward); - } else { - action->setVisible(false); - animation->setDirection(QPropertyAnimation::Direction::Backward); - } - - iconWidget->setVisible(true); - q->lineEdit()->setTextMargins(marginsInAnimation); - animation->start(); } void DSearchEditPrivate::_q_onVoiceActionTrigger(bool checked) diff --git a/src/widgets/dstyle.cpp b/src/widgets/dstyle.cpp index d1fd1160..349e5336 100644 --- a/src/widgets/dstyle.cpp +++ b/src/widgets/dstyle.cpp @@ -1339,18 +1339,27 @@ void DStyle::drawPrimitive(const QStyle *style, DStyle::PrimitiveElement pe, con //先绘画阴影 DDrawUtils::drawShadow(p, btn->rect + shadow_margin, frameRadius, frameRadius, QColor(0, 0, 0, 0.25 * 255), shadowRadius, QPoint(offsetX, offsetY)); //再绘画上面的待显示区域 + + if(ENABLE_ANIMATIONS && ENABLE_ANIMATION_MESSAGE) { + p->setPen(Qt::NoPen); + } else { + p->setPen(QPen(btn->dpalette.frameShadowBorder(), 1)); + } + p->setPen(Qt::NoPen); p->setBrush(btn->noBackground ? Qt::NoBrush : p->background()); p->drawRoundedRect(opt->rect, frameRadius, frameRadius); - p->setBrush(Qt::NoBrush); - QPen pen; - pen.setWidth(1); - pen.setColor(DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::DarkType - ? QColor(255, 255, 255, int(0.1 * 255)) - : QColor(0, 0, 0, int(0.12 * 255))); - p->setPen(pen); - p->drawRoundedRect(opt->rect, frameRadius, frameRadius); + if(ENABLE_ANIMATIONS && ENABLE_ANIMATION_MESSAGE) { + p->setBrush(Qt::NoBrush); + QPen pen; + pen.setWidth(1); + pen.setColor(DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::DarkType + ? QColor(255, 255, 255, int(0.1 * 255)) + : QColor(0, 0, 0, int(0.12 * 255))); + p->setPen(pen); + p->drawRoundedRect(opt->rect, frameRadius, frameRadius); + } } break; } @@ -1453,6 +1462,12 @@ void DStyle::drawControl(const QStyle *style, DStyle::ControlElement ce, const Q option.dpalette = btn->dpalette; option.rect = dstyle.subElementRect(SE_SwitchButtonGroove, opt, w); + if(!ENABLE_ANIMATIONS || !ENABLE_ANIMATION_SWITCHBUTTON) { + dstyle.drawPrimitive(PE_SwitchButtonGroove, &option, p, w); + option.rect = dstyle.subElementRect(SE_SwitchButtonHandle, opt, w); + dstyle.drawPrimitive(PE_SwitchButtonHandle, &option, p, w); + } + if (btn->state & State_HasFocus) { QStyleOptionFocusRect fropt; fropt.QStyleOption::operator=(*btn); @@ -1493,6 +1508,10 @@ void DStyle::drawControl(const QStyle *style, DStyle::ControlElement ce, const Q case CE_ButtonBoxButton: { if (const DStyleOptionButton *btn = qstyleoption_cast(opt)) { DStyleHelper dstyle(style); + + if (!ENABLE_ANIMATIONS || !ENABLE_ANIMATION_BUTTONBOX) + dstyle.drawControl(CE_ButtonBoxButtonBevel, btn, p, w); + DStyleOptionButton subopt = *btn; if (btn->features & DStyleOptionButton::HasDciIcon) subopt.dciIcon = btn->dciIcon; @@ -1503,7 +1522,10 @@ void DStyle::drawControl(const QStyle *style, DStyle::ControlElement ce, const Q DStyleOptionButtonBoxButton fropt; fropt = *boxbtn; fropt.rect = dstyle.subElementRect(SE_ButtonBoxButtonFocusRect, btn, w); - fropt.position = DStyleOptionButtonBoxButton::OnlyOne; + + if (ENABLE_ANIMATIONS && ENABLE_ANIMATION_BUTTONBOX) + fropt.position = DStyleOptionButtonBoxButton::OnlyOne; + style->drawPrimitive(PE_FrameFocusRect, &fropt, p, w); } } @@ -1578,12 +1600,14 @@ void DStyle::drawControl(const QStyle *style, DStyle::ControlElement ce, const Q break; } case CE_ButtonBoxButtonLabel: { - if (opt->state & StateFlag::State_MouseOver) { - constexpr qreal hoverScale = 1.2; // hover 时放大1.2倍 - p->scale(hoverScale, hoverScale); - p->setRenderHint(QPainter::SmoothPixmapTransform); - p->translate((1 - hoverScale) * (opt->rect.x() + opt->rect.width() / 2) / hoverScale - , (1 - hoverScale) * (opt->rect.y() + opt->rect.height() / 2) / hoverScale); + if (ENABLE_ANIMATIONS && ENABLE_ANIMATION_BUTTONBOX) { + if (opt->state & StateFlag::State_MouseOver) { + constexpr qreal hoverScale = 1.2; // hover 时放大1.2倍 + p->scale(hoverScale, hoverScale); + p->setRenderHint(QPainter::SmoothPixmapTransform); + p->translate((1 - hoverScale) * (opt->rect.x() + opt->rect.width() / 2) / hoverScale + , (1 - hoverScale) * (opt->rect.y() + opt->rect.height() / 2) / hoverScale); + } } style->drawControl(CE_PushButtonLabel, opt, p, w); diff --git a/src/widgets/dswitchbutton.cpp b/src/widgets/dswitchbutton.cpp index 8935c0c0..b0625ac1 100644 --- a/src/widgets/dswitchbutton.cpp +++ b/src/widgets/dswitchbutton.cpp @@ -60,8 +60,10 @@ void DSwitchButton::paintEvent(QPaintEvent *e) initStyleOption(&opt); painter.drawControl(DStyle::CE_SwitchButton, opt); - painter.setRenderHint(QPainter::SmoothPixmapTransform); - painter.drawImage(rect().adjusted(4, -8, -4, 8), d->player.currentImage()); // 为了显示按钮的阴影所留的空白 + if (ENABLE_ANIMATIONS && ENABLE_ANIMATION_SWITCHBUTTON) { + painter.setRenderHint(QPainter::SmoothPixmapTransform); + painter.drawImage(rect().adjusted(4, -8, -4, 8), d->player.currentImage()); // 为了显示按钮的阴影所留的空白 + } } /*! @@ -128,6 +130,12 @@ void DSwitchButtonPrivate::init() q->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); q->setCheckable(true); + + if(!ENABLE_ANIMATIONS || !ENABLE_ANIMATION_SWITCHBUTTON) { + q->connect(q, &DSwitchButton::toggled, q, &DSwitchButton::checkedChanged); + return; + } + auto initPlayer= [this, q]() { DDciIcon icon = !checked ? DDciIcon::fromTheme("switch_on") : DDciIcon::fromTheme("switch_off"); player.setIcon(icon);