Class: Ruber::StatusBar

Inherits:
KDE::StatusBar
  • Object
show all
Defined in:
lib/ruber/main_window/status_bar.rb

Overview

The Ruber status bar

Instance Method Summary (collapse)

Constructor Details

- (StatusBar) initialize(parent)

Creates a new StatusBar. parent is the status bar’s parent widget



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/ruber/main_window/status_bar.rb', line 35

def initialize parent
  super parent
  @view = nil
  @cursor_position_label = Qt::Label.new(self){self.margin = 3}
  @status_label = Qt::Label.new self
  @mode_label = Qt::Label.new(self){self.margin = 3}
  @selection_mode_label = Qt::Label.new(self){self.margin = 3}
#       @cursor_position_label.margin = 3
#       @status_label.margin = 3
#       @mode_label.margin = 3
#       @selection_mode_label.margin = 3
#       @status_label.margin = 3
  add_widget @cursor_position_label
  add_widget @status_label
  add_widget @mode_label
  add_widget @selection_mode_label
  update
end

Instance Method Details

- (Object) clear_widgets

Empties all the widgets in the status bar (it doesn’t hide messages, though)



83
84
85
86
87
88
# File 'lib/ruber/main_window/status_bar.rb', line 83

def clear_widgets
  @cursor_position_label.text = ''
  @status_label.pixmap = Qt::Pixmap.new
  @mode_label.text = ''
  @selection_mode_label.text= ''
end

- (Object) display_information(msg) (private)

Displays the information emitted by the document associated with the view



112
113
114
# File 'lib/ruber/main_window/status_bar.rb', line 112

def display_information msg
  show_message msg, 4000
end

Slot Signature:

display_information(const QString &)

- (Object) update (private)

Update the various widget so they respect the view’s status



95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/ruber/main_window/status_bar.rb', line 95

def update
  if @view
    pos = @view.cursor_position
    update_cursor_position pos
    update_view_mode @view.view_mode
    update_selection_mode @view.block_selection?
  else
    update_cursor_position nil
    update_view_mode nil
    update_selection_mode nil
  end
  update_state
end

Slot Signature:

update()

- (Object) update_cursor_position(pos) (private)

Updates the cursor position



119
120
121
122
123
124
# File 'lib/ruber/main_window/status_bar.rb', line 119

def update_cursor_position pos
  if pos
    @cursor_position_label.text = "Line: #{pos.line+1} Col: #{pos.column+1}"
  else @cursor_position_label.text = ''
  end
end

Slot Signature:

update_cursor_position(KTextEditor::Cursor)

- (Object) update_selection_mode(mode) (private)

Updates the selection mode



136
137
138
139
140
141
# File 'lib/ruber/main_window/status_bar.rb', line 136

def update_selection_mode mode
  @selection_mode_label.text = if mode.nil? then ''
  elsif mode then 'BLOCK'
  else 'LINE'
  end
end

Slot Signature:

update_selection_mode(bool)

- (Object) update_state (private)

Updates the status icon



146
147
148
149
150
151
152
# File 'lib/ruber/main_window/status_bar.rb', line 146

def update_state
  pix = if @view and ((d = @view.document).modified? or d.modified_on_disk?)
    d.icon.pixmap(16)
  else Qt::Pixmap.new(16, 16){|px| px.fill Qt::Color.new(Qt.transparent)}
  end
  @status_label.pixmap = pix
end

Slot Signature:

update_state()

- (Object) update_view_mode(mode) (private)

Updates the view mode



129
130
131
# File 'lib/ruber/main_window/status_bar.rb', line 129

def update_view_mode mode
  @mode_label.text = mode ? mode : ''
end

Slot Signature:

update_view_mode(const QString &)

- (Object) view=(v)

Associates an editor view with the status bar. This means that the status bar will display information about that view.

v can be the view to associate with the status bar or nil. If it’s nil, the status bar won’t show anything



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/ruber/main_window/status_bar.rb', line 61

def view= v
  return if @view == v
  if @view 
    disconnect @view, nil, self, nil 
    disconnect @view.document, nil, self, nil
    clear_widgets
  end
  @view = v
  if v
    connect @view, SIGNAL('information_message(QString, QWidget*)'), self, SLOT('display_information(const QString &)')
    connect @view, SIGNAL('cursor_position_changed(KTextEditor::Cursor, QWidget*)'), self, SLOT('update_cursor_position(KTextEditor::Cursor)')
    connect @view, SIGNAL('view_mode_changed(QString, QWidget*)'), self, SLOT('update_view_mode(const QString &)')
    connect @view, SIGNAL('selection_mode_changed(bool, QWidget*)'), self, SLOT('update_selection_mode(bool)')
    connect @view.document, SIGNAL('modified_changed(bool, QObject*)'), self, SLOT('update_state()')
    connect @view.document, SIGNAL('modified_on_disk(QObject*, bool, KTextEditor::ModificationInterface::ModifiedOnDiskReason)'), self, SLOT('update_state()')
    update
  end
end