当前位置: 首页>>代码示例>>C++>>正文


C++ KMenu::isEmpty方法代码示例

本文整理汇总了C++中KMenu::isEmpty方法的典型用法代码示例。如果您正苦于以下问题:C++ KMenu::isEmpty方法的具体用法?C++ KMenu::isEmpty怎么用?C++ KMenu::isEmpty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在KMenu的用法示例。


在下文中一共展示了KMenu::isEmpty方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: contextMenuRequested

// 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) );
	}
}
开发者ID:fagu,项目名称:kileip,代码行数:93,代码来源:usermenutree.cpp


注:本文中的KMenu::isEmpty方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。