10#include <QGraphicsRectItem>
11#include <QGraphicsScene>
28 createWidgets (scene);
39void NonPdfCropping::createWidgets(QGraphicsScene &scene)
41 const double MARGIN_PERCENT = 5.0;
42 const int ZERO_WIDTH_IS_ALWAYS_VISIBLE = 0;
44 int marginHor = qFloor (scene.width() * MARGIN_PERCENT / 100.0);
45 int marginVer = qFloor (scene.height() * MARGIN_PERCENT / 100.0);
47 QRect box (qFloor (scene.sceneRect().left() + marginHor),
48 qFloor (scene.sceneRect().top() + marginVer),
49 qFloor (scene.sceneRect().width() - 2 * marginHor),
50 qFloor (scene.sceneRect().height() - 2 * marginVer));
57 m_box =
new QGraphicsRectItem;
58 m_box->setZValue (
Z_BOX);
59 m_box->setPen (QPen (QBrush (Qt::gray), ZERO_WIDTH_IS_ALWAYS_VISIBLE));
60 scene.addItem (m_box);
65void NonPdfCropping::disableEventsWhileMovingAutomatically ()
67 m_handleTL->setDisableEventsWhileMovingAutomatically (
true);
68 m_handleTR->setDisableEventsWhileMovingAutomatically (
true);
69 m_handleBR->setDisableEventsWhileMovingAutomatically (
true);
70 m_handleBL->setDisableEventsWhileMovingAutomatically (
true);
73void NonPdfCropping::enableEventsWhileMovingAutomatically ()
75 m_handleTL->setDisableEventsWhileMovingAutomatically (
false);
76 m_handleTR->setDisableEventsWhileMovingAutomatically (
false);
77 m_handleBR->setDisableEventsWhileMovingAutomatically (
false);
78 m_handleBL->setDisableEventsWhileMovingAutomatically (
false);
87 QRectF rectTL = m_handleTL->mapRectToScene (m_handleTL->boundingRect());
88 QRectF rectBR = m_handleBR->mapRectToScene (m_handleBR->boundingRect());
90 QRectF rectUnited = rectTL.united (rectBR);
96 const QPointF &oldPos)
98 disableEventsWhileMovingAutomatically();
100 double deltaX = newPos.x() - oldPos.x();
101 double deltaY = newPos.y() - oldPos.y();
103 m_handleTL->moveBy (deltaX,
105 m_handleBR->moveBy (0,
108 enableEventsWhileMovingAutomatically();
114 const QPointF &oldPos)
116 disableEventsWhileMovingAutomatically();
118 double deltaX = newPos.x() - oldPos.x();
119 double deltaY = newPos.y() - oldPos.y();
121 m_handleBL->moveBy (0,
123 m_handleTR->moveBy (deltaX,
126 enableEventsWhileMovingAutomatically();
132 const QPointF &oldPos)
134 disableEventsWhileMovingAutomatically();
136 double deltaX = newPos.x() - oldPos.x();
137 double deltaY = newPos.y() - oldPos.y();
139 m_handleBL->moveBy (deltaX,
141 m_handleTR->moveBy (0,
144 enableEventsWhileMovingAutomatically();
150 const QPointF &oldPos)
152 disableEventsWhileMovingAutomatically();
154 double deltaX = newPos.x() - oldPos.x();
155 double deltaY = newPos.y() - oldPos.y();
157 m_handleTL->moveBy (0,
159 m_handleBR->moveBy (deltaX,
162 enableEventsWhileMovingAutomatically();
167void NonPdfCropping::updateBox ()
172 rectUnited.setWidth (rectUnited.width () - 1);
173 rectUnited.setHeight (rectUnited.height () - 1);
175 m_box->setRect (rectUnited);
180 return QSize (qFloor (m_view.scene()->width()),
181 qFloor (m_view.scene()->height()));
void moveBL(const QPointF &newPos, const QPointF &oldPos)
Bottom left corner handle was moved.
static const int NON_PDF_CROPPING_BOTTOM
Bit flag when handle is aligned with bottom edge at reference point.
void moveBR(const QPointF &newPos, const QPointF &oldPos)
Bottom right corner handle was moved.
QSize windowSize() const
Size of window in scene coordinates.
static const int NON_PDF_CROPPING_RIGHT
Bit flag when handle is aligned with right edge at reference point.
QRectF frameRect() const
Frame rectangle selected by user.
void moveTR(const QPointF &newPos, const QPointF &oldPos)
Top right corner handle was moved.
static const int NON_PDF_CROPPING_LEFT
Bit flag when handle is aligned with left edge at reference point.
void moveTL(const QPointF &newPos, const QPointF &oldPos)
Top left corner handle was moved.
NonPdfCropping(QGraphicsScene &scene, ViewPreview &view)
Single constructor.
static const int NON_PDF_CROPPING_TOP
Bit flag when handle is aligned with top edge at reference point.
This class acts as a single handle for the NonPdfCropping class.
Class that modifies QGraphicsView to automatically expand/shrink the view to fit the window,...