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

Some trim progress. Ctrl+T enters trim mode and cycles through the different...

Some trim progress. Ctrl+T enters trim mode and cycles through the different modes (ripple, roll, ...)
An indicator shows trim mode in statusbar. Only rolling has a basic inmplementation for now
Ref: T1953
parent 6b3cb898
......@@ -218,7 +218,7 @@ const QString SmallJobLabel::getStyleSheet(const QPalette &p)
QColor bg = scheme.background(KColorScheme::LinkBackground).color();
QColor fg = scheme.foreground(KColorScheme::LinkText).color();
QString style = QStringLiteral("QPushButton {margin:3px;padding:2px;background-color: rgb(%1, %2, %3);border-radius: 4px;border: none;color: rgb(%4, %5, %6)}").arg(bg.red()).arg(bg.green()).arg(bg.blue()).arg(fg.red()).arg(fg.green()).arg(fg.blue());
bg = scheme.background(KColorScheme::ActiveBackground).color();
fg = scheme.foreground(KColorScheme::ActiveText).color();
style.append(QStringLiteral("\nQPushButton:hover {margin:3px;padding:2px;background-color: rgb(%1, %2, %3);border-radius: 4px;border: none;color: rgb(%4, %5, %6)}").arg(bg.red()).arg(bg.green()).arg(bg.blue()).arg(fg.red()).arg(fg.green()).arg(fg.blue()));
......
......@@ -172,6 +172,14 @@ enum CacheType {
CacheThumbs = 5
};
enum TrimMode {
NormalTrim,
RippleTrim,
RollingTrim,
SlipTrim,
SlideTrim
};
class TrackInfo {
public:
......
......@@ -1138,11 +1138,18 @@ void MainWindow::setupActions()
connect(m_zoomIn, SIGNAL(triggered(bool)), this, SLOT(slotZoomIn()));
connect(m_zoomOut, SIGNAL(triggered(bool)), this, SLOT(slotZoomOut()));
m_trimLabel = new QLabel(QStringLiteral(" "), this);
m_trimLabel->setFont(QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont));
//m_trimLabel->setAutoFillBackground(true);
m_trimLabel->setAlignment(Qt::AlignHCenter);
m_trimLabel->setStyleSheet("QLabel { background-color :red; }");
KToolBar *toolbar = new KToolBar(QStringLiteral("statusToolBar"), this, Qt::BottomToolBarArea);
toolbar->setMovable(false);
toolbar->setToolButtonStyle(Qt::ToolButtonIconOnly);
/*QString styleBorderless = QStringLiteral("QToolButton { border-width: 0px;margin: 1px 3px 0px;padding: 0px;}");*/
toolbar->addWidget(m_trimLabel);
toolbar->addAction(m_buttonAutomaticSplitAudio);
toolbar->addAction(m_buttonAutomaticTransition);
toolbar->addAction(m_buttonVideoThumbs);
......@@ -1278,6 +1285,8 @@ void MainWindow::setupActions()
monitorGamma->setCurrentItem(KdenliveSettings::monitor_gamma());
connect(monitorGamma, SIGNAL(triggered(int)), this, SLOT(slotSetMonitorGamma(int)));
addAction(QStringLiteral("switch_trim"), i18n("Trim Mode"), this, SLOT(slotSwitchTrimMode()), KoIconUtils::themedIcon(QStringLiteral("cursor-arrow")), Qt::CTRL + Qt::Key_T);
addAction(QStringLiteral("insert_project_tree"), i18n("Insert Zone in Project Bin"), this, SLOT(slotInsertZoneToTree()), QIcon(), Qt::CTRL + Qt::Key_I);
addAction(QStringLiteral("insert_timeline"), i18n("Insert Zone in Timeline"), this, SLOT(slotInsertZoneToTimeline()), QIcon(), Qt::SHIFT + Qt::CTRL + Qt::Key_I);
......@@ -1855,6 +1864,7 @@ void MainWindow::connectDocument()
connect(pCore->producerQueue(), SIGNAL(infoProcessingFinished()), trackView->projectView(), SLOT(slotInfoProcessingFinished()), Qt::DirectConnection);
connect(trackView->projectView(), SIGNAL(importKeyframes(GraphicsRectItem,QString,QString)), this, SLOT(slotProcessImportKeyframes(GraphicsRectItem,QString,QString)));
connect(trackView->projectView(), &CustomTrackView::updateTrimMode, this, &MainWindow::setTrimMode);
connect(m_projectMonitor, &Monitor::multitrackView, trackView, &Timeline::slotMultitrackView);
connect(m_projectMonitor, SIGNAL(renderPosition(int)), trackView, SLOT(moveCursorPos(int)));
connect(m_projectMonitor, SIGNAL(zoneUpdated(QPoint)), trackView, SLOT(slotSetZone(QPoint)));
......@@ -1946,6 +1956,7 @@ void MainWindow::connectDocument()
//show();
//pCore->monitorManager()->activateMonitor(Kdenlive::ClipMonitor, true);
// set tool to select tool
setTrimMode(QStringLiteral());
m_buttonSelectTool->setChecked(true);
connect(m_projectMonitorDock, SIGNAL(visibilityChanged(bool)), m_projectMonitor, SLOT(slotRefreshMonitor(bool)), Qt::UniqueConnection);
connect(m_clipMonitorDock, SIGNAL(visibilityChanged(bool)), m_clipMonitor, SLOT(slotRefreshMonitor(bool)), Qt::UniqueConnection);
......@@ -3852,6 +3863,22 @@ void MainWindow::forceIconSet(bool force)
}
}
void MainWindow::slotSwitchTrimMode()
{
if (pCore->projectManager()->currentTimeline()) {
pCore->projectManager()->currentTimeline()->projectView()->switchTrimMode();
}
}
void MainWindow::setTrimMode(const QString mode)
{
if (pCore->projectManager()->currentTimeline()) {
m_trimLabel->setText(mode);
m_trimLabel->setVisible(!mode.isEmpty());
}
}
#ifdef DEBUG_MAINW
#undef DEBUG_MAINW
#endif
......@@ -223,6 +223,7 @@ private:
KIconLoader *m_iconLoader;
KToolBar *m_timelineToolBar;
QWidget *m_timelineToolBarContainer;
QLabel *m_trimLabel;
/** @brief initialize startup values, return true if first run. */
bool readOptions();
......@@ -472,6 +473,9 @@ private slots:
void slotUpdateCompositing(QAction *compose);
/** @brief Update compositing action to display current project setting. */
void slotUpdateCompositeAction(int mode);
/** @brief Cycle through the different timeline trim modes. */
void slotSwitchTrimMode();
void setTrimMode(const QString mode);
signals:
Q_SCRIPTABLE void abortRenderJob(const QString &url);
......
......@@ -197,13 +197,16 @@ CustomTrackView::~CustomTrackView()
void CustomTrackView::initTools()
{
m_toolManagers.insert(TrimType, new TrimManager(this, m_commandStack));
TrimManager *trim = new TrimManager(this, m_commandStack);
connect(trim, &TrimManager::updateTrimMode, this, &CustomTrackView::updateTrimMode);
m_toolManagers.insert(TrimType, trim);
m_toolManagers.insert(SpacerType, new SpacerManager(this, m_commandStack));
m_toolManagers.insert(ResizeType, new ResizeManager(this, m_commandStack));
m_toolManagers.insert(RazorType, new RazorManager(this, m_commandStack));
m_toolManagers.insert(MoveType, new MoveManager(m_timeline->transitionHandler, this, m_commandStack));
m_toolManagers.insert(SelectType, new SelectManager(this, m_commandStack));
m_toolManagers.insert(GuideType, new GuideManager(this, m_commandStack));
emit updateTrimMode();
}
//virtual
......@@ -249,12 +252,14 @@ void CustomTrackView::keyPressEvent(QKeyEvent * event)
bool CustomTrackView::event( QEvent * e )
{
if ((m_moveOpMode == RollingEnd || m_moveOpMode == RollingStart) && e->type() == QEvent::ShortcutOverride) {
if (((QKeyEvent*)e)->key() == Qt::Key_Escape) {
TrimManager *mgr = qobject_cast<TrimManager *>(m_toolManagers.value(TrimType));
mgr->endRoll();
e->accept();
return true;
if (e->type() == QEvent::ShortcutOverride) {
TrimManager *mgr = qobject_cast<TrimManager *>(m_toolManagers.value(TrimType));
if (mgr && mgr->trimMode() != NormalTrim) {
if (((QKeyEvent*)e)->key() == Qt::Key_Escape) {
mgr->setTrimMode(NormalTrim);
e->accept();
return true;
}
}
}
return QGraphicsView::event(e);
......@@ -4998,6 +5003,17 @@ ClipItem *CustomTrackView::getClipItemAtMiddlePoint(int pos, int track)
return clip;
}
ClipItem *CustomTrackView::getUpperClipItemAt(int pos)
{
ClipItem *clip = NULL;
for (int i = m_timeline->tracksCount(); i > 0; i--) {
clip = getClipItemAtMiddlePoint(pos, i);
if (clip)
break;
}
return clip;
}
Transition *CustomTrackView::getTransitionItemAt(int pos, int track, bool alreadyMoved)
{
const QPointF p(pos, getPositionFromTrack(track) + Transition::itemOffset() + 1);
......@@ -8653,3 +8669,37 @@ void CustomTrackView::sortGuides()
{
qSort(m_guides.begin(), m_guides.end(), sortGuidesList);
}
void CustomTrackView::switchTrimMode()
{
TrimManager *mgr = qobject_cast<TrimManager *>(m_toolManagers.value(TrimType));
TrimMode mode = (TrimMode) (((int) mgr->trimMode() + 1) %5);
// Find best clip to trim
ItemInfo info;
//TODO: if cursor is not on a cut, switch only between splip and slide
AbstractClipItem *trimItem = NULL;
if (m_dragItem && m_dragItem->type() == AVWidget) {
trimItem = m_dragItem;
} else {
// find topmost clip
trimItem = getUpperClipItemAt(m_cursorPos);
if (trimItem) {
slotSelectItem(trimItem);
}
}
if (trimItem) {
info = trimItem->info();
GenTime cursor(m_cursorPos, m_document->fps());
if (cursor == info.startPos) {
// Start trim at clip start
mgr->setTrimMode(mode, info, true);
} else if (cursor == info.startPos) {
// Start trim at clip end
mgr->setTrimMode(mode, info, false);
} else {
int diffStart = qAbs(m_cursorPos - info.startPos.frames(m_document->fps()));
int diffEnd = qAbs(m_cursorPos - info.endPos.frames(m_document->fps()));
mgr->setTrimMode(mode, info, diffStart < diffEnd);
}
}
}
......@@ -325,6 +325,8 @@ public:
GenTime groupSelectedItems(QList <QGraphicsItem *> selection = QList <QGraphicsItem *>(), bool createNewGroup = false, bool selectNewGroup = false);
void sortGuides();
void initTools();
/** @brief Cycle through timeline trim modes, returns label text for trim mode */
void switchTrimMode();
public slots:
/** @brief Send seek request to MLT. */
......@@ -472,6 +474,9 @@ private:
* @param pos a time value that is inside the clip
* @param track the track where the clip is in MLT coordinates */
ClipItem *getClipItemAtMiddlePoint(int pos, int track);
/** @brief Returns the higher clip at pos on the timeline
* @param pos a time value that is inside the clip */
ClipItem *getUpperClipItemAt(int pos);
/** @brief Returns a moved clip from timeline (means that the item was moved but its ItemInfo coordinates have not been updated yet)
* */
ClipItem *getMovedClipItem(ItemInfo info, GenTime offset, int trackOffset);
......@@ -623,6 +628,7 @@ signals:
/** @brief Select active keyframe in effect stack */
void setActiveKeyframe(int);
void loadMonitorScene(MonitorSceneType,bool);
void updateTrimMode(const QString mode = QString());
};
#endif
......
......@@ -32,6 +32,7 @@
TrimManager::TrimManager(CustomTrackView *view, DocUndoStack *commandStack) : AbstractToolManager(view, commandStack)
, m_firstClip(NULL)
, m_secondClip(NULL)
, m_trimMode(NormalTrim)
{
}
......@@ -127,3 +128,35 @@ void TrimManager::endRoll()
m_firstInfo = ItemInfo();
m_secondInfo = ItemInfo();
}
TrimMode TrimManager::trimMode() const
{
return m_trimMode;
}
void TrimManager::setTrimMode(TrimMode mode, ItemInfo info, bool fromStart)
{
m_trimMode = mode;
QString modeLabel;
switch (m_trimMode) {
case RippleTrim:
modeLabel = i18n(" Ripple ");
break;
case RollingTrim:
modeLabel = i18n(" Rolling ");
break;
case SlideTrim:
modeLabel = i18n(" Slide ");
break;
case SlipTrim:
modeLabel = i18n(" Slip ");
break;
default:
emit updateTrimMode(modeLabel);
endRoll();
return;
break;
}
emit updateTrimMode(modeLabel);
enterTrimMode(info, fromStart);
}
......@@ -40,6 +40,8 @@ public:
void mouseRelease(GenTime pos = GenTime());
bool enterTrimMode(ItemInfo info, bool trimStart);
void moveRoll(bool forward);
void setTrimMode(TrimMode mode, ItemInfo info = ItemInfo(), bool fromStart = true);
TrimMode trimMode() const;
public slots:
void endRoll();
......@@ -49,6 +51,10 @@ private:
ClipItem *m_secondClip;
ItemInfo m_firstInfo;
ItemInfo m_secondInfo;
TrimMode m_trimMode;
signals:
void updateTrimMode(const QString);
};
#endif
......
Supports Markdown
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