diff --git a/src/AlertDialog.cpp b/src/AlertDialog.cpp new file mode 100644 index 0000000..749aa4e --- /dev/null +++ b/src/AlertDialog.cpp @@ -0,0 +1,30 @@ +// +// Created by Krad on 2021/12/8. +// + +#include +#include +#include "AlertDialog.h" + +AlertDialog::AlertDialog(QWidget *parent, Qt::WindowFlags f) : GUIFormBaseDialog(parent, f) { + this->setFixedHeight(180); + this->setFixedWidth(400); + QVBoxLayout* layout = new QVBoxLayout(formWidget); + layout->setSpacing(10); + // add title + QLabel* lbl_title = new QLabel(this); + lbl_title->setAlignment(Qt::AlignCenter); + lbl_title->setText(tr("Warning")); + lbl_title->setObjectName("title"); + layout->addWidget(lbl_title); + lbl_msg = new QLabel(this); + layout->addWidget(lbl_msg); +} + +AlertDialog::~AlertDialog() { + +} + +void AlertDialog::setAlertMessage(const QString &msg) { + this->lbl_msg->setText(msg); +} diff --git a/src/AlertDialog.h b/src/AlertDialog.h new file mode 100644 index 0000000..2cb2574 --- /dev/null +++ b/src/AlertDialog.h @@ -0,0 +1,23 @@ +// +// Created by Krad on 2021/12/8. +// + +#ifndef GUI_ALERTDIALOG_H +#define GUI_ALERTDIALOG_H +class QLabel; +#include "GUIFormBaseDialog.h" +class AlertDialog :public GUIFormBaseDialog{ + Q_OBJECT +public: + explicit AlertDialog(QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags()); + ~AlertDialog(); + void setAlertMessage(const QString& msg); +protected: + bool updateReferenceData() override{return true;} + +private: + QLabel* lbl_msg; +}; + + +#endif //GUI_ALERTDIALOG_H diff --git a/src/GUIFormBaseDialog.cpp b/src/GUIFormBaseDialog.cpp index dedbafa..f0a173e 100644 --- a/src/GUIFormBaseDialog.cpp +++ b/src/GUIFormBaseDialog.cpp @@ -20,9 +20,9 @@ GUIFormBaseDialog::GUIFormBaseDialog(QWidget *parent, Qt::WindowFlags f) : QDial QWidget* btnWidget= new QWidget(this); vLayout->addWidget(btnWidget); QHBoxLayout* hLayout = new QHBoxLayout(btnWidget); - QPushButton* btnOk= new QPushButton(btnWidget); + btnOk= new QPushButton(btnWidget); btnOk->setText("OK"); - QPushButton* btnCancel = new QPushButton(btnWidget); + btnCancel = new QPushButton(btnWidget); btnCancel->setText("Cancel"); hLayout->addWidget(btnOk); hLayout->addWidget(btnCancel); @@ -39,3 +39,26 @@ GUIFormBaseDialog::GUIFormBaseDialog(QWidget *parent, Qt::WindowFlags f) : QDial GUIFormBaseDialog::~GUIFormBaseDialog() { } + +void GUIFormBaseDialog::setButtonMode(DialogButtonMode mode) { + switch (mode) { + case OkOnly: + { + btnOk->setVisible(true); + btnCancel->setVisible(false); + return; + } + case OkAndCancel: + { + btnOk->setVisible(true); + btnCancel->setVisible(true); + return; + } + case None: + default: + { + btnOk->setVisible(false); + btnCancel->setVisible(false); + } + } +} diff --git a/src/GUIFormBaseDialog.h b/src/GUIFormBaseDialog.h index 67dbab0..a57a7f2 100644 --- a/src/GUIFormBaseDialog.h +++ b/src/GUIFormBaseDialog.h @@ -4,19 +4,24 @@ #ifndef GUI_GUIFORMBASEDIALOG_H #define GUI_GUIFORMBASEDIALOG_H - +enum DialogButtonMode +{ + None,OkOnly,OkAndCancel +}; #include class GUIFormBaseDialog: public QDialog { Q_OBJECT public: explicit GUIFormBaseDialog(QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags()); ~GUIFormBaseDialog(); - + void setButtonMode(DialogButtonMode mode); protected: virtual bool updateReferenceData(){ return false; }; QWidget* formWidget = nullptr; + QPushButton* btnCancel = nullptr; + QPushButton* btnOk = nullptr; };