Debian Codegraph @

kysdk-qtwidgets/test/testnativetabbar/widget.cpp

raw
1 /*
2 *
3 * Copyright (C) 2024, KylinSoft Co., Ltd.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 3 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this library. If not, see <https://www.gnu.org/licenses/>.
17 *
18 * Authors: Zhenyu Wang <[email protected]>
19 *
20 */
21
22 #include "widget.h"
23 #include "knativetabbar.h"
24 #include <QLabel>
25 #include <QMenu>
26 #include <QVBoxLayout>
27
28 using namespace kdk;
29 Widget::Widget(QWidget *parent)
30 : QWidget(parent)
31 {
32 QWidget *w = new QWidget();
33 KNativeTabbar *tabBar1 = new KNativeTabbar(KNativeTabbarStyle::SegmentLight, w);
34 tabBar1->addTab(QIcon::fromTheme("kylin-music"), "Segment1");
35 tabBar1->addTab("Segment2");
36 tabBar1->addTab(QIcon::fromTheme("kylin-music"), "");
37 tabBar1->addTab("Segment4");
38 tabBar1->addTab("Segment5");
39 tabBar1->addTab("Segment6");
40 KNativeTabbar *tabBar2 = new KNativeTabbar(KNativeTabbarStyle::SegmentDark, w);
41 tabBar2->addTab("SegmentDark1");
42 tabBar2->addTab("SegmentDark2");
43 tabBar2->addTab(QIcon::fromTheme("kylin-music"), "SegmentDark3");
44 tabBar2->addTab("SegmentDark4");
45 tabBar2->addTab("SegmentDark5");
46 tabBar2->addTab(QIcon::fromTheme("kylin-music"), "");
47 KNativeTabbar *tabBar3 = new KNativeTabbar(KNativeTabbarStyle::Sliding, w);
48 tabBar3->addTab(QIcon::fromTheme("ukui-dialog-success"), "正常");
49 tabBar3->addTab(QIcon::fromTheme("dialog-warning"), "错误");
50 tabBar3->addTab(QIcon::fromTheme("dialog-info"), "注意");
51 tabBar3->addTab(QIcon::fromTheme("kylin-music"), "Sliding4");
52 tabBar3->addTab("Sliding5");
53 tabBar3->addTab(QIcon::fromTheme("kylin-music"), "Sliding6");
54 // tabBar3->setIconSize(QSize(24,24));
55 KNativeTabbar *tabBar4 = new KNativeTabbar(KNativeTabbarStyle::Sliding, w);
56 tabBar4->addTab("Segment1");
57 tabBar4->addTab("Segment2");
58 tabBar4->addTab("Segment3");
59 tabBar4->addTab("Segment4");
60 tabBar4->setTabbarStyle(KNativeTabbarStyle::SegmentDark); // 设置style
61 tabBar4->setBorderRadius(10); // 设置圆角半径,只对SegmentDark,SegmentLight样式生效
62 tabBar4->setBackgroundColor(QColor(0, 255, 0)); // 设置背景色
63
64 QLabel *pLabel = new QLabel(w);
65 pLabel->setAlignment(Qt::AlignCenter);
66
67 QMenu *menu = new QMenu();
68 QAction *action1 = new QAction("action1", menu);
69 QAction *action2 = new QAction("action2", menu);
70 QAction *action3 = new QAction("action3", menu);
71 menu->addAction(action1);
72 menu->addAction(action2);
73 menu->addAction(action3);
74
75 connect(tabBar1, &KNativeTabbar::tabBarClicked, this, [=](int index) {
76 pLabel->setText(tabBar1->tabText(index));
77 });
78 connect(tabBar2, &KNativeTabbar::tabBarClicked, this, [=](int index) {
79 pLabel->setText(tabBar2->tabText(index));
80 });
81 connect(tabBar3, &KNativeTabbar::tabBarClicked, this, [=](int index) {
82 pLabel->setText(tabBar3->tabText(index));
83 });
84 connect(tabBar4, &KNativeTabbar::tabBarClicked, this, [=](int index) {
85 pLabel->setText(tabBar4->tabText(index));
86 });
87 connect(tabBar4, &KNativeTabbar::rightlicked, this, [=](QPoint point) {
88 menu->move(point);
89 menu->show();
90 });
91
92 QHBoxLayout *hlayout = new QHBoxLayout();
93 QLabel *label = new QLabel();
94 label->setText("just a test label");
95 hlayout->addWidget(label);
96
97 QVBoxLayout *vLayout = new QVBoxLayout;
98 vLayout->addStretch();
99 vLayout->addWidget(tabBar1);
100 vLayout->addWidget(tabBar2);
101 vLayout->addWidget(tabBar3);
102 vLayout->addWidget(tabBar4);
103 vLayout->addStretch();
104 vLayout->addWidget(pLabel);
105 vLayout->addStretch();
106 vLayout->addLayout(hlayout);
107 vLayout->addStretch();
108 setLayout(vLayout);
109 }
110
111 Widget::~Widget()
112 {
113 }