Debian Codegraph @

kysdk-qtwidgets/test/testarrowtabbar/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 "karrowtabbar.h"
24 #include "knativetabbar.h"
25 #include <QHBoxLayout>
26 #include <QLabel>
27
28 using namespace kdk;
29 Widget::Widget(QWidget *parent)
30 : QWidget(parent)
31 {
32
33 KArrowTabBar *tab1 = new KArrowTabBar();
34 KNativeTabbar *tabBar1 = tab1->tabbar();
35 tabBar1->setTabbarStyle(KNativeTabbarStyle::SegmentLight);
36 tabBar1->addTab(QIcon::fromTheme("kylin-music"), "Segment1");
37 tabBar1->addTab("Segment2");
38 tabBar1->addTab(QIcon::fromTheme("kylin-music"), "");
39 tabBar1->addTab("Segment4");
40 tabBar1->addTab("Segment5");
41 tabBar1->addTab("Segment6");
42
43 KArrowTabBar *tab2 = new KArrowTabBar();
44 KNativeTabbar *tabBar2 = tab2->tabbar();
45 tabBar2->setTabbarStyle(KNativeTabbarStyle::SegmentDark);
46
47 tabBar2->addTab("SegmentDark1");
48 tabBar2->addTab("SegmentDark2");
49 tabBar2->addTab(QIcon::fromTheme("kylin-music"), "SegmentDark3");
50 tabBar2->addTab("SegmentDark4");
51 tabBar2->addTab("SegmentDark5");
52 tabBar2->addTab(QIcon::fromTheme("kylin-music"), "");
53 KArrowTabBar *tab3 = new KArrowTabBar();
54 KNativeTabbar *tabBar3 = tab3->tabbar();
55 tabBar3->setTabbarStyle(KNativeTabbarStyle::Sliding);
56 tabBar3->addTab(QIcon::fromTheme("ukui-dialog-success"), "正常");
57 tabBar3->addTab(QIcon::fromTheme("dialog-warning"), "错误");
58 tabBar3->addTab(QIcon::fromTheme("dialog-info"), "注意");
59 tabBar3->addTab(QIcon::fromTheme("kylin-music"), "Sliding4");
60 tabBar3->addTab("Sliding5");
61 tabBar3->addTab(QIcon::fromTheme("kylin-music"), "Sliding6");
62
63 KArrowTabBar *tab4 = new KArrowTabBar();
64 KNativeTabbar *tabBar4 = tab4->tabbar();
65 tabBar4->addTab("Segment1");
66 tabBar4->addTab("Segment2");
67 tabBar4->addTab("Segment3");
68 tabBar4->addTab("Segment4");
69 tabBar4->setTabbarStyle(KNativeTabbarStyle::SegmentDark); // 设置style
70 tabBar4->setBorderRadius(10); // 设置圆角半径,只对SegmentDark,SegmentLight样式生效
71 tabBar4->setBackgroundColor(QColor(0, 255, 0)); // 设置背景色
72
73 QHBoxLayout *hlayout = new QHBoxLayout();
74 QLabel *label = new QLabel();
75 label->setText("just a test label");
76 hlayout->addWidget(label);
77
78 QVBoxLayout *vLayout = new QVBoxLayout(this);
79 vLayout->addStretch();
80 vLayout->addWidget(tab1);
81 vLayout->addWidget(tab2);
82 vLayout->addWidget(tab3);
83 vLayout->addWidget(tab4);
84 vLayout->addStretch();
85 vLayout->addStretch();
86 vLayout->addLayout(hlayout);
87 vLayout->addStretch();
88 setFixedWidth(500);
89 }
90
91 Widget::~Widget()
92 {
93 }