예제 #1
0
bool ClipboardServer::eventFilter(QObject *object, QEvent *ev)
{
    const QEvent::Type type = ev->type();

    if ( type == QEvent::KeyPress
         || type == QEvent::Shortcut
         || type == QEvent::ShortcutOverride )
    {
        if ( m_ignoreKeysTimer.isActive() ) {
            ev->accept();
            return true;
        }

        m_wnd->updateShortcuts();

        // Close menu on Escape key and give focus back to search edit or browser.
        if (type == QEvent::KeyPress) {
            QKeyEvent *keyevent = static_cast<QKeyEvent *>(ev);
            QMenu *menu = qobject_cast<QMenu*>(object);
            if (menu && keyevent->key() == Qt::Key_Escape) {
                menu->close();
                if (m_wnd->browseMode())
                    m_wnd->enterBrowseMode();
                else
                    m_wnd->enterSearchMode();
            }
        }
    } else if (type == QEvent::Paint) {
        setActivePaintDevice(object);
    }

    return false;
}
예제 #2
0
void Menu::closeAllMenus()
{
    QMenu* parentMenu = this;

    while (parentMenu) {
        parentMenu->close();
        parentMenu = qobject_cast<QMenu*>(parentMenu->parentWidget());
    }
}
예제 #3
0
void Menu::closeAllMenus()
{
    QMenu* menu = this;

    while (menu) {
        menu->close();
        menu = qobject_cast<QMenu*>(QApplication::activePopupWidget());
    }
}
예제 #4
0
파일: music.cpp 프로젝트: listenmer/music
void Music::listMusic_customContextMenuRequested(const QPoint &pos)
{
    if(ui->listMusic->itemAt(pos) == NULL) return;

    QMenu *popMenu =new QMenu(this);
    popMenu->addAction("Delete");
    popMenu->addMenu(ui->menuFile);
    popMenu->addMenu(ui->menuPre);

    connect(popMenu->actions().at(0),SIGNAL(triggered()),this,SLOT(del_file()));

    popMenu->exec(QCursor::pos());//弹出右键菜单,菜单位置为光标位置
    popMenu->close();
    delete popMenu;
}
예제 #5
0
//2nd part of the test
void tst_QMenu::onStatusTipTimer()
{
    QMenu *menu = qobject_cast<QMenu*>(QApplication::activePopupWidget());
    QVERIFY(menu != 0);
    QVERIFY(menu->isVisible());
    QTest::keyClick(menu, Qt::Key_Down);

    //we store the statustip to press escape in any case
    //otherwise, if the test fails it blocks (never gets out of QMenu::exec
    const QString st=statustip;

    menu->close(); //goes out of the menu

    QCOMPARE(st, QString("sub action"));
    QVERIFY(menu->isVisible() == false);
}
예제 #6
0
void wavrImagePicker::currentChanged(const QModelIndex& current, const QModelIndex& previous) {
    QMenu* pMenu = (QMenu*)this->parent();
    if(current.isValid()) {
        int index = current.row() * max_col + current.column();
        if(current.data(TypeRole).toInt() == 1) {
            *selected = index;
            pMenu->actions()[actionIndex]->trigger();
        }
        else {
            setCurrentIndex(previous);
            return;
        }
    }
    hoverItem = NULL;
    setCurrentIndex(QModelIndex());
    pMenu->close();
}
예제 #7
0
void ezQtNodeScene::contextMenuEvent(QGraphicsSceneContextMenuEvent* contextMenuEvent)
{
  QTransform id;

  QGraphicsItem* pItem = itemAt(contextMenuEvent->scenePos(), id);
  int iType = pItem != nullptr ? pItem->type() : -1;
  while (pItem && !(iType >= Type::Node && iType <= Type::Connection))
  {
    pItem = pItem->parentItem();
    iType = pItem != nullptr ? pItem->type() : -1;
  }

  ezQtSearchableMenu* pSearchMenu = nullptr;

  QMenu menu;
  if (iType == Type::Pin)
  {
    ezQtPin* pPin = static_cast<ezQtPin*>(pItem);
    QAction* pAction = new QAction("Disconnect Pin", &menu);
    menu.addAction(pAction);
    connect(pAction, &QAction::triggered, this, [this, pPin](bool bChecked) { DisconnectPinsAction(pPin); });
  }
  else if (iType == Type::Node)
  {
    ezQtNode* pNode = static_cast<ezQtNode*>(pItem);

    // if we clicked on an unselected item, make it the only selected item
    if (!pNode->isSelected())
    {
      clearSelection();
      pNode->setSelected(true);
    }

    // Delete Node
    {
      QAction* pAction = new QAction("Remove", &menu);
      menu.addAction(pAction);
      connect(pAction, &QAction::triggered, this, [this](bool bChecked) { RemoveSelectedNodesAction(); });
    }
  }
  else if (iType == Type::Connection)
  {
    ezQtConnection* pConnection = static_cast<ezQtConnection*>(pItem);
    QAction* pAction = new QAction("Delete Connection", &menu);
    menu.addAction(pAction);
    connect(pAction, &QAction::triggered, this, [this, pConnection](bool bChecked) { DisconnectPinsAction(pConnection); });
  }
  else
  {
    pSearchMenu = new ezQtSearchableMenu(&menu);
    menu.addAction(pSearchMenu);

    connect(pSearchMenu, &ezQtSearchableMenu::MenuItemTriggered, this, &ezQtNodeScene::OnMenuItemTriggered);
    connect(pSearchMenu, &ezQtSearchableMenu::MenuItemTriggered, this, [&menu]() { menu.close(); });

    ezStringBuilder sFullName;

    ezHybridArray<const ezRTTI*, 32> types;
    m_pManager->GetCreateableTypes(types);
    auto pos = contextMenuEvent->scenePos();
    m_vPos = ezVec2(pos.x(), pos.y());
    for (const ezRTTI* pRtti : types)
    {
      const char* szCleanName = pRtti->GetTypeName();

      const char* szColonColon = ezStringUtils::FindLastSubString(szCleanName, "::");
      if (szColonColon != nullptr)
        szCleanName = szColonColon + 2;

      const char* szUnderscore = ezStringUtils::FindLastSubString(szCleanName, "_");
      if (szUnderscore != nullptr)
        szCleanName = szUnderscore + 1;

      sFullName = m_pManager->GetTypeCategory(pRtti);
      sFullName.AppendPath(szCleanName);

      pSearchMenu->AddItem(sFullName, qVariantFromValue((void*)pRtti));
    }

    pSearchMenu->Finalize(m_sContextMenuSearchText);
  }

  menu.exec(contextMenuEvent->screenPos());

  if (pSearchMenu)
  {
    m_sContextMenuSearchText = pSearchMenu->GetSearchText();
  }
}
예제 #8
0
void
FlowView::
contextMenuEvent(QContextMenuEvent *event)
{
  QMenu modelMenu;

  auto skipText = QStringLiteral("skip me");

  //Add filterbox to the context menu
  auto *txtBox = new QLineEdit(&modelMenu);

  txtBox->setPlaceholderText(QStringLiteral("Filter"));
  txtBox->setClearButtonEnabled(true);

  auto *txtBoxAction = new QWidgetAction(&modelMenu);
  txtBoxAction->setDefaultWidget(txtBox);

  modelMenu.addAction(txtBoxAction);

  //Add result treeview to the context menu
  auto *treeView = new QTreeWidget(&modelMenu);
  treeView->header()->close();

  auto *treeViewAction = new QWidgetAction(&modelMenu);
  treeViewAction->setDefaultWidget(treeView);

  modelMenu.addAction(treeViewAction);

  QMap<QString, QTreeWidgetItem*> topLevelItems;
  for (auto const &cat : _scene->registry().categories())
  {
    auto item = new QTreeWidgetItem(treeView);
    item->setText(0, cat);
    item->setData(0, Qt::UserRole, skipText);
    topLevelItems[cat] = item;
  }

  for (auto const &assoc : _scene->registry().registeredModelsCategoryAssociation())
  {
    auto parent = topLevelItems[assoc.second];
    auto item   = new QTreeWidgetItem(parent);
    item->setText(0, assoc.first);
    item->setData(0, Qt::UserRole, assoc.first);
  }

  treeView->expandAll();

  connect(treeView, &QTreeWidget::itemClicked, [&](QTreeWidgetItem *item, int)
  {
    QString modelName = item->data(0, Qt::UserRole).toString();

    if (modelName == skipText)
    {
      return;
    }

    auto type = _scene->registry().create(modelName);

    if (type)
    {
      auto& node = _scene->createNode(std::move(type));

      QPoint pos = event->pos();

      QPointF posView = this->mapToScene(pos);

      node.nodeGraphicsObject().setPos(posView);
    }
    else
    {
      qDebug() << "Model not found";
    }

    modelMenu.close();
  });

  //Setup filtering
  connect(txtBox, &QLineEdit::textChanged, [&](const QString &text)
  {
    for (auto& topLvlItem : topLevelItems)
    {
      for (int i = 0; i < topLvlItem->childCount(); ++i)
      {
        auto child = topLvlItem->child(i);
        auto modelName = child->data(0, Qt::UserRole).toString();
        if (modelName.contains(text, Qt::CaseInsensitive))
        {
          child->setHidden(false);
        }
        else
        {
          child->setHidden(true);
        }
      }
    }
  });

  // make sure the text box gets focus so the user doesn't have to click on it
  txtBox->setFocus();

  modelMenu.exec(event->globalPos());
}