-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchannel_widget.cpp
67 lines (57 loc) · 2.06 KB
/
channel_widget.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
#include "channel_widget.h"
#include <QPushButton>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QLabel>
#include <QStyle>
#include <QInputDialog>
#include <QListWidget>
// ------------------------------------------------------------------------------------------------------------------
CChannelWidget::CChannelWidget(QWidget* parent, ChannelMetadata metadata)
: QWidget(parent), m_ChannelMetadata(metadata)
{
initUi();
}
void CChannelWidget::updateMetadata(const ChannelMetadata& metadata)
{
m_ChannelMetadata = metadata;
updateUsersUi();
}
void CChannelWidget::initUi()
{
m_Layout = new QVBoxLayout(this);
m_MetadataWidget = new QWidget(this);
m_MetadataLayout = new QHBoxLayout(m_MetadataWidget);
m_NameLabel = new QLabel(m_MetadataWidget);
m_NameLabel->setText(m_ChannelMetadata.channelName);
m_ConnectButton = new QPushButton("Verbinden", m_MetadataWidget);
QObject::connect(m_ConnectButton, &QPushButton::pressed, this, &CChannelWidget::onConnectButtonPressed);
m_MetadataLayout->addWidget(m_NameLabel);
m_MetadataLayout->addWidget(m_ConnectButton);
m_MetadataWidget->setLayout(m_MetadataLayout);
m_Layout->addWidget(m_MetadataWidget);
m_ClientList = new QListWidget(this);
updateUsersUi();
m_Layout->addWidget(m_ClientList);
//m_Layout->addLayout(m_ClientsLayout);
}
void CChannelWidget::updateUsersUi()
{
/*QLayoutItem *wItem;
while ((wItem = m_ClientsLayout->takeAt(0)) != nullptr)
delete wItem;*/
m_ClientList->clear();
for (const UserMetadata &md : m_ChannelMetadata.joinedUsers)
{
qDebug() << "Adding user " << md.username << " to layout in channel " << m_ChannelMetadata.channelName;
m_ClientList->addItem(md.username);
}
}
void CChannelWidget::onConnectButtonPressed()
{
bool ok;
QString password = QInputDialog::getText(this, tr("Passwort erforderlich"),
tr("Passwort:"), QLineEdit::Normal, "", &ok);
if (ok && !password.isEmpty())
joinRequested(m_ChannelMetadata.channelName, password);
}