新增了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/spkloading.h gui/spkloading.cpp
inc/spksidebartree.h gui/spksidebartree.cpp
inc/spkappitem.h gui/spkappitem.cpp
inc/spkpopup.h gui/spkpopup.cpp
inc/spkstore.h src/spkstore.cpp
inc/spkuimsg.h src/spkuimsg.cpp
inc/spklogging.h src/spklogging.cpp
inc/spkresource.h src/spkresource.cpp
)
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:
b->setObjectName("spk_styling_recommendbtn");
b->setObjectName("sty_recommendbtn");
break;
case SpkUi::SpkButtonStyle::Warn:
b->setObjectName("spk_styling_warnbtn");
b->setObjectName("sty_warnbtn");
break;
default:
break;

View File

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

View File

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

View File

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

View File

@ -44,6 +44,13 @@ SpkUi::SpkPageUiTest::SpkPageUiTest(QWidget *parent) : QSplitter(parent)
Loading->setObjectName("spk_pg_qsstest_loading");
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->setObjectName("spk_pg_qsstest_poptext");
PopupText->setText("Hello, world");
@ -68,20 +75,21 @@ SpkUi::SpkPageUiTest::SpkPageUiTest(QWidget *parent) : QSplitter(parent)
SlideH->setMaximum(1000);
SlideH->setMinimum(0);
VLayBtn = new QVBoxLayout;
VLayBtn->setObjectName("spk_pg_qsstest_vlay_btn");
VLayBtn->addWidget(Btn);
VLayBtn->addWidget(Chk);
VLayBtn->addWidget(Rad);
VLayBtn->addWidget(Loading);
VLayBtn->addWidget(PopupText);
VLayBtn->addWidget(ShowPopup);
VLayBtn->addWidget(ShowAbout);
VLayTestWidgets = new QVBoxLayout;
VLayTestWidgets->setObjectName("spk_pg_qsstest_vlay_btn");
VLayTestWidgets->addWidget(Btn);
VLayTestWidgets->addWidget(Chk);
VLayTestWidgets->addWidget(Rad);
VLayTestWidgets->addWidget(Loading);
VLayTestWidgets->addWidget(PopupText);
VLayTestWidgets->addWidget(ShowPopup);
VLayTestWidgets->addWidget(ShowAbout);
VLayTestWidgets->addWidget(AppItem);
Group = new QGroupBox(this);
Group->setObjectName("spk_pg_qsstest_groupbox");
Group->setTitle("GroupBox");
Group->setLayout(VLayBtn);
Group->setLayout(VLayTestWidgets);
VLayInput = new QVBoxLayout;
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
#include <QWidget>
#include <QFrame>
#include <QTimeLine>
class SpkLoading : public QWidget
class SpkLoading : public QFrame
{
Q_OBJECT
public:

View File

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

View File

@ -11,6 +11,7 @@
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QSlider>
#include "spkappitem.h"
#include "spkloading.h"
@ -23,7 +24,7 @@ namespace SpkUi
SpkPageUiTest(QWidget *parent = nullptr);
QWidget *WidL, *WidR;
QVBoxLayout *VLayWidgets,
*VLayBtn,
*VLayTestWidgets,
*VLayInput;
QHBoxLayout *HLay4Slider,
*HLayInputBtns;
@ -38,6 +39,7 @@ namespace SpkUi
QSlider *SlideH;
QSlider *SlideV;
SpkLoading *Loading;
SpkAppItem *AppItem;
QLineEdit *PopupText;
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;
public:
UiMetaObject() {}
UiMetaObject *Instance() {return nullptr;} //FIXME!!
public slots:
void SetAccentColor(QColor);
};

View File

@ -22,32 +22,37 @@ QWidget
color: #ffffff;
}
#spk_mw_category
QLabel
{
background: transparent;
}
#styMwCateg
{
border: none;
font-size: 14px;
show-decoration-selected: 1;
}
#spk_mw_category::item
#styMwCateg::item
{
height: 35px;
border: none;
color: %13;
}
#spk_mw_category::item:selected
#styMwCateg::item:selected
{
color: %11;
background-color: %4;
}
#spk_mw_category::branch:!has-children
#styMwCateg::branch:!has-children
{
background: %1;
}
#spk_mw_category::branch:selected
#styMwCateg::branch:selected
{
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)
}
#spk_styling_checkbtn
#styChkBtn
{
border-width: 0px;
background-color: %9
}
#spk_styling_checkbtn:pressed
#styChkBtn:pressed
{
background-color: %5
}
#spk_styling_checkbtn:checked
#styChkBtn:checked
{
background-color: %4
}
#spk_styling_plaincheckbtn
#styPlainChkBtn
{
border-width: 0px;
background-color: %1
}
#spk_styling_plaincheckbtn:pressed
#styPlainChkBtn:pressed
{
background-color: %5
}
#spk_styling_plaincheckbtn:checked
#styPlainChkBtn:checked
{
background-color: %4
}
@ -157,7 +162,19 @@ QScrollBar::add-line, QScrollBar::sub-line
height:0px
}
#spk_about_desc
#styAboutDesc
{
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);
}
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)