added smooth keyframes
This commit is contained in:
@@ -1259,6 +1259,14 @@ QVariant EffectField::validate_keyframe_data(double timecode, bool async) {
|
||||
double progress;
|
||||
get_keyframe_data(timecode, before_keyframe, after_keyframe, progress);
|
||||
|
||||
int kf_type = (progress < 0.5) ? parent_row->keyframe_types.at(before_keyframe) : parent_row->keyframe_types.at(after_keyframe);
|
||||
if (kf_type == KEYFRAME_TYPE_SMOOTH) {
|
||||
double b = 4;
|
||||
double c = 1.313;
|
||||
double x = (b * progress) - (b*0.5);
|
||||
progress = (c*(qPow(M_E, x)/(qPow(M_E, x) + 1)))-((c-1)*0.5);
|
||||
}
|
||||
|
||||
const QVariant& before_data = keyframe_data.at(before_keyframe);
|
||||
switch (type) {
|
||||
case EFFECT_FIELD_DOUBLE:
|
||||
|
||||
@@ -73,6 +73,10 @@ extern QMutex effects_loaded;
|
||||
#define EFFECT_INTERNAL_LOGARITHMICFADE 11
|
||||
#define EFFECT_INTERNAL_COUNT 12
|
||||
|
||||
#define KEYFRAME_TYPE_LINEAR 0
|
||||
#define KEYFRAME_TYPE_SMOOTH 1
|
||||
#define KEYFRAME_TYPE_BEZIER 2
|
||||
|
||||
#define TRAN_TYPE_OPEN 1
|
||||
#define TRAN_TYPE_CLOSE 2
|
||||
#define TRAN_TYPE_OPENWLINK 3
|
||||
|
||||
+41
-4
@@ -16,6 +16,7 @@
|
||||
#include <QLabel>
|
||||
#include <QMouseEvent>
|
||||
#include <QtMath>
|
||||
#include <QMenu>
|
||||
|
||||
#define KEYFRAME_SIZE 6
|
||||
#define KEYFRAME_POINT_COUNT 4
|
||||
@@ -37,6 +38,32 @@ KeyframeView::KeyframeView(QWidget *parent) :
|
||||
{
|
||||
setFocusPolicy(Qt::ClickFocus);
|
||||
setMouseTracking(true);
|
||||
|
||||
setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
connect(this, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(show_context_menu(const QPoint&)));
|
||||
}
|
||||
|
||||
void KeyframeView::show_context_menu(const QPoint& pos) {
|
||||
if (selected_rows.size() > 0) {
|
||||
QMenu menu(this);
|
||||
QAction* linear = menu.addAction("Linear");
|
||||
linear->setData(KEYFRAME_TYPE_LINEAR);
|
||||
QAction* smooth = menu.addAction("Smooth");
|
||||
smooth->setData(KEYFRAME_TYPE_SMOOTH);
|
||||
/*QAction* bezier = menu.addAction("Bezier");
|
||||
bezier->setData(KEYFRAME_TYPE_BEZIER);*/
|
||||
connect(&menu, SIGNAL(triggered(QAction*)), this, SLOT(menu_set_key_type(QAction*)));
|
||||
menu.exec(mapToGlobal(pos));
|
||||
}
|
||||
}
|
||||
|
||||
void KeyframeView::menu_set_key_type(QAction* a) {
|
||||
ComboAction* ca = new ComboAction();
|
||||
for (int i=0;i<selected_rows.size();i++) {
|
||||
ca->append(new SetInt(&selected_rows.at(i)->keyframe_types[selected_keyframes.at(i)], a->data().toInt()));
|
||||
}
|
||||
undo_stack.push(ca);
|
||||
update();
|
||||
}
|
||||
|
||||
void KeyframeView::paintEvent(QPaintEvent*) {
|
||||
@@ -71,7 +98,7 @@ void KeyframeView::paintEvent(QPaintEvent*) {
|
||||
bool keyframe_selected = keyframeIsSelected(row, k);
|
||||
long keyframe_frame = adjust_row_keyframe(row, row->keyframe_times.at(k));
|
||||
if (dragging && keyframe_selected) keyframe_frame += frame_diff;
|
||||
draw_keyframe(p, getScreenPointFromFrame(panel_effect_controls->zoom, keyframe_frame) - x_scroll, keyframe_y, keyframe_selected);
|
||||
draw_keyframe(p, row->keyframe_types.at(k), getScreenPointFromFrame(panel_effect_controls->zoom, keyframe_frame) - x_scroll, keyframe_y, keyframe_selected);
|
||||
}
|
||||
|
||||
rows.append(row);
|
||||
@@ -144,12 +171,22 @@ void KeyframeView::set_y_scroll(int s) {
|
||||
update();
|
||||
}
|
||||
|
||||
void KeyframeView::draw_keyframe(QPainter &p, int x, int y, bool darker) {
|
||||
QPoint points[KEYFRAME_POINT_COUNT] = {QPoint(x-KEYFRAME_SIZE, y), QPoint(x, y-KEYFRAME_SIZE), QPoint(x+KEYFRAME_SIZE, y), QPoint(x, y+KEYFRAME_SIZE)};
|
||||
void KeyframeView::draw_keyframe(QPainter &p, int type, int x, int y, bool darker) {
|
||||
int color = (darker) ? 100 : 160;
|
||||
p.setPen(QColor(0, 0, 0));
|
||||
p.setBrush(QColor(color, color, color));
|
||||
p.drawPolygon(points, KEYFRAME_POINT_COUNT);
|
||||
|
||||
switch (type) {
|
||||
case KEYFRAME_TYPE_LINEAR:
|
||||
{
|
||||
QPoint points[KEYFRAME_POINT_COUNT] = {QPoint(x-KEYFRAME_SIZE, y), QPoint(x, y-KEYFRAME_SIZE), QPoint(x+KEYFRAME_SIZE, y), QPoint(x, y+KEYFRAME_SIZE)};
|
||||
p.drawPolygon(points, KEYFRAME_POINT_COUNT);
|
||||
}
|
||||
break;
|
||||
case KEYFRAME_TYPE_SMOOTH:
|
||||
p.drawEllipse(QPoint(x, y), KEYFRAME_SIZE, KEYFRAME_SIZE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void KeyframeView::mousePressEvent(QMouseEvent *event) {
|
||||
|
||||
+4
-1
@@ -34,7 +34,7 @@ private:
|
||||
void mouseMoveEvent(QMouseEvent* event);
|
||||
void mouseReleaseEvent(QMouseEvent *event);
|
||||
void paintEvent(QPaintEvent *event);
|
||||
void draw_keyframe(QPainter& p, int x, int y, bool darker);
|
||||
void draw_keyframe(QPainter& p, int type, int x, int y, bool darker);
|
||||
bool mousedown;
|
||||
bool dragging;
|
||||
bool keys_selected;
|
||||
@@ -51,6 +51,9 @@ private:
|
||||
|
||||
int x_scroll;
|
||||
int y_scroll;
|
||||
private slots:
|
||||
void show_context_menu(const QPoint& pos);
|
||||
void menu_set_key_type(QAction*);
|
||||
};
|
||||
|
||||
#endif // KEYFRAMEVIEW_H
|
||||
|
||||
Reference in New Issue
Block a user