mirror of
https://gitee.com/spark-store-project/spark-store
synced 2025-12-14 04:42:03 +08:00
进度更新
This commit is contained in:
78
gui/spkloading.cpp
Normal file
78
gui/spkloading.cpp
Normal file
@@ -0,0 +1,78 @@
|
||||
|
||||
#include <QPaintEvent>
|
||||
#include <QPainter>
|
||||
#include "spkloading.h"
|
||||
|
||||
SpkLoading::SpkLoading(QWidget *parent) : QWidget(parent)
|
||||
{
|
||||
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
|
||||
mAnimTimer = new QTimeLine(400, this);
|
||||
mAnimTimer->setFrameRange(10, 30);
|
||||
mAnimTimer->setEasingCurve(QEasingCurve::InCubic);
|
||||
for(int i = 0; i < 5; i++)
|
||||
mSizeList.append(20);
|
||||
connect(mAnimTimer, &QTimeLine::frameChanged, this, &SpkLoading::timer);
|
||||
connect(mAnimTimer, &QTimeLine::finished, this, &SpkLoading::loop);
|
||||
}
|
||||
|
||||
void SpkLoading::paintEvent(QPaintEvent *e)
|
||||
{
|
||||
QPainter p(this);
|
||||
QPen pen(Qt::NoPen);
|
||||
QBrush b({ 0, 0x7b, 0xff }, Qt::SolidPattern); // TODO: Customizable accent color
|
||||
p.setBrush(b);
|
||||
p.setPen(pen);
|
||||
p.setRenderHint(QPainter::Antialiasing);
|
||||
dx = width() / 2 - dh * 2;
|
||||
dy = height() / 2;
|
||||
|
||||
double r;
|
||||
for(int i = 0; i < 5; i++)
|
||||
{
|
||||
r = dh * mSizeList[i] / 80;
|
||||
p.drawEllipse({ dx, dy }, r, r);
|
||||
dx += dh;
|
||||
}
|
||||
e->accept();
|
||||
}
|
||||
|
||||
void SpkLoading::resizeEvent(QResizeEvent *e)
|
||||
{
|
||||
// Calculate size of drawing space
|
||||
if(mUserHeight != 0 && mUserHeight * 5 <= e->size().width())
|
||||
{
|
||||
dw = 5 * mUserHeight;
|
||||
dh = mUserHeight;
|
||||
return;
|
||||
}
|
||||
dh = e->size().height();
|
||||
if(width() < dh * 5)
|
||||
{
|
||||
dw = e->size().width();
|
||||
dh = dw / 5;
|
||||
}
|
||||
else
|
||||
dw = dh * 5;
|
||||
}
|
||||
|
||||
void SpkLoading::timer(int s)
|
||||
{
|
||||
for(int i = 4; i > 0; i--)
|
||||
mSizeList[i] = mSizeList[i - 1];
|
||||
mSizeList[0] = s;
|
||||
update();
|
||||
}
|
||||
|
||||
void SpkLoading::loop()
|
||||
{
|
||||
mAnimTimer->setDirection(mAnimTimer->direction() == QTimeLine::Forward ?
|
||||
QTimeLine::Backward : QTimeLine::Forward);
|
||||
mAnimTimer->start();
|
||||
}
|
||||
|
||||
void SpkLoading::reset()
|
||||
{
|
||||
for(int i = 0; i < 5; i++)
|
||||
mSizeList[i] = 20;
|
||||
update();
|
||||
}
|
||||
@@ -33,7 +33,7 @@ void SpkMainWindow::PopulateCategories(QJsonObject aCategoryData)
|
||||
SpkUiMessage::SendStoreNotification(tr("Failed to load categories; invalid return code."));
|
||||
return;
|
||||
}
|
||||
if(OpRetCode.toDouble() != 0)
|
||||
if(OpRetCode.toInt() != 0)
|
||||
{
|
||||
SpkUiMessage::SendStoreNotification(tr("Failed to load categories; operation failed: %1.")
|
||||
.arg(OpRetCode.toDouble()));
|
||||
@@ -66,7 +66,7 @@ void SpkMainWindow::PopulateCategories(QJsonObject aCategoryData)
|
||||
if(j.contains("type_name") && j.value("type_name").isString())
|
||||
typeName = j.value("type_name").toString();
|
||||
else goto WRONG_CATEGORY;
|
||||
w->AddButton(tr(typeName.toLocal8Bit()), typeId /* TODO: ICONS */);
|
||||
// TODO
|
||||
continue;
|
||||
}
|
||||
WRONG_CATEGORY:
|
||||
@@ -78,9 +78,7 @@ SpkUi::SpkMainWidget::SpkMainWidget(QWidget *parent) : QFrame(parent)
|
||||
{
|
||||
setObjectName("spk_mainwidget");
|
||||
|
||||
VLayCategoryButtons = new QVBoxLayout;
|
||||
VLayCategoryButtons->setObjectName("spk_mw_category_vlay");
|
||||
VLayCategoryButtons->addWidget(new QPushButton);
|
||||
QTreeWidgetItem *item;
|
||||
|
||||
Pager = new QStackedWidget(this);
|
||||
Pager->setObjectName("spk_mw_pager");
|
||||
@@ -88,7 +86,8 @@ SpkUi::SpkMainWidget::SpkMainWidget(QWidget *parent) : QFrame(parent)
|
||||
|
||||
TitleBar = new SpkTitleBar(this);
|
||||
TitleBar->setObjectName("spk_mw_titlebar");
|
||||
TitleBar->SetTitle("Title");
|
||||
TitleBar->SetUseIcon(false);
|
||||
TitleBar->SetTitle("");
|
||||
|
||||
VLayMain = new QVBoxLayout;
|
||||
VLayMain->setObjectName("spk_mw_main_vlay");
|
||||
@@ -97,20 +96,73 @@ SpkUi::SpkMainWidget::SpkMainWidget(QWidget *parent) : QFrame(parent)
|
||||
VLayMain->addWidget(TitleBar);
|
||||
VLayMain->addWidget(Pager);
|
||||
|
||||
CategoryWidget = new SpkCategorySelector(this);
|
||||
VLaySidebar = new QVBoxLayout;
|
||||
VLaySidebar->setObjectName("spk_mw_sidebar_lay");
|
||||
VLaySidebar->setSpacing(0);
|
||||
VLaySidebar->setContentsMargins(0, 0, 0, 0);
|
||||
|
||||
SideBarRestrictor = new QWidget(this);
|
||||
SideBarRestrictor->setObjectName("spk_mw_sidebar_restrictor");
|
||||
SideBarRestrictor->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
|
||||
SideBarRestrictor->setMaximumWidth(300);
|
||||
SideBarRestrictor->setMinimumWidth(300);
|
||||
SideBarRestrictor->setLayout(VLaySidebar);
|
||||
|
||||
HLaySideTop = new QHBoxLayout;
|
||||
HLaySideTop->setObjectName("spk_mw_sidebar_top_lay");
|
||||
HLaySideTop->setSpacing(8);
|
||||
HLaySideTop->setContentsMargins(8, 4, 4, 4);
|
||||
|
||||
StoreIcon = new QLabel(this);
|
||||
StoreIcon->setObjectName("spk_mw_icon");
|
||||
StoreIcon->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
||||
StoreIcon->setMaximumSize({ 48, 48 });
|
||||
StoreIcon->setMinimumSize({ 48, 48 });
|
||||
StoreIcon->setPixmap(QIcon(":/icons/spark-store.svg").pixmap(StoreIcon->size()));
|
||||
|
||||
SidebarMgr = new SpkSidebarSelector(this);
|
||||
SidebarMgr->setObjectName("spk_mw_sidebar_mgr");
|
||||
|
||||
BtnSettings = new QPushButton(this);
|
||||
BtnSettings->setObjectName("spk_styling_plaincheckbtn");
|
||||
BtnSettings->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
||||
BtnSettings->setCheckable(true);
|
||||
BtnSettings->setMaximumSize({ 48, 48 });
|
||||
BtnSettings->setMinimumSize({ 48, 48 });
|
||||
BtnSettings->setIconSize(QSize(24, 24));
|
||||
BtnSettings->setIcon(SpkUi::GetThemedIcon("settings"));
|
||||
BtnSettings->setProperty("spk_pageno", 0);
|
||||
SidebarMgr->BindPageSwitcherButton(BtnSettings);
|
||||
|
||||
HLaySideTop->addWidget(StoreIcon);
|
||||
HLaySideTop->addStretch();
|
||||
HLaySideTop->addWidget(BtnSettings);
|
||||
VLaySidebar->addLayout(HLaySideTop);
|
||||
|
||||
CategoryWidget = new QTreeWidget(this);
|
||||
CategoryWidget->setObjectName("spk_mw_category");
|
||||
CategoryWidget->setLayout(VLayCategoryButtons);
|
||||
CategoryWidget->setAutoFillBackground(true);
|
||||
CategoryWidget->setMaximumWidth(300);
|
||||
CategoryWidget->setMinimumWidth(300);
|
||||
CategoryWidget->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
|
||||
CategoryWidget->setColumnCount(1);
|
||||
CategoryWidget->setHeaderHidden(true);
|
||||
CategoryWidget->setSelectionMode(QAbstractItemView::SelectionMode::SingleSelection);
|
||||
item = new QTreeWidgetItem(QStringList("Placeholder"));
|
||||
item->setData(0, Qt::UserRole + 1, 1);
|
||||
item->setData(0, Qt::UserRole + 2, 1);
|
||||
CategoryWidget->addTopLevelItem(item);
|
||||
// FIXMEIFPOSSIBLE: Fusion adds extra gradient.
|
||||
// Details: https://forum.qt.io/topic/128190/fusion-style-kept-adding-an-extra-
|
||||
// layer-of-gradient-to-my-selected-item-of-qtreewidget-even-with-qss
|
||||
if(SpkUi::OldSystemStyle)
|
||||
CategoryWidget->setStyle(SpkUi::OldSystemStyle);
|
||||
VLaySidebar->addWidget(CategoryWidget);
|
||||
SidebarMgr->BindCategoryWidget(CategoryWidget);
|
||||
|
||||
HorizontalDivide = new QHBoxLayout;
|
||||
HorizontalDivide->setObjectName("spk_mw_divide_hlay");
|
||||
HorizontalDivide->setSpacing(0);
|
||||
HorizontalDivide->setContentsMargins(0, 0, 0, 0);
|
||||
HorizontalDivide->setAlignment(Qt::AlignLeft);
|
||||
HorizontalDivide->addWidget(CategoryWidget);
|
||||
HorizontalDivide->addWidget(SideBarRestrictor);
|
||||
HorizontalDivide->addLayout(VLayMain);
|
||||
|
||||
// Initialize pages
|
||||
|
||||
@@ -79,7 +79,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_msgboxexpandbtn");
|
||||
wExpandBtn->setObjectName("spk_styling_checkbtn");
|
||||
connect(wExpandBtn, &QPushButton::clicked,
|
||||
[&](){ // FIXME: hint doesn't change when visibility changes, this is a quirky hack
|
||||
wExtraArea->setVisible(wExpandBtn->isChecked());
|
||||
@@ -88,12 +88,15 @@ int SpkMsgBox::StaticExec(QString msg, QString title, QMessageBox::Icon icon,
|
||||
else
|
||||
b->setFixedHeight(InitialHeight);
|
||||
});
|
||||
b->AddWidget(wExpandBtn);
|
||||
b->mBtnLay->addWidget(wExpandBtn);
|
||||
b->mBtnLay->addStretch();
|
||||
b->AddWidget(wExtraArea);
|
||||
}
|
||||
|
||||
b->AddSpacing(3);
|
||||
AddButtons(b, buttons);
|
||||
if(hasextra) // Keep conventional buttons centered
|
||||
b->mBtnLay->addStretch();
|
||||
InitialHeight = b->minimumSizeHint().height();
|
||||
auto pos = (SpkUi::PrimaryScreenSize - b->sizeHint()) / 2;
|
||||
b->move(pos.width(), pos.height());
|
||||
|
||||
@@ -9,7 +9,7 @@ SpkUi::SpkPageQssTest::SpkPageQssTest(QWidget *parent) : QSplitter(parent)
|
||||
|
||||
TextStylesheet = new QTextEdit(this);
|
||||
TextStylesheet->setObjectName("spk_pg_qsstest_qsstext");
|
||||
TextStylesheet->setPlainText(*SpkUi::CurrentStylesheet);
|
||||
TextStylesheet->setPlainText(SpkUi::CurrentStylesheet);
|
||||
|
||||
BtnApply = new QPushButton(this);
|
||||
BtnApply->setObjectName("spk_pg_qsstest_btnapply");
|
||||
@@ -38,6 +38,10 @@ SpkUi::SpkPageQssTest::SpkPageQssTest(QWidget *parent) : QSplitter(parent)
|
||||
Rad->setObjectName("spk_pg_qsstest_radiobtn");
|
||||
Rad->setText("RadioButton");
|
||||
|
||||
Loading = new SpkLoading(this);
|
||||
Loading->setObjectName("spk_pg_qsstest_loading");
|
||||
Loading->start();
|
||||
|
||||
SlideV = new QSlider(this);
|
||||
SlideV->setObjectName("spk_pg_qsstest_slider_v");
|
||||
SlideV->setOrientation(Qt::Vertical);
|
||||
@@ -55,6 +59,7 @@ SpkUi::SpkPageQssTest::SpkPageQssTest(QWidget *parent) : QSplitter(parent)
|
||||
VLayBtn->addWidget(Btn);
|
||||
VLayBtn->addWidget(Chk);
|
||||
VLayBtn->addWidget(Rad);
|
||||
VLayBtn->addWidget(Loading);
|
||||
|
||||
Group = new QGroupBox(this);
|
||||
Group->setObjectName("spk_pg_qsstest_groupbox");
|
||||
@@ -95,5 +100,5 @@ void SpkUi::SpkPageQssTest::SetStylesheet()
|
||||
|
||||
void SpkUi::SpkPageQssTest::FetchStylesheet()
|
||||
{
|
||||
TextStylesheet->setPlainText(*SpkUi::CurrentStylesheet);
|
||||
TextStylesheet->setPlainText(SpkUi::CurrentStylesheet);
|
||||
}
|
||||
|
||||
@@ -11,33 +11,40 @@ SpkTitleBar::SpkTitleBar(QWidget *parent) : QWidget(parent)
|
||||
setMinimumHeight(48);
|
||||
setMaximumHeight(48);
|
||||
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
||||
mIcon.setFixedSize(32, 32);
|
||||
|
||||
mMainLayout.addSpacing(8);
|
||||
mMainLayout.addWidget(&mIcon);
|
||||
mMainLayout.addSpacing(8);
|
||||
mMainLayout.addWidget(&mTitle);
|
||||
mMainLayout.addSpacing(8);
|
||||
mMainLayout.addLayout(&mUserSpaceL);
|
||||
mMainLayout.addStretch();
|
||||
mMainLayout.addLayout(&mUserSpaceR);
|
||||
mMainLayout.addSpacing(8);
|
||||
mMainLayout.addWidget(&mBtnMin);
|
||||
mMainLayout.addWidget(&mBtnMaxRestore);
|
||||
mMainLayout.addWidget(&mBtnClose);
|
||||
mIcon = new QLabel(this);
|
||||
mTitle = new QLabel(this);
|
||||
mIcon->setFixedSize(32, 32);
|
||||
|
||||
mBtnMin.SetRole(OperationButton::Minimize);
|
||||
mBtnMaxRestore.SetRole(OperationButton::MaximizeRestore);
|
||||
mBtnClose.SetRole(OperationButton::Close);
|
||||
mMainLayout = new QHBoxLayout(this);
|
||||
mUserSpace = new QHBoxLayout();
|
||||
mBtnGroup = new QHBoxLayout();
|
||||
mBtnMin = new SpkTitleBarDefaultButton(this);
|
||||
mBtnMaxRestore = new SpkTitleBarDefaultButton(this);
|
||||
mBtnClose= new SpkTitleBarDefaultButton(this);
|
||||
mMainLayout->setSpacing(8);
|
||||
mBtnGroup->setSpacing(0);
|
||||
|
||||
mMainLayout.setSpacing(0);
|
||||
mMainLayout.setContentsMargins(0, 0, 0, 0);
|
||||
mMainLayout->addSpacing(8);
|
||||
mMainLayout->addWidget(mIcon);
|
||||
mMainLayout->addWidget(mTitle);
|
||||
mMainLayout->addLayout(mUserSpace);
|
||||
mMainLayout->addLayout(mBtnGroup);
|
||||
mBtnGroup->addWidget(mBtnMin);
|
||||
mBtnGroup->addWidget(mBtnMaxRestore);
|
||||
mBtnGroup->addWidget(mBtnClose);
|
||||
|
||||
setLayout(&mMainLayout);
|
||||
mBtnMin->SetRole(OperationButton::Minimize);
|
||||
mBtnMaxRestore->SetRole(OperationButton::MaximizeRestore);
|
||||
mBtnClose->SetRole(OperationButton::Close);
|
||||
|
||||
connect(&mBtnClose, &QPushButton::clicked, this, &SpkTitleBar::CloseWindow);
|
||||
connect(&mBtnMin, &QPushButton::clicked, this, &SpkTitleBar::MinimizeWindow);
|
||||
connect(&mBtnMaxRestore, &QPushButton::clicked, this, &SpkTitleBar::MaximizeRestoreWindow);
|
||||
mMainLayout->setContentsMargins(0, 0, 0, 0);
|
||||
|
||||
setLayout(mMainLayout);
|
||||
|
||||
connect(mBtnClose, &QPushButton::clicked, this, &SpkTitleBar::CloseWindow);
|
||||
connect(mBtnMin, &QPushButton::clicked, this, &SpkTitleBar::MinimizeWindow);
|
||||
connect(mBtnMaxRestore, &QPushButton::clicked, this, &SpkTitleBar::MaximizeRestoreWindow);
|
||||
}
|
||||
|
||||
SpkTitleBar::~SpkTitleBar()
|
||||
@@ -47,9 +54,9 @@ SpkTitleBar::~SpkTitleBar()
|
||||
|
||||
void SpkTitleBar::SetOperationButton(OperationButton type)
|
||||
{
|
||||
mBtnClose.setVisible(type & OperationButton::Close);
|
||||
mBtnMaxRestore.setVisible(type & OperationButton::MaximizeRestore);
|
||||
mBtnMin.setVisible(type & OperationButton::Minimize);
|
||||
mBtnClose->setVisible(type & OperationButton::Close);
|
||||
mBtnMaxRestore->setVisible(type & OperationButton::MaximizeRestore);
|
||||
mBtnMin->setVisible(type & OperationButton::Minimize);
|
||||
}
|
||||
|
||||
bool SpkTitleBar::event(QEvent *evt)
|
||||
@@ -59,7 +66,7 @@ bool SpkTitleBar::event(QEvent *evt)
|
||||
case QEvent::MouseButtonDblClick:
|
||||
{
|
||||
if(static_cast<QMouseEvent*>(evt)->button())
|
||||
emit mBtnMaxRestore.clicked();
|
||||
emit mBtnMaxRestore->clicked();
|
||||
break;
|
||||
}
|
||||
default:;
|
||||
@@ -90,7 +97,7 @@ void SpkTitleBar::MaximizeRestoreWindow()
|
||||
}
|
||||
}
|
||||
|
||||
SpkTitleBarDefaultButton::SpkTitleBarDefaultButton()
|
||||
SpkTitleBarDefaultButton::SpkTitleBarDefaultButton(QWidget* parent) : QPushButton(parent)
|
||||
{
|
||||
setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
|
||||
setMaximumWidth(ButtonWidth);
|
||||
|
||||
@@ -22,10 +22,12 @@
|
||||
|
||||
namespace SpkUi
|
||||
{
|
||||
QString StylesheetLight, StylesheetDark, *CurrentStylesheet = &StylesheetLight;
|
||||
SpkUiStyle CurrentStyle;
|
||||
QString StylesheetBase, CurrentStylesheet;
|
||||
QColor ColorLine, ColorBack;
|
||||
QSize PrimaryScreenSize;
|
||||
SpkDtkPlugin *DtkPlugin = nullptr;
|
||||
QStyle *OldSystemStyle = nullptr;
|
||||
|
||||
namespace Priv
|
||||
{
|
||||
@@ -36,13 +38,9 @@ namespace SpkUi
|
||||
{
|
||||
// Obtain global stylesheets
|
||||
QFile ObtainStylesheet;
|
||||
ObtainStylesheet.setFileName(":/stylesheets/stylesheets/mainwindow.css");
|
||||
ObtainStylesheet.open(QIODevice::ReadOnly);
|
||||
StylesheetLight = ObtainStylesheet.readAll();
|
||||
ObtainStylesheet.close();
|
||||
ObtainStylesheet.setFileName(":/stylesheets/stylesheets/mainwindow_dark.css");
|
||||
ObtainStylesheet.open(QIODevice::ReadOnly);
|
||||
StylesheetDark = ObtainStylesheet.readAll();
|
||||
StylesheetBase = ObtainStylesheet.readAll();
|
||||
ObtainStylesheet.close();
|
||||
|
||||
SetGlobalStyle(Dark);
|
||||
@@ -96,10 +94,16 @@ namespace SpkUi
|
||||
// FIXME: Chameleon style kept adding unwanted blue focus indication border
|
||||
// to widgets that shouldn't have borders.
|
||||
// We need to eliminate this irritating problem.
|
||||
if(qgetenv("SPARK_NO_QSTYLE_CHANGE") == "1")
|
||||
return;
|
||||
OldSystemStyle = QStyleFactory::create("chameleon"); // TreeWidget doesn't work well with Fusion
|
||||
auto styles = QStyleFactory::keys();
|
||||
styles.removeAll("chameleon");
|
||||
if(styles.contains("Fusion"))
|
||||
qApp->setStyle(QStyleFactory::create("Fusion"));
|
||||
{
|
||||
auto style = QStyleFactory::create("Fusion");
|
||||
qApp->setStyle(style);
|
||||
}
|
||||
else if(styles.size()) // What? This shouldn't happen.
|
||||
qApp->setStyle(QStyleFactory::create(styles[0]));
|
||||
else // Duh...
|
||||
@@ -109,22 +113,34 @@ namespace SpkUi
|
||||
|
||||
void SetGlobalStyle(const SpkUiStyle aStyle)
|
||||
{
|
||||
CurrentStyle = aStyle;
|
||||
switch(aStyle)
|
||||
{
|
||||
case Light:
|
||||
qApp->setStyleSheet(StylesheetLight);
|
||||
CurrentStylesheet = &StylesheetLight;
|
||||
CurrentStylesheet = StylesheetFromColors(
|
||||
QList<QColor>{
|
||||
0x353535, 0x353535, 0xff0000, 0x0070ff, 0x2987ff,
|
||||
0x6b6b6b, 0x656565, 0x606060, 0x404040, 0x383838,
|
||||
ColorTextOnBackground(0x0070ff)
|
||||
});
|
||||
qApp->setStyleSheet(CurrentStylesheet);
|
||||
// TODO
|
||||
ColorLine = Qt::black;
|
||||
break;
|
||||
case Dark:
|
||||
qApp->setStyleSheet(StylesheetDark);
|
||||
CurrentStylesheet = &StylesheetDark;
|
||||
CurrentStylesheet = StylesheetFromColors(
|
||||
QList<QColor>{
|
||||
0x353535, 0x353535, 0xff0000, 0x0070ff, 0x2987ff,
|
||||
0x6b6b6b, 0x656565, 0x606060, 0x404040, 0x383838,
|
||||
ColorTextOnBackground(0x0070ff)
|
||||
});
|
||||
qApp->setStyleSheet(CurrentStylesheet);
|
||||
ColorLine = Qt::white;
|
||||
break;
|
||||
default:
|
||||
sWarn(QObject::tr("SetGlobalStyle invoked with unknown style %1.")
|
||||
.arg(static_cast<int>(aStyle)));
|
||||
break;
|
||||
// default:
|
||||
// sWarn(QObject::tr("SetGlobalStyle invoked with unknown style %1.")
|
||||
// .arg(static_cast<int>(aStyle)));
|
||||
// break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -195,4 +211,27 @@ namespace SpkUi
|
||||
"to continue execution.").arg(sig));
|
||||
}
|
||||
}
|
||||
|
||||
QIcon GetThemedIcon(QString name)
|
||||
{
|
||||
if(CurrentStyle == SpkUiStyle::Dark)
|
||||
name += "-dark";
|
||||
return QIcon(":/icons/" + name + ".svg");
|
||||
}
|
||||
|
||||
QString StylesheetFromColors(QList<QColor> aColors)
|
||||
{
|
||||
QString ret = StylesheetBase;
|
||||
foreach(auto &i, aColors)
|
||||
ret = ret.arg(i.name());
|
||||
return ret;
|
||||
}
|
||||
|
||||
QColor ColorTextOnBackground(QColor c)
|
||||
{
|
||||
// From https://github.com/feiyangqingyun/qtkaifajingyan
|
||||
double gray = (0.299 * c.red() + 0.587 * c.green() + 0.114 * c.blue()) / 255;
|
||||
return gray > 0.5 ? Qt::black : Qt::white;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
SpkWindow::SpkWindow(QWidget *parent, Qt::WindowFlags flags) : QMainWindow(parent, flags)
|
||||
{
|
||||
if(SpkUi::DtkPlugin)
|
||||
if(SpkUi::DtkPlugin && qgetenv("SPARK_NO_DXCB") == "0")
|
||||
SpkUi::DtkPlugin->addWindow(this, parent); // Register window to DXcb so we got Deepin
|
||||
else
|
||||
setWindowFlags(Qt::FramelessWindowHint); // Remove default title bar
|
||||
@@ -24,6 +24,7 @@ SpkWindow::SpkWindow(QWidget *parent, Qt::WindowFlags flags) : QMainWindow(paren
|
||||
mResizing = false;
|
||||
mCloseHook = nullptr;
|
||||
mMaximized = windowState().testFlag(Qt::WindowMaximized);
|
||||
mUseCustomEvents = SpkUi::DtkPlugin == nullptr;
|
||||
|
||||
PopulateUi();
|
||||
}
|
||||
@@ -35,15 +36,19 @@ SpkWindow::~SpkWindow()
|
||||
|
||||
bool SpkWindow::event(QEvent *evt)
|
||||
{
|
||||
// These custom events weren't useful for Deepin platform
|
||||
if(!mUseCustomEvents)
|
||||
return QMainWindow::event(evt);
|
||||
|
||||
switch(evt->type())
|
||||
{
|
||||
case QEvent::WindowStateChange:
|
||||
{
|
||||
mMaximized = windowState().testFlag(Qt::WindowMaximized);
|
||||
if(mMaximized)
|
||||
mTitleBarComponent->mBtnMaxRestore.SetRole(SpkTitleBarDefaultButton::Restore);
|
||||
mTitleBarComponent->mBtnMaxRestore->SetRole(SpkTitleBarDefaultButton::Restore);
|
||||
else
|
||||
mTitleBarComponent->mBtnMaxRestore.SetRole(SpkTitleBarDefaultButton::MaximizeRestore);
|
||||
mTitleBarComponent->mBtnMaxRestore->SetRole(SpkTitleBarDefaultButton::MaximizeRestore);
|
||||
break;
|
||||
}
|
||||
case QEvent::MouseButtonPress:
|
||||
@@ -211,10 +216,10 @@ void SpkWindow::SetWindowTheme(SpkWindow::SpkWindowStyle style)
|
||||
switch(style)
|
||||
{
|
||||
case Light:
|
||||
this->setStyleSheet(SpkUi::StylesheetLight);
|
||||
SpkUi::SetGlobalStyle(SpkUi::SpkUiStyle::Light);
|
||||
break;
|
||||
case Dark:
|
||||
this->setStyleSheet(SpkUi::StylesheetDark);
|
||||
SpkUi::SetGlobalStyle(SpkUi::SpkUiStyle::Dark);
|
||||
break;
|
||||
default:
|
||||
;
|
||||
|
||||
Reference in New Issue
Block a user