新增了SpkAppItem,更改style型对象名,修复侧边栏bug

This commit is contained in:
RigoLigoRLC 2021-08-18 16:44:05 +08:00
parent d49917c6fb
commit f6baf41306
16 changed files with 150 additions and 44 deletions

View File

@ -65,11 +65,13 @@ set(SOURCE_FILES
inc/spkpageuitest.h gui/spkpageuitest.cpp inc/spkpageuitest.h gui/spkpageuitest.cpp
inc/spkloading.h gui/spkloading.cpp inc/spkloading.h gui/spkloading.cpp
inc/spksidebartree.h gui/spksidebartree.cpp inc/spksidebartree.h gui/spksidebartree.cpp
inc/spkappitem.h gui/spkappitem.cpp
inc/spkpopup.h gui/spkpopup.cpp inc/spkpopup.h gui/spkpopup.cpp
inc/spkstore.h src/spkstore.cpp inc/spkstore.h src/spkstore.cpp
inc/spkuimsg.h src/spkuimsg.cpp inc/spkuimsg.h src/spkuimsg.cpp
inc/spklogging.h src/spklogging.cpp inc/spklogging.h src/spklogging.cpp
inc/spkresource.h src/spkresource.cpp
) )
include(cmake/FindLibNotify.cmake) include(cmake/FindLibNotify.cmake)

45
gui/spkappitem.cpp Normal file
View File

@ -0,0 +1,45 @@
#include <QPainter>
#include <QStyleOption>
#include "spkappitem.h"
SpkAppItem::SpkAppItem(QWidget *parent) : QWidget(parent)
{
mMainLay = new QHBoxLayout(this);
mLayText = new QVBoxLayout;
mIcon = new QLabel;
mIcon->setFixedSize(IconSize, IconSize);
mIcon->setAutoFillBackground(false);
mTitle = new QLabel;
mTitle->setWordWrap(false);
mTitle->setObjectName("styAppItmTitle");
mTitle->setAutoFillBackground(true);
mDescription = new QLabel;
mDescription->setWordWrap(true);
mDescription->setObjectName("styAppItmDesc");
mDescription->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
mDescription->setAlignment(Qt::AlignTop | Qt::AlignLeft);
mDescription->setAutoFillBackground(true);
mLayText->addWidget(mTitle);
mLayText->addWidget(mDescription);
mLayText->setAlignment(Qt::AlignTop);
mMainLay->addWidget(mIcon);
mMainLay->addLayout(mLayText);
setMinimumHeight(82);
setMaximumHeight(82);
setMinimumWidth(300);
setMaximumWidth(350);
}
void SpkAppItem::paintEvent(QPaintEvent *e)
{
Q_UNUSED(e)
QStyleOption opt;
opt.init(this);
QPainter p(this);
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
}

View File

