void PlaylistBrowserNS::PlaylistBrowserView::contextMenuEvent( QContextMenuEvent *event ) { QModelIndex clickedIdx = indexAt( event->pos() ); QModelIndexList indices; if( clickedIdx.isValid() && selectedIndexes().contains( clickedIdx ) ) indices << selectedIndexes(); else if( clickedIdx.isValid() ) indices << clickedIdx; QActionList actions = actionsFor( indices ); if( actions.isEmpty() ) { resetActionTargets(); return; } KMenu menu; foreach( QAction *action, actions ) menu.addAction( action ); menu.exec( mapToGlobal( event->pos() ) ); // We keep the items that the action need to be applied to. // Clear the data from all actions now that the context menu has executed. resetActionTargets(); }
void OpmlDirectoryView::contextMenuEvent( QContextMenuEvent *event ) { QModelIndex idx = indexAt( event->pos() ); debug() << idx; event->accept(); QVariant data = model()->data( idx, OpmlDirectoryModel::ActionRole ); QActionList actions = data.value<QActionList>(); if( actions.isEmpty() ) { return; } KMenu menu; foreach( QAction *action, actions ) { if( action ) menu.addAction( action ); } menu.exec( mapToGlobal( event->pos() ) ); //We keep the items that the actions need to be applied to in the actions private data. //Clear the data from all actions now that the context menu has executed. foreach( QAction *action, actions ) action->setData( QVariant() ); }
void Container::contextMenu( int currentTab, QPoint pos ) { KMenu menu; emit tabContextMenuRequested(viewForWidget(widget(currentTab)), &menu); menu.addSeparator(); QAction* closeTabAction = menu.addAction( KIcon("document-close"), i18n( "Close File" ) ); QAction* closeOtherTabsAction = menu.addAction( KIcon("document-close"), i18n( "Close Other Files" ) ); QAction* closeAllTabsAction = menu.addAction( KIcon("document-close"), i18n( "Close All Files" ) ); QAction* triggered = menu.exec(pos); if (triggered) { if ( triggered == closeTabAction ) { closeRequest(currentTab); } else if ( triggered == closeOtherTabsAction ) { // activate the remaining tab widgetActivated(currentTab); // first get the widgets to be closed since otherwise the indices will be wrong QList<QWidget*> otherTabs; for ( int i = 0; i < count(); ++i ) { if ( i != currentTab ) { otherTabs << widget(i); } } // finally close other tabs foreach( QWidget* tab, otherTabs ) { closeRequest(tab); } } else if ( triggered == closeAllTabsAction ) {
void BlockAnalyzer::contextMenuEvent( QContextMenuEvent * ) { KMenu *menu = new KMenu( this ); menu->setTitle( i18n( "Framerate" ) ); QAction *a = menu->addAction( i18n("50 fps"), this, SLOT( set50fps() ) ); if( timeout() == 50 ) a->setChecked( true ); a = menu->addAction( i18n("33 fps"), this, SLOT( set33fps() ) ); if( timeout() == 33 ) a->setChecked( true ); a = menu->addAction( i18n("25 fps"), this, SLOT( set25fps() ) ); if( timeout() == 25 ) a->setChecked( true ); a = menu->addAction( i18n("20 fps"), this, SLOT( set20fps() ) ); if( timeout() == 20 ) a->setChecked( true ); a = menu->addAction( i18n("10 fps"), this, SLOT( set10fps() ) ); if( timeout() == 10 ) a->setChecked( true ); #if defined HAVE_LIBVISUAL menu->addSeparator(); menu->addAction( Amarok::actionCollection()->action( "visualizations" ) ); #endif menu->exec(); }
void TabBar::contextMenu(int tab, const QPoint &pos) { KActionMenu *closedTabsMenu = setupHistoryActions(); m_actualIndex = tab; KMenu menu; MainWindow *mainWindow = rApp->mainWindow(); menu.addAction(mainWindow->actionByName(QL1S("new_tab"))); menu.addAction(mainWindow->actionByName(QL1S("clone_tab"))); if (count() > 1) { menu.addAction(mainWindow->actionByName(QL1S("detach_tab"))); } menu.addAction(mainWindow->actionByName(QL1S("open_last_closed_tab"))); menu.addAction(closedTabsMenu); menu.addSeparator(); menu.addAction(mainWindow->actionByName(QL1S("close_tab"))); if (count() > 1) { menu.addAction(mainWindow->actionByName(QL1S("close_other_tabs"))); } menu.addSeparator(); menu.addAction(mainWindow->actionByName(QL1S("reload_tab"))); if (count() > 1) { menu.addAction(mainWindow->actionByName(QL1S("reload_all_tabs"))); } menu.exec(pos); }
void ActionWidget::slotContextMenu( K3ListView *, Q3ListViewItem *item, const QPoint& pos ) { if ( !item ) return; KMenu *menu = new KMenu; QAction* addCmd = menu->addAction( i18n("Add Command") ); QAction* rmCmd = menu->addAction( i18n("Remove Command") ); if ( !item->parent() ) {// no "command" item rmCmd->setEnabled( false ); item->setOpen( true ); } QAction* executed = menu->exec( pos ); if ( executed == addCmd ) { Q3ListViewItem *p = item->parent() ? item->parent() : item; Q3ListViewItem *cmdItem = new Q3ListViewItem( p, item, i18n("Click here to set the command to be executed"), i18n("<new command>") ); cmdItem->setPixmap( 0, SmallIcon( "exec" ) ); } else if ( executed == rmCmd ) delete item; delete menu; }
void PixmapCollectionEditor::displayMenu(Q3IconViewItem *it, const QPoint &p) { if (!it) return; KMenu *menu = new KMenu(); menu->insertItem(koIcon("edit-rename"), i18n("Rename Item"), this, SLOT(renameItem())); menu->insertItem(koIcon("list-remove"), i18n("Remove Item"), this, SLOT(removeItem())); menu->exec(p); }
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; } } }
void HistoryPanel::contextMenuGroup(const QPoint &pos) { KMenu menu; KAction* action; action = new KAction(KIcon("tab-new"), i18n("Open Folder in Tabs"), this); connect(action, SIGNAL(triggered()), this, SLOT(openAll())); menu.addAction(action); menu.exec(panelTreeView()->mapToGlobal(pos)); }
void ServiceCollectionTreeView::contextMenuEvent( QContextMenuEvent * event ) { if ( m_playableTracks ) CollectionTreeView::contextMenuEvent( event ); else { QModelIndexList indices = selectedIndexes(); if( filterModel() ) { QModelIndexList tmp; foreach( const QModelIndex &idx, indices ) { tmp.append( filterModel()->mapToSource( idx ) ); } indices = tmp; } if( !indices.isEmpty() ) { KMenu menu; if( indices.count() == 1 ) { if( indices.first().isValid() && indices.first().internalPointer() ) { Meta::DataPtr data = static_cast<CollectionTreeItem*>( indices.first().internalPointer() )->data(); if( data ) { Meta::CustomActionsCapability *cac = data->create<Meta::CustomActionsCapability>(); if( cac ) { QList<PopupDropperAction*> actions = cac->customActions(); if( actions.count() ) menu.addSeparator(); foreach( PopupDropperAction *action, actions ) menu.addAction( action ); delete cac; } } } } if( menu.actions().count() > 0 ) { (void)menu.exec( event->globalPos() ); QSet<CollectionTreeItem*> items; foreach( const QModelIndex &index, indices ) { if( index.isValid() && index.internalPointer() ) items.insert( static_cast<CollectionTreeItem*>( index.internalPointer() ) ); } }
void ArchiveMailWidget::customContextMenuRequested(const QPoint&) { const QList<QTreeWidgetItem *> listItems = mWidget->treeWidget->selectedItems(); KMenu menu; menu.addAction(i18n("Add..."),this,SLOT(slotAddItem())); if( !listItems.isEmpty() ) { if( listItems.count() == 1) { menu.addAction(i18n("Open Containing Folder..."),this,SLOT(slotOpenFolder())); } menu.addSeparator(); menu.addAction(i18n("Delete"),this,SLOT(slotRemoveItem())); } menu.exec(QCursor::pos()); }
void DockContainer::popupMenu(QPoint p) { KMenu *pm = new KMenu(this); QAction *kill = pm->addAction( i18n("Kill This Applet")); QAction *change = pm->addAction( i18n("Change Command")); QAction *r = pm->exec(p); /* pm is destroyed now .. if it is destroyed later, there is a risk that kill() double-frees it */ delete pm; if (r == kill) this->kill(); if (r == change) askNewCommand(false); }
void TodoView::contextMenuEvent(QContextMenuEvent *event) { QModelIndex index = currentIndex(); const QStandardItemModel *model = static_cast <const QStandardItemModel *> (index.model()); if (index.isValid() && model) { QString title = model->data(index, Qt::DisplayRole).toString(); KMenu *menu = new KMenu(title, this); /* if (model->data(index, TodoModel::PercentRole).toInt() < 100) { QAction *action = new QAction(i18n("Set task as completed ?"), this); action->setCheckable(true); action->setData(model->data(index, TodoModel::UIDRole).toString()); action->setObjectName(MARK_COMPLETE_ACTION_NAME); menu->addAction(action); menu->addSeparator(); } */ QAction editAction(i18n("Edit task"), this); editAction.setIcon(KIcon("document-edit")); editAction.setData(model->data(index, TodoModel::UIDRole).toString()); editAction.setObjectName(EDIT_ACTION_NAME); QAction viewAction(i18n("View task"), this); viewAction.setIcon(KIcon("view-task")); viewAction.setData(model->data(index, TodoModel::UIDRole).toString()); viewAction.setObjectName(OPEN_ACTION_NAME); QAction deleteAction(i18n("Delete task"), this); deleteAction.setIcon(KIcon("edit-delete")); deleteAction.setData(model->data(index, TodoModel::UIDRole).toString()); deleteAction.setObjectName(DELETE_ACTION_NAME); menu->addAction(&editAction); menu->addAction(&viewAction); menu->addAction(&deleteAction); connect(menu, SIGNAL(triggered(QAction *)), SLOT(slotActionClicked(QAction *))); menu->exec(event->globalPos()); } }
void AlbumsView::contextMenuEvent( QGraphicsSceneContextMenuEvent *event ) { KAction *appendAction = new KAction( KIcon( "media-track-add-amarok" ), i18n( "&Append to Playlist" ), this ); KAction *loadAction = new KAction( KIcon( "folder-open" ), i18nc( "Replace the currently loaded tracks with these", "&Load" ), this ); KAction *queueAction = new KAction( KIcon( "media-track-queue-amarok" ), i18n( "&Queue" ), this ); KAction *editAction = new KAction( KIcon( "media-track-edit-amarok" ), i18n( "Edit Track Details" ), this ); connect( appendAction, SIGNAL( triggered() ), this, SLOT( slotAppendSelected() ) ); connect( loadAction , SIGNAL( triggered() ), this, SLOT( slotPlaySelected() ) ); connect( queueAction , SIGNAL( triggered() ), this, SLOT( slotQueueSelected() ) ); connect( editAction , SIGNAL( triggered() ), this, SLOT( slotEditSelected() ) ); KMenu menu; menu.addAction( appendAction ); menu.addAction( loadAction ); menu.addAction( queueAction ); menu.addSeparator(); menu.addAction( editAction ); QModelIndex index = nativeWidget()->indexAt( event->pos().toPoint() ); if( index.isValid() ) { QStandardItem *item = static_cast<QStandardItemModel*>( model() )->itemFromIndex( index ); AlbumItem *album = dynamic_cast<AlbumItem*>(item); if( album ) { Meta::AlbumPtr albumPtr = album->album(); Meta::CustomActionsCapability *cac = albumPtr->create<Meta::CustomActionsCapability>(); if( cac ) { QList<PopupDropperAction *> actions = cac->customActions(); menu.addSeparator(); foreach( PopupDropperAction *action, actions ) menu.addAction( action ); } } } menu.exec( event->screenPos() ); }
void KTNEFMain::contextMenuEvent( QContextMenuEvent *event ) { QList<KTNEFAttach *> list = mView->getSelection(); if ( !list.count() ) { return; } QAction *view = 0; QAction *viewWith = 0; QAction *prop = 0; KMenu *menu = new KMenu(); if ( list.count() == 1 ) { view = menu->addAction( KIcon( "document-open" ), i18nc( "@action:inmenu", "View" ) ); viewWith = menu->addAction( i18nc( "@action:inmenu", "View With..." ) ); menu->addSeparator(); } QAction *extract = menu->addAction( i18nc( "@action:inmenu", "Extract" ) ); QAction *extractTo = menu->addAction( KIcon( "archive-extract" ), i18nc( "@action:inmenu", "Extract To..." ) ); if ( list.count() == 1 ) { menu->addSeparator(); prop = menu->addAction( KIcon( "document-properties" ), i18nc( "@action:inmenu", "Properties" ) ); } QAction *a = menu->exec( event->globalPos(), 0 ); if ( a ) { if ( a == view ) { viewFile(); } else if ( a == viewWith ) { viewFileAs(); } else if ( a == extract ) { extractFile(); } else if ( a == extractTo ) { extractFileTo(); } else if ( a == prop ) { propertiesFile(); } } delete menu; }
void KexiProjectNavigator::contextMenuEvent(QContextMenuEvent* event) { if (!d->list->currentIndex().isValid() || !(d->features & ContextMenus)) return; KexiProjectModelItem *bit = static_cast<KexiProjectModelItem*>(d->list->currentIndex().internalPointer()); KMenu *pm = 0; if (bit->partItem()) { pm = d->itemMenu; KexiProjectModelItem *par_it = static_cast<KexiProjectModelItem*>(bit->parent()); d->itemMenu->update(par_it->partInfo(), bit->partItem()); } else if (d->partMenu) { pm = d->partMenu; d->partMenu->update(bit->partInfo()); } if (pm) pm->exec(event->globalPos()); event->setAccepted(true); }
void PlayListTabBar::contextMenu(const QPoint& point){ // qDebug() << this << "contextMenu()"; int index=tabAt(point); KMenu menu; QAction *action; if(index!=-1){ action=menu.addAction(KIcon("edit-rename"), tr("Rename Playlist"), this, SLOT(renamePlayList())); action->setData(index); action=menu.addAction(KIcon("edit-clear-list"), tr("Clear Playlist"), this, SLOT(clearPlayList())); action->setData(index); action=menu.addAction(KIcon("dialog-close"), tr("Close Playlist"), this, SLOT(closePlayList())); action->setData(index); }else{ } menu.exec(QCursor::pos()); }
void TabBar::emptyAreaContextMenu(const QPoint &pos) { setupHistoryActions(); KMenu menu; MainWindow *mainWindow = Application::instance()->mainWindow(); menu.addAction(mainWindow->actionByName( QL1S("new_tab") )); menu.addAction(mainWindow->actionByName( QL1S("open_last_closed_tab") )); menu.addAction(mainWindow->actionByName( QL1S("closed_tab_menu") )); menu.addSeparator(); menu.addAction(mainWindow->actionByName( QL1S("reload_all_tabs") )); KToolBar *mainBar = mainWindow->toolBar("mainToolBar"); if(!mainBar->isVisible()) { menu.addAction( mainBar->toggleViewAction() ); } menu.exec(pos); }
void Menu::contextMenuEvent(QContextMenuEvent *event) { QAction *action = actionAt(event->pos()); if (action && action->data().type() == QVariant::ULongLong) { TaskManager::TaskPtr taskPointer = TaskManager::TaskManager::self()->findTask(action->data().toULongLong()); if (taskPointer) { TaskManager::GroupManager *groupManager = new TaskManager::GroupManager(this); Task *task = new Task(new TaskManager::TaskItem(groupManager, taskPointer), groupManager); KMenu *menu = task->contextMenu(); menu->exec(event->globalPos()); delete task; delete groupManager; delete menu; } } }
void LastFmTreeView::contextMenuEvent ( QContextMenuEvent* event ) { m_currentItems.clear(); foreach ( const QModelIndex &i, selectedIndexes() ) { if ( i.isValid() ) m_currentItems << i; } if ( m_currentItems.isEmpty() ) return; QAction separator ( this ); separator.setSeparator ( true ); QActionList actions = createBasicActions( m_currentItems ); actions += &separator; KMenu menu; foreach ( QAction * action, actions ) menu.addAction ( action ); menu.exec ( event->globalPos() ); }
void HistoryPanel::contextMenuItem(const QPoint &pos) { KMenu menu; KAction* action; action = new KAction(KIcon("tab-new"), i18n("Open"), this); connect(action, SIGNAL(triggered()), panelTreeView(), SLOT(openInCurrentTab())); menu.addAction(action); action = new KAction(KIcon("tab-new"), i18n("Open in New Tab"), this); connect(action, SIGNAL(triggered()), panelTreeView(), SLOT(openInNewTab())); menu.addAction(action); action = new KAction(KIcon("window-new"), i18n("Open in New Window"), this); connect(action, SIGNAL(triggered()), panelTreeView(), SLOT(openInNewWindow())); menu.addAction(action); action = new KAction(KIcon("edit-copy"), i18n("Copy Link Address"), this); connect(action, SIGNAL(triggered()), panelTreeView(), SLOT(copyToClipboard())); menu.addAction(action); menu.exec(panelTreeView()->mapToGlobal(pos)); }
bool PlayerWidget::eventFilter(QObject *object, QEvent *event) { if(object == m_layeredWidget) { if(event->type() == QEvent::DragEnter) { QDragEnterEvent *dragEnterEvent = static_cast<QDragEnterEvent *>(event); KUrl::List urls = KUrl::List::fromMimeData(dragEnterEvent->mimeData()); if(!urls.isEmpty()) dragEnterEvent->accept(); else dragEnterEvent->ignore(); return true; } else if(event->type() == QEvent::DragMove) { return true; // eat event } else if(event->type() == QEvent::Drop) { QDropEvent *dropEvent = static_cast<QDropEvent *>(event); KUrl::List urls = KUrl::List::fromMimeData(dropEvent->mimeData()); if(!urls.isEmpty()) { for(KUrl::List::ConstIterator it = urls.begin(), end = urls.end(); it != end; ++it) { const KUrl &url = *it; if(url.protocol() != "file") continue; app()->openVideo(url); break; } } return true; // eat event } else if(event->type() == QEvent::KeyPress) { // NOTE: when on full screen mode, the keyboard input is received but // for some reason it doesn't trigger the correct actions automatically // so we process the event and handle the issue ourselves. QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event); return app()->triggerAction(QKeySequence((keyEvent->modifiers() & ~Qt::KeypadModifier) + keyEvent->key())); } else if(event->type() == QEvent::MouseMove) { QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event); if(mouseEvent->globalPos() != m_currentCursorPos) { m_currentCursorPos = mouseEvent->globalPos(); if(m_layeredWidget->cursor().shape() == Qt::BlankCursor) m_layeredWidget->unsetCursor(); if(m_fullScreenControls->isAttached()) m_fullScreenControls->toggleVisible(true); } } } else if(object == m_infoControlsGroupBox || object->parent() == m_infoControlsGroupBox) { if(event->type() != QEvent::MouseButtonRelease) return QWidget::eventFilter(object, event); QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event); if(mouseEvent->button() != Qt::RightButton) return QWidget::eventFilter(object, event); KMenu menu; QAction *action = menu.addAction(i18n("Show editable position control")); action->setCheckable(true); action->setChecked(app()->playerConfig()->showPositionTimeEdit()); if(menu.exec(mouseEvent->globalPos()) == action) app()->playerConfig()->toggleShowPositionTimeEdit(); return true; // eat event } return QWidget::eventFilter(object, event); }
void Launcher::dropUrls(const KUrl::List &urls, Qt::KeyboardModifiers modifiers) { if (m_serviceGroup || !urls.count()) { return; } if (m_mimeType->is("inode/directory")) { Qt::DropAction dropAction = Qt::CopyAction; if ((modifiers & Qt::ShiftModifier && modifiers & Qt::ControlModifier) || modifiers & Qt::AltModifier) { dropAction = Qt::LinkAction; } else if (modifiers & Qt::ShiftModifier) { dropAction = Qt::MoveAction; } else if (modifiers & Qt::ControlModifier) { dropAction = Qt::CopyAction; } else { KMenu *menu = new KMenu; QAction *moveAction = menu->addAction(KIcon("go-jump"), i18nc("@action:inmenu", "&Move Here\t<shortcut>%1</shortcut>", QKeySequence(Qt::ShiftModifier).toString())); QAction *copyAction = menu->addAction(KIcon("edit-copy"), i18nc("@action:inmenu", "&Copy Here\t<shortcut>%1</shortcut>", QKeySequence(Qt::ControlModifier).toString())); QAction *linkAction = menu->addAction(KIcon("insert-link"), i18nc("@action:inmenu", "&Link Here\t<shortcut>%1</shortcut>", QKeySequence(Qt::ControlModifier + Qt::ShiftModifier).toString())); menu->addSeparator(); menu->addAction(KIcon("process-stop"), i18nc("@action:inmenu", "Cancel")); QAction *activatedAction = menu->exec(QCursor::pos()); delete menu; if (activatedAction == moveAction) { dropAction = Qt::MoveAction; } else if (activatedAction == copyAction) { dropAction = Qt::CopyAction; } else if (activatedAction == linkAction) { dropAction = Qt::LinkAction; } else { return; } } switch (dropAction) { case Qt::MoveAction: KIO::move(urls, m_targetUrl); break; case Qt::CopyAction: KIO::copy(urls, m_targetUrl); break; case Qt::LinkAction: KIO::link(urls, m_targetUrl); break; default: return; } } else if (m_isExecutable) { QString arguments; QString command; for (int i = 0; i < urls.count(); ++i) { arguments += ' ' + KShell::quoteArg(urls[i].isLocalFile()?urls[i].path():urls[i].prettyUrl()); } if (KDesktopFile::isDesktopFile(m_launcherUrl.toLocalFile())) { KDesktopFile desktopFile(m_launcherUrl.toLocalFile()); KConfigGroup config = desktopFile.desktopGroup(); command = config.readPathEntry("Exec", QString()); if (command.isEmpty()) { command = KShell::quoteArg(m_launcherUrl.path()); } } else { command = KShell::quoteArg(m_launcherUrl.path()); } KRun::runCommand(command + ' ' + arguments, NULL); } }
void TwitterPostWidget::checkAnchor(const QUrl& url) { QString scheme = url.scheme(); TwitterApiMicroBlog* blog = qobject_cast<TwitterApiMicroBlog*>(currentAccount()->microblog()); TwitterApiAccount *account = qobject_cast<TwitterApiAccount*>(currentAccount()); if( scheme == "tag" ) { blog->searchBackend()->requestSearchResults(currentAccount(), KUrl::fromPunycode(url.host().toUtf8()), (int)TwitterSearch::ReferenceHashtag); } else if(scheme == "user") { KMenu menu; KAction * info = new KAction( KIcon("user-identity"), i18nc("Who is user", "Who is %1", url.host()), &menu ); KAction * from = new KAction(KIcon("edit-find-user"), i18nc("Posts from user", "Posts from %1",url.host()), &menu); KAction * to = new KAction(KIcon("meeting-attending"), i18nc("Replies to user", "Replies to %1", url.host()), &menu); KAction *cont = new KAction(KIcon("user-properties"),i18nc("Including user name", "Including %1", url.host()), &menu); KAction * openInBrowser = new KAction(KIcon("applications-internet"), i18nc("Open profile page in browser", "Open profile in browser"), &menu); from->setData(TwitterSearch::FromUser); to->setData(TwitterSearch::ToUser); cont->setData(TwitterSearch::ReferenceUser); menu.addAction(info); menu.addAction(from); menu.addAction(to); menu.addAction(cont); menu.addAction(openInBrowser); //Subscribe/UnSubscribe/Block bool isSubscribe = false; QString accountUsername = currentAccount()->username().toLower(); QString postUsername = url.host().toLower(); KAction *subscribe = 0, *block = 0, *replyTo = 0, *dMessage = 0; if(accountUsername != postUsername){ menu.addSeparator(); QMenu *actionsMenu = menu.addMenu(KIcon("applications-system"), i18n("Actions")); replyTo = new KAction(KIcon("edit-undo"), i18nc("Write a message to user attention", "Write to %1", url.host()), actionsMenu); actionsMenu->addAction(replyTo); if( account->friendsList().contains( url.host(), Qt::CaseInsensitive ) ){ dMessage = new KAction(KIcon("mail-message-new"), i18nc("Send direct message to user", "Send private message to %1", url.host()), actionsMenu); actionsMenu->addAction(dMessage); isSubscribe = false;//It's UnSubscribe subscribe = new KAction( KIcon("list-remove-user"), i18nc("Unfollow user", "Unfollow %1", url.host()), actionsMenu); } else { isSubscribe = true; subscribe = new KAction( KIcon("list-add-user"), i18nc("Follow user", "Follow %1", url.host()), actionsMenu); } block = new KAction( KIcon("dialog-cancel"), i18nc("Block user", "Block %1", url.host()), actionsMenu); actionsMenu->addAction(subscribe); actionsMenu->addAction(block); } QAction * ret = menu.exec(QCursor::pos()); if(ret == 0) return; if(ret == info) { TwitterApiWhoisWidget *wd = new TwitterApiWhoisWidget(account, url.host(), currentPost(), this); wd->show(QCursor::pos()); return; } else if(ret == subscribe){ if(isSubscribe) { blog->createFriendship(currentAccount(), url.host()); } else { blog->destroyFriendship(currentAccount(), url.host()); } return; }else if(ret == block){ blog->blockUser(currentAccount(), url.host()); return; } else if(ret == openInBrowser){ Choqok::openUrl( QUrl( currentAccount()->microblog()->profileUrl(currentAccount(), url.host()) ) ); return; } else if(ret == replyTo){ emit reply( QString("@%1").arg(url.host()), QString() ); return; } else if(ret == dMessage){ blog->showDirectMessageDialog(account,url.host()); return; } int type = ret->data().toInt(); blog->searchBackend()->requestSearchResults(currentAccount(), url.host(), type); } else TwitterApiPostWidget::checkAnchor(url); }
// build a context menu void UserMenuTree::contextMenuRequested(const QPoint &pos) { KILE_DEBUG() << "context menu requested ..." ; m_popupItem = dynamic_cast<UserMenuItem*>(itemAt(pos)); if ( !m_popupItem ) { KILE_DEBUG() << "... no item found"; return; } KILE_DEBUG() << "... popup item found: " << m_popupItem->text(0); bool submenu = ( m_popupItem->menutype() == UserMenuData::Submenu ); bool separator = ( m_popupItem->menutype() == UserMenuData::Separator ); KMenu popup; QAction *action = NULL; QSignalMapper signalMapper; connect(&signalMapper, SIGNAL(mapped(int)), this, SLOT(slotPopupActivated(int))); // insert standard menu items action = popup.addAction(KIcon("usermenu-insert-above.png"),i18n("Insert above"), &signalMapper, SLOT(map())); signalMapper.setMapping(action, POPUP_INSERT_ABOVE); action = popup.addAction(KIcon("usermenu-insert-below.png"),i18n("Insert below"), &signalMapper, SLOT(map())); signalMapper.setMapping(action, POPUP_INSERT_BELOW); popup.addSeparator(); // insert separators if ( !separator ) { action = popup.addAction(KIcon("usermenu-separator-above.png"),i18n("Insert a separator above"), &signalMapper, SLOT(map())); signalMapper.setMapping(action, POPUP_SEPARATOR_ABOVE); action = popup.addAction(KIcon("usermenu-separator-below.png"),i18n("Insert a separator below"), &signalMapper, SLOT(map())); signalMapper.setMapping(action, POPUP_SEPARATOR_BELOW); popup.addSeparator(); } // insert submenus action = popup.addAction(KIcon("usermenu-submenu-above.png"),i18n("Insert a submenu above"), &signalMapper, SLOT(map())); signalMapper.setMapping(action, POPUP_SUBMENU_ABOVE); action = popup.addAction(KIcon("usermenu-submenu-below.png"),i18n("Insert a submenu below"), &signalMapper, SLOT(map())); signalMapper.setMapping(action, POPUP_SUBMENU_BELOW); popup.addSeparator(); // insert into submenus if ( submenu ) { action = popup.addAction(KIcon("usermenu-into-submenu.png"),i18n("Insert into this submenu"), &signalMapper, SLOT(map())); signalMapper.setMapping(action, POPUP_INTO_SUBMENU); action = popup.addAction(i18n("Insert a separator into this submenu"), &signalMapper, SLOT(map())); signalMapper.setMapping(action, POPUP_SEPARATOR_INTO_SUBMENU); action = popup.addAction(i18n("Insert a submenu into this submenu"), &signalMapper, SLOT(map())); signalMapper.setMapping(action, POPUP_SUBMENU_INTO_SUBMENU); popup.addSeparator(); } // delete actions action = popup.addAction(KIcon("usermenu-delete.png"),i18n("Delete this item"), &signalMapper, SLOT(map())); signalMapper.setMapping(action,POPUP_DELETE_ITEM); popup.addSeparator(); action = popup.addAction(KIcon("usermenu-clear.png"),i18n("Delete the complete tree"), &signalMapper, SLOT(map())); signalMapper.setMapping(action, POPUP_DELETE_TREE); // expand/collapse tree if ( submenu ) { popup.addSeparator(); if ( m_popupItem->isExpanded() ) { action = popup.addAction(i18n("Collapse submenu"), &signalMapper, SLOT(map())); signalMapper.setMapping(action,POPUP_COLLAPSE_ITEM); } else { action = popup.addAction(i18n("Expand submenu"), &signalMapper, SLOT(map())); signalMapper.setMapping(action,POPUP_EXPAND_ITEM); } popup.addSeparator(); action = popup.addAction(i18n("Collapse complete tree"), &signalMapper, SLOT(map())); signalMapper.setMapping(action,POPUP_COLLAPSE_TREE); action = popup.addAction(i18n("Expand complete tree"), &signalMapper, SLOT(map())); signalMapper.setMapping(action,POPUP_EXPAND_TREE); } // if there are any errors with this item, some info is available int error = m_popupItem->data(0,Qt::UserRole+2).toInt(); if ( error != UserMenuItem::MODEL_ERROR_NONE ) { popup.addSeparator(); action = popup.addAction(KIcon("help-about.png"),i18n("Info"), &signalMapper, SLOT(map())); signalMapper.setMapping(action, POPUP_ITEM_INFO); } // const QPoint& pos parameter in the customContextMenuRequested() signal is normally in widget coordinates. // But classes like QTreeWidget, which inherit from QAbstractScrollArea1 instead use the coordinates of their viewport() if ( !popup.isEmpty() ) { popup.exec( viewport()->mapToGlobal(pos) ); } }