Start porting animationwidget parameter

parent e5276897
......@@ -27,10 +27,11 @@
#include <QString>
#include "klocalizedstring.h"
AssetParameterModel::AssetParameterModel(Mlt::Properties *asset, const QDomElement &assetXml, const QString &assetId, QObject *parent)
AssetParameterModel::AssetParameterModel(Mlt::Properties *asset, const QDomElement &assetXml, const QString &assetId, Kdenlive::MonitorId monitor, QObject *parent)
: QAbstractListModel(parent)
, m_xml(assetXml)
, m_assetId(assetId)
, monitorId(monitor)
, m_asset(asset)
{
Q_ASSERT(asset->is_valid());
......@@ -115,6 +116,7 @@ void AssetParameterModel::setParameter(const QString &name, const QString &value
m_fixedParams[name] = value;
}
}
//refresh monitor after asset change
QSize range(m_asset->get_int("in"), m_asset->get_int("out"));
pCore->refreshProjectRange(range);
}
......@@ -144,16 +146,24 @@ QVariant AssetParameterModel::data(const QModelIndex &index, int role) const
}
return comment;
}
case InRole:
return m_asset->get_int("in");
case OutRole:
return m_asset->get_int("out");
case MinRole:
return parseDoubleAttribute(QStringLiteral("min"), element);
case MaxRole:
return parseDoubleAttribute(QStringLiteral("max"), element);
case FactorRole:
return parseDoubleAttribute(QStringLiteral("factor"), element, 1);
case DecimalsRole:
return (int)parseDoubleAttribute(QStringLiteral("decimals"), element);
case DefaultRole:
return element.attribute(QStringLiteral("default"));
case SuffixRole:
return element.attribute(QStringLiteral("suffix"));
case OpacityRole:
return element.attribute(QStringLiteral("opacity")) != QLatin1String("false");
case ValueRole:
return element.attribute(QStringLiteral("value")).isNull() ? element.attribute(QStringLiteral("default")) : element.attribute(QStringLiteral("value"));
case ListValuesRole:
......@@ -187,8 +197,10 @@ ParamType AssetParameterModel::paramTypeFromStr(const QString &type)
}
if (type == QLatin1String("switch")) {
return ParamType::Switch;
} else if (type.startsWith(QLatin1String("animated"))) {
} else if (type == QLatin1String("animated")) {
return ParamType::Animated;
} else if (type == QLatin1String("animatedrect")) {
return ParamType::AnimatedRect;
} else if (type == QLatin1String("geometry")) {
return ParamType::Geometry;
} else if (type == QLatin1String("addedgeometry")) {
......@@ -223,11 +235,13 @@ ParamType AssetParameterModel::paramTypeFromStr(const QString &type)
}
// static
double AssetParameterModel::parseDoubleAttribute(const QString &attribute, const QDomElement &element)
double AssetParameterModel::parseDoubleAttribute(const QString &attribute, const QDomElement &element, double defaultValue)
{
QLocale locale;
locale.setNumberOptions(QLocale::OmitGroupSeparator);
if (!element.hasAttribute(attribute)) {
return defaultValue;
}
QString content = element.attribute(attribute);
if (content.contains(QLatin1Char('%'))) {
std::unique_ptr<ProfileModel> &profile = pCore->getCurrentProfile();
......@@ -246,8 +260,6 @@ double AssetParameterModel::parseDoubleAttribute(const QString &attribute, const
return p.get_double("eval");
}
return locale.toDouble(content);
return -1;
}
QString AssetParameterModel::getAssetId() const
......
......@@ -44,6 +44,7 @@ enum class ParamType {
Bool,
Switch,
Animated,
AnimatedRect,
Geometry,
Addedgeometry,
Keyframe,
......@@ -65,9 +66,9 @@ class AssetParameterModel : public QAbstractListModel
Q_OBJECT
public:
explicit AssetParameterModel(Mlt::Properties *asset, const QDomElement &assetXml, const QString &assetId, QObject *parent = nullptr);
explicit AssetParameterModel(Mlt::Properties *asset, const QDomElement &assetXml, const QString &assetId, Kdenlive::MonitorId monitor = Kdenlive::ProjectMonitor, QObject *parent = nullptr);
virtual ~AssetParameterModel();
enum { NameRole = Qt::UserRole + 1, TypeRole, CommentRole, MinRole, MaxRole, DefaultRole, SuffixRole, DecimalsRole, ValueRole, ListValuesRole, ListNamesRole };
enum { NameRole = Qt::UserRole + 1, TypeRole, CommentRole, MinRole, MaxRole, DefaultRole, SuffixRole, DecimalsRole, ValueRole, ListValuesRole, ListNamesRole, FactorRole, OpacityRole, InRole, OutRole };
/* @brief Returns the id of the asset represented by this object */
QString getAssetId() const;
......@@ -90,6 +91,10 @@ public:
*/
void commitChanges(const QModelIndex &index, const QString &value);
/* Which monitor is attached to this asset (clip/project)
*/
Kdenlive::MonitorId monitorId;
QVariant data(const QModelIndex &index, int role) const override;
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
......@@ -102,7 +107,7 @@ protected:
- %width and %height that are replaced with profile's height and width.
If keywords are found, mathematical operations are supported. For example "%width -1" is a valid value.
*/
static double parseDoubleAttribute(const QString &attribute, const QDomElement &element);
static double parseDoubleAttribute(const QString &attribute, const QDomElement &element, double defaultValue = -1);
struct ParamRow
{
......
......@@ -27,15 +27,16 @@
#include <QDebug>
#include <QLabel>
#include <QVBoxLayout>
#include <QFontDatabase>
#include <utility>
AssetParameterView::AssetParameterView(QWidget *parent)
: QWidget(parent)
{
m_lay = new QVBoxLayout(this);
m_lay->setContentsMargins(4, 0, 4, 0);
m_lay->setSpacing(2);
m_lay->setContentsMargins(2, 0, 2, 0);
m_lay->setSpacing(0);
setFont(QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont));
}
void AssetParameterView::setModel(const std::shared_ptr<AssetParameterModel> &model)
......
......@@ -22,6 +22,7 @@
#include "doubleparamwidget.hpp"
#include "boolparamwidget.hpp"
#include "effectstack/widgets/listparamwidget.h"
#include "effectstack/widgets/animationwidget.h"
#include <QLabel>
#include <QVBoxLayout>
......@@ -73,9 +74,12 @@ AbstractParamWidget *AbstractParamWidget::construct(const std::shared_ptr<AssetP
case ParamType::Bool:
widget = new BoolParamWidget(model, index, parent);
break;
case ParamType::Switch:
case ParamType::Animated:
case ParamType::Geometry:
case ParamType::Animated:
case ParamType::AnimatedRect:
widget = new AnimationWidget(model, index, parent);
break;
case ParamType::Switch:
case ParamType::Addedgeometry:
case ParamType::Keyframe:
case ParamType::Color:
......
......@@ -202,6 +202,14 @@ MonitorManager *Core::monitorManager()
return m_monitorManager;
}
Monitor *Core::getMonitor(int id)
{
if (id == Kdenlive::ClipMonitor) {
return m_monitorManager->clipMonitor();
}
return m_monitorManager->projectMonitor();
}
std::shared_ptr<BinController> Core::binController()
{
return m_binController;
......@@ -264,6 +272,11 @@ std::unique_ptr<ProfileModel> &Core::getCurrentProfile() const
return ProfileRepository::get()->getProfile(profile);
}
double Core::getCurrentSar() const
{
return getCurrentProfile()->sar();
}
double Core::getCurrentDar() const
{
return getCurrentProfile()->dar();
......
......@@ -28,6 +28,7 @@ class MonitorManager;
class ProducerQueue;
class ProfileModel;
class ProjectManager;
class Monitor;
namespace Mlt {
class Repository;
......@@ -98,6 +99,8 @@ public:
/** @brief Returns a pointer to the current profile */
std::unique_ptr<ProfileModel> &getCurrentProfile() const;
/** @brief Returns Sample Aspect Ratio of current profile */
double getCurrentSar() const;
/** @brief Returns Display Aspect Ratio of current profile */
double getCurrentDar() const;
......@@ -112,6 +115,8 @@ public:
void requestMonitorRefresh();
/** @brief Request project monitor refresh if current position is inside range*/
void refreshProjectRange(QSize range);
/** @brief Returns a reference to a monitor (clip or project monitor) */
Monitor *getMonitor(int id);
/** @brief This function must be called whenever the profile used changes */
void profileChanged();
......
This diff is collapsed.
......@@ -25,6 +25,7 @@
#include <QList>
#include <QWidget>
#include "assets/view/widgets/abstractparamwidget.hpp"
#include "mlt++/MltAnimation.h"
#include "mlt++/MltProperties.h"
#include "timecodedisplay.h"
......@@ -38,15 +39,16 @@ class KSelectAction;
class QComboBox;
class DragValue;
class AnimationWidget : public QWidget
class AnimationWidget : public AbstractParamWidget
{
Q_OBJECT
public:
explicit AnimationWidget(EffectMetaInfo *info, int clipPos, int min, int max, int effectIn, const QString &effectId, const QDomElement &xml,
QWidget *parent = nullptr);
AnimationWidget(std::shared_ptr<AssetParameterModel> model, QModelIndex index, QWidget *parent);
//explicit AnimationWidget(EffectMetaInfo *info, int clipPos, int min, int max, int effectIn, const QString &effectId, const QDomElement &xml,QWidget *parent = nullptr);
virtual ~AnimationWidget();
void updateTimecodeFormat();
void addParameter(const QDomElement &e);
void addParameter(QModelIndex ix);
const QMap<QString, QString> getAnimation();
static QString getDefaultKeyframes(int start, const QString &defaultValue, bool linearOnly = false);
void setActiveKeyframe(int frame);
......@@ -63,7 +65,8 @@ public:
private:
AnimKeyframeRuler *m_ruler;
Monitor *m_monitor;
QPoint m_frameSize;
QSize m_frameSize;
QSize m_monitorSize;
TimecodeDisplay *m_timePos;
KDualAction *m_addKeyframe;
QComboBox *m_presetCombo;
......@@ -108,8 +111,8 @@ private:
void updateSlider(int pos);
void updateRect(int pos);
/** @brief Create widget to adjust param value */
void buildSliderWidget(const QString &paramTag, const QDomElement &e);
void buildRectWidget(const QString &paramTag, const QDomElement &e);
void buildSliderWidget(const QString &paramTag, QModelIndex ix);
void buildRectWidget(const QString &paramTag, QModelIndex ix);
/** @brief Calculate path for keyframes centers and send to monitor */
void setupMonitor(QRect r = QRect());
/** @brief Returns the default value for a parameter from its name */
......@@ -120,6 +123,13 @@ private:
public slots:
void slotSyncPosition(int relTimelinePos);
void slotPositionChanged(int pos = -1, bool seek = true);
/** @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;
private slots:
void slotPrevious();
......@@ -166,9 +176,10 @@ private slots:
void slotLockRatio();
void slotAdjustRectHeight();
void slotAdjustRectWidth();
/** @brief Seek monitor. */
void requestSeek(int pos);
signals:
void seekToPos(int);
/** @brief keyframes dropped / pasted on widget, import them. */
void setKeyframes(const QString &);
void valueChanged();
......
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