From eae069ad93a6822e8cb96522708115793c01c5d7 Mon Sep 17 00:00:00 2001 From: Konstantinos Sideris Date: Thu, 30 Nov 2017 20:02:46 +0200 Subject: Group emoji and dialogs with namespaces --- src/dialogs/ImageOverlay.cc | 131 ++++++++++++++++++++++++++++++++++++++ src/dialogs/ImageOverlayDialog.cc | 129 ------------------------------------- src/dialogs/JoinRoom.cc | 51 +++++++++++++++ src/dialogs/JoinRoomDialog.cc | 49 -------------- src/dialogs/LeaveRoom.cc | 56 ++++++++++++++++ src/dialogs/LeaveRoomDialog.cc | 54 ---------------- src/dialogs/Logout.cc | 74 +++++++++++++++++++++ src/dialogs/LogoutDialog.cc | 72 --------------------- 8 files changed, 312 insertions(+), 304 deletions(-) create mode 100644 src/dialogs/ImageOverlay.cc delete mode 100644 src/dialogs/ImageOverlayDialog.cc create mode 100644 src/dialogs/JoinRoom.cc delete mode 100644 src/dialogs/JoinRoomDialog.cc create mode 100644 src/dialogs/LeaveRoom.cc delete mode 100644 src/dialogs/LeaveRoomDialog.cc create mode 100644 src/dialogs/Logout.cc delete mode 100644 src/dialogs/LogoutDialog.cc (limited to 'src/dialogs') diff --git a/src/dialogs/ImageOverlay.cc b/src/dialogs/ImageOverlay.cc new file mode 100644 index 00000000..1e30b3ff --- /dev/null +++ b/src/dialogs/ImageOverlay.cc @@ -0,0 +1,131 @@ +/* + * 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" + +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(); +} + +// TODO: Move this into Utils +void +ImageOverlay::scaleImage(int max_width, int max_height) +{ + if (originalImage_.isNull()) + return; + + auto width_ratio = (double)max_width / (double)originalImage_.width(); + auto height_ratio = (double)max_height / (double)originalImage_.height(); + + auto min_aspect_ratio = std::min(width_ratio, height_ratio); + + int final_width = 0; + int final_height = 0; + + if (min_aspect_ratio > 1) { + final_width = originalImage_.width(); + final_height = originalImage_.height(); + } else { + final_width = originalImage_.width() * min_aspect_ratio; + final_height = originalImage_.height() * min_aspect_ratio; + } + + image_ = originalImage_.scaled( + final_width, final_height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); +} + +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(); + + scaleImage(max_width, max_height); + + 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/ImageOverlayDialog.cc b/src/dialogs/ImageOverlayDialog.cc deleted file mode 100644 index ad87d144..00000000 --- a/src/dialogs/ImageOverlayDialog.cc +++ /dev/null @@ -1,129 +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 "dialogs/ImageOverlayDialog.h" - -ImageOverlayDialog::ImageOverlayDialog(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(); -} - -// TODO: Move this into Utils -void -ImageOverlayDialog::scaleImage(int max_width, int max_height) -{ - if (originalImage_.isNull()) - return; - - auto width_ratio = (double)max_width / (double)originalImage_.width(); - auto height_ratio = (double)max_height / (double)originalImage_.height(); - - auto min_aspect_ratio = std::min(width_ratio, height_ratio); - - int final_width = 0; - int final_height = 0; - - if (min_aspect_ratio > 1) { - final_width = originalImage_.width(); - final_height = originalImage_.height(); - } else { - final_width = originalImage_.width() * min_aspect_ratio; - final_height = originalImage_.height() * min_aspect_ratio; - } - - image_ = originalImage_.scaled( - final_width, final_height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); -} - -void -ImageOverlayDialog::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(); - - scaleImage(max_width, max_height); - - 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 -ImageOverlayDialog::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/JoinRoom.cc b/src/dialogs/JoinRoom.cc new file mode 100644 index 00000000..5b874011 --- /dev/null +++ b/src/dialogs/JoinRoom.cc @@ -0,0 +1,51 @@ +#include +#include + +#include "Config.h" +#include "FlatButton.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); + + auto label = new QLabel(tr("Room alias to join:"), this); + label->setFont(font); + + roomAliasEdit_ = new QLineEdit(this); + + layout->addWidget(label); + layout->addWidget(roomAliasEdit_); + layout->addLayout(buttonLayout); + + connect(confirmBtn_, &QPushButton::clicked, [=]() { + emit closing(true, roomAliasEdit_->text()); + }); + connect(cancelBtn_, &QPushButton::clicked, [=]() { emit closing(false, nullptr); }); +} diff --git a/src/dialogs/JoinRoomDialog.cc b/src/dialogs/JoinRoomDialog.cc deleted file mode 100644 index 2cee7ef6..00000000 --- a/src/dialogs/JoinRoomDialog.cc +++ /dev/null @@ -1,49 +0,0 @@ -#include -#include - -#include "Config.h" -#include "FlatButton.h" -#include "Theme.h" - -#include "dialogs/JoinRoomDialog.h" - -JoinRoomDialog::JoinRoomDialog(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); - - auto label = new QLabel(tr("Room alias to join:"), this); - label->setFont(font); - - roomAliasEdit_ = new QLineEdit(this); - - layout->addWidget(label); - layout->addWidget(roomAliasEdit_); - layout->addLayout(buttonLayout); - - connect(confirmBtn_, &QPushButton::clicked, [=]() { - emit closing(true, roomAliasEdit_->text()); - }); - connect(cancelBtn_, &QPushButton::clicked, [=]() { emit closing(false, nullptr); }); -} diff --git a/src/dialogs/LeaveRoom.cc b/src/dialogs/LeaveRoom.cc new file mode 100644 index 00000000..6a8447d4 --- /dev/null +++ b/src/dialogs/LeaveRoom.cc @@ -0,0 +1,56 @@ +#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, [=]() { emit closing(true); }); + connect(cancelBtn_, &QPushButton::clicked, [=]() { 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/LeaveRoomDialog.cc b/src/dialogs/LeaveRoomDialog.cc deleted file mode 100644 index b0d1679f..00000000 --- a/src/dialogs/LeaveRoomDialog.cc +++ /dev/null @@ -1,54 +0,0 @@ -#include -#include -#include - -#include "Config.h" -#include "FlatButton.h" -#include "Theme.h" - -#include "dialogs/LeaveRoomDialog.h" - -LeaveRoomDialog::LeaveRoomDialog(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, [=]() { emit closing(true); }); - connect(cancelBtn_, &QPushButton::clicked, [=]() { emit closing(false); }); -} - -void -LeaveRoomDialog::paintEvent(QPaintEvent *) -{ - QStyleOption opt; - opt.init(this); - QPainter p(this); - style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this); -} diff --git a/src/dialogs/Logout.cc b/src/dialogs/Logout.cc new file mode 100644 index 00000000..f4752b0a --- /dev/null +++ b/src/dialogs/Logout.cc @@ -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 "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, [=]() { emit closing(true); }); + connect(cancelBtn_, &QPushButton::clicked, [=]() { 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/LogoutDialog.cc b/src/dialogs/LogoutDialog.cc deleted file mode 100644 index 73e09745..00000000 --- a/src/dialogs/LogoutDialog.cc +++ /dev/null @@ -1,72 +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/LogoutDialog.h" - -LogoutDialog::LogoutDialog(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, [=]() { emit closing(true); }); - connect(cancelBtn_, &QPushButton::clicked, [=]() { emit closing(false); }); -} - -void -LogoutDialog::paintEvent(QPaintEvent *) -{ - QStyleOption opt; - opt.init(this); - QPainter p(this); - style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this); -} -- cgit 1.5.1