feature: paste image in chat #51

Merged
blue merged 3 commits from shunf4/squawk:feat/paste_img into messageFeed 2021-10-16 15:34:01 +00:00
2 changed files with 15 additions and 13 deletions
Showing only changes of commit 52551c1ce0 - Show all commits

View File

@ -51,7 +51,7 @@ Conversation::Conversation(bool muc, Models::Account* acc, Models::Element* el,
delegate(new MessageDelegate(this)), delegate(new MessageDelegate(this)),
manualSliderChange(false), manualSliderChange(false),
tsb(QApplication::style()->styleHint(QStyle::SH_ScrollBar_Transient) == 1), tsb(QApplication::style()->styleHint(QStyle::SH_ScrollBar_Transient) == 1),
pasteImageAction(nullptr), pasteImageAction(new QAction(tr("Paste Image"), this)),
shadow(10, 1, Qt::black, this), shadow(10, 1, Qt::black, this),
contextMenu(new QMenu()) contextMenu(new QMenu())
{ {
@ -88,20 +88,10 @@ Conversation::Conversation(bool muc, Models::Account* acc, Models::Element* el,
this, &Conversation::onTextEditDocSizeChanged); this, &Conversation::onTextEditDocSizeChanged);
m_ui->messageEditor->installEventFilter(&ker); 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); m_ui->messageEditor->setContextMenuPolicy(Qt::CustomContextMenu);
connect(m_ui->messageEditor, &QTextEdit::customContextMenuRequested, this, [this, pasteImageAction](const QPoint &pos) {
pasteImageAction->setEnabled(Conversation::checkClipboardImage());
blue marked this conversation as resolved
Review

Do you mind if we better move it to initialization block? Cuz, since you declare here that variable again as QAction* it might be even considered like another variable rather than that one declared as a property...

Do you mind if we better move it to initialization block? Cuz, since you declare here that variable again as QAction* it might be even considered like another variable rather than that one declared as a property...
Review

How about this change? 52551c1ce0

How about this change? https://git.macaw.me/blue/squawk/commit/52551c1ce0be0a223e388d339389b7a55b159b6c
Review

That's good, thank you!

That's good, thank you!
QMenu *editorMenu = m_ui->messageEditor->createStandardContextMenu(); connect(m_ui->messageEditor, &QTextEdit::customContextMenuRequested, this, &Conversation::onMessageEditorContext);
editorMenu->addSeparator(); connect(pasteImageAction, &QAction::triggered, this, &Conversation::onImagePasted);
editorMenu->addAction(pasteImageAction);
editorMenu->exec(this->m_ui->messageEditor->mapToGlobal(pos));
});
//line->setAutoFillBackground(false); //line->setAutoFillBackground(false);
//if (testAttribute(Qt::WA_TranslucentBackground)) { //if (testAttribute(Qt::WA_TranslucentBackground)) {
@ -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));
}

View File

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