Class: Ui::RelationDelegate

Inherits:
Qt::ItemDelegate
  • Object
show all
Defined in:
lib/roby/log/gui/relations.rb

Constant Summary collapse

MAX_WIDTH =
50

Instance Method Summary collapse

Instance Method Details

#createEditor(parent, option, index) ⇒ Object



119
120
121
122
123
124
125
# File 'lib/roby/log/gui/relations.rb', line 119

def createEditor(parent, option, index)
    color = index.model.data(index, Qt::DisplayRole).to_string
    new_color = Qt::ColorDialog.get_color(Qt::Color.new(color))
    index.model.setData(index, Qt::Variant.new(new_color.name), Qt::DisplayRole)

    nil
end

#paint(painter, option, index) ⇒ Object



126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/roby/log/gui/relations.rb', line 126

def paint(painter, option, index)
    if index.column == 1 && index.internalPointer >= 0
  color = index.model.data(index, Qt::DisplayRole).to_string
  rect = option.rect
  rect.adjust(1, 1, -1, -1)
  if rect.width > MAX_WIDTH
      rect.width = MAX_WIDTH
  end
  painter.fill_rect rect, Qt::Brush.new(Qt::Color.new(color))
    else
  super
    end
end