2017-12-12 00:00:37 +03:00
|
|
|
#include <QDebug>
|
2017-10-15 22:08:51 +03:00
|
|
|
#include <QIcon>
|
|
|
|
|
2018-03-04 14:40:30 +03:00
|
|
|
#include <mtx/requests.hpp>
|
|
|
|
|
2017-10-15 22:08:51 +03:00
|
|
|
#include "Config.h"
|
2017-12-10 16:22:01 +03:00
|
|
|
#include "MainWindow.h"
|
2017-10-28 15:46:39 +03:00
|
|
|
#include "SideBarActions.h"
|
2018-10-07 14:09:47 +03:00
|
|
|
#include "Utils.h"
|
2018-07-17 16:37:25 +03:00
|
|
|
#include "ui/FlatButton.h"
|
|
|
|
#include "ui/Menu.h"
|
|
|
|
#include "ui/OverlayModal.h"
|
2017-10-15 22:08:51 +03:00
|
|
|
|
|
|
|
SideBarActions::SideBarActions(QWidget *parent)
|
2017-11-06 00:04:55 +03:00
|
|
|
: QWidget{parent}
|
2017-10-15 22:08:51 +03:00
|
|
|
{
|
2018-10-06 18:07:02 +03:00
|
|
|
QFont f;
|
|
|
|
f.setPointSizeF(f.pointSizeF());
|
|
|
|
|
|
|
|
const int fontHeight = QFontMetrics(f).height();
|
|
|
|
const int contentHeight = fontHeight * 2.5;
|
|
|
|
|
|
|
|
setFixedHeight(contentHeight);
|
2017-10-15 22:08:51 +03:00
|
|
|
|
|
|
|
layout_ = new QHBoxLayout(this);
|
|
|
|
layout_->setMargin(0);
|
|
|
|
|
|
|
|
QIcon settingsIcon;
|
|
|
|
settingsIcon.addFile(":/icons/icons/ui/settings.png");
|
|
|
|
|
|
|
|
QIcon createRoomIcon;
|
|
|
|
createRoomIcon.addFile(":/icons/icons/ui/add-square-button.png");
|
|
|
|
|
|
|
|
QIcon joinRoomIcon;
|
|
|
|
joinRoomIcon.addFile(":/icons/icons/ui/speech-bubbles-comment-option.png");
|
|
|
|
|
|
|
|
settingsBtn_ = new FlatButton(this);
|
2018-07-25 23:28:37 +03:00
|
|
|
settingsBtn_->setToolTip(tr("User settings"));
|
2017-10-15 22:08:51 +03:00
|
|
|
settingsBtn_->setIcon(settingsIcon);
|
|
|
|
settingsBtn_->setCornerRadius(conf::sidebarActions::iconSize / 2);
|
|
|
|
settingsBtn_->setIconSize(
|
|
|
|
QSize(conf::sidebarActions::iconSize, conf::sidebarActions::iconSize));
|
|
|
|
|
2017-12-10 16:22:01 +03:00
|
|
|
addMenu_ = new Menu(this);
|
|
|
|
createRoomAction_ = new QAction(tr("Create new room"), this);
|
|
|
|
joinRoomAction_ = new QAction(tr("Join a room"), this);
|
|
|
|
|
2018-02-20 18:09:11 +03:00
|
|
|
connect(joinRoomAction_, &QAction::triggered, this, [this]() {
|
2018-03-04 14:40:30 +03:00
|
|
|
MainWindow::instance()->openJoinRoomDialog(
|
|
|
|
[this](const QString &room_id) { emit joinRoom(room_id); });
|
2017-12-10 16:22:01 +03:00
|
|
|
});
|
|
|
|
|
2018-02-20 18:09:11 +03:00
|
|
|
connect(createRoomAction_, &QAction::triggered, this, [this]() {
|
2018-03-04 14:40:30 +03:00
|
|
|
MainWindow::instance()->openCreateRoomDialog(
|
|
|
|
[this](const mtx::requests::CreateRoom &req) { emit createRoom(req); });
|
2017-12-12 00:00:37 +03:00
|
|
|
});
|
|
|
|
|
2017-12-10 16:22:01 +03:00
|
|
|
addMenu_->addAction(createRoomAction_);
|
|
|
|
addMenu_->addAction(joinRoomAction_);
|
|
|
|
|
2017-10-15 22:08:51 +03:00
|
|
|
createRoomBtn_ = new FlatButton(this);
|
2018-07-25 23:28:37 +03:00
|
|
|
createRoomBtn_->setToolTip(tr("Start a new chat"));
|
2017-10-15 22:08:51 +03:00
|
|
|
createRoomBtn_->setIcon(createRoomIcon);
|
|
|
|
createRoomBtn_->setCornerRadius(conf::sidebarActions::iconSize / 2);
|
|
|
|
createRoomBtn_->setIconSize(
|
|
|
|
QSize(conf::sidebarActions::iconSize, conf::sidebarActions::iconSize));
|
|
|
|
|
2018-02-20 18:09:11 +03:00
|
|
|
connect(createRoomBtn_, &QPushButton::clicked, this, [this]() {
|
2017-12-10 16:22:01 +03:00
|
|
|
auto pos = mapToGlobal(createRoomBtn_->pos());
|
|
|
|
auto padding = conf::sidebarActions::iconSize / 2;
|
|
|
|
|
|
|
|
addMenu_->popup(
|
|
|
|
QPoint(pos.x() + padding, pos.y() - padding - addMenu_->sizeHint().height()));
|
|
|
|
});
|
|
|
|
|
2018-07-25 23:28:37 +03:00
|
|
|
roomDirectory_ = new FlatButton(this);
|
|
|
|
roomDirectory_->setToolTip(tr("Room directory"));
|
|
|
|
roomDirectory_->setEnabled(false);
|
|
|
|
roomDirectory_->setIcon(joinRoomIcon);
|
|
|
|
roomDirectory_->setCornerRadius(conf::sidebarActions::iconSize / 2);
|
|
|
|
roomDirectory_->setIconSize(
|
2017-10-15 22:08:51 +03:00
|
|
|
QSize(conf::sidebarActions::iconSize, conf::sidebarActions::iconSize));
|
|
|
|
|
|
|
|
layout_->addWidget(createRoomBtn_);
|
2018-07-25 23:28:37 +03:00
|
|
|
layout_->addWidget(roomDirectory_);
|
2017-10-15 22:08:51 +03:00
|
|
|
layout_->addWidget(settingsBtn_);
|
2017-11-02 01:41:13 +03:00
|
|
|
|
|
|
|
connect(settingsBtn_, &QPushButton::clicked, this, &SideBarActions::showSettings);
|
2017-10-15 22:08:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SideBarActions::resizeEvent(QResizeEvent *event)
|
|
|
|
{
|
|
|
|
Q_UNUSED(event);
|
|
|
|
|
2018-10-07 14:09:47 +03:00
|
|
|
const auto sidebarSizes = utils::calculateSidebarSizes(QFont{});
|
|
|
|
|
|
|
|
if (width() <= sidebarSizes.small) {
|
2018-07-25 23:28:37 +03:00
|
|
|
roomDirectory_->hide();
|
2017-10-15 22:08:51 +03:00
|
|
|
createRoomBtn_->hide();
|
|
|
|
} else {
|
2018-07-25 23:28:37 +03:00
|
|
|
roomDirectory_->show();
|
2017-10-15 22:08:51 +03:00
|
|
|
createRoomBtn_->show();
|
|
|
|
}
|
|
|
|
}
|
2018-01-15 22:04:49 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
SideBarActions::paintEvent(QPaintEvent *)
|
|
|
|
{
|
|
|
|
QStyleOption opt;
|
|
|
|
opt.init(this);
|
|
|
|
QPainter p(this);
|
|
|
|
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
|
|
|
|
}
|