Debian Codegraph @

kysdk-qtwidgets/test/testKButtonBox/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 "kbuttonbox.h"
25 #include "kpushbutton.h"
26 #include <QBoxLayout>
27 #include <QComboBox>
28 #include <QDebug>
29 #include <QList>
30 #include <QPushButton>
31
32 using namespace kdk;
33
34 Widget::Widget(QWidget *parent)
35 : QWidget(parent)
36 {
37 QVBoxLayout *layout = new QVBoxLayout(this);
38
39 QHBoxLayout *layout1 = new QHBoxLayout;
40 KButtonBox *box1 = new KButtonBox(this);
41 KPushButton *btn1 = new KPushButton;
42 btn1->setIcon(QIcon::fromTheme("list-add-symbolic"));
43 btn1->setFixedSize(48, 48);
44 btn1->setIconSize(QSize(32, 32));
45 KPushButton *btn2 = new KPushButton;
46 btn2->setIcon(QIcon::fromTheme("list-remove-symbolic"));
47 btn2->setFixedSize(48, 48);
48 btn2->setIconSize(QSize(32, 32));
49 box1->addButton(btn1);
50 box1->addButton(btn2);
51
52 KButtonBox *box2 = new KButtonBox(this);
53 KPushButton *btn3 = new KPushButton;
54 btn3->setIcon(QIcon::fromTheme("list-add-symbolic"));
55 btn3->setFixedSize(48, 48);
56 btn3->setIconSize(QSize(32, 32));
57 KPushButton *btn4 = new KPushButton;
58 btn4->setIcon(QIcon::fromTheme("list-remove-symbolic"));
59 btn4->setFixedSize(48, 48);
60 btn4->setIconSize(QSize(32, 32));
61 btn4->setEnabled(false);
62 box2->addButton(btn3);
63 box2->addButton(btn4);
64
65 QHBoxLayout *layout2 = new QHBoxLayout;
66 KButtonBox *box3 = new KButtonBox(this);
67 KPushButton *btn5 = new KPushButton(this);
68 btn5->setIcon(QIcon::fromTheme("system-computer-symbolic"));
69 KPushButton *btn6 = new KPushButton(this);
70 btn6->setIcon(QIcon::fromTheme("format-text-italic-symbolic"));
71 KPushButton *btn7 = new KPushButton(this);
72 btn7->setIcon(QIcon::fromTheme("format-text-underline-symbolic"));
73 KPushButton *btn8 = new KPushButton(this);
74 btn8->setIcon(QIcon::fromTheme("format-text-strikethrough-symbolic"));
75 QList<KPushButton *> list;
76 list.insert(0, btn5);
77 list.insert(1, btn6);
78 list.insert(2, btn7);
79 list.insert(3, btn8);
80
81 box3->setButtonList(list);
82 box3->setCheckable(true);
83 box3->setExclusive(false);
84
85 KPushButton *btn = new KPushButton;
86 btn->setText("New Button");
87
88 connect(box1, &KButtonBox::buttonClicked, this, [=](QAbstractButton *button) {
89 if (btn1 == button)
90 box3->addButton(btn);
91 if (btn2 == button)
92 box3->removeButton(btn);
93 });
94
95 layout1->addWidget(box1);
96 layout1->addWidget(box2);
97 layout2->addWidget(box3);
98 layout->addLayout(layout1);
99 layout->addLayout(layout2);
100 this->setLayout(layout);
101 this->setFixedSize(500, 400);
102 }
103
104 Widget::~Widget()
105 {
106 }