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 connect(m_page->gridRowsSpinBox, SIGNAL(valueChanged(int)), this, SLOT(slotPageSettingsChanged(int)));
39 connect(m_page->gridColumnsSpinBox, SIGNAL(valueChanged(int)), this, SLOT(slotPageSettingsChanged(int)));
40
41 KisConfig cfg(true);
42 m_page->boardLayoutComboBox->setCurrentIndex(cfg.readEntry<int>("storyboard/layoutType", ExportLayout::ROWS));
43 m_page->pageOrientationComboBox->setCurrentIndex(cfg.readEntry<int>("storyboard/pageOrientation", 0));
44 m_page->rowsSpinBox->setValue(cfg.readEntry<int>("storyboard/rows", 3));
45 m_page->columnsSpinBox->setValue(cfg.readEntry<int>("storyboard/columns", 3));
46 m_page->fontSizeSpinBox->setValue(cfg.readEntry<int>("storyboard/fontSize", 15));
47 m_page->svgTemplatePathFileRequester->setFileName(cfg.readEntry<QString>("storyboard/svgLayoutFileName", ""));
48 m_page->exportPathFileRequester->setFileName(cfg.readEntry<QString>("storyboard/exportFilePath"));
49 m_page->gridRowsSpinBox->setValue(cfg.readEntry<int>("storyboard/rows", 3));
50 m_page->gridColumnsSpinBox->setValue(cfg.readEntry<int>("storyboard/columns", 3));
51
53 QStringList mimeTypes;
54 mimeTypes << "application/pdf";
55 m_page->exportPathFileRequester->setMimeTypeFilters(mimeTypes);
56 m_page->exportPathFileRequester->setMode(KoFileDialog::SaveFile);
57 }
58 else {
59 m_page->exportPathFileRequester->setMode(KoFileDialog::OpenDirectory);
60 }
61
62 QStringList mimeTypes;
63 mimeTypes << "image/svg+xml";
64 m_page->svgTemplatePathFileRequester->setMimeTypeFilters(mimeTypes);
65 m_page->svgTemplatePathFileRequester->setMode(KoFileDialog::OpenFile);
66
68 slotLayoutChanged(m_page->boardLayoutComboBox->currentIndex());
70}
71
75
76
78{
79 const int layoutIndex = m_page->boardLayoutComboBox->currentIndex();
80 if (layoutIndex == ExportLayout::COLUMNS || layoutIndex == ExportLayout::SVG_TEMPLATE) {
81 return 1;
82 }
83 else if (layoutIndex == ExportLayout::GRID) {
84 return qMax(m_page->gridRowsSpinBox->value(), 1);
85 }
86 else {
87 return qMax(m_page->rowsSpinBox->value(), 1);
88 }
89}
90
92{
93 const int layoutIndex = m_page->boardLayoutComboBox->currentIndex();
94 if (layoutIndex == ExportLayout::ROWS || layoutIndex == ExportLayout::SVG_TEMPLATE) {
95 return 1;
96 }
97 else if (layoutIndex == ExportLayout::GRID) {
98 return qMax(m_page->gridColumnsSpinBox->value(), 1);
99 }
100 else {
101 return qMax(m_page->columnsSpinBox->value(), 1);
102 }
103}
104
106{
107 int index = m_page->pageSizeComboBox->currentIndex();
108 switch (index) {
109 case 0:
110 return QPageSize(QPageSize::PageSizeId::A0);
111 case 1:
112 return QPageSize(QPageSize::PageSizeId::A1);
113 case 2:
114 return QPageSize(QPageSize::PageSizeId::A2);
115 case 3:
116 return QPageSize(QPageSize::PageSizeId::A3);
117 case 4:
118 return QPageSize(QPageSize::PageSizeId::A4);
119 case 5:
120 return QPageSize(QPageSize::PageSizeId::A5);
121 case 6:
122 default:
123 return QPageSize(QPageSize::PageSizeId::Letter);
124 }
125}
126
127QPageLayout::Orientation DlgExportStoryboard::pageOrientation() const
128{
129 return (QPageLayout::Orientation)m_page->pageOrientationComboBox->currentIndex();
130}
131
133{
134 const int layoutIndex = m_page->boardLayoutComboBox->currentIndex();
135 return layoutIndex == ExportLayout::SVG_TEMPLATE;
136}
137
139{
140 return m_page->svgTemplatePathFileRequester->fileName();
141}
142
144{
145 return m_page->exportPathFileRequester->fileName();
146}
147
152
154{
155 return static_cast<ExportLayout>(m_page->boardLayoutComboBox->currentIndex());
156}
157
159{
160 return m_page->fontSizeSpinBox->value();
161}
162
163void DlgExportStoryboard::setUsableMaximums(QPageSize pPageSize, QPageLayout::Orientation pOrientation, ExportLayout pLayout)
164{
165 if (pLayout == ExportLayout::SVG_TEMPLATE) { // Bypass estimates -- We can't really make any educated guess here!
166 m_page->fontSizeSpinBox->setMaximum(50);
167 } else {
168 const QSize pointSize = pPageSize.sizePoints();
169 const QSize orientedPointSize = pOrientation == QPageLayout::Landscape ? QSize(pointSize.height(), pointSize.width()) : pointSize;
170 const QSize sizeInPointsPerBoard = QSize(orientedPointSize.width() / columns(), orientedPointSize.height() / rows());
171
172 const int commentCount = m_model ? qMax(m_model->totalCommentCount(), 1) : 1;
173 const bool stacked = sizeInPointsPerBoard.width() < sizeInPointsPerBoard.height();
174 const QSize sizeInPointsPerComment = stacked ? QSize(sizeInPointsPerBoard.width(), sizeInPointsPerBoard.height() / commentCount)
175 : QSize(sizeInPointsPerBoard.width() / commentCount, sizeInPointsPerBoard.height());
176 const QSize usableMaximumFontSize = sizeInPointsPerComment / 12;
177 m_page->fontSizeSpinBox->setMaximum(qMin(usableMaximumFontSize.width(), usableMaximumFontSize.height()));
178 }
179}
180
182{
183 if (m_page->exportPathFileRequester->fileName().isEmpty()) {
185 QMessageBox::warning(this, i18nc("@title:window", "Krita"), i18n("Please enter a file name to export to."));
186 }
187 else {
188 QMessageBox::warning(this, i18nc("@title:window", "Krita"), i18n("Please enter a directory to export to."));
189 }
190 return;
191 }
192
194
195 QDir dir(m_page->exportPathFileRequester->fileName());
196 if (!dir.exists()) {
197 QMessageBox::warning(this, i18nc("@title:window", "Krita"), i18n("Please enter an existing directory."));
198 return;
199 }
200
201 QFileInfo info("[0-9]*.svg");
202 QStringList filesList = dir.entryList({ info.fileName() });
203
204 if (!filesList.isEmpty()) {
205 QMessageBox::StandardButton result =
206 QMessageBox::warning(0,
207 i18n("Existing files with similar naming scheme"),
208 i18n("Files with the same naming "
209 "scheme exist in the destination "
210 "directory. They might be "
211 "deleted, continue?\n\n"
212 "Directory: %1\n"
213 "Files: %2",
214 dir.absolutePath(), filesList.at(0) + "..."),
215 QMessageBox::Yes | QMessageBox::No,
216 QMessageBox::No);
217 if (result == QMessageBox::No) {
218 return;
219 }
220 }
221 }
222
223 if (layoutSpecifiedBySvgFile() && m_page->svgTemplatePathFileRequester->fileName().isEmpty()) {
224 QMessageBox::warning(this, i18nc("@title:window", "Krita"), i18n("Please choose svg file to specify the layout for exporting."));
225 return;
226 }
227 QFileInfo fi(m_page->svgTemplatePathFileRequester->fileName());
228 if (layoutSpecifiedBySvgFile() && !fi.exists()) {
229 QMessageBox::warning(this, i18nc("@title:window", "Krita"), i18n("The SVG file to specify layout doesn't exist. Please choose an existing SVG file."));
230 return;
231 }
232
233 KisConfig cfg(false);
234 cfg.writeEntry("storyboard/layoutType", m_page->boardLayoutComboBox->currentIndex());
235 cfg.writeEntry("storyboard/pageOrientation", m_page->pageOrientationComboBox->currentIndex());
237 cfg.writeEntry("storyboard/rows", m_page->gridRowsSpinBox->value());
238 cfg.writeEntry("storyboard/columns", m_page->gridColumnsSpinBox->value());
239 } else {
240 cfg.writeEntry("storyboard/rows", m_page->rowsSpinBox->value());
241 cfg.writeEntry("storyboard/columns", m_page->columnsSpinBox->value());
242 }
243 cfg.writeEntry("storyboard/svgLayoutFileName", m_page->svgTemplatePathFileRequester->fileName());
244 cfg.writeEntry("storyboard/exportFilePath", m_page->exportPathFileRequester->fileName());
245 cfg.writeEntry("storyboard/fontSize", m_page->fontSizeSpinBox->value());
246
247 accept();
248}
249
251{
252 m_page->rowsLabel->hide();
253 m_page->rowsSpinBox->hide();
254 m_page->columnsLabel->hide();
255 m_page->columnsSpinBox->hide();
256 m_page->gridLabel->hide();
257 m_page->gridRowsSpinBox->hide();
258 m_page->gridColumnsSpinBox->hide();
259 m_page->rowsColumnsXLabel->hide();
260 m_page->svgTemplatePathLabel->hide();
261 m_page->svgTemplatePathFileRequester->hide();
262
263 switch (state) {
265 m_page->columnsLabel->show();
266 m_page->columnsSpinBox->show();
267 break;
269 m_page->rowsLabel->show();
270 m_page->rowsSpinBox->show();
271 break;
273 m_page->gridLabel->show();
274 m_page->gridRowsSpinBox->show();
275 m_page->rowsColumnsXLabel->show();
276 m_page->gridColumnsSpinBox->show();
277 break;
279 m_page->svgTemplatePathLabel->show();
280 m_page->svgTemplatePathFileRequester->show();
281 break;
282 }
283}
284
@ SVG_TEMPLATE
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
void slotLayoutChanged(int state)
ExportFormat format() const
void writeEntry(const QString &name, const T &value)
Definition kis_config.h:865
T readEntry(const QString &name, const T &defaultValue=T())
Definition kis_config.h:875
A dialog base class with standard buttons and predefined layouts.
Definition KoDialog.h:116
void applyClicked()
void setMainWidget(QWidget *widget)
Definition KoDialog.cpp:345
void setButtonText(ButtonCode id, const QString &text)
Definition KoDialog.cpp:639
virtual void setCaption(const QString &caption)
Definition KoDialog.cpp:489
void setButtons(ButtonCodes buttonMask)
Definition KoDialog.cpp:195
void setDefaultButton(ButtonCode id)
Definition KoDialog.cpp:293
@ 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