daboide Commit
Revision 413
Date: 2006-01-30 16:31:20 -0800 (Mon, 30 Jan 2006)
Author: paul

Changed:
U   trunk/ReportDesigner.py

Log:
(Re)Added moving and sizing of report objects using the mouse. The flicker
on Windows is probably horrible, but on Gtk it looks good. I need to add
more feedback to the move action, but this is a start.


Diff:
Modified: trunk/ReportDesigner.py
===================================================================
--- trunk/ReportDesigner.py     2006-01-31 00:17:16 UTC (rev 412)
+++ trunk/ReportDesigner.py     2006-01-31 00:31:20 UTC (rev 413)
@@ -840,7 +840,6 @@
                                BackColor=(215,215,215), 
ForeColor=(128,128,128),
                                Height=self._bandLabelHeight)
 
-               self._anchors = {}
                self._anchorThickness = 5
                self._anchor = None
                self._mouseDown = False
@@ -849,9 +848,11 @@
 
                self._dragging = False
                self._dragStart = (0,0)
-               self._dragImage = None
+               self._dragObject = None
 
+               self._captureBitmap = None
 
+
        def copy(self):
                self.Parent.copy()
 
@@ -862,10 +863,6 @@
                self.Parent.paste()
 
 
-       def onMouseLeftDown(self, evt):
-               self.updateSelected(evt)
-               
-
        def onContextMenu(self, evt):
                self.updateSelected()
                self.showContextMenu(rdc.getContextMenu())
@@ -881,6 +878,168 @@
                self._rd.editProperty(propName)
 
 
