mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-13 08:29:32 -05:00
Merge pull request #1658 from defnax/attach-picture-button-in-forum-post-dialog;-message-size-check-
Attach picture button in forum post dialog & message size check
This commit is contained in:
commit
0566d08087
@ -25,6 +25,7 @@
|
|||||||
#include <QDesktopWidget>
|
#include <QDesktopWidget>
|
||||||
#include <QDropEvent>
|
#include <QDropEvent>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
|
#include <QTextDocumentFragment>
|
||||||
|
|
||||||
#include <retroshare/rsgxsforums.h>
|
#include <retroshare/rsgxsforums.h>
|
||||||
#include <retroshare/rsgxscircles.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.buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
|
||||||
connect(ui.emoticonButton, SIGNAL(clicked()), this, SLOT(smileyWidgetForums()));
|
connect(ui.emoticonButton, SIGNAL(clicked()), this, SLOT(smileyWidgetForums()));
|
||||||
connect(ui.attachFileButton, SIGNAL(clicked()), this, SLOT(addFile()));
|
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)));
|
connect(ui.generateCheckBox, SIGNAL(toggled(bool)), ui.generateSpinBox, SLOT(setEnabled(bool)));
|
||||||
|
|
||||||
setAcceptDrops(true);
|
setAcceptDrops(true);
|
||||||
@ -337,6 +340,23 @@ void CreateGxsForumMsg::loadFormInformation()
|
|||||||
//ui.forumMessage->setText("");
|
//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()
|
void CreateGxsForumMsg::createMsg()
|
||||||
{
|
{
|
||||||
QString name = misc::removeNewLine(ui.forumSubject->text());
|
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)
|
void CreateGxsForumMsg::fileHashingFinished(QList<HashedFile> hashedFiles)
|
||||||
{
|
{
|
||||||
//std::cerr << "CreateGxsForumMsg::fileHashingFinished() started." << std::endl;
|
//std::cerr << "CreateGxsForumMsg::fileHashingFinished() started." << std::endl;
|
||||||
|
@ -51,6 +51,8 @@ private slots:
|
|||||||
void smileyWidgetForums();
|
void smileyWidgetForums();
|
||||||
void addSmileys();
|
void addSmileys();
|
||||||
void addFile();
|
void addFile();
|
||||||
|
void addPicture();
|
||||||
|
void checkLength();
|
||||||
void reject();
|
void reject();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -200,6 +200,29 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</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>
|
<item>
|
||||||
<spacer>
|
<spacer>
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
@ -259,6 +282,13 @@ p, li { white-space: pre-wrap; }
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="1" column="0">
|
||||||
|
<widget class="QLabel" name="infoLabel">
|
||||||
|
<property name="text">
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
@ -268,7 +298,7 @@ p, li { white-space: pre-wrap; }
|
|||||||
<string>Attach files via drag and drop</string>
|
<string>Attach files via drag and drop</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout_7">
|
<layout class="QGridLayout" name="gridLayout_7">
|
||||||
<item row="0" column="0">
|
<item row="1" column="0">
|
||||||
<widget class="HashBox" name="hashBox">
|
<widget class="HashBox" name="hashBox">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Expanding" vsizetype="Minimum">
|
<sizepolicy hsizetype="Expanding" vsizetype="Minimum">
|
||||||
@ -369,6 +399,7 @@ p, li { white-space: pre-wrap; }
|
|||||||
<resources>
|
<resources>
|
||||||
<include location="../images.qrc"/>
|
<include location="../images.qrc"/>
|
||||||
<include location="../emojione.qrc"/>
|
<include location="../emojione.qrc"/>
|
||||||
|
<include location="../icons.qrc"/>
|
||||||
</resources>
|
</resources>
|
||||||
<connections/>
|
<connections/>
|
||||||
</ui>
|
</ui>
|
||||||
|
Loading…
Reference in New Issue
Block a user