添加商店内弹出窗消息

使用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

View File

@@ -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
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();
}
}

View File

@@ -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())