1
/* ============================================================
3
* This file is a part of digiKam project
4
* http://www.digikam.org
7
* Description : a plugin to apply texture over an image
9
* Copyright (C) 2005-2010 by Gilles Caulier <caulier dot gilles at gmail dot com>
10
* Copyright (C) 2006-2010 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
12
* This program is free software; you can redistribute it
13
* and/or modify it under the terms of the GNU General
14
* Public License as published by the Free Software Foundation;
15
* either version 2, or (at your option)
18
* This program is distributed in the hope that it will be useful,
19
* but WITHOUT ANY WARRANTY; without even the implied warranty of
20
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
* GNU General Public License for more details.
23
* ============================================================ */
25
#include "texturetool.moc"
29
#include <QGridLayout>
35
#include <kapplication.h>
37
#include <kconfiggroup.h>
39
#include <kiconloader.h>
41
#include <knuminput.h>
42
#include <kstandarddirs.h>
46
#include <libkdcraw/rcombobox.h>
47
#include <libkdcraw/rnuminput.h>
52
#include "editortoolsettings.h"
53
#include "imageiface.h"
54
#include "imageregionwidget.h"
55
#include "texturefilter.h"
57
using namespace KDcrawIface;
59
namespace DigikamDecorateImagePlugin
67
configGroupName("texture Tool"),
68
configTextureTypeEntry("TextureType"),
69
configBlendGainEntry("BlendGain"),
77
const QString configGroupName;
78
const QString configTextureTypeEntry;
79
const QString configBlendGainEntry;
81
RComboBox* textureType;
82
RIntNumInput* blendGain;
83
ImageRegionWidget* previewWidget;
84
EditorToolSettings* gboxSettings;
87
TextureTool::TextureTool(QObject* parent)
88
: EditorToolThreaded(parent),
89
d(new TextureToolPriv)
91
setObjectName("texture");
92
setToolName(i18n("Texture"));
93
setToolIcon(SmallIcon("texture"));
95
// -------------------------------------------------------------
97
d->gboxSettings = new EditorToolSettings;
98
d->previewWidget = new ImageRegionWidget;
100
// -------------------------------------------------------------
102
QLabel *label1 = new QLabel(i18n("Type:"));
103
d->textureType = new RComboBox;
104
d->textureType->addItem(i18n("Paper"));
105
d->textureType->addItem(i18n("Paper 2"));
106
d->textureType->addItem(i18n("Fabric"));
107
d->textureType->addItem(i18n("Burlap"));
108
d->textureType->addItem(i18n("Bricks"));
109
d->textureType->addItem(i18n("Bricks 2"));
110
d->textureType->addItem(i18n("Canvas"));
111
d->textureType->addItem(i18n("Marble"));
112
d->textureType->addItem(i18n("Marble 2"));
113
d->textureType->addItem(i18n("Blue Jean"));
114
d->textureType->addItem(i18n("Cell Wood"));
115
d->textureType->addItem(i18n("Metal Wire"));
116
d->textureType->addItem(i18n("Modern"));
117
d->textureType->addItem(i18n("Wall"));
118
d->textureType->addItem(i18n("Moss"));
119
d->textureType->addItem(i18n("Stone"));
120
d->textureType->setDefaultIndex(PaperTexture);
121
d->textureType->setWhatsThis( i18n("Set here the texture type to apply to image."));
123
// -------------------------------------------------------------
125
QLabel *label2 = new QLabel(i18n("Relief:"));
126
d->blendGain = new RIntNumInput;
127
d->blendGain->setRange(1, 255, 1);
128
d->blendGain->setSliderEnabled(true);
129
d->blendGain->setDefaultValue(200);
130
d->blendGain->setWhatsThis(i18n("Set here the relief gain used to merge texture and image."));
132
// -------------------------------------------------------------
134
QGridLayout* mainLayout = new QGridLayout;
135
mainLayout->addWidget(label1, 0, 0, 1, 1);
136
mainLayout->addWidget(d->textureType, 0, 1, 1, 1);
137
mainLayout->addWidget(label2, 1, 0, 1, 2);
138
mainLayout->addWidget(d->blendGain, 2, 0, 1, 2);
139
mainLayout->setRowStretch(3, 10);
140
mainLayout->setMargin(d->gboxSettings->spacingHint());
141
mainLayout->setSpacing(d->gboxSettings->spacingHint());
142
d->gboxSettings->plainPage()->setLayout(mainLayout);
144
// -------------------------------------------------------------
146
setToolSettings(d->gboxSettings);
147
setToolView(d->previewWidget);
148
setPreviewModeMask(PreviewToolBar::AllPreviewModes);
151
// -------------------------------------------------------------
153
connect(d->previewWidget, SIGNAL(signalOriginalClipFocusChanged()),
154
this, SLOT(slotEffect()));
156
connect(d->textureType, SIGNAL(activated(int)),
157
this, SLOT(slotEffect()));
159
connect(d->blendGain, SIGNAL(valueChanged(int)),
160
this, SLOT(slotTimer()));
163
TextureTool::~TextureTool()
168
void TextureTool::readSettings()
170
KSharedConfig::Ptr config = KGlobal::config();
171
KConfigGroup group = config->group(d->configGroupName);
172
d->textureType->blockSignals(true);
173
d->blendGain->blockSignals(true);
174
d->textureType->setCurrentIndex(group.readEntry(d->configTextureTypeEntry, d->textureType->defaultIndex()));
175
d->blendGain->setValue(group.readEntry(d->configBlendGainEntry, d->blendGain->defaultValue()));
176
d->textureType->blockSignals(false);
177
d->blendGain->blockSignals(false);
181
void TextureTool::writeSettings()
183
KSharedConfig::Ptr config = KGlobal::config();
184
KConfigGroup group = config->group(d->configGroupName);
185
group.writeEntry(d->configTextureTypeEntry, d->textureType->currentIndex());
186
group.writeEntry(d->configBlendGainEntry, d->blendGain->value());
190
void TextureTool::slotResetSettings()
192
d->textureType->blockSignals(true);
193
d->blendGain->blockSignals(true);
195
d->textureType->slotReset();
196
d->blendGain->slotReset();
198
d->textureType->blockSignals(false);
199
d->blendGain->blockSignals(false);
204
void TextureTool::prepareEffect()
206
toolSettings()->setEnabled(false);
207
toolView()->setEnabled(false);
209
DImg image = d->previewWidget->getOriginalRegionImage();
210
QString texture = getTexturePath( d->textureType->currentIndex() );
211
int b = 255 - d->blendGain->value();
213
setFilter(new TextureFilter(&image, this, b, texture));
216
void TextureTool::prepareFinal()
218
toolSettings()->setEnabled(false);
219
toolView()->setEnabled(false);
221
ImageIface iface(0, 0);
222
QString texture = getTexturePath( d->textureType->currentIndex() );
223
int b = 255 - d->blendGain->value();
225
setFilter(new TextureFilter(iface.getOriginalImg(), this, b, texture));
228
void TextureTool::putPreviewData()
230
d->previewWidget->setPreviewImage(filter()->getTargetImage());
233
void TextureTool::putFinalData()
235
ImageIface iface(0, 0);
236
iface.putOriginalImage(i18n("Texture"), filter()->getTargetImage().bits());
239
void TextureTool::renderingFinished()
241
toolSettings()->setEnabled(true);
242
toolView()->setEnabled(true);
245
QString TextureTool::getTexturePath(int texture)
252
pattern = "paper-texture";
256
pattern = "paper2-texture";
260
pattern = "fabric-texture";
264
pattern = "burlap-texture";
268
pattern = "bricks-texture";
272
pattern = "bricks2-texture";
276
pattern = "canvas-texture";
280
pattern = "marble-texture";
284
pattern = "marble2-texture";
287
case BlueJeanTexture:
288
pattern = "bluejean-texture";
291
case CellWoodTexture:
292
pattern = "cellwood-texture";
295
case MetalWireTexture:
296
pattern = "metalwire-texture";
300
pattern = "modern-texture";
304
pattern = "wall-texture";
308
pattern = "moss-texture";
312
pattern = "stone-texture";
316
return (KStandardDirs::locate("data", QString("digikam/data/") + pattern + QString(".png")));
319
} // namespace DigikamDecorateImagePlugin