mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
Added anmos changes & own improvements
Added the changes from anmo Added to store/load last used identity for posted composer Added remove button for remove the attached image Fixed to hide the Notes button when there is not text content (PosteItem) Fixed the ui margins better look
This commit is contained in:
parent
8a0eb9705f
commit
246029736d
@ -254,7 +254,13 @@ int RsDirUtil::breakupDirList(const std::string& path,
|
||||
/**** Copied and Tweaked from ftcontroller ***/
|
||||
bool RsDirUtil::fileExists(const std::string& filename)
|
||||
{
|
||||
#ifdef WINDOWS_SYS
|
||||
std::wstring wfilename;
|
||||
librs::util::ConvertUtf8ToUtf16(filename, wfilename);
|
||||
return ( _waccess( wfilename.c_str(), F_OK ) != -1 );
|
||||
#else
|
||||
return ( access( filename.c_str(), F_OK ) != -1 );
|
||||
#endif
|
||||
}
|
||||
|
||||
bool RsDirUtil::moveFile(const std::string& source,const std::string& dest)
|
||||
|
@ -20,6 +20,8 @@
|
||||
|
||||
#include <QBuffer>
|
||||
#include <QMessageBox>
|
||||
#include <QByteArray>
|
||||
#include <QStringList>
|
||||
#include "PostedCreatePostDialog.h"
|
||||
#include "ui_PostedCreatePostDialog.h"
|
||||
|
||||
@ -34,6 +36,10 @@
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <util/imageutil.h>
|
||||
|
||||
#include <gui/RetroShareLink.h>
|
||||
|
||||
PostedCreatePostDialog::PostedCreatePostDialog(TokenQueue* tokenQ, RsPosted *posted, const RsGxsGroupId& grpId, QWidget *parent):
|
||||
QDialog(parent, Qt::WindowSystemMenuHint | Qt::WindowTitleHint | Qt::WindowMinimizeButtonHint | Qt::WindowMaximizeButtonHint | Qt::WindowCloseButtonHint),
|
||||
mTokenQueue(tokenQ), mPosted(posted), mGrpId(grpId),
|
||||
@ -52,19 +58,58 @@ PostedCreatePostDialog::PostedCreatePostDialog(TokenQueue* tokenQ, RsPosted *pos
|
||||
setAttribute ( Qt::WA_DeleteOnClose, true );
|
||||
|
||||
ui->RichTextEditWidget->setPlaceHolderTextPosted();
|
||||
|
||||
ui->hashBox->setAutoHide(true);
|
||||
ui->hashBox->setDefaultTransferRequestFlags(RS_FILE_REQ_ANONYMOUS_ROUTING);
|
||||
connect(ui->hashBox, SIGNAL(fileHashingFinished(QList<HashedFile>)), this, SLOT(fileHashingFinished(QList<HashedFile>)));
|
||||
|
||||
/* fill in the available OwnIds for signing */
|
||||
ui->idChooser->loadIds(IDCHOOSER_ID_REQUIRED, RsGxsId());
|
||||
|
||||
ui->removeButton->hide();
|
||||
|
||||
/* load settings */
|
||||
processSettings(true);
|
||||
}
|
||||
|
||||
PostedCreatePostDialog::~PostedCreatePostDialog()
|
||||
{
|
||||
Settings->saveWidgetInformation(this);
|
||||
|
||||
// save settings
|
||||
processSettings(false);
|
||||
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void PostedCreatePostDialog::processSettings(bool load)
|
||||
{
|
||||
Settings->beginGroup(QString("PostedCreatePostDialog"));
|
||||
|
||||
if (load) {
|
||||
// load settings
|
||||
|
||||
// state of ID Chooser combobox
|
||||
int index = Settings->value("IDChooser", 0).toInt();
|
||||
ui->idChooser->setCurrentIndex(index);
|
||||
} else {
|
||||
// save settings
|
||||
|
||||
// state of ID Chooser combobox
|
||||
Settings->setValue("IDChooser", ui->idChooser->currentIndex());
|
||||
}
|
||||
|
||||
Settings->endGroup();
|
||||
}
|
||||
|
||||
void PostedCreatePostDialog::createPost()
|
||||
{
|
||||
if(ui->titleEdit->text().isEmpty()) {
|
||||
/* error message */
|
||||
QMessageBox::warning(this, "RetroShare", tr("Please add a Title"), QMessageBox::Ok, QMessageBox::Ok);
|
||||
return; //Don't add a empty title!!
|
||||
}
|
||||
|
||||
RsGxsId authorId;
|
||||
switch (ui->idChooser->getChosenId(authorId)) {
|
||||
case GxsIdChooser::KnowId:
|
||||
@ -85,37 +130,27 @@ void PostedCreatePostDialog::createPost()
|
||||
post.mMeta.mGroupId = mGrpId;
|
||||
post.mLink = std::string(ui->linkEdit->text().toUtf8());
|
||||
|
||||
QString text;
|
||||
text = ui->RichTextEditWidget->toHtml();
|
||||
post.mNotes = std::string(text.toUtf8());
|
||||
if(!ui->RichTextEditWidget->toPlainText().trimmed().isEmpty()) {
|
||||
QString text;
|
||||
text = ui->RichTextEditWidget->toHtml();
|
||||
post.mNotes = std::string(text.toUtf8());
|
||||
}
|
||||
|
||||
post.mMeta.mAuthorId = authorId;
|
||||
|
||||
if(!ui->titleEdit->text().isEmpty())
|
||||
{
|
||||
post.mMeta.mMsgName = std::string(ui->titleEdit->text().toUtf8());
|
||||
}else
|
||||
{
|
||||
post.mMeta.mMsgName = std::string(ui->titleEditLink->text().toUtf8());
|
||||
}
|
||||
|
||||
QByteArray ba;
|
||||
QBuffer buffer(&ba);
|
||||
post.mMeta.mMsgName = std::string(ui->titleEdit->text().toUtf8());
|
||||
|
||||
if(!picture.isNull())
|
||||
if(imagebytes.size() > 0)
|
||||
{
|
||||
// send posted image
|
||||
post.mImage.copy((uint8_t *) imagebytes.data(), imagebytes.size());
|
||||
}
|
||||
|
||||
buffer.open(QIODevice::WriteOnly);
|
||||
picture.save(&buffer, "PNG"); // writes image into ba in PNG format
|
||||
post.mImage.copy((uint8_t *) ba.data(), ba.size());
|
||||
int msgsize = post.mLink.length() + post.mMeta.mMsgName.length() + post.mNotes.length() + imagebytes.size();
|
||||
if(msgsize > MAXMESSAGESIZE) {
|
||||
QString errormessage = QString(tr("Message is too large.<br />actual size: %1 bytes, maximum size: %2 bytes.")).arg(msgsize).arg(MAXMESSAGESIZE);
|
||||
QMessageBox::warning(this, "RetroShare", errormessage, QMessageBox::Ok, QMessageBox::Ok);
|
||||
return;
|
||||
}
|
||||
|
||||
if(ui->titleEdit->text().isEmpty()&& ui->titleEditLink->text().isEmpty()) {
|
||||
/* error message */
|
||||
QMessageBox::warning(this, "RetroShare", tr("Please add a Title"), QMessageBox::Ok, QMessageBox::Ok);
|
||||
return; //Don't add a empty title!!
|
||||
}//if(ui->titleEdit->text().isEmpty())
|
||||
|
||||
uint32_t token;
|
||||
mPosted->createPost(token, post);
|
||||
@ -124,17 +159,64 @@ void PostedCreatePostDialog::createPost()
|
||||
accept();
|
||||
}
|
||||
|
||||
void PostedCreatePostDialog::addPicture()
|
||||
void PostedCreatePostDialog::fileHashingFinished(QList<HashedFile> hashedFiles)
|
||||
{
|
||||
QPixmap img = misc::getOpenThumbnailedPicture(this, tr("Load thumbnail picture"), 800, 600);
|
||||
if(hashedFiles.length() > 0) { //It seems like it returns 0 if hashing cancelled
|
||||
HashedFile hashedFile = hashedFiles[0]; //Should be exactly one file
|
||||
RetroShareLink link;
|
||||
link = RetroShareLink::createFile(hashedFile.filename, hashedFile.size, QString::fromStdString(hashedFile.hash.toStdString()));
|
||||
ui->linkEdit->setText(link.toString());
|
||||
}
|
||||
ui->submitButton->setEnabled(true);
|
||||
ui->pushButton->setEnabled(true);
|
||||
}
|
||||
|
||||
if (img.isNull())
|
||||
return;
|
||||
void PostedCreatePostDialog::addPicture()
|
||||
{
|
||||
imagefilename = "";
|
||||
imagebytes.clear();
|
||||
QPixmap empty;
|
||||
ui->imageLabel->setPixmap(empty);
|
||||
|
||||
picture = img;
|
||||
// select a picture file
|
||||
if (misc::getOpenFileName(window(), RshareSettings::LASTDIR_IMAGES, tr("Load Picture File"), "Pictures (*.png *.xpm *.jpg *.jpeg *.gif *.webp )", imagefilename)) {
|
||||
QString encodedImage;
|
||||
QImage image;
|
||||
if (image.load(imagefilename) == false) {
|
||||
fprintf (stderr, "RsHtml::makeEmbeddedImage() - image \"%s\" can't be load\n", imagefilename.toLatin1().constData());
|
||||
imagefilename = "";
|
||||
return;
|
||||
}
|
||||
|
||||
// to show the selected
|
||||
ui->imageLabel->setPixmap(picture);
|
||||
QImage opt;
|
||||
if(ImageUtil::optimizeSizeBytes(imagebytes, image, opt, 800*600, MAXMESSAGESIZE - 1000)) { //Leave space for other stuff
|
||||
ui->imageLabel->setPixmap(QPixmap::fromImage(opt));
|
||||
} else {
|
||||
imagefilename = "";
|
||||
imagebytes.clear();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//Do we need to hash the image?
|
||||
QMessageBox::StandardButton answer;
|
||||
answer = QMessageBox::question(this, tr("Post image"), tr("Do you want to share and link the original image?"), QMessageBox::Yes|QMessageBox::No);
|
||||
if (answer == QMessageBox::Yes) {
|
||||
if(!ui->linkEdit->text().trimmed().isEmpty()) {
|
||||
answer = QMessageBox::question(this, tr("Post image"), tr("You already added a link.<br />Do you want to replace it?"), QMessageBox::Yes|QMessageBox::No);
|
||||
}
|
||||
}
|
||||
|
||||
//If still yes then link it
|
||||
if(answer == QMessageBox::Yes) {
|
||||
ui->submitButton->setEnabled(false);
|
||||
ui->pushButton->setEnabled(false);
|
||||
QStringList files;
|
||||
files.append(imagefilename);
|
||||
ui->hashBox->addAttachments(files,RS_FILE_REQ_ANONYMOUS_ROUTING);
|
||||
}
|
||||
|
||||
ui->removeButton->show();
|
||||
}
|
||||
|
||||
void PostedCreatePostDialog::on_postButton_clicked()
|
||||
@ -151,3 +233,12 @@ void PostedCreatePostDialog::on_linkButton_clicked()
|
||||
{
|
||||
ui->stackedWidget->setCurrentIndex(2);
|
||||
}
|
||||
|
||||
void PostedCreatePostDialog::on_removeButton_clicked()
|
||||
{
|
||||
imagefilename = "";
|
||||
imagebytes.clear();
|
||||
QPixmap empty;
|
||||
ui->imageLabel->setPixmap(empty);
|
||||
ui->removeButton->hide();
|
||||
}
|
||||
|
@ -22,6 +22,7 @@
|
||||
#define POSTEDCREATEPOSTDIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <gui/common/HashBox.h>
|
||||
#include "retroshare/rsposted.h"
|
||||
#include "util/RichTextEdit.h"
|
||||
|
||||
@ -43,7 +44,10 @@ public:
|
||||
explicit PostedCreatePostDialog(TokenQueue* tokenQ, RsPosted* posted, const RsGxsGroupId& grpId, QWidget *parent = 0);
|
||||
~PostedCreatePostDialog();
|
||||
|
||||
QPixmap picture;
|
||||
private:
|
||||
QString imagefilename;
|
||||
QByteArray imagebytes;
|
||||
const int MAXMESSAGESIZE = 32000;
|
||||
|
||||
private slots:
|
||||
void createPost();
|
||||
@ -51,8 +55,12 @@ private slots:
|
||||
void on_postButton_clicked();
|
||||
void on_imageButton_clicked();
|
||||
void on_linkButton_clicked();
|
||||
void on_removeButton_clicked();
|
||||
void fileHashingFinished(QList<HashedFile> hashedFiles);
|
||||
|
||||
private:
|
||||
void processSettings(bool load);
|
||||
|
||||
QString mLink;
|
||||
QString mNotes;
|
||||
TokenQueue* mTokenQueue;
|
||||
|
@ -7,7 +7,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>575</width>
|
||||
<height>429</height>
|
||||
<height>529</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@ -48,6 +48,338 @@
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="4" column="0" colspan="3">
|
||||
<widget class="QStackedWidget" name="stackedWidget">
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="stackedWidgetPage1">
|
||||
<layout class="QGridLayout" name="gridLayout_5">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item row="2" column="0">
|
||||
<widget class="RichTextEdit" name="RichTextEditWidget" native="true"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="stackedWidgetPage2">
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item row="2" column="0" colspan="4">
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="title">
|
||||
<string>Preview</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_4">
|
||||
<item row="0" column="0" rowspan="2">
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="0" column="1" rowspan="2">
|
||||
<widget class="QLabel" name="imageLabel">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>250</width>
|
||||
<height>200</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>800</width>
|
||||
<height>200</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="scaledContents">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2" colspan="2">
|
||||
<spacer name="horizontalSpacer_3">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<spacer name="horizontalSpacer_5">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="1" column="3">
|
||||
<widget class="QToolButton" name="removeButton">
|
||||
<property name="toolTip">
|
||||
<string>Remove image</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="Posted_images.qrc">
|
||||
<normaloff>:/images/trashcan.png</normaloff>:/images/trashcan.png</iconset>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>24</width>
|
||||
<height>24</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="autoRaise">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>447</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Post size is limited to 32 KB, pictures will be downscaled.</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QPushButton" name="pushButton">
|
||||
<property name="text">
|
||||
<string>Add Picture</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0" colspan="4">
|
||||
<widget class="HashBox" name="hashBox">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="widgetResizable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="stackedWidgetPage3">
|
||||
<layout class="QGridLayout" name="gridLayout_3">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLineEdit" name="linkEdit">
|
||||
<property name="placeholderText">
|
||||
<string>Url</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>248</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0" colspan="3">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="signedLabel">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Post as</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="GxsIdChooser" name="idChooser">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="6" column="1">
|
||||
<widget class="QPushButton" name="submitButton">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Post</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="2">
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0" colspan="3">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<property name="spacing">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QPushButton" name="postButton">
|
||||
<property name="text">
|
||||
<string>Post</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="Posted_images.qrc">
|
||||
<normaloff>:/images/post.png</normaloff>:/images/post.png</iconset>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>24</width>
|
||||
<height>24</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="imageButton">
|
||||
<property name="text">
|
||||
<string>Image</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="Posted_images.qrc">
|
||||
<normaloff>:/images/photo.png</normaloff>:/images/photo.png</iconset>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>24</width>
|
||||
<height>24</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="linkButton">
|
||||
<property name="text">
|
||||
<string>Link</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="Posted_images.qrc">
|
||||
<normaloff>:/images/link.png</normaloff>:/images/link.png</iconset>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>24</width>
|
||||
<height>24</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_4">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>298</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="0" column="0" colspan="3">
|
||||
<widget class="StyledLabel" name="info_label">
|
||||
<property name="palette">
|
||||
@ -128,105 +460,7 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0" colspan="3">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<property name="spacing">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QPushButton" name="postButton">
|
||||
<property name="text">
|
||||
<string>Post</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="Posted_images.qrc">
|
||||
<normaloff>:/images/post.png</normaloff>:/images/post.png</iconset>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>24</width>
|
||||
<height>24</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="imageButton">
|
||||
<property name="text">
|
||||
<string>Image</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="Posted_images.qrc">
|
||||
<normaloff>:/images/photo.png</normaloff>:/images/photo.png</iconset>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>24</width>
|
||||
<height>24</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="linkButton">
|
||||
<property name="text">
|
||||
<string>Link</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="Posted_images.qrc">
|
||||
<normaloff>:/images/link.png</normaloff>:/images/link.png</iconset>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>24</width>
|
||||
<height>24</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_4">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>298</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="3" column="0" colspan="3">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="signedLabel">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Post as</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="GxsIdChooser" name="idChooser">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<item row="6" column="0">
|
||||
<spacer name="buttonHSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
@ -242,207 +476,28 @@
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="4" column="2">
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0" colspan="3">
|
||||
<widget class="QStackedWidget" name="stackedWidget">
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<property name="topMargin">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="stackedWidgetPage1">
|
||||
<layout class="QGridLayout" name="gridLayout_5">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="titleEdit">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>6</number>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
<property name="placeholderText">
|
||||
<string>Title</string>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item row="1" column="0">
|
||||
<widget class="RichTextEdit" name="RichTextEditWidget" native="true"/>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLineEdit" name="titleEdit">
|
||||
<property name="placeholderText">
|
||||
<string>Title</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="stackedWidgetPage2">
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item row="0" column="2">
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>447</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="1" column="0" colspan="3">
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="title">
|
||||
<string>Preview</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_4">
|
||||
<item row="0" column="1">
|
||||
<widget class="QLabel" name="imageLabel">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>250</width>
|
||||
<height>200</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>800</width>
|
||||
<height>200</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="scaledContents">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<spacer name="horizontalSpacer_3">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QPushButton" name="pushButton">
|
||||
<property name="text">
|
||||
<string>Add Picture</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Picture size is limited to 34 KB</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="stackedWidgetPage3">
|
||||
<layout class="QGridLayout" name="gridLayout_3">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLineEdit" name="linkEdit">
|
||||
<property name="placeholderText">
|
||||
<string>Url</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>248</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLineEdit" name="titleEditLink">
|
||||
<property name="placeholderText">
|
||||
<string>Title</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<widget class="QPushButton" name="submitButton">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Post</string>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
@ -455,6 +510,12 @@
|
||||
<extends>QLabel</extends>
|
||||
<header>gui/common/StyledLabel.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>HashBox</class>
|
||||
<extends>QScrollArea</extends>
|
||||
<header location="global">gui/common/HashBox.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>HeaderFrame</class>
|
||||
<extends>QFrame</extends>
|
||||
@ -475,8 +536,6 @@
|
||||
</customwidgets>
|
||||
<resources>
|
||||
<include location="Posted_images.qrc"/>
|
||||
<include location="../images.qrc"/>
|
||||
<include location="../icons.qrc"/>
|
||||
</resources>
|
||||
<connections>
|
||||
<connection>
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include <QDateTime>
|
||||
#include <QMenu>
|
||||
#include <QStyle>
|
||||
#include <QTextDocument>
|
||||
|
||||
#include "rshare.h"
|
||||
#include "PostedItem.h"
|
||||
@ -342,7 +343,10 @@ void PostedItem::fill()
|
||||
// FIX THIS UP LATER.
|
||||
ui->notes->setText(RsHtml().formatText(NULL, QString::fromUtf8(mPost.mNotes.c_str()), RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS));
|
||||
|
||||
if(ui->notes->text().isEmpty())
|
||||
QTextDocument doc;
|
||||
doc.setHtml(ui->notes->text());
|
||||
|
||||
if(doc.toPlainText().trimmed().isEmpty())
|
||||
ui->notesButton->hide();
|
||||
// differences between Feed or Top of Comment.
|
||||
if (mFeedHolder)
|
||||
|
@ -21,11 +21,13 @@
|
||||
<file>images/share.png</file>
|
||||
<file>images/notes.png</file>
|
||||
<file>images/link.png</file>
|
||||
<file>images/linkext.png</file>
|
||||
<file>images/post.png</file>
|
||||
<file>images/photo.png</file>
|
||||
<file>images/classic.png</file>
|
||||
<file>images/card.png</file>
|
||||
<file>images/down-hover.png</file>
|
||||
<file>images/up-hover.png</file>
|
||||
<file>images/trashcan.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
BIN
retroshare-gui/src/gui/Posted/images/linkext.png
Normal file
BIN
retroshare-gui/src/gui/Posted/images/linkext.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 660 B |
BIN
retroshare-gui/src/gui/Posted/images/trashcan.png
Normal file
BIN
retroshare-gui/src/gui/Posted/images/trashcan.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.3 KiB |
@ -68,12 +68,12 @@ void ImageUtil::extractImage(QWidget *window, QTextCursor cursor)
|
||||
}
|
||||
}
|
||||
|
||||
bool ImageUtil::optimizeSize(QString &html, const QImage& original, QImage &optimized, int maxPixels, int maxBytes)
|
||||
bool ImageUtil::optimizeSizeBytes(QByteArray &bytearray, const QImage &original, QImage &optimized, int maxPixels, int maxBytes)
|
||||
{
|
||||
//nothing to do if it fits into the limits
|
||||
optimized = original;
|
||||
if ((maxPixels <= 0) || (optimized.width()*optimized.height() <= maxPixels)) {
|
||||
if(checkSize(html, optimized, maxBytes) <= maxBytes) {
|
||||
if(checkSize(bytearray, optimized) <= maxBytes) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -94,14 +94,14 @@ bool ImageUtil::optimizeSize(QString &html, const QImage& original, QImage &opti
|
||||
|
||||
//if maxBytes not defined, do not reduce color space, just downscale
|
||||
if(maxBytes <= 0) {
|
||||
checkSize(html, optimized = original.scaledToWidth(maxwidth, Qt::SmoothTransformation), maxBytes);
|
||||
checkSize(bytearray, optimized = original.scaledToWidth(maxwidth, Qt::SmoothTransformation));
|
||||
return true;
|
||||
}
|
||||
|
||||
//Use binary search to find a suitable image size + linear regression to guess the file size
|
||||
double maxsize = (double)checkSize(html, optimized = original.scaledToWidth(maxwidth, Qt::SmoothTransformation).convertToFormat(QImage::Format_Indexed8, ct, Qt::ThresholdDither), maxBytes);
|
||||
double maxsize = (double)checkSize(bytearray, optimized = original.scaledToWidth(maxwidth, Qt::SmoothTransformation).convertToFormat(QImage::Format_Indexed8, ct, Qt::ThresholdDither));
|
||||
if(maxsize <= maxBytes) return true; //success
|
||||
double minsize = (double)checkSize(html, optimized = original.scaledToWidth(minwidth, Qt::SmoothTransformation).convertToFormat(QImage::Format_Indexed8, ct, Qt::ThresholdDither), maxBytes);
|
||||
double minsize = (double)checkSize(bytearray, optimized = original.scaledToWidth(minwidth, Qt::SmoothTransformation).convertToFormat(QImage::Format_Indexed8, ct, Qt::ThresholdDither));
|
||||
if(minsize > maxBytes) return false; //impossible
|
||||
|
||||
// std::cout << "maxS: " << maxsize << " minS: " << minsize << std::endl;
|
||||
@ -114,7 +114,7 @@ bool ImageUtil::optimizeSize(QString &html, const QImage& original, QImage &opti
|
||||
double b = maxsize - m * ((double)maxwidth * (double)maxwidth / whratio);
|
||||
double a = ((double)(maxBytes - region/2) - b) / m; //maxBytes - region/2 target the center of the accepted region
|
||||
int nextwidth = (int)sqrt(a * whratio);
|
||||
int nextsize = checkSize(html, optimized = original.scaledToWidth(nextwidth, Qt::SmoothTransformation).convertToFormat(QImage::Format_Indexed8, ct, Qt::ThresholdDither), maxBytes);
|
||||
int nextsize = checkSize(bytearray, optimized = original.scaledToWidth(nextwidth, Qt::SmoothTransformation).convertToFormat(QImage::Format_Indexed8, ct, Qt::ThresholdDither));
|
||||
if(nextsize <= maxBytes) {
|
||||
minsize = nextsize;
|
||||
minwidth = nextwidth;
|
||||
@ -136,34 +136,40 @@ bool ImageUtil::optimizeSize(QString &html, const QImage& original, QImage &opti
|
||||
//std::cout << html.toStdString() << std::endl;
|
||||
}
|
||||
|
||||
int ImageUtil::checkSize(QString &embeddedImage, const QImage &img, int maxBytes)
|
||||
bool ImageUtil::optimizeSizeHtml(QString &html, const QImage& original, QImage &optimized, int maxPixels, int maxBytes)
|
||||
{
|
||||
QByteArray bytearray;
|
||||
if(maxBytes > 0){
|
||||
maxBytes = maxBytes * 3/4 - 50; //base64 and html stuff
|
||||
}
|
||||
|
||||
if(optimizeSizeBytes(bytearray, original, optimized, maxPixels, maxBytes))
|
||||
{
|
||||
QByteArray encodedByteArray = bytearray.toBase64();
|
||||
html = "<img src=\"data:image/png;base64,";
|
||||
html.append(encodedByteArray);
|
||||
html.append("\">");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int ImageUtil::checkSize(QByteArray &bytearray, const QImage &img)
|
||||
{
|
||||
rstime::RsScopeTimer st("Check size");
|
||||
|
||||
QByteArray bytearray;
|
||||
bytearray.clear();
|
||||
QBuffer buffer(&bytearray);
|
||||
int size = 0;
|
||||
|
||||
//std::cout << QString("Trying image: format PNG, size %1x%2, colors %3\n").arg(img.width()).arg(img.height()).arg(img.colorCount()).toStdString();
|
||||
if (buffer.open(QIODevice::WriteOnly)) {
|
||||
if (img.save(&buffer, "PNG", 0)) {
|
||||
size = bytearray.length() * 4/3;
|
||||
if((maxBytes > 0) && (size > maxBytes)) // *4/3 for base64
|
||||
{
|
||||
//std::cout << QString("\tToo large, size: %1, limit: %2 bytes\n").arg(bytearray.length() * 4/3).arg(maxBytes).toStdString();
|
||||
}else{
|
||||
//std::cout << QString("\tOK, size: %1, limit: %2 bytes\n").arg(bytearray.length() * 4/3).arg(maxBytes).toStdString();
|
||||
QByteArray encodedByteArray = bytearray.toBase64();
|
||||
//embeddedImage = "<img width=\"%1\" src=\"data:image/png;base64,";
|
||||
embeddedImage = "<img src=\"data:image/png;base64,";
|
||||
embeddedImage.append(encodedByteArray);
|
||||
embeddedImage.append("\">");
|
||||
}
|
||||
size = bytearray.length();
|
||||
} else {
|
||||
std::cerr << "ImageUtil: image can't be saved to buffer" << std::endl;
|
||||
}
|
||||
buffer.close();
|
||||
bytearray.clear();
|
||||
buffer.close();
|
||||
} else {
|
||||
std::cerr << "ImageUtil: buffer can't be opened" << std::endl;
|
||||
}
|
||||
|
@ -23,6 +23,7 @@
|
||||
|
||||
#include <QTextCursor>
|
||||
#include <QWidget>
|
||||
#include <QByteArray>
|
||||
#include <qiterator.h>
|
||||
|
||||
class ImageUtil
|
||||
@ -31,10 +32,11 @@ public:
|
||||
ImageUtil();
|
||||
|
||||
static void extractImage(QWidget *window, QTextCursor cursor);
|
||||
static bool optimizeSize(QString &html, const QImage& original, QImage &optimized, int maxPixels = -1, int maxBytes = -1);
|
||||
static bool optimizeSizeHtml(QString &html, const QImage& original, QImage &optimized, int maxPixels = -1, int maxBytes = -1);
|
||||
static bool optimizeSizeBytes(QByteArray &bytearray, const QImage& original, QImage &optimized, int maxPixels = -1, int maxBytes = -1);
|
||||
|
||||
private:
|
||||
static int checkSize(QString& embeddedImage, const QImage& img, int maxBytes = -1);
|
||||
static int checkSize(QByteArray& embeddedImage, const QImage& img);
|
||||
static void quantization(const QImage& img, QVector<QRgb>& palette);
|
||||
static void quantization(QList<QRgb>::iterator begin, QList<QRgb>::iterator end, int depth, QVector<QRgb>& palette);
|
||||
static void avgbucket(QList<QRgb>::iterator begin, QList<QRgb>::iterator end, QVector<QRgb>& palette);
|
||||
|
Loading…
Reference in New Issue
Block a user