format: 代码格式化

This commit is contained in:
2022-12-23 12:13:48 +08:00
parent 89a3ab0b4c
commit fd4fdbe970
20 changed files with 473 additions and 469 deletions

View File

@@ -5,14 +5,15 @@
BaseWidgetOpacity::BaseWidgetOpacity(QWidget *parent) : DBlurEffectWidget(parent)
{
// WidgetAnimation::widgetOpacity(this,true);
// WidgetAnimation::widgetOpacity(this,true);
}
/// @brief 窗口关闭事件
/// @param event
void BaseWidgetOpacity::closeEvent(QCloseEvent *event)
{
if (!closeWindowAnimation) {
if (!closeWindowAnimation)
{
closeWindowAnimation = true;
QPropertyAnimation *animation = new QPropertyAnimation(this, "windowOpacity");
@@ -21,18 +22,20 @@ void BaseWidgetOpacity::closeEvent(QCloseEvent *event)
animation->setStartValue(1.0);
animation->setEndValue(0.0);
QObject::connect(animation, &QPropertyAnimation::valueChanged, this, [=](const QVariant &value){
this->update();
// setWindowTitle(QString("ヾ(⌒∇⌒*)See You♪ - %1%").arg(int(value.toFloat() * 100)));
});
QObject::connect(animation, &QPropertyAnimation::valueChanged, this, [=](const QVariant &value)
{
this->update();
// setWindowTitle(QString("ヾ(⌒∇⌒*)See You♪ - %1%").arg(int(value.toFloat() * 100)));
});
QObject::connect(animation, &QPropertyAnimation::finished, this, [=](){
this->close();
});
QObject::connect(animation, &QPropertyAnimation::finished, this, [=]()
{ this->close(); });
animation->start();
event->ignore();
} else {
}
else
{
event->accept();
}
}

View File

@@ -3,11 +3,10 @@
#include <QHBoxLayout>
#include <QtConcurrent>
big_image::big_image(DBlurEffectWidget *parent) :
DBlurEffectWidget(parent),
m_image(new QLabel)
big_image::big_image(DBlurEffectWidget *parent) : DBlurEffectWidget(parent),
m_image(new QLabel)
{
// setWindowFlags(this->windowFlags() | Qt::WindowStaysOnTopHint); // 设置图片对话框总在最前
// setWindowFlags(this->windowFlags() | Qt::WindowStaysOnTopHint); // 设置图片对话框总在最前
setWindowModality(Qt::ApplicationModal); // 以上无效不如直接使用 模态化对话框
setRadius(0);
setMaskAlpha(60);

View File

@@ -6,13 +6,12 @@
bool DownloadItem::isInstall = false;
DownloadItem::DownloadItem(QWidget *parent) :
QWidget(parent),
reinstall(false),
close(false),
ui(new Ui::DownloadItem),
output_w(new DDialog),
textbrowser(new QTextBrowser)
DownloadItem::DownloadItem(QWidget *parent) : QWidget(parent),
reinstall(false),
close(false),
ui(new Ui::DownloadItem),
output_w(new DDialog),
textbrowser(new QTextBrowser)
{
ui->setupUi(this);
@@ -34,7 +33,7 @@ void DownloadItem::setValue(qint64 value)
{
ui->progressBar->setValue(qint32(value));
ui->label_2->setText(QString::number(double(value) / 100) + "% (" + speed + ")");
if(ui->label_2->text().left(4) == "100%")
if (ui->label_2->text().left(4) == "100%")
{
download = 1;
ui->label_2->setText(tr("Download Complete."));
@@ -58,7 +57,7 @@ QString DownloadItem::getName()
void DownloadItem::readyInstall()
{
if(!close)
if (!close)
{
ui->progressBar->hide();
ui->pushButton_install->setEnabled(true);
@@ -90,7 +89,7 @@ void DownloadItem::setSpeed(QString s)
void DownloadItem::install(int t)
{
if(!isInstall)
if (!isInstall)
{
isInstall = true;
ui->pushButton_install->hide();
@@ -99,7 +98,7 @@ void DownloadItem::install(int t)
ui->label_2->setText(tr("Installing"));
QtConcurrent::run([=]()
{
{
QProcess installer;
switch(t)
{
@@ -164,10 +163,9 @@ void DownloadItem::install(int t)
ui->widget_spinner->hide();
DownloadItem::isInstall = false;
emit finished();
});
emit finished(); });
// emit finished();
qDebug()<<ui->label_filename->text().toUtf8();
qDebug() << ui->label_filename->text().toUtf8();
}
}

View File

@@ -8,15 +8,15 @@
ProgressButton::ProgressButton(QWidget *parent)
: QWidget{parent}
{
//this->setWindowFlags(Qt::FramelessWindowHint);
// this->setWindowFlags(Qt::FramelessWindowHint);
this->setAttribute(Qt::WA_TranslucentBackground, true);
setMinimumWidth(36);
setMinimumHeight(36);
svgPath="";
backColor=Qt::transparent;
svgPath = "";
backColor = Qt::transparent;
setMouseTracking(true);
connect(this,&ProgressButton::startProcessing,this,&ProgressButton::operationProcessing,Qt::QueuedConnection);
connect(this, &ProgressButton::startProcessing, this, &ProgressButton::operationProcessing, Qt::QueuedConnection);
}
ProgressButton::~ProgressButton()
@@ -26,63 +26,63 @@ ProgressButton::~ProgressButton()
void ProgressButton::paintEvent(QPaintEvent *event)
{
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing,true);
painter.setRenderHint(QPainter::Antialiasing, true);
auto rect = event->rect();
if(buttonState == state::normal || buttonState == state::hover)
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);
// painter.drawEllipse(QPoint(0,0),radiu,radiu);
//radiu -= 3;
// radiu -= 3;
painter.setBrush(backColor);
painter.drawEllipse(QPoint(0,0),radiu,radiu);
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));
m_svgRender.render(&painter, QRectF(-radiu / 2, -radiu / 2, radiu, radiu));
}
else if(buttonState == state::openProgress)
else if (buttonState == state::openProgress)
{
painter.translate(rect.center());
auto radiu = (rect.height() - 6) / 2 -3;
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));
painter.drawEllipse(QPoint(0, 0), radiu, radiu);
painter.setPen(QPen(backColor,3));
painter.setPen(QPen(backColor, 3));
QSvgRenderer m_svgRender;
m_svgRender.load(svgPath);
m_svgRender.render(&painter ,QRectF(-radiu / 2,-radiu / 2,radiu,radiu));
m_svgRender.render(&painter, QRectF(-radiu / 2, -radiu / 2, radiu, radiu));
QRect rect = QRect(-radiu, -radiu,
radiu*2, radiu*2);
radiu * 2, radiu * 2);
painter.setPen(QPen(color.darker(100),3));
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));
painter.drawArc(rect.adjusted(-3, -3, 3, 3), 90 * 16, -static_cast<int>(angle * 16));
}
else if(buttonState == state::closeProgress)
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);
painter.drawEllipse(QPoint(0, 0), radiu, radiu);
radiu -= 3;
painter.setBrush(backColor);
painter.drawEllipse(QPoint(0,0),radiu,radiu);
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));
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));
}
}
@@ -90,12 +90,12 @@ void ProgressButton::setProgress(int progress)
{
buttonState = state::openProgress;
ProgressButton::progress = progress;
if(progress == 0)
if (progress == 0)
{
buttonState = state::normal;
update();
}
if(progress == 100)
if (progress == 100)
{
buttonState = state::closeProgress;
update();
@@ -127,7 +127,7 @@ void ProgressButton::setColor(QColor color)
void ProgressButton::leaveEvent(QEvent *event)
{
if(buttonState == state::hover)
if (buttonState == state::hover)
{
buttonState = state::normal;
update();
@@ -137,12 +137,12 @@ void ProgressButton::leaveEvent(QEvent *event)
void ProgressButton::mousePressEvent(QMouseEvent *event)
{
if(buttonState == state::hover || buttonState == state::normal)
if (buttonState == state::hover || buttonState == state::normal)
{
widthChangeValue = (this->width() - 6) / 2;
update();
}
else if(buttonState == state::closeProgress)
else if (buttonState == state::closeProgress)
{
update();
}
@@ -152,24 +152,21 @@ void ProgressButton::mousePressEvent(QMouseEvent *event)
void ProgressButton::operationProcessing()
{
}
const int RADIUS = 60;
WaterDrop::WaterDrop(QWidget *parent)
: QWidget(parent)
, m_waterDropAnimation(nullptr)
, m_animationRadius(0)
: QWidget(parent), m_waterDropAnimation(nullptr), m_animationRadius(0)
{
this->setFixedSize(QSize(RADIUS * 2, RADIUS * 2));
this->setWindowFlags(Qt::FramelessWindowHint | Qt::Tool);
this->setAttribute(Qt::WA_TranslucentBackground);
this->setAttribute(Qt::WA_DeleteOnClose);
m_waterDropAnimation = new QVariantAnimation(this);
// m_waterDropAnimation->setEasingCurve(QEasingCurve(static_cast<QEasingCurve::Type>(QRandomGenerator::global()->bounded(40))));
// m_waterDropAnimation->setEasingCurve(QEasingCurve(static_cast<QEasingCurve::Type>(QRandomGenerator::global()->bounded(40))));
}
//把鼠标点击的点转换为圆心点坐标
// 把鼠标点击的点转换为圆心点坐标
void WaterDrop::move(const QPoint &point)
{
QPoint translatePoint = point - QPoint(RADIUS, RADIUS);
@@ -196,7 +193,7 @@ void WaterDrop::paintEvent(QPaintEvent *event)
pen.setColor(QColor(0xffffff80));
pen.setWidth(5);
painter.setPen(pen);
painter.drawEllipse(event->rect().center(),m_animationRadius, m_animationRadius);
painter.drawEllipse(event->rect().center(), m_animationRadius, m_animationRadius);
}
void WaterDrop::onRaduisChanged(QVariant value)

View File

@@ -5,13 +5,13 @@
#include <QDebug>
SmoothListWidget::SmoothListWidget(QWidget *parent) : QListWidget(parent)
{
vScrollBar->setOrientation(Qt::Orientation::Vertical); //将滚动条设置为纵向
setVerticalScrollBar(vScrollBar); //设置纵向滚动条
vScrollBar->setOrientation(Qt::Orientation::Vertical); // 将滚动条设置为纵向
setVerticalScrollBar(vScrollBar); // 设置纵向滚动条
connect(vScrollBar, SIGNAL(valueChanged(int)), this, SLOT(onSliderChanged(int)));
}
void SmoothListWidget::wheelEvent(QWheelEvent *e)
{
//当捕获到事件后,调用相对滚动的槽函数
// 当捕获到事件后,调用相对滚动的槽函数
vScrollBar->scroll(e->angleDelta().y());
}
void SmoothListWidget::onSliderChanged(int p)
@@ -21,5 +21,5 @@ void SmoothListWidget::onSliderChanged(int p)
{
emit reachedBottom(); // 1
}
emit msliderChanged(p); // 2
emit msliderChanged(p); // 2
}

View File

@@ -1,56 +1,56 @@
#include "smoothscrollbar.h"
#include <QWheelEvent>
#include <QDebug>
SmoothScrollBar::SmoothScrollBar(QWidget* parent):QScrollBar(parent)
SmoothScrollBar::SmoothScrollBar(QWidget *parent) : QScrollBar(parent)
{
m_scrollAni=new QPropertyAnimation(this);
m_scrollAni = new QPropertyAnimation(this);
m_scrollAni->setTargetObject(this);
m_scrollAni->setPropertyName("value");
m_scrollAni->setEasingCurve(QEasingCurve::OutQuint); //设置动画曲线在Qt文档中有详细的介绍
m_scrollAni->setDuration(500); //设置动画时间,数值越小播放越快
m_targetValue_v=value(); //将m_targetValue_v初始化
m_scrollAni->setEasingCurve(QEasingCurve::OutQuint); // 设置动画曲线在Qt文档中有详细的介绍
m_scrollAni->setDuration(500); // 设置动画时间,数值越小播放越快
m_targetValue_v = value(); // 将m_targetValue_v初始化
}
void SmoothScrollBar::setValue(int value)
{
m_scrollAni->stop();//停止现在的动画,防止出现冲突
m_scrollAni->setStartValue(this->value()); //设置动画滚动的初始值为当前位置
m_scrollAni->setEndValue(value); //设置动画的结束位置为目标值
m_scrollAni->start(); //开始动画
m_scrollAni->stop(); // 停止现在的动画,防止出现冲突
m_scrollAni->setStartValue(this->value()); // 设置动画滚动的初始值为当前位置
m_scrollAni->setEndValue(value); // 设置动画的结束位置为目标值
m_scrollAni->start(); // 开始动画
}
void SmoothScrollBar::scrollTop()
{
setValue(-m_targetValue_v); //开始动画
m_targetValue_v=0;
setValue(-m_targetValue_v); // 开始动画
m_targetValue_v = 0;
}
void SmoothScrollBar::scroll(int value)
{
//这里推荐评论区中大佬优化的写法
if(m_targetValue_v-value>=0)
// 这里推荐评论区中大佬优化的写法
if (m_targetValue_v - value >= 0)
{
m_targetValue_v-=value; //将目标值和相对位置进行运算
setValue(m_targetValue_v); //开始动画
m_targetValue_v -= value; // 将目标值和相对位置进行运算
setValue(m_targetValue_v); // 开始动画
}
}
void SmoothScrollBar::mousePressEvent(QMouseEvent *e)
{
//当使用鼠标操作滚动条时不会刷新m_targetValue_v的值因而需要重写事件对其进行刷新。
// 当使用鼠标操作滚动条时不会刷新m_targetValue_v的值因而需要重写事件对其进行刷新。
m_scrollAni->stop();
QScrollBar::mousePressEvent(e);
m_targetValue_v=value();
m_targetValue_v = value();
}
void SmoothScrollBar::mouseReleaseEvent(QMouseEvent *e)
{
m_scrollAni->stop();
QScrollBar::mouseReleaseEvent(e);
m_targetValue_v=value();
m_targetValue_v = value();
}
void SmoothScrollBar::mouseMoveEvent(QMouseEvent *e)
{
m_scrollAni->stop();
QScrollBar::mouseMoveEvent(e);
m_targetValue_v=value();
m_targetValue_v = value();
}

View File

@@ -13,7 +13,8 @@ WebEnginePage::~WebEnginePage()
void WebEnginePage::setUrl(const QUrl &url)
{
if (m_currentUrl == url) {
if (m_currentUrl == url)
{
return;
}
@@ -32,7 +33,8 @@ QWebEnginePage *WebEnginePage::createWindow(QWebEnginePage::WebWindowType type)
void WebEnginePage::slotUrlChanged(const QUrl &url)
{
if (m_currentUrl == url) {
if (m_currentUrl == url)
{
sender()->deleteLater();
return;
}

View File

@@ -3,23 +3,22 @@
#include <QGraphicsOpacityEffect>
#include <QPropertyAnimation>
#include <QDebug>
DownloadListWidget::DownloadListWidget(QWidget *parent) :
DBlurEffectWidget(parent),
ui(new Ui::DownloadListWidget)
DownloadListWidget::DownloadListWidget(QWidget *parent) : DBlurEffectWidget(parent),
ui(new Ui::DownloadListWidget)
{
ui->setupUi(this);
installEventFilter(this);
this->setAttribute(Qt::WA_Hover,true);
this->setAttribute(Qt::WA_Hover, true);
setFocus();
setFixedSize(500,400);
setFixedSize(500, 400);
setMaskAlpha(250);
ui->listWidget->hide();
ui->widget->show();
// 计算显示下载速度
download_speed.setInterval(1000);
download_speed.start();
connect(&download_speed,&QTimer::timeout,[=]()
{
connect(&download_speed, &QTimer::timeout, [=]()
{
if(isdownload && theSpeed == "")
{
size1 = download_size;
@@ -47,13 +46,13 @@ DownloadListWidget::DownloadListWidget(QWidget *parent) :
downloaditemlist[nowDownload - 1]->setSpeed(theSpeed);
}else{
emit downloadProgress(0);
}
});
} });
}
DownloadListWidget::~DownloadListWidget()
{
if (downloadController) {
if (downloadController)
{
downloadController->stopDownload();
downloadController->deleteLater();
}
@@ -64,41 +63,41 @@ DownloadListWidget::~DownloadListWidget()
void DownloadListWidget::clearItem()
{
ui->listWidget->vScrollBar->scrollTop();
int n=ui->listWidget->count();
for(int i=0;i<n;i++)
int n = ui->listWidget->count();
for (int i = 0; i < n; i++)
{
QListWidgetItem *item = ui->listWidget->takeItem(0);
QWidget *card = ui->listWidget->itemWidget(item);
delete card;
card = NULL;
card = NULL;
delete item;
item = NULL;
item = NULL;
}
ui->listWidget->clear();
}
void DownloadListWidget::addItem(QString name,QString fileName,QString pkgName,const QPixmap icon,QString downloadurl)
void DownloadListWidget::addItem(QString name, QString fileName, QString pkgName, const QPixmap icon, QString downloadurl)
{
if(fileName.isEmpty())
if (fileName.isEmpty())
{
return;
}
urList.append(downloadurl);
allDownload += 1;
DownloadItem *di=new DownloadItem(this);
dlist<<downloadurl;
downloaditemlist<<di;
DownloadItem *di = new DownloadItem(this);
dlist << downloadurl;
downloaditemlist << di;
di->setName(name);
di->setFileName(fileName);
di->pkgName=pkgName;
di->pkgName = pkgName;
di->seticon(icon);
QListWidgetItem* pItem = new QListWidgetItem();
QListWidgetItem *pItem = new QListWidgetItem();
pItem->setSizeHint(QSize(240, 50));
ui->listWidget->addItem(pItem);
ui->listWidget->setItemWidget(pItem, di);
if(!isBusy)
if (!isBusy)
{
nowDownload += 1;
startRequest(urList.at(nowDownload - 1), fileName); // 进行链接请求
startRequest(urList.at(nowDownload - 1), fileName); // 进行链接请求
}
}
@@ -120,10 +119,10 @@ void DownloadListWidget::startRequest(QUrl url, QString fileName)
isdownload = true;
downloaditemlist[allDownload - 1]->free = false;
downloadController = new DownloadController(this); // 并发下载,在点击下载按钮的时候才会初始化
downloadController = new DownloadController(this); // 并发下载,在点击下载按钮的时候才会初始化
connect(downloadController, &DownloadController::downloadProcess, this, &DownloadListWidget::updateDataReadProgress);
connect(downloadController, &DownloadController::downloadFinished, this, &DownloadListWidget::httpFinished);
//connect(downloadController, &DownloadController::errorOccur, this, [=](QString msg){this->sendNotification(msg);});
// connect(downloadController, &DownloadController::errorOccur, this, [=](QString msg){this->sendNotification(msg);});
downloadController->setFilename(fileName);
downloadController->startDownload(url.toString());
}
@@ -135,37 +134,37 @@ void DownloadListWidget::httpFinished() // 完成下载
downloaditemlist[nowDownload - 1]->readyInstall();
downloaditemlist[nowDownload - 1]->free = true;
emit downloadFinished();
if(nowDownload < allDownload)
if (nowDownload < allDownload)
{
// 如果有排队则下载下一个
qDebug() << "切换下一个下载...";
nowDownload += 1;
while(downloaditemlist[nowDownload - 1]->close)
while (downloaditemlist[nowDownload - 1]->close)
{
nowDownload += 1;
if(nowDownload >= allDownload)
if (nowDownload >= allDownload)
{
nowDownload = allDownload;
return;
}
}
QString fileName = downloaditemlist[nowDownload - 1]->getName();
startRequest(urList.at(nowDownload-1), fileName);
startRequest(urList.at(nowDownload - 1), fileName);
}
}
void DownloadListWidget::updateDataReadProgress(QString speedInfo, qint64 bytesRead, qint64 totalBytes)
{
if(totalBytes <= 0)
if (totalBytes <= 0)
{
return;
}
theSpeed = speedInfo;
downloaditemlist[nowDownload - 1]->setMax(10000); // 最大值
downloaditemlist[nowDownload - 1]->setValue(int(bytesRead * 100 / totalBytes) * 100); // 当前值
downloaditemlist[nowDownload - 1]->setMax(10000); // 最大值
downloaditemlist[nowDownload - 1]->setValue(int(bytesRead * 100 / totalBytes) * 100); // 当前值
emit downloadProgress(int(bytesRead * 100 / totalBytes));
download_size = bytesRead;
if(downloaditemlist[nowDownload - 1]->close)
if (downloaditemlist[nowDownload - 1]->close)
{
// 随时检测下载是否被取消
downloadController->disconnect();
@@ -175,21 +174,23 @@ void DownloadListWidget::updateDataReadProgress(QString speedInfo, qint64 bytesR
}
}
void DownloadListWidget::m_move(int x,int y)
void DownloadListWidget::m_move(int x, int y)
{
m_rect.setX(x);
m_rect.setY(y);
move(x,y);
move(x, y);
return;
}
bool DownloadListWidget::eventFilter(QObject *watched, QEvent *event)
{
if (Q_NULLPTR == watched) {
if (Q_NULLPTR == watched)
{
return false;
}
if (QEvent::ActivationChange == event->type()) {
if(QApplication::activeWindow() != this){
if (QEvent::ActivationChange == event->type())
{
if (QApplication::activeWindow() != this)
{
this->close();
}
}