Merge branch 'master' into nodeviewredux

This commit is contained in:
itsmattkc
2020-04-29 05:01:11 +10:00
9 changed files with 211 additions and 113 deletions
+8
View File
@@ -107,6 +107,14 @@ else()
)
endif()
if(UNIX AND NOT APPLE)
target_compile_options(
${OLIVE_TARGET}
PRIVATE
-rdynamic
)
endif()
# Set include directories
target_include_directories(
${OLIVE_TARGET}
+1 -1
View File
@@ -29,7 +29,7 @@ out vec4 fragColor;
// Double gaussian formula, actually used in the code below
// Should be faster than the single gaussian above since it doesn't need sqrt()
float gaussian2(float x, float y, float sigma) {
return (1.0/(pow(sigma, 2.0)*2.0*M_PI))*exp(-0.5*((pow(x, 2.0) + pow(y, 2.0))/pow(sigma, 2.0)));
return (1.0/((sigma*sigma)*2.0*M_PI))*exp(-0.5*(((x*x) + (y*y))/(sigma*sigma)));
}
void main(void) {
+17 -4
View File
@@ -27,10 +27,12 @@
#include "node/factory.h"
#include "widget/menu/menushared.h"
#define super HandMovableView
OLIVE_NAMESPACE_ENTER
NodeView::NodeView(QWidget *parent) :
QGraphicsView(parent),
HandMovableView(parent),
graph_(nullptr),
attached_item_(nullptr),
drop_edge_(nullptr)
@@ -198,7 +200,7 @@ void NodeView::ItemsChanged()
void NodeView::keyPressEvent(QKeyEvent *event)
{
QGraphicsView::keyPressEvent(event);
super::keyPressEvent(event);
if (event->key() == Qt::Key_Escape && attached_item_) {
DetachItemFromCursor();
@@ -211,6 +213,8 @@ void NodeView::keyPressEvent(QKeyEvent *event)
void NodeView::mousePressEvent(QMouseEvent *event)
{
if (HandPress(event)) return;
if (attached_item_) {
Node* dropping_node = attached_item_->GetNode();
@@ -235,12 +239,14 @@ void NodeView::mousePressEvent(QMouseEvent *event)
drop_edge_ = nullptr;
}
QGraphicsView::mousePressEvent(event);
super::mousePressEvent(event);
}
void NodeView::mouseMoveEvent(QMouseEvent *event)
{
QGraphicsView::mouseMoveEvent(event);
if (HandMove(event)) return;
super::mouseMoveEvent(event);
if (attached_item_) {
attached_item_->setPos(mapToScene(event->pos()));
@@ -299,6 +305,13 @@ void NodeView::mouseMoveEvent(QMouseEvent *event)
}
}
void NodeView::mouseReleaseEvent(QMouseEvent *event)
{
if (HandRelease(event)) return;
super::mouseReleaseEvent(event);
}
void NodeView::wheelEvent(QWheelEvent *event)
{
if (event->modifiers() & Qt::ControlModifier) {
+3 -2
View File
@@ -26,6 +26,7 @@
#include "node/graph.h"
#include "nodeviewscene.h"
#include "widget/timelinewidget/view/handmovableview.h"
#include "widget/nodecopypaste/nodecopypaste.h"
OLIVE_NAMESPACE_ENTER
@@ -36,7 +37,7 @@ OLIVE_NAMESPACE_ENTER
* This widget takes a NodeGraph object and constructs a QGraphicsScene representing its data, viewing and allowing
* the user to make modifications to it.
*/
class NodeView : public QGraphicsView, public NodeCopyPasteWidget
class NodeView : public HandMovableView, public NodeCopyPasteWidget
{
Q_OBJECT
public:
@@ -73,8 +74,8 @@ protected:
virtual void keyPressEvent(QKeyEvent *event) override;
virtual void mousePressEvent(QMouseEvent *event) override;
virtual void mouseMoveEvent(QMouseEvent *event) override;
virtual void mouseReleaseEvent(QMouseEvent* event) override;
virtual void wheelEvent(QWheelEvent* event) override;
@@ -16,6 +16,8 @@
set(OLIVE_SOURCES
${OLIVE_SOURCES}
widget/timelinewidget/view/handmovableview.h
widget/timelinewidget/view/handmovableview.cpp
widget/timelinewidget/view/timelineplayhead.h
widget/timelinewidget/view/timelineplayhead.cpp
widget/timelinewidget/view/timelineview.h
@@ -0,0 +1,118 @@
/***
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 "handmovableview.h"
#include <QMouseEvent>
#include "core.h"
OLIVE_NAMESPACE_ENTER
HandMovableView::HandMovableView(QWidget* parent) :
QGraphicsView(parent),
dragging_hand_(false)
{
connect(Core::instance(), &Core::ToolChanged, this, &HandMovableView::ApplicationToolChanged);
}
void HandMovableView::ApplicationToolChanged(Tool::Item tool)
{
if (tool == Tool::kHand) {
setDragMode(ScrollHandDrag);
} else {
setDragMode(default_drag_mode_);
}
ToolChangedEvent(tool);
}
bool HandMovableView::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 HandMovableView::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 HandMovableView::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;
}
void HandMovableView::SetDefaultDragMode(QGraphicsView::DragMode mode)
{
default_drag_mode_ = mode;
setDragMode(default_drag_mode_);
}
const QGraphicsView::DragMode &HandMovableView::GetDefaultDragMode() const
{
return default_drag_mode_;
}
OLIVE_NAMESPACE_EXIT
@@ -0,0 +1,59 @@
/***
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/>.
***/
#ifndef HANDMOVABLEVIEW_H
#define HANDMOVABLEVIEW_H
#include <QGraphicsView>
#include "tool/tool.h"
OLIVE_NAMESPACE_ENTER
class HandMovableView : public QGraphicsView
{
Q_OBJECT
public:
HandMovableView(QWidget* parent = nullptr);
protected:
virtual void ToolChangedEvent(Tool::Item tool){Q_UNUSED(tool)}
bool HandPress(QMouseEvent* event);
bool HandMove(QMouseEvent* event);
bool HandRelease(QMouseEvent* event);
void SetDefaultDragMode(DragMode mode);
const DragMode& GetDefaultDragMode() const;
private:
bool dragging_hand_;
DragMode pre_hand_drag_mode_;
DragMode default_drag_mode_;
private slots:
void ApplicationToolChanged(Tool::Item tool);
};
OLIVE_NAMESPACE_EXIT
#endif // HANDMOVABLEVIEW_H
@@ -34,12 +34,11 @@ OLIVE_NAMESPACE_ENTER
const double TimelineViewBase::kMaximumScale = 8192;
TimelineViewBase::TimelineViewBase(QWidget *parent) :
QGraphicsView(parent),
HandMovableView(parent),
playhead_(0),
playhead_scene_left_(-1),
playhead_scene_right_(-1),
dragging_playhead_(false),
dragging_hand_(false),
limit_y_axis_(false)
{
setScene(&scene_);
@@ -50,7 +49,6 @@ TimelineViewBase::TimelineViewBase(QWidget *parent) :
SetDefaultDragMode(NoDrag);
connect(&scene_, SIGNAL(changed(const QList<QRectF>&)), this, SLOT(UpdateSceneRect()));
connect(Core::instance(), &Core::ToolChanged, this, &TimelineViewBase::ApplicationToolChanged);
SetMaximumScale(kMaximumScale);
}
@@ -100,17 +98,6 @@ rational TimelineViewBase::GetPlayheadTime() const
return Timecode::timestamp_to_time(playhead_, timebase());
}
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());
@@ -148,70 +135,6 @@ bool TimelineViewBase::PlayheadRelease(QMouseEvent*)
return false;
}
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;
}
void TimelineViewBase::ToolChangedEvent(Tool::Item)
{
}
qreal TimelineViewBase::GetPlayheadX()
{
return TimeToScene(Timecode::timestamp_to_time(playhead_, timebase()));
@@ -305,15 +228,4 @@ void TimelineViewBase::SetLimitYAxis(bool)
UpdateSceneRect();
}
void TimelineViewBase::ApplicationToolChanged(Tool::Item tool)
{
if (tool == Tool::kHand) {
setDragMode(ScrollHandDrag);
} else {
setDragMode(default_drag_mode_);
}
ToolChangedEvent(tool);
}
OLIVE_NAMESPACE_EXIT
@@ -24,12 +24,13 @@
#include <QGraphicsView>
#include "core.h"
#include "handmovableview.h"
#include "timelineplayhead.h"
#include "widget/timelinewidget/timelinescaledobject.h"
OLIVE_NAMESPACE_ENTER
class TimelineViewBase : public QGraphicsView, public TimelineScaledObject
class TimelineViewBase : public HandMovableView, public TimelineScaledObject
{
Q_OBJECT
public:
@@ -66,19 +67,10 @@ protected:
rational GetPlayheadTime() const;
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);
virtual void ToolChangedEvent(Tool::Item tool);
virtual void TimebaseChangedEvent(const rational &) override;
private:
@@ -93,15 +85,10 @@ private:
bool dragging_playhead_;
bool dragging_hand_;
DragMode pre_hand_drag_mode_;
QGraphicsScene scene_;
bool limit_y_axis_;
DragMode default_drag_mode_;
rational end_time_;
private slots:
@@ -118,8 +105,6 @@ private slots:
*/
void PageScrollToPlayhead();
void ApplicationToolChanged(Tool::Item tool);
};
OLIVE_NAMESPACE_EXIT