Merge pull request #1740 from defnax/Added-new-rich-text-editor

Added new rich text editor & redesigned Posted Composer
This commit is contained in:
csoler 2019-12-24 12:07:54 +01:00 committed by GitHub
commit 5afa2a1e07
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
43 changed files with 1946 additions and 334 deletions

View File

@ -18,13 +18,16 @@
* * * *
*******************************************************************************/ *******************************************************************************/
#include <QBuffer> #include <QBuffer>
#include <QMessageBox> #include <QMessageBox>
#include "PostedCreatePostDialog.h" #include "PostedCreatePostDialog.h"
#include "ui_PostedCreatePostDialog.h" #include "ui_PostedCreatePostDialog.h"
#include "util/misc.h" #include "util/misc.h"
#include "util/TokenQueue.h" #include "util/TokenQueue.h"
#include "util/RichTextEdit.h"
#include "gui/feeds/SubFileItem.h"
#include "util/rsdir.h"
#include "gui/settings/rsharesettings.h" #include "gui/settings/rsharesettings.h"
#include <QBuffer> #include <QBuffer>
@ -32,21 +35,24 @@
#include <iostream> #include <iostream>
PostedCreatePostDialog::PostedCreatePostDialog(TokenQueue* tokenQ, RsPosted *posted, const RsGxsGroupId& grpId, QWidget *parent): PostedCreatePostDialog::PostedCreatePostDialog(TokenQueue* tokenQ, RsPosted *posted, const RsGxsGroupId& grpId, QWidget *parent):
QDialog(parent, Qt::WindowSystemMenuHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint), QDialog(parent, Qt::WindowSystemMenuHint | Qt::WindowTitleHint | Qt::WindowMinimizeButtonHint | Qt::WindowMaximizeButtonHint | Qt::WindowCloseButtonHint),
mTokenQueue(tokenQ), mPosted(posted), mGrpId(grpId), mTokenQueue(tokenQ), mPosted(posted), mGrpId(grpId),
ui(new Ui::PostedCreatePostDialog) ui(new Ui::PostedCreatePostDialog)
{ {
ui->setupUi(this); ui->setupUi(this);
Settings->loadWidgetInformation(this); Settings->loadWidgetInformation(this);
connect(ui->submitButton, SIGNAL(clicked()), this, SLOT(createPost())); connect(ui->submitButton, SIGNAL(clicked()), this, SLOT(createPost()));
connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(close())); connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(close()));
connect(ui->pushButton, SIGNAL(clicked() ), this , SLOT(addPicture())); connect(ui->pushButton, SIGNAL(clicked() ), this , SLOT(addPicture()));
ui->headerFrame->setHeaderImage(QPixmap(":/images/posted_64.png")); ui->headerFrame->setHeaderImage(QPixmap(":/icons/png/postedlinks.png"));
ui->headerFrame->setHeaderText(tr("Submit a new Post")); ui->headerFrame->setHeaderText(tr("Create a new Post"));
setAttribute ( Qt::WA_DeleteOnClose, true ); setAttribute ( Qt::WA_DeleteOnClose, true );
ui->RichTextEditWidget->setPlaceHolderTextPosted();
/* fill in the available OwnIds for signing */ /* fill in the available OwnIds for signing */
ui->idChooser->loadIds(IDCHOOSER_ID_REQUIRED, RsGxsId()); ui->idChooser->loadIds(IDCHOOSER_ID_REQUIRED, RsGxsId());
} }
@ -78,10 +84,21 @@ void PostedCreatePostDialog::createPost()
RsPostedPost post; RsPostedPost post;
post.mMeta.mGroupId = mGrpId; post.mMeta.mGroupId = mGrpId;
post.mLink = std::string(ui->linkEdit->text().toUtf8()); post.mLink = std::string(ui->linkEdit->text().toUtf8());
post.mNotes = std::string(ui->notesTextEdit->toPlainText().toUtf8());
post.mMeta.mMsgName = std::string(ui->titleEdit->text().toUtf8()); QString text;
text = ui->RichTextEditWidget->toHtml();
post.mNotes = std::string(text.toUtf8());
post.mMeta.mAuthorId = authorId; 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; QByteArray ba;
QBuffer buffer(&ba); QBuffer buffer(&ba);
@ -94,7 +111,7 @@ void PostedCreatePostDialog::createPost()
post.mImage.copy((uint8_t *) ba.data(), ba.size()); post.mImage.copy((uint8_t *) ba.data(), ba.size());
} }
if(ui->titleEdit->text().isEmpty()) { if(ui->titleEdit->text().isEmpty()&& ui->titleEditLink->text().isEmpty()) {
/* error message */ /* error message */
QMessageBox::warning(this, "RetroShare", tr("Please add a Title"), QMessageBox::Ok, QMessageBox::Ok); QMessageBox::warning(this, "RetroShare", tr("Please add a Title"), QMessageBox::Ok, QMessageBox::Ok);
return; //Don't add a empty title!! return; //Don't add a empty title!!
@ -119,3 +136,18 @@ void PostedCreatePostDialog::addPicture()
// to show the selected // to show the selected
ui->imageLabel->setPixmap(picture); ui->imageLabel->setPixmap(picture);
} }
void PostedCreatePostDialog::on_postButton_clicked()
{
ui->stackedWidget->setCurrentIndex(0);
}
void PostedCreatePostDialog::on_imageButton_clicked()
{
ui->stackedWidget->setCurrentIndex(1);
}
void PostedCreatePostDialog::on_linkButton_clicked()
{
ui->stackedWidget->setCurrentIndex(2);
}

View File

@ -23,6 +23,7 @@
#include <QDialog> #include <QDialog>
#include "retroshare/rsposted.h" #include "retroshare/rsposted.h"
#include "util/RichTextEdit.h"
class TokenQueue; class TokenQueue;
@ -47,7 +48,9 @@ public:
private slots: private slots:
void createPost(); void createPost();
void addPicture(); void addPicture();
void on_postButton_clicked();
void on_imageButton_clicked();
void on_linkButton_clicked();
private: private:
QString mLink; QString mLink;

View File

@ -7,11 +7,11 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>575</width> <width>575</width>
<height>467</height> <height>429</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string>Submit Post</string> <string>Create a Post</string>
</property> </property>
<layout class="QGridLayout" name="PostedCreatePostDialogGLayout"> <layout class="QGridLayout" name="PostedCreatePostDialogGLayout">
<property name="leftMargin"> <property name="leftMargin">
@ -121,24 +121,186 @@
<enum>QFrame::Box</enum> <enum>QFrame::Box</enum>
</property> </property>
<property name="text"> <property name="text">
<string>You are submitting a link. The key to a successful submission is interesting content and a descriptive title.</string> <string>You are submitting a post. The key to a successful submission is interesting content and a descriptive title.</string>
</property> </property>
<property name="wordWrap"> <property name="wordWrap">
<bool>true</bool> <bool>true</bool>
</property> </property>
</widget> </widget>
</item> </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">
<spacer name="buttonHSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</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"> <item row="2" column="0" colspan="3">
<widget class="QTabWidget" name="tabWidget"> <widget class="QStackedWidget" name="stackedWidget">
<property name="currentIndex"> <property name="currentIndex">
<number>0</number> <number>0</number>
</property> </property>
<widget class="QWidget" name="tab"> <widget class="QWidget" name="stackedWidgetPage1">
<attribute name="title"> <layout class="QGridLayout" name="gridLayout_5">
<string>Picture</string> <property name="leftMargin">
</attribute> <number>0</number>
</property>
<property name="topMargin">
<number>6</number>
</property>
<property name="rightMargin">
<number>0</number>
</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"> <layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="1"> <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"> <spacer name="horizontalSpacer">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
@ -151,14 +313,7 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="0" column="0"> <item row="1" column="0" colspan="3">
<widget class="QPushButton" name="pushButton">
<property name="text">
<string>Add Picture</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="QGroupBox" name="groupBox"> <widget class="QGroupBox" name="groupBox">
<property name="title"> <property name="title">
<string>Preview</string> <string>Preview</string>
@ -186,19 +341,6 @@
</property> </property>
</widget> </widget>
</item> </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>
<item row="0" column="2"> <item row="0" column="2">
<spacer name="horizontalSpacer_3"> <spacer name="horizontalSpacer_3">
<property name="orientation"> <property name="orientation">
@ -212,25 +354,8 @@
</property> </property>
</spacer> </spacer>
</item> </item>
</layout>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_2">
<attribute name="title">
<string>Notes</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0"> <item row="0" column="0">
<widget class="MimeTextEdit" name="notesTextEdit"/> <spacer name="horizontalSpacer_2">
</item>
</layout>
</widget>
</widget>
</item>
<item row="3" column="0">
<spacer name="buttonHSpacer">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
@ -242,7 +367,68 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="3" column="1"> </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"> <widget class="QPushButton" name="submitButton">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed"> <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
@ -250,61 +436,14 @@
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="styleSheet">
<string notr="true"/>
</property>
<property name="text"> <property name="text">
<string>Submit</string> <string>Post</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="3" 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="QGridLayout" name="titleGLayout">
<item row="0" column="0">
<widget class="QLabel" name="titleLabel">
<property name="text">
<string>Title</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="titleEdit"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="linkLabel">
<property name="text">
<string>Link</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="linkEdit"/>
</item>
<item row="2" column="1">
<widget class="GxsIdChooser" name="idChooser"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="signedLabel">
<property name="text">
<string>Post as</string>
</property>
</widget>
</item>
</layout>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>
@ -322,18 +461,23 @@
<header>gui/common/HeaderFrame.h</header> <header>gui/common/HeaderFrame.h</header>
<container>1</container> <container>1</container>
</customwidget> </customwidget>
<customwidget>
<class>MimeTextEdit</class>
<extends>QTextEdit</extends>
<header location="global">gui/common/MimeTextEdit.h</header>
</customwidget>
<customwidget> <customwidget>
<class>GxsIdChooser</class> <class>GxsIdChooser</class>
<extends>QComboBox</extends> <extends>QComboBox</extends>
<header>gui/gxs/GxsIdChooser.h</header> <header>gui/gxs/GxsIdChooser.h</header>
</customwidget> </customwidget>
<customwidget>
<class>RichTextEdit</class>
<extends>QWidget</extends>
<header>util/RichTextEdit.h</header>
<container>1</container>
</customwidget>
</customwidgets> </customwidgets>
<resources/> <resources>
<include location="Posted_images.qrc"/>
<include location="../images.qrc"/>
<include location="../icons.qrc"/>
</resources>
<connections> <connections>
<connection> <connection>
<sender>buttonBox</sender> <sender>buttonBox</sender>

