usr bin env ruby KCODE UTF-8 require Qt4 require mainwindow rb class N

  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
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 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
#!/usr/bin/env ruby
$KCODE = 'UTF-8'
require 'Qt4'
require 'mainwindow.rb'
class Node < Qt::GraphicsItem
def initialize
super
self.setFlags(Qt::GraphicsItem::ItemIsMovable);
#setCursor(Qt::OpenHandCursor);
end
def set(xpos, ypos, title, color)
@xpos, @ypos, @title, @color = xpos, ypos, title, color
end
def paint(painter, option, widget)
painter.setBrush(@color)
painter.drawEllipse(-5+@xpos, -5+@ypos, 10, 10)
painter.drawText(@xpos+5,@ypos-5,@title)
painter.setBrush(Qt::blue)
painter.setPen(Qt::blue)
painter.drawText(@xpos-5,@ypos-5,@mark)
end
def boundingRect
return Qt::RectF.new(@xpos-5-0.5,@ypos-15-0.5,17,25)
end
def getxpos
return @xpos
end
def getypos
return @ypos
end
end
class Edge < Qt::GraphicsItem
def initialize# parent = Qt::GraphicsItem#(xpos, ypos)#, title, color)
super
#self.setFlags(Qt::GraphicsItem::ItemIsMovable);
#@xpos, @ypos, @title, @color = 0,0,"A",Qt::black#xpos, ypos, "A", Qt::black#title, color
end
def connect(node1, node2)
@node1=node1
@node2=node2
@onexpos = node1.getxpos
@oneypos = node1.getypos
@twoxpos = node2.getxpos
@twoypos = node2.getypos
end
def paint(painter, option, widget)
painter.setBrush(Qt::black)
painter.setPen(Qt::black)
x1 = @node1.scenePos().x()+@onexpos #//one->xpos;// one10;
y1 = @node1.scenePos().y()+@oneypos #//one->ypos;//10;
x2 = @node2.scenePos().x()+@twoxpos #//two->xpos;//100;
y2 = @node2.scenePos().y()+@twoypos #//two->ypos;//+100;
painter.drawLine(x1,y1,x2,y2)#//one->xpos,one->ypos,two->xpos,two->ypos);
update()
end
def boundingRect
return Qt::RectF.new(0,0,0,0)#@xpos-5-0.5,@ypos-15-0.5,17,25)
end
end
class Main_Window < Qt::MainWindow
def initialize# parent = nil
super
@ui = Ui_MainWindowClass.new
@ui.setupUi(self)
#@ui.
@ui.graphicsView.setRenderHints( Qt::Painter::Antialiasing)
end
def draw_graph
graph = Qt::GraphicsScene.new(@ui.graphicsView)
nodes = []
nd1 = Node.new
nd1 = Node.new
nd1.set(10, 10, "A", Qt::black)
nd2 = Node.new
nd2 = Node.new
nd2.set(20, 20, "B", Qt::black)
ed = Edge.new
ed.connect(nd1, nd2)
@ui.graphicsView.setScene(graph)
graph.addItem(nd1)
graph.addItem(nd2)
graph.addItem(ed)
#graph.addLine(10,10,20,20)
#graph.addItem(node)
#grap#
#puts self.graphicsView.methods
#puts graphicsView.methods#.setScene(@graph)
end
end
def main
app = Qt::Application.new(ARGV)
ui = Main_Window.new
#window = Qt::MainWindow.new
window = Main_Window.new
window.draw_graph
#ui.setupUi(window)
window.show
app.exec()
end
main