Krita Source Code Documentation
Loading...
Searching...
No Matches
DlgExportStoryboard.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2020 Saurabh Kumar <saurabhk660@gmail.com>
3 *
4 * SPDX-License-Identifier: LGPL-2.0-or-later
5 */
7#include "StoryboardModel.h"
8
9#include "KoFileDialog.h"
10#include <kis_config.h>
12#include <kis_time_span.h>
13
14#include <QSpinBox>
15#include <QMessageBox>
16
18 : KoDialog()
19 , m_format(format)
20 , m_model(model)
21{
22 m_page = new WdgExportStoryboard(this);
23
25 ? i18nc("Export storyboard dialog caption", "Export Storyboard as PDF")
26 : i18nc("Export storyboard dialog caption", "Export Storyboard as SVG"));
27
29 setButtonText(Apply, i18n("Export"));
31
32 connect(this, SIGNAL(applyClicked()), this, SLOT(slotExportClicked()));
33 connect(m_page->boardLayoutComboBox, SIGNAL(activated(int)), this, SLOT(slotLayoutChanged(int)));
34 connect(m_page->pageSizeComboBox, SIGNAL(activated(int)), this, SLOT(slotPageSettingsChanged(int)));
35 connect(m_page->pageOrientationComboBox, SIGNAL(activated(int)), this, SLOT(slotPageSettingsChanged(int)));
36 connect(m_page->rowsSpinBox, SIGNAL(valueChanged(int)), this, SLOT(slotPageSettingsChanged(int)));
37 connect(m_page->columnsSpinBox, SIGNAL(valueChanged(int)), this, SLOT(slotPageSettingsChanged(int)));
38
39 KisConfig cfg(true);
40 m_page->boardLayoutComboBox->setCurrentIndex(cfg.readEntry<int>("storyboard/layoutType", ExportLayout::ROWS));
41 m_page->pageOrientationComboBox->setCurrentIndex(cfg.readEntry<int>("storyboard/pageOrientation", 0));
42 m_page->rowsSpinBox->setValue(cfg.readEntry<int>("storyboard/rows", 3));
43 m_page->columnsSpinBox->setValue(cfg.readEntry<int>("storyboard/columns", 3));
44 m_page->fontSizeSpinBox->setValue(cfg.readEntry<int>("storyboard/fontSize", 15));
45 m_page->svgTemplatePathFileRequester->setFileName(cfg.readEntry<QString>("storyboard/svgLayoutFileName", ""));
46 m_page->exportPathFileRequester->setFileName(cfg.readEntry<QString>("storyboard/exportFilePath"));
47
49 QStringList mimeTypes;
50 mimeTypes << "application/pdf";
51 m_page->exportPathFileRequester->setMimeTypeFilters(mimeTypes);
52 m_page->exportPathFileRequester->setMode(KoFileDialog::SaveFile);
53 }
54 else {
55 m_page->exportPathFileRequester->setMode(KoFileDialog::OpenDirectory);
56 }
57
58 QStringList mimeTypes;
59 mimeTypes << "image/svg+xml";
60 m_page->svgTemplatePathFileRequester->setMimeTypeFilters(mimeTypes);
61 m_page->svgTemplatePathFileRequester->setMode(KoFileDialog::OpenFile);
62
64 slotLayoutChanged(m_page->boardLayoutComboBox->currentIndex());
66}
67
71
72
74{
75 const int layoutIndex = m_page->boardLayoutComboBox->currentIndex();
76 if (layoutIndex == ExportLayout::COLUMNS || layoutIndex == ExportLayout::SVG_TEMPLATE) {
77 return 1;
78 }
79 else {
80 return qMax(m_page->rowsSpinBox->value(), 1);
81 }
82}
83
85{
86 const int layoutIndex = m_page->boardLayoutComboBox->currentIndex();
87 if (layoutIndex == ExportLayout::ROWS || layoutIndex == ExportLayout::SVG_TEMPLATE) {
88 return 1;
89 }
90 else {
91 return qMax(m_page->columnsSpinBox->value(), 1);
92 }
93}
94
96{
97 int index = m_page->pageSizeComboBox->currentIndex();
98 switch (index) {
99 case 0:
100 return QPageSize(QPageSize::PageSizeId::A0);
101 case 1:
102 return QPageSize(QPageSize::PageSizeId::A1);
103 case 2:
104 return QPageSize(QPageSize::PageSizeId::A2);
105 case 3:
106 return QPageSize(QPageSize::PageSizeId::A3);
107 case 4:
108 return QPageSize(QPageSize::PageSizeId::A4);
109 case 5:
110 return QPageSize(QPageSize::PageSizeId::A5);
111 case 6:
112 default:
113 return QPageSize(QPageSize::PageSizeId::Letter);
114 }
115}
116
117QPageLayout::Orientation DlgExportStoryboard::pageOrientation() const
118{
119 return (QPageLayout::Orientation)m_page->pageOrientationComboBox->currentIndex();
120}
121
123{
124 const int layoutIndex = m_page->boardLayoutComboBox->currentIndex();
125 return layoutIndex == ExportLayout::SVG_TEMPLATE;
126}
127
129{
130 return m_page->svgTemplatePathFileRequester->fileName();
131}
132
134{
135 return m_page->exportPathFileRequester->fileName();
136}
137
142
144{
145 return static_cast<ExportLayout>(m_page->boardLayoutComboBox->currentIndex());
146}
147
149{
150 return m_page->fontSizeSpinBox->value();
151}
152
153void DlgExportStoryboard::setUsableMaximums(QPageSize pPageSize, QPageLayout::Orientation pOrientation, ExportLayout pLayout)
154{
155 if (pLayout == ExportLayout::SVG_TEMPLATE) { // Bypass estimates -- We can't really make any educated guess here!
156 m_page->fontSizeSpinBox->setMaximum(50);
157 } else {
158 const QSize pointSize = pPageSize.sizePoints();
159 const QSize orientedPointSize = pOrientation == QPageLayout::Landscape ? QSize(pointSize.height(), pointSize.width()) : pointSize;
160 const QSize sizeInPointsPerBoard = QSize(orientedPointSize.width() / columns(), orientedPointSize.height() / rows());
161
162 const int commentCount = m_model ? qMax(m_model->totalCommentCount(), 1) : 1;
163 const bool stacked = sizeInPointsPerBoard.width() < sizeInPointsPerBoard.height();
164 const QSize sizeInPointsPerComment = stacked ? QSize(sizeInPointsPerBoard.width(), sizeInPointsPerBoard.height() / commentCount)
165 : QSize(sizeInPointsPerBoard.width() / commentCount, sizeInPointsPerBoard.height());
166 const QSize usableMaximumFontSize = sizeInPointsPerComment / 12;
167 m_page->fontSizeSpinBox->setMaximum(qMin(usableMaximumFontSize.width(), usableMaximumFontSize.height()));
168 }
169}
170
172{
173 if (m_page->exportPathFileRequester->fileName().isEmpty()) {
175 QMessageBox::warning(this, i18nc("@title:window", "Krita"), i18n("Please enter a file name to export to."));
176 }
177 else {
178 QMessageBox::warning(this, i18nc("@title:window", "Krita"), i18n("Please enter a directory to export to."));
179 }
180 return;
181 }
182
184
185 QDir dir(m_page->exportPathFileRequester->fileName());
186 if (!dir.exists()) {
187 QMessageBox::warning(this, i18nc("@title:window", "Krita"), i18n("Please enter an existing directory."));
188 return;
189 }
190
191 QFileInfo info("[0-9]*.svg");
192 QStringList filesList = dir.entryList({ info.fileName() });
193
194 if (!filesList.isEmpty()) {
195 QMessageBox::StandardButton result =
196 QMessageBox::warning(0,
197 i18n("Existing files with similar naming scheme"),
198 i18n("Files with the same naming "
199 "scheme exist in the destination "
200 "directory. They might be "
201 "deleted, continue?\n\n"
202 "Directory: %1\n"
203 "Files: %2",
204 dir.absolutePath(), filesList.at(0) + "..."),
205 QMessageBox::Yes | QMessageBox::No,
206 QMessageBox::No);
207 if (result == QMessageBox::No) {
208 return;
209 }
210 }
211 }
212
213 if (layoutSpecifiedBySvgFile() && m_page->svgTemplatePathFileRequester->fileName().isEmpty()) {
214 QMessageBox::warning(this, i18nc("@title:window", "Krita"), i18n("Please choose svg file to specify the layout for exporting."));
215 return;
216 }
217 QFileInfo fi(m_page->svgTemplatePathFileRequester->fileName());
218 if (layoutSpecifiedBySvgFile() && !fi.exists()) {
219 QMessageBox::warning(this, i18nc("@title:window", "Krita"), i18n("The SVG file to specify layout doesn't exist. Please choose an existing SVG file."));
220 return;
221 }
222
223 KisConfig cfg(false);
224 cfg.writeEntry("storyboard/layoutType", m_page->boardLayoutComboBox->currentIndex());
225 cfg.writeEntry("storyboard/pageOrientation", m_page->pageOrientationComboBox->currentIndex());
226 cfg.writeEntry("storyboard/rows", m_page->rowsSpinBox->value());
227 cfg.writeEntry("storyboard/columns", m_page->columnsSpinBox->value());
228 cfg.writeEntry("storyboard/svgLayoutFileName", m_page->svgTemplatePathFileRequester->fileName());
229 cfg.writeEntry("storyboard/exportFilePath", m_page->exportPathFileRequester->fileName());
230 cfg.writeEntry("storyboard/fontSize", m_page->fontSizeSpinBox->value());
231
232 accept();
233}
234
236{
237 switch (state) {
239 m_page->rowsLabel->hide();
240 m_page->rowsSpinBox->hide();
241 m_page->svgTemplatePathFileRequester->hide();
242 m_page->svgTemplatePathLabel->hide();
243
244 m_page->columnsSpinBox->show();
245 m_page->columnsLabel->show();
246 break;
248 m_page->columnsLabel->hide();
249 m_page->columnsSpinBox->hide();
250 m_page->svgTemplatePathFileRequester->hide();
251 m_page->svgTemplatePathLabel->hide();
252
253 m_page->rowsSpinBox->show();
254 m_page->rowsLabel->show();
255 break;
257 m_page->svgTemplatePathFileRequester->hide();
258 m_page->svgTemplatePathLabel->hide();
259
260 m_page->columnsLabel->show();
261 m_page->columnsSpinBox->show();
262 m_page->rowsSpinBox->show();
263 m_page->rowsLabel->show();
264 break;
266 m_page->columnsLabel->hide();
267 m_page->columnsSpinBox->hide();
268 m_page->rowsSpinBox->hide();
269 m_page->rowsLabel->hide();
270
271 m_page->svgTemplatePathFileRequester->show();
272 m_page->svgTemplatePathLabel->show();
273 break;
274 }
275}
276
@ SVG_TEMPLATE
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
ExportLayout exportLayout() const
DlgExportStoryboard(ExportFormat format, QSharedPointer< StoryboardModel > model)
QSharedPointer< StoryboardModel > m_model
QPageLayout::Orientation pageOrientation() const
void setUsableMaximums(QPageSize pPageSize, QPageLayout::Orientation pOrientation, ExportLayout pLayout)
bool layoutSpecifiedBySvgFile() const
WdgExportStoryboard * m_page
QPageSize pageSize() const
void slotLayoutChanged(int state)
ExportFormat format() const
void writeEntry(const QString &name, const T &value)
Definition kis_config.h:779
T readEntry(const QString &name, const T &defaultValue=T())
Definition kis_config.h:789
A dialog base class with standard buttons and predefined layouts.
Definition KoDialog.h:116
void applyClicked()
void setMainWidget(QWidget *widget)
Definition KoDialog.cpp:354
void setButtonText(ButtonCode id, const QString &text)
Definition KoDialog.cpp:648
virtual void setCaption(const QString &caption)
Definition KoDialog.cpp:498
void setButtons(ButtonCodes buttonMask)
Definition KoDialog.cpp:195
void setDefaultButton(ButtonCode id)
Definition KoDialog.cpp:302
@ Apply
Show Apply button.
Definition KoDialog.h:128
@ Cancel
Show Cancel-button. (this button reject()s the dialog; result set to QDialog::Rejected)
Definition KoDialog.h:130