diff options
author | Michele Calgaro <michele.calgaro@yahoo.it> | 2024-11-22 18:41:30 +0900 |
---|---|---|
committer | Michele Calgaro <michele.calgaro@yahoo.it> | 2024-11-22 20:55:03 +0900 |
commit | 5bed6e4a4c916a97f8fe4d1b07f7eecf4d733b90 (patch) | |
tree | f89cc49efc9ca1d0e1579ecb079ee7e7088ff8c8 /src/imageplugins/superimpose | |
parent | 0bfbf616d9c1fd7abb1bd02732389ab35e5f8771 (diff) | |
download | digikam-5bed6e4a4c916a97f8fe4d1b07f7eecf4d733b90.tar.gz digikam-5bed6e4a4c916a97f8fe4d1b07f7eecf4d733b90.zip |
Rename 'digikam' folder to 'src'
Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
(cherry picked from commit ee0d99607c14cb63d3ebdb3a970b508949fa8219)
Diffstat (limited to 'src/imageplugins/superimpose')
-rw-r--r-- | src/imageplugins/superimpose/Makefile.am | 35 | ||||
-rw-r--r-- | src/imageplugins/superimpose/digikamimageplugin_superimpose.desktop | 52 | ||||
-rw-r--r-- | src/imageplugins/superimpose/digikamimageplugin_superimpose_ui.rc | 20 | ||||
-rw-r--r-- | src/imageplugins/superimpose/dirselectwidget.cpp | 182 | ||||
-rw-r--r-- | src/imageplugins/superimpose/dirselectwidget.h | 78 | ||||
-rw-r--r-- | src/imageplugins/superimpose/imageeffect_superimpose.cpp | 280 | ||||
-rw-r--r-- | src/imageplugins/superimpose/imageeffect_superimpose.h | 87 | ||||
-rw-r--r-- | src/imageplugins/superimpose/imageplugin_superimpose.cpp | 71 | ||||
-rw-r--r-- | src/imageplugins/superimpose/imageplugin_superimpose.h | 58 | ||||
-rw-r--r-- | src/imageplugins/superimpose/superimpose.cpp | 70 | ||||
-rw-r--r-- | src/imageplugins/superimpose/superimpose.h | 67 | ||||
-rw-r--r-- | src/imageplugins/superimpose/superimposetool.cpp | 271 | ||||
-rw-r--r-- | src/imageplugins/superimpose/superimposetool.h | 90 | ||||
-rw-r--r-- | src/imageplugins/superimpose/superimposewidget.cpp | 329 | ||||
-rw-r--r-- | src/imageplugins/superimpose/superimposewidget.h | 118 |
15 files changed, 1808 insertions, 0 deletions
diff --git a/src/imageplugins/superimpose/Makefile.am b/src/imageplugins/superimpose/Makefile.am new file mode 100644 index 00000000..686eff2a --- /dev/null +++ b/src/imageplugins/superimpose/Makefile.am @@ -0,0 +1,35 @@ +METASOURCES = AUTO + +INCLUDES = -I$(top_srcdir)/src/utilities/imageeditor/editor \ + -I$(top_srcdir)/src/utilities/imageeditor/canvas \ + -I$(top_srcdir)/src/libs/histogram \ + -I$(top_srcdir)/src/libs/levels \ + -I$(top_srcdir)/src/libs/curves \ + -I$(top_srcdir)/src/libs/whitebalance \ + -I$(top_srcdir)/src/libs/widgets/common \ + -I$(top_srcdir)/src/libs/widgets/iccprofiles \ + -I$(top_srcdir)/src/libs/widgets/imageplugins \ + -I$(top_srcdir)/src/libs/dialogs \ + -I$(top_srcdir)/src/libs/dimg \ + -I$(top_srcdir)/src/libs/dmetadata \ + -I$(top_srcdir)/src/libs/dimg/filters \ + -I$(top_srcdir)/src/libs/thumbbar \ + -I$(top_srcdir)/src/digikam \ + $(LIBKDCRAW_CFLAGS) \ + $(all_includes) + +digikamimageplugin_superimpose_la_SOURCES = superimposewidget.cpp superimpose.cpp dirselectwidget.cpp \ + imageplugin_superimpose.cpp superimposetool.cpp + + +digikamimageplugin_superimpose_la_LIBADD = $(LIB_TDEPARTS) \ + $(top_builddir)/src/digikam/libdigikam.la + +digikamimageplugin_superimpose_la_LDFLAGS = -module $(KDE_PLUGIN) $(all_libraries) -ltdecore -ltdeui $(LIB_TQT) -ltdefx -lkdcraw -ltdeio + +kde_services_DATA = digikamimageplugin_superimpose.desktop + +kde_module_LTLIBRARIES = digikamimageplugin_superimpose.la + +rcdir = $(kde_datadir)/digikam +rc_DATA = digikamimageplugin_superimpose_ui.rc diff --git a/src/imageplugins/superimpose/digikamimageplugin_superimpose.desktop b/src/imageplugins/superimpose/digikamimageplugin_superimpose.desktop new file mode 100644 index 00000000..ef395a4a --- /dev/null +++ b/src/imageplugins/superimpose/digikamimageplugin_superimpose.desktop @@ -0,0 +1,52 @@ +[Desktop Entry] +Name=ImagePlugin_SuperImpose +Name[bg]=Приставка за снимки - Налагане +Name[da]=Billedplugin_Indkopiering +Name[el]=ΠρόσθετοΕικόνας_Υπερέκθεση +Name[fi]=SuperImpose +Name[hr]=Presvlačenje +Name[it]=PluginImmagini_Sovrapposizione +Name[nl]=Afbeeldingsplugin_SjabloonAanbrengen +Name[sr]=Надоградња +Name[sr@Latn]=Nadogradnja +Name[sv]=Insticksprogram för överlagring +Name[tr]=ResimEklentisi_Büyüt +Name[xx]=xxImagePlugin_SuperImposexx + +Type=Service +X-TDE-ServiceTypes=Digikam/ImagePlugin +Encoding=UTF-8 +Comment=Template superimpose plugin for digiKam +Comment[bg]=Приставка на digiKam за налагане на снимки една върху друга +Comment[ca]=Connector pel digiKam per sobreimposar una plantilla +Comment[da]=Plugin til skabelon-indkopiering i Digikam +Comment[de]=digiKam-Modul zum Anwenden von Schablonen auf ein Bild +Comment[el]=Πρόσθετο πρότυπης υπερέκθεσης για το digiKam +Comment[es]=Plugin de digiKam para superponer una plantilla sobre la imagen +Comment[et]=DigiKami pildile malli lisamise plugin +Comment[fa]=وصلۀ افزودن قالب برای digiKam +Comment[fi]=Liittää useampia kuvia päällekäin +Comment[gl]=Un plugin de digiKam para sobrepor modelos +Comment[hr]=digiKam dodatak za presvlačenje predloškom +Comment[is]=Íforrit fyrir digiKam sem hleður forsniðinni mynd ofan á þá sem unnið er með +Comment[it]=Plugin di sovrapposizione di modelli per digiKam +Comment[ja]=digiKam テンプレート重ね合わせプラグイン +Comment[ms]=Templat plugin superimpose untuk digiKam +Comment[nds]=digiKam-Moduul för't Vörblennen vun Vörlagen +Comment[nl]=Digikam-plugin voor het aanbrengen van een sjabloon op de afbeelding +Comment[pa]=ਡਿਜ਼ੀਕੈਮ ਲਈ ਨਮੂਨਾ ਸੁਪਰ-ਇਮਪੋਜ਼ ਪਲੱਗਇਨ +Comment[pl]=Wtyczka do programu digiKam umożliwiająca nałożenie szablonu na obraz +Comment[pt]=Um 'plugin' do digiKam para sobrepor modelos +Comment[pt_BR]=Um 'plugin' do digiKam para sobrepor modelos +Comment[ru]=Модуль накладывания шаблона для digiKam +Comment[sk]=digiKam plugin pre prekrytie fotografie šablónou +Comment[sr]=digiKam-ов прикључак надоградњу шаблонима +Comment[sr@Latn]=digiKam-ov priključak nadogradnju šablonima +Comment[sv]=Digikam insticksprogram för överlagringsmall +Comment[tr]=digiKam için şablon büyütme eklentisi +Comment[uk]=Втулок накладання шаблону для digiKam +Comment[vi]=Phần bổ sung đặt biểu mẫu trên cho digiKam +Comment[xx]=xxTemplate superimpose plugin for digiKamxx + +X-TDE-Library=digikamimageplugin_superimpose +author=Gilles Caulier, caulier dot gilles at gmail dot com diff --git a/src/imageplugins/superimpose/digikamimageplugin_superimpose_ui.rc b/src/imageplugins/superimpose/digikamimageplugin_superimpose_ui.rc new file mode 100644 index 00000000..ced7edac --- /dev/null +++ b/src/imageplugins/superimpose/digikamimageplugin_superimpose_ui.rc @@ -0,0 +1,20 @@ +<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd"> +<kpartgui version="4" name="digikamimageplugin_superimpose" > + + <MenuBar> + + <Menu name="Decorate" ><text>&Decorate</text> + <Action name="imageplugin_superimpose" /> + </Menu> + + </MenuBar> + + <ToolBar name="ToolBar" > + <text>Main Toolbar</text> + </ToolBar> + + <ActionProperties> + <Action shortcut="" name="imageplugin_superimpose" /> + </ActionProperties> + +</kpartgui> diff --git a/src/imageplugins/superimpose/dirselectwidget.cpp b/src/imageplugins/superimpose/dirselectwidget.cpp new file mode 100644 index 00000000..4856d73c --- /dev/null +++ b/src/imageplugins/superimpose/dirselectwidget.cpp @@ -0,0 +1,182 @@ +/* ============================================================ + * + * 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. + * + * ============================================================ */ + +// TQt includes. + +#include <tqlayout.h> +#include <tqheader.h> +#include <tqlistview.h> +#include <tqdir.h> + +// KDE includes. + +#include <tdelocale.h> + +// Local includes. + +#include "ddebug.h" +#include "dirselectwidget.h" +#include "dirselectwidget.moc" + +namespace DigikamSuperImposeImagesPlugin +{ + +struct DirSelectWidget::Private +{ + KFileTreeBranch* m_item; + TQStringList m_pendingPath; + TQString m_handled; + KURL m_rootUrl; +}; + +DirSelectWidget::DirSelectWidget(TQWidget* parent, const char* name, TQString headerLabel) + : KFileTreeView( parent, name) +{ + d = new Private; + + addColumn( headerLabel ); + + if ( headerLabel.isNull() ) + header()->hide(); + + setAlternateBackground(TQColor()); +} + +DirSelectWidget::DirSelectWidget(KURL rootUrl, KURL currentUrl, + TQWidget* parent, const char* name, TQString headerLabel) + : KFileTreeView( parent, name) +{ + d = new Private; + + addColumn( headerLabel ); + + if ( headerLabel.isNull() ) + header()->hide(); + + setAlternateBackground(TQColor()); + setRootPath(rootUrl, currentUrl); +} + +DirSelectWidget::~DirSelectWidget() +{ + delete d; +} + +KURL DirSelectWidget::path() const +{ + return currentURL(); +} + +void DirSelectWidget::load() +{ + if ( d->m_pendingPath.isEmpty() ) + { + disconnect( d->m_item, TQ_SIGNAL( populateFinished(KFileTreeViewItem *) ), + this, TQ_SLOT( load() ) ); + + emit folderItemSelected(currentURL()); + return; + } + + TQString item = d->m_pendingPath.front(); + d->m_pendingPath.pop_front(); + d->m_handled += item; + KFileTreeViewItem* branch = findItem( d->m_item, d->m_handled ); + + if ( !branch ) + { + DDebug() << "Unable to open " << d->m_handled << endl; + } + else + { + branch->setOpen( true ); + setSelected( branch, true ); + ensureItemVisible ( branch ); + d->m_handled += '/'; + + if ( branch->alreadyListed() ) + load(); + } +} + +void DirSelectWidget::setCurrentPath(KURL currentUrl) +{ + if ( !currentUrl.isValid() ) + return; + + TQString currentPath = TQDir::cleanDirPath(currentUrl.path()); + currentPath = currentPath.mid( d->m_rootUrl.path().length() ); + d->m_pendingPath.clear(); + d->m_handled = TQString(""); + d->m_pendingPath = TQStringList::split( "/", currentPath, true ); + + if ( !d->m_pendingPath[0].isEmpty() ) + d->m_pendingPath.prepend( "" ); // ensure we open the root first. + + connect( d->m_item, TQ_SIGNAL( populateFinished(KFileTreeViewItem *) ), + this, TQ_SLOT( load() ) ); + load(); +} + +void DirSelectWidget::setRootPath(KURL rootUrl, KURL currentUrl) +{ + d->m_rootUrl = rootUrl; + clear(); + TQString root = TQDir::cleanDirPath(rootUrl.path()); + + if ( !root.endsWith("/")) + root.append("/"); + + TQString currentPath = TQDir::cleanDirPath(currentUrl.isValid() ? currentUrl.path() : root); + + d->m_item = addBranch( rootUrl, rootUrl.fileName() ); + setDirOnlyMode( d->m_item, true ); + currentPath = currentPath.mid( root.length() ); + d->m_pendingPath = TQStringList::split( "/", currentPath, true ); + + if ( !d->m_pendingPath[0].isEmpty() ) + d->m_pendingPath.prepend( "" ); // ensure we open the root first. + + connect( d->m_item, TQ_SIGNAL( populateFinished(KFileTreeViewItem *) ), + this, TQ_SLOT( load() ) ); + + load(); + + connect( this, TQ_SIGNAL( executed(TQListViewItem *) ), + this, TQ_SLOT( slotFolderSelected(TQListViewItem *) ) ); +} + +KURL DirSelectWidget::rootPath(void) +{ + return d->m_rootUrl; +} + +void DirSelectWidget::slotFolderSelected(TQListViewItem *) +{ + emit folderItemSelected(currentURL()); +} + +} // NameSpace DigikamSuperImposeImagesPlugin + diff --git a/src/imageplugins/superimpose/dirselectwidget.h b/src/imageplugins/superimpose/dirselectwidget.h new file mode 100644 index 00000000..1ee4abc2 --- /dev/null +++ b/src/imageplugins/superimpose/dirselectwidget.h @@ -0,0 +1,78 @@ +/* ============================================================ + * + * 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. + * + * ============================================================ */ + +#ifndef DIRSELECTWIDGET_H +#define DIRSELECTWIDGET_H + +// TQt includes. + +#include <tqwidget.h> +#include <tqstring.h> + +// KDE includes. + +#include <tdefiletreeview.h> +#include <kurl.h> + +namespace DigikamSuperImposeImagesPlugin +{ + +class DirSelectWidget : public KFileTreeView +{ +TQ_OBJECT + + +public: + + DirSelectWidget(TQWidget* parent, const char* name=0, TQString headerLabel=TQString()); + + DirSelectWidget(KURL rootUrl=KURL("/"), KURL currentUrl=KURL(), + TQWidget* parent=0, const char* name=0, TQString headerLabel=TQString()); + + ~DirSelectWidget(); + + KURL path() const; + KURL rootPath(void); + void setRootPath(KURL rootUrl, KURL currentUrl=KURL(TQString())); + void setCurrentPath(KURL currentUrl); + +signals : + + void folderItemSelected(const KURL &url); + +protected slots: + + void load(); + void slotFolderSelected(TQListViewItem *); + +private: + + struct Private; + Private* d; +}; + +} // NameSpace DigikamSuperImposeImagesPlugin + +#endif /* DIRSELECTWIDGET_H */ diff --git a/src/imageplugins/superimpose/imageeffect_superimpose.cpp b/src/imageplugins/superimpose/imageeffect_superimpose.cpp new file mode 100644 index 00000000..1cea3e08 --- /dev/null +++ b/src/imageplugins/superimpose/imageeffect_superimpose.cpp @@ -0,0 +1,280 @@ +/* ============================================================ + * + * 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. + * + * ============================================================ */ + +// TQt includes. + +#include <tqvgroupbox.h> +#include <tqgroupbox.h> +#include <tqlabel.h> +#include <tqpushbutton.h> +#include <tqpixmap.h> +#include <tqwhatsthis.h> +#include <tqtooltip.h> +#include <tqlayout.h> +#include <tqframe.h> +#include <tqdir.h> +#include <tqfile.h> +#include <tqhbuttongroup.h> + +// KDE includes. + +#include <kcursor.h> +#include <tdelocale.h> +#include <tdeaboutdata.h> +#include <khelpmenu.h> +#include <kiconloader.h> +#include <tdeapplication.h> +#include <tdepopupmenu.h> +#include <kstandarddirs.h> +#include <kprogress.h> +#include <knuminput.h> +#include <kiconloader.h> +#include <tdefiledialog.h> +#include <tdeapplication.h> +#include <tdeconfig.h> +#include <tdeglobalsettings.h> + +// Local includes. + +#include "version.h" +#include "ddebug.h" +#include "dimg.h" +#include "imageiface.h" +#include "thumbbar.h" +#include "superimposewidget.h" +#include "dirselectwidget.h" +#include "imageeffect_superimpose.h" +#include "imageeffect_superimpose.moc" + +namespace DigikamSuperImposeImagesPlugin +{ + +ImageEffect_SuperImpose::ImageEffect_SuperImpose(TQWidget* parent) + : Digikam::ImageDlgBase(parent, i18n("Template Superimpose to Photograph"), + "superimpose", false, false) +{ + TQString whatsThis; + + // About data and help button. + + TDEAboutData* about = new TDEAboutData("digikam", + I18N_NOOP("Template Superimpose"), + digikam_version, + I18N_NOOP("A digiKam image plugin to superimpose a template onto a photograph."), + TDEAboutData::License_GPL, + "(c) 2005-2006, Gilles Caulier\n" + "(c) 2006-2008, Gilles Caulier and Marcel Wiesweg", + 0, + "http://www.digikam.org"); + + about->addAuthor("Gilles Caulier", I18N_NOOP("Author and maintainer"), + "caulier dot gilles at gmail dot com"); + + about->addAuthor("Marcel Wiesweg", I18N_NOOP("Developer"), + "marcel dot wiesweg at gmx dot de"); + + setAboutData(about); + + // ------------------------------------------------------------- + + TQFrame *frame = new TQFrame(plainPage()); + frame->setFrameStyle(TQFrame::Panel|TQFrame::Sunken); + + TQGridLayout* gridFrame = new TQGridLayout( frame, 1, 2, spacingHint()); + m_previewWidget = new SuperImposeWidget(400, 300, frame); + gridFrame->addMultiCellWidget(m_previewWidget, 0, 0, 0, 2); + gridFrame->setRowStretch(0, 10); + TQWhatsThis::add( m_previewWidget, i18n("<p>This is the preview of the template " + "superimposed onto the image.") ); + + // ------------------------------------------------------------- + + TQHButtonGroup *bGroup = new TQHButtonGroup(frame); + TDEIconLoader icon; + bGroup->addSpace(0); + TQPushButton *zoomInButton = new TQPushButton( bGroup ); + bGroup->insert(zoomInButton, ZOOMIN); + zoomInButton->setPixmap( icon.loadIcon( "zoom-in", (TDEIcon::Group)TDEIcon::Toolbar ) ); + zoomInButton->setToggleButton(true); + TQToolTip::add( zoomInButton, i18n( "Zoom in" ) ); + bGroup->addSpace(20); + TQPushButton *zoomOutButton = new TQPushButton( bGroup ); + bGroup->insert(zoomOutButton, ZOOMOUT); + zoomOutButton->setPixmap( icon.loadIcon( "zoom-out", (TDEIcon::Group)TDEIcon::Toolbar ) ); + zoomOutButton->setToggleButton(true); + TQToolTip::add( zoomOutButton, i18n( "Zoom out" ) ); + bGroup->addSpace(20); + TQPushButton *moveButton = new TQPushButton( bGroup ); + bGroup->insert(moveButton, MOVE); + moveButton->setPixmap( icon.loadIcon( "move", (TDEIcon::Group)TDEIcon::Toolbar ) ); + moveButton->setToggleButton(true); + moveButton->setOn(true); + TQToolTip::add( moveButton, i18n( "Move" ) ); + bGroup->addSpace(20); + bGroup->setExclusive(true); + bGroup->setFrameShape(TQFrame::NoFrame); + gridFrame->addMultiCellWidget(bGroup, 1, 1, 1, 1); + gridFrame->setColStretch(0, 10); + gridFrame->setColStretch(2, 10); + + setPreviewAreaWidget(frame); + + // ------------------------------------------------------------- + + TQWidget *gbox2 = new TQWidget(plainPage()); + TQGridLayout* grid = new TQGridLayout( gbox2, 1, 1, marginHint(), spacingHint()); + + m_thumbnailsBar = new Digikam::ThumbBarView(gbox2); + m_dirSelect = new DirSelectWidget(gbox2); + TQPushButton *templateDirButton = new TQPushButton( i18n("Root Directory..."), gbox2 ); + TQWhatsThis::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->setColStretch(1, 10); + + setUserAreaWidget(gbox2); + + // ------------------------------------------------------------- + + connect(bGroup, TQ_SIGNAL(released(int)), + m_previewWidget, TQ_SLOT(slotEditModeChanged(int))); + + connect(m_thumbnailsBar, TQ_SIGNAL(signalURLSelected(const KURL&)), + m_previewWidget, TQ_SLOT(slotSetCurrentTemplate(const KURL&))); + + connect(m_dirSelect, TQ_SIGNAL(folderItemSelected(const KURL &)), + this, TQ_SLOT(slotTemplateDirChanged(const KURL &))); + + connect(templateDirButton, TQ_SIGNAL(clicked()), + this, TQ_SLOT(slotRootTemplateDirChanged())); + + // ------------------------------------------------------------- + + populateTemplates(); +} + +ImageEffect_SuperImpose::~ImageEffect_SuperImpose() +{ +} + +void ImageEffect_SuperImpose::populateTemplates(void) +{ + m_thumbnailsBar->clear(true); + + if (!m_templatesUrl.isValid() || !m_templatesUrl.isLocalFile()) + return; + + TQDir dir(m_templatesUrl.path(), "*.png *.PNG"); + + if (!dir.exists()) + return; + + dir.setFilter ( TQDir::Files | TQDir::NoSymLinks ); + + const TQFileInfoList* fileinfolist = dir.entryInfoList(); + if (!fileinfolist) + return; + + TQFileInfoListIterator it(*fileinfolist); + TQFileInfo* fi; + + while( (fi = it.current() ) ) + { + new Digikam::ThumbBarItem( m_thumbnailsBar, KURL(fi->filePath()) ); + ++it; + } +} + +void ImageEffect_SuperImpose::readUserSettings() +{ + TDEConfig* config = kapp->config(); + config->setGroup("Album Settings"); + KURL albumDBUrl( config->readPathEntry("Album Path", TDEGlobalSettings::documentPath()) ); + config->setGroup("superimpose Tool Dialog"); + 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 ImageEffect_SuperImpose::writeUserSettings() +{ + TDEConfig* config = kapp->config(); + config->setGroup("superimpose Tool Dialog"); + config->writeEntry( "Templates Root URL", m_dirSelect->rootPath().path() ); + config->writeEntry( "Templates URL", m_templatesUrl.path() ); + config->sync();} + +void ImageEffect_SuperImpose::resetValues() +{ + m_previewWidget->resetEdit(); +} + +void ImageEffect_SuperImpose::slotRootTemplateDirChanged(void) +{ + 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 ImageEffect_SuperImpose::slotTemplateDirChanged(const KURL& url) +{ + if( url.isValid() ) + { + m_templatesUrl = url; + populateTemplates(); + } +} + +void ImageEffect_SuperImpose::finalRendering() +{ + setCursor(KCursor::waitCursor()); + m_previewWidget->setEnabled(false); + m_dirSelect->setEnabled(false); + m_thumbnailsBar->setEnabled(false); + + Digikam::ImageIface iface(0, 0); + Digikam::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); + unsetCursor(); + accept(); +} + +} // NameSpace DigikamSuperImposeImagesPlugin + diff --git a/src/imageplugins/superimpose/imageeffect_superimpose.h b/src/imageplugins/superimpose/imageeffect_superimpose.h new file mode 100644 index 00000000..8eb8c18f --- /dev/null +++ b/src/imageplugins/superimpose/imageeffect_superimpose.h @@ -0,0 +1,87 @@ +/* ============================================================ + * + * 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. + * + * ============================================================ */ + +#ifndef IMAGEEFFECT_SUPERIMPOSE_H +#define IMAGEEFFECT_SUPERIMPOSE_H + +// KDE include. + +#include <kurl.h> + +// Digikam includes. + +#include "imagedlgbase.h" + +class TQPushButton; + +namespace Digikam +{ +class ThumbBarView; +} + +namespace DigikamSuperImposeImagesPlugin +{ + +class DirSelectWidget; +class SuperImposeWidget; + +class ImageEffect_SuperImpose : public Digikam::ImageDlgBase +{ + TQ_OBJECT + + +public: + + ImageEffect_SuperImpose(TQWidget* parent); + ~ImageEffect_SuperImpose(); + +private slots: + + void slotTemplateDirChanged(const KURL& url); + void slotRootTemplateDirChanged(void); + +private: + + void readUserSettings(); + void writeUserSettings(); + void resetValues(); + void populateTemplates(void); + void finalRendering(); + +private: + + KURL m_templatesUrl; + KURL m_templatesRootUrl; + + Digikam::ThumbBarView *m_thumbnailsBar; + + SuperImposeWidget *m_previewWidget; + + DirSelectWidget *m_dirSelect; +}; + +} // NameSpace DigikamSuperImposeImagesPlugin + +#endif /* IMAGEEFFECT_SUPERIMPOSE_H */ diff --git a/src/imageplugins/superimpose/imageplugin_superimpose.cpp b/src/imageplugins/superimpose/imageplugin_superimpose.cpp new file mode 100644 index 00000000..ceba44ef --- /dev/null +++ b/src/imageplugins/superimpose/imageplugin_superimpose.cpp @@ -0,0 +1,71 @@ +/* ============================================================ + * + * 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. + * + * ============================================================ */ + +// KDE includes. + +#include <tdelocale.h> +#include <kgenericfactory.h> +#include <klibloader.h> +#include <tdeaction.h> +#include <kcursor.h> + +// Local includes. + +#include "ddebug.h" +#include "superimposetool.h" +#include "imageplugin_superimpose.h" +#include "imageplugin_superimpose.moc" + +using namespace DigikamSuperImposeImagesPlugin; + +K_EXPORT_COMPONENT_FACTORY(digikamimageplugin_superimpose, + KGenericFactory<ImagePlugin_SuperImpose>("digikamimageplugin_superimpose")); + +ImagePlugin_SuperImpose::ImagePlugin_SuperImpose(TQObject *parent, const char*, const TQStringList &) + : Digikam::ImagePlugin(parent, "ImagePlugin_SuperImpose") +{ + m_superimposeAction = new TDEAction(i18n("Template Superimpose..."), "superimpose", 0, + this, TQ_SLOT(slotSuperImpose()), + actionCollection(), "imageplugin_superimpose"); + + setXMLFile("digikamimageplugin_superimpose_ui.rc"); + + DDebug() << "ImagePlugin_SuperImpose plugin loaded" << endl; +} + +ImagePlugin_SuperImpose::~ImagePlugin_SuperImpose() +{ +} + +void ImagePlugin_SuperImpose::setEnabledActions(bool enable) +{ + m_superimposeAction->setEnabled(enable); +} + +void ImagePlugin_SuperImpose::slotSuperImpose() +{ + SuperImposeTool *tool = new SuperImposeTool(this); + loadTool(tool); +} diff --git a/src/imageplugins/superimpose/imageplugin_superimpose.h b/src/imageplugins/superimpose/imageplugin_superimpose.h new file mode 100644 index 00000000..6f3c3a69 --- /dev/null +++ b/src/imageplugins/superimpose/imageplugin_superimpose.h @@ -0,0 +1,58 @@ +/* ============================================================ + * + * 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. + * + * ============================================================ */ + +#ifndef IMAGEPLUGIN_SUPERIMPOSE_H +#define IMAGEPLUGIN_SUPERIMPOSE_H + +// Digikam includes. + +#include "imageplugin.h" +#include "digikam_export.h" + +class TDEAction; + +class DIGIKAMIMAGEPLUGINS_EXPORT ImagePlugin_SuperImpose : public Digikam::ImagePlugin +{ + TQ_OBJECT + + +public: + + ImagePlugin_SuperImpose(TQObject *parent, const char* name, + const TQStringList &args); + ~ImagePlugin_SuperImpose(); + + void setEnabledActions(bool enable); + +private slots: + + void slotSuperImpose(); + +private: + + TDEAction *m_superimposeAction; +}; + +#endif /* IMAGEPLUGIN_SUPERIMPOSE_H */ diff --git a/src/imageplugins/superimpose/superimpose.cpp b/src/imageplugins/superimpose/superimpose.cpp new file mode 100644 index 00000000..7c0ac74b --- /dev/null +++ b/src/imageplugins/superimpose/superimpose.cpp @@ -0,0 +1,70 @@ +/* ============================================================ + * + * This file is a part of digiKam project + * http://www.digikam.org + * + * Date : 2006-18-03 + * Description : Superimpose filter. + * + * 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. + * + * ============================================================ */ + +// Local includes. + +#include "superimpose.h" + +namespace DigikamSuperImposeImagesPlugin +{ + +SuperImpose::SuperImpose(Digikam::DImg *orgImage, Digikam::DImg *templ, + TQRect orgImageSelection, + Digikam::DColorComposer::CompositingOperation compositeRule) +{ + m_orgImage = *orgImage; + m_template = *templ; + m_selection = orgImageSelection; + m_compositeRule = compositeRule; + + filterImage(); +} + +void SuperImpose::filterImage(void) +{ + if (m_template.isNull()) + return; + + int templateWidth = m_template.width(); + int templateHeight = m_template.height(); + + // take selection of src image and scale it to size of template + m_destImage = m_orgImage.smoothScaleSection(m_selection.x(), m_selection.y(), + m_selection.width(), m_selection.height(), templateWidth, templateHeight); + + // convert depth if necessary + m_template.convertToDepthOfImage(&m_destImage); + + // get composer for compositing rule + Digikam::DColorComposer *composer = Digikam::DColorComposer::getComposer(m_compositeRule); + Digikam::DColorComposer::MultiplicationFlags flags = Digikam::DColorComposer::NoMultiplication; + if (m_compositeRule != Digikam::DColorComposer::PorterDuffNone) + flags = Digikam::DColorComposer::MultiplicationFlagsDImg; + + // do alpha blending of template on dest image + m_destImage.bitBlendImage(composer, &m_template, 0, 0, templateWidth, templateHeight, 0, 0, flags); + + delete composer; +} + +} // namespace DigikamSuperImposeImagesPlugin diff --git a/src/imageplugins/superimpose/superimpose.h b/src/imageplugins/superimpose/superimpose.h new file mode 100644 index 00000000..a0b7b6da --- /dev/null +++ b/src/imageplugins/superimpose/superimpose.h @@ -0,0 +1,67 @@ +/* ============================================================ + * + * This file is a part of digiKam project + * http://www.digikam.org + * + * Date : 2006-18-03 + * Description : Superimpose filter. + * + * 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. + * + * ============================================================ */ + +#ifndef SUPERIMPOSE_H +#define SUPERIMPOSE_H + +// TQt includes. + +#include <tqrect.h> + +// Digikam includes. + +#include "dimg.h" +#include "dcolor.h" + +namespace DigikamSuperImposeImagesPlugin +{ + +class SuperImpose +{ + +public: + + SuperImpose(Digikam::DImg *orgImage, Digikam::DImg *templ, + TQRect orgImageSelection, + Digikam::DColorComposer::CompositingOperation + compositeRule = Digikam::DColorComposer::PorterDuffNone); + + Digikam::DImg getTargetImage() { return m_destImage; } + +private: + + void filterImage(void); + +private: + + TQRect m_selection; + + Digikam::DImg m_orgImage; + Digikam::DImg m_template; + Digikam::DImg m_destImage; + Digikam::DColorComposer::CompositingOperation m_compositeRule; +}; + +} // namespace DigikamSuperImposeImagesPlugin + +#endif /* SUPERIMPOSE_H */ diff --git a/src/imageplugins/superimpose/superimposetool.cpp b/src/imageplugins/superimpose/superimposetool.cpp new file mode 100644 index 00000000..f035559c --- /dev/null +++ b/src/imageplugins/superimpose/superimposetool.cpp @@ -0,0 +1,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. + * + * ============================================================ */ + +// TQt includes. + +#include <tqvgroupbox.h> +#include <tqgroupbox.h> +#include <tqlabel.h> +#include <tqpushbutton.h> +#include <tqpixmap.h> +#include <tqwhatsthis.h> +#include <tqtooltip.h> +#include <tqlayout.h> +#include <tqframe.h> +#include <tqdir.h> +#include <tqfile.h> +#include <tqhbuttongroup.h> + +// KDE includes. + +#include <kcursor.h> +#include <tdelocale.h> +#include <tdeaboutdata.h> +#include <khelpmenu.h> +#include <kiconloader.h> +#include <tdeapplication.h> +#include <tdepopupmenu.h> +#include <kstandarddirs.h> +#include <kprogress.h> +#include <knuminput.h> +#include <kiconloader.h> +#include <tdefiledialog.h> +#include <tdeapplication.h> +#include <tdeconfig.h> +#include <tdeglobalsettings.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(TQObject* parent) + : EditorTool(parent) +{ + setName("superimpose"); + setToolName(i18n("Template Superimpose")); + setToolIcon(SmallIcon("superimpose")); + + // ------------------------------------------------------------- + + TQFrame *frame = new TQFrame(0); + frame->setFrameStyle(TQFrame::Panel|TQFrame::Sunken); + + TQGridLayout* gridFrame = new TQGridLayout(frame, 1, 2); + m_previewWidget = new SuperImposeWidget(400, 300, frame); + TQWhatsThis::add( m_previewWidget, i18n("<p>This is the preview of the template " + "superimposed onto the image.") ); + + // ------------------------------------------------------------- + + TQHButtonGroup *bGroup = new TQHButtonGroup(frame); + TDEIconLoader icon; + bGroup->addSpace(0); + TQPushButton *zoomInButton = new TQPushButton( bGroup ); + bGroup->insert(zoomInButton, ZOOMIN); + zoomInButton->setPixmap( icon.loadIcon( "zoom-in", (TDEIcon::Group)TDEIcon::Toolbar ) ); + zoomInButton->setToggleButton(true); + TQToolTip::add( zoomInButton, i18n( "Zoom in" ) ); + bGroup->addSpace(20); + TQPushButton *zoomOutButton = new TQPushButton( bGroup ); + bGroup->insert(zoomOutButton, ZOOMOUT); + zoomOutButton->setPixmap( icon.loadIcon( "zoom-out", (TDEIcon::Group)TDEIcon::Toolbar ) ); + zoomOutButton->setToggleButton(true); + TQToolTip::add( zoomOutButton, i18n( "Zoom out" ) ); + bGroup->addSpace(20); + TQPushButton *moveButton = new TQPushButton( bGroup ); + bGroup->insert(moveButton, MOVE); + moveButton->setPixmap( icon.loadIcon( "move", (TDEIcon::Group)TDEIcon::Toolbar ) ); + moveButton->setToggleButton(true); + moveButton->setOn(true); + TQToolTip::add( moveButton, i18n( "Move" ) ); + bGroup->addSpace(20); + bGroup->setExclusive(true); + bGroup->setFrameShape(TQFrame::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); + TQGridLayout* grid = new TQGridLayout(m_gboxSettings->plainPage(), 1, 1); + + m_thumbnailsBar = new ThumbBarView(m_gboxSettings->plainPage()); + m_dirSelect = new DirSelectWidget(m_gboxSettings->plainPage()); + TQPushButton *templateDirButton = new TQPushButton( i18n("Root Directory..."), m_gboxSettings->plainPage() ); + TQWhatsThis::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, TQ_SIGNAL(released(int)), + m_previewWidget, TQ_SLOT(slotEditModeChanged(int))); + + connect(m_thumbnailsBar, TQ_SIGNAL(signalURLSelected(const KURL&)), + m_previewWidget, TQ_SLOT(slotSetCurrentTemplate(const KURL&))); + + connect(m_dirSelect, TQ_SIGNAL(folderItemSelected(const KURL &)), + this, TQ_SLOT(slotTemplateDirChanged(const KURL &))); + + connect(templateDirButton, TQ_SIGNAL(clicked()), + this, TQ_SLOT(slotRootTemplateDirChanged())); + + // ------------------------------------------------------------- + + populateTemplates(); +} + +SuperImposeTool::~SuperImposeTool() +{ +} + +void SuperImposeTool::populateTemplates() +{ + m_thumbnailsBar->clear(true); + + if (!m_templatesUrl.isValid() || !m_templatesUrl.isLocalFile()) + return; + + TQDir dir(m_templatesUrl.path(), "*.png *.PNG"); + + if (!dir.exists()) + return; + + dir.setFilter ( TQDir::Files | TQDir::NoSymLinks ); + + const TQFileInfoList* fileinfolist = dir.entryInfoList(); + if (!fileinfolist) + return; + + TQFileInfoListIterator it(*fileinfolist); + TQFileInfo* fi; + + while( (fi = it.current() ) ) + { + new ThumbBarItem( m_thumbnailsBar, KURL(fi->filePath()) ); + ++it; + } +} + +void SuperImposeTool::readSettings() +{ + TDEConfig* config = kapp->config(); + config->setGroup("Album Settings"); + KURL albumDBUrl( config->readPathEntry("Album Path", TDEGlobalSettings::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() +{ + TDEConfig* 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 diff --git a/src/imageplugins/superimpose/superimposetool.h b/src/imageplugins/superimpose/superimposetool.h new file mode 100644 index 00000000..7501f23f --- /dev/null +++ b/src/imageplugins/superimpose/superimposetool.h @@ -0,0 +1,90 @@ +/* ============================================================ + * + * 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. + * + * ============================================================ */ + +#ifndef IMAGEEFFECT_SUPERIMPOSE_H +#define IMAGEEFFECT_SUPERIMPOSE_H + +// KDE includes. + +#include <kurl.h> + +// Digikam includes. + +#include "editortool.h" + +class TQPushButton; + +namespace Digikam +{ +class ThumbBarView; +class EditorToolSettings; +} + +namespace DigikamSuperImposeImagesPlugin +{ + +class DirSelectWidget; +class SuperImposeWidget; + +class SuperImposeTool : public Digikam::EditorTool +{ + TQ_OBJECT + + +public: + + SuperImposeTool(TQObject* parent); + ~SuperImposeTool(); + +private slots: + + void slotTemplateDirChanged(const KURL& url); + void slotRootTemplateDirChanged(); + void slotResetSettings(); + +private: + + void readSettings(); + void writeSettings(); + void populateTemplates(); + void finalRendering(); + +private: + + KURL m_templatesUrl; + KURL m_templatesRootUrl; + + Digikam::ThumbBarView *m_thumbnailsBar; + + Digikam::EditorToolSettings *m_gboxSettings; + + SuperImposeWidget *m_previewWidget; + + DirSelectWidget *m_dirSelect; +}; + +} // NameSpace DigikamSuperImposeImagesPlugin + +#endif /* IMAGEEFFECT_SUPERIMPOSE_H */ diff --git a/src/imageplugins/superimpose/superimposewidget.cpp b/src/imageplugins/superimpose/superimposewidget.cpp new file mode 100644 index 00000000..edae15aa --- /dev/null +++ b/src/imageplugins/superimpose/superimposewidget.cpp @@ -0,0 +1,329 @@ +/* ============================================================ + * + * 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. + * + * ============================================================ */ + +// C++ includes. + +#include <cstdio> + +// TQt includes. + +#include <tqpainter.h> + +// KDE includes. + +#include <kstandarddirs.h> +#include <kcursor.h> +#include <tdeglobal.h> + +// Local includes. + +#include "superimpose.h" +#include "superimposewidget.h" +#include "superimposewidget.moc" + +namespace DigikamSuperImposeImagesPlugin +{ + +SuperImposeWidget::SuperImposeWidget(int w, int h, TQWidget *parent) + : TQWidget(parent, 0, TQt::WDestructiveClose) +{ + m_pixmap = new TQPixmap(w, h); + m_editMode = MOVE; + + Digikam::ImageIface iface(0, 0); + m_w = iface.originalWidth(); + m_h = iface.originalHeight(); + + setBackgroundMode(TQt::NoBackground); + setMinimumSize(w, h); + setMouseTracking(true); + + resetEdit(); +} + +SuperImposeWidget::~SuperImposeWidget() +{ + if(m_pixmap) + delete m_pixmap; +} + +Digikam::DImg SuperImposeWidget::makeSuperImpose(void) +{ + Digikam::ImageIface iface(0, 0); + SuperImpose superimpose(iface.getOriginalImg(), &m_template, m_currentSelection); + return superimpose.getTargetImage(); +} + +void SuperImposeWidget::resetEdit(void) +{ + m_zoomFactor = 1.0; + m_currentSelection = TQRect(m_w/2 - m_rect.width()/2, m_h/2 - m_rect.height()/2, + m_rect.width(), m_rect.height()); + makePixmap(); + repaint(false); +} + +void SuperImposeWidget::makePixmap(void) +{ + Digikam::ImageIface iface(0, 0); + SuperImpose superimpose(iface.getOriginalImg(), &m_templateScaled, m_currentSelection); + Digikam::DImg image = superimpose.getTargetImage(); + + m_pixmap->fill(colorGroup().background()); + TQPainter p(m_pixmap); + TQPixmap imagePix = image.convertToPixmap(); + p.drawPixmap(m_rect.x(), m_rect.y(), imagePix, 0, 0, m_rect.width(), m_rect.height()); + p.end(); +} + +void SuperImposeWidget::resizeEvent(TQResizeEvent * e) +{ + blockSignals(true); + delete m_pixmap; + int w = e->size().width(); + int h = e->size().height(); + m_pixmap = new TQPixmap(w, h); + + if (!m_template.isNull()) + { + int templateWidth = m_template.width(); + int templateHeight = m_template.height(); + + if (templateWidth < templateHeight) + { + int neww = (int) ((float)height() / (float)templateHeight * (float)templateWidth); + m_rect = TQRect(width()/2-neww/2, 0, neww, height()); + } + else + { + int newh = (int) ((float)width() / (float)templateWidth * (float)templateHeight); + m_rect = TQRect(0, height()/2-newh/2, width(), newh); + } + + m_templateScaled = m_template.smoothScale(m_rect.width(), m_rect.height()); + makePixmap(); + } + else + { + m_rect = TQRect(); + m_pixmap->fill(colorGroup().background()); + } + + blockSignals(false); +} + +void SuperImposeWidget::paintEvent( TQPaintEvent * ) +{ + bitBlt(this, 0, 0, m_pixmap); +} + +void SuperImposeWidget::slotEditModeChanged(int mode) +{ + m_editMode = mode; +} + +void SuperImposeWidget::slotSetCurrentTemplate(const KURL& url) +{ + m_template.load(url.path()); + + if (m_template.isNull()) + { + m_rect = TQRect(); + return; + } + + int templateWidth = m_template.width(); + int templateHeight = m_template.height(); + + if (templateWidth < templateHeight) + { + int neww = (int) ((float)height() / (float)templateHeight * (float)templateWidth); + m_rect = TQRect(width()/2-neww/2, 0, neww, height()); + } + else + { + int newh = (int) ((float)width() / (float)templateWidth * (float)templateHeight); + m_rect = TQRect(0, height()/2-newh/2, width(), newh); + } + + m_templateScaled = m_template.smoothScale(m_rect.width(), m_rect.height()); + + m_currentSelection = TQRect(m_w/2 - m_rect.width()/2, m_h/2 - m_rect.height()/2, m_rect.width(), m_rect.height()); + zoomSelection(0); +} + +void SuperImposeWidget::moveSelection(int dx, int dy) +{ + TQRect selection = m_currentSelection; + float wf = (float)selection.width() / (float)m_rect.width(); + float hf = (float)selection.height() / (float)m_rect.height(); + + selection.moveBy( -(int)(wf*(float)dx), -(int)(hf*(float)dy) ); + + if (selection.left() < 0) + selection.moveLeft(0); + if (selection.top() < 0) + selection.moveTop(0); + if (selection.bottom() > m_h) + selection.moveBottom(m_h); + if (selection.right() > m_w) + selection.moveRight(m_w); + + m_currentSelection = selection; +} + +bool SuperImposeWidget::zoomSelection(float deltaZoomFactor) +{ + float newZoom = m_zoomFactor + deltaZoomFactor; + + if (newZoom < 0.0) + return false; + + TQRect selection = m_currentSelection; + int wf = (int)((float)m_rect.width() / newZoom); + int hf = (int)((float)m_rect.height() / newZoom); + int deltaX = (m_currentSelection.width() - wf) / 2; + int deltaY = (m_currentSelection.height() - hf) / 2; + + selection.setLeft(m_currentSelection.left() + deltaX); + selection.setTop(m_currentSelection.top() + deltaY); + selection.setWidth(wf); + selection.setHeight(hf); + + // check that selection is still inside original image + TQRect orgImageRect(0, 0, m_w, m_h); + if (!orgImageRect.contains(selection)) + { + // try to adjust + if (selection.left() < 0) + selection.moveLeft(0); + if (selection.top() < 0) + selection.moveTop(0); + if (selection.bottom() > m_h) + selection.moveBottom(m_h); + if (selection.right() > m_w) + selection.moveRight(m_w); + + // was it successful? + if (selection.contains(orgImageRect)) + return false; + + } + + m_zoomFactor = newZoom; + m_currentSelection = selection; + + makePixmap(); + repaint(false); + + return true; +} + +void SuperImposeWidget::mousePressEvent ( TQMouseEvent * e ) +{ + if ( isEnabled() && e->button() == TQt::LeftButton && + rect().contains( e->x(), e->y() ) ) + { + switch (m_editMode) + { + case ZOOMIN: + if (zoomSelection(+0.05)) + moveSelection(width()/2 - e->x(), height()/2 - e->y()); + break; + + case ZOOMOUT: + if (zoomSelection(-0.05)) + moveSelection(width()/2 - e->x(), height()/2 - e->y()); + break; + + case MOVE: + m_xpos = e->x(); + m_ypos = e->y(); + } + } +} + +void SuperImposeWidget::mouseReleaseEvent ( TQMouseEvent * ) +{ + setEditModeCursor(); +} + +void SuperImposeWidget::mouseMoveEvent ( TQMouseEvent * e ) +{ + if ( isEnabled() ) + { + if ( e->state() == TQt::LeftButton ) + { + switch (m_editMode) + { + case ZOOMIN: + case ZOOMOUT: + break; + + case MOVE: + int newxpos = e->x(); + int newypos = e->y(); + + if (newxpos < m_rect.left()) + newxpos = m_rect.left(); + if (newxpos > m_rect.right()) + newxpos = m_rect.right(); + if (newxpos < m_rect.top()) + newxpos = m_rect.top(); + if (newxpos > m_rect.bottom()) + newxpos = m_rect.bottom(); + + moveSelection(newxpos - m_xpos, newypos - m_ypos); + makePixmap(); + repaint(false); + + m_xpos = newxpos; + m_ypos = newypos; + setCursor( KCursor::handCursor() ); + break; + } + } + else if (rect().contains( e->x(), e->y() )) + { + setEditModeCursor(); + } + } +} + +void SuperImposeWidget::setEditModeCursor() +{ + switch (m_editMode) + { + case ZOOMIN: + case ZOOMOUT: + setCursor ( KCursor::crossCursor() ); + break; + + case MOVE: + setCursor ( KCursor::sizeAllCursor() ); + } +} + +} // NameSpace DigikamSuperImposeImagesPlugin diff --git a/src/imageplugins/superimpose/superimposewidget.h b/src/imageplugins/superimpose/superimposewidget.h new file mode 100644 index 00000000..8b3fb048 --- /dev/null +++ b/src/imageplugins/superimpose/superimposewidget.h @@ -0,0 +1,118 @@ +/* ============================================================ + * + * 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. + * + * ============================================================ */ + +#ifndef SUPERIMPOSEWIDGET_H +#define SUPERIMPOSEWIDGET_H + +// TQt includes. + +#include <tqwidget.h> +#include <tqimage.h> +#include <tqrect.h> +#include <tqsize.h> +#include <tqpixmap.h> + +// KDE includes. + +#include <kurl.h> + +// Digikam includes. + +#include "imageiface.h" +#include "dimg.h" + +class TQPixmap; + +namespace Digikam +{ +class ImageIface; +} + +namespace DigikamSuperImposeImagesPlugin +{ + +enum Action +{ + ZOOMIN=0, + ZOOMOUT, + MOVE +}; + +class SuperImposeWidget : public TQWidget +{ +TQ_OBJECT + + +public: + + SuperImposeWidget(int w, int h, TQWidget *parent=0); + ~SuperImposeWidget(); + + void setEditMode(int mode); + void resetEdit(void); + TQRect getCurrentSelection(void); + TQSize getTemplateSize(void); + Digikam::DImg makeSuperImpose(void); + +public slots: + + void slotEditModeChanged(int mode); + void slotSetCurrentTemplate(const KURL& url); + +protected: + + void paintEvent( TQPaintEvent *e ); + void resizeEvent( TQResizeEvent * e ); + void mousePressEvent ( TQMouseEvent * e ); + void mouseReleaseEvent ( TQMouseEvent * e ); + void mouseMoveEvent ( TQMouseEvent * e ); + + bool zoomSelection(float deltaZoomFactor); + void moveSelection(int x, int y); + void makePixmap(void); + void setEditModeCursor(); + +private: + + int m_w; + int m_h; + + int m_xpos; + int m_ypos; + int m_editMode; + float m_zoomFactor; + + TQPixmap *m_pixmap; // For image region selection manipulations. + + TQRect m_rect; // For mouse drag position. + TQRect m_currentSelection; // Region selection in image displayed in the widget. + + Digikam::DImg m_template; // Full template data. + Digikam::DImg m_templateScaled; // Template scaled to preview widget +}; + +} // NameSpace DigikamSuperImposeImagesPlugin + +#endif /* SUPERIMPOSEWIDGET_H */ |