Documentation component by D.Glodt (c)2000-2002 Appendix A: QCanvasEx

QCanvasEx Component

QCanvasEx is a control as a Qcanvas with extensions of properties and méthods.

QCanvasEx Properties
Field Type R/W Default




MixMode Long RW R2_COPYPEN_CAN
Set the foreground mix mode
The differents values are:
R2_BLACK_CAN=1
R2_NOTMERGEPEN_CAN=2
R2_MASKNOTPEN_CAN=3
R2_NOTCOPYPEN_CAN=4
R2_MASKPENNOT_CAN=5
R2_NOT_CAN=6
R2_XORPEN_CAN=7
R2_NOTMASKPEN_CAN=8
R2_MASKPEN_CAN=9
R2_NOTXORPEN_CAN=10
R2_NOP_CAN=11
R2_MERGENOTPEN_CAN=12
R2_COPYPEN_CAN=13
R2_MERGEPENNOT_CAN=14
R2_MERGEPEN_CAN=15
R2_WHITE_CAN=16
PenSize Long RW 1
Pen size for draw  line,rectangle and circle RW
PenStyle Long RW PS_SOLID_CAN
Pen style , the others values are:
PS_SOLID_CAN=0
PS_DASH_CAN=1
PS_DOT_CAN=2
PS_DASHDOT_CAN=3
PS_DASHDOTDOT_CAN=4
PS_NULL_CAN=5
PS_INSIDEFRAME_CAN=6

QCanvasEx Methods
Method Type Description Params




DrawIco SUB(left%,top%,width%,height%,handle%) Draw an icon 3
If  parameters width and height are  0,the icon will show with his dimensions by défault.
CopyToClipboard SUB(rect as QRECT) Copy the image in the clipboard 1
PasteFromClipboard SUB(x%,y%) Paste the image from clipboard 2
GetWidthClipboard FUNCTION as INTEGER Return the image wiith from clipboard 0
GetHeightClipboard FUNCTION as INTEGER Return the image height from clipboard 0
CanPaste FUNCTON as BOOLEAN Return true if image présent in the clipboard 0
Circle SUB(x1%,y1%,x2%,y2%,c%) Draw a circle 5
CircleFilled SUB(x1%,y1%,x2%,y2%,c%,Fill%) Draw a circle filled 6
Rectangle SUB(x1%,y1%,x2%,y2%,c%) Draw a rectangle 5
RectangleFilled SUB(x1%,y1%,x2%,y2%,c%,Fill%) Draw a rectangle filled 6
RoundRect SUB(x1%,y1%,x2%,y2%,x3%,y3%,c%) Draw a round rectangle 7
RoundRectFilled SUB(x1%,y1%,x2%,y2%,x3%,y3%,c%,Fill%) Draw a round rectangle filled 8
Line SUB(x1%,y1%,x2%,y2%,c%) Draw a line 5
FillSurface SUB(x%,y%,c%) Fill the surface pointed by the color of pixel x,y 3
TextOut SUB(x%,y%,s$,fc%,bc%) Draw  text 5
InvertColor SUB(x%,y%,width%,height%) Invert color 4
Mirror SUB(x%,y%,width%,height%) Make a miror x 4
Flip SUB(x%,y%,width%,height%) Make a miror y 4

QCanvasEx Events
Event Type Occurs when... Params




