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 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); }
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); }
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); }
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; }
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); }
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; } } }
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; }
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); }
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; }
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); }
bool FormSoftUpdate::eventFilter(QObject *watched, QEvent *event) { if(watched==ui->treeWidget) { if(event->type()==QEvent::ContextMenu) { QContextMenuEvent* dee = dynamic_cast<QContextMenuEvent*>(event); QMenu *menu = new QMenu(); menu->addAction(removeCommand); //menu->addAction(renameCommand); menu->exec(dee->globalPos()); delete menu; } } return QWidget::eventFilter(watched, event); }
bool KeySequenceDialog::eventFilter(QObject *o, QEvent *e) { if (o == ui.lineEdit && e->type() == QEvent::ContextMenu) { QContextMenuEvent *c = static_cast<QContextMenuEvent *>(e); QMenu *menu = new QMenu(ui.lineEdit); QAction *clearAction = new QAction(tr("Clear"), menu); menu->addAction(clearAction); 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); }
bool Sidebar::eventFilter(QObject *obj, QEvent *ev) { if (ev->type()==QEvent::ContextMenu) { QContextMenuEvent *e = (QContextMenuEvent *) ev; KMultiTabBarTab *bt = dynamic_cast<KMultiTabBarTab*>(obj); if (bt) { kdDebug()<<"Request for popup"<<endl; m_popupButton = bt->id(); ToolView *w = m_idToWidget[m_popupButton]; if (w) { KPopupMenu *p = new KPopupMenu (this); p->insertTitle(SmallIcon("view_remove"), i18n("Behavior"), 50); p->insertItem(w->persistent ? SmallIconSet("window_nofullscreen") : SmallIconSet("window_fullscreen"), w->persistent ? i18n("Make Non-Persistent") : i18n("Make Persistent"), 10); p->insertTitle(SmallIcon("move"), i18n("Move To"), 51); if (position() != 0) p->insertItem(SmallIconSet("back"), i18n("Left Sidebar"),0); if (position() != 1) p->insertItem(SmallIconSet("forward"), i18n("Right Sidebar"),1); if (position() != 2) p->insertItem(SmallIconSet("up"), i18n("Top Sidebar"),2); if (position() != 3) p->insertItem(SmallIconSet("down"), i18n("Bottom Sidebar"),3); connect(p, SIGNAL(activated(int)), this, SLOT(buttonPopupActivate(int))); p->exec(e->globalPos()); delete p; return true; } } }
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); }
bool OrganizeFavoritesDialog::eventFilter(QObject *o, QEvent *ev) { (void)o; GASSERT(o == ui->listWidget); bool ret = false; if(ev->type() == QEvent::ContextMenu){ QContextMenuEvent *cme = (QContextMenuEvent *)ev; m_contextMenu.move(cme->globalPos()); m_contextMenu.show(); ret = true; } else if(ev->type() == QEvent::KeyPress){ QKeyEvent *ke = (QKeyEvent*)ev; if(ke->key() == Qt::Key_Delete){ _remove_favorite(); } } return ret; }
bool PlayerWidget::eventFilter( QObject * o, QEvent * e ) { if ( o == ui_.sliderPitch && e->type() == QEvent::ContextMenu ) { QContextMenuEvent * ce = static_cast<QContextMenuEvent*>( e ); if ( !audioSource_ ) return true; QMenu menu; QAction * resetPitchAction = menu.addAction( tr( "Reset pitch" ) ); QAction * triggeredAction = menu.exec( ce->globalPos() ); if ( triggeredAction == resetPitchAction ) ui_.sliderPitch->setValue( 0 ); return true; } return QWidget::eventFilter( o, e ); }
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); }
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 EventFilter::eventFilter(QObject *watched, QEvent *event) { Q_UNUSED(watched); AVPlayer *player = static_cast<AVPlayer*>(parent()); if (!player || !player->renderer() || !player->renderer()->widget()) return false; if (qobject_cast<QWidget*>(watched) != player->renderer()->widget()) { return false; } #ifndef QT_NO_DYNAMIC_CAST //dynamic_cast is defined as a macro to force a compile error if (player->renderer() != dynamic_cast<VideoRenderer*>(watched)) { // return false; } #endif QEvent::Type type = event->type(); switch (type) { case QEvent::KeyPress: { QKeyEvent *key_event = static_cast<QKeyEvent*>(event); int key = key_event->key(); Qt::KeyboardModifiers modifiers = key_event->modifiers(); switch (key) { case Qt::Key_C: //capture player->captureVideo(); break; case Qt::Key_N: //check playing? player->playNextFrame(); break; case Qt::Key_P: player->play(); break; case Qt::Key_Q: case Qt::Key_Escape: qApp->quit(); break; case Qt::Key_S: player->stop(); //check playing? break; case Qt::Key_Space: //check playing? qDebug("isPaused = %d", player->isPaused()); player->pause(!player->isPaused()); break; case Qt::Key_F: { //TODO: move to gui QWidget *w = qApp->activeWindow(); if (!w) return false; if (w->isFullScreen()) w->showNormal(); else w->showFullScreen(); } break; case Qt::Key_Up: { AudioOutput *ao = player->audio(); if (modifiers == Qt::ControlModifier) { qreal s = player->speed(); if (s < 1.4) s += 0.02; else s += 0.05; if (qAbs<qreal>(s-1.0) <= 0.01) s = 1.0; player->setSpeed(s); return true; } if (ao && ao->isAvailable()) { qreal v = player->audio()->volume(); if (v > 0.5) v += 0.1; else if (v > 0.1) v += 0.05; else v += 0.025; player->audio()->setVolume(v); qDebug("vol = %.3f", player->audio()->volume()); } } break; case Qt::Key_Down: { AudioOutput *ao = player->audio(); if (modifiers == Qt::ControlModifier) { qreal s = player->speed(); if (s < 1.4) s -= 0.02; else s -= 0.05; if (qAbs<qreal>(s-1.0) <= 0.01) s = 1.0; s = qMax<qreal>(s, 0.0); player->setSpeed(s); return true; } if (ao && ao->isAvailable()) { qreal v = player->audio()->volume(); if (v > 0.5) v -= 0.1; else if (v > 0.1) v -= 0.05; else v -= 0.025; player->audio()->setVolume(v); qDebug("vol = %.3f", player->audio()->volume()); } } break; case Qt::Key_O: { if (modifiers == Qt::ControlModifier) { //TODO: emit a signal so we can use custome dialogs? openLocalFile(); } else/* if (m == Qt::NoModifier) */{ emit showNextOSD(); } } break; case Qt::Key_Left: qDebug("<-"); player->seekBackward(); break; case Qt::Key_Right: qDebug("->"); player->seekForward(); break; case Qt::Key_M: if (player->audio()) { player->audio()->setMute(!player->audio()->isMute()); } break; case Qt::Key_R: { VideoRenderer* renderer = player->renderer(); VideoRenderer::OutAspectRatioMode r = renderer->outAspectRatioMode(); renderer->setOutAspectRatioMode(VideoRenderer::OutAspectRatioMode(((int)r+1)%2)); } break; case Qt::Key_T: { QWidget *w = qApp->activeWindow(); if (!w) return false; Qt::WindowFlags wf = w->windowFlags(); if (wf & Qt::WindowStaysOnTopHint) { qDebug("Window not stays on top"); w->setWindowFlags(wf & ~Qt::WindowStaysOnTopHint); } else { qDebug("Window stays on top"); w->setWindowFlags(wf | Qt::WindowStaysOnTopHint); } //call setParent() when changing the flags, causing the widget to be hidden w->show(); } break; case Qt::Key_F1: help(); break; default: return false; } break; } case QEvent::DragEnter: case QEvent::DragMove: { QDropEvent *e = static_cast<QDropEvent*>(event); e->acceptProposedAction(); } break; case QEvent::Drop: { QDropEvent *e = static_cast<QDropEvent*>(event); QString path = e->mimeData()->urls().first().toLocalFile(); player->stop(); player->load(path); player->play(); e->acceptProposedAction(); } break; case QEvent::GraphicsSceneContextMenu: { QGraphicsSceneContextMenuEvent *e = static_cast<QGraphicsSceneContextMenuEvent*>(event); showMenu(e->screenPos()); } break; case QEvent::ContextMenu: { QContextMenuEvent *e = static_cast<QContextMenuEvent*>(event); showMenu(e->globalPos()); } break; default: return false; } return true; //false: for text input }
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 != this && 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; } } if (object == this && event->type() == QEvent::KeyPress && m_window) { QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event); if (keyEvent->key() == Qt::Key_Escape) { const QUrl url = m_window->getUrl(); if (text().trimmed().isEmpty() || text().trimmed() != url.toString()) { setText((url.scheme() == QLatin1String("about") && m_window->isUrlEmpty()) ? QString() : url.toString()); if (!text().trimmed().isEmpty() && SettingsManager::getValue(QLatin1String("AddressField/SelectAllOnFocus")).toBool()) { QTimer::singleShot(0, this, SLOT(selectAll())); } } else { m_window->setFocus(); } } } return QLineEdit::eventFilter(object, event); }
bool MainWindow::eventFilter(QObject *obj, QEvent *event) { switch(event->type()) { case QEvent::ToolTip: { if (obj != viewer) break; QHelpEvent* e = static_cast<QHelpEvent*>(event); if (attributeRect.contains(e->pos())){ QString attribute = viewer->attribute(); if(!attribute.isEmpty()) ToolTip::showText(e->globalPos(), attribute.prepend("<b>").append("</b>"), false, 0.8); } return true; } case QEvent::MouseButtonDblClick: { if (obj != viewer && obj != bottomFrame) break; QMouseEvent *e = static_cast<QMouseEvent*>(event); if(e->button() & Qt::LeftButton) changeFullScreen(); return true; } case QEvent::ContextMenu: { QContextMenuEvent *e = static_cast<QContextMenuEvent*>(event); showContextMenu(e->globalPos()); return true; } case QEvent::Wheel: { QWheelEvent *e = static_cast<QWheelEvent *>(event); // if (e->delta() < 0) // viewer->nextPic(); // else // viewer->prePic(); qreal factor = 0.1; switch(e->modifiers()){ case Qt::ShiftModifier: factor = e->delta() / qreal(2400); // e->delta() is +120 or -120 break; case Qt::ControlModifier: factor = e->delta() / qreal(600); break; default: factor = e->delta() / qreal(1200); break; } viewer->zoomIn(factor, viewer->mapFromGlobal(e->globalPos())); break; } default: break; } return false; }
bool WindowList::eventFilter(QObject *object, QEvent *event) { if (event->type() == QEvent::ContextMenu) { KMenu *menu = qobject_cast<KMenu*>(object); if (menu && menu->activeAction() && menu->activeAction()->data().type() == QVariant::ULongLong) { QContextMenuEvent *cmEvent = static_cast<QContextMenuEvent *>(event); QList<QAction*> actionList; TaskManager::TaskItem item(this, TaskManager::TaskManager::self()->findTask((WId)menu->activeAction()->data().toULongLong())); TaskManager::GroupManager groupManager(this); TaskManager::BasicMenu taskMenu(NULL, &item, &groupManager, actionList); if (taskMenu.exec(cmEvent->globalPos())) { m_listMenu->hide(); } return true; } } else if (event->type() == QEvent::MouseButtonPress) { QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event); if (mouseEvent->button() != Qt::LeftButton) { return false; } KMenu *menu = static_cast<KMenu*>(object); if (menu && menu->activeAction() && menu->activeAction()->data().type() == QVariant::ULongLong) { m_dragStartPosition = mouseEvent->pos(); } } else if (event->type() == QEvent::MouseMove) { QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event); if (!(mouseEvent->buttons() & Qt::LeftButton) || (mouseEvent->pos() - m_dragStartPosition).manhattanLength() < QApplication::startDragDistance()) { return false; } KMenu *menu = static_cast<KMenu*>(object); if (menu && menu->activeAction() && menu->activeAction()->data().type() == QVariant::ULongLong) { QDrag *drag = new QDrag(menu); QMimeData *mimeData = new QMimeData; QByteArray data; WId window = (WId)menu->activeAction()->data().toULongLong(); data.resize(sizeof(WId)); memcpy(data.data(), &window, sizeof(WId)); mimeData->setData("windowsystem/winid", data); drag->setMimeData(mimeData); drag->setPixmap(menu->activeAction()->icon().pixmap(32, 32)); m_listMenu->hide(); drag->exec(); return true; } } return QObject::eventFilter(object, 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 ItemDelegate::eventFilter(QObject *object, QEvent *event) { if (object->objectName() == "editor") { QPlainTextEdit *editor = qobject_cast<QPlainTextEdit*>(object); if (editor == NULL) return false; QEvent::Type type = event->type(); if ( type == QEvent::KeyPress ) { QKeyEvent *keyevent = static_cast<QKeyEvent *>(event); switch ( keyevent->key() ) { case Qt::Key_Enter: case Qt::Key_Return: // Commit data on Ctrl+Return or Enter? if (m_saveOnReturnKey) { if (keyevent->modifiers() == Qt::ControlModifier) { editor->insertPlainText("\n"); return true; } else if (keyevent->modifiers() != Qt::NoModifier) { return false; } } else { if (keyevent->modifiers() != Qt::ControlModifier) return false; } emit commitData(editor); emit closeEditor(editor); return true; case Qt::Key_S: // Commit data on Ctrl+S. if (keyevent->modifiers() != Qt::ControlModifier) return false; emit commitData(editor); emit closeEditor(editor); return true; case Qt::Key_F2: // Commit data on F2. emit commitData(editor); emit closeEditor(editor); return true; case Qt::Key_Escape: // Close editor without committing data. emit closeEditor(editor, QAbstractItemDelegate::RevertModelCache); return true; default: return false; } } else if ( type == QEvent::ContextMenu ) { QAction *act; QMenu *menu = editor->createStandardContextMenu(); connect( menu, SIGNAL(aboutToHide()), menu, SLOT(deleteLater()) ); menu->setParent(editor); act = menu->addAction( tr("&Save Item") ); act->setShortcut( QKeySequence(tr("F2, Ctrl+Enter")) ); connect( act, SIGNAL(triggered()), this, SLOT(editorSave()) ); act = menu->addAction( tr("Cancel Editing") ); act->setShortcut( QKeySequence(tr("Escape")) ); connect( act, SIGNAL(triggered()), this, SLOT(editorCancel()) ); QContextMenuEvent *menuEvent = static_cast<QContextMenuEvent *>(event); menu->popup( menuEvent->globalPos() ); } } else { // resize event for items if (event->type() == QEvent::Resize) { QResizeEvent *resize = static_cast<QResizeEvent *>(event); ItemWidget *item = dynamic_cast<ItemWidget *>(object); if (item != NULL) { item->widget()->resize(resize->size()); onItemChanged(item); return true; } } } return false; }
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); }
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; } else if (button == NoButton) { QToolTip::showText(he->globalPos(), index.data().toString(), this, visualRect(index)); he->accept(); return true; } break; } case QEvent::ContextMenu: { QContextMenuEvent *ce = static_cast<QContextMenuEvent*>(event); const QModelIndex index = indexAt(ce->pos()); WebTab *tab = index.data(TabModel::WebTabRole).value<WebTab*>(); const int tabIndex = tab ? tab->tabIndex() : -1; TabContextMenu::Options options = TabContextMenu::VerticalTabs | TabContextMenu::ShowDetachTabAction; if (m_tabsInOrder) { options |= TabContextMenu::ShowCloseOtherTabsActions; } TabContextMenu menu(tabIndex, m_window, options); addMenuActions(&menu, index); menu.exec(ce->globalPos()); break; } default: break; } return QTreeView::viewportEvent(event); }
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); popupMenu->insertAction(firstAction, checkSpellingAction); popupMenu->insertSeparator(firstAction); // Show menu connect(popupMenu, SIGNAL(triggered(QAction*)), this, SLOT(suggestSpelling(QAction*))); popupMenu->exec(contextEvent->globalPos()); delete popupMenu; for (int i = 0; i < spellingActions.size(); i++) { delete spellingActions[i]; } spellingActions.clear(); return true; } }