Sha256: 7f30a47048bf40408fc32eead8a69c78ac08735733d3cc43eef0f5f616f8cb09

Contents?: true

Size: 1.75 KB

Versions: 101

Compression:

Stored size: 1.75 KB

Contents

require "Qt"
require "qtuitools"
require "knjrbfw/libqt_window.rb"

class QtLoader
  def window
    return @window
  end
  
  def loader
    return @loader
  end
  
  def object_connect
    return @object_connect
  end
  
  def widget(name)
    return @widgets[name]
  end
  
  def initialize(paras)
    @widgets = {}
    
    if (paras.class.to_s == "Hash")
      file_path = paras["file"]
      @object_connect = paras["object_connect"]
    elsif(paras.class.to_s == "String")
      file_path = paras
    elsif(paras.class.to_s == "Array")
      file_path = paras[0]
      @object_connect = paras[1]
    else
      raise "Unknown parameter"
    end
    
    file = Qt::File.new(file_path)
    file.open(Qt::File::ReadOnly)
    @loader = Qt::UiLoader.new
    @window = @loader.load(file, nil)
    file.close
    
    
    @window.findChildren(Qt::Object).each do |widget|
      object_name = widget.object_name.to_s
      
      if (object_name.length > 0)
        @widgets[object_name] = widget
        
        if (@object_connect)
          meta = widget.meta_object
          signals = {}
          0.upto(meta.methodCount - 1) do |count|
            method_info = meta.method(count)
            
            if (method_info.method_type == 1)
              method_name = method_info.signature.match(/^(.+)\(/)
              signals[method_name[1]] = method_info.signature
            end
          end
        end
        
        signals.each do |item|
          func_name = "on_" + object_name + "_" + item[0]
          if (@object_connect.respond_to?(func_name))
            params = item[1].sub(/[a-z]+(\(.*$)/, '\1')
            widget.connect(SIGNAL item[1]) do
              @object_connect.send(func_name)
            end
          end
        end
      end
    end
  end
end

Version data entries

101 entries across 101 versions & 1 rubygems

Version Path
knjrbfw-0.0.72 lib/knj/libqt.rb
knjrbfw-0.0.71 lib/knj/libqt.rb
knjrbfw-0.0.70 lib/knj/libqt.rb
knjrbfw-0.0.69 lib/knj/libqt.rb
knjrbfw-0.0.68 lib/knj/libqt.rb
knjrbfw-0.0.67 lib/knj/libqt.rb
knjrbfw-0.0.66 lib/knj/libqt.rb
knjrbfw-0.0.65 lib/knj/libqt.rb
knjrbfw-0.0.64 lib/knj/libqt.rb
knjrbfw-0.0.63 lib/knj/libqt.rb
knjrbfw-0.0.62 lib/knj/libqt.rb
knjrbfw-0.0.59 lib/knj/libqt.rb
knjrbfw-0.0.58 lib/knj/libqt.rb
knjrbfw-0.0.57 lib/knj/libqt.rb
knjrbfw-0.0.55 lib/knj/libqt.rb
knjrbfw-0.0.54 lib/knj/libqt.rb
knjrbfw-0.0.53 lib/knj/libqt.rb
knjrbfw-0.0.52 lib/knj/libqt.rb
knjrbfw-0.0.51 lib/knj/libqt.rb
knjrbfw-0.0.50 lib/knj/libqt.rb