From 0e814da91c8e041897a4c3f7e6e9234bbc7c6f7a Mon Sep 17 00:00:00 2001 From: Konstantinos Sideris Date: Tue, 17 Jul 2018 16:37:25 +0300 Subject: Move all files under src/ --- src/dialogs/CreateRoom.cc | 162 -------------------------------- src/dialogs/CreateRoom.cpp | 162 ++++++++++++++++++++++++++++++++ src/dialogs/CreateRoom.h | 45 +++++++++ src/dialogs/ImageOverlay.cc | 105 --------------------- src/dialogs/ImageOverlay.cpp | 106 +++++++++++++++++++++ src/dialogs/ImageOverlay.h | 47 ++++++++++ src/dialogs/InviteUsers.cc | 157 ------------------------------- src/dialogs/InviteUsers.cpp | 157 +++++++++++++++++++++++++++++++ src/dialogs/InviteUsers.h | 42 +++++++++ src/dialogs/JoinRoom.cc | 69 -------------- src/dialogs/JoinRoom.cpp | 69 ++++++++++++++ src/dialogs/JoinRoom.h | 30 ++++++ src/dialogs/LeaveRoom.cc | 56 ----------- src/dialogs/LeaveRoom.cpp | 56 +++++++++++ src/dialogs/LeaveRoom.h | 25 +++++ src/dialogs/Logout.cc | 74 --------------- src/dialogs/Logout.cpp | 74 +++++++++++++++ src/dialogs/Logout.h | 42 +++++++++ src/dialogs/MemberList.cpp | 10 +- src/dialogs/MemberList.h | 61 ++++++++++++ src/dialogs/PreviewUploadOverlay.cc | 177 ----------------------------------- src/dialogs/PreviewUploadOverlay.cpp | 177 +++++++++++++++++++++++++++++++++++ src/dialogs/PreviewUploadOverlay.h | 61 ++++++++++++ src/dialogs/ReCaptcha.cpp | 10 +- src/dialogs/ReCaptcha.h | 28 ++++++ src/dialogs/ReadReceipts.cc | 134 -------------------------- src/dialogs/ReadReceipts.cpp | 134 ++++++++++++++++++++++++++ src/dialogs/ReadReceipts.h | 58 ++++++++++++ src/dialogs/RoomSettings.cpp | 27 +++--- src/dialogs/RoomSettings.h | 126 +++++++++++++++++++++++++ 30 files changed, 1524 insertions(+), 957 deletions(-) delete mode 100644 src/dialogs/CreateRoom.cc create mode 100644 src/dialogs/CreateRoom.cpp create mode 100644 src/dialogs/CreateRoom.h delete mode 100644 src/dialogs/ImageOverlay.cc create mode 100644 src/dialogs/ImageOverlay.cpp create mode 100644 src/dialogs/ImageOverlay.h delete mode 100644 src/dialogs/InviteUsers.cc create mode 100644 src/dialogs/InviteUsers.cpp create mode 100644 src/dialogs/InviteUsers.h delete mode 100644 src/dialogs/JoinRoom.cc create mode 100644 src/dialogs/JoinRoom.cpp create mode 100644 src/dialogs/JoinRoom.h delete mode 100644 src/dialogs/LeaveRoom.cc create mode 100644 src/dialogs/LeaveRoom.cpp create mode 100644 src/dialogs/LeaveRoom.h delete mode 100644 src/dialogs/Logout.cc create mode 100644 src/dialogs/Logout.cpp create mode 100644 src/dialogs/Logout.h create mode 100644 src/dialogs/MemberList.h delete mode 100644 src/dialogs/PreviewUploadOverlay.cc create mode 100644 src/dialogs/PreviewUploadOverlay.cpp create mode 100644 src/dialogs/PreviewUploadOverlay.h create mode 100644 src/dialogs/ReCaptcha.h delete mode 100644 src/dialogs/ReadReceipts.cc create mode 100644 src/dialogs/ReadReceipts.cpp create mode 100644 src/dialogs/ReadReceipts.h create mode 100644 src/dialogs/RoomSettings.h (limited to 'src/dialogs') diff --git a/src/dialogs/CreateRoom.cc b/src/dialogs/CreateRoom.cc deleted file mode 100644 index 8c2cc641..00000000 --- a/src/dialogs/CreateRoom.cc +++ /dev/null @@ -1,162 +0,0 @@ -#include -#include -#include -#include - -#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); - visibilityLabel->setStyleSheet(QString("font-size: %1px;").arg(conf::dialogs::labelSize)); - 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); - presetLabel->setStyleSheet(QString("font-size: %1px;").arg(conf::dialogs::labelSize)); - 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); - directLabel_->setStyleSheet(QString("font-size: %1px;").arg(conf::dialogs::labelSize)); - directToggle_ = new Toggle(this); - directToggle_->setActiveColor(QColor("#38A3D8")); - directToggle_->setInactiveColor(QColor("gray")); - directToggle_->setState(true); - - 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, [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, [this]() { - emit closing(false, request_); - - clearFields(); - }); - - connect(visibilityCombo_, - static_cast(&QComboBox::activated), - [this](const QString &text) { - if (text == "Private") { - request_.visibility = mtx::requests::Visibility::Private; - } else { - request_.visibility = mtx::requests::Visibility::Public; - } - }); - - connect(presetCombo_, - static_cast(&QComboBox::activated), - [this](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, [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); -} - -void -CreateRoom::showEvent(QShowEvent *event) -{ - nameInput_->setFocus(); - - QFrame::showEvent(event); -} diff --git a/src/dialogs/CreateRoom.cpp b/src/dialogs/CreateRoom.cpp new file mode 100644 index 00000000..3c538b49 --- /dev/null +++ b/src/dialogs/CreateRoom.cpp @@ -0,0 +1,162 @@ +#include +#include +#include +#include + +#include "dialogs/CreateRoom.h" + +#include "Config.h" +#include "ui/FlatButton.h" +#include "ui/TextField.h" +#include "ui/Theme.h" +#include "ui/ToggleButton.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); + visibilityLabel->setStyleSheet(QString("font-size: %1px;").arg(conf::dialogs::labelSize)); + 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); + presetLabel->setStyleSheet(QString("font-size: %1px;").arg(conf::dialogs::labelSize)); + 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); + directLabel_->setStyleSheet(QString("font-size: %1px;").arg(conf::dialogs::labelSize)); + directToggle_ = new Toggle(this); + directToggle_->setActiveColor(QColor("#38A3D8")); + directToggle_->setInactiveColor(QColor("gray")); + directToggle_->setState(true); + + 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, [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, [this]() { + emit closing(false, request_); + + clearFields(); + }); + + connect(visibilityCombo_, + static_cast(&QComboBox::activated), + [this](const QString &text) { + if (text == "Private") { + request_.visibility = mtx::requests::Visibility::Private; + } else { + request_.visibility = mtx::requests::Visibility::Public; + } + }); + + connect(presetCombo_, + static_cast(&QComboBox::activated), + [this](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, [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); +} + +void +CreateRoom::showEvent(QShowEvent *event) +{ + nameInput_->setFocus(); + + QFrame::showEvent(event); +} diff --git a/src/dialogs/CreateRoom.h b/src/dialogs/CreateRoom.h new file mode 100644 index 00000000..46edebdc --- /dev/null +++ b/src/dialogs/CreateRoom.h @@ -0,0 +1,45 @@ +#pragma once + +#include + +#include + +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; + void showEvent(QShowEvent *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 diff --git a/src/dialogs/ImageOverlay.cc b/src/dialogs/ImageOverlay.cc deleted file mode 100644 index 0e4d9d71..00000000 --- a/src/dialogs/ImageOverlay.cc +++ /dev/null @@ -1,105 +0,0 @@ -/* - * 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 - -#include "Utils.h" -#include "dialogs/ImageOverlay.h" - -using namespace dialogs; - -ImageOverlay::ImageOverlay(QPixmap image, QWidget *parent) - : QWidget{parent} - , originalImage_{image} -{ - setMouseTracking(true); - setParent(0); - - setWindowFlags(windowFlags() | Qt::FramelessWindowHint); - - setAttribute(Qt::WA_NoSystemBackground, true); - setAttribute(Qt::WA_TranslucentBackground, true); - setAttribute(Qt::WA_DeleteOnClose, true); - setWindowState(Qt::WindowFullScreen); - - screen_ = QApplication::desktop()->availableGeometry(); - - move(QApplication::desktop()->mapToGlobal(screen_.topLeft())); - resize(screen_.size()); - - connect(this, SIGNAL(closing()), this, SLOT(close())); - - raise(); -} - -void -ImageOverlay::paintEvent(QPaintEvent *event) -{ - Q_UNUSED(event); - - QPainter painter(this); - painter.setRenderHint(QPainter::Antialiasing); - - // Full screen overlay. - painter.fillRect(QRect(0, 0, screen_.width(), screen_.height()), QColor(55, 55, 55, 170)); - - // Left and Right margins - int outer_margin = screen_.width() * 0.12; - int buttonSize = 36; - int margin = outer_margin * 0.1; - - int max_width = screen_.width() - 2 * outer_margin; - int max_height = screen_.height(); - - image_ = utils::scaleDown(max_width, max_height, originalImage_); - - int diff_x = max_width - image_.width(); - int diff_y = max_height - image_.height(); - - content_ = QRect(outer_margin + diff_x / 2, diff_y / 2, image_.width(), image_.height()); - close_button_ = - QRect(screen_.width() - margin - buttonSize, margin, buttonSize, buttonSize); - - // Draw main content_. - painter.drawPixmap(content_, image_); - - // Draw top right corner X. - QPen pen; - pen.setCapStyle(Qt::RoundCap); - pen.setWidthF(5); - pen.setColor("gray"); - - auto center = close_button_.center(); - - painter.setPen(pen); - painter.drawLine(center - QPointF(15, 15), center + QPointF(15, 15)); - painter.drawLine(center + QPointF(15, -15), center - QPointF(15, -15)); -} - -void -ImageOverlay::mousePressEvent(QMouseEvent *event) -{ - if (event->button() != Qt::LeftButton) - return; - - if (close_button_.contains(event->pos())) - emit closing(); - else if (!content_.contains(event->pos())) - emit closing(); -} diff --git a/src/dialogs/ImageOverlay.cpp b/src/dialogs/ImageOverlay.cpp new file mode 100644 index 00000000..7773f97c --- /dev/null +++ b/src/dialogs/ImageOverlay.cpp @@ -0,0 +1,106 @@ +/* + * 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 + +#include "dialogs/ImageOverlay.h" + +#include "Utils.h" + +using namespace dialogs; + +ImageOverlay::ImageOverlay(QPixmap image, QWidget *parent) + : QWidget{parent} + , originalImage_{image} +{ + setMouseTracking(true); + setParent(0); + + setWindowFlags(windowFlags() | Qt::FramelessWindowHint); + + setAttribute(Qt::WA_NoSystemBackground, true); + setAttribute(Qt::WA_TranslucentBackground, true); + setAttribute(Qt::WA_DeleteOnClose, true); + setWindowState(Qt::WindowFullScreen); + + screen_ = QApplication::desktop()->availableGeometry(); + + move(QApplication::desktop()->mapToGlobal(screen_.topLeft())); + resize(screen_.size()); + + connect(this, SIGNAL(closing()), this, SLOT(close())); + + raise(); +} + +void +ImageOverlay::paintEvent(QPaintEvent *event) +{ + Q_UNUSED(event); + + QPainter painter(this); + painter.setRenderHint(QPainter::Antialiasing); + + // Full screen overlay. + painter.fillRect(QRect(0, 0, screen_.width(), screen_.height()), QColor(55, 55, 55, 170)); + + // Left and Right margins + int outer_margin = screen_.width() * 0.12; + int buttonSize = 36; + int margin = outer_margin * 0.1; + + int max_width = screen_.width() - 2 * outer_margin; + int max_height = screen_.height(); + + image_ = utils::scaleDown(max_width, max_height, originalImage_); + + int diff_x = max_width - image_.width(); + int diff_y = max_height - image_.height(); + + content_ = QRect(outer_margin + diff_x / 2, diff_y / 2, image_.width(), image_.height()); + close_button_ = + QRect(screen_.width() - margin - buttonSize, margin, buttonSize, buttonSize); + + // Draw main content_. + painter.drawPixmap(content_, image_); + + // Draw top right corner X. + QPen pen; + pen.setCapStyle(Qt::RoundCap); + pen.setWidthF(5); + pen.setColor("gray"); + + auto center = close_button_.center(); + + painter.setPen(pen); + painter.drawLine(center - QPointF(15, 15), center + QPointF(15, 15)); + painter.drawLine(center + QPointF(15, -15), center - QPointF(15, -15)); +} + +void +ImageOverlay::mousePressEvent(QMouseEvent *event) +{ + if (event->button() != Qt::LeftButton) + return; + + if (close_button_.contains(event->pos())) + emit closing(); + else if (!content_.contains(event->pos())) + emit closing(); +} diff --git a/src/dialogs/ImageOverlay.h b/src/dialogs/ImageOverlay.h new file mode 100644 index 00000000..b4d42acb --- /dev/null +++ b/src/dialogs/ImageOverlay.h @@ -0,0 +1,47 @@ +/* + * 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 . + */ + +#pragma once + +#include +#include +#include + +namespace dialogs { + +class ImageOverlay : public QWidget +{ + Q_OBJECT +public: + ImageOverlay(QPixmap image, QWidget *parent = nullptr); + +protected: + void mousePressEvent(QMouseEvent *event) override; + void paintEvent(QPaintEvent *event) override; + +signals: + void closing(); + +private: + QPixmap originalImage_; + QPixmap image_; + + QRect content_; + QRect close_button_; + QRect screen_; +}; +} // dialogs diff --git a/src/dialogs/InviteUsers.cc b/src/dialogs/InviteUsers.cc deleted file mode 100644 index 71cfdf20..00000000 --- a/src/dialogs/InviteUsers.cc +++ /dev/null @@ -1,157 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -#include "Config.h" -#include "FlatButton.h" -#include "TextField.h" - -#include "InviteeItem.h" -#include "dialogs/InviteUsers.h" - -#include "mtx.hpp" - -using namespace dialogs; - -InviteUsers::InviteUsers(QWidget *parent) - : QFrame(parent) -{ - setMaximumSize(400, 350); - - auto layout = new QVBoxLayout(this); - layout->setSpacing(30); - layout->setMargin(20); - - auto buttonLayout = new QHBoxLayout(); - buttonLayout->setSpacing(0); - buttonLayout->setMargin(0); - - confirmBtn_ = new FlatButton("INVITE", 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); - - inviteeInput_ = new TextField(this); - inviteeInput_->setLabel(tr("User ID to invite")); - - inviteeList_ = new QListWidget; - inviteeList_->setFrameStyle(QFrame::NoFrame); - inviteeList_->setSelectionMode(QAbstractItemView::NoSelection); - inviteeList_->setAttribute(Qt::WA_MacShowFocusRect, 0); - inviteeList_->setSpacing(5); - - errorLabel_ = new QLabel(this); - errorLabel_->setAlignment(Qt::AlignCenter); - font.setPixelSize(12); - errorLabel_->setFont(font); - - layout->addWidget(inviteeInput_); - layout->addWidget(errorLabel_); - layout->addWidget(inviteeList_); - layout->addLayout(buttonLayout); - - connect(inviteeInput_, &TextField::returnPressed, this, &InviteUsers::addUser); - connect(confirmBtn_, &QPushButton::clicked, [this]() { - emit closing(true, invitedUsers()); - - inviteeInput_->clear(); - inviteeList_->clear(); - errorLabel_->hide(); - }); - - connect(cancelBtn_, &QPushButton::clicked, [this]() { - QStringList emptyList; - emit closing(false, emptyList); - - inviteeInput_->clear(); - inviteeList_->clear(); - errorLabel_->hide(); - }); -} - -void -InviteUsers::addUser() -{ - auto user_id = inviteeInput_->text(); - - try { - namespace ids = mtx::identifiers; - auto user = ids::parse(user_id.toStdString()); - - auto item = new QListWidgetItem(inviteeList_); - auto invitee = new InviteeItem(user, this); - - item->setSizeHint(invitee->minimumSizeHint()); - item->setFlags(Qt::NoItemFlags); - item->setTextAlignment(Qt::AlignCenter); - - inviteeList_->setItemWidget(item, invitee); - - connect(invitee, &InviteeItem::removeItem, this, [this, item]() { - emit removeInvitee(item); - }); - - errorLabel_->hide(); - inviteeInput_->clear(); - } catch (std::exception &e) { - errorLabel_->setText(e.what()); - errorLabel_->show(); - } -} - -void -InviteUsers::removeInvitee(QListWidgetItem *item) -{ - int row = inviteeList_->row(item); - auto widget = inviteeList_->takeItem(row); - - inviteeList_->removeItemWidget(widget); -} - -void -InviteUsers::paintEvent(QPaintEvent *) -{ - QStyleOption opt; - opt.init(this); - QPainter p(this); - style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this); -} - -QStringList -InviteUsers::invitedUsers() const -{ - QStringList users; - - for (int ii = 0; ii < inviteeList_->count(); ++ii) { - auto item = inviteeList_->item(ii); - auto widget = inviteeList_->itemWidget(item); - auto invitee = qobject_cast(widget); - - if (invitee) - users << invitee->userID(); - else - qDebug() << "Cast InviteeItem failed"; - } - - return users; -} - -void -InviteUsers::showEvent(QShowEvent *event) -{ - inviteeInput_->setFocus(); - - QFrame::showEvent(event); -} diff --git a/src/dialogs/InviteUsers.cpp b/src/dialogs/InviteUsers.cpp new file mode 100644 index 00000000..bcd163b0 --- /dev/null +++ b/src/dialogs/InviteUsers.cpp @@ -0,0 +1,157 @@ +#include +#include +#include +#include +#include +#include +#include + +#include "dialogs/InviteUsers.h" + +#include "Config.h" +#include "InviteeItem.h" +#include "ui/FlatButton.h" +#include "ui/TextField.h" + +#include "mtx.hpp" + +using namespace dialogs; + +InviteUsers::InviteUsers(QWidget *parent) + : QFrame(parent) +{ + setMaximumSize(400, 350); + + auto layout = new QVBoxLayout(this); + layout->setSpacing(30); + layout->setMargin(20); + + auto buttonLayout = new QHBoxLayout(); + buttonLayout->setSpacing(0); + buttonLayout->setMargin(0); + + confirmBtn_ = new FlatButton("INVITE", 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); + + inviteeInput_ = new TextField(this); + inviteeInput_->setLabel(tr("User ID to invite")); + + inviteeList_ = new QListWidget; + inviteeList_->setFrameStyle(QFrame::NoFrame); + inviteeList_->setSelectionMode(QAbstractItemView::NoSelection); + inviteeList_->setAttribute(Qt::WA_MacShowFocusRect, 0); + inviteeList_->setSpacing(5); + + errorLabel_ = new QLabel(this); + errorLabel_->setAlignment(Qt::AlignCenter); + font.setPixelSize(12); + errorLabel_->setFont(font); + + layout->addWidget(inviteeInput_); + layout->addWidget(errorLabel_); + layout->addWidget(inviteeList_); + layout->addLayout(buttonLayout); + + connect(inviteeInput_, &TextField::returnPressed, this, &InviteUsers::addUser); + connect(confirmBtn_, &QPushButton::clicked, [this]() { + emit closing(true, invitedUsers()); + + inviteeInput_->clear(); + inviteeList_->clear(); + errorLabel_->hide(); + }); + + connect(cancelBtn_, &QPushButton::clicked, [this]() { + QStringList emptyList; + emit closing(false, emptyList); + + inviteeInput_->clear(); + inviteeList_->clear(); + errorLabel_->hide(); + }); +} + +void +InviteUsers::addUser() +{ + auto user_id = inviteeInput_->text(); + + try { + namespace ids = mtx::identifiers; + auto user = ids::parse(user_id.toStdString()); + + auto item = new QListWidgetItem(inviteeList_); + auto invitee = new InviteeItem(user, this); + + item->setSizeHint(invitee->minimumSizeHint()); + item->setFlags(Qt::NoItemFlags); + item->setTextAlignment(Qt::AlignCenter); + + inviteeList_->setItemWidget(item, invitee); + + connect(invitee, &InviteeItem::removeItem, this, [this, item]() { + emit removeInvitee(item); + }); + + errorLabel_->hide(); + inviteeInput_->clear(); + } catch (std::exception &e) { + errorLabel_->setText(e.what()); + errorLabel_->show(); + } +} + +void +InviteUsers::removeInvitee(QListWidgetItem *item) +{ + int row = inviteeList_->row(item); + auto widget = inviteeList_->takeItem(row); + + inviteeList_->removeItemWidget(widget); +} + +void +InviteUsers::paintEvent(QPaintEvent *) +{ + QStyleOption opt; + opt.init(this); + QPainter p(this); + style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this); +} + +QStringList +InviteUsers::invitedUsers() const +{ + QStringList users; + + for (int ii = 0; ii < inviteeList_->count(); ++ii) { + auto item = inviteeList_->item(ii); + auto widget = inviteeList_->itemWidget(item); + auto invitee = qobject_cast(widget); + + if (invitee) + users << invitee->userID(); + else + qDebug() << "Cast InviteeItem failed"; + } + + return users; +} + +void +InviteUsers::showEvent(QShowEvent *event) +{ + inviteeInput_->setFocus(); + + QFrame::showEvent(event); +} diff --git a/src/dialogs/InviteUsers.h b/src/dialogs/InviteUsers.h new file mode 100644 index 00000000..41e6236a --- /dev/null +++ b/src/dialogs/InviteUsers.h @@ -0,0 +1,42 @@ +#pragma once + +#include +#include +#include +#include + +class FlatButton; +class TextField; +class QListWidget; + +namespace dialogs { + +class InviteUsers : public QFrame +{ + Q_OBJECT +public: + explicit InviteUsers(QWidget *parent = nullptr); + +protected: + void paintEvent(QPaintEvent *event) override; + void showEvent(QShowEvent *event) override; + +signals: + void closing(bool isLeaving, QStringList invitees); + +private slots: + void removeInvitee(QListWidgetItem *item); + +private: + void addUser(); + QStringList invitedUsers() const; + + FlatButton *confirmBtn_; + FlatButton *cancelBtn_; + + TextField *inviteeInput_; + QLabel *errorLabel_; + + QListWidget *inviteeList_; +}; +} // dialogs diff --git a/src/dialogs/JoinRoom.cc b/src/dialogs/JoinRoom.cc deleted file mode 100644 index d6e83014..00000000 --- a/src/dialogs/JoinRoom.cc +++ /dev/null @@ -1,69 +0,0 @@ -#include -#include -#include - -#include "Config.h" -#include "FlatButton.h" -#include "TextField.h" -#include "Theme.h" - -#include "dialogs/JoinRoom.h" - -using namespace dialogs; - -JoinRoom::JoinRoom(QWidget *parent) - : QFrame(parent) -{ - setMaximumSize(400, 400); - - auto layout = new QVBoxLayout(this); - layout->setSpacing(30); - layout->setMargin(20); - - auto buttonLayout = new QHBoxLayout(); - buttonLayout->setSpacing(0); - buttonLayout->setMargin(0); - - confirmBtn_ = new FlatButton("JOIN", 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); - - roomInput_ = new TextField(this); - roomInput_->setLabel(tr("Room ID or alias")); - - layout->addWidget(roomInput_); - layout->addLayout(buttonLayout); - - // TODO: input validation with error messages. - connect(confirmBtn_, &QPushButton::clicked, [this]() { - emit closing(true, roomInput_->text()); - roomInput_->clear(); - }); - connect(cancelBtn_, &QPushButton::clicked, [this]() { emit closing(false, ""); }); -} - -void -JoinRoom::paintEvent(QPaintEvent *) -{ - QStyleOption opt; - opt.init(this); - QPainter p(this); - style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this); -} - -void -JoinRoom::showEvent(QShowEvent *event) -{ - roomInput_->setFocus(); - - QFrame::showEvent(event); -} diff --git a/src/dialogs/JoinRoom.cpp b/src/dialogs/JoinRoom.cpp new file mode 100644 index 00000000..05c0f455 --- /dev/null +++ b/src/dialogs/JoinRoom.cpp @@ -0,0 +1,69 @@ +#include +#include +#include + +#include "dialogs/JoinRoom.h" + +#include "Config.h" +#include "ui/FlatButton.h" +#include "ui/TextField.h" +#include "ui/Theme.h" + +using namespace dialogs; + +JoinRoom::JoinRoom(QWidget *parent) + : QFrame(parent) +{ + setMaximumSize(400, 400); + + auto layout = new QVBoxLayout(this); + layout->setSpacing(30); + layout->setMargin(20); + + auto buttonLayout = new QHBoxLayout(); + buttonLayout->setSpacing(0); + buttonLayout->setMargin(0); + + confirmBtn_ = new FlatButton("JOIN", 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); + + roomInput_ = new TextField(this); + roomInput_->setLabel(tr("Room ID or alias")); + + layout->addWidget(roomInput_); + layout->addLayout(buttonLayout); + + // TODO: input validation with error messages. + connect(confirmBtn_, &QPushButton::clicked, [this]() { + emit closing(true, roomInput_->text()); + roomInput_->clear(); + }); + connect(cancelBtn_, &QPushButton::clicked, [this]() { emit closing(false, ""); }); +} + +void +JoinRoom::paintEvent(QPaintEvent *) +{ + QStyleOption opt; + opt.init(this); + QPainter p(this); + style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this); +} + +void +JoinRoom::showEvent(QShowEvent *event) +{ + roomInput_->setFocus(); + + QFrame::showEvent(event); +} diff --git a/src/dialogs/JoinRoom.h b/src/dialogs/JoinRoom.h new file mode 100644 index 00000000..5919f08f --- /dev/null +++ b/src/dialogs/JoinRoom.h @@ -0,0 +1,30 @@ +#pragma once + +#include + +class FlatButton; +class TextField; + +namespace dialogs { + +class JoinRoom : public QFrame +{ + Q_OBJECT +public: + JoinRoom(QWidget *parent = nullptr); + +signals: + void closing(bool isJoining, const QString &room); + +protected: + void paintEvent(QPaintEvent *event) override; + void showEvent(QShowEvent *event) override; + +private: + FlatButton *confirmBtn_; + FlatButton *cancelBtn_; + + TextField *roomInput_; +}; + +} // dialogs diff --git a/src/dialogs/LeaveRoom.cc b/src/dialogs/LeaveRoom.cc deleted file mode 100644 index 508353c6..00000000 --- a/src/dialogs/LeaveRoom.cc +++ /dev/null @@ -1,56 +0,0 @@ -#include -#include -#include - -#include "Config.h" -#include "FlatButton.h" -#include "Theme.h" - -#include "dialogs/LeaveRoom.h" - -using namespace dialogs; - -LeaveRoom::LeaveRoom(QWidget *parent) - : QFrame(parent) -{ - setMaximumSize(400, 400); - - auto layout = new QVBoxLayout(this); - layout->setSpacing(30); - layout->setMargin(20); - - auto buttonLayout = new QHBoxLayout(); - buttonLayout->setSpacing(0); - buttonLayout->setMargin(0); - - confirmBtn_ = new FlatButton("LEAVE", 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); - - auto label = new QLabel(tr("Are you sure you want to leave?"), this); - label->setFont(font); - - layout->addWidget(label); - layout->addLayout(buttonLayout); - - connect(confirmBtn_, &QPushButton::clicked, [this]() { emit closing(true); }); - connect(cancelBtn_, &QPushButton::clicked, [this]() { emit closing(false); }); -} - -void -LeaveRoom::paintEvent(QPaintEvent *) -{ - QStyleOption opt; - opt.init(this); - QPainter p(this); - style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this); -} diff --git a/src/dialogs/LeaveRoom.cpp b/src/dialogs/LeaveRoom.cpp new file mode 100644 index 00000000..9647d19f --- /dev/null +++ b/src/dialogs/LeaveRoom.cpp @@ -0,0 +1,56 @@ +#include +#include +#include + +#include "dialogs/LeaveRoom.h" + +#include "Config.h" +#include "ui/FlatButton.h" +#include "ui/Theme.h" + +using namespace dialogs; + +LeaveRoom::LeaveRoom(QWidget *parent) + : QFrame(parent) +{ + setMaximumSize(400, 400); + + auto layout = new QVBoxLayout(this); + layout->setSpacing(30); + layout->setMargin(20); + + auto buttonLayout = new QHBoxLayout(); + buttonLayout->setSpacing(0); + buttonLayout->setMargin(0); + + confirmBtn_ = new FlatButton("LEAVE", 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); + + auto label = new QLabel(tr("Are you sure you want to leave?"), this); + label->setFont(font); + + layout->addWidget(label); + layout->addLayout(buttonLayout); + + connect(confirmBtn_, &QPushButton::clicked, [this]() { emit closing(true); }); + connect(cancelBtn_, &QPushButton::clicked, [this]() { emit closing(false); }); +} + +void +LeaveRoom::paintEvent(QPaintEvent *) +{ + QStyleOption opt; + opt.init(this); + QPainter p(this); + style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this); +} diff --git a/src/dialogs/LeaveRoom.h b/src/dialogs/LeaveRoom.h new file mode 100644 index 00000000..98e4938d --- /dev/null +++ b/src/dialogs/LeaveRoom.h @@ -0,0 +1,25 @@ +#pragma once + +#include + +class FlatButton; + +namespace dialogs { + +class LeaveRoom : public QFrame +{ + Q_OBJECT +public: + explicit LeaveRoom(QWidget *parent = nullptr); + +protected: + void paintEvent(QPaintEvent *event) override; + +signals: + void closing(bool isLeaving); + +private: + FlatButton *confirmBtn_; + FlatButton *cancelBtn_; +}; +} // dialogs diff --git a/src/dialogs/Logout.cc b/src/dialogs/Logout.cc deleted file mode 100644 index 99913b04..00000000 --- a/src/dialogs/Logout.cc +++ /dev/null @@ -1,74 +0,0 @@ -/* - * 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 -#include - -#include "Config.h" -#include "FlatButton.h" -#include "Theme.h" - -#include "dialogs/Logout.h" - -using namespace dialogs; - -Logout::Logout(QWidget *parent) - : QFrame(parent) -{ - setMaximumSize(400, 400); - - auto layout = new QVBoxLayout(this); - layout->setSpacing(30); - layout->setMargin(20); - - auto buttonLayout = new QHBoxLayout(); - buttonLayout->setSpacing(0); - buttonLayout->setMargin(0); - - confirmBtn_ = new FlatButton("OK", 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); - - auto label = new QLabel(tr("Logout. Are you sure?"), this); - label->setFont(font); - - layout->addWidget(label); - layout->addLayout(buttonLayout); - - connect(confirmBtn_, &QPushButton::clicked, [this]() { emit closing(true); }); - connect(cancelBtn_, &QPushButton::clicked, [this]() { emit closing(false); }); -} - -void -Logout::paintEvent(QPaintEvent *) -{ - QStyleOption opt; - opt.init(this); - QPainter p(this); - style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this); -} diff --git a/src/dialogs/Logout.cpp b/src/dialogs/Logout.cpp new file mode 100644 index 00000000..e2449817 --- /dev/null +++ b/src/dialogs/Logout.cpp @@ -0,0 +1,74 @@ +/* + * 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 +#include + +#include "dialogs/Logout.h" + +#include "Config.h" +#include "ui/FlatButton.h" +#include "ui/Theme.h" + +using namespace dialogs; + +Logout::Logout(QWidget *parent) + : QFrame(parent) +{ + setMaximumSize(400, 400); + + auto layout = new QVBoxLayout(this); + layout->setSpacing(30); + layout->setMargin(20); + + auto buttonLayout = new QHBoxLayout(); + buttonLayout->setSpacing(0); + buttonLayout->setMargin(0); + + confirmBtn_ = new FlatButton("OK", 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); + + auto label = new QLabel(tr("Logout. Are you sure?"), this); + label->setFont(font); + + layout->addWidget(label); + layout->addLayout(buttonLayout); + + connect(confirmBtn_, &QPushButton::clicked, [this]() { emit closing(true); }); + connect(cancelBtn_, &QPushButton::clicked, [this]() { emit closing(false); }); +} + +void +Logout::paintEvent(QPaintEvent *) +{ + QStyleOption opt; + opt.init(this); + QPainter p(this); + style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this); +} diff --git a/src/dialogs/Logout.h b/src/dialogs/Logout.h new file mode 100644 index 00000000..cfefb970 --- /dev/null +++ b/src/dialogs/Logout.h @@ -0,0 +1,42 @@ +/* + * 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 . + */ + +#pragma once + +#include + +class FlatButton; + +namespace dialogs { + +class Logout : public QFrame +{ + Q_OBJECT +public: + explicit Logout(QWidget *parent = nullptr); + +protected: + void paintEvent(QPaintEvent *event) override; + +signals: + void closing(bool isLoggingOut); + +private: + FlatButton *confirmBtn_; + FlatButton *cancelBtn_; +}; +} // dialogs diff --git a/src/dialogs/MemberList.cpp b/src/dialogs/MemberList.cpp index f0f61686..60c2eb0a 100644 --- a/src/dialogs/MemberList.cpp +++ b/src/dialogs/MemberList.cpp @@ -3,15 +3,15 @@ #include #include +#include "dialogs/MemberList.h" + #include "AvatarProvider.h" +#include "Cache.h" #include "ChatPage.h" #include "Config.h" -#include "FlatButton.h" #include "Utils.h" - -#include "Avatar.h" -#include "Cache.h" -#include "dialogs/MemberList.hpp" +#include "ui/Avatar.h" +#include "ui/FlatButton.h" using namespace dialogs; diff --git a/src/dialogs/MemberList.h b/src/dialogs/MemberList.h new file mode 100644 index 00000000..9c3dc5dc --- /dev/null +++ b/src/dialogs/MemberList.h @@ -0,0 +1,61 @@ +#pragma once + +#include +#include + +class Avatar; +class FlatButton; +class QHBoxLayout; +class QLabel; +class QVBoxLayout; + +struct RoomMember; + +template +class QSharedPointer; + +namespace dialogs { + +class MemberItem : public QWidget +{ + Q_OBJECT + +public: + MemberItem(const RoomMember &member, QWidget *parent); + +private: + QHBoxLayout *topLayout_; + QVBoxLayout *textLayout_; + + Avatar *avatar_; + + QLabel *userName_; + QLabel *userId_; +}; + +class MemberList : public QFrame +{ + Q_OBJECT +public: + MemberList(const QString &room_id, QWidget *parent = nullptr); + +public slots: + void addUsers(const std::vector &users); + +protected: + void paintEvent(QPaintEvent *event) override; + void hideEvent(QHideEvent *event) override + { + list_->clear(); + QFrame::hideEvent(event); + } + +private: + void moveButtonToBottom(); + + QString room_id_; + QLabel *topLabel_; + QListWidget *list_; + FlatButton *moreBtn_; +}; +} // dialogs diff --git a/src/dialogs/PreviewUploadOverlay.cc b/src/dialogs/PreviewUploadOverlay.cc deleted file mode 100644 index a3fe4228..00000000 --- a/src/dialogs/PreviewUploadOverlay.cc +++ /dev/null @@ -1,177 +0,0 @@ -/* - * 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 -#include -#include -#include -#include - -#include "Config.h" -#include "Logging.hpp" -#include "MainWindow.h" -#include "Utils.h" - -#include "dialogs/PreviewUploadOverlay.h" - -using namespace dialogs; - -constexpr const char *DEFAULT = "Upload %1?"; -constexpr const char *ERR_MSG = "Failed to load image type '%1'. Continue upload?"; - -PreviewUploadOverlay::PreviewUploadOverlay(QWidget *parent) - : QWidget{parent} - , titleLabel_{this} - , fileName_{this} - , upload_{tr("Upload"), this} - , cancel_{tr("Cancel"), this} -{ - auto hlayout = new QHBoxLayout; - hlayout->addWidget(&upload_); - hlayout->addWidget(&cancel_); - - auto vlayout = new QVBoxLayout{this}; - vlayout->addWidget(&titleLabel_); - vlayout->addWidget(&infoLabel_); - vlayout->addWidget(&fileName_); - vlayout->addLayout(hlayout); - - connect(&upload_, &QPushButton::clicked, [this]() { - emit confirmUpload(data_, mediaType_, fileName_.text()); - close(); - }); - connect(&cancel_, &QPushButton::clicked, this, &PreviewUploadOverlay::close); -} - -void -PreviewUploadOverlay::init() -{ - QSize winsize; - QPoint center; - - auto window = MainWindow::instance(); - if (window) { - winsize = window->frameGeometry().size(); - center = window->frameGeometry().center(); - } else { - nhlog::ui()->warn("unable to retrieve MainWindow's size"); - } - - fileName_.setText(QFileInfo{filePath_}.fileName()); - - setAutoFillBackground(true); - setWindowFlags(Qt::Tool | Qt::WindowStaysOnTopHint); - setWindowModality(Qt::WindowModal); - - titleLabel_.setStyleSheet( - QString{"font-weight: bold; font-size: %1px;"}.arg(conf::headerFontSize)); - titleLabel_.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - titleLabel_.setAlignment(Qt::AlignCenter); - infoLabel_.setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); - fileName_.setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); - fileName_.setAlignment(Qt::AlignCenter); - upload_.setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - cancel_.setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - upload_.setFontSize(conf::btn::fontSize); - cancel_.setFontSize(conf::btn::fontSize); - - if (isImage_) { - infoLabel_.setAlignment(Qt::AlignCenter); - - const auto maxWidth = winsize.width() * 0.8; - const auto maxHeight = winsize.height() * 0.8; - - // Scale image preview to fit into the application window. - infoLabel_.setPixmap(utils::scaleDown(maxWidth, maxHeight, image_)); - move(center.x() - (width() * 0.5), center.y() - (height() * 0.5)); - } else { - infoLabel_.setAlignment(Qt::AlignLeft); - } - infoLabel_.setScaledContents(false); - - show(); -} - -void -PreviewUploadOverlay::setLabels(const QString &type, const QString &mime, uint64_t upload_size) -{ - if (mediaType_ == "image") { - if (!image_.loadFromData(data_)) { - titleLabel_.setText(QString{tr(ERR_MSG)}.arg(type)); - } else { - titleLabel_.setText(QString{tr(DEFAULT)}.arg(mediaType_)); - } - isImage_ = true; - } else { - auto const info = QString{tr("Media type: %1\n" - "Media size: %2\n")} - .arg(mime) - .arg(utils::humanReadableFileSize(upload_size)); - - titleLabel_.setText(QString{tr(DEFAULT)}.arg("file")); - infoLabel_.setText(info); - } -} - -void -PreviewUploadOverlay::setPreview(const QByteArray data, const QString &mime) -{ - auto const &split = mime.split('/'); - auto const &type = split[1]; - - data_ = data; - mediaType_ = split[0]; - filePath_ = "clipboard." + type; - isImage_ = false; - - setLabels(type, mime, data_.size()); - init(); -} - -void -PreviewUploadOverlay::setPreview(const QString &path) -{ - QFile file{path}; - - if (!file.open(QIODevice::ReadOnly)) { - nhlog::ui()->warn("Failed to open file ({}): {}", - path.toStdString(), - file.errorString().toStdString()); - close(); - return; - } - - QMimeDatabase db; - auto mime = db.mimeTypeForFileNameAndData(path, &file); - - if ((data_ = file.readAll()).isEmpty()) { - nhlog::ui()->warn("Failed to read media: {}", file.errorString().toStdString()); - close(); - return; - } - - auto const &split = mime.name().split('/'); - - mediaType_ = split[0]; - filePath_ = file.fileName(); - isImage_ = false; - - setLabels(split[1], mime.name(), data_.size()); - init(); -} diff --git a/src/dialogs/PreviewUploadOverlay.cpp b/src/dialogs/PreviewUploadOverlay.cpp new file mode 100644 index 00000000..7e54ba4e --- /dev/null +++ b/src/dialogs/PreviewUploadOverlay.cpp @@ -0,0 +1,177 @@ +/* + * 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 +#include +#include +#include +#include + +#include "dialogs/PreviewUploadOverlay.h" + +#include "Config.h" +#include "Logging.h" +#include "MainWindow.h" +#include "Utils.h" + +using namespace dialogs; + +constexpr const char *DEFAULT = "Upload %1?"; +constexpr const char *ERR_MSG = "Failed to load image type '%1'. Continue upload?"; + +PreviewUploadOverlay::PreviewUploadOverlay(QWidget *parent) + : QWidget{parent} + , titleLabel_{this} + , fileName_{this} + , upload_{tr("Upload"), this} + , cancel_{tr("Cancel"), this} +{ + auto hlayout = new QHBoxLayout; + hlayout->addWidget(&upload_); + hlayout->addWidget(&cancel_); + + auto vlayout = new QVBoxLayout{this}; + vlayout->addWidget(&titleLabel_); + vlayout->addWidget(&infoLabel_); + vlayout->addWidget(&fileName_); + vlayout->addLayout(hlayout); + + connect(&upload_, &QPushButton::clicked, [this]() { + emit confirmUpload(data_, mediaType_, fileName_.text()); + close(); + }); + connect(&cancel_, &QPushButton::clicked, this, &PreviewUploadOverlay::close); +} + +void +PreviewUploadOverlay::init() +{ + QSize winsize; + QPoint center; + + auto window = MainWindow::instance(); + if (window) { + winsize = window->frameGeometry().size(); + center = window->frameGeometry().center(); + } else { + nhlog::ui()->warn("unable to retrieve MainWindow's size"); + } + + fileName_.setText(QFileInfo{filePath_}.fileName()); + + setAutoFillBackground(true); + setWindowFlags(Qt::Tool | Qt::WindowStaysOnTopHint); + setWindowModality(Qt::WindowModal); + + titleLabel_.setStyleSheet( + QString{"font-weight: bold; font-size: %1px;"}.arg(conf::headerFontSize)); + titleLabel_.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + titleLabel_.setAlignment(Qt::AlignCenter); + infoLabel_.setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); + fileName_.setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); + fileName_.setAlignment(Qt::AlignCenter); + upload_.setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + cancel_.setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); + upload_.setFontSize(conf::btn::fontSize); + cancel_.setFontSize(conf::btn::fontSize); + + if (isImage_) { + infoLabel_.setAlignment(Qt::AlignCenter); + + const auto maxWidth = winsize.width() * 0.8; + const auto maxHeight = winsize.height() * 0.8; + + // Scale image preview to fit into the application window. + infoLabel_.setPixmap(utils::scaleDown(maxWidth, maxHeight, image_)); + move(center.x() - (width() * 0.5), center.y() - (height() * 0.5)); + } else { + infoLabel_.setAlignment(Qt::AlignLeft); + } + infoLabel_.setScaledContents(false); + + show(); +} + +void +PreviewUploadOverlay::setLabels(const QString &type, const QString &mime, uint64_t upload_size) +{ + if (mediaType_ == "image") { + if (!image_.loadFromData(data_)) { + titleLabel_.setText(QString{tr(ERR_MSG)}.arg(type)); + } else { + titleLabel_.setText(QString{tr(DEFAULT)}.arg(mediaType_)); + } + isImage_ = true; + } else { + auto const info = QString{tr("Media type: %1\n" + "Media size: %2\n")} + .arg(mime) + .arg(utils::humanReadableFileSize(upload_size)); + + titleLabel_.setText(QString{tr(DEFAULT)}.arg("file")); + infoLabel_.setText(info); + } +} + +void +PreviewUploadOverlay::setPreview(const QByteArray data, const QString &mime) +{ + auto const &split = mime.split('/'); + auto const &type = split[1]; + + data_ = data; + mediaType_ = split[0]; + filePath_ = "clipboard." + type; + isImage_ = false; + + setLabels(type, mime, data_.size()); + init(); +} + +void +PreviewUploadOverlay::setPreview(const QString &path) +{ + QFile file{path}; + + if (!file.open(QIODevice::ReadOnly)) { + nhlog::ui()->warn("Failed to open file ({}): {}", + path.toStdString(), + file.errorString().toStdString()); + close(); + return; + } + + QMimeDatabase db; + auto mime = db.mimeTypeForFileNameAndData(path, &file); + + if ((data_ = file.readAll()).isEmpty()) { + nhlog::ui()->warn("Failed to read media: {}", file.errorString().toStdString()); + close(); + return; + } + + auto const &split = mime.name().split('/'); + + mediaType_ = split[0]; + filePath_ = file.fileName(); + isImage_ = false; + + setLabels(split[1], mime.name(), data_.size()); + init(); +} diff --git a/src/dialogs/PreviewUploadOverlay.h b/src/dialogs/PreviewUploadOverlay.h new file mode 100644 index 00000000..8d093c7f --- /dev/null +++ b/src/dialogs/PreviewUploadOverlay.h @@ -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 . + */ + +#pragma once + +#include +#include +#include +#include + +#include "ui/FlatButton.h" + +class QMimeData; + +namespace dialogs { + +class PreviewUploadOverlay : public QWidget +{ + Q_OBJECT +public: + PreviewUploadOverlay(QWidget *parent = nullptr); + + void setPreview(const QByteArray data, const QString &mime); + void setPreview(const QString &path); + +signals: + void confirmUpload(const QByteArray data, const QString &media, const QString &filename); + +private: + void init(); + void setLabels(const QString &type, const QString &mime, uint64_t upload_size); + + bool isImage_; + QPixmap image_; + + QByteArray data_; + QString filePath_; + QString mediaType_; + + QLabel titleLabel_; + QLabel infoLabel_; + QLineEdit fileName_; + + FlatButton upload_; + FlatButton cancel_; +}; +} // dialogs diff --git a/src/dialogs/ReCaptcha.cpp b/src/dialogs/ReCaptcha.cpp index ba54268c..9181d588 100644 --- a/src/dialogs/ReCaptcha.cpp +++ b/src/dialogs/ReCaptcha.cpp @@ -4,13 +4,13 @@ #include #include +#include "dialogs/ReCaptcha.h" + #include "Config.h" -#include "FlatButton.h" #include "MatrixClient.h" -#include "RaisedButton.h" -#include "Theme.h" - -#include "dialogs/ReCaptcha.hpp" +#include "ui/FlatButton.h" +#include "ui/RaisedButton.h" +#include "ui/Theme.h" using namespace dialogs; diff --git a/src/dialogs/ReCaptcha.h b/src/dialogs/ReCaptcha.h new file mode 100644 index 00000000..5f47b0eb --- /dev/null +++ b/src/dialogs/ReCaptcha.h @@ -0,0 +1,28 @@ +#pragma once + +#include + +class FlatButton; +class RaisedButton; + +namespace dialogs { + +class ReCaptcha : public QWidget +{ + Q_OBJECT + +public: + ReCaptcha(const QString &session, QWidget *parent = nullptr); + +protected: + void paintEvent(QPaintEvent *event) override; + +signals: + void closing(); + +private: + FlatButton *openCaptchaBtn_; + RaisedButton *confirmBtn_; + RaisedButton *cancelBtn_; +}; +} // dialogs diff --git a/src/dialogs/ReadReceipts.cc b/src/dialogs/ReadReceipts.cc deleted file mode 100644 index a2e1faf2..00000000 --- a/src/dialogs/ReadReceipts.cc +++ /dev/null @@ -1,134 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -#include "ChatPage.h" -#include "Config.h" -#include "Utils.h" - -#include "Avatar.h" -#include "AvatarProvider.h" -#include "Cache.h" -#include "dialogs/ReadReceipts.h" - -using namespace dialogs; - -ReceiptItem::ReceiptItem(QWidget *parent, - const QString &user_id, - uint64_t timestamp, - const QString &room_id) - : QWidget(parent) -{ - topLayout_ = new QHBoxLayout(this); - topLayout_->setMargin(0); - - textLayout_ = new QVBoxLayout; - textLayout_->setMargin(0); - textLayout_->setSpacing(5); - - QFont font; - font.setPixelSize(conf::receipts::font); - - auto displayName = Cache::displayName(room_id, user_id); - - avatar_ = new Avatar(this); - avatar_->setSize(40); - avatar_->setLetter(utils::firstChar(displayName)); - - // If it's a matrix id we use the second letter. - if (displayName.size() > 1 && displayName.at(0) == '@') - avatar_->setLetter(QChar(displayName.at(1))); - - userName_ = new QLabel(displayName, this); - userName_->setFont(font); - - timestamp_ = new QLabel(dateFormat(QDateTime::fromMSecsSinceEpoch(timestamp)), this); - timestamp_->setFont(font); - - textLayout_->addWidget(userName_); - textLayout_->addWidget(timestamp_); - - topLayout_->addWidget(avatar_); - topLayout_->addLayout(textLayout_, 1); - - AvatarProvider::resolve(ChatPage::instance()->currentRoom(), - user_id, - this, - [this](const QImage &img) { avatar_->setImage(img); }); -} - -QString -ReceiptItem::dateFormat(const QDateTime &then) const -{ - auto now = QDateTime::currentDateTime(); - auto days = then.daysTo(now); - - if (days == 0) - return QString("Today %1").arg(then.toString("HH:mm")); - else if (days < 2) - return QString("Yesterday %1").arg(then.toString("HH:mm")); - else if (days < 365) - return then.toString("dd/MM HH:mm"); - - return then.toString("dd/MM/yy"); -} - -ReadReceipts::ReadReceipts(QWidget *parent) - : QFrame(parent) -{ - setMaximumSize(400, 350); - - auto layout = new QVBoxLayout(this); - layout->setSpacing(30); - layout->setMargin(20); - - userList_ = new QListWidget; - userList_->setFrameStyle(QFrame::NoFrame); - userList_->setSelectionMode(QAbstractItemView::NoSelection); - userList_->setAttribute(Qt::WA_MacShowFocusRect, 0); - userList_->setSpacing(5); - - QFont font; - font.setPixelSize(conf::headerFontSize); - - topLabel_ = new QLabel(tr("Read receipts"), this); - topLabel_->setAlignment(Qt::AlignCenter); - topLabel_->setFont(font); - - layout->addWidget(topLabel_); - layout->addWidget(userList_); -} - -void -ReadReceipts::addUsers(const std::multimap> &receipts) -{ - // We want to remove any previous items that have been set. - userList_->clear(); - - for (const auto &receipt : receipts) { - auto user = new ReceiptItem(this, - QString::fromStdString(receipt.second), - receipt.first, - ChatPage::instance()->currentRoom()); - auto item = new QListWidgetItem(userList_); - - item->setSizeHint(user->minimumSizeHint()); - item->setFlags(Qt::NoItemFlags); - item->setTextAlignment(Qt::AlignCenter); - - userList_->setItemWidget(item, user); - } -} - -void -ReadReceipts::paintEvent(QPaintEvent *) -{ - QStyleOption opt; - opt.init(this); - QPainter p(this); - style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this); -} diff --git a/src/dialogs/ReadReceipts.cpp b/src/dialogs/ReadReceipts.cpp new file mode 100644 index 00000000..c27146ac --- /dev/null +++ b/src/dialogs/ReadReceipts.cpp @@ -0,0 +1,134 @@ +#include +#include +#include +#include +#include +#include +#include + +#include "dialogs/ReadReceipts.h" + +#include "AvatarProvider.h" +#include "Cache.h" +#include "ChatPage.h" +#include "Config.h" +#include "Utils.h" +#include "ui/Avatar.h" + +using namespace dialogs; + +ReceiptItem::ReceiptItem(QWidget *parent, + const QString &user_id, + uint64_t timestamp, + const QString &room_id) + : QWidget(parent) +{ + topLayout_ = new QHBoxLayout(this); + topLayout_->setMargin(0); + + textLayout_ = new QVBoxLayout; + textLayout_->setMargin(0); + textLayout_->setSpacing(5); + + QFont font; + font.setPixelSize(conf::receipts::font); + + auto displayName = Cache::displayName(room_id, user_id); + + avatar_ = new Avatar(this); + avatar_->setSize(40); + avatar_->setLetter(utils::firstChar(displayName)); + + // If it's a matrix id we use the second letter. + if (displayName.size() > 1 && displayName.at(0) == '@') + avatar_->setLetter(QChar(displayName.at(1))); + + userName_ = new QLabel(displayName, this); + userName_->setFont(font); + + timestamp_ = new QLabel(dateFormat(QDateTime::fromMSecsSinceEpoch(timestamp)), this); + timestamp_->setFont(font); + + textLayout_->addWidget(userName_); + textLayout_->addWidget(timestamp_); + + topLayout_->addWidget(avatar_); + topLayout_->addLayout(textLayout_, 1); + + AvatarProvider::resolve(ChatPage::instance()->currentRoom(), + user_id, + this, + [this](const QImage &img) { avatar_->setImage(img); }); +} + +QString +ReceiptItem::dateFormat(const QDateTime &then) const +{ + auto now = QDateTime::currentDateTime(); + auto days = then.daysTo(now); + + if (days == 0) + return QString("Today %1").arg(then.toString("HH:mm")); + else if (days < 2) + return QString("Yesterday %1").arg(then.toString("HH:mm")); + else if (days < 365) + return then.toString("dd/MM HH:mm"); + + return then.toString("dd/MM/yy"); +} + +ReadReceipts::ReadReceipts(QWidget *parent) + : QFrame(parent) +{ + setMaximumSize(400, 350); + + auto layout = new QVBoxLayout(this); + layout->setSpacing(30); + layout->setMargin(20); + + userList_ = new QListWidget; + userList_->setFrameStyle(QFrame::NoFrame); + userList_->setSelectionMode(QAbstractItemView::NoSelection); + userList_->setAttribute(Qt::WA_MacShowFocusRect, 0); + userList_->setSpacing(5); + + QFont font; + font.setPixelSize(conf::headerFontSize); + + topLabel_ = new QLabel(tr("Read receipts"), this); + topLabel_->setAlignment(Qt::AlignCenter); + topLabel_->setFont(font); + + layout->addWidget(topLabel_); + layout->addWidget(userList_); +} + +void +ReadReceipts::addUsers(const std::multimap> &receipts) +{ + // We want to remove any previous items that have been set. + userList_->clear(); + + for (const auto &receipt : receipts) { + auto user = new ReceiptItem(this, + QString::fromStdString(receipt.second), + receipt.first, + ChatPage::instance()->currentRoom()); + auto item = new QListWidgetItem(userList_); + + item->setSizeHint(user->minimumSizeHint()); + item->setFlags(Qt::NoItemFlags); + item->setTextAlignment(Qt::AlignCenter); + + userList_->setItemWidget(item, user); + } +} + +void +ReadReceipts::paintEvent(QPaintEvent *) +{ + QStyleOption opt; + opt.init(this); + QPainter p(this); + style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this); +} diff --git a/src/dialogs/ReadReceipts.h b/src/dialogs/ReadReceipts.h new file mode 100644 index 00000000..5e5615df --- /dev/null +++ b/src/dialogs/ReadReceipts.h @@ -0,0 +1,58 @@ +#pragma once + +#include +#include +#include +#include +#include +#include + +class Avatar; + +namespace dialogs { + +class ReceiptItem : public QWidget +{ + Q_OBJECT + +public: + ReceiptItem(QWidget *parent, + const QString &user_id, + uint64_t timestamp, + const QString &room_id); + +private: + QString dateFormat(const QDateTime &then) const; + + QHBoxLayout *topLayout_; + QVBoxLayout *textLayout_; + + Avatar *avatar_; + + QLabel *userName_; + QLabel *timestamp_; +}; + +class ReadReceipts : public QFrame +{ + Q_OBJECT +public: + explicit ReadReceipts(QWidget *parent = nullptr); + +public slots: + void addUsers(const std::multimap> &users); + +protected: + void paintEvent(QPaintEvent *event) override; + void hideEvent(QHideEvent *event) override + { + userList_->clear(); + QFrame::hideEvent(event); + } + +private: + QLabel *topLabel_; + + QListWidget *userList_; +}; +} // dialogs diff --git a/src/dialogs/RoomSettings.cpp b/src/dialogs/RoomSettings.cpp index 3f40ae89..cfb25997 100644 --- a/src/dialogs/RoomSettings.cpp +++ b/src/dialogs/RoomSettings.cpp @@ -1,16 +1,3 @@ -#include "Avatar.h" -#include "ChatPage.h" -#include "Config.h" -#include "FlatButton.h" -#include "Logging.hpp" -#include "MatrixClient.h" -#include "Painter.h" -#include "TextField.h" -#include "Theme.h" -#include "Utils.h" -#include "dialogs/RoomSettings.hpp" -#include "ui/ToggleButton.h" - #include #include #include @@ -22,6 +9,20 @@ #include #include +#include "dialogs/RoomSettings.h" + +#include "ChatPage.h" +#include "Config.h" +#include "Logging.h" +#include "MatrixClient.h" +#include "Utils.h" +#include "ui/Avatar.h" +#include "ui/FlatButton.h" +#include "ui/Painter.h" +#include "ui/TextField.h" +#include "ui/Theme.h" +#include "ui/ToggleButton.h" + using namespace dialogs; using namespace mtx::events; diff --git a/src/dialogs/RoomSettings.h b/src/dialogs/RoomSettings.h new file mode 100644 index 00000000..6cab03b7 --- /dev/null +++ b/src/dialogs/RoomSettings.h @@ -0,0 +1,126 @@ +#pragma once + +#include +#include + +#include "Cache.h" + +class Avatar; +class FlatButton; +class QComboBox; +class QHBoxLayout; +class QLabel; +class QLabel; +class QLayout; +class QPixmap; +class TextField; +class TextField; +class Toggle; + +template +class QSharedPointer; + +class EditModal : public QWidget +{ + Q_OBJECT + +public: + EditModal(const QString &roomId, QWidget *parent = nullptr); + + void setFields(const QString &roomName, const QString &roomTopic); + +signals: + void nameChanged(const QString &roomName); + void nameEventSentCb(const QString &newName); + void topicEventSentCb(); + void stateEventErrorCb(const QString &msg); + +private: + QString roomId_; + QString initialName_; + QString initialTopic_; + + QLabel *errorField_; + + TextField *nameInput_; + TextField *topicInput_; + + FlatButton *applyBtn_; + FlatButton *cancelBtn_; +}; + +class TopSection : public QWidget +{ + Q_OBJECT + + Q_PROPERTY(QColor textColor WRITE setTextColor READ textColor) + +public: + TopSection(const RoomInfo &info, const QImage &img, QWidget *parent = nullptr); + QSize sizeHint() const override; + void setRoomName(const QString &name); + + QColor textColor() const { return textColor_; } + void setTextColor(QColor &color) { textColor_ = color; } + +protected: + void paintEvent(QPaintEvent *event) override; + +private: + static constexpr int AvatarSize = 72; + static constexpr int Padding = 5; + + RoomInfo info_; + QPixmap avatar_; + QColor textColor_; +}; + +namespace dialogs { + +class RoomSettings : public QFrame +{ + Q_OBJECT +public: + RoomSettings(const QString &room_id, QWidget *parent = nullptr); + +signals: + void closing(); + void enableEncryptionError(const QString &msg); + +protected: + void paintEvent(QPaintEvent *event) override; + +private slots: + void saveSettings(); + +private: + static constexpr int AvatarSize = 64; + + void setAvatar(const QImage &img) { avatarImg_ = img; } + void setupEditButton(); + //! Retrieve the current room information from cache. + void retrieveRoomInfo(); + void enableEncryption(); + + //! Whether the user would be able to change the name or the topic of the room. + bool hasEditRights_ = true; + bool usesEncryption_ = false; + QHBoxLayout *editLayout_; + + // Button section + FlatButton *okBtn_; + FlatButton *cancelBtn_; + + FlatButton *editFieldsBtn_; + + RoomInfo info_; + QString room_id_; + QImage avatarImg_; + + TopSection *topSection_; + + QComboBox *accessCombo; + Toggle *encryptionToggle_; +}; + +} // dialogs -- cgit 1.5.1