Class: Cosmos::LimitscolorWidget

Inherits:
Qt::Label
  • Object
show all
Includes:
Widget
Defined in:
lib/cosmos/tools/tlm_viewer/widgets/limitscolor_widget.rb

Instance Attribute Summary

Attributes included from Widget

#item, #item_name, #limits_set, #limits_state, #packet, #packet_name, #polling_period, #screen, #settings, #target_name, #value, #value_type

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Widget

#context_menu, #get_tooltip_text, included, #process_settings, #set_setting, #set_subsetting, #shutdown, #update_widget

Constructor Details

#initialize(parent_layout, target_name, packet_name, item_name, value_type = :CONVERTED, radius = 10, use_full_item_name = false) ⇒ LimitscolorWidget

Returns a new instance of LimitscolorWidget.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/cosmos/tools/tlm_viewer/widgets/limitscolor_widget.rb', line 18

def initialize(parent_layout, target_name, packet_name, item_name, value_type = :CONVERTED, radius = 10, use_full_item_name = false)
  super(target_name, packet_name, item_name, value_type)
  @value_type = :CONVERTED if @value_type == :WITH_UNITS
  use_full_item_name = ConfigParser::handle_true_false(use_full_item_name)
  @painter = nil
  @foreground = Cosmos::BLACK
  parent_layout.addWidget(self) if parent_layout
  @font = font()
  metrics = Cosmos.getFontMetrics(@font)
  if use_full_item_name
    @item_text = "#{@target_name} #{@packet_name} #{@item_name}"
  else
    @item_text = @item_name
  end
  text_width = metrics.width(@item_text)
  @radius = radius.to_i
  @diameter = @radius * 2
  @text_height = @font.pointSize
  @left_offset = @diameter + 5
  if @text_height > @diameter
    @text_baseline = @text_height
    setFixedSize(text_width + @left_offset, @text_height + 2)
  else
    @text_baseline = @text_height + ((@diameter - @text_height) / 2)
    setFixedSize(text_width + @left_offset, @diameter + 2)
  end
end

Class Method Details

.takes_value?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/cosmos/tools/tlm_viewer/widgets/limitscolor_widget.rb', line 46

def self.takes_value?
  return true
end

Instance Method Details

#paint_implementation(dc) ⇒ Object



85
86
87
88
89
90
91
92
93
# File 'lib/cosmos/tools/tlm_viewer/widgets/limitscolor_widget.rb', line 85

def paint_implementation(dc)
  dc.setBrush(Cosmos.getBrush(@foreground))
  dc.drawEllipse(0, 0, @diameter, @diameter)
  dc.setBrush(Cosmos.getBrush(Cosmos::BLACK))
  dc.drawText(@left_offset, @text_baseline, @item_text)

  #Additional drawing for subclasses
  additional_drawing(dc)
end

#paintEvent(event) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/cosmos/tools/tlm_viewer/widgets/limitscolor_widget.rb', line 69

def paintEvent(event)
  begin
    super(event)
    return if @painter
    @painter = Qt::Painter.new(self)
    # Seems like on initialization sometimes we get some weird bad conditions so check for them
    if @painter.isActive and @painter.paintEngine
      paint_implementation(@painter)
    end
    @painter.dispose
    @painter = nil
  rescue Exception => err
    Cosmos.handle_fatal_exception(err)
  end
end

#value=(data) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/cosmos/tools/tlm_viewer/widgets/limitscolor_widget.rb', line 50

def value=(data)
  super(data)
  case @limits_state
  when :RED, :RED_HIGH, :RED_LOW
    @foreground = 'red'
  when :YELLOW, :YELLOW_HIGH, :YELLOW_LOW
    @foreground = 'yellow'
  when :GREEN, :GREEN_HIGH, :GREEN_LOW
    @foreground = 'lime'
  when :BLUE
    @foreground = 'dodgerblue'
  when :STALE
    @foreground = Cosmos::PURPLE
  else
    @foreground = Cosmos::BLACK
  end
  update()
end