| 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 "kbackgroundgroup.h" |
| 25 |
#include "kborderlessbutton.h" |
| 26 |
#include "klineframe.h" |
| 27 |
#include "kpushbutton.h" |
| 28 |
#include "kswitchbutton.h" |
| 29 |
#include "ktoolbutton.h" |
| 30 |
#include <QCheckBox> |
| 31 |
#include <QFrame> |
| 32 |
#include <QHBoxLayout> |
| 33 |
#include <QLabel> |
| 34 |
#include <QLineEdit> |
| 35 |
|
| 36 |
using namespace kdk; |
| 37 |
Widget::Widget(QWidget *parent) |
| 38 |
: QWidget(parent) |
| 39 |
{ |
| 40 |
QVBoxLayout *vmainLayout = new QVBoxLayout(this); |
| 41 |
|
| 42 |
QLabel *networkLabel = new QLabel(); |
| 43 |
networkLabel->setText("有线网络"); |
| 44 |
networkLabel->setContentsMargins(20, 0, 0, 0); |
| 45 |
|
| 46 |
QWidget *widget1 = new QWidget(); |
| 47 |
|
| 48 |
QLabel *widget1Label = new QLabel(); |
| 49 |
widget1Label->setText("开启"); |
| 50 |
|
| 51 |
KSwitchButton *widget1Switch = new KSwitchButton(); |
| 52 |
|
| 53 |
QHBoxLayout *widget1Layout = new QHBoxLayout(widget1); |
| 54 |
widget1Layout->setContentsMargins(16, 0, 16, 0); |
| 55 |
widget1Layout->addWidget(widget1Label); |
| 56 |
widget1Layout->addStretch(); |
| 57 |
widget1Layout->addWidget(widget1Switch); |
| 58 |
|
| 59 |
KBackgroundGroup *back = new KBackgroundGroup(); |
| 60 |
back->addWidget(widget1); |
| 61 |
|
| 62 |
QWidget *widget2 = new QWidget(); |
| 63 |
// widget2->setFixedHeight(100); |
| 64 |
|
| 65 |
QLabel *widget2label = new QLabel(); |
| 66 |
widget2label->setText("网卡:wwwwwww"); |
| 67 |
|
| 68 |
KBorderlessButton *less = new KBorderlessButton(); |
| 69 |
less->setIcon(QIcon::fromTheme("system-computer-symbolic")); |
| 70 |
less->setAttribute(Qt::WA_TranslucentBackground); |
| 71 |
|
| 72 |
KSwitchButton *widget2Switch = new KSwitchButton(); |
| 73 |
widget2Switch->setAttribute(Qt::WA_TranslucentBackground); |
| 74 |
|
| 75 |
QHBoxLayout *widget2Layout = new QHBoxLayout(widget2); |
| 76 |
widget2Layout->setContentsMargins(16, 0, 16, 0); |
| 77 |
widget2Layout->addWidget(widget2label); |
| 78 |
widget2Layout->addStretch(); |
| 79 |
widget2Layout->addWidget(less); |
| 80 |
widget2Layout->addWidget(widget2Switch); |
| 81 |
|
| 82 |
QWidget *widget3 = new QWidget(); |
| 83 |
// QPushButton *widget3 = new QPushButton(); |
| 84 |
widget3->setProperty("isWindowButton", 0x01); |
| 85 |
|
| 86 |
QLabel *widget3Label1 = new QLabel(); |
| 87 |
widget3Label1->setPixmap(QIcon::fromTheme("system-computer-symbolic").pixmap(16, 16)); |
| 88 |
QLabel *widget3Label2 = new QLabel(); |
| 89 |
widget3Label2->setText("网络名称"); |
| 90 |
|
| 91 |
QLabel *widget3Label3 = new QLabel(); |
| 92 |
widget3Label3->setText("连接"); |
| 93 |
|
| 94 |
KBorderlessButton *widget3btn = new KBorderlessButton(this); |
| 95 |
widget3btn->setIcon(QIcon::fromTheme("stock-people-symbolic")); |
| 96 |
widget3btn->setAttribute(Qt::WA_TranslucentBackground); |
| 97 |
|
| 98 |
QHBoxLayout *widget3Layout = new QHBoxLayout(widget3); |
| 99 |
widget3Layout->setContentsMargins(16, 0, 16, 0); |
| 100 |
widget3Layout->addWidget(widget3Label1); |
| 101 |
widget3Layout->addWidget(widget3Label2); |
| 102 |
widget3Layout->addStretch(); |
| 103 |
widget3Layout->addWidget(widget3Label3); |
| 104 |
widget3Layout->addWidget(widget3btn); |
| 105 |
|
| 106 |
QWidget *widget4 = new QWidget(); |
| 107 |
|
| 108 |
QLabel *widget4Label1 = new QLabel(); |
| 109 |
widget4Label1->setText("点击添加"); |
| 110 |
|
| 111 |
QLabel *widget4Label2 = new QLabel(); |
| 112 |
widget4Label2->setPixmap(QIcon::fromTheme("system-computer-symbolic").pixmap(16, 16)); |
| 113 |
|
| 114 |
QHBoxLayout *widget4Layout = new QHBoxLayout(widget4); |
| 115 |
widget4Layout->addStretch(); |
| 116 |
widget4Layout->addWidget(widget4Label2); |
| 117 |
widget4Layout->addWidget(widget4Label1); |
| 118 |
widget4Layout->addStretch(); |
| 119 |
|
| 120 |
QList<QWidget *> list; |
| 121 |
list.append(widget2); |
| 122 |
list.append(widget3); |
| 123 |
list.append(widget4); |
| 124 |
|
| 125 |
KBackgroundGroup *back1 = new KBackgroundGroup(); |
| 126 |
back1->addWidgetList(list); |
| 127 |
back1->setStateEnable(widget3, true); |
| 128 |
back1->setStateEnable(widget4, true); |
| 129 |
|
| 130 |
QWidget *widget5 = new QWidget(); |
| 131 |
widget5->hide(); |
| 132 |
|
| 133 |
QWidget *widget6 = new QWidget(); |
| 134 |
widget6->setWindowIcon(QIcon::fromTheme("kylin-music")); |
| 135 |
widget6->hide(); |
| 136 |
|
| 137 |
connect(widget1Switch, &KSwitchButton::clicked, this, [=]() { |
| 138 |
if (back1->isVisible()) |
| 139 |
back1->hide(); |
| 140 |
else |
| 141 |
back1->show(); |
| 142 |
}); |
| 143 |
|
| 144 |
// 插入删除 |
| 145 |
connect(widget2Switch, &KSwitchButton::clicked, this, [=]() { |
| 146 |
if (back1->widgetList().contains(widget3)) |
| 147 |
back1->removeWidget(widget3); |
| 148 |
else |
| 149 |
back1->insertWidgetAt(back1->widgetList().count() - 1, widget3); |
| 150 |
back1->setStateEnable(widget3, true); |
| 151 |
}); |
| 152 |
|
| 153 |
connect(less, &KBorderlessButton::clicked, this, [=]() { |
| 154 |
if (back1->widgetList().contains(widget3)) |
| 155 |
back1->removeWidget(widget3); |
| 156 |
else |
| 157 |
back1->insertWidgetAt(back1->widgetList().count() - 1, widget3); |
| 158 |
back1->setStateEnable(widget3, true); |
| 159 |
}); |
| 160 |
|
| 161 |
connect(back1, &KBackgroundGroup::clicked, this, [=](QWidget *widget) { |
| 162 |
if (widget == widget3) { |
| 163 |
if (widget3Label3->isVisible()) |
| 164 |
widget3Label3->hide(); |
| 165 |
else |
| 166 |
widget3Label3->show(); |
| 167 |
} |
| 168 |
if (widget == widget4) { |
| 169 |
if (widget6->isVisible()) |
| 170 |
widget6->hide(); |
| 171 |
else |
| 172 |
widget6->show(); |
| 173 |
} |
| 174 |
}); |
| 175 |
|
| 176 |
connect(widget3btn, &KBorderlessButton::clicked, this, [=]() { |
| 177 |
if (widget5->isVisible()) |
| 178 |
widget5->hide(); |
| 179 |
else |
| 180 |
widget5->show(); |
| 181 |
}); |
| 182 |
vmainLayout->addWidget(networkLabel); |
| 183 |
vmainLayout->addWidget(back); |
| 184 |
vmainLayout->addWidget(back1); |
| 185 |
vmainLayout->addStretch(); |
| 186 |
} |
| 187 |
|
| 188 |
Widget::~Widget() |
| 189 |
{ |
| 190 |
} |