Skip to content

Commit

Permalink
render the best matching callsign like the others in the supercheck list
Browse files Browse the repository at this point in the history
  • Loading branch information
ftl committed May 30, 2024
1 parent f23b139 commit 2b7815e
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 79 deletions.
24 changes: 12 additions & 12 deletions core/callinfo/callinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ type ExchangeFilter interface {

// View defines the visual part of the call information window.
type View interface {
SetBestMatchingCallsign(callsign string)
SetBestMatchingCallsign(callsign core.AnnotatedCallsign)
SetDXCC(string, string, int, int, bool)
SetValue(points, multis int)
SetPredictedExchange(index int, text string)
Expand Down Expand Up @@ -174,11 +174,11 @@ func (c *Callinfo) ShowInfo(call string, band core.Band, mode core.Mode, exchang

supercheck := c.calculateSupercheck(call)
c.bestMatches = make([]string, 0, len(supercheck))
bestMatch := ""
var bestMatch core.AnnotatedCallsign
for i, match := range supercheck {
c.bestMatches = append(c.bestMatches, match.Callsign.String())
if i == 0 {
bestMatch = c.bestMatches[0]
bestMatch = match
}
}

Expand Down Expand Up @@ -352,12 +352,12 @@ func (c *Callinfo) predictExchange(entity dxcc.Prefix, qsos []core.QSO, currentE

type nullView struct{}

func (v *nullView) Show() {}
func (v *nullView) Hide() {}
func (v *nullView) SetBestMatchingCallsign(callsign string) {}
func (v *nullView) SetDXCC(string, string, int, int, bool) {}
func (v *nullView) SetValue(int, int) {}
func (v *nullView) SetPredictedExchange(int, string) {}
func (v *nullView) SetPredictedExchangeFields(fields []core.ExchangeField) {}
func (v *nullView) SetUserInfo(string) {}
func (v *nullView) SetSupercheck(callsigns []core.AnnotatedCallsign) {}
func (v *nullView) Show() {}
func (v *nullView) Hide() {}
func (v *nullView) SetBestMatchingCallsign(callsign core.AnnotatedCallsign) {}
func (v *nullView) SetDXCC(string, string, int, int, bool) {}
func (v *nullView) SetValue(int, int) {}
func (v *nullView) SetPredictedExchange(int, string) {}
func (v *nullView) SetPredictedExchangeFields(fields []core.ExchangeField) {}
func (v *nullView) SetUserInfo(string) {}
func (v *nullView) SetSupercheck(callsigns []core.AnnotatedCallsign) {}
138 changes: 71 additions & 67 deletions ui/callinfoView.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ func attr(name, value string) string {
return fmt.Sprintf("%s=%q", name, value)
}

func (v *callinfoView) SetBestMatchingCallsign(callsign string) {
v.callsignLabel.SetText(callsign)
func (v *callinfoView) SetBestMatchingCallsign(callsign core.AnnotatedCallsign) {
v.callsignLabel.SetMarkup(v.renderCallsign(callsign))
}

func (v *callinfoView) SetDXCC(dxccName, continent string, itu, cq int, arrlCompliant bool) {
Expand Down Expand Up @@ -136,78 +136,82 @@ func (v *callinfoView) SetUserInfo(value string) {
func (v *callinfoView) SetSupercheck(callsigns []core.AnnotatedCallsign) {
var text string
for i, callsign := range callsigns {
// see https://docs.gtk.org/Pango/pango_markup.html for reference
attributes := make([]string, 0, 3)
switch {
case callsign.Duplicate:
attributes = append(attributes,
attr("background", v.style.duplicateBG.ToWeb()),
attr("foreground", v.style.duplicateFG.ToWeb()),
)

case callsign.Worked:
attributes = append(attributes,
attr("background", v.style.workedBG.ToWeb()),
attr("foreground", v.style.workedFG.ToWeb()),
)
case (callsign.Points == 0) && (callsign.Multis == 0):
attributes = append(attributes,
attr("background", v.style.worthlessBG.ToWeb()),
attr("foreground", v.style.worthlessFG.ToWeb()),
)
case callsign.Multis > 0:
attributes = append(attributes,
attr("background", v.style.backgroundColor.ToWeb()),
attr("foreground", v.style.fontColor.ToWeb()),
attr("font-weight", "heavy"),
)
default:
attributes = append(attributes,
attr("background", v.style.backgroundColor.ToWeb()),
attr("foreground", v.style.fontColor.ToWeb()),
)
}

hasPredictedExchange := strings.Join(callsign.PredictedExchange, "") != ""
if hasPredictedExchange {
attributes = append(attributes, attr("font-style", "italic"))
if text != "" {
text += " "
}
attributeString := strings.Join(attributes, " ")

var renderedCallsign string
if i < 9 {
renderedCallsign += fmt.Sprintf("(%d) ", i+1)
text += fmt.Sprintf("(%d) ", i+1)
}

for _, part := range callsign.Assembly {
var partAttributeString string
var partString string
switch part.OP {
case core.Matching:
partAttributeString = ""
partString = part.Value
case core.Insert:
partAttributeString = "underline='single'"
partString = part.Value
case core.Delete:
partAttributeString = ""
partString = "|"
case core.Substitute:
partAttributeString = "underline='single'"
partString = part.Value
case core.FalseFriend:
partAttributeString = "underline='double'"
partString = part.Value
}
renderedCallsign += fmt.Sprintf("<span %s>%s</span>", strings.Join([]string{attributeString, partAttributeString}, " "), partString)
}
text += v.renderCallsign(callsign)
}
v.supercheckLabel.SetMarkup(text)
}

if text != "" {
text += " "
func (v *callinfoView) renderCallsign(callsign core.AnnotatedCallsign) string {
// see https://docs.gtk.org/Pango/pango_markup.html for reference
attributes := make([]string, 0, 3)
switch {
case callsign.Duplicate:
attributes = append(attributes,
attr("background", v.style.duplicateBG.ToWeb()),
attr("foreground", v.style.duplicateFG.ToWeb()),
)

case callsign.Worked:
attributes = append(attributes,
attr("background", v.style.workedBG.ToWeb()),
attr("foreground", v.style.workedFG.ToWeb()),
)
case (callsign.Points == 0) && (callsign.Multis == 0):
attributes = append(attributes,
attr("background", v.style.worthlessBG.ToWeb()),
attr("foreground", v.style.worthlessFG.ToWeb()),
)
case callsign.Multis > 0:
attributes = append(attributes,
attr("background", v.style.backgroundColor.ToWeb()),
attr("foreground", v.style.fontColor.ToWeb()),
attr("font-weight", "heavy"),
)
default:
attributes = append(attributes,
attr("background", v.style.backgroundColor.ToWeb()),
attr("foreground", v.style.fontColor.ToWeb()),
)
}

hasPredictedExchange := strings.Join(callsign.PredictedExchange, "") != ""
if hasPredictedExchange {
attributes = append(attributes, attr("font-style", "italic"))
}
attributeString := strings.Join(attributes, " ")

renderedCallsign := ""
for _, part := range callsign.Assembly {
var partAttributeString string
var partString string
switch part.OP {
case core.Matching:
partAttributeString = ""
partString = part.Value
case core.Insert:
partAttributeString = "underline='single'"
partString = part.Value
case core.Delete:
partAttributeString = ""
partString = "|"
case core.Substitute:
partAttributeString = "underline='single'"
partString = part.Value
case core.FalseFriend:
partAttributeString = "underline='double'"
partString = part.Value
}
text += renderedCallsign
renderedCallsign += fmt.Sprintf("<span %s>%s</span>", strings.Join([]string{attributeString, partAttributeString}, " "), partString)
}
v.supercheckLabel.SetMarkup(text)

return renderedCallsign
}

func (v *callinfoView) SetPredictedExchange(index int, text string) {
Expand Down

0 comments on commit 2b7815e

Please sign in to comment.