forked from mirror/nheko
parent
3c5241ccd0
commit
544b623512
@ -0,0 +1,44 @@ |
||||
#pragma once |
||||
|
||||
#include <QFrame> |
||||
|
||||
#include <mtx.hpp> |
||||
|
||||
class FlatButton; |
||||
class TextField; |
||||
class QComboBox; |
||||
class Toggle; |
||||
|
||||
namespace dialogs { |
||||
|
||||
class CreateRoom : public QFrame |
||||
{ |
||||
Q_OBJECT |
||||
public: |
||||
CreateRoom(QWidget *parent = nullptr); |
||||
|
||||
signals: |
||||
void closing(bool isCreating, const mtx::requests::CreateRoom &request); |
||||
|
||||
protected: |
||||
void paintEvent(QPaintEvent *event) override; |
||||
|
||||
private: |
||||
void clearFields(); |
||||
|
||||
QComboBox *visibilityCombo_; |
||||
QComboBox *presetCombo_; |
||||
|
||||
Toggle *directToggle_; |
||||
|
||||
FlatButton *confirmBtn_; |
||||
FlatButton *cancelBtn_; |
||||
|
||||
TextField *nameInput_; |
||||
TextField *topicInput_; |
||||
TextField *aliasInput_; |
||||
|
||||
mtx::requests::CreateRoom request_; |
||||
}; |
||||
|
||||
} // dialogs
|
@ -1 +1 @@ |
||||
Subproject commit 9946ed125e5cc3b2fb425648679ada615c862be3 |
||||
Subproject commit d03a370ffd1bbdd5623afbe9817d1b929bc76cd7 |
@ -0,0 +1,152 @@ |
||||
#include <QComboBox> |
||||
#include <QLabel> |
||||
#include <QStyleOption> |
||||
#include <QVBoxLayout> |
||||
|
||||
#include "Config.h" |
||||
#include "FlatButton.h" |
||||
#include "TextField.h" |
||||
#include "Theme.h" |
||||
#include "ToggleButton.h" |
||||
|
||||
#include "dialogs/CreateRoom.h" |
||||
|
||||
using namespace dialogs; |
||||
|
||||
CreateRoom::CreateRoom(QWidget *parent) |
||||
: QFrame(parent) |
||||
{ |
||||
setMaximumSize(520, 600); |
||||
|
||||
auto layout = new QVBoxLayout(this); |
||||
layout->setSpacing(30); |
||||
layout->setMargin(20); |
||||
|
||||
auto buttonLayout = new QHBoxLayout(); |
||||
buttonLayout->setSpacing(0); |
||||
buttonLayout->setMargin(0); |
||||
|
||||
confirmBtn_ = new FlatButton("CREATE", this); |
||||
confirmBtn_->setFontSize(conf::btn::fontSize); |
||||
|
||||
cancelBtn_ = new FlatButton(tr("CANCEL"), this); |
||||
cancelBtn_->setFontSize(conf::btn::fontSize); |
||||
|
||||
buttonLayout->addStretch(1); |
||||
buttonLayout->addWidget(confirmBtn_); |
||||
buttonLayout->addWidget(cancelBtn_); |
||||
|
||||
QFont font; |
||||
font.setPixelSize(conf::headerFontSize); |
||||
|
||||
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("#38A3D8")); |
||||
directToggle_->setInactiveColor(QColor("gray")); |
||||
directToggle_->setState(true); |
||||
directLabel_->setStyleSheet("font-size: 15px;"); |
||||
|
||||
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, [=]() { |
||||
request_.name = nameInput_->text().toStdString(); |
||||
request_.topic = topicInput_->text().toStdString(); |
||||
request_.room_alias_name = aliasInput_->text().toStdString(); |
||||
|
||||
emit closing(true, request_); |
||||
|
||||
clearFields(); |
||||
}); |
||||
|
||||
connect(cancelBtn_, &QPushButton::clicked, this, [=]() { |
||||
emit closing(false, request_); |
||||
|
||||
clearFields(); |
||||
}); |
||||
|
||||
connect(visibilityCombo_, |
||||
static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::activated), |
||||
[=](const QString &text) { |
||||
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), |
||||
[=](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, [=](bool isDisabled) { |
||||
request_.is_direct = !isDisabled; |
||||
}); |
||||
} |
||||
|
||||
void |
||||
CreateRoom::clearFields() |
||||
{ |
||||
nameInput_->clear(); |
||||
topicInput_->clear(); |
||||
aliasInput_->clear(); |
||||
} |
||||
|
||||
void |
||||
CreateRoom::paintEvent(QPaintEvent *) |
||||
{ |
||||
QStyleOption opt; |
||||
opt.init(this); |
||||
QPainter p(this); |
||||
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this); |
||||
} |
Loading…
Reference in new issue