17#include "importlayersdialog.h"
18#include "ui_importlayersdialog.h"
20#include <QProgressDialog>
23#include "filemanager.h"
24#include "filedialog.h"
25#include "fileformat.h"
26#include "layermanager.h"
27#include "soundmanager.h"
29#include "layersound.h"
30#include "layervector.h"
34ImportLayersDialog::ImportLayersDialog(
QWidget *parent) :
44 ui->btnImportLayers->setEnabled(
false);
46 hideQuestionMark(*
this);
49ImportLayersDialog::~ImportLayersDialog()
54void ImportLayersDialog::setCore(
Editor *editor)
59void ImportLayersDialog::getFileName()
62 ui->lwLayers->clear();
64 if (mFileName.
isEmpty()) {
return; }
68void ImportLayersDialog::listWidgetChanged()
70 mItemsSelected.
clear();
71 for (
int i = 0; i < ui->lwLayers->count(); i++)
72 if (ui->lwLayers->item(i)->isSelected())
76 ui->btnImportLayers->setEnabled(
true);
78 ui->btnImportLayers->setEnabled(
false);
81void ImportLayersDialog::importLayers()
83 Object*
object = mEditor->object();
84 int currentFrame = mEditor->currentFrame();
85 Q_ASSERT(ui->lwLayers->count() == mImportObject->getLayerCount());
91 mImportLayer = mImportObject->takeLayer(item->data(
Qt::UserRole).toInt());
92 mImportLayer->setName(mEditor->layers()->nameSuggestLayer(item->text()));
93 loadKeyFrames(mImportLayer);
95 object->addLayer(mImportLayer);
97 if (mImportLayer->type() == Layer::VECTOR)
100 for (
int i = 0; i < mImportObject->getColorCount(); i++) {
101 if (!layerVector->usesColor(i)) {
106 const ColorRef color = mImportObject->getColor(i);
107 object->addColor(color);
108 importedColors[i] =
object->getColorCount() - 1;
111 layerVector->moveColor(i, importedColors[i]);
115 if (mImportLayer->type() == Layer::SOUND)
118 layerSound->foreachKeyFrame([
this](
KeyFrame* key)
121 Status st = mEditor->sound()->loadSound(clip, clip->fileName());
126 mEditor->object()->modification();
128 mImportObject.reset();
130 mEditor->scrubTo(currentFrame);
133void ImportLayersDialog::cancel()
138void ImportLayersDialog::getLayers()
145 hideQuestionMark(progress);
151 connect(&fm, &FileManager::progressChanged, [&progress](
int p)
153 progress.setValue(p);
156 connect(&fm, &FileManager::progressRangeChanged, [&progress](
int max)
158 progress.setRange(0, max + 3);
160 mImportObject.reset(fm.load(mFileName));
162 ui->lwLayers->clear();
163 for (
int i = 0; i < mImportObject->getLayerCount(); i++)
165 const QString layerName = mImportObject->getLayer(i)->name();
166 const int layerId = mImportObject->getLayer(i)->id();
171 ui->lwLayers->addItem(item);
175void ImportLayersDialog::loadKeyFrames(
Layer* importedLayer)
180 importedLayer->foreachKeyFrame([](
KeyFrame* k)
static QString getOpenFileName(QWidget *parent, FileType fileType, const QString &caption=QString())
Shows a file dialog which allows the user to select a file to open.
void processEvents(QEventLoop::ProcessEventsFlags flags)
void append(const T &value)
bool isEmpty() const const
bool contains(const Key &key) const const
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QString tr(const char *sourceText, const char *disambiguation, int n)
bool isEmpty() const const