mirror of
https://gitee.com/spark-store-project/spark-store
synced 2025-12-13 12:22:05 +08:00
进度更新
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
class SpkDialog : public SpkWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
friend class SpkMsgBox;
|
||||
public:
|
||||
SpkDialog(QWidget *parent = nullptr);
|
||||
~SpkDialog();
|
||||
|
||||
34
inc/spkloading.h
Normal file
34
inc/spkloading.h
Normal file
@@ -0,0 +1,34 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QWidget>
|
||||
#include <QTimeLine>
|
||||
|
||||
class SpkLoading : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit SpkLoading(QWidget *parent = nullptr);
|
||||
virtual void paintEvent(QPaintEvent *e) override;
|
||||
virtual void resizeEvent(QResizeEvent *e) override;
|
||||
|
||||
private:
|
||||
QTimeLine *mAnimTimer;
|
||||
QList<int> mSizeList;
|
||||
int mUserHeight = 0;
|
||||
int dw, dh;
|
||||
double dx, dy;
|
||||
|
||||
public slots:
|
||||
void start() { mAnimTimer->start(); }
|
||||
void stop() { mAnimTimer->stop(); }
|
||||
void Begin() { start(); setVisible(true); }
|
||||
void End() { stop(); setVisible(false); }
|
||||
void setHeight(int h) { mUserHeight = h; }
|
||||
void reset();
|
||||
|
||||
private slots:
|
||||
void timer(int s);
|
||||
void loop();
|
||||
};
|
||||
|
||||
@@ -9,54 +9,110 @@
|
||||
#include <QStackedWidget>
|
||||
#include <QButtonGroup>
|
||||
#include <QJsonObject>
|
||||
#include <QTreeWidget>
|
||||
#include "spkpageqsstest.h"
|
||||
|
||||
namespace SpkUi
|
||||
{
|
||||
class SpkCategoryButton : public QPushButton
|
||||
{
|
||||
class SpkSidebarSelector : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
SpkCategoryButton(QWidget *parent = nullptr);
|
||||
void SetIcon(QPixmap);
|
||||
void SetText(QString);
|
||||
static constexpr int Spacing = 8;
|
||||
private:
|
||||
QHBoxLayout *mLayout;
|
||||
QLabel *mIcon, *mText;
|
||||
};
|
||||
class SpkCategorySelector : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
SpkCategorySelector(QWidget *parent = nullptr);
|
||||
QPushButton *mLastCheckedBtn;
|
||||
QTreeWidgetItem *mLastSelectedItem;
|
||||
QTreeWidget *mCategoryWidget;
|
||||
|
||||
void AddButton(QString aBtnText, int aCategoryId = 0, QPixmap *aBtnIcon = nullptr);
|
||||
void DeleteAllButtons();
|
||||
public:
|
||||
SpkSidebarSelector(QObject *parent = nullptr) : QObject(parent)
|
||||
{
|
||||
mLastCheckedBtn = nullptr;
|
||||
mLastSelectedItem = nullptr;
|
||||
}
|
||||
// Tree item can either represent a page or a category, data of special roles
|
||||
// help identify them; Buttons instead can only represent a page
|
||||
constexpr static int RoleItemIsCategory = Qt::UserRole + 1;
|
||||
constexpr static int RoleItemCategoryPageId= Qt::UserRole + 2;
|
||||
void BindPageSwitcherButton(QAbstractButton* w)
|
||||
{
|
||||
connect(w, &QAbstractButton::pressed,
|
||||
this, &SpkSidebarSelector::ButtonPressed);
|
||||
}
|
||||
void BindCategoryWidget(QTreeWidget* w)
|
||||
{
|
||||
mCategoryWidget = w;
|
||||
connect(w, &QTreeWidget::itemPressed, this,
|
||||
&SpkSidebarSelector::TreeItemSelected);
|
||||
}
|
||||
|
||||
private slots:
|
||||
// We assume the objects in interest all have the correct properties
|
||||
void ButtonPressed()
|
||||
{
|
||||
auto b = qobject_cast<QPushButton*>(sender());
|
||||
if(mLastCheckedBtn)
|
||||
{
|
||||
if(mLastCheckedBtn != b)
|
||||
{
|
||||
mLastCheckedBtn->setChecked(false);
|
||||
mLastCheckedBtn = nullptr;
|
||||
}
|
||||
else
|
||||
// QUESTIONABLE:
|
||||
// Apparently for checkable buttons, Qt flip their checked property AFTER
|
||||
// this slot function. So to prevent a checkable button being unchecked,
|
||||
// we set it to unchecked here. Qt will flip it back to checked later.
|
||||
b->setChecked(false);
|
||||
}
|
||||
else if(mLastSelectedItem)
|
||||
{
|
||||
mLastSelectedItem->setSelected(false);
|
||||
mLastSelectedItem = nullptr;
|
||||
}
|
||||
mLastCheckedBtn = b;
|
||||
emit SwitchToPage(b->property("spk_pageno").toInt());
|
||||
}
|
||||
void TreeItemSelected(QTreeWidgetItem *item, int column)
|
||||
{
|
||||
if(mLastCheckedBtn)
|
||||
{
|
||||
mLastCheckedBtn->setChecked(false);
|
||||
mLastCheckedBtn = nullptr;
|
||||
}
|
||||
mLastSelectedItem = item;
|
||||
if(item->data(column, RoleItemIsCategory).toBool())
|
||||
emit SwitchToCategory(item->data(column, RoleItemCategoryPageId).toInt());
|
||||
else
|
||||
emit SwitchToPage(item->data(column, RoleItemCategoryPageId).toInt());
|
||||
}
|
||||
|
||||
signals:
|
||||
void CategorySelected(int);
|
||||
|
||||
private:
|
||||
QVBoxLayout *mBtnLayout;
|
||||
QButtonGroup *mGroup;
|
||||
QList<SpkCategoryButton*> mBtnList;
|
||||
void SwitchToCategory(int aCategoryId);
|
||||
void SwitchToPage(int aPageId);
|
||||
};
|
||||
|
||||
|
||||
class SpkMainWidget : public QFrame
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
SpkMainWidget(QWidget *parent = nullptr);
|
||||
|
||||
QHBoxLayout *HorizontalDivide;
|
||||
SpkCategorySelector *CategoryWidget;
|
||||
QVBoxLayout *VLayCategoryButtons,
|
||||
*VLayMain;
|
||||
QVBoxLayout *VLayMain;
|
||||
SpkTitleBar *TitleBar;
|
||||
|
||||
QStackedWidget *Pager;
|
||||
|
||||
// Category widget is for switching pages
|
||||
QWidget *SideBarRestrictor;
|
||||
QVBoxLayout *VLaySidebar;
|
||||
QHBoxLayout *HLaySideTop;
|
||||
QLabel *StoreIcon;
|
||||
QPushButton *BtnSettings, *BtnFeedback, *BtnLogs;
|
||||
QTreeWidget *CategoryWidget;
|
||||
QMap<int, QTreeWidgetItem> *CategoryItemMap;
|
||||
SpkSidebarSelector *SidebarMgr;
|
||||
|
||||
//Pages
|
||||
SpkPageQssTest *PageQssTest;
|
||||
};
|
||||
|
||||
@@ -10,6 +10,9 @@
|
||||
#include <QVBoxLayout>
|
||||
#include <QHBoxLayout>
|
||||
#include <QSlider>
|
||||
|
||||
#include "spkloading.h"
|
||||
|
||||
namespace SpkUi
|
||||
{
|
||||
class SpkPageQssTest : public QSplitter
|
||||
@@ -33,6 +36,7 @@ namespace SpkUi
|
||||
QGroupBox *Group;
|
||||
QSlider *SlideH;
|
||||
QSlider *SlideV;
|
||||
SpkLoading *Loading;
|
||||
|
||||
public slots:
|
||||
void SetStylesheet();
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
//
|
||||
// Created by rigoligo on 2021/5/12.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QMap>
|
||||
#include <QString>
|
||||
#include <QtNetwork/QNetworkReply>
|
||||
#include <QtNetwork/QNetworkAccessManager>
|
||||
|
||||
#include "spklogging.h"
|
||||
#include "spkmainwindow.h"
|
||||
|
||||
@@ -23,10 +23,32 @@ class SpkStore : public QObject
|
||||
SpkStore(bool aCli, QString &aLogPath);
|
||||
~SpkStore();
|
||||
|
||||
SpkMainWindow* GetRootWindow() { return mMainWindow; };
|
||||
SpkMainWindow* GetRootWindow() { return mMainWindow; }
|
||||
|
||||
private:
|
||||
SpkLogger *mLogger;
|
||||
SpkMainWindow *mMainWindow = nullptr;
|
||||
|
||||
QNetworkAccessManager *mNetMgr = nullptr;
|
||||
|
||||
// Following are stationary signal-slot bindings between UI and Store, mostly for handling
|
||||
// API calls and resource downloading.
|
||||
public slots:
|
||||
|
||||
// void RequestStoreMetadata(); ///< All required metadata the store needs when launched
|
||||
// void RequestCategoryPage(int aCategoryId);
|
||||
// void RequestApplicationMetadata(int aAppId);
|
||||
// void RequestRefreshApiUrls(QString aCustomUrl);
|
||||
signals:
|
||||
void StatusStoreMetadata(QNetworkReply::NetworkError, QString);
|
||||
void StatusCategoryPage(QNetworkReply::NetworkError, QString);
|
||||
void StatusApplicationMetadata(QNetworkReply::NetworkError, QString);
|
||||
void StatusRefreshApiUrls(QNetworkReply::NetworkError, QString);
|
||||
|
||||
private:
|
||||
// Store manages all kinds of possible replies, and the caller can only get JSON they need
|
||||
QNetworkReply *mReplyStoreMetadata = nullptr,
|
||||
*mReplyCategory = nullptr,
|
||||
*mReplyAppMetadata = nullptr,
|
||||
*mReplyApiUrls = nullptr;
|
||||
};
|
||||
|
||||
@@ -23,7 +23,7 @@ class SpkTitleBarDefaultButton : public QPushButton
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
SpkTitleBarDefaultButton();
|
||||
SpkTitleBarDefaultButton(QWidget* parent = nullptr);
|
||||
enum OperationButton { Minimize = 1, MaximizeRestore = 2, Close = 4, Restore = 3 };
|
||||
void SetRole(OperationButton);
|
||||
constexpr static int ButtonWidth = 60;
|
||||
@@ -46,23 +46,22 @@ class SpkTitleBar : public QWidget
|
||||
using OperationButton = SpkTitleBarDefaultButton::OperationButton;
|
||||
void SetOperationButton(OperationButton);
|
||||
|
||||
void SetIcon(QPixmap &p) { mIcon.setPixmap(p); };
|
||||
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 SetIcon(QPixmap &p) { mIcon->setPixmap(p); }
|
||||
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; }
|
||||
|
||||
QHBoxLayout &GetLeftUserSpace() { return mUserSpaceL; };
|
||||
QHBoxLayout &GetRightUserSpace() { return mUserSpaceR; };
|
||||
QHBoxLayout *GetUserSpace() { return mUserSpace; }
|
||||
protected:
|
||||
bool event(QEvent*) override;
|
||||
|
||||
private:
|
||||
QLabel mIcon;
|
||||
QLabel mTitle;
|
||||
QLabel *mIcon;
|
||||
QLabel *mTitle;
|
||||
QMainWindow *mLinkedWindow;
|
||||
QHBoxLayout mMainLayout, mUserSpaceL, mUserSpaceR;
|
||||
SpkTitleBarDefaultButton mBtnMin, mBtnMaxRestore, mBtnClose;
|
||||
QHBoxLayout *mMainLayout, *mUserSpace, *mBtnGroup;
|
||||
SpkTitleBarDefaultButton *mBtnMin, *mBtnMaxRestore, *mBtnClose;
|
||||
|
||||
private slots:
|
||||
void CloseWindow();
|
||||
|
||||
@@ -13,15 +13,18 @@
|
||||
|
||||
namespace SpkUi
|
||||
{
|
||||
enum SpkUiStyle { Light, Dark };
|
||||
enum SpkButtonStyle { Normal = 0, Recommend, Warn };
|
||||
|
||||
constexpr int StackTraceArraySize = 64;
|
||||
constexpr const char * const StoreIconName = "spark-store";
|
||||
|
||||
extern QString StylesheetLight, StylesheetDark, *CurrentStylesheet;
|
||||
extern SpkUiStyle CurrentStyle;
|
||||
extern QString StylesheetBase, CurrentStylesheet;
|
||||
extern QColor ColorLine, ColorBack;
|
||||
extern QSize PrimaryScreenSize;
|
||||
extern SpkDtkPlugin *DtkPlugin;
|
||||
enum SpkUiStyle { Light, Dark };
|
||||
enum SpkButtonStyle { Normal = 0, Recommend, Warn };
|
||||
extern QStyle *OldSystemStyle;
|
||||
|
||||
namespace Priv
|
||||
{
|
||||
@@ -32,6 +35,10 @@ namespace SpkUi
|
||||
void GuessAppropriateTheme();
|
||||
void PrepareForDeepinDesktop();
|
||||
bool CheckIsDeepinDesktop();
|
||||
QString StylesheetFromColors(QList<QColor>);
|
||||
|
||||
QIcon GetThemedIcon(QString);
|
||||
QColor ColorTextOnBackground(QColor);
|
||||
|
||||
void CrashSignalHandler(int);
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ class SpkWindow : public QMainWindow
|
||||
bool mMoving, mResizing, mMaximized, mResizable;
|
||||
Qt::Edges mEdgesBeingResized;
|
||||
bool (*mCloseHook)(void);
|
||||
bool mUseCustomEvents;
|
||||
|
||||
static constexpr int BorderWidth = 10;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user