forked from blue/squawk
message context menu began, open and show in folder features
This commit is contained in:
parent
f34289399e
commit
d514db9c4a
7 changed files with 108 additions and 6 deletions
|
@ -379,6 +379,22 @@ void Models::MessageFeed::responseArchive(const std::list<Shared::Message> list,
|
|||
}
|
||||
}
|
||||
|
||||
QModelIndex Models::MessageFeed::index(int row, int column, const QModelIndex& parent) const
|
||||
{
|
||||
if (!hasIndex(row, column, parent)) {
|
||||
return QModelIndex();
|
||||
}
|
||||
|
||||
StorageByTime::iterator itr = indexByTime.nth(row);
|
||||
if (itr != indexByTime.end()) {
|
||||
Shared::Message* msg = *itr;
|
||||
|
||||
return createIndex(row, column, msg);
|
||||
} else {
|
||||
return QModelIndex();
|
||||
}
|
||||
}
|
||||
|
||||
QHash<int, QByteArray> Models::MessageFeed::roleNames() const
|
||||
{
|
||||
return roles;
|
||||
|
|
|
@ -61,6 +61,7 @@ public:
|
|||
bool canFetchMore(const QModelIndex & parent) const override;
|
||||
void fetchMore(const QModelIndex & parent) override;
|
||||
QHash<int, QByteArray> roleNames() const override;
|
||||
QModelIndex index(int row, int column, const QModelIndex & parent) const override;
|
||||
|
||||
void responseArchive(const std::list<Shared::Message> list, bool last);
|
||||
void downloadAttachment(const QString& messageId);
|
||||
|
|
|
@ -68,8 +68,13 @@ QModelIndex FeedView::indexAt(const QPoint& point) const
|
|||
uint32_t y = vh - point.y() + vo;
|
||||
|
||||
for (std::deque<Hint>::size_type i = 0; i < hints.size(); ++i) {
|
||||
if (hints[i].offset + hints[i].height >= y) {
|
||||
return model()->index(i, 0, rootIndex());
|
||||
const Hint& hint = hints[i];
|
||||
if (y <= hint.offset + hint.height) {
|
||||
if (y > hint.offset) {
|
||||
return model()->index(i, 0, rootIndex());
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -279,7 +284,8 @@ void FeedView::paintEvent(QPaintEvent* event)
|
|||
|
||||
for (const QModelIndex& index : toRener) {
|
||||
option.rect = visualRect(index);
|
||||
option.state.setFlag(QStyle::State_MouseOver, option.rect.contains(cursor));
|
||||
bool mouseOver = option.rect.contains(cursor) && vp->rect().contains(cursor);
|
||||
option.state.setFlag(QStyle::State_MouseOver, mouseOver);
|
||||
itemDelegate(index)->paint(&painter, option, index);
|
||||
}
|
||||
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue