2017-04-06 02:06:42 +03:00
|
|
|
/*
|
|
|
|
* nheko Copyright (C) 2017 Konstantinos Sideris <siderisk@auth.gr>
|
|
|
|
*
|
|
|
|
* 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 <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2017-12-11 00:59:50 +03:00
|
|
|
#include <QDebug>
|
2017-04-06 02:06:42 +03:00
|
|
|
#include <QStyleOption>
|
|
|
|
|
2017-07-15 17:11:46 +03:00
|
|
|
#include "Config.h"
|
2017-10-01 19:49:36 +03:00
|
|
|
#include "MainWindow.h"
|
2017-04-06 02:06:42 +03:00
|
|
|
#include "TopRoomBar.h"
|
2018-01-12 11:21:53 +03:00
|
|
|
#include "Utils.h"
|
2018-07-17 16:37:25 +03:00
|
|
|
#include "ui/Avatar.h"
|
|
|
|
#include "ui/FlatButton.h"
|
|
|
|
#include "ui/Menu.h"
|
|
|
|
#include "ui/OverlayModal.h"
|
2018-09-26 15:17:14 +03:00
|
|
|
#include "ui/TextLabel.h"
|
2017-04-06 02:06:42 +03:00
|
|
|
|
|
|
|
TopRoomBar::TopRoomBar(QWidget *parent)
|
2017-08-20 13:47:22 +03:00
|
|
|
: QWidget(parent)
|
2017-11-06 00:04:55 +03:00
|
|
|
, buttonSize_{32}
|
2017-04-06 02:06:42 +03:00
|
|
|
{
|
2018-10-04 00:32:13 +03:00
|
|
|
QFont f;
|
|
|
|
f.setPointSizeF(f.pointSizeF());
|
|
|
|
|
|
|
|
const int fontHeight = QFontMetrics(f).height();
|
|
|
|
const int widgetMargin = fontHeight / 3;
|
|
|
|
const int contentHeight = fontHeight * 3;
|
|
|
|
|
|
|
|
setFixedHeight(contentHeight + widgetMargin);
|
2017-08-26 15:36:10 +03:00
|
|
|
|
2018-05-25 16:13:38 +03:00
|
|
|
topLayout_ = new QHBoxLayout(this);
|
2018-10-04 00:32:13 +03:00
|
|
|
topLayout_->setSpacing(widgetMargin);
|
|
|
|
topLayout_->setContentsMargins(
|
|
|
|
2 * widgetMargin, widgetMargin, 2 * widgetMargin, widgetMargin);
|
2017-08-26 15:36:10 +03:00
|
|
|
|
2019-08-26 02:24:56 +03:00
|
|
|
avatar_ = new Avatar(this, fontHeight * 2);
|
2018-01-12 11:21:53 +03:00
|
|
|
avatar_->setLetter("");
|
2017-08-26 15:36:10 +03:00
|
|
|
|
|
|
|
textLayout_ = new QVBoxLayout();
|
|
|
|
textLayout_->setSpacing(0);
|
2018-10-04 00:32:13 +03:00
|
|
|
textLayout_->setMargin(0);
|
2017-08-26 15:36:10 +03:00
|
|
|
|
2018-09-30 13:24:36 +03:00
|
|
|
QFont roomFont;
|
2018-10-04 00:32:13 +03:00
|
|
|
roomFont.setPointSizeF(roomFont.pointSizeF() * 1.1);
|
2018-09-30 13:24:36 +03:00
|
|
|
roomFont.setWeight(QFont::Medium);
|
2017-08-26 15:36:10 +03:00
|
|
|
|
|
|
|
nameLabel_ = new QLabel(this);
|
|
|
|
nameLabel_->setFont(roomFont);
|
2018-05-25 16:13:38 +03:00
|
|
|
nameLabel_->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed);
|
2017-08-26 15:36:10 +03:00
|
|
|
|
2018-09-30 13:24:36 +03:00
|
|
|
QFont descriptionFont;
|
2017-08-26 15:36:10 +03:00
|
|
|
|
2018-09-19 22:42:26 +03:00
|
|
|
topicLabel_ = new TextLabel(this);
|
|
|
|
topicLabel_->setLineWrapMode(QTextEdit::NoWrap);
|
|
|
|
topicLabel_->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
2017-08-26 15:36:10 +03:00
|
|
|
topicLabel_->setFont(descriptionFont);
|
|
|
|
topicLabel_->setTextInteractionFlags(Qt::TextBrowserInteraction);
|
|
|
|
topicLabel_->setOpenExternalLinks(true);
|
2018-05-25 16:13:38 +03:00
|
|
|
topicLabel_->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed);
|
2017-08-26 15:36:10 +03:00
|
|
|
|
|
|
|
textLayout_->addWidget(nameLabel_);
|
|
|
|
textLayout_->addWidget(topicLabel_);
|
|
|
|
|
|
|
|
settingsBtn_ = new FlatButton(this);
|
2018-07-25 23:28:37 +03:00
|
|
|
settingsBtn_->setToolTip(tr("Room options"));
|
2017-08-26 15:36:10 +03:00
|
|
|
settingsBtn_->setFixedSize(buttonSize_, buttonSize_);
|
|
|
|
settingsBtn_->setCornerRadius(buttonSize_ / 2);
|
|
|
|
|
2019-07-22 04:58:11 +03:00
|
|
|
mentionsBtn_ = new FlatButton(this);
|
|
|
|
mentionsBtn_->setToolTip(tr("Mentions"));
|
|
|
|
mentionsBtn_->setFixedSize(buttonSize_, buttonSize_);
|
|
|
|
mentionsBtn_->setCornerRadius(buttonSize_ / 2);
|
|
|
|
|
2017-08-26 15:36:10 +03:00
|
|
|
QIcon settings_icon;
|
2017-10-15 22:08:51 +03:00
|
|
|
settings_icon.addFile(":/icons/icons/ui/vertical-ellipsis.png");
|
2017-08-26 15:36:10 +03:00
|
|
|
settingsBtn_->setIcon(settings_icon);
|
|
|
|
settingsBtn_->setIconSize(QSize(buttonSize_ / 2, buttonSize_ / 2));
|
|
|
|
|
2019-07-22 04:58:11 +03:00
|
|
|
QIcon mentions_icon;
|
|
|
|
mentions_icon.addFile(":/icons/icons/ui/at-solid.svg");
|
|
|
|
mentionsBtn_->setIcon(mentions_icon);
|
|
|
|
mentionsBtn_->setIconSize(QSize(buttonSize_ / 2, buttonSize_ / 2));
|
|
|
|
|
2018-07-01 22:57:14 +03:00
|
|
|
backBtn_ = new FlatButton(this);
|
|
|
|
backBtn_->setFixedSize(buttonSize_, buttonSize_);
|
|
|
|
backBtn_->setCornerRadius(buttonSize_ / 2);
|
|
|
|
|
|
|
|
QIcon backIcon;
|
|
|
|
backIcon.addFile(":/icons/icons/ui/angle-pointing-to-left.png");
|
|
|
|
backBtn_->setIcon(backIcon);
|
|
|
|
backBtn_->setIconSize(QSize(buttonSize_ / 2, buttonSize_ / 2));
|
|
|
|
backBtn_->hide();
|
|
|
|
|
2018-07-04 00:05:05 +03:00
|
|
|
connect(backBtn_, &QPushButton::clicked, this, &TopRoomBar::showRoomList);
|
2018-07-01 22:57:14 +03:00
|
|
|
|
2017-08-26 15:36:10 +03:00
|
|
|
topLayout_->addWidget(avatar_);
|
2018-07-01 22:57:14 +03:00
|
|
|
topLayout_->addWidget(backBtn_);
|
2017-10-19 19:04:51 +03:00
|
|
|
topLayout_->addLayout(textLayout_, 1);
|
2019-07-22 04:58:11 +03:00
|
|
|
topLayout_->addWidget(mentionsBtn_, 0, Qt::AlignRight);
|
2017-10-19 19:04:51 +03:00
|
|
|
topLayout_->addWidget(settingsBtn_, 0, Qt::AlignRight);
|
2017-08-26 15:36:10 +03:00
|
|
|
|
|
|
|
menu_ = new Menu(this);
|
|
|
|
|
2017-12-11 00:59:50 +03:00
|
|
|
inviteUsers_ = new QAction(tr("Invite users"), this);
|
2018-02-20 18:09:11 +03:00
|
|
|
connect(inviteUsers_, &QAction::triggered, this, [this]() {
|
2018-03-04 14:40:30 +03:00
|
|
|
MainWindow::instance()->openInviteUsersDialog(
|
|
|
|
[this](const QStringList &invitees) { emit inviteUsers(invitees); });
|
2017-12-11 00:59:50 +03:00
|
|
|
});
|
|
|
|
|
2018-05-01 19:35:28 +03:00
|
|
|
roomMembers_ = new QAction(tr("Members"), this);
|
|
|
|
connect(roomMembers_, &QAction::triggered, this, []() {
|
|
|
|
MainWindow::instance()->openMemberListDialog();
|
|
|
|
});
|
|
|
|
|
2017-10-01 19:49:36 +03:00
|
|
|
leaveRoom_ = new QAction(tr("Leave room"), this);
|
2018-02-20 18:09:11 +03:00
|
|
|
connect(leaveRoom_, &QAction::triggered, this, []() {
|
2018-02-10 17:05:31 +03:00
|
|
|
MainWindow::instance()->openLeaveRoomDialog();
|
2017-10-01 19:49:36 +03:00
|
|
|
});
|
|
|
|
|
2018-04-30 21:41:47 +03:00
|
|
|
roomSettings_ = new QAction(tr("Settings"), this);
|
|
|
|
connect(roomSettings_, &QAction::triggered, this, []() {
|
|
|
|
MainWindow::instance()->openRoomSettings();
|
|
|
|
});
|
|
|
|
|
2017-12-11 00:59:50 +03:00
|
|
|
menu_->addAction(inviteUsers_);
|
2018-05-01 19:35:28 +03:00
|
|
|
menu_->addAction(roomMembers_);
|
2017-10-01 19:49:36 +03:00
|
|
|
menu_->addAction(leaveRoom_);
|
2018-04-30 21:41:47 +03:00
|
|
|
menu_->addAction(roomSettings_);
|
2017-08-26 15:36:10 +03:00
|
|
|
|
2018-02-20 18:09:11 +03:00
|
|
|
connect(settingsBtn_, &QPushButton::clicked, this, [this]() {
|
2017-08-26 15:36:10 +03:00
|
|
|
auto pos = mapToGlobal(settingsBtn_->pos());
|
|
|
|
menu_->popup(
|
|
|
|
QPoint(pos.x() + buttonSize_ - menu_->sizeHint().width(), pos.y() + buttonSize_));
|
|
|
|
});
|
2019-07-22 04:58:11 +03:00
|
|
|
|
|
|
|
connect(mentionsBtn_, &QPushButton::clicked, this, [this]() {
|
|
|
|
auto pos = mapToGlobal(mentionsBtn_->pos());
|
|
|
|
emit mentionsClicked(pos);
|
|
|
|
});
|
2017-04-06 02:06:42 +03:00
|
|
|
}
|
|
|
|
|
2018-07-01 22:57:14 +03:00
|
|
|
void
|
|
|
|
TopRoomBar::enableBackButton()
|
|
|
|
{
|
|
|
|
avatar_->hide();
|
|
|
|
backBtn_->show();
|
|
|
|
}
|
|
|
|
|
2018-07-04 00:05:05 +03:00
|
|
|
void
|
|
|
|
TopRoomBar::disableBackButton()
|
|
|
|
{
|
|
|
|
avatar_->show();
|
|
|
|
backBtn_->hide();
|
|
|
|
}
|
|
|
|
|
2017-08-20 13:47:22 +03:00
|
|
|
void
|
|
|
|
TopRoomBar::updateRoomAvatarFromName(const QString &name)
|
2017-04-10 19:01:09 +03:00
|
|
|
{
|
2018-01-12 11:21:53 +03:00
|
|
|
avatar_->setLetter(utils::firstChar(name));
|
2017-09-30 20:43:57 +03:00
|
|
|
update();
|
2017-04-10 19:01:09 +03:00
|
|
|
}
|
|
|
|
|
2017-08-20 13:47:22 +03:00
|
|
|
void
|
|
|
|
TopRoomBar::reset()
|
2017-04-09 02:17:04 +03:00
|
|
|
{
|
2017-08-26 15:36:10 +03:00
|
|
|
nameLabel_->setText("");
|
|
|
|
topicLabel_->setText("");
|
2018-01-12 11:21:53 +03:00
|
|
|
avatar_->setLetter("");
|
2017-10-20 20:58:23 +03:00
|
|
|
}
|
|
|
|
|
2017-10-22 19:03:55 +03:00
|
|
|
void
|
2019-08-26 02:24:56 +03:00
|
|
|
TopRoomBar::updateRoomAvatar(const QString &avatar_image)
|
2017-10-22 19:03:55 +03:00
|
|
|
{
|
|
|
|
avatar_->setImage(avatar_image);
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TopRoomBar::updateRoomAvatar(const QIcon &icon)
|
|
|
|
{
|
|
|
|
avatar_->setIcon(icon);
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TopRoomBar::updateRoomName(const QString &name)
|
|
|
|
{
|
2018-05-25 16:13:38 +03:00
|
|
|
nameLabel_->setText(name);
|
2017-10-22 19:03:55 +03:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TopRoomBar::updateRoomTopic(QString topic)
|
|
|
|
{
|
2018-05-25 16:13:38 +03:00
|
|
|
topic.replace(conf::strings::url_regex, conf::strings::url_html);
|
2018-09-19 22:42:26 +03:00
|
|
|
topicLabel_->clearLinks();
|
|
|
|
topicLabel_->setHtml(topic);
|
2017-10-22 19:03:55 +03:00
|
|
|
update();
|
|
|
|
}
|