added "Copy message" context menu item ofr messages

This commit is contained in:
fourtf 2018-05-23 20:34:37 +02:00
parent 63e88938ef
commit 0d76f6f39f
2 changed files with 30 additions and 11 deletions

View file

@ -50,7 +50,7 @@ public:
const MessageLayoutElement *getElementAt(QPoint point); const MessageLayoutElement *getElementAt(QPoint point);
int getLastCharacterIndex() const; int getLastCharacterIndex() const;
int getSelectionIndex(QPoint position); int getSelectionIndex(QPoint position);
void addSelectionText(QString &str, int from, int to); void addSelectionText(QString &str, int from = 0, int to = INT_MAX);
// Misc // Misc
bool isDisabled() const; bool isDisabled() const;

View file

@ -938,12 +938,13 @@ void ChannelView::mouseReleaseEvent(QMouseEvent *event)
const auto &creator = hoverLayoutElement->getCreator(); const auto &creator = hoverLayoutElement->getCreator();
auto creatorFlags = creator.getFlags(); auto creatorFlags = creator.getFlags();
if ((creatorFlags & (MessageElement::Flags::EmoteImages | MessageElement::Flags::EmojiImage)) != if (event->button() == Qt::RightButton) {
0) { static QMenu *menu = new QMenu;
if (event->button() == Qt::RightButton) { menu->clear();
static QMenu *menu = new QMenu;
menu->clear();
// Emote actions
if ((creatorFlags &
(MessageElement::Flags::EmoteImages | MessageElement::Flags::EmojiImage)) != 0) {
const auto &emoteElement = static_cast<const messages::EmoteElement &>(creator); const auto &emoteElement = static_cast<const messages::EmoteElement &>(creator);
// TODO: We might want to add direct "Open image" variants alongside the Copy actions // TODO: We might want to add direct "Open image" variants alongside the Copy actions
@ -977,12 +978,30 @@ void ChannelView::mouseReleaseEvent(QMouseEvent *event)
QApplication::clipboard()->setText(emotePageLink); // QApplication::clipboard()->setText(emotePageLink); //
}); });
} }
menu->move(QCursor::pos());
menu->show();
return;
} }
// add seperator
if (!menu->actions().empty())
menu->addSeparator();
// Message actions
menu->addAction("Copy message", [layout] {
QString copyString;
layout->addSelectionText(copyString);
QGuiApplication::clipboard()->setText(copyString);
});
// menu->addAction("Quote message", [layout] {
// QString copyString;
// layout->addSelectionText(copyString);
// // insert into input
// });
menu->move(QCursor::pos());
menu->show();
return;
} }
auto &link = hoverLayoutElement->getLink(); auto &link = hoverLayoutElement->getLink();