' Simple Text Viewer for Rapid-Q (Linux/Unix) by William Yu

$APPTYPE GUI
$INCLUDE "rapidq.inc"

DECLARE SUB OpenButtonClick
DECLARE SUB CopyClick
DECLARE SUB KeyPress(Key AS WORD)
DECLARE SUB RichEditMouseUp
DECLARE SUB ButtonClick
DECLARE SUB ExitClick

DIM Font AS QFont

Font.Name = "courier"
Font.Size = 12

CREATE Form AS QForm
  Width = 400
  Height = 215
  Caption = "Rapid-Q Text Viewer"
  Center
  CREATE Panel AS QPanel
    Top = 1
    Left = 1
    Width = 45
    Height = 213
    CREATE OpenButton AS QCoolBtn
       Left = 2
       Top = 2
       Width = 40
       Height = 40
       BMP = "open.xpm"
       Flat = True
       OnClick = OpenButtonClick
    END CREATE
    CREATE CopyButton AS QCoolBtn
       Left = 2
       Top = 43
       Width = 40
       Height = 40
       BMP = "copy.xpm"
       Flat = True
       OnClick = CopyClick
    END CREATE
    CREATE Button3 AS QButton
       Left = 2
       Top = 85
       Width = 40
       Height = 40
       Caption = "None"
    END CREATE
    CREATE Button4 AS QButton
       Left = 2
       Top = 127
       Width = 40
       Height = 40
       Caption = "None"
    END CREATE
    CREATE Button5 AS QCoolBtn
       Left = 2
       Top = 169
       Width = 40
       Height = 40
       BMP = "exit.xpm"
       Flat = True
       OnClick = ExitClick
    END CREATE
  END CREATE
  CREATE RichEdit AS QRichEdit
    Left = 50
    Top = 1
    Width = 345
    Height = 190
    Font = Font
    ScrollBars = ssVertical
    LoadFromFile "rapidq.inc"
    OnKeyPress = KeyPress
    OnMouseUp = RichEditMouseUp
  END CREATE
  CREATE Panel2 AS QPanel
    Top = 196
    Left = 50
    Width = 345
    Height = 17
    CREATE Label1 AS QLabel
      Caption = "Lines: "+STR$(RichEdit.LineCount)
    END CREATE
    CREATE Label2 AS QLabel
      Left = 270
      Caption = "X: "+STR$(RichEdit.WhereX+1)+", Y: "+STR$(RichEdit.WhereY+1)
    END CREATE
  END CREATE
  ShowModal
END CREATE

SUB KeyPress (Key AS WORD)  '' Note, no Shift variable
  Label2.Caption = "X: "+STR$(RichEdit.WhereX+1)+", Y: "+STR$(RichEdit.WhereY+1)
END SUB

SUB RichEditMouseUp
  Label2.Caption = "X: "+STR$(RichEdit.WhereX+1)+", Y: "+STR$(RichEdit.WhereY+1)
END SUB

SUB CopyClick
  ShowMessage(RichEdit.SelText)
END SUB

SUB ExitClick
  Form.Close
END SUB

SUB OpenButtonClick
  DIM OpenDialog AS QOpenDialog

  IF OpenDialog.Execute THEN
    IF FileExists(OpenDialog.FileName) THEN
       RichEdit.LoadFromFile(OpenDialog.FileName)
       Label1.Caption = "Lines: "+STR$(RichEdit.LineCount)
       Label2.Caption = "X: "+STR$(RichEdit.WhereX+1)+", Y: "+STR$(RichEdit.WhereY+1)
    ELSE
       ShowMessage(OpenDialog.FileName+" does not exist!")
    END IF
  END IF
END SUB
