mirror of
https://gitee.com/spark-store-project/spark-store
synced 2025-09-29 15:12:21 +08:00
fix: 修复下载按钮点击/双击/拖动时,主窗口动作与下载管理对话框动作同时触发问题
下载按钮未屏蔽双击事件,导致触发主窗口最大化动作,同时下载对话框显示在原始位置;拖动时触发下载对话框显示,移动时又隐藏下载对话框,造成闪烁现象;重复点击下载按钮,对话框闪烁 Log: 修改下载按钮和下载对话框焦点策略对象,保证对话框焦点状态与下载按钮同步;对话框显示操作移入下载按钮鼠标事件中处理,隐藏操作移入主窗口事件循环中判断,当主窗口/下载对话框均不是活动窗口时隐藏对话框 * 可能修复 ISSUE #I6FNOW,目前修改后,连续点击下载按钮,对话框将按顺序显示/隐藏
This commit is contained in:
parent
4114b51d87
commit
8dfb1fbe2f
@ -51,9 +51,6 @@ Application::Application(int &argc, char **argv)
|
|||||||
// 获取版本特性信息
|
// 获取版本特性信息
|
||||||
m_featuresJsonObj = Utils::parseFeatureJsonFile();
|
m_featuresJsonObj = Utils::parseFeatureJsonFile();
|
||||||
m_version = m_featuresJsonObj.value("version").toString(); // 获取版本号
|
m_version = m_featuresJsonObj.value("version").toString(); // 获取版本号
|
||||||
#if (DTK_VERSION >= DTK_VERSION_CHECK(5, 6, 4, 0))
|
|
||||||
initFeatureDisplayDialog(); // 初始化版本特性对话框
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::handleAboutAction()
|
void Application::handleAboutAction()
|
||||||
@ -64,9 +61,21 @@ void Application::handleAboutAction()
|
|||||||
}
|
}
|
||||||
|
|
||||||
initAboutDialog();
|
initAboutDialog();
|
||||||
|
#if (DTK_VERSION >= DTK_VERSION_CHECK(5, 6, 4, 0))
|
||||||
|
initFeatureDisplayDialog(); // 初始化版本特性对话框
|
||||||
|
#endif
|
||||||
DApplication::handleAboutAction();
|
DApplication::handleAboutAction();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Application::notify(QObject *receiver, QEvent *event)
|
||||||
|
{
|
||||||
|
if (m_mainWindow) {
|
||||||
|
m_mainWindow->notify(receiver, event);
|
||||||
|
}
|
||||||
|
|
||||||
|
return DApplication::notify(receiver, event);
|
||||||
|
}
|
||||||
|
|
||||||
void Application::checkAppConfigLocation()
|
void Application::checkAppConfigLocation()
|
||||||
{
|
{
|
||||||
QDir dir(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation));
|
QDir dir(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation));
|
||||||
@ -99,6 +108,12 @@ void Application::setMainWindow(MainWindow *window)
|
|||||||
{
|
{
|
||||||
initAboutDialog();
|
initAboutDialog();
|
||||||
}
|
}
|
||||||
|
#if (DTK_VERSION >= DTK_VERSION_CHECK(5, 6, 4, 0))
|
||||||
|
if (featureDisplayDialog() == nullptr || featureDisplayDialog()->parent() != m_mainWindow)
|
||||||
|
{
|
||||||
|
initFeatureDisplayDialog(); // 初始化版本特性对话框
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::initAboutDialog()
|
void Application::initAboutDialog()
|
||||||
@ -134,11 +149,6 @@ void Application::initAboutDialog()
|
|||||||
connect(aboutDialog(), &DAboutDialog::destroyed, this, [=]() {
|
connect(aboutDialog(), &DAboutDialog::destroyed, this, [=]() {
|
||||||
setAboutDialog(nullptr);
|
setAboutDialog(nullptr);
|
||||||
});
|
});
|
||||||
#if (DTK_VERSION >= DTK_VERSION_CHECK(5, 6, 4, 0))
|
|
||||||
connect(aboutDialog(), &DAboutDialog::featureActivated, this, [=]() {
|
|
||||||
featureDisplayDialog()->show();
|
|
||||||
});
|
|
||||||
#endif
|
|
||||||
|
|
||||||
dialog->hide();
|
dialog->hide();
|
||||||
}
|
}
|
||||||
@ -194,6 +204,11 @@ void Application::initFeatureDisplayDialog()
|
|||||||
connect(featureDisplayDialog(), &DFeatureDisplayDialog::destroyed, this, [=]() {
|
connect(featureDisplayDialog(), &DFeatureDisplayDialog::destroyed, this, [=]() {
|
||||||
setFeatureDisplayDialog(nullptr);
|
setFeatureDisplayDialog(nullptr);
|
||||||
});
|
});
|
||||||
|
#if (DTK_VERSION >= DTK_VERSION_CHECK(5, 6, 4, 0))
|
||||||
|
connect(aboutDialog(), &DAboutDialog::featureActivated, this, [=]() {
|
||||||
|
featureDisplayDialog()->show();
|
||||||
|
});
|
||||||
|
#endif
|
||||||
|
|
||||||
dialog->hide();
|
dialog->hide();
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@ class Application : public DApplication
|
|||||||
public:
|
public:
|
||||||
Application(int &argc, char **argv);
|
Application(int &argc, char **argv);
|
||||||
void handleAboutAction() override;
|
void handleAboutAction() override;
|
||||||
|
bool notify(QObject *receiver, QEvent *event) override;
|
||||||
|
|
||||||
static void checkAppConfigLocation();
|
static void checkAppConfigLocation();
|
||||||
|
|
||||||
|
@ -132,6 +132,9 @@ void MainWindow::initTitleBar()
|
|||||||
searchEdit->setPlaceholderText(tr("Search or enter spk://"));
|
searchEdit->setPlaceholderText(tr("Search or enter spk://"));
|
||||||
|
|
||||||
downloadButton = new ProgressButton(ui->titlebar);
|
downloadButton = new ProgressButton(ui->titlebar);
|
||||||
|
downloadButton->setDownloadListWidget(downloadlistwidget);
|
||||||
|
downloadButton->setFocusPolicy(Qt::FocusPolicy::ClickFocus);
|
||||||
|
downloadlistwidget->setFocusProxy(downloadButton);
|
||||||
|
|
||||||
QWidget *w_titlebar = new QWidget(ui->titlebar);
|
QWidget *w_titlebar = new QWidget(ui->titlebar);
|
||||||
QHBoxLayout *ly_titlebar = new QHBoxLayout(w_titlebar);
|
QHBoxLayout *ly_titlebar = new QHBoxLayout(w_titlebar);
|
||||||
@ -297,14 +300,6 @@ void MainWindow::initConnections()
|
|||||||
ui->appintopage->setTheme(themeType == DGuiApplicationHelper::DarkType);
|
ui->appintopage->setTheme(themeType == DGuiApplicationHelper::DarkType);
|
||||||
ui->settingspage->setTheme(themeType == DGuiApplicationHelper::DarkType); });
|
ui->settingspage->setTheme(themeType == DGuiApplicationHelper::DarkType); });
|
||||||
|
|
||||||
connect(downloadButton, &ProgressButton::clicked, [=]()
|
|
||||||
{
|
|
||||||
QPoint pos;
|
|
||||||
pos.setX(downloadButton->mapToGlobal(QPoint(0, 0)).x() + downloadButton->width() / 2 - downloadlistwidget->width() / 2);
|
|
||||||
pos.setY(downloadButton->mapToGlobal(QPoint(0, 0)).y() + downloadButton->height() + 5);
|
|
||||||
downloadlistwidget->m_move(pos.x(), pos.y());
|
|
||||||
downloadlistwidget->show(); });
|
|
||||||
|
|
||||||
// appintopage按下下载按钮时标题栏下载列表按钮抖动
|
// appintopage按下下载按钮时标题栏下载列表按钮抖动
|
||||||
connect(ui->appintopage, &AppIntoPage::clickedDownloadBtn, [=]()
|
connect(ui->appintopage, &AppIntoPage::clickedDownloadBtn, [=]()
|
||||||
{
|
{
|
||||||
@ -421,6 +416,34 @@ void MainWindow::updateUi(int now)
|
|||||||
switchPage(AppPageApplist);
|
switchPage(AppPageApplist);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::notify(QObject *receiver, QEvent *event)
|
||||||
|
{
|
||||||
|
if (!receiver) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Dtk::Widget::DStyle *o_ptr = qobject_cast<Dtk::Widget::DStyle *>(receiver);
|
||||||
|
if (o_ptr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (receiver->inherits("QWidgetWindow")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event->type() == QEvent::FocusIn) {
|
||||||
|
QList<QObject *> list = downloadButton->findChildren<QObject *>(QString(), Qt::FindChildrenRecursively);
|
||||||
|
list << downloadlistwidget->findChildren<QObject *>(QString(), Qt::FindChildrenRecursively);
|
||||||
|
if (receiver != downloadButton && receiver != downloadlistwidget && !list.contains(receiver)) {
|
||||||
|
downloadlistwidget->hide();
|
||||||
|
}
|
||||||
|
} else if (event->type() == QEvent::FocusOut) {
|
||||||
|
if (!downloadlistwidget->isActiveWindow() && !isActiveWindow()) {
|
||||||
|
downloadlistwidget->hide();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::on_pushButton_14_clicked()
|
void MainWindow::on_pushButton_14_clicked()
|
||||||
{
|
{
|
||||||
// Check UOS
|
// Check UOS
|
||||||
|
@ -25,7 +25,7 @@ class MainWindow : public BaseWidgetOpacity
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
explicit MainWindow(QWidget *parent = nullptr);
|
explicit MainWindow(QWidget *parent = nullptr);
|
||||||
~MainWindow();
|
~MainWindow() override;
|
||||||
|
|
||||||
void openUrl(const QString &url);
|
void openUrl(const QString &url);
|
||||||
|
|
||||||
@ -41,6 +41,9 @@ private:
|
|||||||
void switchPage(int now);
|
void switchPage(int now);
|
||||||
void updateUi(int now);
|
void updateUi(int now);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void notify(QObject *receiver, QEvent *event);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
//接受来自dbus的url
|
//接受来自dbus的url
|
||||||
void onGetUrl(const QString &url);
|
void onGetUrl(const QString &url);
|
||||||
|
@ -1,20 +1,20 @@
|
|||||||
#include "progressbutton.h"
|
#include "progressbutton.h"
|
||||||
|
#include "widgets/downloadlistwidget.h"
|
||||||
|
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QPainterPath>
|
#include <QPainterPath>
|
||||||
#include <QRect>
|
#include <QMoveEvent>
|
||||||
#include <QConicalGradient>
|
|
||||||
#include <QVariantAnimation>
|
|
||||||
#include <QSvgRenderer>
|
#include <QSvgRenderer>
|
||||||
|
|
||||||
ProgressButton::ProgressButton(QWidget *parent)
|
ProgressButton::ProgressButton(QWidget *parent)
|
||||||
: QWidget{parent}
|
: QWidget{parent}
|
||||||
{
|
{
|
||||||
// this->setWindowFlags(Qt::FramelessWindowHint);
|
// this->setWindowFlags(Qt::FramelessWindowHint);
|
||||||
// this->setAttribute(Qt::WA_TranslucentBackground, true);
|
// this->setAttribute(Qt::WA_TranslucentBackground, true);
|
||||||
setMinimumWidth(36);
|
setMinimumSize(36, 36);
|
||||||
setMinimumHeight(36);
|
|
||||||
svgPath = "";
|
svgPath = "";
|
||||||
backColor = Qt::transparent;
|
backColor = Qt::transparent;
|
||||||
setMouseTracking(true);
|
|
||||||
|
|
||||||
connect(this, &ProgressButton::startProcessing, this, &ProgressButton::operationProcessing, Qt::QueuedConnection);
|
connect(this, &ProgressButton::startProcessing, this, &ProgressButton::operationProcessing, Qt::QueuedConnection);
|
||||||
}
|
}
|
||||||
@ -23,69 +23,6 @@ ProgressButton::~ProgressButton()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProgressButton::paintEvent(QPaintEvent *event)
|
|
||||||
{
|
|
||||||
QPainter painter(this);
|
|
||||||
painter.setRenderHint(QPainter::Antialiasing, true);
|
|
||||||
auto rect = event->rect();
|
|
||||||
|
|
||||||
if (buttonState == state::normal || buttonState == state::hover)
|
|
||||||
{
|
|
||||||
auto radiu = (rect.height() - 6) / 2;
|
|
||||||
painter.translate(rect.center());
|
|
||||||
painter.setPen(Qt::transparent);
|
|
||||||
painter.setBrush(QColor(buttonState == state::normal ? color : color.darker()));
|
|
||||||
// painter.drawEllipse(QPoint(0,0),radiu,radiu);
|
|
||||||
|
|
||||||
// radiu -= 3;
|
|
||||||
painter.setBrush(backColor);
|
|
||||||
painter.drawEllipse(QPoint(0, 0), radiu, radiu);
|
|
||||||
|
|
||||||
QSvgRenderer m_svgRender;
|
|
||||||
m_svgRender.load(svgPath);
|
|
||||||
m_svgRender.render(&painter, QRectF(-radiu / 2, -radiu / 2, radiu, radiu));
|
|
||||||
}
|
|
||||||
else if (buttonState == state::openProgress)
|
|
||||||
{
|
|
||||||
painter.translate(rect.center());
|
|
||||||
auto radiu = (rect.height() - 6) / 2 - 3;
|
|
||||||
painter.setBrush(backColor);
|
|
||||||
painter.setPen(QPen(backColor, 3));
|
|
||||||
painter.drawEllipse(QPoint(0, 0), radiu, radiu);
|
|
||||||
|
|
||||||
painter.setPen(QPen(backColor, 3));
|
|
||||||
|
|
||||||
QSvgRenderer m_svgRender;
|
|
||||||
m_svgRender.load(svgPath);
|
|
||||||
m_svgRender.render(&painter, QRectF(-radiu / 2, -radiu / 2, radiu, radiu));
|
|
||||||
|
|
||||||
QRect rect = QRect(-radiu, -radiu,
|
|
||||||
radiu * 2, radiu * 2);
|
|
||||||
|
|
||||||
painter.setPen(QPen(color.darker(100), 3));
|
|
||||||
auto angle = progress * 360 / 100;
|
|
||||||
painter.drawArc(rect.adjusted(-3, -3, 3, 3), 90 * 16, -static_cast<int>(angle * 16));
|
|
||||||
}
|
|
||||||
else if (buttonState == state::closeProgress)
|
|
||||||
{
|
|
||||||
auto radiu = (rect.height() - 6) / 2;
|
|
||||||
painter.translate(rect.center());
|
|
||||||
painter.setPen(Qt::transparent);
|
|
||||||
painter.setBrush(QColor(0, 0, 0, 63));
|
|
||||||
painter.drawEllipse(QPoint(0, 0), radiu, radiu);
|
|
||||||
|
|
||||||
radiu -= 3;
|
|
||||||
painter.setBrush(backColor);
|
|
||||||
painter.drawEllipse(QPoint(0, 0), radiu, radiu);
|
|
||||||
|
|
||||||
painter.setPen(QPen(color, 3, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
|
|
||||||
painter.drawLine(QPoint(-radiu / 3, 0),
|
|
||||||
QPoint(-radiu / 5, radiu / 3));
|
|
||||||
painter.drawLine(QPoint(-radiu / 5, radiu / 3),
|
|
||||||
QPoint(radiu / 4, -radiu / 4));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ProgressButton::setProgress(int progress)
|
void ProgressButton::setProgress(int progress)
|
||||||
{
|
{
|
||||||
buttonState = state::openProgress;
|
buttonState = state::openProgress;
|
||||||
@ -107,6 +44,11 @@ void ProgressButton::setProgress(int progress)
|
|||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ProgressButton::setDownloadListWidget(DownloadListWidget *widget)
|
||||||
|
{
|
||||||
|
m_downloadListWidget = widget;
|
||||||
|
}
|
||||||
|
|
||||||
void ProgressButton::setIcon(QString svgPATH)
|
void ProgressButton::setIcon(QString svgPATH)
|
||||||
{
|
{
|
||||||
svgPath = svgPATH;
|
svgPath = svgPATH;
|
||||||
@ -125,17 +67,15 @@ void ProgressButton::setColor(QColor color)
|
|||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProgressButton::leaveEvent(QEvent *event)
|
void ProgressButton::mousePressEvent(QMouseEvent *event)
|
||||||
{
|
{
|
||||||
if (buttonState == state::hover)
|
m_mouseMoved = false;
|
||||||
{
|
m_isDownloadListWidgetVisible = m_downloadListWidget->isVisible();
|
||||||
buttonState = state::normal;
|
m_downloadListWidget->hide();
|
||||||
update();
|
QWidget::mousePressEvent(event);
|
||||||
}
|
|
||||||
QWidget::leaveEvent(event);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProgressButton::mousePressEvent(QMouseEvent *event)
|
void ProgressButton::mouseReleaseEvent(QMouseEvent *event)
|
||||||
{
|
{
|
||||||
if (buttonState == state::hover || buttonState == state::normal)
|
if (buttonState == state::hover || buttonState == state::normal)
|
||||||
{
|
{
|
||||||
@ -146,8 +86,109 @@ void ProgressButton::mousePressEvent(QMouseEvent *event)
|
|||||||
{
|
{
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
emit clicked();
|
|
||||||
QWidget::mousePressEvent(event);
|
if (m_mouseMoved) {
|
||||||
|
return QWidget::mouseReleaseEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_isDownloadListWidgetVisible) {
|
||||||
|
m_downloadListWidget->hide();
|
||||||
|
} else {
|
||||||
|
QPoint pos(this->mapToGlobal(QPoint(0, 0)));
|
||||||
|
pos += QPoint(width() / 2 - m_downloadListWidget->width() / 2, height() + 5);
|
||||||
|
m_downloadListWidget->m_move(pos.x(), pos.y());
|
||||||
|
m_downloadListWidget->setWindowState(windowState() & Qt::WindowState::WindowActive);
|
||||||
|
m_downloadListWidget->activateWindow();
|
||||||
|
m_downloadListWidget->show();
|
||||||
|
m_downloadListWidget->raise();
|
||||||
|
}
|
||||||
|
m_isDownloadListWidgetVisible = m_downloadListWidget->isVisible();
|
||||||
|
QWidget::mouseReleaseEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ProgressButton::mouseDoubleClickEvent(QMouseEvent *event)
|
||||||
|
{
|
||||||
|
event->accept();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ProgressButton::mouseMoveEvent(QMouseEvent *event)
|
||||||
|
{
|
||||||
|
m_mouseMoved = true;
|
||||||
|
QWidget::mouseMoveEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ProgressButton::leaveEvent(QEvent *event)
|
||||||
|
{
|
||||||
|
if (buttonState == state::hover)
|
||||||
|
{
|
||||||
|
buttonState = state::normal;
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
QWidget::leaveEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ProgressButton::paintEvent(QPaintEvent *event)
|
||||||
|
{
|
||||||
|
QPainter painter(this);
|
||||||
|
painter.setRenderHint(QPainter::Antialiasing, true);
|
||||||
|
QRect rect = event->rect();
|
||||||
|
|
||||||
|
if (buttonState == state::normal || buttonState == state::hover)
|
||||||
|
{
|
||||||
|
int radius = (rect.height() - 6) / 2;
|
||||||
|
painter.translate(rect.center());
|
||||||
|
painter.setPen(Qt::transparent);
|
||||||
|
painter.setBrush(QColor(buttonState == state::normal ? color : color.darker()));
|
||||||
|
// painter.drawEllipse(QPoint(0, 0), radius, radius);
|
||||||
|
|
||||||
|
// radiu -= 3;
|
||||||
|
painter.setBrush(backColor);
|
||||||
|
painter.drawEllipse(QPoint(0, 0), radius, radius);
|
||||||
|
|
||||||
|
QSvgRenderer m_svgRender;
|
||||||
|
m_svgRender.load(svgPath);
|
||||||
|
m_svgRender.render(&painter, QRectF(-radius / 2, -radius / 2, radius, radius));
|
||||||
|
}
|
||||||
|
else if (buttonState == state::openProgress)
|
||||||
|
{
|
||||||
|
painter.translate(rect.center());
|
||||||
|
int radius = (rect.height() - 6) / 2 - 3;
|
||||||
|
painter.setBrush(backColor);
|
||||||
|
painter.setPen(QPen(backColor, 3));
|
||||||
|
painter.drawEllipse(QPoint(0, 0), radius, radius);
|
||||||
|
|
||||||
|
painter.setPen(QPen(backColor, 3));
|
||||||
|
|
||||||
|
QSvgRenderer m_svgRender;
|
||||||
|
m_svgRender.load(svgPath);
|
||||||
|
m_svgRender.render(&painter, QRectF(-radius / 2, -radius / 2, radius, radius));
|
||||||
|
|
||||||
|
QRect rect = QRect(-radius, -radius,
|
||||||
|
radius * 2, radius * 2);
|
||||||
|
|
||||||
|
painter.setPen(QPen(color.darker(100), 3));
|
||||||
|
qreal angle = progress * 360 / 100 * 1.0;
|
||||||
|
painter.drawArc(rect.adjusted(-3, -3, 3, 3), 90 * 16, -qIntCast(angle * 16));
|
||||||
|
}
|
||||||
|
else if (buttonState == state::closeProgress)
|
||||||
|
{
|
||||||
|
auto radius = (rect.height() - 6) / 2;
|
||||||
|
painter.translate(rect.center());
|
||||||
|
painter.setPen(Qt::transparent);
|
||||||
|
painter.setBrush(QColor(0, 0, 0, 63));
|
||||||
|
painter.drawEllipse(QPoint(0, 0), radius, radius);
|
||||||
|
|
||||||
|
radius -= 3;
|
||||||
|
painter.setBrush(backColor);
|
||||||
|
painter.drawEllipse(QPoint(0, 0), radius, radius);
|
||||||
|
|
||||||
|
painter.setPen(QPen(color, 3, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
|
||||||
|
painter.drawLine(QPoint(-radius / 3, 0),
|
||||||
|
QPoint(-radius / 5, radius / 3));
|
||||||
|
painter.drawLine(QPoint(-radius / 5, radius / 3),
|
||||||
|
QPoint(radius / 4, -radius / 4));
|
||||||
|
}
|
||||||
|
QWidget::paintEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProgressButton::operationProcessing()
|
void ProgressButton::operationProcessing()
|
||||||
@ -156,16 +197,16 @@ void ProgressButton::operationProcessing()
|
|||||||
|
|
||||||
const int RADIUS = 60;
|
const int RADIUS = 60;
|
||||||
WaterDrop::WaterDrop(QWidget *parent)
|
WaterDrop::WaterDrop(QWidget *parent)
|
||||||
: QWidget(parent), m_waterDropAnimation(nullptr), m_animationRadius(0)
|
: QWidget(parent)
|
||||||
|
, m_waterDropAnimation(new QVariantAnimation(this))
|
||||||
|
, m_animationRadius(0)
|
||||||
{
|
{
|
||||||
this->setFixedSize(QSize(RADIUS * 2, RADIUS * 2));
|
this->setFixedSize(QSize(RADIUS * 2, RADIUS * 2));
|
||||||
// this->setWindowFlags(Qt::FramelessWindowHint | Qt::Tool);
|
// this->setWindowFlags(Qt::FramelessWindowHint | Qt::Tool);
|
||||||
// this->setAttribute(Qt::WA_TranslucentBackground);
|
// this->setAttribute(Qt::WA_TranslucentBackground);
|
||||||
// this->setAttribute(Qt::WA_DeleteOnClose);
|
// this->setAttribute(Qt::WA_DeleteOnClose);
|
||||||
m_waterDropAnimation = new QVariantAnimation(this);
|
|
||||||
// m_waterDropAnimation->setEasingCurve(QEasingCurve(static_cast<QEasingCurve::Type>(QRandomGenerator::global()->bounded(40))));
|
|
||||||
|
|
||||||
connect(m_waterDropAnimation, &QVariantAnimation::finished, this, &WaterDrop::deleteLater);
|
// m_waterDropAnimation->setEasingCurve(QEasingCurve(static_cast<QEasingCurve::Type>(QRandomGenerator::global()->bounded(40))));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 把鼠标点击的点转换为圆心点坐标
|
// 把鼠标点击的点转换为圆心点坐标
|
||||||
@ -191,8 +232,7 @@ void WaterDrop::paintEvent(QPaintEvent *event)
|
|||||||
{
|
{
|
||||||
QPainter painter(this);
|
QPainter painter(this);
|
||||||
painter.setRenderHint(QPainter::Antialiasing);
|
painter.setRenderHint(QPainter::Antialiasing);
|
||||||
QPen pen;
|
QPen pen(QBrush(QColor("#ffff80")), 5.0);
|
||||||
pen.setColor(QColor(0xffffff80));
|
|
||||||
pen.setWidth(5);
|
pen.setWidth(5);
|
||||||
painter.setPen(pen);
|
painter.setPen(pen);
|
||||||
painter.drawEllipse(event->rect().center(), m_animationRadius, m_animationRadius);
|
painter.drawEllipse(event->rect().center(), m_animationRadius, m_animationRadius);
|
||||||
@ -200,7 +240,7 @@ void WaterDrop::paintEvent(QPaintEvent *event)
|
|||||||
QWidget::paintEvent(event);
|
QWidget::paintEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WaterDrop::onRadiusChanged(QVariant value)
|
void WaterDrop::onRadiusChanged(const QVariant &value)
|
||||||
{
|
{
|
||||||
m_animationRadius = value.toInt();
|
m_animationRadius = value.toInt();
|
||||||
update();
|
update();
|
||||||
|
@ -1,53 +1,62 @@
|
|||||||
#ifndef PROGRESSBUTTON_H
|
#ifndef PROGRESSBUTTON_H
|
||||||
#define PROGRESSBUTTON_H
|
#define PROGRESSBUTTON_H
|
||||||
|
|
||||||
|
#include <QWidget>
|
||||||
#include <QtWidgets/QWidget>
|
|
||||||
|
|
||||||
#include <QPaintEvent>
|
|
||||||
|
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QTimerEvent>
|
#include <QVariantAnimation>
|
||||||
#include<QColor>
|
|
||||||
#include <QList>
|
|
||||||
#include <QMouseEvent>
|
|
||||||
|
|
||||||
|
|
||||||
|
class DownloadListWidget;
|
||||||
class ProgressButton : public QWidget
|
class ProgressButton : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ProgressButton(QWidget *parent = nullptr);
|
explicit ProgressButton(QWidget *parent = nullptr);
|
||||||
|
~ProgressButton() override;
|
||||||
|
|
||||||
void setIcon(QString svgPATH);
|
void setIcon(QString svgPATH);
|
||||||
void setBackgroundColor(QColor color);
|
void setBackgroundColor(QColor color);
|
||||||
void setColor(QColor color);
|
void setColor(QColor color);
|
||||||
void setProgress(int progress);
|
void setProgress(int progress);
|
||||||
~ProgressButton();
|
|
||||||
|
void setDownloadListWidget(DownloadListWidget *widget);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void mousePressEvent(QMouseEvent *event) override;
|
||||||
|
void mouseReleaseEvent(QMouseEvent *event) override;
|
||||||
|
void mouseDoubleClickEvent(QMouseEvent *event) override;
|
||||||
|
void mouseMoveEvent(QMouseEvent *event) override;
|
||||||
|
void leaveEvent(QEvent *event) override;
|
||||||
|
void paintEvent(QPaintEvent *event) override;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void startProcessing();
|
void startProcessing();
|
||||||
void clicked();
|
void clicked();
|
||||||
|
|
||||||
protected:
|
private slots:
|
||||||
void paintEvent(QPaintEvent *event)override;
|
void operationProcessing();
|
||||||
void leaveEvent(QEvent *event)override;
|
|
||||||
void mousePressEvent(QMouseEvent *event)override;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
enum class state
|
enum state
|
||||||
{
|
{
|
||||||
normal,
|
normal,
|
||||||
hover,
|
hover,
|
||||||
openProgress,
|
openProgress,
|
||||||
closeProgress,
|
closeProgress,
|
||||||
recovery
|
recovery
|
||||||
}
|
};
|
||||||
buttonState{state::normal};
|
|
||||||
|
DownloadListWidget *m_downloadListWidget = nullptr;
|
||||||
|
|
||||||
|
state buttonState{state::normal};
|
||||||
QColor backColor;
|
QColor backColor;
|
||||||
QColor color;
|
QColor color;
|
||||||
QString svgPath;
|
QString svgPath;
|
||||||
int widthChangeValue{0};
|
int widthChangeValue{0};
|
||||||
void operationProcessing();
|
|
||||||
int progress{0};//处理百分比
|
int progress{0};//处理百分比
|
||||||
|
|
||||||
|
bool m_mouseMoved = false;
|
||||||
|
bool m_isDownloadListWidgetVisible = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
class WaterDrop : public QWidget
|
class WaterDrop : public QWidget
|
||||||
@ -55,19 +64,19 @@ class WaterDrop : public QWidget
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
WaterDrop(QWidget *parent = Q_NULLPTR);
|
explicit WaterDrop(QWidget *parent = nullptr);
|
||||||
void show();
|
void show();
|
||||||
void move(const QPoint &point);
|
void move(const QPoint &point);
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
void paintEvent(QPaintEvent *event);
|
void paintEvent(QPaintEvent *event);
|
||||||
void onRadiusChanged(QVariant value);
|
|
||||||
|
private slots:
|
||||||
|
void onRadiusChanged(const QVariant &value);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
class QVariantAnimation* m_waterDropAnimation;
|
QVariantAnimation *m_waterDropAnimation = nullptr;
|
||||||
int m_animationRadius;
|
int m_animationRadius;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif // PROGRESSBUTTON_H
|
#endif // PROGRESSBUTTON_H
|
||||||
|
@ -81,6 +81,7 @@ void DownloadListWidget::clearItem()
|
|||||||
// ui->listWidget->vScrollBar->scrollTop();
|
// ui->listWidget->vScrollBar->scrollTop();
|
||||||
ui->listWidget->clear();
|
ui->listWidget->clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
DownloadItem* DownloadListWidget::addItem(QString name, QString fileName, QString pkgName, const QPixmap icon, QString downloadurl)
|
DownloadItem* DownloadListWidget::addItem(QString name, QString fileName, QString pkgName, const QPixmap icon, QString downloadurl)
|
||||||
{
|
{
|
||||||
if (fileName.isEmpty())
|
if (fileName.isEmpty())
|
||||||
@ -195,21 +196,7 @@ void DownloadListWidget::m_move(int x, int y)
|
|||||||
move(x, y);
|
move(x, y);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
bool DownloadListWidget::eventFilter(QObject *watched, QEvent *event)
|
|
||||||
{
|
|
||||||
if (Q_NULLPTR == watched)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (QEvent::ActivationChange == event->type())
|
|
||||||
{
|
|
||||||
if (QApplication::activeWindow() != this)
|
|
||||||
{
|
|
||||||
this->close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return QWidget::eventFilter(watched, event);
|
|
||||||
}
|
|
||||||
void DownloadListWidget::mouseMoveEvent(QMouseEvent *event)
|
void DownloadListWidget::mouseMoveEvent(QMouseEvent *event)
|
||||||
{
|
{
|
||||||
setGeometry(m_rect);
|
setGeometry(m_rect);
|
||||||
|
@ -27,7 +27,10 @@ public:
|
|||||||
QList<QUrl> getUrlList();
|
QList<QUrl> getUrlList();
|
||||||
void m_move(int x, int y);
|
void m_move(int x, int y);
|
||||||
explicit DownloadListWidget(QWidget *parent = nullptr);
|
explicit DownloadListWidget(QWidget *parent = nullptr);
|
||||||
~DownloadListWidget();
|
~DownloadListWidget() override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void mouseMoveEvent(QMouseEvent *event) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int isdownload = false;
|
int isdownload = false;
|
||||||
@ -48,13 +51,13 @@ private:
|
|||||||
void clearItem();
|
void clearItem();
|
||||||
QRect m_rect;
|
QRect m_rect;
|
||||||
Ui::DownloadListWidget *ui;
|
Ui::DownloadListWidget *ui;
|
||||||
private slots:
|
|
||||||
bool eventFilter(QObject *, QEvent *);
|
|
||||||
void mouseMoveEvent(QMouseEvent *event);
|
|
||||||
void on_pushButton_clicked();
|
|
||||||
signals:
|
signals:
|
||||||
void downloadFinished();
|
void downloadFinished();
|
||||||
void downloadProgress(int i);
|
void downloadProgress(int i);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void on_pushButton_clicked();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DOWNLOADLISTWIDGET_H
|
#endif // DOWNLOADLISTWIDGET_H
|
||||||
|
Loading…
x
Reference in New Issue
Block a user