本文整理汇总了C++中QContextMenuEvent类的典型用法代码示例。如果您正苦于以下问题:C++ QContextMenuEvent类的具体用法?C++ QContextMenuEvent怎么用?C++ QContextMenuEvent使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QContextMenuEvent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: switch
bool QToolBoxHelper::eventFilter(QObject *watched, QEvent *event)
{
switch (event->type()) {
case QEvent::ChildPolished:
// Install on the buttons
if (watched == m_toolbox) {
QChildEvent *ce = static_cast<QChildEvent *>(event);
if (!qstrcmp(ce->child()->metaObject()->className(), "QToolBoxButton"))
ce->child()->installEventFilter(this);
}
break;
case QEvent::ContextMenu:
if (watched != m_toolbox) {
// An action invoked from the passive interactor (ToolBox button) might
// cause its deletion within its event handler, triggering a warning. Re-post
// the event to the toolbox.
QContextMenuEvent *current = static_cast<QContextMenuEvent *>(event);
QContextMenuEvent *copy = new QContextMenuEvent(current->reason(), current->pos(), current-> globalPos(), current->modifiers());
QApplication::postEvent(m_toolbox, copy);
current->accept();
return true;
}
break;
case QEvent::MouseButtonRelease:
if (watched != m_toolbox)
if (QDesignerFormWindowInterface *fw = QDesignerFormWindowInterface::findFormWindow(m_toolbox)) {
fw->clearSelection();
fw->selectWidget(m_toolbox, true);
}
break;
default:
break;
}
return QObject::eventFilter(watched, event);
}
示例2: IntPoint
WebKitPlatformMouseEvent::WebKitPlatformMouseEvent(QInputEvent* event, int clickCount)
{
m_timestamp = WTF::currentTime();
bool isContextMenuEvent = false;
#ifndef QT_NO_CONTEXTMENU
if (event->type() == QEvent::ContextMenu) {
isContextMenuEvent = true;
m_type = PlatformEvent::MousePressed;
QContextMenuEvent* ce = static_cast<QContextMenuEvent*>(event);
m_position = IntPoint(ce->pos());
m_globalPosition = IntPoint(ce->globalPos());
m_button = RightButton;
}
#endif
if (!isContextMenuEvent) {
PlatformEvent::Type type;
mouseEventTypeAndMouseButtonFromQEvent(event, type, m_button);
QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(event);
m_type = type;
m_position = IntPoint(mouseEvent->pos());
m_globalPosition = IntPoint(mouseEvent->globalPos());
}
m_clickCount = clickCount;
mouseEventModifiersFromQtKeyboardModifiers(event->modifiers(), m_modifiers);
}
示例3: eventFilter
bool QtKeySequenceEdit::eventFilter(QObject *o, QEvent *e)
{
if (o == m_lineEdit && e->type() == QEvent::ContextMenu) {
QContextMenuEvent *c = static_cast<QContextMenuEvent *>(e);
QMenu *menu = m_lineEdit->createStandardContextMenu();
const QList<QAction *> actions = menu->actions();
QListIterator<QAction *> itAction(actions);
while (itAction.hasNext()) {
QAction *action = itAction.next();
action->setShortcut(QKeySequence());
QString actionString = action->text();
const int pos = actionString.lastIndexOf(QLatin1Char('\t'));
if (pos > 0)
actionString.remove(pos, actionString.length() - pos);
action->setText(actionString);
}
QAction *actionBefore = 0;
if (actions.count() > 0)
actionBefore = actions[0];
QAction *clearAction = new QAction(tr("Clear Shortcut"), menu);
menu->insertAction(actionBefore, clearAction);
menu->insertSeparator(actionBefore);
clearAction->setEnabled(!m_keySequence.isEmpty());
connect(clearAction, SIGNAL(triggered()), this, SLOT(slotClearShortcut()));
menu->exec(c->globalPos());
delete menu;
e->accept();
return true;
}
return QWidget::eventFilter(o, e);
}
示例4: eventFilter
bool AlbumCoverManager::eventFilter(QObject* obj, QEvent* event) {
if (obj == ui_->albums && event->type() == QEvent::ContextMenu) {
context_menu_items_ = ui_->albums->selectedItems();
if (context_menu_items_.isEmpty()) return false;
bool some_with_covers = false;
for (QListWidgetItem* item : context_menu_items_) {
if (item->icon().cacheKey() != no_cover_icon_.cacheKey())
some_with_covers = true;
}
album_cover_choice_controller_->cover_from_file_action()->setEnabled(
context_menu_items_.size() == 1);
album_cover_choice_controller_->cover_from_url_action()->setEnabled(
context_menu_items_.size() == 1);
album_cover_choice_controller_->show_cover_action()->setEnabled(
some_with_covers && context_menu_items_.size() == 1);
album_cover_choice_controller_->unset_cover_action()->setEnabled(
some_with_covers);
album_cover_choice_controller_->search_for_cover_action()->setEnabled(
app_->cover_providers()->HasAnyProviders());
QContextMenuEvent* e = static_cast<QContextMenuEvent*>(event);
context_menu_->popup(e->globalPos());
return true;
}
return QMainWindow::eventFilter(obj, event);
}
示例5: eventFilter
bool AbstractFloatItem::eventFilter( QObject *object, QEvent *e )
{
if ( !enabled() || !visible() ) {
return false;
}
if( e->type() == QEvent::ContextMenu )
{
QWidget *widget = dynamic_cast<QWidget *>( object );
QContextMenuEvent *menuEvent = dynamic_cast<QContextMenuEvent *> ( e );
if( widget != NULL && menuEvent != NULL && contains( menuEvent->pos() ) )
{
contextMenuEvent( widget, menuEvent );
return true;
}
return false;
}
else if( e->type() == QEvent::ToolTip )
{
QHelpEvent *helpEvent = dynamic_cast<QHelpEvent *>( e );
if( helpEvent != NULL && contains( helpEvent->pos() ) )
{
toolTipEvent( helpEvent );
return true;
}
return false;
}
else
return ScreenGraphicsItem::eventFilter( object, e );
}
示例6: switch
bool ScalableWrapper::eventFilter(QObject* _object, QEvent* _event)
{
bool needShowMenu = false;
QPoint cursorPos = QCursor::pos();
switch (_event->type()) {
case QEvent::ContextMenu: {
QContextMenuEvent* contextMenuEvent = static_cast<QContextMenuEvent*>(_event);
cursorPos = m_editor->viewport()->mapFromGlobal(contextMenuEvent->globalPos());
needShowMenu = true;
break;
}
case QEvent::MouseButtonPress: {
QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(_event);
if (mouseEvent->button() == Qt::RightButton) {
cursorPos = m_editor->viewport()->mapFromGlobal(mouseEvent->globalPos());
needShowMenu = true;
}
break;
}
default: {
break;
}
}
bool result = false;
//
// Если необходимо, то показываем контекстное меню в отдельном прокси элементе,
// предварительно вернув ему 100% масштаб
//
if (needShowMenu) {
QMenu* menu = m_editor->createStandardContextMenu();
QGraphicsProxyWidget* menuProxy = m_editorProxy->createProxyForChildWidget(menu);
const qreal antiZoom = 1. / m_zoomRange;
menuProxy->setScale(antiZoom);
menuProxy->setPos(QCursor::pos());
menu->exec();
delete menu;
//
// Событие перехвачено
//
result = true;
}
//
// Если нет, то стандартная обработка события
//
else {
result = QGraphicsView::eventFilter(_object, _event);
}
return result;
}
示例7: BookmarkInformation
bool AddressWidget::eventFilter(QObject *object, QEvent *event)
{
if (object == m_bookmarkLabel && m_bookmarkLabel && event->type() == QEvent::MouseButtonPress)
{
QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event);
if (mouseEvent && mouseEvent->button() == Qt::LeftButton)
{
if (m_bookmarkLabel->isEnabled())
{
if (BookmarksManager::hasBookmark(getUrl()))
{
BookmarksManager::deleteBookmark(getUrl());
}
else
{
BookmarkInformation *bookmark = new BookmarkInformation();
bookmark->url = getUrl().toString(QUrl::RemovePassword);
bookmark->title = m_window->getTitle();
bookmark->type = UrlBookmark;
BookmarkPropertiesDialog dialog(bookmark, -1, this);
if (dialog.exec() == QDialog::Rejected)
{
delete bookmark;
}
}
updateBookmark();
}
return true;
}
}
if (object && event->type() == QEvent::ContextMenu)
{
QContextMenuEvent *contextMenuEvent = static_cast<QContextMenuEvent*>(event);
if (contextMenuEvent)
{
QMenu menu(this);
QAction *action = menu.addAction(tr("Remove This Icon"), this, SLOT(removeIcon()));
action->setData(object->objectName());
menu.exec(contextMenuEvent->globalPos());
contextMenuEvent->accept();
return true;
}
}
return QLineEdit::eventFilter(object, event);
}
示例8: eventFilter
bool Sidebar::eventFilter(QObject *obj, QEvent *ev)
{
if (ev->type() == QEvent::ContextMenu)
{
QContextMenuEvent *e = (QContextMenuEvent *) ev;
KMultiTabBarTab *bt = dynamic_cast<KMultiTabBarTab*>(obj);
if (bt)
{
//kDebug() << "Request for popup";
m_popupButton = bt->id();
ToolView *w = m_idToWidget[m_popupButton];
if (w)
{
KMenu *p = new KMenu (this);
if (!w->plugin.isNull()) {
Kate::PluginConfigPageInterface* pcpi=dynamic_cast<Kate::PluginConfigPageInterface*>(w->plugin.data());
if (pcpi) {
if (pcpi->configPages()>0)
p->addAction(i18n("Configure ..."))->setData(20);
}
}
p->addTitle(SmallIcon("view_remove"), i18n("Behavior"));
p->addAction(w->persistent ? KIcon("view-restore") : KIcon("view-fullscreen"),
w->persistent ? i18n("Make Non-Persistent") : i18n("Make Persistent") ) -> setData(10);
p->addTitle(SmallIcon("move"), i18n("Move To"));
if (position() != 0)
p->addAction(KIcon("go-previous"), i18n("Left Sidebar"))->setData(0);
if (position() != 1)
p->addAction(KIcon("go-next"), i18n("Right Sidebar"))->setData(1);
if (position() != 2)
p->addAction(KIcon("go-up"), i18n("Top Sidebar"))->setData(2);
if (position() != 3)
p->addAction(KIcon("go-down"), i18n("Bottom Sidebar"))->setData(3);
connect(p, SIGNAL(triggered(QAction*)),
this, SLOT(buttonPopupActivate(QAction*)));
p->exec(e->globalPos());
delete p;
return true;
}
}
}
示例9: switch
bool IndexWindow::eventFilter(QObject *obj, QEvent *e)
{
if (obj == m_searchLineEdit && e->type() == QEvent::KeyPress) {
QKeyEvent *ke = static_cast<QKeyEvent*>(e);
QModelIndex idx = m_indexWidget->currentIndex();
switch (ke->key()) {
case Qt::Key_Up:
idx = m_indexWidget->model()->index(idx.row()-1,
idx.column(), idx.parent());
if (idx.isValid())
m_indexWidget->setCurrentIndex(idx);
break;
case Qt::Key_Down:
idx = m_indexWidget->model()->index(idx.row()+1,
idx.column(), idx.parent());
if (idx.isValid())
m_indexWidget->setCurrentIndex(idx);
break;
case Qt::Key_Escape:
MainWindow::activateCurrentCentralWidgetTab();
break;
default:
;
}
} else if (obj == m_indexWidget && e->type() == QEvent::ContextMenu) {
QContextMenuEvent *ctxtEvent = static_cast<QContextMenuEvent*>(e);
QModelIndex idx = m_indexWidget->indexAt(ctxtEvent->pos());
if (idx.isValid()) {
QMenu menu;
QAction *curTab = menu.addAction(tr("Open Link"));
QAction *newTab = menu.addAction(tr("Open Link in New Tab"));
menu.move(m_indexWidget->mapToGlobal(ctxtEvent->pos()));
QAction *action = menu.exec();
if (curTab == action)
m_indexWidget->activateCurrentItem();
else if (newTab == action) {
QHelpIndexModel *model = qobject_cast<QHelpIndexModel*>(m_indexWidget->model());
QString keyword = model->data(idx, Qt::DisplayRole).toString();
if (model) {
QMap<QString, QUrl> links = model->linksForKeyword(keyword);
if (links.count() == 1) {
CentralWidget::instance()->setSourceInNewTab(links.constBegin().value());
} else {
TopicChooser tc(this, keyword, links);
if (tc.exec() == QDialog::Accepted) {
CentralWidget::instance()->setSourceInNewTab(tc.link());
}
}
}
}
}
}
return QWidget::eventFilter(obj, e);
}
示例10: eventFilter
bool LocationInformationWidget::eventFilter(QObject *, QEvent *ev)
{
if (ev->type() == QEvent::ContextMenu) {
QContextMenuEvent *ctx = (QContextMenuEvent *)ev;
QMenu contextMenu;
contextMenu.addAction(tr("Merge into current site"), this, SLOT(mergeSelectedDiveSites()));
contextMenu.exec(ctx->globalPos());
return true;
}
return false;
}
示例11: switch
PlatformMouseEvent::PlatformMouseEvent(QInputEvent* event, int clickCount)
{
m_timestamp = WTF::currentTime();
QMouseEvent* me = 0;
switch (event->type()) {
case QEvent::MouseMove:
m_eventType = MouseEventMoved;
me = static_cast<QMouseEvent *>(event);
break;
case QEvent::MouseButtonDblClick:
case QEvent::MouseButtonPress:
m_eventType = MouseEventPressed;
me = static_cast<QMouseEvent *>(event);
break;
case QEvent::MouseButtonRelease:
m_eventType = MouseEventReleased;
me = static_cast<QMouseEvent *>(event);
break;
#ifndef QT_NO_CONTEXTMENU
case QEvent::ContextMenu: {
m_eventType = MouseEventPressed;
QContextMenuEvent* ce = static_cast<QContextMenuEvent*>(event);
m_position = IntPoint(ce->pos());
m_globalPosition = IntPoint(ce->globalPos());
m_button = RightButton;
break;
}
#endif // QT_NO_CONTEXTMENU
default:
m_eventType = MouseEventMoved;
}
if (me) {
m_position = IntPoint(me->pos());
m_globalPosition = IntPoint(me->globalPos());
if (me->button() == Qt::LeftButton || (me->buttons() & Qt::LeftButton))
m_button = LeftButton;
else if (me->button() == Qt::RightButton || (me->buttons() & Qt::RightButton))
m_button = RightButton;
else if (me->button() == Qt::MidButton || (me->buttons() & Qt::MidButton))
m_button = MiddleButton;
else
m_button = NoButton;
}
m_clickCount = clickCount;
m_shiftKey = (event->modifiers() & Qt::ShiftModifier);
m_ctrlKey = (event->modifiers() & Qt::ControlModifier);
m_altKey = (event->modifiers() & Qt::AltModifier);
m_metaKey = (event->modifiers() & Qt::MetaModifier);
}
示例12: viewport
bool FrameShadowBase::event(QEvent* e) {
// paintEvents are handled separately
if (e->type() == QEvent::Paint)
return QWidget::event(e);
QWidget* viewport(FrameShadowBase::viewport());
switch (e->type()) {
case QEvent::DragEnter:
case QEvent::DragMove:
case QEvent::DragLeave:
case QEvent::Drop:
if ( viewport ) {
setAcceptDrops(viewport->acceptDrops());
return viewport->QObject::event(e);
}
break;
case QEvent::Enter:
if ( viewport ) {
setCursor(viewport->cursor());
setAcceptDrops(viewport->acceptDrops());
}
break;
case QEvent::ContextMenu:
if ( viewport ) {
QContextMenuEvent* me = static_cast<QContextMenuEvent*>(e);
QContextMenuEvent* ne = new QContextMenuEvent(me->reason(), parentWidget()->mapFromGlobal(me->globalPos()), me->globalPos());
QApplication::sendEvent(viewport, ne);
e->accept();
return true;
}
break;
case QEvent::MouseButtonPress:
releaseMouse();
case QEvent::MouseMove:
case QEvent::MouseButtonRelease:
if ( viewport ) {
QMouseEvent* me = static_cast<QMouseEvent*>(e);
QMouseEvent* ne = new QMouseEvent(e->type(), parentWidget()->mapFromGlobal(me->globalPos()), me->globalPos(), me->button(), me->buttons(), me->modifiers());
QApplication::sendEvent(viewport, ne);
e->accept();
return true;
}
break;
default:
break;
}
e->ignore();
return false;
}
示例13: switch
bool StayPoppedUpComboBox::eventFilter(QObject* o, QEvent* e)
{
// The combo box has installed an event filter on the view.
// If it catches a valid mouse button release there, it will hide the popup.
// Here we prevent this by eating the event ourselves,
// and then dispatching it to its destination.
if (o == m_view || o == m_view->viewport())
{
switch (e->type())
{
case QEvent::MouseButtonRelease:
{
QMouseEvent* m = static_cast<QMouseEvent*>(e);
if (m_view->isVisible() && m_view->rect().contains(m->pos()))
{
if (o == m_view)
{
o->event(e);
}
else
// Viewport: Calling event() does not work, viewportEvent() is needed.
// This is the event that gets redirected to the QTreeView finally!
{
sendViewportEventToView(e);
}
// we have dispatched the event privately; we filter it out from the main dispatching
return true;
}
break;
}
case QEvent::ContextMenu:
{
if (o != m_view)
{
// for whatever reason, the position of the event is slightly wrong
QContextMenuEvent* m = static_cast<QContextMenuEvent*>(e);
QPoint correctPos = m_view->viewport()->mapFromGlobal(m->globalPos());
QContextMenuEvent corrected(m->reason(), correctPos, m->globalPos(), m->modifiers());
sendViewportEventToView(&corrected);
return true;
}
break;
}
default:
break;
}
}
return QComboBox::eventFilter(o, e);
}
示例14: eventFilter
bool LocationInformationWidget::eventFilter(QObject*, QEvent *ev)
{
if( ev->type() == QEvent::ContextMenu ) {
if (ui.diveSiteListView->selectionModel()->selectedIndexes().count() >= 2) {
QContextMenuEvent *ctx = (QContextMenuEvent*) ev;
QMenu contextMenu;
contextMenu.addAction(tr("Merge dive Sites"), this, SLOT(mergeSelectedDiveSites()));
contextMenu.exec(ctx->globalPos());
return true;
}
}
return false;
}
示例15: eventFilter
bool GoBackActionWidget::eventFilter(QObject *object, QEvent *event)
{
if (event->type() == QEvent::ContextMenu)
{
QContextMenuEvent *contextMenuEvent = dynamic_cast<QContextMenuEvent*>(event);
if (contextMenuEvent)
{
QAction *action = menu()->activeAction();
if (action && action->data().type() == QVariant::Int)
{
QMenu contextMenu(menu());
QAction *removeEntryAction = contextMenu.addAction(tr("Remove Entry"), NULL, NULL, QKeySequence(Qt::Key_Delete));
QAction *purgeEntryAction = contextMenu.addAction(tr("Purge Entry"), NULL, NULL, QKeySequence(Qt::ShiftModifier | Qt::Key_Delete));
QAction *selectedAction = contextMenu.exec(contextMenuEvent->globalPos());
if (selectedAction == removeEntryAction)
{
menu()->close();
getWindow()->getContentsWidget()->removeHistoryIndex(action->data().toInt());
}
else if (selectedAction == purgeEntryAction)
{
menu()->close();
getWindow()->getContentsWidget()->removeHistoryIndex(action->data().toInt(), true);
}
}
}
}
else if (event->type() == QEvent::KeyPress)
{
QKeyEvent *keyEvent = dynamic_cast<QKeyEvent*>(event);
if (keyEvent && keyEvent->key() == Qt::Key_Delete && getWindow())
{
QAction *action = menu()->activeAction();
if (action && action->data().type() == QVariant::Int)
{
menu()->close();
getWindow()->getContentsWidget()->removeHistoryIndex(action->data().toInt(), keyEvent->modifiers().testFlag(Qt::ShiftModifier));
}
}
}
return QObject::eventFilter(object, event);
}