-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Drawpile 2.1 animation import
Imports an ORA file and reconstitutes it like Drawpile 2.1 would have animated it. Fixed layers get turned into tracks with a single frame at the beginning, layers get put into groups and put on matching tracks. Usually an animation will have one such group and track, unless fixed layers are used in the middle, in which case they get split up into multiple tracks so that the layering works correctly. This doesn't check if the ORA file being imported actually came from Drawpile 2.1, since it doesn't matter for the functionality.
- Loading branch information
1 parent
8f57c87
commit 6d03997
Showing
41 changed files
with
3,148 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
extern "C" { | ||
#include <dpengine/canvas_state.h> | ||
} | ||
#include "desktop/dialogs/animationimportdialog.h" | ||
#include "desktop/filewrangler.h" | ||
#include "desktop/utils/widgetutils.h" | ||
#include "libclient/import/animationimporter.h" | ||
#include <QApplication> | ||
#include <QDialogButtonBox> | ||
#include <QFormLayout> | ||
#include <QHBoxLayout> | ||
#include <QIcon> | ||
#include <QLineEdit> | ||
#include <QMessageBox> | ||
#include <QPushButton> | ||
#include <QSpinBox> | ||
#include <QThreadPool> | ||
#include <QVBoxLayout> | ||
|
||
namespace dialogs { | ||
|
||
AnimationImportDialog::AnimationImportDialog(QWidget *parent) | ||
: QDialog(parent) | ||
{ | ||
setModal(true); | ||
setWindowTitle(tr("Import Animation")); | ||
resize(600, 200); | ||
|
||
QVBoxLayout *layout = new QVBoxLayout; | ||
setLayout(layout); | ||
|
||
QFormLayout *form = new QFormLayout; | ||
layout->addLayout(form); | ||
|
||
QHBoxLayout *pathLayout = new QHBoxLayout; | ||
form->addRow(tr("File to Import:"), pathLayout); | ||
|
||
m_pathEdit = new QLineEdit; | ||
pathLayout->addWidget(m_pathEdit); | ||
|
||
m_chooseButton = new QPushButton(tr("Choose")); | ||
pathLayout->addWidget(m_chooseButton); | ||
connect( | ||
m_chooseButton, &QAbstractButton::clicked, this, | ||
&AnimationImportDialog::chooseFile); | ||
|
||
m_holdTime = new QSpinBox; | ||
m_holdTime->setRange(1, 99); | ||
m_holdTime->setValue(1); | ||
//: How many frames each imported key frame gets in the timeline. | ||
form->addRow(tr("Key frame length:"), m_holdTime); | ||
updateHoldTimeSuffix(m_holdTime->value()); | ||
connect( | ||
m_holdTime, QOverload<int>::of(&QSpinBox::valueChanged), this, | ||
&AnimationImportDialog::updateHoldTimeSuffix); | ||
|
||
m_framerate = new QSpinBox; | ||
m_framerate->setRange(1, 999); | ||
m_framerate->setValue(24); | ||
form->addRow(tr("Framerate:"), m_framerate); | ||
|
||
layout->addStretch(); | ||
|
||
m_buttons = new QDialogButtonBox(QDialogButtonBox::Cancel); | ||
layout->addWidget(m_buttons); | ||
connect(m_buttons, &QDialogButtonBox::rejected, this, &QDialog::reject); | ||
|
||
m_importButton = | ||
m_buttons->addButton(tr("Import"), QDialogButtonBox::ActionRole); | ||
m_importButton->setIcon(QIcon::fromTheme("document-import")); | ||
connect( | ||
m_buttons, &QDialogButtonBox::clicked, this, | ||
&AnimationImportDialog::buttonClicked); | ||
connect( | ||
m_pathEdit, &QLineEdit::textChanged, this, | ||
&AnimationImportDialog::updateImportButton); | ||
updateImportButton(m_pathEdit->text()); | ||
} | ||
|
||
AnimationImportDialog::~AnimationImportDialog() | ||
{ | ||
if(!isEnabled()) { | ||
QApplication::restoreOverrideCursor(); | ||
} | ||
} | ||
|
||
void AnimationImportDialog::chooseFile() | ||
{ | ||
QString path = FileWrangler(this).getOpenOraPath(); | ||
if(!path.isEmpty()) { | ||
m_pathEdit->setText(path); | ||
} | ||
} | ||
|
||
void AnimationImportDialog::updateHoldTimeSuffix(int value) | ||
{ | ||
m_holdTime->setSuffix(tr(" frame(s)", "", value)); | ||
} | ||
|
||
void AnimationImportDialog::updateImportButton(const QString &path) | ||
{ | ||
m_importButton->setEnabled(!path.trimmed().isEmpty()); | ||
} | ||
|
||
void AnimationImportDialog::buttonClicked(QAbstractButton *button) | ||
{ | ||
if(button == m_importButton) { | ||
runImport(); | ||
} | ||
} | ||
|
||
void AnimationImportDialog::importFinished( | ||
DP_CanvasState *cs, const QString &error) | ||
{ | ||
if(cs) { | ||
emit canvasStateImported(cs); | ||
} else { | ||
QApplication::restoreOverrideCursor(); | ||
QMessageBox::critical(this, tr("Animation Import Error"), error); | ||
setEnabled(true); | ||
} | ||
} | ||
|
||
void AnimationImportDialog::runImport() | ||
{ | ||
if(isEnabled()) { | ||
impex::AnimationImporter *importer = new impex::AnimationImporter( | ||
m_pathEdit->text().trimmed(), m_holdTime->value(), | ||
m_framerate->value()); | ||
connect( | ||
importer, &impex::AnimationImporter::finished, this, | ||
&AnimationImportDialog::importFinished); | ||
QThreadPool::globalInstance()->start(importer); | ||
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); | ||
setEnabled(false); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
#ifndef DESKTOP_DIALOGS_ANIMATIONIMPORTDIALOG | ||
#define DESKTOP_DIALOGS_ANIMATIONIMPORTDIALOG | ||
#include "libclient/drawdance/canvasstate.h" | ||
#include <QDialog> | ||
|
||
class QAbstractButton; | ||
class QDialogButtonBox; | ||
class QLineEdit; | ||
class QPushButton; | ||
class QSpinBox; | ||
struct DP_CanvasState; | ||
|
||
namespace dialogs { | ||
|
||
class AnimationImportDialog final : public QDialog { | ||
Q_OBJECT | ||
public: | ||
explicit AnimationImportDialog(QWidget *parent = nullptr); | ||
~AnimationImportDialog() override; | ||
|
||
signals: | ||
void canvasStateImported(DP_CanvasState *cs); | ||
|
||
private slots: | ||
void chooseFile(); | ||
void updateHoldTimeSuffix(int value); | ||
void updateImportButton(const QString &path); | ||
void buttonClicked(QAbstractButton *button); | ||
void importFinished(DP_CanvasState *cs, const QString &error); | ||
|
||
private: | ||
QLineEdit *m_pathEdit; | ||
QPushButton *m_chooseButton; | ||
QSpinBox *m_holdTime; | ||
QSpinBox *m_framerate; | ||
QDialogButtonBox *m_buttons; | ||
QPushButton *m_importButton; | ||
|
||
void runImport(); | ||
}; | ||
|
||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.