8 #include "PdfCropping.h" 9 #include "PdfFrameHandle.h" 10 #include <QGraphicsRectItem> 11 #include <QGraphicsScene> 13 #include "QtToString.h" 14 #include "ViewPreview.h" 17 const int Z_HANDLE = 100;
23 createWidgets (scene);
26 void PdfCropping::createWidgets(QGraphicsScene &scene)
28 const double MARGIN_PERCENT = 5.0;
29 const int ZERO_WIDTH_IS_ALWAYS_VISIBLE = 0;
31 int marginHor = scene.width() * MARGIN_PERCENT / 100.0;
32 int marginVer = scene.height() * MARGIN_PERCENT / 100.0;
34 QRect box (scene.sceneRect().left() + marginHor,
35 scene.sceneRect().top() + marginVer,
36 scene.sceneRect().width() - 2 * marginHor,
37 scene.sceneRect().height() - 2 * marginVer);
44 m_box =
new QGraphicsRectItem;
45 m_box->setZValue (Z_BOX);
46 m_box->setPen (QPen (QBrush (Qt::gray), ZERO_WIDTH_IS_ALWAYS_VISIBLE));
47 scene.addItem (m_box);
52 void PdfCropping::disableEventsWhileMovingAutomatically ()
60 void PdfCropping::enableEventsWhileMovingAutomatically ()
74 QRectF rectTL = m_handleTL->mapRectToScene (m_handleTL->boundingRect());
75 QRectF rectBR = m_handleBR->mapRectToScene (m_handleBR->boundingRect());
77 QRectF rectUnited = rectTL.united (rectBR);
83 const QPointF &oldPos)
85 disableEventsWhileMovingAutomatically();
87 double deltaX = newPos.x() - oldPos.x();
88 double deltaY = newPos.y() - oldPos.y();
90 m_handleTL->moveBy (deltaX,
92 m_handleBR->moveBy (0,
95 enableEventsWhileMovingAutomatically();
101 const QPointF &oldPos)
103 disableEventsWhileMovingAutomatically();
105 double deltaX = newPos.x() - oldPos.x();
106 double deltaY = newPos.y() - oldPos.y();
108 m_handleBL->moveBy (0,
110 m_handleTR->moveBy (deltaX,
113 enableEventsWhileMovingAutomatically();
119 const QPointF &oldPos)
121 disableEventsWhileMovingAutomatically();
123 double deltaX = newPos.x() - oldPos.x();
124 double deltaY = newPos.y() - oldPos.y();
126 m_handleBL->moveBy (deltaX,
128 m_handleTR->moveBy (0,
131 enableEventsWhileMovingAutomatically();
137 const QPointF &oldPos)
139 disableEventsWhileMovingAutomatically();
141 double deltaX = newPos.x() - oldPos.x();
142 double deltaY = newPos.y() - oldPos.y();
144 m_handleTL->moveBy (0,
146 m_handleBR->moveBy (deltaX,
149 enableEventsWhileMovingAutomatically();
154 void PdfCropping::updateBox ()
159 rectUnited.setWidth (rectUnited.width () - 1);
160 rectUnited.setHeight (rectUnited.height () - 1);
162 m_box->setRect (rectUnited);
167 return QSize (m_view.scene()->width(),
168 m_view.scene()->height());
void moveTL(const QPointF &newPos, const QPointF &oldPos)
Top left corner handle was moved.
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.
QRectF frameRect() const
Frame rectangle selected by user.
PdfCropping(QGraphicsScene &scene, ViewPreview &view)
Single constructor.
Class that modifies QGraphicsView to automatically expand/shrink the view to fit the 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.
This class acts as a single handle for the PdfCropping class.
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.
void setDisableEventsWhileMovingAutomatically(bool disable)
Temporarily disable event handling so code can move this object without triggering a cascade of event...