Class: PixelDelegate

Inherits:
Qt::AbstractItemDelegate
  • Object
show all
Defined in:
ext/ruby/qtruby/examples/itemviews/pixelator/pixeldelegate.rb

Overview

** ** Copyright © 2004-2005 Trolltech AS. All rights reserved. ** ** This file is part of the example classes of the Qt Toolkit. ** ** This file may be used under the terms of the GNU General Public ** License version 2.0 as published by the Free Software Foundation ** and appearing in the file LICENSE.GPL included in the packaging of ** this file. Please review the following information to ensure GNU ** General Public Licensing requirements will be met: ** www.trolltech.com/products/qt/opensource.html ** ** If you are unsure which license is appropriate for your use, please ** review the following information: ** www.trolltech.com/products/qt/licensing.html or contact the ** sales department at [email protected]. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. **

** Translated to QtRuby by Richard Dale

Constant Summary collapse

ItemSize =
256

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent = nil) ⇒ PixelDelegate

Returns a new instance of PixelDelegate.



32
33
34
35
# File 'ext/ruby/qtruby/examples/itemviews/pixelator/pixeldelegate.rb', line 32

def initialize(parent = nil)
    super(parent)
    @pixelSize = 12
end

Instance Attribute Details

#pixelSizeObject

Returns the value of attribute pixelSize.



30
31
32
# File 'ext/ruby/qtruby/examples/itemviews/pixelator/pixeldelegate.rb', line 30

def pixelSize
  @pixelSize
end

Instance Method Details

#paint(painter, option, index) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'ext/ruby/qtruby/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) ⇒ Object



64
65
66
# File 'ext/ruby/qtruby/examples/itemviews/pixelator/pixeldelegate.rb', line 64

def sizeHint(option, index)
    return Qt::Size.new(@pixelSize, @pixelSize)
end