nheko/src/dialogs/JoinRoom.cpp

70 lines
1.9 KiB
C++
Raw Normal View History

#include <QLabel>
2018-09-19 21:42:26 +02:00
#include <QPushButton>
2017-12-10 14:22:01 +01:00
#include <QStyleOption>
#include <QVBoxLayout>
#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"
#include "ui/Theme.h"
using namespace dialogs;
JoinRoom::JoinRoom(QWidget *parent)
: 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);
setMinimumWidth(conf::modals::MIN_WIDGET_WIDTH);
setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
auto layout = new QVBoxLayout(this);
layout->setSpacing(conf::modals::WIDGET_SPACING);
layout->setMargin(conf::modals::WIDGET_MARGIN);
auto buttonLayout = new QHBoxLayout();
2018-09-19 21:42:26 +02:00
buttonLayout->setSpacing(15);
2018-09-19 21:42:26 +02:00
confirmBtn_ = new QPushButton(tr("Join"), this);
cancelBtn_ = new QPushButton(tr("Cancel"), this);
cancelBtn_->setDefault(true);
buttonLayout->addStretch(1);
buttonLayout->addWidget(cancelBtn_);
2018-09-19 21:42:26 +02:00
buttonLayout->addWidget(confirmBtn_);
2017-12-10 14:22:01 +01:00
roomInput_ = new TextField(this);
roomInput_->setLabel(tr("Room ID or alias"));
2017-12-10 14:22:01 +01:00
layout->addWidget(roomInput_);
layout->addLayout(buttonLayout);
layout->addStretch(1);
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
}
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());
roomInput_->clear();
}
void
JoinRoom::showEvent(QShowEvent *event)
{
roomInput_->setFocus();
QFrame::showEvent(event);
}