Debian Codegraph @

kysdk-qtwidgets/test/testtabbar/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 "ktabbar.h"
25 #include <QLabel>
26 #include <QVBoxLayout>
27
28 Widget::Widget(QWidget *parent)
29 : KWidget(parent)
30 {
31 /* 测试说明
32 * 1.tabbar1-tabbar3测试三种样式的显示以及添加tab的功能(在tabbar的开始、中间和末尾位置添加图标、文字以及二者都存在的tab)
33 * 2.tabbar4测试设置tabbar样式、修改tabbar圆角(0-20)以及设置背景色。
34 */
35 QWidget *w = new QWidget();
36 KTabBar *tabBar1 = new KTabBar(KTabBarStyle::SegmentLight, w);
37 tabBar1->addTab(QIcon::fromTheme("kylin-music"), "Segment1");
38 tabBar1->addTab("Segment2");
39 tabBar1->addTab(QIcon::fromTheme("kylin-music"), "");
40 tabBar1->addTab("Segment4");
41 tabBar1->addTab("Segment5");
42 tabBar1->addTab("Segment6");
43 KTabBar *tabBar2 = new KTabBar(KTabBarStyle::SegmentDark, w);
44 tabBar2->addTab("SegmentDark1");
45 tabBar2->addTab("SegmentDark2");
46 tabBar2->addTab(QIcon::fromTheme("kylin-music"), "SegmentDark3");
47 tabBar2->addTab("SegmentDark4");
48 tabBar2->addTab("SegmentDark5");
49 tabBar2->addTab(QIcon::fromTheme("kylin-music"), "");
50 KTabBar *tabBar3 = new KTabBar(KTabBarStyle::Sliding, w);
51 tabBar3->addTab(QIcon::fromTheme("kylin-music"), "");
52 tabBar3->addTab("Sliding2");
53 tabBar3->addTab("Sliding3");
54 tabBar3->addTab("Sliding4");
55 tabBar3->addTab("Sliding5");
56 tabBar3->addTab(QIcon::fromTheme("kylin-music"), "Sliding6");
57 KTabBar *tabBar4 = new KTabBar(KTabBarStyle::Sliding, w);
58 tabBar4->addTab("Segment1");
59 tabBar4->addTab("Segment2");
60 tabBar4->addTab("Segment3");
61 tabBar4->addTab("Segment4");
62 tabBar4->setTabBarStyle(KTabBarStyle::SegmentDark); // 设置style
63 tabBar4->setBorderRadius(10); // 设置圆角半径,只对SegmentDark,SegmentLight样式生效
64 tabBar4->setBackgroundColor(QColor(0, 255, 0)); // 设置背景色
65
66 QLabel *pLabel = new QLabel(w);
67 pLabel->setAlignment(Qt::AlignCenter);
68 connect(tabBar1, &KTabBar::tabBarClicked, this, [=](int index) {
69 pLabel->setText(tabBar1->tabText(index));
70 });
71 connect(tabBar2, &KTabBar::tabBarClicked, this, [=](int index) {
72 pLabel->setText(tabBar2->tabText(index));
73 });
74 connect(tabBar3, &KTabBar::tabBarClicked, this, [=](int index) {
75 pLabel->setText(tabBar3->tabText(index));
76 });
77 connect(tabBar4, &KTabBar::tabBarClicked, this, [=](int index) {
78 pLabel->setText(tabBar4->tabText(index));
79 });
80
81 QHBoxLayout *hlayout = new QHBoxLayout();
82 QLabel *label = new QLabel();
83 label->setText("just a test label");
84 hlayout->addWidget(label);
85
86 QVBoxLayout *vLayout = new QVBoxLayout;
87 vLayout->addStretch();
88 vLayout->addWidget(tabBar1);
89 vLayout->addWidget(tabBar2);
90 vLayout->addWidget(tabBar3);
91 vLayout->addWidget(tabBar4);
92 vLayout->addStretch();
93 vLayout->addWidget(pLabel);
94 vLayout->addStretch();
95 vLayout->addLayout(hlayout);
96 vLayout->addStretch();
97 baseBar()->setLayout(vLayout);
98 }
99
100 Widget::~Widget()
101 {
102 }