Start implementing razor tool

parent b046c17a
......@@ -2859,7 +2859,7 @@ void MainWindow::slotChangeEdit(QAction *action)
void MainWindow::slotSetTool(ProjectTool tool)
{
if (pCore->projectManager()->current() && pCore->projectManager()->currentTimeline()) {
if (pCore->currentDoc()) {
// pCore->projectManager()->current()->setTool(tool);
QString message;
switch (tool) {
......@@ -2874,7 +2874,7 @@ void MainWindow::slotSetTool(ProjectTool tool)
break;
}
m_messageLabel->setMessage(message, InformationMessage);
pCore->projectManager()->currentTimeline()->projectView()->setTool(tool);
m_timelineTabs->getCurrentTimeline()->setTool(tool);
}
}
......
......@@ -132,6 +132,7 @@ Rectangle {
onAudioLevelsChanged: generateWaveform()
MouseArea {
id: mouseArea
enabled: root.activeTool === 0
anchors.fill: parent
acceptedButtons: Qt.LeftButton
drag.target: parent
......
......@@ -70,6 +70,7 @@ Rectangle {
}
property int headerWidth: 140
property int activeTool: 0
property real baseUnit: fontMetrics.font.pointSize
property int currentTrack: 0
property color selectedTrackColor: Qt.rgba(activePalette.highlight.r, activePalette.highlight.g, activePalette.highlight.b, 0.4)
......@@ -366,22 +367,31 @@ Rectangle {
menu.clickedY = mouse.y
menu.popup()
} else {
console.log("Position changed: ",timeline.position)
timeline.seekPosition = (scrollView.flickableItem.contentX + mouse.x) / timeline.scaleFactor
timeline.position = timeline.seekPosition
if (root.activeTool === 1 && mouse.y > ruler.height) {
timeline.cutClipUnderCursor((scrollView.flickableItem.contentX + mouse.x) / timeline.scaleFactor)
} else {
timeline.seekPosition = (scrollView.flickableItem.contentX + mouse.x) / timeline.scaleFactor
timeline.position = timeline.seekPosition
}
}
}
property bool scim: false
onReleased: scim = false
onExited: scim = false
onExited: {
scim = false
}
onPositionChanged: {
if ( mouse.buttons === Qt.LeftButton) {
timeline.seekPosition = (scrollView.flickableItem.contentX + mouse.x) / timeline.scaleFactor
timeline.position = timeline.seekPosition
scim = true
}
else
else {
scim = false
if (root.activeTool === 1) {
cutLine.x = Math.floor((scrollView.flickableItem.contentX + mouse.x) / timeline.scaleFactor) * timeline.scaleFactor - scrollView.flickableItem.contentX
}
}
}
Timer {
id: scrubTimer
......@@ -557,6 +567,17 @@ Rectangle {
x: timeline.seekPosition * timeline.scaleFactor - scrollView.flickableItem.contentX
y: 0
}
Rectangle {
id: cutLine
visible: root.activeTool == 1
color: 'red'
width: Math.max(1, 1 * timeline.scaleFactor)
opacity: (width > 2) ? 0.5 : 1
height: root.height - scrollView.__horizontalScrollBar.height - ruler.height
x: 0
//x: timeline.position * timeline.scaleFactor - scrollView.flickableItem.contentX
y: ruler.height
}
TimelinePlayhead {
id: playhead
visible: timeline.position > -1
......
......@@ -30,6 +30,7 @@
#include "project/projectmanager.h"
#include "timeline2/model/timelineitemmodel.hpp"
#include "timelinewidget.h"
#include "utils/KoIconUtils.h"
#include <KActionCollection>
#include <QApplication>
......@@ -436,11 +437,14 @@ void TimelineController::setZoneOut(int outPoint)
emit zoneMoved(m_zone);
}
void TimelineController::cutClipUnderCursor()
void TimelineController::cutClipUnderCursor(int position)
{
if (position == -1) {
position = m_position;
}
bool foundClip = false;
for (int cid : m_selection.selectedClips) {
if (m_model->requestClipCut(cid, m_position)) {
if (m_model->requestClipCut(cid, position)) {
foundClip = true;
}
}
......@@ -450,9 +454,9 @@ void TimelineController::cutClipUnderCursor()
Q_RETURN_ARG(QVariant, returnedValue));
int trackId = returnedValue.toInt();
if (trackId >= 0) {
int cid = m_model->getClipByPosition(trackId, m_position);
int cid = m_model->getClipByPosition(trackId, position);
if (cid >= 0) {
m_model->requestClipCut(cid, m_position);
m_model->requestClipCut(cid, position);
foundClip = true;
}
}
......
......@@ -190,7 +190,7 @@ public:
void checkDuration();
/* @brief Cuts the clip on current track at timeline position
*/
void cutClipUnderCursor();
Q_INVOKABLE void cutClipUnderCursor(int position = -1);
/* @brief Seeks to selected clip start / end
*/
void seekCurrentClip(bool seekToEnd = false);
......
......@@ -33,6 +33,7 @@
#include "qmltypes/thumbnailprovider.h"
#include "timelinecontroller.h"
#include "transitions/transitionlist/model/transitiontreemodel.hpp"
#include "utils/KoIconUtils.h"
#include <KDeclarative/KDeclarative>
// #include <QUrl>
......@@ -133,3 +134,19 @@ void TimelineWidget::zoneUpdated(const QPoint &zone)
{
m_proxy->setZone(zone);
}
void TimelineWidget::setTool(ProjectTool tool)
{
switch (tool) {
case SpacerTool:
break;
case RazorTool: {
QIcon razorIcon = KoIconUtils::themedIcon(QStringLiteral("edit-cut"));
setCursor(QCursor(razorIcon.pixmap(32, 32)));
break;
}
default:
break;
}
rootObject()->setProperty("activeTool", (int) tool);
}
......@@ -47,6 +47,7 @@ public:
*/
Mlt::Tractor *tractor();
TimelineController *controller();
void setTool(ProjectTool tool);
protected:
void mousePressEvent(QMouseEvent *event) override;
......
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