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); }
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; }
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); }
bool GoBackActionWidget::event(QEvent *event) { if (event->type() == QEvent::MouseButtonPress || event->type() == QEvent::MouseButtonDblClick || event->type() == QEvent::Wheel) { QList<GesturesManager::GesturesContext> contexts; contexts << GesturesManager::ToolBarGesturesContext << GesturesManager::GenericGesturesContext; if (GesturesManager::startGesture(this, event, contexts)) { return true; } } if (event->type() == QEvent::ContextMenu) { QContextMenuEvent *contextMenuEvent = static_cast<QContextMenuEvent*>(event); if (contextMenuEvent) { if (contextMenuEvent->reason() == QContextMenuEvent::Mouse) { contextMenuEvent->accept(); return true; } event->accept(); Window *window = getWindow(); QMenu menu(this); menu.addAction(window ? window->getContentsWidget()->getAction(ActionsManager::ClearTabHistoryAction) : ActionsManager::getAction(ActionsManager::ClearTabHistoryAction, this)); menu.addAction(window ? window->getContentsWidget()->getAction(ActionsManager::PurgeTabHistoryAction) : ActionsManager::getAction(ActionsManager::PurgeTabHistoryAction, this)); ToolBarWidget *toolBar = qobject_cast<ToolBarWidget*>(parentWidget()); if (toolBar) { menu.addSeparator(); menu.addActions(ToolBarWidget::createCustomizationMenu(toolBar->getIdentifier(), QList<QAction*>(), &menu)->actions()); } menu.exec(contextMenuEvent->globalPos()); return true; } return false; } if (event->type() == QEvent::ToolTip) { QHelpEvent *helpEvent = dynamic_cast<QHelpEvent*>(event); if (helpEvent) { const QVector<QKeySequence> shortcuts = ActionsManager::getActionDefinition(ActionsManager::GoBackAction).shortcuts; QString toolTip = text() + (shortcuts.isEmpty() ? QString() : QLatin1String(" (") + shortcuts.at(0).toString(QKeySequence::NativeText) + QLatin1Char(')')); if (getWindow()) { const WindowHistoryInformation history = getWindow()->getContentsWidget()->getHistory(); if (!history.entries.isEmpty() && history.index > 0) { QString title = history.entries.at(history.index - 1).title; title = (title.isEmpty() ? tr("(Untitled)") : title.replace(QLatin1Char('&'), QLatin1String("&&"))); toolTip = title + QLatin1String(" (") + text() + (shortcuts.isEmpty() ? QString() : QLatin1String(" - ") + shortcuts.at(0).toString(QKeySequence::NativeText)) + QLatin1Char(')'); } } QToolTip::showText(helpEvent->globalPos(), toolTip); } return true; } return ActionWidget::event(event); }
bool KrTreeWidget::event(QEvent * event) { switch (event->type()) { // HACK: QT 4 Context menu key isn't handled properly case QEvent::ContextMenu: { QContextMenuEvent* ce = (QContextMenuEvent*) event; if (ce->reason() == QContextMenuEvent::Mouse) { QPoint pos = viewport()->mapFromGlobal(ce->globalPos()); QTreeWidgetItem * item = itemAt(pos); int column = columnAt(pos.x()); emit itemRightClicked(item, ce->globalPos(), column); return true; } else { if (currentItem()) { QRect r = visualItemRect(currentItem()); QPoint p = viewport()->mapToGlobal(QPoint(r.x() + 5, r.y() + 5)); emit itemRightClicked(currentItem(), p, currentColumn()); return true; } } } break; case QEvent::KeyPress: { // HACK: QT 4 Ctrl+A bug fix: Ctrl+A doesn't work if QTreeWidget contains parent / child items // Insert doesn't change the selections for multi selection modes QKeyEvent* ke = (QKeyEvent*) event; switch (ke->key()) { case Qt::Key_Insert: { if (ke->modifiers() != 0) break; QAbstractItemView::SelectionMode mode = selectionMode(); if (mode != QAbstractItemView::ContiguousSelection && mode != QAbstractItemView::ExtendedSelection && mode != QAbstractItemView::MultiSelection) break; ke->accept(); if (currentItem() == 0) return true; currentItem()->setSelected(!currentItem()->isSelected()); return true; } case Qt::Key_A: if (ke->modifiers() == Qt::ControlModifier) { QAbstractItemView::SelectionMode mode = selectionMode(); if (mode == QAbstractItemView::ContiguousSelection || mode == QAbstractItemView::ExtendedSelection || mode == QAbstractItemView::MultiSelection) { selectAll(); ke->accept(); return true; } } break; default: break; } } break; case QEvent::Resize: { QResizeEvent * re = (QResizeEvent *)event; if (!_inResize && re->oldSize() != re->size()) { if (_stretchingColumn != -1 && columnCount()) { QList< int > columnsSizes; int oldSize = 0; for (int i = 0; i != header()->count(); i++) { columnsSizes.append(header()->sectionSize(i)); oldSize += header()->sectionSize(i); } bool res = QTreeWidget::event(event); int newSize = viewport()->width(); int delta = newSize - oldSize; if (delta) { _inResize = true; for (int i = 0; i != header()->count(); i++) { if (i == _stretchingColumn) { int newNs = columnsSizes[ i ] + delta; if (newNs < 8) newNs = 8; header()->resizeSection(i, newNs); } else if (header()->sectionSize(i) != columnsSizes[ i ]) { header()->resizeSection(i, columnsSizes[ i ]); } } _inResize = false; } return res; } } break; } case QEvent::ToolTip: { QHelpEvent *he = static_cast<QHelpEvent*>(event); if (viewport()) { QPoint pos = viewport()->mapFromGlobal(he->globalPos()); QTreeWidgetItem * item = itemAt(pos); int column = columnAt(pos.x()); if (item) { if (!item->toolTip(column).isEmpty()) break; QString tip = item->text(column); int textMargin = QApplication::style()->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1; int requiredWidth = QFontMetrics(font()).width(tip) + 2 * textMargin; if (column == 0 && indentation()) { int level = 0; QTreeWidgetItem *parent = item; while ((parent = parent->parent())) level++; if (rootIsDecorated()) level++; requiredWidth += level * indentation(); } QIcon icon = item->icon(column); if (!icon.isNull()) { QStyleOptionViewItem opts = viewOptions(); QSize iconSize = icon.actualSize(opts.decorationSize); requiredWidth += iconSize.width(); int pixmapMargin = QApplication::style()->pixelMetric(QStyle::PM_FocusFrameHMargin, 0, this) + 1; requiredWidth += 2 * pixmapMargin; } if (!tip.isEmpty() && (columnWidth(column) < requiredWidth)) QToolTip::showText(he->globalPos(), tip, this); return true; } } } break; default: break; } return QTreeWidget::event(event); }