Merge branch 'master' into transitions

This commit is contained in:
itsmattkc
2019-12-08 21:48:19 +11:00
43 changed files with 1257 additions and 150 deletions
+2
View File
@@ -15,8 +15,10 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
add_subdirectory(audiomonitor)
add_subdirectory(clickablelabel)
add_subdirectory(columnedgridlayout)
add_subdirectory(flowlayout)
add_subdirectory(focusablelineedit)
add_subdirectory(footagecombobox)
add_subdirectory(menu)
add_subdirectory(nodeview)
+22
View File
@@ -0,0 +1,22 @@
# 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/clickablelabel/clickablelabel.h
widget/clickablelabel/clickablelabel.cpp
PARENT_SCOPE
)
@@ -0,0 +1,23 @@
#include "clickablelabel.h"
ClickableLabel::ClickableLabel(const QString &text, QWidget *parent) :
QLabel(text, parent)
{
}
ClickableLabel::ClickableLabel(QWidget *parent) :
QLabel(parent)
{
}
void ClickableLabel::mouseReleaseEvent(QMouseEvent *)
{
if (underMouse()) {
emit MouseClicked();
}
}
void ClickableLabel::mouseDoubleClickEvent(QMouseEvent *)
{
emit MouseDoubleClicked();
}
@@ -0,0 +1,23 @@
#ifndef CLICKABLELABEL_H
#define CLICKABLELABEL_H
#include <QLabel>
class ClickableLabel : public QLabel
{
Q_OBJECT
public:
ClickableLabel(const QString& text, QWidget* parent = nullptr);
ClickableLabel(QWidget* parent = nullptr);
protected:
virtual void mouseReleaseEvent(QMouseEvent* event) override;
virtual void mouseDoubleClickEvent(QMouseEvent* event) override;
signals:
void MouseClicked();
void MouseDoubleClicked();
};
#endif // CLICKABLELABEL_H
@@ -0,0 +1,22 @@
# 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/focusablelineedit/focusablelineedit.h
widget/focusablelineedit/focusablelineedit.cpp
PARENT_SCOPE
)
@@ -18,17 +18,17 @@
***/
#include "sliderlineedit.h"
#include "focusablelineedit.h"
#include <QKeyEvent>
SliderLineEdit::SliderLineEdit(QWidget *parent) :
FocusableLineEdit::FocusableLineEdit(QWidget *parent) :
QLineEdit(parent)
{
}
void SliderLineEdit::keyPressEvent(QKeyEvent *e)
void FocusableLineEdit::keyPressEvent(QKeyEvent *e)
{
switch (e->key()) {
case Qt::Key_Return:
@@ -43,7 +43,7 @@ void SliderLineEdit::keyPressEvent(QKeyEvent *e)
}
}
void SliderLineEdit::focusOutEvent(QFocusEvent *e)
void FocusableLineEdit::focusOutEvent(QFocusEvent *e)
{
QLineEdit::focusOutEvent(e);
@@ -23,11 +23,11 @@
#include <QLineEdit>
class SliderLineEdit : public QLineEdit
class FocusableLineEdit : public QLineEdit
{
Q_OBJECT
public:
SliderLineEdit(QWidget* parent);
FocusableLineEdit(QWidget* parent = nullptr);
signals:
void Confirmed();
@@ -58,7 +58,7 @@ void NodeParamViewWidgetBridge::CreateWidgets()
{
IntegerSlider* slider = new IntegerSlider();
widgets_.append(slider);
connect(slider, SIGNAL(ValueChanged(int)), this, SLOT(WidgetCallback()));
connect(slider, SIGNAL(ValueChanged(int64_t)), this, SLOT(WidgetCallback()));
break;
}
case NodeParam::kFloat:
+2 -2
View File
@@ -24,9 +24,9 @@ set(OLIVE_SOURCES
widget/slider/sliderbase.cpp
widget/slider/sliderlabel.h
widget/slider/sliderlabel.cpp
widget/slider/sliderlineedit.h
widget/slider/sliderlineedit.cpp
widget/slider/stringslider.h
widget/slider/stringslider.cpp
widget/slider/timeslider.h
widget/slider/timeslider.cpp
PARENT_SCOPE
)
+11
View File
@@ -53,6 +53,17 @@ void FloatSlider::SetDecimalPlaces(int i)
UpdateLabel(Value());
}
QString FloatSlider::ValueToString(const QVariant &v)
{
return QString::number(v.toDouble(), 'f', decimal_places_);
}
QVariant FloatSlider::StringToValue(const QString &s, bool *ok)
{
// Allow both floats and integers for either modes
return s.toDouble(ok);
}
void FloatSlider::ConvertValue(QVariant v)
{
emit ValueChanged(v.toDouble());
+5
View File
@@ -39,6 +39,11 @@ public:
void SetDecimalPlaces(int i);
protected:
virtual QString ValueToString(const QVariant& v) override;
virtual QVariant StringToValue(const QString& s, bool* ok) override;
signals:
void ValueChanged(double);
+22 -3
View File
@@ -31,21 +31,40 @@ int IntegerSlider::GetValue()
return Value().toInt();
}
void IntegerSlider::SetValue(const int &v)
void IntegerSlider::SetValue(const int64_t &v)
{
SliderBase::SetValue(v);
}
void IntegerSlider::SetMinimum(const int &d)
void IntegerSlider::SetMinimum(const int64_t &d)
{
SetMinimumInternal(d);
}
void IntegerSlider::SetMaximum(const int &d)
void IntegerSlider::SetMaximum(const int64_t &d)
{
SetMaximumInternal(d);
}
QVariant IntegerSlider::StringToValue(const QString &s, bool *ok)
{
bool valid;
// Allow both floats and integers for either modes
double decimal_val = s.toDouble(&valid);
if (ok) {
*ok = valid;
}
if (valid) {
// But for an integer, we round it
return qRound(decimal_val);
}
return QVariant();
}
void IntegerSlider::ConvertValue(QVariant v)
{
emit ValueChanged(v.toInt());
+7 -4
View File
@@ -31,14 +31,17 @@ public:
int GetValue();
void SetValue(const int& v);
void SetValue(const int64_t& v);
void SetMinimum(const int& d);
void SetMinimum(const int64_t& d);
void SetMaximum(const int& d);
void SetMaximum(const int64_t& d);
protected:
virtual QVariant StringToValue(const QString& s, bool* ok) override;
signals:
void ValueChanged(int);
void ValueChanged(int64_t);
private slots:
void ConvertValue(QVariant v);
+27 -41
View File
@@ -31,14 +31,16 @@ SliderBase::SliderBase(Mode mode, QWidget *parent) :
has_min_(false),
has_max_(false),
mode_(mode),
dragged_(false)
dragged_(false),
require_valid_input_(true)
{
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
label_ = new SliderLabel(this);
addWidget(label_);
editor_ = new SliderLineEdit(this);
editor_ = new FocusableLineEdit(this);
addWidget(editor_);
connect(label_, SIGNAL(drag_start()), this, SLOT(LabelPressed()));
@@ -66,6 +68,16 @@ void SliderBase::SetDragMultiplier(const double &d)
drag_multiplier_ = d;
}
void SliderBase::SetRequireValidInput(bool e)
{
require_valid_input_ = e;
}
void SliderBase::SetAlignment(Qt::Alignment alignment)
{
label_->setAlignment(alignment);
}
const QVariant &SliderBase::Value()
{
if (dragged_) {
@@ -127,26 +139,18 @@ const QVariant &SliderBase::ClampValue(const QVariant &v)
void SliderBase::UpdateLabel(const QVariant &v)
{
switch (mode_) {
case kString:
{
QString vstr = v.toString();
label_->setText(ValueToString(v));
}
if (vstr.isEmpty()) {
label_->setText(tr("(none)"));
} else {
label_->setText(vstr);
}
break;
}
case kInteger:
label_->setText(v.toString());
break;
case kFloat:
// For floats, we show a limited number of decimal places
label_->setText(QString::number(v.toDouble(), 'f', decimal_places_));
break;
}
QString SliderBase::ValueToString(const QVariant &v)
{
return v.toString();
}
QVariant SliderBase::StringToValue(const QString &s, bool *ok)
{
*ok = true;
return s;
}
void SliderBase::LabelPressed()
@@ -224,25 +228,7 @@ void SliderBase::LabelDragged(int i)
void SliderBase::LineEditConfirmed()
{
bool is_valid = true;
QVariant test_val;
// Check whether the entered value is valid for this mode
switch (mode_) {
case kString:
// Anything goes for a string
test_val = editor_->text();
break;
case kInteger:
case kFloat:
// Allow both floats and integers for either modes
test_val = editor_->text().toDouble(&is_valid);
if (is_valid && mode_ == kInteger) {
// But for an integer, we round it
test_val = qRound(test_val.toDouble());
}
break;
}
QVariant test_val = StringToValue(editor_->text(), &is_valid);
// Ensure editor doesn't signal that the focus is lost
editor_->blockSignals(true);
@@ -253,7 +239,7 @@ void SliderBase::LineEditConfirmed()
setCurrentWidget(label_);
emit ValueChanged(value_);
} else {
} else if (require_valid_input_) {
QMessageBox::critical(this,
tr("Invalid Value"),
tr("The entered value is not valid for this field."),
+12 -2
View File
@@ -24,7 +24,7 @@
#include <QStackedWidget>
#include "sliderlabel.h"
#include "sliderlineedit.h"
#include "widget/focusablelineedit/focusablelineedit.h"
class SliderBase : public QStackedWidget
{
@@ -40,6 +40,10 @@ public:
void SetDragMultiplier(const double& d);
void SetRequireValidInput(bool e);
void SetAlignment(Qt::Alignment alignment);
signals:
void ValueChanged(QVariant v);
@@ -54,6 +58,10 @@ protected:
void UpdateLabel(const QVariant& v);
virtual QString ValueToString(const QVariant &v);
virtual QVariant StringToValue(const QString& s, bool* ok);
virtual void changeEvent(QEvent* e) override;
int decimal_places_;
@@ -65,7 +73,7 @@ private:
SliderLabel* label_;
SliderLineEdit* editor_;
FocusableLineEdit* editor_;
QVariant value_;
@@ -83,6 +91,8 @@ private:
QVariant temp_dragged_value_;
bool require_valid_input_;
private slots:
void LabelPressed();
+6
View File
@@ -36,6 +36,12 @@ void StringSlider::SetValue(const QString &v)
SliderBase::SetValue(v);
}
QString StringSlider::ValueToString(const QVariant &v)
{
QString vstr = v.toString();
return (vstr.isEmpty()) ? tr("(none)") : vstr;
}
void StringSlider::ConvertValue(QVariant v)
{
emit ValueChanged(v.toString());
+3
View File
@@ -35,6 +35,9 @@ public:
void SetValue(const QString& v);
protected:
virtual QString ValueToString(const QVariant& value) override;
signals:
void ValueChanged(QString);
+34
View File
@@ -0,0 +1,34 @@
#include "timeslider.h"
#include "common/timecodefunctions.h"
TimeSlider::TimeSlider(QWidget *parent) :
IntegerSlider(parent)
{
SetMinimum(0);
}
void TimeSlider::SetTimebase(const rational &timebase)
{
timebase_ = timebase;
// Refresh label since we have a new timebase to generate a timecode with
UpdateLabel(Value());
}
QString TimeSlider::ValueToString(const QVariant &v)
{
if (timebase_.isNull()) {
// We can't generate a timecode without a timebase, so we just return the number
return IntegerSlider::ValueToString(v);
}
return olive::timestamp_to_timecode(v.toLongLong(),
timebase_,
olive::CurrentTimecodeDisplay());
}
QVariant TimeSlider::StringToValue(const QString &s, bool *ok)
{
return olive::timecode_to_timestamp(s, timebase_, olive::CurrentTimecodeDisplay(), ok);
}
+24
View File
@@ -0,0 +1,24 @@
#ifndef TIMESLIDER_H
#define TIMESLIDER_H
#include "common/rational.h"
#include "integerslider.h"
class TimeSlider : public IntegerSlider
{
public:
TimeSlider(QWidget* parent = nullptr);
void SetTimebase(const rational& timebase);
protected:
virtual QString ValueToString(const QVariant& v) override;
virtual QVariant StringToValue(const QString& s, bool* ok) override;
private:
rational timebase_;
};
#endif // TIMESLIDER_H
+3
View File
@@ -14,12 +14,15 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
add_subdirectory(trackview)
add_subdirectory(tool)
add_subdirectory(undo)
add_subdirectory(view)
set(OLIVE_SOURCES
${OLIVE_SOURCES}
widget/timelinewidget/timelineandtrackview.h
widget/timelinewidget/timelineandtrackview.cpp
widget/timelinewidget/timelinescaledobject.h
widget/timelinewidget/timelinescaledobject.cpp
widget/timelinewidget/timelinewidget.h
@@ -0,0 +1,36 @@
#include "timelineandtrackview.h"
#include <QHBoxLayout>
TimelineAndTrackView::TimelineAndTrackView(const TrackType &type, Qt::Alignment vertical_alignment, QWidget *parent) :
QWidget(parent)
{
QHBoxLayout* layout = new QHBoxLayout(this);
layout->setSpacing(0);
layout->setMargin(0);
splitter_ = new QSplitter(Qt::Horizontal);
splitter_->setChildrenCollapsible(false);
layout->addWidget(splitter_);
track_view_ = new TrackView(vertical_alignment);
splitter_->addWidget(track_view_);
view_ = new TimelineView(type, vertical_alignment);
splitter_->addWidget(view_);
}
QSplitter *TimelineAndTrackView::splitter() const
{
return splitter_;
}
TimelineView *TimelineAndTrackView::view() const
{
return view_;
}
TrackView *TimelineAndTrackView::track_view() const
{
return track_view_;
}
@@ -0,0 +1,32 @@
#ifndef TIMELINEANDTRACKVIEW_H
#define TIMELINEANDTRACKVIEW_H
#include <QSplitter>
#include <QWidget>
#include "view/timelineview.h"
#include "trackview/trackview.h"
class TimelineAndTrackView : public QWidget
{
public:
TimelineAndTrackView(const TrackType& type,
Qt::Alignment vertical_alignment = Qt::AlignTop,
QWidget* parent = nullptr);
QSplitter* splitter() const;
TimelineView* view() const;
TrackView* track_view() const;
private:
QSplitter* splitter_;
TimelineView* view_;
TrackView* track_view_;
};
#endif // TIMELINEANDTRACKVIEW_H
+115 -37
View File
@@ -7,6 +7,7 @@
#include "core.h"
#include "common/timecodefunctions.h"
#include "tool/tool.h"
#include "trackview/trackview.h"
TimelineWidget::TimelineWidget(QWidget *parent) :
QWidget(parent),
@@ -15,33 +16,43 @@ TimelineWidget::TimelineWidget(QWidget *parent) :
timeline_node_(nullptr),
playhead_(0)
{
QVBoxLayout* layout = new QVBoxLayout(this);
layout->setSpacing(0);
layout->setMargin(0);
QVBoxLayout* vert_layout = new QVBoxLayout(this);
vert_layout->setSpacing(0);
vert_layout->setMargin(0);
QHBoxLayout* ruler_and_time_layout = new QHBoxLayout();
vert_layout->addLayout(ruler_and_time_layout);
timecode_label_ = new TimeSlider();
timecode_label_->SetAlignment(Qt::AlignCenter);
timecode_label_->setVisible(false);
connect(timecode_label_, SIGNAL(ValueChanged(int64_t)), this, SIGNAL(TimeChanged(const int64_t&)));
connect(timecode_label_, SIGNAL(ValueChanged(int64_t)), this, SLOT(UpdateInternalTime(const int64_t&)));
ruler_and_time_layout->addWidget(timecode_label_);
ruler_ = new TimeRuler(true);
connect(ruler_, SIGNAL(TimeChanged(const int64_t&)), this, SIGNAL(TimeChanged(const int64_t&)));
connect(ruler_, SIGNAL(TimeChanged(const int64_t&)), this, SLOT(UpdateInternalTime(const int64_t&)));
layout->addWidget(ruler_);
ruler_and_time_layout->addWidget(ruler_);
// Create list of TimelineViews - these MUST correspond to the ViewType enum
QSplitter* view_splitter = new QSplitter(Qt::Vertical);
view_splitter->setChildrenCollapsible(false);
layout->addWidget(view_splitter);
vert_layout->addWidget(view_splitter);
// Video view
views_.append(new TimelineView(kTrackTypeVideo, Qt::AlignBottom));
views_.append(new TimelineAndTrackView(kTrackTypeVideo, Qt::AlignBottom));
// Audio view
views_.append(new TimelineView(kTrackTypeAudio, Qt::AlignTop));
views_.append(new TimelineAndTrackView(kTrackTypeAudio, Qt::AlignTop));
// Create tools
tools_.resize(olive::tool::kCount);
tools_.fill(nullptr);
tools_.replace(olive::tool::kPointer, std::make_shared<PointerTool>(this));
// tools_.replace(olive::tool::kEdit, new PointerTool(this)); FIXME: Implement
// tools_.replace(olive::tool::kEdit, new PointerTool(this)); FIXME: Implement
tools_.replace(olive::tool::kRipple, std::make_shared<RippleTool>(this));
tools_.replace(olive::tool::kRolling, std::make_shared<RollingTool>(this));
tools_.replace(olive::tool::kRazor, std::make_shared<RazorTool>(this));
@@ -49,23 +60,25 @@ TimelineWidget::TimelineWidget(QWidget *parent) :
tools_.replace(olive::tool::kSlide, std::make_shared<SlideTool>(this));
tools_.replace(olive::tool::kHand, std::make_shared<HandTool>(this));
tools_.replace(olive::tool::kZoom, std::make_shared<ZoomTool>(this));
//tools_.replace(olive::tool::kTransition, new (this)); FIXME: Implement
//tools_.replace(olive::tool::kRecord, new PointerTool(this)); FIXME: Implement
//tools_.replace(olive::tool::kAdd, new PointerTool(this)); FIXME: Implement
//tools_.replace(olive::tool::kTransition, new (this)); FIXME: Implement
//tools_.replace(olive::tool::kRecord, new PointerTool(this)); FIXME: Implement
//tools_.replace(olive::tool::kAdd, new PointerTool(this)); FIXME: Implement
import_tool_ = std::make_shared<ImportTool>(this);
// Global scrollbar
horizontal_scroll_ = new QScrollBar(Qt::Horizontal);
connect(horizontal_scroll_, SIGNAL(valueChanged(int)), ruler_, SLOT(SetScroll(int)));
connect(views_.first()->horizontalScrollBar(), SIGNAL(rangeChanged(int, int)), horizontal_scroll_, SLOT(setRange(int, int)));
layout->addWidget(horizontal_scroll_);
connect(views_.first()->view()->horizontalScrollBar(), SIGNAL(rangeChanged(int, int)), horizontal_scroll_, SLOT(setRange(int, int)));
vert_layout->addWidget(horizontal_scroll_);
foreach (TimelineAndTrackView* tview, views_) {
TimelineView* view = tview->view();
foreach (TimelineView* view, views_) {
view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
view_splitter->addWidget(view);
view_splitter->addWidget(tview);
connect(view->horizontalScrollBar(), SIGNAL(valueChanged(int)), ruler_, SLOT(SetScroll(int)));
connect(view, SIGNAL(ScaleChanged(double)), this, SLOT(SetScale(double)));
@@ -84,8 +97,12 @@ TimelineWidget::TimelineWidget(QWidget *parent) :
connect(view, SIGNAL(DragLeft(QDragLeaveEvent*)), this, SLOT(ViewDragLeft(QDragLeaveEvent*)));
connect(view, SIGNAL(DragDropped(TimelineViewMouseEvent*)), this, SLOT(ViewDragDropped(TimelineViewMouseEvent*)));
connect(tview->splitter(), SIGNAL(splitterMoved(int, int)), this, SLOT(UpdateHorizontalSplitters()));
// Connect each view's scroll to each other
foreach (TimelineView* other_view, views_) {
foreach (TimelineAndTrackView* other_tview, views_) {
TimelineView* other_view = other_tview->view();
if (view != other_view) {
connect(view->horizontalScrollBar(), SIGNAL(valueChanged(int)), other_view->horizontalScrollBar(), SLOT(setValue(int)));
}
@@ -121,9 +138,12 @@ void TimelineWidget::SetTimebase(const rational &timebase)
SetTimebaseInternal(timebase);
ruler_->SetTimebase(timebase);
timecode_label_->SetTimebase(timebase);
foreach (TimelineView* view, views_) {
view->SetTimebase(timebase);
timecode_label_->setVisible(!timebase.isNull());
foreach (TimelineAndTrackView* view, views_) {
view->view()->SetTimebase(timebase);
}
}
@@ -131,15 +151,19 @@ void TimelineWidget::resizeEvent(QResizeEvent *event)
{
QWidget::resizeEvent(event);
// Update horizontal scrollbar's page step to the width of the panel
horizontal_scroll_->setPageStep(horizontal_scroll_->width());
// Update timecode label size
UpdateTimecodeWidthFromSplitters(views_.first()->splitter());
}
void TimelineWidget::SetTime(const int64_t &timestamp)
void TimelineWidget::SetTime(int64_t timestamp)
{
ruler_->SetTime(timestamp);
foreach (TimelineView* view, views_) {
view->SetTime(timestamp);
foreach (TimelineAndTrackView* view, views_) {
view->view()->SetTime(timestamp);
}
UpdateInternalTime(timestamp);
@@ -154,10 +178,16 @@ void TimelineWidget::ConnectTimelineNode(TimelineOutput *node)
disconnect(timeline_node_, SIGNAL(TrackAdded(TrackOutput*, TrackType)), this, SLOT(AddTrack(TrackOutput*, TrackType)));
disconnect(timeline_node_, SIGNAL(TrackRemoved(TrackOutput*)), this, SLOT(RemoveTrack(TrackOutput*)));
disconnect(timeline_node_, SIGNAL(TimebaseChanged(const rational&)), this, SLOT(SetTimebase(const rational&)));
disconnect(timeline_node_, SIGNAL(TrackHeightChanged(TrackType, int, int)), this, SLOT(TrackHeightChanged(TrackType, int, int)));
SetTimebase(0);
Clear();
for (int i=0;i<views_.size();i++) {
TrackView* track_view = views_.at(i)->track_view();
track_view->DisconnectTrackList();
}
}
timeline_node_ = node;
@@ -169,14 +199,18 @@ void TimelineWidget::ConnectTimelineNode(TimelineOutput *node)
connect(timeline_node_, SIGNAL(TrackAdded(TrackOutput*, TrackType)), this, SLOT(AddTrack(TrackOutput*, TrackType)));
connect(timeline_node_, SIGNAL(TrackRemoved(TrackOutput*)), this, SLOT(RemoveTrack(TrackOutput*)));
connect(timeline_node_, SIGNAL(TimebaseChanged(const rational&)), this, SLOT(SetTimebase(const rational&)));
connect(timeline_node_, SIGNAL(TrackHeightChanged(TrackType, int, int)), this, SLOT(TrackHeightChanged(TrackType, int, int)));
SetTimebase(timeline_node_->timebase());
for (int i=0;i<views_.size();i++) {
TrackType track_type = static_cast<TrackType>(i);
TimelineView* view = views_.at(i)->view();
TrackList* track_list = timeline_node_->track_list(track_type);
TrackView* track_view = views_.at(i)->track_view();
TimelineView* view = views_.at(i);
track_view->ConnectTrackList(track_list);
view->ConnectTrackList(track_list);
view->SetEndTime(timeline_node_->timeline_length());
// Defer to the track to make all the block UI items necessary
@@ -204,15 +238,15 @@ void TimelineWidget::ZoomOut()
void TimelineWidget::SelectAll()
{
foreach (TimelineView* view, views_) {
view->SelectAll();
foreach (TimelineAndTrackView* view, views_) {
view->view()->SelectAll();
}
}
void TimelineWidget::DeselectAll()
{
foreach (TimelineView* view, views_) {
view->DeselectAll();
foreach (TimelineAndTrackView* view, views_) {
view->view()->DeselectAll();
}
}
@@ -440,12 +474,12 @@ TrackOutput *TimelineWidget::GetTrackFromReference(const TrackReference &ref)
int TimelineWidget::GetTrackY(const TrackReference &ref)
{
return views_.at(ref.type())->GetTrackY(ref.index());
return views_.at(ref.type())->view()->GetTrackY(ref.index());
}
int TimelineWidget::GetTrackHeight(const TrackReference &ref)
{
return views_.at(ref.type())->GetTrackHeight(ref.index());
return views_.at(ref.type())->view()->GetTrackHeight(ref.index());
}
void TimelineWidget::CenterOn(qreal scene_pos)
@@ -473,8 +507,8 @@ void TimelineWidget::SetScale(double scale)
ghost->SetScale(scale_);
}
foreach (TimelineView* view, views_) {
view->SetScale(scale_);
foreach (TimelineAndTrackView* view, views_) {
view->view()->SetScale(scale_);
}
}
@@ -497,12 +531,13 @@ bool TimelineWidget::HasGhosts()
void TimelineWidget::UpdateInternalTime(const int64_t &timestamp)
{
playhead_ = timestamp;
timecode_label_->SetValue(timestamp);
}
void TimelineWidget::UpdateTimelineLength(const rational &length)
{
foreach (TimelineView* view, views_) {
view->SetEndTime(length);
foreach (TimelineAndTrackView* view, views_) {
view->view()->SetEndTime(length);
}
}
@@ -588,7 +623,7 @@ void TimelineWidget::AddBlock(Block *block, TrackReference track)
block_items_.insert(block, item);
// Add item to graphics scene
views_.at(track.type())->scene()->addItem(item);
views_.at(track.type())->view()->scene()->addItem(item);
connect(block, SIGNAL(Refreshed()), this, SLOT(BlockChanged()));
break;
@@ -629,11 +664,51 @@ void TimelineWidget::BlockChanged()
}
}
void TimelineWidget::UpdateHorizontalSplitters()
{
QSplitter* sender_splitter = static_cast<QSplitter*>(sender());
foreach (TimelineAndTrackView* tview, views_) {
QSplitter* recv_splitter = tview->splitter();
if (recv_splitter != sender_splitter) {
recv_splitter->blockSignals(true);
recv_splitter->setSizes(sender_splitter->sizes());
recv_splitter->blockSignals(false);
}
}
UpdateTimecodeWidthFromSplitters(sender_splitter);
}
void TimelineWidget::UpdateTimecodeWidthFromSplitters(QSplitter* s)
{
timecode_label_->setFixedWidth(s->sizes().first() + s->handleWidth());
}
void TimelineWidget::TrackHeightChanged(TrackType type, int index, int height)
{
Q_UNUSED(index)
Q_UNUSED(height)
QMap<Block*, TimelineViewBlockItem*>::const_iterator iterator;
TimelineView* view = views_.at(type)->view();
for (iterator=block_items_.begin();iterator!=block_items_.end();iterator++) {
TimelineViewBlockItem* block_item = iterator.value();
if (block_item->Track().type() == type) {
block_item->SetYCoords(view->GetTrackY(block_item->Track().index()),
view->GetTrackHeight(block_item->Track().index()));
}
}
}
void TimelineWidget::AddGhost(TimelineViewGhostItem *ghost)
{
ghost->SetScale(scale_);
ghost_items_.append(ghost);
views_.at(ghost->Track().type())->scene()->addItem(ghost);
views_.at(ghost->Track().type())->view()->scene()->addItem(ghost);
}
void TimelineWidget::SetBlockLinksSelected(Block* block, bool selected)
@@ -663,8 +738,9 @@ void TimelineWidget::MoveRubberBandSelect(bool select_links)
QList<QGraphicsItem*> new_selected_list;
foreach (TimelineView* view, views_) {
foreach (TimelineAndTrackView* tview, views_) {
// Map global mouse coordinates to viewport
TimelineView* view = tview->view();
QRect mapped_rect(view->viewport()->mapFromGlobal(drag_origin_),
view->viewport()->mapFromGlobal(rubberband_now));
@@ -712,7 +788,9 @@ void TimelineWidget::EndRubberBandSelect(bool select_links)
void TimelineWidget::StartHandDrag()
{
// Determine which view to hand drag by which is under the cursor now
foreach (TimelineView* view, views_) {
foreach (TimelineAndTrackView* tview, views_) {
TimelineView* view = tview->view();
if (view->underMouse()) {
hand_drag_view_ = view;
hand_drag_view_origin_ = view->GetScrollCoordinates();
+12 -3
View File
@@ -5,8 +5,9 @@
#include <QRubberBand>
#include <QWidget>
#include "timelineandtrackview.h"
#include "widget/slider/timeslider.h"
#include "widget/timelinewidget/timelinescaledobject.h"
#include "widget/timelinewidget/view/timelineview.h"
#include "widget/timeruler/timeruler.h"
/**
@@ -22,7 +23,7 @@ public:
void Clear();
void SetTime(const int64_t& timestamp);
void SetTime(int64_t timestamp);
void ConnectTimelineNode(TimelineOutput* node);
@@ -324,7 +325,7 @@ private:
TrackOutput* GetTrackFromReference(const TrackReference& ref);
QList<TimelineView*> views_;
QList<TimelineAndTrackView*> views_;
TimeRuler* ruler_;
@@ -334,6 +335,8 @@ private:
QScrollBar* horizontal_scroll_;
TimeSlider* timecode_label_;
int GetTrackY(const TrackReference& ref);
int GetTrackHeight(const TrackReference& ref);
@@ -372,6 +375,12 @@ private slots:
*/
void BlockChanged();
void UpdateHorizontalSplitters();
void UpdateTimecodeWidthFromSplitters(QSplitter *s);
void TrackHeightChanged(TrackType type, int index, int height);
};
#endif // TIMELINEWIDGET_H
@@ -0,0 +1,26 @@
# 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/trackview/trackview.h
widget/timelinewidget/trackview/trackview.cpp
widget/timelinewidget/trackview/trackviewitem.h
widget/timelinewidget/trackview/trackviewitem.cpp
widget/timelinewidget/trackview/trackviewsplitter.h
widget/timelinewidget/trackview/trackviewsplitter.cpp
PARENT_SCOPE
)
@@ -0,0 +1,95 @@
#include "trackview.h"
#include <QDebug>
#include <QResizeEvent>
#include <QScrollBar>
#include <QSplitter>
#include <QVBoxLayout>
#include "trackviewitem.h"
TrackView::TrackView(Qt::Alignment vertical_alignment, QWidget *parent) :
QScrollArea(parent),
list_(nullptr),
alignment_(vertical_alignment)
{
QWidget* central = new QWidget();
setWidget(central);
setWidgetResizable(true);
QVBoxLayout* layout = new QVBoxLayout(central);
layout->setMargin(0);
layout->setSpacing(0);
if (alignment_ == Qt::AlignBottom) {
layout->addStretch();
connect(verticalScrollBar(), SIGNAL(rangeChanged(int, int)), this, SLOT(ScrollbarRangeChanged(int, int)));
last_scrollbar_max_ = verticalScrollBar()->maximum();
}
splitter_ = new TrackViewSplitter(alignment_);
splitter_->setChildrenCollapsible(false);
layout->addWidget(splitter_);
connect(splitter_, SIGNAL(TrackHeightChanged(int, int)), this, SLOT(TrackHeightChanged(int, int)));
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
}
void TrackView::ConnectTrackList(TrackList *list)
{
if (list_ != nullptr) {
foreach (TrackViewItem* item, items_) {
delete item;
}
items_.clear();
disconnect(list_, SIGNAL(TrackHeightChanged(int, int)), splitter_, SLOT(SetTrackHeight(int, int)));
disconnect(list_, SIGNAL(TrackAdded(TrackOutput*)), this, SLOT(InsertTrack(TrackOutput*)));
disconnect(list_, SIGNAL(TrackRemoved(TrackOutput*)), this, SLOT(RemoveTrack(TrackOutput*)));
}
list_ = list;
if (list_ != nullptr) {
foreach (TrackOutput* track, list_->Tracks()) {
splitter_->Insert(track->Index(), track->GetTrackHeight(), new TrackViewItem(track->GetTrackName()));
}
connect(list_, SIGNAL(TrackHeightChanged(int, int)), splitter_, SLOT(SetTrackHeight(int, int)));
connect(list_, SIGNAL(TrackAdded(TrackOutput*)), this, SLOT(InsertTrack(TrackOutput*)));
connect(list_, SIGNAL(TrackRemoved(TrackOutput*)), this, SLOT(RemoveTrack(TrackOutput*)));
}
}
void TrackView::DisconnectTrackList()
{
ConnectTrackList(nullptr);
}
void TrackView::ScrollbarRangeChanged(int, int max)
{
if (max != last_scrollbar_max_) {
int ba_val = last_scrollbar_max_ - verticalScrollBar()->value();
int new_val = max - ba_val;
verticalScrollBar()->setValue(new_val);
last_scrollbar_max_ = max;
}
}
void TrackView::TrackHeightChanged(int index, int height)
{
list_->TrackAt(index)->SetTrackHeight(height);
}
void TrackView::InsertTrack(TrackOutput *track)
{
splitter_->Insert(track->Index(), track->GetTrackHeight(), new TrackViewItem(track->GetTrackName()));
}
void TrackView::RemoveTrack(TrackOutput *track)
{
splitter_->Remove(track->Index());
}
@@ -0,0 +1,45 @@
#ifndef TRACKVIEW_H
#define TRACKVIEW_H
#include <QScrollArea>
#include <QSplitter>
#include "node/output/timeline/tracklist.h"
#include "trackviewitem.h"
#include "trackviewsplitter.h"
class TrackView : public QScrollArea
{
Q_OBJECT
public:
TrackView(Qt::Alignment vertical_alignment = Qt::AlignTop,
QWidget* parent = nullptr);
void ConnectTrackList(TrackList* list);
void DisconnectTrackList();
private:
QList<TrackViewItem*> items_;
TrackList* list_;
TrackViewSplitter* splitter_;
Qt::Alignment alignment_;
int last_scrollbar_max_;
QWidget* top_spacer_;
private slots:
void ScrollbarRangeChanged(int min, int max);
void TrackHeightChanged(int index, int height);
void InsertTrack(TrackOutput* track);
void RemoveTrack(TrackOutput* track);
};
#endif // TRACKVIEW_H
@@ -0,0 +1,84 @@
#include "trackviewitem.h"
#include <QDebug>
#include <QHBoxLayout>
#include <QMouseEvent>
#include <QPainter>
#include <QtMath>
TrackViewItem::TrackViewItem(const QString& name, Qt::Alignment alignment, QWidget *parent) :
QWidget(parent),
alignment_(alignment)
{
QHBoxLayout* layout = new QHBoxLayout(this);
layout->setSpacing(0);
layout->setMargin(0);
stack_ = new QStackedWidget();
layout->addWidget(stack_);
label_ = new ClickableLabel(name);
connect(label_, SIGNAL(MouseDoubleClicked()), this, SLOT(LabelClicked()));
stack_->addWidget(label_);
line_edit_ = new FocusableLineEdit();
connect(line_edit_, SIGNAL(Confirmed()), this, SLOT(LineEditConfirmed()));
connect(line_edit_, SIGNAL(Cancelled()), this, SLOT(LineEditCancelled()));
stack_->addWidget(line_edit_);
mute_button_ = CreateMSLButton(tr("M"), Qt::red);
layout->addWidget(mute_button_);
solo_button_ = CreateMSLButton(tr("S"), Qt::yellow);
layout->addWidget(solo_button_);
lock_button_ = CreateMSLButton(tr("L"), Qt::gray);
layout->addWidget(lock_button_);
setMinimumHeight(mute_button_->height());
}
QPushButton *TrackViewItem::CreateMSLButton(const QString& text, const QColor& checked_color) const
{
QPushButton* button = new QPushButton(text);
button->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
button->setCheckable(true);
button->setStyleSheet(QStringLiteral("QPushButton::checked { background: %1; }").arg(checked_color.name()));
int size = button->sizeHint().height();
size = qRound(size * 0.75);
button->setFixedSize(size, size);
return button;
}
void TrackViewItem::LabelClicked()
{
stack_->setCurrentWidget(line_edit_);
line_edit_->setFocus();
line_edit_->selectAll();
}
void TrackViewItem::LineEditConfirmed()
{
line_edit_->blockSignals(true);
QString line_edit_str = line_edit_->text();
if (!line_edit_str.isEmpty()) {
label_->setText(line_edit_str);
emit NameChanged(line_edit_str);
}
stack_->setCurrentWidget(label_);
line_edit_->blockSignals(false);
}
void TrackViewItem::LineEditCancelled()
{
line_edit_->blockSignals(true);
stack_->setCurrentWidget(label_);
line_edit_->blockSignals(false);
}
@@ -0,0 +1,45 @@
#ifndef TRACKVIEWITEM_H
#define TRACKVIEWITEM_H
#include <QPushButton>
#include <QStackedWidget>
#include <QWidget>
#include "widget/clickablelabel/clickablelabel.h"
#include "widget/focusablelineedit/focusablelineedit.h"
class TrackViewItem : public QWidget
{
Q_OBJECT
public:
TrackViewItem(const QString& name,
Qt::Alignment alignment = Qt::AlignTop,
QWidget* parent = nullptr);
signals:
void NameChanged(const QString& name);
private:
QPushButton* CreateMSLButton(const QString &text, const QColor &checked_color) const;
Qt::Alignment alignment_;
QStackedWidget* stack_;
ClickableLabel* label_;
FocusableLineEdit* line_edit_;
QPushButton* mute_button_;
QPushButton* solo_button_;
QPushButton* lock_button_;
private slots:
void LabelClicked();
void LineEditConfirmed();
void LineEditCancelled();
};
#endif // TRACKVIEWITEM_H
@@ -0,0 +1,150 @@
#include "trackviewsplitter.h"
#include <QDebug>
#include <QPainter>
TrackViewSplitter::TrackViewSplitter(Qt::Alignment vertical_alignment, QWidget* parent) :
QSplitter(Qt::Vertical, parent),
alignment_(vertical_alignment)
{
setHandleWidth(1);
int initial_height = 0;
// Add empty spacer so we get a splitter handle after the last element
addWidget(new QWidget());
setFixedHeight(initial_height);
}
void TrackViewSplitter::HandleReceiver(TrackViewSplitterHandle *h, int diff)
{
int ele_id = -1;
for (int i=0;i<count();i++) {
if (handle(i) == h) {
ele_id = i;
break;
}
}
// The handle index is actually always one above the element index
if (alignment_ == Qt::AlignTop) {
ele_id--;
} else if (alignment_ == Qt::AlignBottom) {
diff = -diff;
}
QList<int> element_sizes = sizes();
int old_ele_sz = element_sizes.at(ele_id);
// Transform element size by diff
int new_ele_sz = old_ele_sz + diff;
// Validate it with the widget's minimum size
new_ele_sz = qMax(new_ele_sz, widget(ele_id)->minimumHeight());
// Correct diff
diff = new_ele_sz - old_ele_sz;
SetTrackHeight(ele_id, new_ele_sz);
if (alignment_ == Qt::AlignBottom) {
ele_id = count() - ele_id - 1;
}
emit TrackHeightChanged(ele_id, new_ele_sz);
}
void TrackViewSplitter::SetTrackHeight(int index, int h)
{
QList<int> element_sizes = sizes();
int old_ele_sz = element_sizes.at(index);
int diff = h - old_ele_sz;
// Set new size on element
element_sizes.replace(index, h);
setSizes(element_sizes);
// Increase height by the difference
setFixedHeight(height() + diff);
}
void TrackViewSplitter::SetHeightWithSizes(const QList<int> &sizes)
{
int start_height = 0;
foreach (int s, sizes) {
start_height += s + handleWidth();
}
setFixedHeight(start_height);
setSizes(sizes);
}
void TrackViewSplitter::Insert(int index, int height, QWidget *item)
{
QList<int> sz = sizes();
if (alignment_ == Qt::AlignBottom) {
index = count() - index;
}
sz.insert(index, height);
insertWidget(index, item);
SetHeightWithSizes(sz);
}
void TrackViewSplitter::Remove(int index)
{
QList<int> sz = sizes();
if (alignment_ == Qt::AlignBottom) {
index = count() - index;
}
sz.removeAt(index);
delete widget(index);
SetHeightWithSizes(sz);
}
QSplitterHandle *TrackViewSplitter::createHandle()
{
return new TrackViewSplitterHandle(orientation(), this);
}
TrackViewSplitterHandle::TrackViewSplitterHandle(Qt::Orientation orientation, QSplitter *parent) :
QSplitterHandle(orientation, parent),
dragging_(false)
{
}
void TrackViewSplitterHandle::mousePressEvent(QMouseEvent *)
{
}
void TrackViewSplitterHandle::mouseMoveEvent(QMouseEvent *)
{
if (dragging_) {
static_cast<TrackViewSplitter*>(parent())->HandleReceiver(this, QCursor::pos().y() - drag_y_);
}
drag_y_ = QCursor::pos().y();
dragging_ = true;
}
void TrackViewSplitterHandle::mouseReleaseEvent(QMouseEvent *)
{
dragging_ = false;
}
void TrackViewSplitterHandle::paintEvent(QPaintEvent *)
{
QPainter p(this);
p.fillRect(rect(), palette().base());
}
@@ -0,0 +1,51 @@
#ifndef TRACKVIEWSPLITTER_H
#define TRACKVIEWSPLITTER_H
#include <QSplitter>
class TrackViewSplitterHandle : public QSplitterHandle
{
Q_OBJECT
public:
TrackViewSplitterHandle(Qt::Orientation orientation, QSplitter *parent);
protected:
virtual void mousePressEvent(QMouseEvent *e) override;
virtual void mouseMoveEvent(QMouseEvent *e) override;
virtual void mouseReleaseEvent(QMouseEvent *e) override;
virtual void paintEvent(QPaintEvent *e) override;
private:
int drag_y_;
bool dragging_;
};
class TrackViewSplitter : public QSplitter
{
Q_OBJECT
public:
TrackViewSplitter(Qt::Alignment vertical_alignment, QWidget* parent = nullptr);
void HandleReceiver(TrackViewSplitterHandle* h, int diff);
void SetHeightWithSizes(const QList<int>& sizes);
void Insert(int index, int height, QWidget* item);
void Remove(int index);
public slots:
void SetTrackHeight(int index, int h);
signals:
void TrackHeightChanged(int index, int height);
protected:
virtual QSplitterHandle *createHandle() override;
private:
Qt::Alignment alignment_;
};
#endif // TRACKVIEWSPLITTER_H
@@ -35,6 +35,7 @@
TimelineView::TimelineView(const TrackType &type, Qt::Alignment vertical_alignment, QWidget *parent) :
QGraphicsView(parent),
connected_track_list_(nullptr),
playhead_(0),
type_(type)
{
@@ -230,12 +231,16 @@ int TimelineView::GetTrackY(int track_index)
{
int y = 0;
if (alignment() & Qt::AlignBottom) {
track_index++;
}
for (int i=0;i<track_index;i++) {
y += GetTrackHeight(i);
}
if (alignment() & Qt::AlignBottom) {
y = -y - GetTrackHeight(0);
y = -y;
}
return y;
@@ -243,10 +248,11 @@ int TimelineView::GetTrackY(int track_index)
int TimelineView::GetTrackHeight(int track_index)
{
// FIXME: Make this adjustable
Q_UNUSED(track_index)
if (!connected_track_list_ || track_index >= connected_track_list_->TrackCount()) {
return TrackOutput::GetDefaultTrackHeight();
}
return fontMetrics().height() * 3;
return connected_track_list_->TrackAt(track_index)->GetTrackHeight();
}
QPoint TimelineView::GetScrollCoordinates()
@@ -260,6 +266,11 @@ void TimelineView::SetScrollCoordinates(const QPoint &pt)
verticalScrollBar()->setValue(pt.y());
}
void TimelineView::ConnectTrackList(TrackList *list)
{
connected_track_list_ = list;
}
int TimelineView::SceneToTrack(double y)
{
int track = -1;
@@ -64,6 +64,8 @@ public:
QPoint GetScrollCoordinates();
void SetScrollCoordinates(const QPoint& pt);
void ConnectTrackList(TrackList* list);
public slots:
void SetTimebase(const rational& timebase);
@@ -110,20 +112,20 @@ private:
void UserSetTime(const int64_t& time);
rational GetPlayheadTime();
void UpdatePlayheadRect();
TrackList* connected_track_list_;
QGraphicsScene scene_;
int64_t playhead_;
QVector<int> track_heights_;
TimelineViewEndItem* end_item_;
TimelinePlayhead playhead_style_;
rational GetPlayheadTime();
void UpdatePlayheadRect();
QRect playhead_rect_;
TrackType type_;