implemented automatically switching to the hand tool when middle clicking on
all TimelineViewBase derivatives
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <QEvent>
|
||||
#include <QLabel>
|
||||
#include <QScrollBar>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include "core.h"
|
||||
@@ -67,6 +68,7 @@ CurveWidget::CurveWidget(QWidget *parent) :
|
||||
connect(view_, &CurveView::TimeChanged, this, &CurveWidget::UpdateBridgeTime);
|
||||
connect(view_->scene(), &QGraphicsScene::selectionChanged, this, &CurveWidget::SelectionChanged);
|
||||
connect(view_, &CurveView::ScaleChanged, this, &CurveWidget::SetScale);
|
||||
connect(view_->horizontalScrollBar(), &QScrollBar::valueChanged, ruler_, &TimeRuler::SetScroll);
|
||||
|
||||
widget_bridge_layout_ = new QHBoxLayout();
|
||||
widget_bridge_layout_->addStretch();
|
||||
|
||||
@@ -15,11 +15,10 @@ KeyframeViewBase::KeyframeViewBase(QWidget *parent) :
|
||||
dragging_bezier_point_(nullptr),
|
||||
y_axis_enabled_(false)
|
||||
{
|
||||
setDragMode(RubberBandDrag);
|
||||
SetDefaultDragMode(RubberBandDrag);
|
||||
setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
|
||||
connect(this, &KeyframeViewBase::customContextMenuRequested, this, &KeyframeViewBase::ShowContextMenu);
|
||||
connect(Core::instance(), &Core::ToolChanged, this, &KeyframeViewBase::ApplicationToolChanged);
|
||||
}
|
||||
|
||||
void KeyframeViewBase::Clear()
|
||||
@@ -67,7 +66,7 @@ KeyframeViewItem *KeyframeViewBase::AddKeyframeInternal(NodeKeyframePtr key)
|
||||
|
||||
void KeyframeViewBase::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
if (PlayheadPress(event)) {
|
||||
if (HandPress(event) || PlayheadPress(event)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -107,7 +106,7 @@ void KeyframeViewBase::mousePressEvent(QMouseEvent *event)
|
||||
|
||||
void KeyframeViewBase::mouseMoveEvent(QMouseEvent *event)
|
||||
{
|
||||
if (PlayheadMove(event)) {
|
||||
if (HandMove(event) || PlayheadMove(event)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -138,7 +137,7 @@ void KeyframeViewBase::mouseMoveEvent(QMouseEvent *event)
|
||||
|
||||
void KeyframeViewBase::mouseReleaseEvent(QMouseEvent *event)
|
||||
{
|
||||
if (PlayheadRelease(event)) {
|
||||
if (HandRelease(event) || PlayheadRelease(event)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -389,12 +388,3 @@ void KeyframeViewBase::ShowKeyframePropertiesDialog()
|
||||
}
|
||||
}
|
||||
|
||||
void KeyframeViewBase::ApplicationToolChanged(Tool::Item tool)
|
||||
{
|
||||
if (tool == Tool::kHand) {
|
||||
setDragMode(ScrollHandDrag);
|
||||
} else {
|
||||
setDragMode(RubberBandDrag);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#ifndef KEYFRAMEVIEWBASE_H
|
||||
#define KEYFRAMEVIEWBASE_H
|
||||
|
||||
#include "core.h"
|
||||
#include "keyframeviewitem.h"
|
||||
#include "node/keyframe.h"
|
||||
#include "widget/curvewidget/beziercontrolpointitem.h"
|
||||
@@ -77,8 +76,6 @@ private slots:
|
||||
|
||||
void ShowKeyframePropertiesDialog();
|
||||
|
||||
void ApplicationToolChanged(Tool::Item tool);
|
||||
|
||||
};
|
||||
|
||||
#endif // KEYFRAMEVIEWBASE_H
|
||||
|
||||
@@ -106,6 +106,8 @@ NodeParamView::NodeParamView(QWidget *parent) :
|
||||
connect(vertical_scrollbar_, &QScrollBar::valueChanged, scroll_area->verticalScrollBar(), &QScrollBar::setValue);
|
||||
connect(vertical_scrollbar_, &QScrollBar::valueChanged, keyframe_view_->verticalScrollBar(), &QScrollBar::setValue);
|
||||
|
||||
connect(keyframe_view_->horizontalScrollBar(), SIGNAL(valueChanged(int)), ruler_, SLOT(SetScroll(int)));
|
||||
|
||||
// Set a default scale - FIXME: Hardcoded
|
||||
SetScale(120);
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
TimelineWidget::TimelineWidget(QWidget *parent) :
|
||||
QWidget(parent),
|
||||
rubberband_(QRubberBand::Rectangle, this),
|
||||
hand_drag_view_(nullptr),
|
||||
timeline_node_(nullptr),
|
||||
playhead_(0)
|
||||
{
|
||||
@@ -61,7 +60,7 @@ TimelineWidget::TimelineWidget(QWidget *parent) :
|
||||
tools_.replace(::Tool::kRazor, std::make_shared<RazorTool>(this));
|
||||
tools_.replace(::Tool::kSlip, std::make_shared<SlipTool>(this));
|
||||
tools_.replace(::Tool::kSlide, std::make_shared<SlideTool>(this));
|
||||
tools_.replace(::Tool::kHand, std::make_shared<HandTool>(this));
|
||||
// tools_.replace(::Tool::kHand, std::make_shared<HandTool>(this));
|
||||
tools_.replace(::Tool::kZoom, std::make_shared<ZoomTool>(this));
|
||||
tools_.replace(::Tool::kTransition, std::make_shared<TransitionTool>(this));
|
||||
//tools_.replace(::Tool::kRecord, new PointerTool(this)); FIXME: Implement
|
||||
@@ -917,33 +916,3 @@ void TimelineWidget::EndRubberBandSelect(bool select_links)
|
||||
rubberband_.hide();
|
||||
rubberband_now_selected_.clear();
|
||||
}
|
||||
|
||||
void TimelineWidget::StartHandDrag()
|
||||
{
|
||||
// Determine which view to hand drag by which is under the cursor now
|
||||
foreach (TimelineAndTrackView* tview, views_) {
|
||||
TimelineView* view = tview->view();
|
||||
|
||||
if (view->underMouse()) {
|
||||
hand_drag_view_ = view;
|
||||
hand_drag_view_origin_ = view->GetScrollCoordinates();
|
||||
drag_origin_ = QCursor::pos();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TimelineWidget::MoveHandDrag()
|
||||
{
|
||||
if (hand_drag_view_ == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Drag the view if we found one in StartHandDrag()
|
||||
hand_drag_view_->SetScrollCoordinates(hand_drag_view_origin_ + (drag_origin_ - QCursor::pos()));
|
||||
}
|
||||
|
||||
void TimelineWidget::EndHandDrag()
|
||||
{
|
||||
hand_drag_view_ = nullptr;
|
||||
}
|
||||
|
||||
@@ -272,19 +272,6 @@ private:
|
||||
virtual void MouseReleaseInternal(TimelineViewMouseEvent *event) override;
|
||||
};
|
||||
|
||||
class HandTool : public Tool
|
||||
{
|
||||
public:
|
||||
HandTool(TimelineWidget* parent);
|
||||
|
||||
virtual void MousePress(TimelineViewMouseEvent *event) override;
|
||||
virtual void MouseMove(TimelineViewMouseEvent *event) override;
|
||||
virtual void MouseRelease(TimelineViewMouseEvent *event) override;
|
||||
private:
|
||||
QPoint screen_drag_start_;
|
||||
QPoint scrollbar_start_;
|
||||
};
|
||||
|
||||
class ZoomTool : public Tool
|
||||
{
|
||||
public:
|
||||
@@ -337,12 +324,6 @@ private:
|
||||
QRubberBand rubberband_;
|
||||
QList<QGraphicsItem*> rubberband_now_selected_;
|
||||
|
||||
void StartHandDrag();
|
||||
void MoveHandDrag();
|
||||
void EndHandDrag();
|
||||
TimelineView* hand_drag_view_;
|
||||
QPoint hand_drag_view_origin_;
|
||||
|
||||
Tool* GetActiveTool();
|
||||
|
||||
QVector< std::shared_ptr<Tool> > tools_;
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
set(OLIVE_SOURCES
|
||||
${OLIVE_SOURCES}
|
||||
widget/timelinewidget/tool/add.cpp
|
||||
widget/timelinewidget/tool/hand.cpp
|
||||
widget/timelinewidget/tool/import.cpp
|
||||
widget/timelinewidget/tool/pointer.cpp
|
||||
widget/timelinewidget/tool/razor.cpp
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
/***
|
||||
|
||||
Olive - Non-Linear Video Editor
|
||||
Copyright (C) 2019 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 "widget/timelinewidget/timelinewidget.h"
|
||||
|
||||
#include <QScrollBar>
|
||||
|
||||
TimelineWidget::HandTool::HandTool(TimelineWidget* parent) :
|
||||
Tool(parent)
|
||||
{
|
||||
}
|
||||
|
||||
void TimelineWidget::HandTool::MousePress(TimelineViewMouseEvent *)
|
||||
{
|
||||
parent()->StartHandDrag();
|
||||
}
|
||||
|
||||
void TimelineWidget::HandTool::MouseMove(TimelineViewMouseEvent *)
|
||||
{
|
||||
parent()->MoveHandDrag();
|
||||
}
|
||||
|
||||
void TimelineWidget::HandTool::MouseRelease(TimelineViewMouseEvent *)
|
||||
{
|
||||
parent()->EndHandDrag();
|
||||
}
|
||||
@@ -30,7 +30,6 @@
|
||||
#include "config/config.h"
|
||||
#include "common/flipmodifiers.h"
|
||||
#include "common/timecodefunctions.h"
|
||||
#include "core.h"
|
||||
#include "node/input/media/media.h"
|
||||
#include "project/item/footage/footage.h"
|
||||
|
||||
@@ -42,7 +41,6 @@ TimelineView::TimelineView(const TrackType &type, Qt::Alignment vertical_alignme
|
||||
Q_ASSERT(vertical_alignment == Qt::AlignTop || vertical_alignment == Qt::AlignBottom);
|
||||
setAlignment(Qt::AlignLeft | vertical_alignment);
|
||||
|
||||
setDragMode(NoDrag);
|
||||
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
|
||||
setBackgroundRole(QPalette::Window);
|
||||
setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
@@ -69,11 +67,16 @@ void TimelineView::DeselectAll()
|
||||
|
||||
void TimelineView::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
if (PlayheadPress(event)) {
|
||||
if (HandPress(event) || PlayheadPress(event)) {
|
||||
// Let the parent handle this
|
||||
return;
|
||||
}
|
||||
|
||||
if (dragMode() != GetDefaultDragMode()) {
|
||||
TimelineViewBase::mousePressEvent(event);
|
||||
return;
|
||||
}
|
||||
|
||||
TimelineViewMouseEvent timeline_event = CreateMouseEvent(event->pos(), event->modifiers());
|
||||
|
||||
emit MousePressed(&timeline_event);
|
||||
@@ -81,11 +84,16 @@ void TimelineView::mousePressEvent(QMouseEvent *event)
|
||||
|
||||
void TimelineView::mouseMoveEvent(QMouseEvent *event)
|
||||
{
|
||||
if (PlayheadMove(event)) {
|
||||
if (HandMove(event) || PlayheadMove(event)) {
|
||||
// Let the parent handle this
|
||||
return;
|
||||
}
|
||||
|
||||
if (dragMode() != GetDefaultDragMode()) {
|
||||
TimelineViewBase::mouseMoveEvent(event);
|
||||
return;
|
||||
}
|
||||
|
||||
TimelineViewMouseEvent timeline_event = CreateMouseEvent(event->pos(), event->modifiers());
|
||||
|
||||
emit MouseMoved(&timeline_event);
|
||||
@@ -93,11 +101,16 @@ void TimelineView::mouseMoveEvent(QMouseEvent *event)
|
||||
|
||||
void TimelineView::mouseReleaseEvent(QMouseEvent *event)
|
||||
{
|
||||
if (PlayheadRelease(event)) {
|
||||
if (HandRelease(event) || PlayheadRelease(event)) {
|
||||
// Let the parent handle this
|
||||
return;
|
||||
}
|
||||
|
||||
if (dragMode() != GetDefaultDragMode()) {
|
||||
TimelineViewBase::mouseReleaseEvent(event);
|
||||
return;
|
||||
}
|
||||
|
||||
TimelineViewMouseEvent timeline_event = CreateMouseEvent(event->pos(), event->modifiers());
|
||||
|
||||
emit MouseReleased(&timeline_event);
|
||||
|
||||
@@ -25,9 +25,12 @@ TimelineViewBase::TimelineViewBase(QWidget *parent) :
|
||||
// Set default scale
|
||||
SetScale(1.0);
|
||||
|
||||
SetDefaultDragMode(NoDrag);
|
||||
|
||||
setViewportUpdateMode(FullViewportUpdate);
|
||||
|
||||
connect(&scene_, SIGNAL(changed(const QList<QRectF>&)), this, SLOT(UpdateSceneRect()));
|
||||
connect(Core::instance(), &Core::ToolChanged, this, &TimelineViewBase::ApplicationToolChanged);
|
||||
}
|
||||
|
||||
void TimelineViewBase::SetScale(const double &scale)
|
||||
@@ -93,6 +96,17 @@ rational TimelineViewBase::GetPlayheadTime()
|
||||
return rational(playhead_ * timebase().numerator(), timebase().denominator());
|
||||
}
|
||||
|
||||
void TimelineViewBase::SetDefaultDragMode(QGraphicsView::DragMode mode)
|
||||
{
|
||||
default_drag_mode_ = mode;
|
||||
setDragMode(default_drag_mode_);
|
||||
}
|
||||
|
||||
const QGraphicsView::DragMode &TimelineViewBase::GetDefaultDragMode() const
|
||||
{
|
||||
return default_drag_mode_;
|
||||
}
|
||||
|
||||
bool TimelineViewBase::PlayheadPress(QMouseEvent *event)
|
||||
{
|
||||
QPointF scene_pos = mapToScene(event->pos());
|
||||
@@ -124,6 +138,66 @@ bool TimelineViewBase::PlayheadRelease(QMouseEvent *event)
|
||||
return dragging_playhead_;
|
||||
}
|
||||
|
||||
bool TimelineViewBase::HandPress(QMouseEvent *event)
|
||||
{
|
||||
if (event->button() == Qt::MiddleButton) {
|
||||
pre_hand_drag_mode_ = dragMode();
|
||||
dragging_hand_ = true;
|
||||
|
||||
setDragMode(ScrollHandDrag);
|
||||
|
||||
// Transform mouse event to act like the left button is pressed
|
||||
QMouseEvent transformed(event->type(),
|
||||
event->localPos(),
|
||||
Qt::LeftButton,
|
||||
Qt::LeftButton,
|
||||
event->modifiers());
|
||||
|
||||
QGraphicsView::mousePressEvent(&transformed);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool TimelineViewBase::HandMove(QMouseEvent *event)
|
||||
{
|
||||
if (dragging_hand_) {
|
||||
// Transform mouse event to act like the left button is pressed
|
||||
QMouseEvent transformed(event->type(),
|
||||
event->localPos(),
|
||||
Qt::LeftButton,
|
||||
Qt::LeftButton,
|
||||
event->modifiers());
|
||||
|
||||
QGraphicsView::mouseMoveEvent(&transformed);
|
||||
}
|
||||
return dragging_hand_;
|
||||
}
|
||||
|
||||
bool TimelineViewBase::HandRelease(QMouseEvent *event)
|
||||
{
|
||||
if (dragging_hand_) {
|
||||
// Transform mouse event to act like the left button is pressed
|
||||
QMouseEvent transformed(event->type(),
|
||||
event->localPos(),
|
||||
Qt::LeftButton,
|
||||
Qt::LeftButton,
|
||||
event->modifiers());
|
||||
|
||||
QGraphicsView::mouseReleaseEvent(&transformed);
|
||||
|
||||
setDragMode(pre_hand_drag_mode_);
|
||||
|
||||
dragging_hand_ = false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
qreal TimelineViewBase::GetPlayheadX()
|
||||
{
|
||||
return TimeToScene(rational(playhead_ * timebase().numerator(), timebase().denominator()));
|
||||
@@ -241,3 +315,12 @@ void TimelineViewBase::SetLimitYAxis(bool e)
|
||||
limit_y_axis_ = true;
|
||||
UpdateSceneRect();
|
||||
}
|
||||
|
||||
void TimelineViewBase::ApplicationToolChanged(Tool::Item tool)
|
||||
{
|
||||
if (tool == Tool::kHand) {
|
||||
setDragMode(ScrollHandDrag);
|
||||
} else {
|
||||
setDragMode(default_drag_mode_);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <QGraphicsView>
|
||||
|
||||
#include "core.h"
|
||||
#include "timelineplayhead.h"
|
||||
#include "timelineviewenditem.h"
|
||||
#include "widget/timelinewidget/timelinescaledobject.h"
|
||||
@@ -42,10 +43,17 @@ protected:
|
||||
|
||||
rational GetPlayheadTime();
|
||||
|
||||
void SetDefaultDragMode(DragMode mode);
|
||||
const DragMode& GetDefaultDragMode() const;
|
||||
|
||||
bool PlayheadPress(QMouseEvent* event);
|
||||
bool PlayheadMove(QMouseEvent* event);
|
||||
bool PlayheadRelease(QMouseEvent* event);
|
||||
|
||||
bool HandPress(QMouseEvent* event);
|
||||
bool HandMove(QMouseEvent* event);
|
||||
bool HandRelease(QMouseEvent* event);
|
||||
|
||||
private:
|
||||
qreal GetPlayheadX();
|
||||
|
||||
@@ -58,12 +66,17 @@ private:
|
||||
|
||||
bool dragging_playhead_;
|
||||
|
||||
bool dragging_hand_;
|
||||
DragMode pre_hand_drag_mode_;
|
||||
|
||||
TimelineViewEndItem* end_item_;
|
||||
|
||||
QGraphicsScene scene_;
|
||||
|
||||
bool limit_y_axis_;
|
||||
|
||||
DragMode default_drag_mode_;
|
||||
|
||||
private slots:
|
||||
/**
|
||||
* @brief Slot called whenever the view resizes or the scene contents change to enforce minimum scene sizes
|
||||
@@ -83,6 +96,8 @@ private slots:
|
||||
*/
|
||||
void PageScrollToPlayhead();
|
||||
|
||||
void ApplicationToolChanged(Tool::Item tool);
|
||||
|
||||
};
|
||||
|
||||
#endif // TIMELINEVIEWBASE_H
|
||||
|
||||
Reference in New Issue
Block a user