22 #include <QGraphicsSceneMouseEvent>
28 if (line.length() != 0) {
31 const int prolongation = 20.0;
32 return QLineF(p1.x() - prolongation, p1.y(), p2.x() + prolongation, p2.y());
45 setFlag(QGraphicsItem::ItemIsMovable,
true);
46 setFlag(QGraphicsItem::ItemIsSelectable,
true);
47 setFlag(QGraphicsItem::ItemSendsGeometryChanges);
95 QString material =
"";
100 material = mp.
text();
116 QString infoToDisplay = material;
124 if (change == ItemPositionChange && scene()) {
127 if (multilayerCandidate) {
132 return QGraphicsItem::itemChange(change, value);
137 if (event->button() == Qt::LeftButton) {
140 QGraphicsItem::mousePressEvent(event);
152 QGraphicsItem::mouseReleaseEvent(event);
158 int requested_row = candidate.
row;
161 if (!requested_parent && !parentItem()) {
162 QGraphicsItem::mouseReleaseEvent(event);
168 if (requested_parent && requested_row == -1) {
170 QGraphicsItem::mouseReleaseEvent(event);
177 if (requested_parent == parentItem()
178 && requested_row ==
getItem()->parent()->getItems().indexOf(
getItem())) {
180 QGraphicsItem::mouseReleaseEvent(event);
186 if (parentItem() && !requested_parent) {
187 QPointF newPos = mapToScene(event->pos()) -
event->pos();
192 QGraphicsItem::mouseReleaseEvent(event);
198 if (requested_parent) {
200 QGraphicsItem::mouseReleaseEvent(event);
224 QVector<MultiLayerCandidate> candidates;
227 for (
auto item : scene()->items()) {
229 MultiLayerView* multilayer = qgraphicsitem_cast<MultiLayerView*>(item);
230 if (multilayer->mapRectToScene(multilayer->
boundingRect()).intersects(layerRect)) {
234 int row = multilayer->
getDropArea(multilayer->mapFromScene(layerRect.center()));
237 std::abs(
static_cast<int>(droparea.center().y() - layerRect.center().y()));
242 candidates.push_back(candidate);
247 if (!candidates.empty()) {
248 std::sort(candidates.begin(), candidates.end());
249 return candidates.back();
#define ASSERT(condition)
Defines class DesignerHelper.
Defines class DesignerScene.
Defines class ExternalProperty.
Defines class GUIHelpers functions.
Defines class MultiLayerView.
Defines class SampleModel.
view of ISampleNode's with rectangular shape and node functionality
QList< NodeEditorPort * > getInputPorts()
virtual QRectF boundingRect() const
virtual void update_appearance()
updates visual appearance of the item (color, icons, size etc)
virtual void setColor(const QColor &color)
virtual void setPortCoordinates()
static int nanometerToScreen(double nanometer)
non-linear conversion of layer's thickness in nanometers to screen size to have reasonable graphics r...
Main class which represents SessionModel on graphics scene.
void setLayerInterfaceLine(const QLineF &line={})
SampleModel * getSampleModel()
The ExternalProperty class defines custom QVariant property to carry the text, color and an identifie...
QVariant itemChange(GraphicsItemChange change, const QVariant &value)
Detects movement of the ILayerView and sends possible drop areas to GraphicsScene for visualization.
ILayerView(QGraphicsItem *parent=0)
QPointF m_drag_start_position
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
Detects possible MultiLayerView's to drop given ILayerView and propagate request to SessionModel.
MultiLayerCandidate getMultiLayerCandidate()
Finds candidate (another MultiLayer) into which we will move our ILayerView.
void update_appearance()
updates visual appearance of the item (color, icons, size etc)
void onPropertyChange(const QString &propertyName)
Propagates change of 'Thickness' dynamic property to screen thickness of ILayerView.
void mousePressEvent(QGraphicsSceneMouseEvent *event)
virtual SessionItem * getItem()
virtual void onPropertyChange(const QString &propertyName)
static const QString P_MATERIAL
static const QString P_THICKNESS
Class to hold MultiLayer candidate for dropping LayerView.
bool operator<(const MultiLayerCandidate &cmp) const
QLineF getInterfaceToScene()
returns line representing interface of multilayer in scene coordinates
int row
requested row number to drop in
MultiLayerView * multilayer
pointer to the candidate
int distance
distance from given ILayerView and drop area
Class representing view of MultiLayer.
int getDropArea(QPointF pos)
Returns index of drop area for given coordinate.
QRectF boundingRect() const override
QRectF getDropAreaRectangle(int row)
Returns drop area rectangle corresponding to given row.
QLineF getInterfaceLine(int row)
Returns line representing interface.
void setLabel(QString name)
Main model to hold sample items.
static const QString P_XPOS
static const QString P_YPOS
bool isTag(const QString &name) const
Returns true if tag is available.
QVariant getItemValue(const QString &tag) const
Directly access value of item under given tag.
void setItemValue(const QString &tag, const QVariant &variant)
Directly set value of item under given tag.
SessionItem * moveItem(SessionItem *item, SessionItem *new_parent=0, int row=-1, const QString &tag="")
Move given parameterized item to the new_parent at given row.