Add missing QPlainTextEdit::createStandardContextMenu(QPoint)
[ChangeLog][QtWidgets] Added QPlainTextEdit::createStandardContextMenu(QPoint) overload that takes the position in document coordinates. This method enables the actions that are sensitive to the given position eg. where the user clicked. Change-Id: I47ed7a1afc4fcfb3318c9b7af37867aeb7f2aa35 Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
This commit is contained in:
parent
25e19acca6
commit
85ecc44eee
@ -2331,9 +2331,12 @@ void QPlainTextEdit::zoomInF(float range)
|
||||
|
||||
#ifndef QT_NO_CONTEXTMENU
|
||||
/*! This function creates the standard context menu which is shown
|
||||
when the user clicks on the line edit with the right mouse
|
||||
when the user clicks on the text edit with the right mouse
|
||||
button. It is called from the default contextMenuEvent() handler.
|
||||
The popup menu's ownership is transferred to the caller.
|
||||
|
||||
We recommend that you use the createStandardContextMenu(QPoint) version instead
|
||||
which will enable the actions that are sensitive to where the user clicked.
|
||||
*/
|
||||
|
||||
QMenu *QPlainTextEdit::createStandardContextMenu()
|
||||
@ -2341,6 +2344,22 @@ QMenu *QPlainTextEdit::createStandardContextMenu()
|
||||
Q_D(QPlainTextEdit);
|
||||
return d->control->createStandardContextMenu(QPointF(), this);
|
||||
}
|
||||
|
||||
/*!
|
||||
\since 5.5
|
||||
This function creates the standard context menu which is shown
|
||||
when the user clicks on the text edit with the right mouse
|
||||
button. It is called from the default contextMenuEvent() handler
|
||||
and it takes the \a position in document coordinates where the mouse click was.
|
||||
This can enable actions that are sensitive to the position where the user clicked.
|
||||
The popup menu's ownership is transferred to the caller.
|
||||
*/
|
||||
|
||||
QMenu *QPlainTextEdit::createStandardContextMenu(const QPoint &position)
|
||||
{
|
||||
Q_D(QPlainTextEdit);
|
||||
return d->control->createStandardContextMenu(position, this);
|
||||
}
|
||||
#endif // QT_NO_CONTEXTMENU
|
||||
|
||||
/*!
|
||||
|
@ -149,6 +149,7 @@ public:
|
||||
virtual QVariant loadResource(int type, const QUrl &name);
|
||||
#ifndef QT_NO_CONTEXTMENU
|
||||
QMenu *createStandardContextMenu();
|
||||
QMenu *createStandardContextMenu(const QPoint &position);
|
||||
#endif
|
||||
|
||||
QTextCursor cursorForPosition(const QPoint &pos) const;
|
||||
|
@ -45,6 +45,7 @@
|
||||
#include <private/qwidgettextcontrol_p.h>
|
||||
#include <qscrollbar.h>
|
||||
#include <qtextobject.h>
|
||||
#include <qmenu.h>
|
||||
|
||||
#include <qabstracttextdocumentlayout.h>
|
||||
#include <qtextdocumentfragment.h>
|
||||
@ -150,6 +151,9 @@ private slots:
|
||||
void layoutAfterMultiLineRemove();
|
||||
void undoCommandRemovesAndReinsertsBlock();
|
||||
void taskQTBUG_43562_lineCountCrash();
|
||||
#ifndef QT_NO_CONTEXTMENU
|
||||
void contextMenu();
|
||||
#endif
|
||||
|
||||
private:
|
||||
void createSelection();
|
||||
@ -1687,5 +1691,41 @@ void tst_QPlainTextEdit::taskQTBUG_43562_lineCountCrash()
|
||||
disconnect(ed->document(), SIGNAL(contentsChange(int, int, int)), 0, 0);
|
||||
}
|
||||
|
||||
#ifndef QT_NO_CONTEXTMENU
|
||||
void tst_QPlainTextEdit::contextMenu()
|
||||
{
|
||||
ed->appendHtml(QStringLiteral("Hello <a href='http://www.qt.io'>Qt</a>"));
|
||||
|
||||
QMenu *menu = ed->createStandardContextMenu();
|
||||
QVERIFY(menu);
|
||||
QAction *action = ed->findChild<QAction *>(QStringLiteral("link-copy"));
|
||||
QVERIFY(!action);
|
||||
delete menu;
|
||||
QVERIFY(!ed->findChild<QAction *>(QStringLiteral("link-copy")));
|
||||
|
||||
ed->setTextInteractionFlags(Qt::TextBrowserInteraction);
|
||||
|
||||
menu = ed->createStandardContextMenu();
|
||||
QVERIFY(menu);
|
||||
action = ed->findChild<QAction *>(QStringLiteral("link-copy"));
|
||||
QVERIFY(action);
|
||||
QVERIFY(!action->isEnabled());
|
||||
delete menu;
|
||||
QVERIFY(!ed->findChild<QAction *>(QStringLiteral("link-copy")));
|
||||
|
||||
QTextCursor cursor = ed->textCursor();
|
||||
cursor.setPosition(ed->toPlainText().length() - 2);
|
||||
ed->setTextCursor(cursor);
|
||||
|
||||
menu = ed->createStandardContextMenu(ed->cursorRect().center());
|
||||
QVERIFY(menu);
|
||||
action = ed->findChild<QAction *>(QStringLiteral("link-copy"));
|
||||
QVERIFY(action);
|
||||
QVERIFY(action->isEnabled());
|
||||
delete menu;
|
||||
QVERIFY(!ed->findChild<QAction *>(QStringLiteral("link-copy")));
|
||||
}
|
||||
#endif // QT_NO_CONTEXTMENU
|
||||
|
||||
QTEST_MAIN(tst_QPlainTextEdit)
|
||||
#include "tst_qplaintextedit.moc"
|
||||
|
Loading…
x
Reference in New Issue
Block a user