Hover drag displays clip/transition settings to allow improved dropping

parent ba1d66e7
......@@ -49,6 +49,9 @@ AbstractClipItem::AbstractClipItem(const ItemInfo &info, const QRectF& rect, dou
setFlag(QGraphicsItem::ItemUsesExtendedStyleOption, true);
setPen(Qt::NoPen);
connect(&m_keyframeView, SIGNAL(updateKeyframes(const QRectF&)), this, SLOT(doUpdate(const QRectF&)));
m_selectionTimer.setSingleShot(true);
m_selectionTimer.setInterval(1000);
QObject::connect(&m_selectionTimer, &QTimer::timeout, this, &AbstractClipItem::slotSelectItem);
}
AbstractClipItem::~AbstractClipItem()
......@@ -326,6 +329,11 @@ void AbstractClipItem::mouseMoveEvent(QGraphicsSceneMouseEvent * event)
}
}
void AbstractClipItem::slotSelectItem()
{
emit selectItem(this);
}
int AbstractClipItem::itemHeight()
{
return 0;
......
......@@ -30,6 +30,7 @@
#include <QGraphicsRectItem>
#include <QGraphicsWidget>
#include <QTimer>
class CustomTrackScene;
class QGraphicsSceneMouseEvent;
......@@ -102,12 +103,14 @@ public:
private slots:
void doUpdate(const QRectF &r);
void slotSelectItem();
protected:
ItemInfo m_info;
GenTime m_maxDuration;
int m_visibleParam;
int m_selectedEffect;
QTimer m_selectionTimer;
double m_fps;
/** @brief True if this is the last clip the user selected */
bool m_isMainSelectedClip;
......@@ -118,6 +121,9 @@ protected:
void mouseMoveEvent(QGraphicsSceneMouseEvent * event);
int trackForPos(int position);
int posForTrack(int track);
signals:
void selectItem(AbstractClipItem*);
};
#endif
......@@ -1609,6 +1609,8 @@ int ClipItem::nextFreeEffectGroupIndex() const
void ClipItem::dropEvent(QGraphicsSceneDragDropEvent * event)
{
if (event->proposedAction() == Qt::CopyAction && scene() && !scene()->views().isEmpty()) {
if (m_selectionTimer.isActive())
m_selectionTimer.stop();
QString effects;
bool transitionDrop = false;
if (event->mimeData()->hasFormat(QStringLiteral("kdenlive/transitionslist"))) {
......@@ -1657,12 +1659,22 @@ void ClipItem::dragEnterEvent(QGraphicsSceneDragDropEvent *event)
if (isItemLocked()) event->setAccepted(false);
else if (event->mimeData()->hasFormat(QStringLiteral("kdenlive/effectslist")) || event->mimeData()->hasFormat(QStringLiteral("kdenlive/transitionslist"))) {
event->acceptProposedAction();
m_selectionTimer.start();
} else event->setAccepted(false);
}
void ClipItem::dragLeaveEvent(QGraphicsSceneDragDropEvent *event)
{
Q_UNUSED(event)
if (m_selectionTimer.isActive())
m_selectionTimer.stop();
}
void ClipItem::dragMoveEvent(QGraphicsSceneDragDropEvent *event)
{
QGraphicsItem::dragMoveEvent(event);
if (m_selectionTimer.isActive() && !isSelected())
m_selectionTimer.start();
}
void ClipItem::addTransition(Transition* t)
......
......@@ -197,6 +197,7 @@ public:
protected:
void dragEnterEvent(QGraphicsSceneDragDropEvent *event);
void dragLeaveEvent(QGraphicsSceneDragDropEvent *event);
void dragMoveEvent(QGraphicsSceneDragDropEvent *event);
void dropEvent(QGraphicsSceneDragDropEvent *event);
//virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *);
//virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *);
......
......@@ -1765,8 +1765,6 @@ void CustomTrackView::insertClipCut(const QString &id, int in, int out)
bool CustomTrackView::insertDropClips(const QMimeData *data, const QPoint &pos)
{
QPointF framePos = mapToScene(pos);
int track = getTrackFromPos(framePos.y());
m_clipDrag = data->hasFormat(QStringLiteral("kdenlive/clip")) || data->hasFormat(QStringLiteral("kdenlive/producerslist"));
// This is not a clip drag, maybe effect or other...
if (!m_clipDrag) return false;
......@@ -1775,6 +1773,8 @@ bool CustomTrackView::insertDropClips(const QMimeData *data, const QPoint &pos)
m_dragItem->setMainSelectedClip(false);
m_dragItem = NULL;
resetSelectionGroup(false);
QPointF framePos = mapToScene(pos);
int track = getTrackFromPos(framePos.y());
QMutexLocker lock(&m_selectionMutex);
if (track <= 0 || track > m_timeline->tracksCount() - 1 || m_timeline->getTrackInfo(track).isLocked) return true;
if (data->hasFormat(QStringLiteral("kdenlive/clip"))) {
......@@ -1807,6 +1807,7 @@ bool CustomTrackView::insertDropClips(const QMimeData *data, const QPoint &pos)
}
m_selectionGroup = new AbstractGroupItem(m_document->fps());
ClipItem *item = new ClipItem(clip, info, m_document->fps(), 1.0, 1, getFrameWidth());
connect(item, &AbstractClipItem::selectItem, this, &CustomTrackView::slotSelectItem);
m_selectionGroup->addItem(item);
QList <GenTime> offsetList;
......@@ -1895,6 +1896,7 @@ bool CustomTrackView::insertDropClips(const QMimeData *data, const QPoint &pos)
start += info.cropDuration;
offsetList.append(start);
ClipItem *item = new ClipItem(clip, info, m_document->fps(), 1.0, 1, getFrameWidth(), true);
connect(item, &AbstractClipItem::selectItem, this, &CustomTrackView::slotSelectItem);
item->setPos(info.startPos.frames(m_document->fps()), item->itemOffset());
if (ids.size() > 1) m_selectionGroup->addItem(item);
else {
......@@ -1940,8 +1942,7 @@ void CustomTrackView::dragEnterEvent(QDragEnterEvent * event)
event->setDropAction(Qt::MoveAction);
event->acceptProposedAction();
}
}
else {
} else {
QGraphicsView::dragEnterEvent(event);
}
}
......@@ -2138,6 +2139,18 @@ void CustomTrackView::slotDropEffect(ClipItem *clip, QDomElement effect, GenTime
}
}
void CustomTrackView::slotSelectItem(AbstractClipItem *item)
{
clearSelection(false);
m_dragItem = item;
m_dragItem->setMainSelectedClip(true);
item->setSelected(true);
if (item->type() == AVWidget)
emit clipItemSelected((ClipItem*)item);
else if (item->type() == TransitionWidget)
emit transitionItemSelected((Transition*)item);
}
void CustomTrackView::slotDropTransition(ClipItem *clip, QDomElement transition, QPointF scenePos)
{
if (clip == NULL) return;
......@@ -2587,6 +2600,7 @@ ClipItem *CustomTrackView::cutClip(const ItemInfo &info, const GenTime &cutTime,
bool snap = KdenliveSettings::snaptopoints();
KdenliveSettings::setSnaptopoints(false);
ClipItem *dup = item->clone(newPos);
connect(dup, &AbstractClipItem::selectItem, this, &CustomTrackView::slotSelectItem);
dup->binClip()->addRef();
dup->setPos(newPos.startPos.frames(m_document->fps()), getPositionFromTrack(newPos.track) + 1 + dup->itemOffset());
......@@ -2770,6 +2784,7 @@ void CustomTrackView::slotAddTransition(ClipItem* /*clip*/, ItemInfo transitionI
void CustomTrackView::addTransition(const ItemInfo &transitionInfo, int endTrack, const QDomElement &params, bool refresh)
{
Transition *tr = new Transition(transitionInfo, endTrack, m_document->fps(), params, true);
connect(tr, &AbstractClipItem::selectItem, this, &CustomTrackView::slotSelectItem);
tr->setPos(transitionInfo.startPos.frames(m_document->fps()), getPositionFromTrack(transitionInfo.track) + tr->itemOffset() + 1);
////qDebug() << "---- ADDING transition " << params.attribute("value");
if (m_timeline->transitionHandler->addTransition(tr->transitionTag(), endTrack, transitionInfo.track, transitionInfo.startPos, transitionInfo.endPos, tr->toXML(), refresh)) {
......@@ -5082,6 +5097,7 @@ void CustomTrackView::addClip(const QString &clipId, ItemInfo info, EffectsList
}
}
ClipItem *item = new ClipItem(binClip, info, m_document->fps(), speed, strobe, getFrameWidth());
connect(item, &AbstractClipItem::selectItem, this, &CustomTrackView::slotSelectItem);
item->setPos(info.startPos.frames(m_document->fps()), getPositionFromTrack(info.track) + 1 + item->itemOffset());
item->setState(state);
item->setEffectList(effects);
......
......@@ -324,7 +324,7 @@ public slots:
* @param offsetList The list of points that should also snap (for example when movin a clip, start and end points should snap
* @param skipSelectedItems if true, the selected item start and end points will not be added to snap list */
void updateSnapPoints(AbstractClipItem *selected, QList <GenTime> offsetList = QList <GenTime> (), bool skipSelectedItems = false);
void slotAddEffect(ClipItem *clip, const QDomElement &effect, int track = -1);
void slotImportClipKeyframes(GraphicsRectItem type, ItemInfo info, QDomElement xml, QMap<QString, QString> data = QMap<QString, QString>());
......@@ -337,6 +337,8 @@ public slots:
void exportTimelineSelection(QString path = QString());
/** Remove zone from current track */
void extractZone(bool closeGap);
/** @brief Select an item in timeline. */
void slotSelectItem(AbstractClipItem *item);
protected:
virtual void drawBackground(QPainter * painter, const QRectF & rect);
......
......@@ -393,7 +393,9 @@ void Timeline::getTransitions() {
else
e.setAttribute(QStringLiteral("value"), value);
}
Transition *tr = new Transition(transitionInfo, a_track, m_doc->fps(), base, QString(prop.get("automatic")) == QLatin1String("1"));
Transition *tr = new Transition(transitionInfo, a_track, m_doc->fps(), base,
QString(prop.get("automatic")) == QLatin1String("1"));
connect(tr, &AbstractClipItem::selectItem, m_trackview, &CustomTrackView::slotSelectItem);
tr->setPos(transitionInfo.startPos.frames(m_doc->fps()), KdenliveSettings::trackheight() * (visibleTracksCount() - transitionInfo.track) + 1 + tr->itemOffset());
if (QString(prop.get("force_track")) == QLatin1String("1")) tr->setForcedTrack(true, a_track);
if (isTrackLocked(b_track)) tr->setItemLocked(true);
......@@ -949,6 +951,7 @@ int Timeline::loadTrack(int ix, int offset, Mlt::Playlist &playlist) {
position += length;
//qDebug()<<"// Loading clip: "<<idString<<" / SPEED: "<<speed<<"\n++++++++++++++++++++++++";
ClipItem *item = new ClipItem(binclip, clipinfo, fps, slowInfo.speed, slowInfo.strobe, m_trackview->getFrameWidth(), true);
connect(item, &AbstractClipItem::selectItem, m_trackview, &CustomTrackView::slotSelectItem);
item->setPos(clipinfo.startPos.frames(fps), KdenliveSettings::trackheight() * (visibleTracksCount() - clipinfo.track) + 1 + item->itemOffset());
//qDebug()<<" * * Loaded clip on tk: "<<clipinfo.track<< ", POS: "<<clipinfo.startPos.frames(fps);
item->updateState(idString);
......
......@@ -134,6 +134,17 @@ void Transition::setTransitionParameters(const QDomElement &params)
else if (m_parameters.attribute(QStringLiteral("force_track")) == QLatin1String("0")) setForcedTrack(false, m_parameters.attribute(QStringLiteral("transition_btrack")).toInt());
m_name = i18n(m_parameters.firstChildElement("name").text().toUtf8().data());
update();
bool hasGeometry = false;
QDomNodeList namenode = m_parameters.elementsByTagName(QStringLiteral("parameter"));
for (int i = 0; i < namenode.count() ; ++i) {
QDomElement pa = namenode.item(i).toElement();
QString paramType = pa.attribute(QStringLiteral("type"));
if (paramType == QLatin1String("geometry") || paramType == QLatin1String("animated")) {
hasGeometry = true;
break;
}
}
setAcceptDrops(hasGeometry);
}
}
......@@ -456,13 +467,30 @@ void Transition::dragEnterEvent(QGraphicsSceneDragDropEvent *event)
if (isItemLocked()) event->setAccepted(false);
else if (event->mimeData()->hasFormat(QStringLiteral("kdenlive/geometry"))) {
event->acceptProposedAction();
m_selectionTimer.start();
} else event->setAccepted(false);
}
void Transition::dragLeaveEvent(QGraphicsSceneDragDropEvent *event)
{
Q_UNUSED(event)
if (m_selectionTimer.isActive())
m_selectionTimer.stop();
}
void Transition::dragMoveEvent(QGraphicsSceneDragDropEvent *event)
{
QGraphicsItem::dragMoveEvent(event);
if (m_selectionTimer.isActive() && !isSelected())
m_selectionTimer.start();
}
//virtual
void Transition::dropEvent(QGraphicsSceneDragDropEvent * event)
{
if (scene() && !scene()->views().isEmpty()) {
if (m_selectionTimer.isActive())
m_selectionTimer.stop();
QString geometry = QString::fromUtf8(event->mimeData()->data(QStringLiteral("kdenlive/geometry")));
event->acceptProposedAction();
CustomTrackView *view = static_cast<CustomTrackView*>(scene()->views().first());
......
......@@ -80,6 +80,8 @@ public:
protected:
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);
void dragEnterEvent(QGraphicsSceneDragDropEvent *event);
void dragLeaveEvent(QGraphicsSceneDragDropEvent *event);
void dragMoveEvent(QGraphicsSceneDragDropEvent *event);
void dropEvent(QGraphicsSceneDragDropEvent *event);
private:
......
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