moved some files around for better organization

This commit is contained in:
itsmattkc
2020-12-16 19:05:22 +11:00
parent 7849d6f3ff
commit 374fa3f75c
39 changed files with 141 additions and 118 deletions
-4
View File
@@ -21,12 +21,8 @@ add_subdirectory(view)
set(OLIVE_SOURCES
${OLIVE_SOURCES}
widget/timelinewidget/snapservice.h
widget/timelinewidget/snapservice.cpp
widget/timelinewidget/timelineandtrackview.h
widget/timelinewidget/timelineandtrackview.cpp
widget/timelinewidget/timelinescaledobject.h
widget/timelinewidget/timelinescaledobject.cpp
widget/timelinewidget/timelinewidget.h
widget/timelinewidget/timelinewidget.cpp
widget/timelinewidget/timelinewidgetselections.h
@@ -1 +0,0 @@
#include "snapservice.h"
-31
View File
@@ -1,31 +0,0 @@
#ifndef SNAPSERVICE_H
#define SNAPSERVICE_H
#include "common/rational.h"
namespace olive {
class SnapService
{
public:
SnapService() = default;
enum SnapPoints {
kSnapToClips = 0x1,
kSnapToPlayhead = 0x2,
kSnapToMarkers = 0x4,
kSnapAll = 0xFF
};
/**
* @brief Snaps point `start_point` that is moving by `movement` to currently existing clips
*/
virtual bool SnapPoint(QList<rational> start_times, rational *movement, int snap_points = kSnapAll) = 0;
virtual void HideSnaps() = 0;
};
}
#endif // SNAPSERVICE_H
@@ -1,137 +0,0 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2020 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 "timelinescaledobject.h"
#include <cfloat>
#include <QtMath>
#include "common/clamp.h"
namespace olive {
const int TimelineScaledObject::kCalculateDimensionsPadding = 10;
TimelineScaledObject::TimelineScaledObject() :
scale_(1.0),
min_scale_(0),
max_scale_(DBL_MAX)
{
}
void TimelineScaledObject::SetTimebase(const rational &timebase)
{
timebase_ = timebase;
timebase_dbl_ = timebase_.toDouble();
TimebaseChangedEvent(timebase);
}
const rational &TimelineScaledObject::timebase() const
{
return timebase_;
}
const double &TimelineScaledObject::timebase_dbl() const
{
return timebase_dbl_;
}
rational TimelineScaledObject::SceneToTime(const double &x, const double &x_scale, const rational &timebase, bool round)
{
double unscaled_time = x / x_scale / timebase.toDouble();
// Adjust screen point by scale and timebase
qint64 rounded_x_mvmt;
if (round) {
rounded_x_mvmt = qRound64(unscaled_time);
} else {
rounded_x_mvmt = qFloor(unscaled_time);
}
// Return a time in the timebase
return rational(rounded_x_mvmt * timebase.numerator(), timebase.denominator());
}
double TimelineScaledObject::TimeToScene(const rational &time)
{
return time.toDouble() * scale_;
}
rational TimelineScaledObject::SceneToTime(const double &x, bool round)
{
return SceneToTime(x, scale_, timebase_, round);
}
void TimelineScaledObject::SetMaximumScale(const double &max)
{
max_scale_ = max;
if (GetScale() > max_scale_) {
SetScale(max_scale_);
}
}
void TimelineScaledObject::SetMinimumScale(const double &min)
{
min_scale_ = min;
if (GetScale() < min_scale_) {
SetScale(min_scale_);
}
}
const double& TimelineScaledObject::GetScale() const
{
return scale_;
}
void TimelineScaledObject::SetScale(const double& scale)
{
Q_ASSERT(scale > 0);
scale_ = clamp(scale, min_scale_, max_scale_);
ScaleChangedEvent(scale_);
}
void TimelineScaledObject::SetScaleFromDimensions(double viewport_width, double content_width)
{
SetScale(CalculateScaleFromDimensions(viewport_width, content_width));
}
double TimelineScaledObject::CalculateScaleFromDimensions(double viewport_sz, double content_sz)
{
return static_cast<double>(viewport_sz / kCalculateDimensionsPadding * (kCalculateDimensionsPadding-1)) / static_cast<double>(content_sz);
}
double TimelineScaledObject::CalculatePaddingFromDimensionScale(double viewport_sz)
{
return (viewport_sz / (kCalculateDimensionsPadding * 2));
}
TimelineScaledWidget::TimelineScaledWidget(QWidget *parent) :
QWidget(parent)
{
}
}
@@ -1,87 +0,0 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2020 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 TIMELINESCALEDOBJECT_H
#define TIMELINESCALEDOBJECT_H
#include <QWidget>
#include "common/rational.h"
namespace olive {
class TimelineScaledObject
{
public:
TimelineScaledObject();
virtual ~TimelineScaledObject() = default;
void SetTimebase(const rational &timebase);
const rational& timebase() const;
const double& timebase_dbl() const;
static rational SceneToTime(const double &x, const double& x_scale, const rational& timebase, bool round = false);
const double& GetScale() const;
void SetScale(const double& scale);
void SetScaleFromDimensions(double viewport_width, double content_width);
static double CalculateScaleFromDimensions(double viewport_sz, double content_sz);
static double CalculatePaddingFromDimensionScale(double viewport_sz);
double TimeToScene(const rational& time);
rational SceneToTime(const double &x, bool round = false);
protected:
virtual void TimebaseChangedEvent(const rational&){}
virtual void ScaleChangedEvent(const double&){}
void SetMaximumScale(const double& max);
void SetMinimumScale(const double& min);
private:
rational timebase_;
double timebase_dbl_;
double scale_;
double min_scale_;
double max_scale_;
static const int kCalculateDimensionsPadding;
};
class TimelineScaledWidget : public QWidget, public TimelineScaledObject
{
Q_OBJECT
public:
TimelineScaledWidget(QWidget* parent = nullptr);
};
}
#endif // TIMELINESCALEDOBJECT_H
+1 -1
View File
@@ -160,7 +160,7 @@ TimelineWidget::TimelineWidget(QWidget *parent) :
// FIXME: Magic number
SetScale(90.0);
SetMaximumScale(TimelineViewBase::kMaximumScale);
SetMaximumScale(TimeBasedView::kMaximumScale);
SetAutoSetTimebase(false);
connect(Core::instance(), &Core::ToolChanged, this, &TimelineWidget::ToolChanged);
+4 -4
View File
@@ -27,13 +27,13 @@
#include "core.h"
#include "node/block/transition/transition.h"
#include "node/nodecopypaste.h"
#include "node/output/viewer/viewer.h"
#include "snapservice.h"
#include "timeline/timelinecommon.h"
#include "timelineandtrackview.h"
#include "widget/nodecopypaste/nodecopypaste.h"
#include "widget/slider/timeslider.h"
#include "widget/timebased/timebased.h"
#include "widget/snapservice/snapservice.h"
#include "widget/timebased/timebasedwidget.h"
#include "widget/timelinewidget/timelinewidgetselections.h"
#include "widget/timelinewidget/tool/import.h"
#include "widget/timelinewidget/tool/tool.h"
@@ -45,7 +45,7 @@ namespace olive {
*
* Encapsulates TimelineViews, TimeRulers, and scrollbars for a complete widget to manipulate Timelines
*/
class TimelineWidget : public TimeBasedWidget, public NodeCopyPasteWidget, public SnapService
class TimelineWidget : public TimeBasedWidget, public NodeCopyPasteService, public SnapService
{
Q_OBJECT
public:
+1 -1
View File
@@ -68,7 +68,7 @@ void ZoomTool::MouseRelease(TimelineViewMouseEvent *event)
// Normalize scale to 1.0 scale
double scene_width = (scene_right - scene_left) / parent()->GetScale();
double new_scale = qMin(TimelineViewBase::kMaximumScale, static_cast<double>(reference_view->viewport()->width()) / scene_width);
double new_scale = qMin(TimeBasedView::kMaximumScale, static_cast<double>(reference_view->viewport()->width()) / scene_width);
parent()->SetScale(new_scale);
@@ -16,19 +16,15 @@
set(OLIVE_SOURCES
${OLIVE_SOURCES}
widget/timelinewidget/view/handmovableview.h
widget/timelinewidget/view/handmovableview.cpp
widget/timelinewidget/view/timelineview.h
widget/timelinewidget/view/timelineview.cpp
widget/timelinewidget/view/timelineviewmouseevent.h
widget/timelinewidget/view/timelineview.h
widget/timelinewidget/view/timelineviewmouseevent.cpp
widget/timelinewidget/view/timelineviewrect.h
widget/timelinewidget/view/timelineviewmouseevent.h
widget/timelinewidget/view/timelineviewrect.cpp
widget/timelinewidget/view/timelineviewbase.h
widget/timelinewidget/view/timelineviewbase.cpp
widget/timelinewidget/view/timelineviewblockitem.h
widget/timelinewidget/view/timelineviewrect.h
widget/timelinewidget/view/timelineviewblockitem.cpp
widget/timelinewidget/view/timelineviewghostitem.h
widget/timelinewidget/view/timelineviewblockitem.h
widget/timelinewidget/view/timelineviewghostitem.cpp
widget/timelinewidget/view/timelineviewghostitem.h
PARENT_SCOPE
)
@@ -1,118 +0,0 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2020 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"
namespace olive {
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_;
}
}
@@ -1,59 +0,0 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2020 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"
namespace olive {
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);
};
}
#endif // HANDMOVABLEVIEW_H
@@ -36,7 +36,7 @@
namespace olive {
TimelineView::TimelineView(Qt::Alignment vertical_alignment, QWidget *parent) :
TimelineViewBase(parent),
TimeBasedView(parent),
selections_(nullptr),
ghosts_(nullptr),
show_beam_cursor_(false),
@@ -59,7 +59,7 @@ void TimelineView::mousePressEvent(QMouseEvent *event)
}
if (dragMode() != GetDefaultDragMode()) {
TimelineViewBase::mousePressEvent(event);
TimeBasedView::mousePressEvent(event);
return;
}
@@ -76,7 +76,7 @@ void TimelineView::mouseMoveEvent(QMouseEvent *event)
}
if (dragMode() != GetDefaultDragMode()) {
TimelineViewBase::mouseMoveEvent(event);
TimeBasedView::mouseMoveEvent(event);
return;
}
@@ -93,7 +93,7 @@ void TimelineView::mouseReleaseEvent(QMouseEvent *event)
}
if (dragMode() != GetDefaultDragMode()) {
TimelineViewBase::mouseReleaseEvent(event);
TimeBasedView::mouseReleaseEvent(event);
return;
}
@@ -283,7 +283,7 @@ void TimelineView::drawForeground(QPainter *painter, const QRectF &rect)
}
// Draw standard TimelineViewBase things (such as playhead)
TimelineViewBase::drawForeground(painter, rect);
TimeBasedView::drawForeground(painter, rect);
}
void TimelineView::ToolChangedEvent(Tool::Item tool)
@@ -28,10 +28,10 @@
#include <QDropEvent>
#include "node/block/clip/clip.h"
#include "timelineviewbase.h"
#include "timelineviewblockitem.h"
#include "timelineviewmouseevent.h"
#include "timelineviewghostitem.h"
#include "widget/timebased/timebasedview.h"
#include "widget/timelinewidget/undo/undo.h"
#include "undo/undostack.h"
@@ -42,7 +42,7 @@ namespace olive {
*
* This widget primarily exposes users to viewing and modifying Block nodes, usually through a TimelineOutput node.
*/
class TimelineView : public TimelineViewBase
class TimelineView : public TimeBasedView
{
Q_OBJECT
public:
@@ -1,334 +0,0 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2020 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 "timelineviewbase.h"
#include <QGraphicsRectItem>
#include <QMouseEvent>
#include <QScrollBar>
#include <QTimer>
#include "common/timecodefunctions.h"
#include "config/config.h"
namespace olive {
const double TimelineViewBase::kMaximumScale = 8192;
TimelineViewBase::TimelineViewBase(QWidget *parent) :
HandMovableView(parent),
playhead_(0),
playhead_scene_left_(-1),
playhead_scene_right_(-1),
dragging_playhead_(false),
snapped_(false),
snap_service_(nullptr),
y_axis_enabled_(false),
y_scale_(1.0)
{
// Sets scene to our scene
setScene(&scene_);
// Set default scale (ensures non-zero scale from beginning)
SetScale(1.0);
// Default to no default drag mode
SetDefaultDragMode(NoDrag);
// Signal to update bounding rect when the scene changes
connect(&scene_, &QGraphicsScene::changed, this, &TimelineViewBase::UpdateSceneRect);
// Always enforce maximum scale
SetMaximumScale(kMaximumScale);
// Workaround for Qt drawing issues with the default MinimalViewportUpdate. While this might be
// slower (Qt documentation says it may actually be faster in some situations),
// MinimalViewportUpdate causes all sorts of graphical crud building up in the scene
setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
}
void TimelineViewBase::TimebaseChangedEvent(const rational &)
{
// Timebase influences position/visibility of playhead
viewport()->update();
}
void TimelineViewBase::EnableSnap(const QList<rational> &points)
{
snapped_ = true;
snap_time_ = points;
viewport()->update();
}
void TimelineViewBase::DisableSnap()
{
snapped_ = false;
viewport()->update();
}
void TimelineViewBase::SetSnapService(SnapService *service)
{
snap_service_ = service;
}
const double &TimelineViewBase::GetYScale() const
{
return y_scale_;
}
void TimelineViewBase::VerticalScaleChangedEvent(double)
{
}
void TimelineViewBase::SetYScale(const double &y_scale)
{
y_scale_ = y_scale;
if (y_axis_enabled_) {
VerticalScaleChangedEvent(y_scale_);
viewport()->update();
}
}
void TimelineViewBase::SetTime(const int64_t time)
{
playhead_ = time;
// Force redraw for playhead
viewport()->update();
}
void TimelineViewBase::drawForeground(QPainter *painter, const QRectF &rect)
{
QGraphicsView::drawForeground(painter, rect);
if (!timebase().isNull()) {
double width = TimeToScene(timebase());
playhead_scene_left_ = GetPlayheadX();
playhead_scene_right_ = playhead_scene_left_ + width;
QRectF playhead_rect(playhead_scene_left_, rect.top(), width, rect.height());
// Get playhead highlight color
QColor highlight = palette().text().color();
highlight.setAlpha(32);
painter->setPen(Qt::NoPen);
painter->setBrush(highlight);
painter->drawRect(playhead_rect);
// FIXME: Hardcoded...
painter->setPen(PLAYHEAD_COLOR);
painter->setBrush(Qt::NoBrush);
painter->drawLine(QLineF(playhead_rect.topLeft(), playhead_rect.bottomLeft()));
}
if (snapped_) {
painter->setPen(palette().text().color());
foreach (const rational& r, snap_time_) {
double x = TimeToScene(r);
painter->drawLine(x, rect.top(), x, rect.height());
}
}
}
rational TimelineViewBase::GetPlayheadTime() const
{
return Timecode::timestamp_to_time(playhead_, timebase());
}
bool TimelineViewBase::PlayheadPress(QMouseEvent *event)
{
QPointF scene_pos = mapToScene(event->pos());
dragging_playhead_ = (event->button() == Qt::LeftButton
&& scene_pos.x() >= playhead_scene_left_
&& scene_pos.x() < playhead_scene_right_);
return dragging_playhead_;
}
bool TimelineViewBase::PlayheadMove(QMouseEvent *event)
{
if (!dragging_playhead_) {
return false;
}
QPointF scene_pos = mapToScene(event->pos());
rational mouse_time = SceneToTime(scene_pos.x());
int64_t target_ts = qMax(static_cast<int64_t>(0), Timecode::time_to_timestamp(mouse_time, timebase()));
if (Core::instance()->snapping() && snap_service_) {
rational target_time = Timecode::timestamp_to_time(target_ts, timebase());
rational movement;
snap_service_->SnapPoint({target_time}, &movement, SnapService::kSnapAll & ~SnapService::kSnapToPlayhead);
if (!movement.isNull()) {
target_ts = Timecode::time_to_timestamp(target_time + movement, timebase());
}
}
SetTime(target_ts);
emit TimeChanged(target_ts);
return true;
}
bool TimelineViewBase::PlayheadRelease(QMouseEvent*)
{
if (dragging_playhead_) {
dragging_playhead_ = false;
if (snap_service_) {
snap_service_->HideSnaps();
}
return true;
}
return false;
}
qreal TimelineViewBase::GetPlayheadX()
{
return TimeToScene(Timecode::timestamp_to_time(playhead_, timebase()));
}
void TimelineViewBase::SetEndTime(const rational &length)
{
end_time_ = length;
UpdateSceneRect();
}
void TimelineViewBase::UpdateSceneRect()
{
QRectF bounding_rect = scene_.itemsBoundingRect();
// There's no need for a timeline to ever go below 0 on the X scale
bounding_rect.setLeft(0);
// Ensure the scene is always the full length of the timeline with a gap at the end to work with
bounding_rect.setRight(TimeToScene(end_time_) + width());
// Any further rect processing from derivatives can be done here
SceneRectUpdateEvent(bounding_rect);
// If the scene is already this rect, do nothing
if (scene_.sceneRect() != bounding_rect) {
scene_.setSceneRect(bounding_rect);
}
}
void TimelineViewBase::resizeEvent(QResizeEvent *event)
{
QGraphicsView::resizeEvent(event);
UpdateSceneRect();
}
void TimelineViewBase::ScaleChangedEvent(const double &scale)
{
TimelineScaledObject::ScaleChangedEvent(scale);
// Update scene rect
UpdateSceneRect();
// Force redraw for playhead if the above function didn't do it
viewport()->update();
}
bool TimelineViewBase::HandleZoomFromScroll(QWheelEvent *event)
{
if (WheelEventIsAZoomEvent(event)) {
// If CTRL is held (or a preference is set to swap CTRL behavior), we zoom instead of scrolling
if (!event->angleDelta().isNull()) {
bool only_vertical = false;
bool only_horizontal = false;
// Ctrl+Shift limits to only one axis
// Alt switches between horizontal only (alt held) or vertical only (alt not held)
if (y_axis_enabled_) {
if (event->modifiers() & Qt::ShiftModifier) {
if (event->modifiers() & Qt::AltModifier) {
only_horizontal = true;
} else {
only_vertical = true;
}
}
} else {
only_horizontal = true;
}
double scale_multiplier;
if (event->angleDelta().x() + event->angleDelta().y() > 0) {
scale_multiplier = 1.1;
} else {
scale_multiplier = 0.9;
}
QPointF cursor_pos;
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
cursor_pos = event->position();
#else
cursor_pos = event->posF();
#endif
if (!only_vertical) {
double new_x_scale = GetScale() * scale_multiplier;
int new_x_scroll = qRound(horizontalScrollBar()->value() / GetScale() * new_x_scale + (cursor_pos.x() - cursor_pos.x() / new_x_scale * GetScale()));
emit ScaleChanged(new_x_scale);
horizontalScrollBar()->setValue(new_x_scroll);
}
if (!only_horizontal) {
double new_y_scale = GetYScale() * scale_multiplier;
int new_y_scroll = qRound(verticalScrollBar()->value() / GetYScale() * new_y_scale + (cursor_pos.y() - cursor_pos.y() / new_y_scale * GetYScale()));
SetYScale(new_y_scale);
verticalScrollBar()->setValue(new_y_scroll);
}
}
return true;
}
return false;
}
bool TimelineViewBase::WheelEventIsAZoomEvent(QWheelEvent *event)
{
return (static_cast<bool>(event->modifiers() & Qt::ControlModifier) == !Config::Current()["ScrollZooms"].toBool());
}
}
@@ -1,129 +0,0 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2020 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 TIMELINEVIEWBASE_H
#define TIMELINEVIEWBASE_H
#include <QGraphicsView>
#include "core.h"
#include "handmovableview.h"
#include "widget/timelinewidget/snapservice.h"
#include "widget/timelinewidget/timelinescaledobject.h"
namespace olive {
class TimelineViewBase : public HandMovableView, public TimelineScaledObject
{
Q_OBJECT
public:
TimelineViewBase(QWidget* parent = nullptr);
static const double kMaximumScale;
void EnableSnap(const QList<rational>& points);
void DisableSnap();
bool IsSnapped() const
{
return snapped_;
}
void SetSnapService(SnapService* service);
const double& GetYScale() const;
void SetYScale(const double& y_scale);
public slots:
void SetTime(const int64_t time);
void SetEndTime(const rational& length);
signals:
void TimeChanged(const int64_t& time);
void ScaleChanged(double scale);
protected:
virtual void drawForeground(QPainter *painter, const QRectF &rect) override;
virtual void resizeEvent(QResizeEvent *event) override;
virtual void ScaleChangedEvent(const double& scale) override;
virtual void SceneRectUpdateEvent(QRectF&){}
virtual void VerticalScaleChangedEvent(double scale);
bool HandleZoomFromScroll(QWheelEvent* event);
bool WheelEventIsAZoomEvent(QWheelEvent* event);
rational GetPlayheadTime() const;
bool PlayheadPress(QMouseEvent* event);
bool PlayheadMove(QMouseEvent* event);
bool PlayheadRelease(QMouseEvent* event);
virtual void TimebaseChangedEvent(const rational &) override;
bool IsYAxisEnabled() const
{
return y_axis_enabled_;
}
void SetYAxisEnabled(bool e)
{
y_axis_enabled_ = e;
}
private:
qreal GetPlayheadX();
int64_t playhead_;
double playhead_scene_left_;
double playhead_scene_right_;
bool dragging_playhead_;
QGraphicsScene scene_;
bool snapped_;
QList<rational> snap_time_;
rational end_time_;
SnapService* snap_service_;
bool y_axis_enabled_;
double y_scale_;
private slots:
/**
* @brief Slot called whenever the view resizes or the scene contents change to enforce minimum scene sizes
*/
void UpdateSceneRect();
};
}
#endif // TIMELINEVIEWBASE_H
@@ -22,7 +22,7 @@
#include <QEvent>
#include "widget/timelinewidget/timelinescaledobject.h"
#include "widget/timebased/timescaledobject.h"
namespace olive {
@@ -48,14 +48,14 @@ TimelineCoordinate TimelineViewMouseEvent::GetCoordinates(bool round_time) const
return TimelineCoordinate(GetFrame(round_time), track_);
}
const Qt::KeyboardModifiers TimelineViewMouseEvent::GetModifiers() const
const Qt::KeyboardModifiers &TimelineViewMouseEvent::GetModifiers() const
{
return modifiers_;
}
rational TimelineViewMouseEvent::GetFrame(bool round) const
{
return TimelineScaledObject::SceneToTime(scene_x_, scale_x_, timebase_, round);
return TimeScaledObject::SceneToTime(scene_x_, scale_x_, timebase_, round);
}
const TrackReference &TimelineViewMouseEvent::GetTrack() const
@@ -40,7 +40,7 @@ public:
const Qt::KeyboardModifiers& modifiers = Qt::NoModifier);
TimelineCoordinate GetCoordinates(bool round_time = false) const;
const Qt::KeyboardModifiers GetModifiers() const;
const Qt::KeyboardModifiers& GetModifiers() const;
/**
* @brief Gets the time at this cursor point
@@ -50,14 +50,14 @@ void TimelineViewRect::SetTrack(const TrackReference &track)
void TimelineViewRect::ScaleChangedEvent(const double &scale)
{
TimelineScaledObject::ScaleChangedEvent(scale);
TimeScaledObject::ScaleChangedEvent(scale);
UpdateRect();
}
void TimelineViewRect::TimebaseChangedEvent(const rational &tb)
{
TimelineScaledObject::TimebaseChangedEvent(tb);
TimeScaledObject::TimebaseChangedEvent(tb);
UpdateRect();
}
@@ -24,14 +24,14 @@
#include <QGraphicsRectItem>
#include "timeline/timelinecoordinate.h"
#include "../timelinescaledobject.h"
#include "widget/timebased/timescaledobject.h"
namespace olive {
/**
* @brief A base class for graphical representations of Block nodes
*/
class TimelineViewRect : public QGraphicsRectItem, public TimelineScaledObject
class TimelineViewRect : public QGraphicsRectItem, public TimeScaledObject
{
public:
TimelineViewRect(QGraphicsItem* parent = nullptr);