本文整理汇总了C++中QContextMenuEvent::pos方法的典型用法代码示例。如果您正苦于以下问题:C++ QContextMenuEvent::pos方法的具体用法?C++ QContextMenuEvent::pos怎么用?C++ QContextMenuEvent::pos使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QContextMenuEvent
的用法示例。
在下文中一共展示了QContextMenuEvent::pos方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: eventFilter
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);
}
示例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 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);
}
示例4: 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 );
}
示例5: if
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);
}
示例6: event
bool SessionListWidget::event(QEvent *event)
{
#ifndef QUTIM_MOBILE_UI
if (event->type() == QEvent::ToolTip) {
if (QHelpEvent *help = static_cast<QHelpEvent*>(event)) {
int index = indexAt(help->pos()).row();
if (index != -1) {
ChatUnit *unit = session(index)->getUnit();
ToolTip::instance()->showText(help->globalPos(), unit, this);
return true;
}
}
} else if (event->type() == QEvent::DragEnter) {
QDragEnterEvent *dragEvent = static_cast<QDragEnterEvent*>(event);
if (const MimeObjectData *data = qobject_cast<const MimeObjectData*>(dragEvent->mimeData())) {
ChatUnit *u = qobject_cast<ChatUnit*>(data->object());
if (u)
dragEvent->acceptProposedAction();
}
return true;
} else if (event->type() == QEvent::Drop) {
QDropEvent *dropEvent = static_cast<QDropEvent*>(event);
if (const MimeObjectData *mimeData
= qobject_cast<const MimeObjectData*>(dropEvent->mimeData())) {
if (ChatUnit *u = qobject_cast<ChatUnit*>(mimeData->object())) {
ChatLayerImpl::get(u,true)->activate();
dropEvent->setDropAction(Qt::CopyAction);
dropEvent->accept();
return true;
}
}
} else
#endif
if (event->type() == QEvent::ContextMenu) {
QContextMenuEvent *ev = static_cast<QContextMenuEvent*>(event);
ChatSessionImpl *s = session(row(itemAt(ev->pos())));
if(s) {
s->unit()->showMenu(ev->globalPos());
return true;
}
}
return QListWidget::event(event);
}
示例7: eventFilter
bool MainWindow::eventFilter(QObject *object, QEvent *event)
{
if (event->type() == QEvent::ContextMenu && object->objectName().contains(QLatin1String("bookmarks"), Qt::CaseInsensitive))
{
QContextMenuEvent *contextMenuEvent = static_cast<QContextMenuEvent*>(event);
QMenu *menu = qobject_cast<QMenu*>(object);
if (contextMenuEvent && menu)
{
QAction *action = menu->actionAt(contextMenuEvent->pos());
if (action && action->data().type() == QVariant::String)
{
m_currentBookmark = action->data().toString();
QMenu contextMenu(this);
contextMenu.addAction(Utils::getIcon(QLatin1String("document-open")), tr("Open"), this, SLOT(openBookmark()));
contextMenu.addAction(tr("Open in New Tab"), this, SLOT(openBookmark()))->setData(NewTabOpen);
contextMenu.addAction(tr("Open in New Background Tab"), this, SLOT(openBookmark()))->setData(NewTabBackgroundOpen);
contextMenu.addSeparator();
contextMenu.addAction(tr("Open in New Window"), this, SLOT(openBookmark()))->setData(NewWindowOpen);
contextMenu.addAction(tr("Open in New Background Window"), this, SLOT(openBookmark()))->setData(NewWindowBackgroundOpen);
contextMenu.exec(contextMenuEvent->globalPos());
return true;
}
}
}
if (event->type() == QEvent::KeyPress && isFullScreen())
{
QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
if (keyEvent->key() == Qt::Key_Escape)
{
actionFullScreen();
}
}
return QMainWindow::eventFilter(object, event);
}
示例8: event
/*! \reimp */
bool QToolBar::event(QEvent *event)
{
Q_D(QToolBar);
switch (event->type()) {
case QEvent::Timer:
if (d->waitForPopupTimer.timerId() == static_cast<QTimerEvent*>(event)->timerId()) {
QWidget *w = QApplication::activePopupWidget();
if (!waitForPopup(this, w)) {
d->waitForPopupTimer.stop();
if (!this->underMouse())
d->layout->setExpanded(false);
}
}
break;
case QEvent::Hide:
if (!isHidden())
break;
// fallthrough intended
case QEvent::Show:
d->toggleViewAction->setChecked(event->type() == QEvent::Show);
emit visibilityChanged(event->type() == QEvent::Show);
#if defined(Q_WS_MAC)
if (toolbarInUnifiedToolBar(this)) {
// I can static_cast because I did the qobject_cast in the if above, therefore
// we must have a QMainWindowLayout here.
QMainWindowLayout *mwLayout = static_cast<QMainWindowLayout *>(parentWidget()->layout());
mwLayout->fixSizeInUnifiedToolbar(this);
mwLayout->syncUnifiedToolbarVisibility();
}
# if !defined(QT_MAC_USE_COCOA)
// Fall through
case QEvent::LayoutRequest: {
// There's currently no way to invalidate the size and let
// HIToolbar know about it. This forces a re-check.
int earlyResult = -1;
if (QMainWindow *mainWindow = qobject_cast<QMainWindow *>(parentWidget())) {
bool needUpdate = true;
if (event->type() == QEvent::LayoutRequest) {
QSize oldSizeHint = sizeHint();
earlyResult = QWidget::event(event) ? 1 : 0;
needUpdate = oldSizeHint != sizeHint();
}
if (needUpdate) {
OSWindowRef windowRef = qt_mac_window_for(mainWindow);
if (toolbarInUnifiedToolBar(this)
&& macWindowToolbarIsVisible(windowRef)) {
DisableScreenUpdates();
macWindowToolbarShow(this, false);
macWindowToolbarShow(this, true);
EnableScreenUpdates();
}
}
if (earlyResult != -1)
return earlyResult;
}
}
# endif // !QT_MAC_USE_COCOA
#endif // Q_WS_MAC
break;
case QEvent::ParentChange:
d->layout->checkUsePopupMenu();
#if defined(Q_WS_MAC)
if (parentWidget() && parentWidget()->isWindow())
qt_mac_updateToolBarButtonHint(parentWidget());
#endif
break;
case QEvent::MouseButtonPress: {
if (d->mousePressEvent(static_cast<QMouseEvent*>(event)))
return true;
break;
}
case QEvent::MouseButtonRelease:
if (d->mouseReleaseEvent(static_cast<QMouseEvent*>(event)))
return true;
break;
case QEvent::HoverEnter:
case QEvent::HoverLeave:
// there's nothing special to do here and we don't want to update the whole widget
return true;
case QEvent::HoverMove: {
#ifndef QT_NO_CURSOR
QHoverEvent *e = static_cast<QHoverEvent*>(event);
QStyleOptionToolBar opt;
initStyleOption(&opt);
if (style()->subElementRect(QStyle::SE_ToolBarHandle, &opt, this).contains(e->pos()))
setCursor(Qt::SizeAllCursor);
else
unsetCursor();
#endif
break;
}
case QEvent::MouseMove:
if (d->mouseMoveEvent(static_cast<QMouseEvent*>(event)))
return true;
break;
//.........这里部分代码省略.........
示例9: event
/*! \reimp */
bool QToolBar::event(QEvent *event)
{
Q_D(QToolBar);
switch (event->type()) {
case QEvent::Timer:
if (d->waitForPopupTimer.timerId() == static_cast<QTimerEvent*>(event)->timerId()) {
QWidget *w = QApplication::activePopupWidget();
if (!waitForPopup(this, w)) {
d->waitForPopupTimer.stop();
if (!this->underMouse())
d->layout->setExpanded(false);
}
}
break;
case QEvent::Hide:
if (!isHidden())
break;
// fallthrough intended
case QEvent::Show:
d->toggleViewAction->setChecked(event->type() == QEvent::Show);
#ifdef Q_OS_OSX
enableMacToolBar(this, event->type() == QEvent::Show);
#endif
emit visibilityChanged(event->type() == QEvent::Show);
break;
case QEvent::ParentChange:
d->layout->checkUsePopupMenu();
break;
case QEvent::MouseButtonPress: {
if (d->mousePressEvent(static_cast<QMouseEvent*>(event)))
return true;
break;
}
case QEvent::MouseButtonRelease:
if (d->mouseReleaseEvent(static_cast<QMouseEvent*>(event)))
return true;
break;
case QEvent::HoverEnter:
case QEvent::HoverLeave:
// there's nothing special to do here and we don't want to update the whole widget
return true;
case QEvent::HoverMove: {
#ifndef QT_NO_CURSOR
QHoverEvent *e = static_cast<QHoverEvent*>(event);
QStyleOptionToolBar opt;
initStyleOption(&opt);
if (style()->subElementRect(QStyle::SE_ToolBarHandle, &opt, this).contains(e->pos()))
setCursor(Qt::SizeAllCursor);
else
unsetCursor();
#endif
break;
}
case QEvent::MouseMove:
if (d->mouseMoveEvent(static_cast<QMouseEvent*>(event)))
return true;
break;
#ifdef Q_OS_WINCE
case QEvent::ContextMenu:
{
QContextMenuEvent* contextMenuEvent = static_cast<QContextMenuEvent*>(event);
QWidget* child = childAt(contextMenuEvent->pos());
QAbstractButton* button = qobject_cast<QAbstractButton*>(child);
if (button)
button->setDown(false);
}
break;
#endif
case QEvent::Leave:
if (d->state != 0 && d->state->dragging) {
#ifdef Q_OS_WIN
// This is a workaround for loosing the mouse on Vista.
QPoint pos = QCursor::pos();
QMouseEvent fake(QEvent::MouseMove, mapFromGlobal(pos), pos, Qt::NoButton,
QApplication::mouseButtons(), QApplication::keyboardModifiers());
d->mouseMoveEvent(&fake);
#endif
} else {
if (!d->layout->expanded)
break;
QWidget *w = QApplication::activePopupWidget();
if (waitForPopup(this, w)) {
d->waitForPopupTimer.start(POPUP_TIMER_INTERVAL, this);
break;
}
d->waitForPopupTimer.stop();
d->layout->setExpanded(false);
break;
}
default:
break;
}
return QWidget::event(event);
}
示例10: eventFilter
bool MarkdownEditor::eventFilter(QObject* watched, QEvent* event)
{
if (event->type() == QEvent::MouseButtonPress)
{
mouseButtonDown = true;
}
else if (event->type() == QEvent::MouseButtonRelease)
{
mouseButtonDown = false;
}
else if (event->type() == QEvent::MouseButtonDblClick)
{
mouseButtonDown = true;
}
if (event->type() != QEvent::ContextMenu || !spellCheckEnabled || this->isReadOnly())
{
return QPlainTextEdit::eventFilter(watched, event);
}
else
{
// Check spelling of text block under mouse
QContextMenuEvent* contextEvent = static_cast<QContextMenuEvent*>(event);
cursorForWord = cursorForPosition(contextEvent->pos());
QTextCharFormat::UnderlineStyle spellingErrorUnderlineStyle =
(QTextCharFormat::UnderlineStyle)
QApplication::style()->styleHint
(
QStyle::SH_SpellCheckUnderlineStyle
);
// Get the formatting for the cursor position under the mouse,
// and see if it has the spell check error underline style.
//
bool wordHasSpellingError = false;
int blockPosition = cursorForWord.positionInBlock();
QList<QTextLayout::FormatRange> formatList =
textCursor().block().layout()->additionalFormats();
int mispelledWordStartPos = 0;
int mispelledWordLength = 0;
for (int i = 0; i < formatList.length(); i++)
{
QTextLayout::FormatRange formatRange = formatList[i];
if
(
(blockPosition >= formatRange.start)
&& (blockPosition <= (formatRange.start + formatRange.length))
&& (formatRange.format.underlineStyle() == spellingErrorUnderlineStyle)
)
{
mispelledWordStartPos = formatRange.start;
mispelledWordLength = formatRange.length;
wordHasSpellingError = true;
break;
}
}
// The word under the mouse is spelled correctly, so use the default
// processing for the context menu and return.
//
if (!wordHasSpellingError)
{
return QPlainTextEdit::eventFilter(watched, event);
}
// Select the misspelled word.
cursorForWord.movePosition(QTextCursor::PreviousCharacter, QTextCursor::MoveAnchor, blockPosition - mispelledWordStartPos);
cursorForWord.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor, mispelledWordLength);
wordUnderMouse = cursorForWord.selectedText();
QStringList suggestions = dictionary.suggestions(wordUnderMouse);
QMenu* popupMenu = createStandardContextMenu();
QAction* firstAction = popupMenu->actions().first();
spellingActions.clear();
if (!suggestions.empty())
{
for (int i = 0; i < suggestions.size(); i++)
{
QAction* suggestionAction = new QAction(suggestions[i], this);
spellingActions.append(suggestionAction);
popupMenu->insertAction(firstAction, suggestionAction);
}
}
else
{
QAction* noSuggestionsAction =
new QAction(tr("No spelling suggestions found"), this);
noSuggestionsAction->setEnabled(false);
spellingActions.append(noSuggestionsAction);
popupMenu->insertAction(firstAction, noSuggestionsAction);
}
popupMenu->insertSeparator(firstAction);
popupMenu->insertAction(firstAction, addWordToDictionaryAction);
popupMenu->insertSeparator(firstAction);
//.........这里部分代码省略.........
示例11: eventFilter
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;
default: ; // stop complaining
}
} else if (obj == m_searchLineEdit
&& e->type() == QEvent::FocusIn
&& static_cast<QFocusEvent *>(e)->reason() != Qt::MouseFocusReason) {
m_searchLineEdit->selectAll();
m_searchLineEdit->setFocus();
} 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 as New Page"));
menu.move(m_indexWidget->mapToGlobal(ctxtEvent->pos()));
QAction *action = menu.exec();
if (curTab == action)
m_indexWidget->activateCurrentItem();
else if (newTab == action) {
open(m_indexWidget, idx);
}
}
} else if (m_indexWidget && obj == m_indexWidget->viewport()
&& e->type() == QEvent::MouseButtonRelease) {
QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(e);
QModelIndex idx = m_indexWidget->indexAt(mouseEvent->pos());
if (idx.isValid()) {
Qt::MouseButtons button = mouseEvent->button();
if (((button == Qt::LeftButton) && (mouseEvent->modifiers() & Qt::ControlModifier))
|| (button == Qt::MidButton)) {
open(m_indexWidget, idx);
}
}
}
else if (Utils::HostOsInfo::isMacHost() && obj == m_indexWidget
&& e->type() == QEvent::KeyPress) {
QKeyEvent *ke = static_cast<QKeyEvent*>(e);
if (ke->key() == Qt::Key_Return || ke->key() == Qt::Key_Enter)
m_indexWidget->activateCurrentItem();
}
return QWidget::eventFilter(obj, e);
}
示例12: viewportEvent
bool TabTreeView::viewportEvent(QEvent *event)
{
switch (event->type()) {
case QEvent::MouseButtonPress: {
QMouseEvent *me = static_cast<QMouseEvent*>(event);
const QModelIndex index = indexAt(me->pos());
updateIndex(index);
WebTab *tab = index.data(TabModel::WebTabRole).value<WebTab*>();
if (me->buttons() == Qt::MiddleButton && tab) {
tab->closeTab();
}
if (me->buttons() != Qt::LeftButton) {
m_pressedIndex = QModelIndex();
m_pressedButton = NoButton;
break;
}
m_pressedIndex = index;
m_pressedButton = buttonAt(me->pos(), m_pressedIndex);
if (m_pressedIndex.isValid()) {
if (m_pressedButton == ExpandButton) {
if (isExpanded(m_pressedIndex)) {
collapse(m_pressedIndex);
} else {
expand(m_pressedIndex);
}
} else if (m_pressedButton == NoButton && tab) {
tab->makeCurrentTab();
}
}
if (m_pressedButton == CloseButton) {
me->accept();
return true;
}
break;
}
case QEvent::MouseMove: {
QMouseEvent *me = static_cast<QMouseEvent*>(event);
if (m_pressedButton == CloseButton) {
me->accept();
return true;
}
break;
}
case QEvent::MouseButtonRelease: {
QMouseEvent *me = static_cast<QMouseEvent*>(event);
if (me->buttons() != Qt::NoButton) {
break;
}
const QModelIndex index = indexAt(me->pos());
updateIndex(index);
if (m_pressedIndex != index) {
break;
}
DelegateButton button = buttonAt(me->pos(), index);
if (m_pressedButton == button) {
if (m_pressedButton == ExpandButton) {
me->accept();
return true;
}
WebTab *tab = index.data(TabModel::WebTabRole).value<WebTab*>();
if (tab) {
if (m_pressedButton == CloseButton) {
tab->closeTab();
} else if (m_pressedButton == AudioButton) {
tab->toggleMuted();
}
}
}
if (m_pressedButton == CloseButton) {
me->accept();
return true;
}
break;
}
case QEvent::HoverEnter:
case QEvent::HoverLeave:
case QEvent::HoverMove: {
QHoverEvent *he = static_cast<QHoverEvent*>(event);
updateIndex(m_hoveredIndex);
m_hoveredIndex = indexAt(he->pos());
updateIndex(m_hoveredIndex);
break;
}
case QEvent::ToolTip: {
QHelpEvent *he = static_cast<QHelpEvent*>(event);
const QModelIndex index = indexAt(he->pos());
DelegateButton button = buttonAt(he->pos(), index);
if (button == AudioButton) {
const bool muted = index.data(TabModel::AudioMutedRole).toBool();
QToolTip::showText(he->globalPos(), muted ? tr("Unmute Tab") : tr("Mute Tab"), this, visualRect(index));
he->accept();
return true;
} else if (button == CloseButton) {
QToolTip::showText(he->globalPos(), tr("Close Tab"), this, visualRect(index));
he->accept();
return true;
//.........这里部分代码省略.........
示例13: eventFilter
bool HelpIndexView::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);
return true;
}
break;
case Qt::Key_Down:
idx = m_IndexWidget->model()->index(idx.row()+1,
idx.column(), idx.parent());
if (idx.isValid())
{
m_IndexWidget->setCurrentIndex(idx);
return true;
}
break;
default: ; // stop complaining
}
}
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)
{
open(m_IndexWidget, idx);
}
}
}
else if (m_IndexWidget && obj == m_IndexWidget->viewport()
&& e->type() == QEvent::MouseButtonRelease)
{
QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(e);
QModelIndex idx = m_IndexWidget->indexAt(mouseEvent->pos());
if (idx.isValid())
{
Qt::MouseButtons button = mouseEvent->button();
if (((button == Qt::LeftButton) && (mouseEvent->modifiers() & Qt::ControlModifier))
|| (button == Qt::MidButton))
{
open(m_IndexWidget, idx);
}
}
}
#ifdef Q_OS_MAC
else if (obj == m_IndexWidget && e->type() == QEvent::KeyPress)
{
QKeyEvent *ke = static_cast<QKeyEvent*>(e);
if (ke->key() == Qt::Key_Return || ke->key() == Qt::Key_Enter)
m_IndexWidget->activateCurrentItem();
}
#endif
return QObject::eventFilter(obj, e);
}