添加商店内弹出窗消息

使用SpkUiMessage::SendStoreNotification激活,必须在SpkStore构造函数加载完全局SpkPopup类之后才可
使用。
This commit is contained in:
RigoLigoRLC
2021-07-20 15:15:37 +08:00
parent e3c43198b9
commit 99083d2bcb
12 changed files with 126 additions and 5 deletions
+1
View File
@@ -65,6 +65,7 @@ set(SOURCE_FILES
inc/spkpageqsstest.h gui/spkpageqsstest.cpp inc/spkpageqsstest.h gui/spkpageqsstest.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/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
+16
View File
@@ -1,6 +1,7 @@
#include <QApplication> #include <QApplication>
#include "spkpageqsstest.h" #include "spkpageqsstest.h"
#include "spkpopup.h"
#include "spkui_general.h" #include "spkui_general.h"
SpkUi::SpkPageQssTest::SpkPageQssTest(QWidget *parent) : QSplitter(parent) SpkUi::SpkPageQssTest::SpkPageQssTest(QWidget *parent) : QSplitter(parent)
@@ -42,6 +43,14 @@ SpkUi::SpkPageQssTest::SpkPageQssTest(QWidget *parent) : QSplitter(parent)
Loading->setObjectName("spk_pg_qsstest_loading"); Loading->setObjectName("spk_pg_qsstest_loading");
Loading->start(); Loading->start();
PopupText = new QLineEdit(this);
PopupText->setObjectName("spk_pg_qsstest_poptext");
PopupText->setText("Hello, world");
ShowPopup = new QPushButton(this);
ShowPopup->setText("Show Popup");
connect(ShowPopup, &QPushButton::clicked, this, &SpkPageQssTest::ShowPopupSlot);
SlideV = new QSlider(this); SlideV = new QSlider(this);
SlideV->setObjectName("spk_pg_qsstest_slider_v"); SlideV->setObjectName("spk_pg_qsstest_slider_v");
SlideV->setOrientation(Qt::Vertical); SlideV->setOrientation(Qt::Vertical);
@@ -60,6 +69,8 @@ SpkUi::SpkPageQssTest::SpkPageQssTest(QWidget *parent) : QSplitter(parent)
VLayBtn->addWidget(Chk); VLayBtn->addWidget(Chk);
VLayBtn->addWidget(Rad); VLayBtn->addWidget(Rad);
VLayBtn->addWidget(Loading); VLayBtn->addWidget(Loading);
VLayBtn->addWidget(PopupText);
VLayBtn->addWidget(ShowPopup);
Group = new QGroupBox(this); Group = new QGroupBox(this);
Group->setObjectName("spk_pg_qsstest_groupbox"); Group->setObjectName("spk_pg_qsstest_groupbox");
@@ -102,3 +113,8 @@ void SpkUi::SpkPageQssTest::FetchStylesheet()
{ {
TextStylesheet->setPlainText(SpkUi::CurrentStylesheet); TextStylesheet->setPlainText(SpkUi::CurrentStylesheet);
} }
void SpkUi::SpkPageQssTest::ShowPopupSlot()
{
SpkUi::Popup->Show(PopupText->text());
}
+55
View File
@@ -0,0 +1,55 @@
#include "spkmainwindow.h"
#include "spkpopup.h"
#include <libavutil/avutil.h>
namespace SpkUi
{
SpkPopup::SpkPopup(QWidget *parent, int aMillis) : QWidget(parent)
{
setAttribute(Qt::WA_TransparentForMouseEvents);
setAttribute(Qt::WA_TranslucentBackground);
setWindowFlags(Qt::ToolTip | Qt::FramelessWindowHint);
mText = new QLabel();
mText->setStyleSheet("border-radius: 11px;"
"background-color: rgba(0,0,0,150);"
"color: white;"
"padding: 5px;");
mText->setText(tr("(No Text)"));
mBox = new QHBoxLayout(this);
mBox->addWidget(mText);
mBox->setContentsMargins(0, 0, 0, 0);
// The reason why we contain it in a widget is that, if we want a QLabel have rounded corners,
// then it must be able to be displayed with a translucent background. However, setting
// Qt::WA_TranslucentBackground will cause the entire background of QLabel transparent.
// Therefore we need a container (SpkPopup) with a transparent background as the canvas layer
// of the actual displayed text.
mAnimFadeIn = new QPropertyAnimation(this, "windowOpacity");
mAnimFadeOut = new QPropertyAnimation(this, "windowOpacity");
mAnim = new QSequentialAnimationGroup(this);
mAnimFadeIn->setStartValue(0);
mAnimFadeIn->setEndValue(1);
mAnimFadeIn->setDuration(250);
mAnimFadeOut->setStartValue(1);
mAnimFadeOut->setEndValue(0);
mAnimFadeOut->setDuration(250);
mAnim->addAnimation(mAnimFadeIn);
mAnim->addPause(aMillis);
mAnim->addAnimation(mAnimFadeOut);
setVisible(false);
}
void SpkPopup::Show(QString aText)
{
if(mAnim->state() == QSequentialAnimationGroup::Running)
mAnim->stop();
QSize parentSize = parentWidget()->size();
mText->setText(aText);
adjustSize();
move(QPoint((parentSize.width() - width()) / 2, parentSize.height() - height() - 30) +
parentWidget()->pos());
setMaximumWidth(parentSize.width() - 200);
setWindowOpacity(1);
show();
mAnim->start();
}
}
+4 -1
View File
@@ -18,6 +18,7 @@
#include "spkui_general.h" #include "spkui_general.h"
#include "spkmsgbox.h" #include "spkmsgbox.h"
#include "spkpopup.h"
#include "spklogging.h" #include "spklogging.h"
namespace SpkUi namespace SpkUi
@@ -32,6 +33,8 @@ namespace SpkUi
QStyle *OldSystemStyle = nullptr; QStyle *OldSystemStyle = nullptr;
QList<QColor> CurrentColorSet; QList<QColor> CurrentColorSet;
SpkPopup *Popup;
namespace States namespace States
{ {
bool IsDDE = false, IsUsingDtkPlugin = false; bool IsDDE = false, IsUsingDtkPlugin = false;
@@ -112,7 +115,7 @@ namespace SpkUi
} }
} }
// FIXME: Chameleon style kept adding unwanted blue focus indication border // NOTE: Chameleon style kept adding unwanted blue focus indication border
// to widgets that shouldn't have borders. // to widgets that shouldn't have borders.
// We need to eliminate this irritating problem. // We need to eliminate this irritating problem.
if(qgetenv("SPARK_NO_QSTYLE_CHANGE").toInt()) if(qgetenv("SPARK_NO_QSTYLE_CHANGE").toInt())
+1 -1
View File
@@ -62,7 +62,7 @@ namespace SpkUi
mLastCheckedBtn = nullptr; mLastCheckedBtn = nullptr;
} }
else else
// QUESTIONABLE: // NOTE:
// Apparently for checkable buttons, Qt flip their checked property AFTER // Apparently for checkable buttons, Qt flip their checked property AFTER
// this slot function. So to prevent a checkable button being unchecked, // 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. // we set it to unchecked here. Qt will flip it back to checked later.
+5
View File
@@ -7,6 +7,7 @@
#include <QCheckBox> #include <QCheckBox>
#include <QGroupBox> #include <QGroupBox>
#include <QTextEdit> #include <QTextEdit>
#include <QLineEdit>
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QSlider> #include <QSlider>
@@ -38,8 +39,12 @@ namespace SpkUi
QSlider *SlideV; QSlider *SlideV;
SpkLoading *Loading; SpkLoading *Loading;
QLineEdit *PopupText;
QPushButton *ShowPopup;
public slots: public slots:
void SetStylesheet(); void SetStylesheet();
void FetchStylesheet(); void FetchStylesheet();
void ShowPopupSlot();
}; };
} }
+30
View File
@@ -0,0 +1,30 @@
#pragma once
#include <QLabel>
#include <QWidget>
#include <QHBoxLayout>
#include <QPropertyAnimation>
#include <QSequentialAnimationGroup>
class SpkMainWindow;
namespace SpkUi
{
class SpkPopup : public QWidget
{
Q_OBJECT
public:
SpkPopup(QWidget *parent, int aMillis = 3000);
public slots:
void Show(QString aText);
private:
QPoint MoveOffset;
QLabel *mText;
QHBoxLayout *mBox;
QPropertyAnimation *mAnimFadeIn, *mAnimFadeOut;
QSequentialAnimationGroup *mAnim;
};
}
+4
View File
@@ -16,6 +16,8 @@ namespace SpkUi
enum SpkUiStyle { Light, Dark }; enum SpkUiStyle { Light, Dark };
enum SpkButtonStyle { Normal = 0, Recommend, Warn }; enum SpkButtonStyle { Normal = 0, Recommend, Warn };
class SpkPopup;
constexpr int StackTraceArraySize = 64; constexpr int StackTraceArraySize = 64;
constexpr const char * const StoreIconName = "spark-store"; constexpr const char * const StoreIconName = "spark-store";
@@ -40,6 +42,8 @@ namespace SpkUi
extern QStyle *OldSystemStyle; extern QStyle *OldSystemStyle;
extern QList<QColor> CurrentColorSet; extern QList<QColor> CurrentColorSet;
extern SpkPopup *Popup;
namespace States namespace States
{ {
extern bool IsDDE, IsUsingDtkPlugin; extern bool IsDDE, IsUsingDtkPlugin;
+2 -1
View File
@@ -6,6 +6,7 @@
#include <QFileInfo> #include <QFileInfo>
#include "spklogging.h" #include "spklogging.h"
#include "spkmsgbox.h" #include "spkmsgbox.h"
#include "spkuimsg.h"
SpkLogger *SpkLogger::Instance = nullptr; SpkLogger *SpkLogger::Instance = nullptr;
@@ -124,6 +125,6 @@ void SpkLogger::Critical(QString message)
void SpkLogger::Notify(QString message) void SpkLogger::Notify(QString message)
{ {
Q_UNUSED(message); SpkUiMessage::SendStoreNotification(message);
} }
+3
View File
@@ -4,8 +4,10 @@
#include <QDir> #include <QDir>
#include <QApplication> #include <QApplication>
#include <QtNetwork/QNetworkProxy> #include <QtNetwork/QNetworkProxy>
#include "dtk/spkdtkplugin.h" #include "dtk/spkdtkplugin.h"
#include "gitver.h" #include "gitver.h"
#include "spkpopup.h"
#include "spkstore.h" #include "spkstore.h"
#include "spkutils.h" #include "spkutils.h"
@@ -50,6 +52,7 @@ SpkStore::SpkStore(bool aCli, QString &aLogPath)
// UI Initialization // UI Initialization
SpkUi::Initialize(); SpkUi::Initialize();
mMainWindow = new SpkMainWindow; mMainWindow = new SpkMainWindow;
SpkUi::Popup = new SpkUi::SpkPopup(mMainWindow);
mMainWindow->show(); mMainWindow->show();
} }
+2 -1
View File
@@ -1,5 +1,6 @@
#include "spkuimsg.h" #include "spkuimsg.h"
#include "spkpopup.h"
NotifyNotification *SpkUiMessage::_notify = nullptr; // Initialize statics NotifyNotification *SpkUiMessage::_notify = nullptr; // Initialize statics
int SpkUiMessage::mTimeoutDesktop = 5000; int SpkUiMessage::mTimeoutDesktop = 5000;
@@ -25,7 +26,7 @@ void SpkUiMessage::SendDesktopNotification(QString s, const char * const icon)
void SpkUiMessage::SendStoreNotification(QString s) // TODO: IMPLEMENT IN-APP NOTIFICATION void SpkUiMessage::SendStoreNotification(QString s) // TODO: IMPLEMENT IN-APP NOTIFICATION
{ {
Q_UNUSED(s); SpkUi::Popup->Show(s);
} }
void SpkUiMessage::SetDesktopNotifyTimeout(int ms) void SpkUiMessage::SetDesktopNotifyTimeout(int ms)
+3 -1
View File
@@ -1,4 +1,5 @@
#include <arpa/inet.h>
#include <QDebug> #include <QDebug>
#include "spkutils.h" #include "spkutils.h"
@@ -14,7 +15,8 @@ void SpkUtils::VerifySingleRequest(QPointer<QNetworkReply> aReply)
QString SpkUtils::GetDistroName() QString SpkUtils::GetDistroName()
{ {
QSettings osRelease("/etc/os-release", QSettings::IniFormat); QSettings osRelease("/etc/os-release", QSettings::IniFormat);
return osRelease.value("PRETTY_NAME", "Unknown Distro").toString(); return osRelease.value("PRETTY_NAME", "Unknown Distro").toString() + "-" +
osRelease.value("BUILD_ID", "Unknown Build").toString();
} }
bool SpkUtils::VerifyReplyJson(QNetworkReply *aReply, QJsonValue &aRetDoc) bool SpkUtils::VerifyReplyJson(QNetworkReply *aReply, QJsonValue &aRetDoc)