various: allow users to override the start and end index of image sequences

Also includes various fixes to footage property setting/signalling.
This commit is contained in:
itsmattkc
2020-03-09 19:58:42 +11:00
parent 0131d83256
commit 16b072fa98
11 changed files with 181 additions and 26 deletions
@@ -21,7 +21,9 @@
#include "videostreamproperties.h"
#include <QGridLayout>
#include <QGroupBox>
#include <QLabel>
#include <QMessageBox>
#include <OpenColorIO/OpenColorIO.h>
namespace OCIO = OCIO_NAMESPACE::v1;
@@ -35,12 +37,16 @@ VideoStreamProperties::VideoStreamProperties(ImageStreamPtr stream) :
QGridLayout* video_layout = new QGridLayout(this);
video_layout->setMargin(0);
video_layout->addWidget(new QLabel(tr("Color Space:")), 0, 0);
int row = 0;
video_layout->addWidget(new QLabel(tr("Color Space:")), row, 0);
video_color_space_ = new QComboBox();
OCIO::ConstConfigRcPtr config = stream->footage()->project()->color_manager()->GetConfig();
int number_of_colorspaces = config->getNumColorSpaces();
video_color_space_->addItem(tr("Default (%1)").arg(stream->footage()->project()->default_input_colorspace()));
for (int i=0;i<number_of_colorspaces;i++) {
QString colorspace = config->getColorSpaceNameByIndex(i);
@@ -49,22 +55,91 @@ VideoStreamProperties::VideoStreamProperties(ImageStreamPtr stream) :
video_color_space_->setCurrentText(stream_->colorspace());
video_layout->addWidget(video_color_space_, 0, 1);
video_layout->addWidget(video_color_space_, row, 1);
row++;
video_premultiply_alpha_ = new QCheckBox(tr("Premultiplied Alpha"));
video_premultiply_alpha_->setChecked(stream_->premultiplied_alpha());
video_layout->addWidget(video_premultiply_alpha_, 1, 0, 1, 2);
video_layout->addWidget(video_premultiply_alpha_, row, 0, 1, 2);
row++;
if (IsImageSequence(stream.get())) {
QGroupBox* imgseq_group = new QGroupBox(tr("Image Sequence"));
QGridLayout* imgseq_layout = new QGridLayout(imgseq_group);
int imgseq_row = 0;
VideoStream* video_stream = static_cast<VideoStream*>(stream.get());
imgseq_layout->addWidget(new QLabel(tr("Start Index:")), imgseq_row, 0);
imgseq_start_time_ = new IntegerSlider();
imgseq_start_time_->SetMinimum(0);
imgseq_start_time_->SetValue(video_stream->start_time());
imgseq_layout->addWidget(imgseq_start_time_, imgseq_row, 1);
imgseq_row++;
imgseq_layout->addWidget(new QLabel(tr("End Index:")), imgseq_row, 0);
imgseq_end_time_ = new IntegerSlider();
imgseq_end_time_->SetMinimum(0);
imgseq_end_time_->SetValue(video_stream->start_time() + video_stream->duration());
imgseq_layout->addWidget(imgseq_end_time_, imgseq_row, 1);
video_layout->addWidget(imgseq_group, row, 0, 1, 2);
}
}
void VideoStreamProperties::Accept(QUndoCommand *parent)
{
QString set_colorspace;
if (video_color_space_->currentIndex() > 0) {
set_colorspace = video_color_space_->currentText();
}
if (video_premultiply_alpha_->isChecked() != stream_->premultiplied_alpha()
|| video_color_space_->currentText() != stream_->colorspace()) {
|| set_colorspace != stream_->colorspace(false)) {
new VideoStreamChangeCommand(stream_,
video_premultiply_alpha_->isChecked(),
video_color_space_->currentText(),
set_colorspace,
parent);
}
if (IsImageSequence(stream_.get())) {
VideoStreamPtr video_stream = std::static_pointer_cast<VideoStream>(stream_);
if (video_stream->start_time() != imgseq_start_time_->GetValue()) {
new ImageSequenceChangeCommand(video_stream,
imgseq_start_time_->GetValue(),
imgseq_end_time_->GetValue() - imgseq_start_time_->GetValue(),
parent);
}
}
}
bool VideoStreamProperties::SanityCheck()
{
if (IsImageSequence(stream_.get())) {
if (imgseq_start_time_->GetValue() >= imgseq_end_time_->GetValue()) {
QMessageBox::critical(this,
tr("Invalid Configuration"),
tr("Image sequence end index must be a value higher than the start index."),
QMessageBox::Ok);
return false;
}
}
return true;
}
bool VideoStreamProperties::IsImageSequence(ImageStream *stream)
{
return (stream->type() == Stream::kVideo && static_cast<VideoStream*>(stream)->is_image_sequence());
}
VideoStreamProperties::VideoStreamChangeCommand::VideoStreamChangeCommand(ImageStreamPtr stream,
@@ -81,7 +156,7 @@ VideoStreamProperties::VideoStreamChangeCommand::VideoStreamChangeCommand(ImageS
void VideoStreamProperties::VideoStreamChangeCommand::redo_internal()
{
old_premultiplied_ = stream_->premultiplied_alpha();
old_colorspace_ = stream_->colorspace();
old_colorspace_ = stream_->colorspace(false);
stream_->set_premultiplied_alpha(new_premultiplied_);
stream_->set_colorspace(new_colorspace_);
@@ -92,3 +167,26 @@ void VideoStreamProperties::VideoStreamChangeCommand::undo_internal()
stream_->set_premultiplied_alpha(old_premultiplied_);
stream_->set_colorspace(old_colorspace_);
}
VideoStreamProperties::ImageSequenceChangeCommand::ImageSequenceChangeCommand(VideoStreamPtr video_stream, int64_t start_index, int64_t duration, QUndoCommand *parent) :
UndoCommand(parent),
video_stream_(video_stream),
new_start_index_(start_index),
new_duration_(duration)
{
}
void VideoStreamProperties::ImageSequenceChangeCommand::redo_internal()
{
old_start_index_ = video_stream_->start_time();
video_stream_->set_start_time(new_start_index_);
old_duration_ = video_stream_->duration();
video_stream_->set_duration(new_duration_);
}
void VideoStreamProperties::ImageSequenceChangeCommand::undo_internal()
{
video_stream_->set_start_time(old_start_index_);
video_stream_->set_duration(old_duration_);
}
@@ -27,6 +27,7 @@
#include "project/item/footage/videostream.h"
#include "streamproperties.h"
#include "undo/undocommand.h"
#include "widget/slider/integerslider.h"
class VideoStreamProperties : public StreamProperties
{
@@ -35,7 +36,11 @@ public:
virtual void Accept(QUndoCommand* parent) override;
virtual bool SanityCheck() override;
private:
static bool IsImageSequence(ImageStream* stream);
/**
* @brief Attached video stream
*/
@@ -51,6 +56,16 @@ private:
*/
QComboBox* video_color_space_;
/**
* @brief Sets the start index for image sequences
*/
IntegerSlider* imgseq_start_time_;
/**
* @brief Sets the end index for image sequences
*/
IntegerSlider* imgseq_end_time_;
class VideoStreamChangeCommand : public UndoCommand {
public:
VideoStreamChangeCommand(ImageStreamPtr stream,
@@ -70,6 +85,29 @@ private:
bool old_premultiplied_;
QString old_colorspace_;
};
class ImageSequenceChangeCommand : public UndoCommand {
public:
ImageSequenceChangeCommand(VideoStreamPtr video_stream,
int64_t start_index,
int64_t duration,
QUndoCommand* parent = nullptr);
protected:
virtual void redo_internal() override;
virtual void undo_internal() override;
private:
VideoStreamPtr video_stream_;
int64_t new_start_index_;
int64_t old_start_index_;
int64_t new_duration_;
int64_t old_duration_;
};
};