# popupmenu class

Provides a popup menu.

Inherits
object widget
Description
This widget can be used to display a popup menu.Technically, a popup menu consists of a list of menu items. 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.
Functions

`$insertItem(<text:string>,[icon_id:string])`
Inserts menu items into a popup menu with optional icon and return the popup identifier.
`$setTitle(<text:string>)`
Sets the popupmenu title to text.
`$exec([<widget:objects>,<x:uinteger>,<y:integer>])`
If called without paramaters show the popup menu at the current pointer position. With the optional parameters show the popup menu at the coordinate x,y widget parameter relative.
`$removeItem(<popup_id:Uinteger>)`
Removes the menu item that has the identifier id.
`$removeItemAt(<index:uinteger>)`
Removes the menu item at position index.
`$insertSeparator(<index:uinteger>)`
Inserts a separator at position index. If the index is negative the separator becomes the last menu item.
`$activatedEvent(<popup_id:uinteger>)`
This function is called when a menu item and return the the item id. The default implementation emits the $activated() signal.
`$highligthtedEvent(<popup_id:uinteger>)`
This function is called when a menu item is highlighted and return the item id. The default implementation emits the $highlighted() signal.

Signals

`$activated()`
This signal is emitted by the default implementation of $activatedEvent().
`$highlighted()`
This signal is emitted by the default implementation of $highlightedEvent().

Examples

    // first we define a class inherited from popupmenu
    class(menu,popupmenu)
    {
        constructor()
        {
            // we store the item's id for checkit in activatedEvent
            @%tile_id=@$insertItem("Tile",118)
            @%cascade_id=@$insertItem("Cascade",115)
            @$insertSeparator(3)
            @%closeactw_id=@$insertItem("Close Active Window",08)
            @%closeallw_id=@$insertItem("Close All Window",58)
        }
        activatedEvent()
        {
            // now we emit a signals to the relative to the user choice
            %id=$0
            if (%id==@%tile_id) @$emit("tile")
            else if(%id==@%cascade_id) @$emit("cascade")
            else if (%id==@%closeactw_id) @$emit("closeactive")
            else @$emit("closeallwindows")
            // deleting the popup
            delete $$
        }
    }
    class (ws,widget)

    {
        #In the constructor we create everything that belong to the single widget.
        constructor()
        {
            #Here we generate a loop to create our labels inside the widget.
            %lay=$new(layout,$$)
            // we use a vbox to managing labels in vertical orientation
            %vb=$new(vbox,$$)
            // then add the vbox to the main layout
            %lay->$addWidget(%vb,0,0)
            // let's create our colorful labels
            for(%i=0;%i<15;%i++)
            {
                @%label=$new(label,%vb)
                @%label->$settext("Another class by N\&G")
                #We set our foreground's colors using the hex array in a random way.
                @%label->$setforegroundcolor($array($rand(255),$rand(255),$rand(255)))
            }
        }
        customContextMenuRequestedEvent()
        {
            #We create  the popupmenu relative to this widget at runtime.
            %p=$new(menu,$$)
            objects.connect %p tile @$parent tile
            objects.connect %p cascade @$parent cascade
            objects.connect %p closeactive @$parent closeactivewindow
            objects.connect %p closeallwindows @$parent closeallwindows
            %p->$exec($$,$($0+10),$($1+10))
        }
    }
    // we create the workspace widget
    %Workspace=$new(workspace)
    // we use as space as we have
    %size[]=%Workspace->$screenResolution()
    // resize it
    %Workspace->$resize(%size[0],%size[1])
    // then create 20 subwidget
    for(%i=0;%i<20;%i++)
    {
        %w=$new(ws,%Workspace)
        // let's add avery widget to the workspace
        %Workspace->$addSubWindow(%w)
        // then "shake it" a little bit around :-)
        %w->$move($rand($(%size[0]-50)),$rand($(%size[1]-50)))
    }
    // reimplement closeEvent to delete all this :-)
    privateimpl(%Workspace,closeEvent)
    {
        delete $$
    }
    #Let's show!
    %Workspace->$show()

Index, Object Classes

KVIrc 4.0.2.4740 Documentation
Generated by root at Tue Feb 1 06:16:04 2011