7 #include "PdfCropping.h" 8 #include "PdfFrameHandle.h" 10 #include <QGraphicsScene> 11 #include <QGraphicsView> 12 #include <QStyleOptionGraphicsItem> 14 const double HANDLE_SIZE_AS_FRACTION_OF_WINDOW_SIZE = 30;
18 const QPointF &pointReference,
22 m_pdfCropping (pdfCropping),
23 m_orientationFlags (orientationFlags),
24 m_disableEventsWhileMovingAutomatically (false),
28 const double SUBTLE_OPACITY = 0.2;
42 setFlags (QGraphicsItem::ItemIsMovable |
43 QGraphicsItem::ItemIsSelectable |
44 QGraphicsItem::ItemSendsScenePositionChanges);
47 setBrush (QBrush (Qt::blue));
50 setOpacity (SUBTLE_OPACITY);
51 setPos (pointReference);
56 QSize handleSize = m_pdfCropping.
windowSize() / HANDLE_SIZE_AS_FRACTION_OF_WINDOW_SIZE;
59 QPointF pointPos = pointReference;
61 pointPos.setX (pointPos.x() - handleSize.width() / 2.0);
63 pointPos.setX (pointPos.x() + handleSize.width() / 2.0);
66 pointPos.setY (pointPos.y() - handleSize.height() / 2.0);
68 pointPos.setY (pointPos.y() + handleSize.height() / 2.0);
73 QPointF topLeftLocal = mapFromScene (pointPos);
75 setRect (QRectF (topLeftLocal,
80 const QVariant &value)
82 QVariant valueFiltered = value;
84 if (change == ItemPositionChange && scene()) {
86 QPointF sizeAsPointF (boundingRect().size().width(),
87 boundingRect().size().height());
90 QPointF newPos = valueFiltered.toPointF();
91 QPointF oldPos = pos ();
94 QRectF newRectItem (newPos,
95 QSize (boundingRect().size().width(),
96 boundingRect().size().height()));
97 QPolygonF newRectScene = mapToScene (newRectItem);
98 QPolygon newRectView = m_view.mapFromScene (newRectScene.boundingRect());
101 QRectF rectWindow = m_scene.sceneRect();
102 if (!rectWindow.contains (newRectView.boundingRect())) {
105 newPos.setX (qMin (rectWindow.right(), qMax (newPos.x(), rectWindow.left())));
106 newPos.setY (qMin (rectWindow.bottom(), qMax (newPos.y(), rectWindow.top())));
108 valueFiltered = (newPos);
114 if (!m_disableEventsWhileMovingAutomatically) {
122 m_pdfCropping.
moveTL (newPos, oldPos);
123 }
else if (right && top) {
124 m_pdfCropping.
moveTR (newPos, oldPos);
125 }
else if (right && bottom) {
126 m_pdfCropping.
moveBR (newPos, oldPos);
127 }
else if (left && bottom) {
128 m_pdfCropping.
moveBL (newPos, oldPos);
133 return QGraphicsItem::itemChange(change, valueFiltered);
139 QStyleOptionGraphicsItem scrubbed (*option);
140 scrubbed.state &= ~QStyle::State_Selected;
141 QGraphicsRectItem::paint (painter, &scrubbed, widget);
146 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...