|
| 1 | +#include "MixerPanelInterface.h" |
| 2 | +#include "MixerPanelInterface_p.h" |
| 3 | + |
| 4 | +#include <QQmlComponent> |
| 5 | +#include <QQuickItem> |
| 6 | +#include <QVariant> |
| 7 | + |
| 8 | +#include <CoreApi/runtimeinterface.h> |
| 9 | + |
| 10 | +#include <ScopicFlowCore/ScrollBehaviorViewModel.h> |
| 11 | +#include <ScopicFlowCore/TrackListInteractionController.h> |
| 12 | +#include <ScopicFlowCore/TrackListLayoutViewModel.h> |
| 13 | + |
| 14 | +#include <coreplugin/ProjectWindowInterface.h> |
| 15 | + |
| 16 | +#include <visualeditor/ProjectViewModelContext.h> |
| 17 | +#include <visualeditor/internal/MixerAddOn.h> |
| 18 | +#include <visualeditor/internal/EditorPreference.h> |
| 19 | + |
| 20 | +namespace VisualEditor { |
| 21 | + |
| 22 | + static Qt::KeyboardModifier getModifier(Internal::EditorPreference::ScrollModifier modifier) { |
| 23 | + switch (modifier) { |
| 24 | + case Internal::EditorPreference::SM_Control: |
| 25 | + return Qt::ControlModifier; |
| 26 | + case Internal::EditorPreference::SM_Alt: |
| 27 | + return Qt::AltModifier; |
| 28 | + case Internal::EditorPreference::SM_Shift: |
| 29 | + return Qt::ShiftModifier; |
| 30 | + } |
| 31 | + Q_UNREACHABLE(); |
| 32 | + } |
| 33 | + |
| 34 | + static sflow::ScrollBehaviorViewModel::ScrollTypes getScrollTypes(MixerPanelInterface::Tool tool) { |
| 35 | + if (tool == MixerPanelInterface::HandTool) { |
| 36 | + return sflow::ScrollBehaviorViewModel::Wheel | sflow::ScrollBehaviorViewModel::Pinch | sflow::ScrollBehaviorViewModel::MiddleButton | sflow::ScrollBehaviorViewModel::LeftButton; |
| 37 | + } |
| 38 | + return sflow::ScrollBehaviorViewModel::Wheel | sflow::ScrollBehaviorViewModel::Pinch | sflow::ScrollBehaviorViewModel::MiddleButton; |
| 39 | + } |
| 40 | + |
| 41 | + void MixerPanelInterfacePrivate::bindScrollBehaviorViewModel() const { |
| 42 | + Q_Q(const MixerPanelInterface); |
| 43 | + scrollBehaviorViewModel->setAlternateAxisModifier(getModifier(Internal::EditorPreference::alternateAxisModifier())); |
| 44 | + scrollBehaviorViewModel->setZoomModifier(getModifier(Internal::EditorPreference::zoomModifier())); |
| 45 | + scrollBehaviorViewModel->setPageModifier(getModifier(Internal::EditorPreference::pageModifier())); |
| 46 | + scrollBehaviorViewModel->setUsePageModifierAsAlternateAxisZoom(Internal::EditorPreference::usePageModifierAsAlternateAxisZoom()); |
| 47 | + scrollBehaviorViewModel->setAutoScroll(Internal::EditorPreference::middleButtonAutoScroll()); |
| 48 | + |
| 49 | + QObject::connect(Internal::EditorPreference::instance(), &Internal::EditorPreference::alternateAxisModifierChanged, scrollBehaviorViewModel, [=, this] { |
| 50 | + scrollBehaviorViewModel->setAlternateAxisModifier(getModifier(Internal::EditorPreference::alternateAxisModifier())); |
| 51 | + }); |
| 52 | + QObject::connect(Internal::EditorPreference::instance(), &Internal::EditorPreference::zoomModifierChanged, scrollBehaviorViewModel, [=, this] { |
| 53 | + scrollBehaviorViewModel->setZoomModifier(getModifier(Internal::EditorPreference::zoomModifier())); |
| 54 | + }); |
| 55 | + QObject::connect(Internal::EditorPreference::instance(), &Internal::EditorPreference::pageModifierChanged, scrollBehaviorViewModel, [=, this] { |
| 56 | + scrollBehaviorViewModel->setPageModifier(getModifier(Internal::EditorPreference::pageModifier())); |
| 57 | + }); |
| 58 | + QObject::connect(Internal::EditorPreference::instance(), &Internal::EditorPreference::usePageModifierAsAlternateAxisZoomChanged, scrollBehaviorViewModel, [=, this] { |
| 59 | + scrollBehaviorViewModel->setUsePageModifierAsAlternateAxisZoom(Internal::EditorPreference::usePageModifierAsAlternateAxisZoom()); |
| 60 | + }); |
| 61 | + QObject::connect(Internal::EditorPreference::instance(), &Internal::EditorPreference::middleButtonAutoScrollChanged, scrollBehaviorViewModel, [=, this] { |
| 62 | + scrollBehaviorViewModel->setAutoScroll(Internal::EditorPreference::middleButtonAutoScroll()); |
| 63 | + }); |
| 64 | + |
| 65 | + scrollBehaviorViewModel->setScrollTypes(getScrollTypes(tool)); |
| 66 | + QObject::connect(q, &MixerPanelInterface::toolChanged, scrollBehaviorViewModel, [=, this] { |
| 67 | + scrollBehaviorViewModel->setScrollTypes(getScrollTypes(tool)); |
| 68 | + }); |
| 69 | + } |
| 70 | + |
| 71 | + MixerPanelInterface::MixerPanelInterface(Internal::MixerAddOn *addOn, Core::ProjectWindowInterface *windowHandle) : QObject(windowHandle), d_ptr(new MixerPanelInterfacePrivate) { |
| 72 | + Q_D(MixerPanelInterface); |
| 73 | + Q_ASSERT(windowHandle->getObjects(staticMetaObject.className()).isEmpty()); |
| 74 | + windowHandle->addObject(staticMetaObject.className(), this); |
| 75 | + d->q_ptr = this; |
| 76 | + d->windowHandle = windowHandle; |
| 77 | + d->addon = addOn; |
| 78 | + |
| 79 | + d->trackListLayoutViewModel = new sflow::TrackListLayoutViewModel(this); |
| 80 | + d->masterTrackListLayoutViewModel = new sflow::TrackListLayoutViewModel(this); |
| 81 | + d->scrollBehaviorViewModel = new sflow::ScrollBehaviorViewModel(this); |
| 82 | + d->trackListInteractionController = ProjectViewModelContext::of(d->windowHandle)->createAndBindTrackListInteractionController(); |
| 83 | + d->masterTrackListInteractionController = ProjectViewModelContext::of(d->windowHandle)->createAndBindTrackListInteractionControllerOfMaster(); |
| 84 | + |
| 85 | + QQmlComponent component(Core::RuntimeInterface::qmlEngine(), "DiffScope.VisualEditor", "MixerView"); |
| 86 | + if (component.isError()) { |
| 87 | + qFatal() << component.errorString(); |
| 88 | + } |
| 89 | + auto o = component.createWithInitialProperties({ |
| 90 | + {"addOn", QVariant::fromValue(d->addon)}, |
| 91 | + {"mixerPanelInterface", QVariant::fromValue(this)} |
| 92 | + }); |
| 93 | + if (component.isError()) { |
| 94 | + qFatal() << component.errorString(); |
| 95 | + } |
| 96 | + o->setParent(this); |
| 97 | + d->mixerView = qobject_cast<QQuickItem *>(o); |
| 98 | + Q_ASSERT(d->mixerView); |
| 99 | + |
| 100 | + d->bindScrollBehaviorViewModel(); |
| 101 | + } |
| 102 | + |
| 103 | + MixerPanelInterface::~MixerPanelInterface() = default; |
| 104 | + |
| 105 | + MixerPanelInterface *MixerPanelInterface::of(const Core::ProjectWindowInterface *windowHandle) { |
| 106 | + return qobject_cast<MixerPanelInterface *>(windowHandle->getFirstObject(staticMetaObject.className())); |
| 107 | + } |
| 108 | + |
| 109 | + Core::ProjectWindowInterface *MixerPanelInterface::windowHandle() const { |
| 110 | + Q_D(const MixerPanelInterface); |
| 111 | + return d->windowHandle; |
| 112 | + } |
| 113 | + |
| 114 | + sflow::TrackListLayoutViewModel *MixerPanelInterface::trackListLayoutViewModel() const { |
| 115 | + Q_D(const MixerPanelInterface); |
| 116 | + return d->trackListLayoutViewModel; |
| 117 | + } |
| 118 | + |
| 119 | + sflow::TrackListLayoutViewModel *MixerPanelInterface::masterTrackListLayoutViewModel() const { |
| 120 | + Q_D(const MixerPanelInterface); |
| 121 | + return d->masterTrackListLayoutViewModel; |
| 122 | + } |
| 123 | + |
| 124 | + sflow::ScrollBehaviorViewModel *MixerPanelInterface::scrollBehaviorViewModel() const { |
| 125 | + Q_D(const MixerPanelInterface); |
| 126 | + return d->scrollBehaviorViewModel; |
| 127 | + } |
| 128 | + |
| 129 | + sflow::TrackListInteractionController *MixerPanelInterface::trackListInteractionController() const { |
| 130 | + Q_D(const MixerPanelInterface); |
| 131 | + return d->trackListInteractionController; |
| 132 | + } |
| 133 | + |
| 134 | + sflow::TrackListInteractionController *MixerPanelInterface::masterTrackListInteractionController() const { |
| 135 | + Q_D(const MixerPanelInterface); |
| 136 | + return d->masterTrackListInteractionController; |
| 137 | + } |
| 138 | + |
| 139 | + QQuickItem *MixerPanelInterface::mixerView() const { |
| 140 | + Q_D(const MixerPanelInterface); |
| 141 | + return d->mixerView; |
| 142 | + } |
| 143 | + |
| 144 | + MixerPanelInterface::Tool MixerPanelInterface::tool() const { |
| 145 | + Q_D(const MixerPanelInterface); |
| 146 | + return d->tool; |
| 147 | + } |
| 148 | + |
| 149 | + void MixerPanelInterface::setTool(Tool tool) { |
| 150 | + Q_D(MixerPanelInterface); |
| 151 | + if (d->tool != tool) { |
| 152 | + d->tool = tool; |
| 153 | + Q_EMIT toolChanged(); |
| 154 | + } |
| 155 | + } |
| 156 | + |
| 157 | +} |
| 158 | + |
| 159 | +#include "moc_MixerPanelInterface.cpp" |
0 commit comments