1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
#include "download_add_widget.h"
#include <QComboBox>
#include <QGridLayout>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QSpacerItem>
#include <QSpinBox>
#include "marked_class.h"
download_add_widget::download_add_widget(std::list<module_info> &modules_, QWidget *parent) : QWidget(parent), modules(modules_)
{
QGridLayout *l = new QGridLayout(this);
layout_settings = new QGridLayout; //must be created before first entry added to combobox to avoid crash
QLabel *lbl_modules = new QLabel(tr("module:"));
QComboBox *combo_modules = new QComboBox;
connect(combo_modules, SIGNAL(currentIndexChanged(QString)), this, SLOT(combo_modules_currentIndexChanged(QString)));
QHBoxLayout *layout_modules = new QHBoxLayout;
layout_modules->addWidget(lbl_modules);
QSpacerItem *spacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Expanding);
layout_modules->addItem(spacer);
layout_modules->addWidget(combo_modules);
l->addLayout(layout_modules, 0, 0, 1, 3);
for(auto m : modules)
{
if(m.type() == SERVER_MODULE_TYPE::SERVER_MODULE_DOWNLOADER)
combo_modules->addItem(m.name().c_str());
}
l->addLayout(layout_settings, 1, 0, 1, 3);
spacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Expanding);
l->addItem(spacer, 2, 0, 1, 3);
QPushButton *btn_ok = new QPushButton(tr("Ok")), *btn_cancel = new QPushButton(tr("Cancel"));
connect(btn_ok, SIGNAL(clicked(bool)), this, SLOT(btn_ok_clicked()));
connect(btn_cancel, SIGNAL(clicked(bool)), this, SLOT(btn_cancel_clicked()));
QHBoxLayout *layout_buttons = new QHBoxLayout;
layout_buttons->addWidget(btn_ok);
spacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Expanding);
layout_buttons->addItem(spacer);
layout_buttons->addWidget(btn_cancel);
l->addLayout(layout_buttons, 3, 0, 1, 3);
setLayout(l);
}
void download_add_widget::combo_modules_currentIndexChanged(QString module)
{
for (QLayoutItem *item = layout_settings->takeAt(0); item != 0; item = layout_settings->takeAt(0))
delete item;
int row = 0;
for(auto m : modules)
{
if(m.name().c_str() == module)
{
for(auto ui : m.download_creation_ui())
{
if(ui.type() == MODULE_UI_ELEMENT_TYPE::UI_STR || ui.type() == MODULE_UI_ELEMENT_TYPE::UI_INTEGER)
{
QLabel *l = new QLabel(ui.name().c_str());
layout_settings->addWidget(l, row, 0);
QSpacerItem *spacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Expanding);
layout_settings->addItem(spacer, row, 1);
switch(ui.type())
{
case MODULE_UI_ELEMENT_TYPE::UI_STR:
{
marked_class<QLineEdit> *edit = new marked_class<QLineEdit>;
edit->set_mark(ui.id());
layout_settings->addWidget(edit, row, 2);
}
break;
case MODULE_UI_ELEMENT_TYPE::UI_INTEGER:
{
marked_class<QSpinBox> *edit = new marked_class<QSpinBox>;
edit->set_mark(ui.id());
layout_settings->addWidget(edit, row, 2);
}
break;
default:
break;
}
++row;
}
}
}
}
}
void download_add_widget::btn_ok_clicked()
{
}
void download_add_widget::btn_cancel_clicked()
{
close();
deleteLater(); //?
}
|