*Use menu position for insert/remove space when necessary

*Show warning when paste cannot be performed
parent 25daf0c1
Pipeline #14623 passed with stage
in 23 minutes and 45 seconds
......@@ -1460,32 +1460,37 @@ bool TimelineFunctions::pasteClips(const std::shared_ptr<TimelineItemModel> &tim
if (res) {
std::shared_ptr<EffectStackModel> destStack = timeline->getClipEffectStackModel(newId);
destStack->fromXml(prod.firstChildElement(QStringLiteral("effects")), undo, redo);
} else {
break;
}
}
// Compositions
for (int i = 0; res && i < compositions.count(); i++) {
QDomElement prod = compositions.at(i).toElement();
QString originalId = prod.attribute(QStringLiteral("composition"));
int in = prod.attribute(QStringLiteral("in")).toInt();
int out = prod.attribute(QStringLiteral("out")).toInt();
int curTrackId = tracksMap.value(prod.attribute(QStringLiteral("track")).toInt());
int aTrackId = prod.attribute(QStringLiteral("a_track")).toInt();
if (aTrackId > 0) {
aTrackId = timeline->getTrackPosition(tracksMap.value(aTrackId));
}
int pos = prod.attribute(QStringLiteral("position")).toInt() - offset;
int newId;
auto transProps = std::make_unique<Mlt::Properties>();
QDomNodeList props = prod.elementsByTagName(QStringLiteral("property"));
for (int j = 0; j < props.count(); j++) {
transProps->set(props.at(j).toElement().attribute(QStringLiteral("name")).toUtf8().constData(),
if (res) {
for (int i = 0; res && i < compositions.count(); i++) {
QDomElement prod = compositions.at(i).toElement();
QString originalId = prod.attribute(QStringLiteral("composition"));
int in = prod.attribute(QStringLiteral("in")).toInt();
int out = prod.attribute(QStringLiteral("out")).toInt();
int curTrackId = tracksMap.value(prod.attribute(QStringLiteral("track")).toInt());
int aTrackId = prod.attribute(QStringLiteral("a_track")).toInt();
if (aTrackId > 0) {
aTrackId = timeline->getTrackPosition(tracksMap.value(aTrackId));
}
int pos = prod.attribute(QStringLiteral("position")).toInt() - offset;
int newId;
auto transProps = std::make_unique<Mlt::Properties>();
QDomNodeList props = prod.elementsByTagName(QStringLiteral("property"));
for (int j = 0; j < props.count(); j++) {
transProps->set(props.at(j).toElement().attribute(QStringLiteral("name")).toUtf8().constData(),
props.at(j).toElement().text().toUtf8().constData());
}
res = res && timeline->requestCompositionInsertion(originalId, curTrackId, aTrackId, position + pos, out - in + 1, std::move(transProps), newId, undo, redo);
}
res = timeline->requestCompositionInsertion(originalId, curTrackId, aTrackId, position + pos, out - in + 1, std::move(transProps), newId, undo, redo);
}
if (!res) {
undo();
pCore->displayMessage(i18n("Could not paste items in timeline"), InformationMessage, 500);
return false;
}
// Rebuild groups
......
......@@ -134,7 +134,11 @@ Rectangle {
}
function getMousePos() {
return (scrollView.contentX + tracksArea.mouseX) / timeline.scaleFactor
if (tracksArea.containsMouse) {
return (scrollView.contentX + tracksArea.mouseX) / timeline.scaleFactor
} else {
return -1;
}
}
function getScrollPos() {
......
......@@ -200,7 +200,7 @@ QMap<int, QString> TimelineController::getTrackNames(bool videoOnly)
void TimelineController::setScaleFactorOnMouse(double scale, bool zoomOnMouse)
{
if (m_root) {
m_root->setProperty("zoomOnMouse", zoomOnMouse ? qMin(getMousePos(), duration()) : -1);
m_root->setProperty("zoomOnMouse", zoomOnMouse ? qBound(0, getMousePos(), duration()) : -1);
m_scale = scale;
emit scaleFactorChanged();
} else {
......@@ -1147,10 +1147,10 @@ void TimelineController::seekToClip(int cid, bool seekToEnd)
void TimelineController::seekToMouse()
{
QVariant returnedValue;
QMetaObject::invokeMethod(m_root, "getMousePos", Q_RETURN_ARG(QVariant, returnedValue));
int mousePos = returnedValue.toInt();
setPosition(mousePos);
int mousePos = getMousePos();
if (mousePos > -1) {
setPosition(mousePos);
}
}
int TimelineController::getMousePos()
......@@ -1526,11 +1526,20 @@ QMap<QString, QString> TimelineController::documentProperties()
return props;
}
void TimelineController::insertSpace(int trackId, int frame)
int TimelineController::getMenuOrTimelinePos() const
{
int frame = m_root->property("mainFrame").toInt();
if (frame == -1) {
frame = pCore->getTimelinePosition();
}
return frame;
}
void TimelineController::insertSpace(int trackId, int frame)
{
if (frame == -1) {
frame = getMenuOrTimelinePos();
}
if (trackId == -1) {
trackId = m_activeTrack;
}
......@@ -1553,7 +1562,7 @@ void TimelineController::insertSpace(int trackId, int frame)
void TimelineController::removeSpace(int trackId, int frame, bool affectAllTracks)
{
if (frame == -1) {
frame = pCore->getTimelinePosition();
frame = getMenuOrTimelinePos();
}
if (trackId == -1) {
trackId = m_activeTrack;
......
......@@ -547,6 +547,7 @@ private:
void initializePreview();
bool darkBackground() const;
int getMenuOrTimelinePos() const;
signals:
void selected(Mlt::Producer *producer);
......
......@@ -326,6 +326,10 @@ void TimelineWidget::slotUngrabHack()
// https://phabricator.kde.org/D5515
if (quickWindow() && quickWindow()->mouseGrabberItem()) {
quickWindow()->mouseGrabberItem()->ungrabMouse();
// Reset menu position
QTimer::singleShot(200, this, [this]() {
rootObject()->setProperty("mainFrame", -1);
});
}
}
......
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