change: change code style to Linux style except indent.
This commit is contained in:
@@ -27,396 +27,411 @@
|
||||
#include "render/opengl/openglrenderer.h"
|
||||
#include "render/rendermanager.h"
|
||||
|
||||
namespace olive {
|
||||
namespace olive
|
||||
{
|
||||
|
||||
#define super QWidget
|
||||
|
||||
ManagedDisplayWidget::ManagedDisplayWidget(QWidget *parent) :
|
||||
QWidget(parent),
|
||||
color_manager_(nullptr),
|
||||
color_service_(nullptr)
|
||||
ManagedDisplayWidget::ManagedDisplayWidget(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, color_manager_(nullptr)
|
||||
, color_service_(nullptr)
|
||||
{
|
||||
QHBoxLayout* layout = new QHBoxLayout(this);
|
||||
layout->setSpacing(0);
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
QHBoxLayout *layout = new QHBoxLayout(this);
|
||||
layout->setSpacing(0);
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
|
||||
if (RenderManager::instance()->backend() == RenderManager::kOpenGL) {
|
||||
// Create OpenGL widget
|
||||
inner_widget_ = new ManagedDisplayWidgetOpenGL();
|
||||
inner_widget_->setAttribute(Qt::WA_TranslucentBackground, false);
|
||||
connect(static_cast<ManagedDisplayWidgetOpenGL*>(inner_widget_),
|
||||
&ManagedDisplayWidgetOpenGL::OnInit,
|
||||
this, &ManagedDisplayWidget::OnInit, Qt::DirectConnection);
|
||||
connect(static_cast<ManagedDisplayWidgetOpenGL*>(inner_widget_),
|
||||
&ManagedDisplayWidgetOpenGL::OnDestroy,
|
||||
this, &ManagedDisplayWidget::OnDestroy, Qt::DirectConnection);
|
||||
connect(static_cast<ManagedDisplayWidgetOpenGL*>(inner_widget_),
|
||||
&ManagedDisplayWidgetOpenGL::OnPaint,
|
||||
this, &ManagedDisplayWidget::OnPaint, Qt::DirectConnection);
|
||||
connect(static_cast<ManagedDisplayWidgetOpenGL*>(inner_widget_),
|
||||
&ManagedDisplayWidgetOpenGL::frameSwapped,
|
||||
this, &ManagedDisplayWidget::frameSwapped, Qt::DirectConnection);
|
||||
if (RenderManager::instance()->backend() == RenderManager::kOpenGL) {
|
||||
// Create OpenGL widget
|
||||
inner_widget_ = new ManagedDisplayWidgetOpenGL();
|
||||
inner_widget_->setAttribute(Qt::WA_TranslucentBackground, false);
|
||||
connect(static_cast<ManagedDisplayWidgetOpenGL *>(inner_widget_),
|
||||
&ManagedDisplayWidgetOpenGL::OnInit, this,
|
||||
&ManagedDisplayWidget::OnInit, Qt::DirectConnection);
|
||||
connect(static_cast<ManagedDisplayWidgetOpenGL *>(inner_widget_),
|
||||
&ManagedDisplayWidgetOpenGL::OnDestroy, this,
|
||||
&ManagedDisplayWidget::OnDestroy, Qt::DirectConnection);
|
||||
connect(static_cast<ManagedDisplayWidgetOpenGL *>(inner_widget_),
|
||||
&ManagedDisplayWidgetOpenGL::OnPaint, this,
|
||||
&ManagedDisplayWidget::OnPaint, Qt::DirectConnection);
|
||||
connect(static_cast<ManagedDisplayWidgetOpenGL *>(inner_widget_),
|
||||
&ManagedDisplayWidgetOpenGL::frameSwapped, this,
|
||||
&ManagedDisplayWidget::frameSwapped, Qt::DirectConnection);
|
||||
|
||||
inner_widget_->installEventFilter(this);
|
||||
inner_widget_->installEventFilter(this);
|
||||
|
||||
// Create OpenGL renderer
|
||||
attached_renderer_ = new OpenGLRenderer(this);
|
||||
// Create OpenGL renderer
|
||||
attached_renderer_ = new OpenGLRenderer(this);
|
||||
|
||||
// Create widget wrapper for OpenGL window
|
||||
// Create widget wrapper for OpenGL window
|
||||
#ifdef USE_QOPENGLWINDOW
|
||||
wrapper_ = QWidget::createWindowContainer(static_cast<ManagedDisplayWidgetOpenGL*>(inner_widget_));
|
||||
wrapper_ = QWidget::createWindowContainer(
|
||||
static_cast<ManagedDisplayWidgetOpenGL *>(inner_widget_));
|
||||
#else
|
||||
wrapper_ = inner_widget_;
|
||||
wrapper_ = inner_widget_;
|
||||
#endif
|
||||
layout->addWidget(wrapper_);
|
||||
} else {
|
||||
inner_widget_ = nullptr;
|
||||
wrapper_ = nullptr;
|
||||
}
|
||||
layout->addWidget(wrapper_);
|
||||
} else {
|
||||
inner_widget_ = nullptr;
|
||||
wrapper_ = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
ManagedDisplayWidget::~ManagedDisplayWidget()
|
||||
{
|
||||
MANAGEDDISPLAYWIDGET_DEFAULT_DESTRUCTOR_INNER;
|
||||
MANAGEDDISPLAYWIDGET_DEFAULT_DESTRUCTOR_INNER;
|
||||
|
||||
if (RenderManager::instance()->backend() == RenderManager::kOpenGL) {
|
||||
disconnect(static_cast<ManagedDisplayWidgetOpenGL*>(inner_widget_),
|
||||
&ManagedDisplayWidgetOpenGL::OnDestroy,
|
||||
this, &ManagedDisplayWidget::OnDestroy);
|
||||
}
|
||||
if (RenderManager::instance()->backend() == RenderManager::kOpenGL) {
|
||||
disconnect(static_cast<ManagedDisplayWidgetOpenGL *>(inner_widget_),
|
||||
&ManagedDisplayWidgetOpenGL::OnDestroy, this,
|
||||
&ManagedDisplayWidget::OnDestroy);
|
||||
}
|
||||
}
|
||||
|
||||
void ManagedDisplayWidget::ConnectColorManager(ColorManager *color_manager)
|
||||
{
|
||||
if (color_manager_ == color_manager) {
|
||||
return;
|
||||
}
|
||||
if (color_manager_ == color_manager) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (color_manager_ != nullptr) {
|
||||
disconnect(color_manager_, &ColorManager::ConfigChanged, this, &ManagedDisplayWidget::ColorConfigChanged);
|
||||
disconnect(color_manager_, &ColorManager::ReferenceSpaceChanged, this, &ManagedDisplayWidget::ColorConfigChanged);
|
||||
}
|
||||
if (color_manager_ != nullptr) {
|
||||
disconnect(color_manager_, &ColorManager::ConfigChanged, this,
|
||||
&ManagedDisplayWidget::ColorConfigChanged);
|
||||
disconnect(color_manager_, &ColorManager::ReferenceSpaceChanged, this,
|
||||
&ManagedDisplayWidget::ColorConfigChanged);
|
||||
}
|
||||
|
||||
color_manager_ = color_manager;
|
||||
color_manager_ = color_manager;
|
||||
|
||||
if (color_manager_ != nullptr) {
|
||||
connect(color_manager_, &ColorManager::ConfigChanged, this, &ManagedDisplayWidget::ColorConfigChanged);
|
||||
connect(color_manager_, &ColorManager::ReferenceSpaceChanged, this, &ManagedDisplayWidget::ColorConfigChanged);
|
||||
}
|
||||
if (color_manager_ != nullptr) {
|
||||
connect(color_manager_, &ColorManager::ConfigChanged, this,
|
||||
&ManagedDisplayWidget::ColorConfigChanged);
|
||||
connect(color_manager_, &ColorManager::ReferenceSpaceChanged, this,
|
||||
&ManagedDisplayWidget::ColorConfigChanged);
|
||||
}
|
||||
|
||||
ColorConfigChanged();
|
||||
emit ColorManagerChanged(color_manager_);
|
||||
ColorConfigChanged();
|
||||
emit ColorManagerChanged(color_manager_);
|
||||
}
|
||||
|
||||
ColorManager *ManagedDisplayWidget::color_manager() const
|
||||
{
|
||||
return color_manager_;
|
||||
return color_manager_;
|
||||
}
|
||||
|
||||
void ManagedDisplayWidget::DisconnectColorManager()
|
||||
{
|
||||
ConnectColorManager(nullptr);
|
||||
ConnectColorManager(nullptr);
|
||||
}
|
||||
|
||||
const ColorTransform &ManagedDisplayWidget::GetColorTransform() const
|
||||
{
|
||||
return color_transform_;
|
||||
return color_transform_;
|
||||
}
|
||||
|
||||
Menu *ManagedDisplayWidget::GetColorSpaceMenu(QMenu *parent, bool auto_connect)
|
||||
{
|
||||
QStringList colorspaces = color_manager()->ListAvailableColorspaces();
|
||||
QStringList colorspaces = color_manager()->ListAvailableColorspaces();
|
||||
|
||||
Menu* ocio_colorspace_menu = new Menu(tr("Color Space"), parent);
|
||||
Menu *ocio_colorspace_menu = new Menu(tr("Color Space"), parent);
|
||||
|
||||
if (auto_connect) {
|
||||
connect(ocio_colorspace_menu, &Menu::triggered, this, &ManagedDisplayWidget::MenuColorspaceSelect);
|
||||
}
|
||||
if (auto_connect) {
|
||||
connect(ocio_colorspace_menu, &Menu::triggered, this,
|
||||
&ManagedDisplayWidget::MenuColorspaceSelect);
|
||||
}
|
||||
|
||||
foreach (const QString& c, colorspaces) {
|
||||
QAction* action = ocio_colorspace_menu->addAction(c);
|
||||
action->setCheckable(true);
|
||||
action->setChecked(color_transform_.output() == c);
|
||||
action->setData(c);
|
||||
}
|
||||
foreach (const QString &c, colorspaces) {
|
||||
QAction *action = ocio_colorspace_menu->addAction(c);
|
||||
action->setCheckable(true);
|
||||
action->setChecked(color_transform_.output() == c);
|
||||
action->setData(c);
|
||||
}
|
||||
|
||||
return ocio_colorspace_menu;
|
||||
return ocio_colorspace_menu;
|
||||
}
|
||||
|
||||
void ManagedDisplayWidget::ColorConfigChanged()
|
||||
{
|
||||
if (!color_manager_) {
|
||||
color_service_ = nullptr;
|
||||
return;
|
||||
}
|
||||
if (!color_manager_) {
|
||||
color_service_ = nullptr;
|
||||
return;
|
||||
}
|
||||
|
||||
SetColorTransform(color_manager_->GetCompliantColorSpace(color_transform_, false));
|
||||
SetColorTransform(
|
||||
color_manager_->GetCompliantColorSpace(color_transform_, false));
|
||||
}
|
||||
|
||||
ColorProcessorPtr ManagedDisplayWidget::color_service()
|
||||
{
|
||||
return color_service_;
|
||||
return color_service_;
|
||||
}
|
||||
|
||||
void ManagedDisplayWidget::ShowDefaultContextMenu()
|
||||
{
|
||||
Menu m(this);
|
||||
Menu m(this);
|
||||
|
||||
if (color_manager_) {
|
||||
m.addMenu(GetColorSpaceMenu(&m));
|
||||
m.addSeparator();
|
||||
m.addMenu(GetDisplayMenu(&m));
|
||||
m.addMenu(GetViewMenu(&m));
|
||||
m.addMenu(GetLookMenu(&m));
|
||||
} else {
|
||||
QAction* a = m.addAction(tr("No color manager connected"));
|
||||
a->setEnabled(false);
|
||||
}
|
||||
if (color_manager_) {
|
||||
m.addMenu(GetColorSpaceMenu(&m));
|
||||
m.addSeparator();
|
||||
m.addMenu(GetDisplayMenu(&m));
|
||||
m.addMenu(GetViewMenu(&m));
|
||||
m.addMenu(GetLookMenu(&m));
|
||||
} else {
|
||||
QAction *a = m.addAction(tr("No color manager connected"));
|
||||
a->setEnabled(false);
|
||||
}
|
||||
|
||||
m.exec(QCursor::pos());
|
||||
m.exec(QCursor::pos());
|
||||
}
|
||||
|
||||
void ManagedDisplayWidget::MenuDisplaySelect(QAction *action)
|
||||
{
|
||||
const ColorTransform& old_transform = GetColorTransform();
|
||||
const ColorTransform &old_transform = GetColorTransform();
|
||||
|
||||
ColorTransform new_transform = color_manager()->GetCompliantColorSpace(ColorTransform(action->data().toString(),
|
||||
old_transform.view(),
|
||||
old_transform.look()));
|
||||
ColorTransform new_transform = color_manager()->GetCompliantColorSpace(
|
||||
ColorTransform(action->data().toString(), old_transform.view(),
|
||||
old_transform.look()));
|
||||
|
||||
SetColorTransform(new_transform);
|
||||
SetColorTransform(new_transform);
|
||||
}
|
||||
|
||||
void ManagedDisplayWidget::MenuViewSelect(QAction *action)
|
||||
{
|
||||
const ColorTransform& old_transform = GetColorTransform();
|
||||
const ColorTransform &old_transform = GetColorTransform();
|
||||
|
||||
ColorTransform new_transform = color_manager()->GetCompliantColorSpace(ColorTransform(old_transform.display(),
|
||||
action->data().toString(),
|
||||
old_transform.look()));
|
||||
ColorTransform new_transform = color_manager()->GetCompliantColorSpace(
|
||||
ColorTransform(old_transform.display(), action->data().toString(),
|
||||
old_transform.look()));
|
||||
|
||||
SetColorTransform(new_transform);
|
||||
SetColorTransform(new_transform);
|
||||
}
|
||||
|
||||
void ManagedDisplayWidget::MenuLookSelect(QAction *action)
|
||||
{
|
||||
const ColorTransform& old_transform = GetColorTransform();
|
||||
const ColorTransform &old_transform = GetColorTransform();
|
||||
|
||||
ColorTransform new_transform = color_manager()->GetCompliantColorSpace(ColorTransform(old_transform.display(),
|
||||
old_transform.view(),
|
||||
action->data().toString()));
|
||||
ColorTransform new_transform = color_manager()->GetCompliantColorSpace(
|
||||
ColorTransform(old_transform.display(), old_transform.view(),
|
||||
action->data().toString()));
|
||||
|
||||
SetColorTransform(new_transform);
|
||||
SetColorTransform(new_transform);
|
||||
}
|
||||
|
||||
void ManagedDisplayWidget::MenuColorspaceSelect(QAction *action)
|
||||
{
|
||||
SetColorTransform(color_manager()->GetCompliantColorSpace(ColorTransform(action->data().toString())));
|
||||
SetColorTransform(color_manager()->GetCompliantColorSpace(
|
||||
ColorTransform(action->data().toString())));
|
||||
}
|
||||
|
||||
void ManagedDisplayWidget::OnDestroy()
|
||||
{
|
||||
attached_renderer_->Destroy();
|
||||
attached_renderer_->PostDestroy();
|
||||
attached_renderer_->Destroy();
|
||||
attached_renderer_->PostDestroy();
|
||||
}
|
||||
|
||||
void ManagedDisplayWidget::SetColorTransform(const ColorTransform &transform)
|
||||
{
|
||||
color_transform_ = transform;
|
||||
color_transform_ = transform;
|
||||
|
||||
SetupColorProcessor();
|
||||
SetupColorProcessor();
|
||||
|
||||
ColorProcessorChangedEvent();
|
||||
ColorProcessorChangedEvent();
|
||||
}
|
||||
|
||||
void ManagedDisplayWidget::OnInit()
|
||||
{
|
||||
if (RenderManager::instance()->backend() == RenderManager::kOpenGL) {
|
||||
QOpenGLContext* context = static_cast<ManagedDisplayWidgetOpenGL*>(inner_widget_)->context();
|
||||
static_cast<OpenGLRenderer*>(attached_renderer_)->Init(context);
|
||||
static_cast<OpenGLRenderer*>(attached_renderer_)->PostInit();
|
||||
}
|
||||
if (RenderManager::instance()->backend() == RenderManager::kOpenGL) {
|
||||
QOpenGLContext *context =
|
||||
static_cast<ManagedDisplayWidgetOpenGL *>(inner_widget_)->context();
|
||||
static_cast<OpenGLRenderer *>(attached_renderer_)->Init(context);
|
||||
static_cast<OpenGLRenderer *>(attached_renderer_)->PostInit();
|
||||
}
|
||||
}
|
||||
|
||||
void ManagedDisplayWidget::EnableDefaultContextMenu()
|
||||
{
|
||||
connect(this, &ManagedDisplayWidget::customContextMenuRequested, this, &ManagedDisplayWidget::ShowDefaultContextMenu);
|
||||
connect(this, &ManagedDisplayWidget::customContextMenuRequested, this,
|
||||
&ManagedDisplayWidget::ShowDefaultContextMenu);
|
||||
}
|
||||
|
||||
void ManagedDisplayWidget::ColorProcessorChangedEvent()
|
||||
{
|
||||
update();
|
||||
update();
|
||||
}
|
||||
|
||||
void ManagedDisplayWidget::makeCurrent()
|
||||
{
|
||||
if (RenderManager::instance()->backend() == RenderManager::kOpenGL) {
|
||||
static_cast<ManagedDisplayWidgetOpenGL*>(inner_widget_)->makeCurrent();
|
||||
}
|
||||
if (RenderManager::instance()->backend() == RenderManager::kOpenGL) {
|
||||
static_cast<ManagedDisplayWidgetOpenGL *>(inner_widget_)->makeCurrent();
|
||||
}
|
||||
}
|
||||
|
||||
void ManagedDisplayWidget::doneCurrent()
|
||||
{
|
||||
if (RenderManager::instance()->backend() == RenderManager::kOpenGL) {
|
||||
static_cast<ManagedDisplayWidgetOpenGL*>(inner_widget_)->doneCurrent();
|
||||
}
|
||||
if (RenderManager::instance()->backend() == RenderManager::kOpenGL) {
|
||||
static_cast<ManagedDisplayWidgetOpenGL *>(inner_widget_)->doneCurrent();
|
||||
}
|
||||
}
|
||||
|
||||
QPaintDevice *ManagedDisplayWidget::paint_device() const
|
||||
{
|
||||
if (RenderManager::instance()->backend() == RenderManager::kOpenGL) {
|
||||
return static_cast<ManagedDisplayWidgetOpenGL*>(inner_widget_);
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
if (RenderManager::instance()->backend() == RenderManager::kOpenGL) {
|
||||
return static_cast<ManagedDisplayWidgetOpenGL *>(inner_widget_);
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void ManagedDisplayWidget::SetInnerMouseTracking(bool e)
|
||||
{
|
||||
if (wrapper_) {
|
||||
wrapper_->setMouseTracking(e);
|
||||
}
|
||||
if (wrapper_) {
|
||||
wrapper_->setMouseTracking(e);
|
||||
}
|
||||
}
|
||||
|
||||
VideoParams ManagedDisplayWidget::GetViewportParams() const
|
||||
{
|
||||
int device_width = width() * devicePixelRatioF();
|
||||
int device_height = height() * devicePixelRatioF();
|
||||
PixelFormat device_format = static_cast<PixelFormat::Format>(OLIVE_CONFIG("OfflinePixelFormat").toInt());
|
||||
return VideoParams(device_width, device_height, device_format, VideoParams::kInternalChannelCount);
|
||||
int device_width = width() * devicePixelRatioF();
|
||||
int device_height = height() * devicePixelRatioF();
|
||||
PixelFormat device_format = static_cast<PixelFormat::Format>(
|
||||
OLIVE_CONFIG("OfflinePixelFormat").toInt());
|
||||
return VideoParams(device_width, device_height, device_format,
|
||||
VideoParams::kInternalChannelCount);
|
||||
}
|
||||
|
||||
void ManagedDisplayWidget::update()
|
||||
{
|
||||
if (RenderManager::instance()->backend() == RenderManager::kOpenGL) {
|
||||
static_cast<ManagedDisplayWidgetOpenGL*>(inner_widget_)->update();
|
||||
}
|
||||
if (RenderManager::instance()->backend() == RenderManager::kOpenGL) {
|
||||
static_cast<ManagedDisplayWidgetOpenGL *>(inner_widget_)->update();
|
||||
}
|
||||
}
|
||||
|
||||
bool ManagedDisplayWidget::eventFilter(QObject *o, QEvent *e)
|
||||
{
|
||||
if (o != inner_widget_) {
|
||||
return super::eventFilter(o, e);
|
||||
}
|
||||
if (o != inner_widget_) {
|
||||
return super::eventFilter(o, e);
|
||||
}
|
||||
|
||||
switch (e->type()) {
|
||||
case QEvent::FocusIn:
|
||||
// HACK: QWindow focus isn't accounted for in QApplication::focusChanged, so we handle it
|
||||
// manually here.
|
||||
PanelManager::instance()->FocusChanged(nullptr, this);
|
||||
break;
|
||||
case QEvent::ContextMenu:
|
||||
{
|
||||
QContextMenuEvent *ctx = static_cast<QContextMenuEvent*>(e);
|
||||
emit customContextMenuRequested(ctx->pos());
|
||||
return true;
|
||||
}
|
||||
case QEvent::MouseButtonPress:
|
||||
{
|
||||
// HACK: QWindows don't seem to receive ContextMenu events on right click (only when pressing
|
||||
// the menu button on the keyboard) so we handle it manually here
|
||||
/*QMouseEvent *ev = static_cast<QMouseEvent*>(e);
|
||||
switch (e->type()) {
|
||||
case QEvent::FocusIn:
|
||||
// HACK: QWindow focus isn't accounted for in QApplication::focusChanged, so we handle it
|
||||
// manually here.
|
||||
PanelManager::instance()->FocusChanged(nullptr, this);
|
||||
break;
|
||||
case QEvent::ContextMenu: {
|
||||
QContextMenuEvent *ctx = static_cast<QContextMenuEvent *>(e);
|
||||
emit customContextMenuRequested(ctx->pos());
|
||||
return true;
|
||||
}
|
||||
case QEvent::MouseButtonPress: {
|
||||
// HACK: QWindows don't seem to receive ContextMenu events on right click (only when pressing
|
||||
// the menu button on the keyboard) so we handle it manually here
|
||||
/*QMouseEvent *ev = static_cast<QMouseEvent*>(e);
|
||||
if (ev->button() == Qt::RightButton) {
|
||||
emit customContextMenuRequested(ev->pos());
|
||||
return true;
|
||||
}*/
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return super::eventFilter(o, e);
|
||||
return super::eventFilter(o, e);
|
||||
}
|
||||
|
||||
Menu* ManagedDisplayWidget::GetDisplayMenu(QMenu* parent, bool auto_connect)
|
||||
Menu *ManagedDisplayWidget::GetDisplayMenu(QMenu *parent, bool auto_connect)
|
||||
{
|
||||
QStringList displays = color_manager()->ListAvailableDisplays();
|
||||
QStringList displays = color_manager()->ListAvailableDisplays();
|
||||
|
||||
Menu* ocio_display_menu = new Menu(tr("Display"), parent);
|
||||
Menu *ocio_display_menu = new Menu(tr("Display"), parent);
|
||||
|
||||
if (auto_connect) {
|
||||
connect(ocio_display_menu, &Menu::triggered, this, &ManagedDisplayWidget::MenuDisplaySelect);
|
||||
}
|
||||
if (auto_connect) {
|
||||
connect(ocio_display_menu, &Menu::triggered, this,
|
||||
&ManagedDisplayWidget::MenuDisplaySelect);
|
||||
}
|
||||
|
||||
foreach (const QString& d, displays) {
|
||||
QAction* action = ocio_display_menu->addAction(d);
|
||||
action->setCheckable(true);
|
||||
action->setChecked(color_transform_.display() == d);
|
||||
action->setData(d);
|
||||
}
|
||||
foreach (const QString &d, displays) {
|
||||
QAction *action = ocio_display_menu->addAction(d);
|
||||
action->setCheckable(true);
|
||||
action->setChecked(color_transform_.display() == d);
|
||||
action->setData(d);
|
||||
}
|
||||
|
||||
return ocio_display_menu;
|
||||
return ocio_display_menu;
|
||||
}
|
||||
|
||||
Menu* ManagedDisplayWidget::GetViewMenu(QMenu* parent, bool auto_connect)
|
||||
Menu *ManagedDisplayWidget::GetViewMenu(QMenu *parent, bool auto_connect)
|
||||
{
|
||||
QStringList views = color_manager()->ListAvailableViews(color_transform_.display());
|
||||
QStringList views =
|
||||
color_manager()->ListAvailableViews(color_transform_.display());
|
||||
|
||||
Menu* ocio_view_menu = new Menu(tr("View"), parent);
|
||||
Menu *ocio_view_menu = new Menu(tr("View"), parent);
|
||||
|
||||
if (auto_connect) {
|
||||
connect(ocio_view_menu, &Menu::triggered, this, &ManagedDisplayWidget::MenuViewSelect);
|
||||
}
|
||||
if (auto_connect) {
|
||||
connect(ocio_view_menu, &Menu::triggered, this,
|
||||
&ManagedDisplayWidget::MenuViewSelect);
|
||||
}
|
||||
|
||||
foreach (const QString& v, views) {
|
||||
QAction* action = ocio_view_menu->addAction(v);
|
||||
action->setCheckable(true);
|
||||
action->setChecked(color_transform_.view() == v);
|
||||
action->setData(v);
|
||||
}
|
||||
foreach (const QString &v, views) {
|
||||
QAction *action = ocio_view_menu->addAction(v);
|
||||
action->setCheckable(true);
|
||||
action->setChecked(color_transform_.view() == v);
|
||||
action->setData(v);
|
||||
}
|
||||
|
||||
return ocio_view_menu;
|
||||
return ocio_view_menu;
|
||||
}
|
||||
|
||||
Menu* ManagedDisplayWidget::GetLookMenu(QMenu* parent, bool auto_connect)
|
||||
Menu *ManagedDisplayWidget::GetLookMenu(QMenu *parent, bool auto_connect)
|
||||
{
|
||||
QStringList looks = color_manager()->ListAvailableLooks();
|
||||
QStringList looks = color_manager()->ListAvailableLooks();
|
||||
|
||||
Menu* ocio_look_menu = new Menu(tr("Look"), parent);
|
||||
Menu *ocio_look_menu = new Menu(tr("Look"), parent);
|
||||
|
||||
if (auto_connect) {
|
||||
connect(ocio_look_menu, &Menu::triggered, this, &ManagedDisplayWidget::MenuLookSelect);
|
||||
}
|
||||
if (auto_connect) {
|
||||
connect(ocio_look_menu, &Menu::triggered, this,
|
||||
&ManagedDisplayWidget::MenuLookSelect);
|
||||
}
|
||||
|
||||
// Setup "no look" action
|
||||
QAction* no_look_action = ocio_look_menu->addAction(tr("(None)"));
|
||||
no_look_action->setCheckable(true);
|
||||
no_look_action->setChecked(color_transform_.look().isEmpty());
|
||||
no_look_action->setData(QString());
|
||||
// Setup "no look" action
|
||||
QAction *no_look_action = ocio_look_menu->addAction(tr("(None)"));
|
||||
no_look_action->setCheckable(true);
|
||||
no_look_action->setChecked(color_transform_.look().isEmpty());
|
||||
no_look_action->setData(QString());
|
||||
|
||||
// Set up the rest of the looks
|
||||
foreach (const QString& l, looks) {
|
||||
QAction* action = ocio_look_menu->addAction(l);
|
||||
action->setCheckable(true);
|
||||
action->setChecked(color_transform_.look() == l);
|
||||
action->setData(l);
|
||||
}
|
||||
// Set up the rest of the looks
|
||||
foreach (const QString &l, looks) {
|
||||
QAction *action = ocio_look_menu->addAction(l);
|
||||
action->setCheckable(true);
|
||||
action->setChecked(color_transform_.look() == l);
|
||||
action->setData(l);
|
||||
}
|
||||
|
||||
return ocio_look_menu;
|
||||
return ocio_look_menu;
|
||||
}
|
||||
|
||||
void ManagedDisplayWidget::SetupColorProcessor()
|
||||
{
|
||||
color_service_ = nullptr;
|
||||
color_service_ = nullptr;
|
||||
|
||||
if (color_manager_) {
|
||||
// (Re)create color processor
|
||||
try {
|
||||
color_service_ = ColorProcessor::Create(color_manager_,
|
||||
color_manager_->GetReferenceColorSpace(),
|
||||
color_transform_);
|
||||
} catch (OCIO::Exception& e) {
|
||||
QMessageBox::critical(this,
|
||||
tr("OpenColorIO Error"),
|
||||
tr("Failed to set color configuration: %1").arg(e.what()),
|
||||
QMessageBox::Ok);
|
||||
}
|
||||
} else {
|
||||
color_service_ = nullptr;
|
||||
}
|
||||
if (color_manager_) {
|
||||
// (Re)create color processor
|
||||
try {
|
||||
color_service_ = ColorProcessor::Create(
|
||||
color_manager_, color_manager_->GetReferenceColorSpace(),
|
||||
color_transform_);
|
||||
} catch (OCIO::Exception &e) {
|
||||
QMessageBox::critical(
|
||||
this, tr("OpenColorIO Error"),
|
||||
tr("Failed to set color configuration: %1").arg(e.what()),
|
||||
QMessageBox::Ok);
|
||||
}
|
||||
} else {
|
||||
color_service_ = nullptr;
|
||||
}
|
||||
|
||||
emit ColorProcessorChanged(color_service_);
|
||||
emit ColorProcessorChanged(color_service_);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -35,282 +35,285 @@
|
||||
#include "render/renderer.h"
|
||||
#include "widget/menu/menu.h"
|
||||
|
||||
namespace olive {
|
||||
namespace olive
|
||||
{
|
||||
|
||||
class ManagedDisplayWidgetOpenGL
|
||||
#ifdef USE_QOPENGLWINDOW
|
||||
: public QOpenGLWindow
|
||||
: public QOpenGLWindow
|
||||
#else
|
||||
: public QOpenGLWidget
|
||||
: public QOpenGLWidget
|
||||
#endif
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
public:
|
||||
ManagedDisplayWidgetOpenGL() = default;
|
||||
ManagedDisplayWidgetOpenGL() = default;
|
||||
|
||||
virtual ~ManagedDisplayWidgetOpenGL() override
|
||||
{
|
||||
if (context()) {
|
||||
DestroyListener();
|
||||
disconnect(context(), &QOpenGLContext::aboutToBeDestroyed,
|
||||
this, &ManagedDisplayWidgetOpenGL::DestroyListener);
|
||||
}
|
||||
}
|
||||
virtual ~ManagedDisplayWidgetOpenGL() override
|
||||
{
|
||||
if (context()) {
|
||||
DestroyListener();
|
||||
disconnect(context(), &QOpenGLContext::aboutToBeDestroyed, this,
|
||||
&ManagedDisplayWidgetOpenGL::DestroyListener);
|
||||
}
|
||||
}
|
||||
|
||||
signals:
|
||||
// Render signals
|
||||
void OnInit();
|
||||
void OnPaint();
|
||||
void OnDestroy();
|
||||
// Render signals
|
||||
void OnInit();
|
||||
void OnPaint();
|
||||
void OnDestroy();
|
||||
|
||||
protected:
|
||||
virtual void initializeGL() override
|
||||
{
|
||||
connect(context(), &QOpenGLContext::aboutToBeDestroyed,
|
||||
this, &ManagedDisplayWidgetOpenGL::DestroyListener,
|
||||
Qt::DirectConnection);
|
||||
virtual void initializeGL() override
|
||||
{
|
||||
connect(context(), &QOpenGLContext::aboutToBeDestroyed, this,
|
||||
&ManagedDisplayWidgetOpenGL::DestroyListener,
|
||||
Qt::DirectConnection);
|
||||
|
||||
emit OnInit();
|
||||
}
|
||||
emit OnInit();
|
||||
}
|
||||
|
||||
virtual void paintGL() override
|
||||
{
|
||||
emit OnPaint();
|
||||
}
|
||||
virtual void paintGL() override
|
||||
{
|
||||
emit OnPaint();
|
||||
}
|
||||
|
||||
private slots:
|
||||
void DestroyListener()
|
||||
{
|
||||
makeCurrent();
|
||||
void DestroyListener()
|
||||
{
|
||||
makeCurrent();
|
||||
|
||||
emit OnDestroy();
|
||||
|
||||
doneCurrent();
|
||||
}
|
||||
emit OnDestroy();
|
||||
|
||||
doneCurrent();
|
||||
}
|
||||
};
|
||||
|
||||
#define MANAGEDDISPLAYWIDGET_DEFAULT_DESTRUCTOR_INNER \
|
||||
makeCurrent();OnDestroy();doneCurrent()
|
||||
#define MANAGEDDISPLAYWIDGET_DEFAULT_DESTRUCTOR(x) \
|
||||
virtual ~x() override{MANAGEDDISPLAYWIDGET_DEFAULT_DESTRUCTOR_INNER;}
|
||||
makeCurrent(); \
|
||||
OnDestroy(); \
|
||||
doneCurrent()
|
||||
#define MANAGEDDISPLAYWIDGET_DEFAULT_DESTRUCTOR(x) \
|
||||
virtual ~x() override \
|
||||
{ \
|
||||
MANAGEDDISPLAYWIDGET_DEFAULT_DESTRUCTOR_INNER; \
|
||||
}
|
||||
|
||||
class ManagedDisplayWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
class ManagedDisplayWidget : public QWidget {
|
||||
Q_OBJECT
|
||||
public:
|
||||
ManagedDisplayWidget(QWidget* parent = nullptr);
|
||||
ManagedDisplayWidget(QWidget *parent = nullptr);
|
||||
|
||||
virtual ~ManagedDisplayWidget() override;
|
||||
virtual ~ManagedDisplayWidget() override;
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief Disconnect a ColorManager (equivalent to ConnectColorManager(nullptr))
|
||||
*/
|
||||
void DisconnectColorManager();
|
||||
void DisconnectColorManager();
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief Access currently connected ColorManager (nullptr if none)
|
||||
*/
|
||||
ColorManager* color_manager() const;
|
||||
ColorManager *color_manager() const;
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief Get current color transform
|
||||
*/
|
||||
const ColorTransform& GetColorTransform() const;
|
||||
const ColorTransform &GetColorTransform() const;
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief Get menu that can be used to select the colorspace
|
||||
*/
|
||||
Menu* GetColorSpaceMenu(QMenu* parent, bool auto_connect = true);
|
||||
Menu *GetColorSpaceMenu(QMenu *parent, bool auto_connect = true);
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief Get menu that can be used to select the display transform
|
||||
*/
|
||||
Menu* GetDisplayMenu(QMenu* parent, bool auto_connect = true);
|
||||
Menu *GetDisplayMenu(QMenu *parent, bool auto_connect = true);
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief Get menu that can be used to select the view transform
|
||||
*/
|
||||
Menu* GetViewMenu(QMenu* parent, bool auto_connect = true);
|
||||
Menu *GetViewMenu(QMenu *parent, bool auto_connect = true);
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief Get menu that can be used to select the look transform
|
||||
*/
|
||||
Menu* GetLookMenu(QMenu* parent, bool auto_connect = true);
|
||||
Menu *GetLookMenu(QMenu *parent, bool auto_connect = true);
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief Passes update signal through to inner widget
|
||||
*/
|
||||
void update();
|
||||
void update();
|
||||
|
||||
virtual bool eventFilter(QObject *o, QEvent *e) override;
|
||||
virtual bool eventFilter(QObject *o, QEvent *e) override;
|
||||
|
||||
public slots:
|
||||
/**
|
||||
/**
|
||||
* @brief Replaces the color transform with a new one
|
||||
*/
|
||||
void SetColorTransform(const ColorTransform& transform);
|
||||
void SetColorTransform(const ColorTransform &transform);
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief Connect a ColorManager (ColorManagers usually belong to the Project)
|
||||
*/
|
||||
void ConnectColorManager(ColorManager* color_manager);
|
||||
void ConnectColorManager(ColorManager *color_manager);
|
||||
|
||||
signals:
|
||||
/**
|
||||
/**
|
||||
* @brief Emitted when the color processor changes
|
||||
*/
|
||||
void ColorProcessorChanged(ColorProcessorPtr processor);
|
||||
void ColorProcessorChanged(ColorProcessorPtr processor);
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief Emitted when a new color manager is connected
|
||||
*/
|
||||
void ColorManagerChanged(ColorManager* color_manager);
|
||||
void ColorManagerChanged(ColorManager *color_manager);
|
||||
|
||||
void frameSwapped();
|
||||
void frameSwapped();
|
||||
|
||||
protected:
|
||||
/**
|
||||
/**
|
||||
* @brief Provides access to the color processor (nullptr if none is set)
|
||||
*/
|
||||
ColorProcessorPtr color_service();
|
||||
ColorProcessorPtr color_service();
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief Enables a context menu that allows simple access to the DVL pipeline
|
||||
*/
|
||||
void EnableDefaultContextMenu();
|
||||
void EnableDefaultContextMenu();
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief Function called whenever the processor changes
|
||||
*
|
||||
* Default functionality is just to call update()
|
||||
*/
|
||||
virtual void ColorProcessorChangedEvent();
|
||||
virtual void ColorProcessorChangedEvent();
|
||||
|
||||
Renderer* renderer() const
|
||||
{
|
||||
return attached_renderer_;
|
||||
}
|
||||
Renderer *renderer() const
|
||||
{
|
||||
return attached_renderer_;
|
||||
}
|
||||
|
||||
void makeCurrent();
|
||||
void makeCurrent();
|
||||
|
||||
void doneCurrent();
|
||||
void doneCurrent();
|
||||
|
||||
#ifdef USE_QOPENGLWINDOW
|
||||
QWindow*
|
||||
QWindow *
|
||||
#else
|
||||
QWidget*
|
||||
QWidget *
|
||||
#endif
|
||||
inner_widget() const
|
||||
{
|
||||
return inner_widget_;
|
||||
}
|
||||
inner_widget() const
|
||||
{
|
||||
return inner_widget_;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief Get inner widget as paint device for QPainter
|
||||
*
|
||||
* NOTE: This will be incompatible with QVulkanWindow so functions using it
|
||||
* will need to be replaced soon.
|
||||
*/
|
||||
QPaintDevice *paint_device() const;
|
||||
QPaintDevice *paint_device() const;
|
||||
|
||||
void SetInnerMouseTracking(bool e);
|
||||
void SetInnerMouseTracking(bool e);
|
||||
|
||||
QRect GetInnerRect() const
|
||||
{
|
||||
return wrapper_ ? wrapper_->rect() : QRect();
|
||||
}
|
||||
QRect GetInnerRect() const
|
||||
{
|
||||
return wrapper_ ? wrapper_->rect() : QRect();
|
||||
}
|
||||
|
||||
VideoParams GetViewportParams() const;
|
||||
VideoParams GetViewportParams() const;
|
||||
|
||||
protected slots:
|
||||
/**
|
||||
/**
|
||||
* @brief Called whenever the internal rendering context has been created
|
||||
*/
|
||||
virtual void OnInit();
|
||||
virtual void OnInit();
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief Called while the internal rendering context is being rendered
|
||||
*/
|
||||
virtual void OnPaint() = 0;
|
||||
virtual void OnPaint() = 0;
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief Called just before the internal rendering context is destroyed
|
||||
*/
|
||||
virtual void OnDestroy();
|
||||
virtual void OnDestroy();
|
||||
|
||||
private:
|
||||
/**
|
||||
/**
|
||||
* @brief Call this if this user has selected a different display/view/look to recreate the processor
|
||||
*/
|
||||
void SetupColorProcessor();
|
||||
void SetupColorProcessor();
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief Cleanup function
|
||||
*/
|
||||
void ClearOCIOLutTexture();
|
||||
void ClearOCIOLutTexture();
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief Main drawing surface abstraction
|
||||
*/
|
||||
#ifdef USE_QOPENGLWINDOW
|
||||
QWindow* inner_widget_;
|
||||
QWindow *inner_widget_;
|
||||
#else
|
||||
QWidget* inner_widget_;
|
||||
QWidget *inner_widget_;
|
||||
#endif
|
||||
QWidget *wrapper_;
|
||||
QWidget *wrapper_;
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief Renderer abstraction
|
||||
*/
|
||||
Renderer* attached_renderer_;
|
||||
Renderer *attached_renderer_;
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief Connected color manager
|
||||
*/
|
||||
ColorManager* color_manager_;
|
||||
ColorManager *color_manager_;
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief Color management service
|
||||
*/
|
||||
ColorProcessorPtr color_service_;
|
||||
ColorProcessorPtr color_service_;
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief Internal color transform storage
|
||||
*/
|
||||
ColorTransform color_transform_;
|
||||
ColorTransform color_transform_;
|
||||
|
||||
private slots:
|
||||
/**
|
||||
/**
|
||||
* @brief Sets all color settings to the defaults pertaining to this configuration
|
||||
*/
|
||||
void ColorConfigChanged();
|
||||
void ColorConfigChanged();
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief The default context menu shown
|
||||
*/
|
||||
void ShowDefaultContextMenu();
|
||||
void ShowDefaultContextMenu();
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief If GetDisplayMenu() is called with `auto_connect` set to true, it will be connected to this
|
||||
*/
|
||||
void MenuDisplaySelect(QAction* action);
|
||||
void MenuDisplaySelect(QAction *action);
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief If GetViewMenu() is called with `auto_connect` set to true, it will be connected to this
|
||||
*/
|
||||
void MenuViewSelect(QAction* action);
|
||||
void MenuViewSelect(QAction *action);
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief If GetLookMenu() is called with `auto_connect` set to true, it will be connected to this
|
||||
*/
|
||||
void MenuLookSelect(QAction* action);
|
||||
void MenuLookSelect(QAction *action);
|
||||
|
||||
/**
|
||||
/**
|
||||
* @brief If GetColorSpaceMenu() is called with `auto_connect` set to true, it will be connected to this
|
||||
*/
|
||||
void MenuColorspaceSelect(QAction* action);
|
||||
|
||||
void MenuColorspaceSelect(QAction *action);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user