void Navigator::setScoreView(ScoreView* v) { if (_cv) { disconnect(this, SIGNAL(viewRectMoved(const QRectF&)), _cv, SLOT(setViewRect(const QRectF&))); disconnect(_cv, SIGNAL(viewRectChanged()), this, SLOT(updateViewRect())); } _cv = QPointer<ScoreView>(v); if (v) { _score = v->score(); rescale(); connect(this, SIGNAL(viewRectMoved(const QRectF&)), v, SLOT(setViewRect(const QRectF&))); connect(_cv, SIGNAL(viewRectChanged()), this, SLOT(updateViewRect())); rescale(); updateViewRect(); } else {
/** * You should use this function instead of calling scale() directly * to keep track of the zoom factor. * @param zoom new zoom factor */ void CanvasView::setZoom(qreal zoom) { if(zoom<=0) return; _zoom = zoom; QMatrix nm(1,0,0,1, matrix().dx(), matrix().dy()); nm.scale(_zoom/100.0, _zoom/100.0); nm.rotate(_rotate); setMatrix(nm); emit viewTransformed(_zoom, _rotate); viewRectChanged(); }
void CanvasView::setCanvas(drawingboard::CanvasScene *scene) { _scene = scene; _toolbox.setScene(scene); setScene(scene); connect(_scene, &drawingboard::CanvasScene::canvasInitialized, [this]() { viewRectChanged(); }); connect(_scene, &drawingboard::CanvasScene::canvasResized, [this](int xoff, int yoff, const QSize &oldsize) { if(oldsize.isEmpty()) { centerOn(_scene->sceneRect().center()); } else { scrollContentsBy(-xoff, -yoff); } }); }
void CanvasView::resizeEvent(QResizeEvent *event) { QGraphicsView::resizeEvent(event); viewRectChanged(); }
void CanvasView::scrollContentsBy(int dx, int dy) { QGraphicsView::scrollContentsBy(dx, dy); viewRectChanged(); }