~ubuntu-branches/ubuntu/saucy/digikam/saucy

« back to all changes in this revision

Viewing changes to imageplugins/decorate/texturetool.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Christian Mangold
  • Date: 2010-04-09 21:30:01 UTC
  • mfrom: (1.2.28 upstream)
  • Revision ID: james.westby@ubuntu.com-20100409213001-4bfyibrd359rn7o3
Tags: 2:1.2.0-0ubuntu1
* New upstream release (LP: #560576)
* Remove all patches, fixed upstream
  - Remove quilt build-depend

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* ============================================================
 
2
 *
 
3
 * This file is a part of digiKam project
 
4
 * http://www.digikam.org
 
5
 *
 
6
 * Date        : 2005-03-10
 
7
 * Description : a plugin to apply texture over an image
 
8
 *
 
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>
 
11
 *
 
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)
 
16
 * any later version.
 
17
 *
 
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.
 
22
 *
 
23
 * ============================================================ */
 
24
 
 
25
#include "texturetool.moc"
 
26
 
 
27
// Qt includes
 
28
 
 
29
#include <QGridLayout>
 
30
#include <QImage>
 
31
#include <QLabel>
 
32
 
 
33
// KDE includes
 
34
 
 
35
#include <kapplication.h>
 
36
#include <kconfig.h>
 
37
#include <kconfiggroup.h>
 
38
#include <kglobal.h>
 
39
#include <kiconloader.h>
 
40
#include <klocale.h>
 
41
#include <knuminput.h>
 
42
#include <kstandarddirs.h>
 
43
 
 
44
// LibKDcraw includes
 
45
 
 
46
#include <libkdcraw/rcombobox.h>
 
47
#include <libkdcraw/rnuminput.h>
 
48
 
 
49
// Local includes
 
50
 
 
51
#include "dimg.h"
 
52
#include "editortoolsettings.h"
 
53
#include "imageiface.h"
 
54
#include "imageregionwidget.h"
 
55
#include "texturefilter.h"
 
56
 
 
57
using namespace KDcrawIface;
 
58
 
 
59
namespace DigikamDecorateImagePlugin
 
60
{
 
61
 
 
62
class TextureToolPriv
 
63
{
 
64
public:
 
65
 
 
66
    TextureToolPriv():
 
67
        configGroupName("texture Tool"),
 
68
        configTextureTypeEntry("TextureType"),
 
69
        configBlendGainEntry("BlendGain"),
 
70
 
 
71
        textureType(0),
 
72
        blendGain(0),
 
73
        previewWidget(0),
 
74
        gboxSettings(0)
 
75
        {}
 
76
 
 
77
    const QString       configGroupName;
 
78
    const QString       configTextureTypeEntry;
 
79
    const QString       configBlendGainEntry;
 
80
 
 
81
    RComboBox*          textureType;
 
82
    RIntNumInput*       blendGain;
 
83
    ImageRegionWidget*  previewWidget;
 
84
    EditorToolSettings* gboxSettings;
 
85
};
 
86
 
 
87
TextureTool::TextureTool(QObject* parent)
 
88
           : EditorToolThreaded(parent),
 
89
             d(new TextureToolPriv)
 
90
{
 
91
    setObjectName("texture");
 
92
    setToolName(i18n("Texture"));
 
93
    setToolIcon(SmallIcon("texture"));
 
94
 
 
95
    // -------------------------------------------------------------
 
96
 
 
97
    d->gboxSettings  = new EditorToolSettings;
 
98
    d->previewWidget = new ImageRegionWidget;
 
99
 
 
100
    // -------------------------------------------------------------
 
101
 
 
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."));
 
122
 
 
123
    // -------------------------------------------------------------
 
124
 
 
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."));
 
131
 
 
132
    // -------------------------------------------------------------
 
133
 
 
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);
 
143
 
 
144
    // -------------------------------------------------------------
 
145
 
 
146
    setToolSettings(d->gboxSettings);
 
147
    setToolView(d->previewWidget);
 
148
    setPreviewModeMask(PreviewToolBar::AllPreviewModes);         
 
149
    init();
 
150
 
 
151
    // -------------------------------------------------------------
 
152
 
 
153
    connect(d->previewWidget, SIGNAL(signalOriginalClipFocusChanged()),
 
154
            this, SLOT(slotEffect()));
 
155
 
 
156
    connect(d->textureType, SIGNAL(activated(int)),
 
157
            this, SLOT(slotEffect()));
 
158
 
 
159
    connect(d->blendGain, SIGNAL(valueChanged(int)),
 
160
            this, SLOT(slotTimer()));
 
161
}
 
162
 
 
163
TextureTool::~TextureTool()
 
