reimplemented sorting and improved view-model
This commit is contained in:
+3
-10
@@ -238,11 +238,7 @@ bool LoadThread::load_worker(QFile& f, QXmlStreamReader& stream, int type) {
|
||||
|
||||
item->set_footage(m);
|
||||
|
||||
if (folder == 0) {
|
||||
project_model.addTopLevelItem(item);
|
||||
} else {
|
||||
find_loaded_folder_by_id(folder)->appendChild(item);
|
||||
}
|
||||
project_model.appendChild(find_loaded_folder_by_id(folder), item);
|
||||
|
||||
// analyze media to see if it's the same
|
||||
loaded_media_items.append(item);
|
||||
@@ -498,6 +494,7 @@ bool LoadThread::load_worker(QFile& f, QXmlStreamReader& stream, int type) {
|
||||
}
|
||||
|
||||
Media* LoadThread::find_loaded_folder_by_id(int id) {
|
||||
if (id == 0) return NULL;
|
||||
for (int j=0;j<loaded_folders.size();j++) {
|
||||
Media* parent_item = loaded_folders.at(j);
|
||||
if (parent_item->temp_id == id) {
|
||||
@@ -582,11 +579,7 @@ void LoadThread::run() {
|
||||
for (int i=0;i<loaded_folders.size();i++) {
|
||||
Media* folder = loaded_folders.at(i);
|
||||
int parent = folder->temp_id2;
|
||||
if (parent > 0) {
|
||||
find_loaded_folder_by_id(parent)->appendChild(folder);
|
||||
} else {
|
||||
project_model.addTopLevelItem(folder);
|
||||
}
|
||||
project_model.appendChild(find_loaded_folder_by_id(parent), folder);
|
||||
}
|
||||
|
||||
cont = load_worker(file, stream, MEDIA_TYPE_FOOTAGE);
|
||||
|
||||
+1
-2
@@ -100,8 +100,7 @@ void update_effect_controls() {
|
||||
void update_ui(bool modified) {
|
||||
if (modified) {
|
||||
update_effect_controls();
|
||||
}
|
||||
project_model.update_data();
|
||||
}
|
||||
panel_effect_controls->update_keyframes();
|
||||
panel_timeline->repaint_timeline();
|
||||
panel_sequence_viewer->update_viewer();
|
||||
|
||||
+40
-36
@@ -34,6 +34,7 @@
|
||||
#include <QMimeData>
|
||||
#include <QPushButton>
|
||||
#include <QInputDialog>
|
||||
#include <QSortFilterProxyModel>
|
||||
#include <QXmlStreamReader>
|
||||
#include <QXmlStreamWriter>
|
||||
|
||||
@@ -57,8 +58,12 @@ Project::Project(QWidget *parent) :
|
||||
{
|
||||
ui->setupUi(this);
|
||||
source_table = ui->treeView;
|
||||
source_table->project_parent = this;
|
||||
|
||||
source_table->setModel(&project_model);
|
||||
sorter = new QSortFilterProxyModel(this);
|
||||
sorter->setSourceModel(&project_model);
|
||||
|
||||
source_table->setModel(sorter);
|
||||
|
||||
/*Media* m = new Media(project_model.get_root());
|
||||
project_model.get_root()->appendChild(m);*/
|
||||
@@ -81,8 +86,8 @@ QString Project::get_next_sequence_name(QString start) {
|
||||
name += "0";
|
||||
}
|
||||
name += QString::number(n);
|
||||
for (int i=0;i<project_model.topLevelItemCount();i++) {
|
||||
if (QString::compare(project_model.topLevelItem(i)->get_name(), name, Qt::CaseInsensitive) == 0) {
|
||||
for (int i=0;i<project_model.childCount();i++) {
|
||||
if (QString::compare(project_model.child(i)->get_name(), name, Qt::CaseInsensitive) == 0) {
|
||||
found = true;
|
||||
n++;
|
||||
break;
|
||||
@@ -165,9 +170,9 @@ void Project::duplicate_selected() {
|
||||
bool duped = false;
|
||||
ComboAction* ca = new ComboAction();
|
||||
for (int j=0;j<items.size();j++) {
|
||||
Media* i = static_cast<Media*>(items.at(j).internalPointer());
|
||||
Media* i = item_to_media(items.at(j));
|
||||
if (i->get_type() == MEDIA_TYPE_SEQUENCE) {
|
||||
new_sequence(ca, i->to_sequence()->copy(), false, static_cast<Media*>(items.at(j).parent().internalPointer()));
|
||||
new_sequence(ca, i->to_sequence()->copy(), false, item_to_media(items.at(j).parent()));
|
||||
duped = true;
|
||||
}
|
||||
}
|
||||
@@ -181,7 +186,7 @@ void Project::duplicate_selected() {
|
||||
void Project::replace_selected_file() {
|
||||
QModelIndexList selected_items = source_table->selectionModel()->selectedRows();
|
||||
if (selected_items.size() == 1) {
|
||||
Media* item = static_cast<Media*>(selected_items.at(0).internalPointer());
|
||||
Media* item = item_to_media(selected_items.at(0));
|
||||
if (item->get_type() == MEDIA_TYPE_FOOTAGE) {
|
||||
replace_media(item, 0);
|
||||
}
|
||||
@@ -204,7 +209,7 @@ void Project::replace_clip_media() {
|
||||
} else {
|
||||
QModelIndexList selected_items = source_table->selectionModel()->selectedRows();
|
||||
if (selected_items.size() == 1) {
|
||||
Media* item = static_cast<Media*>(selected_items.at(0).internalPointer());
|
||||
Media* item = item_to_media(selected_items.at(0));
|
||||
if (item->get_type() == MEDIA_TYPE_SEQUENCE && sequence == item->to_sequence()) {
|
||||
QMessageBox::critical(this, "Active sequence selected", "You cannot insert a sequence into itself, so no clips of this media would be in this sequence.", QMessageBox::Ok);
|
||||
} else {
|
||||
@@ -218,7 +223,7 @@ void Project::replace_clip_media() {
|
||||
void Project::open_properties() {
|
||||
QModelIndexList selected_items = source_table->selectionModel()->selectedRows();
|
||||
if (selected_items.size() == 1) {
|
||||
Media* item = static_cast<Media*>(selected_items.at(0).internalPointer());
|
||||
Media* item = item_to_media(selected_items.at(0));
|
||||
switch (item->get_type()) {
|
||||
case MEDIA_TYPE_FOOTAGE:
|
||||
{
|
||||
@@ -257,11 +262,7 @@ Media* Project::new_sequence(ComboAction *ca, Sequence *s, bool open, Media* par
|
||||
ca->append(new NewSequenceCommand(item, parent));
|
||||
if (open) ca->append(new ChangeSequenceAction(s));
|
||||
} else {
|
||||
if (parent == NULL) {
|
||||
project_model.addTopLevelItem(item);
|
||||
} else {
|
||||
parent->appendChild(item);
|
||||
}
|
||||
project_model.appendChild(NULL, item);
|
||||
if (open) set_sequence(s);
|
||||
}
|
||||
return item;
|
||||
@@ -287,6 +288,11 @@ Media* Project::new_folder(QString name) {
|
||||
return item;
|
||||
}
|
||||
|
||||
Media *Project::item_to_media(const QModelIndex &index) {
|
||||
return static_cast<Media*>(sorter->mapToSource(index).internalPointer());
|
||||
// return static_cast<Media*>(index.internalPointer());
|
||||
}
|
||||
|
||||
void Project::get_all_media_from_table(QList<Media*> items, QList<Media*>& list, int search_type) {
|
||||
for (int i=0;i<items.size();i++) {
|
||||
Media* item = items.at(i);
|
||||
@@ -321,7 +327,7 @@ void Project::delete_selected_media() {
|
||||
QModelIndexList selected_items = source_table->selectionModel()->selectedRows();
|
||||
QList<Media*> items;
|
||||
for (int i=0;i<selected_items.size();i++) {
|
||||
items.append(static_cast<Media*>(selected_items.at(i).internalPointer()));
|
||||
items.append(item_to_media(selected_items.at(i)));
|
||||
}
|
||||
bool remove = true;
|
||||
bool redraw = false;
|
||||
@@ -334,8 +340,8 @@ void Project::delete_selected_media() {
|
||||
QVector<Media*> parents;
|
||||
QList<Media*> sequence_items;
|
||||
QList<Media*> all_top_level_items;
|
||||
for (int i=0;i<project_model.topLevelItemCount();i++) {
|
||||
all_top_level_items.append(project_model.topLevelItem(i));
|
||||
for (int i=0;i<project_model.childCount();i++) {
|
||||
all_top_level_items.append(project_model.child(i));
|
||||
}
|
||||
get_all_media_from_table(all_top_level_items, sequence_items, MEDIA_TYPE_SEQUENCE); // find all sequences in project
|
||||
if (sequence_items.size() > 0) {
|
||||
@@ -425,7 +431,7 @@ void Project::delete_selected_media() {
|
||||
}
|
||||
|
||||
for (int i=0;i<items.size();i++) {
|
||||
ca->append(new DeleteMediaCommand(selected_items.at(i)));
|
||||
ca->append(new DeleteMediaCommand(items.at(i)));
|
||||
|
||||
if (items.at(i)->get_type() == MEDIA_TYPE_SEQUENCE) {
|
||||
redraw = true;
|
||||
@@ -477,7 +483,7 @@ void Project::start_preview_generator(Media* item, bool replacing) {
|
||||
pg->start(QThread::LowPriority);
|
||||
}
|
||||
|
||||
void Project::process_file_list(bool recursive, QStringList& files, Media* parent, Media* replace) {
|
||||
void Project::process_file_list(QStringList& files, bool recursive, Media* replace, Media* parent) {
|
||||
bool imported = false;
|
||||
|
||||
QVector<QString> image_sequence_urls;
|
||||
@@ -505,12 +511,12 @@ void Project::process_file_list(bool recursive, QStringList& files, Media* paren
|
||||
subdir_filenames.append(subdir_files.at(j).filePath());
|
||||
}
|
||||
|
||||
process_file_list(true, subdir_filenames, folder, NULL);
|
||||
process_file_list(subdir_filenames, true, NULL, folder);
|
||||
|
||||
if (create_undo_action) {
|
||||
if (create_undo_action) {
|
||||
ca->append(new AddMediaCommand(folder, parent));
|
||||
} else {
|
||||
parent->appendChild(folder);
|
||||
} else {
|
||||
project_model.appendChild(parent, folder);
|
||||
}
|
||||
|
||||
imported = true;
|
||||
@@ -618,7 +624,7 @@ void Project::process_file_list(bool recursive, QStringList& files, Media* paren
|
||||
if (create_undo_action) {
|
||||
ca->append(new AddMediaCommand(item, parent));
|
||||
} else {
|
||||
parent->appendChild(item);
|
||||
project_model.appendChild(parent, item);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -639,16 +645,16 @@ Media* Project::get_selected_folder() {
|
||||
// if one item is selected and it's a folder, return it
|
||||
QModelIndexList selected_items = source_table->selectionModel()->selectedRows();
|
||||
if (selected_items.size() == 1) {
|
||||
Media* m = static_cast<Media*>(selected_items.at(0).internalPointer());
|
||||
Media* m = item_to_media(selected_items.at(0));
|
||||
if (m->get_type() == MEDIA_TYPE_FOLDER) return m;
|
||||
}
|
||||
return NULL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool Project::reveal_media(void *media, QModelIndex parent) {
|
||||
for (int i=0;i<project_model.rowCount(parent);i++) {
|
||||
const QModelIndex& item = project_model.index(i, 0, parent);
|
||||
Media* m = static_cast<Media*>(item.internalPointer());
|
||||
Media* m = project_model.getItem(item);
|
||||
|
||||
if (m->get_type() == MEDIA_TYPE_FOLDER) {
|
||||
if (reveal_media(media, item)) return true;
|
||||
@@ -676,7 +682,7 @@ void Project::import_dialog() {
|
||||
|
||||
if (fd.exec()) {
|
||||
QStringList files = fd.selectedFiles();
|
||||
process_file_list(false, files, get_selected_folder(), NULL);
|
||||
process_file_list(files, false, NULL, get_selected_folder());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -691,7 +697,7 @@ void Project::delete_clips_using_selected_media() {
|
||||
Clip* c = sequence->clips.at(i);
|
||||
if (c != NULL) {
|
||||
for (int j=0;j<items.size();j++) {
|
||||
Media* m = static_cast<Media*>(items.at(j).internalPointer());
|
||||
Media* m = item_to_media(items.at(j));
|
||||
if (c->media == m) {
|
||||
ca->append(new DeleteClipAction(sequence, i));
|
||||
deleted = true;
|
||||
@@ -700,7 +706,7 @@ void Project::delete_clips_using_selected_media() {
|
||||
}
|
||||
}
|
||||
for (int j=0;j<items.size();j++) {
|
||||
Media* m = static_cast<Media*>(items.at(j).internalPointer());
|
||||
Media* m = item_to_media(items.at(j));
|
||||
if (delete_clips_in_clipboard_with_media(ca, m)) deleted = true;
|
||||
}
|
||||
if (deleted) {
|
||||
@@ -747,7 +753,7 @@ void Project::save_folder(QXmlStreamWriter& stream, int type, bool set_ids_only,
|
||||
bool root = (!parent.parent().isValid());
|
||||
for (int i=0;i<project_model.rowCount(parent);i++) {
|
||||
const QModelIndex& item = project_model.index(i, 0, parent);
|
||||
Media* m = static_cast<Media*>(item.internalPointer());
|
||||
Media* m = project_model.getItem(item);
|
||||
|
||||
if (type == m->get_type()) {
|
||||
if (m->get_type() == MEDIA_TYPE_FOLDER) {
|
||||
@@ -762,13 +768,13 @@ void Project::save_folder(QXmlStreamWriter& stream, int type, bool set_ids_only,
|
||||
if (!item.parent().isValid()) {
|
||||
stream.writeAttribute("parent", "0");
|
||||
} else {
|
||||
stream.writeAttribute("parent", QString::number(static_cast<Media*>(item.parent().internalPointer())->temp_id));
|
||||
stream.writeAttribute("parent", QString::number(project_model.getItem(item.parent())->temp_id));
|
||||
}
|
||||
stream.writeEndElement();
|
||||
}
|
||||
// save_folder(stream, item, type, set_ids_only);
|
||||
} else {
|
||||
int folder = root ? 0 : static_cast<Media*>(parent.internalPointer())->temp_id;
|
||||
int folder = root ? 0 : project_model.getItem(parent)->temp_id;
|
||||
if (type == MEDIA_TYPE_FOOTAGE) {
|
||||
Footage* f = m->to_footage();
|
||||
f->save_id = media_id;
|
||||
@@ -995,9 +1001,8 @@ void Project::add_recent_project(QString url) {
|
||||
}
|
||||
|
||||
void Project::list_all_sequences_worker(QVector<Media*>* list, Media* parent) {
|
||||
int len = (parent == NULL) ? project_model.topLevelItemCount() : parent->childCount();
|
||||
for (int i=0;i<len;i++) {
|
||||
Media* item = (parent == NULL) ? project_model.topLevelItem(i) : parent->child(i);
|
||||
for (int i=0;i<project_model.childCount(parent);i++) {
|
||||
Media* item = project_model.child(i, parent);
|
||||
switch (item->get_type()) {
|
||||
case MEDIA_TYPE_SEQUENCE:
|
||||
list->append(item);
|
||||
@@ -1034,7 +1039,6 @@ void MediaThrobber::animation_update() {
|
||||
animation = 0;
|
||||
}
|
||||
item->set_icon(QIcon(pixmap.copy(THROBBER_SIZE*animation, 0, THROBBER_SIZE, THROBBER_SIZE)));
|
||||
project_model.update_data();
|
||||
animation++;
|
||||
}
|
||||
|
||||
|
||||
+5
-11
@@ -18,6 +18,7 @@ class Media;
|
||||
class QXmlStreamWriter;
|
||||
class QXmlStreamReader;
|
||||
class QFile;
|
||||
class QSortFilterProxyModel;
|
||||
class ComboAction;
|
||||
|
||||
#define LOAD_TYPE_VERSION 69
|
||||
@@ -34,15 +35,6 @@ extern QString recent_proj_file;
|
||||
|
||||
extern ProjectModel project_model;
|
||||
|
||||
/*int get_type_from_tree(Media *item);
|
||||
void* get_media_from_tree(QTreeWidgetItem* item);
|
||||
Footage* get_footage_from_tree(QTreeWidgetItem* item);
|
||||
void set_footage_of_tree(QTreeWidgetItem* item, Footage* media);
|
||||
Sequence* get_sequence_from_tree(QTreeWidgetItem* item);
|
||||
void set_sequence_of_tree(QTreeWidgetItem* item, Sequence* sequence);
|
||||
void set_item_to_folder(QTreeWidgetItem* item);*/
|
||||
//void update_footage_tooltip(Media* item, Footage* media, QString error = 0);
|
||||
|
||||
Sequence* create_sequence_from_media(QVector<Media *> &media_list);
|
||||
|
||||
QString get_channel_layout_name(int channels, uint64_t layout);
|
||||
@@ -59,9 +51,9 @@ public:
|
||||
void clear();
|
||||
Media* new_sequence(ComboAction *ca, Sequence* s, bool open, Media* parent);
|
||||
QString get_next_sequence_name(QString start = 0);
|
||||
void process_file_list(bool recursive, QStringList& files, Media *parent, Media* replace);
|
||||
void process_file_list(QStringList& files, bool recursive = false, Media* replace = NULL, Media *parent = NULL);
|
||||
void replace_media(Media* item, QString filename);
|
||||
Media* get_selected_folder();
|
||||
Media *get_selected_folder();
|
||||
bool reveal_media(void* media, QModelIndex parent = QModelIndex());
|
||||
void add_recent_project(QString url);
|
||||
|
||||
@@ -70,12 +62,14 @@ public:
|
||||
void save_project(bool autorecovery);
|
||||
|
||||
Media* new_folder(QString name);
|
||||
Media* item_to_media(const QModelIndex& index);
|
||||
|
||||
void save_recent_projects();
|
||||
|
||||
QVector<Media*> list_all_project_sequences();
|
||||
|
||||
SourceTable* source_table;
|
||||
QSortFilterProxyModel* sorter;
|
||||
|
||||
QVector<Media*> last_imported_media;
|
||||
|
||||
|
||||
+1
-1
@@ -345,7 +345,7 @@ void Viewer::pause() {
|
||||
// import audio
|
||||
QStringList file_list;
|
||||
file_list.append(get_recorded_audio_filename());
|
||||
panel_project->process_file_list(false, file_list, NULL, NULL);
|
||||
panel_project->process_file_list(file_list);
|
||||
|
||||
// add it to the sequence
|
||||
Clip* c = new Clip(seq);
|
||||
|
||||
+3
-12
@@ -5,6 +5,8 @@
|
||||
#include "undo.h"
|
||||
#include "io/config.h"
|
||||
#include "panels/viewer.h"
|
||||
#include "panels/project.h"
|
||||
#include "projectmodel.h"
|
||||
|
||||
#include "debug.h"
|
||||
|
||||
@@ -296,17 +298,6 @@ Media *Media::parentItem() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
Media *Media::takeChild(int i) {
|
||||
Media* ref = children.at(i);
|
||||
void Media::removeChild(int i) {
|
||||
children.removeAt(i);
|
||||
return ref;
|
||||
}
|
||||
|
||||
void Media::removeChild(Media* m) {
|
||||
for (int i=0;i<children.size();i++) {
|
||||
if (children.at(i) == m) {
|
||||
children.removeAt(i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-2
@@ -46,8 +46,7 @@ public:
|
||||
QVariant data(int column, int role);
|
||||
int row() const;
|
||||
Media *parentItem();
|
||||
Media* takeChild(int i);
|
||||
void removeChild(Media* m);
|
||||
void removeChild(int i);
|
||||
|
||||
bool root;
|
||||
int temp_id;
|
||||
|
||||
+37
-16
@@ -1,4 +1,4 @@
|
||||
#include "projectmodel.h"
|
||||
#include "projectmodel.h"
|
||||
|
||||
#include "panels/panels.h"
|
||||
#include "panels/viewer.h"
|
||||
@@ -123,29 +123,50 @@ int ProjectModel::columnCount(const QModelIndex &parent) const {
|
||||
return root_item->columnCount();
|
||||
}
|
||||
|
||||
int ProjectModel::topLevelItemCount() {
|
||||
return root_item->childCount();
|
||||
Media *ProjectModel::getItem(const QModelIndex &index) const {
|
||||
if (index.isValid()) {
|
||||
Media *item = static_cast<Media*>(index.internalPointer());
|
||||
if (item)
|
||||
return item;
|
||||
}
|
||||
return root_item;
|
||||
}
|
||||
|
||||
Media *ProjectModel::topLevelItem(int i) {
|
||||
return root_item->child(i);
|
||||
void ProjectModel::appendChild(Media *parent, Media *child) {
|
||||
if (parent == NULL) parent = root_item;
|
||||
beginInsertRows(parent == root_item ? QModelIndex() : createIndex(parent->row(), 0, parent), parent->childCount(), parent->childCount());
|
||||
parent->appendChild(child);
|
||||
endInsertRows();
|
||||
}
|
||||
|
||||
void ProjectModel::addTopLevelItem(Media *m) {
|
||||
root_item->appendChild(m);
|
||||
void ProjectModel::moveChild(Media *child, Media *to) {
|
||||
if (to == NULL) to = root_item;
|
||||
Media* from = child->parentItem();
|
||||
beginMoveRows(
|
||||
from == root_item ? QModelIndex() : createIndex(from->row(), 0, from),
|
||||
child->row(),
|
||||
child->row(),
|
||||
to == root_item ? QModelIndex() : createIndex(to->row(), 0, to),
|
||||
to->childCount()
|
||||
);
|
||||
from->removeChild(child->row());
|
||||
to->appendChild(child);
|
||||
endMoveRows();
|
||||
}
|
||||
|
||||
Media *ProjectModel::takeTopLevelItem(int i) {
|
||||
Media* ref = root_item->child(i);
|
||||
root_item->takeChild(i);
|
||||
return ref;
|
||||
void ProjectModel::removeChild(Media* parent, Media* m) {
|
||||
if (parent == NULL) parent = root_item;
|
||||
beginRemoveRows(parent == root_item ? QModelIndex() : createIndex(parent->row(), 0, parent), m->row(), m->row());
|
||||
parent->removeChild(m->row());
|
||||
endRemoveRows();
|
||||
}
|
||||
|
||||
void ProjectModel::removeTopLevelItem(Media *m) {
|
||||
root_item->removeChild(m);
|
||||
Media* ProjectModel::child(int i, Media* parent) {
|
||||
if (parent == NULL) parent = root_item;
|
||||
return parent->child(i);
|
||||
}
|
||||
|
||||
void ProjectModel::update_data() {
|
||||
// emit dataChanged();
|
||||
emit layoutChanged();
|
||||
int ProjectModel::childCount(Media *parent) {
|
||||
if (parent == NULL) parent = root_item;
|
||||
return parent->childCount();
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#ifndef PROJECTMODEL_H
|
||||
#ifndef PROJECTMODEL_H
|
||||
#define PROJECTMODEL_H
|
||||
|
||||
#include <QAbstractItemModel>
|
||||
@@ -25,12 +25,13 @@ public:
|
||||
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
int topLevelItemCount();
|
||||
Media* topLevelItem(int i);
|
||||
void addTopLevelItem(Media*);
|
||||
Media* takeTopLevelItem(int i);
|
||||
void removeTopLevelItem(Media* m);
|
||||
void update_data();
|
||||
Media *getItem(const QModelIndex &index) const;
|
||||
|
||||
void appendChild(Media* parent, Media* child);
|
||||
void moveChild(Media *child, Media *to);
|
||||
void removeChild(Media *parent, Media* m);
|
||||
Media *child(int i, Media* parent = NULL);
|
||||
int childCount(Media* parent = NULL);
|
||||
|
||||
private:
|
||||
Media* root_item;
|
||||
|
||||
+20
-62
@@ -346,40 +346,34 @@ NewSequenceCommand::NewSequenceCommand(Media *s, Media* iparent) :
|
||||
parent(iparent),
|
||||
done(false),
|
||||
old_project_changed(mainWindow->isWindowModified())
|
||||
{}
|
||||
{
|
||||
if (parent == NULL) parent = project_model.get_root();
|
||||
}
|
||||
|
||||
NewSequenceCommand::~NewSequenceCommand() {
|
||||
if (!done) delete seq;
|
||||
}
|
||||
|
||||
void NewSequenceCommand::undo() {
|
||||
if (parent == NULL) {
|
||||
project_model.removeTopLevelItem(seq);
|
||||
} else {
|
||||
parent->removeChild(seq);
|
||||
}
|
||||
project_model.removeChild(parent, seq);
|
||||
|
||||
done = false;
|
||||
mainWindow->setWindowModified(old_project_changed);
|
||||
}
|
||||
|
||||
void NewSequenceCommand::redo() {
|
||||
if (parent == NULL) {
|
||||
project_model.addTopLevelItem(seq);
|
||||
} else {
|
||||
parent->appendChild(seq);
|
||||
}
|
||||
project_model.appendChild(parent, seq);
|
||||
|
||||
done = true;
|
||||
mainWindow->setWindowModified(true);
|
||||
}
|
||||
|
||||
AddMediaCommand::AddMediaCommand(Media* iitem, Media* iparent) :
|
||||
AddMediaCommand::AddMediaCommand(Media* iitem, Media *iparent) :
|
||||
item(iitem),
|
||||
parent(iparent),
|
||||
done(false),
|
||||
old_project_changed(mainWindow->isWindowModified())
|
||||
{
|
||||
if (parent == NULL) parent = project_model.get_root();
|
||||
}
|
||||
{}
|
||||
|
||||
AddMediaCommand::~AddMediaCommand() {
|
||||
if (!done) {
|
||||
@@ -388,73 +382,40 @@ AddMediaCommand::~AddMediaCommand() {
|
||||
}
|
||||
|
||||
void AddMediaCommand::undo() {
|
||||
parent->removeChild(item);
|
||||
project_model.removeChild(parent, item);
|
||||
done = false;
|
||||
mainWindow->setWindowModified(old_project_changed);
|
||||
}
|
||||
|
||||
void AddMediaCommand::redo() {
|
||||
parent->appendChild(item);
|
||||
project_model.update_data();
|
||||
|
||||
/* Here we force the source_table to sort itself.
|
||||
*
|
||||
* For some reason, sometimes when you add items to the QTreeWidget,
|
||||
* (usually upon first import) they appear at the bottom, regardless
|
||||
* of where they should be placed alphabetically. Then when this
|
||||
* function is "undone", and it tries to remove this item from the
|
||||
* QTreeWidget, it immediately sorts and then removes THE WRONG ONE.
|
||||
* If this happens to be a sequence, the sequence data doesn't save
|
||||
* and is then lost forever (outside of autorecoveries).
|
||||
*
|
||||
* The following 2 lines seem to force the source_table to re-sort
|
||||
* correctly and therefore works around this problem. But holy shit.
|
||||
*
|
||||
* I guess I'm "supposed" to use a Model–view–viewmodel instead,
|
||||
* which I'll probably have to switch to soon anyway. So perhaps
|
||||
* this will be a non-issue soon.
|
||||
|
||||
panel_project->source_table->setSortingEnabled(false);
|
||||
panel_project->source_table->setSortingEnabled(true);*/
|
||||
project_model.appendChild(parent, item);
|
||||
|
||||
done = true;
|
||||
mainWindow->setWindowModified(true);
|
||||
}
|
||||
|
||||
DeleteMediaCommand::DeleteMediaCommand(const QModelIndex& i) :
|
||||
DeleteMediaCommand::DeleteMediaCommand(Media* i) :
|
||||
item(i),
|
||||
parent(i.parent()),
|
||||
parent(i->parentItem()),
|
||||
old_project_changed(mainWindow->isWindowModified())
|
||||
{}
|
||||
|
||||
DeleteMediaCommand::~DeleteMediaCommand() {
|
||||
if (done) {
|
||||
Media* m = static_cast<Media*>(item.internalPointer());
|
||||
delete m;
|
||||
if (done) {
|
||||
delete item;
|
||||
}
|
||||
}
|
||||
|
||||
void DeleteMediaCommand::undo() {
|
||||
Media* m = static_cast<Media*>(item.internalPointer());
|
||||
if (!parent.isValid()) {
|
||||
project_model.addTopLevelItem(m);
|
||||
} else {
|
||||
static_cast<Media*>(parent.internalPointer())->appendChild(m);
|
||||
}
|
||||
project_model.appendChild(parent, item);
|
||||
|
||||
mainWindow->setWindowModified(old_project_changed);
|
||||
done = false;
|
||||
}
|
||||
|
||||
void DeleteMediaCommand::redo() {
|
||||
Media* m = static_cast<Media*>(item.internalPointer());
|
||||
if (!parent.isValid()) {
|
||||
project_model.removeTopLevelItem(m);
|
||||
} else {
|
||||
static_cast<Media*>(parent.internalPointer())->removeChild(m);
|
||||
}
|
||||
project_model.removeChild(parent, item);
|
||||
|
||||
project_model.update_data();
|
||||
mainWindow->setWindowModified(true);
|
||||
done = true;
|
||||
}
|
||||
@@ -622,7 +583,7 @@ void ReplaceMediaCommand::replace(QString& filename) {
|
||||
// replace media
|
||||
QStringList files;
|
||||
files.append(filename);
|
||||
panel_project->process_file_list(false, files, NULL, item);
|
||||
panel_project->process_file_list(files, false, item, NULL);
|
||||
}
|
||||
|
||||
void ReplaceMediaCommand::undo() {
|
||||
@@ -728,8 +689,7 @@ MediaMove::MediaMove(SourceTable *s) : table(s), old_project_changed(mainWindow-
|
||||
|
||||
void MediaMove::undo() {
|
||||
for (int i=0;i<items.size();i++) {
|
||||
to->removeChild(items.at(i));
|
||||
froms.at(i)->appendChild(items.at(i));
|
||||
project_model.moveChild(items.at(i), froms.at(i));
|
||||
}
|
||||
mainWindow->setWindowModified(old_project_changed);
|
||||
}
|
||||
@@ -740,10 +700,8 @@ void MediaMove::redo() {
|
||||
for (int i=0;i<items.size();i++) {
|
||||
Media* parent = items.at(i)->parentItem();
|
||||
froms[i] = parent;
|
||||
parent->removeChild(items.at(i));
|
||||
to->appendChild(items.at(i));
|
||||
project_model.moveChild(items.at(i), to);
|
||||
}
|
||||
project_model.update_data();
|
||||
mainWindow->setWindowModified(true);
|
||||
}
|
||||
|
||||
|
||||
+4
-3
@@ -22,6 +22,7 @@ struct EffectMeta;
|
||||
#include <QUndoCommand>
|
||||
#include <QVector>
|
||||
#include <QVariant>
|
||||
#include <QModelIndex>
|
||||
|
||||
extern QUndoStack undo_stack;
|
||||
|
||||
@@ -192,13 +193,13 @@ private:
|
||||
|
||||
class DeleteMediaCommand : public QUndoCommand {
|
||||
public:
|
||||
DeleteMediaCommand(const QModelIndex& i);
|
||||
DeleteMediaCommand(Media *i);
|
||||
~DeleteMediaCommand();
|
||||
void undo();
|
||||
void redo();
|
||||
private:
|
||||
const QModelIndex& item;
|
||||
const QModelIndex& parent;
|
||||
Media* item;
|
||||
Media* parent;
|
||||
bool old_project_changed;
|
||||
bool done;
|
||||
};
|
||||
|
||||
+19
-19
@@ -32,7 +32,6 @@ SourceTable::SourceTable(QWidget* parent) : QTreeView(parent) {
|
||||
setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
connect(&rename_timer, SIGNAL(timeout()), this, SLOT(rename_interval()));
|
||||
connect(this, SIGNAL(clicked(const QModelIndex&)), this, SLOT(item_click(const QModelIndex&)));
|
||||
//connect(this, SIGNAL(itemChanged(Media*,int)), this, SLOT(item_renamed(Media*)));
|
||||
connect(this, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(show_context_menu()));
|
||||
}
|
||||
|
||||
@@ -40,7 +39,7 @@ void SourceTable::show_context_menu() {
|
||||
QMenu menu(this);
|
||||
|
||||
QAction* import_action = menu.addAction("Import...");
|
||||
connect(import_action, SIGNAL(triggered(bool)), panel_project, SLOT(import_dialog()));
|
||||
connect(import_action, SIGNAL(triggered(bool)), project_parent, SLOT(import_dialog()));
|
||||
|
||||
QAction* new_folder_action = menu.addAction("New Folder...");
|
||||
connect(new_folder_action, SIGNAL(triggered(bool)), mainWindow, SLOT(on_actionFolder_triggered()));
|
||||
@@ -48,14 +47,14 @@ void SourceTable::show_context_menu() {
|
||||
QModelIndexList selected_items = selectionModel()->selectedRows();
|
||||
|
||||
if (selected_items.size() > 0) {
|
||||
Media* m = static_cast<Media*>(selected_items.at(0).internalPointer());
|
||||
Media* m = project_parent->item_to_media(selected_items.at(0));
|
||||
|
||||
if (selected_items.size() == 1) {
|
||||
// replace footage
|
||||
int type = m->get_type();
|
||||
if (type == MEDIA_TYPE_FOOTAGE) {
|
||||
QAction* replace_action = menu.addAction("Replace/Relink Media");
|
||||
connect(replace_action, SIGNAL(triggered(bool)), panel_project, SLOT(replace_selected_file()));
|
||||
connect(replace_action, SIGNAL(triggered(bool)), project_parent, SLOT(replace_selected_file()));
|
||||
|
||||
#if defined(Q_OS_WIN)
|
||||
QAction* reveal_in_explorer = menu.addAction("Reveal in Explorer");
|
||||
@@ -68,7 +67,7 @@ void SourceTable::show_context_menu() {
|
||||
}
|
||||
if (type != MEDIA_TYPE_FOLDER) {
|
||||
QAction* replace_clip_media = menu.addAction("Replace Clips Using This Media");
|
||||
connect(replace_clip_media, SIGNAL(triggered(bool)), panel_project, SLOT(replace_clip_media()));
|
||||
connect(replace_clip_media, SIGNAL(triggered(bool)), project_parent, SLOT(replace_clip_media()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,22 +91,22 @@ void SourceTable::show_context_menu() {
|
||||
if (all_sequences) {
|
||||
// ONLY sequences are selected
|
||||
QAction* duplicate_action = menu.addAction("Duplicate");
|
||||
connect(duplicate_action, SIGNAL(triggered(bool)), panel_project, SLOT(duplicate_selected()));
|
||||
connect(duplicate_action, SIGNAL(triggered(bool)), project_parent, SLOT(duplicate_selected()));
|
||||
}
|
||||
|
||||
// ONLY footage is selected
|
||||
if (all_footage) {
|
||||
QAction* delete_footage_from_sequences = menu.addAction("Delete All Clips Using This Media");
|
||||
connect(delete_footage_from_sequences, SIGNAL(triggered(bool)), panel_project, SLOT(delete_clips_using_selected_media()));
|
||||
connect(delete_footage_from_sequences, SIGNAL(triggered(bool)), project_parent, SLOT(delete_clips_using_selected_media()));
|
||||
}
|
||||
|
||||
// delete media
|
||||
QAction* delete_action = menu.addAction("Delete");
|
||||
connect(delete_action, SIGNAL(triggered(bool)), panel_project, SLOT(delete_selected_media()));
|
||||
connect(delete_action, SIGNAL(triggered(bool)), project_parent, SLOT(delete_selected_media()));
|
||||
|
||||
if (selected_items.size() == 1) {
|
||||
QAction* properties_action = menu.addAction("Properties...");
|
||||
connect(properties_action, SIGNAL(triggered(bool)), panel_project, SLOT(open_properties()));
|
||||
connect(properties_action, SIGNAL(triggered(bool)), project_parent, SLOT(open_properties()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,7 +119,7 @@ void SourceTable::create_seq_from_selected() {
|
||||
if (!selected_items.isEmpty()) {
|
||||
QVector<Media*> media_list;
|
||||
for (int i=0;i<selected_items.size();i++) {
|
||||
media_list.append(static_cast<Media*>(selected_items.at(i).internalPointer()));
|
||||
media_list.append(project_parent->item_to_media(selected_items.at(i)));
|
||||
}
|
||||
|
||||
ComboAction* ca = new ComboAction();
|
||||
@@ -130,14 +129,15 @@ void SourceTable::create_seq_from_selected() {
|
||||
panel_timeline->create_ghosts_from_media(s, 0, media_list);
|
||||
panel_timeline->add_clips_from_ghosts(ca, s);
|
||||
|
||||
panel_project->new_sequence(ca, s, true, NULL);
|
||||
project_parent->new_sequence(ca, s, true, NULL);
|
||||
undo_stack.push(ca);
|
||||
}
|
||||
}
|
||||
|
||||
void SourceTable::reveal_in_browser() {
|
||||
QModelIndexList selected_items = selectionModel()->selectedRows();
|
||||
Footage* m = static_cast<Footage*>(selected_items.at(0).internalPointer());
|
||||
Media* media = project_parent->item_to_media(selected_items.at(0));
|
||||
Footage* m = media->to_footage();
|
||||
|
||||
#if defined(Q_OS_WIN)
|
||||
QStringList args;
|
||||
@@ -180,7 +180,7 @@ void SourceTable::rename_interval() {
|
||||
}
|
||||
void SourceTable::item_click(const QModelIndex& index) {
|
||||
if (selectionModel()->selectedRows().size() == 1 && index.column() == 0) {
|
||||
Media* m = static_cast<Media*>(index.internalPointer());
|
||||
Media* m = project_parent->item_to_media(index);
|
||||
if (editing_item == m) {
|
||||
rename_timer.start();
|
||||
} else {
|
||||
@@ -199,9 +199,9 @@ void SourceTable::mouseDoubleClickEvent(QMouseEvent* e) {
|
||||
stop_rename_timer();
|
||||
QModelIndexList selected_items = selectionModel()->selectedRows();
|
||||
if (selected_items.size() == 0) {
|
||||
panel_project->import_dialog();
|
||||
project_parent->import_dialog();
|
||||
} else if (selected_items.size() == 1) {
|
||||
Media* item = static_cast<Media*>(selected_items.at(0).internalPointer());
|
||||
Media* item = project_parent->item_to_media(selected_items.at(0));
|
||||
switch (item->get_type()) {
|
||||
case MEDIA_TYPE_FOOTAGE:
|
||||
panel_footage_viewer->set_media(item);
|
||||
@@ -233,7 +233,7 @@ void SourceTable::dragMoveEvent(QDragMoveEvent *event) {
|
||||
void SourceTable::dropEvent(QDropEvent* event) {
|
||||
const QMimeData* mimeData = event->mimeData();
|
||||
const QModelIndex& drop_item = indexAt(event->pos());
|
||||
Media* m = static_cast<Media*>(drop_item.internalPointer());
|
||||
Media* m = project_parent->item_to_media(drop_item);
|
||||
if (mimeData->hasUrls()) {
|
||||
// drag files in from outside
|
||||
QList<QUrl> urls = mimeData->urls();
|
||||
@@ -250,7 +250,7 @@ void SourceTable::dropEvent(QDropEvent* event) {
|
||||
&& config.drop_on_media_to_replace
|
||||
&& QMessageBox::question(this, "Replace Media", "You dropped a file onto '" + m->get_name() + "'. Would you like to replace it with the dropped file?", QMessageBox::Yes | QMessageBox::No, QMessageBox::No) == QMessageBox::Yes) {
|
||||
replace = true;
|
||||
panel_project->replace_media(m, paths.at(0));
|
||||
project_parent->replace_media(m, paths.at(0));
|
||||
}
|
||||
if (!replace) {
|
||||
QModelIndex parent;
|
||||
@@ -262,7 +262,7 @@ void SourceTable::dropEvent(QDropEvent* event) {
|
||||
}
|
||||
}
|
||||
if (parent.isValid()) setExpanded(parent, true);
|
||||
panel_project->process_file_list(false, paths, static_cast<Media*>(parent.internalPointer()), NULL);
|
||||
project_parent->process_file_list(paths, false, NULL, panel_project->item_to_media(parent));
|
||||
}
|
||||
}
|
||||
event->acceptProposedAction();
|
||||
@@ -277,7 +277,7 @@ void SourceTable::dropEvent(QDropEvent* event) {
|
||||
for (int i=0;i<selected_items.size();i++) {
|
||||
const QModelIndex& item = selected_items.at(i);
|
||||
const QModelIndex& parent = item.parent();
|
||||
Media* s = static_cast<Media*>(item.internalPointer());
|
||||
Media* s = project_parent->item_to_media(item);
|
||||
if (parent != drop_item && item != drop_item) {
|
||||
bool ignore = false;
|
||||
if (parent.isValid()) {
|
||||
|
||||
@@ -13,6 +13,7 @@ class SourceTable : public QTreeView
|
||||
Q_OBJECT
|
||||
public:
|
||||
SourceTable(QWidget* parent = 0);
|
||||
Project* project_parent;
|
||||
protected:
|
||||
void mousePressEvent(QMouseEvent*);
|
||||
void mouseDoubleClickEvent(QMouseEvent *event);
|
||||
|
||||
+13
-8
@@ -246,7 +246,7 @@ void TimelineWidget::dragEnterEvent(QDragEnterEvent *event) {
|
||||
QModelIndexList items = panel_project->source_table->selectionModel()->selectedRows();
|
||||
media_list.resize(items.size());
|
||||
for (int i=0;i<items.size();i++) {
|
||||
media_list[i] = static_cast<Media*>(items.at(i).internalPointer());
|
||||
media_list[i] = panel_project->item_to_media(items.at(i));
|
||||
}
|
||||
import_init = true;
|
||||
}
|
||||
@@ -268,7 +268,7 @@ void TimelineWidget::dragEnterEvent(QDragEnterEvent *event) {
|
||||
file_list.append(urls.at(i).toLocalFile());
|
||||
}
|
||||
|
||||
panel_project->process_file_list(false, file_list, NULL, NULL);
|
||||
panel_project->process_file_list(file_list);
|
||||
|
||||
for (int i=0;i<panel_project->last_imported_media.size();i++) {
|
||||
// waits for media to have a duration
|
||||
@@ -316,12 +316,15 @@ void TimelineWidget::dragEnterEvent(QDragEnterEvent *event) {
|
||||
}
|
||||
|
||||
void TimelineWidget::dragMoveEvent(QDragMoveEvent *event) {
|
||||
if (sequence != NULL && panel_timeline->importing) {
|
||||
if (panel_timeline->importing) {
|
||||
event->acceptProposedAction();
|
||||
QPoint pos = event->pos();
|
||||
update_ghosts(pos, event->keyboardModifiers() & Qt::ShiftModifier);
|
||||
panel_timeline->move_insert = ((event->keyboardModifiers() & Qt::ControlModifier) && (panel_timeline->tool == TIMELINE_TOOL_POINTER || panel_timeline->importing));
|
||||
update_ui(false);
|
||||
|
||||
if (sequence != NULL) {
|
||||
QPoint pos = event->pos();
|
||||
update_ghosts(pos, event->keyboardModifiers() & Qt::ShiftModifier);
|
||||
panel_timeline->move_insert = ((event->keyboardModifiers() & Qt::ControlModifier) && (panel_timeline->tool == TIMELINE_TOOL_POINTER || panel_timeline->importing));
|
||||
update_ui(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -343,7 +346,8 @@ void TimelineWidget::wheelEvent(QWheelEvent *event) {
|
||||
}
|
||||
}
|
||||
|
||||
void TimelineWidget::dragLeaveEvent(QDragLeaveEvent*) {
|
||||
void TimelineWidget::dragLeaveEvent(QDragLeaveEvent* event) {
|
||||
event->accept();
|
||||
if (panel_timeline->importing) {
|
||||
if (panel_timeline->importing_files) {
|
||||
undo_stack.undo();
|
||||
@@ -355,6 +359,7 @@ void TimelineWidget::dragLeaveEvent(QDragLeaveEvent*) {
|
||||
}
|
||||
if (self_created_sequence != NULL) {
|
||||
delete self_created_sequence;
|
||||
self_created_sequence = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user