mirror of
https://gitee.com/spark-store-project/spark-store
synced 2025-05-17 06:39:50 +08:00
fix: compatible with deepin V23 compact mode
modify titlebar layout, widget size and animation; modify whole window layout, allow titlebar to resize automatically Log: compatible with deepin V23 compact mode
This commit is contained in:
parent
b292c6cbf2
commit
b49ea2c71f
@ -22,9 +22,6 @@
|
||||
#define AppPageSearchlist 1
|
||||
#define AppPageAppdetail 2
|
||||
#define AppPageSettings 3
|
||||
#define WaylandSearchCenter 1
|
||||
#define OtherSearchCenter 2
|
||||
#define RightSearchSpace 1
|
||||
#define UploadServerUrl "https://upload.deepinos.org.cn/"
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent)
|
||||
@ -126,6 +123,16 @@ void MainWindow::closeEvent(QCloseEvent *event)
|
||||
BaseWidgetOpacity::closeEvent(event);
|
||||
}
|
||||
|
||||
void MainWindow::changeEvent(QEvent *event)
|
||||
{
|
||||
if (event->type() != QEvent::StyleChange) {
|
||||
return BaseWidgetOpacity::changeEvent(event);
|
||||
}
|
||||
|
||||
BaseWidgetOpacity::changeEvent(event);
|
||||
downloadButton->setFixedSize(searchEdit->sizeHint().height(), searchEdit->sizeHint().height());
|
||||
}
|
||||
|
||||
void MainWindow::initUI()
|
||||
{
|
||||
QSettings config(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + "/config.ini", QSettings::IniFormat);
|
||||
@ -159,8 +166,9 @@ void MainWindow::initTitleBar()
|
||||
ui->titlebar->setBackgroundTransparent(true);
|
||||
|
||||
// 初始化标题栏控件
|
||||
DLabel *title = new DLabel(ui->titlebar);
|
||||
title->setText(tr("Spark Store"));
|
||||
DLabel *titleLabel = new DLabel(ui->titlebar);
|
||||
titleLabel->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
|
||||
titleLabel->setText(tr("Spark Store"));
|
||||
|
||||
backButton = new DPushButton(ui->titlebar);
|
||||
|
||||
@ -170,34 +178,36 @@ void MainWindow::initTitleBar()
|
||||
searchEdit->lineEdit()->setFixedWidth(350);
|
||||
|
||||
downloadButton = new ProgressButton(ui->titlebar);
|
||||
downloadButton->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
||||
downloadButton->setDownloadListWidget(downloadlistwidget);
|
||||
downloadButton->setFocusPolicy(Qt::FocusPolicy::ClickFocus);
|
||||
downloadButton->setFixedSize(searchEdit->sizeHint().height(), searchEdit->sizeHint().height());
|
||||
downloadlistwidget->setFocusProxy(downloadButton);
|
||||
|
||||
QWidget *w_titlebar = new QWidget(ui->titlebar);
|
||||
QHBoxLayout *ly_titlebar = new QHBoxLayout(w_titlebar);
|
||||
ly_titlebar->addWidget(title);
|
||||
ly_titlebar->addWidget(backButton);
|
||||
// Check wayland configs
|
||||
QSettings config(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + "/config.ini", QSettings::IniFormat);
|
||||
if (!config.value("runtime/isDDE").toBool() && config.value("runtime/useWayland").toBool())
|
||||
{
|
||||
// Wayland 搜索栏居中
|
||||
ly_titlebar->addStretch(WaylandSearchCenter);
|
||||
}
|
||||
else
|
||||
{
|
||||
// dwayland dxcb 搜索栏顶部右侧居中
|
||||
ly_titlebar->addStretch(OtherSearchCenter);
|
||||
}
|
||||
ly_titlebar->addWidget(searchEdit);
|
||||
ly_titlebar->addWidget(downloadButton);
|
||||
ly_titlebar->addStretch(RightSearchSpace);
|
||||
ui->titlebar->setCustomWidget(w_titlebar);
|
||||
QWidget *customWidget = new QWidget(ui->titlebar);
|
||||
customWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
||||
ui->titlebar->setCustomWidget(customWidget);
|
||||
|
||||
QHBoxLayout *customWidgetLayout = new QHBoxLayout(customWidget);
|
||||
customWidgetLayout->setContentsMargins(8, 0, 0, 0);
|
||||
customWidgetLayout->setSpacing(8);
|
||||
customWidgetLayout->addWidget(titleLabel, 0, Qt::AlignLeft);
|
||||
customWidgetLayout->addWidget(backButton, 0, Qt::AlignLeft);
|
||||
QWidget *centralWidget = new QWidget(customWidget);
|
||||
centralWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
|
||||
customWidgetLayout->addWidget(centralWidget, 1, Qt::AlignHCenter);
|
||||
|
||||
QHBoxLayout *centralLayout = new QHBoxLayout(centralWidget);
|
||||
centralLayout->setContentsMargins(0, 0, 10, 0);
|
||||
centralLayout->setSpacing(0);
|
||||
|
||||
centralLayout->addWidget(searchEdit, 0, Qt::AlignHCenter);
|
||||
centralLayout->addSpacing(10);
|
||||
centralLayout->addWidget(downloadButton, 0, Qt::AlignHCenter);
|
||||
|
||||
initTitleBarMenu();
|
||||
|
||||
backButton->hide();
|
||||
backButton->setDisabled(true);
|
||||
downloadlistwidget->hide();
|
||||
}
|
||||
|
||||
@ -353,9 +363,9 @@ void MainWindow::initConnections()
|
||||
ui->stackedWidget->setCurrentIndex(pageHistory.at(pageHistory.count() - 2));
|
||||
pageHistory.removeLast();
|
||||
if (pageHistory.count() > 1) {
|
||||
backButton->show();
|
||||
backButton->setEnabled(true);
|
||||
} else {
|
||||
backButton->hide();
|
||||
backButton->setDisabled(true);
|
||||
} });
|
||||
|
||||
// 搜索事件
|
||||
@ -446,11 +456,11 @@ void MainWindow::switchPage(int now) // 临时方案,回家后修改
|
||||
qDebug() << pageHistory.count();
|
||||
if (pageHistory.count() >= 1)
|
||||
{
|
||||
backButton->show();
|
||||
backButton->setEnabled(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
backButton->hide();
|
||||
backButton->setDisabled(true);
|
||||
}
|
||||
ui->stackedWidget->setCurrentIndex(now);
|
||||
ui->stackedWidget->currentWidget()->setFocus();
|
||||
|
@ -34,6 +34,7 @@ public:
|
||||
|
||||
protected:
|
||||
void closeEvent(QCloseEvent *event) override;
|
||||
void changeEvent(QEvent *event) override;
|
||||
|
||||
private:
|
||||
void initUI();
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -9,10 +9,6 @@
|
||||
ProgressButton::ProgressButton(QWidget *parent)
|
||||
: QWidget{parent}
|
||||
{
|
||||
// this->setWindowFlags(Qt::FramelessWindowHint);
|
||||
// this->setAttribute(Qt::WA_TranslucentBackground, true);
|
||||
setMinimumSize(36, 36);
|
||||
|
||||
svgPath = "";
|
||||
backColor = Qt::transparent;
|
||||
|
||||
@ -77,12 +73,9 @@ void ProgressButton::mousePressEvent(QMouseEvent *event)
|
||||
|
||||
void ProgressButton::mouseReleaseEvent(QMouseEvent *event)
|
||||
{
|
||||
if (buttonState == state::hover || buttonState == state::normal)
|
||||
{
|
||||
widthChangeValue = (this->width() - 6) / 2;
|
||||
update();
|
||||
}
|
||||
else if (buttonState == state::closeProgress)
|
||||
if (buttonState == state::hover
|
||||
|| buttonState == state::normal
|
||||
|| buttonState == state::closeProgress)
|
||||
{
|
||||
update();
|
||||
}
|
||||
@ -135,15 +128,11 @@ void ProgressButton::paintEvent(QPaintEvent *event)
|
||||
|
||||
if (buttonState == state::normal || buttonState == state::hover)
|
||||
{
|
||||
int radius = (rect.height() - 6) / 2;
|
||||
painter.translate(rect.center());
|
||||
qreal radius = rect.height() / 2.0;
|
||||
painter.translate(QRectF(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);
|
||||
painter.drawEllipse(QPointF(0, 0), radius, radius);
|
||||
|
||||
QSvgRenderer m_svgRender;
|
||||
m_svgRender.load(svgPath);
|
||||
@ -151,42 +140,34 @@ void ProgressButton::paintEvent(QPaintEvent *event)
|
||||
}
|
||||
else if (buttonState == state::openProgress)
|
||||
{
|
||||
painter.translate(rect.center());
|
||||
int radius = (rect.height() - 6) / 2 - 3;
|
||||
qreal radius = rect.height() / 2.0 - 1;
|
||||
painter.translate(QRectF(rect).center());
|
||||
painter.setPen(QPen(backColor.darker(), 2));
|
||||
painter.setBrush(backColor);
|
||||
painter.setPen(QPen(backColor, 3));
|
||||
painter.drawEllipse(QPoint(0, 0), radius, radius);
|
||||
painter.drawEllipse(QPointF(0, 0), radius, radius);
|
||||
|
||||
painter.setPen(QPen(backColor, 3));
|
||||
QRectF rectF = QRectF(-radius, -radius, radius * 2, radius * 2);
|
||||
painter.setPen(QPen(color.darker(100), 2));
|
||||
qreal angle = progress * 360 / 100 * 1.0;
|
||||
painter.drawArc(rectF, 90 * 16, -qIntCast(angle * 16));
|
||||
|
||||
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;
|
||||
qreal radius = rect.height() / 2.0 - 1;
|
||||
painter.translate(QRectF(rect).center());
|
||||
painter.setPen(QPen(color.darker(100), 2));
|
||||
painter.setBrush(backColor);
|
||||
painter.drawEllipse(QPoint(0, 0), radius, radius);
|
||||
painter.drawEllipse(QPointF(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));
|
||||
painter.setPen(QPen(color, 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
|
||||
painter.drawLine(QPointF(-radius / 3, 0),
|
||||
QPointF(-radius / 5, radius / 3));
|
||||
painter.drawLine(QPointF(-radius / 5, radius / 3),
|
||||
QPointF(radius / 4, -radius / 4));
|
||||
}
|
||||
QWidget::paintEvent(event);
|
||||
}
|
||||
@ -212,7 +193,7 @@ WaterDrop::WaterDrop(QWidget *parent)
|
||||
// 把鼠标点击的点转换为圆心点坐标
|
||||
void WaterDrop::move(const QPoint &point)
|
||||
{
|
||||
QPoint translatePoint = point - QPoint(RADIUS, RADIUS);
|
||||
QPoint translatePoint = point - rect().center();
|
||||
QWidget::move(translatePoint);
|
||||
}
|
||||
|
||||
@ -223,7 +204,7 @@ void WaterDrop::show()
|
||||
m_waterDropAnimation->setDuration(350);
|
||||
|
||||
connect(m_waterDropAnimation, &QVariantAnimation::valueChanged, this, &WaterDrop::onRadiusChanged);
|
||||
connect(m_waterDropAnimation, &QVariantAnimation::finished, this, &WaterDrop::close);
|
||||
connect(m_waterDropAnimation, &QVariantAnimation::finished, this, &WaterDrop::deleteLater);
|
||||
m_waterDropAnimation->start(QVariantAnimation::DeleteWhenStopped);
|
||||
QWidget::show();
|
||||
}
|
||||
|
@ -52,7 +52,6 @@ private:
|
||||
QColor backColor;
|
||||
QColor color;
|
||||
QString svgPath;
|
||||
int widthChangeValue{0};
|
||||
int progress{0};//处理百分比
|
||||
|
||||
bool m_mouseMoved = false;
|
||||
|
Loading…
x
Reference in New Issue
Block a user