diff --git a/core/callinfo/callinfo.go b/core/callinfo/callinfo.go index e9e4999..acd61c7 100644 --- a/core/callinfo/callinfo.go +++ b/core/callinfo/callinfo.go @@ -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) @@ -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 } } @@ -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) {} diff --git a/ui/callinfoView.go b/ui/callinfoView.go index 542169e..043669a 100644 --- a/ui/callinfoView.go +++ b/ui/callinfoView.go @@ -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) { @@ -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("%s", 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("%s", strings.Join([]string{attributeString, partAttributeString}, " "), partString) } - v.supercheckLabel.SetMarkup(text) + + return renderedCallsign } func (v *callinfoView) SetPredictedExchange(index int, text string) {