added support of the questions

This commit is contained in:
Andrei Yankovich 2021-01-18 23:20:03 +03:00
parent 6cc502f101
commit 0964928742
9 changed files with 102 additions and 26 deletions

View File

@ -58,21 +58,17 @@ Dialog {
} }
function autoclosePause() { function autoclosePause() {
if (autoClose)
progressAnimation.pause(); progressAnimation.pause();
} }
function autocloseResume() { function autocloseResume() {
progressAnimation.resume();
}
onClosed: {
if (autoClose) if (autoClose)
opacity = 0; progressAnimation.resume();
} }
closePolicy: (!clickClose || autoClose)? Popup.NoAutoClose: Popup.CloseOnReleaseOutside closePolicy: (!clickClose || autoClose)? Popup.NoAutoClose: Popup.CloseOnReleaseOutside
onRejected: close()
footer: ProgressBar { footer: ProgressBar {
id: progress; id: progress;
@ -81,7 +77,6 @@ Dialog {
visible: autoClose visible: autoClose
value: 0; value: 0;
NumberAnimation on value { NumberAnimation on value {
id: progressAnimation id: progressAnimation

View File

@ -5,9 +5,9 @@
* of this license document, but changing it is not allowed. * of this license document, but changing it is not allowed.
*/ */
import QtQuick 2.11 import QtQuick 2.15
import QtQuick.Controls 2.3 import QtQuick.Controls 2.5
import QtQuick.Controls.Material 2.0 import QtQuick.Controls.Material 2.15
import QtQuick.Layouts 1.3 import QtQuick.Layouts 1.3
BasePopUp { BasePopUp {
@ -110,6 +110,4 @@ BasePopUp {
text: titleText text: titleText
horizontalAlignment: Text.AlignHCenter horizontalAlignment: Text.AlignHCenter
} }
} }

View File

@ -5,15 +5,17 @@
* of this license document, but changing it is not allowed. * of this license document, but changing it is not allowed.
*/ */
import QtQuick 2.12 import QtQuick 2.15
import QtQuick.Controls.Material 2.12 import QtQuick.Controls.Material 2.15
import QtQuick.Controls 2.12 import QtQuick.Controls 2.15
import QtQuick.Layouts 1.3 import QtQuick.Layouts 1.3
import QtGraphicalEffects 1.12 import QtGraphicalEffects 1.15
Item { Item {
readonly property var model: notificationService; readonly property var model: notificationService;
readonly property var msg: model.notify readonly property var msg: model.notify
readonly property var qst: model.question
readonly property var history: model.history readonly property var history: model.history
Metrix { Metrix {
@ -30,14 +32,46 @@ Item {
x: parent.width - width - margin; x: parent.width - width - margin;
y: margin; y: margin;
width: 5 * metrix.pt; width: 4 * metrix.pt;
height: width * 0.5 height: width * 0.5
} }
YesNoQuestion {
id: questionMsgBox
titleText : qst.title;
text: (qst)? qst.text: "";
img: (qst)? qst.img: "";
type: 0;
x: parent.width / 2 - width / 2;
y: parent.height / 2 - height / 2;
width: 6 * metrix.pt;
height: width * 0.4
onAccepted: {
if (model) {
model.questionComplete(true, qst.type)
}
}
onRejected: {
if (model) {
model.questionComplete(false, qst.type)
}
}
}
onMsgChanged: { onMsgChanged: {
if (msg.isValid()) { if (msg.isValid()) {
notyfyView._show(); notyfyView._show();
} }
} }
onQstChanged: {
if (qst.isValid()) {
questionMsgBox._show();
}
}
} }

View File

@ -0,0 +1,15 @@
import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Controls.Material 2.15
import QtQuick.Layouts 1.15
NotificationForm {
id: questionDialog
autoClose: false
clickClose: false
footer: DialogButtonBox {
standardButtons: Dialog.Yes | Dialog.No;
}
}

View File

@ -5,5 +5,6 @@
<file>NotifyModule/NotificationForm.qml</file> <file>NotifyModule/NotificationForm.qml</file>
<file>NotifyModule/BasePopUp.qml</file> <file>NotifyModule/BasePopUp.qml</file>
<file>NotifyModule/Metrix.qml</file> <file>NotifyModule/Metrix.qml</file>
<file>NotifyModule/YesNoQuestion.qml</file>
</qresource> </qresource>
</RCC> </RCC>

View File

@ -10,7 +10,7 @@ namespace QmlNotificationService {
NotificationData::NotificationData(const QString &title, NotificationData::NotificationData(const QString &title,
const QString &text, const QString &text,
const QString &img, Type type) { const QString &img, int type) {
_text = text; _text = text;
_title = title; _title = title;

View File

@ -31,7 +31,7 @@ public:
explicit NotificationData(const QString& title = "", explicit NotificationData(const QString& title = "",
const QString& text = "", const QString& text = "",
const QString& img = "", const QString& img = "",
Type type = Type::Normal); int type = Type::Normal);
Q_INVOKABLE QString text() const; Q_INVOKABLE QString text() const;
Q_INVOKABLE QString img() const; Q_INVOKABLE QString img() const;

View File

@ -18,6 +18,10 @@ NotificationData NotificationService::notify() const {
return _notify; return _notify;
} }
NotificationData NotificationService::question() const {
return _question;
}
void NotificationService::setNotify(const NotificationData& notify) { void NotificationService::setNotify(const NotificationData& notify) {
if (_notify != notify) if (_notify != notify)
_history.push_back(_notify); _history.push_back(_notify);
@ -27,6 +31,16 @@ void NotificationService::setNotify(const NotificationData& notify) {
emit notifyChanged(); emit notifyChanged();
} }
void NotificationService::setQuestion(const NotificationData &question) {
_question = question;
emit questionChanged();
}
void NotificationService::questionComplete(bool accepted, int code) {
emit questionCompleted(accepted, code);
}
void NotificationService::setNotify(const QString &title, void NotificationService::setNotify(const QString &title,
const QString &text, const QString &text,
const QString &img, const QString &img,
@ -36,6 +50,10 @@ void NotificationService::setNotify(const QString &title,
static_cast<NotificationData::Type>(type))); static_cast<NotificationData::Type>(type)));
} }
void NotificationService::setQuestion(const QString &title, const QString &text, const QString &img, int code) {
setQuestion(NotificationData(title, text, img, code));
}
NotificationService *NotificationService::getService() { NotificationService *NotificationService::getService() {
static auto service = new NotificationService; static auto service = new NotificationService;
return service; return service;

View File

@ -15,20 +15,17 @@ class NOTIFYSERVICESHARED_EXPORT NotificationService: public QObject
Q_OBJECT Q_OBJECT
Q_PROPERTY(NotificationData notify READ notify NOTIFY notifyChanged) Q_PROPERTY(NotificationData notify READ notify NOTIFY notifyChanged)
Q_PROPERTY(NotificationData question READ question NOTIFY questionChanged)
Q_PROPERTY(QList<NotificationData> history READ history NOTIFY notifyChanged) Q_PROPERTY(QList<NotificationData> history READ history NOTIFY notifyChanged)
private:
explicit NotificationService(QObject *ptr = nullptr);
NotificationData _notify;
QList<NotificationData> _history;
public: public:
/** /**
* @brief notify * @brief notify
* @return notyfyData for qml * @return notyfyData for qml
*/ */
NotificationData notify() const; NotificationData notify() const;
NotificationData question() const;
/** /**
* @brief setNotify - add new message for application * @brief setNotify - add new message for application
@ -36,11 +33,20 @@ public:
*/ */
void setNotify(const NotificationData &notify); void setNotify(const NotificationData &notify);
void setQuestion(const NotificationData& question);
Q_INVOKABLE void questionComplete(bool accepted, int code = 0);
Q_INVOKABLE void setNotify(const QString& title = "", Q_INVOKABLE void setNotify(const QString& title = "",
const QString& text = "", const QString& text = "",
const QString& img = "", const QString& img = "",
int type = NotificationData::Normal); int type = NotificationData::Normal);
Q_INVOKABLE void setQuestion(const QString& title = "",
const QString& text = "",
const QString& img = "",
int code = 0);
/** /**
* @brief getService * @brief getService
* @return pointer t oservice * @return pointer t oservice
@ -55,6 +61,15 @@ public:
signals: signals:
void notifyChanged(); void notifyChanged();
void questionChanged();
void questionCompleted(bool accepted, int questionCode);
private:
explicit NotificationService(QObject *ptr = nullptr);
NotificationData _question;
NotificationData _notify;
QList<NotificationData> _history;
}; };
} }