Debian Codegraph @

kysdk-qtwidgets/test/testWidget/testwidget.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 <QAction>
24 #include <QApplication>
25 #include <QCheckBox>
26 #include <QCoreApplication>
27 #include <QDialogButtonBox>
28 #include <QFileDialog>
29 #include <QInputDialog>
30 #include <QList>
31 #include <QMenu>
32 #include <QMessageBox>
33 #include <QProgressBar>
34 #include <QProgressDialog>
35 #include <QScreen>
36 #include <QSizePolicy>
37 #include <QSlider>
38 #include <QStringList>
39 #include <QStyleFactory>
40 #include <QTableWidget>
41 #include <QTranslator>
42
43 #include "kaboutdialog.h"
44 #include "kbadge.h"
45 #include "kballontip.h"
46 #include "kborderbutton.h"
47 #include "kborderlessbutton.h"
48 #include "kinputdialog.h"
49 #include "knavigationbar.h"
50 #include "kpasswordedit.h"
51 #include "kpixmapcontainer.h"
52 #include "kprogressbar.h"
53 #include "kprogressdialog.h"
54 #include "ksearchlineedit.h"
55 #include "ksecuritylevelbar.h"
56 #include "kslider.h"
57 #include "kswitchbutton.h"
58 #include "ktabbar.h"
59 #include "ktoolbutton.h"
60 #include "kuninstalldialog.h"
61 #include "kwindowbuttonbar.h"
62 #include "testwidget.h"
63 #include "xatom-helper.h"
64
65 TestWidget::TestWidget(QWidget *parent)
66 : KWidget(parent)
67 {
68 setMinimumSize(640, 800);
69 this->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
70 // 窗体显示在中间
71 // QDesktopWidget *screenResolution = QApplication::desktop();
72 // this->move((screenResolution->width() - this->width()) / 2, (screenResolution->height() - this->height()) / 2);
73 QScreen *primaryScreen = QGuiApplication::primaryScreen();
74 if (primaryScreen) {
75 QRect screenGeometry = primaryScreen->availableGeometry();
76 this->move((screenGeometry.width() - this->width()) / 2, (screenGeometry.height() - this->height()) / 2);
77 }
78
79 this->setWindowTitle("testWindow");
80
81 KBorderButton *pLeftBtn = new KBorderButton(this);
82 pLeftBtn->setText("Left");
83
84 KSwitchButton *pSwitchBtn1 = new KSwitchButton(this);
85 pSwitchBtn1->setFixedSize(100, 26);
86 pSwitchBtn1->setEnabled(false);
87 KSwitchButton *pSwitchBtn2 = new KSwitchButton(this);
88 pSwitchBtn2->setFixedSize(100, 26);
89
90 KBorderButton *pRightBtn = new KBorderButton(this);
91 pRightBtn->setText("Right");
92 // pRightBtn->setEnabled(false);
93
94 QIcon icon = QIcon::fromTheme("edit-find-symbolic");
95 pRightBtn->setIcon(icon);
96
97 KSearchLineEdit *pSearchBar = new KSearchLineEdit(this);
98 // 默认是带completer的,如果不需要 可以设置为空
99 pSearchBar->setCompleter(nullptr);
100
101 QVBoxLayout *vLayout = new QVBoxLayout();
102
103 QHBoxLayout *hLayout = new QHBoxLayout();
104
105 vLayout->addLayout(hLayout);
106 vLayout->addStretch();
107
108 vLayout->addWidget(pSearchBar);
109
110 hLayout = new QHBoxLayout();
111 KSlider *slider = new KSlider(Qt::Horizontal, this);
112 slider->setSliderType(KSliderType::NodeSlider);
113 slider->setRange(0, 100);
114 slider->setTickInterval(20);
115 slider->setValue(33);
116 slider->setTickPosition(QSlider::TicksBothSides);
117
118 hLayout->addWidget(slider);
119 vLayout->addLayout(hLayout);
120
121 hLayout = new QHBoxLayout();
122 hLayout->addWidget(pLeftBtn);
123 hLayout->addWidget(pRightBtn);
124 vLayout->addLayout(hLayout);
125
126 hLayout = new QHBoxLayout();
127 hLayout->addWidget(pSwitchBtn1);
128 hLayout->addWidget(pSwitchBtn2);
129 vLayout->addLayout(hLayout);
130
131 KBorderlessButton *borderlessButton1 = new KBorderlessButton(this);
132 borderlessButton1->setText("borderless1");
133
134 KProgressDialog *progress1 = new KProgressDialog(this);
135 connect(borderlessButton1, &KBorderlessButton::clicked, progress1, &QProgressDialog::show);
136 progress1->setValue(20);
137 progress1->setShowDetail(true);
138
139 KBorderlessButton *borderlessButton2 = new KBorderlessButton(this);
140 borderlessButton2->setText("borderless2");
141
142 KProgressDialog *progress2 = new KProgressDialog(tr("下载"), tr("取消"), 0, 100, this);
143 progress2->setSubContent("下载中...");
144 progress2->setSuffix("MB");
145 progress2->setWindowTitle("进度对话框");
146 progress2->setWindowIcon("kylin-music");
147 progress2->setValue(50);
148 progress2->setShowDetail(false);
149 connect(borderlessButton2, &KBorderlessButton::clicked, progress2, &KProgressDialog::show);
150
151 hLayout = new QHBoxLayout();
152 hLayout->addWidget(borderlessButton1);
153 hLayout->addWidget(borderlessButton2);
154 vLayout->addLayout(hLayout);
155
156 KBorderlessButton *borderlessButton3 = new KBorderlessButton(QIcon::fromTheme("edit-find-symbolic"), this);
157 KBorderlessButton *borderlessButton4 = new KBorderlessButton(QIcon::fromTheme("edit-find-symbolic"), "borderless4", this);
158
159 hLayout = new QHBoxLayout();
160 hLayout->addWidget(borderlessButton3);
161 hLayout->addWidget(borderlessButton4);
162 vLayout->addLayout(hLayout);
163
164 KPixmapContainer *container = new KPixmapContainer(this);
165 // QPixmap pixmap;
166 // pixmap.load("/home/sunzhen/my.jpg");
167 // pixmap = pixmap.scaled(36,36);
168
169 // container->setPixmap(pixmap);
170 container->setPixmap(QIcon::fromTheme("edit-find-symbolic").pixmap(36, 36));
171 container->setValue(1000);
172 hLayout = new QHBoxLayout();
173 hLayout->addWidget(container);
174 vLayout->addLayout(hLayout);
175
176 KPasswordEdit *edit = new KPasswordEdit(this);
177 edit->setFixedWidth(200);
178 edit->setText("adad");
179 // edit->setLoading(true);
180 // edit->setState(LoginState::LoginFailed);
181 edit->setClearButtonEnabled(true);
182 KPasswordEdit *edit2 = new KPasswordEdit(this);
183 edit2->setFixedWidth(200);
184 edit2->setText("12313");
185 edit2->setEnabled(false);
186 edit2->setClearButtonEnabled(true);
187 hLayout = new QHBoxLayout();
188 hLayout->addWidget(edit);
189 hLayout->addWidget(edit2);
190 vLayout->addLayout(hLayout);
191
192 KProgressBar *progressbar = new KProgressBar(this);
193 progressbar->setRange(0, 100);
194 progressbar->setValue(100);
195 progressbar->setTextVisible(true);
196 progressbar->setAlignment(Qt::AlignRight);
197 hLayout = new QHBoxLayout();
198 hLayout->addWidget(progressbar);
199 vLayout->addLayout(hLayout);
200
201 // KProgressBar* progressbar2 = new KProgressBar(this);
202 // progressbar2->setOrientation(Qt::Vertical);
203 // progressbar2->setValue(50);
204 // progressbar2->setTextVisible(true);
205 // progressbar2->setAlignment(Qt::AlignRight);
206 // hLayout = new QHBoxLayout();
207 // hLayout->addWidget(progressbar2);
208 // vLayout->addLayout(hLayout);
209
210 KBallonTip *ballonTip = new KBallonTip("这是一段操作信息描述的文字,这是一段操作信息描述的文字,这是一段操作信息描述的文字,这是一段操作信息描述的文字", TipType::Error, this);
211 ballonTip->setFixedWidth(400);
212 hLayout = new QHBoxLayout();
213 hLayout->addWidget(ballonTip);
214 vLayout->addLayout(hLayout);
215 // ballonTip->setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed);
216
217 KSecurityLevelBar *barrrr = new KSecurityLevelBar(this);
218 barrrr->setSecurityLevel(SecurityLevel::Medium);
219 hLayout = new QHBoxLayout();
220 hLayout->addWidget(barrrr);
221 vLayout->addLayout(hLayout);
222
223 KBadge *badge1 = new KBadge(this);
224 badge1->setValue(-9);
225 // badge1->setFontSize(20);
226 KBadge *badge2 = new KBadge(this);
227 badge2->setValue(99);
228 // badge2->setFontSize(10);
229 KBadge *badge3 = new KBadge(this);
230 badge3->setValue(999);
231 // badge3->setMinimumHeight(50);
232 badge3->setFontSize(15);
233 KBadge *badge4 = new KBadge(this);
234 badge4->setValue(9991);
235 // badge4->setColor(QColor(255,0,0));
236 hLayout = new QHBoxLayout();
237 hLayout->addWidget(badge1);
238 hLayout->addWidget(badge2);
239 hLayout->addWidget(badge3);
240 hLayout->addWidget(badge4);
241 vLayout->addLayout(hLayout);
242
243 KTabBar *tabBar1 = new KTabBar(KTabBarStyle::SegmentLight, this);
244 tabBar1->addTab("first");
245 tabBar1->addTab("second");
246 tabBar1->addTab("third");
247
248 KTabBar *tabBar2 = new KTabBar(KTabBarStyle::SegmentDark, this);
249 tabBar2->addTab("first");
250 tabBar2->addTab("second");
251 tabBar2->addTab("third");
252
253 KTabBar *tabBar3 = new KTabBar(KTabBarStyle::Sliding, this);
254 tabBar3->addTab("first");
255 tabBar3->addTab("second");
256 tabBar3->addTab("third");
257
258 KUninstallDialog *uninstallDialog = new KUninstallDialog("browser360-cn-stable", "104", this);
259 KAboutDialog *aboutDialog = new KAboutDialog(this, QIcon::fromTheme("edit-find-symbolic"), "麒麟引导修复工具", tr("Version:2020.1.0"));
260
261 connect(pLeftBtn, &KBorderButton::clicked, uninstallDialog, &KUninstallDialog::show);
262 connect(pRightBtn, &KBorderButton::clicked, aboutDialog, &KAboutDialog::show);
263
264 vLayout->addWidget(tabBar1);
265 vLayout->addWidget(tabBar2);
266 vLayout->addWidget(tabBar3);
267 vLayout->addStretch();
268 baseBar()->setLayout(vLayout);
269
270 vLayout = new QVBoxLayout();
271 KNavigationBar *bar = new KNavigationBar(this);
272
273 QStandardItem *item1 = new QStandardItem(QIcon::fromTheme("system-computer-symbolic"), tr("一级导航"));
274 QStandardItem *item2 = new QStandardItem(QIcon::fromTheme("stock-people-symbolic"), tr("二级导航"));
275 QList<QStandardItem *> list;
276 QStandardItem *item3 = new QStandardItem(QIcon::fromTheme("camera-switch-symbolic"), tr("一组一级导航"));
277 QStandardItem *item4 = new QStandardItem(QIcon::fromTheme("media-eq-symbolic"), tr("一组一级导航"));
278 list << item3 << item4;
279 bar->addItem(item1);
280 bar->addSubItem(item2);
281 bar->addGroupItems(list, "测试一组");
282 QStandardItem *item5 = new QStandardItem(QIcon::fromTheme("camera-switch-symbolic"), tr("二组一级导航"));
283 QStandardItem *item6 = new QStandardItem(QIcon::fromTheme("media-eq-symbolic"), tr("二组一级导航"));
284 QStandardItem *item7 = new QStandardItem(QIcon::fromTheme("media-eq-symbolic"), tr("二组二级导航"));
285 QList<QStandardItem *> list2;
286 list2 << item5 << item6;
287 bar->addGroupItems(list2, "测试二组");
288 bar->addSubItem(item7);
289
290 vLayout->addWidget(bar);
291 sideBar()->setLayout(vLayout);
292 this->setLayoutType(HorizontalType);
293 }
294 TestWidget::~TestWidget()
295 {
296 }