File indexing completed on 2025-03-09 03:58:53
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2012-12-19 0007 * Description : Workflow properties dialog. 0008 * 0009 * SPDX-FileCopyrightText: 2012-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 "workflowdlg.h" 0016 0017 // Qt includes 0018 0019 #include <QPointer> 0020 #include <QGridLayout> 0021 #include <QGroupBox> 0022 #include <QLabel> 0023 #include <QApplication> 0024 #include <QStyle> 0025 #include <QStandardPaths> 0026 #include <QDialogButtonBox> 0027 #include <QVBoxLayout> 0028 #include <QPushButton> 0029 0030 // KDE includes 0031 0032 #include <klocalizedstring.h> 0033 0034 // Local includes 0035 0036 #include "dlayoutbox.h" 0037 #include "dxmlguiwindow.h" 0038 #include "dexpanderbox.h" 0039 #include "dtextedit.h" 0040 0041 namespace Digikam 0042 { 0043 0044 class Q_DECL_HIDDEN WorkflowDlg::Private 0045 { 0046 0047 public: 0048 0049 explicit Private() 0050 : buttons (nullptr), 0051 titleEdit(nullptr), 0052 descEdit (nullptr) 0053 { 0054 } 0055 0056 QDialogButtonBox* buttons; 0057 DTextEdit* titleEdit; 0058 DTextEdit* descEdit; 0059 }; 0060 0061 WorkflowDlg::WorkflowDlg(const Workflow& wf, bool create) 0062 : QDialog(nullptr), 0063 d (new Private) 0064 { 0065 setModal(true); 0066 setWindowTitle(create ? i18nc("@title:window", "New Workflow") : i18nc("@title:window", "Edit Workflow")); 0067 0068 d->buttons = new QDialogButtonBox(QDialogButtonBox::Help | QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this); 0069 d->buttons->button(QDialogButtonBox::Ok)->setDefault(true); 0070 0071 QWidget* const page = new QWidget(this); 0072 QLabel* const logo = new QLabel(page); 0073 logo->setPixmap(QIcon::fromTheme(QLatin1String("digikam")).pixmap(QSize(48,48))); 0074 0075 QLabel* const topLabel = new QLabel(page); 0076 0077 if (create) 0078 { 0079 topLabel->setText(i18n("<qt><b>Create new Workflow</b></qt>")); 0080 } 0081 else 0082 { 0083 topLabel->setText(i18n("<qt><b>Workflow Properties</b></qt>")); 0084 } 0085 0086 topLabel->setAlignment(Qt::AlignLeft | Qt::AlignVCenter); 0087 topLabel->setWordWrap(false); 0088 0089 DLineWidget* const topLine = new DLineWidget(Qt::Horizontal); 0090 0091 // -------------------------------------------------------- 0092 0093 QLabel* const titleLabel = new QLabel(page); 0094 titleLabel->setText(i18nc("@title: batch worklow name", "&Title:")); 0095 0096 d->titleEdit = new DTextEdit(page); 0097 d->titleEdit->setLinesVisible(1); 0098 d->titleEdit->setIgnoredCharacters(QLatin1String("/")); 0099 d->titleEdit->selectAll(); 0100 d->titleEdit->setFocus(); 0101 titleLabel->setBuddy(d->titleEdit); 0102 0103 // -------------------------------------------------------- 0104 0105 QLabel* const descLabel = new QLabel(page); 0106 descLabel->setText(i18n("Description:")); 0107 0108 d->descEdit = new DTextEdit(page); 0109 d->descEdit->setLinesVisible(1); 0110 d->descEdit->setIgnoredCharacters(QLatin1String("/")); 0111 descLabel->setBuddy(d->descEdit); 0112 0113 // -------------------------------------------------------- 0114 0115 QGridLayout* const grid = new QGridLayout(); 0116 grid->addWidget(logo, 0, 0, 1, 1); 0117 grid->addWidget(topLabel, 0, 1, 1, 1); 0118 grid->addWidget(topLine, 1, 0, 1, 2); 0119 grid->addWidget(titleLabel, 2, 0, 1, 1); 0120 grid->addWidget(d->titleEdit, 2, 1, 1, 1); 0121 grid->addWidget(descLabel, 3, 0, 1, 1, Qt::AlignLeft | Qt::AlignTop); 0122 grid->addWidget(d->descEdit, 3, 1, 1, 1); 0123 grid->setSpacing(qMin(QApplication::style()->pixelMetric(QStyle::PM_LayoutHorizontalSpacing), 0124 QApplication::style()->pixelMetric(QStyle::PM_LayoutVerticalSpacing))); 0125 grid->setContentsMargins(QMargins()); 0126 page->setLayout(grid); 0127 0128 QVBoxLayout* const vbx = new QVBoxLayout(this); 0129 vbx->addWidget(page); 0130 vbx->addWidget(d->buttons); 0131 setLayout(vbx); 0132 0133 if (create) 0134 { 0135 d->titleEdit->setText(i18n("New Workflow")); 0136 } 0137 else 0138 { 0139 d->titleEdit->setText(wf.title); 0140 d->descEdit->setText(wf.desc); 0141 } 0142 0143 // -- slots connections ------------------------------------------- 0144 0145 connect(d->titleEdit, SIGNAL(textChanged()), 0146 this, SLOT(slotTitleChanged())); 0147 0148 connect(d->buttons->button(QDialogButtonBox::Ok), SIGNAL(clicked()), 0149 this, SLOT(accept())); 0150 0151 connect(d->buttons->button(QDialogButtonBox::Cancel), SIGNAL(clicked()), 0152 this, SLOT(reject())); 0153 0154 connect(d->buttons->button(QDialogButtonBox::Help), SIGNAL(clicked()), 0155 this, SLOT(slotHelp())); 0156 } 0157 0158 WorkflowDlg::~WorkflowDlg() 0159 { 0160 delete d; 0161 } 0162 0163 QString WorkflowDlg::title() const 0164 { 0165 return d->titleEdit->text(); 0166 } 0167 0168 QString WorkflowDlg::description() const 0169 { 0170 return d->descEdit->text(); 0171 } 0172 0173 bool WorkflowDlg::editProps(Workflow& wf) 0174 { 0175 QPointer<WorkflowDlg> dlg = new WorkflowDlg(wf); 0176 bool ok = (dlg->exec() == QDialog::Accepted); 0177 0178 if (ok) 0179 { 0180 wf.title = dlg->title(); 0181 wf.desc = dlg->description(); 0182 } 0183 0184 delete dlg; 0185 0186 return ok; 0187 } 0188 0189 bool WorkflowDlg::createNew(Workflow& wf) 0190 { 0191 QPointer<WorkflowDlg> dlg = new WorkflowDlg(wf, true); 0192 bool ok = (dlg->exec() == QDialog::Accepted); 0193 0194 if (ok) 0195 { 0196 wf.title = dlg->title(); 0197 wf.desc = dlg->description(); 0198 } 0199 0200 delete dlg; 0201 0202 return ok; 0203 } 0204 0205 void WorkflowDlg::slotTitleChanged() 0206 { 0207 QString text = d->titleEdit->text(); 0208 Workflow wf = WorkflowManager::instance()->findByTitle(text); 0209 bool enable = (wf.title.isEmpty() && !text.isEmpty()); 0210 d->buttons->button(QDialogButtonBox::Ok)->setEnabled(enable); 0211 } 0212 0213 void WorkflowDlg::slotHelp() 0214 { 0215 openOnlineDocumentation(QLatin1String("batch_queue"), QLatin1String("bqm_workflow")); 0216 } 0217 0218 } // namespace Digikam 0219 0220 #include "moc_workflowdlg.cpp"