better attachment between labels and tracks

This commit is contained in:
itsmattkc
2019-04-04 19:35:52 +11:00
parent e708791e90
commit d7091c2b10
9 changed files with 53 additions and 27 deletions
+1
View File
@@ -71,6 +71,7 @@ int Track::height()
void Track::set_height(int h) void Track::set_height(int h)
{ {
height_ = qMax(h, olive::timeline::kTrackMinHeight); height_ = qMax(h, olive::timeline::kTrackMinHeight);
emit HeightChanged(h);
} }
QString Track::name() QString Track::name()
+3
View File
@@ -98,6 +98,9 @@ public slots:
void SetSoloed(bool soloed); void SetSoloed(bool soloed);
void SetLocked(bool locked); void SetLocked(bool locked);
signals:
void HeightChanged(int height);
private: private:
void ResizeClipArray(int new_size); void ResizeClipArray(int new_size);
+9
View File
@@ -37,6 +37,8 @@ void TrackList::AddTrack()
{ {
Track* track = new Track(this, type_); Track* track = new Track(this, type_);
tracks_.append(track); tracks_.append(track);
emit TrackCountChanged();
} }
void TrackList::RemoveTrack(int i) void TrackList::RemoveTrack(int i)
@@ -45,6 +47,8 @@ void TrackList::RemoveTrack(int i)
return; return;
} }
tracks_.removeAt(i); tracks_.removeAt(i);
emit TrackCountChanged();
} }
Track *TrackList::First() Track *TrackList::First()
@@ -52,6 +56,11 @@ Track *TrackList::First()
return tracks_.first(); return tracks_.first();
} }
Track *TrackList::Last()
{
return tracks_.last();
}
int TrackList::TrackCount() int TrackList::TrackCount()
{ {
return tracks_.size(); return tracks_.size();
+4
View File
@@ -15,6 +15,7 @@ public:
void AddTrack(); void AddTrack();
void RemoveTrack(int i); void RemoveTrack(int i);
Track* First(); Track* First();
Track* Last();
int TrackCount(); int TrackCount();
int IndexOfTrack(Track* track); int IndexOfTrack(Track* track);
Track* TrackAt(int i); Track* TrackAt(int i);
@@ -24,6 +25,9 @@ public:
Sequence* GetParent(); Sequence* GetParent();
signals:
void TrackCountChanged();
private: private:
void ResizeTrackArray(int i); void ResizeTrackArray(int i);
+16 -17
View File
@@ -2,10 +2,10 @@
int olive::timeline::kTimelineLabelFixedWidth = 200; int olive::timeline::kTimelineLabelFixedWidth = 200;
TimelineArea::TimelineArea(Timeline* timeline) : TimelineArea::TimelineArea(Timeline* timeline, olive::timeline::Alignment alignment) :
timeline_(timeline), timeline_(timeline),
track_list_(nullptr), track_list_(nullptr),
alignment_(olive::timeline::kAlignmentTop) alignment_(alignment)
{ {
QHBoxLayout* layout = new QHBoxLayout(this); QHBoxLayout* layout = new QHBoxLayout(this);
layout->setMargin(0); layout->setMargin(0);
@@ -17,10 +17,12 @@ TimelineArea::TimelineArea(Timeline* timeline) :
label_container_layout_ = new QVBoxLayout(label_container); label_container_layout_ = new QVBoxLayout(label_container);
label_container_layout_->setMargin(0); label_container_layout_->setMargin(0);
label_container_layout_->setSpacing(0); label_container_layout_->setSpacing(0);
label_container_layout_->addStretch();
layout->addWidget(label_container); layout->addWidget(label_container);
// VIEW // VIEW
view_ = new TimelineView(timeline_); view_ = new TimelineView(timeline_);
view_->SetAlignment(alignment_);
layout->addWidget(view_); layout->addWidget(view_);
// SCROLLBAR // SCROLLBAR
@@ -30,33 +32,25 @@ TimelineArea::TimelineArea(Timeline* timeline) :
view_->scrollBar = scrollbar; view_->scrollBar = scrollbar;
} }
void TimelineArea::SetAlignment(olive::timeline::Alignment alignment)
{
alignment_ = alignment;
view_->SetAlignment(alignment);
}
void TimelineArea::SetTrackList(Sequence *sequence, Track::Type track_list) void TimelineArea::SetTrackList(Sequence *sequence, Track::Type track_list)
{ {
if (track_list_ != nullptr) {
disconnect(track_list_, SIGNAL(TrackCountChanged()), this, SLOT(RefreshLabels()));
}
if (sequence == nullptr) { if (sequence == nullptr) {
track_list_ = nullptr; track_list_ = nullptr;
labels_.clear();
} else { } else {
track_list_ = sequence->GetTrackList(track_list); track_list_ = sequence->GetTrackList(track_list);
connect(track_list_, SIGNAL(TrackCountChanged()), this, SLOT(RefreshLabels()));
labels_.resize(track_list_->TrackCount());
for (int i=0;i<labels_.size();i++) {
labels_[i] = std::make_shared<TimelineLabel>();
labels_[i]->SetTrack(track_list_->TrackAt(i));
label_container_layout_->addWidget(labels_[i].get());
}
} }
RefreshLabels();
view_->SetTrackList(track_list_); view_->SetTrackList(track_list_);
} }
@@ -64,12 +58,17 @@ void TimelineArea::SetTrackList(Sequence *sequence, Track::Type track_list)
void TimelineArea::RefreshLabels() void TimelineArea::RefreshLabels()
{ {
if (track_list_ == nullptr) { if (track_list_ == nullptr) {
labels_.clear(); labels_.clear();
} else { } else {
labels_.resize(track_list_->TrackCount()); labels_.resize(track_list_->TrackCount());
for (int i=0;i<labels_.size();i++) { for (int i=0;i<labels_.size();i++) {
labels_[i] = std::make_shared<TimelineLabel>();
labels_[i]->SetTrack(track_list_->TrackAt(i)); labels_[i]->SetTrack(track_list_->TrackAt(i));
label_container_layout_->insertWidget(label_container_layout_->count()-1, labels_[i].get());
} }
} }
+1 -2
View File
@@ -12,9 +12,8 @@ class TimelineArea : public QWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
TimelineArea(Timeline *timeline); TimelineArea(Timeline *timeline, olive::timeline::Alignment alignment = olive::timeline::kAlignmentTop);
void SetAlignment(olive::timeline::Alignment alignment);
void SetTrackList(Sequence* sequence, Track::Type track_list); void SetTrackList(Sequence* sequence, Track::Type track_list);
public slots: public slots:
void RefreshLabels(); void RefreshLabels();
+9
View File
@@ -52,6 +52,8 @@ void TimelineLabel::SetTrack(Track *track)
connect(mute_button_, SIGNAL(toggled(bool)), track_, SLOT(SetMuted(bool))); connect(mute_button_, SIGNAL(toggled(bool)), track_, SLOT(SetMuted(bool)));
connect(solo_button_, SIGNAL(toggled(bool)), track_, SLOT(SetSoloed(bool))); connect(solo_button_, SIGNAL(toggled(bool)), track_, SLOT(SetSoloed(bool)));
connect(lock_button_, SIGNAL(toggled(bool)), track_, SLOT(SetLocked(bool))); connect(lock_button_, SIGNAL(toggled(bool)), track_, SLOT(SetLocked(bool)));
connect(track_, SIGNAL(HeightChanged(int)), this, SLOT(UpdateHeight(int)));
} }
} }
@@ -59,6 +61,8 @@ void TimelineLabel::UpdateState()
{ {
label_->setText(track_->name()); label_->setText(track_->name());
UpdateHeight(track_->height());
mute_button_->setChecked(track_->IsMuted()); mute_button_->setChecked(track_->IsMuted());
solo_button_->setChecked(track_->IsSoloed()); solo_button_->setChecked(track_->IsSoloed());
lock_button_->setChecked(track_->IsLocked()); lock_button_->setChecked(track_->IsLocked());
@@ -79,3 +83,8 @@ void TimelineLabel::RenameTrack()
UpdateState(); UpdateState();
} }
} }
void TimelineLabel::UpdateHeight(int h)
{
setFixedHeight(h);
}
+1
View File
@@ -25,6 +25,7 @@ private:
Track* track_; Track* track_;
private slots: private slots:
void RenameTrack(); void RenameTrack();
void UpdateHeight(int h);
}; };
using TimelineLabelPtr = std::shared_ptr<TimelineLabel>; using TimelineLabelPtr = std::shared_ptr<TimelineLabel>;
+9 -8
View File
@@ -1614,7 +1614,6 @@ void TimelineView::update_ghosts(const QPoint& mouse_pos, bool lock_frame) {
Track* mouse_track = getTrackFromScreenPoint(mouse_pos.y()); Track* mouse_track = getTrackFromScreenPoint(mouse_pos.y());
long frame_diff = (lock_frame) ? 0 : ParentTimeline()->getTimelineFrameFromScreenPoint(mouse_pos.x()) - ParentTimeline()->drag_frame_start; long frame_diff = (lock_frame) ? 0 : ParentTimeline()->getTimelineFrameFromScreenPoint(mouse_pos.x()) - ParentTimeline()->drag_frame_start;
int track_diff = ((effective_tool == olive::timeline::TIMELINE_TOOL_SLIDE || ParentTimeline()->transition_select != kTransitionNone) && !ParentTimeline()->importing) ? 0 : mouse_track - ParentTimeline()->drag_track_start;
long validator; long validator;
long earliest_in_point = LONG_MAX; long earliest_in_point = LONG_MAX;
@@ -3321,17 +3320,19 @@ void TimelineView::resizeEvent(QResizeEvent *) {
// ************************************** // **************************************
Track *TimelineView::getTrackFromScreenPoint(int y) { Track *TimelineView::getTrackFromScreenPoint(int y) {
if (y < 0 || y > height()) { if (y < 0) {
return nullptr; return track_list_->First();
} else if (y > height()) {
return track_list_->Last();
} }
y += scroll; y += scroll;
int heights = 0; int heights = 0;
for (int i=0;i<track_list_->TrackCount();i++) { // for (int i=0;i<track_list_->TrackCount();i++) {
// int i = 0; int i = 0;
// while (true) { while (true) {
int new_heights = heights + 1; int new_heights = heights + 1;
@@ -3343,10 +3344,10 @@ Track *TimelineView::getTrackFromScreenPoint(int y) {
heights = new_heights; heights = new_heights;
// i++; i++;
} }
return nullptr; // return nullptr;
} }
int TimelineView::getScreenPointFromTrack(Track *track) { int TimelineView::getScreenPointFromTrack(Track *track) {