Class: Ruber::Rake::ShortcutDelegate

Inherits:
Qt::StyledItemDelegate
  • Object
show all
Defined in:
plugins/rake/rake_widgets.rb

Overview

Delegate which allows to edit the entries using a KDE::KeySequenceWidget

Instance Method Summary (collapse)

Constructor Details

- (ShortcutDelegate) initialize(col, parent = nil)

A new instance of ShortcutDelegate

Parameters:

  • col (Integer)

    the column number

  • parent (Qt::Widget, nil) (defaults to: nil)

    the parent widget



121
122
123
124
# File 'plugins/rake/rake_widgets.rb', line 121

def initialize col, parent = nil
  super parent
  @column = col
end

Instance Method Details

- (Qt::Widget) createEditor(parent, opt, idx)

Override of Qt::StyledItemDelegate#createEditor which returns a KDE::KeySequenceWidget.

Parameters:

  • parent (Qt::Object)

    the parent object

  • opt (Qt::StyleOptionViewItem)

    controls how the editor appears

  • idx (Qt::ModelIndex)

    the index the editor is for

Returns:

  • (Qt::Widget)

    the editor widget



135
136
137
138
139
140
141
142
143
144
# File 'plugins/rake/rake_widgets.rb', line 135

def createEditor parent, opt, idx
  if idx.column != @column then super
  else
    w = KDE::KeySequenceWidget.new parent
    connect w, SIGNAL('stealShortcut(QKeySequence, KAction*)'), w, SLOT(:applyStealShortcut)
    collections = Ruber[:main_window].factory.clients.map{|cl| cl.action_collection}
    w.check_action_collections = collections
    w
  end
end

- (nil) setEditorData(w, idx)

Override of Qt::StyledItemDelegate#setEditorData which fills the editor with the content of the model.

Parameters:

  • w (Qt::Widget)

    the editor widget

  • idx (Qt::ModelIndex)

    the index the editor is for

Returns:

  • (nil)


154
155
156
157
158
159
# File 'plugins/rake/rake_widgets.rb', line 154

def setEditorData w, idx
  if idx.column != @column then super
  else w.key_sequence = Qt::KeySequence.new(idx.data.to_string)
  end
  nil
end

- (nil) setModelData(w, model, idx)

Override of Qt::StyledItemDelegate#setModelData which inserts the contents of the shortcut widget in the model.

Parameters:

  • w (Qt::Widget)

    the editor widget

  • the (Qt::AbstractItemModel)

    model the index refers to

  • the (Qt::ModelIndex)

    index to modify

Returns:

  • (nil)


170
171
172
173
174
175
# File 'plugins/rake/rake_widgets.rb', line 170

def setModelData w, model, idx
  if idx.column != @column then super
  else model.set_data idx, Qt::Variant.new(w.key_sequence.to_string), Qt::DisplayRole
  end
  nil
end

- (nil) updateEditorGeometry(w, opt, idx)

Override of Qt::StyledItemDelegate#updateEditorGeometry

geometry

Parameters:

  • w (Qt::Widget)

    the editor widget

  • opt (Qt::StyleOptionViewItem)

    the option to use when changing the editor

  • the (Qt::ModelIndex)

    index associated with the editor

Returns:

  • (nil)


186
187
188
189
190
191
192
193
194
195
# File 'plugins/rake/rake_widgets.rb', line 186

def updateEditorGeometry w, opt, idx
  if idx.column != @column then super
  else
    tl = opt.rect.top_left
    size = w.rect.size
    size.width += 50
    w.geometry = Qt::Rect.new tl, size
  end
  nil
end