Close dialogs on confirmation

This commit is contained in:
Konstantinos Sideris 2018-09-20 09:59:14 +03:00
parent d4ce7a9dda
commit ecc346a6da
8 changed files with 31 additions and 38 deletions

View file

@ -138,7 +138,7 @@ RegisterPage::RegisterPage(QWidget *parent)
new dialogs::ReCaptcha(QString::fromStdString(session), this); new dialogs::ReCaptcha(QString::fromStdString(session), this);
connect(captchaDialog, connect(captchaDialog,
&dialogs::ReCaptcha::closing, &dialogs::ReCaptcha::confirmation,
this, this,
[this, user, pass, session, captchaDialog]() { [this, user, pass, session, captchaDialog]() {
captchaDialog->close(); captchaDialog->close();

View file

@ -105,6 +105,7 @@ CreateRoom::CreateRoom(QWidget *parent)
emit createRoom(request_); emit createRoom(request_);
clearFields(); clearFields();
emit close();
}); });
connect(cancelBtn_, &QPushButton::clicked, this, [this]() { connect(cancelBtn_, &QPushButton::clicked, this, [this]() {

View file

@ -69,6 +69,8 @@ InviteUsers::InviteUsers(QWidget *parent)
inviteeInput_->clear(); inviteeInput_->clear();
inviteeList_->clear(); inviteeList_->clear();
errorLabel_->hide(); errorLabel_->hide();
emit close();
}); });
connect(cancelBtn_, &QPushButton::clicked, [this]() { connect(cancelBtn_, &QPushButton::clicked, [this]() {

View file

@ -58,6 +58,8 @@ JoinRoom::handleInput()
// TODO: input validation with error messages. // TODO: input validation with error messages.
emit joinRoom(roomInput_->text()); emit joinRoom(roomInput_->text());
roomInput_->clear(); roomInput_->clear();
emit close();
} }
void void

View file

@ -43,6 +43,9 @@ LeaveRoom::LeaveRoom(QWidget *parent)
layout->addWidget(label); layout->addWidget(label);
layout->addLayout(buttonLayout); layout->addLayout(buttonLayout);
connect(confirmBtn_, &QPushButton::clicked, this, &LeaveRoom::leaving); connect(confirmBtn_, &QPushButton::clicked, this, [this]() {
emit leaving();
emit close();
});
connect(cancelBtn_, &QPushButton::clicked, this, &LeaveRoom::close); connect(cancelBtn_, &QPushButton::clicked, this, &LeaveRoom::close);
} }

View file

@ -63,6 +63,9 @@ Logout::Logout(QWidget *parent)
layout->addLayout(buttonLayout); layout->addLayout(buttonLayout);
layout->addStretch(1); layout->addStretch(1);
connect(confirmBtn_, &QPushButton::clicked, this, &Logout::loggingOut); connect(confirmBtn_, &QPushButton::clicked, this, [this]() {
emit loggingOut();
emit close();
});
connect(cancelBtn_, &QPushButton::clicked, this, &Logout::close); connect(cancelBtn_, &QPushButton::clicked, this, &Logout::close);
} }

View file

