File indexing completed on 2025-03-09 03:58:52
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2008-11-27 0007 * Description : a view to show Batch Tool Settings. 0008 * 0009 * SPDX-FileCopyrightText: 2008-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 "toolsettingsview.h" 0016 0017 // Qt includes 0018 0019 #include <QLabel> 0020 #include <QGridLayout> 0021 #include <QFont> 0022 #include <QPushButton> 0023 #include <QScrollArea> 0024 #include <QString> 0025 #include <QIcon> 0026 #include <QApplication> 0027 0028 // KDE includes 0029 0030 #include <klocalizedstring.h> 0031 0032 // Local includes 0033 0034 #include "dlayoutbox.h" 0035 #include "thememanager.h" 0036 #include "batchtoolsfactory.h" 0037 #include "dpluginbqm.h" 0038 #include "dpluginaboutdlg.h" 0039 #include "dxmlguiwindow.h" 0040 0041 namespace Digikam 0042 { 0043 0044 class Q_DECL_HIDDEN ToolSettingsView::Private 0045 { 0046 0047 public: 0048 0049 enum ToolSettingsViewMode 0050 { 0051 MessageView = 0, 0052 SettingsView 0053 }; 0054 0055 public: 0056 0057 explicit Private() 0058 : messageView (nullptr), 0059 settingsViewIcon (nullptr), 0060 settingsViewTitle(nullptr), 0061 settingsViewReset(nullptr), 0062 settingsViewHelp (nullptr), 0063 settingsViewAbout(nullptr), 0064 settingsView (nullptr), 0065 tool (nullptr) 0066 { 0067 } 0068 0069 QLabel* messageView; 0070 QLabel* settingsViewIcon; 0071 QLabel* settingsViewTitle; 0072 0073 QPushButton* settingsViewReset; 0074 QPushButton* settingsViewHelp; 0075 QPushButton* settingsViewAbout; 0076 0077 QScrollArea* settingsView; 0078 0079 BatchToolSet set; 0080 BatchTool* tool; 0081 }; 0082 0083 ToolSettingsView::ToolSettingsView(QWidget* const parent) 0084 : QStackedWidget(parent), 0085 d (new Private) 0086 { 0087 setAttribute(Qt::WA_DeleteOnClose); 0088 0089 // -------------------------------------------------------------------------- 0090 0091 d->messageView = new QLabel(this); 0092 d->messageView->setAlignment(Qt::AlignCenter); 0093 0094 insertWidget(Private::MessageView, d->messageView); 0095 0096 // -------------------------------------------------------------------------- 0097 0098 DVBox* const vbox = new DVBox(this); 0099 QFrame* const toolDescriptor = new QFrame(vbox); 0100 d->settingsViewIcon = new QLabel(); 0101 d->settingsViewTitle = new QLabel(); 0102 QFont font = d->settingsViewTitle->font(); 0103 font.setBold(true); 0104 d->settingsViewTitle->setFont(font); 0105 0106 d->settingsViewReset = new QPushButton(); 0107 d->settingsViewReset->setIcon(QIcon::fromTheme(QLatin1String("document-revert"))); 0108 d->settingsViewReset->setToolTip(i18n("Reset current tool settings to default values.")); 0109 0110 d->settingsViewHelp = new QPushButton(); 0111 d->settingsViewHelp->setIcon(QIcon::fromTheme(QLatin1String("globe"))); 0112 d->settingsViewHelp->setToolTip(i18n("Tool online handbook...")); 0113 0114 d->settingsViewAbout = new QPushButton(); 0115 d->settingsViewAbout->setIcon(QIcon::fromTheme(QLatin1String("help-about"))); 0116 d->settingsViewAbout->setToolTip(i18n("About this tool...")); 0117 0118 QString frameStyle = QString::fromUtf8("QFrame {" 0119 "color: %1;" 0120 "border: 1px solid %2;" 0121 "border-radius: 5px;" 0122 "background-color: %3;" 0123 "}") 0124 .arg(qApp->palette().color(QPalette::HighlightedText).name()) 0125 .arg(qApp->palette().color(QPalette::HighlightedText).name()) 0126 .arg(qApp->palette().color(QPalette::Highlight).name()); 0127 0128 QString noFrameStyle = QLatin1String("QFrame {" 0129 "border: none;" 0130 "}"); 0131 0132 d->settingsViewIcon->setStyleSheet(noFrameStyle); 0133 d->settingsViewTitle->setStyleSheet(noFrameStyle); 0134 d->settingsViewReset->setStyleSheet(noFrameStyle); 0135 d->settingsViewHelp->setStyleSheet(noFrameStyle); 0136 d->settingsViewAbout->setStyleSheet(noFrameStyle); 0137 toolDescriptor->setStyleSheet(frameStyle); 0138 0139 d->settingsViewIcon->setAlignment(Qt::AlignVCenter | Qt::AlignRight); 0140 d->settingsViewTitle->setAlignment(Qt::AlignCenter); 0141 0142 QGridLayout* const descrLayout = new QGridLayout(); 0143 descrLayout->addWidget(d->settingsViewIcon, 0, 0, 1, 1); 0144 descrLayout->addWidget(d->settingsViewTitle, 0, 1, 1, 1); 0145 descrLayout->addWidget(d->settingsViewReset, 0, 2, 1, 1); 0146 descrLayout->addWidget(d->settingsViewHelp , 0, 3, 1, 1); 0147 descrLayout->addWidget(d->settingsViewAbout, 0, 4, 1, 1); 0148 descrLayout->setColumnStretch(1, 10); 0149 toolDescriptor->setLayout(descrLayout); 0150 0151 // -------------------------------------------------------------------------- 0152 0153 d->settingsView = new QScrollArea(vbox); 0154 d->settingsView->setWidgetResizable(true); 0155 0156 vbox->setSpacing(0); 0157 vbox->setContentsMargins(QMargins()); 0158 vbox->setStretchFactor(d->settingsView, 10); 0159 0160 insertWidget(Private::SettingsView, vbox); 0161 setToolSettingsWidget(new QWidget(this)); 0162 setViewMode(Private::MessageView); 0163 0164 // -------------------------------------------------------------------------- 0165 0166 connect(ThemeManager::instance(), SIGNAL(signalThemeChanged()), 0167 this, SLOT(slotThemeChanged())); 0168 0169 connect(d->settingsViewAbout, SIGNAL(clicked()), 0170 this, SLOT(slotAboutPlugin())); 0171 0172 connect(d->settingsViewHelp, SIGNAL(clicked()), 0173 this, SLOT(slotHelpPlugin())); 0174 } 0175 0176 ToolSettingsView::~ToolSettingsView() 0177 { 0178 Q_FOREACH (BatchTool* const tool, BatchToolsFactory::instance()->toolsList()) 0179 { 0180 tool->deleteSettingsWidget(); 0181 } 0182 0183 delete d; 0184 } 0185 0186 void ToolSettingsView::slotAboutPlugin() 0187 { 0188 if (d->tool) 0189 { 0190 if (d->tool->plugin()) 0191 { 0192 QPointer<DPluginAboutDlg> dlg = new DPluginAboutDlg(dynamic_cast<DPlugin*>(d->tool->plugin())); 0193 dlg->exec(); 0194 delete dlg; 0195 } 0196 } 0197 } 0198 0199 void ToolSettingsView::slotHelpPlugin() 0200 { 0201 if (d->tool) 0202 { 0203 if (d->tool->plugin()) 0204 { 0205 openOnlineDocumentation(d->tool->plugin()->handbookSection(), 0206 d->tool->plugin()->handbookChapter(), 0207 d->tool->plugin()->handbookReference()); 0208 } 0209 } 0210 } 0211 0212 void ToolSettingsView::setBusy(bool b) 0213 { 0214 d->settingsView->viewport()->setEnabled(!b); 0215 d->settingsViewReset->setEnabled(!b); 0216 } 0217 0218 void ToolSettingsView::setToolSettingsWidget(QWidget* const w) 0219 { 0220 QWidget* wdt = nullptr; 0221 0222 if (!w) 0223 { 0224 wdt = new QWidget; 0225 } 0226 else 0227 { 0228 wdt = w; 0229 } 0230 0231 d->settingsView->takeWidget(); 0232 wdt->setParent(d->settingsView->viewport()); 0233 d->settingsView->setWidget(wdt); 0234 setViewMode(Private::SettingsView); 0235 } 0236 0237 void ToolSettingsView::slotThemeChanged() 0238 { 0239 QPalette palette; 0240 palette.setColor(d->messageView->backgroundRole(), qApp->palette().color(QPalette::Base)); 0241 d->messageView->setPalette(palette); 0242 0243 QPalette palette2; 0244 palette2.setColor(d->settingsView->backgroundRole(), qApp->palette().color(QPalette::Base)); 0245 d->settingsView->setPalette(palette2); 0246 } 0247 0248 int ToolSettingsView::viewMode() const 0249 { 0250 return indexOf(currentWidget()); 0251 } 0252 0253 void ToolSettingsView::setViewMode(int mode) 0254 { 0255 if ((mode != Private::MessageView) && (mode != Private::SettingsView)) 0256 { 0257 return; 0258 } 0259 0260 if (mode == Private::MessageView) 0261 { 0262 d->settingsViewReset->setEnabled(false); 0263 } 0264 else 0265 { 0266 d->settingsViewReset->setEnabled(true); 0267 } 0268 0269 setCurrentIndex(mode); 0270 } 0271 0272 void ToolSettingsView::slotToolSelected(const BatchToolSet& set) 0273 { 0274 d->set = set; 0275 0276 if (d->tool) 0277 { 0278 disconnect(d->tool, SIGNAL(signalSettingsChanged(BatchToolSettings)), 0279 this, SLOT(slotSettingsChanged(BatchToolSettings))); 0280 0281 disconnect(d->settingsViewReset, SIGNAL(clicked()), 0282 d->tool, SLOT(slotResetSettingsToDefault())); 0283 } 0284 0285 d->tool = BatchToolsFactory::instance()->findTool(d->set.name, d->set.group); 0286 0287 if (d->tool) 0288 { 0289 d->settingsViewIcon->setPixmap(d->tool->toolIcon().pixmap(22)); 0290 d->settingsViewTitle->setText(d->tool->toolTitle()); 0291 d->tool->setSettings(d->set.settings); 0292 0293 // Only set on Reset button if Manager is not busy (settings widget is disabled in this case). 0294 0295 d->settingsViewReset->setEnabled(d->settingsView->viewport()->isEnabled()); 0296 0297 d->settingsViewAbout->setEnabled(d->tool->plugin()); 0298 0299 setToolSettingsWidget(d->tool->settingsWidget()); 0300 0301 connect(d->tool, SIGNAL(signalSettingsChanged(BatchToolSettings)), 0302 this, SLOT(slotSettingsChanged(BatchToolSettings))); 0303 0304 connect(d->settingsViewReset, SIGNAL(clicked()), 0305 d->tool, SLOT(slotResetSettingsToDefault())); 0306 } 0307 else 0308 { 0309 d->settingsViewIcon->clear(); 0310 d->settingsViewTitle->clear(); 0311 d->settingsViewReset->setEnabled(false); 0312 setToolSettingsWidget(nullptr); 0313 } 0314 } 0315 0316 void ToolSettingsView::slotSettingsChanged(const BatchToolSettings& settings) 0317 { 0318 d->set.settings = settings; 0319 0320 Q_EMIT signalSettingsChanged(d->set); 0321 } 0322 0323 } // namespace Digikam 0324 0325 #include "moc_toolsettingsview.cpp"