Commit ebb04024 authored by Eoin O'Neill's avatar Eoin O'Neill 🍀
Browse files

Working new export GUI for storyboard docker.

The old one was messy and users had a hard time understanding
the settings. This one should be cleaner and convey what it needs
to clearer without explanation.

Settings have been restricted to more usable ranges so that there
is less room for user error.
parent f88b8e2e
......@@ -13,7 +13,7 @@
#include <QSpinBox>
#include <QMessageBox>
DlgExportStoryboard::DlgExportStoryboard(ExportFormat format, KisTimeSpan span)
DlgExportStoryboard::DlgExportStoryboard(ExportFormat format)
: KoDialog()
, m_format(format)
{
......@@ -28,112 +28,104 @@ DlgExportStoryboard::DlgExportStoryboard(ExportFormat format, KisTimeSpan span)
setDefaultButton(Apply);
connect(this, SIGNAL(applyClicked()), this, SLOT(slotExportClicked()));
connect(m_page->chkUseSVGLayout, SIGNAL(stateChanged(int)), this, SLOT(slotChkUseSvgLayoutChanged(int)));
m_page->spinboxRow->setMinimum(1);
m_page->spinboxColumn->setMinimum(1);
connect(m_page->boardLayoutComboBox, SIGNAL(activated(int)), this, SLOT(slotLayoutChanged(int)));
KisConfig cfg(true);
m_page->spinboxFirstItem->setValue(span.start());
m_page->spinboxLastItem->setValue(span.end());
m_page->spinboxRow->setValue(cfg.readEntry<int>("storyboard/rows", 3));
m_page->spinboxColumn->setValue(cfg.readEntry<int>("storyboard/columns", 3));
m_page->spinboxFontSize->setValue(cfg.readEntry<int>("storyboard/fontSize", 15));
m_page->svgLayoutFileName->setFileName(cfg.readEntry<QString>("storyboard/svgLayoutFileName", ""));
m_page->svgFileBaseName->setText(cfg.readEntry<QString>("storyboard/svgFileBaseName", ""));
m_page->chkUseSVGLayout->setChecked(cfg.readEntry<bool>("storyboard/chkUseSVGLayout", false));
m_page->exportFileName->setFileName(cfg.readEntry<QString>("storyboard/exportFileName", ""));
m_page->boardLayoutComboBox->setCurrentIndex(cfg.readEntry<int>("storyboard/layoutType", ExportLayout::ROWS));
m_page->pageOrientationComboBox->setCurrentIndex(cfg.readEntry<int>("storyboard/pageOrientation", 0));
m_page->rowsSpinBox->setValue(cfg.readEntry<int>("storyboard/rows", 3));
m_page->columnsSpinBox->setValue(cfg.readEntry<int>("storyboard/columns", 3));
m_page->fontSizeSpinBox->setValue(cfg.readEntry<int>("storyboard/fontSize", 15));
m_page->svgTemplatePathFileRequester->setFileName(cfg.readEntry<QString>("storyboard/svgLayoutFileName", ""));
m_page->exportPathFileRequester->setFileName(cfg.readEntry<QString>("storyboard/exportFilePath"));
if (format == ExportFormat::PDF) {
m_page->svgFileBaseName->hide();
m_page->lblSvgFileBaseName->hide();
QStringList mimeTypes;
mimeTypes << "application/pdf";
m_page->exportFileName->setMimeTypeFilters(mimeTypes);
m_page->exportFileName->setMode(KoFileDialog::SaveFile);
m_page->exportPathFileRequester->setMimeTypeFilters(mimeTypes);
m_page->exportPathFileRequester->setMode(KoFileDialog::SaveFile);
}
else {
m_page->exportFileName->setMode(KoFileDialog::OpenDirectory);
m_page->lblExportFileName->setText(i18n("Export Directory: "));
m_page->exportPathFileRequester->setMode(KoFileDialog::OpenDirectory);
}
QStringList mimeTypes;
mimeTypes << "image/svg+xml";
m_page->svgLayoutFileName->setMimeTypeFilters(mimeTypes);
m_page->svgLayoutFileName->setMode(KoFileDialog::OpenFile);
m_page->svgTemplatePathFileRequester->setMimeTypeFilters(mimeTypes);
m_page->svgTemplatePathFileRequester->setMode(KoFileDialog::OpenFile);
setMainWidget(m_page);
slotChkUseSvgLayoutChanged(m_page->chkUseSVGLayout->checkState());
slotLayoutChanged(m_page->boardLayoutComboBox->currentIndex());
}
DlgExportStoryboard::~DlgExportStoryboard()
{
}
int DlgExportStoryboard::firstItem() const
{
return m_page->spinboxFirstItem->value();
}
int DlgExportStoryboard::lastItem() const
{
return m_page->spinboxLastItem->value();
}
int DlgExportStoryboard::rows() const
{
return m_page->spinboxRow->value();
const int layoutIndex = m_page->boardLayoutComboBox->currentIndex();
if (layoutIndex == ExportLayout::COLUMNS || layoutIndex == ExportLayout::SVG_TEMPLATE) {
return 1;
}
else {
return m_page->rowsSpinBox->value();
}
}
int DlgExportStoryboard::columns() const
{
return m_page->spinboxColumn->value();
const int layoutIndex = m_page->boardLayoutComboBox->currentIndex();
if (layoutIndex == ExportLayout::ROWS || layoutIndex == ExportLayout::SVG_TEMPLATE) {
return 1;
}
else {
return m_page->columnsSpinBox->value();
}
}
QPageSize DlgExportStoryboard::pageSize() const
{
int index = m_page->cmbPageSize->currentIndex();
int index = m_page->pageSizeComboBox->currentIndex();
switch (index) {
case 0:
return QPageSize(QPageSize::PageSizeId::A4);
case 1:
return QPageSize(QPageSize::PageSizeId::A0);
case 2:
case 1:
return QPageSize(QPageSize::PageSizeId::A1);
case 3:
case 2:
return QPageSize(QPageSize::PageSizeId::A2);
case 4:
case 3:
return QPageSize(QPageSize::PageSizeId::A3);
default:
case 4:
return QPageSize(QPageSize::PageSizeId::A4);
case 5:
return QPageSize(QPageSize::PageSizeId::A5);
case 6:
default:
return QPageSize(QPageSize::PageSizeId::Letter);
}
}
QPageLayout::Orientation DlgExportStoryboard::pageOrientation() const
{
return (QPageLayout::Orientation)m_page->cmbPageOrient->currentIndex();
return (QPageLayout::Orientation)m_page->pageOrientationComboBox->currentIndex();
}
bool DlgExportStoryboard::layoutSpecifiedBySvgFile() const
{
return m_page->chkUseSVGLayout->isChecked();
const int layoutIndex = m_page->boardLayoutComboBox->currentIndex();
return layoutIndex == ExportLayout::SVG_TEMPLATE;
}
QString DlgExportStoryboard::layoutSvgFile() const
{
return m_page->svgLayoutFileName->fileName();
return m_page->svgTemplatePathFileRequester->fileName();
}
QString DlgExportStoryboard::saveFileName() const
{
return m_page->exportFileName->fileName();
}
QString DlgExportStoryboard::svgFileBaseName() const
{
return m_page->svgFileBaseName->text();
return m_page->exportPathFileRequester->fileName();
}
ExportFormat DlgExportStoryboard::format() const
......@@ -143,17 +135,12 @@ ExportFormat DlgExportStoryboard::format() const
int DlgExportStoryboard::fontSize() const
{
return m_page->spinboxFontSize->value();
return m_page->fontSizeSpinBox->value();
}
void DlgExportStoryboard::slotExportClicked()
{
if (firstItem() > lastItem()) {
QMessageBox::warning(this, i18nc("@title:window", "Krita"), i18n("Please enter correct range. The first frame should be less than or equal to the last frame."));
return;
}
if (m_page->exportFileName->fileName().isEmpty()) {
if (m_page->exportPathFileRequester->fileName().isEmpty()) {
if (m_format == ExportFormat::PDF) {
QMessageBox::warning(this, i18nc("@title:window", "Krita"), i18n("Please enter a file name to export to."));
}
......@@ -165,13 +152,13 @@ void DlgExportStoryboard::slotExportClicked()
if (m_format == ExportFormat::SVG) {
QDir dir(m_page->exportFileName->fileName());
QDir dir(m_page->exportPathFileRequester->fileName());
if (!dir.exists()) {
QMessageBox::warning(this, i18nc("@title:window", "Krita"), i18n("Please enter an existing directory."));
return;
}
QFileInfo info(svgFileBaseName() + "[0-9]*.svg");
QFileInfo info("[0-9]*.svg");
QStringList filesList = dir.entryList({ info.fileName() });
if (!filesList.isEmpty()) {
......@@ -193,35 +180,66 @@ void DlgExportStoryboard::slotExportClicked()
}
}
if (m_page->chkUseSVGLayout->isChecked() && m_page->svgLayoutFileName->fileName().isEmpty()) {
if (layoutSpecifiedBySvgFile() && m_page->svgTemplatePathFileRequester->fileName().isEmpty()) {
QMessageBox::warning(this, i18nc("@title:window", "Krita"), i18n("Please choose svg file to specify the layout for exporting."));
return;
}
QFileInfo fi(m_page->svgLayoutFileName->fileName());
if (m_page->chkUseSVGLayout->isChecked() && !fi.exists()) {
QFileInfo fi(m_page->svgTemplatePathFileRequester->fileName());
if (layoutSpecifiedBySvgFile() && !fi.exists()) {
QMessageBox::warning(this, i18nc("@title:window", "Krita"), i18n("The SVG file to specify layout doesn't exist. Please choose an existing SVG file."));
return;
}
KisConfig cfg(false);
cfg.writeEntry("storyboard/firstItem", m_page->spinboxFirstItem->value());
cfg.writeEntry("storyboard/lastItem", m_page->spinboxLastItem->value());
cfg.writeEntry("storyboard/rows", m_page->spinboxRow->value());
cfg.writeEntry("storyboard/columns", m_page->spinboxColumn->value());
cfg.writeEntry("storyboard/fontSize", m_page->spinboxFontSize->value());
cfg.writeEntry("storyboard/svgLayoutFileName", m_page->svgLayoutFileName->fileName());
cfg.writeEntry("storyboard/svgFileBaseName", m_page->svgFileBaseName->text());
cfg.writeEntry("storyboard/chkUseSVGLayout", m_page->chkUseSVGLayout->isChecked());
cfg.writeEntry("storyboard/exportFileName", m_page->exportFileName->fileName());
cfg.writeEntry("storyboard/layoutType", m_page->boardLayoutComboBox->currentIndex());
cfg.writeEntry("storyboard/pageOrientation", m_page->pageOrientationComboBox->currentIndex());
cfg.writeEntry("storyboard/rows", m_page->rowsSpinBox->value());
cfg.writeEntry("storyboard/columns", m_page->columnsSpinBox->value());
cfg.writeEntry("storyboard/svgLayoutFileName", m_page->svgTemplatePathFileRequester->fileName());
cfg.writeEntry("storyboard/exportFilePath", m_page->exportPathFileRequester->fileName());
cfg.writeEntry("storyboard/fontSize", m_page->fontSizeSpinBox->value());
accept();
}
void DlgExportStoryboard::slotChkUseSvgLayoutChanged(int state)
{
m_page->spinboxRow->setEnabled(state != Qt::Checked);
m_page->spinboxColumn->setEnabled(state != Qt::Checked);
m_page->cmbPageSize->setEnabled(state != Qt::Checked);
m_page->cmbPageOrient->setEnabled(state != Qt::Checked);
m_page->svgLayoutFileName->setEnabled(state == Qt::Checked);
void DlgExportStoryboard::slotLayoutChanged(int state)
{
switch (state) {
case ExportLayout::COLUMNS:
m_page->rowsLabel->hide();
m_page->rowsSpinBox->hide();
m_page->svgTemplatePathFileRequester->hide();
m_page->svgTemplatePathLabel->hide();
m_page->columnsSpinBox->show();
m_page->columnsLabel->show();
break;
case ExportLayout::ROWS:
m_page->columnsLabel->hide();
m_page->columnsSpinBox->hide();
m_page->svgTemplatePathFileRequester->hide();
m_page->svgTemplatePathLabel->hide();
m_page->rowsSpinBox->show();
m_page->rowsLabel->show();
break;
case ExportLayout::GRID:
m_page->svgTemplatePathFileRequester->hide();
m_page->svgTemplatePathLabel->hide();
m_page->columnsLabel->show();
m_page->columnsSpinBox->show();
m_page->rowsSpinBox->show();
m_page->rowsLabel->show();
break;
case ExportLayout::SVG_TEMPLATE:
m_page->columnsLabel->hide();
m_page->columnsSpinBox->hide();
m_page->rowsSpinBox->hide();
m_page->rowsLabel->hide();
m_page->svgTemplatePathFileRequester->show();
m_page->svgTemplatePathLabel->show();
break;
}
}
......@@ -16,12 +16,21 @@
class QPageSize;
class KisTimeSpan;
enum ExportFormat : unsigned int
enum ExportFormat
{
PDF,
PDF = 0,
SVG
};
enum ExportLayout
{
ROWS = 0,
COLUMNS = 1,
GRID = 2,
SVG_TEMPLATE = 3
};
class WdgExportStoryboard : public QWidget, public Ui::WdgExportStoryboard
{
Q_OBJECT
......@@ -39,10 +48,8 @@ class DlgExportStoryboard: public KoDialog
{
Q_OBJECT
public:
DlgExportStoryboard(ExportFormat format, KisTimeSpan span);
DlgExportStoryboard(ExportFormat format);
~DlgExportStoryboard() override;
int firstItem() const;
int lastItem() const;
int rows() const;
int columns() const;
QPageSize pageSize() const;
......@@ -50,13 +57,12 @@ public:
bool layoutSpecifiedBySvgFile() const;
QString layoutSvgFile() const;
QString saveFileName() const;
QString svgFileBaseName() const;
ExportFormat format() const;
int fontSize() const;
private Q_SLOTS:
void slotExportClicked();
void slotChkUseSvgLayoutChanged(int state);
void slotLayoutChanged(int state);
private:
WdgExportStoryboard *m_page {0};
......
......@@ -345,7 +345,9 @@ void StoryboardDockerDock::slotExportAsSvg()
void StoryboardDockerDock::slotExport(ExportFormat format)
{
KisTimeSpan span = m_canvas->image()->animationInterface()->fullClipRange();
DlgExportStoryboard dlg(format, span);
QFileInfo fileInfo(m_canvas->imageView()->document()->path());
const QString imageFileName = fileInfo.baseName();
DlgExportStoryboard dlg(format);
if (dlg.exec() == QDialog::Accepted) {
dlg.hide();
......@@ -372,23 +374,8 @@ void StoryboardDockerDock::slotExport(ExportFormat format)
}
//getting the range of items to render
int firstItemFrame = dlg.firstItem();
QModelIndex firstIndex = m_storyboardModel->lastIndexBeforeFrame(firstItemFrame);
if (!firstIndex.isValid()) {
firstIndex = m_storyboardModel->index(0,0);
}
else {
siblingAtRow(firstIndex, firstIndex.row() + 1);
}
int lastItemFrame = dlg.lastItem();
QModelIndex lastIndex = m_storyboardModel->indexFromFrame(lastItemFrame);
if (!lastIndex.isValid()) {
lastIndex = m_storyboardModel->lastIndexBeforeFrame(lastItemFrame);
}
if (!lastIndex.isValid()) {
lastIndex = m_storyboardModel->index(0, 0);
}
QModelIndex firstIndex = m_storyboardModel->index(0,0);
QModelIndex lastIndex = m_storyboardModel->index(m_storyboardModel->rowCount() - 1, 0);
if (!firstIndex.isValid() || !lastIndex.isValid()) {
QMessageBox::warning((QWidget*)(&dlg), i18nc("@title:window", "Krita"), i18n("Please enter correct range. There are no panels in the range of frames provided."));
......@@ -416,7 +403,7 @@ void StoryboardDockerDock::slotExport(ExportFormat format)
QSvgGenerator generator;
if (dlg.format() == ExportFormat::SVG) {
generator.setFileName(dlg.saveFileName() + "/" + dlg.svgFileBaseName() + "0.svg");
generator.setFileName(dlg.saveFileName() + "/" + imageFileName + "0.svg");
QSize sz = printer.pageRect().size();
generator.setSize(sz);
generator.setViewBox(QRect(0, 0, sz.width(), sz.height()));
......@@ -441,7 +428,7 @@ void StoryboardDockerDock::slotExport(ExportFormat format)
if (dlg.format() == ExportFormat::SVG) {
p.end();
p.eraseRect(printer.pageRect());
generator.setFileName(dlg.saveFileName() + "/" + dlg.svgFileBaseName() + QString::number(i / layoutCellRects.size()) + ".svg");
generator.setFileName(dlg.saveFileName() + "/" + imageFileName + QString::number(i / layoutCellRects.size()) + ".svg");
QSize sz = printer.pageRect().size();
generator.setSize(sz);
generator.setViewBox(QRect(0, 0, sz.width(), sz.height()));
......
......@@ -14,6 +14,7 @@
#include <kis_mainwindow_observer.h>
#include <kis_canvas2.h>
#include <kis_action.h>
#include "DlgExportStoryboard.h"
class Ui_WdgStoryboardDock;
class CommentMenu;
......@@ -22,9 +23,7 @@ class StoryboardCommentModel;
class StoryboardModel;
class StoryboardDelegate;
class KisNodeManager;
class DlgExportStoryboard;
class QPrinter;
enum ExportFormat : unsigned int;
class StoryboardDockerDock : public QDockWidget, public KisMainwindowObserver{
Q_OBJECT
......
......@@ -6,88 +6,46 @@
<rect>
<x>0</x>
<y>0</y>
<width>430</width>
<height>386</height>
<width>384</width>
<height>388</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>384</width>
<height>0</height>
</size>
</property>
<property name="windowTitle">
<string>Export Storyboard</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QFormLayout" name="formLayout">
<property name="leftMargin">
<number>8</number>
</property>
<property name="rightMargin">
<number>8</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label_4">
<widget class="QLabel" name="pageSizeLabel">
<property name="text">
<string>Frame number of first item to render:</string>
<string>Page Size:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSpinBox" name="spinboxFirstItem"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Frame number of last item to render:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="spinboxLastItem">
<property name="maximum">
<number>100000</number>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Rows per page :</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QSpinBox" name="spinboxRow"/>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Columns per page :</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QSpinBox" name="spinboxColumn">
<property name="value">
<number>0</number>
<widget class="QComboBox" name="pageSizeComboBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Font Size :</string>
<property name="currentIndex">
<number>4</number>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QSpinBox" name="spinboxFontSize"/>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Page Size :</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QComboBox" name="cmbPageSize">
<item>
<property name="text">
<string>A4</string>
</property>
</item>
<item>
<property name="text">
<string>A0</string>
......@@ -108,22 +66,38 @@
<string>A3</string>
</property>
</item>
<item>
<property name="text">
<string>A4</string>
</property>
</item>
<item>
<property name="text">
<string>A5</string>
</property>
</item>
<item>
<property name="text">
<string>US Letter</string>
</property>
</item>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="label_7">
<item row="1" column="0">
<widget class="QLabel" name="pageOrientationLabel">
<property name="text">
<string>Page Orientation :</string>
<string>Page Orientation:</string>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QComboBox" name="cmbPageOrient">
<item row="1" column="1">
<widget class="QComboBox" name="pageOrientationComboBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<item>
<property name="text">
<string>Portrait</string>
......@@ -136,56 +110,180 @@
</item>
</widget>
</item>
<item row="7" column="0">
<widget class="QCheckBox" name="chkUseSVGLayout">
<item row="3" column="0">
<widget class="QLabel" name="boardLayoutLabel">
<property name="text">
<string>Specify Layout Using SVG file </string>
<string>Board Layout:</string>
</property>
</widget>
</item>
<item row="8" column="0">
<widget class="QLabel" name="label_8">
<property name="text">
<string>SVG file for specifying layout :</string>
<item row="3" column="1">
<widget class="QComboBox" name="boardLayoutComboBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>