| 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: Sisheng He <[email protected]> |
| 20 |
* |
| 21 |
*/ |
| 22 |
|
| 23 |
#include "widget.h" |
| 24 |
|
| 25 |
#include "ktabbar.h" |
| 26 |
#include <QBoxLayout> |
| 27 |
#include <QSlider> |
| 28 |
#include <QTabWidget> |
| 29 |
|
| 30 |
Widget::Widget(QWidget *parent) |
| 31 |
: KWidget(parent) |
| 32 |
{ |
| 33 |
initUI(this); |
| 34 |
} |
| 35 |
|
| 36 |
void Widget::initUI(QWidget *parent) |
| 37 |
{ |
| 38 |
setMinimumWidth(900); |
| 39 |
KPushButtonFrame *pushbutton = new KPushButtonFrame(tr("pushbutton frame")); |
| 40 |
pushbutton->pushButton()->setText(tr("click")); |
| 41 |
|
| 42 |
KSwitchButtonFrame *switchbutton = new KSwitchButtonFrame(tr("switchbutton frame")); |
| 43 |
connect(switchbutton->switchButton(), &KSwitchButton::clicked, this, [=](bool checked) { |
| 44 |
pushbutton->setVisible(checked); |
| 45 |
}); |
| 46 |
|
| 47 |
KComboBoxFrame *comboboxbutton = new KComboBoxFrame(tr("comboboxbutton frame")); |
| 48 |
comboboxbutton->comboBox()->addItem(tr("you can add item by addItem")); |
| 49 |
comboboxbutton->comboBox()->addItem(tr("you can add item by addItem1")); |
| 50 |
connect(comboboxbutton->comboBox(), &QComboBox::currentTextChanged, this, [=](QString text) { |
| 51 |
qDebug() << "selected combox item = " << text; |
| 52 |
}); |
| 53 |
|
| 54 |
KLineEditFrame *lineeditbutton = new KLineEditFrame(tr("lineeditbutton frame")); |
| 55 |
|
| 56 |
KSliderFrame *sliderbutton = new KSliderFrame(tr("sliderbutton frame"), false); |
| 57 |
sliderbutton->leftLabel()->setText(tr("small")); |
| 58 |
sliderbutton->rightLabel()->setText(tr("large")); |
| 59 |
sliderbutton->slider()->setRange(1, 10); |
| 60 |
sliderbutton->slider()->setValue(4); |
| 61 |
|
| 62 |
connect(sliderbutton->slider(), &KSlider::valueChanged, this, [=](int value) { |
| 63 |
qDebug() << "slider value = " << value; |
| 64 |
}); |
| 65 |
|
| 66 |
KRadioButtonFrame *radiobutton = new KRadioButtonFrame(tr("radiobutton frame")); |
| 67 |
QRadioButton *button1 = new QRadioButton(tr("radio1")); |
| 68 |
QRadioButton *button2 = new QRadioButton(tr("radio2")); |
| 69 |
QRadioButton *button3 = new QRadioButton(tr("radio3")); |
| 70 |
radiobutton->addButton(button1); |
| 71 |
radiobutton->addButton(button2); |
| 72 |
radiobutton->addButton(button3); |
| 73 |
connect(radiobutton->buttonGroup(), QOverload<QAbstractButton *>::of(&QButtonGroup::buttonClicked), [=](QAbstractButton *button) { |
| 74 |
qDebug() << "radio button = " << button->text(); |
| 75 |
}); |
| 76 |
|
| 77 |
KAddButton *addUserBtn = new KAddButton(); |
| 78 |
addUserBtn->setObjectName("addUser"); |
| 79 |
addUserBtn->setRadiusType(KBaseFrame::BorderRadiusStyle::Around); |
| 80 |
|
| 81 |
QHBoxLayout *addUserHorLayout = new QHBoxLayout(); |
| 82 |
addUserHorLayout->setContentsMargins(0, 0, 0, 0); |
| 83 |
addUserHorLayout->addWidget(addUserBtn); |
| 84 |
|
| 85 |
KBaseFrame *addUserFrame = new KBaseFrame(this, KBaseFrame::BorderRadiusStyle::Around, true); |
| 86 |
addUserFrame->setContentsMargins(0, 0, 0, 0); |
| 87 |
addUserFrame->setObjectName("continue"); |
| 88 |
addUserFrame->setLayout(addUserHorLayout); |
| 89 |
|
| 90 |
KSettingGroup *settinggroup = new KSettingGroup(parent); |
| 91 |
|
| 92 |
settinggroup->addWidget(pushbutton); |
| 93 |
settinggroup->addWidget(switchbutton); |
| 94 |
settinggroup->addWidget(comboboxbutton); |
| 95 |
settinggroup->addWidget(lineeditbutton); |
| 96 |
settinggroup->addWidget(sliderbutton); |
| 97 |
settinggroup->addWidget(radiobutton); |
| 98 |
settinggroup->addWidget(addUserFrame); |
| 99 |
|
| 100 |
QVBoxLayout *mainLayout = new QVBoxLayout(parent); |
| 101 |
mainLayout->addWidget(settinggroup); |
| 102 |
|
| 103 |
this->baseBar()->setLayout(mainLayout); |
| 104 |
this->baseBar()->setBackgroundRole(QPalette::Window); |
| 105 |
|
| 106 |
this->setLayoutType(LayoutType::HorizontalType); |
| 107 |
} |
| 108 |
|
| 109 |
Widget::~Widget() |
| 110 |
{ |
| 111 |
} |