View File

@ -27,13 +27,15 @@
#include "gui/feeds/FeedHolder.h" #include "gui/feeds/FeedHolder.h"
#include "gui/gxs/GxsIdDetails.h" #include "gui/gxs/GxsIdDetails.h"
#include "util/misc.h" #include "util/misc.h"
#include "util/HandleRichText.h"
#include "ui_PostedItem.h" #include "ui_PostedItem.h"
#include <retroshare/rsposted.h> #include <retroshare/rsposted.h>
#include <iostream> #include <iostream>
#define LINK_IMAGE ":/images/thumb-link.png"
/** Constructor */ /** Constructor */
PostedItem::PostedItem(FeedHolder *feedHolder, uint32_t feedId, const RsGxsGroupId &groupId, const RsGxsMessageId &messageId, bool isHome, bool autoUpdate) : PostedItem::PostedItem(FeedHolder *feedHolder, uint32_t feedId, const RsGxsGroupId &groupId, const RsGxsMessageId &messageId, bool isHome, bool autoUpdate) :
@ -235,7 +237,7 @@ void PostedItem::loadComment(const uint32_t &token)
if (comNb == 1) { if (comNb == 1) {
sComButText = sComButText.append("(1)"); sComButText = sComButText.append("(1)");
} else if (comNb > 1) { } else if (comNb > 1) {
sComButText = tr("Comments").append(" (%1)").arg(comNb); sComButText = " " + tr("Comments").append(" (%1)").arg(comNb);
} }
ui->commentButton->setText(sComButText); ui->commentButton->setText(sComButText);
} }
@ -253,22 +255,6 @@ void PostedItem::fill()
int desired_height = 1.5*(ui->voteDownButton->height() + ui->voteUpButton->height() + ui->scoreLabel->height()); int desired_height = 1.5*(ui->voteDownButton->height() + ui->voteUpButton->height() + ui->scoreLabel->height());
int desired_width = sqpixmap2.width()*desired_height/(float)sqpixmap2.height(); int desired_width = sqpixmap2.width()*desired_height/(float)sqpixmap2.height();
if(mPost.mImage.mData != NULL)
{
QPixmap pixmap;
GxsIdDetails::loadPixmapFromData(mPost.mImage.mData, mPost.mImage.mSize, pixmap,GxsIdDetails::ORIGINAL);
// Wiping data - as its been passed to thumbnail.
QPixmap sqpixmap = pixmap.scaled(desired_width,desired_height, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);
ui->thumbnailLabel->setPixmap(sqpixmap);
ui->pictureLabel->setPixmap(pixmap);
}
else
{
//ui->thumbnailLabel->setFixedSize(desired_width,desired_height);
ui->expandButton->setDisabled(true);
}
QDateTime qtime; QDateTime qtime;
qtime.setTime_t(mPost.mMeta.mPublishTs); qtime.setTime_t(mPost.mMeta.mPublishTs);
QString timestamp = qtime.toString("hh:mm dd-MMM-yyyy"); QString timestamp = qtime.toString("hh:mm dd-MMM-yyyy");
@ -318,6 +304,28 @@ void PostedItem::fill()
ui->siteLabel->setText(sitestr); ui->siteLabel->setText(sitestr);
if(mPost.mImage.mData != NULL)
{
QPixmap pixmap;
GxsIdDetails::loadPixmapFromData(mPost.mImage.mData, mPost.mImage.mSize, pixmap,GxsIdDetails::ORIGINAL);
// Wiping data - as its been passed to thumbnail.
QPixmap sqpixmap = pixmap.scaled(desired_width,desired_height, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);
ui->thumbnailLabel->setPixmap(sqpixmap);
ui->pictureLabel->setPixmap(pixmap);
}
else if (urlOkay && (mPost.mImage.mData == NULL))
{
ui->expandButton->setDisabled(true);
ui->thumbnailLabel->setPixmap(QPixmap(LINK_IMAGE));
}
else
{
ui->expandButton->setDisabled(true);
ui->thumbnailLabel->setPixmap(sqpixmap2);
}
//QString score = "Hot" + QString::number(post.mHotScore); //QString score = "Hot" + QString::number(post.mHotScore);
//score += " Top" + QString::number(post.mTopScore); //score += " Top" + QString::number(post.mTopScore);
//score += " New" + QString::number(post.mNewScore); //score += " New" + QString::number(post.mNewScore);
@ -327,7 +335,8 @@ void PostedItem::fill()
ui->scoreLabel->setText(score); ui->scoreLabel->setText(score);
// FIX THIS UP LATER. // FIX THIS UP LATER.
ui->notes->setText(QString::fromUtf8(mPost.mNotes.c_str())); 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()) if(ui->notes->text().isEmpty())
ui->notesButton->hide(); ui->notesButton->hide();
// differences between Feed or Top of Comment. // differences between Feed or Top of Comment.

View File

@ -652,7 +652,7 @@
<property name="spacing"> <property name="spacing">
<number>1</number> <number>1</number>
</property> </property>
<item row="0" column="0"> <item row="0" column="0" colspan="2">
<widget class="QLabel" name="notes"> <widget class="QLabel" name="notes">
<property name="text"> <property name="text">
<string/> <string/>
@ -660,6 +660,12 @@
<property name="wordWrap"> <property name="wordWrap">
<bool>true</bool> <bool>true</bool>
</property> </property>
<property name="openExternalLinks">
<bool>true</bool>
</property>
<property name="textInteractionFlags">
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
</property>
</widget> </widget>
</item> </item>
</layout> </layout>
@ -673,17 +679,17 @@
<extends>QLabel</extends> <extends>QLabel</extends>
<header>gui/common/StyledLabel.h</header> <header>gui/common/StyledLabel.h</header>
</customwidget> </customwidget>
<customwidget>
<class>GxsIdLabel</class>
<extends>QLabel</extends>
<header>gui/gxs/GxsIdLabel.h</header>
</customwidget>
<customwidget> <customwidget>
<class>ElidedLabel</class> <class>ElidedLabel</class>
<extends>QLabel</extends> <extends>QLabel</extends>
<header location="global">gui/common/ElidedLabel.h</header> <header location="global">gui/common/ElidedLabel.h</header>
<container>1</container> <container>1</container>
</customwidget> </customwidget>
<customwidget>
<class>GxsIdLabel</class>
<extends>QLabel</extends>
<header>gui/gxs/GxsIdLabel.h</header>
</customwidget>
</customwidgets> </customwidgets>
<resources> <resources>
<include location="Posted_images.qrc"/> <include location="Posted_images.qrc"/>

View File

@ -17,7 +17,11 @@
<file>images/up-arrow.png</file> <file>images/up-arrow.png</file>
<file>images/comments.png</file> <file>images/comments.png</file>
<file>images/thumb-default.png</file> <file>images/thumb-default.png</file>
<file>images/thumb-link.png</file>
<file>images/share.png</file> <file>images/share.png</file>
<file>images/notes.png</file> <file>images/notes.png</file>
<file>images/link.png</file>
<file>images/post.png</file>
<file>images/photo.png</file>
</qresource> </qresource>
</RCC> </RCC>

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.6 KiB

View File

