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;

View File

@ -51,6 +51,8 @@ private slots:
void smileyWidgetForums();
void addSmileys();
void addFile();
void addPicture();
void checkLength();
void reject();
protected:

View File

@ -200,6 +200,29 @@
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="attachPictureButton">
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="toolTip">
<string>Attach a Picture</string>
</property>
<property name="icon">
<iconset resource="../icons.qrc">
<normaloff>:/icons/png/attach-image.png</normaloff>:/icons/png/attach-image.png</iconset>
</property>
<property name="iconSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation">
@ -259,6 +282,13 @@ p, li { white-space: pre-wrap; }
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="infoLabel">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</widget>
</item>
@ -268,7 +298,7 @@ p, li { white-space: pre-wrap; }
<string>Attach files via drag and drop</string>
</property>
<layout class="QGridLayout" name="gridLayout_7">
<item row="0" column="0">
<item row="1" column="0">
<widget class="HashBox" name="hashBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Minimum">
@ -369,6 +399,7 @@ p, li { white-space: pre-wrap; }
<resources>
<include location="../images.qrc"/>
<include location="../emojione.qrc"/>
<include location="../icons.qrc"/>
</resources>
<connections/>
</ui>