mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-02 06:06:10 -04: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
12 changed files with 666 additions and 212 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue