mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-12 02:55:18 -04:00
Used AvatarDialog to choose an avatar for an identity.
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7913 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
b0a8eba546
commit
5dd26de35b
8 changed files with 273 additions and 274 deletions
|
@ -23,96 +23,90 @@
|
|||
|
||||
#include <QBuffer>
|
||||
|
||||
#include "gui/common/AvatarDialog.h"
|
||||
#include "gui/common/AvatarDefs.h"
|
||||
|
||||
#include "gui/gxs/GxsIdDetails.h"
|
||||
#include "util/TokenQueue.h"
|
||||
#include "AvatarDialog.h"
|
||||
#include "ui_AvatarDialog.h"
|
||||
#include "AvatarDefs.h"
|
||||
#include "util/misc.h"
|
||||
|
||||
#include <retroshare/rsidentity.h>
|
||||
#include <retroshare/rspeers.h>
|
||||
#include <retroshare/rsmsgs.h>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
|
||||
/** Constructor */
|
||||
AvatarDialog::AvatarDialog(QWidget *parent)
|
||||
: QDialog(parent, Qt::WindowSystemMenuHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint)
|
||||
AvatarDialog::AvatarDialog(QWidget *parent) :
|
||||
QDialog(parent, Qt::WindowSystemMenuHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint),
|
||||
ui(new(Ui::AvatarDialog))
|
||||
{
|
||||
/* Invoke Qt Designer generated QObject setup routine */
|
||||
ui.setupUi(this);
|
||||
|
||||
ui.headerFrame->setHeaderImage(QPixmap(":/images/no_avatar_70.png"));
|
||||
ui.headerFrame->setHeaderText(tr("Set your Avatar picture"));
|
||||
ui->setupUi(this);
|
||||
|
||||
ui->headerFrame->setHeaderImage(QPixmap(":/images/no_avatar_70.png"));
|
||||
ui->headerFrame->setHeaderText(tr("Set your Avatar picture"));
|
||||
|
||||
connect(ui.avatarButton, SIGNAL(clicked(bool)), this, SLOT(changeAvatar()));
|
||||
connect(ui.removeButton, SIGNAL(clicked(bool)), this, SLOT(removeAvatar()));
|
||||
|
||||
connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(saveAvatar()));
|
||||
|
||||
loadOwnAvatar();
|
||||
connect(ui->avatarButton, SIGNAL(clicked(bool)), this, SLOT(changeAvatar()));
|
||||
connect(ui->removeButton, SIGNAL(clicked(bool)), this, SLOT(removeAvatar()));
|
||||
|
||||
connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
|
||||
connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
|
||||
|
||||
updateInterface();
|
||||
}
|
||||
|
||||
AvatarDialog::~AvatarDialog()
|
||||
{
|
||||
delete(ui);
|
||||
}
|
||||
|
||||
void AvatarDialog::changeAvatar()
|
||||
{
|
||||
QPixmap img = misc::getOpenThumbnailedPicture(this, tr("Load Avatar"), 128, 128);
|
||||
QPixmap img = misc::getOpenThumbnailedPicture(this, tr("Load Avatar"), 128, 128);
|
||||
|
||||
if (img.isNull())
|
||||
return;
|
||||
if (img.isNull())
|
||||
return;
|
||||
|
||||
ui.avatarLabel->setPixmap(img) ;
|
||||
|
||||
}
|
||||
|
||||
void AvatarDialog::loadOwnAvatar()
|
||||
{
|
||||
RsPeerDetails pd ;
|
||||
if (rsPeers->getPeerDetails(rsPeers->getOwnId(),pd)) {
|
||||
QPixmap avatar;
|
||||
AvatarDefs::getOwnAvatar(avatar);
|
||||
ui.avatarLabel->setPixmap(avatar);
|
||||
return;
|
||||
}
|
||||
ui->avatarLabel->setPixmap(img);
|
||||
updateInterface();
|
||||
}
|
||||
|
||||
void AvatarDialog::removeAvatar()
|
||||
{
|
||||
ui.avatarLabel->setPixmap(NULL);
|
||||
ui->avatarLabel->setPixmap(QPixmap());
|
||||
updateInterface();
|
||||
}
|
||||
|
||||
void AvatarDialog::saveAvatar()
|
||||
{
|
||||
const QPixmap *pixmap = ui.avatarLabel->pixmap();
|
||||
|
||||
if (!pixmap->isNull())
|
||||
{
|
||||
QByteArray ba;
|
||||
QBuffer buffer(&ba);
|
||||
|
||||
buffer.open(QIODevice::WriteOnly);
|
||||
pixmap->save(&buffer, "PNG"); // writes image into ba in PNG format
|
||||
|
||||
rsMsgs->setOwnAvatarData((unsigned char *)(ba.data()), ba.size()) ; // last char 0 included.
|
||||
|
||||
}
|
||||
|
||||
close();
|
||||
}
|
||||
|
||||
void AvatarDialog::setAvatar(const RsGxsImage &avatar)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void AvatarDialog::getAvatar(RsGxsImage &avatar)
|
||||
void AvatarDialog::updateInterface()
|
||||
{
|
||||
|
||||
const QPixmap *pixmap = ui->avatarLabel->pixmap();
|
||||
if (pixmap && !pixmap->isNull()) {
|
||||
ui->removeButton->setEnabled(true);
|
||||
} else {
|
||||
ui->removeButton->setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
void AvatarDialog::setAvatar(const QPixmap &avatar)
|
||||
{
|
||||
ui->avatarLabel->setPixmap(avatar);
|
||||
updateInterface();
|
||||
}
|
||||
|
||||
void AvatarDialog::getAvatar(QPixmap &avatar)
|
||||
{
|
||||
const QPixmap *pixmap = ui->avatarLabel->pixmap();
|
||||
if (!pixmap) {
|
||||
avatar = QPixmap();
|
||||
return;
|
||||
}
|
||||
|
||||
avatar = *pixmap;
|
||||
}
|
||||
|
||||
void AvatarDialog::getAvatar(QByteArray &avatar)
|
||||
{
|
||||
const QPixmap *pixmap = ui->avatarLabel->pixmap();
|
||||
if (!pixmap) {
|
||||
avatar.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
QBuffer buffer(&avatar);
|
||||
|
||||
buffer.open(QIODevice::WriteOnly);
|
||||
pixmap->save(&buffer, "PNG"); // writes image into ba in PNG format
|
||||
}
|
||||
|
|
|
@ -24,21 +24,15 @@
|
|||
#ifndef _AVATARDIALOG_H
|
||||
#define _AVATARDIALOG_H
|
||||
|
||||
#include "ui_AvatarDialog.h"
|
||||
#include <QDialog>
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "util/TokenQueue.h"
|
||||
#include <retroshare/rsidentity.h>
|
||||
#include <retroshare/rsgxsifacetypes.h>
|
||||
#include <retroshare/rsgxscommon.h>
|
||||
#include <QString>
|
||||
class QPixmap;
|
||||
class QByteArray;
|
||||
|
||||
namespace Ui {
|
||||
class AvatarDialog;
|
||||
}
|
||||
|
||||
|
||||
class AvatarDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
@ -46,20 +40,21 @@ class AvatarDialog : public QDialog
|
|||
public:
|
||||
AvatarDialog(QWidget *parent = 0);
|
||||
~AvatarDialog();
|
||||
|
||||
void setAvatar(const RsGxsImage &avatar);
|
||||
void getAvatar(RsGxsImage &avatar);
|
||||
|
||||
void setAvatar(const QPixmap &avatar);
|
||||
|
||||
void getAvatar(QPixmap &avatar);
|
||||
void getAvatar(QByteArray &avatar);
|
||||
|
||||
private slots:
|
||||
|
||||
void changeAvatar();
|
||||
void removeAvatar();
|
||||
void saveAvatar();
|
||||
void loadOwnAvatar();
|
||||
void changeAvatar();
|
||||
void removeAvatar();
|
||||
|
||||
private:
|
||||
Ui::AvatarDialog ui;
|
||||
void updateInterface();
|
||||
|
||||
private:
|
||||
Ui::AvatarDialog *ui;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -55,6 +55,12 @@
|
|||
<height>128</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::Box</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Sunken</enum>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Your Avatar Picture</string>
|
||||
</property>
|
||||
|
|
|
@ -28,8 +28,6 @@
|
|||
#include "gui/common/AvatarDefs.h"
|
||||
#include "gui/common/AvatarDialog.h"
|
||||
|
||||
#include "util/misc.h"
|
||||
|
||||
#include "AvatarWidget.h"
|
||||
#include "ui_AvatarWidget.h"
|
||||
|
||||
|
@ -84,9 +82,21 @@ QString AvatarWidget::frameState()
|
|||
|
||||
void AvatarWidget::mouseReleaseEvent(QMouseEvent */*event*/)
|
||||
{
|
||||
if (mFlag.isOwnId) {
|
||||
AvatarDialog *dialog = new AvatarDialog();
|
||||
dialog->show();
|
||||
if (!mFlag.isOwnId) {
|
||||
return;
|
||||
}
|
||||
|
||||
AvatarDialog dialog(this);
|
||||
|
||||
QPixmap avatar;
|
||||
AvatarDefs::getOwnAvatar(avatar, "");
|
||||
|
||||
dialog.setAvatar(avatar);
|
||||
if (dialog.exec() == QDialog::Accepted) {
|
||||
QByteArray newAvatar;
|
||||
dialog.getAvatar(newAvatar);
|
||||
|
||||
rsMsgs->setOwnAvatarData((unsigned char *)(newAvatar.data()), newAvatar.size()) ; // last char 0 included.
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue