message context menu began, open and show in folder features

This commit is contained in:
Blue 2021-05-04 17:09:41 +03:00
parent f34289399e
commit d514db9c4a
7 changed files with 108 additions and 6 deletions

View file

@ -47,7 +47,8 @@ Conversation::Conversation(bool muc, Models::Account* acc, Models::Element* el,
delegate(new MessageDelegate(this)),
manualSliderChange(false),
tsb(QApplication::style()->styleHint(QStyle::SH_ScrollBar_Transient) == 1),
shadow(10, 1, Qt::black, this)
shadow(10, 1, Qt::black, this),
contextMenu(new QMenu())
{
m_ui->setupUi(this);
@ -55,6 +56,7 @@ Conversation::Conversation(bool muc, Models::Account* acc, Models::Element* el,
feed->setItemDelegate(delegate);
feed->setFrameShape(QFrame::NoFrame);
feed->setContextMenuPolicy(Qt::CustomContextMenu);
delegate->initializeFonts(feed->getFont());
feed->setModel(el->feed);
el->feed->incrementObservers();
@ -62,6 +64,7 @@ Conversation::Conversation(bool muc, Models::Account* acc, Models::Element* el,
connect(el->feed, &Models::MessageFeed::newMessage, this, &Conversation::onFeedMessage);
connect(feed, &FeedView::resized, this, &Conversation::positionShadow);
connect(feed, &FeedView::customContextMenuRequested, this, &Conversation::onFeedContext);
connect(acc, &Models::Account::childChanged, this, &Conversation::onAccountChanged);
@ -88,8 +91,6 @@ Conversation::Conversation(bool muc, Models::Account* acc, Models::Element* el,
//m_ui->scrollArea->setBackgroundRole(QPalette::Base);
//}
//m_ui->scrollArea->installEventFilter(&scrollResizeCatcher);
//line->setMyAvatarPath(acc->getAvatarPath());
//line->setMyName(acc->getName());
@ -98,6 +99,8 @@ Conversation::Conversation(bool muc, Models::Account* acc, Models::Element* el,
Conversation::~Conversation()
{
delete contextMenu;
element->feed->decrementObservers();
}
@ -402,3 +405,31 @@ void Conversation::positionShadow()
shadow.move(feed->pos());
shadow.raise();
}
void Conversation::onFeedContext(const QPoint& pos)
{
QModelIndex index = feed->indexAt(pos);
if (index.isValid()) {
Shared::Message* item = static_cast<Shared::Message*>(index.internalPointer());
contextMenu->clear();
bool showMenu = false;
QString path = item->getAttachPath();
if (path.size() > 0) {
showMenu = true;
QAction* open = contextMenu->addAction(Shared::icon("document-new-from-template"), tr("Open"));
connect(open, &QAction::triggered, [path]() {
QDesktopServices::openUrl(QUrl::fromLocalFile(path));
});
QAction* show = contextMenu->addAction(Shared::icon("document-new-from-template"), tr("Show in folder"));
connect(show, &QAction::triggered, [path]() {
Shared::showInDirectory(path);
});
}
if (showMenu) {
contextMenu->popup(feed->viewport()->mapToGlobal(pos));
}
}
}

View file

@ -25,6 +25,9 @@
#include <QMimeData>
#include <QFileInfo>
#include <QGraphicsOpacityEffect>
#include <QMenu>
#include <QAction>
#include <QDesktopServices>
#include "shared/message.h"
#include "order.h"
@ -103,6 +106,7 @@ protected slots:
void onAccountChanged(Models::Item* item, int row, int col);
void onFeedMessage(const Shared::Message& msg);
void positionShadow();
void onFeedContext(const QPoint &pos);
public:
const bool isMuc;
@ -126,6 +130,7 @@ protected:
bool tsb; //transient scroll bars
ShadowOverlay shadow;
QMenu* contextMenu;
};
#endif // CONVERSATION_H