2017-12-12 00:00:37 +03:00
|
|
|
#include <QComboBox>
|
|
|
|
#include <QLabel>
|
2018-09-19 22:42:26 +03:00
|
|
|
#include <QPushButton>
|
2017-12-12 00:00:37 +03:00
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
|
|
|
#include "dialogs/CreateRoom.h"
|
|
|
|
|
2018-07-17 16:37:25 +03:00
|
|
|
#include "Config.h"
|
|
|
|
#include "ui/TextField.h"
|
|
|
|
#include "ui/ToggleButton.h"
|
|
|
|
|
2017-12-12 00:00:37 +03:00
|
|
|
using namespace dialogs;
|
|
|
|
|
|
|
|
CreateRoom::CreateRoom(QWidget *parent)
|
|
|
|
: QFrame(parent)
|
|
|
|
{
|
2018-09-19 22:42:26 +03:00
|
|
|
setAutoFillBackground(true);
|
|
|
|
setWindowFlags(Qt::Tool | Qt::WindowStaysOnTopHint);
|
|
|
|
setWindowModality(Qt::WindowModal);
|
|
|
|
setAttribute(Qt::WA_DeleteOnClose, true);
|
|
|
|
|
2018-09-30 13:24:36 +03:00
|
|
|
QFont largeFont;
|
|
|
|
largeFont.setPointSizeF(largeFont.pointSizeF() * 1.5);
|
2018-08-11 17:55:44 +03:00
|
|
|
|
2018-07-22 18:03:12 +03:00
|
|
|
setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
|
2018-08-11 17:55:44 +03:00
|
|
|
setMinimumHeight(conf::modals::MIN_WIDGET_HEIGHT);
|
2018-09-30 13:24:36 +03:00
|
|
|
setMinimumWidth(QFontMetrics(largeFont).averageCharWidth() * 30 -
|
2018-08-11 17:55:44 +03:00
|
|
|
2 * conf::modals::WIDGET_MARGIN);
|
2017-12-12 00:00:37 +03:00
|
|
|
|
|
|
|
auto layout = new QVBoxLayout(this);
|
2018-07-22 18:03:12 +03:00
|
|
|
layout->setSpacing(conf::modals::WIDGET_SPACING);
|
|
|
|
layout->setMargin(conf::modals::WIDGET_MARGIN);
|
2017-12-12 00:00:37 +03:00
|
|
|
|
|
|
|
auto buttonLayout = new QHBoxLayout();
|
2018-09-19 22:42:26 +03:00
|
|
|
buttonLayout->setSpacing(15);
|
2017-12-12 00:00:37 +03:00
|
|
|
|
2018-09-19 22:42:26 +03:00
|
|
|
confirmBtn_ = new QPushButton(tr("Create room"), this);
|
2018-09-20 08:52:31 +03:00
|
|
|
confirmBtn_->setDefault(true);
|
|
|
|
cancelBtn_ = new QPushButton(tr("Cancel"), this);
|
2017-12-12 00:00:37 +03:00
|
|
|
|
|
|
|
buttonLayout->addStretch(1);
|
|
|
|
buttonLayout->addWidget(cancelBtn_);
|
2018-09-19 22:42:26 +03:00
|
|
|
buttonLayout->addWidget(confirmBtn_);
|
2017-12-12 00:00:37 +03:00
|
|
|
|
|
|
|
QFont font;
|
2018-09-30 13:24:36 +03:00
|
|
|
font.setPointSizeF(font.pointSizeF() * 1.3);
|
2017-12-12 00:00:37 +03:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2017-12-21 15:36:05 +03:00
|
|
|
auto visibilityLabel = new QLabel(tr("Room Visibility"), this);
|
2018-07-22 18:03:12 +03:00
|
|
|
visibilityCombo_ = new QComboBox(this);
|
2017-12-12 00:00:37 +03:00
|
|
|
visibilityCombo_->addItem("Private");
|
|
|
|
visibilityCombo_->addItem("Public");
|
|
|
|
|
|
|
|
visibilityLayout->addWidget(visibilityLabel);
|
|
|
|
visibilityLayout->addWidget(visibilityCombo_, 0, Qt::AlignBottom | Qt::AlignRight);
|
|
|
|
|
2017-12-21 15:36:05 +03:00
|
|
|
auto presetLabel = new QLabel(tr("Room Preset"), this);
|
2018-07-22 18:03:12 +03:00
|
|
|
presetCombo_ = new QComboBox(this);
|
2017-12-12 00:00:37 +03:00
|
|
|
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);
|
2018-07-22 18:03:12 +03:00
|
|
|
directToggle_ = new Toggle(this);
|
2017-12-12 00:00:37 +03:00
|
|
|
directToggle_->setActiveColor(QColor("#38A3D8"));
|
|
|
|
directToggle_->setInactiveColor(QColor("gray"));
|
|
|
|
directToggle_->setState(true);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2018-02-20 18:09:11 +03:00
|
|
|
connect(confirmBtn_, &QPushButton::clicked, this, [this]() {
|
2017-12-12 00:00:37 +03:00
|
|
|
request_.name = nameInput_->text().toStdString();
|
|
|
|
request_.topic = topicInput_->text().toStdString();
|
|
|
|
request_.room_alias_name = aliasInput_->text().toStdString();
|
|
|
|
|
2018-09-19 22:42:26 +03:00
|
|
|
emit createRoom(request_);
|
2017-12-12 00:00:37 +03:00
|
|
|
|
|
|
|
clearFields();
|
2018-09-20 09:59:14 +03:00
|
|
|
emit close();
|
2017-12-12 00:00:37 +03:00
|
|
|
});
|
|
|
|
|
2018-02-20 18:09:11 +03:00
|
|
|
connect(cancelBtn_, &QPushButton::clicked, this, [this]() {
|
2017-12-12 00:00:37 +03:00
|
|
|
clearFields();
|
2018-09-19 22:42:26 +03:00
|
|
|
emit close();
|
2017-12-12 00:00:37 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
connect(visibilityCombo_,
|
|
|
|
static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::activated),
|
2018-02-20 18:09:11 +03:00
|
|
|
[this](const QString &text) {
|
2017-12-12 00:00:37 +03:00
|
|
|
if (text == "Private") {
|
|
|
|
request_.visibility = mtx::requests::Visibility::Private;
|
|
|
|
} else {
|
|
|
|
request_.visibility = mtx::requests::Visibility::Public;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
connect(presetCombo_,
|
|
|
|
static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::activated),
|
2018-02-20 18:09:11 +03:00
|
|
|
[this](const QString &text) {
|
2017-12-12 00:00:37 +03:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-02-20 18:09:11 +03:00
|
|
|
connect(directToggle_, &Toggle::toggled, this, [this](bool isDisabled) {
|
2017-12-12 00:00:37 +03:00
|
|
|
request_.is_direct = !isDisabled;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CreateRoom::clearFields()
|
|
|
|
{
|
|
|
|
nameInput_->clear();
|
|
|
|
topicInput_->clear();
|
|
|
|
aliasInput_->clear();
|
|
|
|
}
|
|
|
|
|
2018-01-16 23:50:47 +03:00
|
|
|
void
|
|
|
|
CreateRoom::showEvent(QShowEvent *event)
|
|
|
|
{
|
|
|
|
nameInput_->setFocus();
|
|
|
|
|
|
|
|
QFrame::showEvent(event);
|
|
|
|
}
|