From 76190c5ec7c526493e0ea5ba5be305caf3c85e5e Mon Sep 17 00:00:00 2001 From: zhangyuanyuan1 Date: Thu, 7 Jul 2022 15:22:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=98=E7=9B=98info=E6=8C=89=E9=92=AE?= =?UTF-8?q?=E9=80=82=E9=85=8D=E4=B8=BB=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/frontend/tools/infobutton.cpp | 35 ++++++++++++++++++++++++++----- src/frontend/tools/infobutton.h | 6 ++++++ 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/src/frontend/tools/infobutton.cpp b/src/frontend/tools/infobutton.cpp index 5e57f880..46d52708 100644 --- a/src/frontend/tools/infobutton.cpp +++ b/src/frontend/tools/infobutton.cpp @@ -26,8 +26,10 @@ #define ICON_SIZE 16,16 #define BACKGROUND_COLOR QColor(0,0,0,0) #define FOREGROUND_COLOR_NORMAL qApp->palette().text().color() -#define FOREGROUND_COLOR_HOVER QColor(55,144,250,255) -#define FOREGROUND_COLOR_PRESS QColor(36,109,212,255) +//#define FOREGROUND_COLOR_HOVER QColor(55,144,250,255) +//#define FOREGROUND_COLOR_PRESS QColor(36,109,212,255) +#define FOREGROUND_COLOR_BRIGHTTEXT qApp->palette().brightText().color() +#define FOREGROUND_COLOR_HIGHLIGHT qApp->palette().highlight().color() #define OUTER_PATH 8,8,16,16 #define INNER_PATH 9,9,14,14 #define TEXT_POS 14,5,16,16,0 @@ -54,6 +56,26 @@ void InfoButton::onPaletteChanged() this->repaint(); } +QColor InfoButton::mixColor(const QColor &c1, const QColor &c2, qreal bias) +{ + if (bias <= 0.0) { + return c1; + } + if (bias >= 1.0) { + return c2; + } + if (qIsNaN(bias)) { + return c1; + } + + qreal r = mixQreal(c1.redF(), c2.redF(), bias); + qreal g = mixQreal(c1.greenF(), c2.greenF(), bias); + qreal b = mixQreal(c1.blueF(), c2.blueF(), bias); + qreal a = mixQreal(c1.alphaF(), c2.alphaF(), bias); + + return QColor::fromRgbF(r, g, b, a); +} + void InfoButton::paintEvent(QPaintEvent *event) { QPalette pal = this->palette(); @@ -87,7 +109,8 @@ void InfoButton::paintEvent(QPaintEvent *event) void InfoButton::enterEvent(QEvent *event) { - m_foregroundColor = FOREGROUND_COLOR_HOVER; +// m_foregroundColor = FOREGROUND_COLOR_HOVER; + m_foregroundColor = FOREGROUND_COLOR_HIGHLIGHT; this->update(); } @@ -99,14 +122,16 @@ void InfoButton::leaveEvent(QEvent *event) void InfoButton::mousePressEvent(QMouseEvent *event) { - m_foregroundColor = FOREGROUND_COLOR_PRESS; +// m_foregroundColor = FOREGROUND_COLOR_PRESS; + m_foregroundColor = mixColor(FOREGROUND_COLOR_HIGHLIGHT, FOREGROUND_COLOR_BRIGHTTEXT, 0.2); this->update(); return QPushButton::mousePressEvent(event); } void InfoButton::mouseReleaseEvent(QMouseEvent *event) { - m_foregroundColor = FOREGROUND_COLOR_HOVER; +// m_foregroundColor = FOREGROUND_COLOR_HOVER; + m_foregroundColor = mixColor(FOREGROUND_COLOR_HIGHLIGHT, FOREGROUND_COLOR_BRIGHTTEXT, 0.2); this->update(); return QPushButton::mouseReleaseEvent(event); } diff --git a/src/frontend/tools/infobutton.h b/src/frontend/tools/infobutton.h index b10a2774..03897886 100644 --- a/src/frontend/tools/infobutton.h +++ b/src/frontend/tools/infobutton.h @@ -39,6 +39,12 @@ protected: private: void initUI(); + static inline qreal mixQreal(qreal a, qreal b, qreal bias) + { + return a + (b - a) * bias; + } + QColor mixColor(const QColor &c1, const QColor &c2, qreal bias); + private: QColor m_backgroundColor; QColor m_foregroundColor;