-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwidget.cpp
152 lines (126 loc) · 4.89 KB
/
mainwidget.cpp
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#include "mainwidget.h"
/**
* @brief Mainwidget class consructor has major role in creating program's widgets.
* This class takes responsiblity of creating and initilization of each child via calling respective constructor
* and init methods of them by pointers to children class objects and setting up this class as their parrents
* in order to have Qt way of memory management .
* This constructor also sets up connections of children classes slot and signals
* as needed for proper functionality of them. and as well as layouts for correct visualization of children widgets
* on the main widget UI. It creats sobjects of children e.g. addButton, ChatLabel, Mainchatbox and \ref serialize
*/
Widget::Widget(QWidget *parent) : QWidget(parent)
{
setFixedWidth(480);
setMinimumHeight(620);
this->setStyleSheet("background-color: grey");
m_add = new addButton;
m_add->init();
m_add->setParent(this);
m_chatbox = new Mainchatbox;
m_chatbox->init();
m_chatbox->setParent(this);
mainLayout = new QVBoxLayout(this);
mainLayout->setSpacing(0);
mainLayout->setAlignment(Qt::AlignTop);
inputBox = new QHBoxLayout(this);
inputBox->setSpacing(0);
inputBox->addWidget(m_chatbox);
inputBox->setAlignment(Qt::AlignTop);
inputBox->addWidget(m_add);
mainLayout->addLayout(inputBox);
m_serializer = new serialize;
QObject::connect(m_serializer,
&serialize::jsonReady,
this,
&Widget::controller);
m_serializer->init();
m_serializer->setParent(this);
QObject::connect(m_add,
&addButton::addButtonClicked,
m_chatbox,
&Mainchatbox::getText);
QObject::connect(m_chatbox,
&Mainchatbox::RetunKeyPressed,
m_chatbox,
&Mainchatbox::getText);
QObject::connect(m_chatbox,
&Mainchatbox::textready,
this,
&Widget::controller);
QObject::connect(this,
&Widget::chatLabelObjectConstructed,
m_serializer,
&serialize::serializer,Qt::UniqueConnection);
QObject::connect(m_chatbox,
&Mainchatbox::editready,
m_serializer,
&serialize::edit,Qt::UniqueConnection);
QObject::connect(this,
&Widget::labelObjectDeleteRequest,
m_serializer,
&serialize::remove,Qt::UniqueConnection);
}
/**
* @brief Destroy the Widget:: Widget object
* Under the hood it has role of calling destrutors of all children widgets in class hierarchy
*/
Widget::~Widget()
{
}
/**
* @brief Controller method is partially an implement for Model View Controller design
* by taking care of children widgets.
*
* It impose proper controlled logics in creating and modifying children classes as well as setting up their connections of signals and slots
* that are explained in details in each respective class documentation. children classes
* including ChatLabel, Mainchatbox and \ref serialize getting managed via this method
* it also handles Edit and Delete requests signals for children classes in charge, e.g.for class \ref serialize
* which has responsibility of creating binary data.
*
*/
void Widget::controller(QByteArray *input, int keycounter)
{
qInfo () << "mainwidget slot connected.";
m_label = new ChatLabel;
m_label->setParent(this);
m_label->init(input, keycounter);
mainLayout->addWidget(m_label); //includes child layouts of labels
mainLayout->setAlignment(Qt::AlignTop);
QObject::connect(m_label,
&ChatLabel::delButtonClicked,
this,
&Widget::deleteLabel);
QObject::connect(m_label,
&ChatLabel::editButtonClicked,
this,
&Widget::editLabel);
QObject::connect(this,
&Widget::labelObjectEditRequest,
m_chatbox,
&Mainchatbox::editRequestHandler,Qt::UniqueConnection);
emit chatLabelObjectConstructed(m_label,keycounter);
}
/**
* @brief Plays initial role in deleting ChatLabels.
*
* This method responds Delete button click incident on UI
*
*/
void Widget::deleteLabel(ChatLabel* choice, int labelkey)
{
delete choice;
qInfo()<< "label with key" << labelkey << "deleted.";
emit labelObjectDeleteRequest(labelkey); //signal for serializer class
}
/**
* @brief Plays initial role in editing ChatLabels.
*
* This method responds Edit button click incident on UI
*
*/
void Widget::editLabel(ChatLabel* choice, int labelkey)
{
emit labelObjectEditRequest(choice, labelkey); // signal to serializer
qInfo()<< "label with key" << labelkey << "wants being edited!.";
qInfo() << "value:" << choice->getText();
}