10#include <QGraphicsRectItem>
11#include <QGraphicsScene>
24 createWidgets (scene);
27void PdfCropping::createWidgets(QGraphicsScene &scene)
29 const double MARGIN_PERCENT = 5.0;
30 const int ZERO_WIDTH_IS_ALWAYS_VISIBLE = 0;
32 int marginHor = qFloor (scene.width() * MARGIN_PERCENT / 100.0);
33 int marginVer = qFloor (scene.height() * MARGIN_PERCENT / 100.0);
35 QRect box (qFloor (scene.sceneRect().left() + marginHor),
36 qFloor (scene.sceneRect().top() + marginVer),
37 qFloor (scene.sceneRect().width() - 2 * marginHor),
38 qFloor (scene.sceneRect().height() - 2 * marginVer));
45 m_box =
new QGraphicsRectItem;
46 m_box->setZValue (
Z_BOX);
47 m_box->setPen (QPen (QBrush (Qt::gray), ZERO_WIDTH_IS_ALWAYS_VISIBLE));
48 scene.addItem (m_box);
53void PdfCropping::disableEventsWhileMovingAutomatically ()
55 m_handleTL->setDisableEventsWhileMovingAutomatically (
true);
56 m_handleTR->setDisableEventsWhileMovingAutomatically (
true);
57 m_handleBR->setDisableEventsWhileMovingAutomatically (
true);
58 m_handleBL->setDisableEventsWhileMovingAutomatically (
true);
61void PdfCropping::enableEventsWhileMovingAutomatically ()
63 m_handleTL->setDisableEventsWhileMovingAutomatically (
false);
64 m_handleTR->setDisableEventsWhileMovingAutomatically (
false);
65 m_handleBR->setDisableEventsWhileMovingAutomatically (
false);
66 m_handleBL->setDisableEventsWhileMovingAutomatically (
false);
75 QRectF rectTL = m_handleTL->mapRectToScene (m_handleTL->boundingRect());
76 QRectF rectBR = m_handleBR->mapRectToScene (m_handleBR->boundingRect());
78 QRectF rectUnited = rectTL.united (rectBR);
84 const QPointF &oldPos)
86 disableEventsWhileMovingAutomatically();
88 double deltaX = newPos.x() - oldPos.x();
89 double deltaY = newPos.y() - oldPos.y();
91 m_handleTL->moveBy (deltaX,
93 m_handleBR->moveBy (0,
96 enableEventsWhileMovingAutomatically();
102 const QPointF &oldPos)
104 disableEventsWhileMovingAutomatically();
106 double deltaX = newPos.x() - oldPos.x();
107 double deltaY = newPos.y() - oldPos.y();
109 m_handleBL->moveBy (0,
111 m_handleTR->moveBy (deltaX,
114 enableEventsWhileMovingAutomatically();
120 const QPointF &oldPos)
122 disableEventsWhileMovingAutomatically();
124 double deltaX = newPos.x() - oldPos.x();
125 double deltaY = newPos.y() - oldPos.y();
127 m_handleBL->moveBy (deltaX,
129 m_handleTR->moveBy (0,
132 enableEventsWhileMovingAutomatically();
138 const QPointF &oldPos)
140 disableEventsWhileMovingAutomatically();
142 double deltaX = newPos.x() - oldPos.x();
143 double deltaY = newPos.y() - oldPos.y();
145 m_handleTL->moveBy (0,
147 m_handleBR->moveBy (deltaX,
150 enableEventsWhileMovingAutomatically();
155void PdfCropping::updateBox ()
160 rectUnited.setWidth (rectUnited.width () - 1);
161 rectUnited.setHeight (rectUnited.height () - 1);
163 m_box->setRect (rectUnited);
168 return QSize (qFloor (m_view.scene()->width()),
169 qFloor (m_view.scene()->height()));
void moveBL(const QPointF &newPos, const QPointF &oldPos)
Bottom left corner handle was moved.
static const int PDF_CROPPING_LEFT
Bit flag when handle is aligned with left edge at reference point.
PdfCropping(QGraphicsScene &scene, ViewPreview &view)
Single constructor.
static const int PDF_CROPPING_BOTTOM
Bit flag when handle is aligned with bottom edge at reference point.
QSize windowSize() const
Size of window in scene coordinates.
static const int PDF_CROPPING_TOP
Bit flag when handle is aligned with top edge at reference point.
void moveTL(const QPointF &newPos, const QPointF &oldPos)
Top left corner handle was moved.
void moveTR(const QPointF &newPos, const QPointF &oldPos)
Top right corner handle was moved.
void moveBR(const QPointF &newPos, const QPointF &oldPos)
Bottom right corner handle was moved.
QRectF frameRect() const
Frame rectangle selected by user.
static const int PDF_CROPPING_RIGHT
Bit flag when handle is aligned with right edge at reference point.
This class acts as a single handle for the PdfCropping class.
Class that modifies QGraphicsView to automatically expand/shrink the view to fit the window,...