2015-02-03 14:17:35 -05:00
|
|
|
/*
|
|
|
|
* Avatar Dialog
|
|
|
|
*
|
|
|
|
* Copyright 2015 by RetroShare Team
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License Version 2.1 as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This library 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
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
* USA.
|
|
|
|
*
|
|
|
|
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <QBuffer>
|
|
|
|
|
2015-02-04 19:10:37 -05:00
|
|
|
#include "AvatarDialog.h"
|
|
|
|
#include "ui_AvatarDialog.h"
|
|
|
|
#include "AvatarDefs.h"
|
2015-02-03 14:17:35 -05:00
|
|
|
#include "util/misc.h"
|
|
|
|
|
|
|
|
/** Constructor */
|
2015-02-04 19:10:37 -05:00
|
|
|
AvatarDialog::AvatarDialog(QWidget *parent) :
|
|
|
|
QDialog(parent, Qt::WindowSystemMenuHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint),
|
|
|
|
ui(new(Ui::AvatarDialog))
|
2015-02-03 14:17:35 -05:00
|
|
|
{
|
|
|
|
/* Invoke Qt Designer generated QObject setup routine */
|
2015-02-04 19:10:37 -05:00
|
|
|
ui->setupUi(this);
|
2015-02-03 14:17:35 -05:00
|
|
|
|
2015-02-04 19:10:37 -05:00
|
|
|
ui->headerFrame->setHeaderImage(QPixmap(":/images/no_avatar_70.png"));
|
|
|
|
ui->headerFrame->setHeaderText(tr("Set your Avatar picture"));
|
2015-02-03 14:17:35 -05:00
|
|
|
|
2015-02-04 19:10:37 -05:00
|
|
|
connect(ui->avatarButton, SIGNAL(clicked(bool)), this, SLOT(changeAvatar()));
|
|
|
|
connect(ui->removeButton, SIGNAL(clicked(bool)), this, SLOT(removeAvatar()));
|
2015-02-03 14:17:35 -05:00
|
|
|
|
2015-02-04 19:10:37 -05:00
|
|
|
connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
|
|
|
|
connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
|
|
|
|
|
|
|
|
updateInterface();
|
2015-02-03 14:17:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
AvatarDialog::~AvatarDialog()
|
|
|
|
{
|
2015-02-04 19:10:37 -05:00
|
|
|
delete(ui);
|
2015-02-03 14:17:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void AvatarDialog::changeAvatar()
|
|
|
|
{
|
2015-02-04 19:10:37 -05:00
|
|
|
QPixmap img = misc::getOpenThumbnailedPicture(this, tr("Load Avatar"), 128, 128);
|
2015-02-03 14:17:35 -05:00
|
|
|
|
2015-02-04 19:10:37 -05:00
|
|
|
if (img.isNull())
|
|
|
|
return;
|
2015-02-03 14:17:35 -05:00
|
|
|
|
2015-02-04 19:10:37 -05:00
|
|
|
ui->avatarLabel->setPixmap(img);
|
|
|
|
updateInterface();
|
2015-02-03 14:17:35 -05:00
|
|
|
}
|
|
|
|
|
2015-02-04 19:10:37 -05:00
|
|
|
void AvatarDialog::removeAvatar()
|
2015-02-03 14:17:35 -05:00
|
|
|
{
|
2015-02-04 19:10:37 -05:00
|
|
|
ui->avatarLabel->setPixmap(QPixmap());
|
|
|
|
updateInterface();
|
2015-02-03 14:17:35 -05:00
|
|
|
}
|
|
|
|
|
2015-02-04 19:10:37 -05:00
|
|
|
void AvatarDialog::updateInterface()
|
2015-02-03 14:17:35 -05:00
|
|
|
{
|
2015-02-04 19:10:37 -05:00
|
|
|
const QPixmap *pixmap = ui->avatarLabel->pixmap();
|
|
|
|
if (pixmap && !pixmap->isNull()) {
|
|
|
|
ui->removeButton->setEnabled(true);
|
|
|
|
} else {
|
|
|
|
ui->removeButton->setEnabled(false);
|
|
|
|
}
|
2015-02-03 14:17:35 -05:00
|
|
|
}
|
|
|
|
|
2015-02-04 19:10:37 -05:00
|
|
|
void AvatarDialog::setAvatar(const QPixmap &avatar)
|
|
|
|
{
|
|
|
|
ui->avatarLabel->setPixmap(avatar);
|
|
|
|
updateInterface();
|
2015-02-03 14:17:35 -05:00
|
|
|
}
|
|
|
|
|
2015-02-04 19:10:37 -05:00
|
|
|
void AvatarDialog::getAvatar(QPixmap &avatar)
|
|
|
|
{
|
|
|
|
const QPixmap *pixmap = ui->avatarLabel->pixmap();
|
|
|
|
if (!pixmap) {
|
|
|
|
avatar = QPixmap();
|
|
|
|
return;
|
|
|
|
}
|
2015-02-03 14:17:35 -05:00
|
|
|
|
2015-02-04 19:10:37 -05:00
|
|
|
avatar = *pixmap;
|
2015-02-03 14:17:35 -05:00
|
|
|
}
|
2015-02-04 19:10:37 -05:00
|
|
|
|
|
|
|
void AvatarDialog::getAvatar(QByteArray &avatar)
|
2015-02-03 14:17:35 -05:00
|
|
|
{
|
2015-02-04 19:10:37 -05:00
|
|
|
const QPixmap *pixmap = ui->avatarLabel->pixmap();
|
|
|
|
if (!pixmap) {
|
|
|
|
avatar.clear();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QBuffer buffer(&avatar);
|
2015-02-03 14:17:35 -05:00
|
|
|
|
2015-02-04 19:10:37 -05:00
|
|
|
buffer.open(QIODevice::WriteOnly);
|
|
|
|
pixmap->save(&buffer, "PNG"); // writes image into ba in PNG format
|
2015-02-03 14:17:35 -05:00
|
|
|
}
|