matrixion/src/UserInfoWidget.cc

141 lines
3.6 KiB
C++
Raw Normal View History

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-05-19 19:55:38 +03:00
#include <QDebug>
2017-04-06 02:06:42 +03:00
#include "FlatButton.h"
2017-05-19 19:55:38 +03:00
#include "UserInfoWidget.h"
2017-04-06 02:06:42 +03:00
UserInfoWidget::UserInfoWidget(QWidget *parent)
: QWidget(parent)
, display_name_("User")
, user_id_("@user:homeserver.org")
2017-04-06 02:06:42 +03:00
{
QSizePolicy sizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
setSizePolicy(sizePolicy);
setMinimumSize(QSize(0, 65));
topLayout_ = new QHBoxLayout(this);
topLayout_->setSpacing(0);
2017-05-19 19:55:38 +03:00
topLayout_->setMargin(5);
2017-04-06 02:06:42 +03:00
avatarLayout_ = new QHBoxLayout();
textLayout_ = new QVBoxLayout();
userAvatar_ = new Avatar(this);
userAvatar_->setLetter(QChar('?'));
userAvatar_->setSize(55);
userAvatar_->setBackgroundColor("#f9f9f9");
userAvatar_->setTextColor("#333333");
2017-04-06 02:06:42 +03:00
displayNameLabel_ = new QLabel(this);
displayNameLabel_->setStyleSheet(
"padding: 0 9px;"
2017-04-14 15:13:09 +03:00
"color: #171919;"
2017-04-12 02:44:01 +03:00
"font-size: 14px;"
"font-weight: 500;"
2017-04-06 02:06:42 +03:00
"margin-bottom: -10px;");
displayNameLabel_->setAlignment(Qt::AlignLeading | Qt::AlignLeft | Qt::AlignTop);
userIdLabel_ = new QLabel(this);
userIdLabel_->setStyleSheet(
"padding: 0 8px 8px 8px;"
2017-04-14 15:13:09 +03:00
"color: #555459;"
2017-04-12 02:44:01 +03:00
"font-size: 13px");
2017-04-06 02:06:42 +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();
2017-05-19 19:55:38 +03:00
buttonLayout_->setSpacing(0);
buttonLayout_->setMargin(0);
2017-04-06 02:06:42 +03:00
logoutButton_ = new FlatButton(this);
2017-04-14 15:13:09 +03:00
logoutButton_->setForegroundColor(QColor("#555459"));
logoutButton_->setCursor(QCursor(Qt::PointingHandCursor));
2017-04-06 02:06:42 +03:00
QIcon icon;
icon.addFile(":/icons/icons/power-button-off.png", QSize(), QIcon::Normal, QIcon::Off);
2017-04-06 02:06:42 +03:00
logoutButton_->setIcon(icon);
logoutButton_->setIconSize(QSize(16, 16));
2017-04-06 02:06:42 +03:00
buttonLayout_->addWidget(logoutButton_);
2017-04-06 02:06:42 +03:00
topLayout_->addLayout(buttonLayout_);
connect(logoutButton_, SIGNAL(clicked()), this, SIGNAL(logout()));
2017-04-06 02:06:42 +03:00
}
UserInfoWidget::~UserInfoWidget()
{
}
2017-05-19 19:55:38 +03:00
void UserInfoWidget::resizeEvent(QResizeEvent *event)
{
Q_UNUSED(event);
if (width() <= ui::sidebar::SmallSize) {
topLayout_->setContentsMargins(0, 0, 10, 0);
userAvatar_->hide();
displayNameLabel_->hide();
userIdLabel_->hide();
} else {
topLayout_->setMargin(5);
userAvatar_->show();
displayNameLabel_->show();
userIdLabel_->show();
}
}
void UserInfoWidget::reset()
{
displayNameLabel_->setText("");
userIdLabel_->setText("");
userAvatar_->setLetter(QChar('?'));
}
2017-04-06 02:06:42 +03:00
void UserInfoWidget::setAvatar(const QImage &img)
{
avatar_image_ = img;
userAvatar_->setImage(img);
}
void UserInfoWidget::setDisplayName(const QString &name)
{
if (name.isEmpty())
display_name_ = user_id_.split(':')[0].split('@')[1];
else
display_name_ = name;
displayNameLabel_->setText(display_name_);
userAvatar_->setLetter(QChar(display_name_[0]));
2017-04-06 02:06:42 +03:00
}
void UserInfoWidget::setUserId(const QString &userid)
{
user_id_ = userid;
2017-04-06 02:06:42 +03:00
userIdLabel_->setText(userid);
}