10 #include <QGraphicsScene> 11 #include <QGraphicsView> 13 #include <QStyleOptionGraphicsItem> 19 const QPointF &pointReference,
23 m_pdfCropping (pdfCropping),
24 m_orientationFlags (orientationFlags),
25 m_disableEventsWhileMovingAutomatically (false),
29 const double SUBTLE_OPACITY = 0.2;
43 setFlags (QGraphicsItem::ItemIsMovable |
44 QGraphicsItem::ItemIsSelectable |
45 QGraphicsItem::ItemSendsScenePositionChanges);
48 setBrush (QBrush (Qt::blue));
51 setOpacity (SUBTLE_OPACITY);
52 setPos (pointReference);
60 QPointF pointPos = pointReference;
62 pointPos.setX (pointPos.x() - handleSize.width() / 2.0);
64 pointPos.setX (pointPos.x() + handleSize.width() / 2.0);
67 pointPos.setY (pointPos.y() - handleSize.height() / 2.0);
69 pointPos.setY (pointPos.y() + handleSize.height() / 2.0);
74 QPointF topLeftLocal = mapFromScene (pointPos);
76 setRect (QRectF (topLeftLocal,
81 const QVariant &value)
83 QVariant valueFiltered = value;
85 if (change == ItemPositionChange && scene()) {
87 QPointF sizeAsPointF (boundingRect().size().width(),
88 boundingRect().size().height());
91 QPointF newPos = valueFiltered.toPointF();
92 QPointF oldPos = pos ();
95 QRectF newRectItem (newPos,
96 QSize (qFloor (boundingRect().size().width()),
97 qFloor (boundingRect().size().height())));
98 QPolygonF newRectScene = mapToScene (newRectItem);
99 QPolygon newRectView = m_view.mapFromScene (newRectScene.boundingRect());
102 QRectF rectWindow = m_scene.sceneRect();
103 if (!rectWindow.contains (newRectView.boundingRect())) {
106 newPos.setX (qMin (rectWindow.right(), qMax (newPos.x(), rectWindow.left())));
107 newPos.setY (qMin (rectWindow.bottom(), qMax (newPos.y(), rectWindow.top())));
109 valueFiltered = (newPos);
115 if (!m_disableEventsWhileMovingAutomatically) {
123 m_pdfCropping.
moveTL (newPos, oldPos);
124 }
else if (right && top) {
125 m_pdfCropping.
moveTR (newPos, oldPos);
126 }
else if (right && bottom) {
127 m_pdfCropping.
moveBR (newPos, oldPos);
128 }
else if (left && bottom) {
129 m_pdfCropping.
moveBL (newPos, oldPos);
134 return QGraphicsItem::itemChange(change, valueFiltered);
140 QStyleOptionGraphicsItem scrubbed (*option);
141 scrubbed.state &= ~QStyle::State_Selected;
142 QGraphicsRectItem::paint (painter, &scrubbed, widget);
147 m_disableEventsWhileMovingAutomatically = disable;
void moveTL(const QPointF &newPos, const QPointF &oldPos)
Top left corner handle was moved.
PdfFrameHandle(QGraphicsScene &scene, QGraphicsView &view, const QPointF &pointReference, int orientationFlags, PdfCropping &pdfCropping, int zValue)
Single constructor.
void moveBR(const QPointF &newPos, const QPointF &oldPos)
Bottom right corner handle was moved.
static const int PDF_CROPPING_RIGHT
Bit flag when handle is aligned with right edge at reference point.
static const int PDF_CROPPING_TOP
Bit flag when handle is aligned with top edge at reference point.
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
Override the paint method so the dashed-border-when-selected can be removed.
This class shows a frame around the selected portion of the pdf import preview window.
static const int PDF_CROPPING_BOTTOM
Bit flag when handle is aligned with bottom edge at reference point.
void moveBL(const QPointF &newPos, const QPointF &oldPos)
Bottom left corner handle was moved.
QSize windowSize() const
Size of window in scene coordinates.
static const int PDF_CROPPING_LEFT
Bit flag when handle is aligned with left edge at reference point.
void moveTR(const QPointF &newPos, const QPointF &oldPos)
Top right corner handle was moved.
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value)
Intercept the drags and process them, which is the whole point of handles.
void setDisableEventsWhileMovingAutomatically(bool disable)
Temporarily disable event handling so code can move this object without triggering a cascade of event...
const double HANDLE_SIZE_AS_FRACTION_OF_WINDOW_SIZE