mirror of
https://gitee.com/spark-store-project/spark-store
synced 2025-07-18 19:42:21 +08:00
更换SpkWindow基类为QWidget并修复多个问题
修复mResizable为false时阻止窗口移动的问题 更改About窗口为固定大小
This commit is contained in:
parent
58a0336a23
commit
f2e417e02a
@ -7,9 +7,12 @@ SpkAbout::SpkAbout(QWidget *parent) : SpkDialog(parent)
|
||||
{
|
||||
setWindowModality(Qt::ApplicationModal);
|
||||
|
||||
mDialogWidget->setMaximumWidth(600);
|
||||
// mDialogWidget->setMaximumWidth(600);
|
||||
mDialogWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
|
||||
setFixedSize(550, 450);
|
||||
SetResizable(false); // Do you like the dilemma of using self created widget?
|
||||
|
||||
mIconLay = new QHBoxLayout;
|
||||
|
||||
mSpkVersion = new QLabel;
|
||||
@ -24,25 +27,31 @@ SpkAbout::SpkAbout(QWidget *parent) : SpkDialog(parent)
|
||||
mSpkIcon = new QLabel;
|
||||
mSpkIcon->setPixmap(QIcon(":/icons/spark-store.svg").pixmap(QSize(128, 128)));
|
||||
|
||||
auto description =
|
||||
auto description = tr(
|
||||
"Spark Store was started when Chinese home-grown Linux operating systems "
|
||||
"had initially hit the market. Because the Linux desktop ecosystem is not "
|
||||
"good enough at the time being, volunteers built this small App Store in "
|
||||
"the hope that users can get useful applications faster.\n\n"
|
||||
"Right now we are not just a Chinese group. We are discovering our way into "
|
||||
"more Debian-based Linux OSes, and build a real community software repository "
|
||||
"for users around the world.";
|
||||
"for users around the world.");
|
||||
mDescriptionText = new QLabel;
|
||||
mDescriptionText->setObjectName("spk_about_desc");
|
||||
mDescriptionText->setWordWrap(true);
|
||||
mDescriptionText->setText(description);
|
||||
|
||||
mIconLay->addStretch(3);
|
||||
mIconLay->addWidget(mSpkIcon);
|
||||
mIconLay->addStretch(1);
|
||||
mIconLay->addWidget(mSpkVersion);
|
||||
mIconLay->setAlignment(Qt::AlignVCenter);
|
||||
mIconLay->addStretch(3);
|
||||
mIconLay->setAlignment(Qt::AlignVCenter | Qt::AlignHCenter);
|
||||
|
||||
AddStretch();
|
||||
AddLayout(mIconLay);
|
||||
AddSpacing(18);
|
||||
AddWidget(mDescriptionText);
|
||||
AddStretch();
|
||||
SetMargin(18, 0, 18, 18);
|
||||
|
||||
GetTitleBar()->SetOperationButton(SpkTitleBar::OperationButton::Close);
|
||||
|
@ -2,22 +2,23 @@
|
||||
#include "spkdialog.h"
|
||||
#include <QEventLoop>
|
||||
|
||||
SpkDialog::SpkDialog(QWidget *parent) : SpkWindow(parent, Qt::Dialog)
|
||||
SpkDialog::SpkDialog(QWidget *parent) : SpkWindow(parent)
|
||||
{
|
||||
mDialogWidget = new QWidget;
|
||||
mMainVLay = new QVBoxLayout(mDialogWidget);
|
||||
mMainVLay = new QVBoxLayout;
|
||||
mWidgetsVLay = new QVBoxLayout();
|
||||
mBtnLay = new QHBoxLayout();
|
||||
mBtnGroup = new QButtonGroup(this);
|
||||
|
||||
mMainVLay->addLayout(mWidgetsVLay);
|
||||
mMainVLay->addLayout(mBtnLay);
|
||||
mMainVLay->setSizeConstraint(QLayout::SetMinimumSize);
|
||||
|
||||
mBtnLay->setAlignment(Qt::AlignCenter);
|
||||
|
||||
SetCentralWidget(mDialogWidget);
|
||||
|
||||
mDialogWidget->setLayout(mMainVLay);
|
||||
|
||||
// idClicked is not available on platforms we support, shouldn't change it
|
||||
connect(mBtnGroup, QOverload<int>::of(&QButtonGroup::buttonClicked),
|
||||
this, &SpkDialog::ButtonPressed);
|
||||
@ -76,6 +77,11 @@ void SpkDialog::AddSpacing(int a)
|
||||
mWidgetsVLay->addSpacing(a);
|
||||
}
|
||||
|
||||
void SpkDialog::AddStretch(int a)
|
||||
{
|
||||
mWidgetsVLay->addStretch(a);
|
||||
}
|
||||
|
||||
void SpkDialog::SetMargin(int a)
|
||||
{
|
||||
mWidgetsVLay->setMargin(a);
|
||||
|
@ -18,9 +18,11 @@ SpkMainWindow::SpkMainWindow(QWidget *parent) : SpkWindow(parent)
|
||||
SetTitleBar(ui->TitleBar, false);
|
||||
RefreshCategoryData();
|
||||
|
||||
auto size = QGuiApplication::primaryScreen()->size() * 0.25;
|
||||
resize(QGuiApplication::primaryScreen()->size() * 0.5);
|
||||
move(size.width(), size.height());
|
||||
auto size = QGuiApplication::primaryScreen()->size() * 0.5;
|
||||
size = size.expandedTo(QSize(900, 600));
|
||||
resize(size);
|
||||
auto pos = QGuiApplication::primaryScreen()->size() * 0.5 - size * 0.5;
|
||||
move(pos.width(), pos.height());
|
||||
}
|
||||
|
||||
void SpkMainWindow::SwitchDayNightTheme()
|
||||
|
@ -1,6 +1,7 @@
|
||||
|
||||
#include <QEvent>
|
||||
#include <QMouseEvent>
|
||||
#include "spkwindow.h"
|
||||
#include "spkui_general.h"
|
||||
#include "spktitlebar.h"
|
||||
|
||||
|
@ -9,22 +9,25 @@
|
||||
#include "spklogging.h"
|
||||
#include "spkwindow.h"
|
||||
#include "spkui_general.h"
|
||||
#include "spktitlebar.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
SpkWindow::SpkWindow(QWidget *parent, Qt::WindowFlags flags) : QMainWindow(parent, flags)
|
||||
SpkWindow::SpkWindow(QWidget *parent) : QWidget(parent)
|
||||
{
|
||||
mUseCustomEvents = SpkUi::DtkPlugin == nullptr; // Put to the front, to prevent warnings
|
||||
if(SpkUi::DtkPlugin && !qgetenv("SPARK_NO_DXCB").toInt())
|
||||
if(SpkUi::DtkPlugin && !qEnvironmentVariableIntValue("SPARK_NO_DXCB"))
|
||||
SpkUi::DtkPlugin->addWindow(this, parent); // Register window to DXcb so we got Deepin
|
||||
else
|
||||
setWindowFlags(Qt::FramelessWindowHint); // Remove default title bar
|
||||
setAttribute(Qt::WA_Hover);
|
||||
mCornerRadius = 5;
|
||||
mUserCentralWidget = nullptr;
|
||||
mResizable = true;
|
||||
mMoving = mResizing = false;
|
||||
mCloseHook = nullptr;
|
||||
mMaximized = windowState().testFlag(Qt::WindowMaximized);
|
||||
setMouseTracking(true);
|
||||
|
||||
PopulateUi();
|
||||
}
|
||||
@ -38,7 +41,7 @@ bool SpkWindow::event(QEvent *evt)
|
||||
{
|
||||
// These custom events weren't useful for Deepin platform
|
||||
if(!mUseCustomEvents)
|
||||
return QMainWindow::event(evt);
|
||||
return QWidget::event(evt);
|
||||
|
||||
switch(evt->type())
|
||||
{
|
||||
@ -53,7 +56,7 @@ bool SpkWindow::event(QEvent *evt)
|
||||
}
|
||||
case QEvent::MouseButtonPress:
|
||||
{
|
||||
if(!mResizable) break;
|
||||
// if(!mResizable) break;
|
||||
auto e = static_cast<QMouseEvent*>(evt);
|
||||
if(e->button() != Qt::LeftButton) break;
|
||||
auto edge = DetectEdgeOnThis(e->pos());
|
||||
@ -65,7 +68,7 @@ bool SpkWindow::event(QEvent *evt)
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!QMainWindow::event(evt) || 1)
|
||||
if(!QWidget::event(evt) || 1) // Movable property is not implemented, let move anywhere
|
||||
{
|
||||
mMoveOffset = e->globalPos() - pos();
|
||||
mMoving = true;
|
||||
@ -77,7 +80,7 @@ bool SpkWindow::event(QEvent *evt)
|
||||
}
|
||||
case QEvent::MouseButtonRelease:
|
||||
{
|
||||
if(!mResizable) break;
|
||||
// if(!mResizable) break;
|
||||
auto e = static_cast<QMouseEvent*>(evt);
|
||||
if(e->button() != Qt::LeftButton) break;
|
||||
mResizing = false;
|
||||
@ -120,7 +123,7 @@ bool SpkWindow::event(QEvent *evt)
|
||||
default:
|
||||
;
|
||||
}
|
||||
return QMainWindow::event(evt);
|
||||
return QWidget::event(evt);
|
||||
}
|
||||
|
||||
Qt::Edges SpkWindow::DetectEdgeOnThis(QPoint p)
|
||||
@ -227,16 +230,16 @@ void SpkWindow::closeEvent(QCloseEvent *e)
|
||||
|
||||
void SpkWindow::paintEvent(QPaintEvent *e)
|
||||
{
|
||||
//FIXME: DOESN'T WORK!
|
||||
// QPainter painter(this);
|
||||
// painter.setBrush(QBrush(Qt::NoBrush));
|
||||
// painter.setPen(QPen(SpkUi::ColorLine));
|
||||
// QRect rect = this->rect();
|
||||
// rect.setWidth(rect.width() - 2);
|
||||
// rect.setHeight(rect.height() - 2);
|
||||
// rect.adjust(-1, -1, 1, 1);
|
||||
// painter.drawRect(rect);
|
||||
// QWidget::paintEvent(e);
|
||||
QWidget::paintEvent(e);
|
||||
if(!mUseCustomEvents)
|
||||
return;
|
||||
|
||||
QPainter painter(this);
|
||||
painter.setBrush(QBrush(Qt::NoBrush));
|
||||
painter.setPen(QPen(SpkUi::ColorLine));
|
||||
QRect rect = this->rect();
|
||||
rect.adjust(0, 0, -1, -1);
|
||||
painter.drawRect(rect);
|
||||
}
|
||||
|
||||
void SpkWindow::SetCornerRadius(int radius)
|
||||
@ -246,22 +249,22 @@ void SpkWindow::SetCornerRadius(int radius)
|
||||
|
||||
void SpkWindow::PopulateUi()
|
||||
{
|
||||
mCentralWidget = new QWidget(this);
|
||||
mMainVLayout = new QVBoxLayout;
|
||||
mTitleBarComponent = new SpkTitleBar(this);
|
||||
|
||||
mCentralWidget->setLayout(mMainVLayout);
|
||||
setLayout(mMainVLayout);
|
||||
|
||||
mMainVLayout->addWidget(mTitleBarComponent);
|
||||
mMainVLayout->setAlignment(Qt::AlignTop);
|
||||
mMainVLayout->setContentsMargins(0, 0, 0, 0);
|
||||
if(mUseCustomEvents)
|
||||
mMainVLayout->setContentsMargins(1, 1, 1, 1);
|
||||
else
|
||||
mMainVLayout->setContentsMargins(0, 0, 0, 0);
|
||||
mMainVLayout->setSpacing(0);
|
||||
|
||||
mTitleBarComponent->SetTitle(qAppName());
|
||||
mTitleBarComponent->SetUseIcon(false);
|
||||
mTitleBarComponent->SetLinkedWindow(this);
|
||||
|
||||
setCentralWidget(mCentralWidget);
|
||||
setWindowFlag(Qt::NoDropShadowWindowHint, false);
|
||||
}
|
||||
|
||||
|
@ -17,6 +17,7 @@ class SpkDialog : public SpkWindow
|
||||
void AddWidget(QWidget*);
|
||||
void AddLayout(QLayout*);
|
||||
void AddSpacing(int);
|
||||
void AddStretch(int a = 0);
|
||||
void SetMargin(int);
|
||||
void SetMargin(int, int, int, int);
|
||||
int Exec();
|
||||
|
@ -50,7 +50,7 @@ class SpkTitleBar : public QWidget
|
||||
void SetTitle(QString t) { mTitle->setText(t); }
|
||||
QString GetTitle() { return mTitle->text(); }
|
||||
void SetUseIcon(bool t) { mIcon->setVisible(t); }
|
||||
void SetLinkedWindow(QMainWindow *w) { mLinkedWindow = w; }
|
||||
void SetLinkedWindow(SpkWindow *w) { mLinkedWindow = w; }
|
||||
|
||||
QHBoxLayout *GetUserSpace() { return mUserSpace; }
|
||||
protected:
|
||||
@ -59,7 +59,7 @@ class SpkTitleBar : public QWidget
|
||||
private:
|
||||
QLabel *mIcon;
|
||||
QLabel *mTitle;
|
||||
QMainWindow *mLinkedWindow;
|
||||
SpkWindow *mLinkedWindow;
|
||||
QHBoxLayout *mMainLayout, *mUserSpace, *mBtnGroup;
|
||||
SpkTitleBarDefaultButton *mBtnMin, *mBtnMaxRestore, *mBtnClose;
|
||||
|
||||
|
@ -4,16 +4,16 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QFrame>
|
||||
#include <QHBoxLayout>
|
||||
#include <QVBoxLayout>
|
||||
#include <QPushButton>
|
||||
#include <QLabel>
|
||||
#include <QCloseEvent>
|
||||
#include "spktitlebar.h"
|
||||
|
||||
class SpkWindow : public QMainWindow
|
||||
class SpkTitleBar;
|
||||
|
||||
class SpkWindow : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
@ -21,7 +21,7 @@ class SpkWindow : public QMainWindow
|
||||
static constexpr int BorderWidth = 7;
|
||||
|
||||
private:
|
||||
QWidget *mCentralWidget, *mUserCentralWidget;
|
||||
QWidget *mUserCentralWidget;
|
||||
QVBoxLayout *mMainVLayout;
|
||||
SpkTitleBar *mTitleBarComponent;
|
||||
int mCornerRadius;
|
||||
@ -32,7 +32,7 @@ class SpkWindow : public QMainWindow
|
||||
bool mUseCustomEvents;
|
||||
|
||||
public:
|
||||
SpkWindow(QWidget *parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags());
|
||||
SpkWindow(QWidget *parent = nullptr);
|
||||
~SpkWindow() override;
|
||||
void SetCentralWidget(QWidget *);
|
||||
bool GetUseTitleBar();
|
||||
@ -62,4 +62,6 @@ class SpkWindow : public QMainWindow
|
||||
|
||||
private:
|
||||
void PopulateUi();
|
||||
|
||||
void paintWindowBorder();
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user