mirror of
https://gitee.com/spark-store-project/spark-store
synced 2025-09-09 12:52:22 +08:00
添加商店内弹出窗消息
使用SpkUiMessage::SendStoreNotification激活,必须在SpkStore构造函数加载完全局SpkPopup类之后才可 使用。
This commit is contained in:
parent
e3c43198b9
commit
99083d2bcb
@ -65,6 +65,7 @@ set(SOURCE_FILES
|
||||
inc/spkpageqsstest.h gui/spkpageqsstest.cpp
|
||||
inc/spkloading.h gui/spkloading.cpp
|
||||
inc/spksidebartree.h gui/spksidebartree.cpp
|
||||
inc/spkpopup.h gui/spkpopup.cpp
|
||||
|
||||
inc/spkstore.h src/spkstore.cpp
|
||||
inc/spkuimsg.h src/spkuimsg.cpp
|
||||
|
@ -1,6 +1,7 @@
|
||||
|
||||
#include <QApplication>
|
||||
#include "spkpageqsstest.h"
|
||||
#include "spkpopup.h"
|
||||
#include "spkui_general.h"
|
||||
|
||||
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->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->setObjectName("spk_pg_qsstest_slider_v");
|
||||
SlideV->setOrientation(Qt::Vertical);
|
||||
@ -60,6 +69,8 @@ SpkUi::SpkPageQssTest::SpkPageQssTest(QWidget *parent) : QSplitter(parent)
|
||||
VLayBtn->addWidget(Chk);
|
||||
VLayBtn->addWidget(Rad);
|
||||
VLayBtn->addWidget(Loading);
|
||||
VLayBtn->addWidget(PopupText);
|
||||
VLayBtn->addWidget(ShowPopup);
|
||||
|
||||
Group = new QGroupBox(this);
|
||||
Group->setObjectName("spk_pg_qsstest_groupbox");
|
||||
@ -102,3 +113,8 @@ void SpkUi::SpkPageQssTest::FetchStylesheet()
|
||||
{
|
||||
TextStylesheet->setPlainText(SpkUi::CurrentStylesheet);
|
||||
}
|
||||
|
||||
void SpkUi::SpkPageQssTest::ShowPopupSlot()
|
||||
{
|
||||
SpkUi::Popup->Show(PopupText->text());
|
||||
}
|
||||
|
55
gui/spkpopup.cpp
Normal file
55
gui/spkpopup.cpp
Normal 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();
|
||||
}
|
||||
}
|
@ -18,6 +18,7 @@
|
||||
|
||||
#include "spkui_general.h"
|
||||
#include "spkmsgbox.h"
|
||||
#include "spkpopup.h"
|
||||
#include "spklogging.h"
|
||||
|
||||
namespace SpkUi
|
||||
@ -32,6 +33,8 @@ namespace SpkUi
|
||||
QStyle *OldSystemStyle = nullptr;
|
||||
QList<QColor> CurrentColorSet;
|
||||
|
||||
SpkPopup *Popup;
|
||||
|
||||
namespace States
|
||||
{
|
||||
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.
|
||||
// We need to eliminate this irritating problem.
|
||||
if(qgetenv("SPARK_NO_QSTYLE_CHANGE").toInt())
|
||||
|
@ -62,7 +62,7 @@ namespace SpkUi
|
||||
mLastCheckedBtn = nullptr;
|
||||
}
|
||||
else
|
||||
// QUESTIONABLE:
|
||||
// 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.
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include <QCheckBox>
|
||||
#include <QGroupBox>
|
||||
#include <QTextEdit>
|
||||
#include <QLineEdit>
|
||||
#include <QVBoxLayout>
|
||||
#include <QHBoxLayout>
|
||||
#include <QSlider>
|
||||
@ -38,8 +39,12 @@ namespace SpkUi
|
||||
QSlider *SlideV;
|
||||
SpkLoading *Loading;
|
||||
|
||||
QLineEdit *PopupText;
|
||||
QPushButton *ShowPopup;
|
||||
|
||||
public slots:
|
||||
void SetStylesheet();
|
||||
void FetchStylesheet();
|
||||
void ShowPopupSlot();
|
||||
};
|
||||
}
|
||||
|
30
inc/spkpopup.h
Normal file
30
inc/spkpopup.h
Normal 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;
|
||||
};
|
||||
}
|
@ -16,6 +16,8 @@ namespace SpkUi
|
||||
enum SpkUiStyle { Light, Dark };
|
||||
enum SpkButtonStyle { Normal = 0, Recommend, Warn };
|
||||
|
||||
class SpkPopup;
|
||||
|
||||
constexpr int StackTraceArraySize = 64;
|
||||
constexpr const char * const StoreIconName = "spark-store";
|
||||
|
||||
@ -40,6 +42,8 @@ namespace SpkUi
|
||||
extern QStyle *OldSystemStyle;
|
||||
extern QList<QColor> CurrentColorSet;
|
||||
|
||||
extern SpkPopup *Popup;
|
||||
|
||||
namespace States
|
||||
{
|
||||
extern bool IsDDE, IsUsingDtkPlugin;
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include <QFileInfo>
|
||||
#include "spklogging.h"
|
||||
#include "spkmsgbox.h"
|
||||
#include "spkuimsg.h"
|
||||
|
||||
SpkLogger *SpkLogger::Instance = nullptr;
|
||||
|
||||
@ -124,6 +125,6 @@ void SpkLogger::Critical(QString message)
|
||||
|
||||
void SpkLogger::Notify(QString message)
|
||||
{
|
||||
Q_UNUSED(message);
|
||||
SpkUiMessage::SendStoreNotification(message);
|
||||
}
|
||||
|
||||
|
@ -4,8 +4,10 @@
|
||||
#include <QDir>
|
||||
#include <QApplication>
|
||||
#include <QtNetwork/QNetworkProxy>
|
||||
|
||||
#include "dtk/spkdtkplugin.h"
|
||||
#include "gitver.h"
|
||||
#include "spkpopup.h"
|
||||
#include "spkstore.h"
|
||||
#include "spkutils.h"
|
||||
|
||||
@ -50,6 +52,7 @@ SpkStore::SpkStore(bool aCli, QString &aLogPath)
|
||||
// UI Initialization
|
||||
SpkUi::Initialize();
|
||||
mMainWindow = new SpkMainWindow;
|
||||
SpkUi::Popup = new SpkUi::SpkPopup(mMainWindow);
|
||||
|
||||
mMainWindow->show();
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
|
||||
#include "spkuimsg.h"
|
||||
#include "spkpopup.h"
|
||||
|
||||
NotifyNotification *SpkUiMessage::_notify = nullptr; // Initialize statics
|
||||
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
|
||||
{
|
||||
Q_UNUSED(s);
|
||||
SpkUi::Popup->Show(s);
|
||||
}
|
||||
|
||||
void SpkUiMessage::SetDesktopNotifyTimeout(int ms)
|
||||
|
@ -1,4 +1,5 @@
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <QDebug>
|
||||
#include "spkutils.h"
|
||||
|
||||
@ -14,7 +15,8 @@ void SpkUtils::VerifySingleRequest(QPointer<QNetworkReply> aReply)
|
||||
QString SpkUtils::GetDistroName()
|
||||
{
|
||||
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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user