Browse Source

pasteImageAction should be a class member; refactor messageEditor's context menu callback into a member function

pull/51/head
shunf4 7 months ago
parent
commit
52551c1ce0
  1. 27
      ui/widgets/conversation.cpp
  2. 1
      ui/widgets/conversation.h

27
ui/widgets/conversation.cpp

@ -51,7 +51,7 @@ 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),
pasteImageAction(nullptr),
pasteImageAction(new QAction(tr("Paste Image"), this)),
shadow(10, 1, Qt::black, this),
contextMenu(new QMenu())
{
@ -88,21 +88,11 @@ Conversation::Conversation(bool muc, Models::Account* acc, Models::Element* el,
this, &Conversation::onTextEditDocSizeChanged);
m_ui->messageEditor->installEventFilter(&ker);
QAction* pasteImageAction = new QAction(tr("Paste Image"), this);
connect(pasteImageAction, &QAction::triggered, this, &Conversation::onImagePasted);
m_ui->messageEditor->setContextMenuPolicy(Qt::CustomContextMenu);
connect(m_ui->messageEditor, &QTextEdit::customContextMenuRequested, this, [this, pasteImageAction](const QPoint &pos) {
pasteImageAction->setEnabled(Conversation::checkClipboardImage());
QMenu *editorMenu = m_ui->messageEditor->createStandardContextMenu();
editorMenu->addSeparator();
editorMenu->addAction(pasteImageAction);
connect(m_ui->messageEditor, &QTextEdit::customContextMenuRequested, this, &Conversation::onMessageEditorContext);
connect(pasteImageAction, &QAction::triggered, this, &Conversation::onImagePasted);
editorMenu->exec(this->m_ui->messageEditor->mapToGlobal(pos));
});
//line->setAutoFillBackground(false);
//if (testAttribute(Qt::WA_TranslucentBackground)) {
//m_ui->scrollArea->setAutoFillBackground(false);
@ -486,3 +476,14 @@ void Conversation::onFeedContext(const QPoint& pos)
}
}
}
void Conversation::onMessageEditorContext(const QPoint& pos)
{
pasteImageAction->setEnabled(Conversation::checkClipboardImage());
QMenu *editorMenu = m_ui->messageEditor->createStandardContextMenu();
editorMenu->addSeparator();
editorMenu->addAction(pasteImageAction);
editorMenu->exec(this->m_ui->messageEditor->mapToGlobal(pos));
}

1
ui/widgets/conversation.h

@ -114,6 +114,7 @@ protected slots:
void onFeedMessage(const Shared::Message& msg);
void positionShadow();
void onFeedContext(const QPoint &pos);
void onMessageEditorContext(const QPoint &pos);
public:
const bool isMuc;

Loading…
Cancel
Save