File indexing completed on 2025-01-05 03:51:40
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2005-03-10 0007 * Description : a tool to apply texture over an image 0008 * 0009 * SPDX-FileCopyrightText: 2005-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0010 * SPDX-FileCopyrightText: 2006-2010 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de> 0011 * 0012 * SPDX-License-Identifier: GPL-2.0-or-later 0013 * 0014 * ============================================================ */ 0015 0016 #include "texturetool.h" 0017 0018 // Qt includes 0019 0020 #include <QGridLayout> 0021 #include <QImage> 0022 #include <QLabel> 0023 #include <QIcon> 0024 0025 // KDE includes 0026 0027 #include <kconfiggroup.h> 0028 #include <ksharedconfig.h> 0029 #include <klocalizedstring.h> 0030 0031 // Local includes 0032 0033 #include "dimg.h" 0034 #include "editortoolsettings.h" 0035 #include "imageiface.h" 0036 #include "imageregionwidget.h" 0037 #include "texturesettings.h" 0038 #include "texturefilter.h" 0039 0040 namespace DigikamEditorTextureToolPlugin 0041 { 0042 0043 class Q_DECL_HIDDEN TextureTool::Private 0044 { 0045 public: 0046 0047 explicit Private() 0048 : configGroupName(QLatin1String("texture Tool")), 0049 settingsView (nullptr), 0050 previewWidget (nullptr), 0051 gboxSettings (nullptr) 0052 { 0053 } 0054 0055 const QString configGroupName; 0056 0057 TextureSettings* settingsView; 0058 ImageRegionWidget* previewWidget; 0059 EditorToolSettings* gboxSettings; 0060 }; 0061 0062 // -------------------------------------------------------- 0063 0064 TextureTool::TextureTool(QObject* const parent) 0065 : EditorToolThreaded(parent), 0066 d (new Private) 0067 { 0068 setObjectName(QLatin1String("texture")); 0069 0070 // ------------------------------------------------------------- 0071 0072 d->gboxSettings = new EditorToolSettings(nullptr); 0073 d->previewWidget = new ImageRegionWidget; 0074 d->settingsView = new TextureSettings(d->gboxSettings->plainPage()); 0075 0076 // ------------------------------------------------------------- 0077 0078 setToolSettings(d->gboxSettings); 0079 setToolView(d->previewWidget); 0080 setPreviewModeMask(PreviewToolBar::AllPreviewModes); 0081 0082 // ------------------------------------------------------------- 0083 0084 connect(d->settingsView, SIGNAL(signalSettingsChanged()), 0085 this, SLOT(slotTimer())); 0086 } 0087 0088 TextureTool::~TextureTool() 0089 { 0090 delete d; 0091 } 0092 0093 void TextureTool::readSettings() 0094 { 0095 KSharedConfig::Ptr config = KSharedConfig::openConfig(); 0096 KConfigGroup group = config->group(d->configGroupName); 0097 0098 d->settingsView->readSettings(group); 0099 } 0100 0101 void TextureTool::writeSettings() 0102 { 0103 KSharedConfig::Ptr config = KSharedConfig::openConfig(); 0104 KConfigGroup group = config->group(d->configGroupName); 0105 0106 d->settingsView->writeSettings(group); 0107 0108 group.sync(); 0109 } 0110 0111 void TextureTool::slotResetSettings() 0112 { 0113 d->settingsView->resetToDefault(); 0114 } 0115 0116 void TextureTool::preparePreview() 0117 { 0118 DImg image = d->previewWidget->getOriginalRegionImage(); 0119 TextureContainer settings = d->settingsView->settings(); 0120 setFilter(new TextureFilter(&image, this, settings)); 0121 } 0122 0123 void TextureTool::prepareFinal() 0124 { 0125 ImageIface iface; 0126 TextureContainer settings = d->settingsView->settings(); 0127 setFilter(new TextureFilter(iface.original(), this, settings)); 0128 } 0129 0130 void TextureTool::setPreviewImage() 0131 { 0132 d->previewWidget->setPreviewImage(filter()->getTargetImage()); 0133 } 0134 0135 void TextureTool::setFinalImage() 0136 { 0137 ImageIface iface; 0138 iface.setOriginal(i18n("Texture"), filter()->filterAction(), filter()->getTargetImage()); 0139 } 0140 0141 } // namespace DigikamEditorTextureToolPlugin 0142 0143 #include "moc_texturetool.cpp"