@ -44,10 +44,10 @@ void SpkDialog::AddButton(QString text, SpkUi::SpkButtonStyle style)
{ {
case SpkUi::SpkButtonStyle::Recommend: case SpkUi::SpkButtonStyle::Recommend:
b->setObjectName("spk_styling_recommendbtn"); b->setObjectName("sty_recommendbtn");
break; break;
case SpkUi::SpkButtonStyle::Warn: case SpkUi::SpkButtonStyle::Warn:
b->setObjectName("spk_styling_warnbtn"); b->setObjectName("sty_warnbtn");
break; break;
default: default:
break; break;

View File

@ -4,7 +4,7 @@
#include "spkloading.h" #include "spkloading.h"
#include "spkui_general.h" #include "spkui_general.h"
SpkLoading::SpkLoading(QWidget *parent) : QWidget(parent) SpkLoading::SpkLoading(QWidget *parent) : QFrame(parent)
{ {
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum); setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
mAnimTimer = new QTimeLine(400, this); mAnimTimer = new QTimeLine(400, this);

View File

@ -103,8 +103,8 @@ SpkUi::SpkMainWidget::SpkMainWidget(QWidget *parent) : QFrame(parent)
SideBarRestrictor = new QWidget(this); SideBarRestrictor = new QWidget(this);
SideBarRestrictor->setObjectName("spk_mw_sidebar_restrictor"); SideBarRestrictor->setObjectName("spk_mw_sidebar_restrictor");
SideBarRestrictor->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred); SideBarRestrictor->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
SideBarRestrictor->setMaximumWidth(300); SideBarRestrictor->setMaximumWidth(200);
SideBarRestrictor->setMinimumWidth(300); SideBarRestrictor->setMinimumWidth(200);
SideBarRestrictor->setLayout(VLaySidebar); SideBarRestrictor->setLayout(VLaySidebar);
HLaySideTop = new QHBoxLayout; HLaySideTop = new QHBoxLayout;
@ -123,7 +123,7 @@ SpkUi::SpkMainWidget::SpkMainWidget(QWidget *parent) : QFrame(parent)
SidebarMgr->setObjectName("spk_mw_sidebar_mgr"); SidebarMgr->setObjectName("spk_mw_sidebar_mgr");
BtnSettings = new QPushButton(this); BtnSettings = new QPushButton(this);
BtnSettings->setObjectName("spk_styling_plaincheckbtn"); BtnSettings->setObjectName("styPlainChkBtn");
BtnSettings->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); BtnSettings->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
BtnSettings->setCheckable(true); BtnSettings->setCheckable(true);
BtnSettings->setMaximumSize({ 48, 48 }); BtnSettings->setMaximumSize({ 48, 48 });
@ -140,7 +140,7 @@ SpkUi::SpkMainWidget::SpkMainWidget(QWidget *parent) : QFrame(parent)
using SpkUi::SpkSidebarSelector; using SpkUi::SpkSidebarSelector;
CategoryWidget = new SpkSidebarTree(this); CategoryWidget = new SpkSidebarTree(this);
CategoryWidget->setObjectName("spk_mw_category"); CategoryWidget->setObjectName("styMwCateg");
CategoryWidget->setAutoFillBackground(true); CategoryWidget->setAutoFillBackground(true);
CategoryWidget->setColumnCount(1); CategoryWidget->setColumnCount(1);
CategoryWidget->setHeaderHidden(true); CategoryWidget->setHeaderHidden(true);

View File

@ -82,7 +82,7 @@ int SpkMsgBox::StaticExec(QString msg, QString title, QMessageBox::Icon icon,
wExpandBtn->setMaximumWidth(100); wExpandBtn->setMaximumWidth(100);
wExpandBtn->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); wExpandBtn->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
wExpandBtn->setCheckable(true); wExpandBtn->setCheckable(true);
wExpandBtn->setObjectName("spk_styling_checkbtn"); wExpandBtn->setObjectName("styChkBtn");
connect(wExpandBtn, &QPushButton::clicked, connect(wExpandBtn, &QPushButton::clicked,
[&](){ // FIXME: hint doesn't change when visibility changes, this is a quirky hack [&](){ // FIXME: hint doesn't change when visibility changes, this is a quirky hack
wExtraArea->setVisible(wExpandBtn->isChecked()); wExtraArea->setVisible(wExpandBtn->isChecked());

View File

@ -44,6 +44,13 @@ SpkUi::SpkPageUiTest::SpkPageUiTest(QWidget *parent) : QSplitter(parent)
Loading->setObjectName("spk_pg_qsstest_loading"); Loading->setObjectName("spk_pg_qsstest_loading");
Loading->start(); Loading->start();
AppItem = new SpkAppItem(this);
AppItem->setObjectName("spk_pg_qsstest_appitem");
AppItem->SetTitle("Lorem Ipsum");
AppItem->SetDescription("Nam vehicula lacus vitae leo fermentum efficitur. "
"Phasellus finibus risus id aliquam pulvinar.");
AppItem->SetIcon(QIcon::fromTheme("dialog-information").pixmap(72, 72));
PopupText = new QLineEdit(this); PopupText = new QLineEdit(this);
PopupText->setObjectName("spk_pg_qsstest_poptext"); PopupText->setObjectName("spk_pg_qsstest_poptext");
PopupText->setText("Hello, world"); PopupText->setText("Hello, world");
@ -68,20 +75,21 @@ SpkUi::SpkPageUiTest::SpkPageUiTest(QWidget *parent) : QSplitter(parent)
SlideH->setMaximum(1000); SlideH->setMaximum(1000);
SlideH->setMinimum(0); SlideH->setMinimum(0);
VLayBtn = new QVBoxLayout; VLayTestWidgets = new QVBoxLayout;
VLayBtn->setObjectName("spk_pg_qsstest_vlay_btn"); VLayTestWidgets->setObjectName("spk_pg_qsstest_vlay_btn");
VLayBtn->addWidget(Btn); VLayTestWidgets->addWidget(Btn);
VLayBtn->addWidget(Chk); VLayTestWidgets->addWidget(Chk);
VLayBtn->addWidget(Rad); VLayTestWidgets->addWidget(Rad);
VLayBtn->addWidget(Loading); VLayTestWidgets->addWidget(Loading);
VLayBtn->addWidget(PopupText); VLayTestWidgets->addWidget(PopupText);
VLayBtn->addWidget(ShowPopup); VLayTestWidgets->addWidget(ShowPopup);
VLayBtn->addWidget(ShowAbout); VLayTestWidgets->addWidget(ShowAbout);
VLayTestWidgets->addWidget(AppItem);
Group = new QGroupBox(this); Group = new QGroupBox(this);
Group->setObjectName("spk_pg_qsstest_groupbox"); Group->setObjectName("spk_pg_qsstest_groupbox");
Group->setTitle("GroupBox"); Group->setTitle("GroupBox");
Group->setLayout(VLayBtn); Group->setLayout(VLayTestWidgets);
VLayInput = new QVBoxLayout; VLayInput = new QVBoxLayout;
VLayInput->setObjectName("spk_pg_qsstest_inputlay"); VLayInput->setObjectName("spk_pg_qsstest_inputlay");

31
inc/spkappitem.h Normal file
View File

@ -0,0 +1,31 @@
#pragma once
#include <QLabel>
#include <QVBoxLayout>
#include <QHBoxLayout>
class SpkAppItem : public QWidget
{
Q_OBJECT
public:
SpkAppItem(QWidget *parent = nullptr);
void SetIcon(QPixmap p) { mIcon->setPixmap(p); }
void SetTitle(QString s) { mTitle->setText(s); }
void SetDescription(QString s) { mDescription->setText(s); }
protected:
void paintEvent(QPaintEvent *e);
private:
QLabel *mIcon;
QLabel *mTitle;
QLabel *mDescription;
QVBoxLayout *mLayText;
QHBoxLayout *mMainLay;
static constexpr int IconSize = 72;
};

View File

@ -1,10 +1,10 @@
#pragma once #pragma once
#include <QWidget> #include <QFrame>
#include <QTimeLine> #include <QTimeLine>
class SpkLoading : public QWidget class SpkLoading : public QFrame
{ {
Q_OBJECT Q_OBJECT
public: public:

View File

@ -43,20 +43,20 @@ namespace SpkUi
constexpr static int RoleItemCategoryPageId= Qt::UserRole + 2; constexpr static int RoleItemCategoryPageId= Qt::UserRole + 2;
void BindPageSwitcherButton(QAbstractButton* w) void BindPageSwitcherButton(QAbstractButton* w)
{ {
connect(w, &QAbstractButton::pressed, connect(w, &QAbstractButton::toggled,
this, &SpkSidebarSelector::ButtonPressed); this, &SpkSidebarSelector::ButtonPressed);
} }
void BindCategoryWidget(QTreeWidget* w) void BindCategoryWidget(QTreeWidget* w)
{ {
mCategoryWidget = w; mCategoryWidget = w;
connect(w, &QTreeWidget::itemClicked, this, connect(w, &QTreeWidget::itemPressed, this,
&SpkSidebarSelector::TreeItemSelected); &SpkSidebarSelector::TreeItemSelected);
} }
void AddUnusableItem(QTreeWidgetItem *i) { mUnusableItems.append(i); } void AddUnusableItem(QTreeWidgetItem *i) { mUnusableItems.append(i); }
private slots: private slots:
// We assume the objects in interest all have the correct properties // We assume the objects in interest all have the correct properties
void ButtonPressed() void ButtonPressed(bool aBtnState)
{ {
auto b = qobject_cast<QPushButton*>(sender()); auto b = qobject_cast<QPushButton*>(sender());
if(mLastCheckedBtn) if(mLastCheckedBtn)
@ -67,11 +67,7 @@ namespace SpkUi
mLastCheckedBtn = nullptr; mLastCheckedBtn = nullptr;
} }
else else
// NOTE: b->setChecked(aBtnState);
// 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) else if(mLastSelectedItem)
{ {

View File

@ -11,6 +11,7 @@
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QSlider> #include <QSlider>
#include "spkappitem.h"
#include "spkloading.h" #include "spkloading.h"
@ -23,7 +24,7 @@ namespace SpkUi
SpkPageUiTest(QWidget *parent = nullptr); SpkPageUiTest(QWidget *parent = nullptr);
QWidget *WidL, *WidR; QWidget *WidL, *WidR;
QVBoxLayout *VLayWidgets, QVBoxLayout *VLayWidgets,
*VLayBtn, *VLayTestWidgets,
*VLayInput; *VLayInput;
QHBoxLayout *HLay4Slider, QHBoxLayout *HLay4Slider,
*HLayInputBtns; *HLayInputBtns;
@ -38,6 +39,7 @@ namespace SpkUi
QSlider *SlideH; QSlider *SlideH;
QSlider *SlideV; QSlider *SlideV;
SpkLoading *Loading; SpkLoading *Loading;
SpkAppItem *AppItem;
QLineEdit *PopupText; QLineEdit *PopupText;
QPushButton *ShowPopup, QPushButton *ShowPopup,

4
inc/spkresource.h Normal file
View File

@ -0,0 +1,4 @@
#ifndef SPKRESOURCE_H
#define SPKRESOURCE_H
#endif // SPKRESOURCE_H

View File

@ -45,7 +45,6 @@ namespace SpkUi
static UiMetaObject *sGlobalInstance; static UiMetaObject *sGlobalInstance;
public: public:
UiMetaObject() {} UiMetaObject() {}
UiMetaObject *Instance() {return nullptr;} //FIXME!!
public slots: public slots:
void SetAccentColor(QColor); void SetAccentColor(QColor);
}; };

View File

@ -22,32 +22,37 @@ QWidget
color: #ffffff; color: #ffffff;
} }
#spk_mw_category QLabel
{
background: transparent;
}
#styMwCateg
{ {
border: none; border: none;
font-size: 14px; font-size: 14px;
show-decoration-selected: 1; show-decoration-selected: 1;
} }
#spk_mw_category::item #styMwCateg::item
{ {
height: 35px; height: 35px;
border: none; border: none;
color: %13; color: %13;
} }
#spk_mw_category::item:selected #styMwCateg::item:selected
{ {
color: %11; color: %11;
background-color: %4; background-color: %4;
} }
#spk_mw_category::branch:!has-children #styMwCateg::branch:!has-children
{ {
background: %1; background: %1;
} }
#spk_mw_category::branch:selected #styMwCateg::branch:selected
{ {
background-color: %4; background-color: %4;
} }
@ -83,34 +88,34 @@ QPushButton::pressed
background: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 %8, stop:1 %6) background: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 %8, stop:1 %6)
} }
#spk_styling_checkbtn #styChkBtn
{ {
border-width: 0px; border-width: 0px;
background-color: %9 background-color: %9
} }
#spk_styling_checkbtn:pressed #styChkBtn:pressed
{ {
background-color: %5 background-color: %5
} }
#spk_styling_checkbtn:checked #styChkBtn:checked
{ {
background-color: %4 background-color: %4
} }
#spk_styling_plaincheckbtn #styPlainChkBtn
{ {
border-width: 0px; border-width: 0px;
background-color: %1 background-color: %1
} }
#spk_styling_plaincheckbtn:pressed #styPlainChkBtn:pressed
{ {
background-color: %5 background-color: %5
} }
#spk_styling_plaincheckbtn:checked #styPlainChkBtn:checked
{ {
background-color: %4 background-color: %4
} }
@ -157,7 +162,19 @@ QScrollBar::add-line, QScrollBar::sub-line
height:0px height:0px
} }
#spk_about_desc #styAboutDesc
{ {
color: %14 color: %14
} }
SpkAppItem
{
background: %10;
border-radius: 11px;
}
#styAppItmTitle
{
font-weight: 500;
font-size: 17px;
}

0
src/spkresource.cpp Normal file
View File

View File

@ -24,9 +24,11 @@ void SpkUiMessage::SendDesktopNotification(QString s, const char * const icon)
notify_notification_show(_notify, nullptr); notify_notification_show(_notify, nullptr);
} }
void SpkUiMessage::SendStoreNotification(QString s) // TODO: IMPLEMENT IN-APP NOTIFICATION void SpkUiMessage::SendStoreNotification(QString s)
{ {
SpkUi::Popup->Show(s); // I don't really understand these measures of preventing copying really well,
// but Clang-tidy said so, so I did as instructed.
SpkUi::Popup->Show(std::move(s));
} }
void SpkUiMessage::SetDesktopNotifyTimeout(int ms) void SpkUiMessage::SetDesktopNotifyTimeout(int ms)