11 return QRectF(-10 - penWidth / 2, -10 - penWidth / 2,
12 20 + penWidth, 20 + penWidth);
15 void paint(QPainter *painter,
const QStyleOptionGraphicsItem *option,
16 QWidget *widget)
override
18 painter->drawRoundedRect(-10, -10, 20, 20, 5, 5);
28 enum {
Type = UserType + 1 };
41item->setCursor(Qt::IBeamCursor);
46item->setCursor(Qt::IBeamCursor);
54rect.sceneTransform().map(QPointF(0, 0));
57rect.sceneTransform().inverted().map(QPointF(100, 100));
66rect.deviceTransform(view->viewportTransform()).map(QPointF(0, 0));
69rect.deviceTransform(view->viewportTransform()).inverted().map(QPointF(100, 100));
75QRectF CircleItem::boundingRect()
const
78 return QRectF(-radius - penWidth / 2, -radius - penWidth / 2,
79 diameter + penWidth, diameter + penWidth);
85QPainterPath RoundItem::shape()
const
88 path.addEllipse(boundingRect());
95void RoundRectItem::paint(QPainter *painter,
96 const QStyleOptionGraphicsItem *option,
99 painter->drawRoundedRect(-10, -10, 20, 20, 5, 5);
108if (item->data(ObjectName).toString().isEmpty()) {
109 if (qgraphicsitem_cast<ButtonItem *>(item))
110 item->setData(ObjectName,
"Button");
120line->installSceneEventFilter(ellipse);
123ellipse->installSceneEventFilter(line);
129void CustomItem::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
132 QAction *removeAction = menu.addAction(
"Remove");
133 QAction *markAction = menu.addAction(
"Mark");
134 QAction *selectedAction = menu.exec(event->screenPos());
143 setAcceptDrops(
true);
147void CustomItem::dragEnterEvent(QGraphicsSceneDragDropEvent *event)
149 event->setAccepted(event->mimeData()->hasFormat(
"text/plain"));
155QVariant Component::itemChange(GraphicsItemChange change,
const QVariant &value)
157 if (change == ItemPositionChange && scene()) {
159 QPointF newPos = value.toPointF();
160 QRectF rect = scene()->sceneRect();
161 if (!rect.contains(newPos)) {
163 newPos.setX(qMin(rect.right(), qMax(newPos.x(), rect.left())));
164 newPos.setY(qMin(rect.bottom(), qMax(newPos.y(), rect.top())));
168 return QGraphicsItem::itemChange(change, value);
174void CircleItem::setRadius(qreal newRadius)
176 if (radius != newRadius) {
177 prepareGeometryChange();
189scene->destroyItemGroup(group);
206view->viewport()->scroll(dx, dy, deviceRect);
int type() const override
Returns the type of an item as an int.
int type() const override
\reimp
QRectF boundingRect() const override
This pure virtual function defines the outer bounds of the item as a rectangle; all painting must be ...
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override
This function, which is usually called by QGraphicsView, paints the contents of an item in local coor...
QParallelAnimationGroup * group
[0]
QGraphicsEllipseItem * ellipse
static const int ObjectName
[10]