Class: Lingvo::GUI::Widget

Inherits:
Qt::Widget
  • Object
show all
Defined in:
lib/lingvo/gui/widget.rb

Instance Method Summary collapse

Constructor Details

#initialize(parent = nil) ⇒ Widget

Returns a new instance of Widget.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/lingvo/gui/widget.rb', line 8

def initialize(parent = nil)
  super
  @conf = Config.gui
  @conf[:size_for_image] = 0

  setStyleSheet("* { background: #{@conf[:bg]}; margin: #{@conf[:margin]}px }");
  Qt::Shortcut.new Qt::KeySequence.new(Qt::Key_Q.to_i), self, SLOT(:close)
  Qt::Shortcut.new Qt::KeySequence.new(Qt::Key_N.to_i), self, SLOT(:update)

  if @conf[:image].present?
    pixmap = Qt::Pixmap.new(@conf[:image]).scaled(@conf[:image_size_y], @conf[:image_size_x])
    Qt::Label.new('',self).setPixmap pixmap
    @conf[:size_for_image] = @conf[:image_size_y] + 5 # with left space
  end

  @label = Qt::Label.new('', self)

  show
  update
end

Instance Method Details

#closeObject



57
58
59
# File 'lib/lingvo/gui/widget.rb', line 57

def close
  Simple.app.quit
end

#updateObject



52
53
54
55
# File 'lib/lingvo/gui/widget.rb', line 52

def update
  update_word
  update_position
end

#update_positionObject



43
44
45
46
47
48
49
50
# File 'lib/lingvo/gui/widget.rb', line 43

def update_position
  screen_w = Qt::Application::desktop.width.to_i
  screen_w -= 10                    # left space
  screen_w -= @label.sizeHint.width # base label
  screen_w -= @conf[:size_for_image]# image space

  move(screen_w, 20)
end

#update_wordObject



37
38
39
40
41
# File 'lib/lingvo/gui/widget.rb', line 37

def update_word
  @label.setText(word)
  @label.setGeometry(@conf[:size_for_image], 0, @label.sizeHint.width, @label.sizeHint.height)
  setFixedSize(@label.sizeHint.width + @conf[:size_for_image], @label.sizeHint.height)
end

#wordObject



29
30
31
32
33
34
35
# File 'lib/lingvo/gui/widget.rb', line 29

def word
  word = Lingvo::Models::English.rand(1).first
  Console.no_word if word.nil?
  label = "<div style='font-size: #{@conf[:eng_size]}px; color: #{@conf[:eng_fg]}'>#{word.eng}</div>"
  label += "<div style='font-size: #{@conf[:transcr_size]}px; color: #{@conf[:transcr_fg]};'>#{word.transcr}</div>" if @conf[:transcr] == 'on'
  label += "<div style='font-size: #{@conf[:ru_size]}px; color: #{@conf[:ru_fg]}'>#{word.ru}</div>"
end