mirror of
https://gitee.com/spark-store-project/spark-store
synced 2025-12-14 04:42:03 +08:00
进度更新
This commit is contained in:
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user