本文整理汇总了C++中KMenu类的典型用法代码示例。如果您正苦于以下问题:C++ KMenu类的具体用法?C++ KMenu怎么用?C++ KMenu使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了KMenu类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: indexAt
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() );
}
示例2: slotContextMenu
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;
}
示例3: indexAt
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();
}
示例4: Action
void SystemTray::init()
{
ActionCollection *coll = QtUi::actionCollection("General");
_minimizeRestoreAction = new Action(tr("&Minimize"), this, this, SLOT(minimizeRestore()));
#ifdef HAVE_KDE
KMenu *kmenu;
_trayMenu = kmenu = new KMenu();
kmenu->addTitle(_activeIcon, "Quassel IRC");
#else
_trayMenu = new QMenu(associatedWidget());
#endif
_trayMenu->setTitle("Quassel IRC");
#ifndef HAVE_KDE
_trayMenu->setAttribute(Qt::WA_Hover);
#endif
_trayMenu->addAction(coll->action("ConnectCore"));
_trayMenu->addAction(coll->action("DisconnectCore"));
_trayMenu->addAction(coll->action("CoreInfo"));
_trayMenu->addSeparator();
_trayMenu->addAction(_minimizeRestoreAction);
_trayMenu->addAction(coll->action("Quit"));
connect(_trayMenu, SIGNAL(aboutToShow()), SLOT(trayMenuAboutToShow()));
NotificationSettings notificationSettings;
notificationSettings.initAndNotify("Systray/Animate", this, SLOT(enableAnimationChanged(QVariant)), true);
}
示例5: KHelpMenu
void Amor::slotMouseClicked(const QPoint &pos)
{
bool restartTimer = mTimer->isActive();
// Stop the animation while the menu is open.
if( restartTimer ) {
mTimer->stop();
}
if( !mMenu ) {
KHelpMenu* help = new KHelpMenu( 0, KGlobal::mainComponent().aboutData(), false );
KMenu* helpMenu = help->menu();
#ifdef __GNUC__
#warning the following is kinda dirty and should be done by KHelpMenu::menu() I think. (hermier)
#endif
helpMenu->setIcon( SmallIcon( QLatin1String( "help-contents" ) ) );
helpMenu->setTitle( i18nc( "@action:inmenu Amor", "&Help" ) );
mMenu = new KMenu( 0 );
mMenu->addTitle( QLatin1String( "Amor" ) ); // I really don't want this i18n'ed
mMenu->addAction( SmallIcon( QLatin1String ("configure" ) ), i18nc( "@action:inmenu Amor", "&Configure..." ), this, SLOT(slotConfigure()) );
mMenu->addSeparator();
mMenu->addMenu( helpMenu );
mMenu->addAction( SmallIcon( QLatin1String( "application-exit" ) ), i18nc( "@action:inmenu Amor", "&Quit" ), kapp, SLOT(quit()) );
}
mMenu->exec( pos );
if( restartTimer ) {
mTimer->setSingleShot( true );
mTimer->start( 1000 );
}
}
示例6: menu
/******************************************************************************
* Called when the New From Template action is clicked.
* Creates a popup menu listing all alarm templates, in sorted name order.
*/
void TemplateMenuAction::slotInitMenu()
{
KMenu* m = menu();
m->clear();
mOriginalTexts.clear();
// Compile a sorted list of template names
int i, end;
QStringList sorted;
KAEvent::List templates = KAlarm::templateList();
for (i = 0, end = templates.count(); i < end; ++i)
{
QString name = templates[i]->templateName();
int j = 0;
for (int jend = sorted.count();
j < jend && QString::localeAwareCompare(name, sorted[j]) > 0;
++j) ;
sorted.insert(j, name);
}
for (i = 0, end = sorted.count(); i < end; ++i)
{
QAction* act = m->addAction(sorted[i]);
mOriginalTexts[act] = sorted[i]; // keep original text, since action text has shortcuts added
}
}
示例7: KMenu
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();
}
示例8: QWidget
ComponentWidget::ComponentWidget(QWidget *parent, Clock *clock) : QWidget(parent),
m_clock(clock),
m_component(InvalidComponent)
{
m_componentUi.setupUi(this);
KMenu *menu = new KMenu(m_componentUi.componentButton);
for (int i = 1; i < LastComponent; ++i) {
QAction *action = new QAction(Clock::getComponentName(static_cast<ClockComponent>(i)), this);
action->setData(i);
menu->addAction(action);
}
m_componentUi.componentButton->setMenu(menu);
m_componentUi.optionsButton->setMenu(new KMenu(m_componentUi.optionsButton));
if (!parent) {
m_componentUi.insertButton->hide();
m_componentUi.verticalLayout->addWidget(m_componentUi.previewLabel);
}
connect(menu, SIGNAL(triggered(QAction*)), this, SLOT(selectComponent(QAction*)));
connect(m_componentUi.insertButton, SIGNAL(clicked()), this, SLOT(insertComponent()));
}
示例9: unplug
void cMenuManager::unplug (QAction *action)
{
KMenu *menu = d->actionLocations[action];
if (menu)
menu->removeAction (action);
d->actionLocations.erase (action);
}
示例10: on_editor_contextMenu
void SxEditor::on_editor_contextMenu( QMenu* menu, bool *pbContinue )
{
KMenu *pMenu = qobject_cast<KMenu*>(menu);
{
QAction *action = pMenu->addAction("粗体", this, SLOT(on_common_command_clicked()));
action->setObjectName("bold");
}
{
QAction *action = pMenu->addAction("斜体", this, SLOT(on_common_command_clicked()));
action->setObjectName("italic");
}
{
QAction *action = pMenu->addAction("下划线", this, SLOT(on_common_command_clicked()));
action->setObjectName("underline");
}
{
QAction *action = pMenu->addAction("删除线", this, SLOT(on_common_command_clicked()));
action->setObjectName("throughout");
}
{
QAction *action = menu->addSeparator();
}
{
QAction *action = menu->addAction("选择全部", this, SLOT(on_common_command_clicked()));
action->setObjectName("selectAll");
}
{
QAction *action = menu->addAction("粘贴", this, SLOT(on_common_command_clicked()));
bool bEnable = false;
QClipboard *clipboard = QApplication::clipboard();
if(clipboard )
{
const QMimeData *mimedata = clipboard->mimeData();
if (mimedata->hasHtml() || mimedata->hasImage() || mimedata->hasText() || mimedata->hasUrls() || mimedata->hasFormat(KTextEditMime))
{
bEnable = true;
}
}
action->setEnabled(bEnable && !m_pTextEdit->isReadOnly());
action->setObjectName("paste");
}
QTextCursor cursor = m_pTextEdit->textCursor();
bool hasText = !cursor.selection().isEmpty();
{
QAction *action = menu->addAction("剪切", this, SLOT(on_common_command_clicked()));
action->setEnabled(hasText && !m_pTextEdit->isReadOnly());
action->setObjectName("cut");
}
{
QAction *action = menu->addAction("复制", this, SLOT(on_common_command_clicked()));
action->setEnabled(hasText);
action->setObjectName("copy");
}
*pbContinue = false;
}
示例11: i18n
void Configuration::setServiceMenu()
{
KMenu *menu = qobject_cast<KMenu*>(sender());
if (menu->actions().count() > 1)
{
return;
}
KServiceGroup::Ptr rootGroup = KServiceGroup::group(menu->actions()[0]->data().toString());
if (!rootGroup || !rootGroup->isValid() || rootGroup->noDisplay())
{
return;
}
KServiceGroup::List list = rootGroup->entries(true, true, true, true);
QAction *action = menu->addAction(KIcon("list-add"), i18n("Add This Menu"));
action->setData(rootGroup->relPath());
menu->addSeparator();
for (int i = 0; i < list.count(); ++i)
{
if (list.at(i)->isType(KST_KService))
{
const KService::Ptr service = KService::Ptr::staticCast(list.at(i));
action = menu->addAction(KIcon(service->icon()), service->name());
action->setEnabled(false);
}
else if (list.at(i)->isType(KST_KServiceGroup))
{
const KServiceGroup::Ptr group = KServiceGroup::Ptr::staticCast(list.at(i));
if (group->noDisplay() || group->childCount() == 0)
{
continue;
}
KMenu *subMenu = new KMenu(menu);
QAction *action = subMenu->addAction(QString());
action->setData(group->relPath());
action->setVisible(false);
action = menu->addAction(KIcon(group->icon()), group->caption());
action->setMenu(subMenu);
connect(subMenu, SIGNAL(aboutToShow()), this, SLOT(setServiceMenu()));
}
else if (list.at(i)->isType(KST_KServiceSeparator))
{
menu->addSeparator();
}
}
}
示例12: KMenu
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);
}
示例13: DemoWidget
DemoWidget() : QWidget()
{
menu = new KMenu("Popup Menu:");
menu->addAction( "Item1" );
menu->addAction( "Item2" );
menu->addSeparator();
QAction *a = new QAction( "Quit", this );
menu->addAction( a );
connect( a, SIGNAL(triggered()), qApp, SLOT(quit()));
}
示例14: KMenu
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;
}
}
}
示例15: contextMenuGroup
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));
}