@ -33,6 +33,7 @@
#include "util/HandleRichText.h" #include "util/HandleRichText.h"
#include "util/misc.h" #include "util/misc.h"
#include "util/rsdir.h" #include "util/rsdir.h"
#include "util/RichTextEdit.h"
#include <retroshare/rsfiles.h> #include <retroshare/rsfiles.h>
@ -55,7 +56,7 @@ CreateGxsChannelMsg::CreateGxsChannelMsg(const RsGxsGroupId &cId, RsGxsMessageId
Settings->loadWidgetInformation(this); Settings->loadWidgetInformation(this);
mChannelQueue = new TokenQueue(rsGxsChannels->getTokenService(), this); mChannelQueue = new TokenQueue(rsGxsChannels->getTokenService(), this);
headerFrame->setHeaderImage(QPixmap(":/images/channels.png")); headerFrame->setHeaderImage(QPixmap(":/icons/png/channel.png"));
if(!existing_post.isNull()) if(!existing_post.isNull())
headerFrame->setHeaderText(tr("Edit Channel Post")); headerFrame->setHeaderText(tr("Edit Channel Post"));
@ -64,17 +65,19 @@ CreateGxsChannelMsg::CreateGxsChannelMsg(const RsGxsGroupId &cId, RsGxsMessageId
setAttribute ( Qt::WA_DeleteOnClose, true ); setAttribute ( Qt::WA_DeleteOnClose, true );
buttonBox->button(QDialogButtonBox::Ok)->setText(tr("Post"));
connect(buttonBox, SIGNAL(accepted()), this, SLOT(sendMsg())); connect(buttonBox, SIGNAL(accepted()), this, SLOT(sendMsg()));
connect(buttonBox, SIGNAL(rejected()), this, SLOT(cancelMsg())); connect(buttonBox, SIGNAL(rejected()), this, SLOT(cancelMsg()));
connect(addFileButton, SIGNAL(clicked() ), this , SLOT(addExtraFile())); connect(addFileButton, SIGNAL(clicked() ), this , SLOT(addExtraFile()));
connect(addfilepushButton, SIGNAL(clicked() ), this , SLOT(addExtraFile())); connect(addfilepushButton, SIGNAL(clicked() ), this , SLOT(addExtraFile()));
connect(addThumbnailButton, SIGNAL(clicked() ), this , SLOT(addThumbnail())); connect(addThumbnailButton, SIGNAL(clicked() ), this , SLOT(addThumbnail()));
connect(thumbNailCb, SIGNAL(toggled(bool)), this, SLOT(allowAutoMediaThumbNail(bool))); connect(thumbNailCb, SIGNAL(toggled(bool)), this, SLOT(allowAutoMediaThumbNail(bool)));
connect(tabWidget, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenu(QPoint))); connect(stackedWidget, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenu(QPoint)));
connect(generateCheckBox, SIGNAL(toggled(bool)), generateSpinBox, SLOT(setEnabled(bool))); connect(generateCheckBox, SIGNAL(toggled(bool)), generateSpinBox, SLOT(setEnabled(bool)));
connect(addPictureButton, SIGNAL(clicked()), this, SLOT(addPicture()));
connect(msgEdit, SIGNAL(textChanged()), this, SLOT(checkLength()));
generateSpinBox->setEnabled(false); generateSpinBox->setEnabled(false);
thumbNailCb->setVisible(false); thumbNailCb->setVisible(false);
@ -84,7 +87,6 @@ CreateGxsChannelMsg::CreateGxsChannelMsg(const RsGxsGroupId &cId, RsGxsMessageId
thumbNailCb->setVisible(true); thumbNailCb->setVisible(true);
thumbNailCb->setEnabled(true); thumbNailCb->setEnabled(true);
#endif #endif
//buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
setAcceptDrops(true); setAcceptDrops(true);
@ -96,26 +98,6 @@ CreateGxsChannelMsg::CreateGxsChannelMsg(const RsGxsGroupId &cId, RsGxsMessageId
#endif #endif
} }
static const uint32_t MAX_ALLOWED_GXS_MESSAGE_SIZE = 199000;
void CreateGxsChannelMsg::checkLength()
{
QString text;
RsHtml::optimizeHtml(msgEdit, 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);
infoLabel->setStyleSheet("QLabel#infoLabel { }");
}else{
text = tr("Warning: This message is too big of %1 characters after HTML conversion.").arg((0-charRemains));
infoLabel->setStyleSheet("QLabel#infoLabel {color: red; font: bold; }");
}
buttonBox->button(QDialogButtonBox::Ok)->setToolTip(text);
buttonBox->button(QDialogButtonBox::Ok)->setEnabled(charRemains>=0);
infoLabel->setText(text);
}
CreateGxsChannelMsg::~CreateGxsChannelMsg() CreateGxsChannelMsg::~CreateGxsChannelMsg()
{ {
Settings->saveWidgetInformation(this); Settings->saveWidgetInformation(this);
@ -442,7 +424,7 @@ void CreateGxsChannelMsg::addSubject(const QString& text)
void CreateGxsChannelMsg::addHtmlText(const QString& text) void CreateGxsChannelMsg::addHtmlText(const QString& text)
{ {
msgEdit->setHtml(text) ; RichTextEditWidget->setText(text) ;
} }
void CreateGxsChannelMsg::addAttachment(const std::string &path) void CreateGxsChannelMsg::addAttachment(const std::string &path)
@ -650,8 +632,9 @@ void CreateGxsChannelMsg::sendMsg()
/* construct message bits */ /* construct message bits */
std::string subject = std::string(misc::removeNewLine(subjectEdit->text()).toUtf8()); std::string subject = std::string(misc::removeNewLine(subjectEdit->text()).toUtf8());
QString text; QString text;
RsHtml::optimizeHtml(msgEdit, text); text = RichTextEditWidget->toHtml();
std::string msg = std::string(text.toUtf8()); std::string msg = std::string(text.toUtf8());
std::list<RsGxsFile> files; std::list<RsGxsFile> files;
@ -763,18 +746,6 @@ void CreateGxsChannelMsg::addThumbnail()
thumbnail_label->setPixmap(picture); thumbnail_label->setPixmap(picture);
} }
void CreateGxsChannelMsg::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);
msgEdit->textCursor().insertFragment(fragment);
}
}
}
void CreateGxsChannelMsg::loadChannelPostInfo(const uint32_t &token) void CreateGxsChannelMsg::loadChannelPostInfo(const uint32_t &token)
{ {
#ifdef DEBUG_CREATE_GXS_MSG #ifdef DEBUG_CREATE_GXS_MSG
@ -801,13 +772,16 @@ void CreateGxsChannelMsg::loadChannelPostInfo(const uint32_t &token)
} }
subjectEdit->setText(QString::fromUtf8(post.mMeta.mMsgName.c_str())) ; subjectEdit->setText(QString::fromUtf8(post.mMeta.mMsgName.c_str())) ;
msgEdit->setText(QString::fromUtf8(post.mMsg.c_str())) ; RichTextEditWidget->setText(QString::fromUtf8(post.mMsg.c_str()));
for(std::list<RsGxsFile>::const_iterator it(post.mFiles.begin());it!=post.mFiles.end();++it) for(std::list<RsGxsFile>::const_iterator it(post.mFiles.begin());it!=post.mFiles.end();++it)
addAttachment(it->mHash,it->mName,it->mSize,true,RsPeerId(),true); addAttachment(it->mHash,it->mName,it->mSize,true,RsPeerId(),true);
if(post.mThumbnail.mData != NULL)
{
GxsIdDetails::loadPixmapFromData(post.mThumbnail.mData,post.mThumbnail.mSize,picture,GxsIdDetails::ORIGINAL); GxsIdDetails::loadPixmapFromData(post.mThumbnail.mData,post.mThumbnail.mSize,picture,GxsIdDetails::ORIGINAL);
thumbnail_label->setPixmap(picture); thumbnail_label->setPixmap(picture);
}
} }
void CreateGxsChannelMsg::loadChannelInfo(const uint32_t &token) void CreateGxsChannelMsg::loadChannelInfo(const uint32_t &token)
@ -856,3 +830,13 @@ void CreateGxsChannelMsg::loadRequest(const TokenQueue *queue, const TokenReques
} }
} }
} }
void CreateGxsChannelMsg::on_channelpostButton_clicked()
{
stackedWidget->setCurrentIndex(0);
}
void CreateGxsChannelMsg::on_attachmentsButton_clicked()
{
stackedWidget->setCurrentIndex(1);
}

View File

@ -69,10 +69,10 @@ private slots:
void contextMenu(QPoint) ; void contextMenu(QPoint) ;
void addThumbnail(); void addThumbnail();
void addPicture();
void checkLength();
void allowAutoMediaThumbNail(bool); void allowAutoMediaThumbNail(bool);
void on_channelpostButton_clicked();
void on_attachmentsButton_clicked();
private: private:
void loadChannelInfo(const uint32_t &token); void loadChannelInfo(const uint32_t &token);
void loadChannelPostInfo(const uint32_t &token); void loadChannelPostInfo(const uint32_t &token);

View File

@ -37,7 +37,11 @@
<number>0</number> <number>0</number>
</property> </property>
<item row="0" column="0"> <item row="0" column="0">
<widget class="HeaderFrame" name="headerFrame"/> <widget class="HeaderFrame" name="headerFrame">
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
</widget>
</item> </item>
<item row="1" column="0"> <item row="1" column="0">
<widget class="QFrame" name="mainFrame"> <widget class="QFrame" name="mainFrame">
@ -47,9 +51,56 @@
<property name="frameShadow"> <property name="frameShadow">
<enum>QFrame::Raised</enum> <enum>QFrame::Raised</enum>
</property> </property>
<layout class="QGridLayout" name="mainFrameGLayout"> <layout class="QGridLayout" name="gridLayout_4">
<item row="0" column="0"> <item row="0" column="0">
<widget class="QTabWidget" name="tabWidget"> <widget class="QPushButton" name="channelpostButton">
<property name="text">
<string>Channel Post</string>
</property>
<property name="icon">
<iconset resource="../icons.qrc">
<normaloff>:/icons/png/comment.png</normaloff>:/icons/png/comment.png</iconset>
</property>
<property name="iconSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="attachmentsButton">
<property name="text">
<string>Attachments</string>
</property>
<property name="icon">
<iconset resource="../icons.qrc">
<normaloff>:/icons/png/attachements.png</normaloff>:/icons/png/attachements.png</iconset>
</property>
<property name="iconSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
</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>486</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="0" colspan="3">
<widget class="QStackedWidget" name="stackedWidget">
<property name="mouseTracking"> <property name="mouseTracking">
<bool>true</bool> <bool>true</bool>
</property> </property>
@ -62,15 +113,138 @@
<property name="currentIndex"> <property name="currentIndex">
<number>0</number> <number>0</number>
</property> </property>
<widget class="QWidget" name="channelPostTab"> <widget class="QWidget" name="stackedWidgetPage1">
<attribute name="title"> <layout class="QGridLayout" name="gridLayout_3">
<string>Channel Post</string> <property name="leftMargin">
</attribute> <number>0</number>
<layout class="QGridLayout" name="channelPostTabGLayout"> </property>
<item row="0" column="0" colspan="3"> <property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item row="1" column="0">
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0" rowspan="2">
<widget class="QLabel" name="thumbnail_label">
<property name="maximumSize">
<size>
<width>156</width>
<height>107</height>
</size>
</property>
<property name="sizeIncrement">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="pixmap">
<pixmap resource="../images.qrc">:/images/thumb-default-video.png</pixmap>
</property>
</widget>
</item>
<item row="0" column="1" colspan="4">
<widget class="QLabel" name="channelAttachLabel">
<property name="text">
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Ubuntu'; font-size:11pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'MS Shell Dlg 2'; font-size:10pt; font-weight:600;&quot;&gt;Attachments:&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;img src=&quot;:/images/feedback_arrow.png&quot; /&gt;&lt;span style=&quot; font-family:'MS Shell Dlg 2'; font-size:8pt;&quot;&gt; Use Drag and Drop / Add Files button, to Hash new files.&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;img src=&quot;:/images/feedback_arrow.png&quot; /&gt;&lt;span style=&quot; font-family:'MS Shell Dlg 2'; font-size:8pt;&quot;&gt; Copy/Paste RetroShare links from your shares&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QPushButton" name="addThumbnailButton">
<property name="text">
<string>Add Channel Thumbnail</string>
</property>
<property name="icon">
<iconset resource="../icons.qrc">
<normaloff>:/icons/png/add-image.png</normaloff>:/icons/png/add-image.png</iconset>
</property>
<property name="iconSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QPushButton" name="addfilepushButton">
<property name="text">
<string>Add File to Attach</string>
</property>
<property name="icon">
<iconset resource="../icons.qrc">
<normaloff>:/icons/png/add-file.png</normaloff>:/icons/png/add-file.png</iconset>
</property>
<property name="iconSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
</widget>
</item>
<item row="1" column="3" colspan="2">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="2" column="0">
<widget class="QGroupBox" name="messageGBox">
<property name="title">
<string>Message</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<property name="bottomMargin">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QLineEdit" name="subjectEdit">
<property name="placeholderText">
<string>Title</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="RichTextEdit" name="RichTextEditWidget" native="true"/>
</item>
</layout>
</widget>
</item>
<item row="0" column="0">
<layout class="QHBoxLayout" name="channelNameHLayout"> <layout class="QHBoxLayout" name="channelNameHLayout">
<item> <item>
<widget class="QLabel" name="channelNameLabel"> <widget class="QLabel" name="channelNameLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font"> <property name="font">
<font> <font>
<weight>75</weight> <weight>75</weight>
@ -94,138 +268,22 @@
</item> </item>
</layout> </layout>
</item> </item>
<item row="1" column="0">
<layout class="QGridLayout" name="channelAttachGLayout">
<item row="1" column="0">
<widget class="QPushButton" name="addfilepushButton">
<property name="text">
<string>Add File to Attach</string>
</property>
<property name="icon">
<iconset resource="../images.qrc">
<normaloff>:/images/add-share24.png</normaloff>:/images/add-share24.png</iconset>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QPushButton" name="addThumbnailButton">
<property name="text">
<string>Add Channel Thumbnail</string>
</property>
<property name="icon">
<iconset resource="../images.qrc">
<normaloff>:/images/add_image24.png</normaloff>:/images/add_image24.png</iconset>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QPushButton" name="addPictureButton">
<property name="text">
<string>Add Picture</string>
</property>
<property name="icon">
<iconset resource="../images.qrc">
<normaloff>:/images/add_image24.png</normaloff>:/images/add_image24.png</iconset>
</property>
</widget>
</item>
<item row="0" column="0" colspan="3">
<widget class="QLabel" name="channelAttachLabel">
<property name="text">
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Ubuntu'; font-size:11pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'MS Shell Dlg 2'; font-size:10pt; font-weight:600;&quot;&gt;Attachments:&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;img src=&quot;:/images/feedback_arrow.png&quot; /&gt;&lt;span style=&quot; font-family:'MS Shell Dlg 2'; font-size:8pt;&quot;&gt; Use Drag and Drop / Add Files button, to Hash new files.&lt;/span&gt;&lt;/p&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;img src=&quot;:/images/feedback_arrow.png&quot; /&gt;&lt;span style=&quot; font-family:'MS Shell Dlg 2'; font-size:8pt;&quot;&gt; Copy/Paste RetroShare links from your shares&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="1">
<widget class="QLabel" name="thumbnail_label">
<property name="maximumSize">
<size>
<width>156</width>
<height>107</height>
</size>
</property>
<property name="sizeIncrement">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="pixmap">
<pixmap resource="../images.qrc">:/images/thumb-default-video.png</pixmap>
</property>
</widget>
</item>
<item row="1" column="2">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>12</width>
<height>98</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="0" colspan="3">
<widget class="QGroupBox" name="messageGBox">
<property name="title">
<string>Message</string>
</property>
<layout class="QVBoxLayout" name="messageGBoxVLayout">
<item>
<layout class="QHBoxLayout" name="subjectHLayout">
<item>
<widget class="QLabel" name="subjectLabel">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Subject :</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="subjectEdit"/>
</item>
</layout>
</item>
<item>
<widget class="MimeTextEdit" name="msgEdit"/>
</item>
<item>
<widget class="QLabel" name="infoLabel">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
</item> <widget class="QWidget" name="stackedWidgetPage2">
</layout>
</widget>
<widget class="QWidget" name="attachmentsTab">
<attribute name="icon">
<iconset resource="../images.qrc">
<normaloff>:/images/attachment.png</normaloff>:/images/attachment.png</iconset>
</attribute>
<attribute name="title">
<string>Attachments</string>
</attribute>
<layout class="QGridLayout" name="attachmentsTabGLayout"> <layout class="QGridLayout" name="attachmentsTabGLayout">
<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="0" column="0"> <item row="0" column="0">
<widget class="QLabel" name="attachmentsPixLabel"> <widget class="QLabel" name="attachmentsPixLabel">
<property name="text"> <property name="text">
@ -286,8 +344,8 @@ p, li { white-space: pre-wrap; }
<string/> <string/>
</property> </property>
<property name="icon"> <property name="icon">
<iconset resource="../images.qrc"> <iconset resource="../icons.qrc">
<normaloff>:/images/add-share24.png</normaloff>:/images/add-share24.png</iconset> <normaloff>:/icons/png/add-file.png</normaloff>:/icons/png/add-file.png</iconset>
</property> </property>
<property name="iconSize"> <property name="iconSize">
<size> <size>
@ -320,7 +378,7 @@ p, li { white-space: pre-wrap; }
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>812</width> <width>81</width>
<height>24</height> <height>24</height>
</rect> </rect>
</property> </property>
@ -371,7 +429,7 @@ p, li { white-space: pre-wrap; }
</widget> </widget>
</widget> </widget>
</item> </item>
<item row="1" column="0"> <item row="2" column="0" colspan="3">
<layout class="QHBoxLayout" name="buttonHLayout"> <layout class="QHBoxLayout" name="buttonHLayout">
<item> <item>
<widget class="QCheckBox" name="generateCheckBox"> <widget class="QCheckBox" name="generateCheckBox">
@ -392,6 +450,9 @@ p, li { white-space: pre-wrap; }
</item> </item>
<item> <item>
<widget class="QDialogButtonBox" name="buttonBox"> <widget class="QDialogButtonBox" name="buttonBox">
<property name="styleSheet">
<string notr="true"/>
</property>
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
@ -408,19 +469,21 @@ p, li { white-space: pre-wrap; }
</layout> </layout>
</widget> </widget>
<customwidgets> <customwidgets>
<customwidget>
<class>MimeTextEdit</class>
<extends>QTextEdit</extends>
<header location="global">gui/common/MimeTextEdit.h</header>
</customwidget>
<customwidget> <customwidget>
<class>HeaderFrame</class> <class>HeaderFrame</class>
<extends>QFrame</extends> <extends>QFrame</extends>
<header>gui/common/HeaderFrame.h</header> <header>gui/common/HeaderFrame.h</header>
<container>1</container> <container>1</container>
</customwidget> </customwidget>
<customwidget>
<class>RichTextEdit</class>
<extends>QWidget</extends>
<header>util/RichTextEdit.h</header>
<container>1</container>
</customwidget>
</customwidgets> </customwidgets>
<resources> <resources>
<include location="../icons.qrc"/>
<include location="../images.qrc"/> <include location="../images.qrc"/>
</resources> </resources>
<connections/> <connections/>

View File

@ -290,5 +290,24 @@
<file>icons/png/bandwidth.png</file> <file>icons/png/bandwidth.png</file>
<file>icons/png/options2.png</file> <file>icons/png/options2.png</file>
<file>icons/png/exit2.png</file> <file>icons/png/exit2.png</file>
<file>icons/textedit/bold.png</file>
<file>icons/textedit/bullet-list.png</file>
<file>icons/textedit/italic.png</file>
<file>icons/textedit/left-indent.png</file>
<file>icons/textedit/link.png</file>
<file>icons/textedit/numberd-list.png</file>
<file>icons/textedit/photo-of-a-landscape.png</file>
<file>icons/textedit/right-indent.png</file>
<file>icons/textedit/strikethrough.png</file>
<file>icons/textedit/underline.png</file>
<file>icons/textedit/copy.png</file>
<file>icons/textedit/cut.png</file>
<file>icons/textedit/paste.png</file>
<file>icons/textedit/redo.png</file>
<file>icons/textedit/undo.png</file>
<file>icons/textedit/settings.png</file>
<file>icons/png/add-file.png</file>
<file>icons/png/add-image.png</file>
<file>icons/png/attachements.png</file>
</qresource> </qresource>
</RCC> </RCC>

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 541 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 738 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 991 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 988 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

View File

@ -487,12 +487,17 @@
<file>images/textedit/editpaste.png</file> <file>images/textedit/editpaste.png</file>
<file>images/textedit/editredo.png</file> <file>images/textedit/editredo.png</file>
<file>images/textedit/editundo.png</file> <file>images/textedit/editundo.png</file>
<file>images/textedit/edit-image-face-add.png</file>
<file>images/textedit/exportpdf.png</file> <file>images/textedit/exportpdf.png</file>
<file>images/textedit/filenew.png</file> <file>images/textedit/filenew.png</file>
<file>images/textedit/fileopen.png</file> <file>images/textedit/fileopen.png</file>
<file>images/textedit/fileprint.png</file> <file>images/textedit/fileprint.png</file>
<file>images/textedit/filesave.png</file> <file>images/textedit/filesave.png</file>
<file>images/textedit/format-text-color.png</file> <file>images/textedit/format-text-color.png</file>
<file>images/textedit/format-text-strikethrough.png</file>
<file>images/textedit/format-indent-less.png</file>
<file>images/textedit/format-indent-more.png</file>
<file>images/textedit/insert-link.png</file>
<file>images/textedit/format-list-ordered.png</file> <file>images/textedit/format-list-ordered.png</file>
<file>images/textedit/format-list-unordered.png</file> <file>images/textedit/format-list-unordered.png</file>
<file>images/textedit/zoomin.png</file> <file>images/textedit/zoomin.png</file>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 718 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 701 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@ -866,3 +866,21 @@ PostedListWidget QTextBrowser#infoDescription {
background: transparent; background: transparent;
border: none; border: none;
} }
PostedCreatePostDialog QPushButton#submitButton {
font: bold;
font-size: 15px;
color: white;
background: #0099cc;
border-radius: 4px;
max-height: 27px;
min-width: 4em;
padding: 2px;
}
PostedCreatePostDialog QPushButton#submitButton:hover {
background: #03b1f3;
border-radius: 4px;
min-width: 4em;
padding: 2px;
}

View File

@ -626,6 +626,7 @@ HEADERS += rshare.h \
gui/statistics/BWGraph.h \ gui/statistics/BWGraph.h \
util/RsSyntaxHighlighter.h \ util/RsSyntaxHighlighter.h \
util/imageutil.h \ util/imageutil.h \
util/RichTextEdit.h \
gui/NetworkDialog/pgpid_item_model.h \ gui/NetworkDialog/pgpid_item_model.h \
gui/NetworkDialog/pgpid_item_proxy.h \ gui/NetworkDialog/pgpid_item_proxy.h \
gui/common/RsCollection.h \ gui/common/RsCollection.h \
@ -747,7 +748,8 @@ FORMS += gui/StartDialog.ui \
gui/statistics/StatisticsWindow.ui \ gui/statistics/StatisticsWindow.ui \
gui/statistics/BwCtrlWindow.ui \ gui/statistics/BwCtrlWindow.ui \
gui/statistics/RttStatistics.ui \ gui/statistics/RttStatistics.ui \
gui/GetStartedDialog.ui gui/GetStartedDialog.ui \
util/RichTextEdit.ui
# gui/ForumsDialog.ui \ # gui/ForumsDialog.ui \
@ -825,6 +827,7 @@ SOURCES += main.cpp \
util/HandleRichText.cpp \ util/HandleRichText.cpp \
util/ObjectPainter.cpp \ util/ObjectPainter.cpp \
util/RsFile.cpp \ util/RsFile.cpp \
util/RichTextEdit.cpp \
gui/profile/ProfileWidget.cpp \ gui/profile/ProfileWidget.cpp \
gui/profile/StatusMessage.cpp \ gui/profile/StatusMessage.cpp \
gui/profile/ProfileManager.cpp \ gui/profile/ProfileManager.cpp \

View File

@ -0,0 +1,616 @@
/*******************************************************************************
* util/RichTextEdit.cpp *
* *
* Copyright (c) 2019 Retroshare Team <retroshare.project@gmail.com> *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Affero General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Affero General Public License for more details. *
* *
* You should have received a copy of the GNU Affero General Public License *
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
* *
*******************************************************************************/
#include "RichTextEdit.h"
#include <QApplication>
#include <QClipboard>
#include <QMimeData>
#include <QFontDatabase>
#include <QInputDialog>
#include <QColorDialog>
#include <QTextList>
#include <QtDebug>
#include <QFileDialog>
#include <QImageReader>
#include <QSettings>
#include <QBuffer>
#include <QUrl>
#include <QPlainTextEdit>
#include <QMenu>
#include <QDialog>
#include <QTextDocumentFragment>
#include "util/misc.h"
#include "util/HandleRichText.h"
static const uint32_t MAX_ALLOWED_GXS_MESSAGE_SIZE = 199000;
RichTextEdit::RichTextEdit(QWidget *parent) : QWidget(parent) {
setupUi(this);
m_lastBlockList = 0;
f_textedit->setTabStopWidth(40);
connect(f_textedit, SIGNAL(currentCharFormatChanged(QTextCharFormat)),
this, SLOT(slotCurrentCharFormatChanged(QTextCharFormat)));
connect(f_textedit, SIGNAL(cursorPositionChanged()),
this, SLOT(slotCursorPositionChanged()));
m_fontsize_h1 = 18;
m_fontsize_h2 = 16;
m_fontsize_h3 = 14;
m_fontsize_h4 = 12;
fontChanged(f_textedit->font());
bgColorChanged(f_textedit->textColor());
// paragraph formatting
m_paragraphItems << tr("Standard")
<< tr("Heading 1")
<< tr("Heading 2")
<< tr("Heading 3")
<< tr("Heading 4")
<< tr("Monospace");
f_paragraph->addItems(m_paragraphItems);
connect(f_paragraph, SIGNAL(activated(int)),
this, SLOT(textStyle(int)));
// undo & redo
f_undo->setShortcut(QKeySequence::Undo);
f_redo->setShortcut(QKeySequence::Redo);
connect(f_textedit->document(), SIGNAL(undoAvailable(bool)),
f_undo, SLOT(setEnabled(bool)));
connect(f_textedit->document(), SIGNAL(redoAvailable(bool)),
f_redo, SLOT(setEnabled(bool)));
f_undo->setEnabled(f_textedit->document()->isUndoAvailable());
f_redo->setEnabled(f_textedit->document()->isRedoAvailable());
connect(f_undo, SIGNAL(clicked()), f_textedit, SLOT(undo()));
connect(f_redo, SIGNAL(clicked()), f_textedit, SLOT(redo()));
// cut, copy & paste
f_cut->setShortcut(QKeySequence::Cut);
f_copy->setShortcut(QKeySequence::Copy);
f_paste->setShortcut(QKeySequence::Paste);
f_cut->setEnabled(false);
f_copy->setEnabled(false);
connect(f_cut, SIGNAL(clicked()), f_textedit, SLOT(cut()));
connect(f_copy, SIGNAL(clicked()), f_textedit, SLOT(copy()));
connect(f_paste, SIGNAL(clicked()), f_textedit, SLOT(paste()));
connect(f_textedit, SIGNAL(copyAvailable(bool)), f_cut, SLOT(setEnabled(bool)));
connect(f_textedit, SIGNAL(copyAvailable(bool)), f_copy, SLOT(setEnabled(bool)));
#ifndef QT_NO_CLIPBOARD
connect(QApplication::clipboard(), SIGNAL(dataChanged()), this, SLOT(slotClipboardDataChanged()));
#endif
// link
f_link->setShortcut(Qt::CTRL + Qt::Key_L);
connect(f_link, SIGNAL(clicked(bool)), this, SLOT(textLink(bool)));
// bold, italic & underline
f_bold->setShortcut(Qt::CTRL + Qt::Key_B);
f_italic->setShortcut(Qt::CTRL + Qt::Key_I);
f_underline->setShortcut(Qt::CTRL + Qt::Key_U);
connect(f_bold, SIGNAL(clicked()), this, SLOT(textBold()));
connect(f_italic, SIGNAL(clicked()), this, SLOT(textItalic()));
connect(f_underline, SIGNAL(clicked()), this, SLOT(textUnderline()));
connect(f_strikeout, SIGNAL(clicked()), this, SLOT(textStrikeout()));
QAction *removeFormat = new QAction(tr("Remove character formatting"), this);
removeFormat->setShortcut(QKeySequence("CTRL+M"));
connect(removeFormat, SIGNAL(triggered()), this, SLOT(textRemoveFormat()));
f_textedit->addAction(removeFormat);
QAction *removeAllFormat = new QAction(tr("Remove all formatting"), this);
connect(removeAllFormat, SIGNAL(triggered()), this, SLOT(textRemoveAllFormat()));
f_textedit->addAction(removeAllFormat);
QAction *textsource = new QAction(tr("Edit document source"), this);
textsource->setShortcut(QKeySequence("CTRL+O"));
connect(textsource, SIGNAL(triggered()), this, SLOT(textSource()));
f_textedit->addAction(textsource);
QMenu *menu = new QMenu(this);
menu->addAction(removeAllFormat);
menu->addAction(removeFormat);
menu->addAction(textsource);
f_menu->setMenu(menu);
f_menu->setPopupMode(QToolButton::InstantPopup);
// lists
f_list_bullet->setShortcut(Qt::CTRL + Qt::Key_Minus);
f_list_ordered->setShortcut(Qt::CTRL + Qt::Key_Equal);
connect(f_list_bullet, SIGNAL(clicked(bool)), this, SLOT(listBullet(bool)));
connect(f_list_ordered, SIGNAL(clicked(bool)), this, SLOT(listOrdered(bool)));
// indentation
f_indent_dec->setShortcut(Qt::CTRL + Qt::Key_Comma);
f_indent_inc->setShortcut(Qt::CTRL + Qt::Key_Period);
connect(f_indent_inc, SIGNAL(clicked()), this, SLOT(increaseIndentation()));
connect(f_indent_dec, SIGNAL(clicked()), this, SLOT(decreaseIndentation()));
// font size
QFontDatabase db;
foreach(int size, db.standardSizes())
f_fontsize->addItem(QString::number(size));
connect(f_fontsize, SIGNAL(activated(QString)),
this, SLOT(textSize(QString)));
f_fontsize->setCurrentIndex(f_fontsize->findText(QString::number(QApplication::font()
.pointSize())));
// text foreground color
QPixmap pix(16, 16);
pix.fill(QApplication::palette().foreground().color());
f_fgcolor->setIcon(pix);
connect(f_fgcolor, SIGNAL(clicked()), this, SLOT(textFgColor()));
// text background color
pix.fill(QApplication::palette().background().color());
f_bgcolor->setIcon(pix);
connect(f_bgcolor, SIGNAL(clicked()), this, SLOT(textBgColor()));
// images
connect(f_image, SIGNAL(clicked()), this, SLOT(insertImage()));
// check message length
connect(f_textedit, SIGNAL(textChanged()), this, SLOT(checkLength()));
}
void RichTextEdit::textSource() {
QDialog *dialog = new QDialog(this);
QPlainTextEdit *pte = new QPlainTextEdit(dialog);
pte->setPlainText( f_textedit->toHtml() );
QGridLayout *gl = new QGridLayout(dialog);
gl->addWidget(pte,0,0,1,1);
dialog->setWindowTitle(tr("Document source"));
dialog->setMinimumWidth (400);
dialog->setMinimumHeight(600);
dialog->exec();
f_textedit->setHtml(pte->toPlainText());
delete dialog;
}
void RichTextEdit::textRemoveFormat() {
QTextCharFormat fmt;
fmt.setFontWeight(QFont::Normal);
fmt.setFontUnderline (false);
fmt.setFontStrikeOut (false);
fmt.setFontItalic (false);
fmt.setFontPointSize (9);
// fmt.setFontFamily ("Helvetica");
// fmt.setFontStyleHint (QFont::SansSerif);
// fmt.setFontFixedPitch (true);
f_bold ->setChecked(false);
f_underline ->setChecked(false);
f_italic ->setChecked(false);
f_strikeout ->setChecked(false);
f_fontsize ->setCurrentIndex(f_fontsize->findText("9"));
// QTextBlockFormat bfmt = cursor.blockFormat();
// bfmt->setIndent(0);
fmt.clearBackground();
mergeFormatOnWordOrSelection(fmt);
}
void RichTextEdit::textRemoveAllFormat() {
f_bold ->setChecked(false);
f_underline ->setChecked(false);
f_italic ->setChecked(false);
f_strikeout ->setChecked(false);
f_fontsize ->setCurrentIndex(f_fontsize->findText("9"));
QString text = f_textedit->toPlainText();
f_textedit->setPlainText(text);
}
void RichTextEdit::textBold() {
QTextCharFormat fmt;
fmt.setFontWeight(f_bold->isChecked() ? QFont::Bold : QFont::Normal);
mergeFormatOnWordOrSelection(fmt);
}
void RichTextEdit::focusInEvent(QFocusEvent *) {
f_textedit->setFocus(Qt::TabFocusReason);
}
void RichTextEdit::textUnderline() {
QTextCharFormat fmt;
fmt.setFontUnderline(f_underline->isChecked());
mergeFormatOnWordOrSelection(fmt);
}
void RichTextEdit::textItalic() {
QTextCharFormat fmt;
fmt.setFontItalic(f_italic->isChecked());
mergeFormatOnWordOrSelection(fmt);
}
void RichTextEdit::textStrikeout() {
QTextCharFormat fmt;
fmt.setFontStrikeOut(f_strikeout->isChecked());
mergeFormatOnWordOrSelection(fmt);
}
void RichTextEdit::textSize(const QString &p) {
qreal pointSize = p.toFloat();
if (p.toFloat() > 0) {
QTextCharFormat fmt;
fmt.setFontPointSize(pointSize);
mergeFormatOnWordOrSelection(fmt);
}
}
void RichTextEdit::textLink(bool checked) {
bool unlink = false;
QTextCharFormat fmt;
if (checked) {
QString url = f_textedit->currentCharFormat().anchorHref();
bool ok;
QString newUrl = QInputDialog::getText(this, tr("Create a link"),
tr("Link URL:"), QLineEdit::Normal,
url,
&ok);
if (ok) {
fmt.setAnchor(true);
fmt.setAnchorHref(newUrl);
fmt.setForeground(QApplication::palette().color(QPalette::Link));
fmt.setFontUnderline(true);
} else {
unlink = true;
}
} else {
unlink = true;
}
if (unlink) {
fmt.setAnchor(false);
fmt.setForeground(QApplication::palette().color(QPalette::Text));
fmt.setFontUnderline(false);
}
mergeFormatOnWordOrSelection(fmt);
}
void RichTextEdit::textStyle(int index) {
QTextCursor cursor = f_textedit->textCursor();
cursor.beginEditBlock();
// standard
if (!cursor.hasSelection()) {
cursor.select(QTextCursor::BlockUnderCursor);
}
QTextCharFormat fmt;
cursor.setCharFormat(fmt);
f_textedit->setCurrentCharFormat(fmt);
if (index == ParagraphHeading1
|| index == ParagraphHeading2
|| index == ParagraphHeading3
|| index == ParagraphHeading4 ) {
if (index == ParagraphHeading1) {
fmt.setFontPointSize(m_fontsize_h1);
}
if (index == ParagraphHeading2) {
fmt.setFontPointSize(m_fontsize_h2);
}
if (index == ParagraphHeading3) {
fmt.setFontPointSize(m_fontsize_h3);
}
if (index == ParagraphHeading4) {
fmt.setFontPointSize(m_fontsize_h4);
}
if (index == ParagraphHeading2 || index == ParagraphHeading4) {
fmt.setFontItalic(true);
}
fmt.setFontWeight(QFont::Bold);
}
if (index == ParagraphMonospace) {
fmt = cursor.charFormat();
fmt.setFontFamily("Monospace");
fmt.setFontStyleHint(QFont::Monospace);
fmt.setFontFixedPitch(true);
}
cursor.setCharFormat(fmt);
f_textedit->setCurrentCharFormat(fmt);
cursor.endEditBlock();
}
void RichTextEdit::textFgColor() {
QColor col = QColorDialog::getColor(f_textedit->textColor(), this);
QTextCursor cursor = f_textedit->textCursor();
if (!cursor.hasSelection()) {
cursor.select(QTextCursor::WordUnderCursor);
}
QTextCharFormat fmt = cursor.charFormat();
if (col.isValid()) {
fmt.setForeground(col);
} else {
fmt.clearForeground();
}
cursor.setCharFormat(fmt);
f_textedit->setCurrentCharFormat(fmt);
fgColorChanged(col);
}
void RichTextEdit::textBgColor() {
QColor col = QColorDialog::getColor(f_textedit->textBackgroundColor(), this);
QTextCursor cursor = f_textedit->textCursor();
if (!cursor.hasSelection()) {
cursor.select(QTextCursor::WordUnderCursor);
}
QTextCharFormat fmt = cursor.charFormat();
if (col.isValid()) {
fmt.setBackground(col);
} else {
fmt.clearBackground();
}
cursor.setCharFormat(fmt);
f_textedit->setCurrentCharFormat(fmt);
bgColorChanged(col);
}
void RichTextEdit::listBullet(bool checked) {
if (checked) {
f_list_ordered->setChecked(false);
}
list(checked, QTextListFormat::ListDisc);
}
void RichTextEdit::listOrdered(bool checked) {
if (checked) {
f_list_bullet->setChecked(false);
}
list(checked, QTextListFormat::ListDecimal);
}
void RichTextEdit::list(bool checked, QTextListFormat::Style style) {
QTextCursor cursor = f_textedit->textCursor();
cursor.beginEditBlock();
if (!checked) {
QTextBlockFormat obfmt = cursor.blockFormat();
QTextBlockFormat bfmt;
bfmt.setIndent(obfmt.indent());
cursor.setBlockFormat(bfmt);
} else {
QTextListFormat listFmt;
if (cursor.currentList()) {
listFmt = cursor.currentList()->format();
}
listFmt.setStyle(style);
cursor.createList(listFmt);
}
cursor.endEditBlock();
}
void RichTextEdit::mergeFormatOnWordOrSelection(const QTextCharFormat &format) {
QTextCursor cursor = f_textedit->textCursor();
if (!cursor.hasSelection()) {
cursor.select(QTextCursor::WordUnderCursor);
}
cursor.mergeCharFormat(format);
f_textedit->mergeCurrentCharFormat(format);
f_textedit->setFocus(Qt::TabFocusReason);
}
void RichTextEdit::slotCursorPositionChanged() {
QTextList *l = f_textedit->textCursor().currentList();
if (m_lastBlockList && (l == m_lastBlockList || (l != 0 && m_lastBlockList != 0
&& l->format().style() == m_lastBlockList->format().style()))) {
return;
}
m_lastBlockList = l;
if (l) {
QTextListFormat lfmt = l->format();
if (lfmt.style() == QTextListFormat::ListDisc) {
f_list_bullet->setChecked(true);
f_list_ordered->setChecked(false);
} else if (lfmt.style() == QTextListFormat::ListDecimal) {
f_list_bullet->setChecked(false);
f_list_ordered->setChecked(true);
} else {
f_list_bullet->setChecked(false);
f_list_ordered->setChecked(false);
}
} else {
f_list_bullet->setChecked(false);
f_list_ordered->setChecked(false);
}
}
void RichTextEdit::fontChanged(const QFont &f) {
f_fontsize->setCurrentIndex(f_fontsize->findText(QString::number(f.pointSize())));
f_bold->setChecked(f.bold());
f_italic->setChecked(f.italic());
f_underline->setChecked(f.underline());
f_strikeout->setChecked(f.strikeOut());
if (f.pointSize() == m_fontsize_h1) {
f_paragraph->setCurrentIndex(ParagraphHeading1);
} else if (f.pointSize() == m_fontsize_h2) {
f_paragraph->setCurrentIndex(ParagraphHeading2);
} else if (f.pointSize() == m_fontsize_h3) {
f_paragraph->setCurrentIndex(ParagraphHeading3);
} else if (f.pointSize() == m_fontsize_h4) {
f_paragraph->setCurrentIndex(ParagraphHeading4);
} else {
if (f.fixedPitch() && f.family() == "Monospace") {
f_paragraph->setCurrentIndex(ParagraphMonospace);
} else {
f_paragraph->setCurrentIndex(ParagraphStandard);
}
}
if (f_textedit->textCursor().currentList()) {
QTextListFormat lfmt = f_textedit->textCursor().currentList()->format();
if (lfmt.style() == QTextListFormat::ListDisc) {
f_list_bullet->setChecked(true);
f_list_ordered->setChecked(false);
} else if (lfmt.style() == QTextListFormat::ListDecimal) {
f_list_bullet->setChecked(false);
f_list_ordered->setChecked(true);
} else {
f_list_bullet->setChecked(false);
f_list_ordered->setChecked(false);
}
} else {
f_list_bullet->setChecked(false);
f_list_ordered->setChecked(false);
}
}
void RichTextEdit::fgColorChanged(const QColor &c) {
QPixmap pix(16, 16);
if (c.isValid()) {
pix.fill(c);
} else {
pix.fill(QApplication::palette().foreground().color());
}
f_fgcolor->setIcon(pix);
}
void RichTextEdit::bgColorChanged(const QColor &c) {
QPixmap pix(16, 16);
if (c.isValid()) {
pix.fill(c);
} else {
pix.fill(QApplication::palette().background().color());
}
f_bgcolor->setIcon(pix);
}
void RichTextEdit::slotCurrentCharFormatChanged(const QTextCharFormat &format) {
fontChanged(format.font());
bgColorChanged((format.background().isOpaque()) ? format.background().color() : QColor());
fgColorChanged((format.foreground().isOpaque()) ? format.foreground().color() : QColor());
f_link->setChecked(format.isAnchor());
}
void RichTextEdit::slotClipboardDataChanged() {
#ifndef QT_NO_CLIPBOARD
if (const QMimeData *md = QApplication::clipboard()->mimeData())
f_paste->setEnabled(md->hasText());
#endif
}
QString RichTextEdit::toHtml() const {
QString s = f_textedit->toHtml();
// convert emails to links
s = s.replace(QRegExp("(<[^a][^>]+>(?:<span[^>]+>)?|\\s)([a-zA-Z\\d]+@[a-zA-Z\\d]+\\.[a-zA-Z]+)"), "\\1<a href=\"mailto:\\2\">\\2</a>");
// convert links
s = s.replace(QRegExp("(<[^a][^>]+>(?:<span[^>]+>)?|\\s)((?:https?|ftp|file)://[^\\s'\"<>]+)"), "\\1<a href=\"\\2\">\\2</a>");
// see also: Utils::linkify()
return s;
}
void RichTextEdit::increaseIndentation() {
indent(+1);
}
void RichTextEdit::decreaseIndentation() {
indent(-1);
}
void RichTextEdit::indent(int delta) {
QTextCursor cursor = f_textedit->textCursor();
cursor.beginEditBlock();
QTextBlockFormat bfmt = cursor.blockFormat();
int ind = bfmt.indent();
if (ind + delta >= 0) {
bfmt.setIndent(ind + delta);
}
cursor.setBlockFormat(bfmt);
cursor.endEditBlock();
}
void RichTextEdit::setText(const QString& text) {
if (text.isEmpty()) {
setPlainText(text);
return;
}
if (text[0] == '<') {
setHtml(text);
} else {
setPlainText(text);
}
}
void RichTextEdit::insertImage() {
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);
f_textedit->textCursor().insertFragment(fragment);
}
}
}
void RichTextEdit::checkLength(){
QString text;
RsHtml::optimizeHtml(f_textedit, 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);
f_info->setStyleSheet("QLabel#f_info { }");
}else{
text = tr("Warning: This message is too big of %1 characters after HTML conversion.").arg((0-charRemains));
f_info->setStyleSheet("QLabel#f_info {color: red; font: bold; }");
}
//buttonBox->button(QDialogButtonBox::Ok)->setEnabled(charRemains>=0);
f_info->setText(text);
}
void RichTextEdit::setPlaceHolderTextPosted() {
f_textedit->setPlaceholderText(tr("Text (optional)"));
}

View File

@ -0,0 +1,96 @@
/*******************************************************************************
* util/RichTextEdit.h *
* *
* Copyright (c) 2019 Retroshare Team <retroshare.project@gmail.com> *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU Affero General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Affero General Public License for more details. *
* *
* You should have received a copy of the GNU Affero General Public License *
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
* *
*******************************************************************************/
#ifndef _RICHTEXTEDIT_H_
#define _RICHTEXTEDIT_H_
#include <QPointer>
#include "ui_RichTextEdit.h"
/**
* @Brief A simple rich-text editor
*/
class RichTextEdit : public QWidget, protected Ui::RichTextEdit {
Q_OBJECT
public:
RichTextEdit(QWidget *parent = 0);
QString toPlainText() const { return f_textedit->toPlainText(); }
QString toHtml() const;
QTextDocument *document() { return f_textedit->document(); }
QTextCursor textCursor() const { return f_textedit->textCursor(); }
void setTextCursor(const QTextCursor& cursor) { f_textedit->setTextCursor(cursor); }
public slots:
void setText(const QString &text);
void setPlaceHolderTextPosted();
protected slots:
void setPlainText(const QString &text) { f_textedit->setPlainText(text); }
void setHtml(const QString &text) { f_textedit->setHtml(text); }
void textRemoveFormat();
void textRemoveAllFormat();
void textBold();
void textUnderline();
void textStrikeout();
void textItalic();
void textSize(const QString &p);
void textLink(bool checked);
void textStyle(int index);
void textFgColor();
void textBgColor();
void listBullet(bool checked);
void listOrdered(bool checked);
void slotCurrentCharFormatChanged(const QTextCharFormat &format);
void slotCursorPositionChanged();
void slotClipboardDataChanged();
void increaseIndentation();
void decreaseIndentation();
void insertImage();
void textSource();
void checkLength();
protected:
void mergeFormatOnWordOrSelection(const QTextCharFormat &format);
void fontChanged(const QFont &f);
void fgColorChanged(const QColor &c);
void bgColorChanged(const QColor &c);
void list(bool checked, QTextListFormat::Style style);
void indent(int delta);
void focusInEvent(QFocusEvent *event);
QStringList m_paragraphItems;
int m_fontsize_h1;
int m_fontsize_h2;
int m_fontsize_h3;
int m_fontsize_h4;
enum ParagraphItems { ParagraphStandard = 0,
ParagraphHeading1,
ParagraphHeading2,
ParagraphHeading3,
ParagraphHeading4,
ParagraphMonospace };
QPointer<QTextList> m_lastBlockList;
};
#endif

View File

