8 #include "NonPdfCropping.h" 9 #include "NonPdfFrameHandle.h" 10 #include <QGraphicsRectItem> 11 #include <QGraphicsScene> 13 #include "QtToString.h" 14 #include "ViewPreview.h" 17 const int Z_HANDLE = 100;
27 createWidgets (scene);
30 NonPdfCropping::~NonPdfCropping ()
38 void NonPdfCropping::createWidgets(QGraphicsScene &scene)
40 const double MARGIN_PERCENT = 5.0;
41 const int ZERO_WIDTH_IS_ALWAYS_VISIBLE = 0;
43 int marginHor = scene.width() * MARGIN_PERCENT / 100.0;
44 int marginVer = scene.height() * MARGIN_PERCENT / 100.0;
46 QRect box (scene.sceneRect().left() + marginHor,
47 scene.sceneRect().top() + marginVer,
48 scene.sceneRect().width() - 2 * marginHor,
49 scene.sceneRect().height() - 2 * marginVer);
56 m_box =
new QGraphicsRectItem;
57 m_box->setZValue (Z_BOX);
58 m_box->setPen (QPen (QBrush (Qt::gray), ZERO_WIDTH_IS_ALWAYS_VISIBLE));
59 scene.addItem (m_box);
64 void NonPdfCropping::disableEventsWhileMovingAutomatically ()
66 m_handleTL->setDisableEventsWhileMovingAutomatically (
true);
72 void NonPdfCropping::enableEventsWhileMovingAutomatically ()
74 m_handleTL->setDisableEventsWhileMovingAutomatically (
false);
86 QRectF rectTL = m_handleTL->mapRectToScene (m_handleTL->boundingRect());
87 QRectF rectBR = m_handleBR->mapRectToScene (m_handleBR->boundingRect());
89 QRectF rectUnited = rectTL.united (rectBR);
95 const QPointF &oldPos)
97 disableEventsWhileMovingAutomatically();
99 double deltaX = newPos.x() - oldPos.x();
100 double deltaY = newPos.y() - oldPos.y();
102 m_handleTL->moveBy (deltaX,
104 m_handleBR->moveBy (0,
107 enableEventsWhileMovingAutomatically();
113 const QPointF &oldPos)
115 disableEventsWhileMovingAutomatically();
117 double deltaX = newPos.x() - oldPos.x();
118 double deltaY = newPos.y() - oldPos.y();
120 m_handleBL->moveBy (0,
122 m_handleTR->moveBy (deltaX,
125 enableEventsWhileMovingAutomatically();
131 const QPointF &oldPos)
133 disableEventsWhileMovingAutomatically();
135 double deltaX = newPos.x() - oldPos.x();
136 double deltaY = newPos.y() - oldPos.y();
138 m_handleBL->moveBy (deltaX,
140 m_handleTR->moveBy (0,
143 enableEventsWhileMovingAutomatically();
149 const QPointF &oldPos)
151 disableEventsWhileMovingAutomatically();
153 double deltaX = newPos.x() - oldPos.x();
154 double deltaY = newPos.y() - oldPos.y();
156 m_handleTL->moveBy (0,
158 m_handleBR->moveBy (deltaX,
161 enableEventsWhileMovingAutomatically();
166 void NonPdfCropping::updateBox ()
171 rectUnited.setWidth (rectUnited.width () - 1);
172 rectUnited.setHeight (rectUnited.height () - 1);
174 m_box->setRect (rectUnited);
179 return QSize (m_view.scene()->width(),
180 m_view.scene()->height());
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.
QSize windowSize() const
Size of window in scene coordinates.
static const int NON_PDF_CROPPING_TOP
Bit flag when handle is aligned with top edge at reference point.
static const int NON_PDF_CROPPING_BOTTOM
Bit flag when handle is aligned with bottom edge at reference point.
void moveTR(const QPointF &newPos, const QPointF &oldPos)
Top right corner handle was moved.
QRectF frameRect() const
Frame rectangle selected by user.
Class that modifies QGraphicsView to automatically expand/shrink the view to fit the window,...
This class acts as a single handle for the NonPdfCropping class.
void moveBR(const QPointF &newPos, const QPointF &oldPos)
Bottom right corner handle was moved.
NonPdfCropping(QGraphicsScene &scene, ViewPreview &view)
Single constructor.
void moveBL(const QPointF &newPos, const QPointF &oldPos)
Bottom left corner handle was moved.
void setDisableEventsWhileMovingAutomatically(bool disable)
Temporarily disable event handling so code can move this object without triggering a cascade of event...
static const int NON_PDF_CROPPING_RIGHT
Bit flag when handle is aligned with right edge at reference point.