Skip to content

Commit

Permalink
Allow import image dialog multi select
Browse files Browse the repository at this point in the history
  • Loading branch information
mbasaglia committed Sep 16, 2023
1 parent 7a1657c commit 5e55f4b
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 29 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* Alt + click on keyframes cycles between built-in easing curves
* Alt + click on bezier points cycles between tangent symmetry modes (Ctrl+click still works)
* Changing a bezier point from corner to smooth will add tangents if they are missing
* The import image dialog now allows importing multiple images at once
* Misc:
* Switched to an even/odd version numbering scheme
* Bug Fixes:
Expand Down
2 changes: 1 addition & 1 deletion src/gui/widgets/dialogs/glaxnimate_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ void GlaxnimateWindow::switch_tool(tools::Tool* tool)

QString GlaxnimateWindow::get_open_image_file(const QString& title, const QString& dir) const
{
return d->get_open_image_file(title, dir);
return d->get_open_image_files(title, dir)[0];
}

model::BrushStyle * GlaxnimateWindow::linked_brush_style ( bool secondary ) const
Expand Down
2 changes: 1 addition & 1 deletion src/gui/widgets/dialogs/glaxnimate_window_p.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ class GlaxnimateWindow::Private
void status_message(const QString& msg, int duration=5000);
QVariant choose_option(const QString& label, const QVariantMap& options, const QString& title) const;
void set_color_def(model::BrushStyle* sty, bool secondary);
QString get_open_image_file(const QString& title, const QString& dir, QString* out_dir = nullptr);
QStringList get_open_image_files(const QString& title, const QString& dir, QString* out_dir = nullptr, bool multiple = false);
void set_brush_reference(model::BrushStyle* sty, bool secondary);
void trace_dialog(model::DocumentNode* object);
void mouse_moved(const QPointF& pos);
Expand Down
65 changes: 38 additions & 27 deletions src/gui/widgets/dialogs/gw_impl_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ void GlaxnimateWindow::Private::move_to()
}
}

QString GlaxnimateWindow::Private::get_open_image_file(const QString& title, const QString& dir, QString* out_dir)
QStringList GlaxnimateWindow::Private::get_open_image_files(const QString& title, const QString& dir, QString* out_dir, bool multiple)
{
QFileDialog dialog(parent, title, dir);
QStringList filters;
Expand All @@ -210,16 +210,20 @@ QString GlaxnimateWindow::Private::get_open_image_file(const QString& title, con
dialog.setNameFilters(filters);

dialog.setAcceptMode(QFileDialog::AcceptOpen);
dialog.setFileMode(QFileDialog::ExistingFile);
dialog.setOption(QFileDialog::DontUseNativeDialog, !app::settings::get<bool>("open_save", "native_dialog"));

if ( multiple )
dialog.setFileMode(QFileDialog::ExistingFiles);
else
dialog.setFileMode(QFileDialog::ExistingFile);

if ( dialog.exec() == QDialog::Rejected )
return {};

if ( out_dir )
*out_dir = dialog.directory().path();

return dialog.selectedFiles()[0];
return dialog.selectedFiles();
}


Expand All @@ -229,37 +233,44 @@ void GlaxnimateWindow::Private::import_image()
if ( path.isEmpty() )
path = current_document->io_options().path.absolutePath();

QString image_file = get_open_image_file(tr("Import Image"), path, &path);
if ( image_file.isEmpty() )
QStringList image_files = get_open_image_files(tr("Import Image"), path, &path, true);
if ( image_files.isEmpty() )
return;

app::settings::set("open_save", "import_path", path);

auto bitmap = std::make_unique<model::Bitmap>(current_document.get());
bitmap->filename.set(image_file);
if ( bitmap->pixmap().isNull() )
{
show_warning(tr("Import Image"), tr("Could not import image"));
return;
}
/// \todo dialog asking whether to embed

command::UndoMacroGuard macro(tr("Import Image"), current_document.get());

auto defs = current_document->assets();
auto bmp_ptr = bitmap.get();
current_document->push_command(new command::AddObject(&defs->images->values, std::move(bitmap), defs->images->values.size()));

auto image = std::make_unique<model::Image>(current_document.get());
image->image.set(bmp_ptr);
QPointF p(bmp_ptr->pixmap().width() / 2.0, bmp_ptr->pixmap().height() / 2.0);
image->transform->anchor_point.set(p);
image->transform->position.set(p);
auto comp = current_composition();
auto select = image.get();
image->name.set(QFileInfo(image_file).baseName());
current_document->push_command(new command::AddShape(&comp->shapes, std::move(image), comp->shapes.size()));
set_current_document_node(select);
model::Image* select = nullptr;

for ( const auto& image_file : image_files )
{
auto bitmap = std::make_unique<model::Bitmap>(current_document.get());
bitmap->filename.set(image_file);
if ( bitmap->pixmap().isNull() )
{
show_warning(tr("Import Image"), tr("Could not import image"));
continue;
}

auto defs = current_document->assets();
auto bmp_ptr = bitmap.get();
current_document->push_command(new command::AddObject(&defs->images->values, std::move(bitmap), defs->images->values.size()));

auto image = std::make_unique<model::Image>(current_document.get());
image->image.set(bmp_ptr);
QPointF p(bmp_ptr->pixmap().width() / 2.0, bmp_ptr->pixmap().height() / 2.0);
image->transform->anchor_point.set(p);
image->transform->position.set(p);
auto comp = current_composition();
select = image.get();
image->name.set(QFileInfo(image_file).baseName());
current_document->push_command(new command::AddShape(&comp->shapes, std::move(image), comp->shapes.size()));
}

if ( select )
set_current_document_node(select);
}

template<class T>
Expand Down

0 comments on commit 5e55f4b

Please sign in to comment.