wrote mechanisms that allow the tracks to be resized from the trackview
This commit is contained in:
@@ -52,7 +52,7 @@ TimelineWidget::TimelineWidget(QWidget *parent) :
|
||||
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));
|
||||
@@ -60,9 +60,9 @@ 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);
|
||||
|
||||
@@ -178,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;
|
||||
@@ -193,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();
|
||||
|
||||
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
|
||||
@@ -675,6 +685,24 @@ 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_);
|
||||
|
||||
@@ -379,6 +379,8 @@ private slots:
|
||||
|
||||
void UpdateTimecodeWidthFromSplitters(QSplitter *s);
|
||||
|
||||
void TrackHeightChanged(TrackType type, int index, int height);
|
||||
|
||||
};
|
||||
|
||||
#endif // TIMELINEWIDGET_H
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
TrackView::TrackView(Qt::Alignment vertical_alignment, QWidget *parent) :
|
||||
QScrollArea(parent),
|
||||
list_(nullptr),
|
||||
alignment_(vertical_alignment)
|
||||
{
|
||||
QWidget* central = new QWidget();
|
||||
@@ -30,13 +31,40 @@ TrackView::TrackView(Qt::Alignment vertical_alignment, QWidget *parent) :
|
||||
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::resizeEvent(QResizeEvent *event)
|
||||
void TrackView::ConnectTrackList(TrackList *list)
|
||||
{
|
||||
QScrollArea::resizeEvent(event);
|
||||
if (list_ != nullptr) {
|
||||
foreach (TrackViewItem* item, items_) {
|
||||
delete item;
|
||||
}
|
||||
items_.clear();
|
||||
|
||||
//splitter_->setFixedWidth(viewport()->width());
|
||||
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)
|
||||
@@ -50,3 +78,18 @@ void TrackView::ScrollbarRangeChanged(int, int max)
|
||||
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());
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
#include <QScrollArea>
|
||||
#include <QSplitter>
|
||||
|
||||
#include "node/output/timeline/tracklist.h"
|
||||
#include "trackviewitem.h"
|
||||
#include "trackviewsplitter.h"
|
||||
|
||||
class TrackView : public QScrollArea
|
||||
@@ -13,10 +15,14 @@ public:
|
||||
TrackView(Qt::Alignment vertical_alignment = Qt::AlignTop,
|
||||
QWidget* parent = nullptr);
|
||||
|
||||
protected:
|
||||
virtual void resizeEvent(QResizeEvent* event) override;
|
||||
void ConnectTrackList(TrackList* list);
|
||||
void DisconnectTrackList();
|
||||
|
||||
private:
|
||||
QList<TrackViewItem*> items_;
|
||||
|
||||
TrackList* list_;
|
||||
|
||||
TrackViewSplitter* splitter_;
|
||||
|
||||
Qt::Alignment alignment_;
|
||||
@@ -28,6 +34,12 @@ private:
|
||||
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
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include <QPainter>
|
||||
#include <QtMath>
|
||||
|
||||
TrackViewItem::TrackViewItem(Qt::Alignment alignment, QWidget *parent) :
|
||||
TrackViewItem::TrackViewItem(const QString& name, Qt::Alignment alignment, QWidget *parent) :
|
||||
QWidget(parent),
|
||||
alignment_(alignment)
|
||||
{
|
||||
@@ -14,8 +14,17 @@ TrackViewItem::TrackViewItem(Qt::Alignment alignment, QWidget *parent) :
|
||||
layout->setSpacing(0);
|
||||
layout->setMargin(0);
|
||||
|
||||
label_ = new QLabel(tr("Track"));
|
||||
layout->addWidget(label_);
|
||||
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_);
|
||||
@@ -42,3 +51,34 @@ QPushButton *TrackViewItem::CreateMSLButton(const QString& text, const QColor& c
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -1,28 +1,45 @@
|
||||
#ifndef TRACKVIEWITEM_H
|
||||
#define TRACKVIEWITEM_H
|
||||
|
||||
#include <QLabel>
|
||||
#include <QPushButton>
|
||||
#include <QStackedWidget>
|
||||
#include <QWidget>
|
||||
|
||||
#include "widget/clickablelabel/clickablelabel.h"
|
||||
#include "widget/focusablelineedit/focusablelineedit.h"
|
||||
|
||||
class TrackViewItem : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
TrackViewItem(Qt::Alignment alignment = Qt::AlignTop,
|
||||
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_;
|
||||
|
||||
QLabel* label_;
|
||||
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
|
||||
|
||||
@@ -3,8 +3,6 @@
|
||||
#include <QDebug>
|
||||
#include <QPainter>
|
||||
|
||||
#include "trackviewitem.h"
|
||||
|
||||
TrackViewSplitter::TrackViewSplitter(Qt::Alignment vertical_alignment, QWidget* parent) :
|
||||
QSplitter(Qt::Vertical, parent),
|
||||
alignment_(vertical_alignment)
|
||||
@@ -13,22 +11,8 @@ TrackViewSplitter::TrackViewSplitter(Qt::Alignment vertical_alignment, QWidget*
|
||||
|
||||
int initial_height = 0;
|
||||
|
||||
if (alignment_ == Qt::AlignBottom) {
|
||||
// Add empty spacer so we get a splitter handle after the last element
|
||||
addWidget(new QWidget());
|
||||
}
|
||||
|
||||
for (int i=0;i<3;i++) {
|
||||
TrackViewItem* w = new TrackViewItem();
|
||||
addWidget(w);
|
||||
|
||||
initial_height += w->sizeHint().height() + handleWidth();
|
||||
}
|
||||
|
||||
if (alignment_ == Qt::AlignTop) {
|
||||
// Add empty spacer so we get a splitter handle after the last element
|
||||
addWidget(new QWidget());
|
||||
}
|
||||
// Add empty spacer so we get a splitter handle after the last element
|
||||
addWidget(new QWidget());
|
||||
|
||||
setFixedHeight(initial_height);
|
||||
}
|
||||
@@ -64,14 +48,71 @@ void TrackViewSplitter::HandleReceiver(TrackViewSplitterHandle *h, int diff)
|
||||
// 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(ele_id, new_ele_sz);
|
||||
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);
|
||||
|
||||
@@ -24,11 +24,23 @@ private:
|
||||
|
||||
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;
|
||||
|
||||
|
||||
@@ -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_;
|
||||
|
||||
Reference in New Issue
Block a user