class RuGUI::FrameworkAdapters::Qt4::BaseView
Public Class Methods
Returns the builder file extension to be used for this view class.
# File lib/rugui/framework_adapters/Qt4.rb, line 104 def builder_file_extension 'ui' end
Public Instance Methods
Adds a widget to the given container widget.
# File lib/rugui/framework_adapters/Qt4.rb, line 47 def add_widget_to_container(widget, container_widget) widget.parent = container_widget end
Autoconnects signals handlers for the view. If other_target
is given it is used instead of the view itself.
# File lib/rugui/framework_adapters/Qt4.rb, line 70 def autoconnect_signals(view, other_target = nil) # Qt4 doesn't provides a method for autoconnecting signals. end
Builds widgets from the given filename, using the proper builder.
# File lib/rugui/framework_adapters/Qt4.rb, line 90 def build_widgets_from(filename) ui_file_root_widget = load_ui_file(filename) @view_root_widget = root_widget_from(ui_file_root_widget) create_attributes_for_widget_and_children(@view_root_widget) @view_root_widget.show if self.adapted_object.display_root? end
Connects the signal from the widget to the given receiver method.
# File lib/rugui/framework_adapters/Qt4.rb, line 83 def connect_declared_signal(widget, signal, receiver, method) widget.connect(SIGNAL(signal)) do |*args| receiver.send(method, *args) end end
Connects the signal from the widget to the given receiver block. The block is executed in the context of the receiver.
# File lib/rugui/framework_adapters/Qt4.rb, line 76 def connect_declared_signal_block(widget, signal, receiver, block) widget.connect(SIGNAL(signal)) do |*args| receiver.instance_exec(*args, &block) end end
Queues the block call, so that it is only gets executed in the main thread.
# File lib/rugui/framework_adapters/Qt4.rb, line 42 def queue(&block) block.call end
Registers widgets as attributes of the view class.
# File lib/rugui/framework_adapters/Qt4.rb, line 98 def register_widgets register_widget_and_children(@view_root_widget) end
Removes all children from the given container widget.
# File lib/rugui/framework_adapters/Qt4.rb, line 57 def remove_all_children(container_widget) container_widget.children.each do |child| child.parent = nil end end
Removes a widget from the given container widget.
# File lib/rugui/framework_adapters/Qt4.rb, line 52 def remove_widget_from_container(widget, container_widget) widget.parent = nil end
Sets the widget name for the given widget if given.
# File lib/rugui/framework_adapters/Qt4.rb, line 64 def set_widget_name(widget, widget_name) widget.object_name = widget_name end
Private Instance Methods
# File lib/rugui/framework_adapters/Qt4.rb, line 121 def create_attributes_for_widget_and_children(widget) self.adapted_object.send(:create_attribute_for_widget, widget.object_name) widget.children.each do |child| create_attributes_for_widget_and_children(child) unless child.object_name.blank? end end
XXX: Qt’s find_child
is not working, so we do it ourselves, this is surely not optimal.
# File lib/rugui/framework_adapters/Qt4.rb, line 146 def find_child(widget, widget_name) for child in widget.children if child.object_name == widget_name return child else child_found = find_child(child, widget_name) return child_found unless child_found.blank? end end end
# File lib/rugui/framework_adapters/Qt4.rb, line 110 def load_ui_file(filename) file = Qt::File.new(filename) file.open(Qt::File::ReadOnly) loader = Qt::UiLoader.new loader.load(file, nil) end
# File lib/rugui/framework_adapters/Qt4.rb, line 136 def register_widget(widget) unless widget.object_name.nil? self.adapted_object.send("#{widget.object_name}=", widget) self.adapted_object.widgets[widget.object_name] = widget else self.adapted_object.unnamed_widgets << widget end end
Registers widgets as attributes of the view class.
# File lib/rugui/framework_adapters/Qt4.rb, line 129 def register_widget_and_children(widget) register_widget(widget) widget.children.each do |child| register_widget_and_children(child) end end
# File lib/rugui/framework_adapters/Qt4.rb, line 117 def root_widget_from(ui_file_root_widget) self.adapted_object.root.nil? ? ui_file_root_widget : find_child(ui_file_root_widget, self.adapted_object.root) end