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);
}
Exemplo n.º 2
0
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);
}
Exemplo n.º 3
0
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);
}
Exemplo n.º 4
0
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);
}
Exemplo n.º 5
0
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 );
}
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;
}
Exemplo n.º 7
0
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);
}
Exemplo n.º 8
0
  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 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);
}
Exemplo n.º 10
0
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;
}
Exemplo n.º 11
0
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);
}
Exemplo n.º 12
0
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;
      }
Exemplo n.º 13
0
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);
}
Exemplo n.º 14
0
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);
}
Exemplo n.º 16
0
  VisualNode*
  TreeCanvas::eventNode(QEvent* event) {
    int x = 0;
    int y = 0;
    switch (event->type()) {
    case QEvent::ToolTip:
        {
          QHelpEvent* he = static_cast<QHelpEvent*>(event);
          x = he->x();
          y = he->y();
          break;
        }
    case QEvent::MouseButtonDblClick:
    case QEvent::MouseButtonPress:
    case QEvent::MouseButtonRelease:
    case QEvent::MouseMove:
        {
          QMouseEvent* me = static_cast<QMouseEvent*>(event);
          x = me->x();
          y = me->y();
          break;
        }
    case QEvent::ContextMenu:
        {
          QContextMenuEvent* ce = static_cast<QContextMenuEvent*>(event);
          x = ce->x();
          y = ce->y();
          break;
        }
    default:
      return NULL;
    }
    QAbstractScrollArea* sa =
      static_cast<QAbstractScrollArea*>(parentWidget()->parentWidget());
    int xoff = sa->horizontalScrollBar()->value()/scale;
    int yoff = sa->verticalScrollBar()->value()/scale;

    BoundingBox bb = root->getBoundingBox();
    int w =
      static_cast<int>((bb.right-bb.left+Layout::extent)*scale);
    if (w < sa->viewport()->width())
      xoff -= (sa->viewport()->width()-w)/2;
    
    VisualNode* n;
    n = root->findNode(*na,
                       static_cast<int>(x/scale-xtrans+xoff),
                       static_cast<int>((y-30)/scale+yoff));
    return n;
  }
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);
}
Exemplo n.º 18
0
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);
}
Exemplo n.º 19
0
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;
      }
    }
  }
Exemplo n.º 20
0
/**
 * Make the left button also show the context menu to make things
 * simpler for users with single mouse button mice (laptops++).
 */
void QIStateIndicator::mousePressEvent (QMouseEvent *aEv)
{
    /* Do this for the left mouse button event only, cause in the case of the
     * right mouse button it could happen that the context menu event is
     * triggered twice. Also this isn't necessary for the middle mouse button
     * which would be some kind of overstated. */
    if (aEv->button() == Qt::LeftButton)
    {
        QContextMenuEvent qme (QContextMenuEvent::Mouse, aEv->pos(), aEv->globalPos());
        emit contextMenuRequested (this, &qme);
        if (qme.isAccepted())
            aEv->accept();
        else
            QFrame::mousePressEvent (aEv);
    }
    else
        QFrame::mousePressEvent (aEv);
}
Exemplo n.º 21
0
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);
}
Exemplo n.º 22
0
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;
}
Exemplo n.º 23
0
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 );
}
Exemplo n.º 24
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);
}
/*! \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;
#ifdef Q_WS_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);
}
Exemplo n.º 26
0
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;
}
Exemplo n.º 27
0
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
}
Exemplo n.º 28
0
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 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);
}
Exemplo n.º 30
0
/*! \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);
}