Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/fix ui issues #247

Merged
merged 4 commits into from
Jul 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion YUViewLib/src/ui/views/MoveAndZoomableView.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -161,5 +163,4 @@ protected slots:
void slaveSetZoomFactor(double zoom);
//void slaveSetPinchValues(double scaleFactor, QPointF centerPointOffset);
void slaveUpdateWidget();
void getStateFromMaster();
};
70 changes: 60 additions & 10 deletions YUViewLib/src/ui/views/splitViewWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -480,7 +478,6 @@ void splitViewWidget::paintEvent(QPaintEvent *paint_event)
painter.drawPixmap(pos, waitingForCachingPixmap);
}

// Update the mouse cursor
MoveAndZoomableView::updateMouseCursor();

if (testMode)
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -864,6 +890,8 @@ void splitViewWidget::mouseMoveEvent(QMouseEvent *mouse_event)

update();
}

MoveAndZoomableView::updateMouseCursor();
}

void splitViewWidget::mousePressEvent(QMouseEvent *mouse_event)
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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)
Expand All @@ -1418,7 +1454,7 @@ void splitViewWidget::freezeView(bool freeze)
if (this->isMasterView && isSeparateViewEnabled && !playbackPrimary)
{
isViewFrozen = true;
setMouseTracking(false);
this->updateMouseTracking();
update();
}
}
Expand Down Expand Up @@ -1792,3 +1828,17 @@ QPointer<splitViewWidget> splitViewWidget::getOtherWidget() const
return QPointer<splitViewWidget>(qobject_cast<splitViewWidget*>(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();
}
4 changes: 4 additions & 0 deletions YUViewLib/src/ui/views/splitViewWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -264,6 +267,7 @@ private slots:
void testFinished(bool canceled); //< Report the test results and stop the testProgrssUpdateTimer

QPointer<splitViewWidget> getOtherWidget() const;
void getStateFromMaster() override;
};

#endif // SPLITVIEWWIDGET_H