mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-23 14:39:34 -05:00
Moved QAction for saving an image from customContextMenu of GxsForumThreadWidget and ChatWidget to RSTextBrowser
This commit is contained in:
parent
02ad585c2c
commit
dceda36f6e
@ -165,7 +165,6 @@ ChatWidget::ChatWidget(QWidget *parent)
|
||||
connect(ui->actionResetFont, SIGNAL(triggered()), this, SLOT(resetFont()));
|
||||
connect(ui->actionQuote, SIGNAL(triggered()), this, SLOT(quote()));
|
||||
connect(ui->actionDropPlacemark, SIGNAL(triggered()), this, SLOT(dropPlacemark()));
|
||||
connect(ui->actionSave_image, SIGNAL(triggered()), this, SLOT(saveImage()));
|
||||
connect(ui->actionImport_sticker, SIGNAL(triggered()), this, SLOT(saveSticker()));
|
||||
connect(ui->actionShow_Hidden_Images, SIGNAL(triggered()), ui->textBrowser, SLOT(showImages()));
|
||||
ui->actionShow_Hidden_Images->setIcon(ui->textBrowser->getBlockedImage());
|
||||
@ -1151,10 +1150,7 @@ void ChatWidget::pasteText(const QString& S)
|
||||
|
||||
void ChatWidget::contextMenuTextBrowser(QPoint point)
|
||||
{
|
||||
QMatrix matrix;
|
||||
matrix.translate(ui->textBrowser->horizontalScrollBar()->value(), ui->textBrowser->verticalScrollBar()->value());
|
||||
|
||||
QMenu *contextMnu = ui->textBrowser->createStandardContextMenu(matrix.map(point));
|
||||
QMenu *contextMnu = ui->textBrowser->createStandardContextMenuFromPoint(point);
|
||||
|
||||
contextMnu->addSeparator();
|
||||
contextMnu->addAction(ui->actionClearChatHistory);
|
||||
@ -1167,9 +1163,7 @@ void ChatWidget::contextMenuTextBrowser(QPoint point)
|
||||
if (! ui->textBrowser->getShowImages())
|
||||
contextMnu->addAction(ui->actionShow_Hidden_Images);
|
||||
|
||||
ui->actionSave_image->setData(point);
|
||||
ui->actionImport_sticker->setData(point);
|
||||
contextMnu->addAction(ui->actionSave_image);
|
||||
contextMnu->addAction(ui->actionImport_sticker);
|
||||
}
|
||||
|
||||
@ -1995,13 +1989,6 @@ void ChatWidget::dropPlacemark()
|
||||
// or not.
|
||||
}
|
||||
|
||||
void ChatWidget::saveImage()
|
||||
{
|
||||
QPoint point = ui->actionSave_image->data().toPoint();
|
||||
QTextCursor cursor = ui->textBrowser->cursorForPosition(point);
|
||||
ImageUtil::extractImage(window(), cursor);
|
||||
}
|
||||
|
||||
void ChatWidget::saveSticker()
|
||||
{
|
||||
QPoint point = ui->actionImport_sticker->data().toPoint();
|
||||
|
@ -196,7 +196,6 @@ private slots:
|
||||
|
||||
void quote();
|
||||
void dropPlacemark();
|
||||
void saveImage();
|
||||
void saveSticker();
|
||||
|
||||
private:
|
||||
|
@ -1049,15 +1049,6 @@ border-image: url(:/images/closepressed.png)
|
||||
<string>Insert horizontal rule</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionSave_image">
|
||||
<property name="icon">
|
||||
<iconset resource="../images.qrc">
|
||||
<normaloff>:/images/document_save.png</normaloff>:/images/document_save.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Save image</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionImport_sticker">
|
||||
<property name="icon">
|
||||
<iconset resource="../icons.qrc">
|
||||
|
@ -22,6 +22,7 @@
|
||||
|
||||
#include "RSImageBlockWidget.h"
|
||||
#include "gui/common/FilesDefs.h"
|
||||
#include "util/imageutil.h"
|
||||
|
||||
#include <retroshare/rsinit.h> //To get RsAccounts
|
||||
|
||||
@ -33,6 +34,7 @@
|
||||
#include <QPainter>
|
||||
#include <QPlainTextEdit>
|
||||
#include <QTextDocumentFragment>
|
||||
#include <QScrollBar>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
@ -317,18 +319,43 @@ QString RSTextBrowser::anchorForPosition(const QPoint &pos) const
|
||||
return anchor;
|
||||
}
|
||||
|
||||
QMenu *RSTextBrowser::createStandardContextMenu()
|
||||
void RSTextBrowser::addContextMenuAction(QAction *action)
|
||||
{
|
||||
return createStandardContextMenu(QPoint());
|
||||
mContextMenuActions.push_back(action);
|
||||
}
|
||||
QMenu *RSTextBrowser::createStandardContextMenu(const QPoint &position)
|
||||
|
||||
void RSTextBrowser::contextMenuEvent(QContextMenuEvent *event)
|
||||
{
|
||||
QMenu *menu = QTextBrowser::createStandardContextMenu(position);
|
||||
emit calculateContextMenuActions();
|
||||
|
||||
QMenu *contextMenu = createStandardContextMenuFromPoint(event->pos());
|
||||
|
||||
QList<QAction*>::iterator it;
|
||||
for (it = mContextMenuActions.begin(); it != mContextMenuActions.end(); ++it) {
|
||||
contextMenu->addAction(*it);
|
||||
}
|
||||
|
||||
contextMenu->exec(QCursor::pos());
|
||||
|
||||
delete(contextMenu);
|
||||
}
|
||||
|
||||
QMenu *RSTextBrowser::createStandardContextMenuFromPoint(const QPoint &widgetPos)
|
||||
{
|
||||
QMatrix matrix;
|
||||
matrix.translate(horizontalScrollBar()->value(), verticalScrollBar()->value());
|
||||
|
||||
QMenu *menu = QTextBrowser::createStandardContextMenu(matrix.map(widgetPos));
|
||||
|
||||
menu->addSeparator();
|
||||
QAction *a = menu->addAction(FilesDefs::getIconFromQtResourcePath("://icons/textedit/code.png"), tr("View &Source"), this, SLOT(viewSource()));
|
||||
a->setEnabled(!this->document()->isEmpty());
|
||||
|
||||
if (checkImage(widgetPos)) {
|
||||
a = menu->addAction(FilesDefs::getIconFromQtResourcePath(":/images/document_save.png"), tr("Save image"), this, SLOT(saveImage()));
|
||||
a->setData(widgetPos);
|
||||
}
|
||||
|
||||
return menu;
|
||||
}
|
||||
|
||||
@ -350,3 +377,15 @@ void RSTextBrowser::viewSource()
|
||||
|
||||
delete dialog;
|
||||
}
|
||||
|
||||
void RSTextBrowser::saveImage()
|
||||
{
|
||||
QAction *action = dynamic_cast<QAction*>(sender()) ;
|
||||
if (!action) {
|
||||
return;
|
||||
}
|
||||
|
||||
QPoint point = action->data().toPoint();
|
||||
QTextCursor cursor = cursorForPosition(point);
|
||||
ImageUtil::extractImage(window(), cursor);
|
||||
}
|
||||
|
@ -49,6 +49,8 @@ public:
|
||||
bool checkImage(QPoint pos) {QString imageStr; return checkImage(pos, imageStr); }
|
||||
QString anchorForPosition(const QPoint &pos) const;
|
||||
|
||||
// Add QAction to context menu (action won't be deleted)
|
||||
void addContextMenuAction(QAction *action);
|
||||
|
||||
void activateLinkClick(bool active);
|
||||
|
||||
@ -58,8 +60,10 @@ public:
|
||||
QVariant textColorQuotes() const { return highlighter->textColorQuotes();}
|
||||
bool getShowImages() const { return mShowImages; }
|
||||
|
||||
QMenu *createStandardContextMenu();
|
||||
QMenu *createStandardContextMenu(const QPoint &position);
|
||||
QMenu *createStandardContextMenuFromPoint(const QPoint &widgetPos);
|
||||
|
||||
Q_SIGNALS:
|
||||
void calculateContextMenuActions();
|
||||
|
||||
public slots:
|
||||
void showImages();
|
||||
@ -70,9 +74,15 @@ private slots:
|
||||
void linkClicked(const QUrl &url);
|
||||
void destroyImageBlockWidget();
|
||||
void viewSource();
|
||||
void saveImage();
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *event);
|
||||
virtual void contextMenuEvent(QContextMenuEvent *event);
|
||||
|
||||
private:
|
||||
// Hide method from QTextBrowser
|
||||
using QTextBrowser::createStandardContextMenu;
|
||||
|
||||
private:
|
||||
QString mPlaceholderText;
|
||||
@ -80,6 +90,7 @@ private:
|
||||
RSImageBlockWidget *mImageBlockWidget;
|
||||
bool mLinkClickActive;
|
||||
RsSyntaxHighlighter *highlighter;
|
||||
QList<QAction*> mContextMenuActions;
|
||||
#ifdef RSTEXTBROWSER_CHECKIMAGE_DEBUG
|
||||
QRect mCursorRectStart;
|
||||
QRect mCursorRectLeft;
|
||||
|
@ -276,7 +276,6 @@ GxsForumThreadWidget::GxsForumThreadWidget(const RsGxsGroupId &forumId, QWidget
|
||||
|
||||
connect(ui->versions_CB, SIGNAL(currentIndexChanged(int)), this, SLOT(changedVersion()));
|
||||
connect(ui->threadTreeWidget, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(threadListCustomPopupMenu(QPoint)));
|
||||
connect(ui->postText, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenuTextBrowser(QPoint)));
|
||||
connect(ui->forumName, SIGNAL(clicked(QPoint)), this, SLOT(showForumInfo()));
|
||||
|
||||
ui->subscribeToolButton->hide() ;
|
||||
@ -303,8 +302,6 @@ GxsForumThreadWidget::GxsForumThreadWidget(const RsGxsGroupId &forumId, QWidget
|
||||
connect(ui->filterLineEdit, SIGNAL(textChanged(QString)), this, SLOT(filterItems(QString)));
|
||||
connect(ui->filterLineEdit, SIGNAL(filterChanged(int)), this, SLOT(filterColumnChanged(int)));
|
||||
|
||||
connect(ui->actionSave_image, SIGNAL(triggered()), this, SLOT(saveImage()));
|
||||
|
||||
connect(ui->threadedView_TB, SIGNAL(toggled(bool)), this, SLOT(toggleThreadedView(bool)));
|
||||
connect(ui->flatView_TB, SIGNAL(toggled(bool)), this, SLOT(toggleFlatView(bool)));
|
||||
connect(ui->latestPostInThreadView_TB, SIGNAL(toggled(bool)), this, SLOT(toggleLstPostInThreadView(bool)));
|
||||
@ -793,25 +790,6 @@ void GxsForumThreadWidget::threadListCustomPopupMenu(QPoint /*point*/)
|
||||
contextMnu.exec(QCursor::pos());
|
||||
}
|
||||
|
||||
void GxsForumThreadWidget::contextMenuTextBrowser(QPoint point)
|
||||
{
|
||||
QMatrix matrix;
|
||||
matrix.translate(ui->postText->horizontalScrollBar()->value(), ui->postText->verticalScrollBar()->value());
|
||||
|
||||
QMenu *contextMnu = ui->postText->createStandardContextMenu(matrix.map(point));
|
||||
|
||||
contextMnu->addSeparator();
|
||||
|
||||
if(ui->postText->checkImage(point))
|
||||
{
|
||||
ui->actionSave_image->setData(point);
|
||||
contextMnu->addAction(ui->actionSave_image);
|
||||
}
|
||||
|
||||
contextMnu->exec(ui->postText->viewport()->mapToGlobal(point));
|
||||
delete(contextMnu);
|
||||
}
|
||||
|
||||
void GxsForumThreadWidget::headerContextMenuRequested(const QPoint &pos)
|
||||
{
|
||||
QMenu* header_context_menu = new QMenu(tr("Show column"), this);
|
||||
@ -1823,13 +1801,6 @@ void GxsForumThreadWidget::replyForumMessageData(const RsGxsForumMsg &msg)
|
||||
}
|
||||
}
|
||||
|
||||
void GxsForumThreadWidget::saveImage()
|
||||
{
|
||||
QPoint point = ui->actionSave_image->data().toPoint();
|
||||
QTextCursor cursor = ui->postText->cursorForPosition(point);
|
||||
ImageUtil::extractImage(window(), cursor);
|
||||
}
|
||||
|
||||
void GxsForumThreadWidget::toggleThreadedView(bool b) { if(b) changedViewBox(VIEW_THREADED); }
|
||||
void GxsForumThreadWidget::toggleFlatView(bool b) { if(b) changedViewBox(VIEW_FLAT); }
|
||||
void GxsForumThreadWidget::toggleLstPostInThreadView(bool b) { if(b) changedViewBox(VIEW_LAST_POST); }
|
||||
|
@ -108,7 +108,6 @@ protected:
|
||||
private slots:
|
||||
/** Create the context popup menu and it's submenus */
|
||||
void threadListCustomPopupMenu(QPoint point);
|
||||
void contextMenuTextBrowser(QPoint point);
|
||||
void headerContextMenuRequested(const QPoint& pos);
|
||||
void showForumInfo();
|
||||
|
||||
@ -134,8 +133,6 @@ private slots:
|
||||
// This method is used to perform an asynchroneous action on the message data. Any of the methods above can be used as parameter.
|
||||
void async_msg_action(const MsgMethod& method);
|
||||
|
||||
void saveImage();
|
||||
|
||||
void markMsgAsRead();
|
||||
void markMsgAsReadChildren();
|
||||
void markMsgAsUnread();
|
||||
|
@ -568,9 +568,6 @@
|
||||
<family>MS Sans Serif</family>
|
||||
</font>
|
||||
</property>
|
||||
<property name="contextMenuPolicy">
|
||||
<enum>Qt::CustomContextMenu</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
@ -578,15 +575,6 @@
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
<action name="actionSave_image">
|
||||
<property name="icon">
|
||||
<iconset resource="../images.qrc">
|
||||
<normaloff>:/images/document_save.png</normaloff>:/images/document_save.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Save image</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
|
@ -19289,7 +19289,12 @@ p, li { white-space: pre-wrap; }
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location line="+17"/>
|
||||
<location line="+4"/>
|
||||
<source>Save image</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location line="+19"/>
|
||||
<source>Document source</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
|
Loading…
Reference in New Issue
Block a user