From 0a4cd04d6bbc1b97c41892a29eb02665f6d174c8 Mon Sep 17 00:00:00 2001 From: Noldor Date: Fri, 18 Apr 2008 21:04:11 +0000 Subject: more qt4 port (renamed QT3 stuff)) git-svn-id: https://svn.kvirc.de/svn/trunk/kvirc@1507 17fca916-40b9-46aa-a4ea-0a15b648b75c --- src/modules/objects/class_painter.cpp | 2 +- src/modules/objects/class_popupmenu.cpp | 770 ++++++++++++++++---------------- src/modules/objects/class_widget.cpp | 80 ++-- src/modules/objects/class_widget.h | 6 +- src/modules/objects/class_window.cpp | 6 +- src/modules/objects/class_window.h | 4 +- src/modules/objects/class_workspace.cpp | 2 +- 7 files changed, 447 insertions(+), 423 deletions(-) (limited to 'src/modules/objects') diff --git a/src/modules/objects/class_painter.cpp b/src/modules/objects/class_painter.cpp index bc2e41182..04ea9aa0c 100644 --- a/src/modules/objects/class_painter.cpp +++ b/src/modules/objects/class_painter.cpp @@ -364,7 +364,7 @@ const char * const brushstyles_tbl[] = { }[br] [br] %Hello=$new(hello)[br] - %Hello->$setcaption("Painter effects" );[br] + %Hello->$setWindowTitle("Painter effects" );[br] %Hello->$setFont(28,"times",bold);[br] %Btn=$new(button,%Hello)[br] %Btn->$setmaximumwidth(80)[br] diff --git a/src/modules/objects/class_popupmenu.cpp b/src/modules/objects/class_popupmenu.cpp index e15cbdbac..4745938ec 100644 --- a/src/modules/objects/class_popupmenu.cpp +++ b/src/modules/objects/class_popupmenu.cpp @@ -1,373 +1,373 @@ -//mdm : -// File : class_popupmenu.cpp -// Creation date : Mon Feb 01 21:30:48 CEST 2005 -// by Tonino Imbesi(Grifisx) and Alessandro Carbone(Noldor) -// Lucia Papini (^ashura^) English Translation. -// This file is part of the KVirc irc client distribution -// Copyright (C) 1999-2000 Szymon Stefanek (pragma at kvirc dot net) -// -// This program is FREE software. You can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your opinion) any later version. -// -// This program is distributed in the HOPE that it will be USEFUL, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -// See the GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, write to the Free Software Foundation, -// Inc. ,59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -// - - -#include "class_popupmenu.h" -#include "kvi_error.h" -#include "kvi_debug.h" -#include "kvi_locale.h" -#include "kvi_iconmanager.h" -#include "kvi_tal_popupmenu.h" - -#include -#include -#include - - - -/* - @doc: popupmenu - @keyterms: - popupmenu object class, - @title: - popupmenu class - @type: - class - @short: - Provides a popup menu. - @inherits: - [class]object[/class] - [class]widget[/class] - @description: - This widget can be used to display a popup menu.Technically, a popup menu consists of a list of menu items.[br] - You add items with insertItem(). An item is either a string. In addition, items can have an optional icon drawn on the very left side.[br] - @functions: - !fn: $insertItem(,[icon_id:string]) - Inserts menu items into a popup menu with optional icon and return the popup identifier. - !fn: $insertWidget()[br] - Inserts widget items int a popup menu and return the popup identifier.[br] - The widget is treats as a separator; this means that the item is not selectable and you can, for example, simply insert a label if you need a popup menu with a title. - !fn: $insertHandle(,,[icon]) - Inserts a submenu with optional icon into the popup menu. - !fn: $exec([,,]) - If called without paramaters show the popup menu at the current pointer position.[br] - With the optional parameters show the popup menu at the coordinate x,y widget parameter relative. - !fn: $removeItem() - Removes the menu item that has the identifier id. - !fn: $removeItemAt() - Removes the menu item at position index. - !fn: $insertSeparator() - Inserts a separator at position index.[br] - If the index is negative the separator becomes the last menu item. - !fn: $activatedEvent() - This function is called when a menu item and return the the item id.[br] - The default implementation emits the [classfnc]$activated[/classfnc]() signal. - !fn: $highligthtedEvent() - This function is called when a menu item is highlighted and return the item id.[br] - The default implementation emits the [classfnc]$highlighted[/classfnc]() signal. - @signals: - !sg: $activated() - This signal is emitted by the default implementation of [classfnc]$activatedEvent[/classfnc](). - !sg: $highlighted() - This signal is emitted by the default implementation of [classfnc]$highlightedEvent[/classfnc](). - [br] - |-EXAMPLE POPUP MENU-|[br] - |--Start: - # First of all we create an array wich will be used to create random colors.[br] - %Hex[]=$array(0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F)[br] - [br] - class (ws,widget)[br] - {[br] - #In the constructor we create everything that belong to the single widget.[br] - constructor[br] - {[br] - #Geometry of the widget and setting-up of popupmenu [br] - $$->$setGeometry(%X,%Y,100,100)[br] - $$->%lay=$new(layout,$$)[br] - #Here we generate a cicle to create our labels inside the widget.[br] - %i=0[br] - while (%i<10)[br] - {[br] - $$->%label=$new(label,$$)[br] - $$->%label->$settext("Another class by N\&G")[br] - #We set our foreground's coulor using the hex arrey in random way.[br] - %color=%Hex[$rand(14)]%Hex[$rand(14)]%Hex[$rand(14)]%Hex[$rand(14)]%Hex[$rand(14)]%Hex[$rand(14)][br] - $$->%label->$setforegroundcolor(%color)[br] - $$->%label->$setautoresize(1)[br] - #We add the label to the widget's popupmenu.[br] - $$->%lay->$addwidget($$->%label,%i,0)[br] - %i++;[br] - }[br] - #We make the popupmenu relative to this widget: this is merely demonstrative.[br] - #because it creates 25 identical popups.[br] - $$->%Popupmenu=$new(popupmenu,$$)[br] - #we create the label widget wich will be used as popup's title[br] - $$->%Popuptitle=$new(label)[br] - $$->%Popuptitle->$settext("Windows Options")[br] - $$->%Popuptitle->$setAlignment(Center)[br] - #and we add it.[br] - %A=$$->%Popuptitle[br] - $$->%Popupmenu->$insertwidget(%A)[br] - #Here we keep the various IDs in the arrays[br] - %Tile[%I]=$$->%Popupmenu->$insertItem("Tile",118)[br] - %Cascade[%I]=$$->%Popupmenu->$insertItem("Cascade",115)[br] - $$->%Popupmenu->$insertSeparator(3)[br] - %Closeactw[%I]=$$->%Popupmenu->$insertItem("Close Active Window",08)[br] - %Closeallw[%I]=$$->%Popupmenu->$insertItem("Close All Window",58)[br] - $$->$show()[br] - privateimpl($$->%Popupmenu,activatedEvent)[br] - {[br] - %id=$0[br] - %i = 0[br] - #with this cicle we control wich of the items has been called comparing the id given back by the event with our arrays created before;[br] - while (%i<20)[br] - {[br] - if (%id == %Tile[%i]) return %Workspace->$tile()[br] - if (%id == %Cascade[%i]) return %Workspace->$cascade()[br] - if (%id == %Closeactw[%i]) return %Workspace->$closeactivewindow()[br] - if (%id == %Closeallw[%i]) return %Workspace->$closeallwindows()[br] - %i ++[br] - }[br] - }[br] - }[br] - #we activate the popup pushing the right mouse button on the widget[br] - mousepressevent[br] - {[br] - if ($0 == 1) $$->%Popupmenu->$exec()[br] - }[br] - }[br] - %Workspace=$new(workspace)[br] - %Workspace->$resize(640,480)[br] - %I=0[br] - %Cicle=1[br] - while (%I<20)[br] - {[br] - %X=$rand(500)[br] - %Y=$rand(480)[br] - %Widget=$new(ws,%Workspace)[br] - %I++[br] - }[br] - #Let's show! - %Workspace->$show[br] - |--End.[br][br] -*/ - -KVSO_BEGIN_REGISTERCLASS(KviKvsObject_popupmenu,"popupmenu","widget") - KVSO_REGISTER_HANDLER(KviKvsObject_popupmenu,"insertItem", functioninsertItem) - //KVSO_REGISTER_HANDLER(KviKvsObject_popupmenu,"insertWidget", functioninsertWidget) -// KVSO_REGISTER_HANDLER(KviKvsObject_popupmenu,"setTitle", functionsetTitle) - KVSO_REGISTER_HANDLER(KviKvsObject_popupmenu,"exec", functionexec) - KVSO_REGISTER_HANDLER(KviKvsObject_popupmenu,"insertSeparator", functioninsertSeparator) - KVSO_REGISTER_HANDLER(KviKvsObject_popupmenu,"removeItem", functionremoveItem) - - // events - KVSO_REGISTER_HANDLER(KviKvsObject_popupmenu,"highlightedEvent", functionhighlightedEvent) - KVSO_REGISTER_HANDLER(KviKvsObject_popupmenu,"activatedEvent", functionactivatedEvent) - -KVSO_END_REGISTERCLASS(KviKvsObject_popupmenu) - -KVSO_BEGIN_CONSTRUCTOR(KviKvsObject_popupmenu,KviKvsObject_widget) - -KVSO_END_CONSTRUCTOR(KviKvsObject_popupmenu) - - -KVSO_BEGIN_DESTRUCTOR(KviKvsObject_popupmenu) - -KVSO_END_CONSTRUCTOR(KviKvsObject_popupmenu) - -bool KviKvsObject_popupmenu::init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams) -{ - identifier=0; - SET_OBJECT(QMenu) - connect(widget(),SIGNAL(triggered(QAction *)),this,SLOT(slottriggered(QAction *))); - connect(widget(),SIGNAL(highlighted(int)),this,SLOT(slothighlighted(int))); - return true; -} - -bool KviKvsObject_popupmenu::functioninsertItem(KviKvsObjectFunctionCall *c) -{ - QString szItem,szIcon; - KVSO_PARAMETERS_BEGIN(c) - KVSO_PARAMETER("text",KVS_PT_STRING,0,szItem) - KVSO_PARAMETER("icon_id",KVS_PT_STRING,KVS_PF_OPTIONAL,szIcon) - KVSO_PARAMETERS_END(c) - if(!widget())return true; - QPixmap *pix = 0; - int id=0; - QAction * action; - if(!szIcon.isEmpty()) - { - pix = g_pIconManager->getImage(szIcon); - if (pix) action=((QMenu *)widget())->addAction(*pix,szItem); - else c->warning(__tr2qs("pix '%Q' doesn't exists"),&szIcon); - - } - else - action=((QMenu *)widget())->addAction(szItem); - actionsDict[identifier]=action; - c->returnValue()->setInteger(identifier); - identifier++; - return true; -} -/* -bool KviKvsObject_popupmenu::functionsetTitle(KviKvsObjectFunctionCall *c) -{ - QString szTitle; - KVSO_PARAMETERS_BEGIN(c) - KVSO_PARAMETER("title",KVS_PT_STRING,0,szTitle) - KVSO_PARAMETERS_END(c) - if(!widget())return true; - ((QMenu *)widget())->setTitle(szTitle); - - return true; -} -/* -bool KviKvsObject_popupmenu::functioninsertWidget(KviKvsObjectFunctionCall *c) -{ - KviKvsObject *pObject; - kvs_hobject_t hObject; - KVSO_PARAMETERS_BEGIN(c) - KVSO_PARAMETER("widget",KVS_PT_HOBJECT,0,hObject) - KVSO_PARAMETERS_END(c) - pObject=KviKvsKernel::instance()->objectController()->lookupObject(hObject); - if (!pObject) - { - c->warning(__tr2qs("Widget parameter is not an object")); - return true; - } - if (!pObject->object()) - { - c->warning(__tr2qs("Widget parameter is not a valid object")); - return true; - } - if(!pObject->object()->isWidgetType()) - { - c->warning(__tr2qs("Can't add a non-widget object")); - return TRUE; - } - if (widget()) ((KviTalPopupMenu *)widget())->insertItem(((KviTalPopupMenu *)(pObject->object()))); - return true; -} - - -bool KviKvsObject_popupmenu::functioninsertHandle(KviKvsObjectFunctionCall *c) -{ - KviKvsObject *ob; - QString szLabel,szIcon; - kvs_hobject_t hObject; - KVSO_PARAMETERS_BEGIN(c) - KVSO_PARAMETER("text_label",KVS_PT_STRING,0,szLabel) - KVSO_PARAMETER("widget",KVS_PT_HOBJECT,0,hObject) - KVSO_PARAMETER("icon_id",KVS_PT_STRING,KVS_PF_OPTIONAL,szIcon) - KVSO_PARAMETERS_END(c) - ob=KviKvsKernel::instance()->objectController()->lookupObject(hObject); - if(!ob->object()->inherits("KviKvsObject_popupmenu")) - { - c->warning(__tr2qs("Can't add a non - popupmenu object")); - return TRUE; - } - if(!widget())return true; - QPixmap *pix = 0; - int id=0; - if(!szIcon.isEmpty()) - { - pix = g_pIconManager->getImage(szIcon); - if (pix) id=((KviTalPopupMenu *)widget())->insertItem(*pix,szLabel,((KviTalPopupMenu *)(ob->object()))); - else c->warning(__tr2qs("pix '%Q' doesn't exists"),&szIcon); - - } - else - id=((KviTalPopupMenu *)widget())->insertItem(szLabel,((KviTalPopupMenu *)(ob->object()))); - c->returnValue()->setInteger(id); - return true; -} -*/ -bool KviKvsObject_popupmenu::functionexec(KviKvsObjectFunctionCall *c) -{ - if(!c->params()->count()) - { - ((QMenu *)widget())->exec(QCursor::pos()); - return true; - } - - KviKvsObject *pObject; - kvs_uint_t iX,iY; - QString szLabel,szIcon; - kvs_hobject_t hObject; - KVSO_PARAMETERS_BEGIN(c) - KVSO_PARAMETER("widget",KVS_PT_HOBJECT,0,hObject) - KVSO_PARAMETER("x",KVS_PT_UNSIGNEDINTEGER,0,iX) - KVSO_PARAMETER("y",KVS_PT_UNSIGNEDINTEGER,0,iY) - KVSO_PARAMETERS_END(c) - pObject=KviKvsKernel::instance()->objectController()->lookupObject(hObject); - if (!pObject) - { - c->warning(__tr2qs("Widget parameter is not an object")); - return true; - } - if (!pObject->object()) - { - c->warning(__tr2qs("Widget parameter is not a valid object")); - return true; - } - if(!pObject->object()->isWidgetType()) - { - c->warning(__tr2qs("Doesn't a widget object")); - return true; - } - - ((QMenu *)widget())->exec(((QWidget *)(pObject->object()))->mapToGlobal(QPoint(iX,iY)) ); - - return true; -} -bool KviKvsObject_popupmenu::functionremoveItem(KviKvsObjectFunctionCall *c) -{ - kvs_uint_t uItem; - KVSO_PARAMETERS_BEGIN(c) - KVSO_PARAMETER("item_id",KVS_PT_UNSIGNEDINTEGER,0,uItem) - KVSO_PARAMETERS_END(c) - QAction * action=actionsDict.value(uItem); - if(widget() && action){ - ((QMenu *)widget())->removeAction(action); - identifier--; - } - return true; -} - - -bool KviKvsObject_popupmenu::functioninsertSeparator(KviKvsObjectFunctionCall *c) -{ - kvs_uint_t iIndex; - KVSO_PARAMETERS_BEGIN(c) - KVSO_PARAMETER("index",KVS_PT_UNSIGNEDINTEGER,0,iIndex) - KVSO_PARAMETERS_END(c) - QAction * action=actionsDict.value(iIndex); - if(widget()&& action)((QMenu *)widget())->insertSeparator(action); - return true; -} - -void KviKvsObject_popupmenu::slothighlighted(int i) -{ - KviKvsVariantList params(new KviKvsVariant((kvs_int_t)i)); - callFunction(this,"highlightedEvent",¶ms); -} -bool KviKvsObject_popupmenu::functionhighlightedEvent(KviKvsObjectFunctionCall *c) -{ - emitSignal("highlighted",c,c->params()); - return true; -} -void KviKvsObject_popupmenu::slottriggered(QAction *a) -{ +//mdm : +// File : class_popupmenu.cpp +// Creation date : Mon Feb 01 21:30:48 CEST 2005 +// by Tonino Imbesi(Grifisx) and Alessandro Carbone(Noldor) +// Lucia Papini (^ashura^) English Translation. +// This file is part of the KVirc irc client distribution +// Copyright (C) 1999-2000 Szymon Stefanek (pragma at kvirc dot net) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your opinion) any later version. +// +// This program is distributed in the HOPE that it will be USEFUL, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, write to the Free Software Foundation, +// Inc. ,59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// + + +#include "class_popupmenu.h" +#include "kvi_error.h" +#include "kvi_debug.h" +#include "kvi_locale.h" +#include "kvi_iconmanager.h" +#include "kvi_tal_popupmenu.h" + +#include +#include +#include + + + +/* + @doc: popupmenu + @keyterms: + popupmenu object class, + @title: + popupmenu class + @type: + class + @short: + Provides a popup menu. + @inherits: + [class]object[/class] + [class]widget[/class] + @description: + This widget can be used to display a popup menu.Technically, a popup menu consists of a list of menu items.[br] + You add items with insertItem(). An item is either a string. In addition, items can have an optional icon drawn on the very left side.[br] + @functions: + !fn: $insertItem(,[icon_id:string]) + Inserts menu items into a popup menu with optional icon and return the popup identifier. + !fn: $insertWidget()[br] + Inserts widget items int a popup menu and return the popup identifier.[br] + The widget is treats as a separator; this means that the item is not selectable and you can, for example, simply insert a label if you need a popup menu with a title. + !fn: $insertHandle(,,[icon]) + Inserts a submenu with optional icon into the popup menu. + !fn: $exec([,,]) + If called without paramaters show the popup menu at the current pointer position.[br] + With the optional parameters show the popup menu at the coordinate x,y widget parameter relative. + !fn: $removeItem() + Removes the menu item that has the identifier id. + !fn: $removeItemAt() + Removes the menu item at position index. + !fn: $insertSeparator() + Inserts a separator at position index.[br] + If the index is negative the separator becomes the last menu item. + !fn: $activatedEvent() + This function is called when a menu item and return the the item id.[br] + The default implementation emits the [classfnc]$activated[/classfnc]() signal. + !fn: $highligthtedEvent() + This function is called when a menu item is highlighted and return the item id.[br] + The default implementation emits the [classfnc]$highlighted[/classfnc]() signal. + @signals: + !sg: $activated() + This signal is emitted by the default implementation of [classfnc]$activatedEvent[/classfnc](). + !sg: $highlighted() + This signal is emitted by the default implementation of [classfnc]$highlightedEvent[/classfnc](). + [br] + |-EXAMPLE POPUP MENU-|[br] + |--Start: + # First of all we create an array wich will be used to create random colors.[br] + %Hex[]=$array(0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F)[br] + [br] + class (ws,widget)[br] + {[br] + #In the constructor we create everything that belong to the single widget.[br] + constructor[br] + {[br] + #Geometry of the widget and setting-up of popupmenu [br] + $$->$setGeometry(%X,%Y,100,100)[br] + $$->%lay=$new(layout,$$)[br] + #Here we generate a cicle to create our labels inside the widget.[br] + %i=0[br] + while (%i<10)[br] + {[br] + $$->%label=$new(label,$$)[br] + $$->%label->$settext("Another class by N\&G")[br] + #We set our foreground's coulor using the hex arrey in random way.[br] + %color=%Hex[$rand(14)]%Hex[$rand(14)]%Hex[$rand(14)]%Hex[$rand(14)]%Hex[$rand(14)]%Hex[$rand(14)][br] + $$->%label->$setforegroundcolor(%color)[br] + $$->%label->$setautoresize(1)[br] + #We add the label to the widget's popupmenu.[br] + $$->%lay->$addwidget($$->%label,%i,0)[br] + %i++;[br] + }[br] + #We make the popupmenu relative to this widget: this is merely demonstrative.[br] + #because it creates 25 identical popups.[br] + $$->%Popupmenu=$new(popupmenu,$$)[br] + #we create the label widget wich will be used as popup's title[br] + $$->%Popuptitle=$new(label)[br] + $$->%Popuptitle->$settext("Windows Options")[br] + $$->%Popuptitle->$setAlignment(Center)[br] + #and we add it.[br] + %A=$$->%Popuptitle[br] + $$->%Popupmenu->$insertwidget(%A)[br] + #Here we keep the various IDs in the arrays[br] + %Tile[%I]=$$->%Popupmenu->$insertItem("Tile",118)[br] + %Cascade[%I]=$$->%Popupmenu->$insertItem("Cascade",115)[br] + $$->%Popupmenu->$insertSeparator(3)[br] + %Closeactw[%I]=$$->%Popupmenu->$insertItem("Close Active Window",08)[br] + %Closeallw[%I]=$$->%Popupmenu->$insertItem("Close All Window",58)[br] + $$->$show()[br] + privateimpl($$->%Popupmenu,activatedEvent)[br] + {[br] + %id=$0[br] + %i = 0[br] + #with this cicle we control wich of the items has been called comparing the id given back by the event with our arrays created before;[br] + while (%i<20)[br] + {[br] + if (%id == %Tile[%i]) return %Workspace->$tile()[br] + if (%id == %Cascade[%i]) return %Workspace->$cascade()[br] + if (%id == %Closeactw[%i]) return %Workspace->$closeactivewindow()[br] + if (%id == %Closeallw[%i]) return %Workspace->$closeallwindows()[br] + %i ++[br] + }[br] + }[br] + }[br] + #we activate the popup pushing the right mouse button on the widget[br] + mousepressevent[br] + {[br] + if ($0 == 1) $$->%Popupmenu->$exec()[br] + }[br] + }[br] + %Workspace=$new(workspace)[br] + %Workspace->$resize(640,480)[br] + %I=0[br] + %Cicle=1[br] + while (%I<20)[br] + {[br] + %X=$rand(500)[br] + %Y=$rand(480)[br] + %Widget=$new(ws,%Workspace)[br] + %I++[br] + }[br] + #Let's show! + %Workspace->$show[br] + |--End.[br][br] +*/ + +KVSO_BEGIN_REGISTERCLASS(KviKvsObject_popupmenu,"popupmenu","widget") + KVSO_REGISTER_HANDLER(KviKvsObject_popupmenu,"insertItem", functioninsertItem) + //KVSO_REGISTER_HANDLER(KviKvsObject_popupmenu,"insertWidget", functioninsertWidget) +// KVSO_REGISTER_HANDLER(KviKvsObject_popupmenu,"setTitle", functionsetTitle) + KVSO_REGISTER_HANDLER(KviKvsObject_popupmenu,"exec", functionexec) + KVSO_REGISTER_HANDLER(KviKvsObject_popupmenu,"insertSeparator", functioninsertSeparator) + KVSO_REGISTER_HANDLER(KviKvsObject_popupmenu,"removeItem", functionremoveItem) + + // events + KVSO_REGISTER_HANDLER(KviKvsObject_popupmenu,"highlightedEvent", functionhighlightedEvent) + KVSO_REGISTER_HANDLER(KviKvsObject_popupmenu,"activatedEvent", functionactivatedEvent) + +KVSO_END_REGISTERCLASS(KviKvsObject_popupmenu) + +KVSO_BEGIN_CONSTRUCTOR(KviKvsObject_popupmenu,KviKvsObject_widget) + +KVSO_END_CONSTRUCTOR(KviKvsObject_popupmenu) + + +KVSO_BEGIN_DESTRUCTOR(KviKvsObject_popupmenu) + +KVSO_END_CONSTRUCTOR(KviKvsObject_popupmenu) + +bool KviKvsObject_popupmenu::init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams) +{ + identifier=0; + SET_OBJECT(QMenu) + connect(widget(),SIGNAL(triggered(QAction *)),this,SLOT(slottriggered(QAction *))); + connect(widget(),SIGNAL(highlighted(int)),this,SLOT(slothighlighted(int))); + return true; +} + +bool KviKvsObject_popupmenu::functioninsertItem(KviKvsObjectFunctionCall *c) +{ + QString szItem,szIcon; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("text",KVS_PT_STRING,0,szItem) + KVSO_PARAMETER("icon_id",KVS_PT_STRING,KVS_PF_OPTIONAL,szIcon) + KVSO_PARAMETERS_END(c) + if(!widget())return true; + QPixmap *pix = 0; + int id=0; + QAction * action; + if(!szIcon.isEmpty()) + { + pix = g_pIconManager->getImage(szIcon); + if (pix) action=((QMenu *)widget())->addAction(*pix,szItem); + else c->warning(__tr2qs("pix '%Q' doesn't exists"),&szIcon); + + } + else + action=((QMenu *)widget())->addAction(szItem); + actionsDict[identifier]=action; + c->returnValue()->setInteger(identifier); + identifier++; + return true; +} +/* +bool KviKvsObject_popupmenu::functionsetTitle(KviKvsObjectFunctionCall *c) +{ + QString szTitle; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("title",KVS_PT_STRING,0,szTitle) + KVSO_PARAMETERS_END(c) + if(!widget())return true; + ((QMenu *)widget())->setTitle(szTitle); + + return true; +} +/* +bool KviKvsObject_popupmenu::functioninsertWidget(KviKvsObjectFunctionCall *c) +{ + KviKvsObject *pObject; + kvs_hobject_t hObject; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("widget",KVS_PT_HOBJECT,0,hObject) + KVSO_PARAMETERS_END(c) + pObject=KviKvsKernel::instance()->objectController()->lookupObject(hObject); + if (!pObject) + { + c->warning(__tr2qs("Widget parameter is not an object")); + return true; + } + if (!pObject->object()) + { + c->warning(__tr2qs("Widget parameter is not a valid object")); + return true; + } + if(!pObject->object()->isWidgetType()) + { + c->warning(__tr2qs("Can't add a non-widget object")); + return TRUE; + } + if (widget()) ((KviTalPopupMenu *)widget())->insertItem(((KviTalPopupMenu *)(pObject->object()))); + return true; +} + + +bool KviKvsObject_popupmenu::functioninsertHandle(KviKvsObjectFunctionCall *c) +{ + KviKvsObject *ob; + QString szLabel,szIcon; + kvs_hobject_t hObject; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("text_label",KVS_PT_STRING,0,szLabel) + KVSO_PARAMETER("widget",KVS_PT_HOBJECT,0,hObject) + KVSO_PARAMETER("icon_id",KVS_PT_STRING,KVS_PF_OPTIONAL,szIcon) + KVSO_PARAMETERS_END(c) + ob=KviKvsKernel::instance()->objectController()->lookupObject(hObject); + if(!ob->object()->inherits("KviKvsObject_popupmenu")) + { + c->warning(__tr2qs("Can't add a non - popupmenu object")); + return TRUE; + } + if(!widget())return true; + QPixmap *pix = 0; + int id=0; + if(!szIcon.isEmpty()) + { + pix = g_pIconManager->getImage(szIcon); + if (pix) id=((KviTalPopupMenu *)widget())->insertItem(*pix,szLabel,((KviTalPopupMenu *)(ob->object()))); + else c->warning(__tr2qs("pix '%Q' doesn't exists"),&szIcon); + + } + else + id=((KviTalPopupMenu *)widget())->insertItem(szLabel,((KviTalPopupMenu *)(ob->object()))); + c->returnValue()->setInteger(id); + return true; +} +*/ +bool KviKvsObject_popupmenu::functionexec(KviKvsObjectFunctionCall *c) +{ + if(!c->params()->count()) + { + ((QMenu *)widget())->exec(QCursor::pos()); + return true; + } + + KviKvsObject *pObject; + kvs_uint_t iX,iY; + QString szLabel,szIcon; + kvs_hobject_t hObject; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("widget",KVS_PT_HOBJECT,0,hObject) + KVSO_PARAMETER("x",KVS_PT_UNSIGNEDINTEGER,0,iX) + KVSO_PARAMETER("y",KVS_PT_UNSIGNEDINTEGER,0,iY) + KVSO_PARAMETERS_END(c) + pObject=KviKvsKernel::instance()->objectController()->lookupObject(hObject); + if (!pObject) + { + c->warning(__tr2qs("Widget parameter is not an object")); + return true; + } + if (!pObject->object()) + { + c->warning(__tr2qs("Widget parameter is not a valid object")); + return true; + } + if(!pObject->object()->isWidgetType()) + { + c->warning(__tr2qs("Doesn't a widget object")); + return true; + } + + ((QMenu *)widget())->exec(((QWidget *)(pObject->object()))->mapToGlobal(QPoint(iX,iY)) ); + + return true; +} +bool KviKvsObject_popupmenu::functionremoveItem(KviKvsObjectFunctionCall *c) +{ + kvs_uint_t uItem; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("item_id",KVS_PT_UNSIGNEDINTEGER,0,uItem) + KVSO_PARAMETERS_END(c) + QAction * action=actionsDict.value(uItem); + if(widget() && action){ + ((QMenu *)widget())->removeAction(action); + identifier--; + } + return true; +} + + +bool KviKvsObject_popupmenu::functioninsertSeparator(KviKvsObjectFunctionCall *c) +{ + kvs_uint_t iIndex; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("index",KVS_PT_UNSIGNEDINTEGER,0,iIndex) + KVSO_PARAMETERS_END(c) + QAction * action=actionsDict.value(iIndex); + if(widget()&& action)((QMenu *)widget())->insertSeparator(action); + return true; +} + +void KviKvsObject_popupmenu::slothighlighted(int i) +{ + KviKvsVariantList params(new KviKvsVariant((kvs_int_t)i)); + callFunction(this,"highlightedEvent",¶ms); +} +bool KviKvsObject_popupmenu::functionhighlightedEvent(KviKvsObjectFunctionCall *c) +{ + emitSignal("highlighted",c,c->params()); + return true; +} +void KviKvsObject_popupmenu::slottriggered(QAction *a) +{ QHashIterator i(actionsDict); kvs_int_t count=0; bool found=false; @@ -376,18 +376,18 @@ void KviKvsObject_popupmenu::slottriggered(QAction *a) i.next(); if (i.value()!= a) count++; else break; - } - KviKvsVariantList params(new KviKvsVariant(count)); - callFunction(this,"activatedEvent",¶ms); -} -bool KviKvsObject_popupmenu::functionactivatedEvent(KviKvsObjectFunctionCall *c) -{ - emitSignal("activated",c,c->params()); - return true; -} - - -#ifndef COMPILE_USE_STANDALONE_MOC_SOURCES -#include "m_class_popupmenu.moc" -#endif //!COMPILE_USE_STANDALONE_MOC_SOURCES - + } + KviKvsVariantList params(new KviKvsVariant(count)); + callFunction(this,"activatedEvent",¶ms); +} +bool KviKvsObject_popupmenu::functionactivatedEvent(KviKvsObjectFunctionCall *c) +{ + emitSignal("activated",c,c->params()); + return true; +} + + +#ifndef COMPILE_USE_STANDALONE_MOC_SOURCES +#include "m_class_popupmenu.moc" +#endif //!COMPILE_USE_STANDALONE_MOC_SOURCES + diff --git a/src/modules/objects/class_widget.cpp b/src/modules/objects/class_widget.cpp index 2c7c7b3b9..eb3b9cda0 100644 --- a/src/modules/objects/class_widget.cpp +++ b/src/modules/objects/class_widget.cpp @@ -231,13 +231,13 @@ const Qt::WindowType widgettypes_cod[] = { !fn: $setEnabled() Sets the widget state to enabled or disabled if is 1 or 0 respectively. A disabled widget does not receive keyboard nor mouse input. - !fn: $setCaption() - Sets the caption of this widget to . + !fn: $setWindowTitle() + Sets the title of this widget to . This is meaningful for toplevel widgets only. !fn: $setToolTip() Set the tooltip of this widget; the text can contain HTML formatting. - !fn: $window.caption() - Returns the caption text of this widget. + !fn: $windowTitle() + Returns the title text of this widget. !fn: $isTopLevel() Returns '1' if this widget is a toplevel (parentless) one, '0' otherwise. @@ -379,7 +379,7 @@ const Qt::WindowType widgettypes_cod[] = { If you call "[cmd]return[/cmd] $true" you will stop the internal processing of this event. The default implementation does nothing. - !fn: $setIcon() + !fn: $setWindowIcon() Sets the icon for this widget. This is meaningful only for toplevel widgets. See the [doc:image_id]image identifier[/doc] documentation for the explaination of the parameter. @@ -515,7 +515,7 @@ const Qt::WindowType widgettypes_cod[] = { %Widget = $new(widget) # This is the main container for other elements. - %Widget->$setCaption("This is the widget title") + %Widget->$setWindowTitle("This is the widget title") %Widget->$setGeometry(100,200,170,290) # 100 and 200 are distance (pixel) from the left and the top of father widget (in this case the KVIrc window) @@ -620,13 +620,15 @@ KVSO_BEGIN_REGISTERCLASS(KviKvsObject_widget,"widget","object") KVSO_REGISTER_HANDLER(KviKvsObject_widget,"setEnabled",function_setEnabled) KVSO_REGISTER_HANDLER(KviKvsObject_widget,"isEnabled",function_isEnabled) KVSO_REGISTER_HANDLER(KviKvsObject_widget,"setMouseTracking",function_setMouseTracking) - KVSO_REGISTER_HANDLER(KviKvsObject_widget,"setCaption",function_setCaption) - KVSO_REGISTER_HANDLER(KviKvsObject_widget,"caption",function_caption) + KVSO_REGISTER_HANDLER(KviKvsObject_widget,"setCaption",function_setWindowTitle) + KVSO_REGISTER_HANDLER(KviKvsObject_widget,"setWindowTitle",function_setWindowTitle) + KVSO_REGISTER_HANDLER(KviKvsObject_widget,"windowTitle",function_windowTitle) + KVSO_REGISTER_HANDLER(KviKvsObject_widget,"caption",function_windowTitle) KVSO_REGISTER_HANDLER(KviKvsObject_widget,"hasFocus",function_hasFocus) KVSO_REGISTER_HANDLER(KviKvsObject_widget,"setFocus",function_setFocus) KVSO_REGISTER_HANDLER(KviKvsObject_widget,"setToolTip",function_setToolTip) KVSO_REGISTER_HANDLER(KviKvsObject_widget,"setWFlags",function_setWFlags) - KVSO_REGISTER_HANDLER(KviKvsObject_widget,"setIcon",function_setIcon) + KVSO_REGISTER_HANDLER(KviKvsObject_widget,"setIcon",function_setWindowIcon) // fonts KVSO_REGISTER_HANDLER(KviKvsObject_widget,"fontDescent",function_fontDescent) KVSO_REGISTER_HANDLER(KviKvsObject_widget,"fontAscent",function_fontAscent) @@ -1028,7 +1030,6 @@ bool KviKvsObject_widget::function_fontMetricsWidth(KviKvsObjectFunctionCall * c KVSO_PARAMETER("string",KVS_PT_STRING,0,m_szStr) KVSO_PARAMETERS_END(c) if(!widget()) return true; -// int fm = widget()->fontMetrics().width(m_szStr); c->returnValue()->setInteger(widget()->fontMetrics().width(m_szStr)); return true; } @@ -1209,7 +1210,9 @@ bool KviKvsObject_widget::function_setPaletteForeground(KviKvsObjectFunctionCall return false; } - } else { + } + else + { if (c->params()->count()==1) { bool bOk,bOk1,bOk2; @@ -1232,8 +1235,13 @@ bool KviKvsObject_widget::function_setPaletteForeground(KviKvsObjectFunctionCall c->warning(__tr2qs("Not an hex digits")); return true; } - if (widget()) widget()->setPaletteForegroundColor(QColor(iColR,iColG,iColB)); - return true; + if (widget()) + { + QPalette p = widget()->palette(); + p.setColor(widget()->foregroundRole(), QColor(iColR,iColG,iColB)); + widget()->setPalette(p); + return true; + } } if(c->params()->count() < 3) @@ -1248,7 +1256,13 @@ bool KviKvsObject_widget::function_setPaletteForeground(KviKvsObjectFunctionCall return false; } } - if (widget()) widget()->setPaletteForegroundColor(QColor(iColR,iColG,iColB)); + + if (widget()) + { + QPalette p = widget()->palette(); + p.setColor(widget()->foregroundRole(), QColor(iColR,iColG,iColB)); + widget()->setPalette(p); + } return true; } @@ -1309,7 +1323,12 @@ bool KviKvsObject_widget::function_setBackgroundColor(KviKvsObjectFunctionCall * c->warning(__tr2qs("Not an hex digits")); return true; } - if (widget()) widget()->setBackgroundColor(QColor(iColR,iColG,iColB)); + if (widget()) + { + QPalette p = widget()->palette(); + p.setColor(widget()->backgroundRole(), QColor(iColR,iColG,iColB)); + widget()->setPalette(p); + } return true; } @@ -1325,14 +1344,19 @@ bool KviKvsObject_widget::function_setBackgroundColor(KviKvsObjectFunctionCall * return false; } } - if (widget()) widget()->setBackgroundColor(QColor(iColR,iColG,iColB)); + if (widget()) + { + QPalette p = widget()->palette(); + p.setColor(widget()->backgroundRole(), QColor(iColR,iColG,iColB)); + widget()->setPalette(p); + } return true; } bool KviKvsObject_widget::function_backgroundColor(KviKvsObjectFunctionCall *c) { if(!widget())return true; - QColor col = widget()->backgroundColor(); + QColor col = widget()->palette().color(widget()->backgroundRole()); KviKvsArray * a = new KviKvsArray(); a->set(0,new KviKvsVariant((kvs_int_t)col.red())); a->set(1,new KviKvsVariant((kvs_int_t)col.green())); @@ -1344,7 +1368,7 @@ bool KviKvsObject_widget::function_backgroundColor(KviKvsObjectFunctionCall *c) bool KviKvsObject_widget::function_foregroundColor(KviKvsObjectFunctionCall *c) { if(!widget())return true; - QColor col = widget()->foregroundColor(); + QColor col = widget()->palette().color(widget()->foregroundRole()); KviKvsArray * a = new KviKvsArray(); a->set(0,new KviKvsVariant((kvs_int_t)col.red())); a->set(1,new KviKvsVariant((kvs_int_t)col.green())); @@ -1372,19 +1396,19 @@ bool KviKvsObject_widget::function_setMouseTracking(KviKvsObjectFunctionCall *c) return true; } -bool KviKvsObject_widget::function_setCaption(KviKvsObjectFunctionCall *c) +bool KviKvsObject_widget::function_setWindowTitle(KviKvsObjectFunctionCall *c) { - QString szCaption; + QString szWindowTitle; KVSO_PARAMETERS_BEGIN(c) - KVSO_PARAMETER("caption",KVS_PT_STRING,0,szCaption) + KVSO_PARAMETER("title",KVS_PT_STRING,0,szWindowTitle) KVSO_PARAMETERS_END(c) - if(widget()) widget()->setCaption(szCaption); + if(widget()) widget()->setWindowTitle(szWindowTitle); return true; } -bool KviKvsObject_widget::function_caption(KviKvsObjectFunctionCall *c) +bool KviKvsObject_widget::function_windowTitle(KviKvsObjectFunctionCall *c) { - if(widget()) c->returnValue()->setString(widget()->caption().toUtf8().data()); + if(widget()) c->returnValue()->setString(widget()->windowTitle().toUtf8().data()); return true; } @@ -1632,7 +1656,6 @@ bool KviKvsObject_widget::function_setFocusPolicy(KviKvsObjectFunctionCall *c) bool KviKvsObject_widget::function_setWFlags(KviKvsObjectFunctionCall *c) { QStringList wflags; - //Qt::WindowType sum; KVSO_PARAMETERS_BEGIN(c) KVSO_PARAMETER("widget_flags",KVS_PT_STRINGLIST,KVS_PF_OPTIONAL,wflags) KVSO_PARAMETERS_END(c) @@ -1719,9 +1742,10 @@ bool KviKvsObject_widget::function_addWidgetToWrappedLayout(KviKvsObjectFunction c->warning(__tr2qs("Can't add a non-widget object")); return true; } - lay->add(((QWidget *)(ob->object()))); + lay->addWidget(((QWidget *)(ob->object()))); return true; } +//FIXME bool KviKvsObject_widget::function_reparent(KviKvsObjectFunctionCall *c) { KviKvsObject *ob; @@ -1745,7 +1769,7 @@ bool KviKvsObject_widget::function_reparent(KviKvsObjectFunctionCall *c) widget()->reparent(((QWidget *)(ob->object())),QPoint(((QWidget *)(ob->object()))->x(),((QWidget *)(ob->object()))->y())); return true; } -bool KviKvsObject_widget::function_setIcon(KviKvsObjectFunctionCall *c) +bool KviKvsObject_widget::function_setWindowIcon(KviKvsObjectFunctionCall *c) { QString icon; @@ -1754,7 +1778,7 @@ bool KviKvsObject_widget::function_setIcon(KviKvsObjectFunctionCall *c) KVSO_PARAMETERS_END(c) if(!widget())return true; QPixmap * pix = g_pIconManager->getImage(icon); - if(pix)widget()->setIcon(*pix); + if(pix)widget()->setWindowIcon(*pix); return true; } diff --git a/src/modules/objects/class_widget.h b/src/modules/objects/class_widget.h index 0863989fe..c3ef7be19 100644 --- a/src/modules/objects/class_widget.h +++ b/src/modules/objects/class_widget.h @@ -52,7 +52,7 @@ protected: bool function_addWidgetToWrappedLayout(KviKvsObjectFunctionCall *c); bool function_backgroundColor(KviKvsObjectFunctionCall *c); - bool function_caption(KviKvsObjectFunctionCall *c); + bool function_windowTitle(KviKvsObjectFunctionCall *c); bool function_centerToScreen(KviKvsObjectFunctionCall *c); bool function_fontAscent(KviKvsObjectFunctionCall * c); bool function_fontDescent(KviKvsObjectFunctionCall * c); @@ -82,12 +82,12 @@ protected: bool function_screenResolution(KviKvsObjectFunctionCall * c); bool function_setBackgroundColor(KviKvsObjectFunctionCall *c); bool function_setBackgroundImage(KviKvsObjectFunctionCall *c); - bool function_setCaption(KviKvsObjectFunctionCall *c); + bool function_setWindowTitle(KviKvsObjectFunctionCall *c); bool function_setEnabled(KviKvsObjectFunctionCall *c); bool function_setFocus(KviKvsObjectFunctionCall *c); bool function_setFocusPolicy(KviKvsObjectFunctionCall *c); bool function_setFont(KviKvsObjectFunctionCall *c); - bool function_setIcon(KviKvsObjectFunctionCall *c); + bool function_setWindowIcon(KviKvsObjectFunctionCall *c); bool function_setMaximumWidth(KviKvsObjectFunctionCall *c); bool function_setMaximumHeight(KviKvsObjectFunctionCall *c); bool function_setMinimumWidth(KviKvsObjectFunctionCall *c); diff --git a/src/modules/objects/class_window.cpp b/src/modules/objects/class_window.cpp index 81222f086..a0cdb4d08 100644 --- a/src/modules/objects/class_window.cpp +++ b/src/modules/objects/class_window.cpp @@ -96,7 +96,7 @@ void KviKvsScriptWindowWindow::centralWidgetDestroyed() KVSO_BEGIN_REGISTERCLASS(KviKvsObject_window,"window","widget") - KVSO_REGISTER_HANDLER(KviKvsObject_window,"setCaption", functionsetCaption) + KVSO_REGISTER_HANDLER(KviKvsObject_window,"setWindowTitle", functionsetWindowTitle) KVSO_REGISTER_HANDLER(KviKvsObject_window,"setCentralWidget", functionsetCentralWidget) // KVSO_REGISTER_HANDLER(KviKvsObject_window,"setIcon", functionsetIcon) KVSO_END_REGISTERCLASS(KviKvsObject_window) @@ -119,14 +119,14 @@ bool KviKvsObject_window::init(KviKvsRunTimeContext * pContext,KviKvsVariantList return true; } -bool KviKvsObject_window::functionsetCaption(KviKvsObjectFunctionCall *c) +bool KviKvsObject_window::functionsetWindowTitle(KviKvsObjectFunctionCall *c) { QString szCaption; KVSO_PARAMETERS_BEGIN(c) KVSO_PARAMETER("caption",KVS_PT_STRING,0,szCaption) KVSO_PARAMETERS_END(c) if(widget()) - ((KviKvsScriptWindowWindow *)widget())->setCaptionString(szCaption); + ((KviKvsScriptWindowWindow *)widget())->setWindowTitleString(szCaption); return true; } bool KviKvsObject_window::functionsetCentralWidget(KviKvsObjectFunctionCall *c) diff --git a/src/modules/objects/class_window.h b/src/modules/objects/class_window.h index 1324a5626..ba7d053b1 100644 --- a/src/modules/objects/class_window.h +++ b/src/modules/objects/class_window.h @@ -36,7 +36,7 @@ public: protected: virtual bool init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams); - bool functionsetCaption(KviKvsObjectFunctionCall *c); + bool functionsetWindowTitle(KviKvsObjectFunctionCall *c); bool functionsetCentralWidget(KviKvsObjectFunctionCall *c); }; @@ -53,7 +53,7 @@ protected: QWidget * m_pCentralWidget; public: void setCentralWidget(KviKvsObject_widget *o,QWidget * w); - void setCaptionString(const QString &s){ setFixedCaption(s); }; + void setWindowTitleString(const QString &s){ setFixedCaption(s); }; virtual void resizeEvent(QResizeEvent *e); protected slots: void centralWidgetObjectDestroyed(); diff --git a/src/modules/objects/class_workspace.cpp b/src/modules/objects/class_workspace.cpp index 746786e5d..c32b684ce 100644 --- a/src/modules/objects/class_workspace.cpp +++ b/src/modules/objects/class_workspace.cpp @@ -132,7 +132,7 @@ }[br] %Workspace=$new(workspace)[br] %Workspace->$resize(640,480)[br] - %Workspace->$setCaption("Hit the mouse to stop cycling windows....")[br] + %Workspace->$setWindowTitle("Hit the mouse to stop cycling windows....")[br] %I=0[br] %Cicle=1[br] while (%I<20)[br] -- cgit v1.3.1-10-gc9f91