/* * Moonlight|3D * Copyright (C) 2008 The Moonlight|3D team * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * Created on Jul 18, 2008 */ package eu.moonlight3d.graph; import com.trolltech.qt.gui.QBrush; import com.trolltech.qt.gui.QColor; import com.trolltech.qt.gui.QGraphicsItem; import com.trolltech.qt.gui.QGraphicsItemInterface; import com.trolltech.qt.gui.QGraphicsRectItem; class NodeItem extends QGraphicsRectItem implements QGraphicsItemInterface { private QColor normalColor=QColor.darkBlue; private QColor selectedColor=QColor.darkCyan; private Node node; NodeItem(double x1, double y1, double x2, double y2, Node node) { super(x1,y1,x2,y2); this.node=node; setFlag(QGraphicsItem.GraphicsItemFlag.ItemIsMovable, true); setFlag(QGraphicsItem.GraphicsItemFlag.ItemIsSelectable,true); setBrush(new QBrush(normalColor)); } @Override public Object itemChange(QGraphicsItem.GraphicsItemChange change, Object value) { if(change==QGraphicsItem.GraphicsItemChange.ItemPositionHasChanged) { for(Slot slot : node.getSlots()) { // update links slot.updateLinkEndpoint(); } } else if(change==QGraphicsItem.GraphicsItemChange.ItemSelectedChange) { Integer selected=(Integer) value; GraphModel graphModel=(GraphModel) scene(); if(selected==1) { // call graph model listeners graphModel.handleSelection(node,true); setBrush(new QBrush(selectedColor)); } else { // call graph model listeners graphModel.handleSelection(node,false); setBrush(new QBrush(normalColor)); } } return super.itemChange(change,value); } void setNormalColor(QColor normalColor) { if(normalColor==null) { this.normalColor=QColor.darkBlue; } else { this.normalColor=normalColor; } if(!isSelected()) { setBrush(new QBrush(this.normalColor)); } } void setSelectedColor(QColor selectedColor) { if(selectedColor==null) { this.selectedColor=QColor.darkCyan; } else { this.selectedColor=selectedColor; } if(isSelected()) { setBrush(new QBrush(this.selectedColor)); } } }