-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: Unified hover styles for buttons in title bar.
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
1 parent
7e82c03
commit eff9209
Showing
9 changed files
with
155 additions
and
12 deletions.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
src/plugins/filemanager/dfmplugin-titlebar/views/custombutton.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. | ||
// | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
#include "custombutton.h" | ||
|
||
#include <DGuiApplicationHelper> | ||
#include <DStylePainter> | ||
#include <DStyle> | ||
#include <DStyleOption> | ||
|
||
#include <QPaintEvent> | ||
#include <QPainter> | ||
#include <QStyleOptionToolButton> | ||
#include <QStylePainter> | ||
#include <QPainterPath> | ||
|
||
DWIDGET_USE_NAMESPACE | ||
|
||
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); | ||
} |
34 changes: 34 additions & 0 deletions
34
src/plugins/filemanager/dfmplugin-titlebar/views/custombutton.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. | ||
// | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
#ifndef CUSTOMBUTTON_H | ||
#define CUSTOMBUTTON_H | ||
|
||
#include <DIconButton> | ||
#include <DToolButton> | ||
#include <DStyle> | ||
|
||
class CustomDIconButton : public DTK_NAMESPACE::Widget::DIconButton | ||
{ | ||
Q_OBJECT | ||
public: | ||
explicit CustomDIconButton(QWidget *parent = nullptr); | ||
explicit CustomDIconButton(DTK_NAMESPACE::Widget::DStyle::StandardPixmap iconType, QWidget *parent = nullptr); | ||
|
||
protected: | ||
void paintEvent(QPaintEvent *event) override; | ||
}; | ||
|
||
class CustomDToolButton : public DTK_NAMESPACE::Widget::DToolButton | ||
{ | ||
Q_OBJECT | ||
public: | ||
explicit CustomDToolButton(QWidget *parent = nullptr); | ||
|
||
protected: | ||
void paintEvent(QPaintEvent *event) override; | ||
void initStyleOption(QStyleOptionToolButton *option) const override; | ||
}; | ||
|
||
#endif // CUSTOMBUTTON_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters