Properly fix translation errors in viewer
Original fix was wrong, this sorts it out I think. Delta values had to be doubled as we're in Clip space (I think) and the matrix multiplication order had to be swapped around. Updated one of the signla/slot pairs to be simpler as we no longer need to pass the zoom percentage back and forth.
This commit is contained in:
@@ -79,7 +79,7 @@ ViewerWidget::ViewerWidget(QWidget *parent) :
|
||||
connect(display_widget_, &ViewerDisplayWidget::ColorProcessorChanged, this, &ViewerWidget::ColorProcessorChanged);
|
||||
connect(display_widget_, &ViewerDisplayWidget::ColorManagerChanged, this, &ViewerWidget::ColorManagerChanged);
|
||||
connect(sizer_, &ViewerSizer::RequestMatrix, display_widget_, &ViewerDisplayWidget::SetMatrixZoom);
|
||||
connect(sizer_, &ViewerSizer::SendZoomData, display_widget_, &ViewerDisplayWidget::SetZoomData);
|
||||
connect(sizer_, &ViewerSizer::IsZoomed, display_widget_, &ViewerDisplayWidget::IsZoomed);
|
||||
sizer_->SetWidget(display_widget_);
|
||||
|
||||
// Create waveform view when audio is connected and video isn't
|
||||
|
||||
@@ -49,8 +49,7 @@ ViewerDisplayWidget::ViewerDisplayWidget(QWidget *parent) :
|
||||
gizmos_(nullptr),
|
||||
gizmo_click_(false),
|
||||
last_loaded_buffer_(nullptr),
|
||||
zoomed_(false),
|
||||
zoom_multiplier_(1.0)
|
||||
zoomed_(false)
|
||||
{
|
||||
connect(Core::instance(), &Core::ToolChanged, this, &ViewerDisplayWidget::ToolChanged);
|
||||
|
||||
@@ -74,17 +73,13 @@ void ViewerDisplayWidget::SetMatrixZoom(const QMatrix4x4 &mat)
|
||||
update();
|
||||
}
|
||||
|
||||
void ViewerDisplayWidget::SetZoomData(bool flag, int percent)
|
||||
void ViewerDisplayWidget::IsZoomed(bool flag)
|
||||
{
|
||||
zoomed_ = flag;
|
||||
// If the image is smaller than the conainer widget we disable translation
|
||||
// If the image is smaller than the container widget we disable translation
|
||||
if (!flag) {
|
||||
QMatrix4x4 mat;
|
||||
SetMatrixTranslate(mat);
|
||||
zoom_multiplier_ = 1.0f;
|
||||
}
|
||||
else {
|
||||
zoom_multiplier_ = 1.0 / (static_cast<double>(percent) * 0.01);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,7 +97,7 @@ void ViewerDisplayWidget::ToolChanged(Tool::Item tool)
|
||||
QMatrix4x4 ViewerDisplayWidget::GetCompleteMatrix()
|
||||
{
|
||||
QMatrix4x4 mat;
|
||||
return scale_matrix_ * translate_matrix_ * mat;
|
||||
return translate_matrix_ * scale_matrix_ * mat;
|
||||
}
|
||||
|
||||
void ViewerDisplayWidget::SetSignalCursorColorEnabled(bool e)
|
||||
@@ -212,9 +207,9 @@ void ViewerDisplayWidget::mouseMoveEvent(QMouseEvent *event)
|
||||
// Only allow translation if the image is larger than the container widget
|
||||
if ((event->buttons() & Qt::MiddleButton || hand_tool_) && zoomed_) {
|
||||
QPointF delta = event->pos() - position_;
|
||||
// scale delta to widget size and zoom level
|
||||
delta.setX(zoom_multiplier_ * delta.x() / width());
|
||||
delta.setY(zoom_multiplier_ * delta.y() / height());
|
||||
// scale delta to widget size
|
||||
delta.setX(2 * delta.x() / width());
|
||||
delta.setY(2 * delta.y() / height());
|
||||
|
||||
QMatrix4x4 mat;
|
||||
mat = GetMatrixTranslate();
|
||||
|
||||
@@ -117,7 +117,7 @@ public slots:
|
||||
*/
|
||||
void SetImage(FramePtr in_buffer);
|
||||
|
||||
void SetZoomData(bool flag, int percent);
|
||||
void IsZoomed(bool flag);
|
||||
|
||||
void ToolChanged(Tool::Item tool);
|
||||
|
||||
@@ -207,11 +207,6 @@ private:
|
||||
*/
|
||||
bool zoomed_;
|
||||
|
||||
/**
|
||||
* @brief Scale the translation so the image sticks to the mouse and we get sensible movement
|
||||
*/
|
||||
double zoom_multiplier_;
|
||||
|
||||
/**
|
||||
* @brief position of mouse to calculate delta from.
|
||||
*/
|
||||
|
||||
@@ -105,7 +105,7 @@ void ViewerSizer::UpdateSize()
|
||||
// This container is taller than the image, scale by width
|
||||
child_size = QSize(width(), qRound(child_size.width() / aspect_ratio_));
|
||||
}
|
||||
emit SendZoomData(false, 0);
|
||||
emit IsZoomed(false);
|
||||
|
||||
} else {
|
||||
|
||||
@@ -134,7 +134,7 @@ void ViewerSizer::UpdateSize()
|
||||
child_matrix.scale(x_scale, y_scale, 1.0F);
|
||||
|
||||
child_size = QSize(zoomed_width, zoomed_height);
|
||||
emit SendZoomData(zoomed_in, zoom_);
|
||||
emit IsZoomed(zoomed_in);
|
||||
}
|
||||
|
||||
widget_->resize(child_size);
|
||||
|
||||
@@ -65,7 +65,7 @@ public:
|
||||
|
||||
signals:
|
||||
void RequestMatrix(const QMatrix4x4& matrix);
|
||||
void SendZoomData(bool flag, int percent);
|
||||
void IsZoomed(bool flag);
|
||||
|
||||
protected:
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user