Class: Ruber::Workspace
- Defined in:
- lib/ruber/main_window/workspace.rb
Overview
Widget representing the main area of Ruber’s main window, containing the tool widgets, together with their tab bars, and the tab widget containing the views.
Tool Widgets
The workspace provides three tool widgets containers, on all sides of the editor views except above them. The container on each side is indipendent from the others.
A tool widget can be
-
raised
orlowered
: a raised tool widget is the only one which can bee seen and interact with the user. There can be only one raised tool widget for side. All other tool widgets are said to be lowered. -
visible
orhidden
: while a lowered tool widget is can never be seen, the opposite is not necessarily true. A raised tool widget will be visible only if its container is visible, otherwise it will be hidden, too -
active
orinactive
: a tool widget is active only if it has focus, otherwise it’s inactive. Obviously, only visible tool widgets can be active and there can be at most one active tool widget in all the workspace.
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) ⇒ Object
Adds a tool widget to the workspace.
- #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
Creates a new Workspace.
-
#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.
-
#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
Creates a new Workspace. parent is the workspace’s parent widget
124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/ruber/main_window/workspace.rb', line 124 def initialize parent = nil super @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.
240 241 242 243 244 245 |
# File 'lib/ruber/main_window/workspace.rb', line 240 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.
324 325 326 327 328 329 |
# File 'lib/ruber/main_window/workspace.rb', line 324 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) ⇒ Object
Adds a tool widget to the workspace. side is the side where the widget should be put. It can be :left
, :right
or :bottom
. widget is the widget to add; icon is the Qt::Pixmap
containing the icon to put on the tab bar and caption is the text to display on the same caption.
If widget had already been added as a tool widget (either on the same side or another side, then ArgumentError is raised).
145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/ruber/main_window/workspace.rb', line 145 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 end |
#current_widget(side) ⇒ Object
317 318 319 |
# File 'lib/ruber/main_window/workspace.rb', line 317 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.
278 279 280 281 282 283 284 285 286 287 288 289 290 |
# File 'lib/ruber/main_window/workspace.rb', line 278 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 |
#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
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/ruber/main_window/workspace.rb', line 188 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.
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/ruber/main_window/workspace.rb', line 163 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 |
#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.
220 221 222 223 224 225 226 227 228 229 230 231 |
# File 'lib/ruber/main_window/workspace.rb', line 220 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.
298 299 300 301 302 303 304 305 |
# File 'lib/ruber/main_window/workspace.rb', line 298 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.
261 262 263 264 265 266 267 |
# File 'lib/ruber/main_window/workspace.rb', line 261 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.
311 312 313 314 315 |
# File 'lib/ruber/main_window/workspace.rb', line 311 def res = {} @widgets.each_pair{|w, data| res[w] = data.side} res end |