Type QToolBar extends QPanel
   imgl as Qimagelist
   img as qimage
   imgmen as qimage
   imglHandle as integer
   Buttons as integer
   ButtonX as integer
   Clicked as integer
   Hint() as string 
   ShowHint as short

   Sub load
      With QtoolBar
         .imgl.handle = .imglHandle
         .img.parent = Qtoolbar
         .img.Left = 1
         .img.Top = 1
         .img.ShowHint =.ShowHint
         .Buttons = .imgl.Count
         .img.Width = (.Buttons*16 + (.Buttons*7))+6
         .img.FillRect (0, 0, .img.Width, 24,&HC0C0C0)
         For a = 0 to .Buttons - 1
            .img.Draw (a*16 + (7*a+2)+ 4 ,4 ,Qtoolbar.imgl.GetBMP(a) )
         Next
      End With
   End Sub

   sub paint
      With QToolBar
         x1=.ButtonX*22+5 : X2=(.ButtonX+1)*22+5
         .img.rectangle (x1,2,x2,23,&HC0C0C0)
      end With
   end sub

   Sub showButton (Mode as short)
      Dim but as short
      But = mouseX \ 22
      With QToolBar
         if But > .Buttons-1 then exit sub
         Select case Mode
            Case 0
               x1=.ButtonX*22+5 : X2=(.ButtonX+1)*22+5
               .img.rectangle (x1,2,x2,23,&HC0C0C0)
               .ButtonX = mouseX \ 22
               .img.rectangle (2,2,.img.width,24,&HC0C0C0) 
               x1=.ButtonX*22+5 : X2=(.ButtonX+1)*22+4
               .img.Draw (.ButtonX*16 + (7*.ButtonX+2)+ 4 ,4 ,Qtoolbar.imgl.GetBMP(.ButtonX) )
               .img.line (x1,2,x2,2,&Hffffff)
               .img.line (x1,2,x1,22,&Hffffff)
               .img.line (x1,22,x2,22,&H000000)
               .img.line (x2,22,x2,2,&H000000)
               .img.hint = .hint(.ButtonX)
            Case 1
               x1=.ButtonX*22+5 : X2=(.ButtonX+1)*22+5
               .img.rectangle (x1,2,x2,23,&HC0C0C0)
               .img.Draw (.ButtonX*16 + (7*.ButtonX+2)+ 4 ,4 ,Qtoolbar.imgl.GetBMP(.ButtonX) )

               .ButtonX = mouseX \ 22
               x1=.ButtonX*22+5 : X2=(.ButtonX+1)*22+4
               .img.FillRect (x1,2,x2,23,&HC0C0C0)

               .img.Draw (.ButtonX*16 + (7*.ButtonX+2)+ 5 ,5 ,Qtoolbar.imgl.GetBMP(.ButtonX) )

               .img.line (x1,2,x2,2,&H000000)
               .img.line (x1,2,x1,22,&H000000)
               .img.line (x1,22,x2,22,&Hffffff)
              .img.line (x2,22,x2,2,&Hffffff)
          End Select
       end With
   end Sub

   Event img.OnMouseMove
      QtoolBar.ShowButton QtoolBar.Clicked
   end Event

   Event img.OnMouseDown
      QtoolBar.Clicked =1
      QtoolBar.ShowButton 1
   End event

   Event img.OnMouseUp
      QtoolBar.Clicked = 0
      QtoolBar.ShowButton 0
   End event

   Event OnMouseMove
      QtoolBar.Paint
   end Event

   Constructor
      Buttons = 0
      ButtonX = 0
      img.Height = 24
      height = 28
   end constructor
end type
