File indexing completed on 2024-11-03 04:28:55
0001 /* 0002 SPDX-FileCopyrightText: 2008 Jean-Baptiste Mardelle <jb@kdenlive.org> 0003 SPDX-FileCopyrightText: 2011 Marco Gittler <marco@gitma.de> 0004 0005 SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0006 */ 0007 0008 #include "clipstabilize.h" 0009 #include "assets/model/assetparametermodel.hpp" 0010 #include "assets/view/assetparameterview.hpp" 0011 #include "bin/projectclip.h" 0012 #include "bin/projectitemmodel.h" 0013 #include "core.h" 0014 #include "effects/effectsrepository.hpp" 0015 #include "mainwindow.h" 0016 #include "widgets/doublewidget.h" 0017 #include "widgets/positionwidget.h" 0018 0019 #include "kdenlivesettings.h" 0020 #include <KIO/RenameDialog> 0021 #include <KMessageBox> 0022 #include <QFontDatabase> 0023 #include <QPushButton> 0024 #include <memory> 0025 #include <mlt++/Mlt.h> 0026 0027 ClipStabilize::ClipStabilize(const std::vector<QString> &binIds, QString filterName, QWidget *parent) 0028 : QDialog(parent) 0029 , m_filtername(std::move(filterName)) 0030 , m_binIds(binIds) 0031 , m_vbox(nullptr) 0032 , m_assetModel(nullptr) 0033 { 0034 setFont(QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont)); 0035 setupUi(this); 0036 setWindowTitle(i18nc("@title:window", "Stabilize Clip")); 0037 // QString stylesheet = EffectStackView2::getStyleSheet(); 0038 // setStyleSheet(stylesheet); 0039 0040 Q_ASSERT(binIds.size() > 0); 0041 auto firstBinClip = pCore->projectItemModel()->getClipByBinID(m_binIds.front().section(QLatin1Char('/'), 0, 0)); 0042 auto firstUrl = firstBinClip->url(); 0043 m_vbox = new QVBoxLayout(optionsbox); 0044 if (m_filtername == QLatin1String("vidstab")) { 0045 m_view = std::make_unique<AssetParameterView>(this); 0046 qDebug() << "// Fetching effect: " << m_filtername; 0047 std::unique_ptr<Mlt::Filter> asset = EffectsRepository::get()->getEffect(m_filtername); 0048 auto prop = std::make_unique<Mlt::Properties>(asset->get_properties()); 0049 QDomElement xml = EffectsRepository::get()->getXml(m_filtername); 0050 m_assetModel.reset(new AssetParameterModel(std::move(prop), xml, m_filtername, ObjectId())); 0051 QDir dir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QStringLiteral("/effects/presets/")); 0052 const QString presetFile = dir.absoluteFilePath(QString("%1.json").arg(m_assetModel->getAssetId())); 0053 const QVector<QPair<QString, QVariant>> params = m_assetModel->loadPreset(presetFile, i18n("Last setting")); 0054 if (!params.isEmpty()) { 0055 m_assetModel->setParameters(params); 0056 } 0057 m_view->setModel(m_assetModel, QSize(1920, 1080)); 0058 m_vbox->addWidget(m_view.get()); 0059 // Presets 0060 preset_button->setMenu(m_view->presetMenu()); 0061 } 0062 connect(config_button, &QToolButton::clicked, this, [&]() { pCore->window()->manageClipJobs(AbstractTask::STABILIZEJOB, this); }); 0063 0064 connect(buttonBox->button(QDialogButtonBox::Ok), &QPushButton::clicked, this, &QDialog::accept); 0065 adjustSize(); 0066 } 0067 0068 ClipStabilize::~ClipStabilize() {} 0069 0070 std::unordered_map<QString, QVariant> ClipStabilize::filterParams() const 0071 { 0072 QVector<QPair<QString, QVariant>> result = m_assetModel->getAllParameters(); 0073 std::unordered_map<QString, QVariant> params; 0074 0075 for (const auto &it : qAsConst(result)) { 0076 params[it.first] = it.second; 0077 } 0078 return params; 0079 } 0080 0081 QString ClipStabilize::filterName() const 0082 { 0083 return m_filtername; 0084 } 0085 0086 QString ClipStabilize::desc() const 0087 { 0088 return i18nc("Description", "Stabilize clip"); 0089 }