Class: Ruber::Workspace
- Defined in:
- lib/ruber/main_window/workspace.rb
Overview
Widget representing the main area of Ruber’s main window. It contains the space for the main widget (that is, the tab widget where the editors are located) and the tool widgets, together with their tab bars.
To allow for several main widgets existing (but not being visible) at the same time (one main widget for each environment) the space for the main widget is given by a single @Qt::StackedWidget@, where the different main widgets are placed using #add_widget. #main_widget= is then used to bring one of the main widgets to the foreground; #remove_widget removes a widget from the stacked widget (to be used when a project is closed).
The workspace provides three _tool widgets containers_, one on each side of the main widget except above it. The container on each side is indipendent from the others. The containers have buttons for their tool widgets and a @Qt::StackedWidget@ for the widget themselves. Each container is indipendent from the other ones
A tool widget can be in several different states:
-
raised or lowered: a tool widget is raised when it’s on the top of its container stacked widget. There can be only one raised tool widget for side. All tool widgets which aren’t raised are said to be lowered
-
visible or hidden: each tool widget container can be visible or hidden. The raised tool widget in a visible container is said to be visible. Widgets in an hidden container are said to be hidden.
-
active or inactive: the active tool widget is the one which has keyboard focus; all others are inactive. Of course there can be at most one active tool widget across the whole workspace. If the focus is not in one of the tool widgets (most likely meaning one of the editors has focus), all tool widgets will be inactive.
Defined Under Namespace
Classes: StackedWidget, ToolData
Instance Method Summary collapse
-
#activate_tool(tool) ⇒ Object
Gives focus to the tool widget tool (raising and showing it if necessary).
-
#active_tool ⇒ Object
Returns the active tool widget, or nil if there’s no active tool widget.
-
#add_tool_widget(side, widget, icon, caption) ⇒ nil
Adds a tool widget to the workspace.
- #add_widget(w) ⇒ Object
- #current_widget(side) ⇒ Object
-
#hide_tool(tool) ⇒ Object
Hides the stack containing the tool widget tool, giving focus to the active editor, if tool is raised (that is, if it is the current widget of its stack).
-
#initialize(parent = nil) ⇒ Workspace
constructor
A new instance of Workspace.
- #main_widget ⇒ Object
- #main_widget=(w) ⇒ Object
-
#raise_tool(tool) ⇒ Object
Raises the tool widget tool, which can be either the tool widget itself or its
object_name
, either as a string or symbol. -
#remove_tool_widget(arg) ⇒ Object
Removes a tool widget.
- #remove_widget(w) ⇒ Object
-
#show_tool(tool) ⇒ Object
Shows the tool widget tool.
-
#store_sizes ⇒ Object
Stores the tool widgets size in the configuration manager.
-
#toggle_tool(tool) ⇒ Object
Slot.
-
#tool_widgets ⇒ Object
Returns a hash having all the tool widgets as keys and the side each of them is (
:left
,:right
,:bottom
) as values.
Constructor Details
#initialize(parent = nil) ⇒ Workspace
Returns a new instance of Workspace.
129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/ruber/main_window/workspace.rb', line 129 def initialize parent = nil super parent @button_bars = {} @splitters = {} @stacks = {} @widgets = {} @next_id = 0 @tool_sizes = {} @sizes = Ruber[:config][:workspace, :tools_sizes].dup create_skeleton end |
Instance Method Details
#activate_tool(tool) ⇒ Object
Gives focus to the tool widget tool (raising and showing it if necessary). tool can be either the tool widget itself or its object_name
(as either a string or symbol). If tool doesn’t represent a valid tool widget, nothing happens. If tool is a string or symbol and more than one tool widget with the same name exists, which one will obtain focus is undefined.
270 271 272 273 274 275 |
# File 'lib/ruber/main_window/workspace.rb', line 270 def activate_tool tool tool, data = tool_and_data tool return unless tool show_tool tool unless tool.visible? tool.set_focus end |
#active_tool ⇒ Object
Returns the active tool widget, or nil if there’s no active tool widget.
354 355 356 357 358 359 |
# File 'lib/ruber/main_window/workspace.rb', line 354 def active_tool fw = KDE::Application. if @widgets.include? fw then fw else @widgets.keys.find{|w| w.find_children(Qt::Widget).include? fw} end end |
#add_tool_widget(side, widget, icon, caption) ⇒ nil
Adds a tool widget to the workspace
174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/ruber/main_window/workspace.rb', line 174 def side, , icon, if @stacks.values.include? .parent Kernel.raise ArgumentError, "This widget has already been added as tool widget" end = @button_bars[side] id = @next_id .append_tab icon, id, @widgets[] = ToolData.new side, id @stacks[side]. connect .tab(id), SIGNAL('clicked(int)'), self, SLOT('toggle_tool(int)') @next_id += 1 nil end |
#add_widget(w) ⇒ Object
141 142 143 |
# File 'lib/ruber/main_window/workspace.rb', line 141 def w @main_widget. w end |
#current_widget(side) ⇒ Object
347 348 349 |
# File 'lib/ruber/main_window/workspace.rb', line 347 def side @stacks[side]. end |
#hide_tool(tool) ⇒ Object
Hides the stack containing the tool widget tool, giving focus to the active editor, if tool is raised (that is, if it is the current widget of its stack).
tool can be either the tool widget itself or its object_name
(as either a string or symbol). If tool doesn’t represent a valid tool widget, nothing happens. If tool is a string or symbol and more than one tool widget with the same name exists, which one will be used is undefined.
308 309 310 311 312 313 314 315 316 317 318 319 320 |
# File 'lib/ruber/main_window/workspace.rb', line 308 def hide_tool tool tool, data = tool_and_data tool return unless tool store_tool_size tool if tool.visible? stack = tool.parent if stack. == tool @button_bars[data.side].set_tab data.id, false if stack.visible? stack.hide Ruber[:main_window].focus_on_editor end end end |
#main_widget ⇒ Object
149 150 151 |
# File 'lib/ruber/main_window/workspace.rb', line 149 def @main_widget. end |
#main_widget=(w) ⇒ Object
153 154 155 156 157 158 |
# File 'lib/ruber/main_window/workspace.rb', line 153 def w unless @main_widget.include? w Kernel.raise ArgumentError, "a widget which has not been added to the workspace can\'t become the main widget" end @main_widget. = w end |
#raise_tool(tool) ⇒ Object
Raises the tool widget tool, which can be either the tool widget itself or its object_name
, either as a string or symbol. If tool is not a tool widget (or if no tool widget with that object_name
exists), nothing is done. If tool is a string or symbol and more than one tool widget exist with that object_name
, which one is raised is undefined.
Note: this method doesn’t make the container of tool visible if it’s hidden
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 |
# File 'lib/ruber/main_window/workspace.rb', line 218 def raise_tool tool tool, data = tool_and_data tool return unless tool = @button_bars[data.side] stack = @stacks[data.side] old = stack. if old and old.visible? store_tool_size old old_data = @widgets[old] .set_tab old_data.id, false end .set_tab data.id, true if old != tool stack. = tool emit tool_raised(tool) emit tool_shown(tool) if stack.visible? end resize_tool tool end |
#remove_tool_widget(arg) ⇒ Object
Removes a tool widget. arg can be either the widget itself or its object_name
, either as a string or as a symbol. If the widget isn’t a tool widget, nothing happens.
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/ruber/main_window/workspace.rb', line 193 def arg , data = if arg.is_a? String or arg.is_a? Symbol @widgets.find{|k, v| k.object_name == arg.to_s} else [arg, @widgets[arg]] end return unless and data emit removing_tool() stack = @stacks[data.side] raised = stack..equal?() stack. if stack.empty? then stack.hide else raise_tool stack. end @button_bars[data.side].remove_tab data.id end |
#remove_widget(w) ⇒ Object
145 146 147 |
# File 'lib/ruber/main_window/workspace.rb', line 145 def w @main_widget. w end |
#show_tool(tool) ⇒ Object
Shows the tool widget tool. This means that tool will become the current widget in its stack and that the stack will become visible (if it’s not already visible). tool won’t receive focus, unless the previously current widget of its stack had focus.
tool can be either the tool widget itself or its object_name
, either as string or as symbol. In the latter cases, it there’s more than one tool widget with the same object_name
, it’s undefined which one will be shown.
If tool isn’t a tool widget, nothing happens.
250 251 252 253 254 255 256 257 258 259 260 261 |
# File 'lib/ruber/main_window/workspace.rb', line 250 def show_tool tool tool, data = tool_and_data tool return unless tool data = @widgets[tool] stack = @stacks[data.side] visible = tool.visible? give_focus = stack.find_children(Qt::Widget).any?{|w| w.has_focus} raise_tool tool stack.show unless stack.visible? emit tool_shown(tool) unless visible tool.set_focus if give_focus end |
#store_sizes ⇒ Object
Stores the tool widgets size in the configuration manager. It reads the sizes of the splitters for the tool widgets which are visible and uses the values stored previously for the others.
328 329 330 331 332 333 334 335 |
# File 'lib/ruber/main_window/workspace.rb', line 328 def store_sizes @stacks.each_value do |s| w = s. next unless w store_tool_size w if w.visible? end Ruber[:config][:workspace, :tools_sizes] = @sizes end |
#toggle_tool(tool) ⇒ Object
Slot
Activates the tool tool if it’s not visibile and hides its stack if instead it’s visible.
tool can be either the tool widget itself or its object_name
(as either a string or symbol) or the id of the tab associated with the tool widget. If tool doesn’t represent a valid tool widget, nothing happens. If tool is a string or symbol and more than one tool widget with the same name exists, which one will obtain focus is undefined.
Note: the use of the id of the tab as argument is only for internal use.
291 292 293 294 295 296 297 |
# File 'lib/ruber/main_window/workspace.rb', line 291 def toggle_tool tool tool, data = tool_and_data tool return unless tool if !tool.visible? then activate_tool tool else hide_tool tool end end |
#tool_widgets ⇒ Object
Returns a hash having all the tool widgets as keys and the side each of them is (:left
, :right
, :bottom
) as values.
341 342 343 344 345 |
# File 'lib/ruber/main_window/workspace.rb', line 341 def res = {} @widgets.each_pair{|w, data| res[w] = data.side} res end |