网络项三态

This commit is contained in:
zhangyuanyuan1 2022-07-26 11:44:19 +08:00
parent 24a93b77ca
commit 1cfad63190
3 changed files with 20 additions and 39 deletions

View File

@ -36,6 +36,8 @@
#define BUTTON_SIZE 36,36
QColor mixColor(const QColor &c1, const QColor &c2, qreal bias);
InfoButton::InfoButton(QWidget *parent) : QPushButton(parent)
{
this->setFixedSize(BUTTON_SIZE);
@ -56,26 +58,6 @@ 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();

View File

@ -39,12 +39,6 @@ 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;

View File

@ -34,6 +34,10 @@
#define FOREGROUND_COLOR_PRESS_INACTIVE_DARK QColor(70,70,70,255)
#define FOREGROUND_COLOR_NORMAL_ACTIVE QColor(55,144,250,255)
#define FOREGROUND_COLOR_PRESS_ACTIVE QColor(36,109,212,255)
#define COLOR_BRIGHT_TEXT qApp->palette().brightText().color()
#define COLOR_HIGH_LIGHT qApp->palette().highlight().color()
QColor mixColor(const QColor &c1, const QColor &c2, qreal bias);
RadioItemButton::RadioItemButton(QWidget *parent) : QPushButton(parent)
{
@ -159,9 +163,10 @@ void RadioItemButton::paintEvent(QPaintEvent *event)
void RadioItemButton::mousePressEvent(QMouseEvent *event)
{
if (m_isActivated) {
m_backgroundColor = qApp->palette().highlight().color();
// m_backgroundColor = qApp->palette().highlight().color();
m_backgroundColor = mixColor(COLOR_HIGH_LIGHT, COLOR_BRIGHT_TEXT, 0.2);
} else {
m_backgroundColor = qApp->palette().brightText().color();
m_backgroundColor = COLOR_BRIGHT_TEXT;
m_backgroundColor.setAlphaF(0.21);
}
this->update();
@ -171,10 +176,10 @@ void RadioItemButton::mousePressEvent(QMouseEvent *event)
void RadioItemButton::mouseReleaseEvent(QMouseEvent *event)
{
if (m_isActivated) {
m_backgroundColor = qApp->palette().highlight().color();
m_backgroundColor = COLOR_HIGH_LIGHT;
} else {
m_backgroundColor = qApp->palette().brightText().color();
m_backgroundColor.setAlphaF(0.18);
m_backgroundColor = COLOR_BRIGHT_TEXT;
m_backgroundColor.setAlphaF(0.12);
}
this->update();
return QPushButton::mouseReleaseEvent(event);
@ -183,10 +188,10 @@ void RadioItemButton::mouseReleaseEvent(QMouseEvent *event)
void RadioItemButton::enterEvent(QEvent *event)
{
if (m_isActivated) {
m_backgroundColor = qApp->palette().highlight().color();
m_backgroundColor = COLOR_HIGH_LIGHT;
} else {
m_backgroundColor = qApp->palette().brightText().color();
m_backgroundColor.setAlphaF(0.32);
m_backgroundColor = COLOR_BRIGHT_TEXT;
m_backgroundColor.setAlphaF(0.15);
}
this->update();
return QPushButton::enterEvent(event);
@ -195,10 +200,10 @@ void RadioItemButton::enterEvent(QEvent *event)
void RadioItemButton::leaveEvent(QEvent *event)
{
if (m_isActivated) {
m_backgroundColor = qApp->palette().highlight().color();
m_backgroundColor = COLOR_HIGH_LIGHT;
} else {
m_backgroundColor = qApp->palette().brightText().color();
m_backgroundColor.setAlphaF(0.18);
m_backgroundColor = COLOR_BRIGHT_TEXT;
m_backgroundColor.setAlphaF(0.12);
}
this->update();
return QPushButton::leaveEvent(event);
@ -207,10 +212,10 @@ void RadioItemButton::leaveEvent(QEvent *event)
void RadioItemButton::refreshButtonIcon()
{
if (m_isActivated) {
m_backgroundColor = qApp->palette().highlight().color();
m_backgroundColor = COLOR_HIGH_LIGHT;
m_iconLabel->setPixmap(loadSvg(m_pixmap, PixmapColor::WHITE));
} else {
m_backgroundColor = qApp->palette().brightText().color();
m_backgroundColor = COLOR_BRIGHT_TEXT;
m_backgroundColor.setAlphaF(0.18);
if (qApp->palette().base().color().red() > MIDDLE_COLOR) {
m_iconLabel->setPixmap(m_pixmap);