Commit 61ddfffe authored by Rafał Malinowski's avatar Rafał Malinowski

avatars: improve look of buddy avatar widget

parent cbf0bf49
......@@ -34,7 +34,7 @@
#include <QtWidgets/QPushButton>
#include <QtWidgets/QVBoxLayout>
BuddyAvatarWidget::BuddyAvatarWidget(Buddy buddy, QWidget *parent) : QWidget(parent), MyBuddy(buddy), BuddyAvatar(false)
BuddyAvatarWidget::BuddyAvatarWidget(Buddy buddy, QWidget *parent) : QWidget{parent}, m_buddy{buddy}, m_avatarSet(false)
{
}
......@@ -55,7 +55,7 @@ void BuddyAvatarWidget::init()
void BuddyAvatarWidget::showAvatar()
{
if (m_avatars->pixmap(avatarId(MyBuddy)).isNull())
if (m_avatars->pixmap(avatarId(m_buddy)).isNull())
showContactAvatar();
else
showBuddyAvatar();
......@@ -63,53 +63,60 @@ void BuddyAvatarWidget::showAvatar()
void BuddyAvatarWidget::showAvatar(QPixmap pixmap)
{
if (!pixmap.isNull())
pixmap = pixmap.scaled(QSize(128, 128), Qt::KeepAspectRatio, Qt::SmoothTransformation);
AvatarLabel->setPixmap(pixmap);
pixmap = pixmap.scaled(QSize{AVATAR_SIZE, AVATAR_SIZE}, Qt::KeepAspectRatio, Qt::SmoothTransformation);
m_avatarLabel->setPixmap(pixmap);
}
void BuddyAvatarWidget::showBuddyAvatar()
{
showAvatar(m_avatars->pixmap(avatarId(MyBuddy)));
BuddyAvatar = true;
showAvatar(m_avatars->pixmap(avatarId(m_buddy)));
m_avatarSet = true;
}
void BuddyAvatarWidget::showContactAvatar()
{
auto preferredContact = m_buddyPreferredManager->preferredContact(MyBuddy);
auto preferredContact = m_buddyPreferredManager->preferredContact(m_buddy);
showAvatar(m_avatars->pixmap(avatarId(preferredContact)));
BuddyAvatar = false;
m_avatarSet = false;
}
void BuddyAvatarWidget::createGui()
{
QVBoxLayout *photoLayout = new QVBoxLayout(this);
auto photoLayout = make_owned<QVBoxLayout>(this);
photoLayout->setSpacing(2);
AvatarLabel = new QLabel(this);
m_avatarLabel = make_owned<QLabel>(this);
m_avatarLabel->setAlignment(Qt::AlignCenter);
m_avatarLabel->setAutoFillBackground(true);
m_avatarLabel->setBackgroundRole(QPalette::Base);
m_avatarLabel->setLineWidth(1);
m_avatarLabel->setFrameShape(static_cast<QFrame::Shape>(QFrame::StyledPanel | QFrame::Sunken));
m_avatarLabel->setFixedWidth(AVATAR_SIZE + 8);
m_avatarLabel->setFixedHeight(AVATAR_SIZE + 8);
m_avatarLabel->setScaledContents(false);
showAvatar();
photoLayout->addWidget(AvatarLabel, 0, Qt::AlignCenter);
photoLayout->addWidget(m_avatarLabel, 0, Qt::AlignTop | Qt::AlignRight);
ChangePhotoButton = new QPushButton(this);
connect(ChangePhotoButton, SIGNAL(clicked(bool)), this, SLOT(buttonClicked()));
photoLayout->addWidget(ChangePhotoButton);
m_changeAvatarButton = make_owned<QPushButton>(this);
connect(m_changeAvatarButton, SIGNAL(clicked(bool)), this, SLOT(buttonClicked()));
photoLayout->addWidget(m_changeAvatarButton);
setupChangeButton();
}
void BuddyAvatarWidget::setupChangeButton()
{
if (BuddyAvatar)
ChangePhotoButton->setText(tr("Remove Custom Photo..."));
if (m_avatarSet)
m_changeAvatarButton->setText(tr("Remove"));
else
ChangePhotoButton->setText(tr("Change Photo..."));
m_changeAvatarButton->setText(tr("Change"));
}
void BuddyAvatarWidget::buttonClicked()
{
if (BuddyAvatar)
if (m_avatarSet)
removeAvatar();
else
changeAvatar();
......@@ -117,7 +124,7 @@ void BuddyAvatarWidget::buttonClicked()
void BuddyAvatarWidget::changeAvatar()
{
QString newAvatar = QFileDialog::getOpenFileName(
auto newAvatar = QFileDialog::getOpenFileName(
this, tr("Select new photo"), QString(), tr("Images (*.png *.jpg *.bmp);;All Files (*)"), 0);
if (newAvatar.isEmpty())
return;
......@@ -128,8 +135,8 @@ void BuddyAvatarWidget::changeAvatar()
if (!pixmap.isNull())
{
showAvatar(newAvatar);
BuddyAvatarPixmap = pixmap;
BuddyAvatar = true;
m_avatar = pixmap;
m_avatarSet = true;
}
setupChangeButton();
......@@ -143,8 +150,8 @@ void BuddyAvatarWidget::removeAvatar()
const QPixmap BuddyAvatarWidget::avatarPixmap()
{
if (BuddyAvatar && !BuddyAvatarPixmap.isNull())
return BuddyAvatarPixmap;
if (m_avatarSet && !m_avatar.isNull())
return m_avatar;
return QPixmap();
return QPixmap{};
}
......@@ -22,6 +22,7 @@
#pragma once
#include "buddies/buddy.h"
#include "misc/memory.h"
#include <QtCore/QPointer>
#include <QtWidgets/QWidget>
......@@ -41,23 +42,21 @@ public:
explicit BuddyAvatarWidget(Buddy buddy, QWidget *parent = nullptr);
const QPixmap avatarPixmap();
bool buddyAvatar() const
bool avatarSet() const
{
return BuddyAvatar;
return m_avatarSet;
}
private:
QPointer<Avatars> m_avatars;
QPointer<BuddyPreferredManager> m_buddyPreferredManager;
Buddy MyBuddy;
Buddy m_buddy;
bool m_avatarSet;
QPixmap m_avatar;
bool BuddyAvatar;
QPixmap BuddyAvatarPixmap;
QLabel *AvatarLabel;
QPushButton *ChangePhotoButton;
owned_qptr<QLabel> m_avatarLabel;
owned_qptr<QPushButton> m_changeAvatarButton;
void createGui();
void setupChangeButton();
......
......@@ -190,7 +190,7 @@ void BuddyGeneralConfigurationWidget::save()
MyBuddy.setPreferHigherStatuses(PreferHigherStatusCheck->isChecked());
QPixmap avatar = AvatarWidget->avatarPixmap();
if (!AvatarWidget->buddyAvatar() || avatar.isNull())
if (!AvatarWidget->avatarSet() || avatar.isNull())
removeBuddyAvatar();
else
setBuddyAvatar(avatar);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment