21 #include <QGraphicsSceneMouseEvent>
23 #include <QStyleOptionGraphicsItem>
30 setAcceptHoverEvents(
false);
46 qreal toplayer_height =
m_layers.front()->boundingRect().height();
47 qreal bottomlayer_height =
m_layers.back()->boundingRect().height();
48 result.setTop(-toplayer_height / 2.);
49 result.setHeight(
m_rect.height() + (toplayer_height + bottomlayer_height) / 2.);
59 if (option->state & (QStyle::State_Selected | QStyle::State_HasFocus)) {
60 painter->setPen(Qt::DashLine);
71 if (!childItems().contains(layer)) {
74 int previous_row =
m_layers.indexOf(layer);
75 if (previous_row != row) {
76 #if QT_VERSION >= QT_VERSION_CHECK(5, 13, 0)
77 m_layers.swapItemsAt(previous_row, row);
90 Qt::UniqueConnection);
92 Qt::UniqueConnection);
93 layer->setParentItem(
this);
98 ILayerView* layer = qobject_cast<ILayerView*>(sender());
127 int total_height = 0;
130 layer->setY(total_height);
132 qreal drop_area_height = layer->boundingRect().height();
133 qreal drop_area_ypos = total_height - drop_area_height / 2.;
135 QRectF(0, drop_area_ypos,
boundingRect().width(), drop_area_height));
137 total_height += layer->boundingRect().height();
139 qreal drop_area_height =
m_layers.back()->boundingRect().height();
140 qreal drop_area_ypos = total_height - drop_area_height / 2.;
149 m_rect.setHeight(total_height);
151 emit heightChanged();
159 const double wider_than_children(1.15);
162 if (layer->boundingRect().width() > max_width)
163 max_width = layer->boundingRect().width();
165 max_width *= wider_than_children;
166 if (max_width == 0) {
169 m_rect.setWidth(max_width);
173 int xpos = ((
boundingRect().width() - layer->boundingRect().width())) / 2.;
216 QGraphicsItem::dragMoveEvent(event);
235 const DesignerMimeData* mimeData = qobject_cast<const DesignerMimeData*>(event->mimeData());
241 if (mimeData->hasFormat(
"bornagain/widget")
244 event->setAccepted(
true);
246 event->setAccepted(
false);
253 return QGraphicsItem::itemChange(change, value);
#define ASSERT(condition)
Defines class DesignerHelper.
Defines class DesignerMimeData.
Defines class DesignerScene.
Defines class MultiLayerView.
Defines class SampleModel.
virtual void setColor(const QColor &color)
virtual void setRectangle(QRectF rect)
virtual QRectF getRectangle() const
static QRectF getDefaultBoundingRect(const QString &name)
returns default bounding rectangle for given IvView name
static QGradient getLayerGradient(const QColor &color, const QRectF &rect)
static QRectF getDefaultMultiLayerRect()
Mime data for use with SampleDesigner drag and drop operations.
QString getClassName() const
Main class which represents SessionModel on graphics scene.
SampleModel * getSampleModel()
Base class for LayerView and MultiLayerView Provides functionality for moving view on top of MultiLay...
parent class for graphic representation of all ISampleNode's
virtual SessionItem * getItem()
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override
void onLayerAboutToBeDeleted()
virtual void removeLayer(ILayerView *layer)
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override
void updateGeometry()
Updates geometry of MultiLayerView from current childs geometries.
void addView(IView *childView, int row=0) override
int getDropArea(QPointF pos)
Returns index of drop area for given coordinate.
QRectF boundingRect() const override
const DesignerMimeData * checkDragEvent(QGraphicsSceneDragDropEvent *event)
void dropEvent(QGraphicsSceneDragDropEvent *event) override
void updateWidth()
Updates MultiLayerView width, sets x-positions of children.
QList< QLineF > m_interfaces
void dragMoveEvent(QGraphicsSceneDragDropEvent *event) override
QList< QRectF > m_drop_areas
QList< ILayerView * > m_layers
MultiLayerView(QGraphicsItem *parent=0)
virtual void addNewLayer(ILayerView *layer, int row)
QRectF getDropAreaRectangle(int row)
Returns drop area rectangle corresponding to given row.
QLineF getInterfaceLine(int row)
Returns line representing interface.
void updateHeight()
Updates MultiLayer height, sets y-positions of children, defines new drop areas.
Main model to hold sample items.
SessionItem * insertNewItem(QString model_type, SessionItem *parent_item=nullptr, int row=-1, QString tag="")