18#include <QPainterPath>
19#include "viewmanager.h"
23const static qreal mMinScale = 0.01;
24const static qreal mMaxScale = 100.0;
26const std::vector<qreal> gZoomLevels
28 0.01, 0.02, 0.04, 0.06, 0.08, 0.12,
29 0.16, 0.25, 0.33, 0.5, 0.75, 1.0,
30 1.5, 2.0, 3.0, 4.0, 5.0, 6.0,
31 8.0, 16.0, 32.0, 48.0, 64.0, 96.0
39ViewManager::~ViewManager() {
42bool ViewManager::init()
50 updateViewTransforms();
57 o->data()->setCurrentView(mView);
63 return mViewCanvas.
map(p);
68 return mViewCanvasInverse.
map(p);
73 return mViewCanvas.
map(path);
76QRectF ViewManager::mapCanvasToScreen(
const QRectF& rect)
const
78 return mViewCanvas.
mapRect(rect);
81QRectF ViewManager::mapScreenToCanvas(
const QRectF& rect)
const
83 return mViewCanvasInverse.
mapRect(rect);
88 return mViewCanvas.
map(polygon);
93 return mViewCanvasInverse.
map(polygon);
98 return mViewCanvasInverse.
map(path);
108 return mViewCanvasInverse;
111qreal ViewManager::getViewScaleInverse()
const
113 return mViewCanvasInverse.
m11();
116void ViewManager::updateViewTransforms()
125 s.
scale(mScaling, mScaling);
130 float flipX = mIsFlipHorizontal ? -1.f : 1.f;
131 float flipY = mIsFlipVertical ? -1.f : 1.f;
134 mViewCanvas = mView * f * mCentre;
135 mViewCanvasInverse = mViewCanvas.
inverted();
138QPointF ViewManager::translation()
const
143void ViewManager::translate(
float dx,
float dy)
145 mTranslation =
QPointF(dx, dy);
146 updateViewTransforms();
151void ViewManager::translate(
QPointF offset)
153 translate(
static_cast<float>(offset.
x()),
static_cast<float>(offset.
y()));
156void ViewManager::centerView()
161float ViewManager::rotation()
166void ViewManager::rotate(
float degree)
169 updateViewTransforms();
174void ViewManager::rotateRelative(
float delta)
176 mRotation = mRotation + delta;
177 updateViewTransforms();
182void ViewManager::resetRotation()
187qreal ViewManager::scaling()
192void ViewManager::scaleUp()
194 for (
size_t i = 0; i < gZoomLevels.size(); i++)
196 if (mScaling < gZoomLevels[i])
198 scale(gZoomLevels[i]);
203 scale(mScaling * 1.25);
206void ViewManager::scaleDown()
208 const size_t nZoomLevels = gZoomLevels.size();
209 for (
size_t i = 1; i <= nZoomLevels; i++)
211 if (mScaling > gZoomLevels[nZoomLevels - i])
213 scale(gZoomLevels[nZoomLevels - i]);
218 scale(mScaling * 0.8);
221void ViewManager::scale100()
226void ViewManager::scale400()
231void ViewManager::scale300()
236void ViewManager::scale200()
241void ViewManager::scale50()
246void ViewManager::scale33()
251void ViewManager::scale25()
256void ViewManager::scale(qreal scaleValue)
258 if (scaleValue < mMinScale)
260 scaleValue = mMinScale;
262 else if (scaleValue > mMaxScale)
264 scaleValue = mMaxScale;
267 mScaling = scaleValue;
268 updateViewTransforms();
273void ViewManager::scaleAtOffset(qreal scaleValue,
QPointF offset)
275 if (scaleValue < mMinScale)
277 scaleValue = mMinScale;
279 else if (scaleValue > mMaxScale)
281 scaleValue = mMaxScale;
283 mTranslation = (mTranslation + offset) * mScaling / scaleValue - offset;
284 mScaling = scaleValue;
285 updateViewTransforms();
290void ViewManager::flipHorizontal(
bool b)
292 if (b != mIsFlipHorizontal)
294 mIsFlipHorizontal = b;
295 updateViewTransforms();
302void ViewManager::flipVertical(
bool b)
304 if (b != mIsFlipVertical)
307 updateViewTransforms();
314void ViewManager::setOverlayCenter(
bool b)
316 if (b != mOverlayCenter)
319 updateViewTransforms();
324void ViewManager::setOverlayThirds(
bool b)
326 if (b != mOverlayThirds)
329 updateViewTransforms();
334void ViewManager::setOverlayGoldenRatio(
bool b)
336 if (b != mOverlayGoldenRatio)
338 mOverlayGoldenRatio = b;
339 updateViewTransforms();
344void ViewManager::setOverlaySafeAreas(
bool b)
346 if (b != mOverlaySafeAreas)
348 mOverlaySafeAreas = b;
349 updateViewTransforms();
354void ViewManager::setCanvasSize(
QSize size)
359 updateViewTransforms();
363void ViewManager::forceUpdateViewTransform()
365 updateViewTransforms();
369void ViewManager::onCurrentFrameChanged()
375void ViewManager::resetView()
381 updateViewTransforms();
void scrubbed(int frameNumber)
This should be emitted after scrubbing.
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)