Fix translation bugs
The translation needs to be scaled relative to the zoom percentage so we get sensible movement when dragging. Dragging is also disabled when the image is smaller than the container widget. Re-orders the initialisation of some variables to stop a compile warning on Travis.
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::SetZoomFlag, display_widget_, &ViewerDisplayWidget::SetZoomFlag);
|
||||
connect(sizer_, &ViewerSizer::SendZoomData, display_widget_, &ViewerDisplayWidget::SetZoomData);
|
||||
sizer_->SetWidget(display_widget_);
|
||||
|
||||
// Create waveform view when audio is connected and video isn't
|
||||
|
||||
@@ -48,7 +48,8 @@ ViewerDisplayWidget::ViewerDisplayWidget(QWidget *parent) :
|
||||
gizmos_(nullptr),
|
||||
gizmo_click_(false),
|
||||
last_loaded_buffer_(nullptr),
|
||||
zoomed_(false)
|
||||
zoomed_(false),
|
||||
zoom_multiplier_(1.0)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -69,13 +70,17 @@ void ViewerDisplayWidget::SetMatrixZoom(const QMatrix4x4 &mat)
|
||||
update();
|
||||
}
|
||||
|
||||
void ViewerDisplayWidget::SetZoomFlag(bool flag)
|
||||
void ViewerDisplayWidget::SetZoomData(bool flag, int percent)
|
||||
{
|
||||
zoomed_ = flag;
|
||||
// If not scaled reset translation matrix to identity
|
||||
// If the image is smaller than the conainer 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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -174,7 +179,7 @@ void ViewerDisplayWidget::mousePressEvent(QMouseEvent *event)
|
||||
SetMatrixTranslate(mat);
|
||||
}
|
||||
|
||||
// get current position in preperation for move event
|
||||
// If translation is enabled get current position in preperation for move event
|
||||
if (event->button() == Qt::MiddleButton && zoomed_) {
|
||||
position_ = event->pos();
|
||||
return;
|
||||
@@ -189,11 +194,12 @@ void ViewerDisplayWidget::mousePressEvent(QMouseEvent *event)
|
||||
|
||||
void ViewerDisplayWidget::mouseMoveEvent(QMouseEvent *event)
|
||||
{
|
||||
// Only allow translation if the image is larger than the container widget
|
||||
if (event->buttons() & Qt::MiddleButton && zoomed_) {
|
||||
QPointF delta = event->pos() - position_;
|
||||
// scale delta to widget size
|
||||
delta.setX(delta.x() / width());
|
||||
delta.setY(delta.y() / height());
|
||||
// scale delta to widget size and zoom level
|
||||
delta.setX(zoom_multiplier_ * delta.x() / width());
|
||||
delta.setY(zoom_multiplier_ * delta.y() / height());
|
||||
|
||||
QMatrix4x4 mat;
|
||||
mat = GetMatrixTranslate();
|
||||
|
||||
@@ -116,7 +116,7 @@ public slots:
|
||||
*/
|
||||
void SetImage(FramePtr in_buffer);
|
||||
|
||||
void SetZoomFlag(bool flag);
|
||||
void SetZoomData(bool flag, int percent);
|
||||
|
||||
signals:
|
||||
/**
|
||||
@@ -181,8 +181,6 @@ private:
|
||||
*/
|
||||
QMatrix4x4 scale_matrix_;
|
||||
|
||||
bool zoomed_;
|
||||
|
||||
#ifdef Q_OS_LINUX
|
||||
static bool nouveau_check_done_;
|
||||
#endif
|
||||
@@ -201,6 +199,16 @@ private:
|
||||
|
||||
FramePtr last_loaded_buffer_;
|
||||
|
||||
/**
|
||||
* @brief Tells us if the image is zoomed in to be larger than the container widget.
|
||||
*/
|
||||
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,12 +105,15 @@ void ViewerSizer::UpdateSize()
|
||||
// This container is taller than the image, scale by width
|
||||
child_size = QSize(width(), qRound(child_size.width() / aspect_ratio_));
|
||||
}
|
||||
emit SetZoomFlag(false);
|
||||
emit SendZoomData(false, 0);
|
||||
|
||||
} else {
|
||||
|
||||
float x_scale = 1.0f;
|
||||
float y_scale = 1.0f;
|
||||
// Translation is only active if the image is bigger then the widget
|
||||
// See ViewerDisplayWidget::SetZoomData
|
||||
bool zoomed_in = false;
|
||||
|
||||
int zoomed_width = qRound(width_ * static_cast<double>(zoom_) * 0.01);
|
||||
int zoomed_height = qRound(height_ * static_cast<double>(zoom_) * 0.01);
|
||||
@@ -118,18 +121,20 @@ void ViewerSizer::UpdateSize()
|
||||
if (zoomed_width > width()) {
|
||||
x_scale = static_cast<double>(zoomed_width) / static_cast<double>(width());
|
||||
zoomed_width = width();
|
||||
zoomed_in = true;
|
||||
}
|
||||
|
||||
if (zoomed_height > height()) {
|
||||
y_scale = static_cast<double>(zoomed_height) / static_cast<double>(height());
|
||||
zoomed_height = height();
|
||||
zoomed_in = true;
|
||||
}
|
||||
|
||||
// Rather than make a huge surface, we still crop at our width/height and then signal a matrix
|
||||
child_matrix.scale(x_scale, y_scale, 1.0F);
|
||||
|
||||
child_size = QSize(zoomed_width, zoomed_height);
|
||||
emit SetZoomFlag(true);
|
||||
emit SendZoomData(zoomed_in, zoom_);
|
||||
}
|
||||
|
||||
widget_->resize(child_size);
|
||||
|
||||
@@ -65,7 +65,7 @@ public:
|
||||
|
||||
signals:
|
||||
void RequestMatrix(const QMatrix4x4& matrix);
|
||||
void SetZoomFlag(bool flag);
|
||||
void SendZoomData(bool flag, int percent);
|
||||
|
||||
protected:
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user