Debian Codegraph @

kysdk-qtwidgets/test/testbadge/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 <QBoxLayout>
25 #include <QLabel>
26 #include <QSpinBox>
27
28 Widget::Widget(QWidget *parent)
29 : KWidget(parent)
30 {
31 QVBoxLayout *vLayout = new QVBoxLayout(this);
32
33 QHBoxLayout *hLayout = new QHBoxLayout();
34 m_pContainer1 = new KPixmapContainer(this);
35 m_pContainer1->setPixmap(QIcon::fromTheme("edit-find-symbolic").pixmap(16, 16));
36 m_pContainer1->setFontSize(8);
37
38 m_pContainer1->setColor(QColor(255, 0, 0)); // 设置背景色
39 m_pContainer2 = new KPixmapContainer(this);
40 m_pContainer2->setPixmap(QIcon::fromTheme("edit-find-symbolic").pixmap(24, 24));
41 m_pContainer2->setFontSize(10);
42 m_pContainer2->setValue(99); // 设置值
43 m_pContainer2->setValueVisiable(false); // 设置值不可见
44 m_pContainer3 = new KPixmapContainer(this);
45 m_pContainer3->setPixmap(QIcon::fromTheme("edit-find-symbolic").pixmap(36, 36));
46 m_pContainer3->setFontSize(10);
47 m_pContainer3->setValue(999);
48 m_pContainer4 = new KPixmapContainer(this);
49 m_pContainer4->setPixmap(QIcon::fromTheme("edit-find-symbolic").pixmap(48, 48));
50 m_pContainer4->setFontSize(12); // 设置字体大小
51 m_pContainer4->setValue(1000);
52 hLayout->addWidget(m_pContainer1);
53 hLayout->addWidget(m_pContainer2);
54 hLayout->addWidget(m_pContainer3);
55 hLayout->addWidget(m_pContainer4);
56 vLayout->addStretch();
57 vLayout->addLayout(hLayout);
58
59 QLabel *label = new QLabel("调整badge3大小:", this);
60 QSpinBox *spinBox = new QSpinBox(this);
61 spinBox->setValue(m_pContainer3->fontSize());
62 connect(spinBox, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this,
63 [=](int i) {
64 m_pContainer3->setFontSize(spinBox->value());
65 });
66 hLayout = new QHBoxLayout();
67 hLayout->addStretch();
68 hLayout->addWidget(label);
69 hLayout->addWidget(spinBox);
70 hLayout->addStretch();
71 vLayout->addLayout(hLayout);
72 m_pBadge1 = new KBadge(this);
73 m_pBadge1->setValue(0);
74 m_pBadge2 = new KBadge(this);
75 m_pBadge2->setValue(99);
76 // m_pBadge2->setValueVisiable(false);
77 m_pBadge3 = new KBadge(this);
78 m_pBadge3->setValue(999);
79 m_pBadge4 = new KBadge(this);
80 m_pBadge4->setValue(1000);
81 hLayout = new QHBoxLayout(this);
82 hLayout->addWidget(m_pBadge1);
83 hLayout->addWidget(m_pBadge2);
84 hLayout->addWidget(m_pBadge3);
85 hLayout->addWidget(m_pBadge4);
86 vLayout->addLayout(hLayout);
87 vLayout->addStretch();
88 baseBar()->setLayout(vLayout);
89 }
90
91 Widget::~Widget()
92 {
93 }