diff --git a/NotifyModule/BasePopUp.qml b/NotifyModule/BasePopUp.qml index 6505b8b..de2ccd7 100644 --- a/NotifyModule/BasePopUp.qml +++ b/NotifyModule/BasePopUp.qml @@ -58,21 +58,17 @@ Dialog { } function autoclosePause() { - progressAnimation.pause(); + if (autoClose) + progressAnimation.pause(); } function autocloseResume() { - progressAnimation.resume(); - } - - onClosed: { if (autoClose) - opacity = 0; + progressAnimation.resume(); } closePolicy: (!clickClose || autoClose)? Popup.NoAutoClose: Popup.CloseOnReleaseOutside - onRejected: close() footer: ProgressBar { id: progress; @@ -81,7 +77,6 @@ Dialog { visible: autoClose value: 0; - NumberAnimation on value { id: progressAnimation diff --git a/NotifyModule/NotificationForm.qml b/NotifyModule/NotificationForm.qml index 8f58da0..430088d 100644 --- a/NotifyModule/NotificationForm.qml +++ b/NotifyModule/NotificationForm.qml @@ -5,9 +5,9 @@ * of this license document, but changing it is not allowed. */ -import QtQuick 2.11 -import QtQuick.Controls 2.3 -import QtQuick.Controls.Material 2.0 +import QtQuick 2.15 +import QtQuick.Controls 2.5 +import QtQuick.Controls.Material 2.15 import QtQuick.Layouts 1.3 BasePopUp { @@ -110,6 +110,4 @@ BasePopUp { text: titleText horizontalAlignment: Text.AlignHCenter } - - } diff --git a/NotifyModule/NotificationServiceView.qml b/NotifyModule/NotificationServiceView.qml index 90fe5b4..f937319 100644 --- a/NotifyModule/NotificationServiceView.qml +++ b/NotifyModule/NotificationServiceView.qml @@ -5,15 +5,17 @@ * of this license document, but changing it is not allowed. */ -import QtQuick 2.12 -import QtQuick.Controls.Material 2.12 -import QtQuick.Controls 2.12 +import QtQuick 2.15 +import QtQuick.Controls.Material 2.15 +import QtQuick.Controls 2.15 import QtQuick.Layouts 1.3 -import QtGraphicalEffects 1.12 +import QtGraphicalEffects 1.15 Item { readonly property var model: notificationService; readonly property var msg: model.notify + readonly property var qst: model.question + readonly property var history: model.history Metrix { @@ -30,14 +32,46 @@ Item { x: parent.width - width - margin; y: margin; - width: 5 * metrix.pt; + width: 4 * metrix.pt; 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: { if (msg.isValid()) { notyfyView._show(); } } + + onQstChanged: { + if (qst.isValid()) { + questionMsgBox._show(); + } + } } diff --git a/NotifyModule/YesNoQuestion.qml b/NotifyModule/YesNoQuestion.qml new file mode 100644 index 0000000..7adf558 --- /dev/null +++ b/NotifyModule/YesNoQuestion.qml @@ -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; + } +} diff --git a/QML.qrc b/QML.qrc index 2eaf24b..b988579 100644 --- a/QML.qrc +++ b/QML.qrc @@ -5,5 +5,6 @@ NotifyModule/NotificationForm.qml NotifyModule/BasePopUp.qml NotifyModule/Metrix.qml + NotifyModule/YesNoQuestion.qml diff --git a/notificationdata.cpp b/notificationdata.cpp index e8590df..703409d 100644 --- a/notificationdata.cpp +++ b/notificationdata.cpp @@ -10,7 +10,7 @@ namespace QmlNotificationService { NotificationData::NotificationData(const QString &title, const QString &text, - const QString &img, Type type) { + const QString &img, int type) { _text = text; _title = title; diff --git a/notificationdata.h b/notificationdata.h index c7e1d91..2bfe323 100644 --- a/notificationdata.h +++ b/notificationdata.h @@ -31,7 +31,7 @@ public: explicit NotificationData(const QString& title = "", const QString& text = "", const QString& img = "", - Type type = Type::Normal); + int type = Type::Normal); Q_INVOKABLE QString text() const; Q_INVOKABLE QString img() const; diff --git a/notificationservice.cpp b/notificationservice.cpp index e80d555..cfdb5e8 100644 --- a/notificationservice.cpp +++ b/notificationservice.cpp @@ -18,6 +18,10 @@ NotificationData NotificationService::notify() const { return _notify; } +NotificationData NotificationService::question() const { + return _question; +} + void NotificationService::setNotify(const NotificationData& notify) { if (_notify != notify) _history.push_back(_notify); @@ -27,6 +31,16 @@ void NotificationService::setNotify(const NotificationData& notify) { 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, const QString &text, const QString &img, @@ -36,6 +50,10 @@ void NotificationService::setNotify(const QString &title, static_cast(type))); } +void NotificationService::setQuestion(const QString &title, const QString &text, const QString &img, int code) { + setQuestion(NotificationData(title, text, img, code)); +} + NotificationService *NotificationService::getService() { static auto service = new NotificationService; return service; diff --git a/notificationservice.h b/notificationservice.h index b3e6bc1..615c8ed 100644 --- a/notificationservice.h +++ b/notificationservice.h @@ -15,20 +15,17 @@ class NOTIFYSERVICESHARED_EXPORT NotificationService: public QObject Q_OBJECT Q_PROPERTY(NotificationData notify READ notify NOTIFY notifyChanged) + Q_PROPERTY(NotificationData question READ question NOTIFY questionChanged) + Q_PROPERTY(QList history READ history NOTIFY notifyChanged) -private: - explicit NotificationService(QObject *ptr = nullptr); - - NotificationData _notify; - QList _history; - public: /** * @brief notify * @return notyfyData for qml */ NotificationData notify() const; + NotificationData question() const; /** * @brief setNotify - add new message for application @@ -36,11 +33,20 @@ public: */ void setNotify(const NotificationData ¬ify); + void setQuestion(const NotificationData& question); + Q_INVOKABLE void questionComplete(bool accepted, int code = 0); + Q_INVOKABLE void setNotify(const QString& title = "", const QString& text = "", const QString& img = "", int type = NotificationData::Normal); + Q_INVOKABLE void setQuestion(const QString& title = "", + const QString& text = "", + const QString& img = "", + int code = 0); + + /** * @brief getService * @return pointer t oservice @@ -55,6 +61,15 @@ public: signals: void notifyChanged(); + void questionChanged(); + void questionCompleted(bool accepted, int questionCode); + +private: + explicit NotificationService(QObject *ptr = nullptr); + + NotificationData _question; + NotificationData _notify; + QList _history; }; }