Debian Codegraph @

kysdk-qtwidgets/test/testKBubbleWidget/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 "kbubblewidget.h"
25 #include "kwidget.h"
26 #include <QApplication>
27 #include <QFrame>
28 #include <QGraphicsDropShadowEffect>
29 #include <QHBoxLayout>
30 #include <QLayout>
31 using namespace kdk;
32
33 Widget::Widget(QWidget *parent)
34 : QWidget(parent)
35 {
36 QPushButton *btn1 = new QPushButton(this);
37 btn1->setText("常规");
38
39 QPushButton *btn2 = new QPushButton(this);
40 btn2->setText("毛玻璃");
41
42 btn2->move(100, 0);
43
44 KBubbleWidget *w = new KBubbleWidget();
45 w->setTailPosition(TailDirection::TopDirection);
46 w->setTailSize(QSize(16, 8));
47 w->setBorderRadius(12);
48 w->setOpacity(0.4);
49 w->setEnableBlur(false);
50 w->setFixedSize(320, 320);
51 QHBoxLayout *layout = new QHBoxLayout(w);
52 QPushButton *button = new QPushButton(w);
53 button->setText("关闭");
54 layout->addWidget(button);
55 connect(button, &QPushButton::clicked, this, [=]() {
56 w->hide();
57 });
58
59 KBubbleWidget *w2 = new KBubbleWidget();
60 w2->setTailPosition(TailDirection::TopDirection);
61 w2->setTailSize(QSize(16, 8));
62 w2->setBorderRadius(12);
63 w2->setOpacity(0.4);
64 w2->setEnableBlur(true);
65 w2->setFixedSize(320, 320);
66 QPushButton *button2 = new QPushButton(w2);
67 button2->setText("关闭");
68 QHBoxLayout *layout2 = new QHBoxLayout(w2);
69 layout2->addWidget(button2);
70
71 connect(button2, &QPushButton::clicked, this, [=]() {
72 w2->hide();
73 });
74
75 connect(btn1, &QPushButton::clicked, this, [=]() {
76 w->show();
77 });
78 connect(btn2, &QPushButton::clicked, this, [=]() {
79 w2->show();
80 });
81 }
82
83 Widget::~Widget()
84 {
85 }