reimplemented pointer default functionality

This commit is contained in:
itsmattkc
2019-10-12 06:37:53 +11:00
parent 937acd4c8c
commit 6f4e5a04e4
36 changed files with 146 additions and 63 deletions
@@ -0,0 +1,34 @@
# 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/>.
set(OLIVE_SOURCES
${OLIVE_SOURCES}
widget/timelinewidget/view/timelineplayhead.h
widget/timelinewidget/view/timelineplayhead.cpp
widget/timelinewidget/view/timelineview.h
widget/timelinewidget/view/timelineview.cpp
widget/timelinewidget/view/timelineviewmouseevent.h
widget/timelinewidget/view/timelineviewmouseevent.cpp
widget/timelinewidget/view/timelineviewrect.h
widget/timelinewidget/view/timelineviewrect.cpp
widget/timelinewidget/view/timelineviewblockitem.h
widget/timelinewidget/view/timelineviewblockitem.cpp
widget/timelinewidget/view/timelineviewenditem.h
widget/timelinewidget/view/timelineviewenditem.cpp
widget/timelinewidget/view/timelineviewghostitem.h
widget/timelinewidget/view/timelineviewghostitem.cpp
PARENT_SCOPE
)
@@ -0,0 +1,46 @@
/***
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 "timelineplayhead.h"
TimelinePlayhead::TimelinePlayhead()
{
}
QColor TimelinePlayhead::PlayheadColor()
{
return playhead_color_;
}
QColor TimelinePlayhead::PlayheadHighlightColor()
{
return playhead_highlight_color_;
}
void TimelinePlayhead::SetPlayheadColor(QColor c)
{
playhead_color_ = c;
}
void TimelinePlayhead::SetPlayheadHighlightColor(QColor c)
{
playhead_highlight_color_ = c;
}
@@ -0,0 +1,50 @@
/***
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 TIMELINEPLAYHEADSTYLE_H
#define TIMELINEPLAYHEADSTYLE_H
#include <QWidget>
/**
* @brief A QWidget proxy for TimeRuler and TimelinePlayheadItem to allow them to share CSS values
*
* To allow Qt CSS customization (which is only available to QWidgets) to be accessed by TimeRuler
*/
class TimelinePlayhead : public QWidget
{
Q_OBJECT
Q_PROPERTY(QColor playheadColor READ PlayheadColor WRITE SetPlayheadColor DESIGNABLE true)
Q_PROPERTY(QColor playheadHighlightColor READ PlayheadHighlightColor WRITE SetPlayheadHighlightColor DESIGNABLE true)
public:
TimelinePlayhead();
QColor PlayheadColor();
QColor PlayheadHighlightColor();
void SetPlayheadColor(QColor c);
void SetPlayheadHighlightColor(QColor c);
private:
QColor playhead_color_;
QColor playhead_highlight_color_;
};
#endif // TIMELINEPLAYHEADSTYLE_H
@@ -0,0 +1,318 @@
/***
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 "timelineview.h"
#include <QDebug>
#include <QMimeData>
#include <QMouseEvent>
#include <QScrollBar>
#include <QtMath>
#include <QPen>
#include "common/flipmodifiers.h"
#include "common/timecodefunctions.h"
#include "core.h"
#include "node/input/media/media.h"
#include "project/item/footage/footage.h"
TimelineView::TimelineView(const TrackType &type, Qt::Alignment vertical_alignment, QWidget *parent) :
QGraphicsView(parent),
playhead_(0),
type_(type)
{
Q_ASSERT(vertical_alignment == Qt::AlignTop || vertical_alignment == Qt::AlignBottom);
setAlignment(Qt::AlignLeft | vertical_alignment);
setScene(&scene_);
setDragMode(RubberBandDrag);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
setBackgroundRole(QPalette::Window);
connect(&scene_, SIGNAL(changed(const QList<QRectF>&)), this, SLOT(UpdateSceneRect()));
// Create end item
end_item_ = new TimelineViewEndItem();
scene_.addItem(end_item_);
// Set default scale
SetScale(1.0);
}
void TimelineView::SetScale(const double &scale)
{
scale_ = scale;
// Force redraw for playhead
viewport()->update();
end_item_->SetScale(scale_);
}
void TimelineView::SetTimebase(const rational &timebase)
{
SetTimebaseInternal(timebase);
// Timebase influences position/visibility of playhead
viewport()->update();
}
void TimelineView::SelectAll()
{
QList<QGraphicsItem*> all_items = items();
foreach (QGraphicsItem* i, all_items) {
i->setSelected(true);
}
}
void TimelineView::DeselectAll()
{
QList<QGraphicsItem*> all_items = items();
foreach (QGraphicsItem* i, all_items) {
i->setSelected(false);
}
}
void TimelineView::SetTime(const int64_t time)
{
playhead_ = time;
// Force redraw for playhead
viewport()->update();
}
void TimelineView::mousePressEvent(QMouseEvent *event)
{
TimelineViewMouseEvent timeline_event(ScreenToCoordinate(event->pos()),
event->modifiers());
emit MousePressed(&timeline_event);
}
void TimelineView::mouseMoveEvent(QMouseEvent *event)
{
TimelineViewMouseEvent timeline_event(ScreenToCoordinate(event->pos()),
event->modifiers());
emit MouseMoved(&timeline_event);
}
void TimelineView::mouseReleaseEvent(QMouseEvent *event)
{
TimelineViewMouseEvent timeline_event(ScreenToCoordinate(event->pos()),
event->modifiers());
emit MouseReleased(&timeline_event);
}
void TimelineView::mouseDoubleClickEvent(QMouseEvent *event)
{
TimelineViewMouseEvent timeline_event(ScreenToCoordinate(event->pos()),
event->modifiers());
emit MouseDoubleClicked(&timeline_event);
}
void TimelineView::dragEnterEvent(QDragEnterEvent *event)
{
TimelineViewMouseEvent timeline_event(ScreenToCoordinate(event->pos()),
event->keyboardModifiers());
timeline_event.SetMimeData(event->mimeData());
timeline_event.SetEvent(event);
emit DragEntered(&timeline_event);
}
void TimelineView::dragMoveEvent(QDragMoveEvent *event)
{
TimelineViewMouseEvent timeline_event(ScreenToCoordinate(event->pos()),
event->keyboardModifiers());
timeline_event.SetMimeData(event->mimeData());
timeline_event.SetEvent(event);
emit DragMoved(&timeline_event);
}
void TimelineView::dragLeaveEvent(QDragLeaveEvent *event)
{
emit DragLeft(event);
}
void TimelineView::dropEvent(QDropEvent *event)
{
TimelineViewMouseEvent timeline_event(ScreenToCoordinate(event->pos()),
event->keyboardModifiers());
timeline_event.SetMimeData(event->mimeData());
timeline_event.SetEvent(event);
emit DragDropped(&timeline_event);
}
void TimelineView::resizeEvent(QResizeEvent *event)
{
QGraphicsView::resizeEvent(event);
UpdateSceneRect();
}
void TimelineView::drawForeground(QPainter *painter, const QRectF &rect)
{
QGraphicsView::drawForeground(painter, rect);
if (!timebase().isNull()) {
double x = TimeToScene(rational(playhead_ * timebase().numerator(), timebase().denominator()));
double width = TimeToScene(timebase());
QRectF playhead_rect(x, rect.top(), width, rect.height());
painter->setPen(Qt::NoPen);
painter->setBrush(playhead_style_.PlayheadHighlightColor());
painter->drawRect(playhead_rect);
painter->setPen(playhead_style_.PlayheadColor());
painter->setBrush(Qt::NoBrush);
painter->drawLine(QLineF(playhead_rect.topLeft(), playhead_rect.bottomLeft()));
}
}
Stream::Type TimelineView::TrackTypeToStreamType(TrackType track_type)
{
switch (track_type) {
case kTrackTypeNone:
case kTrackTypeCount:
break;
case kTrackTypeVideo:
return Stream::kVideo;
case kTrackTypeAudio:
return Stream::kAudio;
case kTrackTypeSubtitle:
return Stream::kSubtitle;
}
return Stream::kUnknown;
}
TimelineCoordinate TimelineView::ScreenToCoordinate(const QPoint& pt)
{
return SceneToCoordinate(mapToScene(pt));
}
TimelineCoordinate TimelineView::SceneToCoordinate(const QPointF& pt)
{
return TimelineCoordinate(SceneToTime(pt.x()), TrackReference(type_, SceneToTrack(pt.y())));
}
int TimelineView::GetTrackY(int track_index)
{
int y = 0;
for (int i=0;i<track_index;i++) {
y += GetTrackHeight(i);
}
if (alignment() & Qt::AlignBottom) {
y = -y - GetTrackHeight(0);
}
return y;
}
int TimelineView::GetTrackHeight(int track_index)
{
// FIXME: Make this adjustable
Q_UNUSED(track_index)
return fontMetrics().height() * 3;
}
int TimelineView::SceneToTrack(double y)
{
int track = -1;
int heights = 0;
if (alignment() & Qt::AlignBottom) {
y = -y;
}
do {
track++;
heights += GetTrackHeight(track);
} while (y > heights);
return track;
}
void TimelineView::UserSetTime(const int64_t &time)
{
SetTime(time);
emit TimeChanged(time);
}
rational TimelineView::GetPlayheadTime()
{
return rational(playhead_ * timebase().numerator(), timebase().denominator());
}
void TimelineView::UpdateSceneRect()
{
QRectF bounding_rect = scene_.itemsBoundingRect();
// Ensure the scene height is always AT LEAST the height of the view
// The scrollbar appears to have a 1px margin on the top and bottom, hence the -2
int minimum_height = height() - horizontalScrollBar()->height() - 2;
if (alignment() & Qt::AlignBottom) {
// Ensure the scene left and bottom are always 0
bounding_rect.setBottomLeft(QPointF(0, 0));
if (bounding_rect.top() > minimum_height) {
bounding_rect.setTop(-minimum_height);
}
} else {
// Ensure the scene left and top are always 0
bounding_rect.setTopLeft(QPointF(0, 0));
if (bounding_rect.height() < minimum_height) {
bounding_rect.setHeight(minimum_height);
}
}
// Ensure the scene is always the full length of the timeline with a gap at the end to work with
end_item_->SetEndPadding(width()/4);
// If the scene is already this rect, do nothing
if (scene_.sceneRect() == bounding_rect) {
return;
}
scene_.setSceneRect(bounding_rect);
}
void TimelineView::SetEndTime(const rational &length)
{
end_item_->SetEndTime(length);
}
@@ -0,0 +1,136 @@
/***
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 TIMELINEVIEW_H
#define TIMELINEVIEW_H
#include <QGraphicsView>
#include <QDragEnterEvent>
#include <QDragMoveEvent>
#include <QDragLeaveEvent>
#include <QDropEvent>
#include "node/block/clip/clip.h"
#include "node/output/timeline/timeline.h"
#include "timelineplayhead.h"
#include "timelineviewblockitem.h"
#include "timelineviewmouseevent.h"
#include "timelineviewenditem.h"
#include "timelineviewghostitem.h"
#include "widget/timelinewidget/undo/undo.h"
#include "undo/undostack.h"
/**
* @brief A widget for viewing and interacting Sequences
*
* This widget primarily exposes users to viewing and modifying Block nodes, usually through a TimelineOutput node.
*/
class TimelineView : public QGraphicsView, public TimelineScaledObject
{
Q_OBJECT
public:
TimelineView(const TrackType& type,
Qt::Alignment vertical_alignment = Qt::AlignTop,
QWidget* parent = nullptr);
void SetScale(const double& scale);
void SelectAll();
void DeselectAll();
void SetEndTime(const rational& length);
int GetTrackY(int track_index);
int GetTrackHeight(int track_index);
public slots:
void SetTimebase(const rational& timebase);
void SetTime(const int64_t time);
signals:
void ScaleChanged(double scale);
void TimeChanged(const int64_t& time);
void MousePressed(TimelineViewMouseEvent* event);
void MouseMoved(TimelineViewMouseEvent* event);
void MouseReleased(TimelineViewMouseEvent* event);
void MouseDoubleClicked(TimelineViewMouseEvent* event);
void DragEntered(TimelineViewMouseEvent* event);
void DragMoved(TimelineViewMouseEvent* event);
void DragLeft(QDragLeaveEvent* event);
void DragDropped(TimelineViewMouseEvent* event);
protected:
virtual void mousePressEvent(QMouseEvent *event) override;
virtual void mouseMoveEvent(QMouseEvent *event) override;
virtual void mouseReleaseEvent(QMouseEvent *event) override;
virtual void mouseDoubleClickEvent(QMouseEvent *event) override;
virtual void dragEnterEvent(QDragEnterEvent *event) override;
virtual void dragMoveEvent(QDragMoveEvent *event) override;
virtual void dragLeaveEvent(QDragLeaveEvent *event) override;
virtual void dropEvent(QDropEvent *event) override;
virtual void resizeEvent(QResizeEvent *event) override;
virtual void drawForeground(QPainter *painter, const QRectF &rect) override;
private:
TrackType ConnectedTrackType();
Stream::Type TrackTypeToStreamType(TrackType track_type);
TimelineCoordinate ScreenToCoordinate(const QPoint& pt);
TimelineCoordinate SceneToCoordinate(const QPointF& pt);
int SceneToTrack(double y);
void UserSetTime(const int64_t& time);
QGraphicsScene scene_;
int64_t playhead_;
QVector<int> track_heights_;
TimelineViewEndItem* end_item_;
TimelinePlayhead playhead_style_;
rational GetPlayheadTime();
void UpdatePlayheadRect();
QRect playhead_rect_;
TrackType type_;
private slots:
/**
* @brief Slot called whenever the view resizes or the scene contents change to enforce minimum scene sizes
*/
void UpdateSceneRect();
};
#endif // TIMELINEVIEW_H
@@ -0,0 +1,111 @@
/***
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 "timelineviewblockitem.h"
#include <QBrush>
#include <QGraphicsScene>
#include <QGraphicsSceneMouseEvent>
#include <QPainter>
#include <QStyleOptionGraphicsItem>
TimelineViewBlockItem::TimelineViewBlockItem(QGraphicsItem* parent) :
TimelineViewRect(parent),
block_(nullptr)
{
setBrush(Qt::white);
}
Block *TimelineViewBlockItem::block()
{
return block_;
}
void TimelineViewBlockItem::SetBlock(Block *block)
{
block_ = block;
setFlag(QGraphicsItem::ItemIsSelectable, block_->type() == Block::kClip);
UpdateRect();
}
void TimelineViewBlockItem::UpdateRect()
{
if (block_ == nullptr) {
return;
}
double item_left = TimeToScene(block_->in());
double item_width = TimeToScene(block_->length());
// -1 on width and height so we don't overlap any adjacent clips
setRect(0, y_, item_width - 1, height_ - 1);
setPos(item_left, 0.0);
// FIXME: Untranslated
setToolTip(QString("%1\n\nIn: %2\nOut: %3\nMedia In: %4").arg(block_->Name(),
QString::number(block_->in().toDouble()),
QString::number(block_->out().toDouble()),
QString::number(block_->media_in().toDouble())));
}
void TimelineViewBlockItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED(widget)
if (block_ == nullptr) {
return;
}
switch (block_->type()) {
case Block::kClip:
/*QLinearGradient grad;
grad.setStart(0, rect().top());
grad.setFinalStop(0, rect().bottom());
grad.setColorAt(0.0, QColor(160, 160, 240));
grad.setColorAt(1.0, QColor(128, 128, 192));
painter->fillRect(rect(), grad);*/
painter->fillRect(rect(), QColor(128, 128, 192));
if (option->state & QStyle::State_Selected) {
painter->fillRect(rect(), QColor(0, 0, 0, 64));
}
painter->setPen(Qt::white);
painter->drawLine(rect().topLeft(), QPointF(rect().right(), rect().top()));
painter->drawLine(rect().topLeft(), QPointF(rect().left(), rect().bottom() - 1));
painter->drawText(rect(), static_cast<int>(Qt::AlignLeft | Qt::AlignTop), block_->block_name());
painter->setPen(QColor(64, 64, 64));
painter->drawLine(QPointF(rect().left(), rect().bottom() - 1), QPointF(rect().right(), rect().bottom() - 1));
painter->drawLine(QPointF(rect().right(), rect().bottom() - 1), QPointF(rect().right(), rect().top()));
break;
case Block::kGap:
if (option->state & QStyle::State_Selected) {
// FIXME: Make this palette or CSS
painter->fillRect(rect(), Qt::white);
}
break;
case Block::kEnd:
break;
}
}
@@ -0,0 +1,48 @@
/***
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 TIMELINEVIEWCLIPITEM_H
#define TIMELINEVIEWCLIPITEM_H
#include "timelineviewrect.h"
#include "node/block/clip/clip.h"
/**
* @brief A graphical representation of a ClipBlock
*/
class TimelineViewBlockItem : public TimelineViewRect
{
public:
TimelineViewBlockItem(QGraphicsItem* parent = nullptr);
Block* block();
void SetBlock(Block *block);
virtual void UpdateRect() override;
protected:
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override;
private:
Block* block_;
};
#endif // TIMELINEVIEWCLIPITEM_H
@@ -0,0 +1,37 @@
#include "timelineviewenditem.h"
TimelineViewEndItem::TimelineViewEndItem(QGraphicsItem *parent) :
TimelineViewRect(parent),
end_padding_(0)
{
}
void TimelineViewEndItem::SetEndTime(const rational &time)
{
end_time_ = time;
UpdateRect();
}
void TimelineViewEndItem::SetEndPadding(int padding)
{
end_padding_ = padding;
UpdateRect();
}
void TimelineViewEndItem::UpdateRect()
{
// Doesn't need to be more than one pixel
setRect(0, 0, 1, 1);
setPos(TimeToScene(end_time_) + end_padding_, 0);
}
void TimelineViewEndItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
// Item is invisible, this is a no-op
Q_UNUSED(painter)
Q_UNUSED(option)
Q_UNUSED(widget)
}
@@ -0,0 +1,29 @@
#ifndef TIMELINEVIEWENDITEM_H
#define TIMELINEVIEWENDITEM_H
#include "timelineviewrect.h"
/**
* @brief An item placed at the end point of the Timeline to ensure the correct scene size
*/
class TimelineViewEndItem : public TimelineViewRect
{
public:
TimelineViewEndItem(QGraphicsItem* parent = nullptr);
void SetEndTime(const rational& time);
void SetEndPadding(int padding);
virtual void UpdateRect() override;
protected:
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override;
private:
rational end_time_;
int end_padding_;
};
#endif // TIMELINEVIEWENDITEM_H
@@ -0,0 +1,194 @@
/***
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 "timelineviewghostitem.h"
#include <QPainter>
TimelineViewGhostItem::TimelineViewGhostItem(QGraphicsItem *parent) :
TimelineViewRect(parent),
track_adj_(0),
stream_(nullptr),
mode_(olive::timeline::kNone),
can_have_zero_length_(true)
{
SetInvisible(false);
}
TimelineViewGhostItem *TimelineViewGhostItem::FromBlock(Block *block, const TrackReference& track, int y, int height)
{
TimelineViewGhostItem* ghost = new TimelineViewGhostItem();
ghost->SetIn(block->in());
ghost->SetOut(block->out());
ghost->SetMediaIn(block->media_in());
ghost->SetTrack(track);
ghost->SetYCoords(y, height);
ghost->setData(kAttachedBlock, Node::PtrToValue(block));
if (block->type() == Block::kClip) {
ghost->can_have_zero_length_ = false;
}
return ghost;
}
bool TimelineViewGhostItem::CanHaveZeroLength()
{
return can_have_zero_length_;
}
void TimelineViewGhostItem::SetInvisible(bool invisible)
{
setBrush(Qt::NoBrush);
if (invisible) {
setPen(Qt::NoPen);
} else {
setPen(QPen(Qt::yellow, 2)); // FIXME: Make customizable via CSS
}
}
const rational &TimelineViewGhostItem::In() const
{
return in_;
}
const rational &TimelineViewGhostItem::Out() const
{
return out_;
}
const rational &TimelineViewGhostItem::MediaIn() const
{
return media_in_;
}
rational TimelineViewGhostItem::Length() const
{
return out_ - in_;
}
rational TimelineViewGhostItem::AdjustedLength() const
{
return GetAdjustedOut() - GetAdjustedIn();
}
void TimelineViewGhostItem::SetIn(const rational &in)
{
in_ = in;
UpdateRect();
}
void TimelineViewGhostItem::SetOut(const rational &out)
{
out_ = out;
UpdateRect();
}
void TimelineViewGhostItem::SetMediaIn(const rational &media_in)
{
media_in_ = media_in;
}
void TimelineViewGhostItem::SetInAdjustment(const rational &in_adj)
{
in_adj_ = in_adj;
UpdateRect();
}
void TimelineViewGhostItem::SetOutAdjustment(const rational &out_adj)
{
out_adj_ = out_adj;
UpdateRect();
}
void TimelineViewGhostItem::SetTrackAdjustment(const int &track_adj)
{
track_adj_ = track_adj;
}
void TimelineViewGhostItem::SetMediaInAdjustment(const rational &media_in_adj)
{
media_in_adj_ = media_in_adj;
}
const rational &TimelineViewGhostItem::InAdjustment() const
{
return in_adj_;
}
const rational &TimelineViewGhostItem::OutAdjustment() const
{
return out_adj_;
}
const rational &TimelineViewGhostItem::MediaInAdjustment() const
{
return media_in_adj_;
}
const int &TimelineViewGhostItem::TrackAdjustment() const
{
return track_adj_;
}
rational TimelineViewGhostItem::GetAdjustedIn() const
{
return in_ + in_adj_;
}
rational TimelineViewGhostItem::GetAdjustedOut() const
{
return out_ + out_adj_;
}
rational TimelineViewGhostItem::GetAdjustedMediaIn() const
{
return media_in_ + media_in_adj_;
}
TrackReference TimelineViewGhostItem::GetAdjustedTrack() const
{
return TrackReference(track_.type(), track_.index() + track_adj_);
}
const olive::timeline::MovementMode &TimelineViewGhostItem::mode() const
{
return mode_;
}
void TimelineViewGhostItem::SetMode(const olive::timeline::MovementMode &mode)
{
mode_ = mode;
}
void TimelineViewGhostItem::UpdateRect()
{
rational length = GetAdjustedOut() - GetAdjustedIn();
setRect(0, y_, TimeToScene(length), height_ - 1);
setPos(TimeToScene(GetAdjustedIn()), 0);
}
@@ -0,0 +1,102 @@
/***
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 TIMELINEVIEWGHOSTITEM_H
#define TIMELINEVIEWGHOSTITEM_H
#include <QVariant>
#include "common/timelinecommon.h"
#include "project/item/footage/footage.h"
#include "timelineviewblockitem.h"
#include "timelineviewrect.h"
/**
* @brief A graphical representation of changes the user is making before they apply it
*/
class TimelineViewGhostItem : public TimelineViewRect
{
public:
enum DataType {
kAttachedBlock,
kReferenceBlock,
kAttachedFootage
};
TimelineViewGhostItem(QGraphicsItem* parent = nullptr);
static TimelineViewGhostItem* FromBlock(Block *block, const TrackReference &track, int y, int height);
bool CanHaveZeroLength();
void SetInvisible(bool invisible);
const rational& In() const;
const rational& Out() const;
const rational& MediaIn() const;
rational Length() const;
rational AdjustedLength() const;
void SetIn(const rational& in);
void SetOut(const rational& out);
void SetMediaIn(const rational& media_in);
void SetInAdjustment(const rational& in_adj);
void SetOutAdjustment(const rational& out_adj);
void SetTrackAdjustment(const int& track_adj);
void SetMediaInAdjustment(const rational& media_in_adj);
const rational& InAdjustment() const;
const rational& OutAdjustment() const;
const rational& MediaInAdjustment() const;
const int& TrackAdjustment() const;
rational GetAdjustedIn() const;
rational GetAdjustedOut() const;
rational GetAdjustedMediaIn() const;
TrackReference GetAdjustedTrack() const;
const olive::timeline::MovementMode& mode() const;
void SetMode(const olive::timeline::MovementMode& mode);
virtual void UpdateRect() override;
protected:
private:
rational in_;
rational out_;
rational media_in_;
rational in_adj_;
rational out_adj_;
rational media_in_adj_;
int track_adj_;
StreamPtr stream_;
olive::timeline::MovementMode mode_;
bool can_have_zero_length_;
};
#endif // TIMELINEVIEWGHOSTITEM_H
@@ -0,0 +1,79 @@
/***
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 "timelineviewmouseevent.h"
#include <QEvent>
TimelineViewMouseEvent::TimelineViewMouseEvent(const TimelineCoordinate &coord,
const Qt::KeyboardModifiers &modifiers) :
coord_(coord),
modifiers_(modifiers),
source_event_(nullptr),
mime_data_(nullptr)
{
}
TimelineViewMouseEvent::TimelineViewMouseEvent(const rational &frame,
const TrackReference &track,
const Qt::KeyboardModifiers &modifiers) :
coord_(frame, track),
modifiers_(modifiers),
source_event_(nullptr),
mime_data_(nullptr)
{
}
const TimelineCoordinate &TimelineViewMouseEvent::GetCoordinates()
{
return coord_;
}
const Qt::KeyboardModifiers TimelineViewMouseEvent::GetModifiers()
{
return modifiers_;
}
const QMimeData* TimelineViewMouseEvent::GetMimeData()
{
return mime_data_;
}
void TimelineViewMouseEvent::SetMimeData(const QMimeData *data)
{
mime_data_ = data;
}
void TimelineViewMouseEvent::SetEvent(QEvent *event)
{
source_event_ = event;
}
void TimelineViewMouseEvent::accept()
{
if (source_event_ != nullptr)
source_event_->accept();
}
void TimelineViewMouseEvent::ignore()
{
if (source_event_ != nullptr)
source_event_->ignore();
}
@@ -0,0 +1,62 @@
/***
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 TIMELINEVIEWMOUSEEVENT_H
#define TIMELINEVIEWMOUSEEVENT_H
#include <QMimeData>
#include <QPointF>
#include <QPoint>
#include "timeline/timelinecoordinate.h"
class TimelineViewMouseEvent
{
public:
TimelineViewMouseEvent(const TimelineCoordinate& coord,
const Qt::KeyboardModifiers& modifiers = Qt::NoModifier);
TimelineViewMouseEvent(const rational& frame,
const TrackReference &track,
const Qt::KeyboardModifiers& modifiers = Qt::NoModifier);
const TimelineCoordinate& GetCoordinates();
const Qt::KeyboardModifiers GetModifiers();
const QMimeData *GetMimeData();
void SetMimeData(const QMimeData *data);
void SetEvent(QEvent* event);
void accept();
void ignore();
private:
TimelineCoordinate coord_;
Qt::KeyboardModifiers modifiers_;
QEvent* source_event_;
const QMimeData* mime_data_;
};
#endif // TIMELINEVIEWMOUSEEVENT_H
@@ -0,0 +1,54 @@
/***
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 "timelineviewrect.h"
TimelineViewRect::TimelineViewRect(QGraphicsItem* parent) :
QGraphicsRectItem(parent),
y_(0),
height_(0)
{
}
void TimelineViewRect::SetYCoords(int y, int height)
{
y_ = y;
height_ = height;
UpdateRect();
}
const TrackReference &TimelineViewRect::Track()
{
return track_;
}
void TimelineViewRect::SetTrack(const TrackReference &track)
{
track_ = track;
}
void TimelineViewRect::SetScale(const double &scale)
{
scale_ = scale;
UpdateRect();
}
@@ -0,0 +1,54 @@
/***
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 TIMELINEVIEWRECT_H
#define TIMELINEVIEWRECT_H
#include <QGraphicsRectItem>
#include "timeline/timelinecoordinate.h"
#include "../timelinescaledobject.h"
/**
* @brief A base class for graphical representations of Block nodes
*/
class TimelineViewRect : public QGraphicsRectItem, public TimelineScaledObject
{
public:
TimelineViewRect(QGraphicsItem* parent = nullptr);
void SetYCoords(int y, int height);
const TrackReference& Track();
void SetTrack(const TrackReference& track);
void SetScale(const double& scale);
virtual void UpdateRect() = 0;
protected:
int y_;
int height_;
TrackReference track_;
};
#endif // TIMELINEVIEWRECT_H