1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
|
/* ============================================================
*
* This file is a part of digiKam project
* http://www.digikam.org
*
* Date : 2005-01-04
* Description : a Digikam image editor plugin for superimpose a
* template to an image.
*
* Copyright (C) 2005-2008 by Gilles Caulier <caulier dot gilles at gmail dot com>
* Copyright (C) 2006-2008 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
*
* This program is free software; you can redistribute it
* and/or modify it under the terms of the GNU General
* Public License as published by the Free Software Foundation;
* either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* ============================================================ */
// Qt includes.
#include <qvgroupbox.h>
#include <qgroupbox.h>
#include <qlabel.h>
#include <qpushbutton.h>
#include <qpixmap.h>
#include <qwhatsthis.h>
#include <qtooltip.h>
#include <qlayout.h>
#include <qframe.h>
#include <qdir.h>
#include <qfile.h>
#include <qhbuttongroup.h>
// KDE includes.
#include <kcursor.h>
#include <klocale.h>
#include <kaboutdata.h>
#include <khelpmenu.h>
#include <kiconloader.h>
#include <kapplication.h>
#include <kpopupmenu.h>
#include <kstandarddirs.h>
#include <kprogress.h>
#include <knuminput.h>
#include <kiconloader.h>
#include <kfiledialog.h>
#include <kapplication.h>
#include <kconfig.h>
#include <kglobalsettings.h>
// Local includes.
#include "daboutdata.h"
#include "ddebug.h"
#include "dimg.h"
#include "imageiface.h"
#include "editortoolsettings.h"
#include "thumbbar.h"
#include "superimposewidget.h"
#include "dirselectwidget.h"
#include "superimposetool.h"
#include "superimposetool.moc"
using namespace Digikam;
namespace DigikamSuperImposeImagesPlugin
{
SuperImposeTool::SuperImposeTool(QObject* parent)
: EditorTool(parent)
{
setName("superimpose");
setToolName(i18n("Template Superimpose"));
setToolIcon(SmallIcon("superimpose"));
// -------------------------------------------------------------
QFrame *frame = new QFrame(0);
frame->setFrameStyle(QFrame::Panel|QFrame::Sunken);
QGridLayout* gridFrame = new QGridLayout(frame, 1, 2);
m_previewWidget = new SuperImposeWidget(400, 300, frame);
QWhatsThis::add( m_previewWidget, i18n("<p>This is the preview of the template "
"superimposed onto the image.") );
// -------------------------------------------------------------
QHButtonGroup *bGroup = new QHButtonGroup(frame);
KIconLoader icon;
bGroup->addSpace(0);
QPushButton *zoomInButton = new QPushButton( bGroup );
bGroup->insert(zoomInButton, ZOOMIN);
zoomInButton->setPixmap( icon.loadIcon( "viewmag+", (KIcon::Group)KIcon::Toolbar ) );
zoomInButton->setToggleButton(true);
QToolTip::add( zoomInButton, i18n( "Zoom in" ) );
bGroup->addSpace(20);
QPushButton *zoomOutButton = new QPushButton( bGroup );
bGroup->insert(zoomOutButton, ZOOMOUT);
zoomOutButton->setPixmap( icon.loadIcon( "viewmag-", (KIcon::Group)KIcon::Toolbar ) );
zoomOutButton->setToggleButton(true);
QToolTip::add( zoomOutButton, i18n( "Zoom out" ) );
bGroup->addSpace(20);
QPushButton *moveButton = new QPushButton( bGroup );
bGroup->insert(moveButton, MOVE);
moveButton->setPixmap( icon.loadIcon( "move", (KIcon::Group)KIcon::Toolbar ) );
moveButton->setToggleButton(true);
moveButton->setOn(true);
QToolTip::add( moveButton, i18n( "Move" ) );
bGroup->addSpace(20);
bGroup->setExclusive(true);
bGroup->setFrameShape(QFrame::NoFrame);
gridFrame->addMultiCellWidget(m_previewWidget, 0, 0, 0, 2);
gridFrame->addMultiCellWidget(bGroup, 1, 1, 1, 1);
gridFrame->setRowStretch(0, 10);
gridFrame->setColStretch(0, 10);
gridFrame->setColStretch(2, 10);
gridFrame->setMargin(0);
gridFrame->setSpacing(0);
setToolView(frame);
// -------------------------------------------------------------
m_gboxSettings = new EditorToolSettings(EditorToolSettings::Default|
EditorToolSettings::Ok|
EditorToolSettings::Cancel);
QGridLayout* grid = new QGridLayout(m_gboxSettings->plainPage(), 1, 1);
m_thumbnailsBar = new ThumbBarView(m_gboxSettings->plainPage());
m_dirSelect = new DirSelectWidget(m_gboxSettings->plainPage());
QPushButton *templateDirButton = new QPushButton( i18n("Root Directory..."), m_gboxSettings->plainPage() );
QWhatsThis::add( templateDirButton, i18n("<p>Set here the current templates' root directory.") );
grid->addMultiCellWidget(m_thumbnailsBar, 0, 1, 0, 0);
grid->addMultiCellWidget(m_dirSelect, 0, 0, 1, 1);
grid->addMultiCellWidget(templateDirButton, 1, 1, 1, 1);
grid->setMargin(0);
grid->setSpacing(m_gboxSettings->spacingHint());
grid->setColStretch(1, 10);
setToolSettings(m_gboxSettings);
init();
// -------------------------------------------------------------
connect(bGroup, SIGNAL(released(int)),
m_previewWidget, SLOT(slotEditModeChanged(int)));
connect(m_thumbnailsBar, SIGNAL(signalURLSelected(const KURL&)),
m_previewWidget, SLOT(slotSetCurrentTemplate(const KURL&)));
connect(m_dirSelect, SIGNAL(folderItemSelected(const KURL &)),
this, SLOT(slotTemplateDirChanged(const KURL &)));
connect(templateDirButton, SIGNAL(clicked()),
this, SLOT(slotRootTemplateDirChanged()));
// -------------------------------------------------------------
populateTemplates();
}
SuperImposeTool::~SuperImposeTool()
{
}
void SuperImposeTool::populateTemplates()
{
m_thumbnailsBar->clear(true);
if (!m_templatesUrl.isValid() || !m_templatesUrl.isLocalFile())
return;
QDir dir(m_templatesUrl.path(), "*.png *.PNG");
if (!dir.exists())
return;
dir.setFilter ( QDir::Files | QDir::NoSymLinks );
const QFileInfoList* fileinfolist = dir.entryInfoList();
if (!fileinfolist)
return;
QFileInfoListIterator it(*fileinfolist);
QFileInfo* fi;
while( (fi = it.current() ) )
{
new ThumbBarItem( m_thumbnailsBar, KURL(fi->filePath()) );
++it;
}
}
void SuperImposeTool::readSettings()
{
KConfig* config = kapp->config();
config->setGroup("Album Settings");
KURL albumDBUrl( config->readPathEntry("Album Path", KGlobalSettings::documentPath()) );
config->setGroup("superimpose Tool");
config->setGroup("Template Superimpose Tool Settings");
m_templatesRootUrl.setPath( config->readEntry("Templates Root URL", albumDBUrl.path()) );
m_templatesUrl.setPath( config->readEntry("Templates URL", albumDBUrl.path()) );
m_dirSelect->setRootPath(m_templatesRootUrl, m_templatesUrl);
}
void SuperImposeTool::writeSettings()
{
KConfig* config = kapp->config();
config->setGroup("superimpose Tool");
config->writeEntry( "Templates Root URL", m_dirSelect->rootPath().path() );
config->writeEntry( "Templates URL", m_templatesUrl.path() );
config->sync();
}
void SuperImposeTool::slotResetSettings()
{
m_previewWidget->resetEdit();
}
void SuperImposeTool::slotRootTemplateDirChanged()
{
KURL url = KFileDialog::getExistingDirectory(m_templatesRootUrl.path(), kapp->activeWindow(),
i18n("Select Template Root Directory to Use"));
if( url.isValid() )
{
m_dirSelect->setRootPath(url);
m_templatesRootUrl = url;
m_templatesUrl = url;
populateTemplates();
}
}
void SuperImposeTool::slotTemplateDirChanged(const KURL& url)
{
if( url.isValid() )
{
m_templatesUrl = url;
populateTemplates();
}
}
void SuperImposeTool::finalRendering()
{
kapp->setOverrideCursor(KCursor::waitCursor());
m_previewWidget->setEnabled(false);
m_dirSelect->setEnabled(false);
m_thumbnailsBar->setEnabled(false);
ImageIface iface(0, 0);
DImg img = m_previewWidget->makeSuperImpose();
iface.putOriginalImage(i18n("Super Impose"), img.bits(),
img.width(), img.height() );
m_previewWidget->setEnabled(true);
m_dirSelect->setEnabled(true);
m_thumbnailsBar->setEnabled(true);
kapp->restoreOverrideCursor();
}
} // NameSpace DigikamSuperImposeImagesPlugin
|