ColorManager is now specific to the Project

OCIO config was set on a per-project basis, but we were using a singleton for
the ColorManager that would break if more than one project was ever open.
Now the ColorManager belongs to the Project and is always accessed through the
Project.
This commit is contained in:
itsmattkc
2019-12-17 15:18:07 +11:00
parent e1b8fd6352
commit a0b6bb842d
23 changed files with 187 additions and 245 deletions
+16 -3
View File
@@ -28,9 +28,12 @@ ImageStream::ImageStream() :
premultiplied_alpha_(false)
{
set_type(kImage);
}
void ImageStream::FootageSetEvent(Footage *f)
{
// For some reason this connection fails if we don't explicitly specify DirectConnection
connect(ColorManager::instance(), SIGNAL(ConfigChanged()), this, SLOT(ColorConfigChangedSlot()), Qt::DirectConnection);
connect(f->project()->color_manager(), SIGNAL(ConfigChanged()), this, SLOT(ColorConfigChanged()), Qt::DirectConnection);
}
QString ImageStream::description()
@@ -86,11 +89,13 @@ void ImageStream::set_colorspace(const QString &color)
emit ColorSpaceChanged();
}
void ImageStream::ColorConfigChangedSlot()
void ImageStream::ColorConfigChanged()
{
ColorManager* color_manager = static_cast<ColorManager*>(sender());
// Check if this colorspace is in the new config
if (!colorspace_.isEmpty()) {
QStringList colorspaces = ColorManager::ListAvailableInputColorspaces(OCIO::GetCurrentConfig());
QStringList colorspaces = color_manager->ListAvailableInputColorspaces();
if (!colorspaces.contains(colorspace_)) {
// Set to empty if not
colorspace_.clear();
@@ -100,3 +105,11 @@ void ImageStream::ColorConfigChangedSlot()
// Either way, the color calculation has likely changed so we signal here
emit ColorSpaceChanged();
}
void ImageStream::DefaultColorSpaceChanged()
{
// If no colorspace is set, this stream uses the default color space and it's just changed
if (colorspace_.isEmpty()) {
emit ColorSpaceChanged();
}
}
+6 -1
View File
@@ -49,6 +49,9 @@ public:
signals:
void ColorSpaceChanged();
protected:
virtual void FootageSetEvent(Footage*) override;
private:
int width_;
int height_;
@@ -56,7 +59,9 @@ private:
QString colorspace_;
private slots:
void ColorConfigChangedSlot();
void ColorConfigChanged();
void DefaultColorSpaceChanged();
};
using ImageStreamPtr = std::shared_ptr<ImageStream>;
+1
View File
@@ -58,6 +58,7 @@ Footage *Stream::footage() const
void Stream::set_footage(Footage *f)
{
footage_ = f;
FootageSetEvent(footage_);
}
const rational &Stream::timebase() const
+3
View File
@@ -97,6 +97,9 @@ public:
StreamID ToID() const;
protected:
virtual void FootageSetEvent(Footage*){}
private:
Footage* footage_;
+5
View File
@@ -60,3 +60,8 @@ void Project::set_default_input_colorspace(const QString &colorspace)
{
default_input_colorspace_ = colorspace;
}
ColorManager *Project::color_manager()
{
return &color_manager_;
}
+6
View File
@@ -24,6 +24,7 @@
#include <QObject>
#include <memory>
#include "render/colormanager.h"
#include "project/item/folder/folder.h"
/**
@@ -54,6 +55,8 @@ public:
const QString& default_input_colorspace();
void set_default_input_colorspace(const QString& colorspace);
ColorManager* color_manager();
private:
Folder root_;
@@ -61,6 +64,9 @@ private:
QString ocio_config_;
QString default_input_colorspace_;
ColorManager color_manager_;
};
using ProjectPtr = std::shared_ptr<Project>;