Commit dc964b3e authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle
Browse files

Make ClipType available to qml (solves slideshow thumbnails)

parent b0d178a5
......@@ -1261,7 +1261,7 @@ void Bin::selectProxyModel(const QModelIndex &id)
m_locateAction->setEnabled(true);
m_duplicateAction->setEnabled(true);
std::shared_ptr<ProjectClip> clip = std::static_pointer_cast<ProjectClip>(currentItem);
ClipType type = clip->clipType();
ClipType::ProducerType type = clip->clipType();
m_openAction->setEnabled(type == ClipType::Image || type == ClipType::Audio || type == ClipType::Text || type == ClipType::TextTemplate);
showClipProperties(clip, false);
m_deleteAction->setText(i18n("Delete Clip"));
......@@ -1455,7 +1455,7 @@ void Bin::rebuildMenu()
void Bin::contextMenuEvent(QContextMenuEvent *event)
{
bool enableClipActions = false;
ClipType type = ClipType::Unknown;
ClipType::ProducerType type = ClipType::Unknown;
bool isFolder = false;
bool isImported = false;
QString clipService;
......@@ -2105,7 +2105,7 @@ void Bin::slotCreateProjectClip()
qCDebug(KDENLIVE_LOG) << "// Error in clip creation action";
return;
}
ClipType type = (ClipType)act->data().toInt();
ClipType::ProducerType type = (ClipType::ProducerType)act->data().toInt();
QStringList folderInfo = getFolderInfo();
QString parentFolder = getCurrentFolder();
switch (type) {
......@@ -2925,7 +2925,7 @@ void Bin::refreshProxySettings()
} else {
QList<std::shared_ptr<ProjectClip>> toProxy;
for (std::shared_ptr<ProjectClip> clp : clipList) {
ClipType t = clp->clipType();
ClipType::ProducerType t = clp->clipType();
if (t == ClipType::Playlist) {
toProxy << clp;
continue;
......
......@@ -37,7 +37,7 @@
#include <QWindow>
namespace {
QDomElement createProducer(QDomDocument &xml, ClipType type, const QString &resource, const QString &name, int duration, const QString &service)
QDomElement createProducer(QDomDocument &xml, ClipType::ProducerType type, const QString &resource, const QString &name, int duration, const QString &service)
{
QDomElement prod = xml.createElement(QStringLiteral("producer"));
xml.appendChild(prod);
......
......@@ -108,7 +108,7 @@ ProjectClip::ProjectClip(const QString &id, const QDomElement &description, cons
m_thumbnail = thumb;
m_markerModel = std::make_shared<MarkerListModel>(m_binId, pCore->projectManager()->undoStack());
if (description.hasAttribute(QStringLiteral("type"))) {
m_clipType = (ClipType)description.attribute(QStringLiteral("type")).toInt();
m_clipType = (ClipType::ProducerType)description.attribute(QStringLiteral("type")).toInt();
if (m_clipType == ClipType::Audio) {
m_thumbnail = KoIconUtils::themedIcon(QStringLiteral("audio-x-generic"));
}
......@@ -186,7 +186,7 @@ bool ProjectClip::audioThumbCreated() const
return (m_audioThumbCreated);
}
ClipType ProjectClip::clipType() const
ClipType::ProducerType ProjectClip::clipType() const
{
return m_clipType;
}
......
......@@ -101,7 +101,7 @@ public:
std::shared_ptr<ProjectClip> clipAt(int ix) override;
/** @brief Returns the clip type as defined in definitions.h */
ClipType clipType() const;
ClipType::ProducerType clipType() const;
bool selfSoftDelete(Fun &undo, Fun &redo) override;
......
......@@ -90,7 +90,9 @@ namespace TimelineMode {
enum EditMode { NormalEdit = 0, OverwriteEdit = 1, InsertEdit = 2 };
}
enum class ClipType {
namespace ClipType {
Q_NAMESPACE
enum ProducerType {
Unknown = 0,
Audio = 1,
Video = 2,
......@@ -105,6 +107,8 @@ enum class ClipType {
TextTemplate = 11,
QText
};
Q_ENUM_NS(ProducerType)
}
enum ProjectItemType { ProjectClipType = 0, ProjectFolderType, ProjectSubclipType };
......
......@@ -349,7 +349,7 @@ bool DocumentChecker::hasErrorInClips()
for (int i = 0; i < max; ++i) {
QDomElement e = m_missingClips.at(i).toElement();
QString clipType;
ClipType type;
ClipType::ProducerType type;
int status = CLIPMISSING;
const QString service = EffectsList::property(e, QStringLiteral("mlt_service"));
QString resource = service == QLatin1String("timewarp") ? EffectsList::property(e, QStringLiteral("warp_resource"))
......@@ -650,7 +650,7 @@ void DocumentChecker::slotSearchClips()
}
} else if (child->data(0, statusRole).toInt() == CLIPMISSING) {
bool perfectMatch = true;
ClipType type = (ClipType)child->data(0, clipTypeRole).toInt();
ClipType::ProducerType type = (ClipType::ProducerType)child->data(0, clipTypeRole).toInt();
QString clipPath;
if (type != ClipType::SlideShow) {
// Slideshows cannot be found with hash / size
......@@ -732,7 +732,7 @@ QString DocumentChecker::searchLuma(const QDir &dir, const QString &file) const
return searchPathRecursively(dir, fname);
}
QString DocumentChecker::searchPathRecursively(const QDir &dir, const QString &fileName, ClipType type) const
QString DocumentChecker::searchPathRecursively(const QDir &dir, const QString &fileName, ClipType::ProducerType type) const
{
QString foundFileName;
QStringList filters;
......@@ -823,7 +823,7 @@ void DocumentChecker::slotEditItem(QTreeWidgetItem *item, int)
return;
}
item->setText(1, url.toLocalFile());
ClipType type = (ClipType)item->data(0, clipTypeRole).toInt();
ClipType::ProducerType type = (ClipType::ProducerType)item->data(0, clipTypeRole).toInt();
bool fixed = false;
if (type == ClipType::SlideShow && QFile::exists(url.adjusted(QUrl::RemoveFilename).toLocalFile())) {
fixed = true;
......
......@@ -63,7 +63,7 @@ private:
Ui::MissingClips_UI m_ui;
QDialog *m_dialog;
QPair<QString, QString> m_rootReplacement;
QString searchPathRecursively(const QDir &dir, const QString &fileName, ClipType type = ClipType::Unknown) const;
QString searchPathRecursively(const QDir &dir, const QString &fileName, ClipType::ProducerType type = ClipType::Unknown) const;
QString searchFileRecursively(const QDir &dir, const QString &matchSize, const QString &matchHash, const QString &fileName) const;
void checkStatus();
QMap<QString, QString> m_missingTitleImages;
......
......@@ -1164,7 +1164,7 @@ void KdenliveDoc::slotProxyCurrentItem(bool doProxy, QList<std::shared_ptr<Proje
// Parse clips
for (int i = 0; i < clipList.count(); ++i) {
std::shared_ptr<ProjectClip> item = clipList.at(i);
ClipType t = item->clipType();
ClipType::ProducerType t = item->clipType();
// Only allow proxy on some clip types
if ((t == ClipType::Video || t == ClipType::AV || t == ClipType::Unknown || t == ClipType::Image || t == ClipType::Playlist ||
t == ClipType::SlideShow) &&
......
......@@ -51,7 +51,7 @@ const QString LoadJob::getDescription() const
}
namespace {
ClipType getTypeForService(const QString &id, const QString &path)
ClipType::ProducerType getTypeForService(const QString &id, const QString &path)
{
if (id.isEmpty()) {
QString ext = path.section(QLatin1Char('.'), -1);
......@@ -245,7 +245,7 @@ bool LoadJob::startJob()
return true;
}
m_resource = Xml::getXmlProperty(m_xml, QStringLiteral("resource"));
ClipType type = static_cast<ClipType>(m_xml.attribute(QStringLiteral("type")).toInt());
ClipType::ProducerType type = static_cast<ClipType::ProducerType>(m_xml.attribute(QStringLiteral("type")).toInt());
if (type == ClipType::Unknown) {
type = getTypeForService(Xml::getXmlProperty(m_xml, QStringLiteral("mlt_service")), m_resource);
}
......
......@@ -55,7 +55,7 @@ bool ProxyJob::startJob()
m_done = true;
return true;
}
ClipType type = binClip->clipType();
ClipType::ProducerType type = binClip->clipType();
bool result;
QString source = binClip->getProducerProperty(QStringLiteral("kdenlive:originalurl"));
int exif = binClip->getProducerIntProperty(QStringLiteral("_exif_orientation"));
......
......@@ -150,6 +150,11 @@ int main(int argc, char *argv[])
1, 0, // major and minor version of the import
"ClipState", // name in QML
"Error: only enums");
qmlRegisterUncreatableMetaObject(ClipType::staticMetaObject, // static meta object
"com.enums", // import statement
1, 0, // major and minor version of the import
"ProducerType", // name in QML
"Error: only enums");
QString mltPath = parser.value(QStringLiteral("mlt-path"));
QUrl url;
if (parser.positionalArguments().count() != 0) {
......
......@@ -512,7 +512,7 @@ void ClipController::resetProducerProperty(const QString &name)
m_masterProducer->parent().set(name.toUtf8().constData(), (char *)nullptr);
}
ClipType ClipController::clipType() const
ClipType::ProducerType ClipController::clipType() const
{
return m_clipType;
}
......
......@@ -87,7 +87,7 @@ public:
const QString clipUrl() const;
/** @brief Returns the clip's type as defined in definitions.h */
ClipType clipType() const;
ClipType::ProducerType clipType() const;
/** @brief Returns the MLT's producer id */
const QString binId() const;
......@@ -216,7 +216,7 @@ protected:
QString m_path;
int m_audioIndex;
int m_videoIndex;
ClipType m_clipType;
ClipType::ProducerType m_clipType;
bool m_hasLimitedDuration;
QMutex m_effectMutex;
void getInfoForProducer();
......
......@@ -94,7 +94,7 @@ private:
QLabel *m_clipLabel;
Timecode m_tc;
QString m_id;
ClipType m_type;
ClipType::ProducerType m_type;
Mlt::Properties m_properties;
QMap<QString, QString> m_originalProperties;
QMap<QString, QString> m_clipProperties;
......
......@@ -111,7 +111,7 @@ ArchiveWidget::ArchiveWidget(const QString &projectName, const QDomDocument &doc
for (int i = 0; i < list.count(); ++i) {
const std::shared_ptr<ClipController> &clip = list.at(i);
ClipType t = clip->clipType();
ClipType::ProducerType t = clip->clipType();
QString id = clip->binId();
if (t == ClipType::Color) {
continue;
......
......@@ -50,6 +50,7 @@ ClipModel::ClipModel(std::shared_ptr<TimelineModel> parent, std::shared_ptr<Mlt:
std::shared_ptr<ProjectClip> binClip = pCore->projectItemModel()->getClipByBinID(m_binClipId);
m_canBeVideo = binClip->hasVideo();
m_canBeAudio = binClip->hasAudio();
m_clipType = binClip->clipType();
if (binClip) {
m_endlessResize = !binClip->hasLimitedDuration();
} else {
......@@ -548,18 +549,12 @@ PlaylistState::ClipState ClipModel::clipState() const
{
READ_LOCK();
return m_currentState;
/*
if (service()->parent().get_int("audio_index") == -1) {
if (service()->parent().get_int("video_index") == -1) {
return PlaylistState::Disabled;
} else {
return PlaylistState::VideoOnly;
}
} else if (service()->parent().get_int("video_index") == -1) {
return PlaylistState::AudioOnly;
}
return PlaylistState::Original;
*/
}
ClipType::ProducerType ClipModel::clipType() const
{
READ_LOCK();
return m_clipType;
}
void ClipModel::passTimelineProperties(std::shared_ptr<ClipModel> other)
......
......@@ -84,6 +84,8 @@ public:
/** @brief Returns the timeline clip status (video / audio only) */
PlaylistState::ClipState clipState() const;
/** @brief Returns the bin clip type (image, color, AV, ...) */
ClipType::ProducerType clipType() const;
/** @brief Sets the timeline clip status (video / audio only) */
bool setClipState(PlaylistState::ClipState state, Fun &undo, Fun &redo);
......@@ -181,6 +183,7 @@ protected:
bool forceThumbReload; // Used to trigger a forced thumb reload, when producer changes
PlaylistState::ClipState m_currentState;
ClipType::ProducerType m_clipType;
double m_speed = -1; // Speed of the clip
......
......@@ -269,6 +269,8 @@ QVariant TimelineItemModel::data(const QModelIndex &index, int role) const
}
case StatusRole:
return QVariant::fromValue(clip->clipState());
case TypeRole:
return QVariant::fromValue(clip->clipType());
case StartRole:
return clip->getPosition();
case DurationRole:
......
......@@ -684,7 +684,7 @@ bool TimelineModel::requestClipInsertion(const QString &binClipId, int trackId,
if (getTrackById_const(trackId)->isLocked()) {
return false;
}
ClipType type = ClipType::Unknown;
ClipType::ProducerType type = ClipType::Unknown;
QString bid = binClipId.section(QLatin1Char('/'), 0, 0);
if (!pCore->projectItemModel()->hasClip(bid)) {
return false;
......
......@@ -111,6 +111,7 @@ public:
BinIdRole, /// clip only
MarkersRole, /// clip only
StatusRole, /// clip only
TypeRole, /// clip only
KeyframesRole,
DurationRole,
InPointRole, /// clip only
......
......@@ -45,6 +45,7 @@ Rectangle {
property var markers
property var keyframeModel
property var clipStatus: 0
property var clipType: 0
property int fadeIn: 0
property int fadeOut: 0
property int binId: 0
......@@ -92,7 +93,7 @@ Rectangle {
}
onClipResourceChanged: {
if (mltService === 'color') {
if (clipType == ProducerType.Color) {
color: Qt.darker(getColor())
}
}
......@@ -159,7 +160,7 @@ Rectangle {
if (clipStatus == ClipState.Disabled) {
return 'grey'
}
if (mltService === 'color') {
if (clipType == ProducerType.Color) {
var color = clipResource.substring(clipResource.length - 9)
if (color[0] == '#') {
return color
......@@ -190,9 +191,8 @@ Rectangle {
}
}
}
property bool variableThumbs: (isAudio || mltService === 'color' || mltService === '')
property bool isImage: (mltService === 'qimage' || mltService === 'pixbuf')
property string serviceHolder: isImage ? 'image' : (mltService === 'timewarp' ? 'avformat' : mltService)
property bool variableThumbs: (isAudio || clipType == ProducerType.Color || mltService === '')
property bool isImage: clipType == ProducerType.Image
property string baseThumbPath: variableThumbs ? '' : 'image://thumbnail/' + binId + '/' + (isImage ? '#0' : '#')
property string inThumbPath: (variableThumbs || isImage ) ? baseThumbPath : baseThumbPath + Math.floor(inPoint * speed)
property string outThumbPath: (variableThumbs || isImage ) ? baseThumbPath : baseThumbPath + Math.floor(outPoint * speed)
......
......@@ -200,6 +200,7 @@ Column{
}
onLoaded: {
item.clipId= model.item
item.clipType = model.clipType
if (loader.item.isComposition === false) {
console.log('loaded clip: ', model.start, ', ID: ', model.item, ', index: ', trackRoot.DelegateModel.itemsIndex)
item.isAudio= model.audio
......
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