-
Notifications
You must be signed in to change notification settings - Fork 279
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1261 from davidlamhauge/layer_import
Layer import, from *.pclx to active project
- Loading branch information
Showing
9 changed files
with
283 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
#include "importlayersdialog.h" | ||
#include "ui_importlayersdialog.h" | ||
|
||
#include <QFileDialog> | ||
#include <QProgressDialog> | ||
|
||
#include "app_util.h" | ||
#include "filemanager.h" | ||
#include "filedialogex.h" | ||
#include "layermanager.h" | ||
#include "soundmanager.h" | ||
#include "layer.h" | ||
#include "layersound.h" | ||
#include "soundclip.h" | ||
|
||
|
||
ImportLayersDialog::ImportLayersDialog(QWidget *parent) : | ||
QDialog(parent), | ||
ui(new Ui::ImportLayersDialog) | ||
{ | ||
ui->setupUi(this); | ||
connect(ui->btnSelectFile, &QPushButton::clicked, this, &ImportLayersDialog::getFileName); | ||
connect(ui->btnImportLayers, &QPushButton::clicked, this, &ImportLayersDialog::importLayers); | ||
connect(ui->lwLayers, &QListWidget::itemSelectionChanged, this, &ImportLayersDialog::listWidgetChanged); | ||
connect(ui->btnClose, &QPushButton::clicked, this, &ImportLayersDialog::cancel); | ||
ui->lwLayers->setSelectionMode(QAbstractItemView::ExtendedSelection); | ||
ui->btnImportLayers->setEnabled(false); | ||
} | ||
|
||
ImportLayersDialog::~ImportLayersDialog() | ||
{ | ||
delete ui; | ||
} | ||
|
||
void ImportLayersDialog::setCore(Editor *editor) | ||
{ | ||
mEditor = editor; | ||
mObject = mEditor->object(); | ||
} | ||
|
||
void ImportLayersDialog::getFileName() | ||
{ | ||
mFileName.clear(); | ||
ui->lwLayers->clear(); | ||
FileDialog fd(this); | ||
mFileName = QFileDialog::getOpenFileName(this, tr("Choose file"), | ||
fd.getLastOpenPath(FileType::ANIMATION), | ||
tr("Pencil Animation file (*.pclx)")); | ||
if (mFileName.isEmpty()) { return; } | ||
getLayers(); | ||
for (int i = 0; i < mImportObject->getLayerCount(); i++) | ||
ui->lwLayers->addItem(mImportObject->getLayer(i)->name()); | ||
} | ||
|
||
void ImportLayersDialog::listWidgetChanged() | ||
{ | ||
if (ui->lwLayers->count() > 0) | ||
ui->btnImportLayers->setEnabled(true); | ||
else | ||
ui->btnImportLayers->setEnabled(false); | ||
} | ||
|
||
void ImportLayersDialog::importLayers() | ||
{ | ||
int currentFrame = mEditor->currentFrame(); | ||
for (int i = 0; i < mImportObject->getLayerCount(); i++ ) | ||
{ | ||
if (ui->lwLayers->item(i)->isSelected()) | ||
{ | ||
Layer *tmpLayer = mImportObject->findLayerByName(ui->lwLayers->item(i)->text()); | ||
if (tmpLayer->type() == Layer::SOUND) | ||
{ | ||
LayerSound* layerSound = static_cast<LayerSound*>(tmpLayer); | ||
int count = 0; | ||
while (count < layerSound->getNextKeyFramePosition(count)) | ||
{ | ||
int newKeyPos = layerSound->getNextKeyFramePosition(count); | ||
SoundClip* clip = new SoundClip; | ||
clip = layerSound->getSoundClipWhichCovers(newKeyPos); | ||
Status st = mEditor->sound()->loadSound(clip, clip->fileName()); | ||
count = newKeyPos; | ||
} | ||
mObject->addLayer(layerSound); | ||
} | ||
else | ||
{ | ||
mObject->addLayer(tmpLayer); | ||
} | ||
} | ||
} | ||
mEditor->scrubTo(currentFrame); | ||
} | ||
|
||
void ImportLayersDialog::cancel() | ||
{ | ||
close(); | ||
} | ||
|
||
void ImportLayersDialog::getLayers() | ||
{ | ||
QProgressDialog progress(tr("Opening document..."), tr("Abort"), 0, 100, this); | ||
|
||
// Don't show progress bar if running without a GUI (aka. when rendering from command line) | ||
if (isVisible()) | ||
{ | ||
hideQuestionMark(progress); | ||
progress.setWindowModality(Qt::WindowModal); | ||
progress.show(); | ||
} | ||
|
||
FileManager fm; | ||
connect(&fm, &FileManager::progressChanged, [&progress](int p) | ||
{ | ||
progress.setValue(p); | ||
QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); | ||
}); | ||
connect(&fm, &FileManager::progressRangeChanged, [&progress](int max) | ||
{ | ||
progress.setRange(0, max + 3); | ||
}); | ||
mImportObject = fm.load(mFileName); | ||
} |
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,39 @@ | ||
#ifndef IMPORTLAYERSDIALOG_H | ||
#define IMPORTLAYERSDIALOG_H | ||
|
||
#include <QDialog> | ||
#include "object.h" | ||
#include "editor.h" | ||
|
||
namespace Ui { | ||
class ImportLayersDialog; | ||
} | ||
|
||
class ImportLayersDialog : public QDialog | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
explicit ImportLayersDialog(QWidget *parent = nullptr); | ||
~ImportLayersDialog(); | ||
|
||
void setCore(Editor *editor); | ||
|
||
public slots: | ||
void getFileName(); | ||
void listWidgetChanged(); | ||
void importLayers(); | ||
void cancel(); | ||
|
||
private: | ||
Ui::ImportLayersDialog *ui; | ||
|
||
void getLayers(); | ||
|
||
Object *mObject = nullptr; | ||
Object *mImportObject = nullptr; | ||
Editor *mEditor = nullptr; | ||
QString mFileName = ""; | ||
}; | ||
|
||
#endif // IMPORTLAYERSDIALOG_H |
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,93 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ui version="4.0"> | ||
<class>ImportLayersDialog</class> | ||
<widget class="QDialog" name="ImportLayersDialog"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>0</x> | ||
<y>0</y> | ||
<width>400</width> | ||
<height>267</height> | ||
</rect> | ||
</property> | ||
<property name="windowTitle"> | ||
<string>Import Layers from other *.pclx files</string> | ||
</property> | ||
<layout class="QVBoxLayout" name="verticalLayout"> | ||
<item> | ||
<layout class="QHBoxLayout" name="horizontalLayout"> | ||
<item> | ||
<widget class="QLabel" name="labSelectFile"> | ||
<property name="text"> | ||
<string>1. Select PCLX file:</string> | ||
</property> | ||
</widget> | ||
</item> | ||
<item> | ||
<spacer name="horizontalSpacer"> | ||
<property name="orientation"> | ||
<enum>Qt::Horizontal</enum> | ||
</property> | ||
<property name="sizeHint" stdset="0"> | ||
<size> | ||
<width>40</width> | ||
<height>20</height> | ||
</size> | ||
</property> | ||
</spacer> | ||
</item> | ||
<item> | ||
<widget class="QPushButton" name="btnSelectFile"> | ||
<property name="text"> | ||
<string>Select File</string> | ||
</property> | ||
</widget> | ||
</item> | ||
</layout> | ||
</item> | ||
<item> | ||
<widget class="QLabel" name="labSelectLayers"> | ||
<property name="text"> | ||
<string>2. Select layers from file:</string> | ||
</property> | ||
</widget> | ||
</item> | ||
<item> | ||
<widget class="QListWidget" name="lwLayers"/> | ||
</item> | ||
<item> | ||
<layout class="QHBoxLayout" name="horizontalLayout_2"> | ||
<item> | ||
<spacer name="horizontalSpacer_2"> | ||
<property name="orientation"> | ||
<enum>Qt::Horizontal</enum> | ||
</property> | ||
<property name="sizeHint" stdset="0"> | ||
<size> | ||
<width>40</width> | ||
<height>20</height> | ||
</size> | ||
</property> | ||
</spacer> | ||
</item> | ||
<item> | ||
<widget class="QPushButton" name="btnClose"> | ||
<property name="text"> | ||
<string>Close</string> | ||
</property> | ||
</widget> | ||
</item> | ||
<item> | ||
<widget class="QPushButton" name="btnImportLayers"> | ||
<property name="text"> | ||
<string>Import layers</string> | ||
</property> | ||
</widget> | ||
</item> | ||
</layout> | ||
</item> | ||
</layout> | ||
</widget> | ||
<resources/> | ||
<connections/> | ||
</ui> |
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