Fix dragging of clips with audio or video stream disabled

parent 7207f91a
......@@ -151,6 +151,9 @@ QVariant AbstractProjectItem::getData(DataType type) const
case ClipType:
data = clipType();
break;
case ClipHasAudioAndVideo:
data = hasAudioAndVideo();
break;
case JobType:
if (itemType() == ClipItem) {
auto jobIds = pCore->jobManager()->getPendingJobsIds(clipId());
......
......@@ -76,6 +76,8 @@ public:
virtual std::shared_ptr<ProjectClip> clipAt(int ix) = 0;
/** @brief Recursively disable/enable bin effects. */
virtual void setBinEffectsEnabled(bool enabled) = 0;
/** @brief Returns true if item has both audio and video enabled. */
virtual bool hasAudioAndVideo() const = 0;
/** @brief This function executes what should be done when the item is deleted
but without deleting effectively.
......@@ -132,7 +134,8 @@ public:
JobStatus,
// Item status (ready or not, missing, waiting, ...)
ClipStatus,
ClipType
ClipType,
ClipHasAudioAndVideo
};
enum CLIPSTATUS { StatusReady = 0, StatusMissing, StatusWaiting, StatusDeleting };
......
......@@ -229,7 +229,8 @@ public:
// Add audio/video icons for selective drag
int cType = index.data(AbstractProjectItem::ClipType).toInt();
if ((cType == ClipType::AV || cType == ClipType::Playlist) && (opt.state & QStyle::State_MouseOver)) {
bool hasAudioAndVideo = index.data(AbstractProjectItem::ClipHasAudioAndVideo).toBool();
if (hasAudioAndVideo && (cType == ClipType::AV || cType == ClipType::Playlist) && (opt.state & QStyle::State_MouseOver)) {
bounding.moveLeft(bounding.right() + (2 * textMargin));
bounding.adjust(0, textMargin, 0, -textMargin);
QIcon aDrag = QIcon::fromTheme(QStringLiteral("audio-volume-medium"));
......
......@@ -347,6 +347,23 @@ void ProjectClip::setThumbnail(const QImage &img)
}
}
bool ProjectClip::hasAudioAndVideo() const
{
return hasAudio() && hasVideo() && m_masterProducer->get_int("set.test_image") == 0 && m_masterProducer->get_int("set.test_audio") == 0;
}
bool ProjectClip::isCompatible(PlaylistState::ClipState state) const
{
switch (state) {
case PlaylistState::AudioOnly:
return hasAudio() && (m_masterProducer->get_int("set.test_audio") == 0);
case PlaylistState::VideoOnly:
return hasVideo() && (m_masterProducer->get_int("set.test_image") == 0);
default:
return true;
}
}
QPixmap ProjectClip::thumbnail(int width, int height)
{
return m_thumbnail.pixmap(width, height);
......
......@@ -105,8 +105,15 @@ public:
bool selfSoftDelete(Fun &undo, Fun &redo) override;
/** @brief Returns true if item has both audio and video enabled. */
bool hasAudioAndVideo() const override;
/** @brief Check if clip has a parent folder with id id */
bool hasParent(const QString &id) const;
/** @brief Returns true is the clip can have the requested state */
bool isCompatible(PlaylistState::ClipState state) const;
ClipPropertiesController *buildProperties(QWidget *parent);
QPoint zone() const override;
......
......@@ -158,3 +158,8 @@ ClipType::ProducerType ProjectFolder::clipType() const
{
return ClipType::Unknown;
}
bool ProjectFolder::hasAudioAndVideo() const
{
return false;
}
......@@ -83,6 +83,8 @@ public:
/** @brief Returns a list of all children and sub-children clips. */
QList<std::shared_ptr<ProjectClip>> childClips();
ClipType::ProducerType clipType() const override;
/** @brief Returns true if item has both audio and video enabled. */
bool hasAudioAndVideo() const override;
};
#endif
......@@ -83,3 +83,7 @@ ClipType::ProducerType ProjectFolderUp::clipType() const
return ClipType::Unknown;
}
bool ProjectFolderUp::hasAudioAndVideo() const
{
return false;
}
......@@ -74,6 +74,8 @@ public:
QString getToolTip() const override;
bool rename(const QString &name, int column) override;
ClipType::ProducerType clipType() const override;
/** @brief Returns true if item has both audio and video enabled. */
bool hasAudioAndVideo() const override;
private:
Bin *m_bin;
......
......@@ -167,3 +167,8 @@ ClipType::ProducerType ProjectSubClip::clipType() const
{
return m_masterClip->clipType();
}
bool ProjectSubClip::hasAudioAndVideo() const
{
return m_masterClip->hasAudioAndVideo();
}
......@@ -78,6 +78,8 @@ public:
QPoint zone() const override;
QString getToolTip() const override;
bool rename(const QString &name, int column) override;
/** @brief Returns true if item has both audio and video enabled. */
bool hasAudioAndVideo() const override;
/** @brief returns a pointer to the parent clip */
std::shared_ptr<ProjectClip> getMasterClip() const;
......
......@@ -810,9 +810,6 @@ int TimelineModel::suggestCompositionMove(int compoId, int trackId, int position
bool TimelineModel::requestClipCreation(const QString &binClipId, int &id, PlaylistState::ClipState state, Fun &undo, Fun &redo)
{
qDebug() << "requestClipCreation " << binClipId;
int clipId = TimelineModel::getNextId();
id = clipId;
Fun local_undo = deregisterClip_lambda(clipId);
QString bid = binClipId;
if (binClipId.contains(QLatin1Char('/'))) {
bid = binClipId.section(QLatin1Char('/'), 0, 0);
......@@ -820,6 +817,13 @@ bool TimelineModel::requestClipCreation(const QString &binClipId, int &id, Playl
if (!pCore->projectItemModel()->hasClip(bid)) {
return false;
}
std::shared_ptr<ProjectClip> master = pCore->projectItemModel()->getClipByBinID(bid);
if (!master->isCompatible(state)) {
return false;
}
int clipId = TimelineModel::getNextId();
id = clipId;
Fun local_undo = deregisterClip_lambda(clipId);
ClipModel::construct(shared_from_this(), bid, clipId, state);
auto clip = m_allClips[clipId];
Fun local_redo = [clip, this, state]() {
......@@ -901,7 +905,8 @@ bool TimelineModel::requestClipInsertion(const QString &binClipId, int trackId,
res = requestClipCreation(binClipId, id, getTrackById_const(trackId)->trackType(), local_undo, local_redo);
res = res && requestClipMove(id, trackId, position, refreshView, logUndo, local_undo, local_redo);
int target_track = audioDrop ? m_videoTarget : m_audioTarget;
if (res && (!useTargets || target_track > -1)) {
qDebug()<<"CLIP HAS A+V: "<<master->hasAudioAndVideo();
if (res && (!useTargets || target_track > -1) && master->hasAudioAndVideo()) {
if (!useTargets) {
target_track = audioDrop ? getMirrorVideoTrackId(trackId) : getMirrorAudioTrackId(trackId);
}
......
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