82 lines
2.0 KiB
C++
82 lines
2.0 KiB
C++
#ifndef OVERLAYDIALOGSWIDGET_H
|
||
#define OVERLAYDIALOGSWIDGET_H
|
||
|
||
#include <QWidget>
|
||
#include <QVBoxLayout>
|
||
#include <QHBoxLayout>
|
||
#include <QLabel>
|
||
#include <QPushButton>
|
||
#include <QLineEdit>
|
||
#include <QGraphicsOpacityEffect>
|
||
#include <QPropertyAnimation>
|
||
#include <functional>
|
||
|
||
/**
|
||
* @class OverlayDialog
|
||
* @brief 浮层对话框基类
|
||
*
|
||
* 用于IoT设备的模态浮层对话框,替代QMessageBox和QInputDialog
|
||
*/
|
||
class OverlayDialog : public QWidget
|
||
{
|
||
Q_OBJECT
|
||
|
||
public:
|
||
enum DialogType
|
||
{
|
||
Information,
|
||
Warning,
|
||
Question,
|
||
Input
|
||
};
|
||
|
||
explicit OverlayDialog(QWidget *parent = nullptr);
|
||
|
||
// 静态便捷方法
|
||
static void information(QWidget *parent, const QString &title, const QString &message);
|
||
static void warning(QWidget *parent, const QString &title, const QString &message);
|
||
static void question(QWidget *parent, const QString &title, const QString &message,
|
||
std::function<void(bool)> callback);
|
||
static void input(QWidget *parent, const QString &title, const QString &prompt,
|
||
std::function<void(bool, const QString &)> callback,
|
||
const QString &defaultText = "");
|
||
|
||
void setTitle(const QString &title);
|
||
void setMessage(const QString &message);
|
||
void setDialogType(DialogType type);
|
||
void setInputMode(bool inputMode, const QString &placeholder = "");
|
||
void setCallback(std::function<void(bool, const QString &)> callback);
|
||
|
||
void showDialog();
|
||
void hideDialog();
|
||
|
||
signals:
|
||
void accepted(const QString &inputText = QString());
|
||
void rejected();
|
||
|
||
private slots:
|
||
void onAcceptClicked();
|
||
void onRejectClicked();
|
||
|
||
private:
|
||
void setupUI();
|
||
void updateTypeIcon();
|
||
void animateShow();
|
||
void animateHide();
|
||
|
||
QWidget *m_backgroundOverlay;
|
||
QWidget *m_dialogContainer;
|
||
QLabel *m_iconLabel;
|
||
QLabel *m_titleLabel;
|
||
QLabel *m_messageLabel;
|
||
QLineEdit *m_inputEdit;
|
||
QPushButton *m_acceptBtn;
|
||
QPushButton *m_rejectBtn;
|
||
|
||
DialogType m_type;
|
||
bool m_inputMode;
|
||
std::function<void(bool, const QString &)> m_callback;
|
||
};
|
||
|
||
#endif // OVERLAYDIALOGSWIDGET_H
|