29 #include <QGraphicsView>
30 #include <QGraphicsScene>
43 struct SelectionItem::Private
69 d->penDark.setColor(Qt::black);
70 d->penDark.setStyle(Qt::SolidLine);
71 d->penLight.setColor(Qt::white);
72 d->penLight.setStyle(Qt::DashLine);
75 d->penAddRemFg.setColor(Qt::darkGreen);
76 d->penAddRemFg.setStyle(Qt::SolidLine);
77 d->penAddRemFg.setWidth(3);
80 d->showAddRem =
false;
84 d->addRemRect = QRectF(0,0,0,0);
94 if (zoom < 0.00001) zoom = 0.00001;
101 d->addRemRect = QRectF(d->rect.center()-pMargin, QSizeF(margin*2.0, margin*2.0));
102 d->penAddRemFg.setWidthF(3.0 * d->invZoom);
108 d->penDark.setColor(Qt::darkBlue);
109 d->penLight.setColor(Qt::red);
110 d->penAddRemFg.setColor(Qt::darkRed);
114 d->penDark.setColor(Qt::black);
115 d->penLight.setColor(Qt::white);
116 d->penAddRemFg.setColor(Qt::darkGreen);
125 if (d->hasMaxY) d->hasMax =
true;
132 if (d->hasMaxX) d->hasMax =
true;
137 bool oldState = d->showAddRem;
138 d->showAddRem =
false;
140 if ((point.x() < (d->rect.left()-d->selMargin)) ||
141 (point.x() > (d->rect.right()+d->selMargin)) ||
142 (point.y() < (d->rect.top()-d->selMargin)) ||
143 (point.y() > (d->rect.bottom()+d->selMargin)))
145 if (oldState != d->showAddRem) update();
149 if (point.x() < (d->rect.left()+d->selMargin)) {
150 if (oldState != d->showAddRem) update();
151 if (point.y() < (d->rect.top()+d->selMargin))
return TopLeft;
152 if (point.y() > (d->rect.bottom()-d->selMargin))
return BottomLeft;
156 if (point.x() > (d->rect.right()-d->selMargin)) {
157 if (oldState != d->showAddRem) update();
158 if (point.y() < (d->rect.top()+d->selMargin))
return TopRight;
159 if (point.y() > (d->rect.bottom()-d->selMargin))
return BottomRight;
163 if (point.y() < (d->rect.top()+d->selMargin)) {
164 if (oldState != d->showAddRem) update();
167 if (point.y() > (d->rect.bottom()-d->selMargin)) {
168 if (oldState != d->showAddRem) update();
172 d->showAddRem =
true;
173 if (oldState != d->showAddRem) update();
175 if ((point.x() > d->addRemRect.left()) &&
176 (point.x() < d->addRemRect.right()) &&
177 (point.y() > d->addRemRect.top()) &&
178 (point.y() < d->addRemRect.bottom()))
187 prepareGeometryChange();
189 d->rect = d->rect.normalized();
191 if (d->rect.top() < 0) d->rect.setTop(0);
192 if (d->rect.left() < 0) d->rect.setLeft(0);
193 if (d->rect.right() > d->maxX) d->rect.setRight(d->maxX);
194 if (d->rect.bottom() > d->maxY) d->rect.setBottom(d->maxY);
200 d->addRemRect = QRectF(d->rect.center()-pMargin, QSizeF(margin*2, margin*2));
205 if ((d->rect.left() + dp.x()) < 0) dp.setX(-d->rect.left());
206 if ((d->rect.top() + dp.y()) < 0) dp.setY(-d->rect.top());
207 if ((d->rect.right() + dp.x()) > d->maxX) dp.setX(d->maxX - d->rect.right());
208 if ((d->rect.bottom() + dp.y()) > d->maxY) dp.setY(d->maxY - d->rect.bottom());
220 if (tmp.top() > d->addRemRect.top()) {
221 tmp.setTop(d->addRemRect.top());
223 if (tmp.left() > d->addRemRect.left()) {
224 tmp.setLeft(d->addRemRect.left());
227 if (tmp.bottom() < d->addRemRect.bottom()) {
228 tmp.setBottom(d->addRemRect.bottom());
231 if (tmp.right() < d->addRemRect.right()) {
232 tmp.setRight(d->addRemRect.right());
240 painter->setPen(d->penDark);
241 painter->drawRect(d->rect);
243 painter->setPen(d->penLight);
244 painter->drawRect(d->rect);
247 painter->fillRect(d->addRemRect, QBrush(Qt::white));
248 QLineF minus(d->addRemRect.left()+3*d->invZoom, d->rect.center().y(),
249 d->addRemRect.right()-3*d->invZoom, d->rect.center().y());
250 painter->setPen(d->penAddRemFg);
252 painter->drawLine(minus);
255 QLineF plus(d->rect.center().x(), d->addRemRect.top()+3*d->invZoom,
256 d->rect.center().x(), d->addRemRect.bottom()-3*d->invZoom);
257 painter->drawLine(plus);
static const QPointF addRemMarginPoint(addRemMargin, addRemMargin)
void saveZoom(qreal zoom)
static const qreal addRemMargin
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
SelectionItem(QRectF rect)
void setMaxBottom(qreal maxBottom)
static const qreal selMargin
Intersects intersects(QPointF point)
void setSaved(bool isSaved)
void setMaxRight(qreal maxRight)
static const QPointF boundMargin(selMargin, selMargin)
QRectF boundingRect() const
void setRect(QRectF rect)
QPointF fixTranslation(QPointF dp)