chore: recovery backups, temp files and misc campaign artifacts
.bak LocalHistory recovery backups, .tmp0/.tmp1, .gitignore update, reasonix.toml, convert_videoparams.py. Kept as-is from the campaign branch; cleanup can happen separately on main.
This commit is contained in:
@@ -0,0 +1,947 @@
|
||||
/***
|
||||
|
||||
Olive - Non-Linear Video Editor
|
||||
Copyright (C) 2022 Olive Team
|
||||
Modifications Copyright (C) 2025 mikesolar
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
***/
|
||||
|
||||
#include "projectexplorer.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QDesktopServices>
|
||||
#include <QDir>
|
||||
#include <QFileDialog>
|
||||
#include <QMessageBox>
|
||||
#include <QProcess>
|
||||
#include <QUrl>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include "common/define.h"
|
||||
#include "core.h"
|
||||
#include "dialog/footageproperties/footageproperties.h"
|
||||
#include "dialog/proxy/proxydialog.h"
|
||||
#include "dialog/sequence/sequence.h"
|
||||
#include "projectexplorerundo.h"
|
||||
#include "oakengine/footage.h"
|
||||
#include "oakengine/node.h"
|
||||
#include "oakengine/task.h"
|
||||
#include "widget/menu/menu.h"
|
||||
#include "widget/menu/menushared.h"
|
||||
#include "node/nodeundo.h"
|
||||
#include "window/mainwindow/mainwindow.h"
|
||||
#include "window/mainwindow/mainwindowundo.h"
|
||||
#include "widget/timelinewidget/timelinewidget.h"
|
||||
|
||||
namespace olive
|
||||
{
|
||||
|
||||
namespace
|
||||
{
|
||||
QVector<Footage *> get_selected_proxy_footage(const QVector<Node *> &items)
|
||||
{
|
||||
QVector<Footage *> footage;
|
||||
for (Node *node : items) {
|
||||
Footage *candidate = dynamic_cast<Footage *>(node);
|
||||
if (!candidate || !candidate->get_first_enabled_video_stream().is_valid() ||
|
||||
footage.contains(candidate)) {
|
||||
continue;
|
||||
}
|
||||
footage.append(candidate);
|
||||
}
|
||||
return footage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Proxy generation driven by the liboakengine C ABI facade
|
||||
*
|
||||
* Replaces the direct ProxyManager::get_or_start_proxy() drive: the actual
|
||||
* transcode and its synchronous wait live behind
|
||||
* oakengine_footage_proxy_generate() (which also records the proxy state
|
||||
* on the footage and invalidates it), while the task stays on the
|
||||
* TaskManager queue like before.
|
||||
*/
|
||||
class FacadeProxyTask : public Task {
|
||||
public:
|
||||
FacadeProxyTask(Footage *footage)
|
||||
: footage_(footage)
|
||||
{
|
||||
set_title(tr("Generating proxy for \"%1\"")
|
||||
.arg(footage->get_label_or_name()));
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual bool run() override
|
||||
{
|
||||
OakEngineFootage *handle = oakengine_footage_borrow(
|
||||
reinterpret_cast<OakEngineNode *>(footage_));
|
||||
const int rc = oakengine_footage_proxy_generate(handle);
|
||||
oakengine_footage_free(handle);
|
||||
if (rc != OAKENGINE_OK) {
|
||||
char err[512];
|
||||
err[0] = '\0';
|
||||
oakengine_footage_last_error(err, sizeof(err));
|
||||
set_error(err[0] ? QString::fromUtf8(err) :
|
||||
tr("Proxy generation failed"));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
Footage *footage_;
|
||||
};
|
||||
}
|
||||
|
||||
ProjectExplorer::ProjectExplorer(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, model_(this)
|
||||
{
|
||||
// Create layout
|
||||
QVBoxLayout *layout = new QVBoxLayout(this);
|
||||
layout->setSpacing(0);
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
|
||||
// Set up navigation bar
|
||||
nav_bar_ = new ProjectExplorerNavigation(this);
|
||||
connect(nav_bar_, &ProjectExplorerNavigation::size_changed, this,
|
||||
&ProjectExplorer::size_changed_slot);
|
||||
connect(nav_bar_, &ProjectExplorerNavigation::directory_up_clicked, this,
|
||||
&ProjectExplorer::dir_up_slot);
|
||||
layout->addWidget(nav_bar_);
|
||||
|
||||
// Set up stacked widget
|
||||
stacked_widget_ = new QStackedWidget(this);
|
||||
layout->addWidget(stacked_widget_);
|
||||
|
||||
// Set up sort filter proxy model
|
||||
sort_model_.setSourceModel(&model_);
|
||||
sort_model_.setFilterCaseSensitivity(Qt::CaseInsensitive);
|
||||
sort_model_.setSortRole(ProjectViewModel::k_inner_text_role);
|
||||
|
||||
// Add tree view to stacked widget
|
||||
tree_view_ = new ProjectExplorerTreeView(stacked_widget_);
|
||||
tree_view_->setSortingEnabled(true);
|
||||
tree_view_->sortByColumn(0, Qt::AscendingOrder);
|
||||
tree_view_->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
add_view(tree_view_);
|
||||
|
||||
// Add list view to stacked widget
|
||||
list_view_ = new ProjectExplorerListView(stacked_widget_);
|
||||
list_view_->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
add_view(list_view_);
|
||||
|
||||
// Add icon view to stacked widget
|
||||
icon_view_ = new ProjectExplorerIconView(stacked_widget_);
|
||||
icon_view_->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
add_view(icon_view_);
|
||||
|
||||
// Set default view to tree view
|
||||
set_view_type(ProjectToolbar::tree_view);
|
||||
|
||||
// Set default icon size
|
||||
size_changed_slot(k_project_icon_size_default);
|
||||
|
||||
connect(tree_view_, &ProjectExplorerTreeView::customContextMenuRequested,
|
||||
this, &ProjectExplorer::show_context_menu);
|
||||
connect(list_view_, &ProjectExplorerListView::customContextMenuRequested,
|
||||
this, &ProjectExplorer::show_context_menu);
|
||||
connect(icon_view_, &ProjectExplorerIconView::customContextMenuRequested,
|
||||
this, &ProjectExplorer::show_context_menu);
|
||||
|
||||
update_nav_bar_text();
|
||||
}
|
||||
|
||||
const ProjectToolbar::ViewType &ProjectExplorer::view_type() const
|
||||
{
|
||||
return view_type_;
|
||||
}
|
||||
|
||||
void ProjectExplorer::set_view_type(ProjectToolbar::ViewType type)
|
||||
{
|
||||
view_type_ = type;
|
||||
|
||||
// Set widget based on view type
|
||||
switch (view_type_) {
|
||||
case ProjectToolbar::tree_view:
|
||||
stacked_widget_->setCurrentWidget(tree_view_);
|
||||
nav_bar_->setVisible(false);
|
||||
break;
|
||||
case ProjectToolbar::list_view:
|
||||
stacked_widget_->setCurrentWidget(list_view_);
|
||||
nav_bar_->setVisible(true);
|
||||
break;
|
||||
case ProjectToolbar::icon_view:
|
||||
stacked_widget_->setCurrentWidget(icon_view_);
|
||||
nav_bar_->setVisible(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void ProjectExplorer::edit(Node *item)
|
||||
{
|
||||
current_view()->edit(
|
||||
sort_model_.mapFromSource(model_.create_index_from_item(item)));
|
||||
}
|
||||
|
||||
void ProjectExplorer::add_view(QAbstractItemView *view)
|
||||
{
|
||||
view->setModel(&sort_model_);
|
||||
view->setEditTriggers(QAbstractItemView::SelectedClicked);
|
||||
connect(view, &QAbstractItemView::doubleClicked, this,
|
||||
&ProjectExplorer::item_double_clicked_slot);
|
||||
connect(view->selectionModel(), &QItemSelectionModel::selectionChanged,
|
||||
this, &ProjectExplorer::view_selection_changed);
|
||||
connect(view, SIGNAL(double_clicked_empty_area()), this,
|
||||
SLOT(view_empty_area_double_clicked_slot()));
|
||||
stacked_widget_->addWidget(view);
|
||||
}
|
||||
|
||||
void ProjectExplorer::browse_to_folder(const QModelIndex &index)
|
||||
{
|
||||
// Set appropriate views to this index
|
||||
icon_view_->setRootIndex(index);
|
||||
list_view_->setRootIndex(index);
|
||||
|
||||
// Set navbar text to folder's name
|
||||
update_nav_bar_text();
|
||||
|
||||
// Set directory up enabled button based on whether we're in root or not
|
||||
nav_bar_->set_dir_up_enabled(index.isValid());
|
||||
}
|
||||
|
||||
int ProjectExplorer::confirm_item_deletion(Node *item)
|
||||
{
|
||||
QMessageBox msgbox(this);
|
||||
msgbox.setWindowTitle(tr("Confirm Item Deletion"));
|
||||
msgbox.setIcon(QMessageBox::Warning);
|
||||
|
||||
QStringList connected_nodes_names;
|
||||
foreach (const Node::OutputConnection &connected,
|
||||
item->output_connections()) {
|
||||
if (!dynamic_cast<Folder *>(connected.second.node())) {
|
||||
connected_nodes_names.append(
|
||||
get_human_readable_node_name(connected.second.node()));
|
||||
}
|
||||
}
|
||||
|
||||
msgbox.setText(
|
||||
tr("The item \"%1\" is currently connected to the following nodes:\n\n"
|
||||
"%2\n\n"
|
||||
"Are you sure you wish to delete this footage?")
|
||||
.arg(get_human_readable_node_name(item),
|
||||
connected_nodes_names.join('\n')));
|
||||
|
||||
// Set up buttons
|
||||
msgbox.addButton(QMessageBox::Yes);
|
||||
msgbox.addButton(QMessageBox::YesToAll);
|
||||
msgbox.addButton(QMessageBox::No);
|
||||
msgbox.addButton(QMessageBox::Cancel);
|
||||
|
||||
// Run messagebox
|
||||
return msgbox.exec();
|
||||
}
|
||||
|
||||
bool ProjectExplorer::delete_items_internal(const QVector<Node *> &selected,
|
||||
bool &check_if_item_is_in_use,
|
||||
MultiUndoCommand *command)
|
||||
{
|
||||
for (int i = 0; i < selected.size(); i++) {
|
||||
// Delete sequences first
|
||||
Node *node = selected.at(i);
|
||||
|
||||
bool can_delete_item = true;
|
||||
|
||||
if (check_if_item_is_in_use) {
|
||||
foreach (const Node::OutputConnection &oc,
|
||||
node->output_connections()) {
|
||||
Folder *folder_test = dynamic_cast<Folder *>(oc.second.node());
|
||||
if (!folder_test) {
|
||||
// This sequence outputs to SOMETHING, confirm the user if they want to delete this
|
||||
int r = confirm_item_deletion(node);
|
||||
|
||||
switch (r) {
|
||||
case QMessageBox::No:
|
||||
can_delete_item = false;
|
||||
break;
|
||||
case QMessageBox::Cancel:
|
||||
return false;
|
||||
case QMessageBox::YesToAll:
|
||||
check_if_item_is_in_use = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (can_delete_item) {
|
||||
Sequence *sequence = dynamic_cast<Sequence *>(node);
|
||||
if (sequence &&
|
||||
Core::instance()->main_window()->is_sequence_open(sequence)) {
|
||||
command->add_child(new CloseSequenceCommand(sequence));
|
||||
}
|
||||
|
||||
if (node->folder()) {
|
||||
command->add_child(
|
||||
new Folder::RemoveElementCommand(node->folder(), node));
|
||||
}
|
||||
|
||||
command->add_child(
|
||||
new NodeRemoveWithExclusiveDependenciesAndDisconnect(node));
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
QString ProjectExplorer::get_human_readable_node_name(Node *node)
|
||||
{
|
||||
if (node->get_label().isEmpty()) {
|
||||
return node->name();
|
||||
} else {
|
||||
return tr("%1 (%2)").arg(node->get_label(), node->name());
|
||||
}
|
||||
}
|
||||
|
||||
void ProjectExplorer::update_nav_bar_text()
|
||||
{
|
||||
QString absolute;
|
||||
|
||||
Folder *f = static_cast<Folder *>(
|
||||
sort_model_.mapToSource(list_view_->rootIndex()).internalPointer());
|
||||
while (f && f != project()->root()) {
|
||||
absolute.prepend(QStringLiteral("%1 / ").arg(f->get_label()));
|
||||
f = f->folder();
|
||||
}
|
||||
|
||||
absolute.prepend(QStringLiteral("/ "));
|
||||
|
||||
nav_bar_->set_text(absolute);
|
||||
}
|
||||
|
||||
QAbstractItemView *ProjectExplorer::current_view() const
|
||||
{
|
||||
return static_cast<QAbstractItemView *>(stacked_widget_->currentWidget());
|
||||
}
|
||||
|
||||
void ProjectExplorer::view_empty_area_double_clicked_slot()
|
||||
{
|
||||
emit double_clicked_item(nullptr);
|
||||
}
|
||||
|
||||
void ProjectExplorer::item_double_clicked_slot(const QModelIndex &index)
|
||||
{
|
||||
// Retrieve source item from index
|
||||
Node *i =
|
||||
static_cast<Node *>(sort_model_.mapToSource(index).internalPointer());
|
||||
|
||||
// If the item is a folder, browse to it
|
||||
if (dynamic_cast<Folder *>(i) &&
|
||||
(view_type() == ProjectToolbar::list_view ||
|
||||
view_type() == ProjectToolbar::icon_view)) {
|
||||
browse_to_folder(index);
|
||||
}
|
||||
|
||||
// Emit a signal
|
||||
emit double_clicked_item(i);
|
||||
}
|
||||
|
||||
void ProjectExplorer::size_changed_slot(int s)
|
||||
{
|
||||
icon_view_->setGridSize(QSize(s, s));
|
||||
|
||||
list_view_->setIconSize(QSize(s, s));
|
||||
}
|
||||
|
||||
void ProjectExplorer::dir_up_slot()
|
||||
{
|
||||
QModelIndex current_root = icon_view_->rootIndex();
|
||||
|
||||
if (current_root.isValid()) {
|
||||
QModelIndex parent = current_root.parent();
|
||||
|
||||
browse_to_folder(parent);
|
||||
}
|
||||
}
|
||||
|
||||
void ProjectExplorer::rename_selected_item()
|
||||
{
|
||||
auto indexes = current_view()->selectionModel()->selectedRows();
|
||||
if (!indexes.empty()) {
|
||||
current_view()->edit(indexes.first());
|
||||
}
|
||||
}
|
||||
|
||||
void ProjectExplorer::set_search_filter(const QString &s)
|
||||
{
|
||||
sort_model_.setFilterFixedString(s);
|
||||
}
|
||||
|
||||
void ProjectExplorer::show_context_menu()
|
||||
{
|
||||
Menu menu;
|
||||
Menu new_menu;
|
||||
|
||||
context_menu_items_ = selected_items();
|
||||
|
||||
if (context_menu_items_.isEmpty()) {
|
||||
// Items to show if no items are selected
|
||||
|
||||
// "New" menu
|
||||
new_menu.setTitle(tr("&New"));
|
||||
MenuShared::instance()->add_items_for_new_menu(&new_menu);
|
||||
menu.addMenu(&new_menu);
|
||||
|
||||
// "Import" action
|
||||
QAction *import_action = menu.addAction(tr("&Import..."));
|
||||
connect(import_action, &QAction::triggered, Core::instance(),
|
||||
&Core::dialog_import_show);
|
||||
} else {
|
||||
// Actions to add when only one item is selected
|
||||
if (context_menu_items_.size() == 1) {
|
||||
Node *context_menu_item = context_menu_items_.first();
|
||||
|
||||
if (dynamic_cast<Folder *>(context_menu_item)) {
|
||||
QAction *open_in_new_tab =
|
||||
menu.addAction(tr("Open in New Tab"));
|
||||
connect(open_in_new_tab, &QAction::triggered, this,
|
||||
&ProjectExplorer::open_context_menu_item_in_new_tab);
|
||||
|
||||
QAction *open_in_new_window =
|
||||
menu.addAction(tr("Open in New Window"));
|
||||
connect(open_in_new_window, &QAction::triggered, this,
|
||||
&ProjectExplorer::open_context_menu_item_in_new_window);
|
||||
|
||||
} else if (dynamic_cast<Footage *>(context_menu_item)) {
|
||||
QString reveal_text;
|
||||
|
||||
#if defined(Q_OS_WINDOWS)
|
||||
reveal_text = tr("Reveal in Explorer");
|
||||
#elif defined(Q_OS_MAC)
|
||||
reveal_text = tr("Reveal in Finder");
|
||||
#else
|
||||
reveal_text = tr("Reveal in File Manager");
|
||||
#endif
|
||||
|
||||
QAction *reveal_action = menu.addAction(reveal_text);
|
||||
connect(reveal_action, &QAction::triggered, this,
|
||||
&ProjectExplorer::reveal_selected_footage);
|
||||
|
||||
QAction *replace_action = menu.addAction(tr("Replace Footage"));
|
||||
connect(replace_action, &QAction::triggered, this,
|
||||
&ProjectExplorer::replace_selected_footage);
|
||||
}
|
||||
|
||||
menu.addSeparator();
|
||||
}
|
||||
|
||||
bool all_items_are_footage = true;
|
||||
bool all_items_have_video_streams = true;
|
||||
bool all_items_are_footage_or_sequence = true;
|
||||
|
||||
foreach (Node *i, context_menu_items_) {
|
||||
Footage *footage_cast_test = dynamic_cast<Footage *>(i);
|
||||
Sequence *sequence_cast_test = dynamic_cast<Sequence *>(i);
|
||||
|
||||
if (footage_cast_test &&
|
||||
!footage_cast_test->has_enabled_video_streams()) {
|
||||
all_items_have_video_streams = false;
|
||||
}
|
||||
|
||||
if (!footage_cast_test) {
|
||||
all_items_are_footage = false;
|
||||
}
|
||||
|
||||
if (!footage_cast_test && !sequence_cast_test) {
|
||||
all_items_are_footage_or_sequence = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (all_items_are_footage && all_items_have_video_streams) {
|
||||
const QVector<Footage *> proxy_footage =
|
||||
get_selected_proxy_footage(context_menu_items_);
|
||||
|
||||
Menu *proxy_menu = new Menu(tr("Proxy"), &menu);
|
||||
menu.addMenu(proxy_menu);
|
||||
|
||||
QAction *generate_proxy =
|
||||
proxy_menu->addAction(tr("Generate Proxy"));
|
||||
generate_proxy->setEnabled(!proxy_footage.isEmpty());
|
||||
connect(generate_proxy, &QAction::triggered, this,
|
||||
&ProjectExplorer::generate_proxies_for_selected_footage);
|
||||
|
||||
QAction *use_proxy = proxy_menu->addAction(tr("Use Proxy"));
|
||||
use_proxy->setCheckable(true);
|
||||
use_proxy->setEnabled(!proxy_footage.isEmpty());
|
||||
use_proxy->setChecked(
|
||||
!proxy_footage.isEmpty() &&
|
||||
std::all_of(proxy_footage.cbegin(), proxy_footage.cend(),
|
||||
[](const Footage *footage) {
|
||||
return footage->proxy_enabled();
|
||||
}));
|
||||
connect(use_proxy, &QAction::triggered, this,
|
||||
&ProjectExplorer::set_selected_footage_proxy_enabled);
|
||||
|
||||
QAction *reveal_proxy = proxy_menu->addAction(tr("Reveal Proxy"));
|
||||
reveal_proxy->setEnabled(
|
||||
std::any_of(proxy_footage.cbegin(), proxy_footage.cend(),
|
||||
[](const Footage *footage) {
|
||||
return !footage->proxy_path().isEmpty();
|
||||
}));
|
||||
connect(reveal_proxy, &QAction::triggered, this,
|
||||
&ProjectExplorer::reveal_proxy_for_selected_footage);
|
||||
|
||||
QAction *delete_proxy = proxy_menu->addAction(tr("Delete Proxy"));
|
||||
delete_proxy->setEnabled(
|
||||
std::any_of(proxy_footage.cbegin(), proxy_footage.cend(),
|
||||
[](const Footage *footage) {
|
||||
return !footage->proxy_path().isEmpty();
|
||||
}));
|
||||
connect(delete_proxy, &QAction::triggered, this,
|
||||
&ProjectExplorer::delete_proxies_for_selected_footage);
|
||||
|
||||
QAction *proxy_settings =
|
||||
proxy_menu->addAction(tr("Proxy Settings..."));
|
||||
connect(proxy_settings, &QAction::triggered, this,
|
||||
&ProjectExplorer::show_proxy_dialog_for_selected_footage);
|
||||
}
|
||||
|
||||
Q_UNUSED(all_items_are_footage_or_sequence)
|
||||
|
||||
if (context_menu_items_.size() == 1) {
|
||||
menu.addSeparator();
|
||||
|
||||
auto rename_action = menu.addAction(tr("Rename"));
|
||||
connect(rename_action, &QAction::triggered, this,
|
||||
&ProjectExplorer::rename_selected_item);
|
||||
}
|
||||
|
||||
auto delete_action = menu.addAction(tr("Delete"));
|
||||
connect(delete_action, &QAction::triggered, this,
|
||||
&ProjectExplorer::delete_selected);
|
||||
|
||||
if (context_menu_items_.size() == 1) {
|
||||
menu.addSeparator();
|
||||
|
||||
QAction *properties_action = menu.addAction(tr("P&roperties"));
|
||||
connect(properties_action, &QAction::triggered, this,
|
||||
&ProjectExplorer::show_item_properties_dialog);
|
||||
}
|
||||
}
|
||||
|
||||
menu.exec(QCursor::pos());
|
||||
}
|
||||
|
||||
void ProjectExplorer::show_item_properties_dialog()
|
||||
{
|
||||
Node *sel = context_menu_items_.first();
|
||||
|
||||
// FIXME: Support for multiple items
|
||||
if (dynamic_cast<Footage *>(sel)) {
|
||||
FootagePropertiesDialog fpd(this, static_cast<Footage *>(sel));
|
||||
fpd.exec();
|
||||
|
||||
} else if (dynamic_cast<Folder *>(sel)) {
|
||||
Core::instance()->label_nodes(context_menu_items_);
|
||||
|
||||
} else if (dynamic_cast<Sequence *>(sel)) {
|
||||
SequenceDialog sd(static_cast<Sequence *>(sel),
|
||||
SequenceDialog::k_existing, this);
|
||||
sd.exec();
|
||||
}
|
||||
}
|
||||
|
||||
void ProjectExplorer::reveal_selected_footage()
|
||||
{
|
||||
Footage *footage = static_cast<Footage *>(context_menu_items_.first());
|
||||
|
||||
#if defined(Q_OS_WINDOWS)
|
||||
// Explorer
|
||||
QStringList args;
|
||||
args << "/select," << QDir::toNativeSeparators(footage->filename());
|
||||
QProcess::startDetached("explorer", args);
|
||||
#elif defined(Q_OS_MAC)
|
||||
QStringList args;
|
||||
args << "-e";
|
||||
args << "tell application \"Finder\"";
|
||||
args << "-e";
|
||||
args << "activate";
|
||||
args << "-e";
|
||||
args << "select POSIX file \"" + footage->filename() + "\"";
|
||||
args << "-e";
|
||||
args << "end tell";
|
||||
QProcess::startDetached("osascript", args);
|
||||
#else
|
||||
QDesktopServices::openUrl(QUrl::fromLocalFile(
|
||||
QFileInfo(footage->filename()).dir().absolutePath()));
|
||||
#endif
|
||||
}
|
||||
|
||||
void ProjectExplorer::replace_selected_footage()
|
||||
{
|
||||
Footage *footage = static_cast<Footage *>(context_menu_items_.first());
|
||||
|
||||
QString file =
|
||||
QFileDialog::getOpenFileName(this, tr("Replace Footage"), QString(),
|
||||
Core::footage_file_dialog_filter());
|
||||
if (!file.isEmpty()) {
|
||||
if (!Core::is_footage_extension_allowed(file)) {
|
||||
QMessageBox::warning(
|
||||
this, tr("Unsupported media"),
|
||||
tr("This file type is not allowed by the current media type "
|
||||
"filter."));
|
||||
return;
|
||||
}
|
||||
|
||||
// Change the filename through the facade relink (reprobes the new
|
||||
// file and resets proxy/stream state); the label policy stays here.
|
||||
OakEngineFootage *facade_handle = oakengine_footage_borrow(
|
||||
reinterpret_cast<OakEngineNode *>(footage));
|
||||
const int relink_rc = oakengine_footage_relink(
|
||||
facade_handle, file.toUtf8().constData());
|
||||
oakengine_footage_free(facade_handle);
|
||||
if (relink_rc != OAKENGINE_OK) {
|
||||
char err[512];
|
||||
err[0] = '\0';
|
||||
oakengine_footage_last_error(err, sizeof(err));
|
||||
QMessageBox::warning(
|
||||
this, tr("Cannot replace footage"),
|
||||
err[0] ? QString::fromUtf8(err) :
|
||||
tr("The file could not be used as media."));
|
||||
return;
|
||||
}
|
||||
|
||||
if (QFileInfo(footage->filename()).fileName() ==
|
||||
footage->get_label()) {
|
||||
// Footage label == filename, change label too
|
||||
oakengine_node_set_label(
|
||||
reinterpret_cast<OakEngineNode *>(footage),
|
||||
QFileInfo(file).fileName().toUtf8().constData());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ProjectExplorer::open_context_menu_item_in_new_tab()
|
||||
{
|
||||
Core::instance()->main_window()->open_folder(
|
||||
static_cast<Folder *>(context_menu_items_.first()), false);
|
||||
}
|
||||
|
||||
void ProjectExplorer::open_context_menu_item_in_new_window()
|
||||
{
|
||||
Core::instance()->main_window()->open_folder(
|
||||
static_cast<Folder *>(context_menu_items_.first()), true);
|
||||
}
|
||||
|
||||
void ProjectExplorer::generate_proxies_for_selected_footage()
|
||||
{
|
||||
if (!project()) {
|
||||
qWarning() << "GenerateProxiesForSelectedFootage: no project";
|
||||
return;
|
||||
}
|
||||
|
||||
const QVector<Footage *> footage =
|
||||
get_selected_proxy_footage(context_menu_items_);
|
||||
qDebug()
|
||||
<< "GenerateProxiesForSelectedFootage: starting proxy generation for"
|
||||
<< footage.size() << "footage item(s)";
|
||||
for (Footage *item : footage) {
|
||||
const VideoParams video = item->get_first_enabled_video_stream();
|
||||
if (!video.is_valid()) {
|
||||
qWarning()
|
||||
<< "GenerateProxiesForSelectedFootage: skipping item with no valid video stream"
|
||||
<< item->filename();
|
||||
continue;
|
||||
}
|
||||
|
||||
// Queue one facade-backed task per footage item (same queueing
|
||||
// semantics as the old per-footage proxy tasks).
|
||||
oakengine_task_manager_add(
|
||||
reinterpret_cast<OakEngineTask *>(new FacadeProxyTask(item)));
|
||||
}
|
||||
}
|
||||
|
||||
void ProjectExplorer::set_selected_footage_proxy_enabled(bool enabled)
|
||||
{
|
||||
const QVector<Footage *> footage =
|
||||
get_selected_proxy_footage(context_menu_items_);
|
||||
qDebug() << "ProjectExplorer::SetSelectedFootageProxyEnabled:" << enabled
|
||||
<< "footage count=" << footage.size();
|
||||
for (Footage *item : footage) {
|
||||
if (item->proxy_path().isEmpty()) {
|
||||
qDebug()
|
||||
<< " skipping item with empty proxy path" << item->filename();
|
||||
continue;
|
||||
}
|
||||
|
||||
OakEngineFootage *handle = oakengine_footage_borrow(
|
||||
reinterpret_cast<OakEngineNode *>(item));
|
||||
oakengine_footage_proxy_set_enabled(handle, enabled ? 1 : 0);
|
||||
oakengine_footage_free(handle);
|
||||
// The facade call toggles the flag; cache invalidation for the UI
|
||||
// stays here.
|
||||
item->invalidate_all(Footage::k_filename_input);
|
||||
}
|
||||
}
|
||||
|
||||
void ProjectExplorer::reveal_proxy_for_selected_footage()
|
||||
{
|
||||
const QVector<Footage *> footage =
|
||||
get_selected_proxy_footage(context_menu_items_);
|
||||
for (Footage *item : footage) {
|
||||
char proxy_path[4096];
|
||||
proxy_path[0] = '\0';
|
||||
OakEngineFootage *handle = oakengine_footage_borrow(
|
||||
reinterpret_cast<OakEngineNode *>(item));
|
||||
oakengine_footage_proxy_get_path(handle, proxy_path,
|
||||
sizeof(proxy_path));
|
||||
oakengine_footage_free(handle);
|
||||
if (proxy_path[0] == '\0') {
|
||||
continue;
|
||||
}
|
||||
const QString path = QString::fromUtf8(proxy_path);
|
||||
|
||||
#if defined(Q_OS_WINDOWS)
|
||||
QStringList args;
|
||||
args << "/select," << QDir::toNativeSeparators(path);
|
||||
QProcess::startDetached(QStringLiteral("explorer"), args);
|
||||
#elif defined(Q_OS_MAC)
|
||||
QStringList args;
|
||||
args << "-e";
|
||||
args << "tell application \"Finder\"";
|
||||
args << "-e";
|
||||
args << "activate";
|
||||
args << "-e";
|
||||
args << "select POSIX file \"" + path + "\"";
|
||||
args << "-e";
|
||||
args << "end tell";
|
||||
QProcess::startDetached(QStringLiteral("osascript"), args);
|
||||
#else
|
||||
QDesktopServices::openUrl(QUrl::fromLocalFile(
|
||||
QFileInfo(path).dir().absolutePath()));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void ProjectExplorer::delete_proxies_for_selected_footage()
|
||||
{
|
||||
const QVector<Footage *> footage =
|
||||
get_selected_proxy_footage(context_menu_items_);
|
||||
for (Footage *item : footage) {
|
||||
if (item->proxy_path().isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Facade delete: removes the file, clears the proxy state and
|
||||
// invalidates the footage.
|
||||
OakEngineFootage *handle = oakengine_footage_borrow(
|
||||
reinterpret_cast<OakEngineNode *>(item));
|
||||
oakengine_footage_proxy_delete(handle);
|
||||
oakengine_footage_free(handle);
|
||||
}
|
||||
}
|
||||
|
||||
void ProjectExplorer::show_proxy_dialog_for_selected_footage()
|
||||
{
|
||||
ProxyDialog d(this, get_selected_proxy_footage(context_menu_items_));
|
||||
d.exec();
|
||||
}
|
||||
|
||||
void ProjectExplorer::view_selection_changed()
|
||||
{
|
||||
QItemSelectionModel *model = static_cast<QItemSelectionModel *>(sender());
|
||||
|
||||
QModelIndexList selection = model->selectedIndexes();
|
||||
|
||||
QVector<Node *> nodes;
|
||||
|
||||
foreach (const QModelIndex &index, selection) {
|
||||
Node *sel = static_cast<Node *>(
|
||||
sort_model_.mapToSource(index).internalPointer());
|
||||
if (!nodes.contains(sel)) {
|
||||
nodes.append(sel);
|
||||
}
|
||||
}
|
||||
|
||||
if (nodes.isEmpty()) {
|
||||
nodes.append(get_root());
|
||||
}
|
||||
|
||||
emit selection_changed(nodes);
|
||||
}
|
||||
|
||||
Project *ProjectExplorer::project() const
|
||||
{
|
||||
return model_.project();
|
||||
}
|
||||
|
||||
void ProjectExplorer::set_project(Project *p)
|
||||
{
|
||||
model_.set_project(p);
|
||||
}
|
||||
|
||||
Folder *ProjectExplorer::get_root() const
|
||||
{
|
||||
QModelIndex root_index = sort_model_.mapToSource(tree_view_->rootIndex());
|
||||
|
||||
if (!root_index.isValid()) {
|
||||
return project()->root();
|
||||
}
|
||||
|
||||
return static_cast<Folder *>(root_index.internalPointer());
|
||||
}
|
||||
|
||||
void ProjectExplorer::set_root(Folder *item)
|
||||
{
|
||||
QModelIndex index =
|
||||
sort_model_.mapFromSource(model_.create_index_from_item(item));
|
||||
|
||||
browse_to_folder(index);
|
||||
tree_view_->setRootIndex(index);
|
||||
}
|
||||
|
||||
QVector<Node *> ProjectExplorer::selected_items() const
|
||||
{
|
||||
// Determine which view is active and get its selected indexes
|
||||
QModelIndexList index_list =
|
||||
current_view()->selectionModel()->selectedRows();
|
||||
|
||||
// Convert indexes to item objects
|
||||
QVector<Node *> selected_items;
|
||||
|
||||
for (int i = 0; i < index_list.size(); i++) {
|
||||
QModelIndex index = sort_model_.mapToSource(index_list.at(i));
|
||||
|
||||
Node *item = static_cast<Node *>(index.internalPointer());
|
||||
|
||||
selected_items.append(item);
|
||||
}
|
||||
|
||||
return selected_items;
|
||||
}
|
||||
|
||||
Folder *ProjectExplorer::get_selected_folder() const
|
||||
{
|
||||
if (project() == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Folder *folder = nullptr;
|
||||
|
||||
// Get the selected items from the panel
|
||||
QVector<Node *> selected_nodes = selected_items();
|
||||
|
||||
// Heuristic for finding the selected folder:
|
||||
//
|
||||
// - If `folder` is nullptr, we set the first folder we find. Either the item itself if it's a folder, or the
|
||||
// item's parent.
|
||||
// - Otherwise, if all folders found are the same, we'll use that to import into.
|
||||
// - If more than one folder is found, we play it safe and import into the root folder
|
||||
|
||||
for (int i = 0; i < selected_nodes.size(); i++) {
|
||||
Node *sel_item = selected_nodes.at(i);
|
||||
|
||||
// If this item is not a folder, presumably it's parent is
|
||||
if (!dynamic_cast<Folder *>(sel_item)) {
|
||||
sel_item = sel_item->folder();
|
||||
}
|
||||
|
||||
if (folder == nullptr) {
|
||||
// If the folder is nullptr, cache it as this folder
|
||||
folder = static_cast<Folder *>(sel_item);
|
||||
} else if (folder != sel_item) {
|
||||
// If not, we've already cached a folder so we check if it's the same
|
||||
// If it isn't, we "play it safe" and use the root folder
|
||||
folder = nullptr;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// If we didn't pick up a folder from the heuristic above for whatever reason, use root
|
||||
if (folder == nullptr) {
|
||||
folder = project()->root();
|
||||
}
|
||||
|
||||
return folder;
|
||||
}
|
||||
|
||||
ProjectViewModel *ProjectExplorer::model()
|
||||
{
|
||||
return &model_;
|
||||
}
|
||||
|
||||
void ProjectExplorer::select_all()
|
||||
{
|
||||
current_view()->selectAll();
|
||||
}
|
||||
|
||||
void ProjectExplorer::deselect_all()
|
||||
{
|
||||
current_view()->selectionModel()->clearSelection();
|
||||
}
|
||||
|
||||
void ProjectExplorer::delete_selected()
|
||||
{
|
||||
QVector<Node *> selected = selected_items();
|
||||
|
||||
if (selected.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
MultiUndoCommand *command = new MultiUndoCommand();
|
||||
|
||||
bool check_if_item_is_in_use = true;
|
||||
|
||||
if (delete_items_internal(selected, check_if_item_is_in_use, command)) {
|
||||
Core::instance()->undo_stack()->push(
|
||||
command, tr("Deleted %1 Item(s)").arg(selected.size()));
|
||||
} else {
|
||||
delete command;
|
||||
}
|
||||
}
|
||||
|
||||
bool ProjectExplorer::select_item(Node *n, bool deselect_all_first)
|
||||
{
|
||||
if (deselect_all_first) {
|
||||
deselect_all();
|
||||
}
|
||||
|
||||
QModelIndex index = model_.create_index_from_item(n);
|
||||
|
||||
if (index.isValid()) {
|
||||
index = sort_model_.mapFromSource(index);
|
||||
|
||||
QModelIndex parent = index.parent();
|
||||
if (view_type() == ProjectToolbar::tree_view) {
|
||||
// Expand all folders until this index is visible
|
||||
while (parent.isValid()) {
|
||||
tree_view_->expand(parent);
|
||||
parent = parent.parent();
|
||||
}
|
||||
} else {
|
||||
browse_to_folder(parent);
|
||||
}
|
||||
|
||||
current_view()->selectionModel()->select(
|
||||
index, QItemSelectionModel::Select | QItemSelectionModel::Rows);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,208 @@
|
||||
/***
|
||||
|
||||
Olive - Non-Linear Video Editor
|
||||
Copyright (C) 2022 Olive Team
|
||||
Modifications Copyright (C) 2025 mikesolar
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
***/
|
||||
|
||||
#ifndef OAK_PROJECTEXPLORER_H
|
||||
#define OAK_PROJECTEXPLORER_H
|
||||
|
||||
#include <QSortFilterProxyModel>
|
||||
#include <QStackedWidget>
|
||||
#include <QTimer>
|
||||
#include <QTreeView>
|
||||
|
||||
#include "node/project.h"
|
||||
#include "projectviewmodel.h"
|
||||
#include "widget/projectexplorer/projectexplorericonview.h"
|
||||
#include "widget/projectexplorer/projectexplorerlistview.h"
|
||||
#include "widget/projectexplorer/projectexplorertreeview.h"
|
||||
#include "widget/projectexplorer/projectexplorernavigation.h"
|
||||
#include "widget/projecttoolbar/projecttoolbar.h"
|
||||
|
||||
namespace olive
|
||||
{
|
||||
|
||||
/**
|
||||
* @brief A widget for browsing through a Project structure.
|
||||
*
|
||||
* ProjectExplorer automatically handles the view<->model system using a ProjectViewModel. Therefore, all that needs to
|
||||
* be provided is the Project structure itself.
|
||||
*
|
||||
* This widget contains three views, tree view, list view, and icon view. These can be switched at any time.
|
||||
*/
|
||||
class ProjectExplorer : public QWidget {
|
||||
Q_OBJECT
|
||||
public:
|
||||
ProjectExplorer(QWidget *parent);
|
||||
|
||||
const ProjectToolbar::ViewType &view_type() const;
|
||||
|
||||
Project *project() const;
|
||||
void set_project(Project *p);
|
||||
|
||||
Folder *get_root() const;
|
||||
void set_root(Folder *item);
|
||||
|
||||
QVector<Node *> selected_items() const;
|
||||
|
||||
/**
|
||||
* @brief Use a heuristic to determine which (if any) folder is selected
|
||||
*
|
||||
* Generally for some import/adding processes, we assume that if a folder is selected, the user probably wants to
|
||||
* create the new object in it rather than in the root. If, however, more than one folder is selected, we can't
|
||||
* truly determine any folder from this and just return the root instead.
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* A folder that's heuristically been determined as "selected", or the root directory if none, or nullptr if no
|
||||
* project is open.
|
||||
*/
|
||||
Folder *get_selected_folder() const;
|
||||
|
||||
/**
|
||||
* @brief Access the ViewModel model of the project
|
||||
*/
|
||||
ProjectViewModel *model();
|
||||
|
||||
void select_all();
|
||||
|
||||
void deselect_all();
|
||||
|
||||
void delete_selected();
|
||||
|
||||
bool select_item(Node *n, bool deselect_all_first = true);
|
||||
|
||||
public slots:
|
||||
void set_view_type(ProjectToolbar::ViewType type);
|
||||
|
||||
void edit(Node *item);
|
||||
|
||||
void rename_selected_item();
|
||||
|
||||
void set_search_filter(const QString &s);
|
||||
|
||||
signals:
|
||||
/**
|
||||
* @brief Emitted when an Item is double clicked
|
||||
*
|
||||
* @param item
|
||||
*
|
||||
* The Item that was double clicked, or nullptr if empty area was double clicked
|
||||
*/
|
||||
void double_clicked_item(Node *item);
|
||||
|
||||
void selection_changed(const QVector<Node *> &selected);
|
||||
|
||||
private:
|
||||
/**
|
||||
* @brief Get all the blocks that solely rely on an input node
|
||||
*
|
||||
* Ignores blocks that depend on multiple inputs
|
||||
*/
|
||||
QList<Block *> get_footage_blocks(QList<Node *> nodes);
|
||||
|
||||
/**
|
||||
* @brief Simple convenience function for adding a view to this stacked widget
|
||||
*
|
||||
* Mainly for use in the constructor. Adds the view, connects its signals/slots, and sets the model.
|
||||
*
|
||||
* @param view
|
||||
*
|
||||
* View to add to the stack
|
||||
*/
|
||||
void add_view(QAbstractItemView *view);
|
||||
|
||||
/**
|
||||
* @brief Browse to a specific folder index in the model
|
||||
*
|
||||
* Only affects list_view_ and icon_view_.
|
||||
*
|
||||
* @param index
|
||||
*
|
||||
* Either an invalid index to return to the project root, or an index to a valid Folder object.
|
||||
*/
|
||||
void browse_to_folder(const QModelIndex &index);
|
||||
|
||||
int confirm_item_deletion(Node *item);
|
||||
|
||||
bool delete_items_internal(const QVector<Node *> &selected,
|
||||
bool &check_if_item_is_in_use,
|
||||
MultiUndoCommand *command);
|
||||
|
||||
static QString get_human_readable_node_name(Node *node);
|
||||
|
||||
void update_nav_bar_text();
|
||||
|
||||
/**
|
||||
* @brief Get the currently active QAbstractItemView
|
||||
*/
|
||||
QAbstractItemView *current_view() const;
|
||||
|
||||
QStackedWidget *stacked_widget_;
|
||||
|
||||
ProjectExplorerNavigation *nav_bar_;
|
||||
|
||||
ProjectExplorerIconView *icon_view_;
|
||||
ProjectExplorerListView *list_view_;
|
||||
ProjectExplorerTreeView *tree_view_;
|
||||
|
||||
ProjectToolbar::ViewType view_type_;
|
||||
|
||||
QSortFilterProxyModel sort_model_;
|
||||
ProjectViewModel model_;
|
||||
|
||||
QVector<Node *> context_menu_items_;
|
||||
|
||||
private slots:
|
||||
void view_empty_area_double_clicked_slot();
|
||||
|
||||
void item_double_clicked_slot(const QModelIndex &index);
|
||||
|
||||
void size_changed_slot(int s);
|
||||
|
||||
void dir_up_slot();
|
||||
|
||||
void show_context_menu();
|
||||
|
||||
void show_item_properties_dialog();
|
||||
|
||||
void reveal_selected_footage();
|
||||
|
||||
void replace_selected_footage();
|
||||
|
||||
void open_context_menu_item_in_new_tab();
|
||||
|
||||
void open_context_menu_item_in_new_window();
|
||||
|
||||
void generate_proxies_for_selected_footage();
|
||||
|
||||
void set_selected_footage_proxy_enabled(bool enabled);
|
||||
|
||||
void reveal_proxy_for_selected_footage();
|
||||
|
||||
void delete_proxies_for_selected_footage();
|
||||
|
||||
void show_proxy_dialog_for_selected_footage();
|
||||
|
||||
void view_selection_changed();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // OAK_PROJECTEXPLORER_H
|
||||
@@ -0,0 +1,35 @@
|
||||
/***
|
||||
|
||||
Olive - Non-Linear Video Editor
|
||||
Copyright (C) 2022 Olive Team
|
||||
Modifications Copyright (C) 2025 mikesolar
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
***/
|
||||
|
||||
#include "projectexplorericonview.h"
|
||||
|
||||
namespace olive
|
||||
{
|
||||
|
||||
ProjectExplorerIconView::ProjectExplorerIconView(QWidget *parent)
|
||||
: ProjectExplorerListViewBase(parent)
|
||||
{
|
||||
setViewMode(QListView::IconMode);
|
||||
|
||||
setItemDelegate(&delegate_);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/***
|
||||
|
||||
Olive - Non-Linear Video Editor
|
||||
Copyright (C) 2022 Olive Team
|
||||
Modifications Copyright (C) 2025 mikesolar
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
***/
|
||||
|
||||
#ifndef OAK_PROJECTEXPLORERICONVIEW_H
|
||||
#define OAK_PROJECTEXPLORERICONVIEW_H
|
||||
|
||||
#include "projectexplorerlistviewbase.h"
|
||||
#include "projectexplorericonviewitemdelegate.h"
|
||||
|
||||
namespace olive
|
||||
{
|
||||
|
||||
/**
|
||||
* @brief The view widget used when ProjectExplorer is in Icon View
|
||||
*/
|
||||
class ProjectExplorerIconView : public ProjectExplorerListViewBase {
|
||||
Q_OBJECT
|
||||
public:
|
||||
ProjectExplorerIconView(QWidget *parent);
|
||||
|
||||
private:
|
||||
ProjectExplorerIconViewItemDelegate delegate_;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // OAK_PROJECTEXPLORERICONVIEW_H
|
||||
@@ -0,0 +1,110 @@
|
||||
/***
|
||||
|
||||
Olive - Non-Linear Video Editor
|
||||
Copyright (C) 2022 Olive Team
|
||||
Modifications Copyright (C) 2025 mikesolar
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
***/
|
||||
|
||||
#include "projectexplorericonviewitemdelegate.h"
|
||||
|
||||
#include <QPainter>
|
||||
|
||||
#include "common/qtutils.h"
|
||||
|
||||
namespace olive
|
||||
{
|
||||
|
||||
ProjectExplorerIconViewItemDelegate::ProjectExplorerIconViewItemDelegate(
|
||||
QObject *parent)
|
||||
: QStyledItemDelegate(parent)
|
||||
{
|
||||
}
|
||||
|
||||
QSize ProjectExplorerIconViewItemDelegate::sizeHint(
|
||||
const QStyleOptionViewItem &option, const QModelIndex &) const
|
||||
{
|
||||
Q_UNUSED(option)
|
||||
|
||||
return QSize(256, 256);
|
||||
}
|
||||
|
||||
void ProjectExplorerIconViewItemDelegate::paint(
|
||||
QPainter *painter, const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index) const
|
||||
{
|
||||
QFontMetrics fm = painter->fontMetrics();
|
||||
QRect img_rect = option.rect;
|
||||
|
||||
// Draw Text
|
||||
if (fm.height() < option.rect.height() / 2) {
|
||||
img_rect.setHeight(img_rect.height() - fm.height());
|
||||
|
||||
QRect text_rect = option.rect;
|
||||
text_rect.setTop(text_rect.top() + option.rect.height() - fm.height());
|
||||
|
||||
QColor text_bgcolor;
|
||||
QColor text_fgcolor;
|
||||
|
||||
if (option.state & QStyle::State_Selected) {
|
||||
text_bgcolor = option.palette.highlight().color();
|
||||
text_fgcolor = option.palette.highlightedText().color();
|
||||
} else {
|
||||
text_bgcolor = Qt::white;
|
||||
text_fgcolor = Qt::black;
|
||||
}
|
||||
|
||||
painter->fillRect(text_rect, text_bgcolor);
|
||||
painter->setPen(text_fgcolor);
|
||||
|
||||
QString duration_str = index.data(Qt::UserRole).toString();
|
||||
|
||||
int timecode_width = QtUtils::q_font_metrics_width(fm, duration_str);
|
||||
|
||||
int max_name_width = option.rect.width();
|
||||
|
||||
if (timecode_width < option.rect.width() / 2) {
|
||||
painter->drawText(
|
||||
text_rect, static_cast<int>(Qt::AlignBottom | Qt::AlignRight),
|
||||
index.data(Qt::UserRole).toString());
|
||||
max_name_width -= timecode_width;
|
||||
}
|
||||
|
||||
painter->drawText(text_rect,
|
||||
static_cast<int>(Qt::AlignBottom | Qt::AlignLeft),
|
||||
fm.elidedText(index.data(Qt::DisplayRole).toString(),
|
||||
Qt::ElideRight, max_name_width));
|
||||
}
|
||||
|
||||
// Draw image
|
||||
QIcon ico = index.data(Qt::DecorationRole).value<QIcon>();
|
||||
QSize icon_size = ico.actualSize(img_rect.size());
|
||||
img_rect =
|
||||
QRect(img_rect.x() + (img_rect.width() / 2 - icon_size.width() / 2),
|
||||
img_rect.y() + (img_rect.height() / 2 - icon_size.height() / 2),
|
||||
icon_size.width(), icon_size.height());
|
||||
painter->drawPixmap(img_rect, ico.pixmap(icon_size));
|
||||
|
||||
if (option.state & QStyle::State_Selected) {
|
||||
QColor highlight_color = option.palette.highlight().color();
|
||||
highlight_color.setAlphaF(0.5);
|
||||
|
||||
painter->setCompositionMode(QPainter::CompositionMode_SourceAtop);
|
||||
painter->fillRect(img_rect, highlight_color);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/***
|
||||
|
||||
Olive - Non-Linear Video Editor
|
||||
Copyright (C) 2022 Olive Team
|
||||
Modifications Copyright (C) 2025 mikesolar
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
***/
|
||||
|
||||
#ifndef OAK_PROJECTEXPLORERICONVIEWITEMDELEGATE_H
|
||||
#define OAK_PROJECTEXPLORERICONVIEWITEMDELEGATE_H
|
||||
|
||||
#include <QStyledItemDelegate>
|
||||
|
||||
#include "common/define.h"
|
||||
|
||||
namespace olive
|
||||
{
|
||||
|
||||
/**
|
||||
* @brief The delegate that's used to draw items when ProjectExplorer is in Icon view
|
||||
*/
|
||||
class ProjectExplorerIconViewItemDelegate : public QStyledItemDelegate {
|
||||
public:
|
||||
ProjectExplorerIconViewItemDelegate(QObject *parent = nullptr);
|
||||
|
||||
virtual QSize sizeHint(const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index) const override;
|
||||
virtual void paint(QPainter *painter, const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index) const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // OAK_PROJECTEXPLORERICONVIEWITEMDELEGATE_H
|
||||
@@ -0,0 +1,35 @@
|
||||
/***
|
||||
|
||||
Olive - Non-Linear Video Editor
|
||||
Copyright (C) 2022 Olive Team
|
||||
Modifications Copyright (C) 2025 mikesolar
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
***/
|
||||
|
||||
#include "projectexplorerlistview.h"
|
||||
|
||||
namespace olive
|
||||
{
|
||||
|
||||
ProjectExplorerListView::ProjectExplorerListView(QWidget *parent)
|
||||
: ProjectExplorerListViewBase(parent)
|
||||
{
|
||||
setViewMode(QListView::ListMode);
|
||||
|
||||
setItemDelegate(&delegate_);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/***
|
||||
|
||||
Olive - Non-Linear Video Editor
|
||||
Copyright (C) 2022 Olive Team
|
||||
Modifications Copyright (C) 2025 mikesolar
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
***/
|
||||
|
||||
#ifndef OAK_PROJECTEXPLORERLISTVIEW_H
|
||||
#define OAK_PROJECTEXPLORERLISTVIEW_H
|
||||
|
||||
#include "projectexplorerlistviewbase.h"
|
||||
#include "projectexplorerlistviewitemdelegate.h"
|
||||
|
||||
namespace olive
|
||||
{
|
||||
|
||||
/**
|
||||
* @brief The view widget used when ProjectExplorer is in List View
|
||||
*/
|
||||
class ProjectExplorerListView : public ProjectExplorerListViewBase {
|
||||
Q_OBJECT
|
||||
public:
|
||||
ProjectExplorerListView(QWidget *parent);
|
||||
|
||||
private:
|
||||
ProjectExplorerListViewItemDelegate delegate_;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // OAK_PROJECTEXPLORERLISTVIEW_H
|
||||
@@ -0,0 +1,59 @@
|
||||
/***
|
||||
|
||||
Olive - Non-Linear Video Editor
|
||||
Copyright (C) 2022 Olive Team
|
||||
Modifications Copyright (C) 2025 mikesolar
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
***/
|
||||
|
||||
#include "projectexplorerlistviewbase.h"
|
||||
|
||||
#include <QMouseEvent>
|
||||
|
||||
namespace olive
|
||||
{
|
||||
|
||||
ProjectExplorerListViewBase::ProjectExplorerListViewBase(QWidget *parent)
|
||||
: QListView(parent)
|
||||
{
|
||||
// FIXME Is this necessary?
|
||||
setMovement(QListView::Free);
|
||||
|
||||
// Set selection mode (allows multiple item selection)
|
||||
setSelectionMode(QAbstractItemView::ExtendedSelection);
|
||||
|
||||
// Set resize mode
|
||||
setResizeMode(QListView::Adjust);
|
||||
|
||||
// Set widget to emit a signal on right click
|
||||
setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
}
|
||||
|
||||
void ProjectExplorerListViewBase::mouseDoubleClickEvent(QMouseEvent *event)
|
||||
{
|
||||
// Cache here so if the index becomes invalid after the base call, we still know the truth
|
||||
bool item_at_location = indexAt(event->pos()).isValid();
|
||||
|
||||
// Perform default double click functions
|
||||
QListView::mouseDoubleClickEvent(event);
|
||||
|
||||
// QAbstractItemView already has a doubleClicked() signal, but we emit another here for double clicking empty space
|
||||
if (!item_at_location) {
|
||||
emit double_clicked_empty_area();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
/***
|
||||
|
||||
Olive - Non-Linear Video Editor
|
||||
Copyright (C) 2022 Olive Team
|
||||
Modifications Copyright (C) 2025 mikesolar
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
***/
|
||||
|
||||
#ifndef OAK_PROJECTEXPLORERLISTVIEWBASE_H
|
||||
#define OAK_PROJECTEXPLORERLISTVIEWBASE_H
|
||||
|
||||
#include <QListView>
|
||||
|
||||
#include "common/define.h"
|
||||
|
||||
namespace olive
|
||||
{
|
||||
|
||||
/**
|
||||
* @brief A QListView derivative that contains functionality used by both List view and Icon view (which are both based
|
||||
* on QListView)
|
||||
*/
|
||||
class ProjectExplorerListViewBase : public QListView {
|
||||
Q_OBJECT
|
||||
public:
|
||||
ProjectExplorerListViewBase(QWidget *parent);
|
||||
|
||||
protected:
|
||||
/**
|
||||
* @brief Double click event override
|
||||
*
|
||||
* Function that signals DoubleClickedView().
|
||||
*
|
||||
* FIXME: This code is the same as the code in ProjectExplorerTreeView. Is there a way to merge these two through
|
||||
* subclassing?
|
||||
*/
|
||||
virtual void mouseDoubleClickEvent(QMouseEvent *event) override;
|
||||
|
||||
signals:
|
||||
/**
|
||||
* @brief Unconditional double click signal
|
||||
*
|
||||
* Emits a signal when the view is double clicked but not on any particular item
|
||||
*/
|
||||
void double_clicked_empty_area();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // OAK_PROJECTEXPLORERLISTVIEWBASE_H
|
||||
@@ -0,0 +1,91 @@
|
||||
/***
|
||||
|
||||
Olive - Non-Linear Video Editor
|
||||
Copyright (C) 2022 Olive Team
|
||||
Modifications Copyright (C) 2025 mikesolar
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
***/
|
||||
|
||||
#include "projectexplorerlistviewitemdelegate.h"
|
||||
|
||||
#include <QPainter>
|
||||
|
||||
namespace olive
|
||||
{
|
||||
|
||||
ProjectExplorerListViewItemDelegate::ProjectExplorerListViewItemDelegate(
|
||||
QObject *parent)
|
||||
: QStyledItemDelegate(parent)
|
||||
{
|
||||
}
|
||||
|
||||
QSize ProjectExplorerListViewItemDelegate::sizeHint(
|
||||
const QStyleOptionViewItem &option, const QModelIndex &) const
|
||||
{
|
||||
return QSize(option.decorationSize.height(),
|
||||
option.decorationSize.height());
|
||||
}
|
||||
|
||||
void ProjectExplorerListViewItemDelegate::paint(
|
||||
QPainter *painter, const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index) const
|
||||
{
|
||||
QFontMetrics fm = painter->fontMetrics();
|
||||
QRect img_rect = option.rect;
|
||||
|
||||
if (option.state & QStyle::State_Selected) {
|
||||
painter->fillRect(option.rect, option.palette.highlight());
|
||||
}
|
||||
|
||||
img_rect.setWidth(qMin(img_rect.width(), img_rect.height()));
|
||||
|
||||
QIcon ico = index.data(Qt::DecorationRole).value<QIcon>();
|
||||
QSize icon_size = ico.actualSize(img_rect.size());
|
||||
img_rect =
|
||||
QRect(img_rect.x() + (img_rect.width() / 2 - icon_size.width() / 2),
|
||||
img_rect.y() + (img_rect.height() / 2 - icon_size.height() / 2),
|
||||
icon_size.width(), icon_size.height());
|
||||
painter->drawPixmap(img_rect, ico.pixmap(icon_size));
|
||||
|
||||
QRect text_rect = option.rect;
|
||||
text_rect.setLeft(text_rect.left() + option.rect.height());
|
||||
|
||||
int maximum_line_count = qMax(1, option.rect.height() / fm.height() - 1);
|
||||
QString text;
|
||||
if (maximum_line_count == 1) {
|
||||
text = index.data(Qt::DisplayRole).toString();
|
||||
} else {
|
||||
text = index.data(Qt::ToolTipRole).toString();
|
||||
if (text.isEmpty()) {
|
||||
text = index.data(Qt::DisplayRole).toString();
|
||||
} else {
|
||||
QStringList strings = text.split("\n");
|
||||
while (strings.size() > maximum_line_count) {
|
||||
strings.removeLast();
|
||||
}
|
||||
text = strings.join("\n");
|
||||
}
|
||||
}
|
||||
|
||||
painter->setPen(option.state & QStyle::State_Selected ?
|
||||
option.palette.highlightedText().color() :
|
||||
option.palette.text().color());
|
||||
|
||||
painter->drawText(text_rect,
|
||||
static_cast<int>(Qt::AlignLeft | Qt::AlignVCenter), text);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/***
|
||||
|
||||
Olive - Non-Linear Video Editor
|
||||
Copyright (C) 2022 Olive Team
|
||||
Modifications Copyright (C) 2025 mikesolar
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
***/
|
||||
|
||||
#ifndef OAK_PROJECTEXPLORERLISTVIEWITEMDELEGATE_H
|
||||
#define OAK_PROJECTEXPLORERLISTVIEWITEMDELEGATE_H
|
||||
|
||||
#include <QStyledItemDelegate>
|
||||
|
||||
#include "common/define.h"
|
||||
|
||||
namespace olive
|
||||
{
|
||||
|
||||
/**
|
||||
* @brief The delegate that's used to draw items when ProjectExplorer is in List view
|
||||
*/
|
||||
class ProjectExplorerListViewItemDelegate : public QStyledItemDelegate {
|
||||
public:
|
||||
ProjectExplorerListViewItemDelegate(QObject *parent = nullptr);
|
||||
|
||||
virtual QSize sizeHint(const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index) const override;
|
||||
virtual void paint(QPainter *painter, const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index) const override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // OAK_PROJECTEXPLORERLISTVIEWITEMDELEGATE_H
|
||||
@@ -0,0 +1,103 @@
|
||||
/***
|
||||
|
||||
Olive - Non-Linear Video Editor
|
||||
Copyright (C) 2022 Olive Team
|
||||
Modifications Copyright (C) 2025 mikesolar
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
***/
|
||||
|
||||
#include "projectexplorernavigation.h"
|
||||
|
||||
#include <QEvent>
|
||||
#include <QHBoxLayout>
|
||||
|
||||
#include "common/define.h"
|
||||
#include "ui/icons/icons.h"
|
||||
|
||||
namespace olive
|
||||
{
|
||||
|
||||
ProjectExplorerNavigation::ProjectExplorerNavigation(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
// Create widget layout
|
||||
QHBoxLayout *layout = new QHBoxLayout(this);
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
|
||||
// Create "directory up" button
|
||||
dir_up_btn_ = new QPushButton(this);
|
||||
dir_up_btn_->setEnabled(false);
|
||||
dir_up_btn_->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
|
||||
layout->addWidget(dir_up_btn_);
|
||||
connect(dir_up_btn_, SIGNAL(clicked(bool)), this,
|
||||
SIGNAL(directory_up_clicked()));
|
||||
|
||||
// Create directory tree label
|
||||
dir_lbl_ = new QLabel(this);
|
||||
dir_lbl_->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred);
|
||||
layout->addWidget(dir_lbl_);
|
||||
|
||||
// Create size slider
|
||||
size_slider_ = new QSlider(this);
|
||||
size_slider_->setOrientation(Qt::Horizontal);
|
||||
size_slider_->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred);
|
||||
layout->addWidget(size_slider_);
|
||||
connect(size_slider_, SIGNAL(valueChanged(int)), this,
|
||||
SIGNAL(size_changed(int)));
|
||||
|
||||
retranslate();
|
||||
update_icons();
|
||||
}
|
||||
|
||||
void ProjectExplorerNavigation::set_text(const QString &s)
|
||||
{
|
||||
dir_lbl_->setText(s);
|
||||
}
|
||||
|
||||
void ProjectExplorerNavigation::set_dir_up_enabled(bool e)
|
||||
{
|
||||
dir_up_btn_->setEnabled(e);
|
||||
}
|
||||
|
||||
void ProjectExplorerNavigation::set_size_value(int s)
|
||||
{
|
||||
size_slider_->setValue(s);
|
||||
}
|
||||
|
||||
void ProjectExplorerNavigation::changeEvent(QEvent *e)
|
||||
{
|
||||
if (e->type() == QEvent::LanguageChange) {
|
||||
retranslate();
|
||||
} else if (e->type() == QEvent::StyleChange) {
|
||||
update_icons();
|
||||
}
|
||||
QWidget::changeEvent(e);
|
||||
}
|
||||
|
||||
void ProjectExplorerNavigation::retranslate()
|
||||
{
|
||||
dir_up_btn_->setToolTip(tr("Go to parent folder"));
|
||||
}
|
||||
|
||||
void ProjectExplorerNavigation::update_icons()
|
||||
{
|
||||
dir_up_btn_->setIcon(icon::dir_up);
|
||||
size_slider_->setMinimum(k_project_icon_size_minimum);
|
||||
size_slider_->setMaximum(k_project_icon_size_maximum);
|
||||
size_slider_->setValue(k_project_icon_size_default);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
/***
|
||||
|
||||
Olive - Non-Linear Video Editor
|
||||
Copyright (C) 2022 Olive Team
|
||||
Modifications Copyright (C) 2025 mikesolar
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
***/
|
||||
|
||||
#ifndef OAK_PROJECTEXPLORERLISTVIEWTOOLBAR_H
|
||||
#define OAK_PROJECTEXPLORERLISTVIEWTOOLBAR_H
|
||||
|
||||
#include <QLabel>
|
||||
#include <QPushButton>
|
||||
#include <QSlider>
|
||||
#include <QWidget>
|
||||
|
||||
#include "common/define.h"
|
||||
|
||||
namespace olive
|
||||
{
|
||||
|
||||
/**
|
||||
* @brief A navigation bar widget for ProjectExplorer's Icon and List views
|
||||
*
|
||||
* Unlike the Tree view, Icon and List don't follow a hierarchical view of information. This means there is no direct
|
||||
* way of navigating in and out of folders in those view types. We solve this in two ways:
|
||||
*
|
||||
* * Double clicking a Folder in those views will enter that folder
|
||||
* * This navigation bar offers a "directory up" button for leaving a folder
|
||||
*
|
||||
* This navbar also provides an icon size slider for those views (between kProjectIconSizeMinimum and
|
||||
* kProjectIconSizeMaximum) as well as text that's intended to be set to the current Folder's name (or
|
||||
* empty for the root folder).
|
||||
*
|
||||
* This widget does not actually communicate to Project or ProjectExplorer classes. It is simply UI widgets that are
|
||||
* intended to be connected in ways that do. This is the primarily responsibility of ProjectExplorer.
|
||||
*
|
||||
* By default, the directory up button is disabled (assuming root folder), the text is empty, and the icon size slider
|
||||
* is set to kProjectIconSizeDefault.
|
||||
*/
|
||||
class ProjectExplorerNavigation : public QWidget {
|
||||
Q_OBJECT
|
||||
public:
|
||||
ProjectExplorerNavigation(QWidget *parent);
|
||||
|
||||
/**
|
||||
* @brief Sets the text string
|
||||
*
|
||||
* This text is intended to be set to the current Folder's name
|
||||
*
|
||||
* @param s
|
||||
*/
|
||||
void set_text(const QString &s);
|
||||
|
||||
/**
|
||||
* @brief Set whether the "directory up" button is enabled or not
|
||||
*
|
||||
* @param e
|
||||
*/
|
||||
void set_dir_up_enabled(bool e);
|
||||
|
||||
/**
|
||||
* @brief Set the current value of the size slider
|
||||
*
|
||||
* NOTE: Does NOT emit SizeChanged().
|
||||
*
|
||||
* @param s
|
||||
*
|
||||
* New size value to set to
|
||||
*/
|
||||
void set_size_value(int s);
|
||||
|
||||
signals:
|
||||
/**
|
||||
* @brief Signal emitted when the directory up button is clicked
|
||||
*/
|
||||
void directory_up_clicked();
|
||||
|
||||
/**
|
||||
* @brief Signal emitted when the icon size slider changes value
|
||||
*
|
||||
* @param size
|
||||
*
|
||||
* New size set in the slider
|
||||
*/
|
||||
void size_changed(int size);
|
||||
|
||||
protected:
|
||||
virtual void changeEvent(QEvent *) override;
|
||||
|
||||
private:
|
||||
void retranslate();
|
||||
|
||||
void update_icons();
|
||||
|
||||
QPushButton *dir_up_btn_;
|
||||
|
||||
QLabel *dir_lbl_;
|
||||
|
||||
QSlider *size_slider_;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // OAK_PROJECTEXPLORERLISTVIEWTOOLBAR_H
|
||||
@@ -0,0 +1,59 @@
|
||||
/***
|
||||
|
||||
Olive - Non-Linear Video Editor
|
||||
Copyright (C) 2022 Olive Team
|
||||
Modifications Copyright (C) 2025 mikesolar
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
***/
|
||||
|
||||
#include "projectexplorertreeview.h"
|
||||
|
||||
#include <QMouseEvent>
|
||||
|
||||
namespace olive
|
||||
{
|
||||
|
||||
ProjectExplorerTreeView::ProjectExplorerTreeView(QWidget *parent)
|
||||
: QTreeView(parent)
|
||||
{
|
||||
// Set selection mode (allows multiple item selection)
|
||||
setSelectionMode(QAbstractItemView::ExtendedSelection);
|
||||
|
||||
// Allow dragging and dropping
|
||||
setDragDropMode(QAbstractItemView::DragDrop);
|
||||
|
||||
// Enable dragging
|
||||
setDragEnabled(true);
|
||||
|
||||
// Allow dropping from external sources
|
||||
setAcceptDrops(true);
|
||||
|
||||
// Set context menu to emit a signal
|
||||
setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
}
|
||||
|
||||
void ProjectExplorerTreeView::mouseDoubleClickEvent(QMouseEvent *event)
|
||||
{
|
||||
// Perform default double click functions
|
||||
QTreeView::mouseDoubleClickEvent(event);
|
||||
|
||||
// QAbstractItemView already has a doubleClicked() signal, but we emit another here for double clicking empty space
|
||||
if (!indexAt(event->pos()).isValid()) {
|
||||
emit double_clicked_empty_area();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
/***
|
||||
|
||||
Olive - Non-Linear Video Editor
|
||||
Copyright (C) 2022 Olive Team
|
||||
Modifications Copyright (C) 2025 mikesolar
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
***/
|
||||
|
||||
#ifndef OAK_PROJECTEXPLORERTREEVIEW_H
|
||||
#define OAK_PROJECTEXPLORERTREEVIEW_H
|
||||
|
||||
#include <QTreeView>
|
||||
|
||||
#include "common/define.h"
|
||||
|
||||
namespace olive
|
||||
{
|
||||
|
||||
/**
|
||||
* @brief The view widget used when ProjectExplorer is in Tree View
|
||||
*
|
||||
* A fairly simple subclass of QTreeView that provides a double clicked signal whether the index is valid or not
|
||||
* (QAbstractItemView has a doubleClicked() signal but it's only emitted with a valid index).
|
||||
*/
|
||||
class ProjectExplorerTreeView : public QTreeView {
|
||||
Q_OBJECT
|
||||
public:
|
||||
ProjectExplorerTreeView(QWidget *parent);
|
||||
|
||||
protected:
|
||||
/**
|
||||
* @brief Double click event override
|
||||
*
|
||||
* Function that signals DoubleClickedView().
|
||||
*
|
||||
* FIXME: This code is the same as the code in ProjectExplorerListViewBase. Is there a way to merge these two through
|
||||
*
|
||||
*/
|
||||
virtual void mouseDoubleClickEvent(QMouseEvent *event) override;
|
||||
|
||||
signals:
|
||||
/**
|
||||
* @brief Unconditional double click signal
|
||||
*
|
||||
* Emits a signal when the view is double clicked but not on any particular item
|
||||
*/
|
||||
void double_clicked_empty_area();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // OAK_PROJECTEXPLORERTREEVIEW_H
|
||||
@@ -0,0 +1,32 @@
|
||||
/***
|
||||
|
||||
Olive - Non-Linear Video Editor
|
||||
Copyright (C) 2022 Olive Team
|
||||
Modifications Copyright (C) 2025 mikesolar
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
***/
|
||||
|
||||
#ifndef OAK_PROJECTEXPLORERUNDO_H
|
||||
#define OAK_PROJECTEXPLORERUNDO_H
|
||||
|
||||
#include "undo/undocommand.h"
|
||||
|
||||
namespace olive
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
#endif // OAK_PROJECTEXPLORERUNDO_H
|
||||
@@ -0,0 +1,573 @@
|
||||
/***
|
||||
|
||||
Olive - Non-Linear Video Editor
|
||||
Copyright (C) 2022 Olive Team
|
||||
Modifications Copyright (C) 2025 mikesolar
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
***/
|
||||
|
||||
#include "projectviewmodel.h"
|
||||
#include "ui/icons/icons.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QMimeData>
|
||||
#include <QUrl>
|
||||
|
||||
#include "common/qtutils.h"
|
||||
#include "core.h"
|
||||
#include "node/nodeundo.h"
|
||||
|
||||
namespace olive
|
||||
{
|
||||
|
||||
ProjectViewModel::ProjectViewModel(QObject *parent)
|
||||
: QAbstractItemModel(parent)
|
||||
, project_(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
Project *ProjectViewModel::project() const
|
||||
{
|
||||
return project_;
|
||||
}
|
||||
|
||||
void ProjectViewModel::set_project(Project *p)
|
||||
{
|
||||
beginResetModel();
|
||||
|
||||
if (project_) {
|
||||
disconnect_item(project_->root());
|
||||
}
|
||||
|
||||
project_ = p;
|
||||
|
||||
if (project_) {
|
||||
connect_item(project_->root());
|
||||
}
|
||||
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
QModelIndex ProjectViewModel::index(int row, int column,
|
||||
const QModelIndex &parent) const
|
||||
{
|
||||
// I'm actually not 100% sure what this does, but it seems logical and was in the earlier code
|
||||
if (!hasIndex(row, column, parent)) {
|
||||
return QModelIndex();
|
||||
}
|
||||
|
||||
// Get the parent object, we assume it's a folder since only folders can have children
|
||||
Folder *item_parent = static_cast<Folder *>(get_item_object_from_index(parent));
|
||||
|
||||
// Return an index to this object
|
||||
return createIndex(row, column, item_parent->item_child(row));
|
||||
}
|
||||
|
||||
QModelIndex ProjectViewModel::parent(const QModelIndex &child) const
|
||||
{
|
||||
// Get the Item object from the index
|
||||
Node *item = get_item_object_from_index(child);
|
||||
|
||||
// Get Item's parent object
|
||||
Folder *par = item->folder();
|
||||
|
||||
// If the parent is the root, return an empty index
|
||||
if (par == project_->root()) {
|
||||
return QModelIndex();
|
||||
}
|
||||
|
||||
// Otherwise return a true index to its parent
|
||||
int parent_index = index_of_child(par);
|
||||
|
||||
// Make sure the index is valid (there's no reason it shouldn't be)
|
||||
Q_ASSERT(parent_index > -1);
|
||||
|
||||
// Return an index to the parent
|
||||
return createIndex(parent_index, 0, par);
|
||||
}
|
||||
|
||||
int ProjectViewModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
// If there's no project, there are obviously no items to show
|
||||
if (project_ == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// If the index is the root, return the root child count
|
||||
if (parent == QModelIndex()) {
|
||||
return project_->root()->item_child_count();
|
||||
}
|
||||
|
||||
// Otherwise, the index must contain a valid pointer, so we just return its child count
|
||||
return static_cast<Folder *>(get_item_object_from_index(parent))
|
||||
->item_child_count();
|
||||
}
|
||||
|
||||
int ProjectViewModel::columnCount(const QModelIndex &parent) const
|
||||
{
|
||||
Q_UNUSED(parent)
|
||||
|
||||
// Not strictly necessary, but a decent visual cue that there's no project currently active
|
||||
if (project_ == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return k_column_count;
|
||||
}
|
||||
|
||||
QVariant ProjectViewModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
Node *internal_item = get_item_object_from_index(index);
|
||||
|
||||
ColumnType column_type = static_cast<ColumnType>(index.column());
|
||||
|
||||
switch (role) {
|
||||
case Qt::DisplayRole:
|
||||
case k_inner_text_role: {
|
||||
// Standard text role
|
||||
|
||||
switch (column_type) {
|
||||
case k_name:
|
||||
return internal_item->get_label();
|
||||
case k_duration:
|
||||
return internal_item->data(Node::duration);
|
||||
case k_rate:
|
||||
return internal_item->data(Node::frequency_rate);
|
||||
case k_last_modified:
|
||||
case k_created_time: {
|
||||
qint64 using_time =
|
||||
(column_type == k_last_modified) ?
|
||||
internal_item->data(Node::modified_time).toLongLong() :
|
||||
internal_item->data(Node::created_time).toLongLong();
|
||||
|
||||
if (using_time == 0) {
|
||||
// 0 is the null value, return nothing
|
||||
break;
|
||||
}
|
||||
|
||||
QVariant ret;
|
||||
|
||||
if (role == k_inner_text_role) {
|
||||
// Use time value directly for correct sorting
|
||||
ret = using_time;
|
||||
} else {
|
||||
// Display role, format to a human readable string
|
||||
ret = QtUtils::get_formatted_date_time(
|
||||
QDateTime::fromSecsSinceEpoch(using_time));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
case k_column_count:
|
||||
break;
|
||||
}
|
||||
} break;
|
||||
case Qt::EditRole:
|
||||
if (column_type == k_name) {
|
||||
return internal_item->get_label();
|
||||
}
|
||||
break;
|
||||
case Qt::DecorationRole:
|
||||
// If this is the first column, return the Item's icon
|
||||
if (column_type == k_name) {
|
||||
return icon::from_name(internal_item->data(Node::icon).toString());
|
||||
}
|
||||
break;
|
||||
case Qt::ToolTipRole:
|
||||
return internal_item->data(Node::tooltip);
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
QVariant ProjectViewModel::headerData(int section, Qt::Orientation orientation,
|
||||
int role) const
|
||||
{
|
||||
// Check if we need text data (DisplayRole) and orientation is horizontal
|
||||
// FIXME I'm not 100% sure what happens if the orientation is vertical/if that check is necessary
|
||||
if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
|
||||
ColumnType column_type = static_cast<ColumnType>(section);
|
||||
|
||||
// Return the name based on the column's current type
|
||||
switch (column_type) {
|
||||
case k_name:
|
||||
return tr("Name");
|
||||
case k_duration:
|
||||
return tr("Duration");
|
||||
case k_rate:
|
||||
return tr("Rate");
|
||||
case k_last_modified:
|
||||
return tr("Modified");
|
||||
case k_created_time:
|
||||
return tr("Created");
|
||||
case k_column_count:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return QAbstractItemModel::headerData(section, orientation, role);
|
||||
}
|
||||
|
||||
bool ProjectViewModel::hasChildren(const QModelIndex &parent) const
|
||||
{
|
||||
// If it's a folder, we always return TRUE in order to always show the "expand triangle" icon,
|
||||
// even when there are no "physical" children
|
||||
Node *item = get_item_object_from_index(parent);
|
||||
|
||||
return dynamic_cast<Folder *>(item);
|
||||
}
|
||||
|
||||
bool ProjectViewModel::setData(const QModelIndex &index, const QVariant &value,
|
||||
int role)
|
||||
{
|
||||
// The name is editable
|
||||
if (index.isValid() && index.column() == k_name && role == Qt::EditRole) {
|
||||
Node *item = get_item_object_from_index(index);
|
||||
|
||||
QString new_name = value.toString();
|
||||
|
||||
if (!new_name.isEmpty()) {
|
||||
NodeRenameCommand *nrc = new NodeRenameCommand();
|
||||
|
||||
nrc->add_node(item, value.toString());
|
||||
|
||||
Core::instance()->undo_stack()->push(
|
||||
nrc, tr("Renamed Item \"%1\" to \"%2\"")
|
||||
.arg(item->get_label(), new_name));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ProjectViewModel::canFetchMore(const QModelIndex &parent) const
|
||||
{
|
||||
// Use the same hack that always returns true with folders so the expand triangle is always visible
|
||||
return hasChildren(parent);
|
||||
}
|
||||
|
||||
Qt::ItemFlags ProjectViewModel::flags(const QModelIndex &index) const
|
||||
{
|
||||
if (!index.isValid()) {
|
||||
// Allow dropping files from external sources
|
||||
return Qt::ItemIsDropEnabled;
|
||||
}
|
||||
|
||||
Qt::ItemFlags f = Qt::ItemIsDragEnabled | QAbstractItemModel::flags(index);
|
||||
|
||||
if (dynamic_cast<Folder *>(get_item_object_from_index(index))) {
|
||||
f |= Qt::ItemIsDropEnabled;
|
||||
}
|
||||
|
||||
// If the column is the kName column, that means it's editable
|
||||
if (index.column() == k_name) {
|
||||
f |= Qt::ItemIsEditable;
|
||||
}
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
QStringList ProjectViewModel::mimeTypes() const
|
||||
{
|
||||
// Allow data from this model and a file list from external sources
|
||||
return { Project::k_item_mime_type, QStringLiteral("text/uri-list") };
|
||||
}
|
||||
|
||||
QMimeData *ProjectViewModel::mimeData(const QModelIndexList &indexes) const
|
||||
{
|
||||
// Compliance with Qt standard
|
||||
if (indexes.isEmpty()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Encode mime data for the rows/items that were dragged
|
||||
QMimeData *data = new QMimeData();
|
||||
|
||||
// Use QDataStream to stream the item data into a byte array
|
||||
QByteArray encoded_data;
|
||||
QDataStream stream(&encoded_data, QIODevice::WriteOnly);
|
||||
|
||||
// The indexes list includes indexes for each column which we don't use. To make sure each row only gets sent *once*,
|
||||
// we keep a list of dragged items
|
||||
QVector<void *> dragged_items;
|
||||
|
||||
foreach (QModelIndex index, indexes) {
|
||||
if (index.isValid()) {
|
||||
// Check if we've dragged this item before
|
||||
if (!dragged_items.contains(index.internalPointer())) {
|
||||
// If not, add it to the stream (and also keep track of it in the vector)
|
||||
Node *item = static_cast<Node *>(index.internalPointer());
|
||||
QVector<Track::Reference> streams;
|
||||
|
||||
if (ViewerOutput *footage =
|
||||
dynamic_cast<ViewerOutput *>(item)) {
|
||||
streams = footage->get_enabled_streams_as_references();
|
||||
}
|
||||
|
||||
stream << streams << reinterpret_cast<quintptr>(item);
|
||||
|
||||
dragged_items.append(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Set byte array as the mime data and return the mime data
|
||||
data->setData(Project::k_item_mime_type, encoded_data);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
bool ProjectViewModel::dropMimeData(const QMimeData *data,
|
||||
Qt::DropAction action, int row, int column,
|
||||
const QModelIndex &drop)
|
||||
{
|
||||
// Default recommended checks from https://doc.qt.io/qt-5/model-view-programming.html#using-drag-and-drop-with-item-views
|
||||
if (!canDropMimeData(data, action, row, column, drop)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (action == Qt::IgnoreAction) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Probe mime data for its format
|
||||
QStringList mime_formats = data->formats();
|
||||
|
||||
if (mime_formats.contains(Project::k_item_mime_type)) {
|
||||
// Data is drag/drop data from this model
|
||||
QByteArray model_data = data->data(Project::k_item_mime_type);
|
||||
|
||||
// Use QDataStream to deserialize the data
|
||||
QDataStream stream(&model_data, QIODevice::ReadOnly);
|
||||
|
||||
// Get the Item object that the items were dropped on
|
||||
Folder *drop_location =
|
||||
dynamic_cast<Folder *>(get_item_object_from_index(drop));
|
||||
|
||||
// If this is not a folder, we cannot drop these items here
|
||||
if (!drop_location) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Variables to deserialize into
|
||||
quintptr item_ptr;
|
||||
QList<Track::Reference> streams;
|
||||
|
||||
// Loop through all data
|
||||
MultiUndoCommand *move_command = new MultiUndoCommand();
|
||||
|
||||
int count = 0;
|
||||
|
||||
while (!stream.atEnd()) {
|
||||
stream >> streams >> item_ptr;
|
||||
|
||||
Node *item = reinterpret_cast<Node *>(item_ptr);
|
||||
|
||||
// Check if Item is already the drop location or if its parent is the drop location, in which case this is a
|
||||
// no-op
|
||||
|
||||
if (item != drop_location && item->folder() != drop_location &&
|
||||
(!dynamic_cast<Folder *>(item) ||
|
||||
!item_is_parent_of_child(static_cast<Folder *>(item),
|
||||
drop_location))) {
|
||||
move_command->add_child(new NodeEdgeRemoveCommand(
|
||||
item,
|
||||
NodeInput(item->folder(), Folder::k_child_input,
|
||||
item->folder()->index_of_child_in_array(item))));
|
||||
move_command->add_child(
|
||||
new FolderAddChild(drop_location, item));
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
Core::instance()->undo_stack()->push(move_command,
|
||||
tr("Move %1 Item(s)").arg(count));
|
||||
|
||||
return true;
|
||||
|
||||
} else if (mime_formats.contains(QStringLiteral("text/uri-list"))) {
|
||||
// We received a list of files
|
||||
QByteArray file_data = data->data(QStringLiteral("text/uri-list"));
|
||||
|
||||
// Use text stream to parse (just an easy way of sifting through line breaks
|
||||
QTextStream stream(&file_data);
|
||||
|
||||
// Convert QByteArray to QStringList (which Core takes for importing)
|
||||
QStringList urls;
|
||||
while (!stream.atEnd()) {
|
||||
QUrl url = stream.readLine();
|
||||
|
||||
if (!url.isEmpty()) {
|
||||
urls.append(url.toLocalFile());
|
||||
}
|
||||
}
|
||||
|
||||
// Get folder dropped onto
|
||||
Node *drop_item = get_item_object_from_index(drop);
|
||||
|
||||
// If we didn't drop onto an item, find the nearest parent folder (should eventually terminate at root either way)
|
||||
if (!dynamic_cast<Folder *>(drop_item)) {
|
||||
drop_item = drop_item->folder();
|
||||
|
||||
if (!drop_item) {
|
||||
// Failed to find folder to place this in
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Trigger an import
|
||||
Core::instance()->import_files(urls, static_cast<Folder *>(drop_item));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
int ProjectViewModel::index_of_child(Node *item) const
|
||||
{
|
||||
// Find parent's index within its own parent
|
||||
Folder *parent = item->folder();
|
||||
|
||||
if (parent) {
|
||||
return parent->index_of_child(item);
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
Node *ProjectViewModel::get_item_object_from_index(const QModelIndex &index) const
|
||||
{
|
||||
if (index.isValid()) {
|
||||
return static_cast<Node *>(index.internalPointer());
|
||||
}
|
||||
|
||||
return project_ ? project_->root() : nullptr;
|
||||
}
|
||||
|
||||
bool ProjectViewModel::item_is_parent_of_child(Folder *parent, Node *child) const
|
||||
{
|
||||
// Loop through parent hierarchy checking if `parent` is one of its parents
|
||||
do {
|
||||
child = child->folder();
|
||||
|
||||
if (parent == child) {
|
||||
return true;
|
||||
}
|
||||
} while (child != nullptr);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void ProjectViewModel::connect_item(Node *n)
|
||||
{
|
||||
connect(n, &Node::label_changed, this, &ProjectViewModel::item_renamed);
|
||||
|
||||
Folder *f = dynamic_cast<Folder *>(n);
|
||||
if (f) {
|
||||
connect(f, &Folder::begin_insert_item, this,
|
||||
&ProjectViewModel::folder_begin_insert_item);
|
||||
connect(f, &Folder::end_insert_item, this,
|
||||
&ProjectViewModel::folder_end_insert_item);
|
||||
connect(f, &Folder::begin_remove_item, this,
|
||||
&ProjectViewModel::folder_begin_remove_item);
|
||||
connect(f, &Folder::end_remove_item, this,
|
||||
&ProjectViewModel::folder_end_remove_item);
|
||||
|
||||
foreach (Node *c, f->children()) {
|
||||
connect_item(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ProjectViewModel::disconnect_item(Node *n)
|
||||
{
|
||||
disconnect(n, &Node::label_changed, this, &ProjectViewModel::item_renamed);
|
||||
|
||||
Folder *f = dynamic_cast<Folder *>(n);
|
||||
if (f) {
|
||||
disconnect(f, &Folder::begin_insert_item, this,
|
||||
&ProjectViewModel::folder_begin_insert_item);
|
||||
disconnect(f, &Folder::end_insert_item, this,
|
||||
&ProjectViewModel::folder_end_insert_item);
|
||||
disconnect(f, &Folder::begin_remove_item, this,
|
||||
&ProjectViewModel::folder_begin_remove_item);
|
||||
disconnect(f, &Folder::end_remove_item, this,
|
||||
&ProjectViewModel::folder_end_remove_item);
|
||||
|
||||
foreach (Node *c, f->children()) {
|
||||
disconnect_item(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ProjectViewModel::folder_begin_insert_item(Node *n, int insert_index)
|
||||
{
|
||||
Folder *folder = static_cast<Folder *>(sender());
|
||||
|
||||
connect_item(n);
|
||||
|
||||
QModelIndex index;
|
||||
|
||||
if (folder != project_->root()) {
|
||||
index = create_index_from_item(folder);
|
||||
}
|
||||
|
||||
beginInsertRows(index, insert_index, insert_index);
|
||||
}
|
||||
|
||||
void ProjectViewModel::folder_end_insert_item()
|
||||
{
|
||||
endInsertRows();
|
||||
}
|
||||
|
||||
void ProjectViewModel::folder_begin_remove_item(Node *n, int child_index)
|
||||
{
|
||||
Folder *folder = static_cast<Folder *>(sender());
|
||||
|
||||
disconnect_item(n);
|
||||
|
||||
QModelIndex index;
|
||||
|
||||
if (folder != project_->root()) {
|
||||
index = create_index_from_item(folder);
|
||||
}
|
||||
|
||||
beginRemoveRows(index, child_index, child_index);
|
||||
}
|
||||
|
||||
void ProjectViewModel::folder_end_remove_item()
|
||||
{
|
||||
endRemoveRows();
|
||||
}
|
||||
|
||||
void ProjectViewModel::item_renamed()
|
||||
{
|
||||
Node *item = static_cast<Node *>(sender());
|
||||
|
||||
QModelIndex index = create_index_from_item(item);
|
||||
|
||||
emit dataChanged(index, index, { Qt::DisplayRole, Qt::EditRole });
|
||||
}
|
||||
|
||||
QModelIndex ProjectViewModel::create_index_from_item(Node *item, int column)
|
||||
{
|
||||
return createIndex(index_of_child(item), column, item);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,176 @@
|
||||
/***
|
||||
|
||||
Olive - Non-Linear Video Editor
|
||||
Copyright (C) 2022 Olive Team
|
||||
Modifications Copyright (C) 2025 mikesolar
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
***/
|
||||
|
||||
#ifndef OAK_VIEWMODEL_H
|
||||
#define OAK_VIEWMODEL_H
|
||||
|
||||
#include <QAbstractItemModel>
|
||||
|
||||
#include "node/block/block.h"
|
||||
#include "node/project.h"
|
||||
#include "undo/undocommand.h"
|
||||
|
||||
namespace olive
|
||||
{
|
||||
|
||||
/**
|
||||
* @brief An adapter that interprets the data in a Project into a Qt item model for usage in ViewModel Views.
|
||||
*
|
||||
* Assuming a Project is currently "open" (i.e. the Project is connected to a ProjectExplorer/ProjectPanel through
|
||||
* a ProjectViewModel), it may be better to make modifications (e.g. additions/removals/renames) through the
|
||||
* ProjectViewModel so that the views can be efficiently and correctly updated. ProjectViewModel contains several
|
||||
* "wrapper" functions for Project and Item functions that also signal any connected views to update accordingly.
|
||||
*/
|
||||
class ProjectViewModel : public QAbstractItemModel {
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum ColumnType {
|
||||
/// Media name
|
||||
k_name,
|
||||
|
||||
/// Media duration
|
||||
k_duration,
|
||||
|
||||
/// Media rate (frame rate for video, sample rate for audio)
|
||||
k_rate,
|
||||
|
||||
/// Last modified time (for footage/files)
|
||||
k_last_modified,
|
||||
|
||||
/// Creation time (for footage/files)
|
||||
k_created_time,
|
||||
|
||||
/// Count
|
||||
k_column_count
|
||||
};
|
||||
|
||||
static const int k_inner_text_role = Qt::UserRole + 1;
|
||||
|
||||
/**
|
||||
* @brief ProjectViewModel Constructor
|
||||
*
|
||||
* @param parent
|
||||
* Parent object for memory handling
|
||||
*/
|
||||
ProjectViewModel(QObject *parent);
|
||||
|
||||
/**
|
||||
* @brief Get currently active project
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* Currently active project or nullptr if there is none
|
||||
*/
|
||||
Project *project() const;
|
||||
|
||||
/**
|
||||
* @brief Set the project to adapt
|
||||
*
|
||||
* Any views attached to this model will get updated by this function.
|
||||
*
|
||||
* @param p
|
||||
*
|
||||
* Project to adapt, can be set to nullptr to "close" the project (will show an empty model that cannot be modified)
|
||||
*/
|
||||
void set_project(Project *p);
|
||||
|
||||
/** Compulsory Qt QAbstractItemModel overrides */
|
||||
virtual QModelIndex
|
||||
index(int row, int column,
|
||||
const QModelIndex &parent = QModelIndex()) const override;
|
||||
virtual QModelIndex parent(const QModelIndex &child) const override;
|
||||
virtual int
|
||||
rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
virtual int
|
||||
columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
virtual QVariant data(const QModelIndex &index,
|
||||
int role = Qt::DisplayRole) const override;
|
||||
|
||||
/** Optional Qt QAbstractItemModel overrides */
|
||||
virtual QVariant headerData(int section, Qt::Orientation orientation,
|
||||
int role = Qt::DisplayRole) const override;
|
||||
virtual bool
|
||||
hasChildren(const QModelIndex &parent = QModelIndex()) const override;
|
||||
virtual bool setData(const QModelIndex &index, const QVariant &value,
|
||||
int role = Qt::EditRole) override;
|
||||
virtual bool canFetchMore(const QModelIndex &parent) const override;
|
||||
|
||||
/** Drag and drop support */
|
||||
virtual Qt::ItemFlags flags(const QModelIndex &index) const override;
|
||||
virtual QStringList mimeTypes() const override;
|
||||
virtual QMimeData *mimeData(const QModelIndexList &indexes) const override;
|
||||
virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action,
|
||||
int row, int column,
|
||||
const QModelIndex &parent) override;
|
||||
|
||||
/**
|
||||
* @brief Convenience function for creating QModelIndexes from an Item object
|
||||
*/
|
||||
QModelIndex create_index_from_item(Node *item, int column = 0);
|
||||
|
||||
private:
|
||||
/**
|
||||
* @brief Retrieve the index of `item` in its parent
|
||||
*
|
||||
* This function will return the index of a specified item in its parent according to whichever sorting algorithm
|
||||
* is currently active.
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* Index of the specified item, or -1 if the item is root (in which case it has no parent).
|
||||
*/
|
||||
int index_of_child(Node *item) const;
|
||||
|
||||
/**
|
||||
* @brief Retrieves the Item object from a given index
|
||||
*
|
||||
* A convenience function for retrieving Item objects. If the index is not valid, this returns the root Item.
|
||||
*/
|
||||
Node *get_item_object_from_index(const QModelIndex &index) const;
|
||||
|
||||
/**
|
||||
* @brief Check if an Item is a parent of a Child
|
||||
*
|
||||
* Checks entire "parent hierarchy" of `child` to see if `parent` is one of its parents.
|
||||
*/
|
||||
bool item_is_parent_of_child(Folder *parent, Node *child) const;
|
||||
|
||||
void connect_item(Node *n);
|
||||
|
||||
void disconnect_item(Node *n);
|
||||
|
||||
Project *project_;
|
||||
|
||||
private slots:
|
||||
void folder_begin_insert_item(Node *n, int insert_index);
|
||||
|
||||
void folder_end_insert_item();
|
||||
|
||||
void folder_begin_remove_item(Node *n, int child_index);
|
||||
|
||||
void folder_end_remove_item();
|
||||
|
||||
void item_renamed();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // OAK_VIEWMODEL_H
|
||||
Reference in New Issue
Block a user