Example #1
0
bool MainWindow::eventFilter(QObject *object, QEvent *event)
{
	if (event->type() == QEvent::KeyPress && isFullScreen())
	{
		QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);

		if (keyEvent->key() == Qt::Key_Escape)
		{
			actionFullScreen();
		}
	}

	return QMainWindow::eventFilter(object, event);
}
Example #2
0
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);
}