'*  DerulantPanel component for Rapidq
'*  version 1.0.0
'*  coded by Nastase Eodor
'*  http://rqwork.evonet.ro
'*  rqwork@evonet.ro

$Resource Up_Res   as "Up.BMP"
$Resource Down_Res as "Down.BMP"

Declare Sub EventTemplate_Collapse(Sender As QPanel)
Declare Sub EventTemplate_Expand(Sender As QPanel)
Declare Sub EventTemplate_Collapsing(Sender As QPanel)
Declare Sub EventTemplate_Expanding(Sender As QPanel)
Declare Sub EventTemplate_CaptionClick(Sender As QPanel,Image As QImage,BYREF Caption$)

Type QDerulantPanel Extends QPanel
     Private:
     Image          As QImage
     Timer          As QTimer
     Expanded       As Integer
     Size           As Integer
     Public:
     Speed          As Integer
     Increment      As Integer
     Caption        As String  Property Set SetCaption
     OnCollapse     As Event(EventTemplate_Collapse)
     OnCollapsing   As Event(EventTemplate_Collapsing)
     OnExpand       As Event(EventTemplate_Expand)
     OnExpanding    As Event(EventTemplate_Expanding)
     OnCaptionClick As Event(EventTemplate_CaptionClick)

     With This

     Property Set SetCaption(Value As String)
         .Caption = Value
         .Image.TextOut(8,4,.Caption,&H00E19272,-1)
     End Property

     Sub Expand
         If .OnExpand Then CallFunc .OnExpand, This
         .Timer.Interval = .Speed
         .Timer.Enabled = 1
     End Sub

     Sub Collapse
         If .OnCollapse Then CallFunc .OnCollapse, This
         .Size = .Height
         .Timer.Interval = .Speed
         .Timer.Enabled = 1
     End Sub

     Event Timer.OnTimer
         If .Expanded Then
            Dec(.Height,.Increment)
            If .Height < .Image.Height Then
               .Timer.Enabled = 0
               .Height = .Image.height
               .Expanded = 0
            End If
            If .OnExpanding Then CallFunc .OnExpanding, This
         Else
            Inc(.Height,.Increment)
            If .Height > .Size Then
               .Timer.Enabled = 0
               .Height = .Size
               .Expanded = 1
            End If
            If .OnCollapsing Then CallFunc .OnCollapsing, This
         End If
     End Event

     Event Image.OnClick
         If .OnCaptionClick Then CallFunc .OnCaptionClick, This, This.Image ,This.Caption
         If .Expanded Then
            .Image.BMPHandle = down_Res
            .Image.Font.AddStyles fsBold
            .Image.TextOut(8,4,.Caption,&H00E19272,-1)
            .Collapse
         Else
            .Image.BMPHandle = up_Res
            .Image.Font.DelStyles fsBold
            .Image.TextOut(8,4,.Caption,&H00E19272,-1)
            .Expand
         End If
     End Event

     End With

     Constructor
     Timer.Enabled   = 0
     Image.Parent    = This
     Image.Height    = 25
     Image.Align     = 1
     Image.Font.Name = "Tahoma"
     Image.Font.Size = 10
     Image.Cursor    = -21
     Size            = 0
     Speed           = 1
     Increment       = 8
     Color           = &HFFFFFF
     Expanded        = 1
     BevelOuter      = 0
     Image.BMPHandle = up_Res
     End Constructor
End Type
