#243 修改系统按钮的鼠标悬浮背景色和按下时背景色
This commit is contained in:
parent
a0fcb0ae6d
commit
7713230e6b
|
@ -25,6 +25,7 @@
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "framelesshelpercore_global_p.h"
|
#include "framelesshelpercore_global_p.h"
|
||||||
#include "framelessmanager_p.h"
|
#include "framelessmanager_p.h"
|
||||||
|
#include "framelessmanager.h"
|
||||||
#ifdef Q_OS_WINDOWS
|
#ifdef Q_OS_WINDOWS
|
||||||
# include "winverhelper_p.h"
|
# include "winverhelper_p.h"
|
||||||
#endif // Q_OS_WINDOWS
|
#endif // Q_OS_WINDOWS
|
||||||
|
@ -278,25 +279,39 @@ QColor Utils::calculateSystemButtonBackgroundColor(const SystemButtonType button
|
||||||
if (state == ButtonState::Normal) {
|
if (state == ButtonState::Normal) {
|
||||||
return kDefaultTransparentColor;
|
return kDefaultTransparentColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const bool isDark = (FramelessManager::instance()->systemTheme() == SystemTheme::Dark);
|
||||||
const bool isClose = (button == SystemButtonType::Close);
|
const bool isClose = (button == SystemButtonType::Close);
|
||||||
const bool isTitleColor = isTitleBarColorized();
|
const bool isTitleColor = isTitleBarColorized();
|
||||||
const bool isHovered = (state == ButtonState::Hovered);
|
const bool isHovered = (state == ButtonState::Hovered);
|
||||||
const auto result = [isClose, isTitleColor]() -> QColor {
|
const auto result = [isDark, isClose, isTitleColor]() -> QColor {
|
||||||
if (isClose) {
|
if (isClose) {
|
||||||
return kDefaultSystemCloseButtonBackgroundColor;
|
return kDefaultSystemCloseButtonBackgroundColor;
|
||||||
}
|
}
|
||||||
if (isTitleColor) {
|
if (isTitleColor) {
|
||||||
return getAccentColor();
|
const auto accent = getAccentColor();
|
||||||
|
return [](const QColor &color) -> QColor {
|
||||||
|
// Calculate the most appropriate foreground color, based on the
|
||||||
|
// current background color.
|
||||||
|
const qreal grayF = (
|
||||||
|
(qreal(0.299) * color.redF()) +
|
||||||
|
(qreal(0.587) * color.greenF()) +
|
||||||
|
(qreal(0.114) * color.blueF()));
|
||||||
|
static constexpr const auto kFlag = qreal(0.5);
|
||||||
|
if ((grayF < kFlag) || qFuzzyCompare(grayF, kFlag)) {
|
||||||
|
return kDefaultWhiteColor;
|
||||||
|
}
|
||||||
|
return kDefaultBlackColor;
|
||||||
|
}(accent);
|
||||||
}
|
}
|
||||||
return kDefaultSystemButtonBackgroundColor;
|
return isDark ? kDefaultWhiteColor : kDefaultBlackColor;
|
||||||
}();
|
}();
|
||||||
if (isClose) {
|
if (isClose) {
|
||||||
return (isHovered ? result.lighter(110) : result.lighter(140));
|
return (isHovered ? result.lighter(110) : result.lighter(140));
|
||||||
}
|
}
|
||||||
if (!isTitleColor) {
|
|
||||||
return (isHovered ? result.lighter(110) : result);
|
return (isHovered ? QColor(result.red(), result.green(), result.blue(), 12) :
|
||||||
}
|
QColor(result.red(), result.green(), result.blue(), 6));
|
||||||
return (isHovered ? result.lighter(150) : result.lighter(120));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Utils::shouldAppsUseDarkMode()
|
bool Utils::shouldAppsUseDarkMode()
|
||||||
|
|
Loading…
Reference in New Issue