Commit 8821b5ea authored by Julius Künzel's avatar Julius Künzel
Browse files

Add new assetparam ui type "urllist"

parent b771350e
......@@ -20,6 +20,7 @@ set(kdenlive_SRCS
assets/view/widgets/boolparamwidget.cpp
assets/view/widgets/buttonparamwidget.cpp
assets/view/widgets/switchparamwidget.cpp
assets/view/widgets/urllistparamwidget.cpp
assets/view/widgets/urlparamwidget.cpp
assets/view/widgets/doubleparamwidget.cpp
assets/view/widgets/colorwheel.cpp
......
......@@ -492,6 +492,8 @@ QVariant AssetParameterModel::data(const QModelIndex &index, int role) const
QDomElement namesElem = element.firstChildElement(QStringLiteral("paramlistdisplay"));
return i18n(namesElem.text().toUtf8().data()).split(QLatin1Char(','));
}
case NewStuffRole:
return element.attribute(QStringLiteral("newstuff"));
case List1Role:
return parseAttribute(m_ownerId, QStringLiteral("list1"), element);
case List2Role:
......@@ -546,6 +548,9 @@ ParamType AssetParameterModel::paramTypeFromStr(const QString &type)
if (type == QLatin1String("list")) {
return ParamType::List;
}
if (type == QLatin1String("urllist")) {
return ParamType::UrlList;
}
if (type == QLatin1String("bool")) {
return ParamType::Bool;
}
......
......@@ -43,6 +43,7 @@ class KeyframeModelList;
enum class ParamType {
Double,
List, // Value can be chosen from a list of pre-defined ones
UrlList, // File can be choosen from a list of pre-defined ones or a custom file can be used (like url)
Bool,
Switch,
RestrictedAnim, // animated 1 dimensional param with linear support only
......@@ -102,6 +103,7 @@ public:
AlphaRole,
ListValuesRole,
ListNamesRole,
NewStuffRole,
FactorRole,
FilterRole,
FilterJobParamsRole,
......
......@@ -38,6 +38,7 @@
#include "positioneditwidget.hpp"
#include "slidewidget.hpp"
#include "switchparamwidget.hpp"
#include "urllistparamwidget.h"
#include "urlparamwidget.hpp"
#include <QLabel>
......@@ -86,6 +87,9 @@ AbstractParamWidget *AbstractParamWidget::construct(const std::shared_ptr<AssetP
case ParamType::List:
widget = new ListParamWidget(model, index, parent);
break;
case ParamType::UrlList:
widget = new UrlListParamWidget(model, index, parent);
break;
case ParamType::Bool:
widget = new BoolParamWidget(model, index, parent);
break;
......
/***************************************************************************
* Copyright (C) 2021 by Julius Künzel (jk.kdedev@smartlab.uber.space) *
* This file is part of Kdenlive. See www.kdenlive.org. *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) version 3 or any later version accepted by the *
* membership of KDE e.V. (or its successor approved by the membership *
* of KDE e.V.), which shall act as a proxy defined in Section 14 of *
* version 3 of the license. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
#include "urllistparamwidget.h"
#include "assets/model/assetparametermodel.hpp"
#include "core.h"
#include "mltconnection.h"
#include "mainwindow.h"
#include <kns3/downloaddialog.h>
UrlListParamWidget::UrlListParamWidget(std::shared_ptr<AssetParameterModel> model, QModelIndex index, QWidget *parent)
: AbstractParamWidget(std::move(model), index, parent)
{
setupUi(this);
// Get data from model
QString comment = m_model->data(m_index, AssetParameterModel::CommentRole).toString();
const QString configFile = m_model->data(m_index, AssetParameterModel::NewStuffRole).toString();
// setup the comment
setToolTip(comment);
m_labelComment->setText(comment);
m_widgetComment->setHidden(true);
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
m_list->setIconSize(QSize(50, 30));
setMinimumHeight(m_list->sizeHint().height());
// setup download
m_download->setHidden(configFile.isEmpty());
// setup the name
m_labelName->setText(m_model->data(m_index, Qt::DisplayRole).toString());
slotRefresh();
connect(m_download, &QToolButton::clicked, this, &UrlListParamWidget::downloadNewItems);
connect(m_open, &QToolButton::clicked, this, &UrlListParamWidget::openFile);
// emit the signal of the base class when appropriate
// The connection is ugly because the signal "currentIndexChanged" is overloaded in QComboBox
connect(this->m_list, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
this, [this](int) {
emit valueChanged(m_index, m_list->itemData(m_list->currentIndex()).toString(), true);
});
}
void UrlListParamWidget::setCurrentIndex(int index)
{
m_list->setCurrentIndex(index);
}
void UrlListParamWidget::setCurrentText(const QString &text)
{
m_list->setCurrentText(text);
}
void UrlListParamWidget::addItem(const QString &text, const QVariant &value)
{
m_list->addItem(text, value);
}
void UrlListParamWidget::setItemIcon(int index, const QIcon &icon)
{
m_list->setItemIcon(index, icon);
}
void UrlListParamWidget::setIconSize(const QSize &size)
{
m_list->setIconSize(size);
}
void UrlListParamWidget::slotShowComment(bool show)
{
if (!m_labelComment->text().isEmpty()) {
m_widgetComment->setVisible(show);
}
}
QString UrlListParamWidget::getValue()
{
return m_list->currentData().toString();
}
void UrlListParamWidget::slotRefresh()
{
const QSignalBlocker bk(m_list);
m_list->clear();
QStringList names = m_model->data(m_index, AssetParameterModel::ListNamesRole).toStringList();
QStringList values = m_model->data(m_index, AssetParameterModel::ListValuesRole).toStringList();
QString value = m_model->data(m_index, AssetParameterModel::ValueRole).toString();
QString filter = m_model->data(m_index, AssetParameterModel::FilterRole).toString();
filter.remove(0, filter.indexOf("(")+1);
filter.remove(filter.indexOf(")")-1, -1);
m_fileExt = filter.split(" ");
if (values.first() == QLatin1String("%lumaPaths")) {
// special case: Luma files
values.clear();
names.clear();
if (pCore->getCurrentFrameSize().width() > 1000) {
// HD project
values = MainWindow::m_lumaFiles.value(QStringLiteral("16_9"));
} else if (pCore->getCurrentFrameSize().height() > 1000) {
values = MainWindow::m_lumaFiles.value(QStringLiteral("9_16"));
} else if (pCore->getCurrentFrameSize().height() == pCore->getCurrentFrameSize().width()) {
values = MainWindow::m_lumaFiles.value(QStringLiteral("square"));
} else if (pCore->getCurrentFrameSize().height() == 480) {
values = MainWindow::m_lumaFiles.value(QStringLiteral("NTSC"));
} else {
values = MainWindow::m_lumaFiles.value(QStringLiteral("PAL"));
}
m_list->addItem(i18n("None (Dissolve)"));
}
if (values.first() == QLatin1String("%lutPaths")) {
// special case: LUT files
values.clear();
names.clear();
// check for Kdenlive installed luts files
QStringList customLuts = QStandardPaths::locateAll(QStandardPaths::AppDataLocation, QStringLiteral("luts"), QStandardPaths::LocateDirectory);
#ifdef Q_OS_WIN
// Windows downloaded lumas are saved in AppLocalDataLocation
customLuts.append(QStandardPaths::locateAll(QStandardPaths::AppLocalDataLocation, QStringLiteral("luts"), QStandardPaths::LocateDirectory));
#endif
for (const QString &folderpath : qAsConst(customLuts)) {
QDir dir(folderpath);
QDirIterator it(dir.absolutePath(), m_fileExt, QDir::Files, QDirIterator::Subdirectories);
while (it.hasNext()) {
values.append(it.next());
}
}
}
// add all matching files in the location of the current item too
if (!value.isEmpty()) {
QString path = QUrl(value).adjusted(QUrl::RemoveFilename).toString();
QDir dir(path);
for (const auto &filename : dir.entryList(m_fileExt, QDir::Files)) {
values.append(dir.filePath(filename));
}
// make sure the current value is added. If it is a duplicate we remove it later
values << value;
}
values.removeDuplicates();
// build ui list
for (const QString &value : qAsConst(values)) {
names.append(QUrl(value).fileName());
}
for (int i = 0; i < values.count(); i++) {
const QString &entry = values.at(i);
m_list->addItem(names.at(i), entry);
// Create thumbnails
if (!entry.isEmpty() && (entry.endsWith(QLatin1String(".png")) || entry.endsWith(QLatin1String(".pgm")))) {
if (MainWindow::m_lumacache.contains(entry)) {
m_list->setItemIcon(i + 1, QPixmap::fromImage(MainWindow::m_lumacache.value(entry)));
} else {
QImage pix(entry);
if (!pix.isNull()) {
MainWindow::m_lumacache.insert(entry, pix.scaled(50, 30, Qt::KeepAspectRatio, Qt::SmoothTransformation));
m_list->setItemIcon(i + 1, QPixmap::fromImage(MainWindow::m_lumacache.value(entry)));
}
}
}
}
// select current value
if (!value.isEmpty()) {
int ix = m_list->findData(value);
if (ix > -1) {
m_list->setCurrentIndex(ix);
}
}
}
void UrlListParamWidget::openFile()
{
QString path = KRecentDirs::dir(QStringLiteral(":KdenliveUrlListParamFolder"));
QString filter = m_model->data(m_index, AssetParameterModel::FilterRole).toString();
if (path.isEmpty()) {
path = QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
}
QString urlString = QFileDialog::getOpenFileName(this, QString(), path, filter);
if (!urlString.isEmpty()) {
QString path = QUrl(urlString).adjusted(QUrl::RemoveFilename).toString();
KRecentDirs::add(QStringLiteral(":KdenliveUrlListParamFolder"), QUrl(urlString).adjusted(QUrl::RemoveFilename).toString());
emit valueChanged(m_index, urlString, true);
slotRefresh();
}
}
int UrlListParamWidget::getNewStuff(const QString &configFile)
{
KNS3::Entry::List entries;
QPointer<KNS3::DownloadDialog> dialog = new KNS3::DownloadDialog(configFile);
if (dialog->exec() != 0) {
entries = dialog->changedEntries();
}
for (const KNS3::Entry &entry : qAsConst(entries)) {
if (entry.status() == KNS3::Entry::Installed) {
qCDebug(KDENLIVE_LOG) << "// Installed files: " << entry.installedFiles();
}
}
delete dialog;
return entries.size();
}
void UrlListParamWidget::downloadNewItems()
{
const QString configFile = m_model->data(m_index, AssetParameterModel::NewStuffRole).toString();
if(configFile.isEmpty()) {
return;
}
if (getNewStuff(configFile) > 0) {
if(configFile.contains(QStringLiteral("kdenlive_wipes.knsrc"))) {
MltConnection::refreshLumas();
}
slotRefresh();
}
}
/***************************************************************************
* Copyright (C) 2021 by Julius Künzel (jk.kdedev@smartlab.uber.space) *
* This file is part of Kdenlive. See www.kdenlive.org. *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) version 3 or any later version accepted by the *
* membership of KDE e.V. (or its successor approved by the membership *
* of KDE e.V.), which shall act as a proxy defined in Section 14 of *
* version 3 of the license. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
#ifndef URLLISTPARAMWIDGET_H
#define URLLISTPARAMWIDGET_H
#include "assets/view/widgets/abstractparamwidget.hpp"
#include "ui_urllistparamwidget_ui.h"
#include <QVariant>
#include <QWidget>
class AssetParameterModel;
/** @brief This class represents a parameter that requires
the user to choose a value from a list
*/
class UrlListParamWidget : public AbstractParamWidget, public Ui::UrlListParamWidget_UI
{
Q_OBJECT
public:
/** @brief Constructor for the widgetComment
@param name String containing the name of the parameter
@param comment Optional string containing the comment associated to the parameter
@param parent Parent widget
*/
UrlListParamWidget(std::shared_ptr<AssetParameterModel> model, QModelIndex index, QWidget *parent);
/** @brief Set the index of the current displayed element
@param index Integer holding the index of the target element (0-indexed)
*/
void setCurrentIndex(int index);
/** @brief Set the text currently displayed on the list
@param text String containing the text of the element to show
*/
void setCurrentText(const QString &text);
/** @brief Add an item to the list.
@param text String to be displayed in the list
@param value Underlying value corresponding to the text
*/
void addItem(const QString &text, const QVariant &value = QVariant());
/** @brief Set the icon of a given element
@param index Integer holding the index of the target element (0-indexed)
@param icon The corresponding icon
*/
void setItemIcon(int index, const QIcon &icon);
/** @brief Set the size of the icons shown in the list
@param size Target size of the icon
*/
void setIconSize(const QSize &size);
/** @brief Returns the current value of the parameter
*/
QString getValue();
private:
QStringList m_fileExt;
/** @brief Instantiates a "Get Hot New Stuff" dialog.
* @param configFile configuration file for KNewStuff
* @return number of installed items */
int getNewStuff(const QString &configFile = QString());
public slots:
/** @brief Toggle the comments on or off
*/
void slotShowComment(bool show) override;
/** @brief refresh the properties to reflect changes in the model
*/
void slotRefresh() override;
/** @brief Open fileopen dialog
*/
void openFile();
/** @brief Open KNewStuff dialog to download new LUTs
*/
void downloadNewItems();
};
#endif
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>UrlListParamWidget_UI</class>
<widget class="QWidget" name="UrlListParamWidget_UI">
<layout class="QGridLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<property name="spacing">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="m_labelName">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="3">
<widget class="QWidget" name="m_widgetComment" native="true">
<layout class="QGridLayout" name="_2">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<property name="spacing">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="m_labelComment">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<property name="textFormat">
<enum>Qt::RichText</enum>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="0" column="1">
<widget class="QWidget" name="widget" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QComboBox" name="m_list">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToMinimumContentsLength</enum>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="m_open">
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset theme="document-open">
<normaloff>.</normaloff>.</iconset>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="m_download">
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset theme="edit-download">
<normaloff>.</normaloff>.</iconset>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment