Debian Codegraph @

kysdk-qtwidgets/test/testballontip/widget.cpp

raw
1 /*
2 *
3 *
4 * Copyright (C) 2023, KylinSoft Co., Ltd.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this library. If not, see <https://www.gnu.org/licenses/>.
18 *
19 * Authors: Zhen Sun <[email protected]>
20 *
21 */
22
23 #include "widget.h"
24 #include <QBoxLayout>
25 #include <QGraphicsDropShadowEffect>
26
27 Widget::Widget(QWidget *parent)
28 : KWidget(parent)
29 {
30 QVBoxLayout *vLayout = new QVBoxLayout();
31
32 QPushButton *button = new QPushButton(this);
33 button->setText("NothingTip");
34 QPushButton *button1 = new QPushButton(this);
35 button1->setText("NormalTip");
36 QPushButton *button2 = new QPushButton(this);
37 button2->setText("InfoTip");
38 QPushButton *button3 = new QPushButton(this);
39 button3->setText("WarningTip");
40 QPushButton *button4 = new QPushButton(this);
41 button4->setText("ErrorTip");
42 vLayout->addWidget(button);
43 vLayout->addWidget(button1);
44 vLayout->addWidget(button2);
45 vLayout->addWidget(button3);
46 vLayout->addWidget(button4);
47
48 // 提供了两种构造函数 m_pNothingTip 和 m_pInfoTip 分别为两种构造函数
49 m_pNothingTip = new KBallonTip();
50 m_pNothingTip->setWindowFlag(Qt::FramelessWindowHint);
51 m_pNothingTip->setAttribute(Qt::WA_TranslucentBackground);
52 m_pNothingTip->setTipType(TipType::Nothing); // 设置KBallonTip类型
53 m_pNothingTip->setText("这是一段操作信息描述的文字,这是一段操作信息描述的文字,这是一段操作信息描述的文字,这是一段操作信息描述的文字"); // 设置文本内容
54
55 m_pNormalTip = new KBallonTip();
56 m_pNormalTip->setWindowFlag(Qt::FramelessWindowHint);
57 m_pNormalTip->setAttribute(Qt::WA_TranslucentBackground);
58 m_pNormalTip->setTipType(TipType::Normal);
59 m_pNormalTip->setText("setContentsMargins调整边距");
60 // 两种setmargins都支持
61 // m_pWarningTip->setContentsMargins(QMargins(0,0,0,0));
62 m_pNormalTip->setContentsMargins(20, 20, 20, 20); // 设置内容边距
63
64 m_pInfoTip = new KBallonTip("提供两种构造函数", TipType::Info);
65 m_pInfoTip->setWindowFlag(Qt::FramelessWindowHint);
66 m_pInfoTip->setAttribute(Qt::WA_TranslucentBackground);
67
68 m_pWarningTip = new KBallonTip();
69 m_pWarningTip->setWindowFlag(Qt::FramelessWindowHint);
70 m_pWarningTip->setAttribute(Qt::WA_TranslucentBackground);
71 m_pWarningTip->setTipType(TipType::Warning);
72 m_pWarningTip->setText("这是一段操作信息描述的文字,这是一段操作信息描述的文字,这是一段操作信息描述的文字,这是一段操作信息描述的文字");
73
74 QMargins marge(20, 20, 20, 20);
75 m_pErrorTip = new KBallonTip();
76 m_pErrorTip->setWindowFlag(Qt::FramelessWindowHint);
77 m_pErrorTip->setAttribute(Qt::WA_TranslucentBackground);
78 m_pErrorTip->setTipType(TipType::Error);
79 m_pErrorTip->setContentsMargins(marge); // 通过 QMargins 设置内容边距
80 m_pErrorTip->setText("这是一段操作信息描述的文字,这是一段操作信息描述的文字,这是一段操作信息描述的文字,这是一段操作信息描述的文字");
81
82 connect(button, &QPushButton::clicked, this, [=]() {
83 m_pNothingTip->setTipTime(4000); // 设置显示时间
84 m_pNothingTip->showInfo(); // 定时显示KBallonTip,随后隐退 默认为1s
85 });
86
87 connect(button1, &QPushButton::clicked, this, [=]() {
88 m_pNormalTip->setTipTime(3000);
89 m_pNormalTip->showInfo();
90 });
91
92 connect(button2, &QPushButton::clicked, this, [=]() {
93 m_pInfoTip->setTipTime(2000);
94 m_pInfoTip->showInfo();
95 });
96
97 connect(button3, &QPushButton::clicked, this, [=]() {
98 m_pWarningTip->setTipTime(1000);
99 m_pWarningTip->showInfo();
100 });
101 connect(button4, &QPushButton::clicked, this, [=]() {
102 m_pErrorTip->showInfo();
103 });
104 // //vLayout->addWidget(m_pNothingTip);
105 // vLayout->addWidget(m_pNormalTip);
106 // vLayout->addWidget(m_pInfoTip);
107 // vLayout->addWidget(m_pWarningTip);
108 // vLayout->addWidget(m_pErrorTip);
109 this->baseBar()->setLayout(vLayout);
110 }
111
112 Widget::~Widget()
113 {
114 }