Merge pull request #1115 from PhenomRetroShare/Add_CopyComment

Add Copy action for Gxs Comments.
This commit is contained in:
csoler 2017-11-22 20:31:49 +01:00 committed by GitHub
commit c8c90ab892
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 8 deletions

View file

@ -13,7 +13,7 @@
<property name="windowTitle"> <property name="windowTitle">
<string>Form</string> <string>Form</string>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_3"> <layout class="QVBoxLayout" name="GxsCommentDialogVLayout">
<item> <item>
<widget class="QFrame" name="postFrame"> <widget class="QFrame" name="postFrame">
<property name="sizePolicy"> <property name="sizePolicy">
@ -22,7 +22,7 @@
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="postFrameVLayout">
<property name="leftMargin"> <property name="leftMargin">
<number>9</number> <number>9</number>
</property> </property>
@ -36,7 +36,7 @@
</widget> </widget>
</item> </item>
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout"> <layout class="QHBoxLayout" name="toolBarHLayout">
<item> <item>
<widget class="QPushButton" name="hotSortButton"> <widget class="QPushButton" name="hotSortButton">
<property name="text"> <property name="text">
@ -80,7 +80,7 @@
</widget> </widget>
</item> </item>
<item> <item>
<spacer name="horizontalSpacer"> <spacer name="toolBarHSpacer">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
@ -93,7 +93,7 @@
</spacer> </spacer>
</item> </item>
<item> <item>
<widget class="QLabel" name="label_2"> <widget class="QLabel" name="idLabel">
<property name="text"> <property name="text">
<string>Voter ID:</string> <string>Voter ID:</string>
</property> </property>

View file

@ -21,13 +21,14 @@
* *
*/ */
#include <QMimeData>
#include <QTextDocument>
#include <QAbstractTextDocumentLayout> #include <QAbstractTextDocumentLayout>
#include <QApplication> #include <QApplication>
#include <QClipboard>
#include <QDateTime> #include <QDateTime>
#include <QMenu> #include <QMenu>
#include <QMimeData>
#include <QPainter> #include <QPainter>
#include <QTextDocument>
#include "gui/common/RSElidedItemDelegate.h" #include "gui/common/RSElidedItemDelegate.h"
#include "gui/gxs/GxsCommentTreeWidget.h" #include "gui/gxs/GxsCommentTreeWidget.h"
@ -54,7 +55,8 @@
#define POST_COLOR_ROLE (Qt::UserRole+2) #define POST_COLOR_ROLE (Qt::UserRole+2)
/* Images for context menu icons */ /* Images for context menu icons */
#define IMAGE_MESSAGE ":/images/folder-draft.png" #define IMAGE_MESSAGE ":/images/folder-draft.png"
#define IMAGE_COPY ":/images/copy.png"
#define IMAGE_VOTEUP ":/images/vote_up.png" #define IMAGE_VOTEUP ":/images/vote_up.png"
#define IMAGE_VOTEDOWN ":/images/vote_down.png" #define IMAGE_VOTEDOWN ":/images/vote_down.png"
@ -170,6 +172,7 @@ void GxsCommentTreeWidget::setCurrentCommentMsgId(QTreeWidgetItem *current, QTre
if(current) if(current)
{ {
mCurrentCommentMsgId = RsGxsMessageId(current->text(PCITEM_COLUMN_MSGID).toStdString()); mCurrentCommentMsgId = RsGxsMessageId(current->text(PCITEM_COLUMN_MSGID).toStdString());
mCurrentCommentText = current->text(PCITEM_COLUMN_COMMENT);
} }
} }
@ -180,6 +183,8 @@ void GxsCommentTreeWidget::customPopUpMenu(const QPoint& /*point*/)
action->setDisabled(mCurrentCommentMsgId.isNull()); action->setDisabled(mCurrentCommentMsgId.isNull());
action = contextMnu.addAction(QIcon(IMAGE_MESSAGE), tr("Submit Comment"), this, SLOT(makeComment())); action = contextMnu.addAction(QIcon(IMAGE_MESSAGE), tr("Submit Comment"), this, SLOT(makeComment()));
action->setDisabled(mMsgVersions.empty()); action->setDisabled(mMsgVersions.empty());
action = contextMnu.addAction(QIcon(IMAGE_COPY), tr("Copy Comment"), this, SLOT(copyComment()));
action->setDisabled(mCurrentCommentMsgId.isNull());
contextMnu.addSeparator(); contextMnu.addSeparator();
@ -308,6 +313,14 @@ void GxsCommentTreeWidget::replyToComment()
pcc.exec(); pcc.exec();
} }
void GxsCommentTreeWidget::copyComment()
{
QMimeData *mimeData = new QMimeData();
mimeData->setHtml("<html>"+mCurrentCommentText+"</html>");
QClipboard *clipboard = QApplication::clipboard();
clipboard->setMimeData(mimeData, QClipboard::Clipboard);
}
void GxsCommentTreeWidget::setup(RsTokenService *token_service, RsGxsCommentService *comment_service) void GxsCommentTreeWidget::setup(RsTokenService *token_service, RsGxsCommentService *comment_service)
{ {
mRsTokenService = token_service; mRsTokenService = token_service;

View file

@ -71,6 +71,8 @@ public slots:
void makeComment(); void makeComment();
void replyToComment(); void replyToComment();
void copyComment();
void voteUp(); void voteUp();
void voteDown(); void voteDown();
@ -89,6 +91,7 @@ protected:
std::set<RsGxsMessageId> mMsgVersions; std::set<RsGxsMessageId> mMsgVersions;
RsGxsMessageId mLatestMsgId; RsGxsMessageId mLatestMsgId;
RsGxsMessageId mCurrentCommentMsgId; RsGxsMessageId mCurrentCommentMsgId;
QString mCurrentCommentText;
RsGxsId mVoterId; RsGxsId mVoterId;
std::map<RsGxsMessageId, QTreeWidgetItem *> mLoadingMap; std::map<RsGxsMessageId, QTreeWidgetItem *> mLoadingMap;