forked from hANSIc99/Pythonic
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmessagearea.cpp
More file actions
141 lines (106 loc) · 3.53 KB
/
messagearea.cpp
File metadata and controls
141 lines (106 loc) · 3.53 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#include "messagearea.h"
bool OutputWidget::m_styleOption = false;
bool MessageWidget::m_styleOption = false;
MessageArea::MessageArea(const QString &title,
const int maxItems,
QWidget *parent)
: QWidget(parent)
, m_maxItems(maxItems)
{
qCDebug(logC, "called");
setLayout(&m_masterLayout);
m_title.setText(title);
/* Setup clear button */
m_clearButton.setText(QStringLiteral("Clear list"));
m_mainWidget.setLayout(&m_layout);
m_scrollArea.setWidget(&m_mainWidget);
m_scrollArea.setWidgetResizable(true);
m_masterLayout.addWidget(&m_title);
m_masterLayout.addWidget(&m_scrollArea);
m_masterLayout.addWidget(&m_clearButton);
m_layout.addStretch(1);
/* Signals & Slots : Miscellaneous */
connect(&m_clearButton, &QPushButton::clicked,
this, &MessageArea::clearList);
}
void MessageArea::addWidget(QWidget *widget){
m_layout.insertWidget(0, widget);
/* Delete old widget if number of widgets exceeds limit */
QLayoutItem *item;
if((item = m_layout.layout()->takeAt(m_maxItems)) != NULL){
delete item->widget();
delete item;
}
}
void MessageArea::clearList()
{
QLayoutItem *item;
while((item = m_layout.layout()->takeAt(0)) != NULL){
if(!item->isEmpty()){
delete item->widget();
delete item;
}
}
m_layout.addStretch(1);
}
OutputWidget::OutputWidget(
const QString &objectName,
const quint32 id,
const QString ×tamp,
const QString &output,
QWidget *parent)
: QFrame(parent)
{
m_objectName.setText(objectName);
m_id.setText(QString("0x%1").arg(id));
QString sTimestamp = QString("Received: %1").arg(timestamp);
m_timestamp.setText(sTimestamp);
m_output.setText(output);
/* Setup top area: Object name and Id */
m_topArea.setLayout(&m_topAreaLAyout);
m_topAreaLAyout.addWidget(&m_objectName);
m_topAreaLAyout.addStretch(1);
m_topAreaLAyout.addWidget(&m_id);
//m_topAreaLAyout.setSizeConstraint(QLayout::SetMaximumSize);
/* Setup Master Layout */
m_masterLayout.addWidget(&m_topArea);
m_masterLayout.addWidget(&m_timestamp);
m_masterLayout.addWidget(&m_output);
//m_topAreaLAyout.setSizeConstraint(QLayout::SetMaximumSize);
setLayout(&m_masterLayout);
if(m_styleOption ){
setFrameStyle(QFrame::Panel | QFrame::Raised);
} else {
setFrameStyle(QFrame::Panel | QFrame::Sunken);
}
m_styleOption = !m_styleOption;
setMinimumWidth(200);
setMaximumHeight(200);
}
MessageWidget::MessageWidget(const QString &objName,
const quint32 id,
const QString ×tamp,
const QString &msg,
QWidget *parent)
: QFrame(parent)
{
setLayout(&m_layout);
/* Setup top area: Object name and Id */
m_topArea.setLayout(&m_topAreaLAyout);
m_topAreaLAyout.addWidget(&m_timestamp);
m_topAreaLAyout.addStretch(1);
m_topAreaLAyout.addWidget(&m_id);
m_id.setText(QString("0x%1").arg(id));
m_objectName.setText(objName);
m_timestamp.setText(timestamp);
m_message.setText(msg);
m_layout.addWidget(&m_topArea);
m_layout.addWidget(&m_objectName);
m_layout.addWidget(&m_message);
if(m_styleOption ){
setFrameStyle(QFrame::Panel | QFrame::Raised);
} else {
setFrameStyle(QFrame::Panel | QFrame::Sunken);
}
m_styleOption = !m_styleOption;
}