Skip to content

Commit

Permalink
Fix LottieFile import
Browse files Browse the repository at this point in the history
  • Loading branch information
mbasaglia committed Oct 10, 2023
1 parent c9c6ce4 commit 6bc2289
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 95 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* The play button now resumes from the current frame rather than resetting to the start
* Fixed saving custom templates
* Toggling visibility / lock of a layer by clicking on its icon now adds an undo/redo action
* Fixed LottieFiles import

## 0.5.4

Expand Down
1 change: 1 addition & 0 deletions data/plugins/dotLottie/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
{
"type": "format",
"name": "dotLottie",
"slug": "dotlottie",
"extensions": ["lottie"],
"auto_open": false,
"open": {
Expand Down
2 changes: 2 additions & 0 deletions src/gui/widgets/dialogs/gw_impl_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1251,9 +1251,11 @@ void GlaxnimateWindow::Private::import_from_lottiefiles()
LottieFilesSearchDialog dialog;
if ( !dialog.exec() )
return;

io::Options options;
options.format = io::IoRegistry::instance().from_slug("lottie");
options.filename = dialog.selected_name() + ".json";

load_remote_document(dialog.selected_url(), options, dialog.result() == LottieFilesSearchDialog::Open);
}

Expand Down
139 changes: 71 additions & 68 deletions src/gui/widgets/lottiefiles/lottiefiles_search_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,39 +23,42 @@
class glaxnimate::gui::LottieFilesSearchDialog::Private
{
public:
void search(const QString& query, int page)
void search(const QString& query, const QString& page)
{
if ( query.isEmpty() )
featured(page);
else
search_query(query, page);
}

void search_query(const QString& query, int page)
void search_query(const QString& query, const QString& page)
{
static QString graphql_query = R"(
query Search($withAep: Boolean, $pageSize: Float, $page: Float, $query: String!)
query Search($withAep: Boolean, $pageSize: Int, $page: String, $query: String!)
{
search(withAep: $withAep, pageSize: $pageSize, page: $page, query: $query)
searchPublicAnimations(withAep: $withAep, first: $pageSize, after: $page, query: $query)
{
query,
currentPage,
totalPages,
results
{
bgColor,
id,
imageFrame,
imageUrl,
lottieUrl,
name,
url,
likesCount,
commentsCount,
createdBy {
username
edges {
node {
bgColor,
id,
imageFrame,
imageUrl,
jsonUrl,
name,
url,
likesCount,
commentsCount,
createdBy {
username
}
}
}
pageInfo {
endCursor
hasNextPage
}
totalCount
}
})";
QJsonObject vars;
Expand All @@ -65,42 +68,49 @@ class glaxnimate::gui::LottieFilesSearchDialog::Private
vars["query"] = query;

current_query = query;
previous_page = current_page;
current_page = page;

graphql.query(graphql_query, vars);
}

void featured(int page)
void featured(const QString& page)
{
static QString query = R"(
query Search($page: Float)
query Search($page: String, $pageSize: Int, $collectionId: Float!)
{
featured(page: $page)
publicCollectionAnimations(after: $page, first: $pageSize, collectionId: $collectionId)
{
query,
currentPage,
totalPages,
results
{
bgColor,
id,
imageFrame,
imageUrl,
lottieUrl,
name,
url,
likesCount,
commentsCount,
createdBy {
username
edges {
node {
bgColor,
id,
imageFrame,
imageUrl,
jsonUrl,
name,
url,
likesCount,
commentsCount,
createdBy {
username
}
}
}
pageInfo {
endCursor
hasNextPage
}
totalCount
}
})";
QJsonObject vars;
vars["page"] = page;
vars["pageSize"] = layout_rows * layout_columns;
vars["collectionId"] = 1318984.;

current_query = "";
previous_page = current_page;
current_page = page;

graphql.query(query, vars);
Expand Down Expand Up @@ -132,7 +142,7 @@ class glaxnimate::gui::LottieFilesSearchDialog::Private

auto d = response["data"].toObject();

if ( !response["data"].isObject() || (!d["search"].isObject() && !d["featured"].isObject()) )
if ( !response["data"].isObject() || (!d["searchPublicAnimations"].isObject() && !d["publicCollectionAnimations"].isObject()) )
{
if ( reply->error() )
{
Expand All @@ -157,42 +167,38 @@ class glaxnimate::gui::LottieFilesSearchDialog::Private
}

QJsonObject data;
if ( d["featured"].isObject() )
data = d["featured"].toObject();
if ( d["publicCollectionAnimations"].isObject() )
data = d["publicCollectionAnimations"].toObject();
else
data = d["search"].toObject();
data = d["searchPublicAnimations"].toObject();

current_query = data["query"].toString();
current_page = data["currentPage"].toInt();
max_pages = data["totalPages"].toInt();
clear_results();
auto qresults = data["results"].toArray();
auto qresults = data["edges"].toArray();
results.reserve(qresults.size());
for ( const auto& rev : qresults )
{
auto result = rev.toObject();
auto result = rev.toObject()["node"].toObject();
add_result({
result["id"].toInt(),
result["name"].toString(),
result["createdBy"].toObject()["username"].toString(),
result["url"].toString(),
result["imageUrl"].toString(),
result["lottieUrl"].toString(),
result["jsonUrl"].toString(),
QColor(result["bgColor"].toString()),
result["likesCount"].toInt(),
result["commentsCount"].toInt(),
});
}

ui.spin_page->setMaximum(max_pages);
ui.spin_page->setValue(current_page);
ui.label_page_count->setText(QString::number(max_pages));
auto page_info = data["pageInfo"].toObject();

if ( max_pages > 1 )
{
ui.spin_page->setEnabled(true);
ui.button_next->setEnabled(true);
}
next_page = page_info["endCursor"].toString();
if ( !page_info["hasNextPage"].toBool() )
next_page = "";

ui.button_next->setEnabled(!next_page.isEmpty());
ui.button_previous->setEnabled(!current_page.isEmpty());
}

void on_error(const QString& msg)
Expand All @@ -207,7 +213,6 @@ class glaxnimate::gui::LottieFilesSearchDialog::Private
ui.progress_bar->setMaximum(100);
ui.progress_bar->setValue(0);
ui.progress_bar->setVisible(true);
ui.spin_page->setEnabled(false);
ui.button_next->setEnabled(false);
}

Expand Down Expand Up @@ -269,15 +274,15 @@ class glaxnimate::gui::LottieFilesSearchDialog::Private
GraphQl graphql{"https://graphql.lottiefiles.com/"};
LottieFilesSearchDialog* dialog;
QString current_query;
int current_page = -1;
int max_pages = 0;
std::vector<std::unique_ptr<LottieFilesResultItem>> results;
QSize preview_size{200, 200};
int layout_columns = 4;
int layout_rows = 3;
QUrl current_url;
QString current_name;

QString previous_page;
QString current_page;
QString next_page;
};

glaxnimate::gui::LottieFilesSearchDialog::LottieFilesSearchDialog(QWidget* parent)
Expand All @@ -288,7 +293,7 @@ glaxnimate::gui::LottieFilesSearchDialog::LottieFilesSearchDialog(QWidget* paren
d->ui.progress_bar->setVisible(false);
d->clear_results();
d->ui.result_area->setMinimumWidth(d->preview_size.width() * d->layout_columns + 128);
d->featured(1);
d->featured("");

connect(&d->graphql, &GraphQl::query_started, this, [this]{d->start_load();});
connect(&d->graphql, &GraphQl::query_finished, this, [this](QNetworkReply* reply){d->on_response(reply);});
Expand Down Expand Up @@ -321,19 +326,17 @@ void glaxnimate::gui::LottieFilesSearchDialog::clicked_open()
void glaxnimate::gui::LottieFilesSearchDialog::clicked_search()
{
if ( d->current_query != d->ui.input_query->text() && d->ui.input_query->text().size() > 2 )
d->search(d->ui.input_query->text(), 1);
d->search(d->ui.input_query->text(), "");
}

void glaxnimate::gui::LottieFilesSearchDialog::clicked_next()
{
if ( d->ui.spin_page->value() < d->max_pages )
d->ui.spin_page->setValue(d->ui.spin_page->value() + 1);
d->search(d->current_query, d->next_page);
}

void glaxnimate::gui::LottieFilesSearchDialog::page_changed(int page)
void glaxnimate::gui::LottieFilesSearchDialog::clicked_previous()
{
if ( page != d->current_page && d->ui.spin_page->isEnabled() )
d->search(d->current_query, page);
d->search(d->current_query, d->previous_page);
}

const QUrl & glaxnimate::gui::LottieFilesSearchDialog::selected_url() const
Expand Down
2 changes: 1 addition & 1 deletion src/gui/widgets/lottiefiles/lottiefiles_search_dialog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ private slots:
void clicked_import();
void clicked_search();
void clicked_next();
void page_changed(int page);
void clicked_previous();

private:
class Private;
Expand Down
40 changes: 14 additions & 26 deletions src/gui/widgets/lottiefiles/lottiefiles_search_dialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ SPDX-License-Identifier: GPL-3.0-or-later
<string>Import From LottieFiles</string>
</property>
<property name="windowIcon">
<iconset theme="lottiefiles"/>
<iconset theme="lottiefiles">
<normaloff>.</normaloff>.</iconset>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
Expand Down Expand Up @@ -92,26 +93,12 @@ SPDX-License-Identifier: GPL-3.0-or-later
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="label">
<widget class="QPushButton" name="button_previous">
<property name="text">
<string>Page</string>
<string>Previous Page</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spin_page"/>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>of</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_page_count">
<property name="text">
<string notr="true">0</string>
<property name="icon">
<iconset theme="go-previous"/>
</property>
</widget>
</item>
Expand Down Expand Up @@ -276,18 +263,18 @@ SPDX-License-Identifier: GPL-3.0-or-later
</hints>
</connection>
<connection>
<sender>spin_page</sender>
<signal>valueChanged(int)</signal>
<sender>button_previous</sender>
<signal>clicked()</signal>
<receiver>LottieFilesSearchDialog</receiver>
<slot>page_changed(int)</slot>
<slot>clicked_previous()</slot>
<hints>
<hint type="sourcelabel">
<x>82</x>
<y>581</y>
<x>78</x>
<y>570</y>
</hint>
<hint type="destinationlabel">
<x>147</x>
<y>691</y>
<x>381</x>
<y>724</y>
</hint>
</hints>
</connection>
Expand All @@ -298,5 +285,6 @@ SPDX-License-Identifier: GPL-3.0-or-later
<slot>clicked_search()</slot>
<slot>clicked_next()</slot>
<slot>page_changed(int)</slot>
<slot>clicked_previous()</slot>
</slots>
</ui>

0 comments on commit 6bc2289

Please sign in to comment.