File: dialogexample.cpp

package info (click to toggle)
dtkwidget 5.7.12-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 36,540 kB
  • sloc: cpp: 63,257; ansic: 132; python: 88; sh: 42; makefile: 13
file content (184 lines) | stat: -rw-r--r-- 6,152 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
// SPDX-FileCopyrightText: 2020 - 2022 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: LGPL-3.0-or-later

#include <QHBoxLayout>
#include <QVBoxLayout>

#include <DLabel>
#include <DDialog>
#include <DPushButton>
#include <DPasswordEdit>
#include <DMessageManager>
#include <DFileChooserEdit>
#include <DFloatingMessage>

#include "dialogexample.h"

DWIDGET_USE_NAMESPACE

DialogExampleWindow::DialogExampleWindow(QWidget *parent)
    : PageWindowInterface(parent)
{
    addExampleWindow(new DDialogExample(this));
    addExampleWindow(new DFileDialogExample(this));
    addExampleWindow(new DMessageManagerExample(this));
}

DDialogExample::DDialogExample(QWidget *parent)
    : ExampleWindowInterface(parent)
{
    QLabel *label1 = new QLabel;
    QLabel *label2 = new QLabel;

    label1->setFixedSize(381, 181);
    label1->setScaledContents(true);
    label2->setFixedSize(381, 160);
    label2->setScaledContents(true);
    label1->setPixmap(QPixmap(":/images/example/DDialog_1.png"));
    label2->setPixmap(QPixmap(":/images/example/DDialog_2.png"));

    DLabel *label = new DLabel;
    QVBoxLayout *mainlayout = new QVBoxLayout(this);
    DPushButton *btn = new DPushButton("开始还原");
    mainlayout->setContentsMargins(0,0,0,0);
    mainlayout->setSpacing(0);

    label->setPixmap(QPixmap(":/images/example/DDialog.png"));
    label->setFixedSize(550, 426);
    label->setScaledContents(true);

    mainlayout->addWidget(btn, 0, Qt::AlignCenter);
    mainlayout->addWidget(label1, 0, Qt::AlignCenter);
    mainlayout->addWidget(label2, 0, Qt::AlignCenter);
    mainlayout->addSpacing(60);
    mainlayout->addWidget(label, 0, Qt::AlignCenter);
    mainlayout->addSpacing(70);

    connect(btn, &DPushButton::clicked, this, [ = ] {
        DDialog dialog;
        dialog.setIcon(style()->standardIcon(QStyle::SP_MessageBoxWarning));
        dialog.setTitle("还原当前系统需要管理员权限");
        dialog.addContent(new DPasswordEdit);
        dialog.addButton("取消");
        dialog.addButton("授权", false, DDialog::ButtonRecommend);
        dialog.exec();
    });

}

QString DDialogExample::getTitleName() const
{
    return "DDialog";
}

QString DDialogExample::getDescriptionInfo() const
{
    return "用于需要用户处理事务,又不希望跳转\n"
           "页面以致打断工作流程时。";
}

int DDialogExample::getFixedHeight() const
{
    return 967;
}

DFileDialogExample::DFileDialogExample(QWidget *parent)
    : ExampleWindowInterface(parent)
{
    QLabel *label1 = new QLabel;
    QLabel *label2 = new QLabel;
    DLabel *label3 = new DLabel;
    DFileChooserEdit *dialog = new DFileChooserEdit;
    QVBoxLayout *mainLayout= new QVBoxLayout(this);

    mainLayout->setContentsMargins(0, 0, 0, 0);
    mainLayout->setSpacing(0);
    label1->setFixedSize(550, 334);
    label2->setFixedSize(550, 334);
    label3->setFixedSize(550, 387);
    label1->setScaledContents(true);
    label2->setScaledContents(true);
    label3->setScaledContents(true);
    label1->setPixmap(QPixmap(":/images/example/DFileDialog_1.png"));
    label2->setPixmap(QPixmap(":/images/example/DFileDialog_2.png"));
    label3->setPixmap(QPixmap(":/images/example/DFileDialog.png"));

    mainLayout->addWidget(dialog, 0, Qt::AlignCenter);
    mainLayout->addWidget(label1, 0, Qt::AlignCenter);
    mainLayout->addWidget(label2, 0, Qt::AlignCenter);
    mainLayout->addWidget(label3, 0, Qt::AlignCenter);
}

QString DFileDialogExample::getTitleName() const
{
    return "DFileDialog";
}

QString DFileDialogExample::getDescriptionInfo() const
{
    return "有需要调用打开文件,保存文件的地\n"
           "方。底部工具栏上面的选项和内容多少\n"
           "会根据应用自身的需要显示不同的内容。\n";
}

int DFileDialogExample::getFixedHeight() const
{
    return 1256;
}

DMessageManagerExample::DMessageManagerExample(QWidget *parent)
    : ExampleWindowInterface(parent)
{
    QVBoxLayout *mainlayout = new QVBoxLayout(this);
    QLabel *label = new QLabel;
    QVBoxLayout *labelLayout = new QVBoxLayout(label);
    DPushButton *btn1 = new DPushButton("点击按钮呼出自动消失的提示信息");
    DPushButton *btn2 = new DPushButton("点击按钮呼出不会自动消失的提示信息");

    connect(btn1, &DPushButton::clicked, this, [ = ] {
        DMessageManager::instance()->sendMessage(this, style()->standardIcon(QStyle::SP_MessageBoxWarning),
                                                 "成功添加到\"校园民谣\"");
    });
    connect(btn2, &DPushButton::clicked, this, [ = ] {
        DFloatingMessage *message = new DFloatingMessage(DFloatingMessage::ResidentType);
        message->setIcon(style()->standardIcon(QStyle::SP_MessageBoxWarning));
        message->setMessage("磁盘中的原文件已被修改,是否重新输入?");
        message->setWidget(new DPushButton("重新载入"));
        labelLayout->addWidget(message, 0, Qt::AlignCenter | Qt::AlignBottom);
        DMessageManager::instance()->sendMessage(this, message);
    });

    label->setScaledContents(true);
    label->setFixedSize(550, 309);
    label->setPixmap(QPixmap(":/images/example/dock_notice.png"));
    labelLayout->addStretch(10);

    mainlayout->setContentsMargins(0, 0, 0, 0);
    mainlayout->setSpacing(0);
    mainlayout->addWidget(btn1, 0, Qt::AlignCenter);
    mainlayout->addWidget(btn2, 0, Qt::AlignCenter);
    mainlayout->addWidget(label, 0, Qt::AlignCenter);
}

QString DMessageManagerExample::getTitleName() const
{
    return "DMessageManager";
}

QString DMessageManagerExample::getDescriptionInfo() const
{
    return "类型1\n"
           "这类应用内提醒是不需要用户进行操作\n"
           "的,过几秒钟后会自主消失,仅仅是向\n"
           "用户告知一些信息,比如什么成功或失\n"
           "败了,有什么需要注意的之类的。\n"
           "类型2\n"
           "这类应用内提醒需要用户的操作,在用\n"
           "户操作之前不会自主消失\n";
}

int DMessageManagerExample::getFixedHeight() const
{
    return 588;
}