+       def onMouseMove(self, evt):
+               import wx  ## need to abstract DC and mouse cursors!!
+               if self._mouseDown:
+                       if not self._dragging:
+                               self._dragging = True
+                               self._dragStart = evt.EventData["mousePosition"]
+               else:
+                       self._setMouseMoveMode(evt.EventData["mousePosition"])
+
+               if self._dragging:
+                       dragObj = self._dragObject
+#                      self.SetCursor(wx.StockCursor(wx.CURSOR_SIZENWSE))
+                       pos = evt.EventData["mousePosition"]
+
+                       if self._mouseDragMode == "sizing":
+                               z = self.Parent.ZoomFactor
+                               oldPos = self._mousePosition
+                               curPos = evt.EventData["mousePosition"]
+                               self._mousePosition = curPos
+
+                               offset = {"x": (curPos[0] - oldPos[0]) / z,
+                                               "y": -1*((curPos[1] - 
oldPos[1]) / z)}
+
+                               if offset["x"] != 0 or offset["y"] != 0:
+                                       # dragging the object is resizing it.
+                                       hAnchor = 
dragObj.getProp("hAnchor").lower()
+                                       vAnchor = 
dragObj.getProp("vAnchor").lower()
+                                       w, h = dragObj.getProp("width"), 
dragObj.getProp("height")
+                                       x, y = dragObj.getProp("x"), 
dragObj.getProp("y")
+                                       getPt = self._rw.getPt
+                                       x,y,w,h = getPt(x), getPt(y), getPt(w), 
getPt(h)
+                                       anchor = self._anchor
+
+                                       newWidth = w
+                                       newHeight = h
+                                       newX = x
+                                       newY = y
+                                       
+                                       if anchor[0] == "l":
+                                               newWidth = w-offset["x"]
+               
+                                               if hAnchor == "left":
+                                                       newX = x + offset["x"]
+                                               elif hAnchor == "center":
+                                                       newWidth = w - (2 * 
offset["x"])
+
+                                       if anchor[0] == "r":
+                                               newWidth = w+offset["x"]
+
+                                               if hAnchor == "right":
+                                                       newX = x + offset["x"]
+                                               elif hAnchor == "center":
+                                                       newWidth = w + (2 * 
offset["x"])
+
+                                       if anchor[1] == "b":
+                                               newHeight = h-offset["y"]
+               
+                                               if vAnchor == "bottom":
+                                                       newY = y + offset["y"]
+                                               elif vAnchor == "middle":
+                                                       newHeight = h - (2 * 
offset["y"])
+
+                                       if anchor[1] == "t":
+                                               newHeight = h+offset["y"]
+               
+                                               if vAnchor == "top":
+                                                       newY = y + offset["y"]
+                                               elif vAnchor == "middle":
+                                                       newHeight = h - (2 * 
offset["y"])
+
+                                       dragObj.setProp("x", repr(newX))
+                                       dragObj.setProp("width", repr(newWidth))
+                                       dragObj.setProp("y", repr(newY))
+                                       dragObj.setProp("height", 
repr(newHeight))
+                                               
+                                       self.refresh()
+                               
+
+       def onMouseLeftUp(self, evt):
+               self._mouseDown = False
+               dragging = self._dragging
+               dragObject = self._dragObject
+               self._dragging, self._dragObject = False, None
+
+               if dragging and dragObject and self._mouseDragMode == "moving":
+                       pos = evt.EventData["mousePosition"]
+
+                       offset = {"x": pos[0] - self._dragStart[0],
+                                       "y": -1*(pos[1] - self._dragStart[1])}
+
+                       if offset["x"] != 0 or offset["y"] !=0:
+                               z = self.Parent.ZoomFactor
+                               # dragging the object is moving it to a new 
position.
+                               for propName in ("x", "y"):
+                                       old = dragObject.getProp(propName)
+
+                                       unit = "pt"
+                                       if isinstance(old, basestring) and 
len(old) > 3:
+                                               if old[-4] == "pica":
+                                                       unit = "pica"
+                                               elif old[-2].isalpha():
+                                                       unit = old[-2:]
+                                       old = self._rw.getPt(old)
+
+                                       new = round(old + (offset[propName]/z), 
1)
+                                       if new < 0:
+                                               new = 0
+                                       new = self._rw.ptToUnit(new, unit)
+                                       dragObject.setProp(propName, repr(new))
+                       self.refresh()
+                       dabo.ui.callAfterInterval(rdc.refreshProps, 200)
+
+
+       def onMouseLeftDown(self, evt):
+               self.updateSelected(evt)
+
+               if self.Application.Platform == "Mac":
+                       # Mac needs the following line, or LeftUp will never 
fire. TODO:
+                       # figure out how to abstract this into dPemMixin (if 
possible).
+                       # I posted a message to wxPython-mac regarding this - 
not sure if
+                       # it is a bug or a "by design" platform inconsistency.
+                       evt.stop()
+
+               self._mouseDown = True
+               mouseObj = self.getMouseObject()
+               if not isinstance(mouseObj, Band):
+                       self._dragObject = mouseObj
+               self._mousePosition = evt.EventData["mousePosition"]
+
+
+       def _setMouseMoveMode(self, pos):
+               import wx
+               mouseObj = self.getMouseObject()
+               if mouseObj and not isinstance(mouseObj, Band) \
+                               and mouseObj in rdc.SelectedObjects:
+                       self._anchor = self._mouseOnAnchor(pos) 
+                       if self._anchor is not None:
+                               self._mouseDragMode = "sizing"
+                               self.SetCursor(wx.StockCursor(wx.CURSOR_SIZING))
+                       else:
+                               self._mouseDragMode = "moving"
+                               
self.SetCursor(wx.StockCursor(wx.CURSOR_SIZENWSE))
+               else:
+                       self._anchor = None
+                       self._mouseDragMode = None
+                       self.SetCursor(wx.StockCursor(wx.CURSOR_DEFAULT))
+
+
+       def _mouseOnAnchor(self, pos):
+               """Return the anchor that the mouse is on, or None."""
+               mouseObj = self.getMouseObject()
+               if mouseObj is None or isinstance(mouseObj, Band):
+                       return None
+
+               for k,v in mouseObj._anchors.items():
+                       minx, miny = v[2] - self._anchorThickness, v[3] - 
self._anchorThickness
+                       maxx, maxy = v[2] + self._anchorThickness, v[3] + 
self._anchorThickness
+                       if (minx < pos[0] and maxx > pos[0]) and (miny < pos[1] 
and maxy > pos[1]):
+                               return k
+               return None
+
+
        def getMouseObject(self):
                """Returns the topmost object underneath the mouse."""
                rw = self.Parent._rw
@@ -968,6 +1127,7 @@
                selObjs = []
 
                for obj in self.ReportObject.get("Objects", []):
+                       obj._anchors = {}
                        objType = obj.__class__.__name__
                        size, position = self.getObjSizeAndPosition(obj)
                        rect = [position[0], position[1], size[0], size[1]]
@@ -1183,7 +1343,7 @@
                                        "lm": ["left", "middle", x-1, 
y+(.5*height)-(.5*thickness)],
                                        "rm": ["right", "middle", 
x+width-thickness+1, y+(.5*height)-(.5*thickness)]}
 
-                       self._anchors = anchors
+                       obj._anchors = anchors
 
                        for k,v in anchors.items():
                                dc.SetBrush(wx.Brush((0,0,0), wx.SOLID))
@@ -1423,7 +1583,9 @@
                                        parentBands.append(parentBand)
 
                                if isinstance(val, basestring) and len(val) > 3:
-                                       if val[-2].isalpha():
+                                       if val[-4] == "pica":
+                                               unit = "pica"
+                                       elif val[-2].isalpha():
                                                unit = val[-2:]
 
                                val = self._rw.getPt(val)




_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev

Reply via email to