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
+1 -1
View File
@@ -68,7 +68,7 @@ if(MSVC)
# Enabling this threw warnings from FFmpeg headers that broke compilation. See if this is fixable.
#target_compile_options(${OLIVE_TARGET} PRIVATE /W4 /WX)
else()
target_compile_options(${OLIVE_TARGET} PRIVATE -O3 -Werror -Wuninitialized -pedantic-errors -Wall -Wextra -Wconversion -Wsign-conversion)
target_compile_options(${OLIVE_TARGET} PRIVATE -O2 -Werror -Wuninitialized -pedantic-errors -Wall -Wextra -Wconversion -Wsign-conversion)
endif()
target_include_directories(
+161 -25
View File
@@ -24,7 +24,7 @@
#include "config/config.h"
QString padded(int arg, int padding) {
QString padded(int64_t arg, int padding) {
return QString("%1").arg(arg, padding, 10, QChar('0'));
}
@@ -35,21 +35,11 @@ QString olive::timestamp_to_timecode(const int64_t &timestamp,
{
double timestamp_dbl = (rational(timestamp) * timebase).toDouble();
// Determine what symbol to separate frames (";" is used for drop frame, ":" is non-drop frame)
QString frame_token = ";";
switch (display) {
case kTimecodeNonDropFrame:
frame_token = ":";
// Convert timestamp from drop frame to non-drop frame
// FIXME: There's probably a better way to do this
if (timebase == rational(1001, 30000)) {
timestamp_dbl = timestamp_dbl / (30000.0/1001.0) * 30.0;
} else if (timebase == rational(1001, 60000)) {
timestamp_dbl = timestamp_dbl / (60000.0/1001.0) * 60.0;
} else if (timebase == rational(1001, 24000)) {
timestamp_dbl = timestamp_dbl / (24000.0/1001.0) * 24.0;
if (timebase.numerator() == 1001) {
timestamp_dbl = timestamp_dbl / timebase.flipped().toDouble() * (static_cast<double>(timebase.denominator())/1000.0);
}
/* fall-through */
case kTimecodeDropFrame:
@@ -63,16 +53,15 @@ QString olive::timestamp_to_timecode(const int64_t &timestamp,
prefix = "+";
}
timestamp_dbl = qAbs(timestamp_dbl);
int total_seconds = qFloor(timestamp_dbl);
int hours = total_seconds / 3600;
int mins = total_seconds / 60 - hours * 60;
int secs = total_seconds - mins * 60;
if (display == kTimecodeSeconds) {
int fraction = qRound((timestamp_dbl - total_seconds) * 1000);
timestamp_dbl = qAbs(timestamp_dbl);
int64_t total_seconds = qFloor(timestamp_dbl);
int64_t hours = total_seconds / 3600;
int64_t mins = total_seconds / 60 - hours * 60;
int64_t secs = total_seconds - mins * 60;
int64_t fraction = qRound64((timestamp_dbl - static_cast<double>(total_seconds)) * 1000);
return QString("%1%2:%3:%4.%5").arg(prefix,
padded(hours, 2),
@@ -80,9 +69,49 @@ QString olive::timestamp_to_timecode(const int64_t &timestamp,
padded(secs, 2),
padded(fraction, 3));
} else {
rational frame_rate = timebase.flipped();
// Determine what symbol to separate frames (";" is used for drop frame, ":" is non-drop frame)
QString frame_token;
double frame_rate = timebase.flipped().toDouble();
int rounded_frame_rate = qRound(frame_rate);
int64_t frames, secs, mins, hours;
int64_t f = timestamp;
int frames = qRound((timestamp_dbl - total_seconds) * frame_rate.toDouble());
if (display == kTimecodeDropFrame && timebase.numerator() == 1001) {
frame_token = ";";
/**
* CONVERT A FRAME NUMBER TO DROP FRAME TIMECODE
*
* Code by David Heidelberger, adapted from Andrew Duncan, further adapted for Olive by Olive Team
* Given an int called framenumber and a double called framerate
* Framerate should be 29.97, 59.94, or 23.976, otherwise the calculations will be off.
*/
// If frame number is greater than 24 hrs, next operation will rollover clock
f %= (qRound(frame_rate*3600)*24);
// Number of frames per ten minutes
int64_t framesPer10Minutes = qRound(frame_rate * 600);
int64_t d = f / framesPer10Minutes;
int64_t m = f % framesPer10Minutes;
// Number of frames to drop on the minute marks is the nearest integer to 6% of the framerate
int64_t dropFrames = qRound(frame_rate * (2.0/30.0));
// Number of frames per minute is the round of the framerate * 60 minus the number of dropped frames
f += dropFrames*9*d;
if (m > dropFrames) {
f += dropFrames * ((m - dropFrames) / (qRound(frame_rate)*60 - dropFrames));
}
} else {
frame_token = ":";
}
// non-drop timecode
hours = f / (3600*rounded_frame_rate);
mins = f / (60*rounded_frame_rate) % 60;
secs = f / rounded_frame_rate % 60;
frames = f % rounded_frame_rate;
return QString("%1%2:%3:%4%5%6").arg(prefix,
padded(hours, 2),
@@ -101,6 +130,108 @@ QString olive::timestamp_to_timecode(const int64_t &timestamp,
return QString();
}
int64_t olive::timecode_to_timestamp(const QString &timecode, const rational &timebase, const olive::TimecodeDisplay &display, bool* ok)
{
double timebase_dbl = timebase.toDouble();
if (timecode.isEmpty()) {
goto err_fatal;
}
switch (display) {
case kTimecodeNonDropFrame:
case kTimecodeDropFrame:
case kTimecodeSeconds:
{
const int kTimecodeElementCount = 4;
QStringList timecode_split = timecode.split(QRegExp("(:)|(;)|(\\.)"));
bool valid;
// We only deal with HH, MM, SS, and FF. Any values after that are ignored.
while (timecode_split.size() > kTimecodeElementCount) {
timecode_split.removeLast();
}
// Convert values to integers
QList<int64_t> timecode_numbers;
foreach (const QString& element, timecode_split) {
valid = true;
timecode_numbers.append((element.isEmpty()) ? 0 : element.toLong(&valid));
// If element cannot be converted to a number,
if (!valid) {
goto err_fatal;
}
}
// Ensure value size is always 4
while (timecode_numbers.size() < 4) {
timecode_numbers.prepend(0);
}
double frame_rate = timebase.flipped().toDouble();
int rounded_frame_rate = qRound(frame_rate);
int64_t hours = timecode_numbers.at(0);
int64_t mins = timecode_numbers.at(1);
int64_t secs = timecode_numbers.at(2);
int64_t frames = timecode_numbers.at(3);
int64_t sec_count = (hours*3600 + mins*60 + secs);
int64_t timestamp = sec_count*rounded_frame_rate + frames;
if (display == kTimecodeDropFrame && timebase.numerator() == 1001) {
// Number of frames to drop on the minute marks is the nearest integer to 6% of the framerate
int64_t dropFrames = qRound64(frame_rate * (2.0/30.0));
// d and m need to be calculated from
int64_t real_fr_ts = qRound64(static_cast<double>(sec_count)*frame_rate) + frames;
int64_t framesPer10Minutes = qRound(frame_rate * 600);
int64_t d = real_fr_ts / framesPer10Minutes;
int64_t m = real_fr_ts % framesPer10Minutes;
if (m > dropFrames) {
timestamp -= dropFrames * ((m - dropFrames) / (qRound(frame_rate)*60 - dropFrames));
}
timestamp -= dropFrames*9*d;
}
if (ok) *ok = true;
return timestamp;
}
case kMilliseconds:
{
bool valid;
double timecode_secs = timecode.toDouble(&valid);
if (valid) {
// Convert milliseconds to seconds
timecode_secs *= 0.001;
// Convert seconds to frames
timecode_secs /= timebase_dbl;
if (ok) *ok = true;
return qRound(timecode_secs);
} else {
goto err_fatal;
}
}
case kFrames:
if (ok) *ok = true;
return timecode.toLong(ok);
}
err_fatal:
if (ok) *ok = false;
return 0;
}
rational olive::timestamp_to_time(const int64_t &timestamp, const rational &timebase)
{
return rational(timestamp) * timebase;
@@ -108,7 +239,12 @@ rational olive::timestamp_to_time(const int64_t &timestamp, const rational &time
int64_t olive::time_to_timestamp(const rational &time, const rational &timebase)
{
return qRound64(time.toDouble() * timebase.flipped().toDouble());
return time_to_timestamp(time.toDouble(), timebase);
}
int64_t olive::time_to_timestamp(const double &time, const rational &timebase)
{
return qRound64(time * timebase.flipped().toDouble());
}
olive::TimecodeDisplay olive::CurrentTimecodeDisplay()
+3
View File
@@ -42,7 +42,10 @@ TimecodeDisplay CurrentTimecodeDisplay();
*/
QString timestamp_to_timecode(const int64_t &timestamp, const rational& timebase, const TimecodeDisplay& display, bool show_plus_if_positive = false);
int64_t timecode_to_timestamp(const QString& timecode, const rational& timebase, const TimecodeDisplay& display, bool *ok = nullptr);
int64_t time_to_timestamp(const rational& time, const rational& timebase);
int64_t time_to_timestamp(const double& time, const rational& timebase);
rational timestamp_to_time(const int64_t& timestamp, const rational& timebase);
+1 -1
View File
@@ -49,7 +49,7 @@ Config &Config::Current()
void Config::SetDefaults()
{
config_map_.clear();
config_map_["TimecodeDisplay"] = olive::kTimecodeNonDropFrame;
config_map_["TimecodeDisplay"] = olive::kTimecodeDropFrame;
config_map_["DefaultStillLength"] = QVariant::fromValue(rational(2));
config_map_["HoverFocus"] = false;
config_map_["AudioScrubbing"] = true;
+6
View File
@@ -46,6 +46,7 @@ TimelineOutput::TimelineOutput()
connect(list, SIGNAL(BlockRemoved(Block*)), this, SIGNAL(BlockRemoved(Block*)));
connect(list, SIGNAL(TrackAdded(TrackOutput*)), this, SLOT(TrackListAddedTrack(TrackOutput*)));
connect(list, SIGNAL(TrackRemoved(TrackOutput*)), this, SIGNAL(TrackRemoved(TrackOutput*)));
connect(list, SIGNAL(TrackHeightChanged(int, int)), this, SLOT(TrackHeightChangedSlot(int, int)));
}
}
@@ -196,3 +197,8 @@ void TimelineOutput::TrackListAddedTrack(TrackOutput *track)
TrackType type = static_cast<TrackList*>(sender())->TrackType();
emit TrackAdded(track, type);
}
void TimelineOutput::TrackHeightChangedSlot(int index, int height)
{
emit TrackHeightChanged(static_cast<TrackList*>(sender())->type(), index, height);
}
+4
View File
@@ -70,6 +70,8 @@ signals:
void TrackAdded(TrackOutput* track, TrackType type);
void TrackRemoved(TrackOutput* track);
void TrackHeightChanged(TrackType type, int index, int height);
protected:
virtual NodeValueTable Value(const NodeValueDatabase& value) const override;
@@ -93,6 +95,8 @@ private slots:
void TrackListAddedTrack(TrackOutput* track);
void TrackHeightChangedSlot(int index, int height);
};
#endif // TIMELINEOUTPUT_H
+23 -9
View File
@@ -33,6 +33,11 @@ TrackList::TrackList(TimelineOutput* parent, const enum TrackType &type, NodeInp
connect(track_input, SIGNAL(SizeChanged(int)), this, SLOT(TrackListSizeChanged(int)));
}
const TrackType &TrackList::type() const
{
return type_;
}
void TrackList::TrackAddedBlock(Block *block)
{
emit BlockAdded(block, static_cast<TrackOutput*>(sender())->Index());
@@ -55,12 +60,12 @@ void TrackList::TrackListSizeChanged(int size)
}
}
const QVector<TrackOutput *> &TrackList::Tracks()
const QVector<TrackOutput *> &TrackList::Tracks() const
{
return track_cache_;
}
TrackOutput *TrackList::TrackAt(int index)
TrackOutput *TrackList::TrackAt(int index) const
{
if (index < 0 || index >= track_cache_.size()) {
return nullptr;
@@ -69,16 +74,21 @@ TrackOutput *TrackList::TrackAt(int index)
return track_cache_.at(index);
}
const rational &TrackList::TrackLength()
const rational &TrackList::TrackLength() const
{
return total_length_;
}
const enum TrackType &TrackList::TrackType()
const enum TrackType &TrackList::TrackType() const
{
return type_;
}
int TrackList::TrackCount() const
{
return track_cache_.size();
}
TrackOutput* TrackList::AddTrack()
{
TrackOutput* track = new TrackOutput();
@@ -104,9 +114,6 @@ TrackOutput* TrackList::AddTrack()
}*/
// End test code
// Connect this track to the current last track
NodeParam::ConnectEdge(track->output(), assoc_input);
return track;
}
@@ -132,13 +139,14 @@ void TrackList::TrackConnected(NodeEdgePtr edge)
Node* connected_node = edge->output()->parentNode();
if (connected_node->IsTrack()) {
TrackOutput* connected_track = static_cast<TrackOutput*>(connected_node);// Traverse through Tracks caching and connecting them
TrackOutput* connected_track = static_cast<TrackOutput*>(connected_node);
track_cache_.replace(track_index, connected_track);
connect(connected_track, SIGNAL(BlockAdded(Block*)), this, SLOT(TrackAddedBlock(Block*)));
connect(connected_track, SIGNAL(BlockRemoved(Block*)), this, SLOT(TrackRemovedBlock(Block*)));
connect(connected_track, SIGNAL(TrackLengthChanged()), this, SLOT(UpdateTotalLength()));
connect(connected_track, SIGNAL(TrackHeightChanged(int)), this, SLOT(TrackHeightChangedSlot(int)));
connected_track->SetIndex(track_index);
connected_track->set_track_type(type_);
@@ -175,6 +183,7 @@ void TrackList::TrackDisconnected(NodeEdgePtr edge)
disconnect(track, SIGNAL(BlockAdded(Block*)), this, SLOT(TrackAddedBlock(Block*)));
disconnect(track, SIGNAL(BlockRemoved(Block*)), this, SLOT(TrackRemovedBlock(Block*)));
disconnect(track, SIGNAL(TrackLengthChanged()), this, SLOT(UpdateTotalLength()));
disconnect(track, SIGNAL(TrackHeightChanged(int)), this, SLOT(TrackHeightChangedSlot(int)));
emit TrackListChanged();
@@ -182,7 +191,7 @@ void TrackList::TrackDisconnected(NodeEdgePtr edge)
}
}
NodeGraph *TrackList::GetParentGraph()
NodeGraph *TrackList::GetParentGraph() const
{
return static_cast<NodeGraph*>(parent()->parent());
}
@@ -199,3 +208,8 @@ void TrackList::UpdateTotalLength()
emit LengthChanged(total_length_);
}
void TrackList::TrackHeightChangedSlot(int height)
{
emit TrackHeightChanged(static_cast<TrackOutput*>(sender())->Index(), height);
}
+16 -5
View File
@@ -34,17 +34,21 @@ class TrackList : public QObject {
public:
TrackList(TimelineOutput *parent, const enum TrackType& type, NodeInputArray* track_input);
const QVector<TrackOutput*>& Tracks();
const enum TrackType& type() const;
TrackOutput* TrackAt(int index);
const QVector<TrackOutput*>& Tracks() const;
TrackOutput* TrackAt(int index) const;
TrackOutput *AddTrack();
void RemoveTrack();
const rational& TrackLength();
const rational& TrackLength() const;
const enum TrackType& TrackType();
const enum TrackType& TrackType() const;
int TrackCount() const;
signals:
void BlockAdded(Block* block, int index);
@@ -59,8 +63,10 @@ signals:
void LengthChanged(const rational &length);
void TrackHeightChanged(int index, int height);
private:
NodeGraph* GetParentGraph();
NodeGraph* GetParentGraph() const;
/**
* @brief A cache of connected Tracks
@@ -104,6 +110,11 @@ private slots:
*/
void UpdateTotalLength();
/**
* @brief Slot when a track height changes, transforms to the TrackHeightChanged signal which includes a track index
*/
void TrackHeightChangedSlot(int height);
};
#endif // TRACKLIST_H
+52
View File
@@ -20,7 +20,9 @@
#include "track.h"
#include <QApplication>
#include <QDebug>
#include <QFontMetrics>
#include "node/block/gap/gap.h"
#include "node/graph.h"
@@ -35,6 +37,9 @@ TrackOutput::TrackOutput() :
connect(block_input_, SIGNAL(EdgeAdded(NodeEdgePtr)), this, SLOT(BlockConnected(NodeEdgePtr)));
connect(block_input_, SIGNAL(EdgeRemoved(NodeEdgePtr)), this, SLOT(BlockDisconnected(NodeEdgePtr)));
connect(block_input_, SIGNAL(SizeChanged(int)), this, SLOT(BlockListSizeChanged(int)));
// Set default height
track_height_ = GetDefaultTrackHeight();
}
void TrackOutput::set_track_type(const TrackType &track_type)
@@ -78,6 +83,26 @@ QString TrackOutput::Description() const
"a Sequence.");
}
QString TrackOutput::GetTrackName()
{
if (track_name_.isEmpty()) {
return GetDefaultTrackName(track_type_, index_);
}
return track_name_;
}
const int &TrackOutput::GetTrackHeight() const
{
return track_height_;
}
void TrackOutput::SetTrackHeight(const int &height)
{
track_height_ = height;
emit TrackHeightChanged(track_height_);
}
void TrackOutput::Retranslate()
{
block_input_->set_name(tr("Blocks"));
@@ -310,6 +335,33 @@ bool TrackOutput::IsTrack() const
return true;
}
int TrackOutput::GetDefaultTrackHeight()
{
return qApp->fontMetrics().height() * 3;
}
QString TrackOutput::GetDefaultTrackName(TrackType type, int index)
{
// Starts tracks at 1 rather than 0
int user_friendly_index = index+1;
switch (type) {
case kTrackTypeVideo: return tr("Video %1").arg(user_friendly_index);
case kTrackTypeAudio: return tr("Audio %1").arg(user_friendly_index);
case kTrackTypeSubtitle: return tr("Subtitle %1").arg(user_friendly_index);
case kTrackTypeNone:
case kTrackTypeCount:
break;
}
return tr("Track %1").arg(user_friendly_index);
}
void TrackOutput::SetTrackName(const QString &name)
{
track_name_ = name;
}
void TrackOutput::UpdateInOutFrom(int index)
{
Q_ASSERT(index >= 0);
+21
View File
@@ -45,6 +45,11 @@ public:
virtual QString Category() const override;
virtual QString Description() const override;
QString GetTrackName();
const int& GetTrackHeight() const;
void SetTrackHeight(const int& height);
virtual void Retranslate() override;
const int& Index();
@@ -127,6 +132,13 @@ public:
virtual bool IsTrack() const override;
static int GetDefaultTrackHeight();
static QString GetDefaultTrackName(TrackType type, int index);
public slots:
void SetTrackName(const QString& name);
signals:
/**
* @brief Signal emitted when a Block is added to this Track
@@ -143,6 +155,11 @@ signals:
*/
void TrackLengthChanged();
/**
* @brief Signal emitted when the height of the track has changed
*/
void TrackHeightChanged(int height);
protected:
private:
@@ -158,6 +175,10 @@ private:
rational track_length_;
int track_height_;
QString track_name_;
int block_invalidate_cache_stack_;
int index_;
+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_;