Allow to import stickers from chat window

This commit is contained in:
hunbernd 2019-10-05 23:18:41 +02:00
parent 641964fff9
commit e52f1282ec
7 changed files with 46 additions and 12 deletions

View File

@ -32,6 +32,7 @@
#include <QTextStream>
#include <QTimer>
#include <QToolTip>
#include <QInputDialog>
#include "ChatWidget.h"
#include "ui_ChatWidget.h"
@ -162,6 +163,7 @@ ChatWidget::ChatWidget(QWidget *parent)
connect(ui->actionQuote, SIGNAL(triggered()), this, SLOT(quote()));
connect(ui->actionDropPlacemark, SIGNAL(triggered()), this, SLOT(dropPlacemark()));
connect(ui->actionSave_image, SIGNAL(triggered()), this, SLOT(saveImage()));
connect(ui->actionImport_sticker, SIGNAL(triggered()), this, SLOT(saveSticker()));
connect(ui->actionShow_Hidden_Images, SIGNAL(triggered()), ui->textBrowser, SLOT(showImages()));
ui->actionShow_Hidden_Images->setIcon(ui->textBrowser->getBlockedImage());
@ -1127,7 +1129,9 @@ void ChatWidget::contextMenuTextBrowser(QPoint point)
contextMnu->addAction(ui->actionShow_Hidden_Images);
ui->actionSave_image->setData(point);
ui->actionImport_sticker->setData(point);
contextMnu->addAction(ui->actionSave_image);
contextMnu->addAction(ui->actionImport_sticker);
}
QString anchor = ui->textBrowser->anchorForPosition(point);
@ -1909,3 +1913,13 @@ void ChatWidget::saveImage()
QTextCursor cursor = ui->textBrowser->cursorForPosition(point);
ImageUtil::extractImage(window(), cursor);
}
void ChatWidget::saveSticker()
{
QPoint point = ui->actionImport_sticker->data().toPoint();
QTextCursor cursor = ui->textBrowser->cursorForPosition(point);
QString filename = QInputDialog::getText(window(), "Import sticker", "Sticker name");
if(filename.isEmpty()) return;
filename = Emoticons::importedStickerPath() + "/" + filename + ".png";
ImageUtil::extractImage(window(), cursor, filename);
}

View File

@ -194,6 +194,7 @@ private slots:
void quote();
void dropPlacemark();
void saveImage();
void saveSticker();
private:
bool findText(const QString& qsStringToFind);

View File

@ -918,6 +918,15 @@ border-image: url(:/images/closepressed.png)
<string>Save image</string>
</property>
</action>
<action name="actionImport_sticker">
<property name="icon">
<iconset resource="../images.qrc">
<normaloff>:/icons/png/addstickers.png</normaloff>:/icons/png/addstickers.png</iconset>
</property>
<property name="text">
<string>Import sticker</string>
</property>
</action>
<action name="actionSendAsPlainText">
<property name="checkable">
<bool>true</bool>

View File

@ -29,6 +29,7 @@
#include <QTabWidget>
#include <QWidget>
#include <QMessageBox>
#include <QDir>
#include <iostream>
#include <math.h>
@ -49,9 +50,12 @@ void Emoticons::load()
{
loadSmiley();
filters << "*.png" << "*.jpg" << "*.gif";
stickerFolders << (QString::fromStdString(RsAccounts::ConfigDirectory()) + "/stickers"); //under .retroshare, shared between users
stickerFolders << (QString::fromStdString(RsAccounts::AccountDirectory()) + "/stickers"); //under account, unique for user
stickerFolders << (QString::fromStdString(RsAccounts::ConfigDirectory()) + "/stickers"); //under .retroshare, shared between users
stickerFolders << (QString::fromStdString(RsAccounts::systemDataDirectory()) + "/stickers"); //exe's folder, shipped with RS
QDir dir(QString::fromStdString(RsAccounts::AccountDirectory()));
dir.mkpath("stickers/imported");
}
void Emoticons::loadSmiley()
@ -458,6 +462,12 @@ void Emoticons::showStickerWidget(QWidget *parent, QWidget *button, const char *
QApplication::restoreOverrideCursor();
}
QString Emoticons::importedStickerPath()
{
QDir dir(stickerFolders[0]);
return dir.absoluteFilePath("imported");
}
void Emoticons::loadToolTips(QWidget *container)
{
QApplication::setOverrideCursor(Qt::WaitCursor);

View File

@ -30,15 +30,15 @@ class Emoticons
{
public:
static void load();
static void loadSmiley();
static void refreshStickerTabs(QVector<QString>& stickerTabs, QString foldername);
static void refreshStickerTabs(QVector<QString>& stickerTabs);
static void showSmileyWidget(QWidget *parent, QWidget *button, const char *slotAddMethod, bool above);
static void showStickerWidget(QWidget *parent, QWidget *button, const char *slotAddMethod, bool above);
static QString importedStickerPath();
private:
static void loadToolTips(QWidget *container);
static void loadSmiley();
static void refreshStickerTabs(QVector<QString>& stickerTabs, QString foldername);
static void refreshStickerTabs(QVector<QString>& stickerTabs);
};
#endif

View File

@ -37,7 +37,7 @@
ImageUtil::ImageUtil() {}
void ImageUtil::extractImage(QWidget *window, QTextCursor cursor)
void ImageUtil::extractImage(QWidget *window, QTextCursor cursor, QString file)
{
cursor.movePosition(QTextCursor::Left, QTextCursor::MoveAnchor, 1);
cursor.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor, 2);
@ -52,13 +52,13 @@ void ImageUtil::extractImage(QWidget *window, QTextCursor cursor)
QImage image = QImage::fromData(ba);
if(!image.isNull())
{
QString file;
success = true;
if(misc::getSaveFileName(window, RshareSettings::LASTDIR_IMAGES, "Save Picture File", "Pictures (*.png *.xpm *.jpg)", file))
if(!file.isEmpty() || misc::getSaveFileName(window, RshareSettings::LASTDIR_IMAGES, "Save Picture File", "Pictures (*.png *.xpm *.jpg)", file))
{
if(!image.save(file, 0, 100))
if(!image.save(file + ".png", 0, 100))
QMessageBox::warning(window, QApplication::translate("ImageUtil", "Save image"), QApplication::translate("ImageUtil", "Cannot save the image, invalid filename"));
if(!image.save(file, nullptr, 100))
if(!image.save(file + ".png", nullptr, 100))
QMessageBox::warning(window, QApplication::translate("ImageUtil", "Save image"), QApplication::translate("ImageUtil", "Cannot save the image, invalid filename")
+ "\n" + file);
}
}
}

View File

@ -30,7 +30,7 @@ class ImageUtil
public:
ImageUtil();
static void extractImage(QWidget *window, QTextCursor cursor);
static void extractImage(QWidget *window, QTextCursor cursor, QString file = "");
static bool optimizeSize(QString &html, const QImage& original, QImage &optimized, int maxPixels = -1, int maxBytes = -1);
private: