Added new rich text editor & improved design for Create Post

* Added new Rich Text Editor
* Redesigned the Create Post Composer for Posted Links
* When only link is added display different thumbnail
This commit is contained in:
defnax 2019-12-19 19:05:13 +01:00
parent dadc86e291
commit 47678b33a4
36 changed files with 1691 additions and 135 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/MRichTextEdit.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->MRichTextEditWidget->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());
post.mMeta.mAuthorId = authorId;
QString text;
text = ui->MRichTextEditWidget->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; 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!!
@ -118,4 +135,19 @@ 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/MRichTextEdit.h"
class TokenQueue; class TokenQueue;
@ -41,13 +42,15 @@ public:
*/ */
explicit PostedCreatePostDialog(TokenQueue* tokenQ, RsPosted* posted, const RsGxsGroupId& grpId, QWidget *parent = 0); explicit PostedCreatePostDialog(TokenQueue* tokenQ, RsPosted* posted, const RsGxsGroupId& grpId, QWidget *parent = 0);
~PostedCreatePostDialog(); ~PostedCreatePostDialog();
QPixmap picture; QPixmap picture;
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="MRichTextEdit" name="MRichTextEditWidget" 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,8 +341,8 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="0"> <item row="0" column="2">
<spacer name="horizontalSpacer_2"> <spacer name="horizontalSpacer_3">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
@ -199,8 +354,8 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="0" column="2"> <item row="0" column="0">
<spacer name="horizontalSpacer_3"> <spacer name="horizontalSpacer_2">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
@ -215,34 +370,65 @@
</layout> </layout>
</widget> </widget>
</item> </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> </layout>
</widget> </widget>
<widget class="QWidget" name="tab_2"> <widget class="QWidget" name="stackedWidgetPage3">
<attribute name="title">
<string>Notes</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_3"> <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"> <item row="0" column="0">
<widget class="MimeTextEdit" name="notesTextEdit"/> <widget class="QLineEdit" name="titleEditLink">
<property name="placeholderText">
<string>Title</string>
</property>
</widget>
</item> </item>
</layout> </layout>
</widget> </widget>
</widget> </widget>
</item> </item>
<item row="3" column="0"> <item row="4" column="1">
<spacer name="buttonHSpacer">
<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="3" 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>MRichTextEdit</class>
<extends>QWidget</extends>
<header>util/MRichTextEdit.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");
@ -317,6 +303,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);
@ -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

@ -116,7 +116,7 @@
<file>icons/png/newsfeed-notify.png</file> <file>icons/png/newsfeed-notify.png</file>
<file>icons/png/newsfeed.png</file> <file>icons/png/newsfeed.png</file>
<file>icons/png/options.png</file> <file>icons/png/options.png</file>
<file>icons/png/pencil-edit-button.png</file> <file>icons/png/pencil-edit-button.png</file>
<file>icons/png/people-notify.png</file> <file>icons/png/people-notify.png</file>
<file>icons/png/people.png</file> <file>icons/png/people.png</file>
<file>icons/png/person.png</file> <file>icons/png/person.png</file>
@ -134,7 +134,7 @@
<file>icons/png/thumbs-down.png</file> <file>icons/png/thumbs-down.png</file>
<file>icons/png/thumbs-neutral.png</file> <file>icons/png/thumbs-neutral.png</file>
<file>icons/png/thumbs-up.png</file> <file>icons/png/thumbs-up.png</file>
<file>icons/png/typing.png</file> <file>icons/png/typing.png</file>
<file>icons/png/video.png</file> <file>icons/png/video.png</file>
<file>icons/posted_128.png</file> <file>icons/posted_128.png</file>
<file>icons/posted_red_128.png</file> <file>icons/posted_red_128.png</file>
@ -290,5 +290,21 @@
<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>
</qresource> </qresource>
</RCC> </RCC>

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

@ -0,0 +1,620 @@
/*
** Copyright (C) 2019 by defnax <retroshare.project@gmail.com>
**
** Copyright (C) 2013 Jiří Procházka (Hobrasoft)
** Contact: http://www.hobrasoft.cz/
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
** This file is under the terms of the GNU Lesser General Public License
** version 2.1 as published by the Free Software Foundation and appearing
** in the file LICENSE.LGPL included in the packaging of this file.
** Please review the following information to ensure the
** GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** $QT_END_LICENSE$
*/
#include "MRichTextEdit.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;
MRichTextEdit::MRichTextEdit(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 MRichTextEdit::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 MRichTextEdit::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 MRichTextEdit::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 MRichTextEdit::textBold() {
QTextCharFormat fmt;
fmt.setFontWeight(f_bold->isChecked() ? QFont::Bold : QFont::Normal);
mergeFormatOnWordOrSelection(fmt);
}
void MRichTextEdit::focusInEvent(QFocusEvent *) {
f_textedit->setFocus(Qt::TabFocusReason);
}
void MRichTextEdit::textUnderline() {
QTextCharFormat fmt;
fmt.setFontUnderline(f_underline->isChecked());
mergeFormatOnWordOrSelection(fmt);
}
void MRichTextEdit::textItalic() {
QTextCharFormat fmt;
fmt.setFontItalic(f_italic->isChecked());
mergeFormatOnWordOrSelection(fmt);
}
void MRichTextEdit::textStrikeout() {
QTextCharFormat fmt;
fmt.setFontStrikeOut(f_strikeout->isChecked());
mergeFormatOnWordOrSelection(fmt);
}
void MRichTextEdit::textSize(const QString &p) {
qreal pointSize = p.toFloat();
if (p.toFloat() > 0) {
QTextCharFormat fmt;
fmt.setFontPointSize(pointSize);
mergeFormatOnWordOrSelection(fmt);
}
}
void MRichTextEdit::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 MRichTextEdit::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 MRichTextEdit::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 MRichTextEdit::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 MRichTextEdit::listBullet(bool checked) {
if (checked) {
f_list_ordered->setChecked(false);
}
list(checked, QTextListFormat::ListDisc);
}
void MRichTextEdit::listOrdered(bool checked) {
if (checked) {
f_list_bullet->setChecked(false);
}
list(checked, QTextListFormat::ListDecimal);
}
void MRichTextEdit::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 MRichTextEdit::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 MRichTextEdit::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 MRichTextEdit::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 MRichTextEdit::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 MRichTextEdit::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 MRichTextEdit::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 MRichTextEdit::slotClipboardDataChanged() {
#ifndef QT_NO_CLIPBOARD
if (const QMimeData *md = QApplication::clipboard()->mimeData())
f_paste->setEnabled(md->hasText());
#endif
}
QString MRichTextEdit::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 MRichTextEdit::increaseIndentation() {
indent(+1);
}
void MRichTextEdit::decreaseIndentation() {
indent(-1);
}
void MRichTextEdit::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 MRichTextEdit::setText(const QString& text) {
if (text.isEmpty()) {
setPlainText(text);
return;
}
if (text[0] == '<') {
setHtml(text);
} else {
setPlainText(text);
}
}
void MRichTextEdit::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 MRichTextEdit::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 MRichTextEdit::setPlaceHolderTextPosted() {
f_textedit->setPlaceholderText(tr("Text (optional)"));
}

View File

@ -0,0 +1,101 @@
/*
** Copyright (C) 2019 by defnax <retroshare.project@gmail.com>
**
** Copyright (C) 2013 Jiří Procházka (Hobrasoft)
** Contact: http://www.hobrasoft.cz/
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
** This file is under the terms of the GNU Lesser General Public License
** version 2.1 as published by the Free Software Foundation and appearing
** in the file LICENSE.LGPL included in the packaging of this file.
** Please review the following information to ensure the
** GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** $QT_END_LICENSE$
*/
#ifndef _MRICHTEXTEDIT_H_
#define _MRICHTEXTEDIT_H_
#include <QPointer>
#include "ui_MRichTextEdit.h"
/**
* @Brief A simple rich-text editor
*/
class MRichTextEdit : public QWidget, protected Ui::MRichTextEdit {
Q_OBJECT
public:
MRichTextEdit(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,598 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MRichTextEdit</class>
<widget class="QWidget" name="MRichTextEdit">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>699</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="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="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>