DtkWidget
DTK Widget module
载入中...
搜索中...
未找到
ddialog.h
浏览该文件的文档.
1// SPDX-FileCopyrightText: 2015 - 2023 UnionTech Software Technology Co., Ltd.
2//
3// SPDX-License-Identifier: LGPL-3.0-or-later
4
5#ifndef DDIALOG_H
6#define DDIALOG_H
7
8#include <QIcon>
9
10#include <DAbstractDialog>
11
12class QAbstractButton;
13class QButtonGroup;
14class QLabel;
15class QCloseEvent;
16class QVBoxLayout;
17
18DWIDGET_BEGIN_NAMESPACE
19
20class DDialogPrivate;
22{
23 Q_OBJECT
24
25 Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged)
26 Q_PROPERTY(QString message READ message WRITE setMessage NOTIFY messageChanged)
27 Q_PROPERTY(QIcon icon READ icon WRITE setIcon)
28 Q_PROPERTY(Qt::TextFormat textFormat READ textFormat WRITE setTextFormat NOTIFY textFormatChanged)
29 Q_PROPERTY(bool onButtonClickedClose READ onButtonClickedClose WRITE setOnButtonClickedClose)
30 Q_PROPERTY(bool closeButtonVisible READ closeButtonVisible WRITE setCloseButtonVisible)
31
32public:
34 ButtonNormal,
35 ButtonWarning,
36 ButtonRecommend
37 };
38
39 explicit DDialog(QWidget *parent = nullptr);
40 explicit DDialog(const QString &title, const QString& message, QWidget *parent = 0);
41
42 int getButtonIndexByText(const QString &text) const;
43 int buttonCount() const;
44 int contentCount() const;
45 QList<QAbstractButton*> getButtons() const;
46 QList<QWidget*> getContents() const;
47 QAbstractButton* getButton(int index) const;
48 QWidget* getContent(int index) const;
49 QString title() const;
50 QString message() const;
51 QIcon icon() const;
52#if DTK_VERSION < DTK_VERSION_CHECK(6, 0, 0, 0)
53 D_DECL_DEPRECATED QPixmap iconPixmap() const;
54#endif
55 Qt::TextFormat textFormat() const;
56 bool onButtonClickedClose() const;
57
58 void setContentLayoutContentsMargins(const QMargins &margins);
59 QMargins contentLayoutContentsMargins() const;
60
61 bool closeButtonVisible() const;
62
63Q_SIGNALS:
64 void aboutToClose();
65 void closed();
66 void buttonClicked(int index, const QString &text);
67 void titleChanged(QString title);
68 void messageChanged(QString massage);
69 void textFormatChanged(Qt::TextFormat textFormat);
70 void sizeChanged(QSize size);
71 void visibleChanged(bool visible);
72
73public Q_SLOTS:
74 int addButton(const QString &text, bool isDefault = false, ButtonType type = ButtonNormal);
75 int addButtons(const QStringList &text);
76 void insertButton(int index, const QString &text, bool isDefault = false, ButtonType type = ButtonNormal);
77 void insertButton(int index, QAbstractButton* button, bool isDefault = false);
78 void insertButtons(int index, const QStringList &text);
79 void removeButton(int index);
80 void removeButton(QAbstractButton *button);
81 void removeButtonByText(const QString &text);
82 void clearButtons();
83 bool setDefaultButton(int index);
84 bool setDefaultButton(const QString &str);
85 void setDefaultButton(QAbstractButton *button);
86 void addContent(QWidget *widget, Qt::Alignment alignment = {});
87 void insertContent(int index, QWidget *widget, Qt::Alignment alignment = {});
88 void removeContent(QWidget *widget, bool isDelete = true);
89 void clearContents(bool isDelete = true);
90 void setSpacing(int spacing);
91 void addSpacing(int spacing);
92 void insertSpacing(int index, int spacing);
93 void clearSpacing();
94 void setButtonText(int index, const QString &text);
95 void setButtonIcon(int index, const QIcon &icon);
96 void setTitle(const QString &title);
97 void setWordWrapTitle(bool wordWrap);
98 void setMessage(const QString& message);
99 void setWordWrapMessage(bool wordWrap);
100 void setIcon(const QIcon &icon);
101#if DTK_VERSION < DTK_VERSION_CHECK(6, 0, 0, 0)
102 D_DECL_DEPRECATED void setIcon(const QIcon &icon, const QSize &expectedSize);
103 D_DECL_DEPRECATED void setIconPixmap(const QPixmap &iconPixmap);
104#endif
105 void setTextFormat(Qt::TextFormat textFormat);
106 void setOnButtonClickedClose(bool onButtonClickedClose);
107 void setCloseButtonVisible(bool closeButtonVisible);
108
109 int exec() Q_DECL_OVERRIDE;
110
111protected:
112 explicit DDialog(DDialogPrivate &dd, QWidget *parent = 0);
113
114 void showEvent(QShowEvent *event) Q_DECL_OVERRIDE;
115 void hideEvent(QHideEvent *event) Q_DECL_OVERRIDE;
116 void closeEvent(QCloseEvent *event) override;
117 void childEvent(QChildEvent *event) Q_DECL_OVERRIDE;
118 void resizeEvent(QResizeEvent *event) override;
119 void keyPressEvent(QKeyEvent *event) override;
120 bool eventFilter(QObject *watched, QEvent *event) override;
121 void changeEvent(QEvent *event) override;
122
123private:
124 D_DECLARE_PRIVATE(DDialog)
125
126 Q_PRIVATE_SLOT(d_func(), void _q_onButtonClicked())
127};
128
129DWIDGET_END_NAMESPACE
130
131#endif // DDIALOG_H
可以使用 DAbstractDialog 类创建符合 DDE 风格的对话框窗口.
Definition dabstractdialog.h:23
DDialog 旨在提供简要的讯问式对话框的快速实现。提供了包含标题,对话框内容,默认图标,用以添加按钮的布局和一个可以自由添加内容的内容布局。
Definition ddialog.h:22
ButtonType
表示按钮类型
Definition ddialog.h:33