Sha256: 7e4a4f83c62ef974c60f4c0b3b9a9ee7f567853b1c494e1092e7993d86cdd206

Contents?: true

Size: 1.38 KB

Versions: 12

Compression:

Stored size: 1.38 KB

Contents

# encoding: ascii-8bit

# Copyright 2014 Ball Aerospace & Technologies Corp.
# All Rights Reserved.
#
# This program is free software; you can modify and/or redistribute it
# under the terms of the GNU General Public License
# as published by the Free Software Foundation; version 3 with
# attribution addendums as found in the LICENSE.txt

require 'cosmos/tools/tlm_viewer/widgets/widget'
require 'cosmos/tools/tlm_viewer/widgets/canvas_clickable'

module Cosmos
  # Display text on the canvas of a given size and color
  class CanvaslabelWidget
    include Widget
    include CanvasClickable

    def initialize(parent_layout, x, y, text, font_size = 12, color = 'black')
      super()
      @x = x.to_i
      @paint_y = y.to_i
      @text = text
      @color = Cosmos::getColor(color)
      @font = Cosmos.getFont("helvetica", font_size.to_i)
      fm = Qt::FontMetrics.new(@font)
      @x_end = @x + fm.width(text)
      # drawText uses the y value as the bottom of the text
      # Thus for the clickable area we need to set the y_end to the y value
      # and calculate the top y value by subtracting the font height
      @y_end = y.to_i
      @y = @y_end - fm.height()
      parent_layout.add_repaint(self)
    end

    def paint(painter)
      painter.save
      painter.setPen(@color)
      painter.setFont(@font)
      painter.drawText(@x, @paint_y, @text)
      painter.restore
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
cosmos-4.5.2-java lib/cosmos/tools/tlm_viewer/widgets/canvaslabel_widget.rb
cosmos-4.5.2 lib/cosmos/tools/tlm_viewer/widgets/canvaslabel_widget.rb
cosmos-4.5.1-java lib/cosmos/tools/tlm_viewer/widgets/canvaslabel_widget.rb
cosmos-4.5.1 lib/cosmos/tools/tlm_viewer/widgets/canvaslabel_widget.rb
cosmos-4.5.0-java lib/cosmos/tools/tlm_viewer/widgets/canvaslabel_widget.rb
cosmos-4.5.0 lib/cosmos/tools/tlm_viewer/widgets/canvaslabel_widget.rb
cosmos-4.4.2-java lib/cosmos/tools/tlm_viewer/widgets/canvaslabel_widget.rb
cosmos-4.4.2 lib/cosmos/tools/tlm_viewer/widgets/canvaslabel_widget.rb
cosmos-4.4.1-java lib/cosmos/tools/tlm_viewer/widgets/canvaslabel_widget.rb
cosmos-4.4.1 lib/cosmos/tools/tlm_viewer/widgets/canvaslabel_widget.rb
cosmos-4.4.0-java lib/cosmos/tools/tlm_viewer/widgets/canvaslabel_widget.rb
cosmos-4.4.0 lib/cosmos/tools/tlm_viewer/widgets/canvaslabel_widget.rb