separated effect from UI

This commit is contained in:
itsmattkc
2019-03-12 22:49:01 +11:00
parent 0b090ddc21
commit 5b03af5e5a
58 changed files with 1166 additions and 1071 deletions
+10 -5
View File
@@ -53,7 +53,7 @@ CollapsibleWidget::CollapsibleWidget(QWidget* parent) : QWidget(parent) {
collapse_button = new QPushButton(title_bar);
collapse_button->setIconSize(collapse_button->iconSize()*0.5);
collapse_button->setStyleSheet("QPushButton { border: none; }");
setText(tr("<untitled>"));
SetText(tr("<untitled>"));
title_bar_layout->addWidget(collapse_button);
title_bar_layout->addWidget(enabled_check);
title_bar_layout->addWidget(header);
@@ -80,20 +80,25 @@ void CollapsibleWidget::header_click(bool s, bool deselect) {
if (deselect) emit deselect_others(this);
}
bool CollapsibleWidget::is_focused() {
bool CollapsibleWidget::IsFocused() {
if (hasFocus()) return true;
return title_bar->hasFocus();
}
bool CollapsibleWidget::is_expanded() {
bool CollapsibleWidget::IsExpanded() {
return contents->isVisible();
}
bool CollapsibleWidget::IsSelected()
{
return selected;
}
void CollapsibleWidget::set_button_icon(bool open) {
collapse_button->setIcon(open ? olive::icon::DownArrow : olive::icon::RightArrow);
}
void CollapsibleWidget::setContents(QWidget* c) {
void CollapsibleWidget::SetContents(QWidget* c) {
bool existing = (contents != nullptr);
contents = c;
if (!existing) {
@@ -103,7 +108,7 @@ void CollapsibleWidget::setContents(QWidget* c) {
}
}
void CollapsibleWidget::setText(const QString &s) {
void CollapsibleWidget::SetText(const QString &s) {
header->setText(s);
}
+10 -9
View File
@@ -35,7 +35,7 @@
class CollapsibleWidgetHeader : public QWidget {
Q_OBJECT
public:
CollapsibleWidgetHeader(QWidget* parent = 0);
CollapsibleWidgetHeader(QWidget* parent = nullptr);
bool selected;
protected:
void mousePressEvent(QMouseEvent* event);
@@ -48,17 +48,18 @@ class CollapsibleWidget : public QWidget
{
Q_OBJECT
public:
CollapsibleWidget(QWidget* parent = 0);
void setContents(QWidget* c);
void setText(const QString &);
bool is_focused();
bool is_expanded();
CollapsibleWidget(QWidget* parent = nullptr);
void SetContents(QWidget* c);
void SetText(const QString &);
bool IsFocused();
bool IsExpanded();
bool IsSelected();
protected:
CheckboxEx* enabled_check;
bool selected;
QWidget* contents;
CollapsibleWidgetHeader* title_bar;
private:
bool selected;
QWidget* contents;
QLabel* header;
QVBoxLayout* layout;
QPushButton* collapse_button;
+94
View File
@@ -0,0 +1,94 @@
#include "effectui.h"
#include <QPoint>
#include <QMenu>
#include "project/clip.h"
#include "ui/menuhelper.h"
EffectUI::EffectUI(Effect* e) :
effect_(e)
{
Q_ASSERT(e != nullptr);
SetText(e->name);
QWidget* ui = new QWidget(this);
SetContents(ui);
layout_ = new QGridLayout(ui);
layout_->setSpacing(4);
connect(title_bar,
SIGNAL(customContextMenuRequested(const QPoint&)),
this,
SIGNAL(TitleBarContextMenuRequested(const QPoint&)));
for (int i=0;i<e->row_count();i++) {
EffectRow* row = e->row(i);
QLabel* row_label = new QLabel(row->name());
labels_.append(row_label);
layout_->addWidget(row_label, i, 0);
for (int j=0;j<row->FieldCount();j++) {
EffectField* field = row->Field(j);
QWidget* widget = field->CreateWidget();
layout_->addWidget(widget, i, j + 1);
}
}
connect(enabled_check, SIGNAL(clicked(bool)), this, SLOT(field_changed()));
}
Effect *EffectUI::GetEffect()
{
return effect_;
}
int EffectUI::GetRowPos(int row)
{
QLabel* row_label = labels_.at(row);
return mapToGlobal(row_label->rect().center()).y();
}
void EffectUI::show_context_menu(const QPoint& pos) {
if (effect_->meta->type == EFFECT_TYPE_EFFECT) {
QMenu menu;
Clip* c = effect_->parent_clip;
int index = c->IndexOfEffect(effect_);
menu.addAction(tr("Cu&t"), this, SIGNAL(CutRequested()));
menu.addAction(tr("&Copy"), this, SIGNAL(CopyRequested()));
olive::MenuHelper.create_effect_paste_action(&menu);
menu.addSeparator();
if (index > 0) {
menu.addAction(tr("Move &Up"), this, SLOT(move_up()));
}
if (index < c->effects.size() - 1) {
menu.addAction(tr("Move &Down"), this, SLOT(move_down()));
}
menu.addSeparator();
menu.addAction(tr("D&elete"), this, SLOT(delete_self()));
menu.addSeparator();
menu.addAction(tr("Load Settings From File"), this, SLOT(load_from_file()));
menu.addAction(tr("Save Settings to File"), this, SLOT(save_to_file()));
menu.exec(title_bar->mapToGlobal(pos));
}
}
+27
View File
@@ -0,0 +1,27 @@
#ifndef EFFECTUI_H
#define EFFECTUI_H
#include "collapsiblewidget.h"
#include "project/effect.h"
class EffectUI : public CollapsibleWidget {
Q_OBJECT
public:
EffectUI(Effect* e);
Effect* GetEffect();
int GetRowPos(int row);
signals:
void CutRequested();
void CopyRequested();
void TitleBarContextMenuRequested(const QPoint&);
private:
Effect* effect_;
QGridLayout* layout_;
QVector<QLabel*> labels_;
private slots:
void show_context_menu(const QPoint&);
};
#endif // EFFECTUI_H
+41 -49
View File
@@ -23,7 +23,6 @@
#include "project/effect.h"
#include "ui/collapsiblewidget.h"
#include "panels/panels.h"
#include "panels/effectcontrols.h"
#include "project/clip.h"
#include "panels/timeline.h"
#include "ui/timelineheader.h"
@@ -62,6 +61,11 @@ KeyframeView::KeyframeView(QWidget *parent) :
connect(this, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(show_context_menu(const QPoint&)));
}
void KeyframeView::SetEffects(const QVector<EffectUI *> &open_effects)
{
open_effects_ = open_effects;
}
void KeyframeView::show_context_menu(const QPoint& pos) {
if (selected_fields.size() > 0) {
QMenu menu(this);
@@ -101,73 +105,61 @@ void KeyframeView::paintEvent(QPaintEvent*) {
rowY.clear();
rows.clear();
if (panel_effect_controls->selected_clips.size() > 0) {
if (!open_effects_.isEmpty()) {
visible_in = LONG_MAX;
visible_out = 0;
for (int j=0;j<panel_effect_controls->selected_clips.size();j++) {
ClipPtr c = olive::ActiveSequence->clips.at(panel_effect_controls->selected_clips.at(j));
for (int i=0;i<open_effects_.size();i++) {
Clip* c = open_effects_.at(i)->GetEffect()->parent_clip;
visible_in = qMin(visible_in, c->timeline_in());
visible_out = qMax(visible_out, c->timeline_out());
}
for (int j=0;j<panel_effect_controls->selected_clips.size();j++) {
ClipPtr c = olive::ActiveSequence->clips.at(panel_effect_controls->selected_clips.at(j));
for (int i=0;i<c->effects.size();i++) {
EffectPtr e = c->effects.at(i);
if (e->container->is_expanded()) {
for (int j=0;j<e->row_count();j++) {
EffectRow* row = e->row(j);
for (int j=0;j<open_effects_.size();j++) {
// TODO address this
EffectUI* container = open_effects_.at(j);
Effect* e = container->GetEffect();
/*
if (container->IsExpanded()) {
for (int j=0;j<e->row_count();j++) {
EffectRow* row = e->row(j);
ClickableLabel* label = row->label;
QWidget* contents = e->container->contents;
int keyframe_y = container->GetRowPos(j);
QVector<long> key_times;
QVector<long> key_times;
int keyframe_y = label->y()
+ (label->height()>>1)
+ mapFrom(panel_effect_controls, contents->mapTo(panel_effect_controls, contents->pos())).y()
- e->container->title_bar->height();
for (int l=0;l<row->FieldCount();l++) {
EffectField* f = row->Field(l);
for (int k=0;k<f->keyframes.size();k++) {
if (!key_times.contains(f->keyframes.at(k).time)) {
bool keyframe_selected = keyframeIsSelected(f, k);
long keyframe_frame = adjust_row_keyframe(row, f->keyframes.at(k).time, visible_in);
for (int l=0;l<row->FieldCount();l++) {
EffectField* f = row->Field(l);
for (int k=0;k<f->keyframes.size();k++) {
if (!key_times.contains(f->keyframes.at(k).time)) {
bool keyframe_selected = keyframeIsSelected(f, k);
long keyframe_frame = adjust_row_keyframe(row, f->keyframes.at(k).time, visible_in);
// see if any other keyframes have this time
int appearances = 0;
for (int m=0;m<row->FieldCount();m++) {
EffectField* compf = row->Field(m);
for (int n=0;n<compf->keyframes.size();n++) {
if (f->keyframes.at(k).time == compf->keyframes.at(n).time) {
appearances++;
}
// see if any other keyframes have this time
int appearances = 0;
for (int m=0;m<row->FieldCount();m++) {
EffectField* compf = row->Field(m);
for (int n=0;n<compf->keyframes.size();n++) {
if (f->keyframes.at(k).time == compf->keyframes.at(n).time) {
appearances++;
}
}
if (appearances != row->FieldCount()) {
QColor cc = get_curve_color(l, row->FieldCount());
draw_keyframe(p, f->keyframes.at(k).type, getScreenPointFromFrame(panel_effect_controls->zoom, keyframe_frame) - x_scroll, keyframe_y, keyframe_selected, cc.red(), cc.green(), cc.blue());
} else {
draw_keyframe(p, f->keyframes.at(k).type, getScreenPointFromFrame(panel_effect_controls->zoom, keyframe_frame) - x_scroll, keyframe_y, keyframe_selected);
}
key_times.append(f->keyframes.at(k).time);
}
if (appearances != row->FieldCount()) {
QColor cc = get_curve_color(l, row->FieldCount());
draw_keyframe(p, f->keyframes.at(k).type, getScreenPointFromFrame(panel_effect_controls->zoom, keyframe_frame) - x_scroll, keyframe_y, keyframe_selected, cc.red(), cc.green(), cc.blue());
} else {
draw_keyframe(p, f->keyframes.at(k).type, getScreenPointFromFrame(panel_effect_controls->zoom, keyframe_frame) - x_scroll, keyframe_y, keyframe_selected);
}
key_times.append(f->keyframes.at(k).time);
}
}
rows.append(row);
rowY.append(keyframe_y);
*/
}
rows.append(row);
rowY.append(keyframe_y);
}
}
}
+44 -38
View File
@@ -24,6 +24,8 @@
#include <QWidget>
#include <QPainter>
#include "ui/effectui.h"
class Clip;
class Effect;
class EffectRow;
@@ -31,56 +33,60 @@ class EffectField;
class TimelineHeader;
class KeyframeView : public QWidget {
Q_OBJECT
Q_OBJECT
public:
KeyframeView(QWidget* parent = 0);
KeyframeView(QWidget* parent = nullptr);
void delete_selected_keyframes();
void SetEffects(const QVector<EffectUI*>& open_effects);
TimelineHeader* header;
void delete_selected_keyframes();
long visible_in;
long visible_out;
TimelineHeader* header;
long visible_in;
long visible_out;
signals:
void wheel_event_signal(QWheelEvent*);
void wheel_event_signal(QWheelEvent*);
public slots:
void set_x_scroll(int);
void set_y_scroll(int);
void resize_move(double d);
void set_x_scroll(int);
void set_y_scroll(int);
void resize_move(double d);
private:
QVector<EffectField*> selected_fields;
QVector<int> selected_keyframes;
QVector<int> rowY;
QVector<EffectRow*> rows;
QVector<long> old_key_vals;
void mousePressEvent(QMouseEvent* event);
void mouseMoveEvent(QMouseEvent* event);
void mouseReleaseEvent(QMouseEvent *event);
void paintEvent(QPaintEvent *event);
void wheelEvent(QWheelEvent* e);
bool mousedown;
bool dragging;
bool keys_selected;
bool select_rect;
bool scroll_drag;
QVector<EffectUI*> open_effects_;
bool keyframeIsSelected(EffectField *field, int keyframe);
QVector<EffectField*> selected_fields;
QVector<int> selected_keyframes;
QVector<int> rowY;
QVector<EffectRow*> rows;
QVector<long> old_key_vals;
void mousePressEvent(QMouseEvent* event);
void mouseMoveEvent(QMouseEvent* event);
void mouseReleaseEvent(QMouseEvent *event);
void paintEvent(QPaintEvent *event);
void wheelEvent(QWheelEvent* e);
bool mousedown;
bool dragging;
bool keys_selected;
bool select_rect;
bool scroll_drag;
long drag_frame_start;
long last_frame_diff;
int rect_select_x;
int rect_select_y;
int rect_select_w;
int rect_select_h;
int rect_select_offset;
bool keyframeIsSelected(EffectField *field, int keyframe);
int x_scroll;
int y_scroll;
long drag_frame_start;
long last_frame_diff;
int rect_select_x;
int rect_select_y;
int rect_select_w;
int rect_select_h;
int rect_select_offset;
void update_keys();
int x_scroll;
int y_scroll;
void update_keys();
private slots:
void show_context_menu(const QPoint& pos);
void menu_set_key_type(QAction*);
void show_context_menu(const QPoint& pos);
void menu_set_key_type(QAction*);
};
#endif // KEYFRAMEVIEW_H
+13 -10
View File
@@ -20,21 +20,18 @@
#include "menuhelper.h"
#include "oliveglobal.h"
#include "ui/focusfilter.h"
#include "io/config.h"
#include "panels/panels.h"
#include "mainwindow.h"
#include <QMessageBox>
#include <QInputDialog>
#include <QPushButton>
#include <QStyleFactory>
#include "io/config.h"
#include "io/clipboard.h"
#include "mainwindow.h"
#include "oliveglobal.h"
#include "panels/panels.h"
#include "ui/focusfilter.h"
MenuHelper olive::MenuHelper;
void MenuHelper::InitializeSharedMenus()
@@ -262,6 +259,12 @@ void MenuHelper::open_recent_from_menu() {
olive::Global.get()->open_recent(index);
}
void MenuHelper::create_effect_paste_action(QMenu *menu)
{
QAction* paste_action = menu->addAction(tr("&Paste"), panel_timeline, SLOT(paste(bool)));
paste_action->setEnabled(clipboard.size() > 0 && clipboard_type == CLIPBOARD_TYPE_EFFECT);
}
QMenu* MenuHelper::create_submenu(QMenuBar* parent,
const QObject *receiver,
const char *member) {
+9
View File
@@ -186,6 +186,15 @@ public slots:
*/
void open_recent_from_menu();
/**
* @brief Create a "Paste" action on the specified menu that's enabled only if the clipboard contains effects
*
* @param menu
*
* Menu to add action to
*/
void create_effect_paste_action(QMenu *menu);
private:
QAction* new_project_;
QAction* new_sequence_;
+3 -3
View File
@@ -115,7 +115,7 @@ void TimelineHeader::set_in_point(long new_in) {
new_out = viewer->seq->getEndFrame();
}
olive::UndoStack.push(new SetTimelineInOutCommand(viewer->seq, true, new_in, new_out));
olive::UndoStack.push(new SetTimelineInOutCommand(viewer->seq.get(), true, new_in, new_out));
update_parents();
}
@@ -127,7 +127,7 @@ void TimelineHeader::set_out_point(long new_out) {
new_in = 0;
}
olive::UndoStack.push(new SetTimelineInOutCommand(viewer->seq, true, new_in, new_out));
olive::UndoStack.push(new SetTimelineInOutCommand(viewer->seq.get(), true, new_in, new_out));
update_parents();
}
@@ -280,7 +280,7 @@ void TimelineHeader::mouseReleaseEvent(QMouseEvent*) {
if (viewer->seq != nullptr) {
dragging = false;
if (resizing_workarea) {
olive::UndoStack.push(new SetTimelineInOutCommand(viewer->seq, true, temp_workarea_in, temp_workarea_out));
olive::UndoStack.push(new SetTimelineInOutCommand(viewer->seq.get(), true, temp_workarea_in, temp_workarea_out));
} else if (dragging_markers && selected_markers.size() > 0) {
bool moved = false;
ComboAction* ca = new ComboAction();
+7 -7
View File
@@ -259,7 +259,7 @@ void TimelineWidget::dragEnterEvent(QDragEnterEvent *event) {
}
if (event->source() == panel_footage_viewer->viewer_widget) {
SequencePtr proposed_seq = panel_footage_viewer->seq;
Sequence* proposed_seq = panel_footage_viewer->seq.get();
if (proposed_seq != olive::ActiveSequence) { // don't allow nesting the same sequence
media_list.append(panel_footage_viewer->media);
import_init = true;
@@ -280,7 +280,7 @@ void TimelineWidget::dragEnterEvent(QDragEnterEvent *event) {
for (int i=0;i<panel_project->last_imported_media.size();i++) {
// waits for media to have a duration
// TODO would be much nicer if this was multithreaded
FootagePtr f = panel_project->last_imported_media.at(i)->to_footage();
Footage* f = panel_project->last_imported_media.at(i)->to_footage();
f->ready_lock.lock();
f->ready_lock.unlock();
@@ -302,14 +302,14 @@ void TimelineWidget::dragEnterEvent(QDragEnterEvent *event) {
event->acceptProposedAction();
long entry_point;
SequencePtr seq = olive::ActiveSequence;
Sequence* seq = olive::ActiveSequence;
if (seq == nullptr) {
// if no sequence, we're going to create a new one using the clips as a reference
entry_point = 0;
self_created_sequence = create_sequence_from_media(media_list);
seq = self_created_sequence;
seq = self_created_sequence.get();
} else {
entry_point = panel_timeline->getTimelineFrameFromScreenPoint(event->pos().x());
panel_timeline->drag_frame_start = entry_point + getFrameFromScreenPoint(panel_timeline->zoom, 50);
@@ -515,11 +515,11 @@ void TimelineWidget::dropEvent(QDropEvent* event) {
ComboAction* ca = new ComboAction();
SequencePtr s = olive::ActiveSequence;
Sequence* s = olive::ActiveSequence;
// if we're dropping into nothing, create a new sequences based on the clip being dragged
if (s == nullptr) {
s = self_created_sequence;
s = self_created_sequence.get();
panel_project->create_sequence_internal(ca, self_created_sequence, true, nullptr);
self_created_sequence = nullptr;
} else if (event->keyboardModifiers() & Qt::ControlModifier) {
@@ -2953,7 +2953,7 @@ void TimelineWidget::paintEvent(QPaintEvent*) {
if (clip->media() != nullptr && clip->media()->get_type() == MEDIA_TYPE_FOOTAGE) {
bool draw_checkerboard = false;
QRect checkerboard_rect(clip_rect);
FootagePtr m = clip->media()->to_footage();
Footage* m = clip->media()->to_footage();
FootageStream* ms = clip->media_stream();
if (ms == nullptr) {
draw_checkerboard = true;
+6 -6
View File
@@ -91,7 +91,7 @@ ViewerWidget::~ViewerWidget() {
}
void ViewerWidget::delete_function() {
close_active_clips(viewer->seq);
close_active_clips(viewer->seq.get());
}
void ViewerWidget::set_waveform_scroll(int s) {
@@ -168,7 +168,7 @@ void ViewerWidget::save_frame() {
fn += selected_ext;
}
renderer->start_render(context(), viewer->seq, fn);
renderer->start_render(context(), viewer->seq.get(), fn);
}
}
@@ -228,11 +228,11 @@ void ViewerWidget::frame_update() {
update();
} else {
doneCurrent();
renderer->start_render(context(), viewer->seq);
renderer->start_render(context(), viewer->seq.get());
}
// render the audio
compose_audio(viewer, viewer->seq, viewer->get_playback_speed(), viewer->WaitingForPlayWake());
compose_audio(viewer, viewer->seq.get(), viewer->get_playback_speed(), viewer->WaitingForPlayWake());
}
}
@@ -253,7 +253,7 @@ void ViewerWidget::seek_from_click(int x) {
void ViewerWidget::context_destroy() {
makeCurrent();
if (viewer->seq != nullptr) {
close_active_clips(viewer->seq);
close_active_clips(viewer->seq.get());
}
renderer->delete_ctx();
doneCurrent();
@@ -619,7 +619,7 @@ void ViewerWidget::paintGL() {
if (renderer->did_texture_fail() && !viewer->playing) {
doneCurrent();
renderer->start_render(context(), viewer->seq);
renderer->start_render(context(), viewer->seq.get());
}
}
}