Class: Ruber::EditorView

Inherits:
Qt::Widget
  • Object
show all
Includes:
KTextEditorWrapper
Defined in:
lib/ruber/editor/editor_view.rb

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Methods included from KTextEditorWrapper

#connect_wrapped_signals, #initialize_wrapper, #interface, #internal, #method_missing, prepare_wrapper_connections

Signal Summary

Constructor Details

- (EditorView) initialize(doc, internal, parent = nil)

A new instance of EditorView



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/ruber/editor/editor_view.rb', line 72

def initialize doc, internal, parent = nil
  super parent
  set_attribute Qt::WA_DeleteOnClose, true
  @block_selection = false
  @doc = doc
  @view = internal
  @view.parent = self
  initialize_wrapper @view, self.class.instance_variable_get(:@signal_table)
  self.focus_proxy = @view
  self.layout = Qt::VBoxLayout.new self
  layout.set_contents_margins 0,0,0,0
  layout.spacing = 0
  layout.add_widget @view

  connect @view, SIGNAL('selectionChanged(KTextEditor::View*)'), self, SLOT('slot_selection_changed(KTextEditor::View*)')
  
  @view.connect(SIGNAL('cursorPositionChanged(KTextEditor::View*, KTextEditor::Cursor)'))do |v, c| 
    emit cursor_position_changed( @view.cursor_position_virtual, self)
  end
  @view.connect(SIGNAL('mousePositionChanged(KTextEditor::View*, KTextEditor::Cursor)')) do |v, c|
    emit mouse_position_changed( @view.cursor_position_virtual, self)
  end
  @view.connect(SIGNAL('viewModeChanged(KTextEditor::View*)')) do |v|
    emit view_mode_changed( view_mode, self)
  end
  @view.connect(SIGNAL('viewEditModeChanged(KTextEditor::View*, KTextEditor::View::EditMode)')) do |v, m|
    emit edit_mode_changed( m, self)
  end

  am = @doc.interface('annotation_interface').annotation_model
  am.connect(SIGNAL('annotations_changed()')) do
    show = Ruber[:config][:general, :auto_annotations] && am.has_annotations?
    set_annotation_border_visible(show) rescue NoMethodError
  end
  
  @view.context_menu = @view.default_context_menu(Qt::Menu.new(@view))
  
  self.focus_policy = Qt::WheelFocus
  
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Ruber::KTextEditorWrapper

Instance Attribute Details

- (Object) doc (readonly) Also known as: document

signals ‘closing()’, ‘information_message(QString, QObject*)’, ‘cursor_position_changed(KTextEditor::Cursor, QObject*)’, ‘view_mode_changed(QString, QObject*)’, ‘edit_mode_changed(KTextEditor::View::EditMode, QObject*)’, ‘selection_mode_changed(bool, QObject*)’, ‘context_menu_about_to_show(QMenu*, QObject*)’, ‘focus_in(QObject*)’, ‘focus_out(QObject*)’, ‘horizontal_scroll_position_changed(QObject*)’, ‘mouse_position_changed(KTextEditor::Cursor, QObject*)’, ‘selection_changed(QObject*)’, ‘text_inserted(KTextEditor::Cursor, QString, QObject*)’, ‘vertical_scroll_position_changed(KTextEditor::Cursor, QObject*)’



70
71
72
# File 'lib/ruber/editor/editor_view.rb', line 70

def doc
  @doc
end

Instance Method Details

- (Boolean) block_selection?

Returns:

  • (Boolean)


143
144
145
# File 'lib/ruber/editor/editor_view.rb', line 143

def block_selection?
  @view.block_selection.to_bool
end

- (Object) close



147
148
149
150
# File 'lib/ruber/editor/editor_view.rb', line 147

def close
  emit closing self
  super
end

- (Object) execute_action(name, arg = nil)

Executes the action with name the view’s action collection. This is made by having the action emit the triggered() or toggled(bool) signal (depending on whether it’s a standard action or a KDE::ToggleAction). In the second case, arg is the argument passed to the signal.

Returns true if an action with name name was found and false otherwise.



165
166
167
168
169
170
171
172
173
# File 'lib/ruber/editor/editor_view.rb', line 165

def execute_action name, arg = nil
  a = action_collection.action(name)
  case a
  when KDE::ToggleAction then a.instance_eval{emit toggled(arg)}
  when nil then return false
  else a.instance_eval{emit triggered}
  end
  true
end

- (Object) go_to(row, col)



131
132
133
# File 'lib/ruber/editor/editor_view.rb', line 131

def go_to row, col
  @view.set_cursor_position KTextEditor::Cursor.new(row, col)
end

- (Object) hide_annotation_border



139
140
141
# File 'lib/ruber/editor/editor_view.rb', line 139

def hide_annotation_border
  set_annotation_border_visible false
end

- (Object) hideEvent(e) (protected)



177
178
179
# File 'lib/ruber/editor/editor_view.rb', line 177

def hideEvent e
  emit about_to_hide(self) unless e.spontaneous
end

- (Boolean) move_cursor_by(row, col)

Moves the cursor of the given amount

If the cursor ends up being out of range, nothing is done

Parameters:

  • row (Integer)

    the amount of rows to move the cursor of. If it’s negative, the cursor will be moved upwards, otherwise it’ll be moved downwards

  • col (Integer)

    the amount of columns to move the cursor of. If it’s negative, the cursor will be moved to the left, otherwise it’ll be moved to the right

Returns:

  • (Boolean)

    true if the cursor was moved successfully and false if it was out of range



124
125
126
127
128
129
# File 'lib/ruber/editor/editor_view.rb', line 124

def move_cursor_by row, col
  cur = @view.cursor_position
  cur.line += row
  cur.column += col
  @view.set_cursor_position cur
end

- (Object) set_annotation_border_visible(vis)



152
153
154
# File 'lib/ruber/editor/editor_view.rb', line 152

def set_annotation_border_visible vis
  @view.qobject_cast(KTextEditor::AnnotationViewInterface).set_annotation_border_visible vis
end

- (Object) show_annotation_border



135
136
137
# File 'lib/ruber/editor/editor_view.rb', line 135

def show_annotation_border
  set_annotation_border_visible true
end

- (Object) showEvent(e) (protected)



181
182
183
# File 'lib/ruber/editor/editor_view.rb', line 181

def showEvent e
  emit about_to_show(self) unless e.spontaneous
end

- (Object) slot_selection_changed(v) (private)



187
188
189
190
191
192
193
194
# File 'lib/ruber/editor/editor_view.rb', line 187

def slot_selection_changed v
  emit selection_changed(self)
  changed = @view.block_selection ^ @block_selection
  if changed
    @block_selection = @view.block_selection
    emit selection_mode_changed(@block_selection, self)
  end
end

Slot Signature:

slot_selection_changed(KTextEditor::View*)

Signal Details

- closing(QWidget* arg1)

- cursor_position_changed(KTextEditor::Cursor arg1, QWidget* arg2)

- view_mode_changed(QString arg1, QWidget* arg2)

- edit_mode_changed(KTextEditor::View::EditMode arg1, QWidget* arg2)

- selection_mode_changed(bool arg1, QWidget* arg2)

- mouse_position_changed(KTextEditor::Cursor arg1, QWidget* arg2)

- selection_changed(QWidget* arg1)

- about_to_hide(QWidget* arg1)

- about_to_show(QWidget* arg1)