1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197 | /* ============================================================
*
* This file is a part of digiKam project
* https://www.digikam.org
*
* Date : 2007-11-07
* Description : a tool to print images
*
* SPDX-FileCopyrightText: 2007-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*
* ============================================================ */
#include "advprintsettings.h"
// Qt includes
#include <QStandardPaths>
// KDE includes
#include <klocalizedstring.h>
#include <kconfiggroup.h>
// Local includes
#include "advprintphoto.h"
namespace DigikamGenericPrintCreatorPlugin
{
AdvPrintSettings::AdvPrintSettings()
: selMode (IMAGES),
printerName (outputName(FILES)),
/// Select a different page to force a refresh in initPhotoSizes.
pageSize (QSizeF(-1, -1)),
captionType (NONE),
captionColor (QColor(Qt::yellow)),
captionFont (QFont(QLatin1String("Sans Serif"))),
captionSize (4),
currentPreviewPage(0),
currentCropPhoto (0),
disableCrop (false),
imageFormat (JPEG),
conflictRule (FileSaveConflictBox::OVERWRITE),
openInFileBrowser (true),
outputLayouts (nullptr),
outputPrinter (nullptr)
{
}
AdvPrintSettings::~AdvPrintSettings()
{
for (int i = 0 ; i < photos.count() ; ++i)
{
delete photos.at(i);
}
photos.clear();
}
void AdvPrintSettings::readSettings(KConfigGroup& group)<--- Parameter 'group' can be declared as reference to const
{
selMode = (Selection)group.readEntry("SelMode",
(int)IMAGES);
imageFormat = (ImageFormat)group.readEntry("ImageFormat",
(int)JPEG);
savedPhotoSize = group.readEntry("PhotoSize",
QString());
printerName = group.readEntry("Printer",
outputName(FILES));
captionType = (CaptionType)group.readEntry(QLatin1String("CaptionType"),
(int)NONE);
captionColor = group.readEntry(QLatin1String("CaptionColor"),
QColor(Qt::yellow));
captionFont = group.readEntry(QLatin1String("CaptionFont"),
QFont(QLatin1String("Sans Serif")));
captionSize = group.readEntry(QLatin1String("CaptionSize"),
4);
captionTxt = group.readEntry(QLatin1String("CustomCaption"),
QString());
outputDir = group.readEntry("OutputPath",
QUrl::fromLocalFile(QStandardPaths::writableLocation
(QStandardPaths::DocumentsLocation)));
conflictRule = (FileSaveConflictBox::ConflictRule)group.readEntry("ConflictRule",
(int)FileSaveConflictBox::OVERWRITE);
openInFileBrowser = group.readEntry("OpenInFileBrowser",
true);
imageFormat = (ImageFormat)group.readEntry("ImageFormat",
(int)JPEG);
}
void AdvPrintSettings::writeSettings(KConfigGroup& group)
{
group.writeEntry("SelMode", (int)selMode);
group.writeEntry("ImageFormat", (int)imageFormat);
group.writeEntry("PhotoSize", savedPhotoSize);
group.writeEntry("Printer", printerName);
group.writeEntry("CaptionType", (int)captionType);
group.writeEntry("CaptionColor", captionColor);
group.writeEntry("CaptionFont", captionFont);
group.writeEntry("CaptionSize", captionSize);
group.writeEntry("CustomCaption", captionTxt);
group.writeEntry("OutputPath", outputDir);
group.writeEntry("ConflictRule", (int)conflictRule);
group.writeEntry("OpenInFileBrowser", openInFileBrowser);
group.writeEntry("ImageFormat", (int)imageFormat);
}
QString AdvPrintSettings::outputName(Output out) const
{
QMap<Output, QString> outputs = outputNames();
if (outputs.contains(out))
{
return outputs[out];
}
return QString();
}
QMap<AdvPrintSettings::Output, QString> AdvPrintSettings::outputNames()
{
QMap<Output, QString> out;
out[FILES] = i18nc("Output: FILE", "Print to Image File");
#ifndef Q_OS_WIN
out[PDF] = i18nc("Output: PDF", "Print to PDF");
#endif
out[GIMP] = i18nc("Output: GIMP", "Print with Gimp");
return out;
}
QString AdvPrintSettings::format() const
{
if (imageFormat == JPEG)
{
return QLatin1String("JPEG");
}
else if (imageFormat == TIFF)
{
return QLatin1String("TIF");
}
return QLatin1String("PNG");
}
QMap<AdvPrintSettings::ImageFormat, QString> AdvPrintSettings::imageFormatNames()
{
QMap<ImageFormat, QString> frms;
frms[JPEG] = i18nc("Image format: JPEG", "JPEG");
frms[PNG] = i18nc("Image format: PNG", "PNG");
frms[TIFF] = i18nc("Image format: TIFF", "TIFF");
return frms;
}
QMap<AdvPrintSettings::CaptionType, QString> AdvPrintSettings::captionTypeNames()
{
QMap<CaptionType, QString> types;
types[NONE] = i18nc("Caption type: NONE", "No caption");
types[FILENAME] = i18nc("Caption type: FILENAME", "Image file names");
types[DATETIME] = i18nc("Caption type: DATETIME", "Exif date-time");
types[COMMENT] = i18nc("Caption type: COMMENT", "Item comments");
types[CUSTOM] = i18nc("Caption type: CUSTOM", "Custom format");
return types;
}
QRect* AdvPrintSettings::getLayout(int photoIndex, int sizeIndex) const
{
AdvPrintPhotoSize* const s = photosizes.at(sizeIndex);
// how many photos would actually be printed, including copies?
int photoCount = (photoIndex + 1);
// how many pages? Recall that the first layout item is the paper size
int photosPerPage = s->m_layouts.count() - 1;
int remainder = photoCount % photosPerPage;
int retVal = (remainder == 0) ? photosPerPage : remainder;
return s->m_layouts.at(retVal);
}
} // namespace DigikamGenericPrintCreatorPlugin
|