Debian Codegraph @

kysdk-qtwidgets/test/testKLabel/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 "klabel.h"
24 #include <QDebug>
25 #include <QHBoxLayout>
26 #include <QIcon>
27 #include <QPushButton>
28
29 using namespace kdk;
30 Widget::Widget(QWidget *parent)
31 : QWidget(parent)
32 {
33 QVBoxLayout *vlayout = new QVBoxLayout(this);
34 QVBoxLayout *layout = new QVBoxLayout();
35
36 KLabel *label1 = new KLabel();
37 label1->setText("我是一个测试tooltip的lable");
38 label1->setBackgroundColor(true, Qt::red);
39 // label1->setFixedWidth(100);
40
41 KLabel *label2 = new KLabel(this);
42 label2->setPixmap(QIcon::fromTheme("system-computer-symbolic").pixmap(16, 16));
43 label2->setDataHightColor(true);
44 label2->setLabelType(KLabelType::DataType);
45 label2->setText("我是一个测试lable");
46
47 KLabel *label3 = new KLabel();
48 label3->setFixedWidth(100);
49 label3->setText("测\n测dawdadafauphfuawhfawhfp");
50 label3->setWordWrap(true);
51 label3->setPixmap(QIcon::fromTheme("system-computer-symbolic").pixmap(16, 16));
52 label3->setLabelType(KLabelType::DataType);
53 label3->setBackgroundColor(Qt::white);
54 label3->setDataHightColor(true);
55
56 KLabel *label4 = new KLabel();
57 label4->setLabelType(KLabelType::CircleType);
58 label4->setPixmap(QIcon::fromTheme("system-computer-symbolic").pixmap(16, 16));
59 label4->setFixedSize(50, 50);
60 QFont font1;
61 int i = font().pointSize();
62 font1.setPointSize(i + 16);
63 label1->setFont(font1);
64
65 label4->setPixmap(QIcon::fromTheme("dialog-ok").pixmap(16, 16));
66 label4->setBackgroundColor(true, Qt::green);
67
68 QPushButton *btn1 = new QPushButton("默认");
69 QPushButton *btn2 = new QPushButton("高亮背景");
70 QPushButton *btn3 = new QPushButton("自定义背景");
71 QHBoxLayout *hlayout = new QHBoxLayout();
72 hlayout->addWidget(btn1);
73 hlayout->addWidget(btn2);
74 hlayout->addWidget(btn3);
75
76 connect(btn1, &QPushButton::clicked, this, [=] {
77 label4->setHighlightBackground(false);
78 label4->setBackgroundColor(false);
79 label4->setPixmap(QIcon::fromTheme("system-computer-symbolic").pixmap(16, 16));
80 });
81 connect(btn2, &QPushButton::clicked, this, [=] {
82 label4->setHighlightBackground(true);
83 label4->setPixmap(QIcon::fromTheme("system-computer-symbolic").pixmap(16, 16));
84 });
85 connect(btn3, &QPushButton::clicked, this, [=] {
86 label4->setBackgroundColor(true, QColor(82, 196, 41));
87 label4->setPixmap(QIcon::fromTheme("dialog-ok").pixmap(16, 16));
88 });
89
90 KLabel *label5 = new KLabel(this);
91 label5->setText("测试进入/离开信号/点击信号/双击信号");
92 connect(label5, &KLabel::enterWidget, this, [=] {
93 qDebug() << "enter label5";
94 });
95 connect(label5, &KLabel::leaveWidget, this, [=] {
96 qDebug() << "leave label5";
97 });
98 connect(label5, &KLabel::clicked, this, [=](bool checked) {
99 qDebug() << "clicked label5" << checked;
100 });
101 connect(label5,&KLabel::doubleClicked,this,[=](){
102 qDebug()<<"doubleClicked label5";
103 });
104
105 QHBoxLayout *hlayout1 = new QHBoxLayout(this);
106
107 KLabel *label6 = new KLabel(this);
108 label6->setText("测试三态");
109 label6->setTristate(true);
110
111 QPushButton *btn = new QPushButton(this);
112 connect(btn, &QPushButton::clicked, this, [=] {
113 if (label6->isTristate())
114 label6->setTristate(false);
115 else
116 label6->setTristate(true);
117 });
118
119 hlayout1->addWidget(label6);
120 hlayout1->addWidget(btn);
121
122 QHBoxLayout *hlayout2 = new QHBoxLayout(this);
123
124 KLabel *label7 = new KLabel(this);
125 label7->setText("测试font color role");
126 label7->setFontColorRole(QPalette::PlaceholderText);
127 hlayout2->addWidget(label7);
128
129 layout->addWidget(label1);
130 layout->addWidget(label2);
131 layout->addWidget(label3);
132 layout->addLayout(hlayout);
133 layout->addWidget(label4);
134 layout->addWidget(label5);
135 layout->addLayout(hlayout1);
136 layout->addLayout(hlayout2);
137 vlayout->addLayout(layout);
138 }
139
140 Widget::~Widget()
141 {
142 }