From 7ad4da516804d4c74c76344f18f8270660f38dfb Mon Sep 17 00:00:00 2001 From: Noldor Date: Tue, 26 Oct 2010 16:47:57 +0000 Subject: Code improvements in kvs class popupmenu git-svn-id: https://svn.kvirc.de/svn/trunk/kvirc@5114 17fca916-40b9-46aa-a4ea-0a15b648b75c --- src/modules/objects/class_popupmenu.cpp | 45 +++++++++++++++++++++++++++++++++ src/modules/objects/class_popupmenu.h | 2 +- 2 files changed, 46 insertions(+), 1 deletion(-) (limited to 'src/modules/objects') diff --git a/src/modules/objects/class_popupmenu.cpp b/src/modules/objects/class_popupmenu.cpp index aa3d50b17..f90674758 100644 --- a/src/modules/objects/class_popupmenu.cpp +++ b/src/modules/objects/class_popupmenu.cpp @@ -57,6 +57,9 @@ @functions: !fn: $insertItem(,[icon_id:string]) Inserts menu items into a popup menu with optional icon and return the popup identifier. + !fn: $addMenu() Sets the popupmenu title to text. !fn: $exec([,,]) @@ -169,6 +172,7 @@ KVSO_BEGIN_REGISTERCLASS(KviKvsObject_popupmenu,"popupmenu","widget") KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_popupmenu,exec) KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_popupmenu,insertSeparator) KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_popupmenu,removeItem) + KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_popupmenu,addMenu) // events KVSO_REGISTER_HANDLER_BY_NAME(KviKvsObject_popupmenu,highlightedEvent) @@ -255,6 +259,47 @@ KVSO_CLASS_FUNCTION(popupmenu,exec) return true; } + + +KVSO_CLASS_FUNCTION(popupmenu,addMenu) +{ + CHECK_INTERNAL_POINTER(widget()) + KviKvsObject *pObject; + kvs_uint_t iIdx; + kvs_hobject_t hObject; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("popupmenu",KVS_PT_HOBJECT,0,hObject) + KVSO_PARAMETER("index",KVS_PT_UNSIGNEDINTEGER,KVS_PF_OPTIONAL,iIdx) + KVSO_PARAMETERS_END(c) + pObject=KviKvsKernel::instance()->objectController()->lookupObject(hObject); + if (!pObject)\ + { + c->warning(__tr2qs_ctx("Popup menu parameter is not an object","objects"));\ + return true; + } + if (!pObject->object())\ + { + c->warning(__tr2qs_ctx("Popup menu parameter is not a valid object","objects"));\ + return true;\ + } + if(!pObject->inheritsClass("popupmenu"))\ + {\ + c->warning(__tr2qs_ctx("Popupmenu object required","objects"));\ + return true;\ + } + QAction *pAction; + if(iIdx) + { + QAction *pActionBefore=actionsDict[iIdx]; + pAction=((QMenu *)widget())->insertMenu(pActionBefore,(QMenu*)pObject->object()); + } + else pAction=((QMenu *)widget())->addMenu((QMenu*)pObject->object()); + actionsDict[identifier]=pAction; + c->returnValue()->setInteger(identifier); + identifier++; + return true; +} + KVSO_CLASS_FUNCTION(popupmenu,removeItem) { CHECK_INTERNAL_POINTER(widget()) diff --git a/src/modules/objects/class_popupmenu.h b/src/modules/objects/class_popupmenu.h index ed4dad066..287cfaaef 100644 --- a/src/modules/objects/class_popupmenu.h +++ b/src/modules/objects/class_popupmenu.h @@ -43,7 +43,7 @@ protected: int identifier; bool insertItem(KviKvsObjectFunctionCall *c); bool setTitle(KviKvsObjectFunctionCall *c); - //bool insertWidget(KviKvsObjectFunctionCall *c); + bool addMenu(KviKvsObjectFunctionCall *c); //bool insertHandle(KviKvsObjectFunctionCall *c); bool exec(KviKvsObjectFunctionCall *c); bool removeItem(KviKvsObjectFunctionCall *c); -- cgit v1.3.1-10-gc9f91