[Gambas-user] QPainter in GAMBAS3
Pino Zollo
pinozollo at ...626...
Tue May 31 14:17:17 CEST 2011
> i think you call paint.begin in a _draw event, no ?
No, ...Draw.begin please see the all class source.
Sub Disegna() is called continuously...how would be a better way ?
Shall I put Draw.Begin only once at the opening of the window ?
Thanks
Pino
2011/5/30 Pino Zollo <pinozollo at ...626...>:
> > Hi
> > This message is a bit obscure for me..... please help !
> >
> > It appears in the Console.
> >
> > "QPainter::begin: A paint device can only be painted by one painter at a
> > time.
> > QPainter::end: Painter not active, aborted"
> >
> > Actually I can not determine which statement and which class exactly
> > generates it
' Gambas class file
'**********************************************************
Static Public Fine As Float
Static Public Inizio As Float
Static Public zoom As Float
Static Public Freq As Float
Static Public Fin As Float
Static Public Ffin As Float
Static Public F2 As Float
Static Public D As Float = 0
Static Public Ba As Boolean
Static Public vfo0 As Float = 14200
Static Public FullSpan As Boolean = False
Static Public DH As Float
Static Public OldBand As String = "20m"
Static Public Band As String = "20m"
Static Public CaCol As Integer ' Call Color
Static Public BeCol As Integer ' Background Color
Public Sub _new()
End
Public Sub Form_Open()
Me.Text = "DBLog Scale"
Me.Top = Settings["Scale/Top", Me.Top]
Me.Left = Settings["Scale/Left", Me.Left]
Me.Height = Settings["Scale/Height", Me.Height]
Me.Width = Settings["Scale/Width", Me.Width]
' ME.Move(200, 80)
' ME.ShowModal ' a cosa serve ??
' ME.Sticky = TRUE ' does nothing
' DEBUG ME.Sticky
' ME.TopOnly = TRUE
' DEBUG ME.TopOnly ' Why is always false ? after 2.15 it works...
Inizio = FMain.lowerl
Fine = FMain.upperl
Freq = FMain.F 'Val(Replace$(FMain.FreqRadio.text, ",", ""))
'14.200 ' dummy
zoom = 30 ' 30 KHz 30 marks in the full Height
F2 = Freq * 1000 ' in KHz
'DEBUG Inizio;; Fine;; Freq
DrawingArea1.Resize(Me.ClientW, Me.ClientH)
DrawingArea1.Cached = True
' Draw.Begin(DrawingArea1)
Disegna()
Catch
Debug error.text, error.Where
End
Public Sub Form_Close()
' Draw.End
Settings["Scale/Top"] = Me.Top
Settings["Scale/Left"] = Me.Left
Settings["Scale/Height"] = Me.Height
Settings["Scale/Width"] = Me.Width
End
Public Sub Form_Resize()
Try DrawingArea1.Resize(Me.ClientW, Me.ClientH) 'TRY
Disegna()
' DrawingArea1.Refresh ' what is this for ?
End
Public Sub Disegna() ' dovrebbe aspettare la fine della scrittura su Band
Dim i, passo, Rap, St, En, p0 As Float
Dim F, P, R As Integer
Dim hField As ResultField ' for Spots
Dim iInd As Integer
Dim FSpot As Float
Dim Raw_Count As Integer
Dim Columns_Count As Integer
_label:
Inizio = FMain.lowerl ' Get band limits
Fine = FMain.upperl
Band = FMain.ComboBand.Text
If Band <> OldBand And FullSpan Then ' Put in Full Span the new band
zoom = (Fine - Inizio) * 1000
Fin = Inizio
Freq = (Fine + Inizio) / 2
OldBand = Band
Endif
Draw.Begin(DrawingArea1) '
<--------------------------------------------------------------------- here
Rap = Draw.w / 3
DH = Draw.H
' [GB2:BCOL] DrawingArea1.BackColor = Color.White ' OK works
DrawingArea1.Background = Color.White ' OK works
Draw.Foreground = &HDFEFFF&
Draw.FillStyle = Fill.Solid
Draw.FillColor = &HDFEFFF&
Draw.Rect(0, 0, Rap, Draw.h)
Draw.Foreground = Color.Black
Draw.Line(Rap, 0, Rap, Draw.H)
St = Inizio * 1000 ' in KHz
En = Fine * 1000
F = Int((Freq * 1000 - zoom / 2))
Fin = F
passo = (Draw.H / (zoom)) ' KHz -1 senza Int
Draw.Font.Size = 8
For i = 0 To Draw.H + 1 Step passo ' dirty trick !! the +1
If F > En Or F < St Then
Draw.Foreground = Color.Red
Else
Draw.Foreground = Color.Black
End If
If F Mod 5 <> 0 Then
Draw.Line(Rap - 5, i, Rap, i)
Else
Draw.Line(Rap - 10, i, Rap, i)
If FMain.comma Then
Draw.Text(Replace$(Format$(F / 1000, "##0.000"), ",", "."), 0,
i - 6,,, Align.TopLeft) ' -6 because Align seems not to work
Else
Draw.Text(Format$(F / 1000, "##0.000"), 0, i - 6,,, Align.TopLeft)
Endif
End If
Inc F
Next
Ffin = F - 1
' DEBUG Fin;; Ffin;; Ffin - Fin;; F2;; St;; En
p0 = (F2 - Fin) / (Ffin - Fin) * Draw.H
P = Int(p0)
R = Int(Rap)
' Draw.Transparent = TRUE
Draw.Foreground = Color.Red
Draw.FillColor = Color.Red
Draw.Polygon([R, P, R - 8, P - 5, R - 8, P + 5])
' Fill spots
Draw.Font.Size = 9
Draw.FillColor = Color.White
For iInd = 0 To FBand.GridStations.Rows.Count - 1
If FMain.comma Then
Try Fspot = Val(Replace$(FBand.GridStations[iInd, 1].Text, ".",
",")) * 1000
Else
Try Fspot = Val(FBand.GridStations[iInd, 1].Text) * 1000
Endif
If Fspot >= Fin And Fspot <= Ffin Then
SelectColor(iInd)
P = Int((FSpot - Fin) / (Ffin - Fin) * Draw.H)
Draw.Foreground = Color.White
Draw.FillColor = BeCol
Draw.Rect(R + 1, P - 6, Draw.W - R, 13) ' for background
Draw.Foreground = CaCol
Draw.Line(R, P, R + 20, P)
Draw.Text(FBand.GridStations[iInd, 2].Text, R + 25, P - 6,,,
Align.TopLeft)
Endif
Next
Draw.End
Catch
Debug error.text, error.Where
End
Public Sub SelectColor(I As Integer)
Select Case Left$(FBand.GridStations[I, 0].Text, 4)
Case " NEW"
BeCol = &HFFFF00&
CaCol = &HFF0000& ' yellow was &HFF0000&
Case " NEE"
' Draw.Background = &HCBFFCC& ' does not work
' Draw.BackColor = &HCBFFCC& ' does not work
BeCol = &HCBFFCC&
CaCol = &HFF0000& ' red
Case "CQCQ"
BeCol = Color.White
CaCol = &H0505050&
Case "DIAL"
BeCol = Color.White
CaCol = &H0800040&
Case "WKB4"
BeCol = Color.White
CaCol = &H0A0A0A0&
Case " Not"
BeCol = Color.White
CaCol = Color.Blue
Case "MEMO"
BeCol = Color.White
CaCol = &H0000000&
Default
BeCol = Color.White
CaCol = Color.Blue
End Select
End
Public Sub Control(VFO As Float)
If VFO <> vfo0 Then
D = (Ffin - Fin) / 10
F2 = VFO
If Not FullSpan Then ' do not slide is in Fill span mode
If F2 < Fin Or F2 > Ffin Then
Freq = F2 / 1000
D = 0
Else
If Abs(F2 - Fin) < D Then
Ba = True
Freq = (F2 + 3 * D) / 1000
End If
If Abs(F2 - Ffin) < D Then
Ba = False
Freq = (F2 - 3 * D) / 1000
End If
End If
Endif
' Form_Resize
Disegna()
vfo0 = VFO
Endif
End
Public Sub DrawingArea1_Menu()
MenuPopUp.popup
Catch
Debug error.text, error.Where
End
Public Sub Zin_Click()
zoom = zoom - 10
If zoom <= 0 Then zoom = 3
Freq = F2 / 1000
FullSpan = False
Disegna()
Catch
Debug error.text, error.Where
End
Public Sub Zo_Click()
zoom = zoom + 10
Freq = F2 / 1000
FullSpan = False
Disegna()
Catch
Debug error.text, error.Where
End
Public Sub Reset_Click()
zoom = 30
Freq = F2 / 1000
FullSpan = False
Disegna()
Catch
Debug error.text, error.Where
End
Public Sub CW_Click()
zoom = 10
Freq = F2 / 1000
FullSpan = False
Disegna()
Catch
Debug error.text, error.Where
End
Public Sub DIGI_Click()
zoom = 3
Freq = F2 / 1000
FullSpan = False
Disegna()
Catch
Debug error.text, error.Where
End
Public Sub SSB_Click()
zoom = 90
Freq = F2 / 1000
FullSpan = False
Disegna()
Catch
Debug error.text, error.Where
End
Public Sub Full_Click()
zoom = (Fine - Inizio) * 1000
Fin = Inizio
Freq = (Fine + Inizio) / 2
FullSpan = True
Disegna()
Catch
Debug error.text, error.Where
End
Public Sub DrawingArea1_MouseDown()
Dim Fm As Float
If Mouse.Left Then
Fm = (Fin + (Ffin - Fin) * Mouse.Y / DH) / 1000
FMain.FreqA = Fm
FMain.FreqB = Fm
If FMain.fldigi_on Then
FMain.Command_fldigi("log.set_call", "", "main.set_frequency",
Str(Int(Fm * 1000000)), FMain.ComboMode.Text)
' IF FMain.comma THEN
' ' FMain.Command_fldigi("log.set_call", "",
"main.set_frequency", Replace$(Str(Fm), ".", ""), FMain.ComboMode.text)
' ELSE
' FMain.Command_fldigi("log.set_call", "", "main.set_frequency",
Str(Int(Fm * 1000000)), FMain.ComboMode.Text)
' ENDIF
Else
FMain.tune = True ' Inform FMain to change VFO frequencies
Endif
Endif
Catch
Debug error.text, error.Where
End
More information about the User
mailing list