-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathtimelinelayerwidget.cpp
95 lines (79 loc) · 2.95 KB
/
timelinelayerwidget.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include "timelinelayerwidget.h"
#include "ui_timelinelayerwidget.h"
#include <QLabel>
#include <QComboBox>
#include <QDebug>
#include <QStringListModel>
#include <QFileInfo>
#include <QDesktopServices>
#include <QUrl>
#include "timeline.h"
#include "timelineeventswidget.h"
QStringListModel gScriptsModel(QStringList(""));
TimelineLayerWidget::TimelineLayerWidget(const std::shared_ptr<TimelineLayer>& layer, QWidget *parent) :
QWidget(parent),
ui(new Ui::TimelineLayerWidget),
mLayer(layer)
{
ui->setupUi(this);
mLblLayerName = findChild<QLabel*>("layer_name");
mEventsWidget = findChild<TimelineEventsWidget*>("events");
mScriptBox = findChild<QComboBox*>("postprocess_script");
mEditScriptButton = findChild<QPushButton*>("btn_edit_script");
mDeleteScriptButton = NULL;
mLblLayerName->setText(mLayer->name());
mEventsWidget->setEventSource(&mLayer->events());
mScriptBox->setModel(&gScriptsModel);
mScriptBox->setCurrentText(mLayer->script());
QObject::connect(mLayer.get(), &TimelineLayer::scriptChanged,
mScriptBox, &QComboBox::setCurrentText);
QObject::connect(mScriptBox, SIGNAL(currentIndexChanged(const QString&)),
mLayer.get(), SLOT(setScript(const QString&)));
QObject::connect(mEventsWidget, &TimelineEventsWidget::focusGained,
this, &TimelineLayerWidget::focusGained);
QObject::connect(mEventsWidget, &TimelineEventsWidget::focusLost,
this, &TimelineLayerWidget::focusLost);
QObject::connect(mEventsWidget, &TimelineEventsWidget::selectionChanged,
this, &TimelineLayerWidget::selectionChanged);
QObject::connect(mEventsWidget, &TimelineEventsWidget::singleClicked,
this, &TimelineLayerWidget::requestSetCursor);
}
TimelineLayerWidget::~TimelineLayerWidget()
{
delete ui;
}
void TimelineLayerWidget::setViewport(double startTime, double length)
{
mEventsWidget->setViewport(startTime, length);
}
void TimelineLayerWidget::setCursor(double time)
{
mEventsWidget->setCursor(time);
}
const Selection& TimelineLayerWidget::selection() const
{
return mEventsWidget->selection();
}
void TimelineLayerWidget::editScript()
{
if (mLayer->script().isEmpty())
return;
const QString path = mLayer->scriptPath();
if (!QFileInfo(path).exists()) {
QFile file(path);
file.open(QIODevice::WriteOnly);
QString text = QString("-- %1.lua\n\n"
"function process(events)\n"
"\tfor idx, event in pairs(events) do\n"
"\t\t\n"
"\tend\n"
"end\n").arg(mLayer->script());
file.write(text.toUtf8());
file.close();
}
QDesktopServices::openUrl(QUrl::fromLocalFile(path));
}
void TimelineLayerWidget::setSnapInterval(double interval)
{
mEventsWidget->setSnapInterval(interval);
}