File indexing completed on 2024-12-22 04:36:19
0001 /* 0002 SPDX-FileCopyrightText: 2021 Julius Künzel <jk.kdedev@smartlab.uber.space> 0003 This file is part of Kdenlive. See www.kdenlive.org. 0004 0005 SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0006 */ 0007 0008 #include "recthelper.hpp" 0009 #include "assets/keyframes/model/keyframemodellist.hpp" 0010 #include "assets/model/assetparametermodel.hpp" 0011 #include "core.h" 0012 #include "monitor/monitor.h" 0013 #include "utils/gentime.h" 0014 0015 #include <QSize> 0016 #include <utility> 0017 RectHelper::RectHelper(Monitor *monitor, std::shared_ptr<AssetParameterModel> model, QPersistentModelIndex index, QObject *parent) 0018 : KeyframeMonitorHelper(monitor, std::move(model), std::move(index), parent) 0019 { 0020 } 0021 0022 bool RectHelper::connectMonitor(bool activate) 0023 { 0024 if (activate == m_active) { 0025 return true; 0026 } 0027 m_active = activate; 0028 if (activate) { 0029 connect(m_monitor, &Monitor::effectChanged, this, &RectHelper::slotUpdateFromMonitorRect, Qt::UniqueConnection); 0030 } else { 0031 m_monitor->setEffectKeyframe(false); 0032 disconnect(m_monitor, &Monitor::effectChanged, this, &RectHelper::slotUpdateFromMonitorRect); 0033 } 0034 return m_active; 0035 } 0036 0037 void RectHelper::slotUpdateFromMonitorRect(const QRect &rect) 0038 { 0039 QSize frameSize = pCore->getCurrentFrameSize(); 0040 double x = double(rect.x() + rect.width() / 2) / frameSize.width(); 0041 double y = double(rect.y() + rect.height() / 2) / frameSize.height(); 0042 double w = double(rect.width()) / frameSize.width() * 0.5; 0043 double h = double(rect.height()) / frameSize.height() * 0.5; 0044 Q_EMIT updateKeyframeData(m_indexes.at(0), x); 0045 Q_EMIT updateKeyframeData(m_indexes.at(1), y); 0046 Q_EMIT updateKeyframeData(m_indexes.at(2), w); 0047 Q_EMIT updateKeyframeData(m_indexes.at(3), h); 0048 } 0049 0050 void RectHelper::refreshParams(int pos) 0051 { 0052 int x = 0, y = 0, w = 500, h = 500; 0053 QSize frameSize = pCore->getCurrentFrameSize(); 0054 for (const auto &ix : qAsConst(m_indexes)) { 0055 auto type = m_model->data(ix, AssetParameterModel::TypeRole).value<ParamType>(); 0056 if (type != ParamType::KeyframeParam) { 0057 continue; 0058 } 0059 QString paramName = m_model->data(ix, AssetParameterModel::NameRole).toString(); 0060 double value = m_model->getKeyframeModel()->getInterpolatedValue(pos, ix).toDouble(); 0061 if (paramName.contains(QLatin1String("Position X"))) { 0062 x = frameSize.width() * value; 0063 } else if (paramName.contains(QLatin1String("Position Y"))) { 0064 y = frameSize.height() * value; 0065 } else if (paramName.contains(QLatin1String("Size X"))) { 0066 w = frameSize.width() * value * 2; 0067 } else if (paramName.contains(QLatin1String("Size Y"))) { 0068 h = frameSize.height() * value * 2; 0069 } 0070 } 0071 if (m_monitor) { 0072 qDebug() << QRect(x, y, w, h); 0073 m_monitor->setUpEffectGeometry(QRect(x - w / 2, y - h / 2, w, h)); 0074 } 0075 }