core/vgui/impl/qt/vgui_qt_menu.cxx
Go to the documentation of this file.
00001 #include "vgui_qt_menu.h"
00002 #include <vcl_iostream.h>
00003 
00004 //---------------------------------------------------------------------------
00005 vgui_qt_menu::vgui_qt_menu(const vgui_menu& menu)
00006 : QPopupMenu()
00007 {
00008    connect(this, SIGNAL(activated(int)), this, SLOT(upon_activated(int)));
00009 
00010    //int i = 1;
00011    commands_ = new vgui_command_sptr[menu.size()];
00012    for (unsigned int i=0; i < menu.size(); ++i)
00013    {
00014       if (menu[i].is_separator())
00015       {
00016          insertSeparator();
00017       }
00018       else if (menu[i].is_command())
00019       {
00020          insertItem(menu[i].name.c_str(), i);
00021          commands_[i] = menu[i].cmnd;
00022       }
00023       else if (menu[i].is_submenu())
00024       {
00025          vgui_qt_menu* qm = new vgui_qt_menu(*(menu[i].menu));
00026          insertItem(menu[i].name.c_str(), (QPopupMenu*)qm, i);
00027       }
00028    }
00029 }
00030 
00031 
00032 //---------------------------------------------------------------------------
00033 void vgui_qt_menu::upon_activated(int id)
00034 {
00035 #ifdef DEBUG
00036    vcl_cerr << "upon_activated " << id << vcl_endl;
00037 #endif
00038    vgui_command_sptr c = commands_[id];
00039    c->execute();
00040 }