@ -0,0 +1,610 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>RichTextEdit</class>
<widget class="QWidget" name="RichTextEdit">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>703</width>
<height>312</height>
</rect>
</property>
<property name="windowTitle">
<string notr="true"/>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>1</number>
</property>
<property name="leftMargin">
<number>1</number>
</property>
<property name="topMargin">
<number>1</number>
</property>
<property name="rightMargin">
<number>1</number>
</property>
<property name="bottomMargin">
<number>1</number>
</property>
<item>
<widget class="QWidget" name="f_toolbar" native="true">
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
<number>2</number>
</property>
<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>
<widget class="QComboBox" name="f_paragraph">
<property name="focusPolicy">
<enum>Qt::ClickFocus</enum>
</property>
<property name="toolTip">
<string>Paragraph formatting</string>
</property>
<property name="editable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="f_fontsize">
<property name="font">
<font>
<family>MS Sans Serif</family>
<pointsize>10</pointsize>
</font>
</property>
<property name="focusPolicy">
<enum>Qt::ClickFocus</enum>
</property>
<property name="toolTip">
<string>Font size</string>
</property>
<property name="editable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="f_fgcolor">
<property name="focusPolicy">
<enum>Qt::ClickFocus</enum>
</property>
<property name="toolTip">
<string>Text foreground color</string>
</property>
<property name="text">
<string>.</string>
</property>
<property name="iconSize">
<size>
<width>22</width>
<height>22</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="f_bgcolor">
<property name="focusPolicy">
<enum>Qt::ClickFocus</enum>
</property>
<property name="toolTip">
<string>Text background color</string>
</property>
<property name="text">
<string>.</string>
</property>
<property name="iconSize">
<size>
<width>22</width>
<height>22</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="Line" name="line_4">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="f_undo">
<property name="enabled">
<bool>false</bool>
</property>
<property name="focusPolicy">
<enum>Qt::ClickFocus</enum>
</property>
<property name="toolTip">
<string>Undo (CTRL+Z)</string>
</property>
<property name="text">
<string>Undo</string>
</property>
<property name="icon">
<iconset resource="../gui/icons.qrc">
<normaloff>:/icons/textedit/undo.png</normaloff>:/icons/textedit/undo.png</iconset>
</property>
<property name="iconSize">
<size>
<width>22</width>
<height>22</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="f_redo">
<property name="enabled">
<bool>false</bool>
</property>
<property name="focusPolicy">
<enum>Qt::ClickFocus</enum>
</property>
<property name="toolTip">
<string>Redo</string>
</property>
<property name="text">
<string>Redo</string>
</property>
<property name="icon">
<iconset resource="../gui/icons.qrc">
<normaloff>:/icons/textedit/redo.png</normaloff>:/icons/textedit/redo.png</iconset>
</property>
<property name="iconSize">
<size>
<width>22</width>
<height>22</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="f_cut">
<property name="focusPolicy">
<enum>Qt::ClickFocus</enum>
</property>
<property name="toolTip">
<string>Cut (CTRL+X)</string>
</property>
<property name="text">
<string>Cut</string>
</property>
<property name="icon">
<iconset resource="../gui/icons.qrc">
<normaloff>:/icons/textedit/cut.png</normaloff>:/icons/textedit/cut.png</iconset>
</property>
<property name="iconSize">
<size>
<width>22</width>
<height>22</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="f_copy">
<property name="focusPolicy">
<enum>Qt::ClickFocus</enum>
</property>
<property name="toolTip">
<string>Copy (CTRL+C)</string>
</property>
<property name="text">
<string>Copy</string>
</property>
<property name="icon">
<iconset resource="../gui/icons.qrc">
<normaloff>:/icons/textedit/copy.png</normaloff>:/icons/textedit/copy.png</iconset>
</property>
<property name="iconSize">
<size>
<width>22</width>
<height>22</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="f_paste">
<property name="focusPolicy">
<enum>Qt::ClickFocus</enum>
</property>
<property name="toolTip">
<string>Paste (CTRL+V)</string>
</property>
<property name="text">
<string>Paste</string>
</property>
<property name="icon">
<iconset resource="../gui/icons.qrc">
<normaloff>:/icons/textedit/paste.png</normaloff>:/icons/textedit/paste.png</iconset>
</property>
<property name="iconSize">
<size>
<width>22</width>
<height>22</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="f_link">
<property name="focusPolicy">
<enum>Qt::ClickFocus</enum>
</property>
<property name="toolTip">
<string>Link (CTRL+L)</string>
</property>
<property name="text">
<string>Link</string>
</property>
<property name="icon">
<iconset resource="../gui/icons.qrc">
<normaloff>:/icons/textedit/link.png</normaloff>:/icons/textedit/link.png</iconset>
</property>
<property name="iconSize">
<size>
<width>22</width>
<height>22</height>
</size>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="Line" name="line_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="f_bold">
<property name="focusPolicy">
<enum>Qt::ClickFocus</enum>
</property>
<property name="toolTip">
<string notr="true">Bold (CTRL+B)</string>
</property>
<property name="text">
<string>Bold</string>
</property>
<property name="icon">
<iconset resource="../gui/icons.qrc">
<normaloff>:/icons/textedit/bold.png</normaloff>:/icons/textedit/bold.png</iconset>
</property>
<property name="iconSize">
<size>
<width>22</width>
<height>22</height>
</size>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="f_italic">
<property name="focusPolicy">
<enum>Qt::ClickFocus</enum>
</property>
<property name="toolTip">
<string>Italic (CTRL+I)</string>
</property>
<property name="text">
<string>Italic</string>
</property>
<property name="icon">
<iconset resource="../gui/icons.qrc">
<normaloff>:/icons/textedit/italic.png</normaloff>:/icons/textedit/italic.png</iconset>
</property>
<property name="iconSize">
<size>
<width>22</width>
<height>22</height>
</size>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="f_underline">
<property name="focusPolicy">
<enum>Qt::ClickFocus</enum>
</property>
<property name="toolTip">
<string>Underline (CTRL+U)</string>
</property>
<property name="text">
<string>Underline</string>
</property>
<property name="icon">
<iconset resource="../gui/icons.qrc">
<normaloff>:/icons/textedit/underline.png</normaloff>:/icons/textedit/underline.png</iconset>
</property>
<property name="iconSize">
<size>
<width>22</width>
<height>22</height>
</size>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="f_strikeout">
<property name="icon">
<iconset resource="../gui/icons.qrc">
<normaloff>:/icons/textedit/strikethrough.png</normaloff>:/icons/textedit/strikethrough.png</iconset>
</property>
<property name="iconSize">
<size>
<width>22</width>
<height>22</height>
</size>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="Line" name="line_5">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="f_list_bullet">
<property name="focusPolicy">
<enum>Qt::ClickFocus</enum>
</property>
<property name="toolTip">
<string>Bullet list (CTRL+-)</string>
</property>
<property name="text">
<string>Bullet list</string>
</property>
<property name="icon">
<iconset resource="../gui/icons.qrc">
<normaloff>:/icons/textedit/bullet-list.png</normaloff>:/icons/textedit/bullet-list.png</iconset>
</property>
<property name="iconSize">
<size>
<width>22</width>
<height>22</height>
</size>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="f_list_ordered">
<property name="focusPolicy">
<enum>Qt::ClickFocus</enum>
</property>
<property name="toolTip">
<string>Ordered list (CTRL+=)</string>
</property>
<property name="text">
<string>Ordered list</string>
</property>
<property name="icon">
<iconset resource="../gui/icons.qrc">
<normaloff>:/icons/textedit/numberd-list.png</normaloff>:/icons/textedit/numberd-list.png</iconset>
</property>
<property name="iconSize">
<size>
<width>22</width>
<height>22</height>
</size>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="f_indent_dec">
<property name="focusPolicy">
<enum>Qt::ClickFocus</enum>
</property>
<property name="toolTip">
<string>Decrease indentation (CTRL+,)</string>
</property>
<property name="icon">
<iconset resource="../gui/icons.qrc">
<normaloff>:/icons/textedit/left-indent.png</normaloff>:/icons/textedit/left-indent.png</iconset>
</property>
<property name="iconSize">
<size>
<width>22</width>
<height>22</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="f_indent_inc">
<property name="focusPolicy">
<enum>Qt::ClickFocus</enum>
</property>
<property name="toolTip">
<string>Increase indentation (CTRL+.)</string>
</property>
<property name="icon">
<iconset resource="../gui/icons.qrc">
<normaloff>:/icons/textedit/right-indent.png</normaloff>:/icons/textedit/right-indent.png</iconset>
</property>
<property name="iconSize">
<size>
<width>22</width>
<height>22</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="Line" name="line_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="f_image">
<property name="toolTip">
<string>Attach a Picture</string>
</property>
<property name="icon">
<iconset resource="../gui/icons.qrc">
<normaloff>:/icons/textedit/photo-of-a-landscape.png</normaloff>:/icons/textedit/photo-of-a-landscape.png</iconset>
</property>
<property name="iconSize">
<size>
<width>22</width>
<height>22</height>
</size>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<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>
<widget class="QToolButton" name="f_menu">
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../gui/icons.qrc">
<normaloff>:/icons/textedit/settings.png</normaloff>:/icons/textedit/settings.png</iconset>
</property>
<property name="iconSize">
<size>
<width>22</width>
<height>22</height>
</size>
</property>
</widget>
</item>
</layout>
<zorder>f_paragraph</zorder>
<zorder>f_undo</zorder>
<zorder>f_redo</zorder>
<zorder>f_cut</zorder>
<zorder>f_copy</zorder>
<zorder>f_paste</zorder>
<zorder>line</zorder>
<zorder>f_link</zorder>
<zorder>line_3</zorder>
<zorder>f_italic</zorder>
<zorder>f_underline</zorder>
<zorder>line_2</zorder>
<zorder>line_5</zorder>
<zorder>f_list_bullet</zorder>
<zorder>f_list_ordered</zorder>
<zorder>f_indent_dec</zorder>
<zorder>f_indent_inc</zorder>
<zorder>f_bold</zorder>
<zorder>f_strikeout</zorder>
<zorder>f_image</zorder>
<zorder>f_menu</zorder>
<zorder>f_fontsize</zorder>
<zorder>f_fgcolor</zorder>
<zorder>f_bgcolor</zorder>
<zorder>line_4</zorder>
</widget>
</item>
<item>
<widget class="MimeTextEdit" name="f_textedit">
<property name="font">
<font>
<family>MS Sans Serif</family>
<pointsize>9</pointsize>
</font>
</property>
<property name="autoFormatting">
<set>QTextEdit::AutoNone</set>
</property>
<property name="tabChangesFocus">
<bool>true</bool>
</property>
<property name="placeholderText">
<string>Text</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="f_info">
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>MimeTextEdit</class>
<extends>QTextEdit</extends>
<header>gui/common/MimeTextEdit.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>f_textedit</tabstop>
<tabstop>f_strikeout</tabstop>
<tabstop>f_image</tabstop>
<tabstop>f_menu</tabstop>
</tabstops>
<resources>
<include location="../gui/images.qrc"/>
<include location="../gui/icons.qrc"/>
</resources>
<connections/>
</ui>