code cleanup

This commit is contained in:
itsmattkc
2018-07-20 19:06:57 +01:00
parent 4a6e261fe2
commit 8845ba0577
20 changed files with 296 additions and 125 deletions
+7 -7
View File
@@ -4,15 +4,17 @@
#include "project/effect.h" #include "project/effect.h"
#include <QPixmap> #include <QPixmap>
#include <QFont>
#include <QXmlStreamReader> #include <QXmlStreamReader>
#include <QXmlStreamWriter> #include <QXmlStreamWriter>
class QSpinBox; class QSpinBox;
class QCheckBox; class QCheckBox;
class QComboBox;
class LabelSlider; class LabelSlider;
class QOpenGLTexture; class QOpenGLTexture;
class QTextEdit; class QTextEdit;
class QPushButton; class QPushButton;
class ColorButton;
class ComboBoxEx;
enum VideoEffects { enum VideoEffects {
VIDEO_TRANSFORM_EFFECT, VIDEO_TRANSFORM_EFFECT,
@@ -51,7 +53,7 @@ public:
LabelSlider* anchor_x_box; LabelSlider* anchor_x_box;
LabelSlider* anchor_y_box; LabelSlider* anchor_y_box;
LabelSlider* opacity; LabelSlider* opacity;
QComboBox* blend_mode_box; ComboBoxEx* blend_mode_box;
public slots: public slots:
void toggle_uniform_scale(bool enabled); void toggle_uniform_scale(bool enabled);
private: private:
@@ -99,15 +101,13 @@ public:
void save(QXmlStreamWriter* stream); void save(QXmlStreamWriter* stream);
QTextEdit* text_val; QTextEdit* text_val;
LabelSlider* size_val; LabelSlider* size_val;
QPushButton* set_color_button; ColorButton* set_color_button;
QColor color; ComboBoxEx* set_font_combobox;
private slots: private slots:
void set_color();
void update_texture(); void update_texture();
private: private:
void set_button_color();
QPixmap pixmap;
QOpenGLTexture* texture; QOpenGLTexture* texture;
QFont font;
}; };
// audio effects // audio effects
+2 -10
View File
@@ -8,20 +8,12 @@
#include "ui/labelslider.h" #include "ui/labelslider.h"
#include "ui/collapsiblewidget.h" #include "ui/collapsiblewidget.h"
PanEffect::PanEffect(Clip* c) : Effect(c) { PanEffect::PanEffect(Clip* c) : Effect(c, EFFECT_TYPE_AUDIO, AUDIO_PAN_EFFECT) {
setup_effect(EFFECT_TYPE_AUDIO, AUDIO_PAN_EFFECT);
QGridLayout* ui_layout = new QGridLayout();
ui_layout->addWidget(new QLabel("Pan:"), 0, 0); ui_layout->addWidget(new QLabel("Pan:"), 0, 0);
pan_val = new LabelSlider(); pan_val = new LabelSlider();
pan_val->set_minimum_value(-100); pan_val->set_minimum_value(-100);
pan_val->set_maximum_value(100); pan_val->set_maximum_value(100);
ui_layout->addWidget(pan_val, 0, 1); ui_layout->addWidget(pan_val, 0, 1);
ui->setLayout(ui_layout);
container->setContents(ui);
// set defaults // set defaults
pan_val->set_value(0); pan_val->set_value(0);
+1 -9
View File
@@ -12,11 +12,7 @@
#include "project/sequence.h" #include "project/sequence.h"
#include "panels/timeline.h" #include "panels/timeline.h"
ShakeEffect::ShakeEffect(Clip *c) : Effect(c) { ShakeEffect::ShakeEffect(Clip *c) : Effect(c, EFFECT_TYPE_VIDEO, VIDEO_SHAKE_EFFECT) {
setup_effect(EFFECT_TYPE_VIDEO, VIDEO_SHAKE_EFFECT);
QGridLayout* ui_layout = new QGridLayout();
ui_layout->addWidget(new QLabel("Intensity:"), 0, 0); ui_layout->addWidget(new QLabel("Intensity:"), 0, 0);
intensity_val = new LabelSlider(); intensity_val = new LabelSlider();
intensity_val->set_minimum_value(0); intensity_val->set_minimum_value(0);
@@ -32,10 +28,6 @@ ShakeEffect::ShakeEffect(Clip *c) : Effect(c) {
frequency_val->set_minimum_value(0); frequency_val->set_minimum_value(0);
ui_layout->addWidget(frequency_val, 2, 1); ui_layout->addWidget(frequency_val, 2, 1);
ui->setLayout(ui_layout);
container->setContents(ui);
// set defaults // set defaults
intensity_val->set_value(50); intensity_val->set_value(50);
rotation_val->set_value(0); rotation_val->set_value(0);
+52 -42
View File
@@ -7,42 +7,62 @@
#include <QPainter> #include <QPainter>
#include <QPushButton> #include <QPushButton>
#include <QColorDialog> #include <QColorDialog>
#include <QFontDatabase>
#include <QComboBox>
#include <QDebug> #include <QDebug>
#include "ui/labelslider.h" #include "ui/labelslider.h"
#include "ui/collapsiblewidget.h" #include "ui/collapsiblewidget.h"
#include "project/clip.h" #include "project/clip.h"
#include "project/sequence.h" #include "project/sequence.h"
#include "ui/comboboxex.h"
#include "ui/colorbutton.h"
TextEffect::TextEffect(Clip *c) : Effect(c), texture(NULL) { class FontCombobox : public ComboBoxEx {
setup_effect(EFFECT_TYPE_VIDEO, VIDEO_TEXT_EFFECT); public:
FontCombobox(QWidget* parent = 0) : ComboBoxEx(parent) {}
QGridLayout* ui_layout = new QGridLayout(); protected:
void showPopup() {
QString current = currentText();
clear();
QStringList fonts = QFontDatabase().families();
bool found = false;
for (int i=0;i<fonts.size();i++) {
addItem(fonts.at(i));
if (!found && fonts.at(i) == current) {
setCurrentIndex(i);
found = true;
}
}
QComboBox::showPopup();
}
};
TextEffect::TextEffect(Clip *c) : Effect(c, EFFECT_TYPE_VIDEO, VIDEO_TEXT_EFFECT), texture(NULL) {
ui_layout->addWidget(new QLabel("Text:"), 0, 0); ui_layout->addWidget(new QLabel("Text:"), 0, 0);
text_val = new QTextEdit(); text_val = new QTextEdit();
text_val->setUndoRedoEnabled(true); text_val->setUndoRedoEnabled(true);
ui_layout->addWidget(text_val, 0, 1); ui_layout->addWidget(text_val, 0, 1);
ui_layout->addWidget(new QLabel("Size:"), 1, 0); ui_layout->addWidget(new QLabel("Font:"), 1, 0);
set_font_combobox = new FontCombobox();
ui_layout->addWidget(set_font_combobox, 1, 1);
ui_layout->addWidget(new QLabel("Size:"), 2, 0);
size_val = new LabelSlider(); size_val = new LabelSlider();
size_val->set_minimum_value(0); size_val->set_minimum_value(0);
ui_layout->addWidget(size_val, 1, 1); ui_layout->addWidget(size_val, 2, 1);
ui_layout->addWidget(new QLabel("Color:"), 2, 0); ui_layout->addWidget(new QLabel("Color:"), 3, 0);
set_color_button = new QPushButton(); set_color_button = new ColorButton();
ui_layout->addWidget(set_color_button, 2, 1); ui_layout->addWidget(set_color_button, 3, 1);
ui->setLayout(ui_layout); set_font_combobox->addItem(font.family());
container->setContents(ui);
color = Qt::white;
set_button_color();
connect(text_val, SIGNAL(textChanged()), this, SLOT(update_texture())); connect(text_val, SIGNAL(textChanged()), this, SLOT(update_texture()));
connect(size_val, SIGNAL(valueChanged()), this, SLOT(update_texture())); connect(size_val, SIGNAL(valueChanged()), this, SLOT(update_texture()));
connect(set_color_button, SIGNAL(clicked(bool)), this, SLOT(set_color())); connect(set_color_button, SIGNAL(color_changed()), this, SLOT(update_texture()));
connect(set_font_combobox, SIGNAL(currentTextChanged(QString)), this, SLOT(update_texture()));
size_val->set_value(24); size_val->set_value(24);
text_val->setText("Sample Text"); text_val->setText("Sample Text");
@@ -53,38 +73,27 @@ TextEffect::~TextEffect() {
delete texture; delete texture;
} }
void TextEffect::set_button_color() {
QPalette pal = set_color_button->palette();
pal.setColor(QPalette::Button, color);
set_color_button->setPalette(pal);
}
void TextEffect::set_color() {
color = QColorDialog::getColor(color, NULL);
set_button_color();
update_texture();
}
void TextEffect::update_texture() { void TextEffect::update_texture() {
pixmap = QPixmap(parent_clip->sequence->width, parent_clip->sequence->height); QImage pixmap(parent_clip->sequence->width, parent_clip->sequence->height, QImage::Format_ARGB32_Premultiplied);
pixmap.fill(Qt::transparent); pixmap.fill(Qt::transparent);
QPainter p(&pixmap); QPainter p(&pixmap);
p.setRenderHint(QPainter::TextAntialiasing, true); p.setRenderHint(QPainter::TextAntialiasing, true);
// set font // set font
QFont font = p.font(); font.setFamily(set_font_combobox->currentText());
font.setPointSize(size_val->value()); font.setPointSize(size_val->value());
font.setStyleHint(QFont::Helvetica, QFont::PreferAntialias);
p.setFont(font); p.setFont(font);
p.setPen(color); p.setPen(set_color_button->get_color());
p.drawText(QRect(0, 0, pixmap.width(), pixmap.height()), Qt::AlignCenter | Qt::TextWordWrap, text_val->toPlainText()); p.drawText(QRect(0, 0, pixmap.width(), pixmap.height()), Qt::AlignCenter | Qt::TextWordWrap, text_val->toPlainText());
if (texture == NULL) { if (texture == NULL) {
texture = new QOpenGLTexture(pixmap.toImage()); texture = new QOpenGLTexture(pixmap);
} else { } else {
texture->destroy(); texture->destroy();
texture->setData(pixmap.toImage()); texture->setData(pixmap);
} }
// queue a repaint of the canvas // queue a repaint of the canvas
@@ -95,8 +104,8 @@ void TextEffect::post_gl() {
if (texture != NULL) { if (texture != NULL) {
texture->bind(); texture->bind();
int half_width = pixmap.width()/2; int half_width = parent_clip->sequence->width/2;
int half_height = pixmap.height()/2; int half_height = parent_clip->sequence->height/2;
glBegin(GL_QUADS); glBegin(GL_QUADS);
glTexCoord2f(0.0, 0.0); glTexCoord2f(0.0, 0.0);
@@ -117,7 +126,7 @@ Effect* TextEffect::copy(Clip* c) {
TextEffect* e = new TextEffect(c); TextEffect* e = new TextEffect(c);
e->text_val->setPlainText(text_val->toPlainText()); e->text_val->setPlainText(text_val->toPlainText());
e->size_val->set_value(size_val->value()); e->size_val->set_value(size_val->value());
e->color = color; e->set_color_button->set_color(set_color_button->get_color());
return e; return e;
} }
@@ -128,16 +137,17 @@ void TextEffect::load(QXmlStreamReader* stream) {
if (a.name() == "size") { if (a.name() == "size") {
size_val->set_value(a.value().toDouble()); size_val->set_value(a.value().toDouble());
} else if (a.name() == "r") { } else if (a.name() == "r") {
color.setRed(a.value().toInt()); set_color_button->get_color().setRed(a.value().toInt());
} else if (a.name() == "g") { } else if (a.name() == "g") {
color.setGreen(a.value().toInt()); set_color_button->get_color().setGreen(a.value().toInt());
} else if (a.name() == "b") { } else if (a.name() == "b") {
color.setBlue(a.value().toInt()); set_color_button->get_color().setBlue(a.value().toInt());
} }
} }
while (!(stream->name() == "effect" && stream->isEndElement())) { while (!(stream->name() == "effect" && stream->isEndElement())) {
stream->readNext(); stream->readNext();
if (stream->name() == "text" && stream->isStartElement()) { if (stream->name() == "text" && stream->isStartElement()) {
stream->readNext();
text_val->setPlainText(stream->text().toString()); text_val->setPlainText(stream->text().toString());
} }
} }
@@ -145,8 +155,8 @@ void TextEffect::load(QXmlStreamReader* stream) {
void TextEffect::save(QXmlStreamWriter* stream) { void TextEffect::save(QXmlStreamWriter* stream) {
stream->writeAttribute("size", QString::number(size_val->value())); stream->writeAttribute("size", QString::number(size_val->value()));
stream->writeAttribute("r", QString::number(color.red())); stream->writeAttribute("r", QString::number(set_color_button->get_color().red()));
stream->writeAttribute("g", QString::number(color.green())); stream->writeAttribute("g", QString::number(set_color_button->get_color().green()));
stream->writeAttribute("b", QString::number(color.blue())); stream->writeAttribute("b", QString::number(set_color_button->get_color().blue()));
stream->writeTextElement("text", text_val->toPlainText()); stream->writeTextElement("text", text_val->toPlainText());
} }
+4 -10
View File
@@ -14,17 +14,14 @@
#include "project/sequence.h" #include "project/sequence.h"
#include "io/media.h" #include "io/media.h"
#include "ui/labelslider.h" #include "ui/labelslider.h"
#include "ui/comboboxex.h"
#define BLEND_MODE_NORMAL 0 #define BLEND_MODE_NORMAL 0
#define BLEND_MODE_SCREEN 1 #define BLEND_MODE_SCREEN 1
#define BLEND_MODE_MULTIPLY 2 #define BLEND_MODE_MULTIPLY 2
#define BLEND_MODE_OVERLAY 3 #define BLEND_MODE_OVERLAY 3
TransformEffect::TransformEffect(Clip* c) : Effect(c) { TransformEffect::TransformEffect(Clip* c) : Effect(c, EFFECT_TYPE_VIDEO, VIDEO_TRANSFORM_EFFECT) {
setup_effect(EFFECT_TYPE_VIDEO, VIDEO_TRANSFORM_EFFECT);
QGridLayout* ui_layout = new QGridLayout();
ui_layout->addWidget(new QLabel("Position:"), 0, 0); ui_layout->addWidget(new QLabel("Position:"), 0, 0);
position_x = new LabelSlider(); position_x = new LabelSlider();
ui_layout->addWidget(position_x, 0, 1); ui_layout->addWidget(position_x, 0, 1);
@@ -63,17 +60,13 @@ TransformEffect::TransformEffect(Clip* c) : Effect(c) {
ui_layout->addWidget(opacity, 5, 1); ui_layout->addWidget(opacity, 5, 1);
ui_layout->addWidget(new QLabel("Blend Mode:"), 6, 0); ui_layout->addWidget(new QLabel("Blend Mode:"), 6, 0);
blend_mode_box = new QComboBox(); blend_mode_box = new ComboBoxEx();
blend_mode_box->addItem("Normal", BLEND_MODE_NORMAL); blend_mode_box->addItem("Normal", BLEND_MODE_NORMAL);
blend_mode_box->addItem("Overlay", BLEND_MODE_OVERLAY); blend_mode_box->addItem("Overlay", BLEND_MODE_OVERLAY);
blend_mode_box->addItem("Screen", BLEND_MODE_SCREEN); blend_mode_box->addItem("Screen", BLEND_MODE_SCREEN);
blend_mode_box->addItem("Multiply", BLEND_MODE_MULTIPLY); blend_mode_box->addItem("Multiply", BLEND_MODE_MULTIPLY);
ui_layout->addWidget(blend_mode_box, 6, 1); ui_layout->addWidget(blend_mode_box, 6, 1);
ui->setLayout(ui_layout);
container->setContents(ui);
// set defaults // set defaults
position_x->set_default_value(c->sequence->width/2); position_x->set_default_value(c->sequence->width/2);
position_y->set_default_value(c->sequence->height/2); position_y->set_default_value(c->sequence->height/2);
@@ -98,6 +91,7 @@ TransformEffect::TransformEffect(Clip* c) : Effect(c) {
connect(opacity, SIGNAL(valueChanged()), this, SLOT(field_changed())); connect(opacity, SIGNAL(valueChanged()), this, SLOT(field_changed()));
connect(uniform_scale_box, SIGNAL(toggled(bool)), this, SLOT(toggle_uniform_scale(bool))); connect(uniform_scale_box, SIGNAL(toggled(bool)), this, SLOT(toggle_uniform_scale(bool)));
connect(uniform_scale_box, SIGNAL(toggled(bool)), this, SLOT(field_changed())); connect(uniform_scale_box, SIGNAL(toggled(bool)), this, SLOT(field_changed()));
connect(uniform_scale_box, SIGNAL(clicked(bool)), this, SLOT(checkbox_command()));
connect(blend_mode_box, SIGNAL(currentIndexChanged(int)), this, SLOT(field_changed())); connect(blend_mode_box, SIGNAL(currentIndexChanged(int)), this, SLOT(field_changed()));
} }
+3 -11
View File
@@ -9,20 +9,12 @@
#include "ui/labelslider.h" #include "ui/labelslider.h"
#include "ui/collapsiblewidget.h" #include "ui/collapsiblewidget.h"
VolumeEffect::VolumeEffect(Clip* c) : Effect(c) { VolumeEffect::VolumeEffect(Clip* c) : Effect(c, EFFECT_TYPE_AUDIO, AUDIO_VOLUME_EFFECT) {
setup_effect(EFFECT_TYPE_AUDIO, AUDIO_VOLUME_EFFECT); ui_layout->addWidget(new QLabel("Volume:"), 0, 0);
QGridLayout* ui_layout = new QGridLayout();
ui_layout->addWidget(new QLabel("Volume:"), 0, 0);
volume_val = new LabelSlider(); volume_val = new LabelSlider();
volume_val->set_minimum_value(0); volume_val->set_minimum_value(0);
volume_val->set_maximum_value(400); volume_val->set_maximum_value(400);
ui_layout->addWidget(volume_val, 0, 1); ui_layout->addWidget(volume_val, 0, 1);
ui->setLayout(ui_layout);
container->setContents(ui);
// set defaults // set defaults
volume_val->set_value(100); volume_val->set_value(100);
+6 -10
View File
@@ -31,7 +31,6 @@
#define OLIVE_FILE_FILTER "Olive Project (*.ove)" #define OLIVE_FILE_FILTER "Olive Project (*.ove)"
QString autorecovery_filename;
QTimer autorecovery_timer; QTimer autorecovery_timer;
void MainWindow::setup_layout() { void MainWindow::setup_layout() {
@@ -292,12 +291,8 @@ void MainWindow::on_action_Paste_triggered()
void MainWindow::autorecover_interval() { void MainWindow::autorecover_interval() {
if (project_changed) { if (project_changed) {
QString old_filename = project_url; panel_project->save_project(true);
project_url = autorecovery_filename;
panel_project->save_project();
qDebug() << "[INFO] Auto-recovery project saved"; qDebug() << "[INFO] Auto-recovery project saved";
project_url = old_filename;
project_changed = true;
} }
} }
@@ -308,7 +303,7 @@ bool MainWindow::save_project_as() {
fn += ".ove"; fn += ".ove";
} }
project_url = fn; project_url = fn;
panel_project->save_project(); panel_project->save_project(false);
return true; return true;
} }
return false; return false;
@@ -318,7 +313,7 @@ bool MainWindow::save_project() {
if (project_url.isEmpty()) { if (project_url.isEmpty()) {
return save_project_as(); return save_project_as();
} else { } else {
panel_project->save_project(); panel_project->save_project(false);
return true; return true;
} }
} }
@@ -361,11 +356,12 @@ void MainWindow::on_action_Open_Project_triggered()
void MainWindow::on_actionProject_triggered() void MainWindow::on_actionProject_triggered()
{ {
if (can_close_project()) { if (can_close_project()) {
project_url.clear(); panel_effect_controls->clear_effects(true);
project_changed = false;
panel_project->new_project(); panel_project->new_project();
undo_stack.clear(); undo_stack.clear();
panel_timeline->redraw_all_clips(false); panel_timeline->redraw_all_clips(false);
project_url.clear();
project_changed = false;
} }
} }
+6 -2
View File
@@ -62,7 +62,9 @@ SOURCES += \
project/undo.cpp \ project/undo.cpp \
ui/scrollarea.cpp \ ui/scrollarea.cpp \
effects/shakeeffect.cpp \ effects/shakeeffect.cpp \
effects/texteffect.cpp effects/texteffect.cpp \
ui/comboboxex.cpp \
ui/colorbutton.cpp
HEADERS += \ HEADERS += \
mainwindow.h \ mainwindow.h \
@@ -97,7 +99,9 @@ HEADERS += \
effects/transition.h \ effects/transition.h \
ui/audiomonitor.h \ ui/audiomonitor.h \
project/undo.h \ project/undo.h \
ui/scrollarea.h ui/scrollarea.h \
ui/comboboxex.h \
ui/colorbutton.h
FORMS += \ FORMS += \
mainwindow.ui \ mainwindow.ui \
+3
View File
@@ -12,6 +12,7 @@
#include "ui/collapsiblewidget.h" #include "ui/collapsiblewidget.h"
#include "project/sequence.h" #include "project/sequence.h"
#include "project/undo.h" #include "project/undo.h"
#include "panels/project.h"
EffectControls::EffectControls(QWidget *parent) : EffectControls::EffectControls(QWidget *parent) :
QDockWidget(parent), QDockWidget(parent),
@@ -37,6 +38,7 @@ void EffectControls::menu_select(QAction* q) {
} }
} }
undo_stack.push(command); undo_stack.push(command);
project_changed = true;
} }
void EffectControls::show_menu(bool video) { void EffectControls::show_menu(bool video) {
@@ -134,6 +136,7 @@ void EffectControls::delete_effects() {
} }
if (command->clips.size() > 0) { if (command->clips.size() > 0) {
undo_stack.push(command); undo_stack.push(command);
project_changed = true;
} else { } else {
delete command; delete command;
} }
+16 -6
View File
@@ -34,6 +34,7 @@ extern "C" {
#define MAXIMUM_RECENT_PROJECTS 10 #define MAXIMUM_RECENT_PROJECTS 10
QString autorecovery_filename;
bool project_changed = false; bool project_changed = false;
QString project_url = ""; QString project_url = "";
QStringList recent_projects; QStringList recent_projects;
@@ -556,8 +557,9 @@ bool Project::load_worker(QFile& f, QXmlStreamReader& stream, int type) {
{ {
QTreeWidgetItem* parent = NULL; QTreeWidgetItem* parent = NULL;
Sequence* s = new Sequence(); Sequence* s = new Sequence();
bool open_sequence = false;
// load attributes about stream // load attributes about sequence
for (int j=0;j<stream.attributes().size();j++) { for (int j=0;j<stream.attributes().size();j++) {
const QXmlStreamAttribute& attr = stream.attributes().at(j); const QXmlStreamAttribute& attr = stream.attributes().at(j);
if (attr.name() == "name") { if (attr.name() == "name") {
@@ -575,6 +577,8 @@ bool Project::load_worker(QFile& f, QXmlStreamReader& stream, int type) {
s->audio_frequency = attr.value().toInt(); s->audio_frequency = attr.value().toInt();
} else if (attr.name() == "alayout") { } else if (attr.name() == "alayout") {
s->audio_layout = attr.value().toInt(); s->audio_layout = attr.value().toInt();
} else if (attr.name() == "open") {
open_sequence = true;
} }
} }
@@ -692,6 +696,8 @@ bool Project::load_worker(QFile& f, QXmlStreamReader& stream, int type) {
} }
new_sequence(NULL, s, false, parent); new_sequence(NULL, s, false, parent);
if (open_sequence) set_sequence(s);
} }
break; break;
} }
@@ -835,6 +841,9 @@ void Project::save_folder(QXmlStreamWriter& stream, QTreeWidgetItem* parent, int
stream.writeAttribute("framerate", QString::number(s->frame_rate)); stream.writeAttribute("framerate", QString::number(s->frame_rate));
stream.writeAttribute("afreq", QString::number(s->audio_frequency)); stream.writeAttribute("afreq", QString::number(s->audio_frequency));
stream.writeAttribute("alayout", QString::number(s->audio_layout)); stream.writeAttribute("alayout", QString::number(s->audio_layout));
if (s == sequence) {
stream.writeAttribute("open", "1");
}
for (int j=0;j<s->clip_count();j++) { for (int j=0;j<s->clip_count();j++) {
Clip* c = s->get_clip(j); Clip* c = s->get_clip(j);
if (c != NULL) { if (c != NULL) {
@@ -883,11 +892,11 @@ void Project::save_folder(QXmlStreamWriter& stream, QTreeWidgetItem* parent, int
} }
} }
void Project::save_project() { void Project::save_project(bool autorecovery) {
folder_id = 1; folder_id = 1;
media_id = 0; media_id = 0;
QFile file(project_url); QFile file(autorecovery ? autorecovery_filename : project_url);
if (!file.open(QIODevice::WriteOnly/* | QIODevice::Text*/)) { if (!file.open(QIODevice::WriteOnly/* | QIODevice::Text*/)) {
qDebug() << "[ERROR] Could not open file"; qDebug() << "[ERROR] Could not open file";
return; return;
@@ -921,9 +930,10 @@ void Project::save_project() {
file.close(); file.close();
add_recent_project(project_url); if (!autorecovery) {
add_recent_project(project_url);
project_changed = false; project_changed = false;
}
} }
void Project::save_recent_projects() { void Project::save_recent_projects() {
+2 -1
View File
@@ -31,6 +31,7 @@ namespace Ui {
class Project; class Project;
} }
extern QString autorecovery_filename;
extern bool project_changed; extern bool project_changed;
extern QString project_url; extern QString project_url;
extern QStringList recent_projects; extern QStringList recent_projects;
@@ -56,7 +57,7 @@ public:
void new_project(); void new_project();
void load_project(); void load_project();
void save_project(); void save_project(bool autorecovery);
QTreeWidgetItem* new_folder(); QTreeWidgetItem* new_folder();
+16 -7
View File
@@ -5,27 +5,36 @@
#include "ui/viewerwidget.h" #include "ui/viewerwidget.h"
#include "ui/collapsiblewidget.h" #include "ui/collapsiblewidget.h"
#include "effects/effects.h" #include "effects/effects.h"
#include "panels/project.h"
#include "project/undo.h"
#include <QCheckBox> #include <QCheckBox>
#include <QGridLayout>
Effect::Effect(Clip* c) : parent_clip(c) { Effect::Effect(Clip* c, int t, int i) : parent_clip(c), type(t), id(i) {
type = EFFECT_TYPE_INVALID;
}
void Effect::setup_effect(int t, int i) {
type = t;
id = i;
container = new CollapsibleWidget(); container = new CollapsibleWidget();
if (type == EFFECT_TYPE_VIDEO) { if (type == EFFECT_TYPE_VIDEO) {
container->setText(video_effect_names[i]); container->setText(video_effect_names[i]);
} else if (type == EFFECT_TYPE_AUDIO) { } else if (type == EFFECT_TYPE_AUDIO) {
container->setText(audio_effect_names[i]); container->setText(audio_effect_names[i]);
} }
connect(container->enabled_check, SIGNAL(clicked(bool)), this, SLOT(checkbox_command()));
connect(container->enabled_check, SIGNAL(clicked(bool)), this, SLOT(field_changed()));
ui = new QWidget(); ui = new QWidget();
ui_layout = new QGridLayout();
ui->setLayout(ui_layout);
container->setContents(ui);
} }
void Effect::field_changed() { void Effect::field_changed() {
panel_viewer->viewer_widget->update(); panel_viewer->viewer_widget->update();
project_changed = true;
}
void Effect::checkbox_command() {
CheckboxCommand* c = new CheckboxCommand(static_cast<QCheckBox*>(sender()));
undo_stack.push(c);
} }
bool Effect::is_enabled() { bool Effect::is_enabled() {
+5 -6
View File
@@ -5,6 +5,7 @@
#include <QString> #include <QString>
class QWidget; class QWidget;
class CollapsibleWidget; class CollapsibleWidget;
class QGridLayout;
struct Clip; struct Clip;
class QXmlStreamReader; class QXmlStreamReader;
@@ -16,13 +17,14 @@ class Effect : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
Effect(Clip* c); // default constructor Effect(Clip* c, int t, int i); // default constructor
Clip* parent_clip;
int type; int type;
int id; int id;
QString name; QString name;
CollapsibleWidget* container; CollapsibleWidget* container;
QGridLayout* ui_layout;
QWidget* ui; QWidget* ui;
Clip* parent_clip;
bool is_enabled(); bool is_enabled();
@@ -34,12 +36,9 @@ public:
virtual void process_gl(int* anchor_x, int* anchor_y); virtual void process_gl(int* anchor_x, int* anchor_y);
virtual void post_gl(); virtual void post_gl();
virtual void process_audio(quint8* samples, int nb_bytes); virtual void process_audio(quint8* samples, int nb_bytes);
public slots: public slots:
void field_changed(); void field_changed();
void checkbox_command();
protected:
void setup_effect(int t, int i);
}; };
#endif // EFFECT_H #endif // EFFECT_H
+16
View File
@@ -3,6 +3,7 @@
#include <QDebug> #include <QDebug>
#include <QTreeWidgetItem> #include <QTreeWidgetItem>
#include <QMessageBox> #include <QMessageBox>
#include <QCheckBox>
#include "project/clip.h" #include "project/clip.h"
#include "project/sequence.h" #include "project/sequence.h"
@@ -383,3 +384,18 @@ void LinkCommand::redo() {
} }
} }
} }
CheckboxCommand::CheckboxCommand(QCheckBox* b) : box(b), done(true), checked(box->isChecked()) {}
CheckboxCommand::~CheckboxCommand() {}
void CheckboxCommand::undo() {
box->setChecked(!checked);
done = false;
}
void CheckboxCommand::redo() {
if (!done) {
box->setChecked(checked);
}
}
+13
View File
@@ -2,6 +2,7 @@
#define UNDO_H #define UNDO_H
class QTreeWidgetItem; class QTreeWidgetItem;
class QCheckBox;
struct Clip; struct Clip;
struct Sequence; struct Sequence;
@@ -79,4 +80,16 @@ private:
QVector< QVector<int> > old_links; QVector< QVector<int> > old_links;
}; };
class CheckboxCommand : public QUndoCommand {
public:
CheckboxCommand(QCheckBox* b);
~CheckboxCommand();
void undo();
void redo();
private:
QCheckBox* box;
bool checked;
bool done;
};
#endif // UNDO_H #endif // UNDO_H
+48
View File
@@ -0,0 +1,48 @@
#include "colorbutton.h"
#include "project/undo.h"
#include <QColorDialog>
ColorButton::ColorButton(QWidget *parent)
: QPushButton(parent), color(Qt::white) {
set_button_color();
connect(this, SIGNAL(clicked(bool)), this, SLOT(open_dialog()));
}
QColor ColorButton::get_color() {
return color;
}
void ColorButton::set_color(QColor c) {
color = c;
}
void ColorButton::set_button_color() {
QPalette pal = palette();
pal.setColor(QPalette::Button, color);
setPalette(pal);
}
void ColorButton::open_dialog() {
QColor old_color = color;
QColor new_color = QColorDialog::getColor(color, NULL);
if (old_color != new_color) {
ColorCommand* command = new ColorCommand(this, old_color, new_color);
undo_stack.push(command);
set_button_color();
emit color_changed();
}
}
ColorCommand::ColorCommand(ColorButton* s, QColor o, QColor n)
: sender(s), old_color(o), new_color(n) {}
void ColorCommand::undo() {
sender->set_color(old_color);
}
void ColorCommand::redo() {
sender->set_color(new_color);
}
+34
View File
@@ -0,0 +1,34 @@
#ifndef COLORBUTTON_H
#define COLORBUTTON_H
#include <QPushButton>
#include <QColor>
#include <QUndoCommand>
class ColorButton : public QPushButton {
Q_OBJECT
public:
ColorButton(QWidget* parent = 0);
QColor get_color();
void set_color(QColor c);
private:
QColor color;
void set_button_color();
signals:
void color_changed();
private slots:
void open_dialog();
};
class ColorCommand : public QUndoCommand {
public:
ColorCommand(ColorButton* s, QColor o, QColor n);
void undo();
void redo();
private:
ColorButton* sender;
QColor old_color;
QColor new_color;
};
#endif // COLORBUTTON_H
+41
View File
@@ -0,0 +1,41 @@
#include "comboboxex.h"
#include "project/undo.h"
#include <QUndoCommand>
#include <QWheelEvent>
class ComboBoxExCommand : public QUndoCommand {
public:
ComboBoxExCommand(ComboBoxEx* obj, int old_index, int new_index) :
combobox(obj), old_val(old_index), new_val(new_index), done(true) {}
void undo() {
combobox->setCurrentIndex(old_val);
done = false;
}
void redo() {
if (!done) {
combobox->setCurrentIndex(new_val);
}
}
private:
ComboBoxEx* combobox;
int old_val;
int new_val;
bool done;
};
ComboBoxEx::ComboBoxEx(QWidget *parent) : QComboBox(parent), index(0) {
connect(this, SIGNAL(activated(int)), this, SLOT(index_changed(int)));
}
void ComboBoxEx::index_changed(int i) {
if (index != i) {
undo_stack.push(new ComboBoxExCommand(this, index, i));
index = i;
}
}
void ComboBoxEx::wheelEvent(QWheelEvent* e) {
e->ignore();
}
+18
View File
@@ -0,0 +1,18 @@
#ifndef COMBOBOXEX_H
#define COMBOBOXEX_H
#include <QComboBox>
#include <QDebug>
class ComboBoxEx : public QComboBox {
Q_OBJECT
public:
ComboBoxEx(QWidget* parent = 0);
private slots:
void index_changed(int);
private:
int index;
void wheelEvent(QWheelEvent* e);
};
#endif // COMBOBOXEX_H
+3 -4
View File
@@ -19,8 +19,7 @@ extern "C" {
#include <libavformat/avformat.h> #include <libavformat/avformat.h>
} }
ViewerWidget::ViewerWidget(QWidget *parent) : QOpenGLWidget(parent) ViewerWidget::ViewerWidget(QWidget *parent) : QOpenGLWidget(parent) {
{
multithreaded = true; multithreaded = true;
enable_paint = true; enable_paint = true;
force_audio = false; force_audio = false;
@@ -130,7 +129,7 @@ void ViewerWidget::paintGL() {
// perform all transform effects // perform all transform effects
for (int j=0;j<c->effects.size();j++) { for (int j=0;j<c->effects.size();j++) {
c->effects.at(j)->process_gl(&anchor_x, &anchor_y); if (c->effects.at(j)->is_enabled()) c->effects.at(j)->process_gl(&anchor_x, &anchor_y);
} }
if (c->opening_transition != NULL) { if (c->opening_transition != NULL) {
@@ -169,7 +168,7 @@ void ViewerWidget::paintGL() {
// perform all transform effects // perform all transform effects
for (int j=0;j<c->effects.size();j++) { for (int j=0;j<c->effects.size();j++) {
c->effects.at(j)->post_gl(); if (c->effects.at(j)->is_enabled()) c->effects.at(j)->post_gl();
} }
} }
} else if (render_audio && } else if (render_audio &&