added atach picture button to forum post

This commit is contained in:
defnax 2019-09-29 17:32:14 +02:00
parent c228e4058d
commit 25e966d039
3 changed files with 66 additions and 1 deletions

View file

@ -25,6 +25,7 @@
#include <QDesktopWidget>
#include <QDropEvent>
#include <QPushButton>
#include <QTextDocumentFragment>
#include <retroshare/rsgxsforums.h>
#include <retroshare/rsgxscircles.h>
@ -103,6 +104,8 @@ CreateGxsForumMsg::CreateGxsForumMsg(const RsGxsGroupId &fId, const RsGxsMessage
connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
connect(ui.emoticonButton, SIGNAL(clicked()), this, SLOT(smileyWidgetForums()));
connect(ui.attachFileButton, SIGNAL(clicked()), this, SLOT(addFile()));
connect(ui.attachPictureButton, SIGNAL(clicked()), this, SLOT(addPicture()));
connect(ui.forumMessage, SIGNAL(textChanged()), this, SLOT(checkLength()));
connect(ui.generateCheckBox, SIGNAL(toggled(bool)), ui.generateSpinBox, SLOT(setEnabled(bool)));
setAcceptDrops(true);
@ -337,6 +340,23 @@ void CreateGxsForumMsg::loadFormInformation()
//ui.forumMessage->setText("");
}
static const uint32_t MAX_ALLOWED_GXS_MESSAGE_SIZE = 199000;
void CreateGxsForumMsg::checkLength()
{
QString text;
RsHtml::optimizeHtml(ui.forumMessage, text);
std::wstring msg = text.toStdWString();
int charRemains = MAX_ALLOWED_GXS_MESSAGE_SIZE - msg.length();
if(charRemains >= 0)
text = tr("It remains %1 characters after HTML conversion.").arg(charRemains);
else
text = tr("Warning: This message is too big of %1 characters after HTML conversion.").arg((0-charRemains));
ui.buttonBox->button(QDialogButtonBox::Ok)->setToolTip(text);
ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(charRemains>=0);
ui.infoLabel->setText(text);
}
void CreateGxsForumMsg::createMsg()
{
QString name = misc::removeNewLine(ui.forumSubject->text());
@ -489,6 +509,18 @@ void CreateGxsForumMsg::addFile()
}
}
void CreateGxsForumMsg::addPicture()
{
QString file;
if (misc::getOpenFileName(window(), RshareSettings::LASTDIR_IMAGES, tr("Load Picture File"), "Pictures (*.png *.xpm *.jpg *.jpeg)", file)) {
QString encodedImage;
if (RsHtml::makeEmbeddedImage(file, encodedImage, 640*480, MAX_ALLOWED_GXS_MESSAGE_SIZE - 200)) {
QTextDocumentFragment fragment = QTextDocumentFragment::fromHtml(encodedImage);
ui.forumMessage->textCursor().insertFragment(fragment);
}
}
}
void CreateGxsForumMsg::fileHashingFinished(QList<HashedFile> hashedFiles)
{
//std::cerr << "CreateGxsForumMsg::fileHashingFinished() started." << std::endl;