for viewer zooming, scale texture instead of surface #332
This commit is contained in:
+100
-48
@@ -4,6 +4,7 @@
|
||||
#include <QResizeEvent>
|
||||
#include <QScrollBar>
|
||||
#include <QVBoxLayout>
|
||||
#include <QApplication>
|
||||
|
||||
#include "viewerwidget.h"
|
||||
#include "panels/viewer.h"
|
||||
@@ -12,42 +13,52 @@
|
||||
|
||||
// enforces aspect ratio
|
||||
ViewerContainer::ViewerContainer(QWidget *parent) :
|
||||
QScrollArea(parent),
|
||||
QWidget(parent),
|
||||
fit(true),
|
||||
child(nullptr)
|
||||
{
|
||||
setFrameShadow(QFrame::Plain);
|
||||
setFrameShape(QFrame::NoFrame);
|
||||
horizontal_scrollbar = new QScrollBar(Qt::Horizontal, this);
|
||||
vertical_scrollbar = new QScrollBar(Qt::Vertical, this);
|
||||
|
||||
area = new QWidget(this);
|
||||
area->move(0, 0);
|
||||
setWidget(area);
|
||||
horizontal_scrollbar->setSingleStep(20);
|
||||
vertical_scrollbar->setSingleStep(20);
|
||||
|
||||
child = new ViewerWidget(area);
|
||||
child = new ViewerWidget(this);
|
||||
child->container = this;
|
||||
|
||||
connect(horizontal_scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scroll_changed()));
|
||||
connect(vertical_scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scroll_changed()));
|
||||
}
|
||||
|
||||
ViewerContainer::~ViewerContainer() {
|
||||
delete child;
|
||||
delete area;
|
||||
|
||||
delete horizontal_scrollbar;
|
||||
delete vertical_scrollbar;
|
||||
}
|
||||
|
||||
void ViewerContainer::dragScrollPress(const QPoint &p) {
|
||||
drag_start_x = p.x();
|
||||
drag_start_y = p.y();
|
||||
horiz_start = horizontalScrollBar()->value();
|
||||
vert_start = verticalScrollBar()->value();
|
||||
|
||||
horiz_start = horizontal_scrollbar->value();
|
||||
vert_start = vertical_scrollbar->value();
|
||||
}
|
||||
|
||||
void ViewerContainer::dragScrollMove(const QPoint &p) {
|
||||
int true_x = p.x() + (horiz_start - horizontalScrollBar()->value());
|
||||
int true_y = p.y() + (vert_start - verticalScrollBar()->value());
|
||||
int this_x = p.x();
|
||||
int this_y = p.y();
|
||||
|
||||
horizontalScrollBar()->setValue(horizontalScrollBar()->value() + (drag_start_x - true_x));
|
||||
verticalScrollBar()->setValue(verticalScrollBar()->value() + (drag_start_y - true_y));
|
||||
horizontal_scrollbar->setValue(horiz_start + (drag_start_x-this_x));
|
||||
vertical_scrollbar->setValue(vert_start + (drag_start_y-this_y));
|
||||
}
|
||||
|
||||
drag_start_x = true_x;
|
||||
drag_start_y = true_y;
|
||||
void ViewerContainer::parseWheelEvent(QWheelEvent *event) {
|
||||
if (event->modifiers() & Qt::AltModifier) {
|
||||
QApplication::sendEvent(horizontal_scrollbar, event);
|
||||
} else {
|
||||
QApplication::sendEvent(vertical_scrollbar, event);
|
||||
}
|
||||
}
|
||||
|
||||
void ViewerContainer::adjust() {
|
||||
@@ -55,46 +66,87 @@ void ViewerContainer::adjust() {
|
||||
if (child->waveform) {
|
||||
child->move(0, 0);
|
||||
child->resize(size());
|
||||
} else if (fit) {
|
||||
double aspect_ratio = double(viewer->seq->width)/double(viewer->seq->height);
|
||||
|
||||
int widget_x = 0;
|
||||
int widget_y = 0;
|
||||
int widget_width = width();
|
||||
int widget_height = height();
|
||||
double widget_ar = double(widget_width) / double(widget_height);
|
||||
|
||||
bool widget_is_wider_than_sequence = widget_ar > aspect_ratio;
|
||||
|
||||
if (widget_is_wider_than_sequence) {
|
||||
widget_width = widget_height * aspect_ratio;
|
||||
widget_x = (width() / 2) - (widget_width / 2);
|
||||
} else {
|
||||
widget_height = widget_width / aspect_ratio;
|
||||
widget_y = (height() / 2) - (widget_height / 2);
|
||||
}
|
||||
|
||||
child->move(widget_x, widget_y);
|
||||
child->resize(widget_width, widget_height);
|
||||
|
||||
zoom = double(widget_width) / double(viewer->seq->width);
|
||||
} else {
|
||||
int zoomed_width = double(viewer->seq->width)*zoom;
|
||||
int zoomed_height = double(viewer->seq->height)*zoom;
|
||||
int zoomed_x = 0;
|
||||
int zoomed_y = 0;
|
||||
horizontal_scrollbar->setVisible(false);
|
||||
vertical_scrollbar->setVisible(false);
|
||||
|
||||
if (zoomed_width < width()) zoomed_x = (width()>>1)-(zoomed_width>>1);
|
||||
if (zoomed_height < height()) zoomed_y = (height()>>1)-(zoomed_height>>1);
|
||||
int zoomed_width = qRound(double(viewer->seq->width)*zoom);
|
||||
int zoomed_height = qRound(double(viewer->seq->height)*zoom);
|
||||
|
||||
child->move(zoomed_x, zoomed_y);
|
||||
child->resize(zoomed_width, zoomed_height);
|
||||
if (fit || zoomed_width > width() || zoomed_height > height()) {
|
||||
// if the zoom size is greater than or equal to the available area, only use the available area
|
||||
|
||||
double aspect_ratio = double(viewer->seq->width)/double(viewer->seq->height);
|
||||
|
||||
int widget_x = 0;
|
||||
int widget_y = 0;
|
||||
int widget_width = width();
|
||||
int widget_height = height();
|
||||
|
||||
if (!fit) {
|
||||
widget_width -= vertical_scrollbar->width();
|
||||
widget_height -= horizontal_scrollbar->height();
|
||||
}
|
||||
|
||||
double widget_ar = double(widget_width) / double(widget_height);
|
||||
|
||||
bool widget_is_wider_than_sequence = widget_ar > aspect_ratio;
|
||||
|
||||
if (widget_is_wider_than_sequence) {
|
||||
widget_width = widget_height * aspect_ratio;
|
||||
widget_x = (width() / 2) - (widget_width / 2);
|
||||
} else {
|
||||
widget_height = widget_width / aspect_ratio;
|
||||
widget_y = (height() / 2) - (widget_height / 2);
|
||||
}
|
||||
|
||||
child->move(widget_x, widget_y);
|
||||
child->resize(widget_width, widget_height);
|
||||
|
||||
if (fit) {
|
||||
zoom = double(widget_width) / double(viewer->seq->width);
|
||||
} else if (zoomed_width > width() || zoomed_height > height()) {
|
||||
horizontal_scrollbar->setVisible(true);
|
||||
vertical_scrollbar->setVisible(true);
|
||||
|
||||
horizontal_scrollbar->setMaximum(zoomed_width - width());
|
||||
vertical_scrollbar->setMaximum(zoomed_height - height());
|
||||
|
||||
horizontal_scrollbar->setValue(horizontal_scrollbar->maximum()/2);
|
||||
vertical_scrollbar->setValue(vertical_scrollbar->maximum()/2);
|
||||
}
|
||||
} else {
|
||||
// if the zoom size is smaller than the available area, scale the surface down
|
||||
|
||||
int zoomed_x = 0;
|
||||
int zoomed_y = 0;
|
||||
|
||||
if (zoomed_width < width()) zoomed_x = (width()>>1)-(zoomed_width>>1);
|
||||
if (zoomed_height < height()) zoomed_y = (height()>>1)-(zoomed_height>>1);
|
||||
|
||||
child->move(zoomed_x, zoomed_y);
|
||||
child->resize(zoomed_width, zoomed_height);
|
||||
}
|
||||
}
|
||||
}
|
||||
area->resize(qMax(width(), child->width()), qMax(height(), child->height()));
|
||||
}
|
||||
|
||||
void ViewerContainer::resizeEvent(QResizeEvent *event) {
|
||||
horizontal_scrollbar->move(0, height()-horizontal_scrollbar->height());
|
||||
horizontal_scrollbar->setFixedWidth(width()-vertical_scrollbar->width());
|
||||
horizontal_scrollbar->setPageStep(width());
|
||||
|
||||
vertical_scrollbar->move(width() - vertical_scrollbar->width(), 0);
|
||||
vertical_scrollbar->setFixedHeight(height()-horizontal_scrollbar->height());
|
||||
vertical_scrollbar->setPageStep(height());
|
||||
|
||||
event->accept();
|
||||
adjust();
|
||||
}
|
||||
|
||||
void ViewerContainer::scroll_changed() {
|
||||
child->set_scroll(
|
||||
double(horizontal_scrollbar->value())/double(horizontal_scrollbar->maximum()),
|
||||
double(vertical_scrollbar->value())/double(vertical_scrollbar->maximum())
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user