File indexing completed on 2024-05-12 04:52:52
0001 /* 0002 SPDX-FileCopyrightText: 2017 Jean-Baptiste Mardelle 0003 SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0004 */ 0005 0006 #include "geometryeditwidget.hpp" 0007 #include "assets/model/assetparametermodel.hpp" 0008 #include "core.h" 0009 #include "kdenlivesettings.h" 0010 #include "monitor/monitor.h" 0011 #include "monitor/monitormanager.h" 0012 #include "widgets/geometrywidget.h" 0013 #include "widgets/timecodedisplay.h" 0014 #include <QVBoxLayout> 0015 #include <framework/mlt_types.h> 0016 #include <mlt++/MltProperties.h> 0017 0018 GeometryEditWidget::GeometryEditWidget(std::shared_ptr<AssetParameterModel> model, QModelIndex index, QSize frameSize, QWidget *parent) 0019 : AbstractParamWidget(std::move(model), index, parent) 0020 { 0021 auto *layout = new QVBoxLayout(this); 0022 QString comment = m_model->data(m_index, AssetParameterModel::CommentRole).toString(); 0023 const QString value = m_model->data(m_index, AssetParameterModel::ValueRole).toString().simplified(); 0024 int start = m_model->data(m_index, AssetParameterModel::ParentInRole).toInt(); 0025 int end = start + m_model->data(m_index, AssetParameterModel::ParentDurationRole).toInt(); 0026 QRect rect; 0027 if (value.contains(QLatin1Char('%'))) { 0028 QSize profileSize = pCore->getCurrentFrameSize(); 0029 Mlt::Properties mlt_prop; 0030 m_model->passProperties(mlt_prop); 0031 mlt_prop.set("rect", value.toUtf8().data()); 0032 mlt_rect r = mlt_prop.get_rect("rect"); 0033 rect = QRect(int(profileSize.width() * r.x), int(profileSize.height() * r.y), int(profileSize.width() * r.w), int(profileSize.height() * r.h)); 0034 ; 0035 } else { 0036 QStringList vals = value.split(QLatin1Char(' ')); 0037 if (vals.count() >= 4) { 0038 rect = QRect(vals.at(0).toInt(), vals.at(1).toInt(), vals.at(2).toInt(), vals.at(3).toInt()); 0039 } 0040 } 0041 if (rect.isNull()) { 0042 // Cannot read value, use random default 0043 rect = QRect(50, 50, 200, 200); 0044 } 0045 Monitor *monitor = pCore->getMonitor(m_model->monitorId); 0046 m_geom = new GeometryWidget(monitor, QPair<int, int>(start, end), rect, 100, frameSize, false, 0047 m_model->data(m_index, AssetParameterModel::OpacityRole).toBool(), this); 0048 m_geom->setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred)); 0049 connect(m_geom, &GeometryWidget::updateMonitorGeometry, this, [this](const QRect r) { 0050 if (m_model->isActive()) { 0051 pCore->getMonitor(m_model->monitorId)->setUpEffectGeometry(r); 0052 } 0053 }); 0054 layout->setContentsMargins(0, 0, 0, 0); 0055 layout->addWidget(m_geom); 0056 setFixedHeight(m_geom->sizeHint().height()); 0057 0058 // Q_EMIT the signal of the base class when appropriate 0059 connect(this->m_geom, &GeometryWidget::valueChanged, this, [this](const QString &val) { Q_EMIT valueChanged(m_index, val, true); }); 0060 0061 setToolTip(comment); 0062 } 0063 0064 GeometryEditWidget::~GeometryEditWidget() = default; 0065 0066 void GeometryEditWidget::slotRefresh() 0067 { 0068 const QString value = m_model->data(m_index, AssetParameterModel::ValueRole).toString().simplified(); 0069 QRect rect; 0070 QStringList vals = value.split(QLatin1Char(' ')); 0071 int start = m_model->data(m_index, AssetParameterModel::ParentInRole).toInt(); 0072 int end = start + m_model->data(m_index, AssetParameterModel::ParentDurationRole).toInt(); 0073 m_geom->slotSetRange(QPair<int, int>(start, end)); 0074 if (vals.count() >= 4) { 0075 rect = QRect(vals.at(0).toInt(), vals.at(1).toInt(), vals.at(2).toInt(), vals.at(3).toInt()); 0076 m_geom->setValue(rect); 0077 } 0078 } 0079 0080 void GeometryEditWidget::slotShowComment(bool show) 0081 { 0082 Q_UNUSED(show); 0083 } 0084 0085 void GeometryEditWidget::monitorSeek(int pos) 0086 { 0087 // Update monitor scene for geometry params 0088 int start = m_model->data(m_index, AssetParameterModel::ParentPositionRole).toInt(); 0089 int end = start + m_model->data(m_index, AssetParameterModel::ParentDurationRole).toInt(); 0090 if (pos >= start && pos < end) { 0091 m_geom->connectMonitor(true); 0092 pCore->getMonitor(m_model->monitorId)->setEffectKeyframe(true); 0093 } else { 0094 m_geom->connectMonitor(false); 0095 } 0096 } 0097 0098 void GeometryEditWidget::slotInitMonitor(bool active) 0099 { 0100 m_geom->connectMonitor(active); 0101 Monitor *monitor = pCore->getMonitor(m_model->monitorId); 0102 if (active) { 0103 monitor->setEffectKeyframe(true); 0104 connect(monitor, &Monitor::seekPosition, this, &GeometryEditWidget::monitorSeek, Qt::UniqueConnection); 0105 } else { 0106 disconnect(monitor, &Monitor::seekPosition, this, &GeometryEditWidget::monitorSeek); 0107 } 0108 }