-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
Rewrote the hover styles for DIconButton and DToolButton to ensure consistent hover styles in the title bar. Log: Unified hover styles for buttons in the sidebar and title bar. Bug: https://pms.uniontech.com/bug-view-296765.html
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. | ||
// | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
#include "custombutton.h" | ||
|
||
#include <DGuiApplicationHelper> | ||
Check warning on line 7 in src/plugins/filemanager/dfmplugin-titlebar/views/custombutton.cpp GitHub Actions / cppcheck
Check warning on line 7 in src/plugins/filemanager/dfmplugin-titlebar/views/custombutton.cpp GitHub Actions / static-check / static-check
|
||
#include <DStylePainter> | ||
Check warning on line 8 in src/plugins/filemanager/dfmplugin-titlebar/views/custombutton.cpp GitHub Actions / cppcheck
Check warning on line 8 in src/plugins/filemanager/dfmplugin-titlebar/views/custombutton.cpp GitHub Actions / static-check / static-check
|
||
#include <DStyle> | ||
Check warning on line 9 in src/plugins/filemanager/dfmplugin-titlebar/views/custombutton.cpp GitHub Actions / cppcheck
|
||
#include <DStyleOption> | ||
Check warning on line 10 in src/plugins/filemanager/dfmplugin-titlebar/views/custombutton.cpp GitHub Actions / cppcheck
Check warning on line 10 in src/plugins/filemanager/dfmplugin-titlebar/views/custombutton.cpp GitHub Actions / static-check / static-check
|
||
|
||
#include <QPaintEvent> | ||
Check warning on line 12 in src/plugins/filemanager/dfmplugin-titlebar/views/custombutton.cpp GitHub Actions / cppcheck
|
||
#include <QPainter> | ||
Check warning on line 13 in src/plugins/filemanager/dfmplugin-titlebar/views/custombutton.cpp GitHub Actions / cppcheck
|
||
#include <QStyleOptionToolButton> | ||
Check warning on line 14 in src/plugins/filemanager/dfmplugin-titlebar/views/custombutton.cpp GitHub Actions / cppcheck
Check warning on line 14 in src/plugins/filemanager/dfmplugin-titlebar/views/custombutton.cpp GitHub Actions / static-check / static-check
|
||
#include <QStylePainter> | ||
Check warning on line 15 in src/plugins/filemanager/dfmplugin-titlebar/views/custombutton.cpp GitHub Actions / cppcheck
Check warning on line 15 in src/plugins/filemanager/dfmplugin-titlebar/views/custombutton.cpp GitHub Actions / static-check / static-check
|
||
#include <QPainterPath> | ||
Check warning on line 16 in src/plugins/filemanager/dfmplugin-titlebar/views/custombutton.cpp GitHub Actions / cppcheck
Check warning on line 16 in src/plugins/filemanager/dfmplugin-titlebar/views/custombutton.cpp GitHub Actions / static-check / static-check
|
||
|
||
CustomDIconButton::CustomDIconButton(QWidget *parent) | ||
: DIconButton(parent) | ||
{ | ||
setFlat(true); | ||
} | ||
|
||
CustomDIconButton::CustomDIconButton(DStyle::StandardPixmap iconType, QWidget *parent) | ||
: DIconButton(iconType, parent) | ||
{ | ||
setFlat(true); | ||
} | ||
|
||
void CustomDIconButton::paintEvent(QPaintEvent *event) | ||
{ | ||
Q_UNUSED(event) | ||
QPainter painter(this); | ||
painter.setRenderHint(QPainter::Antialiasing); | ||
|
||
DStyleOptionButton opt; | ||
initStyleOption(&opt); | ||
|
||
if (isEnabled() && underMouse() && !isDown() && !isChecked()) { | ||
bool isDarkTheme = DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::DarkType; | ||
QColor hoverColor = isDarkTheme ? QColor(255, 255, 255, 15) | ||
: QColor(0, 0, 0, 26); | ||
|
||
DStyleHelper dstyle(style()); | ||
const int radius = dstyle.pixelMetric(DStyle::PM_FrameRadius); | ||
|
||
painter.setPen(Qt::NoPen); | ||
painter.setBrush(hoverColor); | ||
painter.drawRoundedRect(rect(), radius, radius); | ||
} | ||
|
||
DStyleHelper dstyle(style()); | ||
dstyle.drawControl(DStyle::CE_IconButton, &opt, &painter, this); | ||
} | ||
|
||
CustomDToolButton::CustomDToolButton(QWidget *parent) | ||
: DToolButton(parent) | ||
{ | ||
} | ||
|
||
void CustomDToolButton::initStyleOption(QStyleOptionToolButton *option) const | ||
{ | ||
DToolButton::initStyleOption(option); | ||
if (underMouse()) { | ||
bool isDarkTheme = DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::DarkType; | ||
QColor hoverColor = isDarkTheme ? QColor(255, 255, 255, 15) | ||
: QColor(0, 0, 0, 26); | ||
option->palette.setColor(QPalette::Button, hoverColor); | ||
} | ||
} | ||
|
||
void CustomDToolButton::paintEvent(QPaintEvent *event) | ||
{ | ||
Q_UNUSED(event) | ||
QStylePainter p(this); | ||
QStyleOptionToolButton opt; | ||
initStyleOption(&opt); | ||
p.drawComplexControl(QStyle::CC_ToolButton, opt); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. | ||
// | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
#ifndef CUSTOMBUTTON_H | ||
#define CUSTOMBUTTON_H | ||
|
||
#include <DIconButton> | ||
Check warning on line 8 in src/plugins/filemanager/dfmplugin-titlebar/views/custombutton.h GitHub Actions / cppcheck
|
||
#include <DToolButton> | ||
#include <DStyle> | ||
|
||
DWIDGET_USE_NAMESPACE | ||
|
||
class CustomDIconButton : public DIconButton | ||
{ | ||
Q_OBJECT | ||
public: | ||
explicit CustomDIconButton(QWidget *parent = nullptr); | ||
explicit CustomDIconButton(DStyle::StandardPixmap iconType, QWidget *parent = nullptr); | ||
|
||
protected: | ||
void paintEvent(QPaintEvent *event) override; | ||
}; | ||
|
||
class CustomDToolButton : public DToolButton | ||
{ | ||
Q_OBJECT | ||
public: | ||
explicit CustomDToolButton(QWidget *parent = nullptr); | ||
|
||
protected: | ||
void paintEvent(QPaintEvent *event) override; | ||
void initStyleOption(QStyleOptionToolButton *option) const; | ||
}; | ||
|
||
#endif // CUSTOMBUTTON_H |