mirror of
https://github.com/QuasarApp/Snake.git
synced 2025-04-26 17:54:42 +00:00
fix notify
This commit is contained in:
parent
0469b27a11
commit
6fd2976004
@ -16,6 +16,7 @@ SOURCES += \
|
||||
back-end/ProfileViewItems/mainclient.cpp \
|
||||
back-end/ProfileViewItems/mainmenumodel.cpp \
|
||||
back-end/ProfileViewItems/networkclient.cpp \
|
||||
back-end/ProfileViewItems/notificationdata.cpp \
|
||||
back-end/ProfileViewItems/notificationservice.cpp \
|
||||
back-end/ProfileViewItems/playerclientdata.cpp \
|
||||
back-end/ProfileViewItems/settingsviewmodel.cpp \
|
||||
@ -92,6 +93,7 @@ HEADERS += \
|
||||
back-end/ProfileViewItems/mainclient.h \
|
||||
back-end/ProfileViewItems/mainmenumodel.h \
|
||||
back-end/ProfileViewItems/networkclient.h \
|
||||
back-end/ProfileViewItems/notificationdata.h \
|
||||
back-end/ProfileViewItems/notificationservice.h \
|
||||
back-end/ProfileViewItems/playerclientdata.h \
|
||||
back-end/ProfileViewItems/settingsviewmodel.h \
|
||||
|
@ -0,0 +1,28 @@
|
||||
#include "notificationdata.h"
|
||||
|
||||
NotificationData::NotificationData(const QString &title,
|
||||
const QString &text,
|
||||
const QString &img) {
|
||||
|
||||
_text = text;
|
||||
_title = title;
|
||||
_img = img;
|
||||
}
|
||||
|
||||
QString NotificationData::text() const {
|
||||
return _text;
|
||||
}
|
||||
|
||||
QString NotificationData::img() const {
|
||||
return _img;
|
||||
}
|
||||
|
||||
QString NotificationData::title() const {
|
||||
return _title;
|
||||
}
|
||||
|
||||
bool NotificationData::operator ==(const NotificationData &righ) {
|
||||
return _title == righ._title &&
|
||||
_text == righ._text &&
|
||||
_img == righ._img;
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
#ifndef NOTIFICATIONDATA_H
|
||||
#define NOTIFICATIONDATA_H
|
||||
#include <QObject>
|
||||
|
||||
class NotificationData
|
||||
{
|
||||
Q_GADGET
|
||||
Q_PROPERTY(QString text READ text)
|
||||
Q_PROPERTY(QString img READ img)
|
||||
Q_PROPERTY(QString title READ title)
|
||||
|
||||
QString _text;
|
||||
QString _img;
|
||||
QString _title;
|
||||
|
||||
public:
|
||||
explicit NotificationData(const QString& title = "", const QString& text = "", const QString& img = "");
|
||||
Q_INVOKABLE QString text() const;
|
||||
Q_INVOKABLE QString img() const;
|
||||
Q_INVOKABLE QString title() const;
|
||||
bool operator ==(const NotificationData &righ);
|
||||
};
|
||||
|
||||
#endif // NOTIFICATIONDATA_H
|
@ -4,18 +4,18 @@ NotificationService::NotificationService(QObject * ptr): QObject (ptr) {
|
||||
|
||||
}
|
||||
|
||||
QString NotificationService::notify() const {
|
||||
NotificationData NotificationService::notify() const {
|
||||
return _notify;
|
||||
}
|
||||
|
||||
void NotificationService::setNotify(const QString& notify) {
|
||||
void NotificationService::setNotify(const NotificationData& notify) {
|
||||
if (_notify == notify)
|
||||
return;
|
||||
|
||||
_notify = notify;
|
||||
_history.push_back(_notify);
|
||||
|
||||
emit notifyChanged(_notify);
|
||||
emit notifyChanged();
|
||||
}
|
||||
|
||||
NotificationService *NotificationService::getService() {
|
||||
@ -23,6 +23,6 @@ NotificationService *NotificationService::getService() {
|
||||
return service;
|
||||
}
|
||||
|
||||
const QStringList &NotificationService::history() const {
|
||||
const QList<NotificationData> &NotificationService::history() const {
|
||||
return _history;
|
||||
}
|
||||
|
@ -1,30 +1,32 @@
|
||||
#ifndef NOTIFICATIONSERVICE_H
|
||||
#define NOTIFICATIONSERVICE_H
|
||||
|
||||
#include "notificationdata.h"
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class NotificationService: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY(QString notify READ notify NOTIFY notifyChanged)
|
||||
Q_PROPERTY(QStringList history READ history NOTIFY notifyChanged)
|
||||
Q_PROPERTY(NotificationData notify READ notify NOTIFY notifyChanged)
|
||||
Q_PROPERTY(QList<NotificationData> history READ history NOTIFY notifyChanged)
|
||||
|
||||
private:
|
||||
explicit NotificationService(QObject *ptr = nullptr);
|
||||
|
||||
QString _notify;
|
||||
QStringList _history;
|
||||
NotificationData _notify;
|
||||
QList<NotificationData> _history;
|
||||
|
||||
public:
|
||||
QString notify() const;
|
||||
void setNotify(const QString ¬ify);
|
||||
NotificationData notify() const;
|
||||
void setNotify(const NotificationData ¬ify);
|
||||
static NotificationService* getService();
|
||||
|
||||
const QStringList& history() const;
|
||||
const QList<NotificationData> & history() const;
|
||||
|
||||
signals:
|
||||
void notifyChanged(QString notify);
|
||||
void notifyChanged();
|
||||
};
|
||||
|
||||
|
||||
|
@ -31,6 +31,8 @@ bool ClientApp::init(QQmlApplicationEngine *engine) {
|
||||
qmlRegisterType <Diff> ();
|
||||
qmlRegisterType <MainMenuModel> ();
|
||||
qmlRegisterType <UserView> ();
|
||||
qRegisterMetaType<NotificationData>("NotificationData");
|
||||
qRegisterMetaType<QList<NotificationData>> ("QList<NotificationData>");
|
||||
|
||||
auto root = engine->rootContext();
|
||||
if (!root)
|
||||
|
@ -77,15 +77,16 @@ void Controller::update() {
|
||||
stopTimer();
|
||||
|
||||
if (!_showMenu) {
|
||||
setShowMenu(true);
|
||||
/** TO-DO **/
|
||||
// tr(" Next Lvl!!!"),
|
||||
// tr(QString(" You anblock next lvl (%0)" ).arg(lvl)),
|
||||
// "qrc:/texture/up");
|
||||
NotificationService::getService()->setNotify(
|
||||
QString(" You anblock next lvl (%0)" ).arg(lvl));
|
||||
|
||||
NotificationData notify(tr(" Next Lvl!!!"),
|
||||
tr(" You anblock next lvl (%0)" ).arg(lvl),
|
||||
"qrc:/texture/up");
|
||||
|
||||
NotificationService::getService()->setNotify(notify);
|
||||
}
|
||||
|
||||
nextLvl();
|
||||
|
||||
}
|
||||
|
||||
long_changed(static_cast<int>(world.getCurrentLong()));
|
||||
|
@ -6,15 +6,15 @@ import QtGraphicalEffects 1.12
|
||||
|
||||
Item {
|
||||
readonly property var model: notificationService;
|
||||
readonly property string msg: model.notify
|
||||
readonly property var msg: model.notify
|
||||
readonly property var history: model.history
|
||||
|
||||
|
||||
NotificationForm {
|
||||
id: notyfyView
|
||||
titleText : qsTr("new Message");
|
||||
text: msg;
|
||||
img: "";
|
||||
titleText : (msg)? msg.title: "";
|
||||
text: (msg)? msg.text: "";
|
||||
img: (msg)? msg.img: "";
|
||||
|
||||
x: parent.width - width - margin;
|
||||
y: margin;
|
||||
@ -22,4 +22,8 @@ Item {
|
||||
width: 40 * metrix.gamePt;
|
||||
height: width * 0.5
|
||||
}
|
||||
|
||||
onMsgChanged: {
|
||||
notyfyView._show();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user