Debian Codegraph @

kysdk-qtwidgets/test/testnavigationbar/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 <QDebug>
25 #include <QLabel>
26
27 Widget::Widget(QWidget *parent)
28 : KWidget(parent)
29 {
30 QVBoxLayout *vLayout = new QVBoxLayout();
31 m_pBar = new KNavigationBar(this);
32
33 QStandardItem *item1 = new QStandardItem(QIcon::fromTheme("system-computer-symbolic"), tr("一级导航"));
34 QStandardItem *item2 = new QStandardItem(QIcon::fromTheme("stock-people-symbolic"), tr("二级导航"));
35 QList<QStandardItem *> list;
36 QStandardItem *item3 = new QStandardItem(QIcon::fromTheme("camera-switch-symbolic"), tr("一组一级导航1"));
37 QStandardItem *item4 = new QStandardItem(QIcon::fromTheme("media-eq-symbolic"), tr("一组一级导航2"));
38 list << item3 << item4;
39 m_pBar->addItem(item1); // 增加常规Item
40 m_pBar->addSubItem(item2); // 增加次级Item
41 m_pBar->addGroupItems(list, "测试一组"); // 组增加Item,在导航栏中会显示tag
42 QStandardItem *item5 = new QStandardItem(QIcon::fromTheme("camera-switch-symbolic"), tr("二组一级导航1"));
43 item5->setData("1", KNavigationBar::NavigationBarDataType::ValueRole);
44 QStandardItem *item6 = new QStandardItem(QIcon::fromTheme("media-eq-symbolic"), tr("二组一级导航2"));
45 item6->setData("2", KNavigationBar::NavigationBarDataType::ValueRole);
46 QStandardItem *item7 = new QStandardItem(QIcon::fromTheme("media-eq-symbolic"), tr("二组二级导航"));
47 QList<QStandardItem *> list2;
48 list2 << item5 << item6;
49 m_pBar->addGroupItems(list2, "测试二组");
50 m_pBar->setTabValueVisible(true);
51 m_pBar->setTabValue(item7, "3");
52 m_pBar->insertGroupItems("测试二组", 2, item7);
53
54 m_pBar->setAddTagVisible("测试二组", true);
55 m_pBar->setAddIcon("测试二组", QIcon::fromTheme("list-add-symbolic"));
56 m_pBar->setExtendTagVisible("测试二组", true);
57
58 connect(m_pBar, &KNavigationBar::addTagClicked, this, [=]() {
59 m_pBar->removeGroupItem("测试二组", item6);
60 });
61
62 m_pBar->addTag("测试三组");
63 vLayout->addWidget(m_pBar);
64 sideBar()->setLayout(vLayout);
65
66 vLayout = new QVBoxLayout;
67 QLabel *pLabel = new QLabel(this);
68 pLabel->setAlignment(Qt::AlignCenter);
69 vLayout->addWidget(pLabel);
70 baseBar()->setLayout(vLayout);
71
72 m_pBar->model()->item(1)->setEnabled(false);
73 m_pBar->model()->item(2)->setEnabled(false);
74 m_pBar->model()->item(3)->setEnabled(false);
75 m_pBar->model()->item(4)->setEnabled(false);
76
77 // QListView* ba= m_pBar->listview(); //获取listview
78 // ba->setDisabled(true); //整体禁用
79
80 // QStandardItemModel* m_mode = m_pBar->model(); //获取mode
81
82 connect(m_pBar->listview(), &QListView::clicked, this, [=](const QModelIndex &index) {
83 pLabel->setText(index.data().toString());
84 });
85 this->setLayoutType(HorizontalType);
86 }
87
88 Widget::~Widget()
89 {
90 }