File indexing completed on 2025-01-05 03:53:14
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2017-05-25 0007 * Description : a tool to print images 0008 * 0009 * SPDX-FileCopyrightText: 2017-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0010 * 0011 * SPDX-License-Identifier: GPL-2.0-or-later 0012 * 0013 * ============================================================ */ 0014 0015 #include "advprintoutputpage.h" 0016 0017 // Qt includes 0018 0019 #include <QIcon> 0020 #include <QLabel> 0021 #include <QUrl> 0022 #include <QWidget> 0023 #include <QApplication> 0024 #include <QStyle> 0025 #include <QCheckBox> 0026 #include <QGridLayout> 0027 #include <QComboBox> 0028 0029 // KDE includes 0030 0031 #include <klocalizedstring.h> 0032 0033 // Local includes 0034 0035 #include "advprintwizard.h" 0036 #include "dfileselector.h" 0037 #include "filesaveconflictbox.h" 0038 0039 namespace DigikamGenericPrintCreatorPlugin 0040 { 0041 0042 class Q_DECL_HIDDEN AdvPrintOutputPage::Private 0043 { 0044 public: 0045 0046 explicit Private(QWizard* const dialog) 0047 : labelImagesFormat(nullptr), 0048 destUrl (nullptr), 0049 conflictBox (nullptr), 0050 imagesFormat (nullptr), 0051 fileBrowserCB (nullptr), 0052 wizard (nullptr), 0053 settings (nullptr) 0054 { 0055 wizard = dynamic_cast<AdvPrintWizard*>(dialog); 0056 0057 if (wizard) 0058 { 0059 settings = wizard->settings(); 0060 } 0061 } 0062 0063 QLabel* labelImagesFormat; 0064 DFileSelector* destUrl; 0065 FileSaveConflictBox* conflictBox; 0066 QComboBox* imagesFormat; 0067 QCheckBox* fileBrowserCB; 0068 AdvPrintWizard* wizard; 0069 AdvPrintSettings* settings; 0070 }; 0071 0072 AdvPrintOutputPage::AdvPrintOutputPage(QWizard* const dialog, const QString& title) 0073 : DWizardPage(dialog, title), 0074 d (new Private(dialog)) 0075 { 0076 QWidget* const main = new QWidget(this); 0077 0078 // -------------------- 0079 0080 d->labelImagesFormat = new QLabel(main); 0081 d->labelImagesFormat->setWordWrap(false); 0082 d->labelImagesFormat->setText(i18n("Image Format:")); 0083 0084 d->imagesFormat = new QComboBox(main); 0085 d->imagesFormat->setEditable(false); 0086 d->imagesFormat->setWhatsThis(i18n("Select your preferred format to export printing as image.")); 0087 0088 QMap<AdvPrintSettings::ImageFormat, QString> map2 = AdvPrintSettings::imageFormatNames(); 0089 QMap<AdvPrintSettings::ImageFormat, QString>::const_iterator it2 = map2.constBegin(); 0090 0091 while (it2 != map2.constEnd()) 0092 { 0093 d->imagesFormat->addItem(it2.value(), (int)it2.key()); 0094 ++it2; 0095 } 0096 0097 d->labelImagesFormat->setBuddy(d->imagesFormat); 0098 0099 // -------------------- 0100 0101 QLabel* const fileLabel = new QLabel(main); 0102 fileLabel->setWordWrap(false); 0103 fileLabel->setText(i18n("Destination folder:")); 0104 0105 d->destUrl = new DFileSelector(main); 0106 d->destUrl->setFileDlgMode(QFileDialog::Directory); 0107 d->destUrl->setFileDlgOptions(QFileDialog::ShowDirsOnly); 0108 d->destUrl->setFileDlgTitle(i18nc("@title:window", "Destination Folder")); 0109 d->destUrl->lineEdit()->setPlaceholderText(i18n("Output Destination Path")); 0110 fileLabel->setBuddy(d->destUrl); 0111 0112 // -------------------- 0113 0114 QLabel* const outputLbl = new QLabel(main); 0115 outputLbl->setText(i18n("The image output file name will be generated automatically.")); 0116 d->conflictBox = new FileSaveConflictBox(main); 0117 0118 // -------------------- 0119 0120 d->fileBrowserCB = new QCheckBox(main); 0121 d->fileBrowserCB->setText(i18n("Open in File Browser")); 0122 0123 // -------------------- 0124 0125 QGridLayout* const grid = new QGridLayout(main); 0126 grid->setSpacing(qMin(QApplication::style()->pixelMetric(QStyle::PM_LayoutHorizontalSpacing), 0127 QApplication::style()->pixelMetric(QStyle::PM_LayoutVerticalSpacing))); 0128 grid->addWidget(d->labelImagesFormat, 0, 0, 1, 1); 0129 grid->addWidget(d->imagesFormat, 0, 1, 1, 2); 0130 grid->addWidget(fileLabel, 1, 0, 1, 1); 0131 grid->addWidget(d->destUrl, 1, 1, 1, 1); 0132 grid->addWidget(outputLbl, 2, 0, 1, 2); 0133 grid->addWidget(d->conflictBox, 3, 0, 1, 2); 0134 grid->addWidget(d->fileBrowserCB, 4, 0, 1, 2); 0135 grid->setRowStretch(5, 10); 0136 0137 setPageWidget(main); 0138 setLeftBottomPix(QIcon::fromTheme(QLatin1String("folder-image"))); 0139 0140 connect(d->destUrl->lineEdit(), SIGNAL(textEdited(QString)), 0141 this, SIGNAL(completeChanged())); 0142 0143 connect(d->destUrl, SIGNAL(signalUrlSelected(QUrl)), 0144 this, SIGNAL(completeChanged())); 0145 } 0146 0147 AdvPrintOutputPage::~AdvPrintOutputPage() 0148 { 0149 delete d; 0150 } 0151 0152 void AdvPrintOutputPage::initializePage() 0153 { 0154 d->destUrl->setFileDlgPath(d->settings->outputDir.toLocalFile()); 0155 d->conflictBox->setConflictRule(d->settings->conflictRule); 0156 d->fileBrowserCB->setChecked(d->settings->openInFileBrowser); 0157 d->imagesFormat->setCurrentIndex((int)d->settings->imageFormat); 0158 } 0159 0160 bool AdvPrintOutputPage::validatePage() 0161 { 0162 if (d->destUrl->fileDlgPath().isEmpty()) 0163 { 0164 return false; 0165 } 0166 0167 d->settings->outputDir = QUrl::fromLocalFile(d->destUrl->fileDlgPath()); 0168 d->settings->conflictRule = d->conflictBox->conflictRule(); 0169 d->settings->openInFileBrowser = d->fileBrowserCB->isChecked(); 0170 d->settings->imageFormat = AdvPrintSettings::ImageFormat(d->imagesFormat->currentIndex()); 0171 0172 return true; 0173 } 0174 0175 bool AdvPrintOutputPage::isComplete() const 0176 { 0177 return (!d->destUrl->fileDlgPath().isEmpty()); 0178 } 0179 0180 } // namespace DigikamGenericPrintCreatorPlugin 0181 0182 #include "moc_advprintoutputpage.cpp"