diff --git a/CMakeLists.txt b/CMakeLists.txt index a1342e8f..6d1bf0ea 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -86,6 +86,7 @@ set(SRC_FILES src/InputValidator.cc src/Login.cc src/LoginPage.cc + src/LoginSettings.cc src/MainWindow.cc src/MatrixClient.cc src/Profile.cc @@ -164,6 +165,7 @@ qt5_wrap_cpp(MOC_HEADERS include/TimelineView.h include/TimelineViewManager.h include/LoginPage.h + include/LoginSettings.h include/MainWindow.h include/MatrixClient.h include/RegisterPage.h diff --git a/include/LoginPage.h b/include/LoginPage.h index 8ed54def..8a44ef7a 100644 --- a/include/LoginPage.h +++ b/include/LoginPage.h @@ -26,7 +26,9 @@ #include "FlatButton.h" #include "InputValidator.h" +#include "LoginSettings.h" #include "MatrixClient.h" +#include "OverlayModal.h" #include "RaisedButton.h" #include "TextField.h" @@ -53,10 +55,14 @@ private slots: // Displays errors produced during the login. void loginError(QString error_message); + // Manipulate settings modal. + void showSettingsModal(); + void closeSettingsModal(const QString &server); + private: QVBoxLayout *top_layout_; - QHBoxLayout *back_layout_; + QHBoxLayout *top_bar_layout_; QHBoxLayout *logo_layout_; QHBoxLayout *button_layout_; @@ -64,6 +70,7 @@ private: QLabel *error_label_; FlatButton *back_button_; + FlatButton *advanced_settings_button_; RaisedButton *login_button_; QWidget *form_widget_; @@ -73,6 +80,10 @@ private: TextField *matrixid_input_; TextField *password_input_; + OverlayModal *settings_modal_; + LoginSettings *login_settings_; + QString custom_domain_; + InputValidator *matrix_id_validator_; // Matrix client API provider. diff --git a/include/LoginSettings.h b/include/LoginSettings.h new file mode 100644 index 00000000..3fc00488 --- /dev/null +++ b/include/LoginSettings.h @@ -0,0 +1,40 @@ +/* + * nheko Copyright (C) 2017 Konstantinos Sideris + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef LOGIN_SETTINGS_H +#define LOGIN_SETTINGS_H + +#include + +#include "FlatButton.h" +#include "TextField.h" + +class LoginSettings : public QFrame +{ + Q_OBJECT +public: + explicit LoginSettings(QWidget *parent = nullptr); + +signals: + void closing(const QString &server); + +private: + TextField *input_; + FlatButton *submit_button_; +}; + +#endif // LOGIN_SETTINGS_H diff --git a/include/ui/OverlayModal.h b/include/ui/OverlayModal.h index aff93d02..d90eccea 100644 --- a/include/ui/OverlayModal.h +++ b/include/ui/OverlayModal.h @@ -50,6 +50,7 @@ private: inline void OverlayModal::setDuration(int duration) { duration_ = duration; + animation_->setDuration(duration_); } inline void OverlayModal::setColor(QColor color) diff --git a/src/LoginPage.cc b/src/LoginPage.cc index 5dbde983..f00f3a28 100644 --- a/src/LoginPage.cc +++ b/src/LoginPage.cc @@ -21,28 +21,43 @@ LoginPage::LoginPage(QSharedPointer client, QWidget *parent) : QWidget(parent) - , client_(client) + , settings_modal_{nullptr} + , login_settings_{nullptr} + , client_{client} { matrix_id_validator_ = new InputValidator(this); top_layout_ = new QVBoxLayout(); - back_layout_ = new QHBoxLayout(); - back_layout_->setSpacing(0); - back_layout_->setContentsMargins(5, 5, -1, -1); + top_bar_layout_ = new QHBoxLayout(); + top_bar_layout_->setSpacing(0); + top_bar_layout_->setMargin(0); back_button_ = new FlatButton(this); back_button_->setMinimumSize(QSize(30, 30)); + back_button_->setForegroundColor("#333333"); back_button_->setCursor(QCursor(Qt::PointingHandCursor)); + advanced_settings_button_ = new FlatButton(this); + advanced_settings_button_->setMinimumSize(QSize(30, 30)); + advanced_settings_button_->setForegroundColor("#333333"); + advanced_settings_button_->setCursor(QCursor(Qt::PointingHandCursor)); + QIcon icon; icon.addFile(":/icons/icons/left-angle.png", QSize(), QIcon::Normal, QIcon::Off); back_button_->setIcon(icon); back_button_->setIconSize(QSize(24, 24)); - back_layout_->addWidget(back_button_, 0, Qt::AlignLeft | Qt::AlignVCenter); - back_layout_->addStretch(1); + QIcon advanced_settings_icon; + advanced_settings_icon.addFile(":/icons/icons/cog.png", QSize(), QIcon::Normal, QIcon::Off); + + advanced_settings_button_->setIcon(advanced_settings_icon); + advanced_settings_button_->setIconSize(QSize(24, 24)); + + top_bar_layout_->addWidget(back_button_, 0, Qt::AlignLeft | Qt::AlignVCenter); + top_bar_layout_->addStretch(1); + top_bar_layout_->addWidget(advanced_settings_button_, 0, Qt::AlignRight | Qt::AlignVCenter); logo_ = new QLabel(this); logo_->setPixmap(QPixmap(":/logos/nheko-128.png")); @@ -64,14 +79,14 @@ LoginPage::LoginPage(QSharedPointer client, QWidget *parent) form_wrapper_->addWidget(form_widget_); form_wrapper_->addStretch(1); - matrixid_input_ = new TextField(); + matrixid_input_ = new TextField(this); matrixid_input_->setTextColor("#333333"); matrixid_input_->setLabel("Matrix ID"); matrixid_input_->setInkColor("#555459"); matrixid_input_->setBackgroundColor("#f9f9f9"); matrixid_input_->setPlaceholderText("e.g @joe:matrix.org"); - password_input_ = new TextField(); + password_input_ = new TextField(this); password_input_->setTextColor("#333333"); password_input_->setLabel("Password"); password_input_->setInkColor("#555459"); @@ -83,7 +98,7 @@ LoginPage::LoginPage(QSharedPointer client, QWidget *parent) button_layout_ = new QHBoxLayout(); button_layout_->setSpacing(0); - button_layout_->setContentsMargins(0, 0, 0, 50); + button_layout_->setContentsMargins(0, 0, 0, 30); login_button_ = new RaisedButton("LOGIN", this); login_button_->setBackgroundColor(QColor("#333333")); @@ -100,7 +115,7 @@ LoginPage::LoginPage(QSharedPointer client, QWidget *parent) error_label_ = new QLabel(this); error_label_->setStyleSheet("color: #E22826; font-size: 11pt;"); - top_layout_->addLayout(back_layout_); + top_layout_->addLayout(top_bar_layout_); top_layout_->addStretch(1); top_layout_->addLayout(logo_layout_); top_layout_->addLayout(form_wrapper_); @@ -116,6 +131,7 @@ LoginPage::LoginPage(QSharedPointer client, QWidget *parent) connect(matrixid_input_, SIGNAL(returnPressed()), login_button_, SLOT(click())); connect(password_input_, SIGNAL(returnPressed()), login_button_, SLOT(click())); connect(client_.data(), SIGNAL(loginError(QString)), this, SLOT(loginError(QString))); + connect(advanced_settings_button_, SIGNAL(clicked()), this, SLOT(showSettingsModal())); matrixid_input_->setValidator(matrix_id_validator_->id_); } @@ -135,18 +151,49 @@ void LoginPage::onLoginButtonClicked() loginError("Empty password"); } else { QString user = matrixid_input_->text().split(":").at(0).split("@").at(1); - QString home_server = matrixid_input_->text().split(":").at(1); QString password = password_input_->text(); + QString home_server = custom_domain_.isEmpty() + ? matrixid_input_->text().split(":").at(1) + : custom_domain_; + client_->setServer(home_server); client_->login(user, password); } } +void LoginPage::showSettingsModal() +{ + if (login_settings_ == nullptr) { + login_settings_ = new LoginSettings(this); + connect(login_settings_, &LoginSettings::closing, this, &LoginPage::closeSettingsModal); + } + + if (settings_modal_ == nullptr) { + settings_modal_ = new OverlayModal(this, login_settings_); + settings_modal_->setDuration(100); + settings_modal_->setColor(QColor(55, 55, 55, 170)); + } + + settings_modal_->fadeIn(); +} + +void LoginPage::closeSettingsModal(const QString &server) +{ + custom_domain_ = server; + settings_modal_->fadeOut(); +} + void LoginPage::reset() { matrixid_input_->clear(); password_input_->clear(); + + settings_modal_->deleteLater(); + login_settings_->deleteLater(); + + login_settings_ = nullptr; + settings_modal_ = nullptr; } void LoginPage::onBackButtonClicked() diff --git a/src/LoginSettings.cc b/src/LoginSettings.cc new file mode 100644 index 00000000..b3725caf --- /dev/null +++ b/src/LoginSettings.cc @@ -0,0 +1,61 @@ +/* + * nheko Copyright (C) 2017 Konstantinos Sideris + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include + +#include "LoginSettings.h" + +LoginSettings::LoginSettings(QWidget *parent) + : QFrame(parent) +{ + setMaximumSize(400, 400); + setStyleSheet("background-color: #f9f9f9"); + + auto layout = new QVBoxLayout(this); + layout->setSpacing(30); + layout->setContentsMargins(20, 20, 20, 10); + + input_ = new TextField(this); + input_->setTextColor("#555459"); + input_->setLabel("Homeserver's domain"); + input_->setInkColor("#333333"); + input_->setBackgroundColor("#f9f9f9"); + input_->setPlaceholderText("e.g matrix.domain.org:3434"); + + submit_button_ = new FlatButton("OK", this); + submit_button_->setBackgroundColor("black"); + submit_button_->setForegroundColor("black"); + submit_button_->setCursor(QCursor(Qt::PointingHandCursor)); + submit_button_->setFontSize(15); + submit_button_->setFixedHeight(50); + submit_button_->setCornerRadius(3); + + auto label = new QLabel("Advanced Settings", this); + label->setStyleSheet("color: #333333"); + + layout->addWidget(label); + layout->addWidget(input_); + layout->addWidget(submit_button_); + + setLayout(layout); + + connect(input_, SIGNAL(returnPressed()), submit_button_, SIGNAL(clicked())); + connect(submit_button_, &QPushButton::clicked, [=]() { + emit closing(input_->text()); + }); +} diff --git a/src/MainWindow.cc b/src/MainWindow.cc index e43cd383..ce9d1110 100644 --- a/src/MainWindow.cc +++ b/src/MainWindow.cc @@ -79,7 +79,7 @@ void MainWindow::removeOverlayProgressBar() progress_modal_->fadeOut(); } - if (progress_modal_ != nullptr) + if (spinner_ != nullptr) spinner_->deleteLater(); progress_modal_ = nullptr;