164
{
 
165
    delete d;
 
166
}
 
167
 
 
168
void TextureTool::readSettings()
 
169
{
 
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);
 
178
    slotEffect();
 
179
}
 
180
 
 
181
void TextureTool::writeSettings()
 
182
{
 
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());
 
187
    group.sync();
 
188
}
 
189
 
 
190
void TextureTool::slotResetSettings()
 
191
{
 
192
    d->textureType->blockSignals(true);
 
193
    d->blendGain->blockSignals(true);
 
194
 
 
195
    d->textureType->slotReset();
 
196
    d->blendGain->slotReset();
 
197
 
 
198
    d->textureType->blockSignals(false);
 
199
    d->blendGain->blockSignals(false);
 
200
 
 
201
    slotEffect();
 
202
}
 
203
 
 
204
void TextureTool::prepareEffect()
 
205
{
 
206
    toolSettings()->setEnabled(false);    
 
207
    toolView()->setEnabled(false);    
 
208
 
 
209
    DImg image      = d->previewWidget->getOriginalRegionImage();
 
210
    QString texture = getTexturePath( d->textureType->currentIndex() );
 
211
    int b           = 255 - d->blendGain->value();
 
212
 
 
213
    setFilter(new TextureFilter(&image, this, b, texture));
 
214
}
 
215
 
 
216
void TextureTool::prepareFinal()
 
217
{
 
218
    toolSettings()->setEnabled(false);    
 
219
    toolView()->setEnabled(false);    
 
220
 
 
221
    ImageIface iface(0, 0);
 
222
    QString texture = getTexturePath( d->textureType->currentIndex() );
 
223
    int b           = 255 - d->blendGain->value();
 
224
 
 
225
    setFilter(new TextureFilter(iface.getOriginalImg(), this, b, texture));
 
226
}
 
227
 
 
228
void TextureTool::putPreviewData()
 
229
{
 
230
    d->previewWidget->setPreviewImage(filter()->getTargetImage());
 
231
}
 
232
 
 
233
void TextureTool::putFinalData()
 
234
{
 
235
    ImageIface iface(0, 0);
 
236
    iface.putOriginalImage(i18n("Texture"), filter()->getTargetImage().bits());
 
237
}
 
238
 
 
239
void TextureTool::renderingFinished()
 
240
{
 
241
    toolSettings()->setEnabled(true);    
 
242
    toolView()->setEnabled(true);
 
243
}
 
244
 
 
245
QString TextureTool::getTexturePath(int texture)
 
246
{
 
247
    QString pattern;
 
248
 
 
249
    switch (texture)
 
250
    {
 
251
       case PaperTexture:
 
252
          pattern = "paper-texture";
 
253
          break;
 
254
 
 
255
       case Paper2Texture:
 
256
          pattern = "paper2-texture";
 
257
          break;
 
258
 
 
259
       case FabricTexture:
 
260
          pattern = "fabric-texture";
 
261
          break;
 
262
 
 
263
       case BurlapTexture:
 
264
          pattern = "burlap-texture";
 
265
          break;
 
266
 
 
267
       case BricksTexture:
 
268
          pattern = "bricks-texture";
 
269
          break;
 
270
 
 
271
       case Bricks2Texture:
 
272
          pattern = "bricks2-texture";
 
273
          break;
 
274
 
 
275
       case CanvasTexture:
 
276
          pattern = "canvas-texture";
 
277
          break;
 
278
 
 
279
       case MarbleTexture:
 
280
          pattern = "marble-texture";
 
281
          break;
 
282
 
 
283
       case Marble2Texture:
 
284
          pattern = "marble2-texture";
 
285
          break;
 
286
 
 
287
       case BlueJeanTexture:
 
288
          pattern = "bluejean-texture";
 
289
          break;
 
290
 
 
291
       case CellWoodTexture:
 
292
          pattern = "cellwood-texture";
 
293
          break;
 
294
 
 
295
       case MetalWireTexture:
 
296
          pattern = "metalwire-texture";
 
297
          break;
 
298
 
 
299
       case ModernTexture:
 
300
          pattern = "modern-texture";
 
301
          break;
 
302
 
 
303
       case WallTexture:
 
304
          pattern = "wall-texture";
 
305
          break;
 
306
 
 
307
       case MossTexture:
 
308
          pattern = "moss-texture";
 
309
          break;
 
310
 
 
311
       case StoneTexture:
 
312
          pattern = "stone-texture";
 
313
          break;
 
314
    }
 
315
 
 
316
    return (KStandardDirs::locate("data", QString("digikam/data/") + pattern + QString(".png")));
 
317
}
 
318
 
 
319
}  // namespace DigikamDecorateImagePlugin