added auto-scroll to rich text effect
This commit is contained in:
@@ -2,6 +2,16 @@
|
||||
|
||||
#include <QTextDocument>
|
||||
|
||||
#include "timeline/clip.h"
|
||||
|
||||
enum AutoscrollDirection {
|
||||
SCROLL_OFF,
|
||||
SCROLL_UP,
|
||||
SCROLL_DOWN,
|
||||
SCROLL_LEFT,
|
||||
SCROLL_RIGHT,
|
||||
};
|
||||
|
||||
RichTextEffect::RichTextEffect(Clip *c, const EffectMeta *em) :
|
||||
Effect(c, em)
|
||||
{
|
||||
@@ -9,6 +19,7 @@ RichTextEffect::RichTextEffect(Clip *c, const EffectMeta *em) :
|
||||
|
||||
EffectRow* text_row = new EffectRow(this, tr("Text"));
|
||||
text_val = new StringField(text_row, "text");
|
||||
text_val->SetColumnSpan(2);
|
||||
|
||||
EffectRow* padding_row = new EffectRow(this, tr("Padding"));
|
||||
padding_field = new DoubleField(padding_row, "padding");
|
||||
@@ -24,6 +35,16 @@ RichTextEffect::RichTextEffect(Clip *c, const EffectMeta *em) :
|
||||
vertical_align->AddItem(tr("Center"), Qt::AlignCenter);
|
||||
vertical_align->AddItem(tr("Bottom"), Qt::AlignBottom);
|
||||
vertical_align->SetValueAt(0, Qt::AlignCenter);
|
||||
vertical_align->SetColumnSpan(2);
|
||||
|
||||
EffectRow* autoscroll_row = new EffectRow(this, tr("Auto-Scroll"));
|
||||
autoscroll = new ComboField(autoscroll_row, "autoscroll");
|
||||
autoscroll->AddItem(tr("Off"), SCROLL_OFF);
|
||||
autoscroll->AddItem(tr("Up"), SCROLL_UP);
|
||||
autoscroll->AddItem(tr("Down"), SCROLL_DOWN);
|
||||
autoscroll->AddItem(tr("Left"), SCROLL_LEFT);
|
||||
autoscroll->AddItem(tr("Right"), SCROLL_RIGHT);
|
||||
autoscroll->SetColumnSpan(2);
|
||||
|
||||
// Create default text
|
||||
text_val->SetValueAt(0, "<html>"
|
||||
@@ -54,10 +75,47 @@ void RichTextEffect::redraw(double timecode)
|
||||
int translate_x = qRound(position_x->GetDoubleAt(timecode) + padding);
|
||||
int translate_y = qRound(position_y->GetDoubleAt(timecode) + padding);
|
||||
|
||||
if (vertical_align->GetValueAt(timecode).toInt() == Qt::AlignCenter) {
|
||||
translate_y += height / 2 - td.size().height() / 2;
|
||||
} else if (vertical_align->GetValueAt(timecode).toInt() == Qt::AlignBottom) {
|
||||
translate_y += height - td.size().height();
|
||||
int doc_height = qRound(td.size().height());
|
||||
|
||||
AutoscrollDirection auto_scroll_dir = static_cast<AutoscrollDirection>(autoscroll->GetValueAt(timecode).toInt());
|
||||
|
||||
double scroll_progress;
|
||||
|
||||
if (auto_scroll_dir != SCROLL_OFF) {
|
||||
double clip_length_secs = double(parent_clip->length()) / parent_clip->media_frame_rate();
|
||||
scroll_progress = (timecode - double(parent_clip->clip_in()) / parent_clip->media_frame_rate()) / clip_length_secs;
|
||||
}
|
||||
|
||||
if (auto_scroll_dir == SCROLL_OFF || auto_scroll_dir == SCROLL_LEFT || auto_scroll_dir == SCROLL_RIGHT) {
|
||||
|
||||
// If we're not auto-scrolling the vertical direction, respect the vertical alignment
|
||||
if (vertical_align->GetValueAt(timecode).toInt() == Qt::AlignCenter) {
|
||||
translate_y += height / 2 - doc_height / 2;
|
||||
} else if (vertical_align->GetValueAt(timecode).toInt() == Qt::AlignBottom) {
|
||||
translate_y += height - doc_height;
|
||||
}
|
||||
|
||||
// Check if we are autoscrolling
|
||||
if (auto_scroll_dir != SCROLL_OFF) {
|
||||
|
||||
if (auto_scroll_dir == SCROLL_LEFT) {
|
||||
scroll_progress = 1.0 - scroll_progress;
|
||||
}
|
||||
|
||||
int doc_width = td.size().width();
|
||||
translate_x += qRound(-doc_width + (img.width() + doc_width) * scroll_progress);
|
||||
}
|
||||
|
||||
} else if (auto_scroll_dir == SCROLL_UP || auto_scroll_dir == SCROLL_DOWN) {
|
||||
|
||||
// Auto-scroll bottom to top or top to bottom
|
||||
|
||||
if (auto_scroll_dir == SCROLL_UP) {
|
||||
scroll_progress = 1.0 - scroll_progress;
|
||||
}
|
||||
|
||||
translate_y += qRound(-doc_height + (height + doc_height)*scroll_progress);
|
||||
|
||||
}
|
||||
|
||||
QRect clip_rect = img.rect();
|
||||
@@ -67,3 +125,8 @@ void RichTextEffect::redraw(double timecode)
|
||||
|
||||
td.drawContents(&p, clip_rect);
|
||||
}
|
||||
|
||||
bool RichTextEffect::AlwaysUpdate()
|
||||
{
|
||||
return autoscroll->GetValueAt(autoscroll->Now()).toInt() != SCROLL_OFF;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user