QCanvasEx Example 1

 $typecheck on
 $INCLUDE "Rapidq.inc"
 $INCLUDE "Object\QCanvasEx.inc"
 declare sub OuvrirClick
 declare sub FermerClick
 declare sub QuitterClick
 declare sub Copier
 declare sub Coller
 declare sub Present
 const title="Viewer picture"
 dim bitmap as QBITMAP
 dim source as QRECT
 CREATE Form AS QFORM
   Caption =title
   Width = 600
   Height = 600
   Center
   CREATE Menu AS QMAINMENU
     CREATE item1 AS QMENUITEM
       Caption="&Fichier"
       CREATE item2 AS QMENUITEM
         Caption="&Ouvrir"
         OnClick=OuvrirClick
       END CREATE
       CREATE item4 AS QMENUITEM
         Caption="&Fermer"
         OnClick=FermerClick
       END CREATE
       CREATE item5 AS QMENUITEM
         Caption="-"
       END CREATE
       CREATE item6 AS QMENUITEM
         Caption="&Quitter"
         OnClick=QuitterClick
       END CREATE
     END CREATE
     CREATE item11 as QMENUITEM
       Caption="&Edition"
       OnClick=Present
       CREATE item12 as QMENUITEM
         Caption="&Copier"
         OnClick=Copier
       END CREATE
       CREATE item13 as QMENUITEM
         Caption="&Coller"
         OnClick=Coller
         Enabled=false
        END CREATE
      END CREATE
    END CREATE
    CREATE ScrollBox1 AS QSCROLLBOX
      AutoScroll = 1
      Align=5
      Color = &HFFFFFF
      CREATE image AS QCanvasEx
        width=1000
        height=1000
      END CREATE
    END CREATE
  END CREATE
  bitmap.PixelFormat=6
  Form.ShowModal
  
  sub OuvrirClick
    dim file as QOPENDIALOG
    
    file.Filter="Fichiers bitmap(*.bmp)|*.bmp"
    file.InitialDir=CurDir$
    if file.Execute then
      bitmap.Bmp=file.FileName
      image.draw(0,0,bitmap.bmp)
      Form.Caption=title+"-"+file.FileName
    end if
  end sub
  
  sub FermerClick
     image.repaint
     Form.Caption=title
  end sub
  
  sub QuitterClick
    Form.Close
  end sub
  
  sub Copier
    source.left=0
    source.top=0 
    source.right=bitmap.width 
    source.bottom=bitmap.height 
    image.copyToClipboard(source)
  end sub
  
  sub coller
    image.pasteFromClipboard(20,20)
    form.caption=str$(image.GetWidthClipboard)+"*"+str$(image.GetHeightClipboard)
  end sub
  
  Sub Present
    if image.canpaste then
      item13.enabled=true
    else
      item13.enabled=false
    end if
  End Sub
QCanvasEx Example 2
$typecheck on
$INCLUDE "Rapidq.inc" 
$Include "Object\QCanvasEx.inc"
$INCLUDE "OBJECT\QCOLORDIALOG.INC"

declare sub selectdrawing(sender as qmenuitem)
declare sub selectSize(sender as qmenuitem)
declare sub move(x as integer,y as integer)
declare sub start(bt as integer,x as integer,y as integer)
declare sub stop
declare sub ResetMenuDrawing
declare sub ResetMenuSize
declare sub SelectPenColor
declare sub SelectBackColor
declare sub New
declare sub Quit

dim TypeDraw as integer
TypeDraw=1
dim flag as integer
dim orx as integer
dim ory as integer
dim ox as integer
dim oy as integer
dim pencolor as long
dim backcolor as long
dim Dial as QColorDialog

CREATE Form AS QFORM
  Caption="Paint"
  Width=690
  Height=503
  Center
  CREATE MainMenu AS QMAINMENU
    CREATE MenuFile AS QMENUITEM
      Caption="&File"
      CREATE MenuNew AS QMENUITEM
        Caption="&New"
        OnClick=New
      END CREATE
      CREATE separator AS QMENUITEM
        Caption="-"
      END CREATE
      CREATE MenuExit AS QMENUITEM
        Caption="&Exit"
        OnClick=Quit
      END CREATE
    END CREATE
    CREATE MenuTool AS QMENUITEM
      Caption="&Tools"
      CREATE MenuPenColor AS QMENUITEM
        Caption="&Pen color"
        OnClick=SelectPenColor
      END CREATE
      CREATE MenuPenSize AS QMENUITEM
        Caption="&Pen size"
        CREATE MenuSize1 AS QMENUITEM
          Caption="&Size 1"
          Tag=1
          Checked=true
          OnClick=SelectSize
        END CREATE
        CREATE MenuSize2 AS QMENUITEM
          Caption="&Size 2"
          Tag=2
          OnClick=SelectSize
        END CREATE
        CREATE MenuSize4 AS QMENUITEM
          Caption="&Size 4"
          Tag=3
          OnClick=SelectSize
        END CREATE
        CREATE MenuSize8 AS QMENUITEM
          Caption="&Size 8"
          Tag=4
          OnClick=SelectSize
        END CREATE
      END CREATE
      CREATE MenuBackcolor AS QMENUITEM
        Caption="&Back color"
        OnClick=SelectBackColor
      END CREATE
    END CREATE
    CREATE MenuDrawing AS QMENUITEM
      caption="&Drawing"
      CREATE MenuDraw AS QMENUITEM
        Caption="&Draw"
        tag=1
        Checked=true
        OnClick=SelectDrawing
      END CREATE
      CREATE MenuLine AS QMENUITEM
        Caption="&Line"
        tag=2
        OnClick=SelectDrawing
      END CREATE
      CREATE MenuRect AS QMENUITEM
        Caption="&Rectangle"
        tag=3
        OnClick=SelectDrawing
      END CREATE
      CREATE MenuRectFilled AS QMENUITEM
        Caption="&Rectangle filled"
        tag=4
        OnClick=SelectDrawing
      END CREATE
      CREATE MenuCircle AS QMENUITEM
        Caption="&Circle"
        tag=5
        OnClick=SelectDrawing
      END CREATE
      CREATE MenuCircleFilled AS QMENUITEM
        Caption="&Circle filled"
        tag=6
        OnClick=SelectDrawing
      END CREATE
      CREATE MenuFill AS QMENUITEM
        Caption="&Fill"
        tag=7
        OnClick=SelectDrawing
      END CREATE
    END CREATE
  END CREATE
  CREATE ScrollBox1 AS QSCROLLBOX
    Align=alClient
    color=&hffffff
    CREATE image AS QCanvasEx
      Align=alClient
      OnMouseMove=move
      OnMouseDown=start
      OnMouseUp=stop
    END CREATE
  END CREATE
