fix notify

This commit is contained in:
Andrei Yankovich 2019-08-19 18:02:40 +03:00
parent 0469b27a11
commit 6fd2976004
8 changed files with 86 additions and 23 deletions

View File

@ -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 \

View File

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

View File

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

View File

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

View File

@ -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 &notify);
NotificationData notify() const;
void setNotify(const NotificationData &notify);
static NotificationService* getService();
const QStringList& history() const;
const QList<NotificationData> & history() const;
signals:
void notifyChanged(QString notify);
void notifyChanged();
};

View File

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

View File

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

View File

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