void TreeArea::groupsItemClicked(const QPoint& pos){ // We assume that if the item clicked does not have any child, it is a group QTreeWidgetItem* item = this->groupsTree->currentItem(); if (item->parent() == NULL){ // Add a menu QMenu menu(this->groupsTree); // Add the actions to the menu QAction* actionHide = menu.addAction("Hide Group"); QAction* actionShow = menu.addAction("Show Group"); QAction* actionColor = menu.addAction("Change Group Color"); // Connect the actions created with their slots QObject::connect(actionHide, SIGNAL(triggered()), this, SLOT(hideGroup())); QObject::connect(actionShow, SIGNAL(triggered()), this, SLOT(showGroup())); QObject::connect(actionColor, SIGNAL(triggered()), this, SLOT(changeGroupColor())); // Show the menu at the current position menu.exec(QCursor::pos()); } else { // Add a menu QMenu menu(this->groupsTree); // Add the actions to the menu QAction* actionHide = menu.addAction("Hide Sort"); QAction* actionShow = menu.addAction("Show Sort"); QAction* actionColor = menu.addAction("Change Sort Color"); // Connect the actions created with their slots QObject::connect(actionHide, SIGNAL(triggered()), this, SLOT(hideSortClickedFromGroup())); QObject::connect(actionShow, SIGNAL(triggered()), this, SLOT(showSortClickedFromGroup())); QObject::connect(actionColor, SIGNAL(triggered()), this, SLOT(changeSortColorClickedFromGroup())); // Show the menu at the current position menu.exec(QCursor::pos()); } }
/*! \brief show the context menu */ void XletSwitchBoard::contextMenuEvent(QContextMenuEvent *event) { // check if there is a group under the cursor Group *group = getGroup(m_layout->getPosInGrid(event->pos())); QMenu contextMenu(this); QAction *action; if (group) { action = contextMenu.addAction(tr("Remove group %1").arg(group->name()), this, SLOT(removeGroup())); action->setProperty("group", QVariant::fromValue((void *)group)); action = contextMenu.addAction(tr("Change color of group %1").arg(group->name()), this, SLOT(changeGroupColor())); action->setProperty("group", QVariant::fromValue((void *)group)); action = contextMenu.addAction(tr("Rename group %1").arg(group->name()), this, SLOT(changeGroupName())); action->setProperty("group", QVariant::fromValue((void *)group)); } action = contextMenu.addAction(tr("Add Phone number entry"), this, SLOT(addPhoneNumberEntry())); action->setProperty("pos", m_layout->getPosInGrid(event->pos())); action = new QAction(tr("Draw the grid"), this); action->setCheckable(true); action->setChecked(m_drawGrid); connect(action, SIGNAL(toggled(bool)), this, SLOT(drawTheGrid(bool))); contextMenu.addAction(action); contextMenu.exec(event->globalPos()); }