Changeset 8402:b3c7185610d1 in orange
 Timestamp:
 07/20/11 18:51:07 (3 years ago)
 Branch:
 default
 Convert:
 46992b64809debd0d9de4b2fe889812e5b7c6213
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

orange/OrangeWidgets/owplot3d.py
r8401 r8402 223 223 item_pos_y += self.metrics.height() 224 224 225 def point_inside(self, x, y):225 def contains(self, x, y): 226 226 return self.position[0] <= x <= self.position[0]+self.size[0] and\ 227 227 self.position[1] <= y <= self.position[1]+self.size[1] … … 236 236 self.current_vertex = first_vertex 237 237 238 def point_inside(self, x, y):238 def contains(self, x, y): 239 239 x1, x2 = sorted([self.first_vertex[0], self.current_vertex[0]]) 240 240 y1, y2 = sorted([self.first_vertex[1], self.current_vertex[1]]) … … 243 243 return True 244 244 return False 245 246 def move(self, dx, dy): 247 self.first_vertex[0] += dx 248 self.first_vertex[1] += dy 249 self.current_vertex[0] += dx 250 self.current_vertex[1] += dy 245 251 246 252 def draw(self): … … 255 261 def valid(self): 256 262 return self.first_vertex != self.current_vertex 257 # TODO 263 # TODO: drop if too small 258 264 259 265 class PolygonSelection(object): … … 262 268 self.current_vertex = first_vertex 263 269 self.first_vertex = first_vertex 270 self.polygon = None 264 271 265 272 def add_current_vertex(self): … … 268 275 if distance < 10**2: 269 276 self.vertices.append(self.first_vertex) 277 self.polygon = QPolygon([QPoint(x, y) for (x, y) in self.vertices]) 270 278 return True 271 279 else: … … 273 281 return False 274 282 275 def point_inside(self, x, y): 276 return False # TODO 283 def contains(self, x, y): 284 if self.polygon == None: 285 return False 286 return self.polygon.containsPoint(QPoint(x, y), Qt.OddEvenFill) 287 288 def move(self, dx, dy): 289 self.vertices = [[x+dx, y+dy] for x,y in self.vertices] 290 self.current_vertex[0] += dx 291 self.current_vertex[1] += dy 292 self.polygon = QPolygon([QPoint(x, y) for (x, y) in self.vertices]) 277 293 278 294 def draw(self): … … 960 976 x_win, y_win = project(x, y, z) 961 977 for selection in self.selections: 962 if selection. point_inside(x_win, y_win):978 if selection.contains(x_win, y_win): 963 979 indices.append(i) 964 980 break … … 975 991 976 992 if buttons & Qt.LeftButton: 977 if self.legend. point_inside(pos.x(), pos.y()):993 if self.legend.contains(pos.x(), pos.y()): 978 994 self.state = PlotState.DRAGGING_LEGEND 979 995 self.new_selection = None 980 996 else: 997 if self.state == PlotState.SELECTING: 998 return 999 for selection in self.selections: 1000 if selection.contains(pos.x(), pos.y()): 1001 self.state = PlotState.PANNING 1002 self.dragged_selection = selection 1003 return 981 1004 self.state = PlotState.SELECTING 982 1005 if self.selection_type == SelectionType.RECTANGLE or\ … … 1000 1023 if self.state == PlotState.IDLE: 1001 1024 for selection in self.selections: 1002 if selection. point_inside(pos.x(), pos.y()):1025 if selection.contains(pos.x(), pos.y()): 1003 1026 self.setCursor(Qt.OpenHandCursor) 1004 1027 break … … 1011 1034 dy = pos.y()  self.mouse_pos.y() 1012 1035 1013 if self.state == PlotState.SELECTING :1036 if self.state == PlotState.SELECTING and self.new_selection != None: 1014 1037 self.new_selection.current_vertex = [pos.x(), pos.y()] 1015 1038 elif self.state == PlotState.DRAGGING_LEGEND: … … 1034 1057 self.additional_scale = [dx / self.scale_factor, dy / self.scale_factor, 0]\ 1035 1058 if self.scale_x_axis else [0, dy / self.scale_factor, dx / self.scale_factor] 1059 elif self.state == PlotState.PANNING: 1060 self.dragged_selection.move(dx, dy) 1036 1061 1037 1062 self.mouse_pos = pos … … 1061 1086 elif self.state == PlotState.ROTATING: 1062 1087 self.state = PlotState.IDLE 1088 elif self.state == PlotState.PANNING: 1089 self.selection_change_callback() if self.selection_change_callback else None 1063 1090 1064 1091 if not (self.state == PlotState.SELECTING and self.selection_type == SelectionType.POLYGON):
Note: See TracChangeset
for help on using the changeset viewer.