File indexing completed on 2025-01-05 03:59:34
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2023-12-21 0007 * Description : Marble Settings View. 0008 * 0009 * SPDX-FileCopyrightText: 2007 by Torsten Rahn <rahn at kde dot org> 0010 * SPDX-FileCopyrightText: 2008 by Jens-Michael Hoffmann <jensmh at gmx dot de> 0011 * SPDX-FileCopyrightText: 2022-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0012 * 0013 * SPDX-License-Identifier: LGPL-2.1-or-later 0014 * 0015 * ============================================================ */ 0016 0017 #include "MarblePluginSettingsWidget.h" 0018 0019 // Qt includes 0020 0021 #include <QIcon> 0022 #include <QList> 0023 #include <QPointer> 0024 #include <QMessageBox> 0025 #include <QGroupBox> 0026 #include <QListView> 0027 #include <QHeaderView> 0028 #include <QTreeWidget> 0029 #include <QTreeWidgetItem> 0030 #include <QVBoxLayout> 0031 #include <QHBoxLayout> 0032 #include <QLabel> 0033 #include <QMap> 0034 #include <QToolButton> 0035 0036 // KDE includes 0037 0038 #include <klocalizedstring.h> 0039 0040 // Local includes 0041 0042 #include "DialogConfigurationInterface.h" 0043 #include "ParseRunnerPlugin.h" 0044 #include "PluginItemDelegate.h" 0045 #include "RenderPluginModel.h" 0046 0047 #include "geopluginaboutdlg.h" 0048 0049 using namespace Digikam; 0050 0051 namespace Marble 0052 { 0053 0054 class MarblePluginSettingsWidget::Private 0055 { 0056 public: 0057 0058 Private() = default; 0059 0060 public: 0061 0062 QListView* renderListView = nullptr; 0063 QTreeWidget* runnerListView = nullptr; 0064 PluginItemDelegate* itemDelegate = nullptr; 0065 QPointer<RenderPluginModel> renderPluginModel; 0066 QList<const ParseRunnerPlugin*> runnerPluginList; 0067 QMap<QToolButton*, QTreeWidgetItem*> runnerBtnMap; 0068 }; 0069 0070 // --- 0071 0072 MarblePluginSettingsWidget::MarblePluginSettingsWidget(QWidget* const parent) 0073 : QWidget(parent), 0074 d (new Private) 0075 { 0076 QGroupBox* const grpRender = new QGroupBox(i18n("Render Tools"), this); 0077 QVBoxLayout* const vlayRender = new QVBoxLayout(grpRender); 0078 d->renderListView = new QListView(grpRender); 0079 d->itemDelegate = new PluginItemDelegate(d->renderListView, this); 0080 d->renderListView->setItemDelegate(d->itemDelegate); 0081 vlayRender->addWidget(d->renderListView); 0082 0083 QGroupBox* const grpRunner = new QGroupBox(i18n("Runner Tools"), this); 0084 QVBoxLayout* const vlayRunner = new QVBoxLayout(grpRunner); 0085 d->runnerListView = new QTreeWidget(grpRunner); 0086 d->runnerListView->setColumnCount(2); 0087 d->runnerListView->setRootIsDecorated(false); 0088 d->runnerListView->setUniformRowHeights(false); 0089 d->runnerListView->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); 0090 d->runnerListView->setAllColumnsShowFocus(true); 0091 d->runnerListView->setSelectionMode(QAbstractItemView::NoSelection); 0092 d->runnerListView->setFocusPolicy(Qt::NoFocus); 0093 d->runnerListView->setSortingEnabled(true); 0094 d->runnerListView->sortByColumn(0, Qt::AscendingOrder); 0095 d->runnerListView->setIconSize(QSize(16, 16)); 0096 d->runnerListView->setHeaderHidden(true); 0097 d->runnerListView->header()->setSectionResizeMode(0, QHeaderView::Stretch); 0098 d->runnerListView->header()->setSectionResizeMode(1, QHeaderView::Fixed); 0099 d->runnerListView->header()->setSortIndicatorShown(false); 0100 0101 vlayRunner->addWidget(d->runnerListView); 0102 0103 QVBoxLayout* const vlay = new QVBoxLayout(this); 0104 vlay->addWidget(grpRender); 0105 vlay->addWidget(grpRunner); 0106 0107 connect(d->itemDelegate, SIGNAL(aboutPluginClicked(QModelIndex)), 0108 this, SLOT(slotAboutRenderPlugin(QModelIndex))); 0109 0110 connect(d->itemDelegate, SIGNAL(configPluginClicked(QModelIndex)), 0111 this, SLOT(slotRenderPluginConfigDialog(QModelIndex))); 0112 } 0113 0114 MarblePluginSettingsWidget::~MarblePluginSettingsWidget() 0115 { 0116 delete d; 0117 } 0118 0119 void MarblePluginSettingsWidget::setAboutIcon(const QIcon& icon) 0120 { 0121 d->itemDelegate->setAboutIcon(icon); 0122 } 0123 0124 void MarblePluginSettingsWidget::setConfigIcon(const QIcon& icon) 0125 { 0126 d->itemDelegate->setConfigIcon(icon); 0127 } 0128 0129 void MarblePluginSettingsWidget::setModel(RenderPluginModel* const pluginModel) 0130 { 0131 if (!d->renderPluginModel.isNull()) 0132 { 0133 disconnect(d->renderPluginModel.data(), nullptr, this, nullptr); 0134 } 0135 0136 d->renderPluginModel = pluginModel; 0137 d->renderListView->setModel(d->renderPluginModel); 0138 0139 if (!d->renderPluginModel.isNull()) 0140 { 0141 connect(d->renderPluginModel.data(), SIGNAL(itemChanged(QStandardItem*)), 0142 this, SIGNAL(pluginListViewClicked())); 0143 } 0144 } 0145 0146 void MarblePluginSettingsWidget::setRunnerPlugins(const QList<const ParseRunnerPlugin*>& list) 0147 { 0148 d->runnerPluginList = list; 0149 0150 Q_FOREACH (const ParseRunnerPlugin* plug, d->runnerPluginList) 0151 { 0152 QTreeWidgetItem* const item = new QTreeWidgetItem(d->runnerListView); 0153 item->setChildIndicatorPolicy(QTreeWidgetItem::DontShowIndicator); 0154 item->setText(0, plug->name()); 0155 item->setIcon(0, QIcon::fromTheme(QLatin1String("plugins"))); 0156 item->setToolTip(0, plug->description()); 0157 0158 QWidget* const bbox = new QWidget(d->runnerListView); 0159 QHBoxLayout* const hlay = new QHBoxLayout(bbox); 0160 QToolButton* const btn = new QToolButton(bbox); 0161 hlay->addStretch(); 0162 hlay->addWidget(btn); 0163 hlay->setContentsMargins(QMargins(0, 0, 0 ,0)); 0164 btn->setIcon(QIcon::fromTheme(QLatin1String("help-about"))); 0165 btn->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum)); 0166 d->runnerListView->setItemWidget(item, 1, bbox); 0167 d->runnerBtnMap.insert(btn, item); 0168 0169 connect(btn, SIGNAL(released()), 0170 this, SLOT(slotAboutRunnerPlugin())); 0171 } 0172 } 0173 0174 void MarblePluginSettingsWidget::slotAboutRenderPlugin(const QModelIndex& index) 0175 { 0176 if (d->renderPluginModel.isNull()) 0177 { 0178 return; 0179 } 0180 0181 QPointer<GeoPluginAboutDlg> dlg = new GeoPluginAboutDlg(d->renderPluginModel->pluginIface(index), this); 0182 dlg->exec(); 0183 delete dlg; 0184 } 0185 0186 void MarblePluginSettingsWidget::slotAboutRunnerPlugin() 0187 { 0188 QToolButton* const btn = dynamic_cast<QToolButton*>(sender()); 0189 0190 if (!btn) 0191 { 0192 return; 0193 } 0194 0195 QTreeWidgetItem* const item = d->runnerBtnMap.value(btn); 0196 0197 if (!item) 0198 { 0199 return; 0200 } 0201 0202 Q_FOREACH (const ParseRunnerPlugin* plug, d->runnerPluginList) 0203 { 0204 if (plug->name() == item->text(0)) 0205 { 0206 QPointer<GeoPluginAboutDlg> dlg = new GeoPluginAboutDlg((PluginInterface*)(plug), this); 0207 dlg->exec(); 0208 delete dlg; 0209 0210 break; 0211 } 0212 } 0213 } 0214 0215 void MarblePluginSettingsWidget::slotRenderPluginConfigDialog(const QModelIndex& index) 0216 { 0217 if (d->renderPluginModel.isNull()) 0218 { 0219 return; 0220 } 0221 0222 DialogConfigurationInterface* const configInterface = d->renderPluginModel->pluginDialogConfigurationInterface(index); 0223 QDialog* const configDialog = configInterface ? configInterface->configDialog() : nullptr; 0224 0225 if (configDialog) 0226 { 0227 configDialog->exec(); 0228 } 0229 } 0230 0231 } // namespace Marble 0232 0233 #include "moc_MarblePluginSettingsWidget.cpp"