Class: Ui::RelationDelegate

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

Constant Summary collapse

MAX_WIDTH =
50

Instance Method Summary collapse

Instance Method Details

#createEditor(parent, option, index) ⇒ Object



169
170
171
172
173
174
175
# File 'lib/roby/gui/relations_view/relations_config.rb', line 169

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



177
178
179
180
181
182
183
184
185
186
187
188
189
# File 'lib/roby/gui/relations_view/relations_config.rb', line 177

def paint(painter, option, index)
    if index.column == 1 && RelationConfigModel.category_from_index(index) >= 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