Class: Syskit::GUI::RuntimeState::ActionListDelegate

Inherits:
Qt::StyledItemDelegate
  • Object
show all
Defined in:
lib/syskit/gui/runtime_state.rb

Constant Summary collapse

OUTER_MARGIN =
5
INTERLINE =
3

Instance Method Summary collapse

Instance Method Details

#paint(painter, option, index) ⇒ Object



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
# File 'lib/syskit/gui/runtime_state.rb', line 82

def paint(painter, option, index)
    painter.save

    if (option.state & Qt::Style::State_Selected) != 0
        painter.fill_rect(option.rect, option.palette.highlight)
        painter.brush = option.palette.highlighted_text
    end

    main = index.data.toString
    doc = index.data(Qt::UserRole).to_string || ''
    text_bounds = Qt::Rect.new

    fm = option.font_metrics
    painter.draw_text(
        Qt::Rect.new(option.rect.x + OUTER_MARGIN, option.rect.y + OUTER_MARGIN, option.rect.width - 2 * OUTER_MARGIN, fm.height),
        Qt::AlignLeft, main, text_bounds)

    font = painter.font
    font.italic = true
    painter.font = font
    painter.draw_text(
        Qt::Rect.new(option.rect.x + OUTER_MARGIN, text_bounds.bottom + INTERLINE, option.rect.width - 2 * OUTER_MARGIN, fm.height),
        Qt::AlignLeft, doc, text_bounds)
ensure
    painter.restore
end

#sizeHint(option, index) ⇒ Object



73
74
75
76
77
78
79
80
# File 'lib/syskit/gui/runtime_state.rb', line 73

def sizeHint(option, index)
    fm = option.font_metrics
    main = index.data.toString
    doc = index.data(Qt::UserRole).to_string || ''
    Qt::Size.new(
        [fm.width(main), fm.width(doc)].max + 2 * OUTER_MARGIN,
        fm.height * 2 + OUTER_MARGIN * 2 + INTERLINE)
end