diff options
Diffstat (limited to 'src/imageplugins/border')
28 files changed, 2348 insertions, 0 deletions
diff --git a/src/imageplugins/border/Makefile.am b/src/imageplugins/border/Makefile.am new file mode 100644 index 00000000..385acfab --- /dev/null +++ b/src/imageplugins/border/Makefile.am @@ -0,0 +1,34 @@ +METASOURCES = AUTO +SUBDIRS = patterns + +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/digikam \ + $(LIBKDCRAW_CFLAGS) \ + $(all_includes) + +digikamimageplugin_border_la_SOURCES = imageplugin_border.cpp \ + bordertool.cpp border.cpp + +digikamimageplugin_border_la_LIBADD = $(LIB_TDEPARTS) \ + $(top_builddir)/src/digikam/libdigikam.la + +digikamimageplugin_border_la_LDFLAGS = -module $(KDE_PLUGIN) $(all_libraries) -ltdecore -ltdeui $(LIB_TQT) -ltdefx -lkdcraw -ltdeio + +kde_services_DATA = digikamimageplugin_border.desktop + +kde_module_LTLIBRARIES = digikamimageplugin_border.la + +rcdir = $(kde_datadir)/digikam +rc_DATA = digikamimageplugin_border_ui.rc diff --git a/src/imageplugins/border/border.cpp b/src/imageplugins/border/border.cpp new file mode 100644 index 00000000..00726f58 --- /dev/null +++ b/src/imageplugins/border/border.cpp @@ -0,0 +1,393 @@ +/* ============================================================ + * + * This file is a part of digiKam project + * http://www.digikam.org + * + * Date : 2005-05-25 + * Description : border threaded image filter. + * + * Copyright 2005-2007 by Gilles Caulier <caulier dot gilles at gmail dot com> + * Copyright 2006-2007 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 <cmath> +#include <cstdlib> + +// TQt includes. + +#include <tqpoint.h> +#include <tqregion.h> +#include <tqpointarray.h> + +// Local includes. + +#include "dimg.h" +#include "ddebug.h" +#include "border.h" + +namespace DigikamBorderImagesPlugin +{ + +Border::Border(Digikam::DImg *image, TQObject *parent, int orgWidth, int orgHeight, + TQString borderPath, int borderType, float borderPercent, + Digikam::DColor solidColor, + Digikam::DColor niepceBorderColor, + Digikam::DColor niepceLineColor, + Digikam::DColor bevelUpperLeftColor, + Digikam::DColor bevelLowerRightColor, + Digikam::DColor decorativeFirstColor, + Digikam::DColor decorativeSecondColor) + : Digikam::DImgThreadedFilter(image, parent, "Border") +{ + m_orgWidth = orgWidth; + m_orgHeight = orgHeight; + m_orgRatio = (float)m_orgWidth / (float)m_orgHeight; + m_borderType = borderType; + m_borderPath = borderPath; + int size = (image->width() > image->height()) ? image->height() : image->width(); + m_borderMainWidth = (int)(size * borderPercent); + m_border2ndWidth = (int)(size * 0.005); + + // Clamp internal border with to 1 pixel to be visible with small image. + if (m_border2ndWidth < 1) m_border2ndWidth = 1; + + m_solidColor = solidColor; + m_niepceBorderColor = niepceBorderColor; + m_niepceLineColor = niepceLineColor; + m_bevelUpperLeftColor = bevelUpperLeftColor; + m_bevelLowerRightColor = bevelLowerRightColor; + m_decorativeFirstColor = decorativeFirstColor; + m_decorativeSecondColor = decorativeSecondColor; + + m_preserveAspectRatio = true; + + initFilter(); +} + +Border::Border(Digikam::DImg *orgImage, TQObject *parent, int orgWidth, int orgHeight, + TQString borderPath, int borderType, + int borderWidth1, int borderWidth2, int borderWidth3, int borderWidth4, + Digikam::DColor solidColor, + Digikam::DColor niepceBorderColor, + Digikam::DColor niepceLineColor, + Digikam::DColor bevelUpperLeftColor, + Digikam::DColor bevelLowerRightColor, + Digikam::DColor decorativeFirstColor, + Digikam::DColor decorativeSecondColor) + : Digikam::DImgThreadedFilter(orgImage, parent, "Border") +{ + m_orgWidth = orgWidth; + m_orgHeight = orgHeight; + + m_borderType = borderType; + m_borderWidth1 = borderWidth1; + m_borderWidth2 = borderWidth2; + m_borderWidth3 = borderWidth3; + m_borderWidth4 = borderWidth4; + + m_solidColor = solidColor; + m_niepceBorderColor = niepceBorderColor; + m_niepceLineColor = niepceLineColor; + m_bevelUpperLeftColor = bevelUpperLeftColor; + m_bevelLowerRightColor = bevelLowerRightColor; + m_decorativeFirstColor = decorativeFirstColor; + m_decorativeSecondColor = decorativeSecondColor; + + m_borderPath = borderPath; + + m_preserveAspectRatio = false; + + initFilter(); +} + +void Border::filterImage(void) +{ + switch (m_borderType) + { + case SolidBorder: + if (m_preserveAspectRatio) + solid(m_orgImage, m_destImage, m_solidColor, m_borderMainWidth); + else + solid2(m_orgImage, m_destImage, m_solidColor, m_borderWidth1); + break; + + case NiepceBorder: + if (m_preserveAspectRatio) + niepce(m_orgImage, m_destImage, m_niepceBorderColor, m_borderMainWidth, + m_niepceLineColor, m_border2ndWidth); + else + niepce2(m_orgImage, m_destImage, m_niepceBorderColor, m_borderWidth1, + m_niepceLineColor, m_borderWidth4); + break; + + case BeveledBorder: + if (m_preserveAspectRatio) + bevel(m_orgImage, m_destImage, m_bevelUpperLeftColor, + m_bevelLowerRightColor, m_borderMainWidth); + else + bevel2(m_orgImage, m_destImage, m_bevelUpperLeftColor, + m_bevelLowerRightColor, m_borderWidth1); + break; + + case PineBorder: + case WoodBorder: + case PaperBorder: + case ParqueBorder: + case IceBorder: + case LeafBorder: + case MarbleBorder: + case RainBorder: + case CratersBorder: + case DriedBorder: + case PinkBorder: + case StoneBorder: + case ChalkBorder: + case GraniteBorder: + case RockBorder: + case WallBorder: + if (m_preserveAspectRatio) + pattern(m_orgImage, m_destImage, m_borderMainWidth, + m_decorativeFirstColor, m_decorativeSecondColor, + m_border2ndWidth, m_border2ndWidth); + else + pattern2(m_orgImage, m_destImage, m_borderWidth1, + m_decorativeFirstColor, m_decorativeSecondColor, + m_borderWidth2, m_borderWidth2); + break; + } +} + +// -- Methods to preserve aspect ratio of image ------------------------------------------ + +void Border::solid(Digikam::DImg &src, Digikam::DImg &dest, const Digikam::DColor &fg, int borderWidth) +{ + if (m_orgWidth > m_orgHeight) + { + int height = src.height() + borderWidth*2; + dest = Digikam::DImg((int)(height*m_orgRatio), height, src.sixteenBit(), src.hasAlpha()); + dest.fill(fg); + dest.bitBltImage(&src, (dest.width()-src.width())/2, borderWidth); + } + else + { + int width = src.width() + borderWidth*2; + dest = Digikam::DImg(width, (int)(width/m_orgRatio), src.sixteenBit(), src.hasAlpha()); + dest.fill(fg); + dest.bitBltImage(&src, borderWidth, (dest.height()-src.height())/2); + } +} + +void Border::niepce(Digikam::DImg &src, Digikam::DImg &dest, const Digikam::DColor &fg, + int borderWidth, const Digikam::DColor &bg, int lineWidth) +{ + Digikam::DImg tmp; + solid(src, tmp, bg, lineWidth); + solid(tmp, dest, fg, borderWidth); +} + +void Border::bevel(Digikam::DImg &src, Digikam::DImg &dest, const Digikam::DColor &topColor, + const Digikam::DColor &btmColor, int borderWidth) +{ + int width, height; + + if (m_orgWidth > m_orgHeight) + { + height = src.height() + borderWidth*2; + width = (int)(height*m_orgRatio); + } + else + { + width = src.width() + borderWidth*2; + height = (int)(width/m_orgRatio); + } + + dest = Digikam::DImg(width, height, src.sixteenBit(), src.hasAlpha()); + dest.fill(topColor); + + TQPointArray btTriangle(3); + btTriangle.setPoint(0, width, 0); + btTriangle.setPoint(1, 0, height); + btTriangle.setPoint(2, width, height); + TQRegion btRegion(btTriangle); + + for(int x=0 ; x < width ; x++) + { + for(int y=0 ; y < height ; y++) + { + if (btRegion.contains(TQPoint(x, y))) + dest.setPixelColor(x, y, btmColor); + } + } + + if (m_orgWidth > m_orgHeight) + { + dest.bitBltImage(&src, (dest.width()-src.width())/2, borderWidth); + } + else + { + dest.bitBltImage(&src, borderWidth, (dest.height()-src.height())/2); + } +} + +void Border::pattern(Digikam::DImg &src, Digikam::DImg &dest, int borderWidth, + const Digikam::DColor &firstColor, const Digikam::DColor &secondColor, + int firstWidth, int secondWidth) +{ + // Original image with the first solid border around. + Digikam::DImg tmp; + solid(src, tmp, firstColor, firstWidth); + + // Border tiled image using pattern with second solid border around. + int width, height; + + if (m_orgWidth > m_orgHeight) + { + height = tmp.height() + borderWidth*2; + width = (int)(height*m_orgRatio); + } + else + { + width = tmp.width() + borderWidth*2; + height = (int)(width/m_orgRatio); + } + + Digikam::DImg tmp2(width, height, tmp.sixteenBit(), tmp.hasAlpha()); + DDebug() << "Border File:" << m_borderPath << endl; + Digikam::DImg border(m_borderPath); + if ( border.isNull() ) + return; + + border.convertToDepthOfImage(&tmp2); + + for (int x = 0 ; x < width ; x+=border.width()) + for (int y = 0 ; y < height ; y+=border.height()) + tmp2.bitBltImage(&border, x, y); + + solid(tmp2, dest, secondColor, secondWidth); + + // Merge both images to one. + if (m_orgWidth > m_orgHeight) + { + dest.bitBltImage(&tmp, (dest.width()-tmp.width())/2, borderWidth); + } + else + { + dest.bitBltImage(&tmp, borderWidth, (dest.height()-tmp.height())/2); + } +} + +// -- Methods to not-preserve aspect ratio of image ------------------------------------------ + + +void Border::solid2(Digikam::DImg &src, Digikam::DImg &dest, const Digikam::DColor &fg, int borderWidth) +{ + dest = Digikam::DImg(src.width() + borderWidth*2, src.height() + borderWidth*2, + src.sixteenBit(), src.hasAlpha()); + dest.fill(fg); + dest.bitBltImage(&src, borderWidth, borderWidth); +} + +void Border::niepce2(Digikam::DImg &src, Digikam::DImg &dest, const Digikam::DColor &fg, int borderWidth, + const Digikam::DColor &bg, int lineWidth) +{ + Digikam::DImg tmp; + solid2(src, tmp, bg, lineWidth); + solid2(tmp, dest, fg, borderWidth); +} + +void Border::bevel2(Digikam::DImg &src, Digikam::DImg &dest, const Digikam::DColor &topColor, + const Digikam::DColor &btmColor, int borderWidth) +{ + int x, y; + int wc; + + dest = Digikam::DImg(src.width() + borderWidth*2, + src.height() + borderWidth*2, + src.sixteenBit(), src.hasAlpha()); + + // top + + for(y=0, wc = (int)dest.width()-1; y < borderWidth; ++y, --wc) + { + for(x=0; x < wc; ++x) + dest.setPixelColor(x, y, topColor); + + for(;x < (int)dest.width(); ++x) + dest.setPixelColor(x, y, btmColor); + } + + // left and right + + for(; y < (int)dest.height()-borderWidth; ++y) + { + for(x=0; x < borderWidth; ++x) + dest.setPixelColor(x, y, topColor); + + for(x = (int)dest.width()-1; x > (int)dest.width()-borderWidth-1; --x) + dest.setPixelColor(x, y, btmColor); + } + + // bottom + + for(wc = borderWidth; y < (int)dest.height(); ++y, --wc) + { + for(x=0; x < wc; ++x) + dest.setPixelColor(x, y, topColor); + + for(; x < (int)dest.width(); ++x) + dest.setPixelColor(x, y, btmColor); + } + + dest.bitBltImage(&src, borderWidth, borderWidth); +} + +void Border::pattern2(Digikam::DImg &src, Digikam::DImg &dest, int borderWidth, + const Digikam::DColor &firstColor, const Digikam::DColor &secondColor, + int firstWidth, int secondWidth) +{ + // Border tile. + + int w = m_orgWidth + borderWidth*2; + int h = m_orgHeight + borderWidth*2; + + DDebug() << "Border File:" << m_borderPath << endl; + Digikam::DImg border(m_borderPath); + if ( border.isNull() ) + return; + + Digikam::DImg borderImg(w, h, src.sixteenBit(), src.hasAlpha()); + border.convertToDepthOfImage(&borderImg); + + for (int x = 0 ; x < w ; x+=border.width()) + for (int y = 0 ; y < h ; y+=border.height()) + borderImg.bitBltImage(&border, x, y); + + // First line around the pattern tile. + Digikam::DImg tmp = borderImg.smoothScale(src.width() + borderWidth*2, + src.height() + borderWidth*2 ); + + solid2(tmp, dest, firstColor, firstWidth); + + // Second line around original image. + tmp.reset(); + solid2(src, tmp, secondColor, secondWidth); + + // Copy original image. + dest.bitBltImage(&tmp, borderWidth, borderWidth); +} + +} // NameSpace DigikamBorderImagesPlugin diff --git a/src/imageplugins/border/border.h b/src/imageplugins/border/border.h new file mode 100644 index 00000000..b213e27a --- /dev/null +++ b/src/imageplugins/border/border.h @@ -0,0 +1,151 @@ +/* ============================================================ + * + * This file is a part of digiKam project + * http://www.digikam.org + * + * Date : 2005-05-25 + * Description : border threaded image filter. + * + * Copyright 2005-2007 by Gilles Caulier <caulier dot gilles at gmail dot com> + * Copyright 2006-2007 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 BORDER_H +#define BORDER_H + +// TQt includes. + +#include <tqstring.h> +#include <tqcolor.h> +#include <tqimage.h> + +// Digikam includes. + +#include "dimgthreadedfilter.h" + +namespace DigikamBorderImagesPlugin +{ + +class Border : public Digikam::DImgThreadedFilter +{ + +public: + + enum BorderTypes + { + SolidBorder=0, + NiepceBorder, + BeveledBorder, + PineBorder, + WoodBorder, + PaperBorder, + ParqueBorder, + IceBorder, + LeafBorder, + MarbleBorder, + RainBorder, + CratersBorder, + DriedBorder, + PinkBorder, + StoneBorder, + ChalkBorder, + GraniteBorder, + RockBorder, + WallBorder + }; + +public: + + /** Constructor using settings to preserve aspect ratio of image. */ + Border(Digikam::DImg *orgImage, TQObject *parent=0, int orgWidth=0, int orgHeight=0, + TQString borderPath=TQString(), int borderType=SolidBorder, float borderPercent=0.1, + Digikam::DColor solidColor = Digikam::DColor(), + Digikam::DColor niepceBorderColor = Digikam::DColor(), + Digikam::DColor niepceLineColor = Digikam::DColor(), + Digikam::DColor bevelUpperLeftColor = Digikam::DColor(), + Digikam::DColor bevelLowerRightColor = Digikam::DColor(), + Digikam::DColor decorativeFirstColor = Digikam::DColor(), + Digikam::DColor decorativeSecondColor = Digikam::DColor()); + + /** Constructor using settings to not-preserve aspect ratio of image. */ + Border(Digikam::DImg *orgImage, TQObject *parent=0, int orgWidth=0, int orgHeight=0, + TQString borderPath=TQString(), int borderType=SolidBorder, + int borderWidth1=100, int borderWidth2=20, int borderWidth3=20, int borderWidth4=10, + Digikam::DColor solidColor = Digikam::DColor(), + Digikam::DColor niepceBorderColor = Digikam::DColor(), + Digikam::DColor niepceLineColor = Digikam::DColor(), + Digikam::DColor bevelUpperLeftColor = Digikam::DColor(), + Digikam::DColor bevelLowerRightColor = Digikam::DColor(), + Digikam::DColor decorativeFirstColor = Digikam::DColor(), + Digikam::DColor decorativeSecondColor = Digikam::DColor()); + + ~Border(){}; + +private: + + virtual void filterImage(void); + + + /** Methods to preserve aspect ratio of image. */ + void solid(Digikam::DImg &src, Digikam::DImg &dest, const Digikam::DColor &fg, int borderWidth); + void niepce(Digikam::DImg &src, Digikam::DImg &dest, const Digikam::DColor &fg, int borderWidth, + const Digikam::DColor &bg, int lineWidth); + void bevel(Digikam::DImg &src, Digikam::DImg &dest, const Digikam::DColor &topColor, + const Digikam::DColor &btmColor, int borderWidth); + void pattern(Digikam::DImg &src, Digikam::DImg &dest, int borderWidth, const Digikam::DColor &firstColor, + const Digikam::DColor &secondColor, int firstWidth, int secondWidth); + + /** Methods to not-preserve aspect ratio of image. */ + void solid2(Digikam::DImg &src, Digikam::DImg &dest, const Digikam::DColor &fg, int borderWidth); + void niepce2(Digikam::DImg &src, Digikam::DImg &dest, const Digikam::DColor &fg, int borderWidth, + const Digikam::DColor &bg, int lineWidth); + void bevel2(Digikam::DImg &src, Digikam::DImg &dest, const Digikam::DColor &topColor, + const Digikam::DColor &btmColor, int borderWidth); + void pattern2(Digikam::DImg &src, Digikam::DImg &dest, int borderWidth, const Digikam::DColor &firstColor, + const Digikam::DColor &secondColor, int firstWidth, int secondWidth); + +private: + + bool m_preserveAspectRatio; + + int m_orgWidth; + int m_orgHeight; + + int m_borderType; + + int m_borderWidth1; + int m_borderWidth2; + int m_borderWidth3; + int m_borderWidth4; + + int m_borderMainWidth; + int m_border2ndWidth; + + float m_orgRatio; + + TQString m_borderPath; + + Digikam::DColor m_solidColor; + Digikam::DColor m_niepceBorderColor; + Digikam::DColor m_niepceLineColor; + Digikam::DColor m_bevelUpperLeftColor; + Digikam::DColor m_bevelLowerRightColor; + Digikam::DColor m_decorativeFirstColor; + Digikam::DColor m_decorativeSecondColor; +}; + +} // NameSpace DigikamBorderImagesPlugin + +#endif /* BORDER_H */ diff --git a/src/imageplugins/border/bordertool.cpp b/src/imageplugins/border/bordertool.cpp new file mode 100644 index 00000000..160f5b0a --- /dev/null +++ b/src/imageplugins/border/bordertool.cpp @@ -0,0 +1,668 @@ +/* ============================================================ + * + * This file is a part of digiKam project + * http://www.digikam.org + * + * Date : 2005-01-20 + * Description : a digiKam image plugin to add a border + * around an image. + * + * Copyright 2005-2008 by Gilles Caulier <caulier dot gilles at gmail dot com> + * Copyright 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 <tqcheckbox.h> +#include <tqlabel.h> +#include <tqlayout.h> +#include <tqwhatsthis.h> + +// KDE includes. + +#include <tdeaboutdata.h> +#include <tdeapplication.h> +#include <kcolorbutton.h> +#include <tdeconfig.h> +#include <kiconloader.h> +#include <tdelocale.h> +#include <kseparator.h> +#include <kstandarddirs.h> + +// LibKDcraw includes. + +#include <libkdcraw/rnuminput.h> +#include <libkdcraw/rcombobox.h> + +// Local includes. + +#include "daboutdata.h" +#include "ddebug.h" +#include "imageiface.h" +#include "imagewidget.h" +#include "editortoolsettings.h" +#include "border.h" +#include "bordertool.h" +#include "bordertool.moc" + +using namespace KDcrawIface; +using namespace Digikam; + +namespace DigikamBorderImagesPlugin +{ + +BorderTool::BorderTool(TQObject* parent) + : EditorToolThreaded(parent) +{ + setName("border"); + setToolName(i18n("Add Border")); + setToolIcon(SmallIcon("bordertool")); + + m_previewWidget = new ImageWidget("bordertool Tool", 0, TQString(), + false, ImageGuideWidget::HVGuideMode, false); + + setToolView(m_previewWidget); + + // ------------------------------------------------------------- + + m_gboxSettings = new EditorToolSettings(EditorToolSettings::Default| + EditorToolSettings::Ok| + EditorToolSettings::Cancel); + TQGridLayout* grid = new TQGridLayout(m_gboxSettings->plainPage(), 11, 2); + + TQLabel *label1 = new TQLabel(i18n("Type:"), m_gboxSettings->plainPage()); + + m_borderType = new RComboBox(m_gboxSettings->plainPage()); + m_borderType->insertItem( i18n("Solid") ); + // Niepce is Real name. This is the first guy in the world to have built a camera. + m_borderType->insertItem( "Niepce" ); + m_borderType->insertItem( i18n("Beveled") ); + m_borderType->insertItem( i18n("Decorative Pine") ); + m_borderType->insertItem( i18n("Decorative Wood") ); + m_borderType->insertItem( i18n("Decorative Paper") ); + m_borderType->insertItem( i18n("Decorative Parquet") ); + m_borderType->insertItem( i18n("Decorative Ice") ); + m_borderType->insertItem( i18n("Decorative Leaf") ); + m_borderType->insertItem( i18n("Decorative Marble") ); + m_borderType->insertItem( i18n("Decorative Rain") ); + m_borderType->insertItem( i18n("Decorative Craters") ); + m_borderType->insertItem( i18n("Decorative Dried") ); + m_borderType->insertItem( i18n("Decorative Pink") ); + m_borderType->insertItem( i18n("Decorative Stone") ); + m_borderType->insertItem( i18n("Decorative Chalk") ); + m_borderType->insertItem( i18n("Decorative Granite") ); + m_borderType->insertItem( i18n("Decorative Rock") ); + m_borderType->insertItem( i18n("Decorative Wall") ); + m_borderType->setDefaultItem(Border::SolidBorder); + TQWhatsThis::add( m_borderType, i18n("<p>Select the border type to add around the image.")); + + KSeparator *line1 = new KSeparator(Horizontal, m_gboxSettings->plainPage()); + + // ------------------------------------------------------------------- + + m_preserveAspectRatio = new TQCheckBox(m_gboxSettings->plainPage()); + m_preserveAspectRatio->setText(i18n("Preserve Aspect Ratio")); + TQWhatsThis::add(m_preserveAspectRatio, i18n("Enable this option if you want to preserve the aspect " + "ratio of the image. If enabled, the border width will be " + "in percent of the image size, else the border width will " + "in pixels.")); + + m_labelBorderPercent = new TQLabel(i18n("Width (%):"), m_gboxSettings->plainPage()); + m_borderPercent = new RIntNumInput(m_gboxSettings->plainPage()); + m_borderPercent->setRange(1, 50, 1); + m_borderPercent->setDefaultValue(10); + TQWhatsThis::add(m_borderPercent, i18n("<p>Set here the border width in percent of the image size.")); + + m_labelBorderWidth = new TQLabel(i18n("Width (pixels):"), m_gboxSettings->plainPage()); + m_borderWidth = new RIntNumInput(m_gboxSettings->plainPage()); + m_borderWidth->setDefaultValue(100); + TQWhatsThis::add(m_borderWidth, i18n("<p>Set here the border width in pixels to add around the image.")); + + ImageIface iface(0, 0); + int w = iface.originalWidth(); + int h = iface.originalHeight(); + + if (w > h) + m_borderWidth->setRange(1, h/2, 1); + else + m_borderWidth->setRange(1, w/2, 1); + + KSeparator *line2 = new KSeparator(Horizontal, m_gboxSettings->plainPage()); + + // ------------------------------------------------------------------- + + m_labelForeground = new TQLabel(m_gboxSettings->plainPage()); + m_firstColorButton = new KColorButton( TQColor( 192, 192, 192 ), m_gboxSettings->plainPage() ); + m_labelBackground = new TQLabel(m_gboxSettings->plainPage()); + m_secondColorButton = new KColorButton( TQColor( 128, 128, 128 ), m_gboxSettings->plainPage() ); + + // ------------------------------------------------------------------- + + grid->addMultiCellWidget(label1, 0, 0, 0, 2); + grid->addMultiCellWidget(m_borderType, 1, 1, 0, 2); + grid->addMultiCellWidget(line1, 2, 2, 0, 2); + grid->addMultiCellWidget(m_preserveAspectRatio, 3, 3, 0, 2); + grid->addMultiCellWidget(m_labelBorderPercent, 4, 4, 0, 2); + grid->addMultiCellWidget(m_borderPercent, 5, 5, 0, 2); + grid->addMultiCellWidget(m_labelBorderWidth, 6, 6, 0, 2); + grid->addMultiCellWidget(m_borderWidth, 7, 7, 0, 2); + grid->addMultiCellWidget(line2, 8, 8, 0, 2); + grid->addMultiCellWidget(m_labelForeground, 9, 9, 0, 0); + grid->addMultiCellWidget(m_firstColorButton, 9, 9, 1, 2); + grid->addMultiCellWidget(m_labelBackground, 10, 10, 0, 0); + grid->addMultiCellWidget(m_secondColorButton, 10, 10, 1, 2); + grid->setRowStretch(11, 10); + grid->setMargin(m_gboxSettings->spacingHint()); + grid->setSpacing(m_gboxSettings->spacingHint()); + + setToolSettings(m_gboxSettings); + init(); + + // ------------------------------------------------------------- + + connect(m_preserveAspectRatio, TQ_SIGNAL(toggled(bool)), + this, TQ_SLOT(slotPreserveAspectRatioToggled(bool))); + + connect(m_borderType, TQ_SIGNAL(activated(int)), + this, TQ_SLOT(slotBorderTypeChanged(int))); + + connect(m_borderPercent, TQ_SIGNAL(valueChanged(int)), + this, TQ_SLOT(slotTimer())); + + connect(m_borderWidth, TQ_SIGNAL(valueChanged(int)), + this, TQ_SLOT(slotTimer())); + + connect(m_firstColorButton, TQ_SIGNAL(changed(const TQColor &)), + this, TQ_SLOT(slotColorForegroundChanged(const TQColor &))); + + connect(m_secondColorButton, TQ_SIGNAL(changed(const TQColor &)), + this, TQ_SLOT(slotColorBackgroundChanged(const TQColor &))); +} + +BorderTool::~BorderTool() +{ +} + +void BorderTool::readSettings() +{ + m_borderType->blockSignals(true); + m_borderPercent->blockSignals(true); + m_borderWidth->blockSignals(true); + m_firstColorButton->blockSignals(true); + m_secondColorButton->blockSignals(true); + m_preserveAspectRatio->blockSignals(true); + + TDEConfig *config = kapp->config(); + config->setGroup("border Tool"); + + m_borderType->setCurrentItem(config->readNumEntry("Border Type", m_borderType->defaultItem())); + m_borderPercent->setValue(config->readNumEntry("Border Percent", m_borderPercent->defaultValue())); + m_borderWidth->setValue(config->readNumEntry("Border Width", m_borderWidth->defaultValue())); + m_preserveAspectRatio->setChecked(config->readBoolEntry("Preserve Aspect Ratio", true)); + + TQColor black(0, 0, 0); + TQColor white(255, 255, 255); + TQColor gray1(192, 192, 192); + TQColor gray2(128, 128, 128); + + m_solidColor = config->readColorEntry("Solid Color", &black); + m_niepceBorderColor = config->readColorEntry("Niepce Border Color", &white); + m_niepceLineColor = config->readColorEntry("Niepce Line Color", &black); + m_bevelUpperLeftColor = config->readColorEntry("Bevel Upper Left Color", &gray1); + m_bevelLowerRightColor = config->readColorEntry("Bevel Lower Right Color", &gray2); + m_decorativeFirstColor = config->readColorEntry("Decorative First Color", &black); + m_decorativeSecondColor = config->readColorEntry("Decorative Second Color", &black); + + m_borderType->blockSignals(false); + m_borderPercent->blockSignals(false); + m_borderWidth->blockSignals(false); + m_firstColorButton->blockSignals(false); + m_secondColorButton->blockSignals(false); + m_preserveAspectRatio->blockSignals(false); + + slotBorderTypeChanged(m_borderType->currentItem()); +} + +void BorderTool::writeSettings() +{ + TDEConfig *config = kapp->config(); + config->setGroup("border Tool"); + + config->writeEntry("Border Type", m_borderType->currentItem()); + config->writeEntry("Border Percent", m_borderPercent->value()); + config->writeEntry("Border Width", m_borderWidth->value()); + config->writeEntry("Preserve Aspect Ratio", m_preserveAspectRatio->isChecked()); + + config->writeEntry("Solid Color", m_solidColor); + config->writeEntry("Niepce Border Color", m_niepceBorderColor); + config->writeEntry("Niepce Line Color", m_niepceLineColor); + config->writeEntry("Bevel Upper Left Color", m_bevelUpperLeftColor); + config->writeEntry("Bevel Lower Right Color", m_bevelLowerRightColor); + config->writeEntry("Decorative First Color", m_decorativeFirstColor); + config->writeEntry("Decorative Second Color", m_decorativeSecondColor); + + m_previewWidget->writeSettings(); + + config->sync(); +} + +void BorderTool::slotResetSettings() +{ + m_borderType->blockSignals(true); + m_borderPercent->blockSignals(true); + m_borderWidth->blockSignals(true); + m_firstColorButton->blockSignals(true); + m_secondColorButton->blockSignals(true); + m_preserveAspectRatio->blockSignals(true); + + m_borderType->slotReset(); + m_borderPercent->slotReset(); + m_borderWidth->slotReset(); + m_preserveAspectRatio->setChecked(true); + + m_solidColor = TQColor(0, 0, 0); + m_niepceBorderColor = TQColor(255, 255, 255); + m_niepceLineColor = TQColor(0, 0, 0); + m_bevelUpperLeftColor = TQColor(192, 192, 192); + m_bevelLowerRightColor = TQColor(128, 128, 128); + m_decorativeFirstColor = TQColor(0, 0, 0); + m_decorativeSecondColor = TQColor(0, 0, 0); + + m_borderType->blockSignals(false); + m_borderPercent->blockSignals(false); + m_borderWidth->blockSignals(false); + m_firstColorButton->blockSignals(false); + m_secondColorButton->blockSignals(false); + m_preserveAspectRatio->blockSignals(false); + + slotBorderTypeChanged(Border::SolidBorder); +} + +void BorderTool::renderingFinished() +{ + m_preserveAspectRatio->setEnabled(true); + m_borderType->setEnabled(true); + m_borderPercent->setEnabled(true); + m_borderWidth->setEnabled(true); + m_firstColorButton->setEnabled(true); + m_secondColorButton->setEnabled(true); + toggleBorderSlider(m_preserveAspectRatio->isChecked()); +} + +void BorderTool::slotColorForegroundChanged(const TQColor &color) +{ + switch (m_borderType->currentItem()) + { + case Border::SolidBorder: + m_solidColor = color; + break; + + case Border::NiepceBorder: + m_niepceBorderColor = color; + break; + + case Border::BeveledBorder: + m_bevelUpperLeftColor = color; + break; + + case Border::PineBorder: + case Border::WoodBorder: + case Border::PaperBorder: + case Border::ParqueBorder: + case Border::IceBorder: + case Border::LeafBorder: + case Border::MarbleBorder: + case Border::RainBorder: + case Border::CratersBorder: + case Border::DriedBorder: + case Border::PinkBorder: + case Border::StoneBorder: + case Border::ChalkBorder: + case Border::GraniteBorder: + case Border::RockBorder: + case Border::WallBorder: + m_decorativeFirstColor = color; + break; + } + + slotEffect(); +} + +void BorderTool::slotColorBackgroundChanged(const TQColor &color) +{ + switch (m_borderType->currentItem()) + { + case Border::SolidBorder: + m_solidColor = color; + break; + + case Border::NiepceBorder: + m_niepceLineColor = color; + break; + + case Border::BeveledBorder: + m_bevelLowerRightColor = color; + break; + + case Border::PineBorder: + case Border::WoodBorder: + case Border::PaperBorder: + case Border::ParqueBorder: + case Border::IceBorder: + case Border::LeafBorder: + case Border::MarbleBorder: + case Border::RainBorder: + case Border::CratersBorder: + case Border::DriedBorder: + case Border::PinkBorder: + case Border::StoneBorder: + case Border::ChalkBorder: + case Border::GraniteBorder: + case Border::RockBorder: + case Border::WallBorder: + m_decorativeSecondColor = color; + break; + } + + slotEffect(); +} + +void BorderTool::slotBorderTypeChanged(int borderType) +{ + m_labelForeground->setText(i18n("First:")); + m_labelBackground->setText(i18n("Second:")); + TQWhatsThis::add( m_firstColorButton, i18n("<p>Set here the foreground color of the border.")); + TQWhatsThis::add( m_secondColorButton, i18n("<p>Set here the Background color of the border.")); + m_firstColorButton->setEnabled(true); + m_secondColorButton->setEnabled(true); + m_labelForeground->setEnabled(true); + m_labelBackground->setEnabled(true); + m_borderPercent->setEnabled(true); + + switch (borderType) + { + case Border::SolidBorder: + m_firstColorButton->setColor( m_solidColor ); + m_secondColorButton->setEnabled(false); + m_labelBackground->setEnabled(false); + break; + + case Border::NiepceBorder: + TQWhatsThis::add( m_firstColorButton, i18n("<p>Set here the color of the main border.")); + TQWhatsThis::add( m_secondColorButton, i18n("<p>Set here the color of the line.")); + m_firstColorButton->setColor( m_niepceBorderColor ); + m_secondColorButton->setColor( m_niepceLineColor ); + break; + + case Border::BeveledBorder: + TQWhatsThis::add( m_firstColorButton, i18n("<p>Set here the color of the upper left area.")); + TQWhatsThis::add( m_secondColorButton, i18n("<p>Set here the color of the lower right area.")); + m_firstColorButton->setColor( m_bevelUpperLeftColor ); + m_secondColorButton->setColor( m_bevelLowerRightColor ); + break; + + case Border::PineBorder: + case Border::WoodBorder: + case Border::PaperBorder: + case Border::ParqueBorder: + case Border::IceBorder: + case Border::LeafBorder: + case Border::MarbleBorder: + case Border::RainBorder: + case Border::CratersBorder: + case Border::DriedBorder: + case Border::PinkBorder: + case Border::StoneBorder: + case Border::ChalkBorder: + case Border::GraniteBorder: + case Border::RockBorder: + case Border::WallBorder: + TQWhatsThis::add( m_firstColorButton, i18n("<p>Set here the color of the first line.")); + TQWhatsThis::add( m_secondColorButton, i18n("<p>Set here the color of the second line.")); + m_firstColorButton->setColor( m_decorativeFirstColor ); + m_secondColorButton->setColor( m_decorativeSecondColor ); + break; + } + + slotEffect(); +} + +void BorderTool::prepareEffect() +{ + m_borderType->setEnabled(false); + m_borderPercent->setEnabled(false); + m_borderWidth->setEnabled(false); + m_firstColorButton->setEnabled(false); + m_secondColorButton->setEnabled(false); + m_preserveAspectRatio->setEnabled(false); + + ImageIface* iface = m_previewWidget->imageIface(); + int orgWidth = iface->originalWidth(); + int orgHeight = iface->originalHeight(); + int w = iface->previewWidth(); + int h = iface->previewHeight(); + bool sixteenBit = iface->previewSixteenBit(); + uchar *data = iface->getPreviewImage(); + DImg previewImage(w, h, sixteenBit, + iface->previewHasAlpha(), data); + delete [] data; + + int borderType = m_borderType->currentItem(); + float ratio = (float)w/(float)orgWidth; + int borderWidth = (int)((float)m_borderWidth->value()*ratio); + TQString border = getBorderPath( m_borderType->currentItem() ); + + if (m_preserveAspectRatio->isChecked()) + { + setFilter(dynamic_cast<DImgThreadedFilter*>( + new Border(&previewImage, this, orgWidth, orgHeight, + border, borderType, m_borderPercent->value()/100.0, + DColor(m_solidColor, sixteenBit), + DColor(m_niepceBorderColor, sixteenBit), + DColor(m_niepceLineColor, sixteenBit), + DColor(m_bevelUpperLeftColor, sixteenBit), + DColor(m_bevelLowerRightColor, sixteenBit), + DColor(m_decorativeFirstColor, sixteenBit), + DColor(m_decorativeSecondColor, sixteenBit)))); + } + else + { + setFilter(dynamic_cast<DImgThreadedFilter*>( + new Border(&previewImage, this, orgWidth, orgHeight, + border, borderType, borderWidth, + (int)(20.0*ratio), (int)(20.0*ratio), 3, + DColor(m_solidColor, sixteenBit), + DColor(m_niepceBorderColor, sixteenBit), + DColor(m_niepceLineColor, sixteenBit), + DColor(m_bevelUpperLeftColor, sixteenBit), + DColor(m_bevelLowerRightColor, sixteenBit), + DColor(m_decorativeFirstColor, sixteenBit), + DColor(m_decorativeSecondColor, sixteenBit)))); + } +} + +void BorderTool::prepareFinal() +{ + m_borderType->setEnabled(false); + m_borderPercent->setEnabled(false); + m_borderWidth->setEnabled(false); + m_firstColorButton->setEnabled(false); + m_secondColorButton->setEnabled(false); + + int borderType = m_borderType->currentItem(); + int borderWidth = m_borderWidth->value(); + float borderRatio = m_borderPercent->value()/100.0; + TQString border = getBorderPath( m_borderType->currentItem() ); + + ImageIface iface(0, 0); + int orgWidth = iface.originalWidth(); + int orgHeight = iface.originalHeight(); + bool sixteenBit = iface.previewSixteenBit(); + uchar *data = iface.getOriginalImage(); + DImg orgImage(orgWidth, orgHeight, sixteenBit, + iface.originalHasAlpha(), data); + delete [] data; + + if (m_preserveAspectRatio->isChecked()) + { + setFilter(dynamic_cast<DImgThreadedFilter*>( + new Border(&orgImage, this, orgWidth, orgHeight, + border, borderType, borderRatio, + DColor(m_solidColor, sixteenBit), + DColor(m_niepceBorderColor, sixteenBit), + DColor(m_niepceLineColor, sixteenBit), + DColor(m_bevelUpperLeftColor, sixteenBit), + DColor(m_bevelLowerRightColor, sixteenBit), + DColor(m_decorativeFirstColor, sixteenBit), + DColor(m_decorativeSecondColor, sixteenBit)))); + } + else + { + setFilter(dynamic_cast<DImgThreadedFilter*>( + new Border(&orgImage, this, orgWidth, orgHeight, + border, borderType, borderWidth, 15, 15, 10, + DColor(m_solidColor, sixteenBit), + DColor(m_niepceBorderColor, sixteenBit), + DColor(m_niepceLineColor, sixteenBit), + DColor(m_bevelUpperLeftColor, sixteenBit), + DColor(m_bevelLowerRightColor, sixteenBit), + DColor(m_decorativeFirstColor, sixteenBit), + DColor(m_decorativeSecondColor, sixteenBit)))); + } +} + +void BorderTool::putPreviewData() +{ + ImageIface* iface = m_previewWidget->imageIface(); + int w = iface->previewWidth(); + int h = iface->previewHeight(); + + DImg imTemp = filter()->getTargetImage().smoothScale(w, h, TQSize::ScaleMin); + DImg imDest( w, h, filter()->getTargetImage().sixteenBit(), + filter()->getTargetImage().hasAlpha() ); + + imDest.fill( DColor(m_previewWidget->paletteBackgroundColor().rgb(), + filter()->getTargetImage().sixteenBit()) ); + + imDest.bitBltImage(&imTemp, (w-imTemp.width())/2, (h-imTemp.height())/2); + + iface->putPreviewImage(imDest.bits()); + m_previewWidget->updatePreview(); +} + +void BorderTool::putFinalData() +{ + ImageIface iface(0, 0); + + DImg targetImage = filter()->getTargetImage(); + iface.putOriginalImage(i18n("Add Border"), + targetImage.bits(), + targetImage.width(), targetImage.height()); +} + +TQString BorderTool::getBorderPath(int border) +{ + TQString pattern; + + switch (border) + { + case Border::PineBorder: + pattern = "pine-pattern"; + break; + + case Border::WoodBorder: + pattern = "wood-pattern"; + break; + + case Border::PaperBorder: + pattern = "paper-pattern"; + break; + + case Border::ParqueBorder: + pattern = "parque-pattern"; + break; + + case Border::IceBorder: + pattern = "ice-pattern"; + break; + + case Border::LeafBorder: + pattern = "leaf-pattern"; + break; + + case Border::MarbleBorder: + pattern = "marble-pattern"; + break; + + case Border::RainBorder: + pattern = "rain-pattern"; + break; + + case Border::CratersBorder: + pattern = "craters-pattern"; + break; + + case Border::DriedBorder: + pattern = "dried-pattern"; + break; + + case Border::PinkBorder: + pattern = "pink-pattern"; + break; + + case Border::StoneBorder: + pattern = "stone-pattern"; + break; + + case Border::ChalkBorder: + pattern = "chalk-pattern"; + break; + + case Border::GraniteBorder: + pattern = "granit-pattern"; + break; + + case Border::RockBorder: + pattern = "rock-pattern"; + break; + + case Border::WallBorder: + pattern = "wall-pattern"; + break; + + default: + return TQString(); + } + + TDEGlobal::dirs()->addResourceType(pattern.ascii(), TDEGlobal::dirs()->kde_default("data") + + "digikam/data"); + return (TDEGlobal::dirs()->findResourceDir(pattern.ascii(), pattern + ".png") + pattern + ".png" ); +} + +void BorderTool::slotPreserveAspectRatioToggled(bool b) +{ + toggleBorderSlider(b); + slotTimer(); +} + +void BorderTool::toggleBorderSlider(bool b) +{ + m_borderPercent->setEnabled(b); + m_borderWidth->setEnabled(!b); + m_labelBorderPercent->setEnabled(b); + m_labelBorderWidth->setEnabled(!b); +} + +} // NameSpace DigikamBorderImagesPlugin diff --git a/src/imageplugins/border/bordertool.h b/src/imageplugins/border/bordertool.h new file mode 100644 index 00000000..a8ec5ccf --- /dev/null +++ b/src/imageplugins/border/bordertool.h @@ -0,0 +1,123 @@ +/* ============================================================ + * + * This file is a part of digiKam project + * http://www.digikam.org + * + * Date : 2005-01-20 + * Description : a digiKam image plugin to add a border + * around an image. + * + * Copyright 2005-2008 by Gilles Caulier <caulier dot gilles at gmail dot com> + * Copyright 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 BORDERTOOL_H +#define BORDERTOOL_H + +// TQt includes. + +#include <tqstring.h> + +// Digikam includes. + +#include "editortool.h" + +class TQLabel; +class TQCheckBox; +class TQColor; + +class KColorButton; + +namespace KDcrawIface +{ +class RIntNumInput; +class RComboBox; +} + +namespace Digikam +{ +class EditorToolSettings; +class ImageWidget; +} + +namespace DigikamBorderImagesPlugin +{ + +class BorderTool : public Digikam::EditorToolThreaded +{ + TQ_OBJECT + + +public: + + BorderTool(TQObject *parent); + ~BorderTool(); + +private: + + TQString getBorderPath(int border); + +private slots: + + void slotPreserveAspectRatioToggled(bool); + void slotBorderTypeChanged(int borderType); + void slotColorForegroundChanged(const TQColor &color); + void slotColorBackgroundChanged(const TQColor &color); + void slotResetSettings(); + +private: + + void writeSettings(); + void readSettings(); + void prepareEffect(); + void prepareFinal(); + void putPreviewData(); + void putFinalData(); + void renderingFinished(); + void toggleBorderSlider(bool b); + +private: + + TQLabel *m_labelBorderPercent; + TQLabel *m_labelBorderWidth; + TQLabel *m_labelForeground; + TQLabel *m_labelBackground; + + TQCheckBox *m_preserveAspectRatio; + + TQColor m_solidColor; + TQColor m_niepceBorderColor; + TQColor m_niepceLineColor; + TQColor m_bevelUpperLeftColor; + TQColor m_bevelLowerRightColor; + TQColor m_decorativeFirstColor; + TQColor m_decorativeSecondColor; + + KDcrawIface::RComboBox *m_borderType; + + KDcrawIface::RIntNumInput *m_borderPercent; + KDcrawIface::RIntNumInput *m_borderWidth; + + KColorButton *m_firstColorButton; + KColorButton *m_secondColorButton; + + Digikam::ImageWidget *m_previewWidget; + + Digikam::EditorToolSettings *m_gboxSettings; +}; + +} // NameSpace DigikamBorderImagesPlugin + +#endif /* BORDERTOOL_H */ diff --git a/src/imageplugins/border/digikamimageplugin_border.desktop b/src/imageplugins/border/digikamimageplugin_border.desktop new file mode 100644 index 00000000..45f32a7e --- /dev/null +++ b/src/imageplugins/border/digikamimageplugin_border.desktop @@ -0,0 +1,50 @@ +[Desktop Entry] +Name=ImagePlugin_Border +Name[bg]=Приставка за снимки - �амки +Name[da]=Billedplugin_Indramning +Name[el]=ΠρόσθετοΕικόνας_Περίγραμμα +Name[fi]=Reunus +Name[hr]=Obrub +Name[it]=PluginImmagini_Bordo +Name[nl]=Afbeeldingsplugin_Rand +Name[sr]=Оквир +Name[sr@Latn]=Okvir +Name[sv]=Insticksprogram för bildkanter +Name[tr]=ResimEklentisi_Çerçeve +Name[xx]=xxImagePlugin_Borderxx +Type=Service +X-TDE-ServiceTypes=Digikam/ImagePlugin +Encoding=UTF-8 +Comment=Add border to image plugin for digiKam +Comment[bg]=Приставка на digiKam за добавяне на рамки на снимки +Comment[ca]=Connector pel digiKam per afegir una vora a la imatge +Comment[da]=Plugin til indramning af billeder i Digikam +Comment[de]=digiKam-Modul zum Hinzufügen eines Rahmens zu einem Bild +Comment[el]=Πρόσθετο προσθήκης περιγράμματος σε εικόνα για το digiKam +Comment[es]=Plugin de digiKam para añadir bordes a la imagen +Comment[et]=DigiKami pildile raami lisamise plugin +Comment[fa]=افزودن لبه به وصلۀ تصویر برای digiKam +Comment[fi]=Lisää kuvaan reunuksen +Comment[gl]=Un plugin de digiKam para engadir un contorno á imaxe +Comment[hr]=digiKam dodatak za dodavanje obruba +Comment[is]=Íforrit fyrir digiKam sem gerir ramma á myndir +Comment[it]=Plugin per l'aggiunta di bordi a un'immagire per digiKam +Comment[ja]=digikam 画像装飾プラグイン +Comment[nds]=digiKam-Moduul för't Tofögen vun Ränners rund en Bild +Comment[nl]=Digikam-plugin voor het toevoegen van randen +Comment[pa]=ਡਿਜ਼ੀਕੈਮ ਲਈ ਹਾਸ਼ੀਆ ਜੋੜਨ ਲਈ ਪਲੱਗਇਨ +Comment[pl]=Wtyczka do programu digiKam dodająca ramkę do obrazu +Comment[pt]=Um 'plugin' do digiKam para adicionar um contorno à imagem +Comment[pt_BR]=Plugin de adicionar borda na imagem +Comment[ru]=Модуль digiKam наложения рамки на изображение +Comment[sk]=digiKam plugin pridávajúci okraj obrázku +Comment[sr]=Прикључак за digiKam који додаје оквир на слику +Comment[sr@Latn]=Priključak za digiKam koji dodaje okvir na sliku +Comment[sv]=Digikam insticksprogram för tillägg av kanter +Comment[tr]=digiKam için resme çerçeve eklenme eklentisi +Comment[uk]=Втулок digiKam для додавання рамки навколо зображення +Comment[vi]=Phần bổ sung thêm viền trên ảnh cho digiKam +Comment[xx]=xxAdd border to image plugin for digiKamxx + +X-TDE-Library=digikamimageplugin_border +author=Gilles Caulier, caulier dot gilles at gmail dot com diff --git a/src/imageplugins/border/digikamimageplugin_border_ui.rc b/src/imageplugins/border/digikamimageplugin_border_ui.rc new file mode 100644 index 00000000..8cce0581 --- /dev/null +++ b/src/imageplugins/border/digikamimageplugin_border_ui.rc @@ -0,0 +1,20 @@ +<!DOCTYPE kpartgui SYSTEM "kpartgui.dtd"> +<kpartgui version="6" name="digikamimageplugin_border" > + + <MenuBar> + + <Menu name="Decorate" ><text>&Decorate</text> + <Action name="imageplugin_border" /> + </Menu> + + </MenuBar> + + <ToolBar name="ToolBar" > + <text>Main Toolbar</text> + </ToolBar> + + <ActionProperties> + <Action name="imageplugin_border" /> + </ActionProperties> + +</kpartgui> diff --git a/src/imageplugins/border/imageeffect_border.cpp b/src/imageplugins/border/imageeffect_border.cpp new file mode 100644 index 00000000..9f3dd6c3 --- /dev/null +++ b/src/imageplugins/border/imageeffect_border.cpp @@ -0,0 +1,667 @@ +/* ============================================================ + * + * This file is a part of digiKam project + * http://www.digikam.org + * + * Date : 2005-01-20 + * Description : a digiKam image plugin to add a border + * around an image. + * + * Copyright 2005-2008 by Gilles Caulier <caulier dot gilles at gmail dot com> + * Copyright 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 <tqlabel.h> +#include <tqwhatsthis.h> +#include <tqlayout.h> +#include <tqcombobox.h> +#include <tqcheckbox.h> + +// KDE includes. + +#include <kseparator.h> +#include <tdelocale.h> +#include <tdeaboutdata.h> +#include <kiconloader.h> +#include <tdeapplication.h> +#include <kstandarddirs.h> +#include <tdeconfig.h> +#include <knuminput.h> +#include <kcolorbutton.h> + +// Local includes. + +#include "version.h" +#include "ddebug.h" +#include "imageiface.h" +#include "imagewidget.h" +#include "border.h" +#include "imageeffect_border.h" +#include "imageeffect_border.moc" + +namespace DigikamBorderImagesPlugin +{ + +ImageEffect_Border::ImageEffect_Border(TQWidget* parent) + : Digikam::ImageGuideDlg(parent, i18n("Add Border Around Photograph"), + "border", false, false, false, + Digikam::ImageGuideWidget::HVGuideMode) +{ + // No need Abort button action. + showButton(User1, false); + + TQString whatsThis; + + TDEAboutData* about = new TDEAboutData("digikam", + I18N_NOOP("Add Border"), + digikam_version, + I18N_NOOP("A digiKam image plugin to add a border around an image."), + TDEAboutData::License_GPL, + "(c) 2005, 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); + + // ------------------------------------------------------------- + + TQWidget *gboxSettings = new TQWidget(plainPage()); + TQGridLayout* gridSettings = new TQGridLayout(gboxSettings, 10, 2, spacingHint()); + + TQLabel *label1 = new TQLabel(i18n("Type:"), gboxSettings); + + m_borderType = new TQComboBox( false, gboxSettings ); + m_borderType->insertItem( i18n("Solid") ); + // Niepce is Real name. This is the first guy in the world to have built a camera. + m_borderType->insertItem( "Niepce" ); + m_borderType->insertItem( i18n("Beveled") ); + m_borderType->insertItem( i18n("Decorative Pine") ); + m_borderType->insertItem( i18n("Decorative Wood") ); + m_borderType->insertItem( i18n("Decorative Paper") ); + m_borderType->insertItem( i18n("Decorative Parquet") ); + m_borderType->insertItem( i18n("Decorative Ice") ); + m_borderType->insertItem( i18n("Decorative Leaf") ); + m_borderType->insertItem( i18n("Decorative Marble") ); + m_borderType->insertItem( i18n("Decorative Rain") ); + m_borderType->insertItem( i18n("Decorative Craters") ); + m_borderType->insertItem( i18n("Decorative Dried") ); + m_borderType->insertItem( i18n("Decorative Pink") ); + m_borderType->insertItem( i18n("Decorative Stone") ); + m_borderType->insertItem( i18n("Decorative Chalk") ); + m_borderType->insertItem( i18n("Decorative Granite") ); + m_borderType->insertItem( i18n("Decorative Rock") ); + m_borderType->insertItem( i18n("Decorative Wall") ); + TQWhatsThis::add( m_borderType, i18n("<p>Select the border type to add around the image.")); + + KSeparator *line1 = new KSeparator(Horizontal, gboxSettings); + + // ------------------------------------------------------------------- + + m_preserveAspectRatio = new TQCheckBox(gboxSettings); + m_preserveAspectRatio->setText(i18n("Preserve Aspect Ratio")); + TQWhatsThis::add(m_preserveAspectRatio, i18n("Enable this option if you want to preserve the aspect " + "ratio of the image. If enabled, the border width will be " + "in percent of the image size, else the border width will " + "in pixels.")); + + m_labelBorderPercent = new TQLabel(i18n("Width (%):"), gboxSettings); + m_borderPercent = new KIntNumInput(gboxSettings); + m_borderPercent->setRange(1, 50, 1, true); + TQWhatsThis::add(m_borderPercent, i18n("<p>Set here the border width in percent of the image size.")); + + m_labelBorderWidth = new TQLabel(i18n("Width (pixels):"), gboxSettings); + m_borderWidth = new KIntNumInput(gboxSettings); + TQWhatsThis::add(m_borderWidth, i18n("<p>Set here the border width in pixels to add around the image.")); + + Digikam::ImageIface iface(0, 0); + int w = iface.originalWidth(); + int h = iface.originalHeight(); + + if (w > h) + m_borderWidth->setRange(1, h/2, 1, true); + else + m_borderWidth->setRange(1, w/2, 1, true); + + KSeparator *line2 = new KSeparator(Horizontal, gboxSettings); + + // ------------------------------------------------------------------- + + m_labelForeground = new TQLabel(gboxSettings); + m_firstColorButton = new KColorButton( TQColor( 192, 192, 192 ), gboxSettings ); + m_labelBackground = new TQLabel(gboxSettings); + m_secondColorButton = new KColorButton( TQColor( 128, 128, 128 ), gboxSettings ); + + // ------------------------------------------------------------------- + + gridSettings->addMultiCellWidget(label1, 0, 0, 0, 2); + gridSettings->addMultiCellWidget(m_borderType, 1, 1, 0, 2); + gridSettings->addMultiCellWidget(line1, 2, 2, 0, 2); + gridSettings->addMultiCellWidget(m_preserveAspectRatio, 3, 3, 0, 2); + gridSettings->addMultiCellWidget(m_labelBorderPercent, 4, 4, 0, 2); + gridSettings->addMultiCellWidget(m_borderPercent, 5, 5, 0, 2); + gridSettings->addMultiCellWidget(m_labelBorderWidth, 6, 6, 0, 2); + gridSettings->addMultiCellWidget(m_borderWidth, 7, 7, 0, 2); + gridSettings->addMultiCellWidget(line2, 8, 8, 0, 2); + gridSettings->addMultiCellWidget(m_labelForeground, 9, 9, 0, 0); + gridSettings->addMultiCellWidget(m_firstColorButton, 9, 9, 1, 2); + gridSettings->addMultiCellWidget(m_labelBackground, 10, 10, 0, 0); + gridSettings->addMultiCellWidget(m_secondColorButton, 10, 10, 1, 2); + + setUserAreaWidget(gboxSettings); + + // ------------------------------------------------------------- + + connect(m_preserveAspectRatio, TQ_SIGNAL(toggled(bool)), + this, TQ_SLOT(slotPreserveAspectRatioToggled(bool))); + + connect(m_borderType, TQ_SIGNAL(activated(int)), + this, TQ_SLOT(slotBorderTypeChanged(int))); + + connect(m_borderPercent, TQ_SIGNAL(valueChanged(int)), + this, TQ_SLOT(slotTimer())); + + connect(m_borderWidth, TQ_SIGNAL(valueChanged(int)), + this, TQ_SLOT(slotTimer())); + + connect(m_firstColorButton, TQ_SIGNAL(changed(const TQColor &)), + this, TQ_SLOT(slotColorForegroundChanged(const TQColor &))); + + connect(m_secondColorButton, TQ_SIGNAL(changed(const TQColor &)), + this, TQ_SLOT(slotColorBackgroundChanged(const TQColor &))); +} + +ImageEffect_Border::~ImageEffect_Border() +{ +} + +void ImageEffect_Border::readUserSettings(void) +{ + m_borderType->blockSignals(true); + m_borderPercent->blockSignals(true); + m_borderWidth->blockSignals(true); + m_firstColorButton->blockSignals(true); + m_secondColorButton->blockSignals(true); + m_preserveAspectRatio->blockSignals(true); + + TDEConfig *config = kapp->config(); + config->setGroup("border Tool Dialog"); + + m_borderType->setCurrentItem(config->readNumEntry("Border Type", Border::SolidBorder)); + m_borderPercent->setValue(config->readNumEntry("Border Percent", 10) ); + m_borderWidth->setValue(config->readNumEntry("Border Width", 100) ); + m_preserveAspectRatio->setChecked(config->readBoolEntry("Preserve Aspect Ratio", true) ); + + TQColor black(0, 0, 0); + TQColor white(255, 255, 255); + TQColor gray1(192, 192, 192); + TQColor gray2(128, 128, 128); + + m_solidColor = config->readColorEntry("Solid Color", &black); + m_niepceBorderColor = config->readColorEntry("Niepce Border Color", &white); + m_niepceLineColor = config->readColorEntry("Niepce Line Color", &black); + m_bevelUpperLeftColor = config->readColorEntry("Bevel Upper Left Color", &gray1); + m_bevelLowerRightColor = config->readColorEntry("Bevel Lower Right Color", &gray2); + m_decorativeFirstColor = config->readColorEntry("Decorative First Color", &black); + m_decorativeSecondColor = config->readColorEntry("Decorative Second Color", &black); + + m_borderType->blockSignals(false); + m_borderPercent->blockSignals(false); + m_borderWidth->blockSignals(false); + m_firstColorButton->blockSignals(false); + m_secondColorButton->blockSignals(false); + m_preserveAspectRatio->blockSignals(false); + + slotBorderTypeChanged(m_borderType->currentItem()); +} + +void ImageEffect_Border::writeUserSettings(void) +{ + TDEConfig *config = kapp->config(); + config->setGroup("border Tool Dialog"); + + config->writeEntry("Border Type", m_borderType->currentItem()); + config->writeEntry("Border Percent", m_borderPercent->value()); + config->writeEntry("Border Width", m_borderWidth->value()); + config->writeEntry("Preserve Aspect Ratio", m_preserveAspectRatio->isChecked()); + + config->writeEntry("Solid Color", m_solidColor); + config->writeEntry("Niepce Border Color", m_niepceBorderColor); + config->writeEntry("Niepce Line Color", m_niepceLineColor); + config->writeEntry("Bevel Upper Left Color", m_bevelUpperLeftColor); + config->writeEntry("Bevel Lower Right Color", m_bevelLowerRightColor); + config->writeEntry("Decorative First Color", m_decorativeFirstColor); + config->writeEntry("Decorative Second Color", m_decorativeSecondColor); + + config->sync(); +} + +void ImageEffect_Border::resetValues() +{ + m_borderType->blockSignals(true); + m_borderPercent->blockSignals(true); + m_borderWidth->blockSignals(true); + m_firstColorButton->blockSignals(true); + m_secondColorButton->blockSignals(true); + m_preserveAspectRatio->blockSignals(true); + + m_borderType->setCurrentItem(Border::SolidBorder); + m_borderPercent->setValue(10); + m_borderWidth->setValue(100); + m_preserveAspectRatio->setChecked(true); + + m_solidColor = TQColor(0, 0, 0); + m_niepceBorderColor = TQColor(255, 255, 255); + m_niepceLineColor = TQColor(0, 0, 0); + m_bevelUpperLeftColor = TQColor(192, 192, 192); + m_bevelLowerRightColor = TQColor(128, 128, 128); + m_decorativeFirstColor = TQColor(0, 0, 0); + m_decorativeSecondColor = TQColor(0, 0, 0); + + m_borderType->blockSignals(false); + m_borderPercent->blockSignals(false); + m_borderWidth->blockSignals(false); + m_firstColorButton->blockSignals(false); + m_secondColorButton->blockSignals(false); + m_preserveAspectRatio->blockSignals(false); + + slotBorderTypeChanged(Border::SolidBorder); +} + +void ImageEffect_Border::renderingFinished() +{ + m_preserveAspectRatio->setEnabled(true); + m_borderType->setEnabled(true); + m_borderPercent->setEnabled(true); + m_borderWidth->setEnabled(true); + m_firstColorButton->setEnabled(true); + m_secondColorButton->setEnabled(true); + toggleBorderSlider(m_preserveAspectRatio->isChecked()); +} + +void ImageEffect_Border::slotColorForegroundChanged(const TQColor &color) +{ + switch (m_borderType->currentItem()) + { + case Border::SolidBorder: + m_solidColor = color; + break; + + case Border::NiepceBorder: + m_niepceBorderColor = color; + break; + + case Border::BeveledBorder: + m_bevelUpperLeftColor = color; + break; + + case Border::PineBorder: + case Border::WoodBorder: + case Border::PaperBorder: + case Border::ParqueBorder: + case Border::IceBorder: + case Border::LeafBorder: + case Border::MarbleBorder: + case Border::RainBorder: + case Border::CratersBorder: + case Border::DriedBorder: + case Border::PinkBorder: + case Border::StoneBorder: + case Border::ChalkBorder: + case Border::GraniteBorder: + case Border::RockBorder: + case Border::WallBorder: + m_decorativeFirstColor = color; + break; + } + + slotEffect(); +} + +void ImageEffect_Border::slotColorBackgroundChanged(const TQColor &color) +{ + switch (m_borderType->currentItem()) + { + case Border::SolidBorder: + m_solidColor = color; + break; + + case Border::NiepceBorder: + m_niepceLineColor = color; + break; + + case Border::BeveledBorder: + m_bevelLowerRightColor = color; + break; + + case Border::PineBorder: + case Border::WoodBorder: + case Border::PaperBorder: + case Border::ParqueBorder: + case Border::IceBorder: + case Border::LeafBorder: + case Border::MarbleBorder: + case Border::RainBorder: + case Border::CratersBorder: + case Border::DriedBorder: + case Border::PinkBorder: + case Border::StoneBorder: + case Border::ChalkBorder: + case Border::GraniteBorder: + case Border::RockBorder: + case Border::WallBorder: + m_decorativeSecondColor = color; + break; + } + + slotEffect(); +} + +void ImageEffect_Border::slotBorderTypeChanged(int borderType) +{ + m_labelForeground->setText(i18n("First:")); + m_labelBackground->setText(i18n("Second:")); + TQWhatsThis::add( m_firstColorButton, i18n("<p>Set here the foreground color of the border.")); + TQWhatsThis::add( m_secondColorButton, i18n("<p>Set here the Background color of the border.")); + m_firstColorButton->setEnabled(true); + m_secondColorButton->setEnabled(true); + m_labelForeground->setEnabled(true); + m_labelBackground->setEnabled(true); + m_borderPercent->setEnabled(true); + + switch (borderType) + { + case Border::SolidBorder: + m_firstColorButton->setColor( m_solidColor ); + m_secondColorButton->setEnabled(false); + m_labelBackground->setEnabled(false); + break; + + case Border::NiepceBorder: + TQWhatsThis::add( m_firstColorButton, i18n("<p>Set here the color of the main border.")); + TQWhatsThis::add( m_secondColorButton, i18n("<p>Set here the color of the line.")); + m_firstColorButton->setColor( m_niepceBorderColor ); + m_secondColorButton->setColor( m_niepceLineColor ); + break; + + case Border::BeveledBorder: + TQWhatsThis::add( m_firstColorButton, i18n("<p>Set here the color of the upper left area.")); + TQWhatsThis::add( m_secondColorButton, i18n("<p>Set here the color of the lower right area.")); + m_firstColorButton->setColor( m_bevelUpperLeftColor ); + m_secondColorButton->setColor( m_bevelLowerRightColor ); + break; + + case Border::PineBorder: + case Border::WoodBorder: + case Border::PaperBorder: + case Border::ParqueBorder: + case Border::IceBorder: + case Border::LeafBorder: + case Border::MarbleBorder: + case Border::RainBorder: + case Border::CratersBorder: + case Border::DriedBorder: + case Border::PinkBorder: + case Border::StoneBorder: + case Border::ChalkBorder: + case Border::GraniteBorder: + case Border::RockBorder: + case Border::WallBorder: + TQWhatsThis::add( m_firstColorButton, i18n("<p>Set here the color of the first line.")); + TQWhatsThis::add( m_secondColorButton, i18n("<p>Set here the color of the second line.")); + m_firstColorButton->setColor( m_decorativeFirstColor ); + m_secondColorButton->setColor( m_decorativeSecondColor ); + break; + } + + slotEffect(); +} + +void ImageEffect_Border::prepareEffect() +{ + m_borderType->setEnabled(false); + m_borderPercent->setEnabled(false); + m_borderWidth->setEnabled(false); + m_firstColorButton->setEnabled(false); + m_secondColorButton->setEnabled(false); + m_preserveAspectRatio->setEnabled(false); + + Digikam::ImageIface* iface = m_imagePreviewWidget->imageIface(); + int orgWidth = iface->originalWidth(); + int orgHeight = iface->originalHeight(); + int w = iface->previewWidth(); + int h = iface->previewHeight(); + bool sixteenBit = iface->previewSixteenBit(); + uchar *data = iface->getPreviewImage(); + Digikam::DImg previewImage(w, h, sixteenBit, + iface->previewHasAlpha(), data); + delete [] data; + + int borderType = m_borderType->currentItem(); + float ratio = (float)w/(float)orgWidth; + int borderWidth = (int)((float)m_borderWidth->value()*ratio); + TQString border = getBorderPath( m_borderType->currentItem() ); + + if (m_preserveAspectRatio->isChecked()) + { + m_threadedFilter = dynamic_cast<Digikam::DImgThreadedFilter *>( + new Border(&previewImage, this, orgWidth, orgHeight, + border, borderType, m_borderPercent->value()/100.0, + Digikam::DColor(m_solidColor, sixteenBit), + Digikam::DColor(m_niepceBorderColor, sixteenBit), + Digikam::DColor(m_niepceLineColor, sixteenBit), + Digikam::DColor(m_bevelUpperLeftColor, sixteenBit), + Digikam::DColor(m_bevelLowerRightColor, sixteenBit), + Digikam::DColor(m_decorativeFirstColor, sixteenBit), + Digikam::DColor(m_decorativeSecondColor, sixteenBit)) ); + } + else + { + m_threadedFilter = dynamic_cast<Digikam::DImgThreadedFilter *>( + new Border(&previewImage, this, orgWidth, orgHeight, + border, borderType, borderWidth, + (int)(20.0*ratio), (int)(20.0*ratio), 3, + Digikam::DColor(m_solidColor, sixteenBit), + Digikam::DColor(m_niepceBorderColor, sixteenBit), + Digikam::DColor(m_niepceLineColor, sixteenBit), + Digikam::DColor(m_bevelUpperLeftColor, sixteenBit), + Digikam::DColor(m_bevelLowerRightColor, sixteenBit), + Digikam::DColor(m_decorativeFirstColor, sixteenBit), + Digikam::DColor(m_decorativeSecondColor, sixteenBit)) ); + } +} + +void ImageEffect_Border::prepareFinal() +{ + m_borderType->setEnabled(false); + m_borderPercent->setEnabled(false); + m_borderWidth->setEnabled(false); + m_firstColorButton->setEnabled(false); + m_secondColorButton->setEnabled(false); + + int borderType = m_borderType->currentItem(); + int borderWidth = m_borderWidth->value(); + float borderRatio = m_borderPercent->value()/100.0; + TQString border = getBorderPath( m_borderType->currentItem() ); + + Digikam::ImageIface iface(0, 0); + int orgWidth = iface.originalWidth(); + int orgHeight = iface.originalHeight(); + bool sixteenBit = iface.previewSixteenBit(); + uchar *data = iface.getOriginalImage(); + Digikam::DImg orgImage(orgWidth, orgHeight, sixteenBit, + iface.originalHasAlpha(), data); + delete [] data; + + if (m_preserveAspectRatio->isChecked()) + { + m_threadedFilter = dynamic_cast<Digikam::DImgThreadedFilter *>( + new Border(&orgImage, this, orgWidth, orgHeight, + border, borderType, borderRatio, + Digikam::DColor(m_solidColor, sixteenBit), + Digikam::DColor(m_niepceBorderColor, sixteenBit), + Digikam::DColor(m_niepceLineColor, sixteenBit), + Digikam::DColor(m_bevelUpperLeftColor, sixteenBit), + Digikam::DColor(m_bevelLowerRightColor, sixteenBit), + Digikam::DColor(m_decorativeFirstColor, sixteenBit), + Digikam::DColor(m_decorativeSecondColor, sixteenBit)) ); + } + else + { + m_threadedFilter = dynamic_cast<Digikam::DImgThreadedFilter *>( + new Border(&orgImage, this, orgWidth, orgHeight, + border, borderType, borderWidth, 15, 15, 10, + Digikam::DColor(m_solidColor, sixteenBit), + Digikam::DColor(m_niepceBorderColor, sixteenBit), + Digikam::DColor(m_niepceLineColor, sixteenBit), + Digikam::DColor(m_bevelUpperLeftColor, sixteenBit), + Digikam::DColor(m_bevelLowerRightColor, sixteenBit), + Digikam::DColor(m_decorativeFirstColor, sixteenBit), + Digikam::DColor(m_decorativeSecondColor, sixteenBit)) ); + } +} + +void ImageEffect_Border::putPreviewData(void) +{ + Digikam::ImageIface* iface = m_imagePreviewWidget->imageIface(); + int w = iface->previewWidth(); + int h = iface->previewHeight(); + + Digikam::DImg imTemp = m_threadedFilter->getTargetImage().smoothScale(w, h, TQSize::ScaleMin); + Digikam::DImg imDest( w, h, m_threadedFilter->getTargetImage().sixteenBit(), + m_threadedFilter->getTargetImage().hasAlpha() ); + + imDest.fill( Digikam::DColor(paletteBackgroundColor().rgb(), + m_threadedFilter->getTargetImage().sixteenBit()) ); + + imDest.bitBltImage(&imTemp, (w-imTemp.width())/2, (h-imTemp.height())/2); + + iface->putPreviewImage(imDest.bits()); + m_imagePreviewWidget->updatePreview(); +} + +void ImageEffect_Border::putFinalData(void) +{ + Digikam::ImageIface iface(0, 0); + + Digikam::DImg targetImage = m_threadedFilter->getTargetImage(); + iface.putOriginalImage(i18n("Add Border"), + targetImage.bits(), + targetImage.width(), targetImage.height()); +} + +TQString ImageEffect_Border::getBorderPath(int border) +{ + TQString pattern; + + switch (border) + { + case Border::PineBorder: + pattern = "pine-pattern"; + break; + + case Border::WoodBorder: + pattern = "wood-pattern"; + break; + + case Border::PaperBorder: + pattern = "paper-pattern"; + break; + + case Border::ParqueBorder: + pattern = "parque-pattern"; + break; + + case Border::IceBorder: + pattern = "ice-pattern"; + break; + + case Border::LeafBorder: + pattern = "leaf-pattern"; + break; + + case Border::MarbleBorder: + pattern = "marble-pattern"; + break; + + case Border::RainBorder: + pattern = "rain-pattern"; + break; + + case Border::CratersBorder: + pattern = "craters-pattern"; + break; + + case Border::DriedBorder: + pattern = "dried-pattern"; + break; + + case Border::PinkBorder: + pattern = "pink-pattern"; + break; + + case Border::StoneBorder: + pattern = "stone-pattern"; + break; + + case Border::ChalkBorder: + pattern = "chalk-pattern"; + break; + + case Border::GraniteBorder: + pattern = "granit-pattern"; + break; + + case Border::RockBorder: + pattern = "rock-pattern"; + break; + + case Border::WallBorder: + pattern = "wall-pattern"; + break; + + default: + return TQString(); + } + + TDEGlobal::dirs()->addResourceType(pattern.ascii(), TDEGlobal::dirs()->kde_default("data") + + "digikam/data"); + return (TDEGlobal::dirs()->findResourceDir(pattern.ascii(), pattern + ".png") + pattern + ".png" ); +} + +void ImageEffect_Border::slotPreserveAspectRatioToggled(bool b) +{ + toggleBorderSlider(b); + slotTimer(); +} + +void ImageEffect_Border::toggleBorderSlider(bool b) +{ + m_borderPercent->setEnabled(b); + m_borderWidth->setEnabled(!b); + m_labelBorderPercent->setEnabled(b); + m_labelBorderWidth->setEnabled(!b); +} + +} // NameSpace DigikamBorderImagesPlugin + diff --git a/src/imageplugins/border/imageeffect_border.h b/src/imageplugins/border/imageeffect_border.h new file mode 100644 index 00000000..787a76a0 --- /dev/null +++ b/src/imageplugins/border/imageeffect_border.h @@ -0,0 +1,109 @@ +/* ============================================================ + * + * This file is a part of digiKam project + * http://www.digikam.org + * + * Date : 2005-01-20 + * Description : a digiKam image plugin to add a border + * around an image. + * + * Copyright 2005-2008 by Gilles Caulier <caulier dot gilles at gmail dot com> + * Copyright 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_BORDER_H +#define IMAGEEFFECT_BORDER_H + +// TQt includes. + +#include <tqstring.h> + +// Digikam includes. + +#include "imageguidedlg.h" + +class TQComboBox; +class TQLabel; +class TQCheckBox; +class TQColor; + +class KIntNumInput; +class KColorButton; + +namespace DigikamBorderImagesPlugin +{ + +class ImageEffect_Border : public Digikam::ImageGuideDlg +{ + TQ_OBJECT + + +public: + + ImageEffect_Border(TQWidget *parent); + ~ImageEffect_Border(); + +private: + + TQString getBorderPath(int border); + +private slots: + + void slotPreserveAspectRatioToggled(bool); + void slotBorderTypeChanged(int borderType); + void slotColorForegroundChanged(const TQColor &color); + void slotColorBackgroundChanged(const TQColor &color); + void readUserSettings(); + +private: + + void writeUserSettings(); + void resetValues(); + void prepareEffect(); + void prepareFinal(); + void putPreviewData(); + void putFinalData(); + void renderingFinished(); + void toggleBorderSlider(bool b); + +private: + + TQLabel *m_labelBorderPercent; + TQLabel *m_labelBorderWidth; + TQLabel *m_labelForeground; + TQLabel *m_labelBackground; + + TQComboBox *m_borderType; + + TQCheckBox *m_preserveAspectRatio; + + TQColor m_solidColor; + TQColor m_niepceBorderColor; + TQColor m_niepceLineColor; + TQColor m_bevelUpperLeftColor; + TQColor m_bevelLowerRightColor; + TQColor m_decorativeFirstColor; + TQColor m_decorativeSecondColor; + + KIntNumInput *m_borderPercent; + KIntNumInput *m_borderWidth; + + KColorButton *m_firstColorButton; + KColorButton *m_secondColorButton; +}; + +} // NameSpace DigikamBorderImagesPlugin + +#endif /* IMAGEEFFECT_BORDER_H */ diff --git a/src/imageplugins/border/imageplugin_border.cpp b/src/imageplugins/border/imageplugin_border.cpp new file mode 100644 index 00000000..f0c5a236 --- /dev/null +++ b/src/imageplugins/border/imageplugin_border.cpp @@ -0,0 +1,71 @@ +/* ============================================================ + * + * This file is a part of digiKam project + * http://www.digikam.org + * + * Date : 2005-01-20 + * Description : a digiKam image plugin to add a border + * around an image. + * + * Copyright 2005-2008 by Gilles Caulier <caulier dot gilles at gmail dot com> + * + * 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 "bordertool.h" +#include "imageplugin_border.h" +#include "imageplugin_border.moc" + +using namespace DigikamBorderImagesPlugin; + +K_EXPORT_COMPONENT_FACTORY(digikamimageplugin_border, + KGenericFactory<ImagePlugin_Border>("digikamimageplugin_border")); + +ImagePlugin_Border::ImagePlugin_Border(TQObject *parent, const char*, const TQStringList &) + : Digikam::ImagePlugin(parent, "ImagePlugin_Border") +{ + m_borderAction = new TDEAction(i18n("Add Border..."), "bordertool", + 0, + this, TQ_SLOT(slotBorder()), + actionCollection(), "imageplugin_border"); + + setXMLFile("digikamimageplugin_border_ui.rc"); + + DDebug() << "ImagePlugin_Border plugin loaded" << endl; +} + +ImagePlugin_Border::~ImagePlugin_Border() +{ +} + +void ImagePlugin_Border::setEnabledActions(bool enable) +{ + m_borderAction->setEnabled(enable); +} + +void ImagePlugin_Border::slotBorder() +{ + BorderTool *tool = new BorderTool(this); + loadTool(tool); +} diff --git a/src/imageplugins/border/imageplugin_border.h b/src/imageplugins/border/imageplugin_border.h new file mode 100644 index 00000000..e5b3d959 --- /dev/null +++ b/src/imageplugins/border/imageplugin_border.h @@ -0,0 +1,57 @@ +/* ============================================================ + * + * This file is a part of digiKam project + * http://www.digikam.org + * + * Date : 2005-01-20 + * Description : a digiKam image plugin to add a border + * around an image. + * + * Copyright 2005-2008 by Gilles Caulier <caulier dot gilles at gmail dot com> + * + * 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_BORDER_H +#define IMAGEPLUGIN_BORDER_H + +// Digikam includes. + +#include "imageplugin.h" +#include "digikam_export.h" + +class TDEAction; + +class DIGIKAMIMAGEPLUGINS_EXPORT ImagePlugin_Border : public Digikam::ImagePlugin +{ + TQ_OBJECT + + +public: + + ImagePlugin_Border(TQObject *parent, const char* name, + const TQStringList &args); + ~ImagePlugin_Border(); + + void setEnabledActions(bool enable); + +private slots: + + void slotBorder(); + +private: + + TDEAction *m_borderAction; +}; + +#endif /* IMAGEPLUGIN_BORDER_H */ diff --git a/src/imageplugins/border/patterns/Makefile.am b/src/imageplugins/border/patterns/Makefile.am new file mode 100644 index 00000000..31bb4b2d --- /dev/null +++ b/src/imageplugins/border/patterns/Makefile.am @@ -0,0 +1,5 @@ +borderpicsdir = $(kde_datadir)/digikam/data +borderpics_DATA = pine-pattern.png wood-pattern.png paper-pattern.png parque-pattern.png \ + ice-pattern.png leaf-pattern.png marble-pattern.png rain-pattern.png \ + craters-pattern.png dried-pattern.png pink-pattern.png stone-pattern.png \ + chalk-pattern.png granit-pattern.png rock-pattern.png wall-pattern.png diff --git a/src/imageplugins/border/patterns/chalk-pattern.png b/src/imageplugins/border/patterns/chalk-pattern.png Binary files differnew file mode 100644 index 00000000..31c34f62 --- /dev/null +++ b/src/imageplugins/border/patterns/chalk-pattern.png diff --git a/src/imageplugins/border/patterns/craters-pattern.png b/src/imageplugins/border/patterns/craters-pattern.png Binary files differnew file mode 100644 index 00000000..fe8fe792 --- /dev/null +++ b/src/imageplugins/border/patterns/craters-pattern.png diff --git a/src/imageplugins/border/patterns/dried-pattern.png b/src/imageplugins/border/patterns/dried-pattern.png Binary files differnew file mode 100644 index 00000000..fca948ff --- /dev/null +++ b/src/imageplugins/border/patterns/dried-pattern.png diff --git a/src/imageplugins/border/patterns/granit-pattern.png b/src/imageplugins/border/patterns/granit-pattern.png Binary files differnew file mode 100644 index 00000000..eccbb354 --- /dev/null +++ b/src/imageplugins/border/patterns/granit-pattern.png diff --git a/src/imageplugins/border/patterns/ice-pattern.png b/src/imageplugins/border/patterns/ice-pattern.png Binary files differnew file mode 100644 index 00000000..30a67265 --- /dev/null +++ b/src/imageplugins/border/patterns/ice-pattern.png diff --git a/src/imageplugins/border/patterns/leaf-pattern.png b/src/imageplugins/border/patterns/leaf-pattern.png Binary files differnew file mode 100644 index 00000000..b602fceb --- /dev/null +++ b/src/imageplugins/border/patterns/leaf-pattern.png diff --git a/src/imageplugins/border/patterns/marble-pattern.png b/src/imageplugins/border/patterns/marble-pattern.png Binary files differnew file mode 100644 index 00000000..6346bf1f --- /dev/null +++ b/src/imageplugins/border/patterns/marble-pattern.png diff --git a/src/imageplugins/border/patterns/paper-pattern.png b/src/imageplugins/border/patterns/paper-pattern.png Binary files differnew file mode 100644 index 00000000..43da3b2f --- /dev/null +++ b/src/imageplugins/border/patterns/paper-pattern.png diff --git a/src/imageplugins/border/patterns/parque-pattern.png b/src/imageplugins/border/patterns/parque-pattern.png Binary files differnew file mode 100644 index 00000000..2aa5e96f --- /dev/null +++ b/src/imageplugins/border/patterns/parque-pattern.png diff --git a/src/imageplugins/border/patterns/pine-pattern.png b/src/imageplugins/border/patterns/pine-pattern.png Binary files differnew file mode 100644 index 00000000..4ae7a687 --- /dev/null +++ b/src/imageplugins/border/patterns/pine-pattern.png diff --git a/src/imageplugins/border/patterns/pink-pattern.png b/src/imageplugins/border/patterns/pink-pattern.png Binary files differnew file mode 100644 index 00000000..d0649c85 --- /dev/null +++ b/src/imageplugins/border/patterns/pink-pattern.png diff --git a/src/imageplugins/border/patterns/rain-pattern.png b/src/imageplugins/border/patterns/rain-pattern.png Binary files differnew file mode 100644 index 00000000..a282c442 --- /dev/null +++ b/src/imageplugins/border/patterns/rain-pattern.png diff --git a/src/imageplugins/border/patterns/rock-pattern.png b/src/imageplugins/border/patterns/rock-pattern.png Binary files differnew file mode 100644 index 00000000..04dc8b0e --- /dev/null +++ b/src/imageplugins/border/patterns/rock-pattern.png diff --git a/src/imageplugins/border/patterns/stone-pattern.png b/src/imageplugins/border/patterns/stone-pattern.png Binary files differnew file mode 100644 index 00000000..98da7c2c --- /dev/null +++ b/src/imageplugins/border/patterns/stone-pattern.png diff --git a/src/imageplugins/border/patterns/wall-pattern.png b/src/imageplugins/border/patterns/wall-pattern.png Binary files differnew file mode 100644 index 00000000..3c101597 --- /dev/null +++ b/src/imageplugins/border/patterns/wall-pattern.png diff --git a/src/imageplugins/border/patterns/wood-pattern.png b/src/imageplugins/border/patterns/wood-pattern.png Binary files differnew file mode 100644 index 00000000..bfe4c724 --- /dev/null +++ b/src/imageplugins/border/patterns/wood-pattern.png |