Commit f6df2d2c authored by Jouni Pentikäinen's avatar Jouni Pentikäinen

Add a dialog to image sequence import

parent 5666bac8
......@@ -62,6 +62,7 @@ set(kritaui_LIB_SRCS
dialogs/kis_dlg_blacklist_cleanup.cpp
dialogs/kis_dlg_layer_style.cpp
dialogs/kis_dlg_png_import.cpp
dialogs/kis_dlg_import_image_sequence.cpp
flake/kis_node_dummies_graph.cpp
flake/kis_dummies_facade_base.cpp
flake/kis_dummies_facade.cpp
......@@ -431,6 +432,7 @@ ki18n_wrap_ui(kritaui_LIB_SRCS
forms/wdgpresetselectorstrip.ui
forms/wdgdlgblacklistcleanup.ui
forms/wdgrectangleconstraints.ui
forms/wdgimportimagesequence.ui
forms/KisDetailsPaneBase.ui
forms/KisOpenPaneBase.ui
input/config/kis_input_configuration_page.ui
......
......@@ -120,6 +120,7 @@
#include "kis_resource_server_provider.h"
#ifdef HAVE_OPENGL
#include "kis_animation_importer.h"
#include "dialogs/kis_dlg_import_image_sequence.h"
#include "kis_animation_exporter.h"
#endif
#include "kis_icon_utils.h"
......@@ -1558,10 +1559,18 @@ void KisMainWindow::importAnimation()
KisDocument *document = activeView()->document();
if (!document) return;
KisAnimationImporterUI importer(this);
importer.importSequence(document);
KisDlgImportImageSequence dlg(this, document);
activeView()->canvasBase()->refetchDataFromImage();
if (dlg.exec() == QDialog::Accepted) {
QStringList files = dlg.files();
int firstFrame = dlg.firstFrame();
int step = dlg.step();
KisAnimationImporter importer(document->image());
importer.import(files, firstFrame, step);
activeView()->canvasBase()->refetchDataFromImage();
}
#endif
}
......
/*
* Copyright (c) 2016 Jouni Pentikäinen <joupent@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "kis_dlg_import_image_sequence.h"
#include "KisDocument.h"
#include "KisMainWindow.h"
#include "kis_image.h"
#include "kis_image_animation_interface.h"
class KisDlgImportImageSequence::ListItem : QListWidgetItem {
public:
ListItem(const QString &text, QListWidget *view, QCollator *collator)
: QListWidgetItem(text, view),
collator(collator)
{}
bool operator <(const QListWidgetItem &other) const
{
int cmp = collator->compare(this->text(), other.text());
return cmp < 0;
}
private:
QCollator *collator;
};
KisDlgImportImageSequence::KisDlgImportImageSequence(KisMainWindow *mainWindow, KisDocument *document) :
KoDialog(mainWindow),
mainWindow(mainWindow),
document(document)
{
setButtons(Ok | Cancel);
setDefaultButton(Ok);
QWidget * page = new QWidget(this);
ui.setupUi(page);
setMainWidget(page);
enableButtonOk(false);
ui.cmbOrder->addItem(i18n("Ascending"), Ascending);
ui.cmbOrder->addItem(i18n("Descencing"), Descending);
ui.cmbOrder->setCurrentIndex(0);
ui.cmbSortMode->addItem(i18n("Alphabetical"), Natural);
ui.cmbSortMode->addItem(i18n("Numerical"), Numerical);
ui.cmbSortMode->setCurrentIndex(1);
ui.lstFiles->setSelectionMode(QAbstractItemView::ExtendedSelection);
connect(ui.btnAddImages, &QAbstractButton::clicked, this, &KisDlgImportImageSequence::slotAddFiles);
connect(ui.btnRemove, &QAbstractButton::clicked, this, &KisDlgImportImageSequence::slotRemoveFiles);
connect(ui.spinStep, SIGNAL(valueChanged(int)), this, SLOT(slotSkipChanged(int)));
connect(ui.cmbOrder, SIGNAL(currentIndexChanged(int)), this, SLOT(slotOrderOptionsChanged(int)));
connect(ui.cmbSortMode, SIGNAL(currentIndexChanged(int)), this, SLOT(slotOrderOptionsChanged(int)));
}
QStringList KisDlgImportImageSequence::files()
{
QStringList list;
for (int i=0; i < ui.lstFiles->count(); i++) {
list.append(ui.lstFiles->item(i)->text());
}
return list;
}
int KisDlgImportImageSequence::firstFrame()
{
return ui.spinFirstFrame->value();
}
int KisDlgImportImageSequence::step()
{
return ui.spinStep->value();
}
void KisDlgImportImageSequence::slotAddFiles()
{
QStringList urls = mainWindow->showOpenFileDialog();
if (!urls.isEmpty()) {
Q_FOREACH(QString url, urls) {
new ListItem(url, ui.lstFiles, &collator);
}
sortFileList();
}
enableButtonOk(ui.lstFiles->count() > 0);
}
void KisDlgImportImageSequence::slotRemoveFiles()
{
QList<QListWidgetItem*> selected = ui.lstFiles->selectedItems();
Q_FOREACH(QListWidgetItem *item, selected) {
delete item;
}
enableButtonOk(ui.lstFiles->count() > 0);
}
void KisDlgImportImageSequence::slotSkipChanged(int)
{
int documentFps = document->image()->animationInterface()->framerate();
float sourceFps = 1.0f * documentFps / ui.spinStep->value();
ui.lblFramerate->setText(i18n("Source fps: %1", sourceFps));
}
void KisDlgImportImageSequence::slotOrderOptionsChanged(int)
{
sortFileList();
}
void KisDlgImportImageSequence::sortFileList()
{
int order = ui.cmbOrder->currentData().toInt();
bool numeric = ui.cmbSortMode->currentData().toInt() == Numerical;
collator.setNumericMode(numeric);
ui.lstFiles->sortItems((order == Ascending) ? Qt::AscendingOrder : Qt::DescendingOrder);
}
/*
* Copyright (c) 2016 Jouni Pentikäinen <joupent@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef KISDLGIMPORTIMAGESEQUENCE_H
#define KISDLGIMPORTIMAGESEQUENCE_H
#include <QObject>
#include <QCollator>
#include "KoDialog.h"
#include "ui_wdgimportimagesequence.h"
class KisDocument;
class KisMainWindow;
class KisDlgImportImageSequence : public KoDialog
{
Q_OBJECT
public:
KisDlgImportImageSequence(KisMainWindow *mainWindow, KisDocument *document);
QStringList files();
int firstFrame();
int step();
protected Q_SLOTS:
void slotAddFiles();
void slotRemoveFiles();
void slotSkipChanged(int);
void slotOrderOptionsChanged(int);
private:
void sortFileList();
private:
Ui_WdgImportImageSequence ui;
KisMainWindow *mainWindow;
KisDocument *document;
enum OrderingOptions {
Ascending = 1,
Descending = 2,
Natural = 4,
Numerical = 8
};
class ListItem;
QCollator collator;
};
#endif // KISDLGIMPORTIMAGESEQUENCE_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>WdgImportImageSequence</class>
<widget class="QWidget" name="WdgImportImageSequence">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>575</width>
<height>428</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QListWidget" name="lstFiles"/>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="btnAddImages">
<property name="text">
<string>Add images...</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnRemove">
<property name="text">
<string>Remove</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Order</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QComboBox" name="cmbOrder"/>
</item>
<item>
<widget class="QComboBox" name="cmbSortMode"/>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Timing</string>
</property>
<layout class="QFormLayout" name="formLayout">
<item row="1" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Start at</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="spinFirstFrame">
<property name="toolTip">
<string>The frame number for the first image</string>
</property>
<property name="maximum">
<number>9999</number>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Step</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QSpinBox" name="spinStep">
<property name="toolTip">
<string>Number of frames between images</string>
</property>
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>999</number>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<widget class="QLabel" name="lblFramerate">
<property name="text">
<string>Source FPS:</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
......@@ -18,8 +18,6 @@
#include "kis_animation_importer.h"
#include "KisMainWindow.h"
#include "KoFileDialog.h"
#include "KoColorSpace.h"
#include "KisPart.h"
#include "KisDocument.h"
......@@ -30,36 +28,6 @@
#include "kis_raster_keyframe_channel.h"
#include "commands/kis_image_layer_add_command.h"
struct KisAnimationImporterUI::Private
{
KisMainWindow *mainWindow;
Private(KisMainWindow *parent)
: mainWindow(parent)
{}
};
KisAnimationImporterUI::KisAnimationImporterUI(KisMainWindow *mainWindow)
: m_d(new Private(mainWindow))
{
}
KisAnimationImporterUI::~KisAnimationImporterUI()
{}
void KisAnimationImporterUI::importSequence(KisDocument *document)
{
QStringList urls = m_d->mainWindow->showOpenFileDialog();
if (urls.isEmpty()) return;
urls.sort();
KisAnimationImporter importer(document->image());
importer.import(urls, 0, 1);
}
struct KisAnimationImporter::Private
{
KisImageSP image;
......
......@@ -25,22 +25,6 @@
class KisDocument;
class KisMainWindow;
class KRITAUI_EXPORT KisAnimationImporterUI : public QObject
{
Q_OBJECT
public:
KisAnimationImporterUI(KisMainWindow *parent);
~KisAnimationImporterUI();
void importSequence(KisDocument *document);
private:
class Private;
QScopedPointer<Private> m_d;
};
class KRITAUI_EXPORT KisAnimationImporter : public QObject
{
Q_OBJECT
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment