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