timeline: implement track select tool

Fixes #866
This commit is contained in:
itsmattkc
2022-04-11 19:49:50 -07:00
parent 5bb1aa41f7
commit 7ceb5c0914
12 changed files with 169 additions and 8 deletions
+3
View File
@@ -74,6 +74,9 @@ public:
/// Add tool
kAdd,
/// Track select tool
kTrackSelect,
kCount
};
@@ -41,6 +41,7 @@
#include "tool/rolling.h"
#include "tool/slide.h"
#include "tool/slip.h"
#include "tool/trackselect.h"
#include "tool/transition.h"
#include "tool/zoom.h"
#include "tool/tool.h"
@@ -100,6 +101,7 @@ TimelineWidget::TimelineWidget(QWidget *parent) :
tools_.fill(nullptr);
tools_.replace(olive::Tool::kPointer, new PointerTool(this));
tools_.replace(olive::Tool::kTrackSelect, new TrackSelectTool(this));
tools_.replace(olive::Tool::kEdit, new EditTool(this));
tools_.replace(olive::Tool::kRipple, new RippleTool(this));
tools_.replace(olive::Tool::kRolling, new RollingTool(this));
@@ -38,6 +38,8 @@ set(OLIVE_SOURCES
widget/timelinewidget/tool/slide.h
widget/timelinewidget/tool/slip.cpp
widget/timelinewidget/tool/slip.h
widget/timelinewidget/tool/trackselect.cpp
widget/timelinewidget/tool/trackselect.h
widget/timelinewidget/tool/transition.cpp
widget/timelinewidget/tool/transition.h
widget/timelinewidget/tool/tool.cpp
+2 -2
View File
@@ -44,6 +44,7 @@ PointerTool::PointerTool(TimelineWidget *parent) :
trimming_allowed_(true),
track_movement_allowed_(true),
gap_trimming_allowed_(false),
can_rubberband_select_(false),
rubberband_selecting_(false)
{
}
@@ -715,8 +716,7 @@ Timeline::MovementMode PointerTool::IsCursorInTrimHandle(Block *block, qreal cur
}
}
void PointerTool::InitiateDrag(Block *clicked_item,
Timeline::MovementMode trim_mode)
void PointerTool::InitiateDrag(Block *clicked_item, Timeline::MovementMode trim_mode)
{
InitiateDragInternal(clicked_item, trim_mode, false, false, false);
}
+8 -6
View File
@@ -39,8 +39,7 @@ public:
protected:
virtual void FinishDrag(TimelineViewMouseEvent *event);
virtual void InitiateDrag(Block* clicked_item,
Timeline::MovementMode trim_mode);
virtual void InitiateDrag(Block* clicked_item, Timeline::MovementMode trim_mode);
TimelineViewGhostItem* AddGhostFromBlock(Block *block, Timeline::MovementMode mode, bool check_if_exists = false);
@@ -69,10 +68,8 @@ protected:
bool dont_roll_trims,
bool allow_nongap_rolling, bool slide_instead_of_moving);
const Timeline::MovementMode& drag_movement_mode() const
{
return drag_movement_mode_;
}
const Timeline::MovementMode& drag_movement_mode() const { return drag_movement_mode_; }
void set_drag_movement_mode(const Timeline::MovementMode &d) { drag_movement_mode_ = d; }
void SetMovementAllowed(bool e)
{
@@ -94,6 +91,11 @@ protected:
gap_trimming_allowed_ = e;
}
void SetClickedItem(Block *b)
{
clicked_item_ = b;
}
private:
Timeline::MovementMode IsCursorInTrimHandle(Block* block, qreal cursor_x);
@@ -0,0 +1,96 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2021 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#include "trackselect.h"
#include "node/block/gap/gap.h"
#include "node/output/track/track.h"
#include "widget/timelinewidget/timelinewidget.h"
namespace olive {
TrackSelectTool::TrackSelectTool(TimelineWidget *parent) :
PointerTool(parent)
{
}
void TrackSelectTool::MousePress(TimelineViewMouseEvent *event)
{
QVector<Block*> blocks;
bool forward = !(event->GetModifiers() & Qt::ControlModifier);
parent()->DeselectAll();
if (event->GetModifiers() & Qt::ShiftModifier) {
// Track only
Track *track = parent()->GetTrackFromReference(event->GetTrack());
if (track) {
SelectBlocksOnTrack(track, event, &blocks, forward);
}
} else {
// All tracks
foreach (Track *track, parent()->sequence()->GetTracks()) {
SelectBlocksOnTrack(track, event, &blocks, forward);
}
}
if (!blocks.isEmpty()) {
parent()->SignalSelectedBlocks(blocks);
set_drag_movement_mode(Timeline::kMove);
SetClickedItem(blocks.first());
drag_start_ = event->GetCoordinates();
} else {
set_drag_movement_mode(Timeline::kNone);
}
}
void TrackSelectTool::SelectBlocksOnTrack(Track *track, TimelineViewMouseEvent *event, QVector<Block*> *blocks, bool forward)
{
Block *b = track->NearestBlockBeforeOrAt(event->GetFrame());
if (!b && !track->Blocks().isEmpty() && !forward) {
// Fallback to first or last block in track
b = track->Blocks().last();
}
while (b) {
if (!dynamic_cast<GapBlock*>(b)) {
if (!blocks->contains(b)) {
parent()->AddSelection(b);
blocks->append(b);
}
if (!(event->GetModifiers() & Qt::AltModifier)) {
if (ClipBlock *clip = dynamic_cast<ClipBlock*>(b)) {
foreach (Block *link, clip->block_links()) {
if (!blocks->contains(link)) {
parent()->AddSelection(link);
blocks->append(link);
}
}
}
}
}
b = forward ? b->next() : b->previous();
}
}
}
@@ -0,0 +1,42 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2021 Olive Team
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#ifndef TRACKSELECTTOOL_H
#define TRACKSELECTTOOL_H
#include "pointer.h"
namespace olive {
class TrackSelectTool : public PointerTool
{
public:
TrackSelectTool(TimelineWidget *parent);
virtual void MousePress(TimelineViewMouseEvent *event) override;
private:
void SelectBlocksOnTrack(Track *track, TimelineViewMouseEvent *event, QVector<Block *> *blocks, bool forward);
};
}
#endif // TRACKSELECTTOOL_H
@@ -347,6 +347,9 @@ void TimelineView::ToolChangedEvent(Tool::Item tool)
case Tool::kZoom:
setCursor(Qt::CrossCursor);
break;
case Tool::kTrackSelect:
setCursor(Qt::SizeHorCursor); // FIXME: Not the ideal cursor
break;
default:
unsetCursor();
}
+3
View File
@@ -42,6 +42,7 @@ Toolbar::Toolbar(QWidget *parent) :
// Create standard tool buttons
btn_pointer_tool_ = CreateToolButton(Tool::kPointer);
btn_trackselect_tool_ = CreateToolButton(Tool::kTrackSelect);
btn_edit_tool_ = CreateToolButton(Tool::kEdit);
btn_ripple_tool_ = CreateToolButton(Tool::kRipple);
btn_rolling_tool_ = CreateToolButton(Tool::kRolling);
@@ -107,6 +108,7 @@ void Toolbar::resizeEvent(QResizeEvent *e)
void Toolbar::Retranslate()
{
btn_pointer_tool_->setToolTip(tr("Pointer Tool"));
btn_trackselect_tool_->setToolTip(tr("Track Select Tool"));
btn_edit_tool_->setToolTip(tr("Edit Tool"));
btn_ripple_tool_->setToolTip(tr("Ripple Tool"));
btn_rolling_tool_->setToolTip(tr("Rolling Tool"));
@@ -124,6 +126,7 @@ void Toolbar::Retranslate()
void Toolbar::UpdateIcons()
{
btn_pointer_tool_->setIcon(icon::ToolPointer);
btn_trackselect _tool_->setIcon(icon::TriRight); // FIXME: Procure real icon
btn_edit_tool_->setIcon(icon::ToolEdit);
btn_ripple_tool_->setIcon(icon::ToolRipple);
btn_rolling_tool_->setIcon(icon::ToolRolling);
+1
View File
@@ -173,6 +173,7 @@ private:
QList<ToolbarButton*> toolbar_btns_;
ToolbarButton* btn_pointer_tool_;
ToolbarButton* btn_trackselect_tool_;
ToolbarButton* btn_edit_tool_;
ToolbarButton* btn_ripple_tool_;
ToolbarButton* btn_rolling_tool_;
+6
View File
@@ -207,6 +207,11 @@ MainMenu::MainMenu(MainWindow *parent) :
tools_pointer_item_->setData(Tool::kPointer);
tools_group_->addAction(tools_pointer_item_);
tools_trackselect_item_ = tools_menu_->AddItem("trackselecttool", this, &MainMenu::ToolItemTriggered, tr("D"));
tools_trackselect_item_->setCheckable(true);
tools_trackselect_item_->setData(Tool::kTrackSelect);
tools_group_->addAction(tools_trackselect_item_);
tools_edit_item_ = tools_menu_->AddItem("edittool", this, &MainMenu::ToolItemTriggered, tr("X"));
tools_edit_item_->setCheckable(true);
tools_edit_item_->setData(Tool::kEdit);
@@ -763,6 +768,7 @@ void MainMenu::Retranslate()
// Tools menu
tools_menu_->setTitle(tr("&Tools"));
tools_pointer_item_->setText(tr("Pointer Tool"));
tools_trackselect_item_->setText(tr("Track Select Tool"));
tools_edit_item_->setText(tr("Edit Tool"));
tools_ripple_item_->setText(tr("Ripple Tool"));
tools_rolling_item_->setText(tr("Rolling Tool"));
+1
View File
@@ -272,6 +272,7 @@ private:
Menu* tools_menu_;
QActionGroup* tools_group_;
QAction* tools_pointer_item_;
QAction* tools_trackselect_item_;
QAction* tools_edit_item_;
QAction* tools_ripple_item_;
QAction* tools_rolling_item_;