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
161
162
163
164
|
// SPDX-FileCopyrightText: 2021 Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later
#include <QComboBox>
#include <QLabel>
#include <QPushButton>
#include <QVBoxLayout>
#include "dialogs/CreateRoom.h"
#include "Config.h"
#include "ui/TextField.h"
#include "ui/ToggleButton.h"
using namespace dialogs;
CreateRoom::CreateRoom(QWidget *parent)
: QFrame(parent)
{
setAutoFillBackground(true);
setWindowFlags(Qt::Tool | Qt::WindowStaysOnTopHint);
setWindowModality(Qt::WindowModal);
setAttribute(Qt::WA_DeleteOnClose, true);
QFont largeFont;
largeFont.setPointSizeF(largeFont.pointSizeF() * 1.5);
setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
setMinimumHeight(conf::modals::MIN_WIDGET_HEIGHT);
setMinimumWidth(conf::window::minModalWidth);
auto layout = new QVBoxLayout(this);
layout->setSpacing(conf::modals::WIDGET_SPACING);
layout->setContentsMargins(conf::modals::WIDGET_MARGIN,
conf::modals::WIDGET_MARGIN,
conf::modals::WIDGET_MARGIN,
conf::modals::WIDGET_MARGIN);
auto buttonLayout = new QHBoxLayout();
buttonLayout->setSpacing(15);
confirmBtn_ = new QPushButton(tr("Create room"), this);
confirmBtn_->setDefault(true);
cancelBtn_ = new QPushButton(tr("Cancel"), this);
buttonLayout->addStretch(1);
buttonLayout->addWidget(cancelBtn_);
buttonLayout->addWidget(confirmBtn_);
QFont font;
font.setPointSizeF(font.pointSizeF() * 1.3);
nameInput_ = new TextField(this);
nameInput_->setLabel(tr("Name"));
topicInput_ = new TextField(this);
topicInput_->setLabel(tr("Topic"));
aliasInput_ = new TextField(this);
aliasInput_->setLabel(tr("Alias"));
auto visibilityLayout = new QHBoxLayout;
visibilityLayout->setContentsMargins(0, 10, 0, 10);
auto presetLayout = new QHBoxLayout;
presetLayout->setContentsMargins(0, 10, 0, 10);
auto visibilityLabel = new QLabel(tr("Room Visibility"), this);
visibilityCombo_ = new QComboBox(this);
visibilityCombo_->addItem("Private");
visibilityCombo_->addItem("Public");
visibilityLayout->addWidget(visibilityLabel);
visibilityLayout->addWidget(visibilityCombo_, 0, Qt::AlignBottom | Qt::AlignRight);
auto presetLabel = new QLabel(tr("Room Preset"), this);
presetCombo_ = new QComboBox(this);
presetCombo_->addItem("Private Chat");
presetCombo_->addItem("Public Chat");
presetCombo_->addItem("Trusted Private Chat");
presetLayout->addWidget(presetLabel);
presetLayout->addWidget(presetCombo_, 0, Qt::AlignBottom | Qt::AlignRight);
auto directLabel_ = new QLabel(tr("Direct Chat"), this);
directToggle_ = new Toggle(this);
directToggle_->setActiveColor(QColor(0x38, 0xA3, 0xD8));
directToggle_->setInactiveColor(QColor("gray"));
directToggle_->setState(false);
auto directLayout = new QHBoxLayout;
directLayout->setContentsMargins(0, 10, 0, 10);
directLayout->addWidget(directLabel_);
directLayout->addWidget(directToggle_, 0, Qt::AlignBottom | Qt::AlignRight);
layout->addWidget(nameInput_);
layout->addWidget(topicInput_);
layout->addWidget(aliasInput_);
layout->addLayout(visibilityLayout);
layout->addLayout(presetLayout);
layout->addLayout(directLayout);
layout->addLayout(buttonLayout);
connect(confirmBtn_, &QPushButton::clicked, this, [this]() {
request_.name = nameInput_->text().toStdString();
request_.topic = topicInput_->text().toStdString();
request_.room_alias_name = aliasInput_->text().toStdString();
emit createRoom(request_);
clearFields();
emit close();
});
connect(cancelBtn_, &QPushButton::clicked, this, [this]() {
clearFields();
emit close();
});
connect(visibilityCombo_,
static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentTextChanged),
this,
[this](const QString &text) {
if (text == "Private") {
request_.visibility = mtx::common::RoomVisibility::Private;
} else {
request_.visibility = mtx::common::RoomVisibility::Public;
}
});
connect(presetCombo_,
static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentTextChanged),
this,
[this](const QString &text) {
if (text == "Private Chat") {
request_.preset = mtx::requests::Preset::PrivateChat;
} else if (text == "Public Chat") {
request_.preset = mtx::requests::Preset::PublicChat;
} else {
request_.preset = mtx::requests::Preset::TrustedPrivateChat;
}
});
connect(directToggle_, &Toggle::toggled, this, [this](bool isEnabled) {
request_.is_direct = isEnabled;
});
}
void
CreateRoom::clearFields()
{
nameInput_->clear();
topicInput_->clear();
aliasInput_->clear();
}
void
CreateRoom::showEvent(QShowEvent *event)
{
nameInput_->setFocus();
QFrame::showEvent(event);
}
|