2017-10-01 18:49:36 +02:00
|
|
|
#include <QLabel>
|
2018-09-19 21:42:26 +02:00
|
|
|
#include <QPushButton>
|
2017-10-01 18:49:36 +02:00
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
2017-11-30 19:02:46 +01:00
|
|
|
#include "dialogs/JoinRoom.h"
|
2017-11-30 12:53:28 +01:00
|
|
|
|
2018-07-17 15:37:25 +02:00
|
|
|
#include "Config.h"
|
|
|
|
#include "ui/TextField.h"
|
|
|
|
|
2017-11-30 19:02:46 +01:00
|
|
|
using namespace dialogs;
|
|
|
|
|
|
|
|
JoinRoom::JoinRoom(QWidget *parent)
|
2017-10-01 18:49:36 +02:00
|
|
|
: QFrame(parent)
|
|
|
|
{
|
2018-09-19 21:42:26 +02:00
|
|
|
setAutoFillBackground(true);
|
|
|
|
setWindowFlags(Qt::Tool | Qt::WindowStaysOnTopHint);
|
|
|
|
setWindowModality(Qt::WindowModal);
|
|
|
|
setAttribute(Qt::WA_DeleteOnClose, true);
|
|
|
|
|
2018-07-22 17:03:12 +02:00
|
|
|
setMinimumWidth(conf::modals::MIN_WIDGET_WIDTH);
|
|
|
|
setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
|
2017-10-01 18:49:36 +02:00
|
|
|
|
|
|
|
auto layout = new QVBoxLayout(this);
|
2018-07-22 17:03:12 +02:00
|
|
|
layout->setSpacing(conf::modals::WIDGET_SPACING);
|
|
|
|
layout->setMargin(conf::modals::WIDGET_MARGIN);
|
2017-10-01 18:49:36 +02:00
|
|
|
|
|
|
|
auto buttonLayout = new QHBoxLayout();
|
2018-09-19 21:42:26 +02:00
|
|
|
buttonLayout->setSpacing(15);
|
2017-10-01 18:49:36 +02:00
|
|
|
|
2018-09-19 21:42:26 +02:00
|
|
|
confirmBtn_ = new QPushButton(tr("Join"), this);
|
2018-09-20 07:52:31 +02:00
|
|
|
confirmBtn_->setDefault(true);
|
|
|
|
cancelBtn_ = new QPushButton(tr("Cancel"), this);
|
2017-10-01 18:49:36 +02:00
|
|
|
|
|
|
|
buttonLayout->addStretch(1);
|
|
|
|
buttonLayout->addWidget(cancelBtn_);
|
2018-09-19 21:42:26 +02:00
|
|
|
buttonLayout->addWidget(confirmBtn_);
|
2017-10-01 18:49:36 +02:00
|
|
|
|
2017-12-10 14:22:01 +01:00
|
|
|
roomInput_ = new TextField(this);
|
|
|
|
roomInput_->setLabel(tr("Room ID or alias"));
|
2017-10-01 18:49:36 +02:00
|
|
|
|
2017-12-10 14:22:01 +01:00
|
|
|
layout->addWidget(roomInput_);
|
2017-10-01 18:49:36 +02:00
|
|
|
layout->addLayout(buttonLayout);
|
2018-07-22 17:03:12 +02:00
|
|
|
layout->addStretch(1);
|
2017-10-01 18:49:36 +02:00
|
|
|
|
2018-07-22 17:03:12 +02:00
|
|
|
connect(roomInput_, &QLineEdit::returnPressed, this, &JoinRoom::handleInput);
|
|
|
|
connect(confirmBtn_, &QPushButton::clicked, this, &JoinRoom::handleInput);
|
2018-09-19 21:42:26 +02:00
|
|
|
connect(cancelBtn_, &QPushButton::clicked, this, &JoinRoom::close);
|
2017-12-10 14:22:01 +01:00
|
|
|
}
|
|
|
|
|
2018-07-22 17:03:12 +02:00
|
|
|
void
|
|
|
|
JoinRoom::handleInput()
|
|
|
|
{
|
|
|
|
if (roomInput_->text().isEmpty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
// TODO: input validation with error messages.
|
2018-09-19 21:42:26 +02:00
|
|
|
emit joinRoom(roomInput_->text());
|
2018-07-22 17:03:12 +02:00
|
|
|
roomInput_->clear();
|
2018-09-20 08:59:14 +02:00
|
|
|
|
|
|
|
emit close();
|
2018-07-22 17:03:12 +02:00
|
|
|
}
|
|
|
|
|
2018-01-16 21:50:47 +01:00
|
|
|
void
|
|
|
|
JoinRoom::showEvent(QShowEvent *event)
|
|
|
|
{
|
|
|
|
roomInput_->setFocus();
|
|
|
|
|
|
|
|
QFrame::showEvent(event);
|
|
|
|
}
|