diff --git a/YUViewLib/src/ui/views/MoveAndZoomableView.h b/YUViewLib/src/ui/views/MoveAndZoomableView.h index 4440c17a0..2f2e29ac4 100644 --- a/YUViewLib/src/ui/views/MoveAndZoomableView.h +++ b/YUViewLib/src/ui/views/MoveAndZoomableView.h @@ -148,6 +148,8 @@ protected slots: const QPen ZOOM_RECT_PEN = QPen(QColor(50, 50, 255, 150)); const QBrush ZOOM_RECT_BRUSH = QBrush(QColor(50, 50, 255, 50)); + virtual void getStateFromMaster(); + private: QPoint viewDraggingMousePosStart; QPoint viewDraggingStartOffset; @@ -161,5 +163,4 @@ protected slots: void slaveSetZoomFactor(double zoom); //void slaveSetPinchValues(double scaleFactor, QPointF centerPointOffset); void slaveUpdateWidget(); - void getStateFromMaster(); }; diff --git a/YUViewLib/src/ui/views/splitViewWidget.cpp b/YUViewLib/src/ui/views/splitViewWidget.cpp index abca50043..ff5723ba9 100644 --- a/YUViewLib/src/ui/views/splitViewWidget.cpp +++ b/YUViewLib/src/ui/views/splitViewWidget.cpp @@ -183,10 +183,8 @@ void splitViewWidget::paintEvent(QPaintEvent *paint_event) painter.fillRect(boxRect,Qt::white); painter.drawRect(boxRect); - // Draw the text painter.drawText(textRect, Qt::AlignCenter, text); - // Update the mouse cursor MoveAndZoomableView::updateMouseCursor(); return; @@ -480,7 +478,6 @@ void splitViewWidget::paintEvent(QPaintEvent *paint_event) painter.drawPixmap(pos, waitingForCachingPixmap); } - // Update the mouse cursor MoveAndZoomableView::updateMouseCursor(); if (testMode) @@ -540,6 +537,7 @@ void splitViewWidget::updatePixelPositions() // We now have the pixel difference value for the item under the cursor. // We now draw one zoom box per view const auto viewNum = (isSplitting() && item[1]) ? 2 : 1; + QPoint positions[2]; for (int view = 0; view < viewNum; view++) { // Get the size of the item @@ -556,12 +554,26 @@ void splitViewWidget::updatePixelPositions() if (pixelPoxY < 0) pixelPoxY -= 1; - zoomBoxPixelUnderCursor[view] = QPoint(pixelPosX, pixelPoxY); + positions[view] = QPoint(pixelPosX, pixelPoxY); } } + + setZoomBoxPixelUnderCursor(positions[0], positions[1], true); } } +void splitViewWidget::setZoomBoxPixelUnderCursor(QPoint posA, QPoint posB, bool setOtherViewIfLinked, bool callUpdate) +{ + if (this->enableLink && setOtherViewIfLinked) + this->getOtherWidget()->setZoomBoxPixelUnderCursor(posA, posB, false, true); + + this->zoomBoxPixelUnderCursor[0] = posA; + this->zoomBoxPixelUnderCursor[1] = posB; + + if (callUpdate) + update(); +} + void splitViewWidget::paintZoomBox(int view, QPainter &painter, int xSplit, const QPoint &drawArea_botR, playlistItem *item, int frame, const QPoint &pixelPos, bool pixelPosInItem, double zoomFactor, bool playing) { if (!this->drawZoomBox) @@ -688,6 +700,20 @@ void splitViewWidget::paintZoomBox(int view, QPainter &painter, int xSplit, cons } } +void splitViewWidget::setDrawZoomBox(bool drawZoomBox, bool setOtherViewIfLinked, bool callUpdate) +{ + if (this->enableLink && setOtherViewIfLinked) + this->getOtherWidget()->setDrawZoomBox(drawZoomBox, false, callUpdate); + + this->drawZoomBox = drawZoomBox; + QSignalBlocker actionZoomBoxBlocker(this->actionZoomBox); + this->actionZoomBox.setChecked(drawZoomBox); + this->updateMouseTracking(); + + if (callUpdate) + update(); +} + void splitViewWidget::paintRegularGrid(QPainter *painter, playlistItem *item) { if (regularGridSize == 0) @@ -864,6 +890,8 @@ void splitViewWidget::mouseMoveEvent(QMouseEvent *mouse_event) update(); } + + MoveAndZoomableView::updateMouseCursor(); } void splitViewWidget::mousePressEvent(QMouseEvent *mouse_event) @@ -1002,6 +1030,14 @@ void splitViewWidget::setZoomFactor(double zoom) } } +void splitViewWidget::updateMouseTracking() +{ + if (isViewFrozen) + this->setMouseTracking(false); + else + this->setMouseTracking(viewSplitMode != DISABLED || this->drawZoomBox); +} + bool splitViewWidget::updateMouseCursor(const QPoint &mousePos) { if (!MoveAndZoomableView::updateMouseCursor(mousePos)) @@ -1061,10 +1097,8 @@ void splitViewWidget::gridSetCustom(bool checked) void splitViewWidget::toggleZoomBox(bool checked) { - Q_UNUSED(checked); - this->drawZoomBox = !this->drawZoomBox; - this->setMouseTracking(this->drawZoomBox); - update(); + Q_UNUSED(checked); + this->setDrawZoomBox(!this->drawZoomBox, true, true); } void splitViewWidget::toggleSeparateWindow(bool checked) @@ -1197,6 +1231,8 @@ void splitViewWidget::setViewSplitMode(ViewSplitMode mode, bool setOtherViewIfLi QSignalBlocker actionSplitViewBlocker(actionSplitView[i]); actionSplitView[i].setChecked(viewSplitMode == ViewSplitMode(i)); } + + this->updateMouseTracking(); if (callUpdate) update(); @@ -1408,7 +1444,7 @@ void splitViewWidget::freezeView(bool freeze) { // View is frozen and should be unfrozen isViewFrozen = false; - setMouseTracking(true); + this->updateMouseTracking(); update(); } if (!isViewFrozen && freeze) @@ -1418,7 +1454,7 @@ void splitViewWidget::freezeView(bool freeze) if (this->isMasterView && isSeparateViewEnabled && !playbackPrimary) { isViewFrozen = true; - setMouseTracking(false); + this->updateMouseTracking(); update(); } } @@ -1792,3 +1828,17 @@ QPointer splitViewWidget::getOtherWidget() const return QPointer(qobject_cast(this->masterView)); } } + +void splitViewWidget::getStateFromMaster() +{ + const auto mainView = this->getOtherWidget(); + this->setViewSplitMode(mainView->viewSplitMode, false); + this->setSplittingPoint(mainView->splittingPoint, false); + this->setRegularGridSize(mainView->regularGridSize, false); + this->setDrawZoomBox(mainView->drawZoomBox, false); + + this->updateMouseTracking(); + update(); + + MoveAndZoomableView::getStateFromMaster(); +} diff --git a/YUViewLib/src/ui/views/splitViewWidget.h b/YUViewLib/src/ui/views/splitViewWidget.h index a33967e2b..3d8b75229 100644 --- a/YUViewLib/src/ui/views/splitViewWidget.h +++ b/YUViewLib/src/ui/views/splitViewWidget.h @@ -172,6 +172,7 @@ private slots: QAction actionSeparateViewPlaybackBoth; QAction actionZoomBox; + void updateMouseTracking(); virtual bool updateMouseCursor(const QPoint &srcMousePos) override; // When the splitView is set as a center widget this will assert that after the adding operation the widget will have a @@ -202,9 +203,11 @@ private slots: QPoint zoomBoxMousePosition; //!< If we are drawing the zoom box(es) we have to know where the mouse currently is. QColor zoomBoxBackgroundColor; //!< The color of the zoom box background (read from settings) void paintZoomBox(int view, QPainter &painter, int xSplit, const QPoint &drawArea_botR, playlistItem *item, int frame, const QPoint &pixelPos, bool pixelPosInItem, double zoomFactor, bool playing); + void setDrawZoomBox(bool drawZoomBox, bool setOtherViewIfLinked = true, bool callUpdate = false); //!< Using the current mouse position, calculate the position in the items under the mouse (per view) void updatePixelPositions(); + void setZoomBoxPixelUnderCursor(QPoint posA, QPoint posB, bool setOtherViewIfLinked = true, bool callUpdate = false); QPoint zoomBoxPixelUnderCursor[2]; //!< The above function will update this. (The position of the pixel under the cursor (per item)) // Regular grid @@ -264,6 +267,7 @@ private slots: void testFinished(bool canceled); //< Report the test results and stop the testProgrssUpdateTimer QPointer getOtherWidget() const; + void getStateFromMaster() override; }; #endif // SPLITVIEWWIDGET_H