mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-27 00:19:25 -05:00
Applied patch from AsamK and fixed german translation.
Reduced code duplication with avatar picture loading, by creating two new functions that handle image choosing and thumbnail creation. two new functions: bool misc::getOpenAvatarPicture(QWidget *parent, QByteArray &image_data) QPixmap misc::getOpenThumbnailedPicture(QWidget *parent, const QString &caption, int width, int height) getOpenThumbnailedPicture opens a QFileDialog to let the user choose a picture file. This picture is converted to a thumbnail and returned as a QPixmap. getOpenAvatarPicture calls getOpenThumbnailedPicture and converts the result to a PNG byte array. All three avatar loading functions now call getOpenAvatarPicture Furthermore Channel Logo and Channel Msg thumbnail functions now use getOpenThumbnailedPicture git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4561 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
43c0594d18
commit
0fbada0eba
@ -1810,39 +1810,17 @@ void FriendsDialog::updateAvatar()
|
||||
|
||||
void FriendsDialog::getAvatar()
|
||||
{
|
||||
QString fileName;
|
||||
if (misc::getOpenFileName(this, RshareSettings::LASTDIR_IMAGES, tr("Load File"), tr("Pictures (*.png *.xpm *.jpg *.tiff *.gif)"), fileName))
|
||||
QByteArray ba;
|
||||
if (misc::getOpenAvatarPicture(this, ba))
|
||||
{
|
||||
QPixmap picture;
|
||||
picture = QPixmap(fileName).scaled(96,96, Qt::IgnoreAspectRatio,Qt::SmoothTransformation);
|
||||
|
||||
#ifdef FRIENDS_DEBUG
|
||||
std::cerr << "Sending avatar image down the pipe" << std::endl ;
|
||||
std::cerr << "Avatar image size = " << ba.size() << std::endl ;
|
||||
#endif
|
||||
|
||||
// send avatar down the pipe for other peers to get it.
|
||||
QByteArray ba;
|
||||
QBuffer buffer(&ba);
|
||||
buffer.open(QIODevice::WriteOnly);
|
||||
picture.save(&buffer, "PNG"); // writes image into ba in PNG format
|
||||
|
||||
#ifdef FRIENDS_DEBUG
|
||||
std::cerr << "Image size = " << ba.size() << std::endl ;
|
||||
#endif
|
||||
|
||||
rsMsgs->setOwnAvatarData((unsigned char *)(ba.data()),ba.size()) ; // last char 0 included.
|
||||
|
||||
// I suppressed this because it gets called already by rsMsgs->setOwnAvatarData() through a Qt notification signal
|
||||
//updateAvatar() ;
|
||||
rsMsgs->setOwnAvatarData((unsigned char *)(ba.data()), ba.size()) ; // last char 0 included.
|
||||
}
|
||||
}
|
||||
|
||||
void FriendsDialog::changeAvatarClicked()
|
||||
{
|
||||
|
||||
updateAvatar();
|
||||
}
|
||||
|
||||
void FriendsDialog::on_actionCreate_New_Forum_activated()
|
||||
{
|
||||
MainWindow::activatePage (MainWindow::Forums);
|
||||
|
@ -145,7 +145,6 @@ private slots:
|
||||
void setFont();
|
||||
void getFont();
|
||||
|
||||
void changeAvatarClicked();
|
||||
void getAvatar();
|
||||
void updateOwnStatus(const QString &peer_id, int status);
|
||||
|
||||
@ -222,4 +221,4 @@ private:
|
||||
|
||||
#endif // MINIMAL_RSGUI
|
||||
|
||||
#endif
|
||||
#endif
|
@ -23,7 +23,6 @@
|
||||
#include <QFileInfo>
|
||||
#include <QWidgetAction>
|
||||
#include <QTimer>
|
||||
#include <QBuffer>
|
||||
|
||||
#include "common/vmessagebox.h"
|
||||
#include "common/StatusDefs.h"
|
||||
@ -51,6 +50,7 @@
|
||||
#include "util/PixmapMerging.h"
|
||||
#include "LogoBar.h"
|
||||
#include "util/Widget.h"
|
||||
#include "util/misc.h"
|
||||
#include "settings/rsharesettings.h"
|
||||
#include "common/RSTreeWidgetItem.h"
|
||||
|
||||
@ -1085,11 +1085,6 @@ void MessengerWindow::sendMessage()
|
||||
MessageComposer::msgFriend(id, false);
|
||||
}
|
||||
|
||||
void MessengerWindow::changeAvatarClicked()
|
||||
{
|
||||
updateAvatar();
|
||||
}
|
||||
|
||||
void MessengerWindow::updateAvatar()
|
||||
{
|
||||
unsigned char *data = NULL;
|
||||
@ -1112,24 +1107,13 @@ void MessengerWindow::updateAvatar()
|
||||
|
||||
void MessengerWindow::getAvatar()
|
||||
{
|
||||
QString fileName = QFileDialog::getOpenFileName(this, "Load File", QDir::homePath(), "Pictures (*.png *.xpm *.jpg)");
|
||||
if(!fileName.isEmpty())
|
||||
QByteArray ba;
|
||||
if (misc::getOpenAvatarPicture(this, ba))
|
||||
{
|
||||
picture = QPixmap(fileName).scaled(96,96, Qt::IgnoreAspectRatio,Qt::SmoothTransformation);
|
||||
|
||||
std::cerr << "Sending avatar image down the pipe" << std::endl ;
|
||||
|
||||
// send avatar down the pipe for other peers to get it.
|
||||
QByteArray ba;
|
||||
QBuffer buffer(&ba);
|
||||
buffer.open(QIODevice::WriteOnly);
|
||||
picture.save(&buffer, "PNG"); // writes image into ba in PNG format
|
||||
|
||||
std::cerr << "Image size = " << ba.size() << std::endl ;
|
||||
|
||||
rsMsgs->setOwnAvatarData((unsigned char *)(ba.data()),ba.size()) ; // last char 0 included.
|
||||
|
||||
updateAvatar() ;
|
||||
#ifdef MSG_DEBUG
|
||||
std::cerr << "Avatar image size = " << ba.size() << std::endl ;
|
||||
#endif
|
||||
rsMsgs->setOwnAvatarData((unsigned char *)(ba.data()), ba.size()) ; // last char 0 included.
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -91,7 +91,6 @@ private slots:
|
||||
/** get own last stored Avatar**/
|
||||
void getAvatar();
|
||||
|
||||
void changeAvatarClicked();
|
||||
void updateOwnStatus(const QString &peer_id, int status);
|
||||
|
||||
void savestatusmessage();
|
||||
@ -138,4 +137,4 @@ private:
|
||||
Ui::MessengerWindow ui;
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
@ -241,14 +241,15 @@ void CreateChannel::cancelChannel()
|
||||
return;
|
||||
}
|
||||
|
||||
void CreateChannel::addChannelLogo()
|
||||
void CreateChannel::addChannelLogo() // the same function as in EditChanDetails
|
||||
{
|
||||
QString fileName;
|
||||
if (misc::getOpenFileName(this, RshareSettings::LASTDIR_IMAGES, tr("Load File"), tr("Pictures (*.png *.xpm *.jpg)"), fileName))
|
||||
{
|
||||
picture = QPixmap(fileName).scaled(64,64, Qt::IgnoreAspectRatio,Qt::SmoothTransformation);
|
||||
QPixmap img = misc::getOpenThumbnailedPicture(this, tr("Load channel logo"), 64, 64);
|
||||
|
||||
// to show the selected
|
||||
ui.ChannelLogoButton->setIcon(picture);
|
||||
}
|
||||
if (img.isNull())
|
||||
return;
|
||||
|
||||
picture = img;
|
||||
|
||||
// to show the selected
|
||||
ui.ChannelLogoButton->setIcon(picture);
|
||||
}
|
||||
|
@ -571,24 +571,13 @@ void CreateChannelMsg::sendMessage(std::wstring subject, std::wstring msg, std::
|
||||
|
||||
void CreateChannelMsg::addThumbnail()
|
||||
{
|
||||
QString fileName;
|
||||
if (misc::getOpenFileName(this, RshareSettings::LASTDIR_IMAGES, tr("Load File"), tr("Pictures (*.png *.xpm *.jpg)"), fileName))
|
||||
{
|
||||
picture = QPixmap(fileName).scaled(156,107, Qt::IgnoreAspectRatio,Qt::SmoothTransformation);
|
||||
|
||||
// to show the selected
|
||||
thumbnail_label->setPixmap(picture);
|
||||
QPixmap img = misc::getOpenThumbnailedPicture(this, tr("Load thumbnail picture"), 156, 107);
|
||||
|
||||
std::cerr << "Sending Thumbnail image down the pipe" << std::endl ;
|
||||
if (img.isNull())
|
||||
return;
|
||||
|
||||
// send Thumbnail down the pipe for other peers to get it.
|
||||
QByteArray ba;
|
||||
QBuffer buffer(&ba);
|
||||
buffer.open(QIODevice::WriteOnly);
|
||||
picture.save(&buffer, "PNG"); // writes image into ba in PNG format
|
||||
picture = img;
|
||||
|
||||
std::cerr << "Image size = " << ba.size() << std::endl ;
|
||||
|
||||
//updateThumbnail() ;
|
||||
}
|
||||
// to show the selected
|
||||
thumbnail_label->setPixmap(picture);
|
||||
}
|
||||
|
@ -135,15 +135,16 @@ void EditChanDetails::applyDialog()
|
||||
}
|
||||
|
||||
|
||||
void EditChanDetails::addChannelLogo()
|
||||
void EditChanDetails::addChannelLogo() // the same function as in CreateChannel
|
||||
{
|
||||
QString fileName = QFileDialog::getOpenFileName(this, tr("Load File"), QDir::homePath(), tr("Pictures (*.png *.xpm *.jpg)"));
|
||||
if(!fileName.isEmpty())
|
||||
{
|
||||
picture = QPixmap(fileName).scaled(64,64, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
|
||||
QPixmap img = misc::getOpenThumbnailedPicture(this, tr("Load channel logo"), 64, 64);
|
||||
|
||||
// to show the selected
|
||||
ui.ChannelLogoButton->setIcon(picture);
|
||||
}
|
||||
if (img.isNull())
|
||||
return;
|
||||
|
||||
picture = img;
|
||||
|
||||
// to show the selected
|
||||
ui.ChannelLogoButton->setIcon(picture);
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,6 @@
|
||||
****************************************************************/
|
||||
|
||||
#include <QPixmap>
|
||||
#include <QBuffer>
|
||||
|
||||
#include "PopupChatWindow.h"
|
||||
#include "PopupChatDialog.h"
|
||||
@ -291,20 +290,10 @@ void PopupChatWindow::calculateTitle(PopupChatDialog *dialog)
|
||||
|
||||
void PopupChatWindow::getAvatar()
|
||||
{
|
||||
QString fileName;
|
||||
if (misc::getOpenFileName(this, RshareSettings::LASTDIR_IMAGES, tr("Load File"), tr("Pictures (*.png *.xpm *.jpg *.tiff *.gif)"), fileName))
|
||||
QByteArray ba;
|
||||
if (misc::getOpenAvatarPicture(this, ba))
|
||||
{
|
||||
QPixmap picture = QPixmap(fileName).scaled(96,96, Qt::IgnoreAspectRatio,Qt::SmoothTransformation);
|
||||
|
||||
std::cerr << "Sending avatar image down the pipe" << std::endl;
|
||||
|
||||
// send avatar down the pipe for other peers to get it.
|
||||
QByteArray ba;
|
||||
QBuffer buffer(&ba);
|
||||
buffer.open(QIODevice::WriteOnly);
|
||||
picture.save(&buffer, "PNG"); // writes image into ba in PNG format
|
||||
|
||||
std::cerr << "Image size = " << ba.size() << std::endl;
|
||||
std::cerr << "Avatar image size = " << ba.size() << std::endl ;
|
||||
|
||||
rsMsgs->setOwnAvatarData((unsigned char *)(ba.data()), ba.size()); // last char 0 included.
|
||||
}
|
||||
|
Binary file not shown.
File diff suppressed because it is too large
Load Diff
@ -23,6 +23,8 @@
|
||||
#include <QString>
|
||||
#include <QDir>
|
||||
#include <QFileDialog>
|
||||
#include <QByteArray>
|
||||
#include <QBuffer>
|
||||
|
||||
#include "misc.h"
|
||||
|
||||
@ -243,6 +245,43 @@ QString misc::removeNewLine(const std::wstring &text)
|
||||
return QString::fromStdWString(text).replace("\n", " ");
|
||||
}
|
||||
|
||||
/*!
|
||||
* Let's the user choose an avatar picture file, which is returned as a PNG thumbnail
|
||||
* in a byte array
|
||||
*
|
||||
* return false, if the user canceled the dialog, otherwise true
|
||||
*/
|
||||
bool misc::getOpenAvatarPicture(QWidget *parent, QByteArray &image_data)
|
||||
{
|
||||
QPixmap picture = getOpenThumbnailedPicture(parent, tr("Load avatar image"), 96, 96);
|
||||
|
||||
if (picture.isNull())
|
||||
return false;
|
||||
|
||||
// save image in QByteArray
|
||||
QBuffer buffer(&image_data);
|
||||
buffer.open(QIODevice::WriteOnly);
|
||||
picture.save(&buffer, "PNG"); // writes image into ba in PNG format
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*!
|
||||
* Open a QFileDialog to let the user choose a picture file.
|
||||
* This picture is converted to a thumbnail and returned as a QPixmap.
|
||||
*
|
||||
* \return a null pixmap, if the user canceled the dialog, otherwise the chosen picture
|
||||
*/
|
||||
QPixmap misc::getOpenThumbnailedPicture(QWidget *parent, const QString &caption, int width, int height)
|
||||
{
|
||||
// Let the user choose an picture file
|
||||
QString fileName;
|
||||
if (!getOpenFileName(parent, RshareSettings::LASTDIR_IMAGES, caption, tr("Pictures (*.png *.xpm *.jpg *.tiff *.gif)"), fileName))
|
||||
return QPixmap();
|
||||
|
||||
return QPixmap(fileName).scaled(width, height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
|
||||
}
|
||||
|
||||
bool misc::getOpenFileName(QWidget *parent, RshareSettings::enumLastDir type, const QString &caption, const QString &filter, QString &file)
|
||||
{
|
||||
QString lastDir = Settings->getLastDir(type);
|
||||
|
@ -156,6 +156,8 @@ class misc : public QObject
|
||||
static QString removeNewLine(const std::string &text);
|
||||
static QString removeNewLine(const std::wstring &text);
|
||||
|
||||
static bool getOpenAvatarPicture(QWidget *parent, QByteArray &image_data);
|
||||
static QPixmap getOpenThumbnailedPicture(QWidget *parent, const QString &caption, int width, int height);
|
||||
static bool getOpenFileName(QWidget *parent, RshareSettings::enumLastDir type, const QString &caption, const QString &filter, QString &file);
|
||||
static bool getOpenFileNames(QWidget *parent, RshareSettings::enumLastDir type, const QString &caption, const QString &filter, QStringList &files);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user