added viewer zoom functionality
This commit is contained in:
+26
-13
@@ -14,6 +14,7 @@
|
||||
#include "ui/audiomonitor.h"
|
||||
#include "ui_timeline.h"
|
||||
#include "playback/playback.h"
|
||||
#include "ui/viewerwidget.h"
|
||||
#include "debug.h"
|
||||
|
||||
#define FRAMES_IN_ONE_MINUTE 1798 // 1800 - 2
|
||||
@@ -46,9 +47,9 @@ Viewer::Viewer(QWidget *parent) :
|
||||
ui->headers->viewer = this;
|
||||
ui->headers->snapping = false;
|
||||
ui->headers->show_text(false);
|
||||
ui->glViewerPane->child = ui->openGLWidget;
|
||||
ui->openGLWidget->viewer = this;
|
||||
viewer_widget = ui->openGLWidget;
|
||||
ui->glViewerPane->viewer = this;
|
||||
viewer_widget = ui->glViewerPane->child;
|
||||
viewer_widget->viewer = this;
|
||||
set_media(NULL);
|
||||
|
||||
ui->currentTimecode->setEnabled(false);
|
||||
@@ -63,7 +64,8 @@ Viewer::Viewer(QWidget *parent) :
|
||||
connect(&playback_updater, SIGNAL(timeout()), this, SLOT(timer_update()));
|
||||
connect(&recording_flasher, SIGNAL(timeout()), this, SLOT(recording_flasher_update()));
|
||||
connect(ui->horizontalScrollBar, SIGNAL(valueChanged(int)), ui->headers, SLOT(set_scroll(int)));
|
||||
connect(ui->horizontalScrollBar, SIGNAL(valueChanged(int)), ui->openGLWidget, SLOT(set_waveform_scroll(int)));
|
||||
connect(ui->horizontalScrollBar, SIGNAL(valueChanged(int)), viewer_widget, SLOT(set_waveform_scroll(int)));
|
||||
connect(ui->zoomComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(zoom_update(int)));
|
||||
|
||||
update_playhead_timecode(0);
|
||||
update_end_timecode();
|
||||
@@ -75,7 +77,7 @@ Viewer::~Viewer() {
|
||||
|
||||
bool Viewer::is_focused() {
|
||||
return ui->headers->hasFocus()
|
||||
|| ui->openGLWidget->hasFocus()
|
||||
|| viewer_widget->hasFocus()
|
||||
|| ui->pushButton->hasFocus()
|
||||
|| ui->pushButton_2->hasFocus()
|
||||
|| ui->pushButton_3->hasFocus()
|
||||
@@ -378,7 +380,7 @@ void Viewer::update_header_zoom() {
|
||||
minimum_zoom = (sequenceEndFrame > 0) ? ((double) ui->headers->width() / (double) sequenceEndFrame) : 1;
|
||||
ui->headers->update_zoom(qMax(ui->headers->get_zoom(), minimum_zoom));
|
||||
ui->headers->set_scrollbar_max(ui->horizontalScrollBar, sequenceEndFrame, ui->headers->width());
|
||||
ui->openGLWidget->waveform_zoom = ui->headers->get_zoom();
|
||||
viewer_widget->waveform_zoom = ui->headers->get_zoom();
|
||||
} else {
|
||||
ui->headers->update();
|
||||
}
|
||||
@@ -422,9 +424,9 @@ void Viewer::set_zoom(bool in) {
|
||||
} else {
|
||||
ui->headers->update_zoom(qMax(minimum_zoom, ui->headers->get_zoom()*0.5));
|
||||
}
|
||||
if (ui->openGLWidget->waveform) {
|
||||
ui->openGLWidget->waveform_zoom = ui->headers->get_zoom();
|
||||
ui->openGLWidget->update();
|
||||
if (viewer_widget->waveform) {
|
||||
viewer_widget->waveform_zoom = ui->headers->get_zoom();
|
||||
viewer_widget->update();
|
||||
}
|
||||
ui->headers->set_scrollbar_max(ui->horizontalScrollBar, seq->getEndFrame(), ui->headers->width());
|
||||
center_scroll_to_playhead(ui->horizontalScrollBar, ui->headers->get_zoom(), seq->playhead);
|
||||
@@ -555,7 +557,19 @@ void Viewer::recording_flasher_update() {
|
||||
ui->pushButton_3->setStyleSheet("background: red;");
|
||||
} else {
|
||||
ui->pushButton_3->setStyleSheet(QString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Viewer::zoom_update(int i) {
|
||||
if (i == 0) {
|
||||
ui->glViewerPane->fit = true;
|
||||
} else {
|
||||
ui->glViewerPane->fit = false;
|
||||
QString pc = ui->zoomComboBox->itemText(i);
|
||||
pc = pc.left(pc.length() - 1);
|
||||
ui->glViewerPane->zoom = pc.toDouble()*0.01;
|
||||
}
|
||||
ui->glViewerPane->adjust();
|
||||
}
|
||||
|
||||
void Viewer::clean_created_seq() {
|
||||
@@ -583,8 +597,8 @@ void Viewer::set_sequence(bool main, Sequence *s) {
|
||||
|
||||
ui->headers->setEnabled(!null_sequence);
|
||||
ui->currentTimecode->setEnabled(!null_sequence);
|
||||
ui->openGLWidget->setEnabled(!null_sequence);
|
||||
ui->openGLWidget->setVisible(!null_sequence);
|
||||
viewer_widget->setEnabled(!null_sequence);
|
||||
viewer_widget->setVisible(!null_sequence);
|
||||
ui->pushButton->setEnabled(!null_sequence);
|
||||
ui->pushButton_2->setEnabled(!null_sequence);
|
||||
ui->pushButton_3->setEnabled(!null_sequence);
|
||||
@@ -599,7 +613,6 @@ void Viewer::set_sequence(bool main, Sequence *s) {
|
||||
update_playhead_timecode(seq->playhead);
|
||||
update_end_timecode();
|
||||
|
||||
ui->glViewerPane->aspect_ratio = (float) seq->width / (float) seq->height;
|
||||
ui->glViewerPane->adjust();
|
||||
|
||||
setWindowTitle(panel_name + seq->name);
|
||||
|
||||
@@ -83,6 +83,7 @@ private slots:
|
||||
void update_playhead();
|
||||
void timer_update();
|
||||
void recording_flasher_update();
|
||||
void zoom_update(int i);
|
||||
private:
|
||||
void clean_created_seq();
|
||||
void set_sequence(bool main, Sequence* s);
|
||||
|
||||
+1
-16
@@ -49,16 +49,6 @@
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<widget class="ViewerWidget" name="openGLWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>110</x>
|
||||
<y>50</y>
|
||||
<width>300</width>
|
||||
<height>200</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
@@ -109,7 +99,7 @@
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="comboBox">
|
||||
<widget class="QComboBox" name="zoomComboBox">
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Fit</string>
|
||||
@@ -332,11 +322,6 @@
|
||||
</widget>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>ViewerWidget</class>
|
||||
<extends>QOpenGLWidget</extends>
|
||||
<header>ui/viewerwidget.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>ViewerContainer</class>
|
||||
<extends>QWidget</extends>
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@
|
||||
#define MEDIA_TYPE_SEQUENCE 1
|
||||
#define MEDIA_TYPE_FOLDER 2
|
||||
|
||||
class Footage;
|
||||
struct Footage;
|
||||
class MediaThrobber;
|
||||
struct Sequence;
|
||||
#include <QIcon>
|
||||
|
||||
+43
-12
@@ -2,43 +2,74 @@
|
||||
|
||||
#include <QWidget>
|
||||
#include <QResizeEvent>
|
||||
#include <QScrollBar>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include "viewerwidget.h"
|
||||
#include "panels/viewer.h"
|
||||
#include "project/sequence.h"
|
||||
#include "debug.h"
|
||||
|
||||
// enforces aspect ratio
|
||||
ViewerContainer::ViewerContainer(QWidget *parent) :
|
||||
QWidget(parent),
|
||||
aspect_ratio(1),
|
||||
QScrollArea(parent),
|
||||
fit(true),
|
||||
child(NULL)
|
||||
{}
|
||||
{
|
||||
setFrameShadow(QFrame::Plain);
|
||||
setFrameShape(QFrame::NoFrame);
|
||||
|
||||
area = new QWidget(this);
|
||||
area->move(0, 0);
|
||||
setWidget(area);
|
||||
|
||||
child = new ViewerWidget(area);
|
||||
}
|
||||
|
||||
ViewerContainer::~ViewerContainer() {
|
||||
delete area;
|
||||
}
|
||||
|
||||
void ViewerContainer::adjust() {
|
||||
if (child != NULL) {
|
||||
if (viewer->seq != NULL) {
|
||||
if (child->waveform) {
|
||||
child->move(0, 0);
|
||||
child->resize(size());
|
||||
} else {
|
||||
QSize widget_size = 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 = widget_size.width();
|
||||
int widget_height = widget_size.height();
|
||||
int widget_width = width();
|
||||
int widget_height = height();
|
||||
float widget_ar = (float) widget_width /(float) widget_height;
|
||||
|
||||
bool widget_is_larger_than_sequence = widget_ar > aspect_ratio;
|
||||
bool widget_is_wider_than_sequence = widget_ar > aspect_ratio;
|
||||
|
||||
if (widget_is_larger_than_sequence) {
|
||||
if (widget_is_wider_than_sequence) {
|
||||
widget_width = widget_height * aspect_ratio;
|
||||
widget_x = (widget_size.width() / 2) - (widget_width / 2);
|
||||
widget_x = (width() / 2) - (widget_width / 2);
|
||||
} else {
|
||||
widget_height = widget_width / aspect_ratio;
|
||||
widget_y = (widget_size.height() / 2) - (widget_height / 2);
|
||||
widget_y = (height() / 2) - (widget_height / 2);
|
||||
}
|
||||
|
||||
child->move(widget_x, widget_y);
|
||||
child->resize(widget_width, widget_height);
|
||||
} 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;
|
||||
|
||||
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) {
|
||||
|
||||
+12
-3
@@ -1,15 +1,21 @@
|
||||
#ifndef VIEWERCONTAINER_H
|
||||
#define VIEWERCONTAINER_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QScrollArea>
|
||||
class Viewer;
|
||||
class ViewerWidget;
|
||||
|
||||
class ViewerContainer : public QWidget
|
||||
class ViewerContainer : public QScrollArea
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ViewerContainer(QWidget *parent = 0);
|
||||
float aspect_ratio;
|
||||
~ViewerContainer();
|
||||
|
||||
bool fit;
|
||||
double zoom;
|
||||
|
||||
Viewer* viewer;
|
||||
ViewerWidget* child;
|
||||
void adjust();
|
||||
|
||||
@@ -19,6 +25,9 @@ protected:
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
|
||||
private:
|
||||
QWidget* area;
|
||||
};
|
||||
|
||||
#endif // VIEWERCONTAINER_H
|
||||
|
||||
Reference in New Issue
Block a user