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-06-02 18:04:51 +03:00
|
|
|
#include <QTimer>
|
2017-05-19 19:55:38 +03:00
|
|
|
|
2018-10-01 17:56:46 +03:00
|
|
|
#include <iostream>
|
|
|
|
|
2017-07-15 17:11:46 +03:00
|
|
|
#include "Config.h"
|
2017-06-02 18:04:51 +03:00
|
|
|
#include "MainWindow.h"
|
2017-05-19 19:55:38 +03:00
|
|
|
#include "UserInfoWidget.h"
|
2018-07-17 16:37:25 +03:00
|
|
|
#include "ui/Avatar.h"
|
|
|
|
#include "ui/FlatButton.h"
|
|
|
|
#include "ui/OverlayModal.h"
|
2017-04-06 02:06:42 +03:00
|
|
|
|
|
|
|
UserInfoWidget::UserInfoWidget(QWidget *parent)
|
2017-08-20 13:47:22 +03:00
|
|
|
: QWidget(parent)
|
|
|
|
, display_name_("User")
|
|
|
|
, user_id_("@user:homeserver.org")
|
2017-04-06 02:06:42 +03:00
|
|
|
{
|
2018-10-01 17:56:46 +03:00
|
|
|
const int fontHeight = QFontMetrics(font()).height();
|
|
|
|
const int widgetMargin = fontHeight / 3;
|
|
|
|
const int contentHeight = fontHeight * 3;
|
|
|
|
|
|
|
|
logoutButtonSize_ = fontHeight + (fontHeight / 4);
|
|
|
|
|
|
|
|
setFixedHeight(contentHeight + widgetMargin * 2);
|
2017-09-10 12:59:21 +03:00
|
|
|
|
|
|
|
topLayout_ = new QHBoxLayout(this);
|
|
|
|
topLayout_->setSpacing(0);
|
2018-10-01 17:56:46 +03:00
|
|
|
topLayout_->setMargin(widgetMargin);
|
2017-09-10 12:59:21 +03:00
|
|
|
|
|
|
|
avatarLayout_ = new QHBoxLayout();
|
|
|
|
textLayout_ = new QVBoxLayout();
|
2018-10-01 17:56:46 +03:00
|
|
|
textLayout_->setSpacing(0);
|
|
|
|
textLayout_->setContentsMargins(
|
|
|
|
widgetMargin * 2, widgetMargin, widgetMargin * 2, widgetMargin);
|
2017-09-10 12:59:21 +03:00
|
|
|
|
|
|
|
userAvatar_ = new Avatar(this);
|
2017-11-16 17:33:52 +03:00
|
|
|
userAvatar_->setObjectName("userAvatar");
|
2017-09-10 12:59:21 +03:00
|
|
|
userAvatar_->setLetter(QChar('?'));
|
2018-10-01 17:56:46 +03:00
|
|
|
userAvatar_->setSize(fontHeight * 2.5);
|
2017-09-10 12:59:21 +03:00
|
|
|
|
2018-09-30 13:24:36 +03:00
|
|
|
QFont nameFont;
|
|
|
|
nameFont.setWeight(QFont::Medium);
|
2017-09-10 12:59:21 +03:00
|
|
|
|
|
|
|
displayNameLabel_ = new QLabel(this);
|
|
|
|
displayNameLabel_->setFont(nameFont);
|
2017-11-16 17:33:52 +03:00
|
|
|
displayNameLabel_->setObjectName("displayNameLabel");
|
2017-09-10 12:59:21 +03:00
|
|
|
displayNameLabel_->setAlignment(Qt::AlignLeading | Qt::AlignLeft | Qt::AlignTop);
|
|
|
|
|
|
|
|
userIdLabel_ = new QLabel(this);
|
2017-11-16 17:33:52 +03:00
|
|
|
userIdLabel_->setObjectName("userIdLabel");
|
2017-09-10 12:59:21 +03:00
|
|
|
userIdLabel_->setAlignment(Qt::AlignLeading | Qt::AlignLeft | Qt::AlignVCenter);
|
|
|
|
|
|
|
|
avatarLayout_->addWidget(userAvatar_);
|
|
|
|
textLayout_->addWidget(displayNameLabel_);
|
|
|
|
textLayout_->addWidget(userIdLabel_);
|
|
|
|
|
|
|
|
topLayout_->addLayout(avatarLayout_);
|
|
|
|
topLayout_->addLayout(textLayout_);
|
|
|
|
topLayout_->addStretch(1);
|
|
|
|
|
|
|
|
buttonLayout_ = new QHBoxLayout();
|
|
|
|
buttonLayout_->setSpacing(0);
|
|
|
|
buttonLayout_->setMargin(0);
|
|
|
|
|
|
|
|
logoutButton_ = new FlatButton(this);
|
2018-07-25 23:28:37 +03:00
|
|
|
logoutButton_->setToolTip(tr("Logout"));
|
2017-09-10 12:59:21 +03:00
|
|
|
logoutButton_->setCornerRadius(logoutButtonSize_ / 2);
|
|
|
|
|
|
|
|
QIcon icon;
|
2017-10-15 22:08:51 +03:00
|
|
|
icon.addFile(":/icons/icons/ui/power-button-off.png");
|
2017-09-10 12:59:21 +03:00
|
|
|
|
|
|
|
logoutButton_->setIcon(icon);
|
2017-10-15 22:08:51 +03:00
|
|
|
logoutButton_->setIconSize(QSize(logoutButtonSize_, logoutButtonSize_));
|
2017-09-10 12:59:21 +03:00
|
|
|
|
|
|
|
buttonLayout_->addWidget(logoutButton_);
|
|
|
|
|
|
|
|
topLayout_->addLayout(buttonLayout_);
|
|
|
|
|
|
|
|
// Show the confirmation dialog.
|
2018-08-31 09:10:47 +03:00
|
|
|
connect(logoutButton_, &QPushButton::clicked, this, []() {
|
|
|
|
MainWindow::instance()->openLogoutDialog();
|
2017-09-10 12:59:21 +03:00
|
|
|
});
|
2017-06-02 18:04:51 +03:00
|
|
|
}
|
|
|
|
|
2017-08-20 13:47:22 +03:00
|
|
|
void
|
|
|
|
UserInfoWidget::resizeEvent(QResizeEvent *event)
|
2017-05-19 19:55:38 +03:00
|
|
|
{
|
2017-09-10 12:59:21 +03:00
|
|
|
Q_UNUSED(event);
|
|
|
|
|
|
|
|
if (width() <= ui::sidebar::SmallSize) {
|
|
|
|
topLayout_->setContentsMargins(0, 0, logoutButtonSize_ / 2 - 5 / 2, 0);
|
|
|
|
|
|
|
|
userAvatar_->hide();
|
|
|
|
displayNameLabel_->hide();
|
|
|
|
userIdLabel_->hide();
|
|
|
|
} else {
|
|
|
|
topLayout_->setMargin(5);
|
|
|
|
userAvatar_->show();
|
|
|
|
displayNameLabel_->show();
|
|
|
|
userIdLabel_->show();
|
|
|
|
}
|
2017-11-09 00:09:15 +03:00
|
|
|
|
|
|
|
QWidget::resizeEvent(event);
|
2017-05-19 19:55:38 +03:00
|
|
|
}
|
|
|
|
|
2017-08-20 13:47:22 +03:00
|
|
|
void
|
|
|
|
UserInfoWidget::reset()
|
2017-04-09 02:17:04 +03:00
|
|
|
{
|
2017-09-10 12:59:21 +03:00
|
|
|
displayNameLabel_->setText("");
|
|
|
|
userIdLabel_->setText("");
|
|
|
|
userAvatar_->setLetter(QChar('?'));
|
2017-04-09 02:17:04 +03:00
|
|
|
}
|
|
|
|
|
2017-08-20 13:47:22 +03:00
|
|
|
void
|
|
|
|
UserInfoWidget::setAvatar(const QImage &img)
|
2017-04-06 02:06:42 +03:00
|
|
|
{
|
2017-09-10 12:59:21 +03:00
|
|
|
avatar_image_ = img;
|
|
|
|
userAvatar_->setImage(img);
|
2017-09-30 20:43:57 +03:00
|
|
|
update();
|
2017-04-06 02:06:42 +03:00
|
|
|
}
|
|
|
|
|
2017-08-20 13:47:22 +03:00
|
|
|
void
|
|
|
|
UserInfoWidget::setDisplayName(const QString &name)
|
2017-04-06 02:06:42 +03:00
|
|
|
{
|
2017-09-10 12:59:21 +03:00
|
|
|
if (name.isEmpty())
|
|
|
|
display_name_ = user_id_.split(':')[0].split('@')[1];
|
|
|
|
else
|
|
|
|
display_name_ = name;
|
2017-05-16 15:43:29 +03:00
|
|
|
|
2017-09-10 12:59:21 +03:00
|
|
|
displayNameLabel_->setText(display_name_);
|
|
|
|
userAvatar_->setLetter(QChar(display_name_[0]));
|
2017-09-30 20:43:57 +03:00
|
|
|
update();
|
2017-04-06 02:06:42 +03:00
|
|
|
}
|
|
|
|
|
2017-08-20 13:47:22 +03:00
|
|
|
void
|
|
|
|
UserInfoWidget::setUserId(const QString &userid)
|
2017-04-06 02:06:42 +03:00
|
|
|
{
|
2017-09-10 12:59:21 +03:00
|
|
|
user_id_ = userid;
|
|
|
|
userIdLabel_->setText(userid);
|
2017-04-06 02:06:42 +03:00
|
|
|
}
|
2017-11-16 17:33:52 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
UserInfoWidget::paintEvent(QPaintEvent *event)
|
|
|
|
{
|
|
|
|
Q_UNUSED(event);
|
|
|
|
|
|
|
|
QStyleOption opt;
|
|
|
|
opt.init(this);
|
|
|
|
QPainter p(this);
|
|
|
|
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
|
|
|
|
}
|