Alert Dialog

This commit is contained in:
Krad
2021-12-08 17:49:51 +08:00
parent 35570a7cb4
commit b40939ec6e
4 changed files with 85 additions and 4 deletions

30
src/AlertDialog.cpp Normal file
View File

@@ -0,0 +1,30 @@
//
// Created by Krad on 2021/12/8.
//
#include <QtWidgets/QVBoxLayout>
#include <QtWidgets/QLabel>
#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);
}

23
src/AlertDialog.h Normal file
View File

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

View File

@@ -20,9 +20,9 @@ GUIFormBaseDialog::GUIFormBaseDialog(QWidget *parent, Qt::WindowFlags f) : QDial
QWidget* btnWidget= new QWidget(this); QWidget* btnWidget= new QWidget(this);
vLayout->addWidget(btnWidget); vLayout->addWidget(btnWidget);
QHBoxLayout* hLayout = new QHBoxLayout(btnWidget); QHBoxLayout* hLayout = new QHBoxLayout(btnWidget);
QPushButton* btnOk= new QPushButton(btnWidget); btnOk= new QPushButton(btnWidget);
btnOk->setText("OK"); btnOk->setText("OK");
QPushButton* btnCancel = new QPushButton(btnWidget); btnCancel = new QPushButton(btnWidget);
btnCancel->setText("Cancel"); btnCancel->setText("Cancel");
hLayout->addWidget(btnOk); hLayout->addWidget(btnOk);
hLayout->addWidget(btnCancel); hLayout->addWidget(btnCancel);
@@ -39,3 +39,26 @@ GUIFormBaseDialog::GUIFormBaseDialog(QWidget *parent, Qt::WindowFlags f) : QDial
GUIFormBaseDialog::~GUIFormBaseDialog() { 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);
}
}
}

View File

@@ -4,19 +4,24 @@
#ifndef GUI_GUIFORMBASEDIALOG_H #ifndef GUI_GUIFORMBASEDIALOG_H
#define GUI_GUIFORMBASEDIALOG_H #define GUI_GUIFORMBASEDIALOG_H
enum DialogButtonMode
{
None,OkOnly,OkAndCancel
};
#include <QDialog> #include <QDialog>
class GUIFormBaseDialog: public QDialog { class GUIFormBaseDialog: public QDialog {
Q_OBJECT Q_OBJECT
public: public:
explicit GUIFormBaseDialog(QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags()); explicit GUIFormBaseDialog(QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags());
~GUIFormBaseDialog(); ~GUIFormBaseDialog();
void setButtonMode(DialogButtonMode mode);
protected: protected:
virtual bool updateReferenceData(){ virtual bool updateReferenceData(){
return false; return false;
}; };
QWidget* formWidget = nullptr; QWidget* formWidget = nullptr;
QPushButton* btnCancel = nullptr;
QPushButton* btnOk = nullptr;
}; };