-
Notifications
You must be signed in to change notification settings - Fork 0
/
chatlabel.cpp
161 lines (138 loc) · 4.51 KB
/
chatlabel.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
153
154
155
156
157
158
159
160
#include "chatlabel.h"
/**
* @brief Construct a new Chat Label:: Chat Label object.
*
* Also notifies it's success by a message to stderr.
*
*/
ChatLabel::ChatLabel()
{
qInfo() << "label object constructed";
}
/**
* @brief Destroy the Chat Label:: Chat Label object
*
* Also notifies it's success by a message to stderr.
*
*/
ChatLabel::~ChatLabel()
{
qInfo() << "label object destructed";
}
/**
* @brief method getText() returns string value of each chat labels.
*
* in the class \ref serialize it is needed to read a ChatLabel instance string value which accomplished
* by methods serialize::buildMap and serialize::edit and they inlinely call this method, This must
* NOT TO BE CONFUSED by same method name in class Mainchatbox,
*
* @return QString
*/
QString ChatLabel::getText()
{
return chatlabel->text();
}
/**
* @brief method for edit ChatLabel instance's string values
*
* Once Edit button provided by class Mainchatbox triggered (released), eventually this will be called as a method to
* modify string value followed by editButtonClicked() signal which notifies class \ref serialize and Mainchatbox of
* the ongoing edit incident.
*
* @param newtext
*/
void ChatLabel::edit(QByteArray *newtext)
{
this->chatlabel->clear();
this->chatlabel->setText(*newtext);
}
/**
* @brief Method for early initialization of class ChatLabel and it's components.
*
* which is constructs encapsulated objects
* including push buttons Delete and Edit as well as a Label for displying texts and Ui Layouts
* which organize all corresponding widgets on UI
*
*
* @param input
* @param labelkey
*/
void ChatLabel::init(QByteArray* input, int labelkey)
{
chatlabel = new QLabel;
m_key = labelkey;
chatlabel->setObjectName("label");
delButton = new QPushButton;
delButton->setObjectName("delete button");
editButton = new QPushButton;
editButton->setObjectName("edit button");
parentLayout = new QVBoxLayout(this);
labelLayout = new QHBoxLayout(this);
buttonLayout = new QVBoxLayout(this);
chatlabel->setFixedHeight(50);
delButton->setFixedHeight(24);
editButton->setFixedHeight(24);
parentLayout->setSpacing(6);
labelLayout->setSpacing(5);
buttonLayout->setSpacing(2);
delButton->setParent(this);
delButton->setText("Delete");
delButton->setStyleSheet("QPushButton {background-color: #A3C1DA}");
editButton->setParent(this);
editButton->setText("Edit");
editButton->setStyleSheet("QPushButton {background-color: #A3C1DA}");
chatlabel->setParent(this);
read = new QByteArray;
m_buffer.setBuffer(read);
m_buffer.open(QIODevice::WriteOnly);
m_buffer.write(*input);
m_buffer.close();
qInfo() << "label slot connected.";
qInfo() << "label have red:" << *read;
/*some sort of layouting*/
buttonLayout->addWidget(editButton);
buttonLayout->addWidget(delButton);
// bottuns added to button layout
labelLayout->addWidget(chatlabel,6);
labelLayout->addLayout(buttonLayout,2);
parentLayout->addLayout(labelLayout);
parentLayout->setAlignment(Qt::AlignTop);
setStyleSheet("QLabel { background-color: #f2f1cb }");
qInfo() << "Label geometry set!";
chatlabel->setText(*read);
delete read;
connect (delButton,
SIGNAL(released()),
this,
SLOT(deleteSignalEmitter()));
connect (editButton,
SIGNAL(released()),
this,
SLOT(editSignalEmiter()));
}
/**
* @brief This method emits delButtonClicked() signal.
*
* It then activates slot Widget::deleteLabel slot of main widget and eventually when
* ChatLabel object deleted it emits Widget::labelObjectDeleteRequest signal to notify slot of serialize::remove
* which takes reponsiblity of removing ChatLabel also from binary file.
*
*/
void ChatLabel::deleteSignalEmitter()
{
emit delButtonClicked(this, m_key);
}
/**
* @brief This method emit editButtonClicked() signal once end user click on Edit button on UI.
* and that signal trigers Widget::editLabel slot in main widget where another signal of
* Widget::labelObjectEditRequest emits to notify both classes of Mainchatbox via
* Mainchatbox::editRequestHandler slot and \ref serialize via
* serialize::edit slot both of them take part in editing the chat label either from
* class instance and binary file all connections here handled by
* method Widget::controller in mian widget
*
*/
void ChatLabel::editSignalEmiter()
{
emit editButtonClicked(this, m_key);
}