mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-22 19:08:58 +03:00
Don't clear selection when a context menu is requested
This commit is contained in:
parent
c64a1bf759
commit
bbf37bf633
2 changed files with 40 additions and 0 deletions
|
@ -7,6 +7,17 @@
|
||||||
|
|
||||||
#include "Utils.h"
|
#include "Utils.h"
|
||||||
|
|
||||||
|
bool
|
||||||
|
ContextMenuFilter::eventFilter(QObject *obj, QEvent *event)
|
||||||
|
{
|
||||||
|
if (event->type() == QEvent::MouseButtonPress) {
|
||||||
|
emit contextMenuIsOpening();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return QObject::eventFilter(obj, event);
|
||||||
|
}
|
||||||
|
|
||||||
TextLabel::TextLabel(QWidget *parent)
|
TextLabel::TextLabel(QWidget *parent)
|
||||||
: TextLabel(QString(), parent)
|
: TextLabel(QString(), parent)
|
||||||
{}
|
{}
|
||||||
|
@ -39,6 +50,12 @@ TextLabel::TextLabel(const QString &text, QWidget *parent)
|
||||||
setFixedHeight(0);
|
setFixedHeight(0);
|
||||||
|
|
||||||
connect(this, &TextLabel::linkActivated, this, &TextLabel::handleLinkActivation);
|
connect(this, &TextLabel::linkActivated, this, &TextLabel::handleLinkActivation);
|
||||||
|
|
||||||
|
auto filter = new ContextMenuFilter(this);
|
||||||
|
installEventFilter(filter);
|
||||||
|
connect(filter, &ContextMenuFilter::contextMenuIsOpening, this, [this]() {
|
||||||
|
contextMenuRequested_ = true;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -46,6 +63,12 @@ TextLabel::focusOutEvent(QFocusEvent *e)
|
||||||
{
|
{
|
||||||
QTextBrowser::focusOutEvent(e);
|
QTextBrowser::focusOutEvent(e);
|
||||||
|
|
||||||
|
// We keep the selection available for the context menu.
|
||||||
|
if (contextMenuRequested_) {
|
||||||
|
contextMenuRequested_ = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
QTextCursor cursor = textCursor();
|
QTextCursor cursor = textCursor();
|
||||||
cursor.clearSelection();
|
cursor.clearSelection();
|
||||||
setTextCursor(cursor);
|
setTextCursor(cursor);
|
||||||
|
|
|
@ -9,6 +9,22 @@ class QMouseEvent;
|
||||||
class QFocusEvent;
|
class QFocusEvent;
|
||||||
class QWheelEvent;
|
class QWheelEvent;
|
||||||
|
|
||||||
|
class ContextMenuFilter : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit ContextMenuFilter(QWidget *parent)
|
||||||
|
: QObject(parent)
|
||||||
|
{}
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void contextMenuIsOpening();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
bool eventFilter(QObject *obj, QEvent *event);
|
||||||
|
};
|
||||||
|
|
||||||
class TextLabel : public QTextBrowser
|
class TextLabel : public QTextBrowser
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -35,4 +51,5 @@ signals:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString link_;
|
QString link_;
|
||||||
|
bool contextMenuRequested_ = false;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue