implemented cursors in the timeline
Note: this does not use the cursor SVGs in app/ui/cursors since I was never really satisfied with them. They're kept for posterity for the time being.
@@ -9,6 +9,8 @@ public:
|
||||
kTrimIn,
|
||||
kTrimOut
|
||||
};
|
||||
|
||||
static bool IsATrimMode(MovementMode mode) {return mode == kTrimIn || mode == kTrimOut;}
|
||||
};
|
||||
|
||||
#endif // TIMELINECOMMON_H
|
||||
|
||||
@@ -41,6 +41,7 @@ NodeValueTable VideoRenderWorker::RenderInternal(const NodeDependency& path, con
|
||||
emit CompletedFrame(path, job_time, hash, texture);
|
||||
|
||||
// If we actually have a texture, download it into the disk cache
|
||||
qDebug() << "Texture was null:" << texture.isNull();
|
||||
if (!texture.isNull()) {
|
||||
Download(path, hash, texture, frame_cache_->CachePathName(hash));
|
||||
}
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
<!-- NOTE: I'm not a huge fan of these cursors, it may be good to commission some new ones soon -->
|
||||
|
||||
<RCC>
|
||||
<qresource prefix="/cursors">
|
||||
<file>1_left.svg</file>
|
||||
<file>1_right.svg</file>
|
||||
<file>2.svg</file>
|
||||
<file>3_left.svg</file>
|
||||
<file>3_right.svg</file>
|
||||
<file>4.svg</file>
|
||||
<file>5.svg</file>
|
||||
<file>5b.svg</file>
|
||||
<file>5c.svg</file>
|
||||
<file>trim-left.svg</file>
|
||||
<file>trim-right.svg</file>
|
||||
<file>slip.svg</file>
|
||||
<file>ripple-left.svg</file>
|
||||
<file>ripple-right.svg</file>
|
||||
<file>rolling.svg</file>
|
||||
<file>razor-a.svg</file>
|
||||
<file>razor-b.svg</file>
|
||||
<file>razor-c.svg</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
||||
|
Before Width: | Height: | Size: 358 KiB After Width: | Height: | Size: 358 KiB |
|
Before Width: | Height: | Size: 358 KiB After Width: | Height: | Size: 358 KiB |
|
Before Width: | Height: | Size: 358 KiB After Width: | Height: | Size: 358 KiB |
|
Before Width: | Height: | Size: 358 KiB After Width: | Height: | Size: 358 KiB |
|
Before Width: | Height: | Size: 358 KiB After Width: | Height: | Size: 358 KiB |
|
Before Width: | Height: | Size: 359 KiB After Width: | Height: | Size: 359 KiB |
|
Before Width: | Height: | Size: 358 KiB After Width: | Height: | Size: 358 KiB |
|
Before Width: | Height: | Size: 358 KiB After Width: | Height: | Size: 358 KiB |
|
Before Width: | Height: | Size: 358 KiB After Width: | Height: | Size: 358 KiB |
@@ -15,6 +15,7 @@
|
||||
TimelineWidget::TimelineWidget(QWidget *parent) :
|
||||
QWidget(parent),
|
||||
rubberband_(QRubberBand::Rectangle, this),
|
||||
active_tool_(nullptr),
|
||||
timeline_node_(nullptr),
|
||||
playhead_(0)
|
||||
{
|
||||
@@ -652,8 +653,17 @@ void TimelineWidget::ViewMousePressed(TimelineViewMouseEvent *event)
|
||||
|
||||
void TimelineWidget::ViewMouseMoved(TimelineViewMouseEvent *event)
|
||||
{
|
||||
if (timeline_node_ != nullptr && active_tool_ != nullptr) {
|
||||
active_tool_->MouseMove(event);
|
||||
if (timeline_node_) {
|
||||
if (active_tool_) {
|
||||
active_tool_->MouseMove(event);
|
||||
} else {
|
||||
// Mouse is not down, attempt a hover event
|
||||
Tool* hover_tool = GetActiveTool();
|
||||
|
||||
if (hover_tool) {
|
||||
hover_tool->HoverMove(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -661,6 +671,7 @@ void TimelineWidget::ViewMouseReleased(TimelineViewMouseEvent *event)
|
||||
{
|
||||
if (timeline_node_ != nullptr && active_tool_ != nullptr) {
|
||||
active_tool_->MouseRelease(event);
|
||||
active_tool_ = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -668,6 +679,7 @@ void TimelineWidget::ViewMouseDoubleClicked(TimelineViewMouseEvent *event)
|
||||
{
|
||||
if (timeline_node_ != nullptr && active_tool_ != nullptr) {
|
||||
active_tool_->MouseDoubleClick(event);
|
||||
active_tool_ = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -81,6 +81,8 @@ private:
|
||||
virtual void MouseRelease(TimelineViewMouseEvent *){}
|
||||
virtual void MouseDoubleClick(TimelineViewMouseEvent *){}
|
||||
|
||||
virtual void HoverMove(TimelineViewMouseEvent *){}
|
||||
|
||||
virtual void DragEnter(TimelineViewMouseEvent *){}
|
||||
virtual void DragMove(TimelineViewMouseEvent *){}
|
||||
virtual void DragLeave(QDragLeaveEvent *){}
|
||||
@@ -144,6 +146,9 @@ private:
|
||||
virtual void MousePress(TimelineViewMouseEvent *event) override;
|
||||
virtual void MouseMove(TimelineViewMouseEvent *event) override;
|
||||
virtual void MouseRelease(TimelineViewMouseEvent *event) override;
|
||||
|
||||
virtual void HoverMove(TimelineViewMouseEvent *event) override;
|
||||
|
||||
protected:
|
||||
void SetMovementAllowed(bool allowed);
|
||||
void SetTrackMovementAllowed(bool allowed);
|
||||
@@ -178,6 +183,8 @@ private:
|
||||
virtual void ProcessDrag(const TimelineCoordinate &mouse_pos);
|
||||
|
||||
private:
|
||||
Timeline::MovementMode IsCursorInTrimHandle(TimelineViewBlockItem* block, qreal cursor_x);
|
||||
|
||||
void InitiateDrag(const TimelineCoordinate &mouse_pos);
|
||||
|
||||
void AddGhostInternal(TimelineViewGhostItem* ghost, Timeline::MovementMode mode);
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
|
||||
#include "common/clamp.h"
|
||||
#include "common/flipmodifiers.h"
|
||||
#include "common/qtversionabstraction.h"
|
||||
#include "common/range.h"
|
||||
#include "common/timecodefunctions.h"
|
||||
#include "config/config.h"
|
||||
@@ -140,6 +141,27 @@ void TimelineWidget::PointerTool::MouseRelease(TimelineViewMouseEvent *event)
|
||||
dragging_ = false;
|
||||
}
|
||||
|
||||
void TimelineWidget::PointerTool::HoverMove(TimelineViewMouseEvent *event)
|
||||
{
|
||||
// No dragging, but we still want to process cursors
|
||||
TimelineViewBlockItem* block_at_cursor = GetItemAtScenePos(event->GetCoordinates());
|
||||
|
||||
if (block_at_cursor) {
|
||||
switch (IsCursorInTrimHandle(block_at_cursor, event->GetSceneX())) {
|
||||
case Timeline::kTrimIn:
|
||||
parent()->setCursor(Qt::SizeHorCursor);
|
||||
break;
|
||||
case Timeline::kTrimOut:
|
||||
parent()->setCursor(Qt::SizeHorCursor);
|
||||
break;
|
||||
default:
|
||||
parent()->unsetCursor();
|
||||
}
|
||||
} else {
|
||||
parent()->unsetCursor();
|
||||
}
|
||||
}
|
||||
|
||||
void TimelineWidget::PointerTool::SetMovementAllowed(bool allowed)
|
||||
{
|
||||
movement_allowed_ = allowed;
|
||||
@@ -211,7 +233,7 @@ void TimelineWidget::PointerTool::MouseReleaseInternal(TimelineViewMouseEvent *e
|
||||
Block* b = Node::ValueToPtr<Block>(ghost->data(TimelineViewGhostItem::kAttachedBlock));
|
||||
|
||||
// Normal blocks work in conjunction with the gap made above
|
||||
if (ghost->mode() == Timeline::kTrimIn || ghost->mode() == Timeline::kTrimOut) {
|
||||
if (Timeline::IsATrimMode(ghost->mode())) {
|
||||
// If we were trimming, we'll need to change the length
|
||||
|
||||
// If we were trimming the in point, we'll need to adjust the media in too
|
||||
@@ -280,21 +302,13 @@ void TimelineWidget::PointerTool::InitiateDrag(const TimelineCoordinate &mouse_p
|
||||
// Record where the drag started in timeline coordinates
|
||||
track_start_ = mouse_pos.GetTrack();
|
||||
|
||||
// Determine whether we're trimming or moving based on the position of the cursor
|
||||
Timeline::MovementMode trim_mode = Timeline::kNone;
|
||||
|
||||
// FIXME: Hardcoded number
|
||||
double kTrimHandle = qMax(10.0, parent()->TimeToScene(parent()->timebase()));
|
||||
|
||||
qreal mouse_x = parent()->TimeToScene(mouse_pos.GetFrame());
|
||||
|
||||
// Determine whether we're trimming or moving based on the position of the cursor
|
||||
Timeline::MovementMode trim_mode = IsCursorInTrimHandle(clicked_item, mouse_x);
|
||||
|
||||
if (trimming_allowed_ && mouse_x <= clicked_item->x() + kTrimHandle) {
|
||||
trim_mode = Timeline::kTrimIn;
|
||||
} else if (trimming_allowed_ && mouse_x >= clicked_item->x() + clicked_item->rect().right() - kTrimHandle) {
|
||||
trim_mode = Timeline::kTrimOut;
|
||||
} else if (movement_allowed_) {
|
||||
// Some derived classes don't allow movement
|
||||
// Some derived classes don't allow movement
|
||||
if (trim_mode == Timeline::kNone && movement_allowed_) {
|
||||
trim_mode = Timeline::kMove;
|
||||
}
|
||||
|
||||
@@ -377,6 +391,24 @@ void TimelineWidget::PointerTool::ProcessDrag(const TimelineCoordinate &mouse_po
|
||||
parent());
|
||||
}
|
||||
|
||||
Timeline::MovementMode TimelineWidget::PointerTool::IsCursorInTrimHandle(TimelineViewBlockItem *block, qreal cursor_x)
|
||||
{
|
||||
double kTrimHandle = QFontMetricsWidth(parent()->fontMetrics(), "H");
|
||||
|
||||
// Block is too narrow, no trimming allowed
|
||||
if (block->rect().width() <= kTrimHandle * 2) {
|
||||
return Timeline::kNone;
|
||||
}
|
||||
|
||||
if (trimming_allowed_ && cursor_x <= block->x() + kTrimHandle) {
|
||||
return Timeline::kTrimIn;
|
||||
} else if (trimming_allowed_ && cursor_x >= block->x() + block->rect().right() - kTrimHandle) {
|
||||
return Timeline::kTrimOut;
|
||||
} else {
|
||||
return Timeline::kNone;
|
||||
}
|
||||
}
|
||||
|
||||
void TimelineWidget::PointerTool::InitiateGhosts(TimelineViewBlockItem* clicked_item,
|
||||
Timeline::MovementMode trim_mode,
|
||||
bool allow_gap_trimming)
|
||||
@@ -389,8 +421,7 @@ void TimelineWidget::PointerTool::InitiateGhosts(TimelineViewBlockItem* clicked_
|
||||
bool multitrim_enabled = true;
|
||||
|
||||
// Determine if the clicked item is the earliest/latest in the track for in/out trimming respectively
|
||||
if (trim_mode == Timeline::kTrimIn
|
||||
|| trim_mode == Timeline::kTrimOut) {
|
||||
if (Timeline::IsATrimMode(trim_mode)) {
|
||||
multitrim_enabled = IsClipTrimmable(clicked_item, clips, trim_mode);
|
||||
}
|
||||
|
||||
@@ -405,13 +436,12 @@ void TimelineWidget::PointerTool::InitiateGhosts(TimelineViewBlockItem* clicked_
|
||||
bool include_this_clip = true;
|
||||
|
||||
if (clip_item->block()->type() == Block::kGap
|
||||
&& trim_mode != Timeline::kTrimIn
|
||||
&& trim_mode != Timeline::kTrimOut) {
|
||||
&& !Timeline::IsATrimMode(trim_mode)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (clip_item != clicked_item
|
||||
&& (trim_mode == Timeline::kTrimIn || trim_mode == Timeline::kTrimOut)) {
|
||||
&& (Timeline::IsATrimMode(trim_mode))) {
|
||||
include_this_clip = multitrim_enabled ? IsClipTrimmable(clip_item, clips, trim_mode) : false;
|
||||
}
|
||||
|
||||
|
||||
@@ -45,6 +45,7 @@ TimelineView::TimelineView(const TrackType &type, Qt::Alignment vertical_alignme
|
||||
setBackgroundRole(QPalette::Window);
|
||||
setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
SetLimitYAxis(true);
|
||||
viewport()->setMouseTracking(true);
|
||||
}
|
||||
|
||||
void TimelineView::SelectAll()
|
||||
@@ -207,6 +208,25 @@ void TimelineView::drawBackground(QPainter *painter, const QRectF &rect)
|
||||
}
|
||||
}
|
||||
|
||||
void TimelineView::ToolChangedEvent(Tool::Item tool)
|
||||
{
|
||||
switch (tool) {
|
||||
case Tool::kRazor:
|
||||
setCursor(Qt::SplitHCursor);
|
||||
break;
|
||||
case Tool::kEdit:
|
||||
setCursor(Qt::IBeamCursor);
|
||||
break;
|
||||
case Tool::kAdd:
|
||||
case Tool::kTransition:
|
||||
case Tool::kZoom:
|
||||
setCursor(Qt::CrossCursor);
|
||||
break;
|
||||
default:
|
||||
unsetCursor();
|
||||
}
|
||||
}
|
||||
|
||||
Stream::Type TimelineView::TrackTypeToStreamType(TrackType track_type)
|
||||
{
|
||||
switch (track_type) {
|
||||
|
||||
@@ -87,6 +87,8 @@ protected:
|
||||
|
||||
virtual void drawBackground(QPainter *painter, const QRectF &rect) override;
|
||||
|
||||
virtual void ToolChangedEvent(Tool::Item tool) override;
|
||||
|
||||
private:
|
||||
TrackType ConnectedTrackType();
|
||||
Stream::Type TrackTypeToStreamType(TrackType track_type);
|
||||
|
||||
@@ -14,6 +14,7 @@ TimelineViewBase::TimelineViewBase(QWidget *parent) :
|
||||
playhead_(0),
|
||||
playhead_scene_left_(-1),
|
||||
playhead_scene_right_(-1),
|
||||
dragging_playhead_(false),
|
||||
dragging_hand_(false),
|
||||
limit_y_axis_(false)
|
||||
{
|
||||
@@ -136,7 +137,13 @@ bool TimelineViewBase::PlayheadMove(QMouseEvent *event)
|
||||
|
||||
bool TimelineViewBase::PlayheadRelease(QMouseEvent *event)
|
||||
{
|
||||
return dragging_playhead_;
|
||||
if (dragging_playhead_) {
|
||||
dragging_playhead_ = false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool TimelineViewBase::HandPress(QMouseEvent *event)
|
||||
@@ -199,6 +206,10 @@ bool TimelineViewBase::HandRelease(QMouseEvent *event)
|
||||
return false;
|
||||
}
|
||||
|
||||
void TimelineViewBase::ToolChangedEvent(Tool::Item tool)
|
||||
{
|
||||
}
|
||||
|
||||
qreal TimelineViewBase::GetPlayheadX()
|
||||
{
|
||||
return TimeToScene(rational(playhead_ * timebase().numerator(), timebase().denominator()));
|
||||
@@ -324,4 +335,6 @@ void TimelineViewBase::ApplicationToolChanged(Tool::Item tool)
|
||||
} else {
|
||||
setDragMode(default_drag_mode_);
|
||||
}
|
||||
|
||||
ToolChangedEvent(tool);
|
||||
}
|
||||
|
||||
@@ -54,6 +54,8 @@ protected:
|
||||
bool HandMove(QMouseEvent* event);
|
||||
bool HandRelease(QMouseEvent* event);
|
||||
|
||||
virtual void ToolChangedEvent(Tool::Item tool);
|
||||
|
||||
private:
|
||||
qreal GetPlayheadX();
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ TimelineViewBlockItem::TimelineViewBlockItem(QGraphicsItem* parent) :
|
||||
block_(nullptr)
|
||||
{
|
||||
setBrush(Qt::white);
|
||||
setCursor(Qt::DragMoveCursor);
|
||||
}
|
||||
|
||||
Block *TimelineViewBlockItem::block()
|
||||
|
||||
@@ -74,6 +74,11 @@ void TimelineViewMouseEvent::SetEvent(QEvent *event)
|
||||
source_event_ = event;
|
||||
}
|
||||
|
||||
const qreal &TimelineViewMouseEvent::GetSceneX() const
|
||||
{
|
||||
return scene_x_;
|
||||
}
|
||||
|
||||
void TimelineViewMouseEvent::accept()
|
||||
{
|
||||
if (source_event_ != nullptr)
|
||||
|
||||
@@ -57,6 +57,8 @@ public:
|
||||
|
||||
void SetEvent(QEvent* event);
|
||||
|
||||
const qreal& GetSceneX() const;
|
||||
|
||||
void accept();
|
||||
void ignore();
|
||||
|
||||
|
||||