AppMenuView::AppMenuView(QWidget* parent): model_(new QStandardItemModel()), menu_cache(NULL), menu_cache_reload_notify(NULL), QTreeView(parent) { setHeaderHidden(true); setSelectionMode(SingleSelection); // initialize model // TODO: share one model among all app menu view widgets // ensure that we're using lxmenu-data (FIXME: should we do this?) QByteArray oldenv = qgetenv("XDG_MENU_PREFIX"); qputenv("XDG_MENU_PREFIX", "lxde-"); menu_cache = menu_cache_lookup("applications.menu"); // if(!oldenv.isEmpty()) qputenv("XDG_MENU_PREFIX", oldenv); // restore the original value if needed if(menu_cache) { MenuCacheDir* dir = menu_cache_dup_root_dir(menu_cache); menu_cache_reload_notify = menu_cache_add_reload_notify(menu_cache, _onMenuCacheReload, this); if(dir) { /* content of menu is already loaded */ addMenuItems(NULL, dir); menu_cache_item_unref(MENU_CACHE_ITEM(dir)); } } setModel(model_); connect(selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), SIGNAL(selectionChanged())); selectionModel()->select(model_->index(0, 0), QItemSelectionModel::SelectCurrent); }
void AppMenuView::addMenuItems(QStandardItem* parentItem, MenuCacheDir* dir) { GSList* l; GSList* list; /* Iterate over all menu items in this directory. */ for(l = list = menu_cache_dir_list_children(dir); l != NULL; l = l->next) { /* Get the menu item. */ MenuCacheItem* menuItem = MENU_CACHE_ITEM(l->data); switch(menu_cache_item_get_type(menuItem)) { case MENU_CACHE_TYPE_NONE: case MENU_CACHE_TYPE_SEP: break; case MENU_CACHE_TYPE_APP: case MENU_CACHE_TYPE_DIR: { AppMenuViewItem* newItem = new AppMenuViewItem(menuItem); if(parentItem) parentItem->insertRow(parentItem->rowCount(), newItem); else model_->insertRow(model_->rowCount(), newItem); if(menu_cache_item_get_type(menuItem) == MENU_CACHE_TYPE_DIR) addMenuItems(newItem, MENU_CACHE_DIR(menuItem)); break; } } } g_slist_free_full(list, (GDestroyNotify)menu_cache_item_unref); }
void XdgCachedMenu::addMenuItems(QMenu* menu, MenuCacheDir* dir) { for(GSList* l = menu_cache_dir_get_children(dir); l; l = l->next) { MenuCacheItem* item = (MenuCacheItem*)l->data; MenuCacheType type = menu_cache_item_get_type(item); if(type == MENU_CACHE_TYPE_SEP) { menu->addSeparator(); continue; } else { XdgCachedMenuAction* action = new XdgCachedMenuAction(item, menu); menu->addAction(action); if(type == MENU_CACHE_TYPE_APP) connect(action, SIGNAL(triggered(bool)), SLOT(onItemTrigerred())); else if(type == MENU_CACHE_TYPE_DIR) { XdgCachedMenu* submenu = new XdgCachedMenu(menu); action->setMenu(submenu); addMenuItems(submenu, (MenuCacheDir*)item); } } } }
XdgCachedMenu::XdgCachedMenu(MenuCache* menuCache, QWidget* parent): QMenu(parent) { // qDebug() << "CREATE MENU FROM CACHE" << menuCache; connect(this, SIGNAL(hovered(QAction*)), SLOT(onItemHovered(QAction*))); MenuCacheDir* dir = menu_cache_get_root_dir(menuCache); addMenuItems(this, dir); }
XdgCachedMenu::XdgCachedMenu(MenuCache* menuCache, QWidget* parent): QMenu(parent) { // qDebug() << "CREATE MENU FROM CACHE" << menuCache; MenuCacheDir* dir = menu_cache_get_root_dir(menuCache); addMenuItems(this, dir); connect(this, SIGNAL(aboutToShow()), SLOT(onAboutToShow())); }
void AppMenuView::onMenuCacheReload(MenuCache* mc) { MenuCacheDir* dir = menu_cache_dup_root_dir(mc); model_->clear(); /* FIXME: preserve original selection */ if(dir) { addMenuItems(NULL, dir); menu_cache_item_unref(MENU_CACHE_ITEM(dir)); selectionModel()->select(model_->index(0, 0), QItemSelectionModel::SelectCurrent); } }
bool PauseLayer:: init(GameLayer *gameLayer) { if (!CCLayer::init()) { return false; } float scale = Utility::isIPad() ? 1 : 0.5; gLayer = gameLayer; charMenuIemList = new CCArray; // Utility::addSpriteSheet("buttonTexture"); isCallFromRecords = true; winSize = CCDirector::sharedDirector()->getWinSize(); CCLayerColor *colorLayer = CCLayerColor::create(ccc4(50, 50, 50, 100), winSize.width , winSize.height ); addChild(colorLayer); if (gameLayer->sceneType == kSceneTypeGameScene) { addMenuItems("btnNewGame.png", 1); } addMenuItems("btnMenu.png", 2); CCMenu *btnMenu = CCMenu::createWithArray(charMenuIemList); btnMenu->alignItemsHorizontallyWithPadding(winSize.width * 0.05); btnMenu->setPosition(ccp(winSize.width * 0.2, winSize.height * 0.1)); addChild(btnMenu, 2); CCSprite *iconStar = CCSprite::createWithSpriteFrameName("coinsStars_4.png"); iconStar->setScale(0.8); iconStar->setPosition(ccp(winSize.width * 0.05, winSize.height * 0.92)); addChild(iconStar, 2); const char *totalStars = CCString::createWithFormat("%d", Utility::getTotalStars())->getCString(); CCLabelBMFont *starsLabel = CCLabelBMFont::create(totalStars, kFontChubby, 0); starsLabel->setPosition(ccp(iconStar->getPositionX() + winSize.width * 0.05, winSize.height * 0.92)); starsLabel->setScale(scale); addChild(starsLabel, 2); addObjectiveLayer(); hideHUDButtons(); //add resume button createButton("btnResume.png", 3, ccp(winSize.width * 0.9, winSize.height * 0.1)); // createButton("btnSound.png", 4, ccp(winSize.width * 0.95,winSize.height * 0.92)); return true; }
void fluid_menu::introFinished() { menu_items.clear(); addMenuItems(oss); populatePictureFlow(); }