mirror of
https://gitee.com/spark-store-project/spark-store
synced 2025-07-18 03:22:20 +08:00
新增SpkIconButton为主题和按钮工作减负
This commit is contained in:
parent
2e04d05b34
commit
cefd309097
@ -60,6 +60,7 @@ set(SOURCE_FILES
|
||||
|
||||
inc/spkwindow.h gui/spkwindow.cpp
|
||||
inc/spktitlebar.h gui/spktitlebar.cpp
|
||||
inc/spkiconbutton.h gui/spkiconbutton.cpp
|
||||
inc/spkui_general.h gui/spkui_general.cpp
|
||||
inc/spkmainwindow.h gui/spkmainwindow.cpp
|
||||
inc/spkmsgbox.h gui/spkmsgbox.cpp
|
||||
|
@ -44,6 +44,11 @@ SpkUi::SpkPageUiTest::SpkPageUiTest(QWidget *parent) : QSplitter(parent)
|
||||
Loading->setObjectName("spk_pg_qsstest_loading");
|
||||
Loading->start();
|
||||
|
||||
Prog = new QProgressBar(this);
|
||||
Prog->setObjectName("spk_pg_qsstest_prog");
|
||||
Prog->setValue(65);
|
||||
Prog->setRange(0, 100);
|
||||
|
||||
AppItem = new SpkAppItem(0, this);
|
||||
AppItem->setObjectName("spk_pg_qsstest_appitem");
|
||||
AppItem->SetTitle("Lorem ipsum dolor sit amet, consectetur adipiscing elit.");
|
||||
@ -87,11 +92,16 @@ SpkUi::SpkPageUiTest::SpkPageUiTest(QWidget *parent) : QSplitter(parent)
|
||||
SlideH->setMaximum(1000);
|
||||
SlideH->setMinimum(0);
|
||||
|
||||
IconBtn = new SpkIconButton(this);
|
||||
IconBtn->setObjectName("spk_pg_qsstest_iconbtn");
|
||||
IconBtn->SetIcon(QIcon(":/icons/settings.svg"), QSize{ 16, 16 });
|
||||
|
||||
VLayTestWidgets = new QVBoxLayout;
|
||||
VLayTestWidgets->setObjectName("spk_pg_qsstest_vlay_btn");
|
||||
VLayTestWidgets->addWidget(Btn);
|
||||
VLayTestWidgets->addWidget(Chk);
|
||||
VLayTestWidgets->addWidget(Rad);
|
||||
VLayTestWidgets->addWidget(IconBtn);
|
||||
VLayTestWidgets->addWidget(Loading);
|
||||
VLayTestWidgets->addWidget(PopupText);
|
||||
VLayTestWidgets->addWidget(ShowPopup);
|
||||
@ -113,6 +123,7 @@ SpkUi::SpkPageUiTest::SpkPageUiTest(QWidget *parent) : QSplitter(parent)
|
||||
VLayWidgets->setObjectName("spk_pg_qsstest_widgetlay");
|
||||
VLayWidgets->addWidget(Group);
|
||||
VLayWidgets->addWidget(SlideH);
|
||||
VLayWidgets->addWidget(Prog);
|
||||
|
||||
HLay4Slider = new QHBoxLayout;
|
||||
HLay4Slider->setObjectName("spk_pg_qsstest_hlay_for_slider");
|
||||
@ -122,6 +133,7 @@ SpkUi::SpkPageUiTest::SpkPageUiTest(QWidget *parent) : QSplitter(parent)
|
||||
WidL = new QWidget(this);
|
||||
WidL->setObjectName("spk_pg_qsstest_widleft");
|
||||
WidL->setLayout(HLay4Slider);
|
||||
WidL->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
|
||||
|
||||
WidR = new QWidget(this);
|
||||
WidR->setObjectName("spk_pg_qsstest_widright");
|
||||
|
56
gui/spkiconbutton.cpp
Normal file
56
gui/spkiconbutton.cpp
Normal file
@ -0,0 +1,56 @@
|
||||
|
||||
#include <QMargins>
|
||||
#include <QPainter>
|
||||
#include <QVariant>
|
||||
#include <QDebug>
|
||||
#include "spkiconbutton.h"
|
||||
|
||||
SpkIconButton::SpkIconButton(QWidget *parent) :
|
||||
QPushButton(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void SpkIconButton::SetIcon(QIcon i, QSize s)
|
||||
{
|
||||
mPmapPaintedIcon = i.pixmap(s);
|
||||
|
||||
setFixedSize((mPmapSize = s.grownBy(QMargins(IconMargin, IconMargin, IconMargin, IconMargin))));
|
||||
}
|
||||
|
||||
void SpkIconButton::SetIcon(QPixmap m)
|
||||
{
|
||||
mPmapPaintedIcon = m;
|
||||
|
||||
setFixedSize((mPmapSize = m.size().grownBy(QMargins(IconMargin, IconMargin,
|
||||
IconMargin, IconMargin))));
|
||||
}
|
||||
|
||||
void SpkIconButton::SetIconSize(QSize s)
|
||||
{
|
||||
setFixedSize((mPmapSize = s.grownBy(QMargins(IconMargin, IconMargin, IconMargin, IconMargin))));
|
||||
}
|
||||
|
||||
void SpkIconButton::paintEvent(QPaintEvent *e)
|
||||
{
|
||||
QPushButton::paintEvent(e);
|
||||
|
||||
// Paint the icon mask
|
||||
QPainter p(this), p1(&mPmapPaintedIcon);
|
||||
QBrush b(Qt::SolidPattern);
|
||||
|
||||
p.drawPixmap(IconMargin, IconMargin, mPmapPaintedIcon);
|
||||
if(isDown() || isChecked())
|
||||
{
|
||||
b.setColor(SpkUi::ColorBtnMaskSelected);
|
||||
}
|
||||
else
|
||||
{
|
||||
b.setColor(SpkUi::ColorBtnMaskUnselected);
|
||||
}
|
||||
p1.setCompositionMode(QPainter::CompositionMode_SourceIn);
|
||||
p1.fillRect(0, 0, mPmapSize.width(), mPmapSize.height(), b);
|
||||
p1.end();
|
||||
p.drawPixmap(IconMargin, IconMargin, mPmapPaintedIcon);
|
||||
p.end();
|
||||
}
|
@ -319,7 +319,7 @@ void SpkMainWindow::PopulateAppDetails(QJsonObject appDetails)
|
||||
void SpkMainWindow::ReloadThemedUiIcons()
|
||||
{
|
||||
for(auto &i : mThemedUiIconReferences)
|
||||
i.first->setIcon(SpkUi::GetThemedIcon(i.second));
|
||||
i.first->SetIcon(SpkUi::GetThemedIcon(i.second), QSize { 20, 20 });
|
||||
}
|
||||
|
||||
// ==================== Main Window Initialization ====================
|
||||
@ -338,7 +338,7 @@ void SpkMainWindow::Initialize()
|
||||
[=](){ emit SearchKeyword(ui->SearchEdit->text(), 1); });
|
||||
connect(ui->PageAppList, &SpkUi::SpkPageAppList::ApplicationClicked,
|
||||
this, &SpkMainWindow::EnterAppDetails);
|
||||
connect(ui->BtnDayNight, &QPushButton::pressed,
|
||||
connect(ui->BtnDayNight, &QPushButton::clicked,
|
||||
this, &SpkMainWindow::SwitchDayNightTheme);
|
||||
if(SpkUi::States::IsUsingDtkPlugin)
|
||||
{
|
||||
@ -347,7 +347,7 @@ void SpkMainWindow::Initialize()
|
||||
}
|
||||
|
||||
// Register themed button icons
|
||||
mThemedUiIconReferences.append({ ui->BtnSettings, "settings" });
|
||||
// mThemedUiIconReferences.append({ ui->BtnSettings, "settings" });
|
||||
mThemedUiIconReferences.append({ ui->BtnDayNight, "daynight" });
|
||||
}
|
||||
|
||||
@ -400,24 +400,20 @@ SpkUi::SpkMainWidget::SpkMainWidget(QWidget *parent) : QFrame(parent)
|
||||
SidebarMgr = new SpkSidebarSelector(this);
|
||||
SidebarMgr->setObjectName("spk_mw_sidebar_mgr");
|
||||
|
||||
BtnSettings = new QPushButton(this);
|
||||
BtnSettings = new SpkIconButton(this);
|
||||
BtnSettings->setObjectName("styPlainChkBtn");
|
||||
BtnSettings->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
||||
BtnSettings->setCheckable(true);
|
||||
BtnSettings->setMaximumSize({ 40, 40 });
|
||||
BtnSettings->setMinimumSize({ 40, 40 });
|
||||
BtnSettings->setIconSize(QSize(20, 20));
|
||||
BtnSettings->setIcon(SpkUi::GetThemedIcon("settings"));
|
||||
BtnSettings->setFixedSize({ 40, 40 });
|
||||
BtnSettings->SetIcon(QIcon(":/icons/settings.svg"), QSize(20, 20));
|
||||
BtnSettings->setProperty("spk_pageno", 0);
|
||||
SidebarMgr->BindPageSwitcherButton(BtnSettings);
|
||||
|
||||
BtnDayNight = new QPushButton(this);
|
||||
BtnDayNight = new SpkIconButton(this);
|
||||
BtnDayNight->setObjectName("styPlainChkBtn");
|
||||
BtnDayNight->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
||||
BtnDayNight->setMaximumSize({ 40, 40 });
|
||||
BtnDayNight->setMinimumSize({ 40, 40 });
|
||||
BtnDayNight->setIconSize(QSize(20, 20));
|
||||
BtnDayNight->setIcon(SpkUi::GetThemedIcon("daynight"));
|
||||
BtnDayNight->setFixedSize({ 40, 40 });
|
||||
BtnDayNight->SetIcon(QIcon(":/icons/daynight.svg"), QSize(20, 20));
|
||||
|
||||
HLaySideTop->addWidget(StoreIcon);
|
||||
HLaySideTop->addStretch();
|
||||
|
@ -102,6 +102,7 @@ SpkTitleBarDefaultButton::SpkTitleBarDefaultButton(QWidget* parent) : QPushButto
|
||||
setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
|
||||
setMaximumWidth(ButtonWidth);
|
||||
setMinimumWidth(ButtonWidth);
|
||||
setFocusPolicy(Qt::NoFocus);
|
||||
}
|
||||
|
||||
void SpkTitleBarDefaultButton::paintEvent(QPaintEvent *e)
|
||||
|
@ -27,7 +27,7 @@ namespace SpkUi
|
||||
UiMetaObject SpkUiMetaObject;
|
||||
SpkUiStyle CurrentStyle;
|
||||
QString StylesheetBase, CurrentStylesheet;
|
||||
QColor ColorLine, ColorBack;
|
||||
QColor ColorLine, ColorBack, ColorBtnMaskSelected, ColorBtnMaskUnselected;
|
||||
QSize PrimaryScreenSize;
|
||||
SpkDtkPlugin *DtkPlugin = nullptr;
|
||||
QStyle *OldSystemStyle = nullptr;
|
||||
@ -46,6 +46,16 @@ namespace SpkUi
|
||||
bool CrashHandlerActivated;
|
||||
}
|
||||
|
||||
// ======================= Static Linkage Private Functions ========================
|
||||
|
||||
static void SetBtnMaskColor()
|
||||
{
|
||||
ColorBtnMaskUnselected = ColorTextOnBackground(CurrentColorSet[Qss::ControlsBgnd]);
|
||||
ColorBtnMaskSelected = ColorTextOnBackground(CurrentColorSet[Qss::AccentColor]);
|
||||
}
|
||||
|
||||
// ======================== Public Functions =========================
|
||||
|
||||
void Initialize()
|
||||
{
|
||||
// Obtain global stylesheets
|
||||
@ -153,6 +163,7 @@ namespace SpkUi
|
||||
Qss::ColorSet tempset;
|
||||
switch(aStyle)
|
||||
{
|
||||
case Invalid:
|
||||
case Light:
|
||||
tempset = Qss::LightColorSet;
|
||||
ColorLine = Qt::black;
|
||||
@ -169,6 +180,7 @@ namespace SpkUi
|
||||
}
|
||||
CurrentColorSet = tempset;
|
||||
CurrentStylesheet = StylesheetFromColors(CurrentColorSet);
|
||||
SetBtnMaskColor();
|
||||
qApp->setStyleSheet(CurrentStylesheet);
|
||||
}
|
||||
|
||||
@ -262,11 +274,16 @@ namespace SpkUi
|
||||
return gray > 0.5 ? Qt::black : Qt::white;
|
||||
}
|
||||
|
||||
// =================== UiMetaObject =======================
|
||||
// UiMetaObject is the signal-slot receiver for DDE plugin, receiving the DDE system level
|
||||
// notifications of UI theme changes
|
||||
|
||||
void UiMetaObject::SetAccentColor(QColor aColor)
|
||||
{
|
||||
CurrentColorSet[Qss::AccentColor] = aColor.lighter(90);
|
||||
CurrentColorSet[Qss::AccentColorHighlighted] = aColor.lighter(105);
|
||||
CurrentColorSet[Qss::TextOnAccentColor] = ColorTextOnBackground(aColor);
|
||||
SetBtnMaskColor();
|
||||
qApp->setStyleSheet(StylesheetFromColors(CurrentColorSet));
|
||||
}
|
||||
|
||||
|
@ -11,9 +11,11 @@
|
||||
#include <QVBoxLayout>
|
||||
#include <QHBoxLayout>
|
||||
#include <QSlider>
|
||||
#include <QProgressBar>
|
||||
#include "spkappitem.h"
|
||||
#include "spkstretchlayout.h"
|
||||
#include "page/spkpageappdetails.h"
|
||||
#include "spkiconbutton.h"
|
||||
|
||||
#include "spkloading.h"
|
||||
|
||||
@ -40,6 +42,8 @@ namespace SpkUi
|
||||
QGroupBox *Group;
|
||||
QSlider *SlideH;
|
||||
QSlider *SlideV;
|
||||
SpkIconButton *IconBtn;
|
||||
QProgressBar *Prog;
|
||||
SpkLoading *Loading;
|
||||
SpkAppItem *AppItem;
|
||||
SpkStretchLayout *DetailsLay;
|
||||
|
30
inc/spkiconbutton.h
Normal file
30
inc/spkiconbutton.h
Normal file
@ -0,0 +1,30 @@
|
||||
#ifndef SPKICONBUTTON_H
|
||||
#define SPKICONBUTTON_H
|
||||
|
||||
#include <QPushButton>
|
||||
#include "spkui_general.h"
|
||||
|
||||
class SpkIconButton : public QPushButton
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
SpkIconButton(QWidget *parent = nullptr);
|
||||
~SpkIconButton() {};
|
||||
|
||||
void SetIcon(QIcon, QSize);
|
||||
void SetIcon(QPixmap);
|
||||
void SetIconSize(QSize);
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *) override;
|
||||
|
||||
private:
|
||||
static enum { Dark, Light } sCurrentTheme;
|
||||
QPixmap mPmapPaintedIcon;
|
||||
QSize mPmapSize;
|
||||
|
||||
static constexpr int IconMargin = 8; // shall we make it changable?
|
||||
};
|
||||
|
||||
#endif // SPKICONBUTTON_H
|
@ -14,6 +14,7 @@
|
||||
#include <QPointer>
|
||||
#include <QTimeLine>
|
||||
#include "spkfocuslineedit.h"
|
||||
#include "spkiconbutton.h"
|
||||
#include "page/spkpageuitest.h"
|
||||
#include "page/spkpageapplist.h"
|
||||
#include "page/spkpageappdetails.h"
|
||||
@ -144,7 +145,7 @@ namespace SpkUi
|
||||
QVBoxLayout *VLaySidebar;
|
||||
QHBoxLayout *HLaySideTop;
|
||||
QLabel *StoreIcon;
|
||||
QPushButton *BtnSettings, *BtnFeedback, *BtnLogs, *BtnDayNight;
|
||||
SpkIconButton *BtnSettings, *BtnFeedback, *BtnLogs, *BtnDayNight;
|
||||
SpkSidebarTree *CategoryWidget;
|
||||
QMap<int, QTreeWidgetItem> *CategoryItemMap;
|
||||
SpkSidebarSelector *SidebarMgr;
|
||||
@ -184,7 +185,7 @@ class SpkMainWindow : public SpkWindow
|
||||
mCategoryAppListGetReply,
|
||||
mAppDetailsGetReply;
|
||||
SpkUi::SpkStackedPages mCurrentPage = SpkUi::PgInvalid;
|
||||
QList<QPair<QPushButton*, QString>> mThemedUiIconReferences;
|
||||
QList<QPair<SpkIconButton*, QString>> mThemedUiIconReferences;
|
||||
|
||||
public slots:
|
||||
void ReloadThemedUiIcons();
|
||||
|
@ -39,7 +39,9 @@ namespace SpkUi
|
||||
extern UiMetaObject SpkUiMetaObject;
|
||||
extern SpkUiStyle CurrentStyle;
|
||||
extern QString StylesheetBase, CurrentStylesheet;
|
||||
extern QColor ColorLine, ColorBack;
|
||||
extern QColor ColorLine, ColorBack,
|
||||
ColorBtnMaskUnselected, ///< SpkIconButton icon mask colors, unselected & selected
|
||||
ColorBtnMaskSelected;
|
||||
extern QSize PrimaryScreenSize;
|
||||
extern SpkDtkPlugin *DtkPlugin;
|
||||
extern QStyle *OldSystemStyle;
|
||||
|
@ -98,6 +98,23 @@ QScrollBar::add-line, QScrollBar::sub-line
|
||||
height:0px
|
||||
}
|
||||
|
||||
QProgressBar
|
||||
{
|
||||
border: none;
|
||||
background-color: DCTL2;
|
||||
height: 8px;
|
||||
border-radius: 4px;
|
||||
font-size: 1px;
|
||||
color: transparent;
|
||||
}
|
||||
|
||||
QProgressBar::chunk
|
||||
{
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
background-color: ACC_;
|
||||
}
|
||||
|
||||
/* Custom widgets */
|
||||
|
||||
ElidedLabel
|
||||
@ -182,6 +199,22 @@ SpkAppItem::hover
|
||||
background-color: ACC_
|
||||
}
|
||||
|
||||
SpkIconButton
|
||||
{
|
||||
border-width: 0px;
|
||||
background-color: GBG_;
|
||||
}
|
||||
|
||||
SpkIconButton:pressed
|
||||
{
|
||||
background-color: ACCH;
|
||||
}
|
||||
|
||||
SpkIconButton:checked
|
||||
{
|
||||
background-color: ACC_;
|
||||
}
|
||||
|
||||
SpkTitleBar
|
||||
{
|
||||
background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 DCTL2, stop:1 DCTL1)
|
||||
|
@ -23,7 +23,7 @@ bool SpkUtils::VerifyReplyJson(QNetworkReply *aReply, QJsonValue &aRetDoc)
|
||||
{
|
||||
QJsonParseError err;
|
||||
QByteArray rawjson = aReply->readAll();
|
||||
qDebug() << "Received:" << rawjson;
|
||||
// qDebug() << "Received:" << rawjson;
|
||||
QJsonDocument ret = QJsonDocument::fromJson(rawjson, &err);
|
||||
QJsonObject replyObject;
|
||||
if(err.error != QJsonParseError::NoError)
|
||||
|
Loading…
x
Reference in New Issue
Block a user