The VGT I am working on is GPL and Open Source. While making the switch I have been able to rewrite portions of the old and dusty code so that portions of it could be lent to other softwares. Here is a link so you can download the full source: http://my.pogoplug.com/share/RPBBQftK2AaDIG99LwumcA/
This is what I am doing. First .. I have ripped apart the UI and the calculations so the code you are going to see is just a widget that will be docked into the UI. Also, the code is in PyQt, but with some translation you should be able to see how it could fit in pure Qt.
# Maintainer (Traipse): Tyler Starke
# Version: Traipse 'Pious-Paladin'
# $Id: main.py,v Traipse 'Pious-Paladin' prof.ebral Exp $
#
# Description: Base Map Gear
"""
Planned Implementation:
The map will change first and foremost by creating a new layer called the Table Layer. This layer will be just that, a table.
The Background layer will be a bit different
"""
from PyQt4 import QtGui, QtCore
from tool_gears.path_gear import path
from map_engine.scroll_gear import ScrollGear
from map_engine.mini_gear import MiniGear
def __init__(self):
super(MapDocket, self).__init__()
self.createDocket()
self.createMap()
self.setScene(self.mapView)
self.centerOn(0,0)
self.show()
def createDocket(self):
self.
setBackgroundBrush(QtGui.
QBrush(QtGui.
QPixmap(path
['textures']+'versa_anigre.jpg'))) self.
setViewportUpdateMode(QtGui.
QGraphicsView.
BoundingRectViewportUpdate)
def createMap(self):
#self.dropEvent = self.sceneDropEvent
self.mapView.setSceneRect(0, 0, 1000, 1000)
item = MiniGear(path['textures']+'grass-natural.jpg')
self.mapView.addItem(item)
item = MiniGear(path['textures']+'water20.jpg')
self.mapView.addItem(item)
def dropEvent(self, evt):
print 'Dropped'
def wheelEvent(self, evt):
scale = evt.delta()
if scale < 0: x = .9; y = .9
if scale > 0: x = 1.1; y = 1.1
self.scale(x, y)
# Maintainer (Traipse): Tyler Starke
# Version: Traipse 'Pious-Paladin'
# $Id: main.py,v Traipse 'Pious-Paladin' prof.ebral Exp $
#
# Description: Base Map Gear
"""
Planned Implementation:
The map will change first and foremost by creating a new layer called the Table Layer. This layer will be just that, a table.
The Background layer will be a bit different
"""
from PyQt4 import QtGui, QtCore
from tool_gears.path_gear import path
from map_engine.scroll_gear import ScrollGear
from map_engine.mini_gear import MiniGear
class MapDocket(QtGui.QGraphicsView):
def __init__(self):
super(MapDocket, self).__init__()
self.createDocket()
self.createMap()
self.setScene(self.mapView)
self.centerOn(0,0)
self.show()
def createDocket(self):
self.setBackgroundBrush(QtGui.QBrush(QtGui.QPixmap(path['textures']+'versa_anigre.jpg')))
self.setCacheMode(QtGui.QGraphicsView.CacheBackground)
self.setViewportUpdateMode(QtGui.QGraphicsView.BoundingRectViewportUpdate)
self.setDragMode(QtGui.QGraphicsView.ScrollHandDrag)
def createMap(self):
self.mapView = QtGui.QGraphicsScene()
#self.dropEvent = self.sceneDropEvent
self.mapView.setSceneRect(0, 0, 1000, 1000)
self.mapView.setItemIndexMethod(QtGui.QGraphicsScene.NoIndex)
item = MiniGear(path['textures']+'grass-natural.jpg')
self.mapView.addItem(item)
item = MiniGear(path['textures']+'water20.jpg')
self.mapView.addItem(item)
def dropEvent(self, evt):
print 'Dropped'
def wheelEvent(self, evt):
scale = evt.delta()
if scale < 0: x = .9; y = .9
if scale > 0: x = 1.1; y = 1.1
self.scale(x, y)
To copy to clipboard, switch view to plain text mode
What I do is class a GraphicsView and then I create the scene in side and set the scene to the view. Then I can add items to the seen. See how I am adding items? Here is the class in its current state:
# Version: Traipse 'Pious-Paladin'
# $Id: main.py,v Traipse 'Pious-Paladin' prof.ebral Exp $
#
# Description: Base Map Gear
from PyQt4 import QtGui
from tool_gears.path_gear import path
def __init__(self, pixmap):
super(MiniGear, self).__init__()
self.
setPixmap(QtGui.
QPixmap(pixmap
)) self.setAcceptDrops(True)
self.setAcceptHoverEvents(True)
def dropEvent(self, evt):
print 'Dropped'
def dragMoveEvent(self, evt):
print 'Move'
# Version: Traipse 'Pious-Paladin'
# $Id: main.py,v Traipse 'Pious-Paladin' prof.ebral Exp $
#
# Description: Base Map Gear
from PyQt4 import QtGui
from tool_gears.path_gear import path
class MiniGear(QtGui.QGraphicsPixmapItem):
def __init__(self, pixmap):
super(MiniGear, self).__init__()
self.setPixmap(QtGui.QPixmap(pixmap))
self.setAcceptDrops(True)
self.setAcceptHoverEvents(True)
self.setFlags(QtGui.QGraphicsItem.ItemIsMovable)
def dropEvent(self, evt):
print 'Dropped'
def dragMoveEvent(self, evt):
print 'Move'
To copy to clipboard, switch view to plain text mode
I am creating items this way because it will give me a lot more options to manipulate the item later. If I create a dictionary of Map Minis, and I will, I can pull a stunt like this.
image = MiniGear(path['textures']+'grass-natural.jpg')
self.mapMinis[self.minis] = image
self.minis += 1
image = MiniGear(path['textures']+'grass-natural.jpg')
self.mapMinis[self.minis] = image
self.minis += 1
To copy to clipboard, switch view to plain text mode
This puts that image into the dictionary, but the image will also have callable functions, practically inside itself. So later I will be able to do something like
self.mapMinis[0].addEffect( Effect )
self.mapMinis[0].addEffect( Effect )
To copy to clipboard, switch view to plain text mode
And that item will have an effect added to it.
Bookmarks