class PixelDelegate

Constants

ItemSize

Attributes

pixelSize[RW]

Public Class Methods

new(parent = nil) click to toggle source
Calls superclass method
# File examples/itemviews/pixelator/pixeldelegate.rb, line 32
def initialize(parent = nil)
    super(parent)
    @pixelSize = 12
end

Public Instance Methods

paint(painter, option, index) click to toggle source
# File examples/itemviews/pixelator/pixeldelegate.rb, line 37
def paint(painter, option, index)
    painter.renderHint = Qt::Painter::Antialiasing
    painter.pen = Qt::NoPen

    if (option.state & Qt::Style::State_Selected.to_i) != 0
        painter.brush = option.palette.highlight
    else
        painter.brush = Qt::Brush.new(Qt::white)
    end

    painter.drawRect(option.rect)

    if (option.state & Qt::Style::State_Selected.to_i) != 0
        painter.brush = option.palette.highlightedText
    else
        painter.brush = Qt::Brush.new(Qt::black)
    end

    size = [option.rect.width, option.rect.height].min
    brightness = index.model.data(index, Qt::DisplayRole).to_i
    radius = (size/2.0) - (brightness/255.0 * size/2.0)

    painter.drawEllipse(Qt::RectF.new(option.rect.x + option.rect.width/2 - radius,
                            option.rect.y + option.rect.height/2 - radius,
                            2*radius, 2*radius))
end
sizeHint(option, index) click to toggle source
# File examples/itemviews/pixelator/pixeldelegate.rb, line 64
def sizeHint(option, index)
    return Qt::Size.new(@pixelSize, @pixelSize)
end