mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-27 16:39:29 -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()
|
void FriendsDialog::getAvatar()
|
||||||
{
|
{
|
||||||
QString fileName;
|
|
||||||
if (misc::getOpenFileName(this, RshareSettings::LASTDIR_IMAGES, tr("Load File"), tr("Pictures (*.png *.xpm *.jpg *.tiff *.gif)"), fileName))
|
|
||||||
{
|
|
||||||
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 ;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// send avatar down the pipe for other peers to get it.
|
|
||||||
QByteArray ba;
|
QByteArray ba;
|
||||||
QBuffer buffer(&ba);
|
if (misc::getOpenAvatarPicture(this, ba))
|
||||||
buffer.open(QIODevice::WriteOnly);
|
{
|
||||||
picture.save(&buffer, "PNG"); // writes image into ba in PNG format
|
|
||||||
|
|
||||||
#ifdef FRIENDS_DEBUG
|
#ifdef FRIENDS_DEBUG
|
||||||
std::cerr << "Image size = " << ba.size() << std::endl ;
|
std::cerr << "Avatar image size = " << ba.size() << std::endl ;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
rsMsgs->setOwnAvatarData((unsigned char *)(ba.data()),ba.size()) ; // last char 0 included.
|
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() ;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FriendsDialog::changeAvatarClicked()
|
|
||||||
{
|
|
||||||
|
|
||||||
updateAvatar();
|
|
||||||
}
|
|
||||||
|
|
||||||
void FriendsDialog::on_actionCreate_New_Forum_activated()
|
void FriendsDialog::on_actionCreate_New_Forum_activated()
|
||||||
{
|
{
|
||||||
MainWindow::activatePage (MainWindow::Forums);
|
MainWindow::activatePage (MainWindow::Forums);
|
||||||
|
@ -145,7 +145,6 @@ private slots:
|
|||||||
void setFont();
|
void setFont();
|
||||||
void getFont();
|
void getFont();
|
||||||
|
|
||||||
void changeAvatarClicked();
|
|
||||||
void getAvatar();
|
void getAvatar();
|
||||||
void updateOwnStatus(const QString &peer_id, int status);
|
void updateOwnStatus(const QString &peer_id, int status);
|
||||||
|
|
||||||
|
@ -23,7 +23,6 @@
|
|||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QWidgetAction>
|
#include <QWidgetAction>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QBuffer>
|
|
||||||
|
|
||||||
#include "common/vmessagebox.h"
|
#include "common/vmessagebox.h"
|
||||||
#include "common/StatusDefs.h"
|
#include "common/StatusDefs.h"
|
||||||
@ -51,6 +50,7 @@
|
|||||||
#include "util/PixmapMerging.h"
|
#include "util/PixmapMerging.h"
|
||||||
#include "LogoBar.h"
|
#include "LogoBar.h"
|
||||||
#include "util/Widget.h"
|
#include "util/Widget.h"
|
||||||
|
#include "util/misc.h"
|
||||||
#include "settings/rsharesettings.h"
|
#include "settings/rsharesettings.h"
|
||||||
#include "common/RSTreeWidgetItem.h"
|
#include "common/RSTreeWidgetItem.h"
|
||||||
|
|
||||||
@ -1085,11 +1085,6 @@ void MessengerWindow::sendMessage()
|
|||||||
MessageComposer::msgFriend(id, false);
|
MessageComposer::msgFriend(id, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessengerWindow::changeAvatarClicked()
|
|
||||||
{
|
|
||||||
updateAvatar();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MessengerWindow::updateAvatar()
|
void MessengerWindow::updateAvatar()
|
||||||
{
|
{
|
||||||
unsigned char *data = NULL;
|
unsigned char *data = NULL;
|
||||||
@ -1112,24 +1107,13 @@ void MessengerWindow::updateAvatar()
|
|||||||
|
|
||||||
void MessengerWindow::getAvatar()
|
void MessengerWindow::getAvatar()
|
||||||
{
|
{
|
||||||
QString fileName = QFileDialog::getOpenFileName(this, "Load File", QDir::homePath(), "Pictures (*.png *.xpm *.jpg)");
|
|
||||||
if(!fileName.isEmpty())
|
|
||||||
{
|
|
||||||
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;
|
QByteArray ba;
|
||||||
QBuffer buffer(&ba);
|
if (misc::getOpenAvatarPicture(this, ba))
|
||||||
buffer.open(QIODevice::WriteOnly);
|
{
|
||||||
picture.save(&buffer, "PNG"); // writes image into ba in PNG format
|
#ifdef MSG_DEBUG
|
||||||
|
std::cerr << "Avatar image size = " << ba.size() << std::endl ;
|
||||||
std::cerr << "Image size = " << ba.size() << std::endl ;
|
#endif
|
||||||
|
rsMsgs->setOwnAvatarData((unsigned char *)(ba.data()), ba.size()) ; // last char 0 included.
|
||||||
rsMsgs->setOwnAvatarData((unsigned char *)(ba.data()),ba.size()) ; // last char 0 included.
|
|
||||||
|
|
||||||
updateAvatar() ;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,7 +91,6 @@ private slots:
|
|||||||
/** get own last stored Avatar**/
|
/** get own last stored Avatar**/
|
||||||
void getAvatar();
|
void getAvatar();
|
||||||
|
|
||||||
void changeAvatarClicked();
|
|
||||||
void updateOwnStatus(const QString &peer_id, int status);
|
void updateOwnStatus(const QString &peer_id, int status);
|
||||||
|
|
||||||
void savestatusmessage();
|
void savestatusmessage();
|
||||||
|
@ -241,14 +241,15 @@ void CreateChannel::cancelChannel()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CreateChannel::addChannelLogo()
|
void CreateChannel::addChannelLogo() // the same function as in EditChanDetails
|
||||||
{
|
{
|
||||||
QString fileName;
|
QPixmap img = misc::getOpenThumbnailedPicture(this, tr("Load channel logo"), 64, 64);
|
||||||
if (misc::getOpenFileName(this, RshareSettings::LASTDIR_IMAGES, tr("Load File"), tr("Pictures (*.png *.xpm *.jpg)"), fileName))
|
|
||||||
{
|
if (img.isNull())
|
||||||
picture = QPixmap(fileName).scaled(64,64, Qt::IgnoreAspectRatio,Qt::SmoothTransformation);
|
return;
|
||||||
|
|
||||||
|
picture = img;
|
||||||
|
|
||||||
// to show the selected
|
// to show the selected
|
||||||
ui.ChannelLogoButton->setIcon(picture);
|
ui.ChannelLogoButton->setIcon(picture);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -571,24 +571,13 @@ void CreateChannelMsg::sendMessage(std::wstring subject, std::wstring msg, std::
|
|||||||
|
|
||||||
void CreateChannelMsg::addThumbnail()
|
void CreateChannelMsg::addThumbnail()
|
||||||
{
|
{
|
||||||
QString fileName;
|
QPixmap img = misc::getOpenThumbnailedPicture(this, tr("Load thumbnail picture"), 156, 107);
|
||||||
if (misc::getOpenFileName(this, RshareSettings::LASTDIR_IMAGES, tr("Load File"), tr("Pictures (*.png *.xpm *.jpg)"), fileName))
|
|
||||||
{
|
if (img.isNull())
|
||||||
picture = QPixmap(fileName).scaled(156,107, Qt::IgnoreAspectRatio,Qt::SmoothTransformation);
|
return;
|
||||||
|
|
||||||
|
picture = img;
|
||||||
|
|
||||||
// to show the selected
|
// to show the selected
|
||||||
thumbnail_label->setPixmap(picture);
|
thumbnail_label->setPixmap(picture);
|
||||||
|
|
||||||
std::cerr << "Sending Thumbnail image down the pipe" << std::endl ;
|
|
||||||
|
|
||||||
// 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
|
|
||||||
|
|
||||||
std::cerr << "Image size = " << ba.size() << std::endl ;
|
|
||||||
|
|
||||||
//updateThumbnail() ;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -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)"));
|
QPixmap img = misc::getOpenThumbnailedPicture(this, tr("Load channel logo"), 64, 64);
|
||||||
if(!fileName.isEmpty())
|
|
||||||
{
|
if (img.isNull())
|
||||||
picture = QPixmap(fileName).scaled(64,64, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
|
return;
|
||||||
|
|
||||||
|
picture = img;
|
||||||
|
|
||||||
// to show the selected
|
// to show the selected
|
||||||
ui.ChannelLogoButton->setIcon(picture);
|
ui.ChannelLogoButton->setIcon(picture);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,6 @@
|
|||||||
****************************************************************/
|
****************************************************************/
|
||||||
|
|
||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
#include <QBuffer>
|
|
||||||
|
|
||||||
#include "PopupChatWindow.h"
|
#include "PopupChatWindow.h"
|
||||||
#include "PopupChatDialog.h"
|
#include "PopupChatDialog.h"
|
||||||
@ -291,20 +290,10 @@ void PopupChatWindow::calculateTitle(PopupChatDialog *dialog)
|
|||||||
|
|
||||||
void PopupChatWindow::getAvatar()
|
void PopupChatWindow::getAvatar()
|
||||||
{
|
{
|
||||||
QString fileName;
|
|
||||||
if (misc::getOpenFileName(this, RshareSettings::LASTDIR_IMAGES, tr("Load File"), tr("Pictures (*.png *.xpm *.jpg *.tiff *.gif)"), fileName))
|
|
||||||
{
|
|
||||||
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;
|
QByteArray ba;
|
||||||
QBuffer buffer(&ba);
|
if (misc::getOpenAvatarPicture(this, ba))
|
||||||
buffer.open(QIODevice::WriteOnly);
|
{
|
||||||
picture.save(&buffer, "PNG"); // writes image into ba in PNG format
|
std::cerr << "Avatar image size = " << ba.size() << std::endl ;
|
||||||
|
|
||||||
std::cerr << "Image size = " << ba.size() << std::endl;
|
|
||||||
|
|
||||||
rsMsgs->setOwnAvatarData((unsigned char *)(ba.data()), ba.size()); // last char 0 included.
|
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 <QString>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
|
#include <QByteArray>
|
||||||
|
#include <QBuffer>
|
||||||
|
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
|
|
||||||
@ -243,6 +245,43 @@ QString misc::removeNewLine(const std::wstring &text)
|
|||||||
return QString::fromStdWString(text).replace("\n", " ");
|
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)
|
bool misc::getOpenFileName(QWidget *parent, RshareSettings::enumLastDir type, const QString &caption, const QString &filter, QString &file)
|
||||||
{
|
{
|
||||||
QString lastDir = Settings->getLastDir(type);
|
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::string &text);
|
||||||
static QString removeNewLine(const std::wstring &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 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);
|
static bool getOpenFileNames(QWidget *parent, RshareSettings::enumLastDir type, const QString &caption, const QString &filter, QStringList &files);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user