bypass useless avatar dialog when choosing own avatar

This commit is contained in:
csoler 2019-08-15 18:11:57 +02:00
parent 6e7a86058d
commit 74b8ed0633
No known key found for this signature in database
GPG Key ID: 7BCA522266C0804C
2 changed files with 33 additions and 19 deletions

View File

@ -145,17 +145,14 @@
</property> </property>
<item row="0" column="0" rowspan="2"> <item row="0" column="0" rowspan="2">
<widget class="AvatarWidget" name="avatar"> <widget class="AvatarWidget" name="avatar">
<property name="minimumSize"> <property name="sizePolicy">
<size> <sizepolicy hsizetype="Maximum" vsizetype="Maximum">
<width>61</width> <horstretch>0</horstretch>
<height>61</height> <verstretch>0</verstretch>
</size> </sizepolicy>
</property> </property>
<property name="maximumSize"> <property name="scaledContents">
<size> <bool>false</bool>
<width>61</width>
<height>61</height>
</size>
</property> </property>
</widget> </widget>
</item> </item>

View File

@ -18,12 +18,15 @@
* * * *
*******************************************************************************/ *******************************************************************************/
#include <QBuffer>
#include <rshare.h> #include <rshare.h>
#include <retroshare/rsstatus.h> #include <retroshare/rsstatus.h>
#include <retroshare/rspeers.h> #include <retroshare/rspeers.h>
#include <retroshare/rsmsgs.h> #include <retroshare/rsmsgs.h>
#include "gui/notifyqt.h" #include "gui/notifyqt.h"
#include "util/misc.h"
#include "gui/common/AvatarDefs.h" #include "gui/common/AvatarDefs.h"
#include "gui/common/AvatarDialog.h" #include "gui/common/AvatarDialog.h"
@ -85,19 +88,33 @@ void AvatarWidget::mouseReleaseEvent(QMouseEvent */*event*/)
if (!mFlag.isOwnId) { if (!mFlag.isOwnId) {
return; return;
} }
QPixmap img = misc::getOpenThumbnailedPicture(this, tr("Choose avatar"), AvatarDialog::RS_AVATAR_DEFAULT_IMAGE_W,AvatarDialog::RS_AVATAR_DEFAULT_IMAGE_H);
AvatarDialog dialog(this); if (img.isNull())
return;
QPixmap avatar; setPixmap(img);
AvatarDefs::getOwnAvatar(avatar, "");
dialog.setAvatar(avatar); QByteArray data;
if (dialog.exec() == QDialog::Accepted) { QBuffer buffer(&data);
QByteArray newAvatar;
dialog.getAvatar(newAvatar);
rsMsgs->setOwnAvatarData((unsigned char *)(newAvatar.data()), newAvatar.size()) ; // last char 0 included. buffer.open(QIODevice::WriteOnly);
} img.save(&buffer, "PNG"); // writes image into a in PNG format
rsMsgs->setOwnAvatarData((unsigned char *)(data.data()), data.size()) ; // last char 0 included.
// 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.
// }
} }
void AvatarWidget::setFrameType(FrameType type) void AvatarWidget::setFrameType(FrameType type)