summaryrefslogtreecommitdiffstats
path: root/qtruby/rubylib/examples/qt-examples/chart/canvasview.rb
blob: 296d69139bee22334ded5d27e0834d021c67d477 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
class CanvasView < TQt::CanvasView

    def initialize(canvas, elements, parent = nil, name = "canvas view", f = 0)
        super(canvas, parent, name, f)
        @elements = elements
        @movingItem = nil
    end
    
    def contentsContextMenuEvent( e )
        parent().optionsMenu.exec( TQt::Cursor.pos() )
    end
    
    
    def viewportResizeEvent( e )
        canvas().resize( e.size().width(), e.size().height() )
        parent().drawElements()
    end
    
    
    def contentsMousePressEvent( e )
        list = canvas().collisions( e.pos() )
        list.each do |it|
            if  it.rtti() == CanvasText::CANVAS_TEXT 
                @movingItem = it
                @pos = e.pos()
                return
            end
        end
        @movingItem = nil
    end
    
    
    def contentsMouseMoveEvent( e )
        if @movingItem 
            offset = e.pos() - @pos
            @movingItem.moveBy( offset.x(), offset.y() )
            @pos = e.pos()
            form = parent()
            form.changed = true
            chartType = form.chartType()
            item = @movingItem
            i = item.index()
    
            @elements[i].setProX( chartType, item.x() / canvas().width() )
            @elements[i].setProY( chartType, item.y() / canvas().height() )
    
            canvas().update()
        end
    end

end