1 | // SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. |
2 | // |
3 | // SPDX-License-Identifier: GPL-3.0-or-later |
4 | |
5 | #include "adapterconfigure.h" |
6 | |
7 | AdapterConfigure::AdapterConfigure(QWidget *parent) |
8 | : PageWidget (parent) |
9 | , checkBoxProc(new QCheckBox(QCheckBox::tr("Read from Stdout:" ), this)) |
10 | , checkBoxSock(new QCheckBox(QCheckBox::tr("Read from Socket:" ), this)) |
11 | , mainVLayout(new QVBoxLayout(this)) |
12 | , checkBoxGroup(new QButtonGroup(this)) |
13 | , sections({{checkBoxProc, new ProcConfigure(this)}, |
14 | {checkBoxSock, new SockConfigure(this)}}) |
15 | { |
16 | checkBoxGroup->addButton(checkBoxProc); |
17 | checkBoxGroup->addButton(checkBoxSock); |
18 | mainVLayout->addWidget(checkBoxProc); |
19 | mainVLayout->setSpacing(0); |
20 | mainVLayout->addWidget(sections[checkBoxProc]); |
21 | mainVLayout->setSpacing(0); |
22 | mainVLayout->addWidget(checkBoxSock); |
23 | mainVLayout->setSpacing(0); |
24 | mainVLayout->addWidget(sections[checkBoxSock]); |
25 | setLayout(mainVLayout); |
26 | QObject::connect(checkBoxProc, &QCheckBox::clicked, |
27 | this, &AdapterConfigure::clicked); |
28 | QObject::connect(checkBoxSock, &QCheckBox::clicked, |
29 | this, &AdapterConfigure::clicked); |
30 | checkBoxProc->setChecked(true); |
31 | checkBoxProc->clicked(); |
32 | } |
33 | |
34 | void AdapterConfigure::clicked() |
35 | { |
36 | QCheckBox *checkBox = qobject_cast<QCheckBox*> (sender()); |
37 | if (!checkBox) |
38 | return; |
39 | auto itera = sections.begin(); |
40 | while (itera != sections.end()) { |
41 | if (checkBox == itera.key()) { |
42 | itera.value()->setEnabled(true); |
43 | } else { |
44 | itera.value()->setEnabled(false); |
45 | } |
46 | itera ++; |
47 | } |
48 | } |
49 | |
50 | SockConfigure::SockConfigure(QWidget *parent) |
51 | : ProcConfigure(parent) |
52 | , ip (new QLineEdit(this)) |
53 | , port (new QLineEdit(this)) |
54 | { |
55 | ip->setPlaceholderText(QLineEdit::tr("listen backend ip" )); |
56 | port->setPlaceholderText(QLineEdit::tr("listen backend port" )); |
57 | vLayout->addWidget(ip); |
58 | vLayout->addWidget(port); |
59 | } |
60 | |
61 | ProcConfigure::ProcConfigure(QWidget *parent) |
62 | : QWidget(parent) |
63 | , lauchCmd(new QLineEdit(this)) |
64 | , vLayout(new QVBoxLayout(this)) |
65 | { |
66 | lauchCmd->setPlaceholderText( |
67 | QLineEdit::tr("launch program command" )); |
68 | vLayout->addWidget(lauchCmd); |
69 | setLayout(vLayout); |
70 | } |
71 | |