@ -1,15 +1,13 @@
#include <QDesktopServices> #include <QDesktopServices>
#include <QLabel> #include <QLabel>
#include <QPaintEvent> #include <QPushButton>
#include <QStyleOption> #include <QUrl>
#include <QVBoxLayout> #include <QVBoxLayout>
#include "dialogs/ReCaptcha.h" #include "dialogs/ReCaptcha.h"
#include "Config.h" #include "Config.h"
#include "MatrixClient.h" #include "MatrixClient.h"
#include "ui/FlatButton.h"
#include "ui/RaisedButton.h"
#include "ui/Theme.h" #include "ui/Theme.h"
using namespace dialogs; using namespace dialogs;
@ -20,6 +18,7 @@ ReCaptcha::ReCaptcha(const QString &session, QWidget *parent)
setAutoFillBackground(true); setAutoFillBackground(true);
setWindowFlags(Qt::Tool | Qt::WindowStaysOnTopHint); setWindowFlags(Qt::Tool | Qt::WindowStaysOnTopHint);
setWindowModality(Qt::WindowModal); setWindowModality(Qt::WindowModal);
setAttribute(Qt::WA_DeleteOnClose, true);
auto layout = new QVBoxLayout(this); auto layout = new QVBoxLayout(this);
layout->setSpacing(conf::modals::WIDGET_SPACING); layout->setSpacing(conf::modals::WIDGET_SPACING);
@ -29,22 +28,15 @@ ReCaptcha::ReCaptcha(const QString &session, QWidget *parent)
buttonLayout->setSpacing(8); buttonLayout->setSpacing(8);
buttonLayout->setMargin(0); buttonLayout->setMargin(0);
QFont buttonFont; openCaptchaBtn_ = new QPushButton("Open reCAPTCHA", this);
buttonFont.setPointSizeF(buttonFont.pointSizeF() * conf::modals::BUTTON_TEXT_SIZE_RATIO); cancelBtn_ = new QPushButton(tr("Cancel"), this);
confirmBtn_ = new QPushButton(tr("Confirm"), this);
openCaptchaBtn_ = new FlatButton("OPEN reCAPTCHA", this); confirmBtn_->setDefault(true);
openCaptchaBtn_->setFont(buttonFont);
confirmBtn_ = new RaisedButton(tr("CONFIRM"), this);
confirmBtn_->setFont(buttonFont);
cancelBtn_ = new RaisedButton(tr("CANCEL"), this);
cancelBtn_->setFont(buttonFont);
buttonLayout->addStretch(1); buttonLayout->addStretch(1);
buttonLayout->addWidget(openCaptchaBtn_); buttonLayout->addWidget(openCaptchaBtn_);
buttonLayout->addWidget(confirmBtn_);
buttonLayout->addWidget(cancelBtn_); buttonLayout->addWidget(cancelBtn_);
buttonLayout->addWidget(confirmBtn_);
QFont font; QFont font;
font.setPointSizeF(font.pointSizeF() * conf::modals::LABEL_MEDIUM_SIZE_RATIO); font.setPointSizeF(font.pointSizeF() * conf::modals::LABEL_MEDIUM_SIZE_RATIO);
@ -65,15 +57,9 @@ ReCaptcha::ReCaptcha(const QString &session, QWidget *parent)
QDesktopServices::openUrl(url); QDesktopServices::openUrl(url);
}); });
connect(confirmBtn_, &QPushButton::clicked, this, &dialogs::ReCaptcha::closing); connect(confirmBtn_, &QPushButton::clicked, this, [this]() {
emit confirmation();
emit close();
});
connect(cancelBtn_, &QPushButton::clicked, this, &dialogs::ReCaptcha::close); connect(cancelBtn_, &QPushButton::clicked, this, &dialogs::ReCaptcha::close);
} }
void
ReCaptcha::paintEvent(QPaintEvent *)
{
QStyleOption opt;
opt.init(this);
QPainter p(this);
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
}

View file

@ -2,8 +2,7 @@
#include <QWidget> #include <QWidget>
class FlatButton; class QPushButton;
class RaisedButton;
namespace dialogs { namespace dialogs {
@ -14,15 +13,12 @@ class ReCaptcha : public QWidget
public: public:
ReCaptcha(const QString &session, QWidget *parent = nullptr); ReCaptcha(const QString &session, QWidget *parent = nullptr);
protected:
void paintEvent(QPaintEvent *event) override;
signals: signals:
void closing(); void confirmation();
private: private:
FlatButton *openCaptchaBtn_; QPushButton *openCaptchaBtn_;
RaisedButton *confirmBtn_; QPushButton *confirmBtn_;
RaisedButton *cancelBtn_; QPushButton *cancelBtn_;
}; };
} // dialogs } // dialogs