END CREATE

Form.ShowModal

sub New
  image.repaint
end sub

sub Quit
  Form.close
  Application.terminate
end sub

sub SelectDrawing(sender as qmenuitem)
  TypeDraw=sender.tag
  ResetMenuDrawing
  sender.checked=true
end sub

sub SelectSize(sender as qmenuitem)
  Select case sender.tag
  case 1
    image.pensize=1
  case 2
    image.pensize=2
  case 3
    image.pensize=4
  case 4
    image.pensize=8
  end select
  ResetMenuSize
  sender.checked=true
end sub

sub Start(bt as integer,x as integer,y as integer)  
  flag=true
  orx=x
  ory=y
  ox=x
  oy=y
  select case typeDraw
  case 1
    image.line(x,y,x,y,PenColor)
  case 2
    image.mixmode=R2_NOTXORPEN_CAN
    image.line(x,y,x,y,PenColor)
  case 3
    image.mixmode=R2_NOTXORPEN_CAN
    image.rectangle(x,y,x,y,PenColor)
  case 4
    image.mixmode=R2_NOTXORPEN_CAN
    image.rectangleFilled(x,y,x,y,PenColor,backcolor)
  case 5
    image.mixmode=R2_NOTXORPEN_CAN
    image.circle(x,y,x,y,PenColor)
  case 6
    image.mixmode=R2_NOTXORPEN_CAN
    image.circleFilled(x,y,x,y,PenColor,backcolor)
  case 7
    image.fillSurface(x,y,pencolor)
  end select
end sub 

sub Move(x as integer,y as integer)
  if flag then
    select case typeDraw
    case 1
      image.line(ox,oy,x,y,PenColor)
    case 2
      image.line(orx,ory,ox,oy,PenColor)
      image.line(orx,ory,x,y,PenColor)
    case 3
      image.rectangle(orx,ory,ox,oy,PenColor)
      image.rectangle(orx,ory,x,y,PenColor)
    case 4
      image.rectangleFilled(orx,ory,ox,oy,PenColor,backcolor)
      image.rectangleFilled(orx,ory,x,y,PenColor,backcolor)
    case 5
      image.circle(orx,ory,ox,oy,PenColor)
      image.circle(orx,ory,x,y,PenColor)
    case 6
      image.circleFilled(orx,ory,ox,oy,PenColor,backcolor)
      image.circleFilled(orx,ory,x,y,PenColor,backcolor)
    end select
    ox=x
    oy=y
  end if
end sub 
    
sub Stop
 if  flag then
   image.mixmode=R2_COPYPEN_CAN
   flag=0
 end if
 select case typeDraw
 case 2
   image.line(orx,ory,ox,oy,PenColor)
 case 3
   image.rectangle(orx,ory,ox,oy,PenColor)
 case 4
   image.rectangleFilled(orx,ory,ox,oy,PenColor,backcolor)
 case 5
   image.circle(orx,ory,ox,oy,PenColor)
 case 6
   image.circleFilled(orx,ory,ox,oy,PenColor,backcolor)
 end select
end sub 

sub ResetMenuDrawing
  MenuDraw.checked=false
  MenuLine.checked=false
  MenuRect.checked=false
  MenuRectFilled.checked=false
  MenuCircle.checked=false
  MenuCircleFilled.checked=false
  MenuFill.checked=false
end sub  

sub ResetMenuSize
  MenuSize1.checked=false
  MenuSize2.checked=false
  MenuSize4.checked=false
  MenuSize8.checked=false
end sub  
  
sub SelectPenColor
  Dial.caption="Select pen color"
  if Dial.Execute then
    PenColor=Dial.Color
  end if
end sub

sub SelectBackColor
  Dial.caption="Select backcolor"
  if Dial.Execute then
    BackColor=Dial.Color
  end if
end sub  



Hosted by uCoz