Alert Dialog
This commit is contained in:
30
src/AlertDialog.cpp
Normal file
30
src/AlertDialog.cpp
Normal 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
23
src/AlertDialog.h
Normal 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
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,19 +4,24 @@
|
||||
|
||||
#ifndef GUI_GUIFORMBASEDIALOG_H
|
||||
#define GUI_GUIFORMBASEDIALOG_H
|
||||
|
||||
enum DialogButtonMode
|
||||
{
|
||||
None,OkOnly,OkAndCancel
|
||||
};
|
||||
#include <QDialog>
|
||||
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;
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user