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 can be a string. In addition, items can have an optional icon drawn on the very left side. |
||||||||||||||||||
Functions |
||||||||||||||||||
|
||||||||||||||||||
Signals |
||||||||||||||||||
|
||||||||||||||||||
Examples |
||||||||||||||||||
# First we define a class inherited from popupmenu class(menu,popupmenu) { constructor() { # We store the item's ID for checking 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 every 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() | ||||||||||||||||||