-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwidget.cpp
More file actions
123 lines (97 loc) · 2.47 KB
/
widget.cpp
File metadata and controls
123 lines (97 loc) · 2.47 KB
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
110
111
112
113
114
115
116
117
118
119
120
#include "widget.h"
#include "item.h"
#include <QToolButton>
#include <QDebug>
Widget::Widget(QWidget *parent)
: QWidget(parent)
{
init();
}
Widget::~Widget()
{
}
void Widget::init()
{
initMember();
initUI();
initSignalSlot();
}
void Widget::initMember()
{
_item = new Item(Item::Super, this);
_btnAdd = createToolButton(":/icon/plus", "Add");
_btnDelete = createToolButton(":/icon/subtract", "Delete");
_btnOk = createToolButton("", "Ok");
_btnCancel = createToolButton("", "Cancel");
}
void Widget::initUI()
{
resize(600, 800);
// Set layout
// Item
_item->setTitle("Root");
_item->move(100, 100);
auto tmpItem = new Item();
tmpItem->setTitle("Middle Item 1");
_item->add(tmpItem);
for (int i = 0; i < 3; ++i)
{
auto supItem = new Item(Item::Super);
supItem->setTitle("Super Item " + QString::number(i));
_item->add(supItem);
for (int j = 0; j < 5; ++j)
{
auto kidItem = new Item();
kidItem->setTitle("Kid Item" + QString::number(j));
supItem->add(kidItem);
}
}
tmpItem = new Item();
tmpItem->setTitle("Middle Item 2");
_item->add(tmpItem);
// Buttons
_btnAdd->move(300, 100);
_btnDelete->move(400, 100);
_btnOk->move(100, 700);
_btnCancel->move(200, 700);
}
void Widget::initSignalSlot()
{
connect(_btnAdd, &QToolButton::clicked, this, &Widget::btnAddSlot);
connect(_btnDelete, &QToolButton::clicked, this, &Widget::btnDeleteSlot);
connect(_btnOk, &QToolButton::clicked, this, &Widget::btnOkSlot);
connect(_btnCancel, &QToolButton::clicked, this, &Widget::btnCancelSlot);
}
QToolButton *Widget::createToolButton(const QString &icon, const QString &txt)
{
auto btn = new QToolButton(this);
if (icon.isEmpty()) btn->setToolButtonStyle(Qt::ToolButtonTextOnly);
else btn->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
btn->setIcon(QIcon(icon));
btn->setText(txt);
btn->resize(80, 30);
btn->setIconSize(QSize(20, 20));
return btn;
}
void Widget::btnAddSlot()
{
auto item = _item->getSelectedItem();
if (!item) return;
qDebug() << "btnAddSlot";
item->addItem();
}
void Widget::btnDeleteSlot()
{
auto item = _item->getSelectedItem();
if (!item) return;
qDebug() << "btnDeleteSlot";
item->destroyMe();
}
void Widget::btnOkSlot()
{
qDebug() << "btnOkSlot";
}
void Widget::btnCancelSlot()
{
qDebug() << "btnCancelSlot";
}