Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 31 additions & 5 deletions reader/widgets/RoundColorWidget.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2019 ~ 2020 Uniontech Software Technology Co.,Ltd.
// Copyright (C) 2019 - 2026 Uniontech Software Technology Co.,Ltd.
// SPDX-FileCopyrightText: 2023 - 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later
Expand Down Expand Up @@ -47,9 +47,28 @@ void RoundColorWidget::mousePressEvent(QMouseEvent *event)
}
}

#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
void RoundColorWidget::enterEvent(QEvent *event)
#else
void RoundColorWidget::enterEvent(QEnterEvent *event)
#endif
{
qCDebug(appLog) << "RoundColorWidget enterEvent";
m_isHovered = true;
update();
DWidget::enterEvent(event);
}

void RoundColorWidget::leaveEvent(QEvent *event)
{
qCDebug(appLog) << "RoundColorWidget leaveEvent";
m_isHovered = false;
update();
DWidget::leaveEvent(event);
}

void RoundColorWidget::paintEvent(QPaintEvent *event)
{
// qCDebug(appLog) << "RoundColorWidget paintEvent";
Q_UNUSED(event)
QPainter painter(this);
painter.setPen(Qt::NoPen);
Expand All @@ -59,15 +78,23 @@ void RoundColorWidget::paintEvent(QPaintEvent *event)

QRect squareRect = rect();
if (m_isSelected) {
// qCDebug(appLog) << "RoundColorWidget paintEvent m_isSelected";
//draw select circle
QColor highlightColor = DGuiApplicationHelper::instance()->applicationPalette().highlight().color();
QPen pen;
pen.setBrush(QBrush(highlightColor));
pen.setWidth(borderWidth); //pen width
painter.setPen(pen);
QRect r = squareRect.adjusted(3, 3, -3, -3);
painter.drawEllipse(r);
} else if (m_isHovered) {
bool isDark = DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::DarkType;
QColor hoverColor = isDark ? Qt::white : Qt::black;
hoverColor.setAlpha(38);
QPen pen;
pen.setBrush(QBrush(hoverColor));
pen.setWidth(borderWidth);
painter.setPen(pen);
QRect r = squareRect.adjusted(3, 3, -3, -3);
painter.drawEllipse(r);
}

QPainterPath path;
Expand All @@ -84,5 +111,4 @@ void RoundColorWidget::paintEvent(QPaintEvent *event)
painter.setBrush(Qt::NoBrush);
painter.drawEllipse(r);
}
// qCDebug(appLog) << "RoundColorWidget paintEvent end";
}
26 changes: 24 additions & 2 deletions reader/widgets/RoundColorWidget.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
// Copyright (C) 2019 ~ 2020 Uniontech Software Technology Co.,Ltd.
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
// Copyright (C) 2019 - 2026 Uniontech Software Technology Co.,Ltd.
// SPDX-FileCopyrightText: 2023 - 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#ifndef CUSTOMCONTROL_ROUNDCOLORWIDGET_H
#define CUSTOMCONTROL_ROUNDCOLORWIDGET_H

#include <DWidget>

Check warning on line 9 in reader/widgets/RoundColorWidget.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <DWidget> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QMouseEvent>

Check warning on line 10 in reader/widgets/RoundColorWidget.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QMouseEvent> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
#include <QEnterEvent>
#endif

DWIDGET_USE_NAMESPACE

Expand Down Expand Up @@ -52,6 +55,24 @@
*/
void mousePressEvent(QMouseEvent *event);

/**
* @brief enterEvent
* 鼠标进入事件,触发 hover 灰色边框
* @param event
*/
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
void enterEvent(QEvent *event) override;
#else
void enterEvent(QEnterEvent *event) override;
#endif

/**
* @brief leaveEvent
* 鼠标离开事件,取消 hover 灰色边框
* @param event
*/
void leaveEvent(QEvent *event) override;

/**
* @brief paintEvent
* 绘制事件
Expand All @@ -61,6 +82,7 @@

private:
bool m_isSelected = false;
bool m_isHovered = false;
QColor m_color;
bool m_allnotify = false;
};
Expand Down
Loading