diff --git a/chalk/Makefile.am b/chalk/Makefile.am index 0940e393d..3a8f35134 100644 --- a/chalk/Makefile.am +++ b/chalk/Makefile.am @@ -2,13 +2,13 @@ INCLUDES = $(KOFFICE_INCLUDES) $(KOPAINTER_INCLUDES) $(all_includes) ## The common lib, shared between the part, the plugins, and the filters lib_LTLIBRARIES = libchalkcommon.la -libchalkcommon_la_SOURCES = dummy.cc +libchalkcommon_la_SOURCES = dummy.cpp libchalkcommon_la_LDFLAGS = $(all_libraries) $(LIB_TQT) -version-info 1:0 -no-undefined libchalkcommon_la_LIBADD = sdk/libchalksdk.la core/libchalkimage.la ui/libchalkui.la chalkcolor/libchalkcolor.la $(LCMS_LIBS) $(LIB_KOFFICEUI) $(LIB_KOPAINTER) $(LIB_KOPALETTE) $(LIB_XINPUTEXT) ## The part kde_module_LTLIBRARIES = libchalkpart.la -libchalkpart_la_SOURCES = chalk_part_init.cc +libchalkpart_la_SOURCES = chalk_part_init.cpp libchalkpart_la_LDFLAGS = $(all_libraries) $(LIB_TQT) -module $(KDE_PLUGIN) libchalkpart_la_LIBADD = $(KOFFICE_LIBS) libchalkcommon.la ../chalk/ui/libchalkui.la @@ -17,7 +17,7 @@ METASOURCES = AUTO ## The tdeinit loadable module and executable tdeinit_LTLIBRARIES = chalk.la bin_PROGRAMS = -chalk_la_SOURCES = main.cc +chalk_la_SOURCES = main.cpp chalk_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) $(LIB_TQT) chalk_la_LIBADD = $(LIB_KOFFICECORE) @@ -30,14 +30,14 @@ rc_DATA = chalk.rc chalk_readonly.rc SUBDIRS = sdk chalkcolor core ui . dtd colorspaces plugins data pics # Needed to compile libchalkcommon.la, which has no source files to itself # but everything in static libs. -dummy.cc: - echo > dummy.cc +dummy.cpp: + echo > dummy.cpp messages: rc.cpp $(EXTRACTRC) `find . -name \*.ui` >> rc.cpp $(EXTRACTRC) `find . -name \*.rc` >> rc.cpp perl extracti18n.pl > i18ndata - $(XGETTEXT) i18ndata rc.cpp `find . -name \*.cc -o -name \*.h -o -name \*.cpp` ui/kis_aboutdata.h -o $(podir)/chalk.pot + $(XGETTEXT) i18ndata rc.cpp `find . -name \*.cpp -o -name \*.h -o -name \*.cpp` ui/kis_aboutdata.h -o $(podir)/chalk.pot rm -f i18ndata DOXYGEN_EXCLUDE = CImg.h colorspaces plugins chalkcolor/colorspaces core/tiles diff --git a/chalk/chalk_part_init.cc b/chalk/chalk_part_init.cc deleted file mode 100644 index b56919749..000000000 --- a/chalk/chalk_part_init.cc +++ /dev/null @@ -1,23 +0,0 @@ -/* - * kis_part_init.cc - part of Krayon - * - * Copyright (c) 1999 Matthias Elter - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -#include "ui/kis_factory.h" - - -K_EXPORT_COMPONENT_FACTORY( libchalkpart, KisFactory ) diff --git a/chalk/chalk_part_init.cpp b/chalk/chalk_part_init.cpp new file mode 100644 index 000000000..1915112e4 --- /dev/null +++ b/chalk/chalk_part_init.cpp @@ -0,0 +1,23 @@ +/* + * kis_part_init.cpp - part of Krayon + * + * Copyright (c) 1999 Matthias Elter + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +#include "ui/kis_factory.h" + + +K_EXPORT_COMPONENT_FACTORY( libchalkpart, KisFactory ) diff --git a/chalk/chalkcolor/Makefile.am b/chalk/chalkcolor/Makefile.am index 1fee38366..d31ea1c52 100644 --- a/chalk/chalkcolor/Makefile.am +++ b/chalk/chalkcolor/Makefile.am @@ -11,14 +11,14 @@ CXXFLAGS += $(OPENEXR_CXXFLAGS) lib_LTLIBRARIES = libchalkcolor.la if have_openexr -OPENEXR_SOURCES=kis_f16half_base_colorspace.cc +OPENEXR_SOURCES=kis_f16half_base_colorspace.cpp endif -libchalkcolor_la_SOURCES = kis_color.cc kis_colorspace.cc \ - kis_colorspace_iface.cc kis_colorspace_iface.skel kis_composite_op.cc kis_profile.cc \ - kis_histogram_producer.cc kis_basic_histogram_producers.cc kis_abstract_colorspace.cc \ - kis_colorspace_factory_registry.cc kis_color_conversions.cc kis_u8_base_colorspace.cc \ - kis_u16_base_colorspace.cc kis_f32_base_colorspace.cc $(OPENEXR_SOURCES) +libchalkcolor_la_SOURCES = kis_color.cpp kis_colorspace.cpp \ + kis_colorspace_iface.cpp kis_colorspace_iface.skel kis_composite_op.cpp kis_profile.cpp \ + kis_histogram_producer.cpp kis_basic_histogram_producers.cpp kis_abstract_colorspace.cpp \ + kis_colorspace_factory_registry.cpp kis_color_conversions.cpp kis_u8_base_colorspace.cpp \ + kis_u16_base_colorspace.cpp kis_f32_base_colorspace.cpp $(OPENEXR_SOURCES) libchalkcolor_la_LDFLAGS = -version-info 1:0:0 -no-undefined $(all_libraries) libchalkcolor_la_LIBADD = colorspaces/libchalkcolorspaces.la $(LCMS_LIBS) $(LIB_TDEPARTS) $(LIB_TDECORE) $(LIB_TQT) $(OPENEXR_LIBS) diff --git a/chalk/chalkcolor/colorspaces/Makefile.am b/chalk/chalkcolor/colorspaces/Makefile.am index 90f75d290..18bd587b1 100644 --- a/chalk/chalkcolor/colorspaces/Makefile.am +++ b/chalk/chalkcolor/colorspaces/Makefile.am @@ -6,8 +6,8 @@ INCLUDES = -I$(srcdir)/.. \ noinst_LTLIBRARIES = libchalkcolorspaces.la libchalkcolorspaces_la_SOURCES = \ - kis_alpha_colorspace.cc \ - kis_lab_colorspace.cc + kis_alpha_colorspace.cpp \ + kis_lab_colorspace.cpp noinst_HEADERS = \ kis_alpha_colorspace.h \ diff --git a/chalk/chalkcolor/colorspaces/kis_alpha_colorspace.cc b/chalk/chalkcolor/colorspaces/kis_alpha_colorspace.cpp similarity index 100% rename from chalk/chalkcolor/colorspaces/kis_alpha_colorspace.cc rename to chalk/chalkcolor/colorspaces/kis_alpha_colorspace.cpp diff --git a/chalk/chalkcolor/colorspaces/kis_lab_colorspace.cc b/chalk/chalkcolor/colorspaces/kis_lab_colorspace.cpp similarity index 100% rename from chalk/chalkcolor/colorspaces/kis_lab_colorspace.cc rename to chalk/chalkcolor/colorspaces/kis_lab_colorspace.cpp diff --git a/chalk/chalkcolor/colorspaces/kis_xyz_colorspace.cc b/chalk/chalkcolor/colorspaces/kis_xyz_colorspace.cpp similarity index 100% rename from chalk/chalkcolor/colorspaces/kis_xyz_colorspace.cc rename to chalk/chalkcolor/colorspaces/kis_xyz_colorspace.cpp diff --git a/chalk/chalkcolor/kis_abstract_colorspace.cc b/chalk/chalkcolor/kis_abstract_colorspace.cpp similarity index 100% rename from chalk/chalkcolor/kis_abstract_colorspace.cc rename to chalk/chalkcolor/kis_abstract_colorspace.cpp diff --git a/chalk/chalkcolor/kis_basic_histogram_producers.cc b/chalk/chalkcolor/kis_basic_histogram_producers.cpp similarity index 100% rename from chalk/chalkcolor/kis_basic_histogram_producers.cc rename to chalk/chalkcolor/kis_basic_histogram_producers.cpp diff --git a/chalk/chalkcolor/kis_color.cc b/chalk/chalkcolor/kis_color.cpp similarity index 100% rename from chalk/chalkcolor/kis_color.cc rename to chalk/chalkcolor/kis_color.cpp diff --git a/chalk/chalkcolor/kis_color_conversions.cc b/chalk/chalkcolor/kis_color_conversions.cpp similarity index 100% rename from chalk/chalkcolor/kis_color_conversions.cc rename to chalk/chalkcolor/kis_color_conversions.cpp diff --git a/chalk/chalkcolor/kis_colorspace.cc b/chalk/chalkcolor/kis_colorspace.cpp similarity index 100% rename from chalk/chalkcolor/kis_colorspace.cc rename to chalk/chalkcolor/kis_colorspace.cpp diff --git a/chalk/chalkcolor/kis_colorspace_factory_registry.cc b/chalk/chalkcolor/kis_colorspace_factory_registry.cpp similarity index 100% rename from chalk/chalkcolor/kis_colorspace_factory_registry.cc rename to chalk/chalkcolor/kis_colorspace_factory_registry.cpp diff --git a/chalk/chalkcolor/kis_colorspace_iface.cc b/chalk/chalkcolor/kis_colorspace_iface.cpp similarity index 100% rename from chalk/chalkcolor/kis_colorspace_iface.cc rename to chalk/chalkcolor/kis_colorspace_iface.cpp diff --git a/chalk/chalkcolor/kis_composite_op.cc b/chalk/chalkcolor/kis_composite_op.cpp similarity index 100% rename from chalk/chalkcolor/kis_composite_op.cc rename to chalk/chalkcolor/kis_composite_op.cpp diff --git a/chalk/chalkcolor/kis_f16half_base_colorspace.cc b/chalk/chalkcolor/kis_f16half_base_colorspace.cpp similarity index 100% rename from chalk/chalkcolor/kis_f16half_base_colorspace.cc rename to chalk/chalkcolor/kis_f16half_base_colorspace.cpp diff --git a/chalk/chalkcolor/kis_f32_base_colorspace.cc b/chalk/chalkcolor/kis_f32_base_colorspace.cpp similarity index 100% rename from chalk/chalkcolor/kis_f32_base_colorspace.cc rename to chalk/chalkcolor/kis_f32_base_colorspace.cpp diff --git a/chalk/chalkcolor/kis_histogram_producer.cc b/chalk/chalkcolor/kis_histogram_producer.cpp similarity index 100% rename from chalk/chalkcolor/kis_histogram_producer.cc rename to chalk/chalkcolor/kis_histogram_producer.cpp diff --git a/chalk/chalkcolor/kis_profile.cc b/chalk/chalkcolor/kis_profile.cc deleted file mode 100644 index 61b2ad327..000000000 --- a/chalk/chalkcolor/kis_profile.cc +++ /dev/null @@ -1,208 +0,0 @@ -/* - * kis_profile.cc - part of Krayon - * - * Copyright (c) 2000 Matthias Elter - * 2001 John Califf - * 2004 Boudewijn Rempt - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -#include -#include -#include -#include LCMS_HEADER - -#include -#include -#include - -#include - -#include "kis_profile.h" -#include "kis_global.h" - -#include "ksharedptr.h" - -#include -#include -#include - -KisProfile::KisProfile(TQByteArray rawData) - : m_rawData(rawData), - m_filename( TQString() ), - m_valid( false ), - m_suitableForOutput(false) -{ - m_profile = cmsOpenProfileFromMem(rawData.data(), (DWORD)rawData.size()); - init(); -} - -KisProfile::KisProfile(const TQString& file) - : m_filename(file), - m_valid( false ), - m_suitableForOutput( false ) -{ -} - -KisProfile::KisProfile(const cmsHPROFILE profile) - : m_profile(profile), - m_filename( TQString() ), - m_valid( true ) -{ - size_t bytesNeeded=0; - - // Make a raw data image ready for saving - _cmsSaveProfileToMem(m_profile, 0, &bytesNeeded); // calc size - if(m_rawData.resize(bytesNeeded)) - { - _cmsSaveProfileToMem(m_profile, m_rawData.data(), &bytesNeeded); // fill buffer - cmsHPROFILE newprofile = cmsOpenProfileFromMem(m_rawData.data(), (DWORD) bytesNeeded); - cmsCloseProfile(m_profile); - m_profile = newprofile; - } - else - m_rawData.resize(0); - - init(); -} - -KisProfile::~KisProfile() -{ - cmsCloseProfile(m_profile); -} - - -bool KisProfile::load() -{ - TQFile file(m_filename); - file.open(IO_ReadOnly); - m_rawData = file.readAll(); - m_profile = cmsOpenProfileFromMem(m_rawData.data(), (DWORD)m_rawData.size()); - file.close(); - - if (m_profile == 0) { - kdWarning() << "Failed to load profile from " << m_filename << endl; - } - - return init(); - -} - -bool KisProfile::init() -{ - if (m_profile) { - m_colorSpaceSignature = cmsGetColorSpace(m_profile); - m_deviceClass = cmsGetDeviceClass(m_profile); - m_productName = cmsTakeProductName(m_profile); - m_productDescription = cmsTakeProductDesc(m_profile); - m_productInfo = cmsTakeProductInfo(m_profile); - m_valid = true; - - // Check if the profile can convert (something->this) -// LPMATSHAPER OutMatShaper = cmsBuildOutputMatrixShaper(m_profile); -// if( OutMatShaper ) -// { -// m_suitableForOutput = true; -// } - cmsCIEXYZTRIPLE Primaries; - - if (cmsTakeColorants(&Primaries, m_profile)) - { - m_suitableForOutput = true; - } - -#if 0 - // XXX: It wasn't that easy to save a little memory: thsi gives an lcms error - // Okay, we know enough. Free the memory; we'll load it again if needed. - - cmsCloseProfile(m_profile); - m_profile = 0; - -#endif - return true; - } - return false; -} - -cmsHPROFILE KisProfile::profile() -{ -#if 0 - if (m_profile = 0) { - TQFile file(m_filename); - file.open(IO_ReadOnly); - m_rawData = file.readAll(); - m_profile = cmsOpenProfileFromMem(m_rawData.data(), (DWORD)m_rawData.size()); - file.close(); - } -#endif - return m_profile; -} - -bool KisProfile::save() -{ - return false; -} - -KisAnnotationSP KisProfile::annotation() const -{ - // XXX we hardcode icc, this is correct for lcms? - // XXX productName(), or just "ICC Profile"? - if (!m_rawData.isEmpty()) - return new KisAnnotation("icc", productName(), m_rawData); - else - return 0; -} - -KisProfile * KisProfile::getScreenProfile (int screen) -{ - -#ifdef Q_WS_X11 - - Atom type; - int format; - unsigned long nitems; - unsigned long bytes_after; - TQ_UINT8 * str; - - static Atom icc_atom = XInternAtom( tqt_xdisplay(), "_ICC_PROFILE", False ); - - if ( XGetWindowProperty ( tqt_xdisplay(), - tqt_xrootwin( screen ), - icc_atom, - 0, - INT_MAX, - False, - XA_CARDINAL, - &type, - &format, - &nitems, - &bytes_after, - (unsigned char **) &str) - ) { - - TQByteArray bytes (nitems); - bytes.assign((char*)str, (TQ_UINT32)nitems); - - return new KisProfile(bytes); - } else { - return NULL; - } -#else - return NULL; - -#endif -} - - diff --git a/chalk/chalkcolor/kis_profile.cpp b/chalk/chalkcolor/kis_profile.cpp new file mode 100644 index 000000000..df98a7506 --- /dev/null +++ b/chalk/chalkcolor/kis_profile.cpp @@ -0,0 +1,208 @@ +/* + * kis_profile.cpp - part of Krayon + * + * Copyright (c) 2000 Matthias Elter + * 2001 John Califf + * 2004 Boudewijn Rempt + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +#include +#include +#include +#include LCMS_HEADER + +#include +#include +#include + +#include + +#include "kis_profile.h" +#include "kis_global.h" + +#include "ksharedptr.h" + +#include +#include +#include + +KisProfile::KisProfile(TQByteArray rawData) + : m_rawData(rawData), + m_filename( TQString() ), + m_valid( false ), + m_suitableForOutput(false) +{ + m_profile = cmsOpenProfileFromMem(rawData.data(), (DWORD)rawData.size()); + init(); +} + +KisProfile::KisProfile(const TQString& file) + : m_filename(file), + m_valid( false ), + m_suitableForOutput( false ) +{ +} + +KisProfile::KisProfile(const cmsHPROFILE profile) + : m_profile(profile), + m_filename( TQString() ), + m_valid( true ) +{ + size_t bytesNeeded=0; + + // Make a raw data image ready for saving + _cmsSaveProfileToMem(m_profile, 0, &bytesNeeded); // calc size + if(m_rawData.resize(bytesNeeded)) + { + _cmsSaveProfileToMem(m_profile, m_rawData.data(), &bytesNeeded); // fill buffer + cmsHPROFILE newprofile = cmsOpenProfileFromMem(m_rawData.data(), (DWORD) bytesNeeded); + cmsCloseProfile(m_profile); + m_profile = newprofile; + } + else + m_rawData.resize(0); + + init(); +} + +KisProfile::~KisProfile() +{ + cmsCloseProfile(m_profile); +} + + +bool KisProfile::load() +{ + TQFile file(m_filename); + file.open(IO_ReadOnly); + m_rawData = file.readAll(); + m_profile = cmsOpenProfileFromMem(m_rawData.data(), (DWORD)m_rawData.size()); + file.close(); + + if (m_profile == 0) { + kdWarning() << "Failed to load profile from " << m_filename << endl; + } + + return init(); + +} + +bool KisProfile::init() +{ + if (m_profile) { + m_colorSpaceSignature = cmsGetColorSpace(m_profile); + m_deviceClass = cmsGetDeviceClass(m_profile); + m_productName = cmsTakeProductName(m_profile); + m_productDescription = cmsTakeProductDesc(m_profile); + m_productInfo = cmsTakeProductInfo(m_profile); + m_valid = true; + + // Check if the profile can convert (something->this) +// LPMATSHAPER OutMatShaper = cmsBuildOutputMatrixShaper(m_profile); +// if( OutMatShaper ) +// { +// m_suitableForOutput = true; +// } + cmsCIEXYZTRIPLE Primaries; + + if (cmsTakeColorants(&Primaries, m_profile)) + { + m_suitableForOutput = true; + } + +#if 0 + // XXX: It wasn't that easy to save a little memory: thsi gives an lcms error + // Okay, we know enough. Free the memory; we'll load it again if needed. + + cmsCloseProfile(m_profile); + m_profile = 0; + +#endif + return true; + } + return false; +} + +cmsHPROFILE KisProfile::profile() +{ +#if 0 + if (m_profile = 0) { + TQFile file(m_filename); + file.open(IO_ReadOnly); + m_rawData = file.readAll(); + m_profile = cmsOpenProfileFromMem(m_rawData.data(), (DWORD)m_rawData.size()); + file.close(); + } +#endif + return m_profile; +} + +bool KisProfile::save() +{ + return false; +} + +KisAnnotationSP KisProfile::annotation() const +{ + // XXX we hardcode icc, this is correct for lcms? + // XXX productName(), or just "ICC Profile"? + if (!m_rawData.isEmpty()) + return new KisAnnotation("icc", productName(), m_rawData); + else + return 0; +} + +KisProfile * KisProfile::getScreenProfile (int screen) +{ + +#ifdef Q_WS_X11 + + Atom type; + int format; + unsigned long nitems; + unsigned long bytes_after; + TQ_UINT8 * str; + + static Atom icc_atom = XInternAtom( tqt_xdisplay(), "_ICC_PROFILE", False ); + + if ( XGetWindowProperty ( tqt_xdisplay(), + tqt_xrootwin( screen ), + icc_atom, + 0, + INT_MAX, + False, + XA_CARDINAL, + &type, + &format, + &nitems, + &bytes_after, + (unsigned char **) &str) + ) { + + TQByteArray bytes (nitems); + bytes.assign((char*)str, (TQ_UINT32)nitems); + + return new KisProfile(bytes); + } else { + return NULL; + } +#else + return NULL; + +#endif +} + + diff --git a/chalk/chalkcolor/kis_u16_base_colorspace.cc b/chalk/chalkcolor/kis_u16_base_colorspace.cpp similarity index 100% rename from chalk/chalkcolor/kis_u16_base_colorspace.cc rename to chalk/chalkcolor/kis_u16_base_colorspace.cpp diff --git a/chalk/chalkcolor/kis_u8_base_colorspace.cc b/chalk/chalkcolor/kis_u8_base_colorspace.cpp similarity index 100% rename from chalk/chalkcolor/kis_u8_base_colorspace.cc rename to chalk/chalkcolor/kis_u8_base_colorspace.cpp diff --git a/chalk/colorspaces/cmyk_u16/Makefile.am b/chalk/colorspaces/cmyk_u16/Makefile.am index 00cdd32d1..7f5ec9ca6 100644 --- a/chalk/colorspaces/cmyk_u16/Makefile.am +++ b/chalk/colorspaces/cmyk_u16/Makefile.am @@ -7,7 +7,7 @@ INCLUDES = -I$(srcdir)/../../sdk \ $(all_includes) lib_LTLIBRARIES = libchalk_cmyk_u16.la -libchalk_cmyk_u16_la_SOURCES = kis_cmyk_u16_colorspace.cc +libchalk_cmyk_u16_la_SOURCES = kis_cmyk_u16_colorspace.cpp libchalk_cmyk_u16_la_LDFLAGS = $(all_libraries) libchalk_cmyk_u16_la_LIBADD = ../../chalkcolor/libchalkcolor.la @@ -15,7 +15,7 @@ libchalk_cmyk_u16_la_LIBADD = ../../chalkcolor/libchalkcolor.la kde_module_LTLIBRARIES = chalk_cmyk_u16_plugin.la # Srcs for the plugin -chalk_cmyk_u16_plugin_la_SOURCES = cmyk_u16_plugin.cc +chalk_cmyk_u16_plugin_la_SOURCES = cmyk_u16_plugin.cpp noinst_HEADERS = cmyk_u16_plugin.h kis_cmyk_u16_colorspace.h chalk_cmyk_u16_plugin_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) $(LIB_TQT) -ltdecore -ltdeui -lkjs -ltdefx -ltdeio -ltdeparts -llcms diff --git a/chalk/colorspaces/cmyk_u16/cmyk_u16_plugin.cc b/chalk/colorspaces/cmyk_u16/cmyk_u16_plugin.cc deleted file mode 100644 index 4b3afa299..000000000 --- a/chalk/colorspaces/cmyk_u16/cmyk_u16_plugin.cc +++ /dev/null @@ -1,61 +0,0 @@ -/* -* cmyk_u16_plugin.cc -- Part of Chalk -* -* Copyright (c) 2004 Boudewijn Rempt (boud@valdyas.org) -* Copyright (c) 2005 Adrian Page -* -* 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 of the License, 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. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -*/ - -#include -#include -#include - -#include -#include -#include -#include -#include "cmyk_u16_plugin.h" -#include "kis_cmyk_u16_colorspace.h" - -typedef KGenericFactory CMYKU16PluginFactory; -K_EXPORT_COMPONENT_FACTORY( chalk_cmyk_u16_plugin, CMYKU16PluginFactory( "chalk" ) ) - - -CMYKU16Plugin::CMYKU16Plugin(TQObject *parent, const char *name, const TQStringList &) - : KParts::Plugin(parent, name) -{ - setInstance(CMYKU16PluginFactory::instance()); - - if ( parent->inherits("KisColorSpaceFactoryRegistry") ) - { - KisColorSpaceFactoryRegistry * f = dynamic_cast( parent ); - - KisColorSpace * colorSpaceCMYKU16 = new KisCmykU16ColorSpace(f, 0); - KisColorSpaceFactory * csf = new KisCmykU16ColorSpaceFactory(); - TQ_CHECK_PTR(colorSpaceCMYKU16); - f->add(csf); - KisHistogramProducerFactoryRegistry::instance()->add( - new KisBasicHistogramProducerFactory - (KisID("CMYK16HISTO", i18n("CMYK16")), colorSpaceCMYKU16) ); - } - -} - -CMYKU16Plugin::~CMYKU16Plugin() -{ -} - -#include "cmyk_u16_plugin.moc" diff --git a/chalk/colorspaces/cmyk_u16/cmyk_u16_plugin.cpp b/chalk/colorspaces/cmyk_u16/cmyk_u16_plugin.cpp new file mode 100644 index 000000000..4195ff225 --- /dev/null +++ b/chalk/colorspaces/cmyk_u16/cmyk_u16_plugin.cpp @@ -0,0 +1,61 @@ +/* +* cmyk_u16_plugin.cpp -- Part of Chalk +* +* Copyright (c) 2004 Boudewijn Rempt (boud@valdyas.org) +* Copyright (c) 2005 Adrian Page +* +* 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 of the License, 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. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include +#include +#include + +#include +#include +#include +#include +#include "cmyk_u16_plugin.h" +#include "kis_cmyk_u16_colorspace.h" + +typedef KGenericFactory CMYKU16PluginFactory; +K_EXPORT_COMPONENT_FACTORY( chalk_cmyk_u16_plugin, CMYKU16PluginFactory( "chalk" ) ) + + +CMYKU16Plugin::CMYKU16Plugin(TQObject *parent, const char *name, const TQStringList &) + : KParts::Plugin(parent, name) +{ + setInstance(CMYKU16PluginFactory::instance()); + + if ( parent->inherits("KisColorSpaceFactoryRegistry") ) + { + KisColorSpaceFactoryRegistry * f = dynamic_cast( parent ); + + KisColorSpace * colorSpaceCMYKU16 = new KisCmykU16ColorSpace(f, 0); + KisColorSpaceFactory * csf = new KisCmykU16ColorSpaceFactory(); + TQ_CHECK_PTR(colorSpaceCMYKU16); + f->add(csf); + KisHistogramProducerFactoryRegistry::instance()->add( + new KisBasicHistogramProducerFactory + (KisID("CMYK16HISTO", i18n("CMYK16")), colorSpaceCMYKU16) ); + } + +} + +CMYKU16Plugin::~CMYKU16Plugin() +{ +} + +#include "cmyk_u16_plugin.moc" diff --git a/chalk/colorspaces/cmyk_u16/kis_cmyk_u16_colorspace.cc b/chalk/colorspaces/cmyk_u16/kis_cmyk_u16_colorspace.cpp similarity index 100% rename from chalk/colorspaces/cmyk_u16/kis_cmyk_u16_colorspace.cc rename to chalk/colorspaces/cmyk_u16/kis_cmyk_u16_colorspace.cpp diff --git a/chalk/colorspaces/cmyk_u8/Makefile.am b/chalk/colorspaces/cmyk_u8/Makefile.am index 90ab3869f..97554d249 100644 --- a/chalk/colorspaces/cmyk_u8/Makefile.am +++ b/chalk/colorspaces/cmyk_u8/Makefile.am @@ -8,7 +8,7 @@ INCLUDES = -I$(srcdir)/../../sdk \ kde_module_LTLIBRARIES = chalkcmykplugin.la -chalkcmykplugin_la_SOURCES = cmyk_plugin.cc kis_cmyk_colorspace.cc +chalkcmykplugin_la_SOURCES = cmyk_plugin.cpp kis_cmyk_colorspace.cpp noinst_HEADERS = cmyk_plugin.h kis_cmyk_colorspace.h chalkcmykplugin_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) $(LIB_TQT) -ltdecore -ltdeui -lkjs -ltdefx -ltdeio -ltdeparts -llcms diff --git a/chalk/colorspaces/cmyk_u8/cmyk_plugin.cc b/chalk/colorspaces/cmyk_u8/cmyk_plugin.cc deleted file mode 100644 index 7b09ecca9..000000000 --- a/chalk/colorspaces/cmyk_u8/cmyk_plugin.cc +++ /dev/null @@ -1,66 +0,0 @@ -/* - * cmyk_plugin.cc -- Part of Chalk - * - * Copyright (c) 2004 Boudewijn Rempt (boud@valdyas.org) - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include "cmyk_plugin.h" - -#include "kis_cmyk_colorspace.h" - -typedef KGenericFactory CMYKPluginFactory; -K_EXPORT_COMPONENT_FACTORY( chalkcmykplugin, CMYKPluginFactory( "chalk" ) ) - - -CMYKPlugin::CMYKPlugin(TQObject *parent, const char *name, const TQStringList &) - : KParts::Plugin(parent, name) -{ - setInstance(CMYKPluginFactory::instance()); - if ( parent->inherits("KisColorSpaceFactoryRegistry") ) - { - KisColorSpaceFactoryRegistry * f = dynamic_cast( parent ); - - KisColorSpace * colorSpaceCMYK = new KisCmykColorSpace(f, 0); - KisColorSpaceFactory * csf = new KisCmykColorSpaceFactory(); - TQ_CHECK_PTR(colorSpaceCMYK); - f->add(csf); - - KisHistogramProducerFactoryRegistry::instance()->add( - new KisBasicHistogramProducerFactory - (KisID("CMYKHISTO", i18n("CMYK")), colorSpaceCMYK) ); - } - -} - -CMYKPlugin::~CMYKPlugin() -{ -} - -#include "cmyk_plugin.moc" diff --git a/chalk/colorspaces/cmyk_u8/cmyk_plugin.cpp b/chalk/colorspaces/cmyk_u8/cmyk_plugin.cpp new file mode 100644 index 000000000..588e286cd --- /dev/null +++ b/chalk/colorspaces/cmyk_u8/cmyk_plugin.cpp @@ -0,0 +1,66 @@ +/* + * cmyk_plugin.cpp -- Part of Chalk + * + * Copyright (c) 2004 Boudewijn Rempt (boud@valdyas.org) + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "cmyk_plugin.h" + +#include "kis_cmyk_colorspace.h" + +typedef KGenericFactory CMYKPluginFactory; +K_EXPORT_COMPONENT_FACTORY( chalkcmykplugin, CMYKPluginFactory( "chalk" ) ) + + +CMYKPlugin::CMYKPlugin(TQObject *parent, const char *name, const TQStringList &) + : KParts::Plugin(parent, name) +{ + setInstance(CMYKPluginFactory::instance()); + if ( parent->inherits("KisColorSpaceFactoryRegistry") ) + { + KisColorSpaceFactoryRegistry * f = dynamic_cast( parent ); + + KisColorSpace * colorSpaceCMYK = new KisCmykColorSpace(f, 0); + KisColorSpaceFactory * csf = new KisCmykColorSpaceFactory(); + TQ_CHECK_PTR(colorSpaceCMYK); + f->add(csf); + + KisHistogramProducerFactoryRegistry::instance()->add( + new KisBasicHistogramProducerFactory + (KisID("CMYKHISTO", i18n("CMYK")), colorSpaceCMYK) ); + } + +} + +CMYKPlugin::~CMYKPlugin() +{ +} + +#include "cmyk_plugin.moc" diff --git a/chalk/colorspaces/cmyk_u8/kis_cmyk_colorspace.cc b/chalk/colorspaces/cmyk_u8/kis_cmyk_colorspace.cpp similarity index 100% rename from chalk/colorspaces/cmyk_u8/kis_cmyk_colorspace.cc rename to chalk/colorspaces/cmyk_u8/kis_cmyk_colorspace.cpp diff --git a/chalk/colorspaces/gray_u16/Makefile.am b/chalk/colorspaces/gray_u16/Makefile.am index 8ee4314cd..d77d32d2a 100644 --- a/chalk/colorspaces/gray_u16/Makefile.am +++ b/chalk/colorspaces/gray_u16/Makefile.am @@ -8,7 +8,7 @@ INCLUDES = -I$(srcdir)/../../sdk \ $(all_includes) lib_LTLIBRARIES = libchalk_gray_u16.la -libchalk_gray_u16_la_SOURCES = kis_gray_u16_colorspace.cc +libchalk_gray_u16_la_SOURCES = kis_gray_u16_colorspace.cpp libchalk_gray_u16_la_LDFLAGS = $(all_libraries) libchalk_gray_u16_la_LIBADD = ../../chalkcolor/libchalkcolor.la @@ -16,7 +16,7 @@ libchalk_gray_u16_la_LIBADD = ../../chalkcolor/libchalkcolor.la kde_module_LTLIBRARIES = chalk_gray_u16_plugin.la # Srcs for the plugin -chalk_gray_u16_plugin_la_SOURCES = gray_u16_plugin.cc +chalk_gray_u16_plugin_la_SOURCES = gray_u16_plugin.cpp noinst_HEADERS = gray_u16_plugin.h kis_gray_u16_colorspace.h chalk_gray_u16_plugin_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) $(LIB_TQT) -ltdecore -ltdeui -lkjs -ltdefx -ltdeio -ltdeparts -llcms diff --git a/chalk/colorspaces/gray_u16/gray_u16_plugin.cc b/chalk/colorspaces/gray_u16/gray_u16_plugin.cc deleted file mode 100644 index 5e9e17f93..000000000 --- a/chalk/colorspaces/gray_u16/gray_u16_plugin.cc +++ /dev/null @@ -1,63 +0,0 @@ -/* -* gray_u16_plugin.cc -- Part of Chalk -* -* Copyright (c) 2004 Boudewijn Rempt (boud@valdyas.org) -* Copyright (c) 2005 Adrian Page -* -* This program is free software; you can grayistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, 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. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -*/ - -#include -#include -#include - -#include - -#include -#include - -#include "gray_u16_plugin.h" -#include "kis_gray_u16_colorspace.h" - -typedef KGenericFactory GRAYU16PluginFactory; -K_EXPORT_COMPONENT_FACTORY( chalk_gray_u16_plugin, GRAYU16PluginFactory( "chalk" ) ) - - -GRAYU16Plugin::GRAYU16Plugin(TQObject *parent, const char *name, const TQStringList &) - : KParts::Plugin(parent, name) -{ - setInstance(GRAYU16PluginFactory::instance()); - - if ( parent->inherits("KisColorSpaceFactoryRegistry") ) - { - KisColorSpaceFactoryRegistry * f = dynamic_cast( parent ); - - KisColorSpace * colorSpaceGRAYU16 = new KisGrayU16ColorSpace(f, 0); - KisColorSpaceFactory * csf = new KisGrayU16ColorSpaceFactory(); - TQ_CHECK_PTR(colorSpaceGRAYU16); - f->add(csf); - - KisHistogramProducerFactoryRegistry::instance()->add( - new KisBasicHistogramProducerFactory - (KisID("GRAYA16HISTO", i18n("GRAY/Alpha16")), colorSpaceGRAYU16) ); - } - -} - -GRAYU16Plugin::~GRAYU16Plugin() -{ -} - -#include "gray_u16_plugin.moc" diff --git a/chalk/colorspaces/gray_u16/gray_u16_plugin.cpp b/chalk/colorspaces/gray_u16/gray_u16_plugin.cpp new file mode 100644 index 000000000..7c1896f94 --- /dev/null +++ b/chalk/colorspaces/gray_u16/gray_u16_plugin.cpp @@ -0,0 +1,63 @@ +/* +* gray_u16_plugin.cpp -- Part of Chalk +* +* Copyright (c) 2004 Boudewijn Rempt (boud@valdyas.org) +* Copyright (c) 2005 Adrian Page +* +* This program is free software; you can grayistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, 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. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include +#include +#include + +#include + +#include +#include + +#include "gray_u16_plugin.h" +#include "kis_gray_u16_colorspace.h" + +typedef KGenericFactory GRAYU16PluginFactory; +K_EXPORT_COMPONENT_FACTORY( chalk_gray_u16_plugin, GRAYU16PluginFactory( "chalk" ) ) + + +GRAYU16Plugin::GRAYU16Plugin(TQObject *parent, const char *name, const TQStringList &) + : KParts::Plugin(parent, name) +{ + setInstance(GRAYU16PluginFactory::instance()); + + if ( parent->inherits("KisColorSpaceFactoryRegistry") ) + { + KisColorSpaceFactoryRegistry * f = dynamic_cast( parent ); + + KisColorSpace * colorSpaceGRAYU16 = new KisGrayU16ColorSpace(f, 0); + KisColorSpaceFactory * csf = new KisGrayU16ColorSpaceFactory(); + TQ_CHECK_PTR(colorSpaceGRAYU16); + f->add(csf); + + KisHistogramProducerFactoryRegistry::instance()->add( + new KisBasicHistogramProducerFactory + (KisID("GRAYA16HISTO", i18n("GRAY/Alpha16")), colorSpaceGRAYU16) ); + } + +} + +GRAYU16Plugin::~GRAYU16Plugin() +{ +} + +#include "gray_u16_plugin.moc" diff --git a/chalk/colorspaces/gray_u16/kis_gray_u16_colorspace.cc b/chalk/colorspaces/gray_u16/kis_gray_u16_colorspace.cpp similarity index 100% rename from chalk/colorspaces/gray_u16/kis_gray_u16_colorspace.cc rename to chalk/colorspaces/gray_u16/kis_gray_u16_colorspace.cpp diff --git a/chalk/colorspaces/gray_u8/Makefile.am b/chalk/colorspaces/gray_u8/Makefile.am index fda7f56a3..1282ef00f 100644 --- a/chalk/colorspaces/gray_u8/Makefile.am +++ b/chalk/colorspaces/gray_u8/Makefile.am @@ -9,13 +9,13 @@ INCLUDES = -I$(srcdir)/../../sdk \ lib_LTLIBRARIES = libchalkgrayscale.la -libchalkgrayscale_la_SOURCES = kis_gray_colorspace.cc +libchalkgrayscale_la_SOURCES = kis_gray_colorspace.cpp libchalkgrayscale_la_LDFLAGS = $(all_libraries) libchalkgrayscale_la_LIBADD = ../../chalkcolor/libchalkcolor.la kde_module_LTLIBRARIES = chalkgrayplugin.la -chalkgrayplugin_la_SOURCES = gray_plugin.cc +chalkgrayplugin_la_SOURCES = gray_plugin.cpp noinst_HEADERS = gray_plugin.h kis_gray_colorspace.h chalkgrayplugin_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) $(LIB_TQT) -ltdecore -ltdeui -lkjs -ltdefx -ltdeio -ltdeparts -llcms diff --git a/chalk/colorspaces/gray_u8/gray_plugin.cc b/chalk/colorspaces/gray_u8/gray_plugin.cc deleted file mode 100644 index 7d03d5f63..000000000 --- a/chalk/colorspaces/gray_u8/gray_plugin.cc +++ /dev/null @@ -1,77 +0,0 @@ -/* - * gray_plugin.cc -- Part of Chalk - * - * Copyright (c) 2004 Boudewijn Rempt (boud@valdyas.org) - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include "gray_plugin.h" -#include "kis_gray_colorspace.h" - -typedef KGenericFactory GrayPluginFactory; -K_EXPORT_COMPONENT_FACTORY( chalkgrayplugin, GrayPluginFactory( "chalkcore" ) ) - - -GrayPlugin::GrayPlugin(TQObject *parent, const char *name, const TQStringList &) - : KParts::Plugin(parent, name) -{ - setInstance(GrayPluginFactory::instance()); - - // This is not a gui plugin; only load it when the doc is created. - if ( parent->inherits("KisColorSpaceFactoryRegistry") ) - { - - KisColorSpaceFactoryRegistry * f = dynamic_cast( parent ); - - // .22 gamma grayscale or something like that. Taken from the lcms tutorial... - LPGAMMATABLE Gamma = cmsBuildGamma(256, 2.2); - cmsHPROFILE hProfile = cmsCreateGrayProfile(cmsD50_xyY(), Gamma); - cmsFreeGamma(Gamma); - KisProfile *defProfile = new KisProfile(hProfile); - - f->addProfile(defProfile); - - KisColorSpace * colorSpaceGrayA = new KisGrayColorSpace(f, 0); - - KisColorSpaceFactory * csf = new KisGrayColorSpaceFactory(); - TQ_CHECK_PTR(colorSpaceGrayA); - - f->add(csf); - - KisHistogramProducerFactoryRegistry::instance()->add( - new KisBasicHistogramProducerFactory - (KisID("GRAYA8HISTO", i18n("GRAY/Alpha8")), colorSpaceGrayA) ); - } - -} - -GrayPlugin::~GrayPlugin() -{ -} - -#include "gray_plugin.moc" diff --git a/chalk/colorspaces/gray_u8/gray_plugin.cpp b/chalk/colorspaces/gray_u8/gray_plugin.cpp new file mode 100644 index 000000000..7f177eea1 --- /dev/null +++ b/chalk/colorspaces/gray_u8/gray_plugin.cpp @@ -0,0 +1,77 @@ +/* + * gray_plugin.cpp -- Part of Chalk + * + * Copyright (c) 2004 Boudewijn Rempt (boud@valdyas.org) + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "gray_plugin.h" +#include "kis_gray_colorspace.h" + +typedef KGenericFactory GrayPluginFactory; +K_EXPORT_COMPONENT_FACTORY( chalkgrayplugin, GrayPluginFactory( "chalkcore" ) ) + + +GrayPlugin::GrayPlugin(TQObject *parent, const char *name, const TQStringList &) + : KParts::Plugin(parent, name) +{ + setInstance(GrayPluginFactory::instance()); + + // This is not a gui plugin; only load it when the doc is created. + if ( parent->inherits("KisColorSpaceFactoryRegistry") ) + { + + KisColorSpaceFactoryRegistry * f = dynamic_cast( parent ); + + // .22 gamma grayscale or something like that. Taken from the lcms tutorial... + LPGAMMATABLE Gamma = cmsBuildGamma(256, 2.2); + cmsHPROFILE hProfile = cmsCreateGrayProfile(cmsD50_xyY(), Gamma); + cmsFreeGamma(Gamma); + KisProfile *defProfile = new KisProfile(hProfile); + + f->addProfile(defProfile); + + KisColorSpace * colorSpaceGrayA = new KisGrayColorSpace(f, 0); + + KisColorSpaceFactory * csf = new KisGrayColorSpaceFactory(); + TQ_CHECK_PTR(colorSpaceGrayA); + + f->add(csf); + + KisHistogramProducerFactoryRegistry::instance()->add( + new KisBasicHistogramProducerFactory + (KisID("GRAYA8HISTO", i18n("GRAY/Alpha8")), colorSpaceGrayA) ); + } + +} + +GrayPlugin::~GrayPlugin() +{ +} + +#include "gray_plugin.moc" diff --git a/chalk/colorspaces/gray_u8/kis_gray_colorspace.cc b/chalk/colorspaces/gray_u8/kis_gray_colorspace.cpp similarity index 100% rename from chalk/colorspaces/gray_u8/kis_gray_colorspace.cc rename to chalk/colorspaces/gray_u8/kis_gray_colorspace.cpp diff --git a/chalk/colorspaces/lms_f32/Makefile.am b/chalk/colorspaces/lms_f32/Makefile.am index bf8c65ecc..b7eedf99a 100644 --- a/chalk/colorspaces/lms_f32/Makefile.am +++ b/chalk/colorspaces/lms_f32/Makefile.am @@ -10,7 +10,7 @@ INCLUDES = \ lib_LTLIBRARIES = libchalk_lms_f32.la -libchalk_lms_f32_la_SOURCES = kis_lms_f32_colorspace.cc +libchalk_lms_f32_la_SOURCES = kis_lms_f32_colorspace.cpp libchalk_lms_f32_la_LDFLAGS = $(all_libraries) libchalk_lms_f32_la_LIBADD = ../../chalkcolor/libchalkcolor.la @@ -18,7 +18,7 @@ libchalk_lms_f32_la_LIBADD = ../../chalkcolor/libchalkcolor.la kde_module_LTLIBRARIES = chalk_lms_f32_plugin.la # Srcs for the plugin -chalk_lms_f32_plugin_la_SOURCES = lms_f32_plugin.cc +chalk_lms_f32_plugin_la_SOURCES = lms_f32_plugin.cpp noinst_HEADERS = lms_f32_plugin.h kis_lms_f32_colorspace.h chalk_lms_f32_plugin_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) $(LIB_TQT) -ltdecore -ltdeui -lkjs -ltdefx -ltdeio -ltdeparts -llcms diff --git a/chalk/colorspaces/lms_f32/kis_lms_f32_colorspace.cc b/chalk/colorspaces/lms_f32/kis_lms_f32_colorspace.cpp similarity index 100% rename from chalk/colorspaces/lms_f32/kis_lms_f32_colorspace.cc rename to chalk/colorspaces/lms_f32/kis_lms_f32_colorspace.cpp diff --git a/chalk/colorspaces/lms_f32/lms_f32_plugin.cc b/chalk/colorspaces/lms_f32/lms_f32_plugin.cc deleted file mode 100644 index f7e581ace..000000000 --- a/chalk/colorspaces/lms_f32/lms_f32_plugin.cc +++ /dev/null @@ -1,64 +0,0 @@ -/* -* lms_f32_plugin.cc -- Part of Chalk -* -* Copyright (c) 2004 Boudewijn Rempt (boud@valdyas.org) -* Copyright (c) 2005 Adrian Page -* Copyright (c) 2005 Cyrille Berger -* -* 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 of the License, 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. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. -*/ - -#include -#include -#include - -#include -#include -#include - -#include "lms_f32_plugin.h" -#include "kis_lms_f32_colorspace.h" - -typedef KGenericFactory LMSF32PluginFactory; -K_EXPORT_COMPONENT_FACTORY( chalk_lms_f32_plugin, LMSF32PluginFactory( "chalk" ) ) - - -LMSF32Plugin::LMSF32Plugin(TQObject *parent, const char *name, const TQStringList &) - : KParts::Plugin(parent, name) -{ - setInstance(LMSF32PluginFactory::instance()); - - if ( parent->inherits("KisColorSpaceFactoryRegistry") ) - { - KisColorSpaceFactoryRegistry * f = dynamic_cast(parent); - - KisColorSpace * colorSpaceLMSF32 = new KisLmsF32ColorSpace(f, 0); - - KisColorSpaceFactory * csf = new KisLmsF32ColorSpaceFactory(); - f->add(csf); - - KisHistogramProducerFactoryRegistry::instance()->add( - new KisBasicHistogramProducerFactory - (KisID("LMSF32HISTO", i18n("Float32")), colorSpaceLMSF32) ); - } - -} - -LMSF32Plugin::~LMSF32Plugin() -{ -} - -#include "lms_f32_plugin.moc" diff --git a/chalk/colorspaces/lms_f32/lms_f32_plugin.cpp b/chalk/colorspaces/lms_f32/lms_f32_plugin.cpp new file mode 100644 index 000000000..2c83ccd6c --- /dev/null +++ b/chalk/colorspaces/lms_f32/lms_f32_plugin.cpp @@ -0,0 +1,64 @@ +/* +* lms_f32_plugin.cpp -- Part of Chalk +* +* Copyright (c) 2004 Boudewijn Rempt (boud@valdyas.org) +* Copyright (c) 2005 Adrian Page +* Copyright (c) 2005 Cyrille Berger +* +* 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 of the License, 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. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +#include +#include +#include + +#include +#include +#include + +#include "lms_f32_plugin.h" +#include "kis_lms_f32_colorspace.h" + +typedef KGenericFactory LMSF32PluginFactory; +K_EXPORT_COMPONENT_FACTORY( chalk_lms_f32_plugin, LMSF32PluginFactory( "chalk" ) ) + + +LMSF32Plugin::LMSF32Plugin(TQObject *parent, const char *name, const TQStringList &) + : KParts::Plugin(parent, name) +{ + setInstance(LMSF32PluginFactory::instance()); + + if ( parent->inherits("KisColorSpaceFactoryRegistry") ) + { + KisColorSpaceFactoryRegistry * f = dynamic_cast(parent); + + KisColorSpace * colorSpaceLMSF32 = new KisLmsF32ColorSpace(f, 0); + + KisColorSpaceFactory * csf = new KisLmsF32ColorSpaceFactory(); + f->add(csf); + + KisHistogramProducerFactoryRegistry::instance()->add( + new KisBasicHistogramProducerFactory + (KisID("LMSF32HISTO", i18n("Float32")), colorSpaceLMSF32) ); + } + +} + +LMSF32Plugin::~LMSF32Plugin() +{ +} + +#include "lms_f32_plugin.moc" diff --git a/chalk/colorspaces/rgb_f16half/Makefile.am b/chalk/colorspaces/rgb_f16half/Makefile.am index 52f0c5836..cea86b4ca 100644 --- a/chalk/colorspaces/rgb_f16half/Makefile.am +++ b/chalk/colorspaces/rgb_f16half/Makefile.am @@ -13,7 +13,7 @@ CXXFLAGS += $(OPENEXR_CXXFLAGS) lib_LTLIBRARIES = libchalk_rgb_f16half.la -libchalk_rgb_f16half_la_SOURCES = kis_rgb_f16half_colorspace.cc +libchalk_rgb_f16half_la_SOURCES = kis_rgb_f16half_colorspace.cpp libchalk_rgb_f16half_la_LDFLAGS = $(all_libraries) libchalk_rgb_f16half_la_LIBADD = ../../chalkcolor/libchalkcolor.la @@ -21,7 +21,7 @@ libchalk_rgb_f16half_la_LIBADD = ../../chalkcolor/libchalkcolor.la kde_module_LTLIBRARIES = chalk_rgb_f16half_plugin.la # Srcs for the plugin -chalk_rgb_f16half_plugin_la_SOURCES = rgb_f16half_plugin.cc +chalk_rgb_f16half_plugin_la_SOURCES = rgb_f16half_plugin.cpp noinst_HEADERS = rgb_f16half_plugin.h kis_rgb_f16half_colorspace.h chalk_rgb_f16half_plugin_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) $(LIB_TQT) -ltdecore -ltdeui -lkjs -ltdefx -ltdeio -ltdeparts -llcms diff --git a/chalk/colorspaces/rgb_f16half/kis_rgb_f16half_colorspace.cc b/chalk/colorspaces/rgb_f16half/kis_rgb_f16half_colorspace.cpp similarity index 100% rename from chalk/colorspaces/rgb_f16half/kis_rgb_f16half_colorspace.cc rename to chalk/colorspaces/rgb_f16half/kis_rgb_f16half_colorspace.cpp diff --git a/chalk/colorspaces/rgb_f16half/rgb_f16half_plugin.cc b/chalk/colorspaces/rgb_f16half/rgb_f16half_plugin.cc deleted file mode 100644 index 911da6a0b..000000000 --- a/chalk/colorspaces/rgb_f16half/rgb_f16half_plugin.cc +++ /dev/null @@ -1,63 +0,0 @@ -/* -* rgb_f32_plugin.cc -- Part of Chalk -* -* Copyright (c) 2004 Boudewijn Rempt (boud@valdyas.org) -* Copyright (c) 2005 Adrian Page -* -* 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 of the License, 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. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. -*/ - -#include -#include -#include - -#include -#include -#include - -#include "rgb_f16half_plugin.h" -#include "kis_rgb_f16half_colorspace.h" - -typedef KGenericFactory RGBF16HalfPluginFactory; -K_EXPORT_COMPONENT_FACTORY( chalk_rgb_f16half_plugin, RGBF16HalfPluginFactory( "chalk" ) ) - - -RGBF16HalfPlugin::RGBF16HalfPlugin(TQObject *parent, const char *name, const TQStringList &) - : KParts::Plugin(parent, name) -{ - setInstance(RGBF16HalfPluginFactory::instance()); - - if ( parent->inherits("KisColorSpaceFactoryRegistry") ) - { - KisColorSpaceFactoryRegistry * f = dynamic_cast( parent ); - - KisColorSpace * colorSpaceRGBF16Half = new KisRgbF16HalfColorSpace(f, 0); - KisColorSpaceFactory *csf = new KisRgbF16HalfColorSpaceFactory(); - TQ_CHECK_PTR(colorSpaceRGBF16Half); - f->add(csf); - KisHistogramProducerFactoryRegistry::instance()->add( - new KisBasicHistogramProducerFactory - (KisID("RGBF16HALFHISTO", i18n("Float16 Half")), colorSpaceRGBF16Half) ); - } - -} - -RGBF16HalfPlugin::~RGBF16HalfPlugin() -{ -} - -#include "rgb_f16half_plugin.moc" - diff --git a/chalk/colorspaces/rgb_f16half/rgb_f16half_plugin.cpp b/chalk/colorspaces/rgb_f16half/rgb_f16half_plugin.cpp new file mode 100644 index 000000000..32505bc88 --- /dev/null +++ b/chalk/colorspaces/rgb_f16half/rgb_f16half_plugin.cpp @@ -0,0 +1,63 @@ +/* +* rgb_f32_plugin.cpp -- Part of Chalk +* +* Copyright (c) 2004 Boudewijn Rempt (boud@valdyas.org) +* Copyright (c) 2005 Adrian Page +* +* 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 of the License, 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. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +#include +#include +#include + +#include +#include +#include + +#include "rgb_f16half_plugin.h" +#include "kis_rgb_f16half_colorspace.h" + +typedef KGenericFactory RGBF16HalfPluginFactory; +K_EXPORT_COMPONENT_FACTORY( chalk_rgb_f16half_plugin, RGBF16HalfPluginFactory( "chalk" ) ) + + +RGBF16HalfPlugin::RGBF16HalfPlugin(TQObject *parent, const char *name, const TQStringList &) + : KParts::Plugin(parent, name) +{ + setInstance(RGBF16HalfPluginFactory::instance()); + + if ( parent->inherits("KisColorSpaceFactoryRegistry") ) + { + KisColorSpaceFactoryRegistry * f = dynamic_cast( parent ); + + KisColorSpace * colorSpaceRGBF16Half = new KisRgbF16HalfColorSpace(f, 0); + KisColorSpaceFactory *csf = new KisRgbF16HalfColorSpaceFactory(); + TQ_CHECK_PTR(colorSpaceRGBF16Half); + f->add(csf); + KisHistogramProducerFactoryRegistry::instance()->add( + new KisBasicHistogramProducerFactory + (KisID("RGBF16HALFHISTO", i18n("Float16 Half")), colorSpaceRGBF16Half) ); + } + +} + +RGBF16HalfPlugin::~RGBF16HalfPlugin() +{ +} + +#include "rgb_f16half_plugin.moc" + diff --git a/chalk/colorspaces/rgb_f16half/tests/Makefile.am b/chalk/colorspaces/rgb_f16half/tests/Makefile.am index cdb3f06c5..ae1cfc827 100644 --- a/chalk/colorspaces/rgb_f16half/tests/Makefile.am +++ b/chalk/colorspaces/rgb_f16half/tests/Makefile.am @@ -10,7 +10,7 @@ AM_CPPFLAGS = -I$(srcdir)/.. \ # $(KDE_CHECK_PLUGIN) assures a shared library is created. check_LTLIBRARIES = tdeunittest_kis_rgb_f16half_colorspace_tester.la -tdeunittest_kis_rgb_f16half_colorspace_tester_la_SOURCES = kis_rgb_f16half_colorspace_tester.cc +tdeunittest_kis_rgb_f16half_colorspace_tester_la_SOURCES = kis_rgb_f16half_colorspace_tester.cpp tdeunittest_kis_rgb_f16half_colorspace_tester_la_LIBADD = -ltdeunittest ../libchalk_rgb_f16half.la tdeunittest_kis_rgb_f16half_colorspace_tester_la_LDFLAGS = -module $(KDE_CHECK_PLUGIN) $(all_libraries) diff --git a/chalk/colorspaces/rgb_f16half/tests/kis_rgb_f16half_colorspace_tester.cc b/chalk/colorspaces/rgb_f16half/tests/kis_rgb_f16half_colorspace_tester.cpp similarity index 100% rename from chalk/colorspaces/rgb_f16half/tests/kis_rgb_f16half_colorspace_tester.cc rename to chalk/colorspaces/rgb_f16half/tests/kis_rgb_f16half_colorspace_tester.cpp diff --git a/chalk/colorspaces/rgb_f32/Makefile.am b/chalk/colorspaces/rgb_f32/Makefile.am index 0d206a3e4..0fd090c97 100644 --- a/chalk/colorspaces/rgb_f32/Makefile.am +++ b/chalk/colorspaces/rgb_f32/Makefile.am @@ -10,7 +10,7 @@ INCLUDES = \ lib_LTLIBRARIES = libchalk_rgb_f32.la -libchalk_rgb_f32_la_SOURCES = kis_rgb_f32_colorspace.cc +libchalk_rgb_f32_la_SOURCES = kis_rgb_f32_colorspace.cpp libchalk_rgb_f32_la_LDFLAGS = $(all_libraries) libchalk_rgb_f32_la_LIBADD = ../../chalkcolor/libchalkcolor.la @@ -18,7 +18,7 @@ libchalk_rgb_f32_la_LIBADD = ../../chalkcolor/libchalkcolor.la kde_module_LTLIBRARIES = chalk_rgb_f32_plugin.la # Srcs for the plugin -chalk_rgb_f32_plugin_la_SOURCES = rgb_f32_plugin.cc +chalk_rgb_f32_plugin_la_SOURCES = rgb_f32_plugin.cpp noinst_HEADERS = rgb_f32_plugin.h kis_rgb_f32_colorspace.h chalk_rgb_f32_plugin_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) $(LIB_TQT) -ltdecore -ltdeui -lkjs -ltdefx -ltdeio -ltdeparts -llcms diff --git a/chalk/colorspaces/rgb_f32/kis_rgb_f32_colorspace.cc b/chalk/colorspaces/rgb_f32/kis_rgb_f32_colorspace.cpp similarity index 100% rename from chalk/colorspaces/rgb_f32/kis_rgb_f32_colorspace.cc rename to chalk/colorspaces/rgb_f32/kis_rgb_f32_colorspace.cpp diff --git a/chalk/colorspaces/rgb_f32/kis_rgb_f32_colorspace.h b/chalk/colorspaces/rgb_f32/kis_rgb_f32_colorspace.h index c6551a4ce..785009e06 100644 --- a/chalk/colorspaces/rgb_f32/kis_rgb_f32_colorspace.h +++ b/chalk/colorspaces/rgb_f32/kis_rgb_f32_colorspace.h @@ -132,7 +132,7 @@ private: }; struct F32OpacityTest { inline bool operator()(const float& opacity) const { - return opacity > F32_OPACITY_TRANSPARENT + 1e-6; // #define EPSILON in the .cc + return opacity > F32_OPACITY_TRANSPARENT + 1e-6; // #define EPSILON in the .cpp } }; }; diff --git a/chalk/colorspaces/rgb_f32/rgb_f32_plugin.cc b/chalk/colorspaces/rgb_f32/rgb_f32_plugin.cc deleted file mode 100644 index 7c1149711..000000000 --- a/chalk/colorspaces/rgb_f32/rgb_f32_plugin.cc +++ /dev/null @@ -1,63 +0,0 @@ -/* -* rgb_f32_plugin.cc -- Part of Chalk -* -* Copyright (c) 2004 Boudewijn Rempt (boud@valdyas.org) -* Copyright (c) 2005 Adrian Page -* -* 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 of the License, 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. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. -*/ - -#include -#include -#include - -#include -#include -#include - -#include "rgb_f32_plugin.h" -#include "kis_rgb_f32_colorspace.h" - -typedef KGenericFactory RGBF32PluginFactory; -K_EXPORT_COMPONENT_FACTORY( chalk_rgb_f32_plugin, RGBF32PluginFactory( "chalk" ) ) - - -RGBF32Plugin::RGBF32Plugin(TQObject *parent, const char *name, const TQStringList &) - : KParts::Plugin(parent, name) -{ - setInstance(RGBF32PluginFactory::instance()); - - if ( parent->inherits("KisColorSpaceFactoryRegistry") ) - { - KisColorSpaceFactoryRegistry * f = dynamic_cast(parent); - - KisColorSpace * colorSpaceRGBF32 = new KisRgbF32ColorSpace(f, 0); - - KisColorSpaceFactory * csf = new KisRgbF32ColorSpaceFactory(); - f->add(csf); - - KisHistogramProducerFactoryRegistry::instance()->add( - new KisBasicHistogramProducerFactory - (KisID("RGBF32HISTO", i18n("Float32")), colorSpaceRGBF32) ); - } - -} - -RGBF32Plugin::~RGBF32Plugin() -{ -} - -#include "rgb_f32_plugin.moc" diff --git a/chalk/colorspaces/rgb_f32/rgb_f32_plugin.cpp b/chalk/colorspaces/rgb_f32/rgb_f32_plugin.cpp new file mode 100644 index 000000000..adc540ac0 --- /dev/null +++ b/chalk/colorspaces/rgb_f32/rgb_f32_plugin.cpp @@ -0,0 +1,63 @@ +/* +* rgb_f32_plugin.cpp -- Part of Chalk +* +* Copyright (c) 2004 Boudewijn Rempt (boud@valdyas.org) +* Copyright (c) 2005 Adrian Page +* +* 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 of the License, 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. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +#include +#include +#include + +#include +#include +#include + +#include "rgb_f32_plugin.h" +#include "kis_rgb_f32_colorspace.h" + +typedef KGenericFactory RGBF32PluginFactory; +K_EXPORT_COMPONENT_FACTORY( chalk_rgb_f32_plugin, RGBF32PluginFactory( "chalk" ) ) + + +RGBF32Plugin::RGBF32Plugin(TQObject *parent, const char *name, const TQStringList &) + : KParts::Plugin(parent, name) +{ + setInstance(RGBF32PluginFactory::instance()); + + if ( parent->inherits("KisColorSpaceFactoryRegistry") ) + { + KisColorSpaceFactoryRegistry * f = dynamic_cast(parent); + + KisColorSpace * colorSpaceRGBF32 = new KisRgbF32ColorSpace(f, 0); + + KisColorSpaceFactory * csf = new KisRgbF32ColorSpaceFactory(); + f->add(csf); + + KisHistogramProducerFactoryRegistry::instance()->add( + new KisBasicHistogramProducerFactory + (KisID("RGBF32HISTO", i18n("Float32")), colorSpaceRGBF32) ); + } + +} + +RGBF32Plugin::~RGBF32Plugin() +{ +} + +#include "rgb_f32_plugin.moc" diff --git a/chalk/colorspaces/rgb_f32/tests/Makefile.am b/chalk/colorspaces/rgb_f32/tests/Makefile.am index 9ad10271b..073c5da74 100644 --- a/chalk/colorspaces/rgb_f32/tests/Makefile.am +++ b/chalk/colorspaces/rgb_f32/tests/Makefile.am @@ -8,7 +8,7 @@ AM_CPPFLAGS = -I$(srcdir)/.. \ # $(KDE_CHECK_PLUGIN) assures a shared library is created. check_LTLIBRARIES = tdeunittest_kis_strategy_colorspace_rgb_f32_tester.la -tdeunittest_kis_strategy_colorspace_rgb_f32_tester_la_SOURCES = kis_strategy_colorspace_rgb_f32_tester.cc +tdeunittest_kis_strategy_colorspace_rgb_f32_tester_la_SOURCES = kis_strategy_colorspace_rgb_f32_tester.cpp tdeunittest_kis_strategy_colorspace_rgb_f32_tester_la_LIBADD = -ltdeunittest ../libchalk_rgb_f32.la tdeunittest_kis_strategy_colorspace_rgb_f32_tester_la_LDFLAGS = -module $(KDE_CHECK_PLUGIN) $(all_libraries) diff --git a/chalk/colorspaces/rgb_f32/tests/kis_strategy_colorspace_rgb_f32_tester.cc b/chalk/colorspaces/rgb_f32/tests/kis_strategy_colorspace_rgb_f32_tester.cpp similarity index 100% rename from chalk/colorspaces/rgb_f32/tests/kis_strategy_colorspace_rgb_f32_tester.cc rename to chalk/colorspaces/rgb_f32/tests/kis_strategy_colorspace_rgb_f32_tester.cpp diff --git a/chalk/colorspaces/rgb_u16/Makefile.am b/chalk/colorspaces/rgb_u16/Makefile.am index 41711c558..283c54e0e 100644 --- a/chalk/colorspaces/rgb_u16/Makefile.am +++ b/chalk/colorspaces/rgb_u16/Makefile.am @@ -8,7 +8,7 @@ INCLUDES = -I$(srcdir)/../../sdk \ $(all_includes) lib_LTLIBRARIES = libchalk_rgb_u16.la -libchalk_rgb_u16_la_SOURCES = kis_rgb_u16_colorspace.cc +libchalk_rgb_u16_la_SOURCES = kis_rgb_u16_colorspace.cpp libchalk_rgb_u16_la_LDFLAGS = $(all_libraries) libchalk_rgb_u16_la_LIBADD = ../../chalkcolor/libchalkcolor.la @@ -16,7 +16,7 @@ libchalk_rgb_u16_la_LIBADD = ../../chalkcolor/libchalkcolor.la kde_module_LTLIBRARIES = chalk_rgb_u16_plugin.la # Srcs for the plugin -chalk_rgb_u16_plugin_la_SOURCES = rgb_u16_plugin.cc +chalk_rgb_u16_plugin_la_SOURCES = rgb_u16_plugin.cpp noinst_HEADERS = rgb_u16_plugin.h kis_rgb_u16_colorspace.h chalk_rgb_u16_plugin_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) $(LIB_TQT) -ltdecore -ltdeui -lkjs -ltdefx -ltdeio -ltdeparts -llcms diff --git a/chalk/colorspaces/rgb_u16/kis_rgb_u16_colorspace.cc b/chalk/colorspaces/rgb_u16/kis_rgb_u16_colorspace.cpp similarity index 100% rename from chalk/colorspaces/rgb_u16/kis_rgb_u16_colorspace.cc rename to chalk/colorspaces/rgb_u16/kis_rgb_u16_colorspace.cpp diff --git a/chalk/colorspaces/rgb_u16/rgb_u16_plugin.cc b/chalk/colorspaces/rgb_u16/rgb_u16_plugin.cc deleted file mode 100644 index bc362a83e..000000000 --- a/chalk/colorspaces/rgb_u16/rgb_u16_plugin.cc +++ /dev/null @@ -1,61 +0,0 @@ -/* -* rgb_u16_plugin.cc -- Part of Chalk -* -* Copyright (c) 2004 Boudewijn Rempt (boud@valdyas.org) -* Copyright (c) 2005 Adrian Page -* -* 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 of the License, 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. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -*/ - -#include -#include -#include - -#include -#include - -#include "rgb_u16_plugin.h" -#include "kis_rgb_u16_colorspace.h" -#include "kis_basic_histogram_producers.h" - -typedef KGenericFactory RGBU16PluginFactory; -K_EXPORT_COMPONENT_FACTORY( chalk_rgb_u16_plugin, RGBU16PluginFactory( "chalk" ) ) - - -RGBU16Plugin::RGBU16Plugin(TQObject *parent, const char *name, const TQStringList &) - : KParts::Plugin(parent, name) -{ - setInstance(RGBU16PluginFactory::instance()); - - if ( parent->inherits("KisColorSpaceFactoryRegistry") ) - { - KisColorSpaceFactoryRegistry * f = dynamic_cast( parent ); - - KisColorSpace * colorSpaceRGBU16 = new KisRgbU16ColorSpace(f, 0); - KisColorSpaceFactory * csFactory = new KisRgbU16ColorSpaceFactory(); - f->add( csFactory ); - - KisHistogramProducerFactoryRegistry::instance()->add( - new KisBasicHistogramProducerFactory - (KisID("RGB16HISTO", i18n("RGB16")), colorSpaceRGBU16) ); - } - -} - -RGBU16Plugin::~RGBU16Plugin() -{ -} - -#include "rgb_u16_plugin.moc" diff --git a/chalk/colorspaces/rgb_u16/rgb_u16_plugin.cpp b/chalk/colorspaces/rgb_u16/rgb_u16_plugin.cpp new file mode 100644 index 000000000..da6e6e427 --- /dev/null +++ b/chalk/colorspaces/rgb_u16/rgb_u16_plugin.cpp @@ -0,0 +1,61 @@ +/* +* rgb_u16_plugin.cpp -- Part of Chalk +* +* Copyright (c) 2004 Boudewijn Rempt (boud@valdyas.org) +* Copyright (c) 2005 Adrian Page +* +* 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 of the License, 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. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include +#include +#include + +#include +#include + +#include "rgb_u16_plugin.h" +#include "kis_rgb_u16_colorspace.h" +#include "kis_basic_histogram_producers.h" + +typedef KGenericFactory RGBU16PluginFactory; +K_EXPORT_COMPONENT_FACTORY( chalk_rgb_u16_plugin, RGBU16PluginFactory( "chalk" ) ) + + +RGBU16Plugin::RGBU16Plugin(TQObject *parent, const char *name, const TQStringList &) + : KParts::Plugin(parent, name) +{ + setInstance(RGBU16PluginFactory::instance()); + + if ( parent->inherits("KisColorSpaceFactoryRegistry") ) + { + KisColorSpaceFactoryRegistry * f = dynamic_cast( parent ); + + KisColorSpace * colorSpaceRGBU16 = new KisRgbU16ColorSpace(f, 0); + KisColorSpaceFactory * csFactory = new KisRgbU16ColorSpaceFactory(); + f->add( csFactory ); + + KisHistogramProducerFactoryRegistry::instance()->add( + new KisBasicHistogramProducerFactory + (KisID("RGB16HISTO", i18n("RGB16")), colorSpaceRGBU16) ); + } + +} + +RGBU16Plugin::~RGBU16Plugin() +{ +} + +#include "rgb_u16_plugin.moc" diff --git a/chalk/colorspaces/rgb_u16/tests/Makefile.am b/chalk/colorspaces/rgb_u16/tests/Makefile.am index 76c4d175b..5bed7dfa6 100644 --- a/chalk/colorspaces/rgb_u16/tests/Makefile.am +++ b/chalk/colorspaces/rgb_u16/tests/Makefile.am @@ -8,7 +8,7 @@ AM_CPPFLAGS = -I$(srcdir)/.. \ # $(KDE_CHECK_PLUGIN) assures a shared library is created. check_LTLIBRARIES = tdeunittest_kis_strategy_colorspace_rgb_u16_tester.la -tdeunittest_kis_strategy_colorspace_rgb_u16_tester_la_SOURCES = kis_strategy_colorspace_rgb_u16_tester.cc +tdeunittest_kis_strategy_colorspace_rgb_u16_tester_la_SOURCES = kis_strategy_colorspace_rgb_u16_tester.cpp tdeunittest_kis_strategy_colorspace_rgb_u16_tester_la_LIBADD = -ltdeunittest ../libchalk_rgb_u16.la tdeunittest_kis_strategy_colorspace_rgb_u16_tester_la_LDFLAGS = -module $(KDE_CHECK_PLUGIN) $(all_libraries) diff --git a/chalk/colorspaces/rgb_u16/tests/kis_strategy_colorspace_rgb_u16_tester.cc b/chalk/colorspaces/rgb_u16/tests/kis_strategy_colorspace_rgb_u16_tester.cpp similarity index 100% rename from chalk/colorspaces/rgb_u16/tests/kis_strategy_colorspace_rgb_u16_tester.cc rename to chalk/colorspaces/rgb_u16/tests/kis_strategy_colorspace_rgb_u16_tester.cpp diff --git a/chalk/colorspaces/rgb_u8/Makefile.am b/chalk/colorspaces/rgb_u8/Makefile.am index c82abaa10..9b27665f0 100644 --- a/chalk/colorspaces/rgb_u8/Makefile.am +++ b/chalk/colorspaces/rgb_u8/Makefile.am @@ -8,7 +8,7 @@ INCLUDES = -I$(srcdir)/../../sdk \ $(all_includes) lib_LTLIBRARIES = libchalkrgb.la -libchalkrgb_la_SOURCES = kis_rgb_colorspace.cc +libchalkrgb_la_SOURCES = kis_rgb_colorspace.cpp libchalkrgb_la_LDFLAGS = $(all_libraries) $(LIB_TQT) libchalkrgb_la_LIBADD = ../../chalkcolor/libchalkcolor.la @@ -16,7 +16,7 @@ libchalkrgb_la_LIBADD = ../../chalkcolor/libchalkcolor.la kde_module_LTLIBRARIES = chalkrgbplugin.la # Srcs for the plugin -chalkrgbplugin_la_SOURCES = rgb_plugin.cc +chalkrgbplugin_la_SOURCES = rgb_plugin.cpp noinst_HEADERS = rgb_plugin.h kis_rgb_colorspace.h chalkrgbplugin_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) $(LIB_TQT) -ltdecore -ltdeui -lkjs -ltdefx -ltdeio -ltdeparts -llcms diff --git a/chalk/colorspaces/rgb_u8/kis_rgb_colorspace.cc b/chalk/colorspaces/rgb_u8/kis_rgb_colorspace.cpp similarity index 100% rename from chalk/colorspaces/rgb_u8/kis_rgb_colorspace.cc rename to chalk/colorspaces/rgb_u8/kis_rgb_colorspace.cpp diff --git a/chalk/colorspaces/rgb_u8/rgb_plugin.cc b/chalk/colorspaces/rgb_u8/rgb_plugin.cc deleted file mode 100644 index 263101259..000000000 --- a/chalk/colorspaces/rgb_u8/rgb_plugin.cc +++ /dev/null @@ -1,74 +0,0 @@ -/* -* rgb_plugin.cc -- Part of Chalk -* -* Copyright (c) 2004 Boudewijn Rempt (boud@valdyas.org) -* -* 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 of the License, 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. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -*/ -#include -#include - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include "rgb_plugin.h" -#include "kis_rgb_colorspace.h" - -typedef KGenericFactory RGBPluginFactory; -K_EXPORT_COMPONENT_FACTORY( chalkrgbplugin, RGBPluginFactory( "chalk" ) ) - - -RGBPlugin::RGBPlugin(TQObject *parent, const char *name, const TQStringList &) - : KParts::Plugin(parent, name) -{ - setInstance(RGBPluginFactory::instance()); - - if ( parent->inherits("KisColorSpaceFactoryRegistry") ) - { - KisColorSpaceFactoryRegistry * f = dynamic_cast(parent); - - KisProfile *defProfile = new KisProfile(cmsCreate_sRGBProfile()); - f->addProfile(defProfile); - - - KisColorSpaceFactory * csFactory = new KisRgbColorSpaceFactory(); - f->add(csFactory); - - KisColorSpace * colorSpaceRGBA = new KisRgbColorSpace(f, 0); - KisHistogramProducerFactoryRegistry::instance()->add( - new KisBasicHistogramProducerFactory - (KisID("RGB8HISTO", i18n("RGB8")), colorSpaceRGBA) ); - } - -} - -RGBPlugin::~RGBPlugin() -{ -} - -#include "rgb_plugin.moc" diff --git a/chalk/colorspaces/rgb_u8/rgb_plugin.cpp b/chalk/colorspaces/rgb_u8/rgb_plugin.cpp new file mode 100644 index 000000000..33f18b17f --- /dev/null +++ b/chalk/colorspaces/rgb_u8/rgb_plugin.cpp @@ -0,0 +1,74 @@ +/* +* rgb_plugin.cpp -- Part of Chalk +* +* Copyright (c) 2004 Boudewijn Rempt (boud@valdyas.org) +* +* 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 of the License, 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. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "rgb_plugin.h" +#include "kis_rgb_colorspace.h" + +typedef KGenericFactory RGBPluginFactory; +K_EXPORT_COMPONENT_FACTORY( chalkrgbplugin, RGBPluginFactory( "chalk" ) ) + + +RGBPlugin::RGBPlugin(TQObject *parent, const char *name, const TQStringList &) + : KParts::Plugin(parent, name) +{ + setInstance(RGBPluginFactory::instance()); + + if ( parent->inherits("KisColorSpaceFactoryRegistry") ) + { + KisColorSpaceFactoryRegistry * f = dynamic_cast(parent); + + KisProfile *defProfile = new KisProfile(cmsCreate_sRGBProfile()); + f->addProfile(defProfile); + + + KisColorSpaceFactory * csFactory = new KisRgbColorSpaceFactory(); + f->add(csFactory); + + KisColorSpace * colorSpaceRGBA = new KisRgbColorSpace(f, 0); + KisHistogramProducerFactoryRegistry::instance()->add( + new KisBasicHistogramProducerFactory + (KisID("RGB8HISTO", i18n("RGB8")), colorSpaceRGBA) ); + } + +} + +RGBPlugin::~RGBPlugin() +{ +} + +#include "rgb_plugin.moc" diff --git a/chalk/colorspaces/wet/Makefile.am b/chalk/colorspaces/wet/Makefile.am index 6d4bacab4..bd7c307f6 100644 --- a/chalk/colorspaces/wet/Makefile.am +++ b/chalk/colorspaces/wet/Makefile.am @@ -17,8 +17,8 @@ INCLUDES = -I$(srcdir)/../../sdk \ kde_module_LTLIBRARIES = chalkwetplugin.la -chalkwetplugin_la_SOURCES = kis_wet_colorspace.cc wet_plugin.cc kis_wetop.cc kis_wet_palette_widget.cc kis_wetness_visualisation_filter.cc kis_texture_painter.cc kis_texture_filter.cc wetphysicsfilter.cc wdgpressure.ui -noinst_HEADERS = kis_wet_colorspace.h wet_plugin.h wetphysicsfilter.h kis_wetop.cc kis_wet_palette_widget.h kis_texture_painter.h kis_wetness_visualisation_filter.h kis_texture_filter.h wetphysicsfilter.h +chalkwetplugin_la_SOURCES = kis_wet_colorspace.cpp wet_plugin.cpp kis_wetop.cpp kis_wet_palette_widget.cpp kis_wetness_visualisation_filter.cpp kis_texture_painter.cpp kis_texture_filter.cpp wetphysicsfilter.cpp wdgpressure.ui +noinst_HEADERS = kis_wet_colorspace.h wet_plugin.h wetphysicsfilter.h kis_wetop.cpp kis_wet_palette_widget.h kis_texture_painter.h kis_wetness_visualisation_filter.h kis_texture_filter.h wetphysicsfilter.h chalkwetplugin_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) $(LIB_TQT) -ltdecore -ltdeui -lkjs -ltdefx -ltdeio -ltdeparts -llcms chalkwetplugin_la_LIBADD = ../../libchalkcommon.la $(LIB_KOPAINTER) $(LIB_KOFFICECORE) \ diff --git a/chalk/colorspaces/wet/kis_texture_filter.cc b/chalk/colorspaces/wet/kis_texture_filter.cc deleted file mode 100644 index 6f58cd14a..000000000 --- a/chalk/colorspaces/wet/kis_texture_filter.cc +++ /dev/null @@ -1,43 +0,0 @@ -/* - * kis_texture_filter.cc -- Part of Chalk - * - * Copyright (c) 2005 Bart Coppens - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include -#include -#include -#include -#include "kis_texture_painter.h" -#include "kis_texture_filter.h" - -void WetPaintDevAction::act(KisPaintDeviceSP device, TQ_INT32 w, TQ_INT32 h) const { - KisColorSpace * cs = device->colorSpace(); - - if (cs->id() != KisID("WET","")) { - kdDebug(DBG_AREA_CMS) << "You set this kind of texture on non-wet layers!.\n"; - return; - } else { - kdDebug(DBG_AREA_CMS) << "Wet Paint Action activated!\n"; - } - - // XXX if params of the painter get configurable, make them here configurable as well? - KisTexturePainter painter(device); - painter.createTexture(0, 0, w, h); - painter.end(); -} - diff --git a/chalk/colorspaces/wet/kis_texture_filter.cpp b/chalk/colorspaces/wet/kis_texture_filter.cpp new file mode 100644 index 000000000..f70272dbf --- /dev/null +++ b/chalk/colorspaces/wet/kis_texture_filter.cpp @@ -0,0 +1,43 @@ +/* + * kis_texture_filter.cpp -- Part of Chalk + * + * Copyright (c) 2005 Bart Coppens + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include +#include +#include +#include +#include "kis_texture_painter.h" +#include "kis_texture_filter.h" + +void WetPaintDevAction::act(KisPaintDeviceSP device, TQ_INT32 w, TQ_INT32 h) const { + KisColorSpace * cs = device->colorSpace(); + + if (cs->id() != KisID("WET","")) { + kdDebug(DBG_AREA_CMS) << "You set this kind of texture on non-wet layers!.\n"; + return; + } else { + kdDebug(DBG_AREA_CMS) << "Wet Paint Action activated!\n"; + } + + // XXX if params of the painter get configurable, make them here configurable as well? + KisTexturePainter painter(device); + painter.createTexture(0, 0, w, h); + painter.end(); +} + diff --git a/chalk/colorspaces/wet/kis_texture_painter.cc b/chalk/colorspaces/wet/kis_texture_painter.cpp similarity index 100% rename from chalk/colorspaces/wet/kis_texture_painter.cc rename to chalk/colorspaces/wet/kis_texture_painter.cpp diff --git a/chalk/colorspaces/wet/kis_wet_colorspace.cc b/chalk/colorspaces/wet/kis_wet_colorspace.cpp similarity index 100% rename from chalk/colorspaces/wet/kis_wet_colorspace.cc rename to chalk/colorspaces/wet/kis_wet_colorspace.cpp diff --git a/chalk/colorspaces/wet/kis_wet_palette_widget.cc b/chalk/colorspaces/wet/kis_wet_palette_widget.cpp similarity index 100% rename from chalk/colorspaces/wet/kis_wet_palette_widget.cc rename to chalk/colorspaces/wet/kis_wet_palette_widget.cpp diff --git a/chalk/colorspaces/wet/kis_wetness_visualisation_filter.cc b/chalk/colorspaces/wet/kis_wetness_visualisation_filter.cc deleted file mode 100644 index f17f4e1c4..000000000 --- a/chalk/colorspaces/wet/kis_wetness_visualisation_filter.cc +++ /dev/null @@ -1,77 +0,0 @@ -/* - * kis_wetness_visualisation_filter.cc -- Part of Chalk - * - * Copyright (c) 2005 Bart Coppens - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include - -#include -#include "kis_meta_registry.h" -#include -#include -#include -#include -#include "kis_wet_colorspace.h" -#include -#include "kis_wetness_visualisation_filter.h" - -WetnessVisualisationFilter::WetnessVisualisationFilter(KisView* view) - : m_view(view), m_action(0) { - connect(&m_timer, TQT_SIGNAL(timeout()), this, TQT_SLOT(slotTimeout())); -} - -// XXX this needs to work on a per-layer basis! - -void WetnessVisualisationFilter::setAction(TDEToggleAction* action) { - m_action = action; - if (!m_action) - return; - KisWetColorSpace* cs = dynamic_cast( - KisMetaRegistry::instance()->csRegistry()->getColorSpace(KisID("WET", ""),"") ); - Q_ASSERT(cs); - m_action->setChecked(cs->paintWetness()); -} - -void WetnessVisualisationFilter::slotActivated() { - kdDebug(DBG_AREA_CMS) << "activated" << endl; - if (!m_action) { - kdDebug(DBG_AREA_CMS) << "no action" << endl; - return; - } - KisWetColorSpace* cs = dynamic_cast( - KisMetaRegistry::instance()->csRegistry()->getColorSpace(KisID("WET", ""),"") ); - Q_ASSERT(cs); - if (!m_action->isChecked()) { - m_timer.stop(); - cs->setPaintWetness(false); - } else { - m_timer.start(500); - cs->setPaintWetness(true); - } -} - -void WetnessVisualisationFilter::slotTimeout() { - KisWetColorSpace* cs = dynamic_cast( - KisMetaRegistry::instance()->csRegistry()->getColorSpace(KisID("WET", ""),"") ); - Q_ASSERT(cs); - if (!cs) return; - cs->resetPhase(); - -} - -#include "kis_wetness_visualisation_filter.moc" diff --git a/chalk/colorspaces/wet/kis_wetness_visualisation_filter.cpp b/chalk/colorspaces/wet/kis_wetness_visualisation_filter.cpp new file mode 100644 index 000000000..634424469 --- /dev/null +++ b/chalk/colorspaces/wet/kis_wetness_visualisation_filter.cpp @@ -0,0 +1,77 @@ +/* + * kis_wetness_visualisation_filter.cpp -- Part of Chalk + * + * Copyright (c) 2005 Bart Coppens + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include + +#include +#include "kis_meta_registry.h" +#include +#include +#include +#include +#include "kis_wet_colorspace.h" +#include +#include "kis_wetness_visualisation_filter.h" + +WetnessVisualisationFilter::WetnessVisualisationFilter(KisView* view) + : m_view(view), m_action(0) { + connect(&m_timer, TQT_SIGNAL(timeout()), this, TQT_SLOT(slotTimeout())); +} + +// XXX this needs to work on a per-layer basis! + +void WetnessVisualisationFilter::setAction(TDEToggleAction* action) { + m_action = action; + if (!m_action) + return; + KisWetColorSpace* cs = dynamic_cast( + KisMetaRegistry::instance()->csRegistry()->getColorSpace(KisID("WET", ""),"") ); + Q_ASSERT(cs); + m_action->setChecked(cs->paintWetness()); +} + +void WetnessVisualisationFilter::slotActivated() { + kdDebug(DBG_AREA_CMS) << "activated" << endl; + if (!m_action) { + kdDebug(DBG_AREA_CMS) << "no action" << endl; + return; + } + KisWetColorSpace* cs = dynamic_cast( + KisMetaRegistry::instance()->csRegistry()->getColorSpace(KisID("WET", ""),"") ); + Q_ASSERT(cs); + if (!m_action->isChecked()) { + m_timer.stop(); + cs->setPaintWetness(false); + } else { + m_timer.start(500); + cs->setPaintWetness(true); + } +} + +void WetnessVisualisationFilter::slotTimeout() { + KisWetColorSpace* cs = dynamic_cast( + KisMetaRegistry::instance()->csRegistry()->getColorSpace(KisID("WET", ""),"") ); + Q_ASSERT(cs); + if (!cs) return; + cs->resetPhase(); + +} + +#include "kis_wetness_visualisation_filter.moc" diff --git a/chalk/colorspaces/wet/kis_wetop.cc b/chalk/colorspaces/wet/kis_wetop.cpp similarity index 100% rename from chalk/colorspaces/wet/kis_wetop.cc rename to chalk/colorspaces/wet/kis_wetop.cpp diff --git a/chalk/colorspaces/wet/wet_plugin.cc b/chalk/colorspaces/wet/wet_plugin.cc deleted file mode 100644 index b919a2897..000000000 --- a/chalk/colorspaces/wet/wet_plugin.cc +++ /dev/null @@ -1,128 +0,0 @@ -/* - * wet_plugin.cc -- Part of Chalk - * - * Copyright (c) 2004 Boudewijn Rempt (boud@valdyas.org) - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include -#include "kis_meta_registry.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "wet_plugin.h" -#include "kis_wet_palette_widget.h" -#include "kis_wet_colorspace.h" -#include "kis_wetop.h" -#include "kis_wetness_visualisation_filter.h" -#include "kis_texture_filter.h" -#include "wetphysicsfilter.h" - -typedef KGenericFactory WetPluginFactory; -K_EXPORT_COMPONENT_FACTORY( chalkwetplugin, WetPluginFactory( "chalkcore" ) ) - - -WetPlugin::WetPlugin(TQObject *parent, const char *name, const TQStringList &) - : KParts::Plugin(parent, name) -{ - setInstance(WetPluginFactory::instance()); - - // This is not a gui plugin; only load it when the doc is created. - if ( parent->inherits("KisColorSpaceFactoryRegistry") ) { - KisColorSpaceFactoryRegistry * f = dynamic_cast(parent); - - KisColorSpace* colorSpaceWet = new KisWetColorSpace(f, 0); - - KisColorSpaceFactory * csf = new KisWetColorSpaceFactory(); - TQ_CHECK_PTR(colorSpaceWet); - - // colorspace - f->add(csf); - - // histogram producer - KisHistogramProducerFactoryRegistry::instance()->add( - new KisBasicHistogramProducerFactory - (KisID("WETHISTO", i18n("Wet")), colorSpaceWet) ); - - // wet brush op - KisPaintOpRegistry::instance()->add(new KisWetOpFactory); - - // Dry filter - KisFilterRegistry::instance()->add( new WetPhysicsFilter() ); - - // Texture Action: - f->addPaintDeviceAction(colorSpaceWet, new WetPaintDevAction); - } - else if (parent->inherits("KisView")) - { - setInstance(WetPluginFactory::instance()); - setXMLFile(locate("data","chalkplugins/wetplugin.rc"), true); - - m_view = dynamic_cast(parent); - // Wetness visualisation - WetnessVisualisationFilter * wf = new WetnessVisualisationFilter(m_view); - wf->setAction(new TDEToggleAction(i18n("Wetness Visualisation"), 0, 0, wf, - TQT_SLOT(slotActivated()), actionCollection(), "wetnessvisualisation")); - - // Create the wet palette - KisWetPaletteWidget * w = new KisWetPaletteWidget(m_view); - TQ_CHECK_PTR(w); - - w->setCaption(i18n("Watercolors")); - - m_view->canvasSubject()->paletteManager()->addWidget(w, "watercolor docker", chalk::COLORBOX, INT_MAX, PALETTE_DOCKER, false); - m_view->canvasSubject()->attach(w); - } - - -} - -WetPlugin::~WetPlugin() -{ -} - -#include "wet_plugin.moc" diff --git a/chalk/colorspaces/wet/wet_plugin.cpp b/chalk/colorspaces/wet/wet_plugin.cpp new file mode 100644 index 000000000..259fe5d1c --- /dev/null +++ b/chalk/colorspaces/wet/wet_plugin.cpp @@ -0,0 +1,128 @@ +/* + * wet_plugin.cpp -- Part of Chalk + * + * Copyright (c) 2004 Boudewijn Rempt (boud@valdyas.org) + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include "kis_meta_registry.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "wet_plugin.h" +#include "kis_wet_palette_widget.h" +#include "kis_wet_colorspace.h" +#include "kis_wetop.h" +#include "kis_wetness_visualisation_filter.h" +#include "kis_texture_filter.h" +#include "wetphysicsfilter.h" + +typedef KGenericFactory WetPluginFactory; +K_EXPORT_COMPONENT_FACTORY( chalkwetplugin, WetPluginFactory( "chalkcore" ) ) + + +WetPlugin::WetPlugin(TQObject *parent, const char *name, const TQStringList &) + : KParts::Plugin(parent, name) +{ + setInstance(WetPluginFactory::instance()); + + // This is not a gui plugin; only load it when the doc is created. + if ( parent->inherits("KisColorSpaceFactoryRegistry") ) { + KisColorSpaceFactoryRegistry * f = dynamic_cast(parent); + + KisColorSpace* colorSpaceWet = new KisWetColorSpace(f, 0); + + KisColorSpaceFactory * csf = new KisWetColorSpaceFactory(); + TQ_CHECK_PTR(colorSpaceWet); + + // colorspace + f->add(csf); + + // histogram producer + KisHistogramProducerFactoryRegistry::instance()->add( + new KisBasicHistogramProducerFactory + (KisID("WETHISTO", i18n("Wet")), colorSpaceWet) ); + + // wet brush op + KisPaintOpRegistry::instance()->add(new KisWetOpFactory); + + // Dry filter + KisFilterRegistry::instance()->add( new WetPhysicsFilter() ); + + // Texture Action: + f->addPaintDeviceAction(colorSpaceWet, new WetPaintDevAction); + } + else if (parent->inherits("KisView")) + { + setInstance(WetPluginFactory::instance()); + setXMLFile(locate("data","chalkplugins/wetplugin.rc"), true); + + m_view = dynamic_cast(parent); + // Wetness visualisation + WetnessVisualisationFilter * wf = new WetnessVisualisationFilter(m_view); + wf->setAction(new TDEToggleAction(i18n("Wetness Visualisation"), 0, 0, wf, + TQT_SLOT(slotActivated()), actionCollection(), "wetnessvisualisation")); + + // Create the wet palette + KisWetPaletteWidget * w = new KisWetPaletteWidget(m_view); + TQ_CHECK_PTR(w); + + w->setCaption(i18n("Watercolors")); + + m_view->canvasSubject()->paletteManager()->addWidget(w, "watercolor docker", chalk::COLORBOX, INT_MAX, PALETTE_DOCKER, false); + m_view->canvasSubject()->attach(w); + } + + +} + +WetPlugin::~WetPlugin() +{ +} + +#include "wet_plugin.moc" diff --git a/chalk/colorspaces/wet/wetphysicsfilter.cc b/chalk/colorspaces/wet/wetphysicsfilter.cpp similarity index 100% rename from chalk/colorspaces/wet/wetphysicsfilter.cc rename to chalk/colorspaces/wet/wetphysicsfilter.cpp diff --git a/chalk/colorspaces/wetsticky/Makefile.am b/chalk/colorspaces/wetsticky/Makefile.am index 4ade368a8..5d4e02894 100644 --- a/chalk/colorspaces/wetsticky/Makefile.am +++ b/chalk/colorspaces/wetsticky/Makefile.am @@ -12,7 +12,7 @@ INCLUDES = -I$(srcdir)/../../sdk \ kde_module_LTLIBRARIES = chalkwsplugin.la -chalkwsplugin_la_SOURCES = wet_sticky_plugin.cc kis_wet_sticky_colorspace.cc kis_ws_engine_filter.cc +chalkwsplugin_la_SOURCES = wet_sticky_plugin.cpp kis_wet_sticky_colorspace.cpp kis_ws_engine_filter.cpp noinst_HEADERS = wet_sticky_plugin.h kis_wet_sticky_colorspace.h kis_ws_engine_filter.h chalkwsplugin_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) diff --git a/chalk/colorspaces/wetsticky/brushop/Makefile.am b/chalk/colorspaces/wetsticky/brushop/Makefile.am index 8df4d61e3..eae064f8e 100644 --- a/chalk/colorspaces/wetsticky/brushop/Makefile.am +++ b/chalk/colorspaces/wetsticky/brushop/Makefile.am @@ -13,8 +13,8 @@ INCLUDES = -I$(srcdir)/../../../sdk \ chalkwsbrushpaintop_la_SOURCES = \ - wsbrushpaintop_plugin.cc \ - kis_wsbrushop.cc + wsbrushpaintop_plugin.cpp \ + kis_wsbrushop.cpp noinst_HEADERS= \ wsbrushpaintop_plugin.h \ diff --git a/chalk/colorspaces/wetsticky/brushop/kis_wsbrushop.cc b/chalk/colorspaces/wetsticky/brushop/kis_wsbrushop.cpp similarity index 100% rename from chalk/colorspaces/wetsticky/brushop/kis_wsbrushop.cc rename to chalk/colorspaces/wetsticky/brushop/kis_wsbrushop.cpp diff --git a/chalk/colorspaces/wetsticky/brushop/wsbrushpaintop_plugin.cc b/chalk/colorspaces/wetsticky/brushop/wsbrushpaintop_plugin.cc deleted file mode 100644 index 1f141bb4f..000000000 --- a/chalk/colorspaces/wetsticky/brushop/wsbrushpaintop_plugin.cc +++ /dev/null @@ -1,56 +0,0 @@ -/* - * wsbrushpaintop_plugin.cc -- Part of Chalk - * - * Copyright (c) 2005 Boudewijn Rempt (boud@valdyas.org) - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include "kis_wsbrushop.h" - -#include "wsbrushpaintop_plugin.h" - -typedef KGenericFactory WSBrushPaintOpPluginFactory; -K_EXPORT_COMPONENT_FACTORY( chalkwsbrushpaintop, WSBrushPaintOpPluginFactory( "chalkcore" ) ) - - -WSBrushPaintOpPlugin::WSBrushPaintOpPlugin(TQObject *parent, const char *name, const TQStringList &) - : KParts::Plugin(parent, name) -{ - setInstance(WSBrushPaintOpPluginFactory::instance()); - - // This is not a gui plugin; only load it when the doc is created. - if ( parent->inherits("KisFactory") ) - { - KisPaintOpRegistry::instance() -> add ( new KisWSBrushOpFactory ); - } - -} - -WSBrushPaintOpPlugin::~WSBrushPaintOpPlugin() -{ -} - -#include "wsbrushpaintop_plugin.moc" diff --git a/chalk/colorspaces/wetsticky/brushop/wsbrushpaintop_plugin.cpp b/chalk/colorspaces/wetsticky/brushop/wsbrushpaintop_plugin.cpp new file mode 100644 index 000000000..97c892b2b --- /dev/null +++ b/chalk/colorspaces/wetsticky/brushop/wsbrushpaintop_plugin.cpp @@ -0,0 +1,56 @@ +/* + * wsbrushpaintop_plugin.cpp -- Part of Chalk + * + * Copyright (c) 2005 Boudewijn Rempt (boud@valdyas.org) + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include "kis_wsbrushop.h" + +#include "wsbrushpaintop_plugin.h" + +typedef KGenericFactory WSBrushPaintOpPluginFactory; +K_EXPORT_COMPONENT_FACTORY( chalkwsbrushpaintop, WSBrushPaintOpPluginFactory( "chalkcore" ) ) + + +WSBrushPaintOpPlugin::WSBrushPaintOpPlugin(TQObject *parent, const char *name, const TQStringList &) + : KParts::Plugin(parent, name) +{ + setInstance(WSBrushPaintOpPluginFactory::instance()); + + // This is not a gui plugin; only load it when the doc is created. + if ( parent->inherits("KisFactory") ) + { + KisPaintOpRegistry::instance() -> add ( new KisWSBrushOpFactory ); + } + +} + +WSBrushPaintOpPlugin::~WSBrushPaintOpPlugin() +{ +} + +#include "wsbrushpaintop_plugin.moc" diff --git a/chalk/colorspaces/wetsticky/kis_wet_sticky_colorspace.cc b/chalk/colorspaces/wetsticky/kis_wet_sticky_colorspace.cpp similarity index 100% rename from chalk/colorspaces/wetsticky/kis_wet_sticky_colorspace.cc rename to chalk/colorspaces/wetsticky/kis_wet_sticky_colorspace.cpp diff --git a/chalk/colorspaces/wetsticky/kis_ws_engine_filter.cc b/chalk/colorspaces/wetsticky/kis_ws_engine_filter.cpp similarity index 100% rename from chalk/colorspaces/wetsticky/kis_ws_engine_filter.cc rename to chalk/colorspaces/wetsticky/kis_ws_engine_filter.cpp diff --git a/chalk/colorspaces/wetsticky/wet_sticky_plugin.cc b/chalk/colorspaces/wetsticky/wet_sticky_plugin.cc deleted file mode 100644 index 76dee20e6..000000000 --- a/chalk/colorspaces/wetsticky/wet_sticky_plugin.cc +++ /dev/null @@ -1,60 +0,0 @@ -/* - * wet_sticky_plugin.cc -- Part of Chalk - * - * Copyright (c) 2005 Boudewijn Rempt (boud@valdyas.org) - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include "wet_sticky_plugin.h" - -#include "kis_wet_sticky_colorspace.h" -#include "kis_ws_engine_filter.h" - -typedef KGenericFactory WetStickyPluginFactory; -K_EXPORT_COMPONENT_FACTORY( chalkwsplugin, WetStickyPluginFactory( "chalkcore" ) ) - - -WetStickyPlugin::WetStickyPlugin(TQObject *parent, const char *name, const TQStringList &) - : KParts::Plugin(parent, name) -{ - setInstance(WetStickyPluginFactory::instance()); - - // This is not a gui plugin; only load it when the doc is created. - if ( parent->inherits("KisFactory") ) - { - KisColorSpace * colorSpaceWS = new KisWetStickyColorSpace(); - TQ_CHECK_PTR(colorSpaceWS); - KisColorSpaceRegistry::instance() -> add(colorSpaceWS); - KisFilterRegistry::instance()->add(new KisWSEngineFilter()); - } - -} - -WetStickyPlugin::~WetStickyPlugin() -{ -} - -#include "wet_sticky_plugin.moc" diff --git a/chalk/colorspaces/wetsticky/wet_sticky_plugin.cpp b/chalk/colorspaces/wetsticky/wet_sticky_plugin.cpp new file mode 100644 index 000000000..e56e4cc88 --- /dev/null +++ b/chalk/colorspaces/wetsticky/wet_sticky_plugin.cpp @@ -0,0 +1,60 @@ +/* + * wet_sticky_plugin.cpp -- Part of Chalk + * + * Copyright (c) 2005 Boudewijn Rempt (boud@valdyas.org) + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include "wet_sticky_plugin.h" + +#include "kis_wet_sticky_colorspace.h" +#include "kis_ws_engine_filter.h" + +typedef KGenericFactory WetStickyPluginFactory; +K_EXPORT_COMPONENT_FACTORY( chalkwsplugin, WetStickyPluginFactory( "chalkcore" ) ) + + +WetStickyPlugin::WetStickyPlugin(TQObject *parent, const char *name, const TQStringList &) + : KParts::Plugin(parent, name) +{ + setInstance(WetStickyPluginFactory::instance()); + + // This is not a gui plugin; only load it when the doc is created. + if ( parent->inherits("KisFactory") ) + { + KisColorSpace * colorSpaceWS = new KisWetStickyColorSpace(); + TQ_CHECK_PTR(colorSpaceWS); + KisColorSpaceRegistry::instance() -> add(colorSpaceWS); + KisFilterRegistry::instance()->add(new KisWSEngineFilter()); + } + +} + +WetStickyPlugin::~WetStickyPlugin() +{ +} + +#include "wet_sticky_plugin.moc" diff --git a/chalk/colorspaces/ycbcr_u16/Makefile.am b/chalk/colorspaces/ycbcr_u16/Makefile.am index ab8200201..e9c273b79 100644 --- a/chalk/colorspaces/ycbcr_u16/Makefile.am +++ b/chalk/colorspaces/ycbcr_u16/Makefile.am @@ -16,7 +16,7 @@ libchalk_ycbcr_u16_la_LIBADD = ../../chalkcolor/libchalkcolor.la kde_module_LTLIBRARIES = chalk_ycbcr_u16_plugin.la # Srcs for the plugin -chalk_ycbcr_u16_plugin_la_SOURCES = ycbcr_u16_plugin.cc +chalk_ycbcr_u16_plugin_la_SOURCES = ycbcr_u16_plugin.cpp noinst_HEADERS = ycbcr_u16_plugin.h kis_ycbcr_u16_colorspace.h chalk_ycbcr_u16_plugin_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) $(LIB_TQT) -ltdecore -ltdeui -lkjs -ltdefx -ltdeio -ltdeparts -llcms @@ -24,6 +24,6 @@ chalk_ycbcr_u16_plugin_la_LIBADD = libchalk_ycbcr_u16.la ../../chalkcolor/libch METASOURCES = AUTO -libchalk_ycbcr_u16_la_SOURCES = kis_ycbcr_u16_colorspace.cc +libchalk_ycbcr_u16_la_SOURCES = kis_ycbcr_u16_colorspace.cpp .NOTPARALLEL: diff --git a/chalk/colorspaces/ycbcr_u16/kis_ycbcr_u16_colorspace.cc b/chalk/colorspaces/ycbcr_u16/kis_ycbcr_u16_colorspace.cpp similarity index 100% rename from chalk/colorspaces/ycbcr_u16/kis_ycbcr_u16_colorspace.cc rename to chalk/colorspaces/ycbcr_u16/kis_ycbcr_u16_colorspace.cpp diff --git a/chalk/colorspaces/ycbcr_u16/ycbcr_u16_plugin.cc b/chalk/colorspaces/ycbcr_u16/ycbcr_u16_plugin.cc deleted file mode 100644 index fdfb23106..000000000 --- a/chalk/colorspaces/ycbcr_u16/ycbcr_u16_plugin.cc +++ /dev/null @@ -1,60 +0,0 @@ -/* - * ycbcr_u16_plugin.cc -- Part of Chalk - * - * Copyright (c) 2006 Cyrille Berger - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include -#include -#include - -#include -#include -#include -#include -#include "ycbcr_u16_plugin.h" -#include "kis_ycbcr_u16_colorspace.h" - -typedef KGenericFactory YCbCrU16PluginFactory; -K_EXPORT_COMPONENT_FACTORY( chalk_ycbcr_u16_plugin, YCbCrU16PluginFactory( "chalk" ) ) - - -YCbCrU16Plugin::YCbCrU16Plugin(TQObject *parent, const char *name, const TQStringList &) - : KParts::Plugin(parent, name) -{ - setInstance(YCbCrU16PluginFactory::instance()); - - if ( parent->inherits("KisColorSpaceFactoryRegistry") ) - { - KisColorSpaceFactoryRegistry * f = dynamic_cast( parent ); - - KisColorSpace * colorSpaceYCbCrU16 = new KisYCbCrU16ColorSpace(f, 0); - KisColorSpaceFactory * csf = new KisYCbCrU16ColorSpaceFactory(); - TQ_CHECK_PTR(colorSpaceYCbCrU16); - f->add(csf); - KisHistogramProducerFactoryRegistry::instance()->add( - new KisBasicHistogramProducerFactory - (KisID("YCbCr16HISTO", i18n("YCbCr16")), colorSpaceYCbCrU16) ); - } - -} - -YCbCrU16Plugin::~YCbCrU16Plugin() -{ -} - -#include "ycbcr_u16_plugin.moc" diff --git a/chalk/colorspaces/ycbcr_u16/ycbcr_u16_plugin.cpp b/chalk/colorspaces/ycbcr_u16/ycbcr_u16_plugin.cpp new file mode 100644 index 000000000..4371a20a4 --- /dev/null +++ b/chalk/colorspaces/ycbcr_u16/ycbcr_u16_plugin.cpp @@ -0,0 +1,60 @@ +/* + * ycbcr_u16_plugin.cpp -- Part of Chalk + * + * Copyright (c) 2006 Cyrille Berger + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include +#include +#include + +#include +#include +#include +#include +#include "ycbcr_u16_plugin.h" +#include "kis_ycbcr_u16_colorspace.h" + +typedef KGenericFactory YCbCrU16PluginFactory; +K_EXPORT_COMPONENT_FACTORY( chalk_ycbcr_u16_plugin, YCbCrU16PluginFactory( "chalk" ) ) + + +YCbCrU16Plugin::YCbCrU16Plugin(TQObject *parent, const char *name, const TQStringList &) + : KParts::Plugin(parent, name) +{ + setInstance(YCbCrU16PluginFactory::instance()); + + if ( parent->inherits("KisColorSpaceFactoryRegistry") ) + { + KisColorSpaceFactoryRegistry * f = dynamic_cast( parent ); + + KisColorSpace * colorSpaceYCbCrU16 = new KisYCbCrU16ColorSpace(f, 0); + KisColorSpaceFactory * csf = new KisYCbCrU16ColorSpaceFactory(); + TQ_CHECK_PTR(colorSpaceYCbCrU16); + f->add(csf); + KisHistogramProducerFactoryRegistry::instance()->add( + new KisBasicHistogramProducerFactory + (KisID("YCbCr16HISTO", i18n("YCbCr16")), colorSpaceYCbCrU16) ); + } + +} + +YCbCrU16Plugin::~YCbCrU16Plugin() +{ +} + +#include "ycbcr_u16_plugin.moc" diff --git a/chalk/colorspaces/ycbcr_u8/Makefile.am b/chalk/colorspaces/ycbcr_u8/Makefile.am index 82f2942df..77c8c432e 100644 --- a/chalk/colorspaces/ycbcr_u8/Makefile.am +++ b/chalk/colorspaces/ycbcr_u8/Makefile.am @@ -16,7 +16,7 @@ libchalk_ycbcr_u8_la_LIBADD = ../../chalkcolor/libchalkcolor.la kde_module_LTLIBRARIES = chalk_ycbcr_u8_plugin.la # Srcs for the plugin -chalk_ycbcr_u8_plugin_la_SOURCES = ycbcr_u8_plugin.cc +chalk_ycbcr_u8_plugin_la_SOURCES = ycbcr_u8_plugin.cpp noinst_HEADERS = ycbcr_u8_plugin.h kis_ycbcr_u8_colorspace.h chalk_ycbcr_u8_plugin_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) $(LIB_TQT) -ltdecore -ltdeui -lkjs -ltdefx -ltdeio -ltdeparts -llcms @@ -25,7 +25,7 @@ chalk_ycbcr_u8_plugin_la_LIBADD = libchalk_ycbcr_u8.la ../../chalkcolor/libchal METASOURCES = AUTO -libchalk_ycbcr_u8_la_SOURCES = kis_ycbcr_u8_colorspace.cc +libchalk_ycbcr_u8_la_SOURCES = kis_ycbcr_u8_colorspace.cpp kde_services_DATA = chalk_ycbcr_u8_plugin.desktop .NOTPARALLEL: diff --git a/chalk/colorspaces/ycbcr_u8/kis_ycbcr_u8_colorspace.cc b/chalk/colorspaces/ycbcr_u8/kis_ycbcr_u8_colorspace.cpp similarity index 100% rename from chalk/colorspaces/ycbcr_u8/kis_ycbcr_u8_colorspace.cc rename to chalk/colorspaces/ycbcr_u8/kis_ycbcr_u8_colorspace.cpp diff --git a/chalk/colorspaces/ycbcr_u8/ycbcr_u8_plugin.cc b/chalk/colorspaces/ycbcr_u8/ycbcr_u8_plugin.cc deleted file mode 100644 index 342074329..000000000 --- a/chalk/colorspaces/ycbcr_u8/ycbcr_u8_plugin.cc +++ /dev/null @@ -1,62 +0,0 @@ -/* - * ycbcr_u8_plugin.cc -- Part of Chalk - * - * Copyright (c) 2006 Cyrille Berger - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include "ycbcr_u8_plugin.h" - -#include -#include -#include - -#include -#include -#include -#include - -#include "kis_ycbcr_u8_colorspace.h" - -typedef KGenericFactory YCbCrU8PluginFactory; -K_EXPORT_COMPONENT_FACTORY( chalk_ycbcr_u8_plugin, YCbCrU8PluginFactory( "chalk" ) ) - - -YCbCrU8Plugin::YCbCrU8Plugin(TQObject *parent, const char *name, const TQStringList &) - : KParts::Plugin(parent, name) -{ - setInstance(YCbCrU8PluginFactory::instance()); - - if ( parent->inherits("KisColorSpaceFactoryRegistry") ) - { - KisColorSpaceFactoryRegistry * f = dynamic_cast( parent ); - - KisColorSpace * colorSpaceYCbCrU8 = new KisYCbCrU8ColorSpace(f, 0); - KisColorSpaceFactory * csf = new KisYCbCrU8ColorSpaceFactory(); - TQ_CHECK_PTR(colorSpaceYCbCrU8); - f->add(csf); - KisHistogramProducerFactoryRegistry::instance()->add( - new KisBasicHistogramProducerFactory - (KisID("YCBR8HISTO", i18n("YCBR8")), colorSpaceYCbCrU8) ); - } - -} - -YCbCrU8Plugin::~YCbCrU8Plugin() -{ -} - -#include "ycbcr_u8_plugin.moc" diff --git a/chalk/colorspaces/ycbcr_u8/ycbcr_u8_plugin.cpp b/chalk/colorspaces/ycbcr_u8/ycbcr_u8_plugin.cpp new file mode 100644 index 000000000..6c3ac2437 --- /dev/null +++ b/chalk/colorspaces/ycbcr_u8/ycbcr_u8_plugin.cpp @@ -0,0 +1,62 @@ +/* + * ycbcr_u8_plugin.cpp -- Part of Chalk + * + * Copyright (c) 2006 Cyrille Berger + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "ycbcr_u8_plugin.h" + +#include +#include +#include + +#include +#include +#include +#include + +#include "kis_ycbcr_u8_colorspace.h" + +typedef KGenericFactory YCbCrU8PluginFactory; +K_EXPORT_COMPONENT_FACTORY( chalk_ycbcr_u8_plugin, YCbCrU8PluginFactory( "chalk" ) ) + + +YCbCrU8Plugin::YCbCrU8Plugin(TQObject *parent, const char *name, const TQStringList &) + : KParts::Plugin(parent, name) +{ + setInstance(YCbCrU8PluginFactory::instance()); + + if ( parent->inherits("KisColorSpaceFactoryRegistry") ) + { + KisColorSpaceFactoryRegistry * f = dynamic_cast( parent ); + + KisColorSpace * colorSpaceYCbCrU8 = new KisYCbCrU8ColorSpace(f, 0); + KisColorSpaceFactory * csf = new KisYCbCrU8ColorSpaceFactory(); + TQ_CHECK_PTR(colorSpaceYCbCrU8); + f->add(csf); + KisHistogramProducerFactoryRegistry::instance()->add( + new KisBasicHistogramProducerFactory + (KisID("YCBR8HISTO", i18n("YCBR8")), colorSpaceYCbCrU8) ); + } + +} + +YCbCrU8Plugin::~YCbCrU8Plugin() +{ +} + +#include "ycbcr_u8_plugin.moc" diff --git a/chalk/core/Makefile.am b/chalk/core/Makefile.am index 9370161af..ae67f2c08 100644 --- a/chalk/core/Makefile.am +++ b/chalk/core/Makefile.am @@ -13,21 +13,21 @@ CXXFLAGS += $(OPENEXR_CXXFLAGS) lib_LTLIBRARIES = libchalkimage.la -libchalkimage_la_SOURCES = kis_adjustment_layer.cc kis_alpha_mask.cc \ - kis_autobrush_resource.cc kis_autogradient_resource.cc kis_background.cc kis_boundary.cc \ - kis_brush.cc kis_command.cc kis_convolution_painter.cc kis_fill_painter.cc \ - kis_filter.cc kis_filter_registry.cc kis_filter_strategy.cc \ - kis_filter_configuration.cc kis_filter_config_widget.cc kis_gradient.cc kis_gradient_painter.cc \ - kis_histogram.cc kis_image.cc kis_imagepipe_brush.cc kis_iterator.cc \ - kis_iterators_pixel.cc kis_layer.cc kis_group_layer.cc kis_paint_layer.cc kis_meta_registry.cc \ - kis_nameserver.cc kis_painter.cc kis_paintop.cc kis_paintop_registry.cc kis_palette.cc \ - kis_pattern.cc kis_rect.cc kis_resource.cc kis_rotate_visitor.cc \ - kis_selected_transaction.cc kis_selection.cc kis_strategy_move.cc kis_transaction.cc \ - kis_transform_worker.cc kis_vec.cc kis_paint_device.cc kis_paint_device_iface.cc \ - kis_paint_device_iface.skel kis_image_iface.cc kis_image_iface.skel kis_basic_math_toolbox.cpp \ - kis_math_toolbox.cpp kis_exif_info.cc kis_thread_pool.cc kis_exif_value.cc \ +libchalkimage_la_SOURCES = kis_adjustment_layer.cpp kis_alpha_mask.cpp \ + kis_autobrush_resource.cpp kis_autogradient_resource.cpp kis_background.cpp kis_boundary.cpp \ + kis_brush.cpp kis_command.cpp kis_convolution_painter.cpp kis_fill_painter.cpp \ + kis_filter.cpp kis_filter_registry.cpp kis_filter_strategy.cpp \ + kis_filter_configuration.cpp kis_filter_config_widget.cpp kis_gradient.cpp kis_gradient_painter.cpp \ + kis_histogram.cpp kis_image.cpp kis_imagepipe_brush.cpp kis_iterator.cpp \ + kis_iterators_pixel.cpp kis_layer.cpp kis_group_layer.cpp kis_paint_layer.cpp kis_meta_registry.cpp \ + kis_nameserver.cpp kis_painter.cpp kis_paintop.cpp kis_paintop_registry.cpp kis_palette.cpp \ + kis_pattern.cpp kis_rect.cpp kis_resource.cpp kis_rotate_visitor.cpp \ + kis_selected_transaction.cpp kis_selection.cpp kis_strategy_move.cpp kis_transaction.cpp \ + kis_transform_worker.cpp kis_vec.cpp kis_paint_device.cpp kis_paint_device_iface.cpp \ + kis_paint_device_iface.skel kis_image_iface.cpp kis_image_iface.skel kis_basic_math_toolbox.cpp \ + kis_math_toolbox.cpp kis_exif_info.cpp kis_thread_pool.cpp kis_exif_value.cpp \ kis_filter_strategy.h kis_random_accessor.cpp kis_random_sub_accessor.cpp \ - kis_perspective_grid.cpp kis_perspectivetransform_worker.cpp kis_perspective_math.cpp kis_scale_visitor.cc + kis_perspective_grid.cpp kis_perspectivetransform_worker.cpp kis_perspective_math.cpp kis_scale_visitor.cpp noinst_HEADERS = kis_rotate_visitor.h kis_selected_transaction.h \ kis_strategy_move.h kis_transform_worker.h kis_datamanager.h kis_iteratorpixeltrait.h \ diff --git a/chalk/core/createdcop.py b/chalk/core/createdcop.py index ef7acc5ef..337d90761 100755 --- a/chalk/core/createdcop.py +++ b/chalk/core/createdcop.py @@ -149,7 +149,7 @@ def createDCOP(header): classname = classname + part.capitalize() classname_upper = classname_upper + part.upper() + "_" ifaceheader = header[:-2] + "_iface.h" - ifaceimplementation = header[:-2] + "_iface.cc" + ifaceimplementation = header[:-2] + "_iface.cpp" ifaceclass = classname + "Iface" #print "with: ", implementation, classname, classname_upper, ifaceheader, ifaceimplementation, ifaceclass diff --git a/chalk/core/kis_adjustment_layer.cc b/chalk/core/kis_adjustment_layer.cpp similarity index 100% rename from chalk/core/kis_adjustment_layer.cc rename to chalk/core/kis_adjustment_layer.cpp diff --git a/chalk/core/kis_alpha_mask.cc b/chalk/core/kis_alpha_mask.cpp similarity index 100% rename from chalk/core/kis_alpha_mask.cc rename to chalk/core/kis_alpha_mask.cpp diff --git a/chalk/core/kis_autobrush_resource.cc b/chalk/core/kis_autobrush_resource.cpp similarity index 100% rename from chalk/core/kis_autobrush_resource.cc rename to chalk/core/kis_autobrush_resource.cpp diff --git a/chalk/core/kis_autogradient_resource.cc b/chalk/core/kis_autogradient_resource.cc deleted file mode 100644 index 671e8fc2f..000000000 --- a/chalk/core/kis_autogradient_resource.cc +++ /dev/null @@ -1,221 +0,0 @@ -/* - * Copyright (c) 2004 Cyrille Berger - * 2004 Sven Langkamp - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include "kis_gradient.h" -#include "kis_autogradient_resource.h" - -// FIXME: use the same #define as in kis_gradient.cc, probably best customizable? -#define PREVIEW_WIDTH 64 -#define PREVIEW_HEIGHT 64 - - -void KisAutogradientResource::createSegment( int interpolation, int colorInterpolation, double startOffset, double endOffset, double middleOffset, TQColor left, TQColor right ) -{ - pushSegment(new KisGradientSegment(interpolation, colorInterpolation, startOffset, middleOffset, endOffset, Color( left, 1 ), Color( right, 1 ))); - -} - -const TQValueVector KisAutogradientResource::getHandlePositions() const -{ - TQValueVector handlePositions; - - handlePositions.push_back(m_segments[0]->startOffset()); - for (uint i = 0; i < m_segments.count(); i++) - { - handlePositions.push_back(m_segments[i]->endOffset()); - } - return handlePositions; -} - -const TQValueVector KisAutogradientResource::getMiddleHandlePositions() const -{ - TQValueVector middleHandlePositions; - - for (uint i = 0; i < m_segments.count(); i++) - { - middleHandlePositions.push_back(m_segments[i]->middleOffset()); - } - return middleHandlePositions; -} - -void KisAutogradientResource::moveSegmentStartOffset( KisGradientSegment* segment, double t) -{ - TQValueVector::iterator it = tqFind( m_segments.begin(), m_segments.end(), segment ); - if ( it != m_segments.end() ) - { - if ( it == m_segments.begin() ) - { - segment->setStartOffset( 0.0 ); - return; - } - KisGradientSegment* previousSegment = (*(it-1)); - if ( t > segment->startOffset() ) - { - if( t > segment->middleOffset() ) - t = segment->middleOffset(); - } - else { - if( t < previousSegment->middleOffset() ) - t = previousSegment->middleOffset(); - } - previousSegment->setEndOffset( t ); - segment->setStartOffset( t ); - } -} - -void KisAutogradientResource::moveSegmentEndOffset( KisGradientSegment* segment, double t) -{ - TQValueVector::iterator it = tqFind( m_segments.begin(), m_segments.end(), segment ); - if ( it != m_segments.end() ) - { - if ( it+1 == m_segments.end() ) - { - segment->setEndOffset( 1.0 ); - return; - } - KisGradientSegment* followingSegment = (*(it+1)); - if ( t < segment->endOffset() ) - { - if( t < segment->middleOffset() ) - t = segment->middleOffset(); - } - else { - if( t > followingSegment->middleOffset() ) - t = followingSegment->middleOffset(); - } - followingSegment->setStartOffset( t ); - segment->setEndOffset( t ); - } -} - -void KisAutogradientResource::moveSegmentMiddleOffset( KisGradientSegment* segment, double t) -{ - if( segment ) - { - if( t > segment->endOffset() ) - segment->setMiddleOffset( segment->endOffset() ); - else if( t < segment->startOffset() ) - segment->setMiddleOffset( segment->startOffset() ); - else - segment->setMiddleOffset( t ); - } -} - -void KisAutogradientResource::splitSegment( KisGradientSegment* segment ) -{ - Q_ASSERT(segment != 0); - TQValueVector::iterator it = tqFind( m_segments.begin(), m_segments.end(), segment ); - if ( it != m_segments.end() ) - { - KisGradientSegment* newSegment = new KisGradientSegment( - segment->interpolation(), segment->colorInterpolation(), - segment ->startOffset(), - ( segment->middleOffset() - segment->startOffset() ) / 2 + segment->startOffset(), - segment->middleOffset(), - segment->startColor(), - segment->colorAt( segment->middleOffset() ) ); - m_segments.insert( it, newSegment ); - segment->setStartColor( segment->colorAt( segment->middleOffset() ) ); - segment->setStartOffset( segment->middleOffset() ); - segment->setMiddleOffset( ( segment->endOffset() - segment->startOffset() ) / 2 + segment->startOffset() ); - } -} - -void KisAutogradientResource::duplicateSegment( KisGradientSegment* segment ) -{ - Q_ASSERT(segment != 0); - TQValueVector::iterator it = tqFind( m_segments.begin(), m_segments.end(), segment ); - if ( it != m_segments.end() ) - { - double middlePostionPercentage = ( segment->middleOffset() - segment->startOffset() ) / segment->length(); - double center = segment->startOffset() + segment->length() / 2; - KisGradientSegment* newSegment = new KisGradientSegment( - segment->interpolation(), segment->colorInterpolation(), - segment ->startOffset(), - segment->length() / 2 * middlePostionPercentage + segment->startOffset(), - center, segment->startColor(), - segment->endColor() ); - m_segments.insert( it, newSegment ); - segment->setStartOffset( center ); - segment->setMiddleOffset( segment->length() * middlePostionPercentage + segment->startOffset() ); - } -} - -void KisAutogradientResource::mirrorSegment( KisGradientSegment* segment ) -{ - Q_ASSERT(segment != 0); - Color tmpColor = segment->startColor(); - segment->setStartColor( segment->endColor() ); - segment->setEndColor( tmpColor ); - segment->setMiddleOffset( segment->endOffset() - ( segment->middleOffset() - segment->startOffset() ) ); - - if( segment->interpolation() == INTERP_SPHERE_INCREASING ) - segment->setInterpolation( INTERP_SPHERE_DECREASING ); - else if( segment->interpolation() == INTERP_SPHERE_DECREASING ) - segment->setInterpolation( INTERP_SPHERE_INCREASING ); - - if( segment->colorInterpolation() == COLOR_INTERP_HSV_CW ) - segment->setColorInterpolation( COLOR_INTERP_HSV_CCW ); - else if( segment->colorInterpolation() == COLOR_INTERP_HSV_CCW ) - segment->setColorInterpolation( COLOR_INTERP_HSV_CW ); -} - -KisGradientSegment* KisAutogradientResource::removeSegment( KisGradientSegment* segment ) -{ - Q_ASSERT(segment != 0); - if( m_segments.count() < 2 ) - return 0; - TQValueVector::iterator it = tqFind( m_segments.begin(), m_segments.end(), segment ); - if ( it != m_segments.end() ) - { - double middlePostionPercentage; - KisGradientSegment* nextSegment; - if( it == m_segments.begin() ) - { - nextSegment = (*(it+1)); - middlePostionPercentage = ( nextSegment->middleOffset() - nextSegment->startOffset() ) / nextSegment->length(); - nextSegment->setStartOffset( segment->startOffset() ); - nextSegment->setMiddleOffset( middlePostionPercentage * nextSegment->length() + nextSegment->startOffset() ); - } - else - { - nextSegment = (*(it-1)); - middlePostionPercentage = ( nextSegment->middleOffset() - nextSegment->startOffset() ) / nextSegment->length(); - nextSegment->setEndOffset( segment->endOffset() ); - nextSegment->setMiddleOffset( middlePostionPercentage * nextSegment->length() + nextSegment->startOffset() ); - } - - delete segment; - m_segments.erase( it ); - return nextSegment; - } - return 0; -} - -bool KisAutogradientResource::removeSegmentPossible() const -{ - if( m_segments.count() < 2 ) - return false; - return true; -} - -void KisAutogradientResource::updatePreview() -{ - setImage( generatePreview( PREVIEW_WIDTH, PREVIEW_HEIGHT ) ); -} diff --git a/chalk/core/kis_autogradient_resource.cpp b/chalk/core/kis_autogradient_resource.cpp new file mode 100644 index 000000000..aaac54efd --- /dev/null +++ b/chalk/core/kis_autogradient_resource.cpp @@ -0,0 +1,221 @@ +/* + * Copyright (c) 2004 Cyrille Berger + * 2004 Sven Langkamp + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "kis_gradient.h" +#include "kis_autogradient_resource.h" + +// FIXME: use the same #define as in kis_gradient.cpp, probably best customizable? +#define PREVIEW_WIDTH 64 +#define PREVIEW_HEIGHT 64 + + +void KisAutogradientResource::createSegment( int interpolation, int colorInterpolation, double startOffset, double endOffset, double middleOffset, TQColor left, TQColor right ) +{ + pushSegment(new KisGradientSegment(interpolation, colorInterpolation, startOffset, middleOffset, endOffset, Color( left, 1 ), Color( right, 1 ))); + +} + +const TQValueVector KisAutogradientResource::getHandlePositions() const +{ + TQValueVector handlePositions; + + handlePositions.push_back(m_segments[0]->startOffset()); + for (uint i = 0; i < m_segments.count(); i++) + { + handlePositions.push_back(m_segments[i]->endOffset()); + } + return handlePositions; +} + +const TQValueVector KisAutogradientResource::getMiddleHandlePositions() const +{ + TQValueVector middleHandlePositions; + + for (uint i = 0; i < m_segments.count(); i++) + { + middleHandlePositions.push_back(m_segments[i]->middleOffset()); + } + return middleHandlePositions; +} + +void KisAutogradientResource::moveSegmentStartOffset( KisGradientSegment* segment, double t) +{ + TQValueVector::iterator it = tqFind( m_segments.begin(), m_segments.end(), segment ); + if ( it != m_segments.end() ) + { + if ( it == m_segments.begin() ) + { + segment->setStartOffset( 0.0 ); + return; + } + KisGradientSegment* previousSegment = (*(it-1)); + if ( t > segment->startOffset() ) + { + if( t > segment->middleOffset() ) + t = segment->middleOffset(); + } + else { + if( t < previousSegment->middleOffset() ) + t = previousSegment->middleOffset(); + } + previousSegment->setEndOffset( t ); + segment->setStartOffset( t ); + } +} + +void KisAutogradientResource::moveSegmentEndOffset( KisGradientSegment* segment, double t) +{ + TQValueVector::iterator it = tqFind( m_segments.begin(), m_segments.end(), segment ); + if ( it != m_segments.end() ) + { + if ( it+1 == m_segments.end() ) + { + segment->setEndOffset( 1.0 ); + return; + } + KisGradientSegment* followingSegment = (*(it+1)); + if ( t < segment->endOffset() ) + { + if( t < segment->middleOffset() ) + t = segment->middleOffset(); + } + else { + if( t > followingSegment->middleOffset() ) + t = followingSegment->middleOffset(); + } + followingSegment->setStartOffset( t ); + segment->setEndOffset( t ); + } +} + +void KisAutogradientResource::moveSegmentMiddleOffset( KisGradientSegment* segment, double t) +{ + if( segment ) + { + if( t > segment->endOffset() ) + segment->setMiddleOffset( segment->endOffset() ); + else if( t < segment->startOffset() ) + segment->setMiddleOffset( segment->startOffset() ); + else + segment->setMiddleOffset( t ); + } +} + +void KisAutogradientResource::splitSegment( KisGradientSegment* segment ) +{ + Q_ASSERT(segment != 0); + TQValueVector::iterator it = tqFind( m_segments.begin(), m_segments.end(), segment ); + if ( it != m_segments.end() ) + { + KisGradientSegment* newSegment = new KisGradientSegment( + segment->interpolation(), segment->colorInterpolation(), + segment ->startOffset(), + ( segment->middleOffset() - segment->startOffset() ) / 2 + segment->startOffset(), + segment->middleOffset(), + segment->startColor(), + segment->colorAt( segment->middleOffset() ) ); + m_segments.insert( it, newSegment ); + segment->setStartColor( segment->colorAt( segment->middleOffset() ) ); + segment->setStartOffset( segment->middleOffset() ); + segment->setMiddleOffset( ( segment->endOffset() - segment->startOffset() ) / 2 + segment->startOffset() ); + } +} + +void KisAutogradientResource::duplicateSegment( KisGradientSegment* segment ) +{ + Q_ASSERT(segment != 0); + TQValueVector::iterator it = tqFind( m_segments.begin(), m_segments.end(), segment ); + if ( it != m_segments.end() ) + { + double middlePostionPercentage = ( segment->middleOffset() - segment->startOffset() ) / segment->length(); + double center = segment->startOffset() + segment->length() / 2; + KisGradientSegment* newSegment = new KisGradientSegment( + segment->interpolation(), segment->colorInterpolation(), + segment ->startOffset(), + segment->length() / 2 * middlePostionPercentage + segment->startOffset(), + center, segment->startColor(), + segment->endColor() ); + m_segments.insert( it, newSegment ); + segment->setStartOffset( center ); + segment->setMiddleOffset( segment->length() * middlePostionPercentage + segment->startOffset() ); + } +} + +void KisAutogradientResource::mirrorSegment( KisGradientSegment* segment ) +{ + Q_ASSERT(segment != 0); + Color tmpColor = segment->startColor(); + segment->setStartColor( segment->endColor() ); + segment->setEndColor( tmpColor ); + segment->setMiddleOffset( segment->endOffset() - ( segment->middleOffset() - segment->startOffset() ) ); + + if( segment->interpolation() == INTERP_SPHERE_INCREASING ) + segment->setInterpolation( INTERP_SPHERE_DECREASING ); + else if( segment->interpolation() == INTERP_SPHERE_DECREASING ) + segment->setInterpolation( INTERP_SPHERE_INCREASING ); + + if( segment->colorInterpolation() == COLOR_INTERP_HSV_CW ) + segment->setColorInterpolation( COLOR_INTERP_HSV_CCW ); + else if( segment->colorInterpolation() == COLOR_INTERP_HSV_CCW ) + segment->setColorInterpolation( COLOR_INTERP_HSV_CW ); +} + +KisGradientSegment* KisAutogradientResource::removeSegment( KisGradientSegment* segment ) +{ + Q_ASSERT(segment != 0); + if( m_segments.count() < 2 ) + return 0; + TQValueVector::iterator it = tqFind( m_segments.begin(), m_segments.end(), segment ); + if ( it != m_segments.end() ) + { + double middlePostionPercentage; + KisGradientSegment* nextSegment; + if( it == m_segments.begin() ) + { + nextSegment = (*(it+1)); + middlePostionPercentage = ( nextSegment->middleOffset() - nextSegment->startOffset() ) / nextSegment->length(); + nextSegment->setStartOffset( segment->startOffset() ); + nextSegment->setMiddleOffset( middlePostionPercentage * nextSegment->length() + nextSegment->startOffset() ); + } + else + { + nextSegment = (*(it-1)); + middlePostionPercentage = ( nextSegment->middleOffset() - nextSegment->startOffset() ) / nextSegment->length(); + nextSegment->setEndOffset( segment->endOffset() ); + nextSegment->setMiddleOffset( middlePostionPercentage * nextSegment->length() + nextSegment->startOffset() ); + } + + delete segment; + m_segments.erase( it ); + return nextSegment; + } + return 0; +} + +bool KisAutogradientResource::removeSegmentPossible() const +{ + if( m_segments.count() < 2 ) + return false; + return true; +} + +void KisAutogradientResource::updatePreview() +{ + setImage( generatePreview( PREVIEW_WIDTH, PREVIEW_HEIGHT ) ); +} diff --git a/chalk/core/kis_background.cc b/chalk/core/kis_background.cpp similarity index 100% rename from chalk/core/kis_background.cc rename to chalk/core/kis_background.cpp diff --git a/chalk/core/kis_boundary.cc b/chalk/core/kis_boundary.cpp similarity index 100% rename from chalk/core/kis_boundary.cc rename to chalk/core/kis_boundary.cpp diff --git a/chalk/core/kis_brush.cc b/chalk/core/kis_brush.cpp similarity index 100% rename from chalk/core/kis_brush.cc rename to chalk/core/kis_brush.cpp diff --git a/chalk/core/kis_command.cc b/chalk/core/kis_command.cpp similarity index 100% rename from chalk/core/kis_command.cc rename to chalk/core/kis_command.cpp diff --git a/chalk/core/kis_convolution_painter.cc b/chalk/core/kis_convolution_painter.cpp similarity index 100% rename from chalk/core/kis_convolution_painter.cc rename to chalk/core/kis_convolution_painter.cpp diff --git a/chalk/core/kis_exif_info.cc b/chalk/core/kis_exif_info.cpp similarity index 100% rename from chalk/core/kis_exif_info.cc rename to chalk/core/kis_exif_info.cpp diff --git a/chalk/core/kis_exif_value.cc b/chalk/core/kis_exif_value.cpp similarity index 100% rename from chalk/core/kis_exif_value.cc rename to chalk/core/kis_exif_value.cpp diff --git a/chalk/core/kis_fill_painter.cc b/chalk/core/kis_fill_painter.cpp similarity index 100% rename from chalk/core/kis_fill_painter.cc rename to chalk/core/kis_fill_painter.cpp diff --git a/chalk/core/kis_filter.cc b/chalk/core/kis_filter.cpp similarity index 100% rename from chalk/core/kis_filter.cc rename to chalk/core/kis_filter.cpp diff --git a/chalk/core/kis_filter_config_widget.cc b/chalk/core/kis_filter_config_widget.cpp similarity index 100% rename from chalk/core/kis_filter_config_widget.cc rename to chalk/core/kis_filter_config_widget.cpp diff --git a/chalk/core/kis_filter_configuration.cc b/chalk/core/kis_filter_configuration.cpp similarity index 100% rename from chalk/core/kis_filter_configuration.cc rename to chalk/core/kis_filter_configuration.cpp diff --git a/chalk/core/kis_filter_registry.cc b/chalk/core/kis_filter_registry.cpp similarity index 100% rename from chalk/core/kis_filter_registry.cc rename to chalk/core/kis_filter_registry.cpp diff --git a/chalk/core/kis_filter_strategy.cc b/chalk/core/kis_filter_strategy.cpp similarity index 100% rename from chalk/core/kis_filter_strategy.cc rename to chalk/core/kis_filter_strategy.cpp diff --git a/chalk/core/kis_gradient.cc b/chalk/core/kis_gradient.cc deleted file mode 100644 index 41541e80e..000000000 --- a/chalk/core/kis_gradient.cc +++ /dev/null @@ -1,639 +0,0 @@ -/* - * kis_gradient.cc - part of Krayon - * - * Copyright (c) 2000 Matthias Elter - * 2001 John Califf - * 2004 Boudewijn Rempt - * 2004 Adrian Page - * 2004 Sven Langkamp - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include -#include - -#include -#include -#include - -#include -#include - -#include -#include - -#include "kis_gradient.h" - -#define PREVIEW_WIDTH 64 -#define PREVIEW_HEIGHT 64 - -KisGradientSegment::RGBColorInterpolationStrategy *KisGradientSegment::RGBColorInterpolationStrategy::m_instance = 0; -KisGradientSegment::HSVCWColorInterpolationStrategy *KisGradientSegment::HSVCWColorInterpolationStrategy::m_instance = 0; -KisGradientSegment::HSVCCWColorInterpolationStrategy *KisGradientSegment::HSVCCWColorInterpolationStrategy::m_instance = 0; - -KisGradientSegment::LinearInterpolationStrategy *KisGradientSegment::LinearInterpolationStrategy::m_instance = 0; -KisGradientSegment::CurvedInterpolationStrategy *KisGradientSegment::CurvedInterpolationStrategy::m_instance = 0; -KisGradientSegment::SineInterpolationStrategy *KisGradientSegment::SineInterpolationStrategy::m_instance = 0; -KisGradientSegment::SphereIncreasingInterpolationStrategy *KisGradientSegment::SphereIncreasingInterpolationStrategy::m_instance = 0; -KisGradientSegment::SphereDecreasingInterpolationStrategy *KisGradientSegment::SphereDecreasingInterpolationStrategy::m_instance = 0; - -KisGradient::KisGradient(const TQString& file) : super(file) -{ -} - -KisGradient::~KisGradient() -{ - for (uint i = 0; i < m_segments.count(); i++) { - delete m_segments[i]; - m_segments[i] = 0; - } -} - -bool KisGradient::load() -{ - return init(); -} - -bool KisGradient::save() -{ - return false; -} - -TQImage KisGradient::img() -{ - return m_img; -} - -bool KisGradient::init() -{ - KoGradientManager gradLoader; - KoGradient* grad = gradLoader.loadGradient(filename()); - - if( !grad ) - return false; - - m_segments.clear(); - - if( grad->colorStops.count() > 1 ) { - KoColorStop *colstop; - for(colstop = grad->colorStops.first(); colstop; colstop = grad->colorStops.next()) { - KoColorStop *colstopNext = grad->colorStops.next(); - - if(colstopNext) { - KoColor leftRgb((int)(colstop->color1 * 255 + 0.5), (int)(colstop->color2 * 255 + 0.5), (int)(colstop->color3 * 255 + 0.5)); - KoColor rightRgb((int)(colstopNext->color1 * 255 + 0.5), (int)(colstopNext->color2 * 255 + 0.5), (int)(colstopNext->color3 * 255 + 0.5)); - - double midp = colstop->midpoint; - midp = colstop->offset + ((colstopNext->offset - colstop->offset) * midp); - - Color leftColor(leftRgb.color(), colstop->opacity); - Color rightColor(rightRgb.color(), colstopNext->opacity); - - KisGradientSegment *segment = new KisGradientSegment(colstop->interpolation, colstop->colorType, colstop->offset, midp, colstopNext->offset, leftColor, rightColor); - TQ_CHECK_PTR(segment); - - if ( !segment->isValid() ) { - delete segment; - return false; - } - - m_segments.push_back(segment); - grad->colorStops.prev(); - } - else { - grad->colorStops.prev(); - break; - } - } - } - else - return false; - - if (!m_segments.isEmpty()) { - m_img = generatePreview(PREVIEW_WIDTH, PREVIEW_HEIGHT); - setValid(true); - return true; - } - else { - return false; - } -} - -void KisGradient::setImage(const TQImage& img) -{ - m_img = img; - m_img.detach(); - - setValid(true); -} - -KisGradientSegment *KisGradient::segmentAt(double t) const -{ - Q_ASSERT(t >= 0 || t <= 1); - Q_ASSERT(!m_segments.empty()); - - for(TQValueVector::const_iterator it = m_segments.begin(); it!= m_segments.end(); ++it) - { - if (t > (*it)->startOffset() - DBL_EPSILON && t < (*it)->endOffset() + DBL_EPSILON) { - return *it; - } - } - - return 0; -} - -void KisGradient::colorAt(double t, TQColor *color, TQ_UINT8 *opacity) const -{ - const KisGradientSegment *segment = segmentAt(t); - Q_ASSERT(segment != 0); - - if (segment) { - Color col = segment->colorAt(t); - *color = col.color(); - *opacity = static_cast(col.alpha() * OPACITY_OPAQUE + 0.5); - } -} - -TQImage KisGradient::generatePreview(int width, int height) const -{ - TQImage img(width, height, 32); - - for (int y = 0; y < img.height(); y++) { - for (int x = 0; x < img.width(); x++) { - - int backgroundRed = 128 + 63 * ((x / 4 + y / 4) % 2); - int backgroundGreen = backgroundRed; - int backgroundBlue = backgroundRed; - - TQColor color; - TQ_UINT8 opacity; - double t = static_cast(x) / (img.width() - 1); - - colorAt(t, &color, &opacity); - - double alpha = static_cast(opacity) / OPACITY_OPAQUE; - - int red = static_cast((1 - alpha) * backgroundRed + alpha * color.red() + 0.5); - int green = static_cast((1 - alpha) * backgroundGreen + alpha * color.green() + 0.5); - int blue = static_cast((1 - alpha) * backgroundBlue + alpha * color.blue() + 0.5); - - img.setPixel(x, y, tqRgb(red, green, blue)); - } - } - - return img; -} - -KisGradientSegment::KisGradientSegment(int interpolationType, int colorInterpolationType, double startOffset, double middleOffset, double endOffset, const Color& startColor, const Color& endColor) -{ - m_interpolator = 0; - - switch (interpolationType) { - case INTERP_LINEAR: - m_interpolator = LinearInterpolationStrategy::instance(); - break; - case INTERP_CURVED: - m_interpolator = CurvedInterpolationStrategy::instance(); - break; - case INTERP_SINE: - m_interpolator = SineInterpolationStrategy::instance(); - break; - case INTERP_SPHERE_INCREASING: - m_interpolator = SphereIncreasingInterpolationStrategy::instance(); - break; - case INTERP_SPHERE_DECREASING: - m_interpolator = SphereDecreasingInterpolationStrategy::instance(); - break; - } - - m_colorInterpolator = 0; - - switch (colorInterpolationType) { - case COLOR_INTERP_RGB: - m_colorInterpolator = RGBColorInterpolationStrategy::instance(); - break; - case COLOR_INTERP_HSV_CCW: - m_colorInterpolator = HSVCCWColorInterpolationStrategy::instance(); - break; - case COLOR_INTERP_HSV_CW: - m_colorInterpolator = HSVCWColorInterpolationStrategy::instance(); - break; - } - - if (startOffset < DBL_EPSILON) { - m_startOffset = 0; - } - else - if (startOffset > 1 - DBL_EPSILON) { - m_startOffset = 1; - } - else { - m_startOffset = startOffset; - } - - if (middleOffset < m_startOffset + DBL_EPSILON) { - m_middleOffset = m_startOffset; - } - else - if (middleOffset > 1 - DBL_EPSILON) { - m_middleOffset = 1; - } - else { - m_middleOffset = middleOffset; - } - - if (endOffset < m_middleOffset + DBL_EPSILON) { - m_endOffset = m_middleOffset; - } - else - if (endOffset > 1 - DBL_EPSILON) { - m_endOffset = 1; - } - else { - m_endOffset = endOffset; - } - - m_length = m_endOffset - m_startOffset; - - if (m_length < DBL_EPSILON) { - m_middleT = 0.5; - } - else { - m_middleT = (m_middleOffset - m_startOffset) / m_length; - } - - m_startColor = startColor; - m_endColor = endColor; -} - -const Color& KisGradientSegment::startColor() const -{ - return m_startColor; -} - -const Color& KisGradientSegment::endColor() const -{ - return m_endColor; -} - -double KisGradientSegment::startOffset() const -{ - return m_startOffset; -} - -double KisGradientSegment::middleOffset() const -{ - return m_middleOffset; -} - -double KisGradientSegment::endOffset() const -{ - return m_endOffset; -} - -void KisGradientSegment::setStartOffset(double t) -{ - m_startOffset = t; - m_length = m_endOffset - m_startOffset; - - if (m_length < DBL_EPSILON) { - m_middleT = 0.5; - } - else { - m_middleT = (m_middleOffset - m_startOffset) / m_length; - } -} -void KisGradientSegment::setMiddleOffset(double t) -{ - m_middleOffset = t; - - if (m_length < DBL_EPSILON) { - m_middleT = 0.5; - } - else { - m_middleT = (m_middleOffset - m_startOffset) / m_length; - } -} - -void KisGradientSegment::setEndOffset(double t) -{ - m_endOffset = t; - m_length = m_endOffset - m_startOffset; - - if (m_length < DBL_EPSILON) { - m_middleT = 0.5; - } - else { - m_middleT = (m_middleOffset - m_startOffset) / m_length; - } -} - -int KisGradientSegment::interpolation() const -{ - return m_interpolator->type(); -} - -void KisGradientSegment::setInterpolation(int interpolationType) -{ - switch (interpolationType) { - case INTERP_LINEAR: - m_interpolator = LinearInterpolationStrategy::instance(); - break; - case INTERP_CURVED: - m_interpolator = CurvedInterpolationStrategy::instance(); - break; - case INTERP_SINE: - m_interpolator = SineInterpolationStrategy::instance(); - break; - case INTERP_SPHERE_INCREASING: - m_interpolator = SphereIncreasingInterpolationStrategy::instance(); - break; - case INTERP_SPHERE_DECREASING: - m_interpolator = SphereDecreasingInterpolationStrategy::instance(); - break; - } -} - -int KisGradientSegment::colorInterpolation() const -{ - return m_colorInterpolator->type(); -} - -void KisGradientSegment::setColorInterpolation(int colorInterpolationType) -{ - switch (colorInterpolationType) { - case COLOR_INTERP_RGB: - m_colorInterpolator = RGBColorInterpolationStrategy::instance(); - break; - case COLOR_INTERP_HSV_CCW: - m_colorInterpolator = HSVCCWColorInterpolationStrategy::instance(); - break; - case COLOR_INTERP_HSV_CW: - m_colorInterpolator = HSVCWColorInterpolationStrategy::instance(); - break; - } -} - -Color KisGradientSegment::colorAt(double t) const -{ - Q_ASSERT(t > m_startOffset - DBL_EPSILON && t < m_endOffset + DBL_EPSILON); - - double segmentT; - - if (m_length < DBL_EPSILON) { - segmentT = 0.5; - } - else { - segmentT = (t - m_startOffset) / m_length; - } - - double colorT = m_interpolator->valueAt(segmentT, m_middleT); - - Color color = m_colorInterpolator->colorAt(colorT, m_startColor, m_endColor); - - return color; -} - -bool KisGradientSegment::isValid() const -{ - if (m_interpolator == 0 || m_colorInterpolator ==0) - return false; - return true; -} - -KisGradientSegment::RGBColorInterpolationStrategy *KisGradientSegment::RGBColorInterpolationStrategy::instance() -{ - if (m_instance == 0) { - m_instance = new RGBColorInterpolationStrategy(); - TQ_CHECK_PTR(m_instance); - } - - return m_instance; -} - -Color KisGradientSegment::RGBColorInterpolationStrategy::colorAt(double t, Color start, Color end) const -{ - int startRed = start.color().red(); - int startGreen = start.color().green(); - int startBlue = start.color().blue(); - double startAlpha = start.alpha(); - int red = static_cast(startRed + t * (end.color().red() - startRed) + 0.5); - int green = static_cast(startGreen + t * (end.color().green() - startGreen) + 0.5); - int blue = static_cast(startBlue + t * (end.color().blue() - startBlue) + 0.5); - double alpha = startAlpha + t * (end.alpha() - startAlpha); - - return Color(TQColor(red, green, blue), alpha); -} - -KisGradientSegment::HSVCWColorInterpolationStrategy *KisGradientSegment::HSVCWColorInterpolationStrategy::instance() -{ - if (m_instance == 0) { - m_instance = new HSVCWColorInterpolationStrategy(); - TQ_CHECK_PTR(m_instance); - } - - return m_instance; -} - -Color KisGradientSegment::HSVCWColorInterpolationStrategy::colorAt(double t, Color start, Color end) const -{ - KoColor sc = KoColor(start.color()); - KoColor ec = KoColor(end.color()); - - int s = static_cast(sc.S() + t * (ec.S() - sc.S()) + 0.5); - int v = static_cast(sc.V() + t * (ec.V() - sc.V()) + 0.5); - int h; - - if (ec.H() < sc.H()) { - h = static_cast(ec.H() + (1 - t) * (sc.H() - ec.H()) + 0.5); - } - else { - h = static_cast(ec.H() + (1 - t) * (360 - ec.H() + sc.H()) + 0.5); - - if (h > 359) { - h -= 360; - } - } - - double alpha = start.alpha() + t * (end.alpha() - start.alpha()); - - return Color(KoColor(h, s, v, KoColor::csHSV).color(), alpha); -} - -KisGradientSegment::HSVCCWColorInterpolationStrategy *KisGradientSegment::HSVCCWColorInterpolationStrategy::instance() -{ - if (m_instance == 0) { - m_instance = new HSVCCWColorInterpolationStrategy(); - TQ_CHECK_PTR(m_instance); - } - - return m_instance; -} - -Color KisGradientSegment::HSVCCWColorInterpolationStrategy::colorAt(double t, Color start, Color end) const -{ - KoColor sc = KoColor(start.color()); - KoColor se = KoColor(end.color()); - - int s = static_cast(sc.S() + t * (se.S() - sc.S()) + 0.5); - int v = static_cast(sc.V() + t * (se.V() - sc.V()) + 0.5); - int h; - - if (sc.H() < se.H()) { - h = static_cast(sc.H() + t * (se.H() - sc.H()) + 0.5); - } - else { - h = static_cast(sc.H() + t * (360 - sc.H() + se.H()) + 0.5); - - if (h > 359) { - h -= 360; - } - } - - double alpha = start.alpha() + t * (end.alpha() - start.alpha()); - - return Color(KoColor(h, s, v, KoColor::csHSV).color(), alpha); -} - -KisGradientSegment::LinearInterpolationStrategy *KisGradientSegment::LinearInterpolationStrategy::instance() -{ - if (m_instance == 0) { - m_instance = new LinearInterpolationStrategy(); - TQ_CHECK_PTR(m_instance); - } - - return m_instance; -} - -double KisGradientSegment::LinearInterpolationStrategy::calcValueAt(double t, double middle) -{ - Q_ASSERT(t > -DBL_EPSILON && t < 1 + DBL_EPSILON); - Q_ASSERT(middle > -DBL_EPSILON && middle < 1 + DBL_EPSILON); - - double value = 0; - - if (t <= middle) { - if (middle < DBL_EPSILON) { - value = 0; - } - else { - value = (t / middle) * 0.5; - } - } - else { - if (middle > 1 - DBL_EPSILON) { - value = 1; - } - else { - value = ((t - middle) / (1 - middle)) * 0.5 + 0.5; - } - } - - return value; -} - -double KisGradientSegment::LinearInterpolationStrategy::valueAt(double t, double middle) const -{ - return calcValueAt(t, middle); -} - -KisGradientSegment::CurvedInterpolationStrategy::CurvedInterpolationStrategy() -{ - m_logHalf = log(0.5); -} - -KisGradientSegment::CurvedInterpolationStrategy *KisGradientSegment::CurvedInterpolationStrategy::instance() -{ - if (m_instance == 0) { - m_instance = new CurvedInterpolationStrategy(); - TQ_CHECK_PTR(m_instance); - } - - return m_instance; -} - -double KisGradientSegment::CurvedInterpolationStrategy::valueAt(double t, double middle) const -{ - Q_ASSERT(t > -DBL_EPSILON && t < 1 + DBL_EPSILON); - Q_ASSERT(middle > -DBL_EPSILON && middle < 1 + DBL_EPSILON); - - double value = 0; - - if (middle < DBL_EPSILON) { - middle = DBL_EPSILON; - } - - value = pow(t, m_logHalf / log(middle)); - - return value; -} - -KisGradientSegment::SineInterpolationStrategy *KisGradientSegment::SineInterpolationStrategy::instance() -{ - if (m_instance == 0) { - m_instance = new SineInterpolationStrategy(); - TQ_CHECK_PTR(m_instance); - } - - return m_instance; -} - -double KisGradientSegment::SineInterpolationStrategy::valueAt(double t, double middle) const -{ - double lt = LinearInterpolationStrategy::calcValueAt(t, middle); - double value = (sin(-M_PI_2 + M_PI * lt) + 1.0) / 2.0; - - return value; -} - -KisGradientSegment::SphereIncreasingInterpolationStrategy *KisGradientSegment::SphereIncreasingInterpolationStrategy::instance() -{ - if (m_instance == 0) { - m_instance = new SphereIncreasingInterpolationStrategy(); - TQ_CHECK_PTR(m_instance); - } - - return m_instance; -} - -double KisGradientSegment::SphereIncreasingInterpolationStrategy::valueAt(double t, double middle) const -{ - double lt = LinearInterpolationStrategy::calcValueAt(t, middle) - 1; - double value = sqrt(1 - lt * lt); - - return value; -} - -KisGradientSegment::SphereDecreasingInterpolationStrategy *KisGradientSegment::SphereDecreasingInterpolationStrategy::instance() -{ - if (m_instance == 0) { - m_instance = new SphereDecreasingInterpolationStrategy(); - TQ_CHECK_PTR(m_instance); - } - - return m_instance; -} - -double KisGradientSegment::SphereDecreasingInterpolationStrategy::valueAt(double t, double middle) const -{ - double lt = LinearInterpolationStrategy::calcValueAt(t, middle); - double value = 1 - sqrt(1 - lt * lt); - - return value; -} - -#include "kis_gradient.moc" - diff --git a/chalk/core/kis_gradient.cpp b/chalk/core/kis_gradient.cpp new file mode 100644 index 000000000..9b240cb06 --- /dev/null +++ b/chalk/core/kis_gradient.cpp @@ -0,0 +1,639 @@ +/* + * kis_gradient.cpp - part of Krayon + * + * Copyright (c) 2000 Matthias Elter + * 2001 John Califf + * 2004 Boudewijn Rempt + * 2004 Adrian Page + * 2004 Sven Langkamp + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include +#include + +#include +#include +#include + +#include +#include + +#include +#include + +#include "kis_gradient.h" + +#define PREVIEW_WIDTH 64 +#define PREVIEW_HEIGHT 64 + +KisGradientSegment::RGBColorInterpolationStrategy *KisGradientSegment::RGBColorInterpolationStrategy::m_instance = 0; +KisGradientSegment::HSVCWColorInterpolationStrategy *KisGradientSegment::HSVCWColorInterpolationStrategy::m_instance = 0; +KisGradientSegment::HSVCCWColorInterpolationStrategy *KisGradientSegment::HSVCCWColorInterpolationStrategy::m_instance = 0; + +KisGradientSegment::LinearInterpolationStrategy *KisGradientSegment::LinearInterpolationStrategy::m_instance = 0; +KisGradientSegment::CurvedInterpolationStrategy *KisGradientSegment::CurvedInterpolationStrategy::m_instance = 0; +KisGradientSegment::SineInterpolationStrategy *KisGradientSegment::SineInterpolationStrategy::m_instance = 0; +KisGradientSegment::SphereIncreasingInterpolationStrategy *KisGradientSegment::SphereIncreasingInterpolationStrategy::m_instance = 0; +KisGradientSegment::SphereDecreasingInterpolationStrategy *KisGradientSegment::SphereDecreasingInterpolationStrategy::m_instance = 0; + +KisGradient::KisGradient(const TQString& file) : super(file) +{ +} + +KisGradient::~KisGradient() +{ + for (uint i = 0; i < m_segments.count(); i++) { + delete m_segments[i]; + m_segments[i] = 0; + } +} + +bool KisGradient::load() +{ + return init(); +} + +bool KisGradient::save() +{ + return false; +} + +TQImage KisGradient::img() +{ + return m_img; +} + +bool KisGradient::init() +{ + KoGradientManager gradLoader; + KoGradient* grad = gradLoader.loadGradient(filename()); + + if( !grad ) + return false; + + m_segments.clear(); + + if( grad->colorStops.count() > 1 ) { + KoColorStop *colstop; + for(colstop = grad->colorStops.first(); colstop; colstop = grad->colorStops.next()) { + KoColorStop *colstopNext = grad->colorStops.next(); + + if(colstopNext) { + KoColor leftRgb((int)(colstop->color1 * 255 + 0.5), (int)(colstop->color2 * 255 + 0.5), (int)(colstop->color3 * 255 + 0.5)); + KoColor rightRgb((int)(colstopNext->color1 * 255 + 0.5), (int)(colstopNext->color2 * 255 + 0.5), (int)(colstopNext->color3 * 255 + 0.5)); + + double midp = colstop->midpoint; + midp = colstop->offset + ((colstopNext->offset - colstop->offset) * midp); + + Color leftColor(leftRgb.color(), colstop->opacity); + Color rightColor(rightRgb.color(), colstopNext->opacity); + + KisGradientSegment *segment = new KisGradientSegment(colstop->interpolation, colstop->colorType, colstop->offset, midp, colstopNext->offset, leftColor, rightColor); + TQ_CHECK_PTR(segment); + + if ( !segment->isValid() ) { + delete segment; + return false; + } + + m_segments.push_back(segment); + grad->colorStops.prev(); + } + else { + grad->colorStops.prev(); + break; + } + } + } + else + return false; + + if (!m_segments.isEmpty()) { + m_img = generatePreview(PREVIEW_WIDTH, PREVIEW_HEIGHT); + setValid(true); + return true; + } + else { + return false; + } +} + +void KisGradient::setImage(const TQImage& img) +{ + m_img = img; + m_img.detach(); + + setValid(true); +} + +KisGradientSegment *KisGradient::segmentAt(double t) const +{ + Q_ASSERT(t >= 0 || t <= 1); + Q_ASSERT(!m_segments.empty()); + + for(TQValueVector::const_iterator it = m_segments.begin(); it!= m_segments.end(); ++it) + { + if (t > (*it)->startOffset() - DBL_EPSILON && t < (*it)->endOffset() + DBL_EPSILON) { + return *it; + } + } + + return 0; +} + +void KisGradient::colorAt(double t, TQColor *color, TQ_UINT8 *opacity) const +{ + const KisGradientSegment *segment = segmentAt(t); + Q_ASSERT(segment != 0); + + if (segment) { + Color col = segment->colorAt(t); + *color = col.color(); + *opacity = static_cast(col.alpha() * OPACITY_OPAQUE + 0.5); + } +} + +TQImage KisGradient::generatePreview(int width, int height) const +{ + TQImage img(width, height, 32); + + for (int y = 0; y < img.height(); y++) { + for (int x = 0; x < img.width(); x++) { + + int backgroundRed = 128 + 63 * ((x / 4 + y / 4) % 2); + int backgroundGreen = backgroundRed; + int backgroundBlue = backgroundRed; + + TQColor color; + TQ_UINT8 opacity; + double t = static_cast(x) / (img.width() - 1); + + colorAt(t, &color, &opacity); + + double alpha = static_cast(opacity) / OPACITY_OPAQUE; + + int red = static_cast((1 - alpha) * backgroundRed + alpha * color.red() + 0.5); + int green = static_cast((1 - alpha) * backgroundGreen + alpha * color.green() + 0.5); + int blue = static_cast((1 - alpha) * backgroundBlue + alpha * color.blue() + 0.5); + + img.setPixel(x, y, tqRgb(red, green, blue)); + } + } + + return img; +} + +KisGradientSegment::KisGradientSegment(int interpolationType, int colorInterpolationType, double startOffset, double middleOffset, double endOffset, const Color& startColor, const Color& endColor) +{ + m_interpolator = 0; + + switch (interpolationType) { + case INTERP_LINEAR: + m_interpolator = LinearInterpolationStrategy::instance(); + break; + case INTERP_CURVED: + m_interpolator = CurvedInterpolationStrategy::instance(); + break; + case INTERP_SINE: + m_interpolator = SineInterpolationStrategy::instance(); + break; + case INTERP_SPHERE_INCREASING: + m_interpolator = SphereIncreasingInterpolationStrategy::instance(); + break; + case INTERP_SPHERE_DECREASING: + m_interpolator = SphereDecreasingInterpolationStrategy::instance(); + break; + } + + m_colorInterpolator = 0; + + switch (colorInterpolationType) { + case COLOR_INTERP_RGB: + m_colorInterpolator = RGBColorInterpolationStrategy::instance(); + break; + case COLOR_INTERP_HSV_CCW: + m_colorInterpolator = HSVCCWColorInterpolationStrategy::instance(); + break; + case COLOR_INTERP_HSV_CW: + m_colorInterpolator = HSVCWColorInterpolationStrategy::instance(); + break; + } + + if (startOffset < DBL_EPSILON) { + m_startOffset = 0; + } + else + if (startOffset > 1 - DBL_EPSILON) { + m_startOffset = 1; + } + else { + m_startOffset = startOffset; + } + + if (middleOffset < m_startOffset + DBL_EPSILON) { + m_middleOffset = m_startOffset; + } + else + if (middleOffset > 1 - DBL_EPSILON) { + m_middleOffset = 1; + } + else { + m_middleOffset = middleOffset; + } + + if (endOffset < m_middleOffset + DBL_EPSILON) { + m_endOffset = m_middleOffset; + } + else + if (endOffset > 1 - DBL_EPSILON) { + m_endOffset = 1; + } + else { + m_endOffset = endOffset; + } + + m_length = m_endOffset - m_startOffset; + + if (m_length < DBL_EPSILON) { + m_middleT = 0.5; + } + else { + m_middleT = (m_middleOffset - m_startOffset) / m_length; + } + + m_startColor = startColor; + m_endColor = endColor; +} + +const Color& KisGradientSegment::startColor() const +{ + return m_startColor; +} + +const Color& KisGradientSegment::endColor() const +{ + return m_endColor; +} + +double KisGradientSegment::startOffset() const +{ + return m_startOffset; +} + +double KisGradientSegment::middleOffset() const +{ + return m_middleOffset; +} + +double KisGradientSegment::endOffset() const +{ + return m_endOffset; +} + +void KisGradientSegment::setStartOffset(double t) +{ + m_startOffset = t; + m_length = m_endOffset - m_startOffset; + + if (m_length < DBL_EPSILON) { + m_middleT = 0.5; + } + else { + m_middleT = (m_middleOffset - m_startOffset) / m_length; + } +} +void KisGradientSegment::setMiddleOffset(double t) +{ + m_middleOffset = t; + + if (m_length < DBL_EPSILON) { + m_middleT = 0.5; + } + else { + m_middleT = (m_middleOffset - m_startOffset) / m_length; + } +} + +void KisGradientSegment::setEndOffset(double t) +{ + m_endOffset = t; + m_length = m_endOffset - m_startOffset; + + if (m_length < DBL_EPSILON) { + m_middleT = 0.5; + } + else { + m_middleT = (m_middleOffset - m_startOffset) / m_length; + } +} + +int KisGradientSegment::interpolation() const +{ + return m_interpolator->type(); +} + +void KisGradientSegment::setInterpolation(int interpolationType) +{ + switch (interpolationType) { + case INTERP_LINEAR: + m_interpolator = LinearInterpolationStrategy::instance(); + break; + case INTERP_CURVED: + m_interpolator = CurvedInterpolationStrategy::instance(); + break; + case INTERP_SINE: + m_interpolator = SineInterpolationStrategy::instance(); + break; + case INTERP_SPHERE_INCREASING: + m_interpolator = SphereIncreasingInterpolationStrategy::instance(); + break; + case INTERP_SPHERE_DECREASING: + m_interpolator = SphereDecreasingInterpolationStrategy::instance(); + break; + } +} + +int KisGradientSegment::colorInterpolation() const +{ + return m_colorInterpolator->type(); +} + +void KisGradientSegment::setColorInterpolation(int colorInterpolationType) +{ + switch (colorInterpolationType) { + case COLOR_INTERP_RGB: + m_colorInterpolator = RGBColorInterpolationStrategy::instance(); + break; + case COLOR_INTERP_HSV_CCW: + m_colorInterpolator = HSVCCWColorInterpolationStrategy::instance(); + break; + case COLOR_INTERP_HSV_CW: + m_colorInterpolator = HSVCWColorInterpolationStrategy::instance(); + break; + } +} + +Color KisGradientSegment::colorAt(double t) const +{ + Q_ASSERT(t > m_startOffset - DBL_EPSILON && t < m_endOffset + DBL_EPSILON); + + double segmentT; + + if (m_length < DBL_EPSILON) { + segmentT = 0.5; + } + else { + segmentT = (t - m_startOffset) / m_length; + } + + double colorT = m_interpolator->valueAt(segmentT, m_middleT); + + Color color = m_colorInterpolator->colorAt(colorT, m_startColor, m_endColor); + + return color; +} + +bool KisGradientSegment::isValid() const +{ + if (m_interpolator == 0 || m_colorInterpolator ==0) + return false; + return true; +} + +KisGradientSegment::RGBColorInterpolationStrategy *KisGradientSegment::RGBColorInterpolationStrategy::instance() +{ + if (m_instance == 0) { + m_instance = new RGBColorInterpolationStrategy(); + TQ_CHECK_PTR(m_instance); + } + + return m_instance; +} + +Color KisGradientSegment::RGBColorInterpolationStrategy::colorAt(double t, Color start, Color end) const +{ + int startRed = start.color().red(); + int startGreen = start.color().green(); + int startBlue = start.color().blue(); + double startAlpha = start.alpha(); + int red = static_cast(startRed + t * (end.color().red() - startRed) + 0.5); + int green = static_cast(startGreen + t * (end.color().green() - startGreen) + 0.5); + int blue = static_cast(startBlue + t * (end.color().blue() - startBlue) + 0.5); + double alpha = startAlpha + t * (end.alpha() - startAlpha); + + return Color(TQColor(red, green, blue), alpha); +} + +KisGradientSegment::HSVCWColorInterpolationStrategy *KisGradientSegment::HSVCWColorInterpolationStrategy::instance() +{ + if (m_instance == 0) { + m_instance = new HSVCWColorInterpolationStrategy(); + TQ_CHECK_PTR(m_instance); + } + + return m_instance; +} + +Color KisGradientSegment::HSVCWColorInterpolationStrategy::colorAt(double t, Color start, Color end) const +{ + KoColor sc = KoColor(start.color()); + KoColor ec = KoColor(end.color()); + + int s = static_cast(sc.S() + t * (ec.S() - sc.S()) + 0.5); + int v = static_cast(sc.V() + t * (ec.V() - sc.V()) + 0.5); + int h; + + if (ec.H() < sc.H()) { + h = static_cast(ec.H() + (1 - t) * (sc.H() - ec.H()) + 0.5); + } + else { + h = static_cast(ec.H() + (1 - t) * (360 - ec.H() + sc.H()) + 0.5); + + if (h > 359) { + h -= 360; + } + } + + double alpha = start.alpha() + t * (end.alpha() - start.alpha()); + + return Color(KoColor(h, s, v, KoColor::csHSV).color(), alpha); +} + +KisGradientSegment::HSVCCWColorInterpolationStrategy *KisGradientSegment::HSVCCWColorInterpolationStrategy::instance() +{ + if (m_instance == 0) { + m_instance = new HSVCCWColorInterpolationStrategy(); + TQ_CHECK_PTR(m_instance); + } + + return m_instance; +} + +Color KisGradientSegment::HSVCCWColorInterpolationStrategy::colorAt(double t, Color start, Color end) const +{ + KoColor sc = KoColor(start.color()); + KoColor se = KoColor(end.color()); + + int s = static_cast(sc.S() + t * (se.S() - sc.S()) + 0.5); + int v = static_cast(sc.V() + t * (se.V() - sc.V()) + 0.5); + int h; + + if (sc.H() < se.H()) { + h = static_cast(sc.H() + t * (se.H() - sc.H()) + 0.5); + } + else { + h = static_cast(sc.H() + t * (360 - sc.H() + se.H()) + 0.5); + + if (h > 359) { + h -= 360; + } + } + + double alpha = start.alpha() + t * (end.alpha() - start.alpha()); + + return Color(KoColor(h, s, v, KoColor::csHSV).color(), alpha); +} + +KisGradientSegment::LinearInterpolationStrategy *KisGradientSegment::LinearInterpolationStrategy::instance() +{ + if (m_instance == 0) { + m_instance = new LinearInterpolationStrategy(); + TQ_CHECK_PTR(m_instance); + } + + return m_instance; +} + +double KisGradientSegment::LinearInterpolationStrategy::calcValueAt(double t, double middle) +{ + Q_ASSERT(t > -DBL_EPSILON && t < 1 + DBL_EPSILON); + Q_ASSERT(middle > -DBL_EPSILON && middle < 1 + DBL_EPSILON); + + double value = 0; + + if (t <= middle) { + if (middle < DBL_EPSILON) { + value = 0; + } + else { + value = (t / middle) * 0.5; + } + } + else { + if (middle > 1 - DBL_EPSILON) { + value = 1; + } + else { + value = ((t - middle) / (1 - middle)) * 0.5 + 0.5; + } + } + + return value; +} + +double KisGradientSegment::LinearInterpolationStrategy::valueAt(double t, double middle) const +{ + return calcValueAt(t, middle); +} + +KisGradientSegment::CurvedInterpolationStrategy::CurvedInterpolationStrategy() +{ + m_logHalf = log(0.5); +} + +KisGradientSegment::CurvedInterpolationStrategy *KisGradientSegment::CurvedInterpolationStrategy::instance() +{ + if (m_instance == 0) { + m_instance = new CurvedInterpolationStrategy(); + TQ_CHECK_PTR(m_instance); + } + + return m_instance; +} + +double KisGradientSegment::CurvedInterpolationStrategy::valueAt(double t, double middle) const +{ + Q_ASSERT(t > -DBL_EPSILON && t < 1 + DBL_EPSILON); + Q_ASSERT(middle > -DBL_EPSILON && middle < 1 + DBL_EPSILON); + + double value = 0; + + if (middle < DBL_EPSILON) { + middle = DBL_EPSILON; + } + + value = pow(t, m_logHalf / log(middle)); + + return value; +} + +KisGradientSegment::SineInterpolationStrategy *KisGradientSegment::SineInterpolationStrategy::instance() +{ + if (m_instance == 0) { + m_instance = new SineInterpolationStrategy(); + TQ_CHECK_PTR(m_instance); + } + + return m_instance; +} + +double KisGradientSegment::SineInterpolationStrategy::valueAt(double t, double middle) const +{ + double lt = LinearInterpolationStrategy::calcValueAt(t, middle); + double value = (sin(-M_PI_2 + M_PI * lt) + 1.0) / 2.0; + + return value; +} + +KisGradientSegment::SphereIncreasingInterpolationStrategy *KisGradientSegment::SphereIncreasingInterpolationStrategy::instance() +{ + if (m_instance == 0) { + m_instance = new SphereIncreasingInterpolationStrategy(); + TQ_CHECK_PTR(m_instance); + } + + return m_instance; +} + +double KisGradientSegment::SphereIncreasingInterpolationStrategy::valueAt(double t, double middle) const +{ + double lt = LinearInterpolationStrategy::calcValueAt(t, middle) - 1; + double value = sqrt(1 - lt * lt); + + return value; +} + +KisGradientSegment::SphereDecreasingInterpolationStrategy *KisGradientSegment::SphereDecreasingInterpolationStrategy::instance() +{ + if (m_instance == 0) { + m_instance = new SphereDecreasingInterpolationStrategy(); + TQ_CHECK_PTR(m_instance); + } + + return m_instance; +} + +double KisGradientSegment::SphereDecreasingInterpolationStrategy::valueAt(double t, double middle) const +{ + double lt = LinearInterpolationStrategy::calcValueAt(t, middle); + double value = 1 - sqrt(1 - lt * lt); + + return value; +} + +#include "kis_gradient.moc" + diff --git a/chalk/core/kis_gradient_painter.cc b/chalk/core/kis_gradient_painter.cpp similarity index 100% rename from chalk/core/kis_gradient_painter.cc rename to chalk/core/kis_gradient_painter.cpp diff --git a/chalk/core/kis_group_layer.cc b/chalk/core/kis_group_layer.cpp similarity index 100% rename from chalk/core/kis_group_layer.cc rename to chalk/core/kis_group_layer.cpp diff --git a/chalk/core/kis_histogram.cc b/chalk/core/kis_histogram.cpp similarity index 100% rename from chalk/core/kis_histogram.cc rename to chalk/core/kis_histogram.cpp diff --git a/chalk/core/kis_image.cc b/chalk/core/kis_image.cpp similarity index 100% rename from chalk/core/kis_image.cc rename to chalk/core/kis_image.cpp diff --git a/chalk/core/kis_image_iface.cc b/chalk/core/kis_image_iface.cpp similarity index 100% rename from chalk/core/kis_image_iface.cc rename to chalk/core/kis_image_iface.cpp diff --git a/chalk/core/kis_imagepipe_brush.cc b/chalk/core/kis_imagepipe_brush.cpp similarity index 100% rename from chalk/core/kis_imagepipe_brush.cc rename to chalk/core/kis_imagepipe_brush.cpp diff --git a/chalk/core/kis_iterator.cc b/chalk/core/kis_iterator.cpp similarity index 100% rename from chalk/core/kis_iterator.cc rename to chalk/core/kis_iterator.cpp diff --git a/chalk/core/kis_iterators_pixel.cc b/chalk/core/kis_iterators_pixel.cpp similarity index 100% rename from chalk/core/kis_iterators_pixel.cc rename to chalk/core/kis_iterators_pixel.cpp diff --git a/chalk/core/kis_layer.cc b/chalk/core/kis_layer.cpp similarity index 100% rename from chalk/core/kis_layer.cc rename to chalk/core/kis_layer.cpp diff --git a/chalk/core/kis_meta_registry.cc b/chalk/core/kis_meta_registry.cpp similarity index 100% rename from chalk/core/kis_meta_registry.cc rename to chalk/core/kis_meta_registry.cpp diff --git a/chalk/core/kis_nameserver.cc b/chalk/core/kis_nameserver.cpp similarity index 100% rename from chalk/core/kis_nameserver.cc rename to chalk/core/kis_nameserver.cpp diff --git a/chalk/core/kis_paint_device.cc b/chalk/core/kis_paint_device.cpp similarity index 100% rename from chalk/core/kis_paint_device.cc rename to chalk/core/kis_paint_device.cpp diff --git a/chalk/core/kis_paint_device_iface.cc b/chalk/core/kis_paint_device_iface.cpp similarity index 100% rename from chalk/core/kis_paint_device_iface.cc rename to chalk/core/kis_paint_device_iface.cpp diff --git a/chalk/core/kis_paint_layer.cc b/chalk/core/kis_paint_layer.cpp similarity index 100% rename from chalk/core/kis_paint_layer.cc rename to chalk/core/kis_paint_layer.cpp diff --git a/chalk/core/kis_painter.cc b/chalk/core/kis_painter.cpp similarity index 100% rename from chalk/core/kis_painter.cc rename to chalk/core/kis_painter.cpp diff --git a/chalk/core/kis_paintop.cc b/chalk/core/kis_paintop.cpp similarity index 100% rename from chalk/core/kis_paintop.cc rename to chalk/core/kis_paintop.cpp diff --git a/chalk/core/kis_paintop_registry.cc b/chalk/core/kis_paintop_registry.cpp similarity index 100% rename from chalk/core/kis_paintop_registry.cc rename to chalk/core/kis_paintop_registry.cpp diff --git a/chalk/core/kis_palette.cc b/chalk/core/kis_palette.cpp similarity index 100% rename from chalk/core/kis_palette.cc rename to chalk/core/kis_palette.cpp diff --git a/chalk/core/kis_pattern.cc b/chalk/core/kis_pattern.cc deleted file mode 100644 index 654449b80..000000000 --- a/chalk/core/kis_pattern.cc +++ /dev/null @@ -1,335 +0,0 @@ -/* - * kis_pattern.cc - part of Krayon - * - * Copyright (c) 2000 Matthias Elter - * 2001 John Califf - * 2004 Boudewijn Rempt - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -#include "kis_pattern.h" - -#include -#include - -#include -#include - -#include -#include -#include -#include -#include -#include - -#include -#include - -#include "kis_color.h" -#include "kis_layer.h" -#include "kis_paint_device.h" - -namespace { - struct GimpPatternHeader { - TQ_UINT32 header_size; /* header_size = sizeof (PatternHeader) + brush name */ - TQ_UINT32 version; /* pattern file version # */ - TQ_UINT32 width; /* width of pattern */ - TQ_UINT32 height; /* height of pattern */ - TQ_UINT32 bytes; /* depth of pattern in bytes : 1, 2, 3 or 4*/ - TQ_UINT32 magic_number; /* GIMP brush magic number */ - }; - - // Yes! This is _NOT_ what my pat.txt file says. It's really not 'GIMP', but 'GPAT' - TQ_UINT32 const GimpPatternMagic = (('G' << 24) + ('P' << 16) + ('A' << 8) + ('T' << 0)); -} - -KisPattern::KisPattern(const TQString& file) : super(file), m_hasFile(true) -{ -} - -KisPattern::KisPattern(KisPaintDevice* image, int x, int y, int w, int h) - : super(""), m_hasFile(false) -{ - // Forcefully convert to RGBA8 - // XXX profile and exposure? - setImage(image->convertToTQImage(0, x, y, w, h)); - setName(image->name()); -} - -KisPattern::~KisPattern() -{ -} - -bool KisPattern::load() -{ - if (!m_hasFile) - return true; - - TQFile file(filename()); - file.open(IO_ReadOnly); - TQByteArray data = file.readAll(); - if (!data.isEmpty()) { - TQ_INT32 startPos = m_data.size(); - - m_data.resize(m_data.size() + data.count()); - memcpy(&m_data[startPos], data.data(), data.count()); - } - file.close(); - return init(); -} - -bool KisPattern::save() -{ - TQFile file(filename()); - file.open(IO_WriteOnly | IO_Truncate); - - TQTextStream stream(&file); - // Header: header_size (24+name length),version,width,height,colourdepth of brush,magic,name - // depth: 1 = greyscale, 2 = greyscale + A, 3 = RGB, 4 = RGBA - // magic = "GPAT", as a single uint32, the docs are wrong here! - // name is UTF-8 (\0-terminated! The docs say nothing about this!) - // _All_ data in network order, it seems! (not mentioned in gimp-2.2.8/devel-docs/pat.txt!!) - // We only save RGBA at the moment - // Version is 1 for now... - - GimpPatternHeader ph; - TQCString utf8Name = name().utf8(); - char const* name = utf8Name.data(); - int nameLength = tqstrlen(name); - - ph.header_size = htonl(sizeof(GimpPatternHeader) + nameLength + 1); // trailing 0 - ph.version = htonl(1); - ph.width = htonl(width()); - ph.height = htonl(height()); - ph.bytes = htonl(4); - ph.magic_number = htonl(GimpPatternMagic); - - TQByteArray bytes; - bytes.setRawData(reinterpret_cast(&ph), sizeof(GimpPatternHeader)); - int wrote = file.writeBlock(bytes); - bytes.resetRawData(reinterpret_cast(&ph), sizeof(GimpPatternHeader)); - - if (wrote == -1) - return false; - - wrote = file.writeBlock(name, nameLength + 1); // Trailing 0 apparantly! - if (wrote == -1) - return false; - - int k = 0; - bytes.resize(width() * height() * 4); - for (TQ_INT32 y = 0; y < height(); y++) { - for (TQ_INT32 x = 0; x < width(); x++) { - // RGBA only - TQRgb pixel = m_img.pixel(x,y); - bytes[k++] = static_cast(tqRed(pixel)); - bytes[k++] = static_cast(tqGreen(pixel)); - bytes[k++] = static_cast(tqBlue(pixel)); - bytes[k++] = static_cast(tqAlpha(pixel)); - } - } - - wrote = file.writeBlock(bytes); - if (wrote == -1) - return false; - - file.close(); - - return true; -} - -TQImage KisPattern::img() -{ - return m_img; -} - -bool KisPattern::init() -{ - // load Gimp patterns - GimpPatternHeader bh; - TQ_INT32 k; - TQValueVector name; - - if (sizeof(GimpPatternHeader) > m_data.size()) { - return false; - } - - memcpy(&bh, &m_data[0], sizeof(GimpPatternHeader)); - bh.header_size = ntohl(bh.header_size); - bh.version = ntohl(bh.version); - bh.width = ntohl(bh.width); - bh.height = ntohl(bh.height); - bh.bytes = ntohl(bh.bytes); - bh.magic_number = ntohl(bh.magic_number); - - if (bh.header_size > m_data.size() || bh.header_size == 0) { - return false; - } - - name.resize(bh.header_size - sizeof(GimpPatternHeader)); - memcpy(&name[0], &m_data[sizeof(GimpPatternHeader)], name.size()); - - if (name[name.size() - 1]) { - return false; - } - - setName(i18n(&name[0])); - - if (bh.width == 0 || bh.height == 0 || !m_img.create(bh.width, bh.height, 32)) { - return false; - } - - k = bh.header_size; - - if (bh.bytes == 1) { - // Grayscale - TQ_INT32 val; - - for (TQ_UINT32 y = 0; y < bh.height; y++) { - for (TQ_UINT32 x = 0; x < bh.width; x++, k++) { - if (static_cast(k) > m_data.size()) { - kdDebug(DBG_AREA_FILE) << "failed in gray\n"; - return false; - } - - val = m_data[k]; - m_img.setPixel(x, y, tqRgb(val, val, val)); - m_img.setAlphaBuffer(false); - } - } - } else if (bh.bytes == 2) { - // Grayscale + A - TQ_INT32 val; - TQ_INT32 alpha; - for (TQ_UINT32 y = 0; y < bh.height; y++) { - for (TQ_UINT32 x = 0; x < bh.width; x++, k++) { - if (static_cast(k + 2) > m_data.size()) { - kdDebug(DBG_AREA_FILE) << "failed in grayA\n"; - return false; - } - - val = m_data[k]; - alpha = m_data[k++]; - m_img.setPixel(x, y, tqRgba(val, val, val, alpha)); - m_img.setAlphaBuffer(true); - } - } - } else if (bh.bytes == 3) { - // RGB without alpha - for (TQ_UINT32 y = 0; y < bh.height; y++) { - for (TQ_UINT32 x = 0; x < bh.width; x++) { - if (static_cast(k + 3) > m_data.size()) { - kdDebug(DBG_AREA_FILE) << "failed in RGB\n"; - return false; - } - - m_img.setPixel(x, y, tqRgb(m_data[k], - m_data[k + 1], - m_data[k + 2])); - k += 3; - m_img.setAlphaBuffer(false); - } - } - } else if (bh.bytes == 4) { - // Has alpha - for (TQ_UINT32 y = 0; y < bh.height; y++) { - for (TQ_UINT32 x = 0; x < bh.width; x++) { - if (static_cast(k + 4) > m_data.size()) { - kdDebug(DBG_AREA_FILE) << "failed in RGBA\n"; - return false; - } - - m_img.setPixel(x, y, tqRgba(m_data[k], - m_data[k + 1], - m_data[k + 2], - m_data[k + 3])); - k += 4; - m_img.setAlphaBuffer(true); - } - } - } else { - return false; - } - - if (m_img.isNull()) { - return false; - } - - setWidth(m_img.width()); - setHeight(m_img.height()); - - setValid(true); - - return true; -} - -KisPaintDeviceSP KisPattern::image(KisColorSpace * colorSpace) { - // Check if there's already a pattern prepared for this colorspace - TQMap::const_iterator it = m_colorspaces.find(colorSpace->id().id()); - if (it != m_colorspaces.end()) - return (*it); - - // If not, create one - KisPaintDeviceSP layer = new KisPaintDevice(colorSpace, "pattern"); - - TQ_CHECK_PTR(layer); - - layer->convertFromTQImage(m_img,""); - - m_colorspaces[colorSpace->id().id()] = layer; - return layer; -} - -TQ_INT32 KisPattern::width() const -{ - return m_width; -} - -void KisPattern::setWidth(TQ_INT32 w) -{ - m_width = w; -} - -TQ_INT32 KisPattern::height() const -{ - return m_height; -} - -void KisPattern::setHeight(TQ_INT32 h) -{ - m_height = h; -} - -void KisPattern::setImage(const TQImage& img) -{ - m_hasFile = false; - m_img = img; - m_img.detach(); - - setWidth(img.width()); - setHeight(img.height()); - - setValid(true); -} - -KisPattern* KisPattern::clone() const -{ - KisPattern* pattern = new KisPattern(""); - pattern->setImage(m_img); - pattern->setName(name()); - return pattern; -} - -#include "kis_pattern.moc" diff --git a/chalk/core/kis_pattern.cpp b/chalk/core/kis_pattern.cpp new file mode 100644 index 000000000..b2a529958 --- /dev/null +++ b/chalk/core/kis_pattern.cpp @@ -0,0 +1,335 @@ +/* + * kis_pattern.cpp - part of Krayon + * + * Copyright (c) 2000 Matthias Elter + * 2001 John Califf + * 2004 Boudewijn Rempt + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +#include "kis_pattern.h" + +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "kis_color.h" +#include "kis_layer.h" +#include "kis_paint_device.h" + +namespace { + struct GimpPatternHeader { + TQ_UINT32 header_size; /* header_size = sizeof (PatternHeader) + brush name */ + TQ_UINT32 version; /* pattern file version # */ + TQ_UINT32 width; /* width of pattern */ + TQ_UINT32 height; /* height of pattern */ + TQ_UINT32 bytes; /* depth of pattern in bytes : 1, 2, 3 or 4*/ + TQ_UINT32 magic_number; /* GIMP brush magic number */ + }; + + // Yes! This is _NOT_ what my pat.txt file says. It's really not 'GIMP', but 'GPAT' + TQ_UINT32 const GimpPatternMagic = (('G' << 24) + ('P' << 16) + ('A' << 8) + ('T' << 0)); +} + +KisPattern::KisPattern(const TQString& file) : super(file), m_hasFile(true) +{ +} + +KisPattern::KisPattern(KisPaintDevice* image, int x, int y, int w, int h) + : super(""), m_hasFile(false) +{ + // Forcefully convert to RGBA8 + // XXX profile and exposure? + setImage(image->convertToTQImage(0, x, y, w, h)); + setName(image->name()); +} + +KisPattern::~KisPattern() +{ +} + +bool KisPattern::load() +{ + if (!m_hasFile) + return true; + + TQFile file(filename()); + file.open(IO_ReadOnly); + TQByteArray data = file.readAll(); + if (!data.isEmpty()) { + TQ_INT32 startPos = m_data.size(); + + m_data.resize(m_data.size() + data.count()); + memcpy(&m_data[startPos], data.data(), data.count()); + } + file.close(); + return init(); +} + +bool KisPattern::save() +{ + TQFile file(filename()); + file.open(IO_WriteOnly | IO_Truncate); + + TQTextStream stream(&file); + // Header: header_size (24+name length),version,width,height,colourdepth of brush,magic,name + // depth: 1 = greyscale, 2 = greyscale + A, 3 = RGB, 4 = RGBA + // magic = "GPAT", as a single uint32, the docs are wrong here! + // name is UTF-8 (\0-terminated! The docs say nothing about this!) + // _All_ data in network order, it seems! (not mentioned in gimp-2.2.8/devel-docs/pat.txt!!) + // We only save RGBA at the moment + // Version is 1 for now... + + GimpPatternHeader ph; + TQCString utf8Name = name().utf8(); + char const* name = utf8Name.data(); + int nameLength = tqstrlen(name); + + ph.header_size = htonl(sizeof(GimpPatternHeader) + nameLength + 1); // trailing 0 + ph.version = htonl(1); + ph.width = htonl(width()); + ph.height = htonl(height()); + ph.bytes = htonl(4); + ph.magic_number = htonl(GimpPatternMagic); + + TQByteArray bytes; + bytes.setRawData(reinterpret_cast(&ph), sizeof(GimpPatternHeader)); + int wrote = file.writeBlock(bytes); + bytes.resetRawData(reinterpret_cast(&ph), sizeof(GimpPatternHeader)); + + if (wrote == -1) + return false; + + wrote = file.writeBlock(name, nameLength + 1); // Trailing 0 apparantly! + if (wrote == -1) + return false; + + int k = 0; + bytes.resize(width() * height() * 4); + for (TQ_INT32 y = 0; y < height(); y++) { + for (TQ_INT32 x = 0; x < width(); x++) { + // RGBA only + TQRgb pixel = m_img.pixel(x,y); + bytes[k++] = static_cast(tqRed(pixel)); + bytes[k++] = static_cast(tqGreen(pixel)); + bytes[k++] = static_cast(tqBlue(pixel)); + bytes[k++] = static_cast(tqAlpha(pixel)); + } + } + + wrote = file.writeBlock(bytes); + if (wrote == -1) + return false; + + file.close(); + + return true; +} + +TQImage KisPattern::img() +{ + return m_img; +} + +bool KisPattern::init() +{ + // load Gimp patterns + GimpPatternHeader bh; + TQ_INT32 k; + TQValueVector name; + + if (sizeof(GimpPatternHeader) > m_data.size()) { + return false; + } + + memcpy(&bh, &m_data[0], sizeof(GimpPatternHeader)); + bh.header_size = ntohl(bh.header_size); + bh.version = ntohl(bh.version); + bh.width = ntohl(bh.width); + bh.height = ntohl(bh.height); + bh.bytes = ntohl(bh.bytes); + bh.magic_number = ntohl(bh.magic_number); + + if (bh.header_size > m_data.size() || bh.header_size == 0) { + return false; + } + + name.resize(bh.header_size - sizeof(GimpPatternHeader)); + memcpy(&name[0], &m_data[sizeof(GimpPatternHeader)], name.size()); + + if (name[name.size() - 1]) { + return false; + } + + setName(i18n(&name[0])); + + if (bh.width == 0 || bh.height == 0 || !m_img.create(bh.width, bh.height, 32)) { + return false; + } + + k = bh.header_size; + + if (bh.bytes == 1) { + // Grayscale + TQ_INT32 val; + + for (TQ_UINT32 y = 0; y < bh.height; y++) { + for (TQ_UINT32 x = 0; x < bh.width; x++, k++) { + if (static_cast(k) > m_data.size()) { + kdDebug(DBG_AREA_FILE) << "failed in gray\n"; + return false; + } + + val = m_data[k]; + m_img.setPixel(x, y, tqRgb(val, val, val)); + m_img.setAlphaBuffer(false); + } + } + } else if (bh.bytes == 2) { + // Grayscale + A + TQ_INT32 val; + TQ_INT32 alpha; + for (TQ_UINT32 y = 0; y < bh.height; y++) { + for (TQ_UINT32 x = 0; x < bh.width; x++, k++) { + if (static_cast(k + 2) > m_data.size()) { + kdDebug(DBG_AREA_FILE) << "failed in grayA\n"; + return false; + } + + val = m_data[k]; + alpha = m_data[k++]; + m_img.setPixel(x, y, tqRgba(val, val, val, alpha)); + m_img.setAlphaBuffer(true); + } + } + } else if (bh.bytes == 3) { + // RGB without alpha + for (TQ_UINT32 y = 0; y < bh.height; y++) { + for (TQ_UINT32 x = 0; x < bh.width; x++) { + if (static_cast(k + 3) > m_data.size()) { + kdDebug(DBG_AREA_FILE) << "failed in RGB\n"; + return false; + } + + m_img.setPixel(x, y, tqRgb(m_data[k], + m_data[k + 1], + m_data[k + 2])); + k += 3; + m_img.setAlphaBuffer(false); + } + } + } else if (bh.bytes == 4) { + // Has alpha + for (TQ_UINT32 y = 0; y < bh.height; y++) { + for (TQ_UINT32 x = 0; x < bh.width; x++) { + if (static_cast(k + 4) > m_data.size()) { + kdDebug(DBG_AREA_FILE) << "failed in RGBA\n"; + return false; + } + + m_img.setPixel(x, y, tqRgba(m_data[k], + m_data[k + 1], + m_data[k + 2], + m_data[k + 3])); + k += 4; + m_img.setAlphaBuffer(true); + } + } + } else { + return false; + } + + if (m_img.isNull()) { + return false; + } + + setWidth(m_img.width()); + setHeight(m_img.height()); + + setValid(true); + + return true; +} + +KisPaintDeviceSP KisPattern::image(KisColorSpace * colorSpace) { + // Check if there's already a pattern prepared for this colorspace + TQMap::const_iterator it = m_colorspaces.find(colorSpace->id().id()); + if (it != m_colorspaces.end()) + return (*it); + + // If not, create one + KisPaintDeviceSP layer = new KisPaintDevice(colorSpace, "pattern"); + + TQ_CHECK_PTR(layer); + + layer->convertFromTQImage(m_img,""); + + m_colorspaces[colorSpace->id().id()] = layer; + return layer; +} + +TQ_INT32 KisPattern::width() const +{ + return m_width; +} + +void KisPattern::setWidth(TQ_INT32 w) +{ + m_width = w; +} + +TQ_INT32 KisPattern::height() const +{ + return m_height; +} + +void KisPattern::setHeight(TQ_INT32 h) +{ + m_height = h; +} + +void KisPattern::setImage(const TQImage& img) +{ + m_hasFile = false; + m_img = img; + m_img.detach(); + + setWidth(img.width()); + setHeight(img.height()); + + setValid(true); +} + +KisPattern* KisPattern::clone() const +{ + KisPattern* pattern = new KisPattern(""); + pattern->setImage(m_img); + pattern->setName(name()); + return pattern; +} + +#include "kis_pattern.moc" diff --git a/chalk/core/kis_rect.cc b/chalk/core/kis_rect.cpp similarity index 100% rename from chalk/core/kis_rect.cc rename to chalk/core/kis_rect.cpp diff --git a/chalk/core/kis_resource.cc b/chalk/core/kis_resource.cpp similarity index 100% rename from chalk/core/kis_resource.cc rename to chalk/core/kis_resource.cpp diff --git a/chalk/core/kis_rotate_visitor.cc b/chalk/core/kis_rotate_visitor.cpp similarity index 100% rename from chalk/core/kis_rotate_visitor.cc rename to chalk/core/kis_rotate_visitor.cpp diff --git a/chalk/core/kis_scale_visitor.cc b/chalk/core/kis_scale_visitor.cpp similarity index 100% rename from chalk/core/kis_scale_visitor.cc rename to chalk/core/kis_scale_visitor.cpp diff --git a/chalk/core/kis_selected_transaction.cc b/chalk/core/kis_selected_transaction.cpp similarity index 100% rename from chalk/core/kis_selected_transaction.cc rename to chalk/core/kis_selected_transaction.cpp diff --git a/chalk/core/kis_selection.cc b/chalk/core/kis_selection.cpp similarity index 100% rename from chalk/core/kis_selection.cc rename to chalk/core/kis_selection.cpp diff --git a/chalk/core/kis_strategy_move.cc b/chalk/core/kis_strategy_move.cpp similarity index 100% rename from chalk/core/kis_strategy_move.cc rename to chalk/core/kis_strategy_move.cpp diff --git a/chalk/core/kis_thread_pool.cc b/chalk/core/kis_thread_pool.cpp similarity index 100% rename from chalk/core/kis_thread_pool.cc rename to chalk/core/kis_thread_pool.cpp diff --git a/chalk/core/kis_transaction.cc b/chalk/core/kis_transaction.cpp similarity index 100% rename from chalk/core/kis_transaction.cc rename to chalk/core/kis_transaction.cpp diff --git a/chalk/core/kis_transform_worker.cc b/chalk/core/kis_transform_worker.cpp similarity index 100% rename from chalk/core/kis_transform_worker.cc rename to chalk/core/kis_transform_worker.cpp diff --git a/chalk/core/kis_vec.cc b/chalk/core/kis_vec.cc deleted file mode 100644 index fa54e1f90..000000000 --- a/chalk/core/kis_vec.cc +++ /dev/null @@ -1,67 +0,0 @@ -/* - * kis_vec.cc - part of KImageShop - * - * Copyright (c) 1999 Matthias Elter - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include "kis_vec.h" - -KisVector2D& KisVector2D::normalize() -{ - double length, ilength; - - length = m_x*m_x + m_y*m_y; - length = sqrt (length); - - if (length > epsilon) - { - ilength = 1/length; - m_x *= ilength; - m_y *= ilength; - } - return *this; -} - -KisVector3D& KisVector3D::normalize() -{ - double length, ilength; - - length = m_x*m_x + m_y*m_y + m_z*m_z; - length = sqrt (length); - - if (length > epsilon) - { - ilength = 1/length; - m_x *= ilength; - m_y *= ilength; - m_z *= ilength; - } - return *this; -} - -KisVector3D& KisVector3D::crossProduct(const KisVector3D &v) -{ - double x,y,z; - - x = m_y*v.m_z - m_z*v.m_y; - y = m_z*v.m_x - m_x*v.m_z; - z = m_x*v.m_y - m_y*v.m_x; - m_x=x; m_y=y; m_z=z; - - return *this; -} - diff --git a/chalk/core/kis_vec.cpp b/chalk/core/kis_vec.cpp new file mode 100644 index 000000000..9bd6ada9f --- /dev/null +++ b/chalk/core/kis_vec.cpp @@ -0,0 +1,67 @@ +/* + * kis_vec.cpp - part of KImageShop + * + * Copyright (c) 1999 Matthias Elter + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "kis_vec.h" + +KisVector2D& KisVector2D::normalize() +{ + double length, ilength; + + length = m_x*m_x + m_y*m_y; + length = sqrt (length); + + if (length > epsilon) + { + ilength = 1/length; + m_x *= ilength; + m_y *= ilength; + } + return *this; +} + +KisVector3D& KisVector3D::normalize() +{ + double length, ilength; + + length = m_x*m_x + m_y*m_y + m_z*m_z; + length = sqrt (length); + + if (length > epsilon) + { + ilength = 1/length; + m_x *= ilength; + m_y *= ilength; + m_z *= ilength; + } + return *this; +} + +KisVector3D& KisVector3D::crossProduct(const KisVector3D &v) +{ + double x,y,z; + + x = m_y*v.m_z - m_z*v.m_y; + y = m_z*v.m_x - m_x*v.m_z; + z = m_x*v.m_y - m_y*v.m_x; + m_x=x; m_y=y; m_z=z; + + return *this; +} + diff --git a/chalk/core/tests/Makefile.am b/chalk/core/tests/Makefile.am index 973166855..9b78866a8 100644 --- a/chalk/core/tests/Makefile.am +++ b/chalk/core/tests/Makefile.am @@ -21,7 +21,7 @@ tdeunittest_kis_image_tester_la_LIBADD = -ltdeunittest ../../libchalkcommon.la tdeunittest_kis_image_tester_la_LDFLAGS = -module $(KDE_CHECK_PLUGIN) $(all_libraries) -tdeunittest_kis_filter_configuration_tester_la_SOURCES = kis_filter_configuration_tester.cc +tdeunittest_kis_filter_configuration_tester_la_SOURCES = kis_filter_configuration_tester.cpp tdeunittest_kis_filter_configuration_tester_la_LIBADD = -ltdeunittest ../../libchalkcommon.la tdeunittest_kis_filter_configuration_tester_la_LDFLAGS = -module $(KDE_CHECK_PLUGIN) $(all_libraries) diff --git a/chalk/core/tests/kis_filter_configuration_tester.cc b/chalk/core/tests/kis_filter_configuration_tester.cpp similarity index 100% rename from chalk/core/tests/kis_filter_configuration_tester.cc rename to chalk/core/tests/kis_filter_configuration_tester.cpp diff --git a/chalk/core/tiles/Makefile.am b/chalk/core/tiles/Makefile.am index 7fad1ab90..9ebe93ec2 100644 --- a/chalk/core/tiles/Makefile.am +++ b/chalk/core/tiles/Makefile.am @@ -12,9 +12,9 @@ INCLUDES = -I$(srcdir)/../ \ noinst_LTLIBRARIES = libchalktile.la -libchalktile_la_SOURCES = kis_tiledvlineiterator.cc kis_tiledhlineiterator.cc \ - kis_tileddatamanager.cc kis_tile.cc kis_tilediterator.cc kis_tiledrectiterator.cc \ - kis_memento.cc kis_tilemanager.cc kis_tiled_random_accessor.cc +libchalktile_la_SOURCES = kis_tiledvlineiterator.cpp kis_tiledhlineiterator.cpp \ + kis_tileddatamanager.cpp kis_tile.cpp kis_tilediterator.cpp kis_tiledrectiterator.cpp \ + kis_memento.cpp kis_tilemanager.cpp kis_tiled_random_accessor.cpp libchalktile_la_METASOURCES = AUTO diff --git a/chalk/core/tiles/kis_memento.cc b/chalk/core/tiles/kis_memento.cpp similarity index 100% rename from chalk/core/tiles/kis_memento.cc rename to chalk/core/tiles/kis_memento.cpp diff --git a/chalk/core/tiles/kis_tile.cc b/chalk/core/tiles/kis_tile.cpp similarity index 100% rename from chalk/core/tiles/kis_tile.cc rename to chalk/core/tiles/kis_tile.cpp diff --git a/chalk/core/tiles/kis_tiled_random_accessor.cc b/chalk/core/tiles/kis_tiled_random_accessor.cpp similarity index 100% rename from chalk/core/tiles/kis_tiled_random_accessor.cc rename to chalk/core/tiles/kis_tiled_random_accessor.cpp diff --git a/chalk/core/tiles/kis_tileddatamanager.cc b/chalk/core/tiles/kis_tileddatamanager.cpp similarity index 100% rename from chalk/core/tiles/kis_tileddatamanager.cc rename to chalk/core/tiles/kis_tileddatamanager.cpp diff --git a/chalk/core/tiles/kis_tiledhlineiterator.cc b/chalk/core/tiles/kis_tiledhlineiterator.cpp similarity index 100% rename from chalk/core/tiles/kis_tiledhlineiterator.cc rename to chalk/core/tiles/kis_tiledhlineiterator.cpp diff --git a/chalk/core/tiles/kis_tilediterator.cc b/chalk/core/tiles/kis_tilediterator.cpp similarity index 100% rename from chalk/core/tiles/kis_tilediterator.cc rename to chalk/core/tiles/kis_tilediterator.cpp diff --git a/chalk/core/tiles/kis_tiledrectiterator.cc b/chalk/core/tiles/kis_tiledrectiterator.cpp similarity index 100% rename from chalk/core/tiles/kis_tiledrectiterator.cc rename to chalk/core/tiles/kis_tiledrectiterator.cpp diff --git a/chalk/core/tiles/kis_tiledvlineiterator.cc b/chalk/core/tiles/kis_tiledvlineiterator.cpp similarity index 100% rename from chalk/core/tiles/kis_tiledvlineiterator.cc rename to chalk/core/tiles/kis_tiledvlineiterator.cpp diff --git a/chalk/core/tiles/kis_tilemanager.cc b/chalk/core/tiles/kis_tilemanager.cpp similarity index 100% rename from chalk/core/tiles/kis_tilemanager.cc rename to chalk/core/tiles/kis_tilemanager.cpp diff --git a/chalk/doc/DESIGN.obsolete b/chalk/doc/DESIGN.obsolete index a1b8e58d4..2f0d25ca6 100644 --- a/chalk/doc/DESIGN.obsolete +++ b/chalk/doc/DESIGN.obsolete @@ -169,7 +169,7 @@ Random head-scratchings - I take it that the two tests that are present in chalk/test are obsolete? - - what with the dummmmmy.cc? + - what with the dummmmmy.cpp? - which bits of the chalk/ui files are still relevant? diff --git a/chalk/doc/brush.txt b/chalk/doc/brush.txt index e2373258f..afadadc5b 100644 --- a/chalk/doc/brush.txt +++ b/chalk/doc/brush.txt @@ -4,7 +4,7 @@ Painting with brushes when I started working on Chalk, I felt I needed examples. I used the following sources: -* The old Chalk brush code (http://webcvs.kde.org/cgi-bin/cvsweb.cgi/koffice/chalk/tools/kis_tool_brush.cc?rev=1.58&content-type=text/x-cvsweb-markup) +* The old Chalk brush code (http://webcvs.kde.org/cgi-bin/cvsweb.cgi/koffice/chalk/tools/kis_tool_brush.cpp?rev=1.58&content-type=text/x-cvsweb-markup) * Peter Jodda's Perico (http://software.jodda.de/perico.html) * The source of the Gimp (both current and 0.99.11 -- the oldest version I could find) (http://www.gimp.org) * David Hodson's article on Gimp brushes (http://members.ozemail.com.au/~hodsond/gimpbrush.html) diff --git a/chalk/main.cc b/chalk/main.cc deleted file mode 100644 index 592c1368f..000000000 --- a/chalk/main.cc +++ /dev/null @@ -1,43 +0,0 @@ -/* - * main.cc - part of KImageShop - * - * Copyright (c) 1999 Matthias Elter - * Copyright (c) 2002 Patrick Julien - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - */ -#include -#include -#include - -#include "ui/kis_aboutdata.h" - -static const TDECmdLineOptions options[] = { - { "+[file(s)]", I18N_NOOP("File(s) or URL(s) to open"), 0 }, - TDECmdLineLastOption -}; - -extern "C" KRITA_EXPORT int kdemain(int argc, char **argv) -{ - TDECmdLineArgs::init(argc, argv, newChalkAboutData()); - TDECmdLineArgs::addCmdLineOptions(options); - - KoApplication app; - - if (!app.start()) - return 1; - - return app.exec(); -} - diff --git a/chalk/main.cpp b/chalk/main.cpp new file mode 100644 index 000000000..6d6b1781f --- /dev/null +++ b/chalk/main.cpp @@ -0,0 +1,43 @@ +/* + * main.cpp - part of KImageShop + * + * Copyright (c) 1999 Matthias Elter + * Copyright (c) 2002 Patrick Julien + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + */ +#include +#include +#include + +#include "ui/kis_aboutdata.h" + +static const TDECmdLineOptions options[] = { + { "+[file(s)]", I18N_NOOP("File(s) or URL(s) to open"), 0 }, + TDECmdLineLastOption +}; + +extern "C" KRITA_EXPORT int kdemain(int argc, char **argv) +{ + TDECmdLineArgs::init(argc, argv, newChalkAboutData()); + TDECmdLineArgs::addCmdLineOptions(options); + + KoApplication app; + + if (!app.start()) + return 1; + + return app.exec(); +} + diff --git a/chalk/plugins/filters/blur/Makefile.am b/chalk/plugins/filters/blur/Makefile.am index d4de75452..53f86c330 100644 --- a/chalk/plugins/filters/blur/Makefile.am +++ b/chalk/plugins/filters/blur/Makefile.am @@ -9,7 +9,7 @@ INCLUDES = -I$(srcdir)/../../../sdk \ $(KOFFICE_INCLUDES) \ $(all_includes) -chalkblurfilter_la_SOURCES = wdgblur.ui blur.cc kis_blur_filter.cc kis_wdg_blur.cc +chalkblurfilter_la_SOURCES = wdgblur.ui blur.cpp kis_blur_filter.cpp kis_wdg_blur.cpp kde_module_LTLIBRARIES = chalkblurfilter.la noinst_HEADERS = blur.h kis_blur_filter.h diff --git a/chalk/plugins/filters/blur/blur.cc b/chalk/plugins/filters/blur/blur.cpp similarity index 100% rename from chalk/plugins/filters/blur/blur.cc rename to chalk/plugins/filters/blur/blur.cpp diff --git a/chalk/plugins/filters/blur/kis_blur_filter.cc b/chalk/plugins/filters/blur/kis_blur_filter.cpp similarity index 100% rename from chalk/plugins/filters/blur/kis_blur_filter.cc rename to chalk/plugins/filters/blur/kis_blur_filter.cpp diff --git a/chalk/plugins/filters/blur/kis_wdg_blur.cc b/chalk/plugins/filters/blur/kis_wdg_blur.cpp similarity index 100% rename from chalk/plugins/filters/blur/kis_wdg_blur.cc rename to chalk/plugins/filters/blur/kis_wdg_blur.cpp diff --git a/chalk/plugins/filters/bumpmap/Makefile.am b/chalk/plugins/filters/bumpmap/Makefile.am index 2b208b33e..9f003aa3e 100644 --- a/chalk/plugins/filters/bumpmap/Makefile.am +++ b/chalk/plugins/filters/bumpmap/Makefile.am @@ -7,7 +7,7 @@ INCLUDES = -I$(srcdir)/../../../sdk \ -I$(srcdir)/../../../../lib/kofficecore \ $(all_includes) -chalkbumpmap_la_SOURCES = bumpmap.cc wdgbumpmap.ui +chalkbumpmap_la_SOURCES = bumpmap.cpp wdgbumpmap.ui kde_module_LTLIBRARIES = chalkbumpmap.la noinst_HEADERS = bumpmap.h diff --git a/chalk/plugins/filters/bumpmap/bumpmap.cc b/chalk/plugins/filters/bumpmap/bumpmap.cpp similarity index 100% rename from chalk/plugins/filters/bumpmap/bumpmap.cc rename to chalk/plugins/filters/bumpmap/bumpmap.cpp diff --git a/chalk/plugins/filters/cimg/Makefile.am b/chalk/plugins/filters/cimg/Makefile.am index 4a180a28d..d82def816 100644 --- a/chalk/plugins/filters/cimg/Makefile.am +++ b/chalk/plugins/filters/cimg/Makefile.am @@ -12,9 +12,9 @@ INCLUDES = -I$(srcdir)/../../../sdk \ chalkcimg_la_SOURCES = \ wdg_cimg.ui\ - kis_cimg_filter.cc\ - kis_cimg_plugin.cc\ - kis_cimgconfig_widget.cc + kis_cimg_filter.cpp\ + kis_cimg_plugin.cpp\ + kis_cimgconfig_widget.cpp # Install this plugin in the KDE modules directory kde_module_LTLIBRARIES = chalkcimg.la diff --git a/chalk/plugins/filters/cimg/kis_cimg_filter.cc b/chalk/plugins/filters/cimg/kis_cimg_filter.cpp similarity index 100% rename from chalk/plugins/filters/cimg/kis_cimg_filter.cc rename to chalk/plugins/filters/cimg/kis_cimg_filter.cpp diff --git a/chalk/plugins/filters/cimg/kis_cimg_plugin.cc b/chalk/plugins/filters/cimg/kis_cimg_plugin.cpp similarity index 100% rename from chalk/plugins/filters/cimg/kis_cimg_plugin.cc rename to chalk/plugins/filters/cimg/kis_cimg_plugin.cpp diff --git a/chalk/plugins/filters/cimg/kis_cimgconfig_widget.cc b/chalk/plugins/filters/cimg/kis_cimgconfig_widget.cpp similarity index 100% rename from chalk/plugins/filters/cimg/kis_cimgconfig_widget.cc rename to chalk/plugins/filters/cimg/kis_cimgconfig_widget.cpp diff --git a/chalk/plugins/filters/colors/Makefile.am b/chalk/plugins/filters/colors/Makefile.am index 293806496..8f54c2ed7 100644 --- a/chalk/plugins/filters/colors/Makefile.am +++ b/chalk/plugins/filters/colors/Makefile.am @@ -9,7 +9,7 @@ INCLUDES = -I$(srcdir)/../../../sdk \ $(KOFFICE_INCLUDES) \ $(all_includes) -chalkextensioncolorsfilters_la_SOURCES = colors.cc kis_minmax_filters.cc kis_color_to_alpha.cc wdgcolortoalphabase.ui kis_wdg_color_to_alpha.cc +chalkextensioncolorsfilters_la_SOURCES = colors.cpp kis_minmax_filters.cpp kis_color_to_alpha.cpp wdgcolortoalphabase.ui kis_wdg_color_to_alpha.cpp kde_module_LTLIBRARIES = chalkextensioncolorsfilters.la noinst_HEADERS = colors.h diff --git a/chalk/plugins/filters/colors/colors.cc b/chalk/plugins/filters/colors/colors.cpp similarity index 100% rename from chalk/plugins/filters/colors/colors.cc rename to chalk/plugins/filters/colors/colors.cpp diff --git a/chalk/plugins/filters/colors/kis_color_to_alpha.cc b/chalk/plugins/filters/colors/kis_color_to_alpha.cpp similarity index 100% rename from chalk/plugins/filters/colors/kis_color_to_alpha.cc rename to chalk/plugins/filters/colors/kis_color_to_alpha.cpp diff --git a/chalk/plugins/filters/colors/kis_minmax_filters.cc b/chalk/plugins/filters/colors/kis_minmax_filters.cpp similarity index 100% rename from chalk/plugins/filters/colors/kis_minmax_filters.cc rename to chalk/plugins/filters/colors/kis_minmax_filters.cpp diff --git a/chalk/plugins/filters/colors/kis_wdg_color_to_alpha.cc b/chalk/plugins/filters/colors/kis_wdg_color_to_alpha.cpp similarity index 100% rename from chalk/plugins/filters/colors/kis_wdg_color_to_alpha.cc rename to chalk/plugins/filters/colors/kis_wdg_color_to_alpha.cpp diff --git a/chalk/plugins/filters/colorsfilters/Makefile.am b/chalk/plugins/filters/colorsfilters/Makefile.am index 8e0be13e1..e7459d7d1 100644 --- a/chalk/plugins/filters/colorsfilters/Makefile.am +++ b/chalk/plugins/filters/colorsfilters/Makefile.am @@ -7,11 +7,11 @@ INCLUDES = -I$(srcdir)/../../../sdk \ $(KOFFICE_INCLUDES) \ $(all_includes) -chalkcolorsfilters_la_SOURCES = colorsfilters.cc \ - kis_perchannel_filter.cc \ +chalkcolorsfilters_la_SOURCES = colorsfilters.cpp \ + kis_perchannel_filter.cpp \ wdg_perchannel.ui \ wdg_brightness_contrast.ui \ - kis_brightness_contrast_filter.cc + kis_brightness_contrast_filter.cpp noinst_HEADERS = colorsfilters.h \ kis_perchannel_filter.h \ diff --git a/chalk/plugins/filters/colorsfilters/colorsfilters.cc b/chalk/plugins/filters/colorsfilters/colorsfilters.cpp similarity index 100% rename from chalk/plugins/filters/colorsfilters/colorsfilters.cc rename to chalk/plugins/filters/colorsfilters/colorsfilters.cpp diff --git a/chalk/plugins/filters/colorsfilters/kis_brightness_contrast_filter.cc b/chalk/plugins/filters/colorsfilters/kis_brightness_contrast_filter.cpp similarity index 100% rename from chalk/plugins/filters/colorsfilters/kis_brightness_contrast_filter.cc rename to chalk/plugins/filters/colorsfilters/kis_brightness_contrast_filter.cpp diff --git a/chalk/plugins/filters/colorsfilters/kis_perchannel_filter.cc b/chalk/plugins/filters/colorsfilters/kis_perchannel_filter.cpp similarity index 100% rename from chalk/plugins/filters/colorsfilters/kis_perchannel_filter.cc rename to chalk/plugins/filters/colorsfilters/kis_perchannel_filter.cpp diff --git a/chalk/plugins/filters/convolutionfilters/Makefile.am b/chalk/plugins/filters/convolutionfilters/Makefile.am index 6e4242f26..cd4582e94 100644 --- a/chalk/plugins/filters/convolutionfilters/Makefile.am +++ b/chalk/plugins/filters/convolutionfilters/Makefile.am @@ -12,10 +12,10 @@ INCLUDES = \ kde_module_LTLIBRARIES = chalkconvolutionfilters.la chalkconvolutionfilters_la_SOURCES = kis_custom_convolution_filter_configuration_base_widget.ui \ - kis_custom_convolution_filter_configuration_widget.cc \ - kis_custom_convolution_filter.cc \ - convolutionfilters.cc \ - kis_convolution_filter.cc + kis_custom_convolution_filter_configuration_widget.cpp \ + kis_custom_convolution_filter.cpp \ + convolutionfilters.cpp \ + kis_convolution_filter.cpp noinst_HEADERS = convolutionfilters.h \ kis_custom_convolution_filter_configuration_widget.h \ diff --git a/chalk/plugins/filters/convolutionfilters/convolutionfilters.cc b/chalk/plugins/filters/convolutionfilters/convolutionfilters.cpp similarity index 100% rename from chalk/plugins/filters/convolutionfilters/convolutionfilters.cc rename to chalk/plugins/filters/convolutionfilters/convolutionfilters.cpp diff --git a/chalk/plugins/filters/convolutionfilters/kis_convolution_filter.cc b/chalk/plugins/filters/convolutionfilters/kis_convolution_filter.cpp similarity index 100% rename from chalk/plugins/filters/convolutionfilters/kis_convolution_filter.cc rename to chalk/plugins/filters/convolutionfilters/kis_convolution_filter.cpp diff --git a/chalk/plugins/filters/convolutionfilters/kis_custom_convolution_filter.cc b/chalk/plugins/filters/convolutionfilters/kis_custom_convolution_filter.cpp similarity index 100% rename from chalk/plugins/filters/convolutionfilters/kis_custom_convolution_filter.cc rename to chalk/plugins/filters/convolutionfilters/kis_custom_convolution_filter.cpp diff --git a/chalk/plugins/filters/convolutionfilters/kis_custom_convolution_filter_configuration_widget.cc b/chalk/plugins/filters/convolutionfilters/kis_custom_convolution_filter_configuration_widget.cpp similarity index 100% rename from chalk/plugins/filters/convolutionfilters/kis_custom_convolution_filter_configuration_widget.cc rename to chalk/plugins/filters/convolutionfilters/kis_custom_convolution_filter_configuration_widget.cpp diff --git a/chalk/plugins/filters/cubismfilter/Makefile.am b/chalk/plugins/filters/cubismfilter/Makefile.am index e281360ed..a26a8e806 100644 --- a/chalk/plugins/filters/cubismfilter/Makefile.am +++ b/chalk/plugins/filters/cubismfilter/Makefile.am @@ -10,9 +10,9 @@ INCLUDES = \ kde_module_LTLIBRARIES = chalkcubismfilter.la -chalkcubismfilter_la_SOURCES = kis_cubism_filter_plugin.cc \ - kis_cubism_filter.cc \ - kis_polygon.cc +chalkcubismfilter_la_SOURCES = kis_cubism_filter_plugin.cpp \ + kis_cubism_filter.cpp \ + kis_polygon.cpp noinst_HEADERS = kis_cubism_filter_plugin.h \ kis_cubism_filter.h \ diff --git a/chalk/plugins/filters/cubismfilter/kis_cubism_filter.cc b/chalk/plugins/filters/cubismfilter/kis_cubism_filter.cpp similarity index 100% rename from chalk/plugins/filters/cubismfilter/kis_cubism_filter.cc rename to chalk/plugins/filters/cubismfilter/kis_cubism_filter.cpp diff --git a/chalk/plugins/filters/cubismfilter/kis_cubism_filter_plugin.cc b/chalk/plugins/filters/cubismfilter/kis_cubism_filter_plugin.cpp similarity index 100% rename from chalk/plugins/filters/cubismfilter/kis_cubism_filter_plugin.cc rename to chalk/plugins/filters/cubismfilter/kis_cubism_filter_plugin.cpp diff --git a/chalk/plugins/filters/cubismfilter/kis_polygon.cc b/chalk/plugins/filters/cubismfilter/kis_polygon.cpp similarity index 100% rename from chalk/plugins/filters/cubismfilter/kis_polygon.cc rename to chalk/plugins/filters/cubismfilter/kis_polygon.cpp diff --git a/chalk/plugins/filters/embossfilter/Makefile.am b/chalk/plugins/filters/embossfilter/Makefile.am index 8bb9cdeb1..69b5cb613 100644 --- a/chalk/plugins/filters/embossfilter/Makefile.am +++ b/chalk/plugins/filters/embossfilter/Makefile.am @@ -11,8 +11,8 @@ INCLUDES = \ kde_module_LTLIBRARIES = chalkembossfilter.la -chalkembossfilter_la_SOURCES = kis_emboss_filter_plugin.cc \ - kis_emboss_filter.cc +chalkembossfilter_la_SOURCES = kis_emboss_filter_plugin.cpp \ + kis_emboss_filter.cpp noinst_HEADERS = kis_emboss_filter_plugin.h \ kis_emboss_filter.h diff --git a/chalk/plugins/filters/embossfilter/kis_emboss_filter.cc b/chalk/plugins/filters/embossfilter/kis_emboss_filter.cpp similarity index 100% rename from chalk/plugins/filters/embossfilter/kis_emboss_filter.cc rename to chalk/plugins/filters/embossfilter/kis_emboss_filter.cpp diff --git a/chalk/plugins/filters/embossfilter/kis_emboss_filter_plugin.cc b/chalk/plugins/filters/embossfilter/kis_emboss_filter_plugin.cpp similarity index 100% rename from chalk/plugins/filters/embossfilter/kis_emboss_filter_plugin.cc rename to chalk/plugins/filters/embossfilter/kis_emboss_filter_plugin.cpp diff --git a/chalk/plugins/filters/example/Makefile.am b/chalk/plugins/filters/example/Makefile.am index fcb56751d..c39558f79 100644 --- a/chalk/plugins/filters/example/Makefile.am +++ b/chalk/plugins/filters/example/Makefile.am @@ -10,7 +10,7 @@ INCLUDES = -I$(srcdir)/../../../sdk \ $(KOFFICE_INCLUDES) \ $(all_includes) -chalkexample_la_SOURCES = example.cc +chalkexample_la_SOURCES = example.cpp kde_module_LTLIBRARIES = chalkexample.la noinst_HEADERS = example.h diff --git a/chalk/plugins/filters/example/example.cc b/chalk/plugins/filters/example/example.cpp similarity index 100% rename from chalk/plugins/filters/example/example.cc rename to chalk/plugins/filters/example/example.cpp diff --git a/chalk/plugins/filters/fastcolortransfer/Makefile.am b/chalk/plugins/filters/fastcolortransfer/Makefile.am index e923ce229..e9a171840 100644 --- a/chalk/plugins/filters/fastcolortransfer/Makefile.am +++ b/chalk/plugins/filters/fastcolortransfer/Makefile.am @@ -10,7 +10,7 @@ INCLUDES = -I$(srcdir)/../../../sdk \ $(KOFFICE_INCLUDES) \ $(all_includes) -chalkfastcolortransfer_la_SOURCES = wdgfastcolortransfer.ui fastcolortransfer.cc \ +chalkfastcolortransfer_la_SOURCES = wdgfastcolortransfer.ui fastcolortransfer.cpp \ kis_wdg_fastcolortransfer.cpp kde_module_LTLIBRARIES = chalkfastcolortransfer.la diff --git a/chalk/plugins/filters/fastcolortransfer/fastcolortransfer.cc b/chalk/plugins/filters/fastcolortransfer/fastcolortransfer.cpp similarity index 100% rename from chalk/plugins/filters/fastcolortransfer/fastcolortransfer.cc rename to chalk/plugins/filters/fastcolortransfer/fastcolortransfer.cpp diff --git a/chalk/plugins/filters/lenscorrectionfilter/Makefile.am b/chalk/plugins/filters/lenscorrectionfilter/Makefile.am index a0e2e5b48..e36e7d001 100644 --- a/chalk/plugins/filters/lenscorrectionfilter/Makefile.am +++ b/chalk/plugins/filters/lenscorrectionfilter/Makefile.am @@ -10,7 +10,7 @@ INCLUDES = -I$(srcdir)/../../../sdk \ $(KOFFICE_INCLUDES) \ $(all_includes) -chalklenscorrectionfilter_la_SOURCES = lenscorrectionfilter.cc \ +chalklenscorrectionfilter_la_SOURCES = lenscorrectionfilter.cpp \ wdglenscorrectionoptions.ui kis_wdg_lens_correction.cpp kde_module_LTLIBRARIES = chalklenscorrectionfilter.la diff --git a/chalk/plugins/filters/lenscorrectionfilter/lenscorrectionfilter.cc b/chalk/plugins/filters/lenscorrectionfilter/lenscorrectionfilter.cpp similarity index 100% rename from chalk/plugins/filters/lenscorrectionfilter/lenscorrectionfilter.cc rename to chalk/plugins/filters/lenscorrectionfilter/lenscorrectionfilter.cpp diff --git a/chalk/plugins/filters/levelfilter/Makefile.am b/chalk/plugins/filters/levelfilter/Makefile.am index 7dc49964c..897779e1b 100644 --- a/chalk/plugins/filters/levelfilter/Makefile.am +++ b/chalk/plugins/filters/levelfilter/Makefile.am @@ -7,10 +7,10 @@ INCLUDES = -I$(srcdir)/../../../sdk \ $(KOFFICE_INCLUDES) \ $(all_includes) -chalklevelfilter_la_SOURCES = levelfilter.cc \ +chalklevelfilter_la_SOURCES = levelfilter.cpp \ wdg_level.ui \ - kis_level_filter.cc \ - kgradientslider.cc + kis_level_filter.cpp \ + kgradientslider.cpp noinst_HEADERS = levelfilter.h \ kis_level_filter.h \ diff --git a/chalk/plugins/filters/levelfilter/kgradientslider.cc b/chalk/plugins/filters/levelfilter/kgradientslider.cpp similarity index 100% rename from chalk/plugins/filters/levelfilter/kgradientslider.cc rename to chalk/plugins/filters/levelfilter/kgradientslider.cpp diff --git a/chalk/plugins/filters/levelfilter/kis_level_filter.cc b/chalk/plugins/filters/levelfilter/kis_level_filter.cpp similarity index 100% rename from chalk/plugins/filters/levelfilter/kis_level_filter.cc rename to chalk/plugins/filters/levelfilter/kis_level_filter.cpp diff --git a/chalk/plugins/filters/levelfilter/levelfilter.cc b/chalk/plugins/filters/levelfilter/levelfilter.cpp similarity index 100% rename from chalk/plugins/filters/levelfilter/levelfilter.cc rename to chalk/plugins/filters/levelfilter/levelfilter.cpp diff --git a/chalk/plugins/filters/noisefilter/Makefile.am b/chalk/plugins/filters/noisefilter/Makefile.am index 8c06406f7..119039f0b 100644 --- a/chalk/plugins/filters/noisefilter/Makefile.am +++ b/chalk/plugins/filters/noisefilter/Makefile.am @@ -10,7 +10,7 @@ INCLUDES = -I$(srcdir)/../../../sdk \ $(KOFFICE_INCLUDES) \ $(all_includes) -chalknoisefilter_la_SOURCES = noisefilter.cc wdgnoiseoptions.ui \ +chalknoisefilter_la_SOURCES = noisefilter.cpp wdgnoiseoptions.ui \ kis_wdg_noise.cpp kde_module_LTLIBRARIES = chalknoisefilter.la diff --git a/chalk/plugins/filters/noisefilter/noisefilter.cc b/chalk/plugins/filters/noisefilter/noisefilter.cpp similarity index 100% rename from chalk/plugins/filters/noisefilter/noisefilter.cc rename to chalk/plugins/filters/noisefilter/noisefilter.cpp diff --git a/chalk/plugins/filters/oilpaintfilter/Makefile.am b/chalk/plugins/filters/oilpaintfilter/Makefile.am index 032fc2f3d..6332d7baa 100644 --- a/chalk/plugins/filters/oilpaintfilter/Makefile.am +++ b/chalk/plugins/filters/oilpaintfilter/Makefile.am @@ -11,8 +11,8 @@ INCLUDES = \ kde_module_LTLIBRARIES = chalkoilpaintfilter.la -chalkoilpaintfilter_la_SOURCES = kis_oilpaint_filter_plugin.cc \ - kis_oilpaint_filter.cc +chalkoilpaintfilter_la_SOURCES = kis_oilpaint_filter_plugin.cpp \ + kis_oilpaint_filter.cpp noinst_HEADERS = kis_oilpaint_filter_plugin.h \ kis_oilpaint_filter.h diff --git a/chalk/plugins/filters/oilpaintfilter/kis_oilpaint_filter.cc b/chalk/plugins/filters/oilpaintfilter/kis_oilpaint_filter.cpp similarity index 100% rename from chalk/plugins/filters/oilpaintfilter/kis_oilpaint_filter.cc rename to chalk/plugins/filters/oilpaintfilter/kis_oilpaint_filter.cpp diff --git a/chalk/plugins/filters/oilpaintfilter/kis_oilpaint_filter_plugin.cc b/chalk/plugins/filters/oilpaintfilter/kis_oilpaint_filter_plugin.cpp similarity index 100% rename from chalk/plugins/filters/oilpaintfilter/kis_oilpaint_filter_plugin.cc rename to chalk/plugins/filters/oilpaintfilter/kis_oilpaint_filter_plugin.cpp diff --git a/chalk/plugins/filters/pixelizefilter/Makefile.am b/chalk/plugins/filters/pixelizefilter/Makefile.am index 750941e1f..20f7bc4ae 100644 --- a/chalk/plugins/filters/pixelizefilter/Makefile.am +++ b/chalk/plugins/filters/pixelizefilter/Makefile.am @@ -11,8 +11,8 @@ INCLUDES = \ kde_module_LTLIBRARIES = chalkpixelizefilter.la -chalkpixelizefilter_la_SOURCES = kis_pixelize_filter_plugin.cc \ - kis_pixelize_filter.cc +chalkpixelizefilter_la_SOURCES = kis_pixelize_filter_plugin.cpp \ + kis_pixelize_filter.cpp noinst_HEADERS = kis_pixelize_filter_plugin.h \ kis_pixelize_filter.h diff --git a/chalk/plugins/filters/pixelizefilter/kis_pixelize_filter.cc b/chalk/plugins/filters/pixelizefilter/kis_pixelize_filter.cpp similarity index 100% rename from chalk/plugins/filters/pixelizefilter/kis_pixelize_filter.cc rename to chalk/plugins/filters/pixelizefilter/kis_pixelize_filter.cpp diff --git a/chalk/plugins/filters/pixelizefilter/kis_pixelize_filter_plugin.cc b/chalk/plugins/filters/pixelizefilter/kis_pixelize_filter_plugin.cpp similarity index 100% rename from chalk/plugins/filters/pixelizefilter/kis_pixelize_filter_plugin.cc rename to chalk/plugins/filters/pixelizefilter/kis_pixelize_filter_plugin.cpp diff --git a/chalk/plugins/filters/raindropsfilter/Makefile.am b/chalk/plugins/filters/raindropsfilter/Makefile.am index 10f44c436..e6a1d4683 100644 --- a/chalk/plugins/filters/raindropsfilter/Makefile.am +++ b/chalk/plugins/filters/raindropsfilter/Makefile.am @@ -11,8 +11,8 @@ INCLUDES = \ kde_module_LTLIBRARIES = chalkraindropsfilter.la -chalkraindropsfilter_la_SOURCES = kis_raindrops_filter_plugin.cc \ - kis_raindrops_filter.cc +chalkraindropsfilter_la_SOURCES = kis_raindrops_filter_plugin.cpp \ + kis_raindrops_filter.cpp noinst_HEADERS = kis_raindrops_filter_plugin.h \ kis_raindrops_filter.h diff --git a/chalk/plugins/filters/raindropsfilter/kis_raindrops_filter.cc b/chalk/plugins/filters/raindropsfilter/kis_raindrops_filter.cpp similarity index 100% rename from chalk/plugins/filters/raindropsfilter/kis_raindrops_filter.cc rename to chalk/plugins/filters/raindropsfilter/kis_raindrops_filter.cpp diff --git a/chalk/plugins/filters/raindropsfilter/kis_raindrops_filter_plugin.cc b/chalk/plugins/filters/raindropsfilter/kis_raindrops_filter_plugin.cpp similarity index 100% rename from chalk/plugins/filters/raindropsfilter/kis_raindrops_filter_plugin.cc rename to chalk/plugins/filters/raindropsfilter/kis_raindrops_filter_plugin.cpp diff --git a/chalk/plugins/filters/randompickfilter/Makefile.am b/chalk/plugins/filters/randompickfilter/Makefile.am index 65e910ff9..3be553f2a 100644 --- a/chalk/plugins/filters/randompickfilter/Makefile.am +++ b/chalk/plugins/filters/randompickfilter/Makefile.am @@ -10,7 +10,7 @@ INCLUDES = -I$(srcdir)/../../../sdk \ $(KOFFICE_INCLUDES) \ $(all_includes) -chalkrandompickfilter_la_SOURCES = randompickfilter.cc wdgrandompickoptions.ui \ +chalkrandompickfilter_la_SOURCES = randompickfilter.cpp wdgrandompickoptions.ui \ kis_wdg_random_pick.cpp kde_module_LTLIBRARIES = chalkrandompickfilter.la diff --git a/chalk/plugins/filters/randompickfilter/randompickfilter.cc b/chalk/plugins/filters/randompickfilter/randompickfilter.cpp similarity index 100% rename from chalk/plugins/filters/randompickfilter/randompickfilter.cc rename to chalk/plugins/filters/randompickfilter/randompickfilter.cpp diff --git a/chalk/plugins/filters/roundcorners/Makefile.am b/chalk/plugins/filters/roundcorners/Makefile.am index 05f2e0554..59655c047 100644 --- a/chalk/plugins/filters/roundcorners/Makefile.am +++ b/chalk/plugins/filters/roundcorners/Makefile.am @@ -10,8 +10,8 @@ INCLUDES = \ kde_module_LTLIBRARIES = chalkroundcornersfilter.la -chalkroundcornersfilter_la_SOURCES = kis_round_corners_filter_plugin.cc \ - kis_round_corners_filter.cc +chalkroundcornersfilter_la_SOURCES = kis_round_corners_filter_plugin.cpp \ + kis_round_corners_filter.cpp noinst_HEADERS = kis_round_corners_filter_plugin.h \ kis_round_corners_filter.h diff --git a/chalk/plugins/filters/roundcorners/kis_round_corners_filter.cc b/chalk/plugins/filters/roundcorners/kis_round_corners_filter.cpp similarity index 100% rename from chalk/plugins/filters/roundcorners/kis_round_corners_filter.cc rename to chalk/plugins/filters/roundcorners/kis_round_corners_filter.cpp diff --git a/chalk/plugins/filters/roundcorners/kis_round_corners_filter_plugin.cc b/chalk/plugins/filters/roundcorners/kis_round_corners_filter_plugin.cpp similarity index 100% rename from chalk/plugins/filters/roundcorners/kis_round_corners_filter_plugin.cc rename to chalk/plugins/filters/roundcorners/kis_round_corners_filter_plugin.cpp diff --git a/chalk/plugins/filters/smalltilesfilter/Makefile.am b/chalk/plugins/filters/smalltilesfilter/Makefile.am index 5705eae94..da7181494 100644 --- a/chalk/plugins/filters/smalltilesfilter/Makefile.am +++ b/chalk/plugins/filters/smalltilesfilter/Makefile.am @@ -10,8 +10,8 @@ INCLUDES = \ kde_module_LTLIBRARIES = chalksmalltilesfilter.la -chalksmalltilesfilter_la_SOURCES = kis_small_tiles_filter_plugin.cc \ - kis_small_tiles_filter.cc +chalksmalltilesfilter_la_SOURCES = kis_small_tiles_filter_plugin.cpp \ + kis_small_tiles_filter.cpp noinst_HEADERS = kis_small_tiles_filter_plugin.h \ kis_small_tiles_filter.h diff --git a/chalk/plugins/filters/smalltilesfilter/kis_small_tiles_filter.cc b/chalk/plugins/filters/smalltilesfilter/kis_small_tiles_filter.cpp similarity index 100% rename from chalk/plugins/filters/smalltilesfilter/kis_small_tiles_filter.cc rename to chalk/plugins/filters/smalltilesfilter/kis_small_tiles_filter.cpp diff --git a/chalk/plugins/filters/smalltilesfilter/kis_small_tiles_filter_plugin.cc b/chalk/plugins/filters/smalltilesfilter/kis_small_tiles_filter_plugin.cpp similarity index 100% rename from chalk/plugins/filters/smalltilesfilter/kis_small_tiles_filter_plugin.cc rename to chalk/plugins/filters/smalltilesfilter/kis_small_tiles_filter_plugin.cpp diff --git a/chalk/plugins/filters/sobelfilter/Makefile.am b/chalk/plugins/filters/sobelfilter/Makefile.am index 38893ad43..4a8e4151d 100644 --- a/chalk/plugins/filters/sobelfilter/Makefile.am +++ b/chalk/plugins/filters/sobelfilter/Makefile.am @@ -10,8 +10,8 @@ INCLUDES = \ kde_module_LTLIBRARIES = chalksobelfilter.la -chalksobelfilter_la_SOURCES = kis_sobel_filter_plugin.cc \ - kis_sobel_filter.cc +chalksobelfilter_la_SOURCES = kis_sobel_filter_plugin.cpp \ + kis_sobel_filter.cpp noinst_HEADERS = kis_sobel_filter_plugin.h \ kis_sobel_filter.h diff --git a/chalk/plugins/filters/sobelfilter/kis_sobel_filter.cc b/chalk/plugins/filters/sobelfilter/kis_sobel_filter.cpp similarity index 100% rename from chalk/plugins/filters/sobelfilter/kis_sobel_filter.cc rename to chalk/plugins/filters/sobelfilter/kis_sobel_filter.cpp diff --git a/chalk/plugins/filters/sobelfilter/kis_sobel_filter_plugin.cc b/chalk/plugins/filters/sobelfilter/kis_sobel_filter_plugin.cpp similarity index 100% rename from chalk/plugins/filters/sobelfilter/kis_sobel_filter_plugin.cc rename to chalk/plugins/filters/sobelfilter/kis_sobel_filter_plugin.cpp diff --git a/chalk/plugins/filters/threadtest/Makefile.am b/chalk/plugins/filters/threadtest/Makefile.am index 7846c3c0e..e1a7c2675 100644 --- a/chalk/plugins/filters/threadtest/Makefile.am +++ b/chalk/plugins/filters/threadtest/Makefile.am @@ -7,7 +7,7 @@ INCLUDES = -I$(srcdir)/../../../sdk \ -I$(srcdir)/../../../../lib/kofficecore \ $(all_includes) -chalkthreadtest_la_SOURCES = threadtest.cc +chalkthreadtest_la_SOURCES = threadtest.cpp kde_module_LTLIBRARIES = chalkthreadtest.la noinst_HEADERS = threadtest.h diff --git a/chalk/plugins/filters/threadtest/threadtest.cc b/chalk/plugins/filters/threadtest/threadtest.cpp similarity index 100% rename from chalk/plugins/filters/threadtest/threadtest.cc rename to chalk/plugins/filters/threadtest/threadtest.cpp diff --git a/chalk/plugins/filters/unsharp/Makefile.am b/chalk/plugins/filters/unsharp/Makefile.am index e955e3bcb..a831dbbdb 100644 --- a/chalk/plugins/filters/unsharp/Makefile.am +++ b/chalk/plugins/filters/unsharp/Makefile.am @@ -9,7 +9,7 @@ INCLUDES = -I$(srcdir)/../../../sdk \ $(KOFFICE_INCLUDES) \ $(all_includes) -chalkunsharpfilter_la_SOURCES = wdgunsharp.ui kis_wdg_unsharp.cc unsharp.cc kis_unsharp_filter.cc +chalkunsharpfilter_la_SOURCES = wdgunsharp.ui kis_wdg_unsharp.cpp unsharp.cpp kis_unsharp_filter.cpp kde_module_LTLIBRARIES = chalkunsharpfilter.la diff --git a/chalk/plugins/filters/unsharp/kis_unsharp_filter.cc b/chalk/plugins/filters/unsharp/kis_unsharp_filter.cpp similarity index 100% rename from chalk/plugins/filters/unsharp/kis_unsharp_filter.cc rename to chalk/plugins/filters/unsharp/kis_unsharp_filter.cpp diff --git a/chalk/plugins/filters/unsharp/kis_wdg_unsharp.cc b/chalk/plugins/filters/unsharp/kis_wdg_unsharp.cpp similarity index 100% rename from chalk/plugins/filters/unsharp/kis_wdg_unsharp.cc rename to chalk/plugins/filters/unsharp/kis_wdg_unsharp.cpp diff --git a/chalk/plugins/filters/unsharp/unsharp.cc b/chalk/plugins/filters/unsharp/unsharp.cpp similarity index 100% rename from chalk/plugins/filters/unsharp/unsharp.cc rename to chalk/plugins/filters/unsharp/unsharp.cpp diff --git a/chalk/plugins/filters/wavefilter/Makefile.am b/chalk/plugins/filters/wavefilter/Makefile.am index 3425e7698..a6b300518 100644 --- a/chalk/plugins/filters/wavefilter/Makefile.am +++ b/chalk/plugins/filters/wavefilter/Makefile.am @@ -10,7 +10,7 @@ INCLUDES = -I$(srcdir)/../../../sdk \ $(KOFFICE_INCLUDES) \ $(all_includes) -chalkwavefilter_la_SOURCES = wavefilter.cc wdgwaveoptions.ui \ +chalkwavefilter_la_SOURCES = wavefilter.cpp wdgwaveoptions.ui \ kis_wdg_wave.cpp kde_module_LTLIBRARIES = chalkwavefilter.la diff --git a/chalk/plugins/filters/wavefilter/wavefilter.cc b/chalk/plugins/filters/wavefilter/wavefilter.cpp similarity index 100% rename from chalk/plugins/filters/wavefilter/wavefilter.cc rename to chalk/plugins/filters/wavefilter/wavefilter.cpp diff --git a/chalk/plugins/paintops/defaultpaintops/Makefile.am b/chalk/plugins/paintops/defaultpaintops/Makefile.am index 31acf6e0e..84e2a4088 100644 --- a/chalk/plugins/paintops/defaultpaintops/Makefile.am +++ b/chalk/plugins/paintops/defaultpaintops/Makefile.am @@ -18,14 +18,14 @@ INCLUDES = -I$(srcdir)/../../../sdk \ chalkdefaultpaintops_la_SOURCES = \ - defaultpaintops_plugin.cc \ - kis_airbrushop.cc \ - kis_brushop.cc \ - kis_duplicateop.cc \ - kis_eraseop.cc \ - kis_penop.cc \ + defaultpaintops_plugin.cpp \ + kis_airbrushop.cpp \ + kis_brushop.cpp \ + kis_duplicateop.cpp \ + kis_eraseop.cpp \ + kis_penop.cpp \ kis_dlgbrushcurvecontrol.ui \ - kis_smudgeop.cc + kis_smudgeop.cpp noinst_HEADERS = defaultpaintops_plugin.h kis_airbrushop.h kis_brushop.h \ kis_duplicateop.h kis_eraseop.h kis_penop.h kis_smudgeop.h diff --git a/chalk/plugins/paintops/defaultpaintops/defaultpaintops_plugin.cc b/chalk/plugins/paintops/defaultpaintops/defaultpaintops_plugin.cc deleted file mode 100644 index 25f12b87b..000000000 --- a/chalk/plugins/paintops/defaultpaintops/defaultpaintops_plugin.cc +++ /dev/null @@ -1,70 +0,0 @@ -/* - * defaultpaintops_plugin.cc -- Part of Chalk - * - * Copyright (c) 2004 Boudewijn Rempt (boud@valdyas.org) - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -#include -#include -#include -#include -#include -#include -#include - -#include - -#include "kis_airbrushop.h" -#include "kis_brushop.h" -#include "kis_duplicateop.h" -#include "kis_eraseop.h" -#include "kis_smudgeop.h" -#include "kis_penop.h" -#include "kis_global.h" -#include "kis_paintop_registry.h" - -#include "defaultpaintops_plugin.h" - -typedef KGenericFactory DefaultPaintOpsPluginFactory; -K_EXPORT_COMPONENT_FACTORY( chalkdefaultpaintops, DefaultPaintOpsPluginFactory( "chalkcore" ) ) - - -DefaultPaintOpsPlugin::DefaultPaintOpsPlugin(TQObject *parent, const char *name, const TQStringList &) - : KParts::Plugin(parent, name) -{ - setInstance(DefaultPaintOpsPluginFactory::instance()); - - // This is not a gui plugin; only load it when the doc is created. - if ( parent->inherits("KisPaintOpRegistry") ) - { - KisPaintOpRegistry * r = dynamic_cast(parent); - // Add hard-coded paint ops. Plugin paintops will add - // themselves in the plugin initialization code. - r->add ( new KisAirbrushOpFactory ); - r->add ( new KisBrushOpFactory ); - r->add ( new KisDuplicateOpFactory ); - r->add ( new KisEraseOpFactory ); - r->add ( new KisPenOpFactory ); - r->add ( new KisSmudgeOpFactory ); - } - -} - -DefaultPaintOpsPlugin::~DefaultPaintOpsPlugin() -{ -} - -#include "defaultpaintops_plugin.moc" diff --git a/chalk/plugins/paintops/defaultpaintops/defaultpaintops_plugin.cpp b/chalk/plugins/paintops/defaultpaintops/defaultpaintops_plugin.cpp new file mode 100644 index 000000000..6e1d3f754 --- /dev/null +++ b/chalk/plugins/paintops/defaultpaintops/defaultpaintops_plugin.cpp @@ -0,0 +1,70 @@ +/* + * defaultpaintops_plugin.cpp -- Part of Chalk + * + * Copyright (c) 2004 Boudewijn Rempt (boud@valdyas.org) + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "kis_airbrushop.h" +#include "kis_brushop.h" +#include "kis_duplicateop.h" +#include "kis_eraseop.h" +#include "kis_smudgeop.h" +#include "kis_penop.h" +#include "kis_global.h" +#include "kis_paintop_registry.h" + +#include "defaultpaintops_plugin.h" + +typedef KGenericFactory DefaultPaintOpsPluginFactory; +K_EXPORT_COMPONENT_FACTORY( chalkdefaultpaintops, DefaultPaintOpsPluginFactory( "chalkcore" ) ) + + +DefaultPaintOpsPlugin::DefaultPaintOpsPlugin(TQObject *parent, const char *name, const TQStringList &) + : KParts::Plugin(parent, name) +{ + setInstance(DefaultPaintOpsPluginFactory::instance()); + + // This is not a gui plugin; only load it when the doc is created. + if ( parent->inherits("KisPaintOpRegistry") ) + { + KisPaintOpRegistry * r = dynamic_cast(parent); + // Add hard-coded paint ops. Plugin paintops will add + // themselves in the plugin initialization code. + r->add ( new KisAirbrushOpFactory ); + r->add ( new KisBrushOpFactory ); + r->add ( new KisDuplicateOpFactory ); + r->add ( new KisEraseOpFactory ); + r->add ( new KisPenOpFactory ); + r->add ( new KisSmudgeOpFactory ); + } + +} + +DefaultPaintOpsPlugin::~DefaultPaintOpsPlugin() +{ +} + +#include "defaultpaintops_plugin.moc" diff --git a/chalk/plugins/paintops/defaultpaintops/kis_airbrushop.cc b/chalk/plugins/paintops/defaultpaintops/kis_airbrushop.cpp similarity index 100% rename from chalk/plugins/paintops/defaultpaintops/kis_airbrushop.cc rename to chalk/plugins/paintops/defaultpaintops/kis_airbrushop.cpp diff --git a/chalk/plugins/paintops/defaultpaintops/kis_brushop.cc b/chalk/plugins/paintops/defaultpaintops/kis_brushop.cpp similarity index 100% rename from chalk/plugins/paintops/defaultpaintops/kis_brushop.cc rename to chalk/plugins/paintops/defaultpaintops/kis_brushop.cpp diff --git a/chalk/plugins/paintops/defaultpaintops/kis_convolveop.cc b/chalk/plugins/paintops/defaultpaintops/kis_convolveop.cpp similarity index 100% rename from chalk/plugins/paintops/defaultpaintops/kis_convolveop.cc rename to chalk/plugins/paintops/defaultpaintops/kis_convolveop.cpp diff --git a/chalk/plugins/paintops/defaultpaintops/kis_duplicateop.cc b/chalk/plugins/paintops/defaultpaintops/kis_duplicateop.cpp similarity index 100% rename from chalk/plugins/paintops/defaultpaintops/kis_duplicateop.cc rename to chalk/plugins/paintops/defaultpaintops/kis_duplicateop.cpp diff --git a/chalk/plugins/paintops/defaultpaintops/kis_eraseop.cc b/chalk/plugins/paintops/defaultpaintops/kis_eraseop.cpp similarity index 100% rename from chalk/plugins/paintops/defaultpaintops/kis_eraseop.cc rename to chalk/plugins/paintops/defaultpaintops/kis_eraseop.cpp diff --git a/chalk/plugins/paintops/defaultpaintops/kis_penop.cc b/chalk/plugins/paintops/defaultpaintops/kis_penop.cpp similarity index 100% rename from chalk/plugins/paintops/defaultpaintops/kis_penop.cc rename to chalk/plugins/paintops/defaultpaintops/kis_penop.cpp diff --git a/chalk/plugins/paintops/defaultpaintops/kis_smudgeop.cc b/chalk/plugins/paintops/defaultpaintops/kis_smudgeop.cpp similarity index 100% rename from chalk/plugins/paintops/defaultpaintops/kis_smudgeop.cc rename to chalk/plugins/paintops/defaultpaintops/kis_smudgeop.cpp diff --git a/chalk/plugins/tools/defaulttools/Makefile.am b/chalk/plugins/tools/defaulttools/Makefile.am index c4d790cb5..ad9e96a5b 100644 --- a/chalk/plugins/tools/defaulttools/Makefile.am +++ b/chalk/plugins/tools/defaulttools/Makefile.am @@ -10,19 +10,19 @@ INCLUDES = -I$(srcdir)/../../../sdk \ $(all_includes) chalkdefaulttools_la_SOURCES = \ - default_tools.cc \ - kis_tool_colorpicker.cc \ - kis_tool_move.cc \ - kis_tool_zoom.cc \ - kis_tool_brush.cc \ - kis_tool_line.cc \ - kis_tool_duplicate.cc \ - kis_tool_fill.cc \ - kis_tool_rectangle.cc \ - kis_tool_ellipse.cc \ - kis_tool_pan.cc \ - kis_tool_text.cc \ - kis_tool_gradient.cc \ + default_tools.cpp \ + kis_tool_colorpicker.cpp \ + kis_tool_move.cpp \ + kis_tool_zoom.cpp \ + kis_tool_brush.cpp \ + kis_tool_line.cpp \ + kis_tool_duplicate.cpp \ + kis_tool_fill.cpp \ + kis_tool_rectangle.cpp \ + kis_tool_ellipse.cpp \ + kis_tool_pan.cpp \ + kis_tool_text.cpp \ + kis_tool_gradient.cpp \ wdgcolorpicker.ui # Install this plugin in the KDE modules directory diff --git a/chalk/plugins/tools/defaulttools/default_tools.cc b/chalk/plugins/tools/defaulttools/default_tools.cc deleted file mode 100644 index 17e0feff0..000000000 --- a/chalk/plugins/tools/defaulttools/default_tools.cc +++ /dev/null @@ -1,88 +0,0 @@ -/* - * default_tools.cc -- Part of Chalk - * - * Copyright (c) 2004 Boudewijn Rempt (boud@valdyas.org) - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -#include -#include - -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include "default_tools.h" - -#include "kis_tool_fill.h" -#include "kis_tool_brush.h" -#include "kis_tool_freehand.h" -#include "kis_tool_gradient.h" -#include "kis_tool_rectangle.h" -#include "kis_tool_colorpicker.h" -#include "kis_tool_line.h" -#include "kis_tool_text.h" -#include "kis_tool_duplicate.h" -#include "kis_tool_move.h" -#include "kis_tool_zoom.h" -#include "kis_tool_ellipse.h" -#include "kis_tool_pan.h" - - -typedef KGenericFactory DefaultToolsFactory; -K_EXPORT_COMPONENT_FACTORY( chalkdefaulttools, DefaultToolsFactory( "chalk" ) ) - - -DefaultTools::DefaultTools(TQObject *parent, const char *name, const TQStringList &) - : KParts::Plugin(parent, name) -{ - setInstance(DefaultToolsFactory::instance()); - - if ( parent->inherits("KisToolRegistry") ) - { - KisToolRegistry * r = dynamic_cast(parent); - - r->add(new KisToolFillFactory()); - r->add(new KisToolGradientFactory()); - r->add(new KisToolBrushFactory()); - r->add(new KisToolColorPickerFactory()); - r->add(new KisToolLineFactory()); - r->add(new KisToolTextFactory()); - r->add(new KisToolDuplicateFactory()); - r->add(new KisToolMoveFactory()); - r->add(new KisToolZoomFactory()); - r->add(new KisToolEllipseFactory()); - r->add(new KisToolRectangleFactory()); - r->add(new KisToolPanFactory()); - - } -} - -DefaultTools::~DefaultTools() -{ -} - -#include "default_tools.moc" diff --git a/chalk/plugins/tools/defaulttools/default_tools.cpp b/chalk/plugins/tools/defaulttools/default_tools.cpp new file mode 100644 index 000000000..6f1bedbbf --- /dev/null +++ b/chalk/plugins/tools/defaulttools/default_tools.cpp @@ -0,0 +1,88 @@ +/* + * default_tools.cpp -- Part of Chalk + * + * Copyright (c) 2004 Boudewijn Rempt (boud@valdyas.org) + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include "default_tools.h" + +#include "kis_tool_fill.h" +#include "kis_tool_brush.h" +#include "kis_tool_freehand.h" +#include "kis_tool_gradient.h" +#include "kis_tool_rectangle.h" +#include "kis_tool_colorpicker.h" +#include "kis_tool_line.h" +#include "kis_tool_text.h" +#include "kis_tool_duplicate.h" +#include "kis_tool_move.h" +#include "kis_tool_zoom.h" +#include "kis_tool_ellipse.h" +#include "kis_tool_pan.h" + + +typedef KGenericFactory DefaultToolsFactory; +K_EXPORT_COMPONENT_FACTORY( chalkdefaulttools, DefaultToolsFactory( "chalk" ) ) + + +DefaultTools::DefaultTools(TQObject *parent, const char *name, const TQStringList &) + : KParts::Plugin(parent, name) +{ + setInstance(DefaultToolsFactory::instance()); + + if ( parent->inherits("KisToolRegistry") ) + { + KisToolRegistry * r = dynamic_cast(parent); + + r->add(new KisToolFillFactory()); + r->add(new KisToolGradientFactory()); + r->add(new KisToolBrushFactory()); + r->add(new KisToolColorPickerFactory()); + r->add(new KisToolLineFactory()); + r->add(new KisToolTextFactory()); + r->add(new KisToolDuplicateFactory()); + r->add(new KisToolMoveFactory()); + r->add(new KisToolZoomFactory()); + r->add(new KisToolEllipseFactory()); + r->add(new KisToolRectangleFactory()); + r->add(new KisToolPanFactory()); + + } +} + +DefaultTools::~DefaultTools() +{ +} + +#include "default_tools.moc" diff --git a/chalk/plugins/tools/defaulttools/kis_tool_brush.cc b/chalk/plugins/tools/defaulttools/kis_tool_brush.cc deleted file mode 100644 index 7c83a36b0..000000000 --- a/chalk/plugins/tools/defaulttools/kis_tool_brush.cc +++ /dev/null @@ -1,167 +0,0 @@ -/* - * kis_tool_brush.cc - part of Chalk - * - * Copyright (c) 2003-2004 Boudewijn Rempt - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include "kis_config.h" -#include "kis_brush.h" -#include "kis_paintop.h" -#include "kis_paintop_registry.h" -#include "kis_cmb_composite.h" -#include "kis_cursor.h" -#include "kis_painter.h" -#include "kis_tool_brush.h" -#include "kis_canvas_subject.h" -#include "kis_boundary.h" -#include "kis_move_event.h" -#include "kis_canvas.h" -#include "kis_layer.h" - -KisToolBrush::KisToolBrush() - : super(i18n("Brush")) -{ - setName("tool_brush"); - setCursor(KisCursor::load("tool_freehand_cursor.png", 5, 5)); - m_rate = 100; // Conveniently hardcoded for now - m_timer = new TQTimer(this); - TQ_CHECK_PTR(m_timer); - - connect(m_timer, TQT_SIGNAL(timeout()), this, TQT_SLOT(timeoutPaint())); - -} - -KisToolBrush::~KisToolBrush() -{ - delete m_timer; - m_timer = 0; -} - -void KisToolBrush::timeoutPaint() -{ - if (currentImage() && painter()) { - painter()->paintAt(m_prevPos, m_prevPressure, m_prevXTilt, m_prevYTilt); - currentImage()->activeLayer()->setDirty(painter()->dirtyRect()); - } -} - - -void KisToolBrush::update(KisCanvasSubject *subject) -{ - super::update(subject); -} - -void KisToolBrush::initPaint(KisEvent *e) -{ - super::initPaint(e); - - if (!m_painter) { - kdWarning() << "Didn't create a painter! Something is wrong!\n"; - return; - } - KisPaintOp * op = KisPaintOpRegistry::instance()->paintOp(m_subject->currentPaintop(), m_subject->currentPaintopSettings(), m_painter); - if (!op) return; - - m_subject->canvasController()->kiscanvas()->update(); // remove the outline - - painter()->setPaintOp(op); // And now the painter owns the op and will destroy it. - - if (op->incremental()) { - m_timer->start( m_rate ); - } -} - - -void KisToolBrush::endPaint() -{ - m_timer->stop(); - super::endPaint(); -} - - -void KisToolBrush::setup(TDEActionCollection *collection) -{ - - m_action = static_cast(collection->action(name())); - - if (m_action == 0) { - m_action = new TDERadioAction(i18n("&Brush"), - "tool_freehand", TQt::Key_B, this, - TQT_SLOT(activate()), collection, - name()); - m_action->setToolTip(i18n("Draw freehand")); - m_action->setExclusiveGroup("tools"); - m_ownAction = true; - } -} - -void KisToolBrush::move(KisMoveEvent *e) { - KisToolFreehand::move(e); - KisConfig cfg; - if (m_mode != PAINT && cfg.cursorStyle() == CURSOR_STYLE_OUTLINE) - paintOutline(e->pos()); -} - -void KisToolBrush::leave(TQEvent */*e*/) { - m_subject->canvasController()->kiscanvas()->update(); // remove the outline -} - - -void KisToolBrush::slotSetPaintingMode( int mode ) -{ - if (mode == TQButton::On) { - // Direct painting - m_paintIncremental = true; - } - else { - m_paintIncremental = false; - } -} - - -TQWidget* KisToolBrush::createOptionWidget(TQWidget* parent) -{ - TQWidget *widget = super::createOptionWidget(parent); - m_chkDirect = new TQCheckBox(i18n("Paint direct"), widget, "chkDirect"); - m_chkDirect->setChecked(true); - connect(m_chkDirect, TQT_SIGNAL(stateChanged(int)), this, TQT_SLOT(slotSetPaintingMode(int))); - - m_optionLayout = new TQGridLayout(NULL, 3, 2, 0, 6); - TQ_CHECK_PTR(m_optionLayout); - - super::addOptionWidgetLayout(m_optionLayout); - m_optionLayout->addWidget(m_chkDirect, 0, 0); - - return widget; -} - -#include "kis_tool_brush.moc" - diff --git a/chalk/plugins/tools/defaulttools/kis_tool_brush.cpp b/chalk/plugins/tools/defaulttools/kis_tool_brush.cpp new file mode 100644 index 000000000..96e262022 --- /dev/null +++ b/chalk/plugins/tools/defaulttools/kis_tool_brush.cpp @@ -0,0 +1,167 @@ +/* + * kis_tool_brush.cpp - part of Chalk + * + * Copyright (c) 2003-2004 Boudewijn Rempt + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "kis_config.h" +#include "kis_brush.h" +#include "kis_paintop.h" +#include "kis_paintop_registry.h" +#include "kis_cmb_composite.h" +#include "kis_cursor.h" +#include "kis_painter.h" +#include "kis_tool_brush.h" +#include "kis_canvas_subject.h" +#include "kis_boundary.h" +#include "kis_move_event.h" +#include "kis_canvas.h" +#include "kis_layer.h" + +KisToolBrush::KisToolBrush() + : super(i18n("Brush")) +{ + setName("tool_brush"); + setCursor(KisCursor::load("tool_freehand_cursor.png", 5, 5)); + m_rate = 100; // Conveniently hardcoded for now + m_timer = new TQTimer(this); + TQ_CHECK_PTR(m_timer); + + connect(m_timer, TQT_SIGNAL(timeout()), this, TQT_SLOT(timeoutPaint())); + +} + +KisToolBrush::~KisToolBrush() +{ + delete m_timer; + m_timer = 0; +} + +void KisToolBrush::timeoutPaint() +{ + if (currentImage() && painter()) { + painter()->paintAt(m_prevPos, m_prevPressure, m_prevXTilt, m_prevYTilt); + currentImage()->activeLayer()->setDirty(painter()->dirtyRect()); + } +} + + +void KisToolBrush::update(KisCanvasSubject *subject) +{ + super::update(subject); +} + +void KisToolBrush::initPaint(KisEvent *e) +{ + super::initPaint(e); + + if (!m_painter) { + kdWarning() << "Didn't create a painter! Something is wrong!\n"; + return; + } + KisPaintOp * op = KisPaintOpRegistry::instance()->paintOp(m_subject->currentPaintop(), m_subject->currentPaintopSettings(), m_painter); + if (!op) return; + + m_subject->canvasController()->kiscanvas()->update(); // remove the outline + + painter()->setPaintOp(op); // And now the painter owns the op and will destroy it. + + if (op->incremental()) { + m_timer->start( m_rate ); + } +} + + +void KisToolBrush::endPaint() +{ + m_timer->stop(); + super::endPaint(); +} + + +void KisToolBrush::setup(TDEActionCollection *collection) +{ + + m_action = static_cast(collection->action(name())); + + if (m_action == 0) { + m_action = new TDERadioAction(i18n("&Brush"), + "tool_freehand", TQt::Key_B, this, + TQT_SLOT(activate()), collection, + name()); + m_action->setToolTip(i18n("Draw freehand")); + m_action->setExclusiveGroup("tools"); + m_ownAction = true; + } +} + +void KisToolBrush::move(KisMoveEvent *e) { + KisToolFreehand::move(e); + KisConfig cfg; + if (m_mode != PAINT && cfg.cursorStyle() == CURSOR_STYLE_OUTLINE) + paintOutline(e->pos()); +} + +void KisToolBrush::leave(TQEvent */*e*/) { + m_subject->canvasController()->kiscanvas()->update(); // remove the outline +} + + +void KisToolBrush::slotSetPaintingMode( int mode ) +{ + if (mode == TQButton::On) { + // Direct painting + m_paintIncremental = true; + } + else { + m_paintIncremental = false; + } +} + + +TQWidget* KisToolBrush::createOptionWidget(TQWidget* parent) +{ + TQWidget *widget = super::createOptionWidget(parent); + m_chkDirect = new TQCheckBox(i18n("Paint direct"), widget, "chkDirect"); + m_chkDirect->setChecked(true); + connect(m_chkDirect, TQT_SIGNAL(stateChanged(int)), this, TQT_SLOT(slotSetPaintingMode(int))); + + m_optionLayout = new TQGridLayout(NULL, 3, 2, 0, 6); + TQ_CHECK_PTR(m_optionLayout); + + super::addOptionWidgetLayout(m_optionLayout); + m_optionLayout->addWidget(m_chkDirect, 0, 0); + + return widget; +} + +#include "kis_tool_brush.moc" + diff --git a/chalk/plugins/tools/defaulttools/kis_tool_colorpicker.cc b/chalk/plugins/tools/defaulttools/kis_tool_colorpicker.cpp similarity index 100% rename from chalk/plugins/tools/defaulttools/kis_tool_colorpicker.cc rename to chalk/plugins/tools/defaulttools/kis_tool_colorpicker.cpp diff --git a/chalk/plugins/tools/defaulttools/kis_tool_duplicate.cc b/chalk/plugins/tools/defaulttools/kis_tool_duplicate.cc deleted file mode 100644 index 7bb4c54fd..000000000 --- a/chalk/plugins/tools/defaulttools/kis_tool_duplicate.cc +++ /dev/null @@ -1,255 +0,0 @@ -/* - * kis_tool_duplicate.cc - part of Chalk - * - * Copyright (c) 2004 Cyrille Berger - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include -#include -#include -#include - -#include -#include -#include -#include - -#include "kis_brush.h" -#include "kis_cursor.h" -#include "kis_image.h" -#include "kis_tool_duplicate.h" -#include "kis_painter.h" -#include "kis_vec.h" -#include "kis_button_press_event.h" -#include "kis_button_release_event.h" -#include "kis_move_event.h" -#include "kis_paintop.h" -#include "kis_paintop_registry.h" -#include "kis_canvas_subject.h" -#include "kis_perspective_grid.h" - -#include "kis_canvas_painter.h" -#include "kis_boundary_painter.h" - -KisToolDuplicate::KisToolDuplicate() - : super(i18n("Duplicate Brush")), m_isOffsetNotUptodate(true), m_position(TQPoint(-1,-1)) -{ - setName("tool_duplicate"); - m_subject = 0; - setCursor(KisCursor::load("tool_duplicate_cursor.png", 5, 5)); -} - -KisToolDuplicate::~KisToolDuplicate() -{ -} - -void KisToolDuplicate::activate() -{ - m_position = TQPoint(-1,-1); - super::activate(); - if( m_subject->currentImg()->perspectiveGrid()->countSubGrids() != 1 ) - { - m_perspectiveCorrection->setEnabled( false ); - m_perspectiveCorrection->setChecked( false ); - } else { - m_perspectiveCorrection->setEnabled( true ); - } -} - -void KisToolDuplicate::buttonPress(KisButtonPressEvent *e) -{ - if (e->state() == ShiftButton) { - m_position = e->pos(); - m_isOffsetNotUptodate = true; - } else { - if (m_position != TQPoint(-1, -1)) { - super::buttonPress(e); - } - } -} - - -void KisToolDuplicate::setup(TDEActionCollection *collection) -{ - m_action = static_cast(collection->action(name())); - - if (m_action == 0) { - m_action = new TDERadioAction(i18n("&Duplicate Brush"), - "tool_duplicate", TQt::Key_C, this, - TQT_SLOT(activate()), collection, - name()); - m_action->setToolTip(i18n("Duplicate parts of the image. Shift-click to select the point to duplicate from to begin.")); - m_action->setExclusiveGroup("tools"); - m_ownAction = true; - } -} - -void KisToolDuplicate::initPaint(KisEvent *e) -{ - if( m_position != TQPoint(-1,-1)) - { - if(m_isOffsetNotUptodate) - { - m_offset = e->pos() - m_position; - m_isOffsetNotUptodate = false; - } - m_paintIncremental = false; - super::initPaint(e); - painter()->setDuplicateOffset( m_offset ); - KisPaintOp * op = KisPaintOpRegistry::instance()->paintOp("duplicate", 0, painter()); - if (op && m_source) { - op->setSource(m_source); - painter()->setPaintOp(op); - } - m_positionStartPainting = e->pos(); - painter()->setDuplicateStart( e->pos() ); - } -} - -void KisToolDuplicate::move(KisMoveEvent *e) -{ - - // Paint the outline where we will (or are) copying from - if( m_position == TQPoint(-1,-1) ) - return; - - TQPoint srcPos; - if (m_mode == PAINT) { - // if we are in perspective correction mode, update the offset when moving - if(m_perspectiveCorrection->isChecked()) - { - double startM[3][3]; - double endM[3][3]; - for(int i = 0; i < 3; i++) - { - for(int j = 0; j < 3; j++) - { - startM[i][j] = 0.; - endM[i][j] = 0.; - } - startM[i][i] = 1.; - endM[i][i] = 1.; - } - - // First look for the grid corresponding to the start point - KisSubPerspectiveGrid* subGridStart = *m_subject->currentImg()->perspectiveGrid()->begin();//device->image()->perspectiveGrid()->gridAt(KisPoint(srcPoint.x() +hotSpot.x(),srcPoint.y() +hotSpot.y())); - TQRect r = TQRect(0,0, m_subject->currentImg()->width(), m_subject->currentImg()->height()); - - if(subGridStart) - { - double* b = KisPerspectiveMath::computeMatrixTransfoFromPerspective( r, *subGridStart->topLeft(), *subGridStart->topRight(), *subGridStart->bottomLeft(), *subGridStart->bottomRight()); - for(int i = 0; i < 3; i++) - { - for(int j = 0; j < 3; j++) - { - startM[i][j] = b[3*i+j]; - } - } - - } - // Second look for the grid corresponding to the end point - KisSubPerspectiveGrid* subGridEnd = *m_subject->currentImg()->perspectiveGrid()->begin();// device->image()->perspectiveGrid()->gridAt(pos); - if(subGridEnd) - { - double* b = KisPerspectiveMath::computeMatrixTransfoToPerspective(*subGridEnd->topLeft(), *subGridEnd->topRight(), *subGridEnd->bottomLeft(), *subGridEnd->bottomRight(), r); - for(int i = 0; i < 3; i++) - { - for(int j = 0; j < 3; j++) - { - endM[i][j] = b[3*i+j]; - } - } - } - // Compute the translation in the perspective transformation space: - KisPoint translat; - { - KisPoint positionStartPaintingT = KisPerspectiveMath::matProd(endM, m_positionStartPainting); - KisPoint currentPositionT = KisPerspectiveMath::matProd(endM, e->pos() ); - KisPoint duplicateStartPoisitionT = KisPerspectiveMath::matProd(endM, m_positionStartPainting - m_offset); - KisPoint duplicateRealPosition = KisPerspectiveMath::matProd(startM, duplicateStartPoisitionT + (currentPositionT - positionStartPaintingT) ); - KisPoint p = e->pos() - duplicateRealPosition; - srcPos = p.floorTQPoint(); - } - - }else { - srcPos = painter()->duplicateOffset().floorTQPoint(); - } - } else { - if(m_isOffsetNotUptodate) - srcPos = e->pos().floorTQPoint() - m_position.floorTQPoint(); - else - srcPos = m_offset.floorTQPoint(); - } - - TQ_INT32 x; - TQ_INT32 y; - - // like KisPaintOp::splitCoordinate - x = (TQ_INT32)((e->x() < 0) ? e->x() - 1 : e->x()); - y = (TQ_INT32)((e->y() < 0) ? e->y() - 1 : e->y()); - srcPos = TQPoint(x - srcPos.x(), y - srcPos.y()); - - paintOutline(srcPos); - super::move(e); -} - -void KisToolDuplicate::paintAt(const KisPoint &pos, - const double pressure, - const double xtilt, - const double ytilt) -{ - if( m_position != TQPoint(-1,-1)) - { - if(m_isOffsetNotUptodate) - { - m_offset = pos - m_position; - m_isOffsetNotUptodate = false; - } - painter()->setDuplicateHealing( m_healing->isChecked() ); - painter()->setDuplicateHealingRadius( m_healingRadius->value() ); - painter()->setDuplicatePerspectiveCorrection( m_perspectiveCorrection->isChecked() ); - painter()->paintAt( pos, pressure, xtilt, ytilt); - } -} - -TQString KisToolDuplicate::quickHelp() const { - return i18n("To start, shift-click on the place you want to duplicate from. Then you can start painting. An indication of where you are copying from will be displayed while drawing and moving the mouse."); -} - -TQWidget* KisToolDuplicate::createOptionWidget(TQWidget* parent) -{ - TQWidget* widget = KisToolPaint::createOptionWidget(parent); - m_healing = new TQCheckBox(widget); - m_healing->setChecked( false); - addOptionWidgetOption(m_healing, new TQLabel(i18n("Healing"), widget )); - m_healingRadius = new KIntNumInput(widget); - - KisBrush *brush = m_subject->currentBrush(); - int healingradius = 20; - if( brush ) - { - healingradius = 2 * TQMAX(brush->width(),brush->height()); - } - - m_healingRadius->setValue( healingradius ); - addOptionWidgetOption(m_healingRadius, new TQLabel(i18n("Healing radius"), widget )); - m_perspectiveCorrection = new TQCheckBox(widget); - addOptionWidgetOption(m_perspectiveCorrection, new TQLabel(i18n("Correct the perspective"), widget )); - return widget; -} - -#include "kis_tool_duplicate.moc" diff --git a/chalk/plugins/tools/defaulttools/kis_tool_duplicate.cpp b/chalk/plugins/tools/defaulttools/kis_tool_duplicate.cpp new file mode 100644 index 000000000..0f917e7f7 --- /dev/null +++ b/chalk/plugins/tools/defaulttools/kis_tool_duplicate.cpp @@ -0,0 +1,255 @@ +/* + * kis_tool_duplicate.cpp - part of Chalk + * + * Copyright (c) 2004 Cyrille Berger + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "kis_brush.h" +#include "kis_cursor.h" +#include "kis_image.h" +#include "kis_tool_duplicate.h" +#include "kis_painter.h" +#include "kis_vec.h" +#include "kis_button_press_event.h" +#include "kis_button_release_event.h" +#include "kis_move_event.h" +#include "kis_paintop.h" +#include "kis_paintop_registry.h" +#include "kis_canvas_subject.h" +#include "kis_perspective_grid.h" + +#include "kis_canvas_painter.h" +#include "kis_boundary_painter.h" + +KisToolDuplicate::KisToolDuplicate() + : super(i18n("Duplicate Brush")), m_isOffsetNotUptodate(true), m_position(TQPoint(-1,-1)) +{ + setName("tool_duplicate"); + m_subject = 0; + setCursor(KisCursor::load("tool_duplicate_cursor.png", 5, 5)); +} + +KisToolDuplicate::~KisToolDuplicate() +{ +} + +void KisToolDuplicate::activate() +{ + m_position = TQPoint(-1,-1); + super::activate(); + if( m_subject->currentImg()->perspectiveGrid()->countSubGrids() != 1 ) + { + m_perspectiveCorrection->setEnabled( false ); + m_perspectiveCorrection->setChecked( false ); + } else { + m_perspectiveCorrection->setEnabled( true ); + } +} + +void KisToolDuplicate::buttonPress(KisButtonPressEvent *e) +{ + if (e->state() == ShiftButton) { + m_position = e->pos(); + m_isOffsetNotUptodate = true; + } else { + if (m_position != TQPoint(-1, -1)) { + super::buttonPress(e); + } + } +} + + +void KisToolDuplicate::setup(TDEActionCollection *collection) +{ + m_action = static_cast(collection->action(name())); + + if (m_action == 0) { + m_action = new TDERadioAction(i18n("&Duplicate Brush"), + "tool_duplicate", TQt::Key_C, this, + TQT_SLOT(activate()), collection, + name()); + m_action->setToolTip(i18n("Duplicate parts of the image. Shift-click to select the point to duplicate from to begin.")); + m_action->setExclusiveGroup("tools"); + m_ownAction = true; + } +} + +void KisToolDuplicate::initPaint(KisEvent *e) +{ + if( m_position != TQPoint(-1,-1)) + { + if(m_isOffsetNotUptodate) + { + m_offset = e->pos() - m_position; + m_isOffsetNotUptodate = false; + } + m_paintIncremental = false; + super::initPaint(e); + painter()->setDuplicateOffset( m_offset ); + KisPaintOp * op = KisPaintOpRegistry::instance()->paintOp("duplicate", 0, painter()); + if (op && m_source) { + op->setSource(m_source); + painter()->setPaintOp(op); + } + m_positionStartPainting = e->pos(); + painter()->setDuplicateStart( e->pos() ); + } +} + +void KisToolDuplicate::move(KisMoveEvent *e) +{ + + // Paint the outline where we will (or are) copying from + if( m_position == TQPoint(-1,-1) ) + return; + + TQPoint srcPos; + if (m_mode == PAINT) { + // if we are in perspective correction mode, update the offset when moving + if(m_perspectiveCorrection->isChecked()) + { + double startM[3][3]; + double endM[3][3]; + for(int i = 0; i < 3; i++) + { + for(int j = 0; j < 3; j++) + { + startM[i][j] = 0.; + endM[i][j] = 0.; + } + startM[i][i] = 1.; + endM[i][i] = 1.; + } + + // First look for the grid corresponding to the start point + KisSubPerspectiveGrid* subGridStart = *m_subject->currentImg()->perspectiveGrid()->begin();//device->image()->perspectiveGrid()->gridAt(KisPoint(srcPoint.x() +hotSpot.x(),srcPoint.y() +hotSpot.y())); + TQRect r = TQRect(0,0, m_subject->currentImg()->width(), m_subject->currentImg()->height()); + + if(subGridStart) + { + double* b = KisPerspectiveMath::computeMatrixTransfoFromPerspective( r, *subGridStart->topLeft(), *subGridStart->topRight(), *subGridStart->bottomLeft(), *subGridStart->bottomRight()); + for(int i = 0; i < 3; i++) + { + for(int j = 0; j < 3; j++) + { + startM[i][j] = b[3*i+j]; + } + } + + } + // Second look for the grid corresponding to the end point + KisSubPerspectiveGrid* subGridEnd = *m_subject->currentImg()->perspectiveGrid()->begin();// device->image()->perspectiveGrid()->gridAt(pos); + if(subGridEnd) + { + double* b = KisPerspectiveMath::computeMatrixTransfoToPerspective(*subGridEnd->topLeft(), *subGridEnd->topRight(), *subGridEnd->bottomLeft(), *subGridEnd->bottomRight(), r); + for(int i = 0; i < 3; i++) + { + for(int j = 0; j < 3; j++) + { + endM[i][j] = b[3*i+j]; + } + } + } + // Compute the translation in the perspective transformation space: + KisPoint translat; + { + KisPoint positionStartPaintingT = KisPerspectiveMath::matProd(endM, m_positionStartPainting); + KisPoint currentPositionT = KisPerspectiveMath::matProd(endM, e->pos() ); + KisPoint duplicateStartPoisitionT = KisPerspectiveMath::matProd(endM, m_positionStartPainting - m_offset); + KisPoint duplicateRealPosition = KisPerspectiveMath::matProd(startM, duplicateStartPoisitionT + (currentPositionT - positionStartPaintingT) ); + KisPoint p = e->pos() - duplicateRealPosition; + srcPos = p.floorTQPoint(); + } + + }else { + srcPos = painter()->duplicateOffset().floorTQPoint(); + } + } else { + if(m_isOffsetNotUptodate) + srcPos = e->pos().floorTQPoint() - m_position.floorTQPoint(); + else + srcPos = m_offset.floorTQPoint(); + } + + TQ_INT32 x; + TQ_INT32 y; + + // like KisPaintOp::splitCoordinate + x = (TQ_INT32)((e->x() < 0) ? e->x() - 1 : e->x()); + y = (TQ_INT32)((e->y() < 0) ? e->y() - 1 : e->y()); + srcPos = TQPoint(x - srcPos.x(), y - srcPos.y()); + + paintOutline(srcPos); + super::move(e); +} + +void KisToolDuplicate::paintAt(const KisPoint &pos, + const double pressure, + const double xtilt, + const double ytilt) +{ + if( m_position != TQPoint(-1,-1)) + { + if(m_isOffsetNotUptodate) + { + m_offset = pos - m_position; + m_isOffsetNotUptodate = false; + } + painter()->setDuplicateHealing( m_healing->isChecked() ); + painter()->setDuplicateHealingRadius( m_healingRadius->value() ); + painter()->setDuplicatePerspectiveCorrection( m_perspectiveCorrection->isChecked() ); + painter()->paintAt( pos, pressure, xtilt, ytilt); + } +} + +TQString KisToolDuplicate::quickHelp() const { + return i18n("To start, shift-click on the place you want to duplicate from. Then you can start painting. An indication of where you are copying from will be displayed while drawing and moving the mouse."); +} + +TQWidget* KisToolDuplicate::createOptionWidget(TQWidget* parent) +{ + TQWidget* widget = KisToolPaint::createOptionWidget(parent); + m_healing = new TQCheckBox(widget); + m_healing->setChecked( false); + addOptionWidgetOption(m_healing, new TQLabel(i18n("Healing"), widget )); + m_healingRadius = new KIntNumInput(widget); + + KisBrush *brush = m_subject->currentBrush(); + int healingradius = 20; + if( brush ) + { + healingradius = 2 * TQMAX(brush->width(),brush->height()); + } + + m_healingRadius->setValue( healingradius ); + addOptionWidgetOption(m_healingRadius, new TQLabel(i18n("Healing radius"), widget )); + m_perspectiveCorrection = new TQCheckBox(widget); + addOptionWidgetOption(m_perspectiveCorrection, new TQLabel(i18n("Correct the perspective"), widget )); + return widget; +} + +#include "kis_tool_duplicate.moc" diff --git a/chalk/plugins/tools/defaulttools/kis_tool_ellipse.cc b/chalk/plugins/tools/defaulttools/kis_tool_ellipse.cc deleted file mode 100644 index 919454b26..000000000 --- a/chalk/plugins/tools/defaulttools/kis_tool_ellipse.cc +++ /dev/null @@ -1,186 +0,0 @@ -/* - * kis_tool_ellipse.cc - part of Krayon - * - * Copyright (c) 2000 John Califf - * Copyright (c) 2002 Patrick Julien - * Copyright (c) 2004 Boudewijn Rempt - * Copyright (c) 2004 Clarence Dang - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include - -#include -#include -#include - -#include "kis_painter.h" -#include "kis_canvas_subject.h" -#include "kis_canvas_controller.h" -#include "kis_tool_ellipse.h" -#include "kis_button_press_event.h" -#include "kis_button_release_event.h" -#include "kis_move_event.h" -#include "kis_paintop_registry.h" -#include "kis_undo_adapter.h" -#include "kis_canvas.h" -#include "kis_canvas_painter.h" -#include "kis_cursor.h" - -KisToolEllipse::KisToolEllipse() - : super(i18n ("Ellipse")), - m_dragging (false), - m_currentImage (0) -{ - setName("tool_ellipse"); - setCursor(KisCursor::load("tool_ellipse_cursor.png", 6, 6)); -} - -KisToolEllipse::~KisToolEllipse() -{ -} - -void KisToolEllipse::update (KisCanvasSubject *subject) -{ - super::update (subject); - if (m_subject) - m_currentImage = m_subject->currentImg (); -} - -void KisToolEllipse::buttonPress(KisButtonPressEvent *event) -{ - if (m_currentImage && event->button() == Qt::LeftButton) { - m_dragging = true; - m_dragStart = m_dragCenter = m_dragEnd = event->pos(); - draw(m_dragStart, m_dragEnd); - } -} - -void KisToolEllipse::move(KisMoveEvent *event) -{ - if (m_dragging) { - // erase old lines on canvas - draw(m_dragStart, m_dragEnd); - // move (alt) or resize ellipse - if (event->state() & TQt::AltButton) { - KisPoint trans = event->pos() - m_dragEnd; - m_dragStart += trans; - m_dragEnd += trans; - } else { - KisPoint diag = event->pos() - (event->state() & TQt::ControlButton - ? m_dragCenter : m_dragStart); - // circle? - if (event->state() & TQt::ShiftButton) { - double size = TQMAX(fabs(diag.x()), fabs(diag.y())); - double w = diag.x() < 0 ? -size : size; - double h = diag.y() < 0 ? -size : size; - diag = KisPoint(w, h); - } - - // resize around center point? - if (event->state() & TQt::ControlButton) { - m_dragStart = m_dragCenter - diag; - m_dragEnd = m_dragCenter + diag; - } else { - m_dragEnd = m_dragStart + diag; - } - } - // draw new lines on canvas - draw(m_dragStart, m_dragEnd); - m_dragCenter = KisPoint((m_dragStart.x() + m_dragEnd.x()) / 2, - (m_dragStart.y() + m_dragEnd.y()) / 2); - } -} - -void KisToolEllipse::buttonRelease(KisButtonReleaseEvent *event) -{ - if (!m_subject || !m_currentImage) - return; - - if (m_dragging && event->button() == Qt::LeftButton) { - // erase old lines on canvas - draw(m_dragStart, m_dragEnd); - m_dragging = false; - - if (m_dragStart == m_dragEnd) - return; - - if (!m_currentImage) - return; - - if (!m_currentImage->activeDevice()) - return; - - KisPaintDeviceSP device = m_currentImage->activeDevice (); - KisPainter painter (device); - if (m_currentImage->undo()) painter.beginTransaction (i18n ("Ellipse")); - - painter.setPaintColor(m_subject->fgColor()); - painter.setBackgroundColor(m_subject->bgColor()); - painter.setFillStyle(fillStyle()); - painter.setBrush(m_subject->currentBrush()); - painter.setPattern(m_subject->currentPattern()); - painter.setOpacity(m_opacity); - painter.setCompositeOp(m_compositeOp); - KisPaintOp * op = KisPaintOpRegistry::instance()->paintOp(m_subject->currentPaintop(), m_subject->currentPaintopSettings(), &painter); - painter.setPaintOp(op); // Painter takes ownership - - painter.paintEllipse(m_dragStart, m_dragEnd, PRESSURE_DEFAULT/*event->pressure()*/, event->xTilt(), event->yTilt()); - device->setDirty( painter.dirtyRect() ); - notifyModified(); - - KisUndoAdapter *adapter = m_currentImage->undoAdapter(); - if (adapter) { - adapter->addCommand(painter.endTransaction()); - } - } -} - -void KisToolEllipse::draw(const KisPoint& start, const KisPoint& end ) -{ - if (!m_subject || !m_currentImage) - return; - - KisCanvasController *controller = m_subject->canvasController (); - KisCanvas *canvas = controller->kiscanvas(); - KisCanvasPainter p (canvas); - - p.setRasterOp (TQt::NotROP); - p.drawEllipse (TQRect (controller->windowToView (start).floorTQPoint(), controller->windowToView (end).floorTQPoint())); - p.end (); -} - -void KisToolEllipse::setup(TDEActionCollection *collection) -{ - m_action = static_cast(collection->action(name())); - - if (m_action == 0) { - TDEShortcut shortcut(TQt::Key_Plus); - shortcut.append(TDEShortcut(TQt::Key_F7)); - m_action = new TDERadioAction(i18n("&Ellipse"), - "tool_ellipse", - shortcut, - this, - TQT_SLOT(activate()), - collection, - name()); - m_action->setToolTip(i18n("Draw an ellipse")); - m_action->setExclusiveGroup("tools"); - m_ownAction = true; - } -} - -#include "kis_tool_ellipse.moc" diff --git a/chalk/plugins/tools/defaulttools/kis_tool_ellipse.cpp b/chalk/plugins/tools/defaulttools/kis_tool_ellipse.cpp new file mode 100644 index 000000000..0488dcb05 --- /dev/null +++ b/chalk/plugins/tools/defaulttools/kis_tool_ellipse.cpp @@ -0,0 +1,186 @@ +/* + * kis_tool_ellipse.cpp - part of Krayon + * + * Copyright (c) 2000 John Califf + * Copyright (c) 2002 Patrick Julien + * Copyright (c) 2004 Boudewijn Rempt + * Copyright (c) 2004 Clarence Dang + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include + +#include +#include +#include + +#include "kis_painter.h" +#include "kis_canvas_subject.h" +#include "kis_canvas_controller.h" +#include "kis_tool_ellipse.h" +#include "kis_button_press_event.h" +#include "kis_button_release_event.h" +#include "kis_move_event.h" +#include "kis_paintop_registry.h" +#include "kis_undo_adapter.h" +#include "kis_canvas.h" +#include "kis_canvas_painter.h" +#include "kis_cursor.h" + +KisToolEllipse::KisToolEllipse() + : super(i18n ("Ellipse")), + m_dragging (false), + m_currentImage (0) +{ + setName("tool_ellipse"); + setCursor(KisCursor::load("tool_ellipse_cursor.png", 6, 6)); +} + +KisToolEllipse::~KisToolEllipse() +{ +} + +void KisToolEllipse::update (KisCanvasSubject *subject) +{ + super::update (subject); + if (m_subject) + m_currentImage = m_subject->currentImg (); +} + +void KisToolEllipse::buttonPress(KisButtonPressEvent *event) +{ + if (m_currentImage && event->button() == Qt::LeftButton) { + m_dragging = true; + m_dragStart = m_dragCenter = m_dragEnd = event->pos(); + draw(m_dragStart, m_dragEnd); + } +} + +void KisToolEllipse::move(KisMoveEvent *event) +{ + if (m_dragging) { + // erase old lines on canvas + draw(m_dragStart, m_dragEnd); + // move (alt) or resize ellipse + if (event->state() & TQt::AltButton) { + KisPoint trans = event->pos() - m_dragEnd; + m_dragStart += trans; + m_dragEnd += trans; + } else { + KisPoint diag = event->pos() - (event->state() & TQt::ControlButton + ? m_dragCenter : m_dragStart); + // circle? + if (event->state() & TQt::ShiftButton) { + double size = TQMAX(fabs(diag.x()), fabs(diag.y())); + double w = diag.x() < 0 ? -size : size; + double h = diag.y() < 0 ? -size : size; + diag = KisPoint(w, h); + } + + // resize around center point? + if (event->state() & TQt::ControlButton) { + m_dragStart = m_dragCenter - diag; + m_dragEnd = m_dragCenter + diag; + } else { + m_dragEnd = m_dragStart + diag; + } + } + // draw new lines on canvas + draw(m_dragStart, m_dragEnd); + m_dragCenter = KisPoint((m_dragStart.x() + m_dragEnd.x()) / 2, + (m_dragStart.y() + m_dragEnd.y()) / 2); + } +} + +void KisToolEllipse::buttonRelease(KisButtonReleaseEvent *event) +{ + if (!m_subject || !m_currentImage) + return; + + if (m_dragging && event->button() == Qt::LeftButton) { + // erase old lines on canvas + draw(m_dragStart, m_dragEnd); + m_dragging = false; + + if (m_dragStart == m_dragEnd) + return; + + if (!m_currentImage) + return; + + if (!m_currentImage->activeDevice()) + return; + + KisPaintDeviceSP device = m_currentImage->activeDevice (); + KisPainter painter (device); + if (m_currentImage->undo()) painter.beginTransaction (i18n ("Ellipse")); + + painter.setPaintColor(m_subject->fgColor()); + painter.setBackgroundColor(m_subject->bgColor()); + painter.setFillStyle(fillStyle()); + painter.setBrush(m_subject->currentBrush()); + painter.setPattern(m_subject->currentPattern()); + painter.setOpacity(m_opacity); + painter.setCompositeOp(m_compositeOp); + KisPaintOp * op = KisPaintOpRegistry::instance()->paintOp(m_subject->currentPaintop(), m_subject->currentPaintopSettings(), &painter); + painter.setPaintOp(op); // Painter takes ownership + + painter.paintEllipse(m_dragStart, m_dragEnd, PRESSURE_DEFAULT/*event->pressure()*/, event->xTilt(), event->yTilt()); + device->setDirty( painter.dirtyRect() ); + notifyModified(); + + KisUndoAdapter *adapter = m_currentImage->undoAdapter(); + if (adapter) { + adapter->addCommand(painter.endTransaction()); + } + } +} + +void KisToolEllipse::draw(const KisPoint& start, const KisPoint& end ) +{ + if (!m_subject || !m_currentImage) + return; + + KisCanvasController *controller = m_subject->canvasController (); + KisCanvas *canvas = controller->kiscanvas(); + KisCanvasPainter p (canvas); + + p.setRasterOp (TQt::NotROP); + p.drawEllipse (TQRect (controller->windowToView (start).floorTQPoint(), controller->windowToView (end).floorTQPoint())); + p.end (); +} + +void KisToolEllipse::setup(TDEActionCollection *collection) +{ + m_action = static_cast(collection->action(name())); + + if (m_action == 0) { + TDEShortcut shortcut(TQt::Key_Plus); + shortcut.append(TDEShortcut(TQt::Key_F7)); + m_action = new TDERadioAction(i18n("&Ellipse"), + "tool_ellipse", + shortcut, + this, + TQT_SLOT(activate()), + collection, + name()); + m_action->setToolTip(i18n("Draw an ellipse")); + m_action->setExclusiveGroup("tools"); + m_ownAction = true; + } +} + +#include "kis_tool_ellipse.moc" diff --git a/chalk/plugins/tools/defaulttools/kis_tool_fill.cc b/chalk/plugins/tools/defaulttools/kis_tool_fill.cc deleted file mode 100644 index df8e4f7c5..000000000 --- a/chalk/plugins/tools/defaulttools/kis_tool_fill.cc +++ /dev/null @@ -1,233 +0,0 @@ -/* - * kis_tool_fill.cc - part of Krayon - * - * Copyright (c) 2000 John Califf - * Copyright (c) 2004 Boudewijn Rempt - * Copyright (c) 2004 Bart Coppens - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include -#include -#include -#include -#include -#include -#include - -#include - -#include "knuminput.h" - -#include "kis_layer.h" -#include "kis_cursor.h" -#include "kis_painter.h" -#include "kis_tool_brush.h" -#include "kis_cmb_composite.h" -#include "kis_tool_fill.h" -#include "kis_colorspace.h" -#include "kis_button_press_event.h" -#include "kis_button_release_event.h" -#include "kis_move_event.h" -#include "kis_pattern.h" -#include "kis_fill_painter.h" -#include "kis_progress_display_interface.h" -#include "kis_undo_adapter.h" -#include "kis_canvas_subject.h" -#include "kis_selection.h" - -KisToolFill::KisToolFill() - : super(i18n("Fill")), m_wasPressed(false) -{ - setName("tool_fill"); - m_subject = 0; - m_oldColor = 0; - m_threshold = 15; - m_usePattern = false; - m_unmerged = false; - m_fillOnlySelection = false; - - setCursor(KisCursor::load("tool_fill_cursor.png", 6, 6)); -} - -void KisToolFill::update(KisCanvasSubject *subject) -{ - m_subject = subject; - m_currentImage = subject->currentImg(); - - super::update(m_subject); -} - -KisToolFill::~KisToolFill() -{ -} - -bool KisToolFill::flood(int startX, int startY) -{ - KisPaintDeviceSP device = m_currentImage->activeDevice(); - if (!device) return false; - - if (m_fillOnlySelection) { - TQRect rc = device->selection()->selectedRect(); - KisPaintDeviceSP filled = new KisPaintDevice(device->colorSpace(), "filled"); - KisFillPainter painter(filled); - if (m_usePattern) - painter.fillRect(rc.x(), rc.y(), rc.width(), rc.height(), - m_subject->currentPattern()); - else - painter.fillRect(rc.x(), rc.y(), rc.width(), rc.height(), - m_subject->fgColor(), m_opacity); - painter.end(); - KisPainter painter2(device); - if (m_currentImage->undo()) painter2.beginTransaction(i18n("Fill")); - painter2.bltSelection(rc.x(), rc.y() , m_compositeOp, filled, m_opacity, - rc.x(), rc.y(), rc.width(), rc.height()); - - device->setDirty(filled->extent()); - notifyModified(); - - if (m_currentImage->undo()) { - m_currentImage->undoAdapter()->addCommand(painter2.endTransaction()); - } - return true; - } - - KisFillPainter painter(device); - if (m_currentImage->undo()) painter.beginTransaction(i18n("Flood Fill")); - painter.setPaintColor(m_subject->fgColor()); - painter.setOpacity(m_opacity); - painter.setFillThreshold(m_threshold); - painter.setCompositeOp(m_compositeOp); - painter.setPattern(m_subject->currentPattern()); - painter.setSampleMerged(!m_unmerged); - painter.setCareForSelection(true); - - KisProgressDisplayInterface *progress = m_subject->progressDisplay(); - if (progress) { - progress->setSubject(&painter, true, true); - } - - if (m_usePattern) - painter.fillPattern(startX, startY); - else - painter.fillColor(startX, startY); - - device->setDirty(painter.dirtyRect()); - notifyModified(); - - if (m_currentImage->undo()) { - m_currentImage->undoAdapter()->addCommand(painter.endTransaction()); - } - - return true; -} - -void KisToolFill::buttonPress(KisButtonPressEvent *e) -{ - m_startPos = e->pos(); - m_wasPressed = true; -} - -void KisToolFill::buttonRelease(KisButtonReleaseEvent *e) -{ - if (!m_subject) return; - if (!m_currentImage || !m_currentImage->activeDevice()) return; - if (e->button() != Qt::LeftButton) return; - if(!m_wasPressed) return; - m_wasPressed = false; - int x, y; - x = m_startPos.floorX(); - y = m_startPos.floorY(); - if (!m_currentImage->bounds().contains(x, y)) { - return; - } - flood(x, y); - notifyModified(); -} - -TQWidget* KisToolFill::createOptionWidget(TQWidget* parent) -{ - TQWidget *widget = super::createOptionWidget(parent); - - m_lbThreshold = new TQLabel(i18n("Threshold: "), widget); - m_slThreshold = new KIntNumInput( widget, "int_widget"); - m_slThreshold->setRange( 1, 100); - m_slThreshold->setSteps( 3, 3); - m_slThreshold->setValue(m_threshold); - connect(m_slThreshold, TQT_SIGNAL(valueChanged(int)), this, TQT_SLOT(slotSetThreshold(int))); - - m_checkUsePattern = new TQCheckBox(i18n("Use pattern"), widget); - m_checkUsePattern->setChecked(m_usePattern); - connect(m_checkUsePattern, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotSetUsePattern(bool))); - - m_checkSampleMerged = new TQCheckBox(i18n("Limit to current layer"), widget); - m_checkSampleMerged->setChecked(m_unmerged); - connect(m_checkSampleMerged, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotSetSampleMerged(bool))); - - m_checkFillSelection = new TQCheckBox(i18n("Fill entire selection"), widget); - m_checkFillSelection->setChecked(m_fillOnlySelection); - connect(m_checkFillSelection, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotSetFillSelection(bool))); - - addOptionWidgetOption(m_slThreshold, m_lbThreshold); - - addOptionWidgetOption(m_checkFillSelection); - addOptionWidgetOption(m_checkSampleMerged); - addOptionWidgetOption(m_checkUsePattern); - - return widget; -} - -void KisToolFill::slotSetThreshold(int threshold) -{ - m_threshold = threshold; -} - -void KisToolFill::slotSetUsePattern(bool state) -{ - m_usePattern = state; -} - -void KisToolFill::slotSetSampleMerged(bool state) -{ - m_unmerged = state; -} - -void KisToolFill::slotSetFillSelection(bool state) -{ - m_fillOnlySelection = state; - m_slThreshold->setEnabled(!state); - m_checkSampleMerged->setEnabled(!state); -} - -void KisToolFill::setup(TDEActionCollection *collection) -{ - m_action = static_cast(collection->action(name())); - - if (m_action == 0) { - m_action = new TDERadioAction(i18n("&Fill"), - "tool_color_fill", - TQt::Key_F, - this, - TQT_SLOT(activate()), - collection, - name()); - m_action->setToolTip(i18n("Contiguous fill")); - m_action->setExclusiveGroup("tools"); - m_ownAction = true; - } -} - -#include "kis_tool_fill.moc" diff --git a/chalk/plugins/tools/defaulttools/kis_tool_fill.cpp b/chalk/plugins/tools/defaulttools/kis_tool_fill.cpp new file mode 100644 index 000000000..ceb78f06b --- /dev/null +++ b/chalk/plugins/tools/defaulttools/kis_tool_fill.cpp @@ -0,0 +1,233 @@ +/* + * kis_tool_fill.cpp - part of Krayon + * + * Copyright (c) 2000 John Califf + * Copyright (c) 2004 Boudewijn Rempt + * Copyright (c) 2004 Bart Coppens + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "knuminput.h" + +#include "kis_layer.h" +#include "kis_cursor.h" +#include "kis_painter.h" +#include "kis_tool_brush.h" +#include "kis_cmb_composite.h" +#include "kis_tool_fill.h" +#include "kis_colorspace.h" +#include "kis_button_press_event.h" +#include "kis_button_release_event.h" +#include "kis_move_event.h" +#include "kis_pattern.h" +#include "kis_fill_painter.h" +#include "kis_progress_display_interface.h" +#include "kis_undo_adapter.h" +#include "kis_canvas_subject.h" +#include "kis_selection.h" + +KisToolFill::KisToolFill() + : super(i18n("Fill")), m_wasPressed(false) +{ + setName("tool_fill"); + m_subject = 0; + m_oldColor = 0; + m_threshold = 15; + m_usePattern = false; + m_unmerged = false; + m_fillOnlySelection = false; + + setCursor(KisCursor::load("tool_fill_cursor.png", 6, 6)); +} + +void KisToolFill::update(KisCanvasSubject *subject) +{ + m_subject = subject; + m_currentImage = subject->currentImg(); + + super::update(m_subject); +} + +KisToolFill::~KisToolFill() +{ +} + +bool KisToolFill::flood(int startX, int startY) +{ + KisPaintDeviceSP device = m_currentImage->activeDevice(); + if (!device) return false; + + if (m_fillOnlySelection) { + TQRect rc = device->selection()->selectedRect(); + KisPaintDeviceSP filled = new KisPaintDevice(device->colorSpace(), "filled"); + KisFillPainter painter(filled); + if (m_usePattern) + painter.fillRect(rc.x(), rc.y(), rc.width(), rc.height(), + m_subject->currentPattern()); + else + painter.fillRect(rc.x(), rc.y(), rc.width(), rc.height(), + m_subject->fgColor(), m_opacity); + painter.end(); + KisPainter painter2(device); + if (m_currentImage->undo()) painter2.beginTransaction(i18n("Fill")); + painter2.bltSelection(rc.x(), rc.y() , m_compositeOp, filled, m_opacity, + rc.x(), rc.y(), rc.width(), rc.height()); + + device->setDirty(filled->extent()); + notifyModified(); + + if (m_currentImage->undo()) { + m_currentImage->undoAdapter()->addCommand(painter2.endTransaction()); + } + return true; + } + + KisFillPainter painter(device); + if (m_currentImage->undo()) painter.beginTransaction(i18n("Flood Fill")); + painter.setPaintColor(m_subject->fgColor()); + painter.setOpacity(m_opacity); + painter.setFillThreshold(m_threshold); + painter.setCompositeOp(m_compositeOp); + painter.setPattern(m_subject->currentPattern()); + painter.setSampleMerged(!m_unmerged); + painter.setCareForSelection(true); + + KisProgressDisplayInterface *progress = m_subject->progressDisplay(); + if (progress) { + progress->setSubject(&painter, true, true); + } + + if (m_usePattern) + painter.fillPattern(startX, startY); + else + painter.fillColor(startX, startY); + + device->setDirty(painter.dirtyRect()); + notifyModified(); + + if (m_currentImage->undo()) { + m_currentImage->undoAdapter()->addCommand(painter.endTransaction()); + } + + return true; +} + +void KisToolFill::buttonPress(KisButtonPressEvent *e) +{ + m_startPos = e->pos(); + m_wasPressed = true; +} + +void KisToolFill::buttonRelease(KisButtonReleaseEvent *e) +{ + if (!m_subject) return; + if (!m_currentImage || !m_currentImage->activeDevice()) return; + if (e->button() != Qt::LeftButton) return; + if(!m_wasPressed) return; + m_wasPressed = false; + int x, y; + x = m_startPos.floorX(); + y = m_startPos.floorY(); + if (!m_currentImage->bounds().contains(x, y)) { + return; + } + flood(x, y); + notifyModified(); +} + +TQWidget* KisToolFill::createOptionWidget(TQWidget* parent) +{ + TQWidget *widget = super::createOptionWidget(parent); + + m_lbThreshold = new TQLabel(i18n("Threshold: "), widget); + m_slThreshold = new KIntNumInput( widget, "int_widget"); + m_slThreshold->setRange( 1, 100); + m_slThreshold->setSteps( 3, 3); + m_slThreshold->setValue(m_threshold); + connect(m_slThreshold, TQT_SIGNAL(valueChanged(int)), this, TQT_SLOT(slotSetThreshold(int))); + + m_checkUsePattern = new TQCheckBox(i18n("Use pattern"), widget); + m_checkUsePattern->setChecked(m_usePattern); + connect(m_checkUsePattern, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotSetUsePattern(bool))); + + m_checkSampleMerged = new TQCheckBox(i18n("Limit to current layer"), widget); + m_checkSampleMerged->setChecked(m_unmerged); + connect(m_checkSampleMerged, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotSetSampleMerged(bool))); + + m_checkFillSelection = new TQCheckBox(i18n("Fill entire selection"), widget); + m_checkFillSelection->setChecked(m_fillOnlySelection); + connect(m_checkFillSelection, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotSetFillSelection(bool))); + + addOptionWidgetOption(m_slThreshold, m_lbThreshold); + + addOptionWidgetOption(m_checkFillSelection); + addOptionWidgetOption(m_checkSampleMerged); + addOptionWidgetOption(m_checkUsePattern); + + return widget; +} + +void KisToolFill::slotSetThreshold(int threshold) +{ + m_threshold = threshold; +} + +void KisToolFill::slotSetUsePattern(bool state) +{ + m_usePattern = state; +} + +void KisToolFill::slotSetSampleMerged(bool state) +{ + m_unmerged = state; +} + +void KisToolFill::slotSetFillSelection(bool state) +{ + m_fillOnlySelection = state; + m_slThreshold->setEnabled(!state); + m_checkSampleMerged->setEnabled(!state); +} + +void KisToolFill::setup(TDEActionCollection *collection) +{ + m_action = static_cast(collection->action(name())); + + if (m_action == 0) { + m_action = new TDERadioAction(i18n("&Fill"), + "tool_color_fill", + TQt::Key_F, + this, + TQT_SLOT(activate()), + collection, + name()); + m_action->setToolTip(i18n("Contiguous fill")); + m_action->setExclusiveGroup("tools"); + m_ownAction = true; + } +} + +#include "kis_tool_fill.moc" diff --git a/chalk/plugins/tools/defaulttools/kis_tool_gradient.cc b/chalk/plugins/tools/defaulttools/kis_tool_gradient.cc deleted file mode 100644 index a46fee808..000000000 --- a/chalk/plugins/tools/defaulttools/kis_tool_gradient.cc +++ /dev/null @@ -1,309 +0,0 @@ -/* - * kis_tool_gradient.cc - part of Chalk - * - * Copyright (c) 2000 John Califf - * Copyright (c) 2002 Patrick Julien - * Copyright (c) 2003 Boudewijn Rempt - * Copyright (c) 2004 Adrian Page - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include "kis_button_press_event.h" -#include "kis_button_release_event.h" -#include "kis_canvas_subject.h" -#include "kis_cmb_composite.h" -#include "kis_cursor.h" -#include "kis_double_widget.h" -#include "kis_gradient_painter.h" -#include "kis_move_event.h" -#include "kis_painter.h" -#include "kis_progress_display_interface.h" -#include "kis_tool_gradient.h" -#include "kis_undo_adapter.h" -#include "kis_canvas.h" -#include "kis_canvas_painter.h" - -KisToolGradient::KisToolGradient() - : super(i18n("Gradient")), - m_dragging( false ) -{ - setName("tool_gradient"); - setCursor(KisCursor::load("tool_gradient_cursor.png", 6, 6)); - - m_startPos = KisPoint(0, 0); - m_endPos = KisPoint(0, 0); - - m_reverse = false; - m_shape = KisGradientPainter::GradientShapeLinear; - m_repeat = KisGradientPainter::GradientRepeatNone; - m_antiAliasThreshold = 0.2; -} - -KisToolGradient::~KisToolGradient() -{ -} - -void KisToolGradient::update(KisCanvasSubject *subject) -{ - m_subject = subject; - super::update(m_subject); -} - -void KisToolGradient::paint(KisCanvasPainter& gc) -{ - if (m_dragging) - paintLine(gc); -} - -void KisToolGradient::paint(KisCanvasPainter& gc, const TQRect&) -{ - if (m_dragging) - paintLine(gc); -} - -void KisToolGradient::buttonPress(KisButtonPressEvent *e) -{ - if (!m_subject || !m_subject->currentImg()) { - return; - } - - if (e->button() == Qt::LeftButton) { - m_dragging = true; - m_startPos = e->pos(); - m_endPos = e->pos(); - } -} - -void KisToolGradient::move(KisMoveEvent *e) -{ - if (m_dragging) { - if (m_startPos != m_endPos) { - paintLine(); - } - - if ((e->state() & TQt::ShiftButton) == TQt::ShiftButton) { - m_endPos = straightLine(e->pos()); - } - else { - m_endPos = e->pos(); - } - - paintLine(); - } -} - -void KisToolGradient::buttonRelease(KisButtonReleaseEvent *e) -{ - if (m_dragging && e->button() == Qt::LeftButton) { - - KisCanvasController *controller = m_subject->canvasController(); - KisImageSP img = m_subject->currentImg(); - - m_dragging = false; - - if (m_startPos == m_endPos) { - controller->updateCanvas(); - m_dragging = false; - return; - } - - if ((e->state() & TQt::ShiftButton) == TQt::ShiftButton) { - m_endPos = straightLine(e->pos()); - } - else { - m_endPos = e->pos(); - } - - KisPaintDeviceSP device; - - if (img && (device = img->activeDevice())) { - - KisGradientPainter painter(device); - - if (img->undo()) painter.beginTransaction(i18n("Gradient")); - - painter.setPaintColor(m_subject->fgColor()); - painter.setGradient(*(m_subject->currentGradient())); - painter.setOpacity(m_opacity); - painter.setCompositeOp(m_compositeOp); - - KisProgressDisplayInterface *progress = m_subject->progressDisplay(); - - if (progress) { - progress->setSubject(&painter, true, true); - } - - bool painted = painter.paintGradient(m_startPos, m_endPos, m_shape, m_repeat, m_antiAliasThreshold, m_reverse, 0, 0, m_subject->currentImg()->width(), m_subject->currentImg()->height()); - - if (painted) { - // does whole thing at moment - device->setDirty(painter.dirtyRect()); - - notifyModified(); - - if (img->undo()) { - img->undoAdapter()->addCommand(painter.endTransaction()); - } - } - - /* remove remains of the line drawn while moving */ - if (controller->kiscanvas()) { - controller->kiscanvas()->update(); - } - - } - } -} - -KisPoint KisToolGradient::straightLine(KisPoint point) -{ - KisPoint comparison = point - m_startPos; - KisPoint result; - - if ( fabs(comparison.x()) > fabs(comparison.y())) { - result.setX(point.x()); - result.setY(m_startPos.y()); - } else { - result.setX( m_startPos.x() ); - result.setY( point.y() ); - } - - return result; -} - -void KisToolGradient::paintLine() -{ - if (m_subject) { - KisCanvasController *controller = m_subject->canvasController(); - KisCanvas *canvas = controller->kiscanvas(); - KisCanvasPainter gc(canvas); - - paintLine(gc); - } -} - -void KisToolGradient::paintLine(KisCanvasPainter& gc) -{ - if (m_subject) { - KisCanvasController *controller = m_subject->canvasController(); - - KisPoint start = controller->windowToView(m_startPos); - KisPoint end = controller->windowToView(m_endPos); - - RasterOp op = gc.rasterOp(); - TQPen old = gc.pen(); - TQPen pen(TQt::SolidLine); - - gc.setRasterOp(TQt::NotROP); - gc.setPen(pen); - gc.drawLine(start.floorTQPoint(), end.floorTQPoint()); - gc.setRasterOp(op); - gc.setPen(old); - } -} - -TQWidget* KisToolGradient::createOptionWidget(TQWidget* parent) -{ - TQWidget *widget = super::createOptionWidget(parent); - TQ_CHECK_PTR(widget); - - m_lbShape = new TQLabel(i18n("Shape:"), widget); - m_lbRepeat = new TQLabel(i18n("Repeat:"), widget); - - m_ckReverse = new TQCheckBox(i18n("Reverse"), widget, "reverse_check"); - connect(m_ckReverse, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotSetReverse(bool))); - - m_cmbShape = new TQComboBox(false, widget, "shape_combo"); - connect(m_cmbShape, TQT_SIGNAL(activated(int)), this, TQT_SLOT(slotSetShape(int))); - m_cmbShape->insertItem(i18n("Linear")); - m_cmbShape->insertItem(i18n("Bi-Linear")); - m_cmbShape->insertItem(i18n("Radial")); - m_cmbShape->insertItem(i18n("Square")); - m_cmbShape->insertItem(i18n("Conical")); - m_cmbShape->insertItem(i18n("Conical Symmetric")); - - m_cmbRepeat = new TQComboBox(false, widget, "repeat_combo"); - connect(m_cmbRepeat, TQT_SIGNAL(activated(int)), this, TQT_SLOT(slotSetRepeat(int))); - m_cmbRepeat->insertItem(i18n("None")); - m_cmbRepeat->insertItem(i18n("Forwards")); - m_cmbRepeat->insertItem(i18n("Alternating")); - - addOptionWidgetOption(m_cmbShape, m_lbShape); - - addOptionWidgetOption(m_cmbRepeat, m_lbRepeat); - - addOptionWidgetOption(m_ckReverse); - - m_lbAntiAliasThreshold = new TQLabel(i18n("Anti-alias threshold:"), widget); - - m_slAntiAliasThreshold = new KDoubleNumInput(widget, "threshold_slider"); - m_slAntiAliasThreshold->setRange( 0, 1); - m_slAntiAliasThreshold->setValue(m_antiAliasThreshold); - connect(m_slAntiAliasThreshold, TQT_SIGNAL(valueChanged(double)), this, TQT_SLOT(slotSetAntiAliasThreshold(double))); - - addOptionWidgetOption(m_slAntiAliasThreshold, m_lbAntiAliasThreshold); - - return widget; -} - -void KisToolGradient::slotSetShape(int shape) -{ - m_shape = static_cast(shape); -} - -void KisToolGradient::slotSetRepeat(int repeat) -{ - m_repeat = static_cast(repeat); -} - -void KisToolGradient::slotSetReverse(bool state) -{ - m_reverse = state; -} - -void KisToolGradient::slotSetAntiAliasThreshold(double value) -{ - m_antiAliasThreshold = value; -} - -void KisToolGradient::setup(TDEActionCollection *collection) -{ - m_action = static_cast(collection->action(name())); - - if (m_action == 0) { - m_action = new TDERadioAction(i18n("&Gradient"), - "tool_gradient", TQt::Key_G, this, - TQT_SLOT(activate()), collection, - name()); - m_action->setToolTip(i18n("Draw a gradient")); - m_action->setExclusiveGroup("tools"); - m_ownAction = true; - } -} - -#include "kis_tool_gradient.moc" - diff --git a/chalk/plugins/tools/defaulttools/kis_tool_gradient.cpp b/chalk/plugins/tools/defaulttools/kis_tool_gradient.cpp new file mode 100644 index 000000000..b8f72a3bb --- /dev/null +++ b/chalk/plugins/tools/defaulttools/kis_tool_gradient.cpp @@ -0,0 +1,309 @@ +/* + * kis_tool_gradient.cpp - part of Chalk + * + * Copyright (c) 2000 John Califf + * Copyright (c) 2002 Patrick Julien + * Copyright (c) 2003 Boudewijn Rempt + * Copyright (c) 2004 Adrian Page + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "kis_button_press_event.h" +#include "kis_button_release_event.h" +#include "kis_canvas_subject.h" +#include "kis_cmb_composite.h" +#include "kis_cursor.h" +#include "kis_double_widget.h" +#include "kis_gradient_painter.h" +#include "kis_move_event.h" +#include "kis_painter.h" +#include "kis_progress_display_interface.h" +#include "kis_tool_gradient.h" +#include "kis_undo_adapter.h" +#include "kis_canvas.h" +#include "kis_canvas_painter.h" + +KisToolGradient::KisToolGradient() + : super(i18n("Gradient")), + m_dragging( false ) +{ + setName("tool_gradient"); + setCursor(KisCursor::load("tool_gradient_cursor.png", 6, 6)); + + m_startPos = KisPoint(0, 0); + m_endPos = KisPoint(0, 0); + + m_reverse = false; + m_shape = KisGradientPainter::GradientShapeLinear; + m_repeat = KisGradientPainter::GradientRepeatNone; + m_antiAliasThreshold = 0.2; +} + +KisToolGradient::~KisToolGradient() +{ +} + +void KisToolGradient::update(KisCanvasSubject *subject) +{ + m_subject = subject; + super::update(m_subject); +} + +void KisToolGradient::paint(KisCanvasPainter& gc) +{ + if (m_dragging) + paintLine(gc); +} + +void KisToolGradient::paint(KisCanvasPainter& gc, const TQRect&) +{ + if (m_dragging) + paintLine(gc); +} + +void KisToolGradient::buttonPress(KisButtonPressEvent *e) +{ + if (!m_subject || !m_subject->currentImg()) { + return; + } + + if (e->button() == Qt::LeftButton) { + m_dragging = true; + m_startPos = e->pos(); + m_endPos = e->pos(); + } +} + +void KisToolGradient::move(KisMoveEvent *e) +{ + if (m_dragging) { + if (m_startPos != m_endPos) { + paintLine(); + } + + if ((e->state() & TQt::ShiftButton) == TQt::ShiftButton) { + m_endPos = straightLine(e->pos()); + } + else { + m_endPos = e->pos(); + } + + paintLine(); + } +} + +void KisToolGradient::buttonRelease(KisButtonReleaseEvent *e) +{ + if (m_dragging && e->button() == Qt::LeftButton) { + + KisCanvasController *controller = m_subject->canvasController(); + KisImageSP img = m_subject->currentImg(); + + m_dragging = false; + + if (m_startPos == m_endPos) { + controller->updateCanvas(); + m_dragging = false; + return; + } + + if ((e->state() & TQt::ShiftButton) == TQt::ShiftButton) { + m_endPos = straightLine(e->pos()); + } + else { + m_endPos = e->pos(); + } + + KisPaintDeviceSP device; + + if (img && (device = img->activeDevice())) { + + KisGradientPainter painter(device); + + if (img->undo()) painter.beginTransaction(i18n("Gradient")); + + painter.setPaintColor(m_subject->fgColor()); + painter.setGradient(*(m_subject->currentGradient())); + painter.setOpacity(m_opacity); + painter.setCompositeOp(m_compositeOp); + + KisProgressDisplayInterface *progress = m_subject->progressDisplay(); + + if (progress) { + progress->setSubject(&painter, true, true); + } + + bool painted = painter.paintGradient(m_startPos, m_endPos, m_shape, m_repeat, m_antiAliasThreshold, m_reverse, 0, 0, m_subject->currentImg()->width(), m_subject->currentImg()->height()); + + if (painted) { + // does whole thing at moment + device->setDirty(painter.dirtyRect()); + + notifyModified(); + + if (img->undo()) { + img->undoAdapter()->addCommand(painter.endTransaction()); + } + } + + /* remove remains of the line drawn while moving */ + if (controller->kiscanvas()) { + controller->kiscanvas()->update(); + } + + } + } +} + +KisPoint KisToolGradient::straightLine(KisPoint point) +{ + KisPoint comparison = point - m_startPos; + KisPoint result; + + if ( fabs(comparison.x()) > fabs(comparison.y())) { + result.setX(point.x()); + result.setY(m_startPos.y()); + } else { + result.setX( m_startPos.x() ); + result.setY( point.y() ); + } + + return result; +} + +void KisToolGradient::paintLine() +{ + if (m_subject) { + KisCanvasController *controller = m_subject->canvasController(); + KisCanvas *canvas = controller->kiscanvas(); + KisCanvasPainter gc(canvas); + + paintLine(gc); + } +} + +void KisToolGradient::paintLine(KisCanvasPainter& gc) +{ + if (m_subject) { + KisCanvasController *controller = m_subject->canvasController(); + + KisPoint start = controller->windowToView(m_startPos); + KisPoint end = controller->windowToView(m_endPos); + + RasterOp op = gc.rasterOp(); + TQPen old = gc.pen(); + TQPen pen(TQt::SolidLine); + + gc.setRasterOp(TQt::NotROP); + gc.setPen(pen); + gc.drawLine(start.floorTQPoint(), end.floorTQPoint()); + gc.setRasterOp(op); + gc.setPen(old); + } +} + +TQWidget* KisToolGradient::createOptionWidget(TQWidget* parent) +{ + TQWidget *widget = super::createOptionWidget(parent); + TQ_CHECK_PTR(widget); + + m_lbShape = new TQLabel(i18n("Shape:"), widget); + m_lbRepeat = new TQLabel(i18n("Repeat:"), widget); + + m_ckReverse = new TQCheckBox(i18n("Reverse"), widget, "reverse_check"); + connect(m_ckReverse, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotSetReverse(bool))); + + m_cmbShape = new TQComboBox(false, widget, "shape_combo"); + connect(m_cmbShape, TQT_SIGNAL(activated(int)), this, TQT_SLOT(slotSetShape(int))); + m_cmbShape->insertItem(i18n("Linear")); + m_cmbShape->insertItem(i18n("Bi-Linear")); + m_cmbShape->insertItem(i18n("Radial")); + m_cmbShape->insertItem(i18n("Square")); + m_cmbShape->insertItem(i18n("Conical")); + m_cmbShape->insertItem(i18n("Conical Symmetric")); + + m_cmbRepeat = new TQComboBox(false, widget, "repeat_combo"); + connect(m_cmbRepeat, TQT_SIGNAL(activated(int)), this, TQT_SLOT(slotSetRepeat(int))); + m_cmbRepeat->insertItem(i18n("None")); + m_cmbRepeat->insertItem(i18n("Forwards")); + m_cmbRepeat->insertItem(i18n("Alternating")); + + addOptionWidgetOption(m_cmbShape, m_lbShape); + + addOptionWidgetOption(m_cmbRepeat, m_lbRepeat); + + addOptionWidgetOption(m_ckReverse); + + m_lbAntiAliasThreshold = new TQLabel(i18n("Anti-alias threshold:"), widget); + + m_slAntiAliasThreshold = new KDoubleNumInput(widget, "threshold_slider"); + m_slAntiAliasThreshold->setRange( 0, 1); + m_slAntiAliasThreshold->setValue(m_antiAliasThreshold); + connect(m_slAntiAliasThreshold, TQT_SIGNAL(valueChanged(double)), this, TQT_SLOT(slotSetAntiAliasThreshold(double))); + + addOptionWidgetOption(m_slAntiAliasThreshold, m_lbAntiAliasThreshold); + + return widget; +} + +void KisToolGradient::slotSetShape(int shape) +{ + m_shape = static_cast(shape); +} + +void KisToolGradient::slotSetRepeat(int repeat) +{ + m_repeat = static_cast(repeat); +} + +void KisToolGradient::slotSetReverse(bool state) +{ + m_reverse = state; +} + +void KisToolGradient::slotSetAntiAliasThreshold(double value) +{ + m_antiAliasThreshold = value; +} + +void KisToolGradient::setup(TDEActionCollection *collection) +{ + m_action = static_cast(collection->action(name())); + + if (m_action == 0) { + m_action = new TDERadioAction(i18n("&Gradient"), + "tool_gradient", TQt::Key_G, this, + TQT_SLOT(activate()), collection, + name()); + m_action->setToolTip(i18n("Draw a gradient")); + m_action->setExclusiveGroup("tools"); + m_ownAction = true; + } +} + +#include "kis_tool_gradient.moc" + diff --git a/chalk/plugins/tools/defaulttools/kis_tool_line.cc b/chalk/plugins/tools/defaulttools/kis_tool_line.cc deleted file mode 100644 index 4e118cccb..000000000 --- a/chalk/plugins/tools/defaulttools/kis_tool_line.cc +++ /dev/null @@ -1,254 +0,0 @@ -/* - * kis_tool_line.cc - part of Krayon - * - * Copyright (c) 2000 John Califf - * Copyright (c) 2002 Patrick Julien - * Copyright (c) 2003 Boudewijn Rempt - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include -#include -#include - -#include -#include -#include -#include - -#include "kis_cursor.h" -#include "kis_painter.h" -#include "kis_tool_line.h" -#include "kis_button_press_event.h" -#include "kis_button_release_event.h" -#include "kis_move_event.h" -#include "kis_paintop_registry.h" -#include "kis_canvas_subject.h" -#include "kis_undo_adapter.h" -#include "kis_canvas.h" -#include "kis_canvas_painter.h" -#include "kis_cursor.h" -#include "kis_layer.h" - -KisToolLine::KisToolLine() - : super(i18n("Line")), - m_dragging( false ) -{ - setName("tool_line"); - setCursor(KisCursor::load("tool_line_cursor.png", 6, 6)); - - m_painter = 0; - m_currentImage = 0; - m_startPos = KisPoint(0, 0); - m_endPos = KisPoint(0, 0); -} - -KisToolLine::~KisToolLine() -{ -} - -void KisToolLine::update(KisCanvasSubject *subject) -{ - m_subject = subject; - m_currentImage = subject->currentImg(); - - super::update(m_subject); -} - - -void KisToolLine::paint(KisCanvasPainter& gc) -{ - if (m_dragging) - paintLine(gc, TQRect()); -} - -void KisToolLine::paint(KisCanvasPainter& gc, const TQRect& rc) -{ - if (m_dragging) - paintLine(gc, rc); -} - -void KisToolLine::buttonPress(KisButtonPressEvent *e) -{ - if (!m_subject || !m_currentImage) return; - - if (!m_subject->currentBrush()) return; - - if (e->button() == Qt::LeftButton) { - m_dragging = true; - //KisCanvasController *controller = m_subject->canvasController(); - m_startPos = e->pos(); //controller->windowToView(e->pos()); - m_endPos = e->pos(); //controller->windowToView(e->pos()); - } -} - -void KisToolLine::move(KisMoveEvent *e) -{ - if (m_dragging) { - if (m_startPos != m_endPos) - paintLine(); - //KisCanvasController *controller = m_subject->canvasController(); - - if (e->state() & TQt::AltButton) { - KisPoint trans = e->pos() - m_endPos; - m_startPos += trans; - m_endPos += trans; - } else if (e->state() & TQt::ShiftButton) - m_endPos = straightLine(e->pos()); - else - m_endPos = e->pos();//controller->windowToView(e->pos()); - paintLine(); - } -} - -void KisToolLine::buttonRelease(KisButtonReleaseEvent *e) -{ - if (m_dragging && e->button() == Qt::LeftButton) { - m_dragging = false; - KisCanvasController *controller = m_subject->canvasController(); - KisImageSP img = m_subject->currentImg(); - - if (m_startPos == m_endPos) { - controller->updateCanvas(); - m_dragging = false; - return; - } - - if ((e->state() & TQt::ShiftButton) == TQt::ShiftButton) { - m_endPos = straightLine(e->pos()); - } - else { - m_endPos = e->pos(); - } - - KisPaintDeviceSP device; - if (m_currentImage && - (device = m_currentImage->activeDevice()) && - m_subject && - m_subject->currentBrush()) - { - delete m_painter; - m_painter = new KisPainter( device ); - TQ_CHECK_PTR(m_painter); - - if (m_currentImage->undo()) m_painter->beginTransaction(i18n("Line")); - - m_painter->setPaintColor(m_subject->fgColor()); - m_painter->setBrush(m_subject->currentBrush()); - m_painter->setOpacity(m_opacity); - m_painter->setCompositeOp(m_compositeOp); - KisPaintOp * op = KisPaintOpRegistry::instance()->paintOp(m_subject->currentPaintop(), m_subject->currentPaintopSettings(), m_painter); - m_painter->setPaintOp(op); // Painter takes ownership - m_painter->paintLine(m_startPos, PRESSURE_DEFAULT, 0, 0, m_endPos, PRESSURE_DEFAULT, 0, 0); - device->setDirty( m_painter->dirtyRect() ); - notifyModified(); - - /* remove remains of the line drawn while moving */ - if (controller->kiscanvas()) { - controller->kiscanvas()->update(); - } - - if (m_currentImage->undo() && m_painter) { - m_currentImage->undoAdapter()->addCommand(m_painter->endTransaction()); - } - delete m_painter; - m_painter = 0; - } else { - if (m_painter) - controller->updateCanvas(m_painter->dirtyRect()); // Removes the last remaining line. - } - } - -} - -KisPoint KisToolLine::straightLine(KisPoint point) -{ - KisPoint comparison = point - m_startPos; - KisPoint result; - - if ( fabs(comparison.x()) > fabs(comparison.y())) { - result.setX(point.x()); - result.setY(m_startPos.y()); - } else { - result.setX( m_startPos.x() ); - result.setY( point.y() ); - } - - return result; -} - -void KisToolLine::paintLine() -{ - if (m_subject) { - KisCanvasController *controller = m_subject->canvasController(); - KisCanvas *canvas = controller->kiscanvas(); - KisCanvasPainter gc(canvas); - TQRect rc; - - paintLine(gc, rc); - } -} - -void KisToolLine::paintLine(KisCanvasPainter& gc, const TQRect&) -{ - if (m_subject) { - KisCanvasController *controller = m_subject->canvasController(); - RasterOp op = gc.rasterOp(); - TQPen old = gc.pen(); - TQPen pen(TQt::SolidLine); - KisPoint start; - KisPoint end; - -// Q_ASSERT(controller); - start = controller->windowToView(m_startPos); - end = controller->windowToView(m_endPos); -// start.setX(start.x() - controller->horzValue()); -// start.setY(start.y() - controller->vertValue()); -// end.setX(end.x() - controller->horzValue()); -// end.setY(end.y() - controller->vertValue()); -// end.setX((end.x() - start.x())); -// end.setY((end.y() - start.y())); -// start *= m_subject->zoomFactor(); -// end *= m_subject->zoomFactor(); - gc.setRasterOp(TQt::NotROP); - gc.setPen(pen); - gc.drawLine(start.floorTQPoint(), end.floorTQPoint()); - gc.setRasterOp(op); - gc.setPen(old); - } -} - -void KisToolLine::setup(TDEActionCollection *collection) -{ - m_action = static_cast(collection->action(name())); - - if (m_action == 0) { - m_action = new TDERadioAction(i18n("&Line"), - "tool_line", TQt::Key_L, this, - TQT_SLOT(activate()), collection, - name()); - m_action->setToolTip(i18n("Draw a line")); - m_action->setExclusiveGroup("tools"); - m_ownAction = true; - } -} - -TQString KisToolLine::quickHelp() const { - return i18n("Alt+Drag will move the origin of the currently displayed line around, Shift+Drag will force you to draw straight lines"); -} - -#include "kis_tool_line.moc" - diff --git a/chalk/plugins/tools/defaulttools/kis_tool_line.cpp b/chalk/plugins/tools/defaulttools/kis_tool_line.cpp new file mode 100644 index 000000000..87cb93907 --- /dev/null +++ b/chalk/plugins/tools/defaulttools/kis_tool_line.cpp @@ -0,0 +1,254 @@ +/* + * kis_tool_line.cpp - part of Krayon + * + * Copyright (c) 2000 John Califf + * Copyright (c) 2002 Patrick Julien + * Copyright (c) 2003 Boudewijn Rempt + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include +#include +#include + +#include +#include +#include +#include + +#include "kis_cursor.h" +#include "kis_painter.h" +#include "kis_tool_line.h" +#include "kis_button_press_event.h" +#include "kis_button_release_event.h" +#include "kis_move_event.h" +#include "kis_paintop_registry.h" +#include "kis_canvas_subject.h" +#include "kis_undo_adapter.h" +#include "kis_canvas.h" +#include "kis_canvas_painter.h" +#include "kis_cursor.h" +#include "kis_layer.h" + +KisToolLine::KisToolLine() + : super(i18n("Line")), + m_dragging( false ) +{ + setName("tool_line"); + setCursor(KisCursor::load("tool_line_cursor.png", 6, 6)); + + m_painter = 0; + m_currentImage = 0; + m_startPos = KisPoint(0, 0); + m_endPos = KisPoint(0, 0); +} + +KisToolLine::~KisToolLine() +{ +} + +void KisToolLine::update(KisCanvasSubject *subject) +{ + m_subject = subject; + m_currentImage = subject->currentImg(); + + super::update(m_subject); +} + + +void KisToolLine::paint(KisCanvasPainter& gc) +{ + if (m_dragging) + paintLine(gc, TQRect()); +} + +void KisToolLine::paint(KisCanvasPainter& gc, const TQRect& rc) +{ + if (m_dragging) + paintLine(gc, rc); +} + +void KisToolLine::buttonPress(KisButtonPressEvent *e) +{ + if (!m_subject || !m_currentImage) return; + + if (!m_subject->currentBrush()) return; + + if (e->button() == Qt::LeftButton) { + m_dragging = true; + //KisCanvasController *controller = m_subject->canvasController(); + m_startPos = e->pos(); //controller->windowToView(e->pos()); + m_endPos = e->pos(); //controller->windowToView(e->pos()); + } +} + +void KisToolLine::move(KisMoveEvent *e) +{ + if (m_dragging) { + if (m_startPos != m_endPos) + paintLine(); + //KisCanvasController *controller = m_subject->canvasController(); + + if (e->state() & TQt::AltButton) { + KisPoint trans = e->pos() - m_endPos; + m_startPos += trans; + m_endPos += trans; + } else if (e->state() & TQt::ShiftButton) + m_endPos = straightLine(e->pos()); + else + m_endPos = e->pos();//controller->windowToView(e->pos()); + paintLine(); + } +} + +void KisToolLine::buttonRelease(KisButtonReleaseEvent *e) +{ + if (m_dragging && e->button() == Qt::LeftButton) { + m_dragging = false; + KisCanvasController *controller = m_subject->canvasController(); + KisImageSP img = m_subject->currentImg(); + + if (m_startPos == m_endPos) { + controller->updateCanvas(); + m_dragging = false; + return; + } + + if ((e->state() & TQt::ShiftButton) == TQt::ShiftButton) { + m_endPos = straightLine(e->pos()); + } + else { + m_endPos = e->pos(); + } + + KisPaintDeviceSP device; + if (m_currentImage && + (device = m_currentImage->activeDevice()) && + m_subject && + m_subject->currentBrush()) + { + delete m_painter; + m_painter = new KisPainter( device ); + TQ_CHECK_PTR(m_painter); + + if (m_currentImage->undo()) m_painter->beginTransaction(i18n("Line")); + + m_painter->setPaintColor(m_subject->fgColor()); + m_painter->setBrush(m_subject->currentBrush()); + m_painter->setOpacity(m_opacity); + m_painter->setCompositeOp(m_compositeOp); + KisPaintOp * op = KisPaintOpRegistry::instance()->paintOp(m_subject->currentPaintop(), m_subject->currentPaintopSettings(), m_painter); + m_painter->setPaintOp(op); // Painter takes ownership + m_painter->paintLine(m_startPos, PRESSURE_DEFAULT, 0, 0, m_endPos, PRESSURE_DEFAULT, 0, 0); + device->setDirty( m_painter->dirtyRect() ); + notifyModified(); + + /* remove remains of the line drawn while moving */ + if (controller->kiscanvas()) { + controller->kiscanvas()->update(); + } + + if (m_currentImage->undo() && m_painter) { + m_currentImage->undoAdapter()->addCommand(m_painter->endTransaction()); + } + delete m_painter; + m_painter = 0; + } else { + if (m_painter) + controller->updateCanvas(m_painter->dirtyRect()); // Removes the last remaining line. + } + } + +} + +KisPoint KisToolLine::straightLine(KisPoint point) +{ + KisPoint comparison = point - m_startPos; + KisPoint result; + + if ( fabs(comparison.x()) > fabs(comparison.y())) { + result.setX(point.x()); + result.setY(m_startPos.y()); + } else { + result.setX( m_startPos.x() ); + result.setY( point.y() ); + } + + return result; +} + +void KisToolLine::paintLine() +{ + if (m_subject) { + KisCanvasController *controller = m_subject->canvasController(); + KisCanvas *canvas = controller->kiscanvas(); + KisCanvasPainter gc(canvas); + TQRect rc; + + paintLine(gc, rc); + } +} + +void KisToolLine::paintLine(KisCanvasPainter& gc, const TQRect&) +{ + if (m_subject) { + KisCanvasController *controller = m_subject->canvasController(); + RasterOp op = gc.rasterOp(); + TQPen old = gc.pen(); + TQPen pen(TQt::SolidLine); + KisPoint start; + KisPoint end; + +// Q_ASSERT(controller); + start = controller->windowToView(m_startPos); + end = controller->windowToView(m_endPos); +// start.setX(start.x() - controller->horzValue()); +// start.setY(start.y() - controller->vertValue()); +// end.setX(end.x() - controller->horzValue()); +// end.setY(end.y() - controller->vertValue()); +// end.setX((end.x() - start.x())); +// end.setY((end.y() - start.y())); +// start *= m_subject->zoomFactor(); +// end *= m_subject->zoomFactor(); + gc.setRasterOp(TQt::NotROP); + gc.setPen(pen); + gc.drawLine(start.floorTQPoint(), end.floorTQPoint()); + gc.setRasterOp(op); + gc.setPen(old); + } +} + +void KisToolLine::setup(TDEActionCollection *collection) +{ + m_action = static_cast(collection->action(name())); + + if (m_action == 0) { + m_action = new TDERadioAction(i18n("&Line"), + "tool_line", TQt::Key_L, this, + TQT_SLOT(activate()), collection, + name()); + m_action->setToolTip(i18n("Draw a line")); + m_action->setExclusiveGroup("tools"); + m_ownAction = true; + } +} + +TQString KisToolLine::quickHelp() const { + return i18n("Alt+Drag will move the origin of the currently displayed line around, Shift+Drag will force you to draw straight lines"); +} + +#include "kis_tool_line.moc" + diff --git a/chalk/plugins/tools/defaulttools/kis_tool_move.cc b/chalk/plugins/tools/defaulttools/kis_tool_move.cpp similarity index 100% rename from chalk/plugins/tools/defaulttools/kis_tool_move.cc rename to chalk/plugins/tools/defaulttools/kis_tool_move.cpp diff --git a/chalk/plugins/tools/defaulttools/kis_tool_pan.cc b/chalk/plugins/tools/defaulttools/kis_tool_pan.cpp similarity index 100% rename from chalk/plugins/tools/defaulttools/kis_tool_pan.cc rename to chalk/plugins/tools/defaulttools/kis_tool_pan.cpp diff --git a/chalk/plugins/tools/defaulttools/kis_tool_rectangle.cc b/chalk/plugins/tools/defaulttools/kis_tool_rectangle.cc deleted file mode 100644 index 852d2c0e0..000000000 --- a/chalk/plugins/tools/defaulttools/kis_tool_rectangle.cc +++ /dev/null @@ -1,187 +0,0 @@ -/* - * kis_tool_rectangle.cc - part of Chalk - * - * Copyright (c) 2000 John Califf - * Copyright (c) 2002 Patrick Julien - * Copyright (c) 2004 Boudewijn Rempt - * Copyright (c) 2004 Clarence Dang - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include - -#include -#include -#include - -#include "kis_button_press_event.h" -#include "kis_button_release_event.h" -#include "kis_canvas_controller.h" -#include "kis_canvas_subject.h" -#include "kis_move_event.h" -#include "kis_painter.h" -#include "kis_paintop_registry.h" -#include "kis_tool_rectangle.h" -#include "kis_undo_adapter.h" -#include "kis_canvas.h" -#include "kis_canvas_painter.h" -#include "kis_cursor.h" -#include "kis_layer.h" - -KisToolRectangle::KisToolRectangle() - : super(i18n ("Rectangle")), - m_dragging (false), - m_currentImage (0) -{ - setName("tool_rectangle"); - setCursor(KisCursor::load("tool_rectangle_cursor.png", 6, 6)); -} - -KisToolRectangle::~KisToolRectangle() -{ -} - -void KisToolRectangle::update (KisCanvasSubject *subject) -{ - super::update (subject); - if (m_subject) - m_currentImage = m_subject->currentImg (); -} - -void KisToolRectangle::buttonPress(KisButtonPressEvent *event) -{ - if (m_currentImage && event->button() == Qt::LeftButton) { - m_dragging = true; - m_dragStart = m_dragCenter = m_dragEnd = event->pos(); - draw(m_dragStart, m_dragEnd); - } -} - -void KisToolRectangle::move(KisMoveEvent *event) -{ - if (m_dragging) { - // erase old lines on canvas - draw(m_dragStart, m_dragEnd); - // move (alt) or resize rectangle - if (event->state() & TQt::AltButton) { - KisPoint trans = event->pos() - m_dragEnd; - m_dragStart += trans; - m_dragEnd += trans; - } else { - KisPoint diag = event->pos() - (event->state() & TQt::ControlButton - ? m_dragCenter : m_dragStart); - // square? - if (event->state() & TQt::ShiftButton) { - double size = TQMAX(fabs(diag.x()), fabs(diag.y())); - double w = diag.x() < 0 ? -size : size; - double h = diag.y() < 0 ? -size : size; - diag = KisPoint(w, h); - } - - // resize around center point? - if (event->state() & TQt::ControlButton) { - m_dragStart = m_dragCenter - diag; - m_dragEnd = m_dragCenter + diag; - } else { - m_dragEnd = m_dragStart + diag; - } - } - // draw new lines on canvas - draw(m_dragStart, m_dragEnd); - m_dragCenter = KisPoint((m_dragStart.x() + m_dragEnd.x()) / 2, - (m_dragStart.y() + m_dragEnd.y()) / 2); - } -} - -void KisToolRectangle::buttonRelease(KisButtonReleaseEvent *event) -{ - if (!m_subject) - return; - - if (!m_currentImage) - return; - - KisPaintDeviceSP device = m_currentImage->activeDevice (); - if (!device) return; - - if (m_dragging && event->button() == Qt::LeftButton) { - // erase old lines on canvas - draw(m_dragStart, m_dragEnd); - m_dragging = false; - - if (m_dragStart == m_dragEnd) - return; - - if (!m_currentImage) - return; - - - KisPainter painter (device); - if (m_currentImage->undo()) painter.beginTransaction (i18n ("Rectangle")); - - painter.setPaintColor(m_subject->fgColor()); - painter.setBackgroundColor(m_subject->bgColor()); - painter.setFillStyle(fillStyle()); - painter.setBrush(m_subject->currentBrush()); - painter.setPattern(m_subject->currentPattern()); - painter.setOpacity(m_opacity); - painter.setCompositeOp(m_compositeOp); - KisPaintOp * op = KisPaintOpRegistry::instance()->paintOp(m_subject->currentPaintop(), m_subject->currentPaintopSettings(), &painter); - painter.setPaintOp(op); - - painter.paintRect(m_dragStart, m_dragEnd, PRESSURE_DEFAULT/*event->pressure()*/, event->xTilt(), event->yTilt()); - device->setDirty( painter.dirtyRect() ); - notifyModified(); - - if (m_currentImage->undo()) { - m_currentImage->undoAdapter()->addCommand(painter.endTransaction()); - } - } -} - -void KisToolRectangle::draw(const KisPoint& start, const KisPoint& end ) -{ - if (!m_subject) - return; - - KisCanvasController *controller = m_subject->canvasController (); - KisCanvas *canvas = controller->kiscanvas(); - KisCanvasPainter p (canvas); - - p.setRasterOp (TQt::NotROP); - p.drawRect (TQRect (controller->windowToView (start).floorTQPoint(), controller->windowToView (end).floorTQPoint())); - p.end (); -} - -void KisToolRectangle::setup(TDEActionCollection *collection) -{ - m_action = static_cast(collection->action(name())); - - if (m_action == 0) { - m_action = new TDERadioAction(i18n("&Rectangle"), - "tool_rectangle", - TQt::Key_F6, - this, - TQT_SLOT(activate()), - collection, - name()); - m_action->setToolTip(i18n("Draw a rectangle")); - m_action->setExclusiveGroup("tools"); - m_ownAction = true; - } -} - -#include "kis_tool_rectangle.moc" diff --git a/chalk/plugins/tools/defaulttools/kis_tool_rectangle.cpp b/chalk/plugins/tools/defaulttools/kis_tool_rectangle.cpp new file mode 100644 index 000000000..69e306ecf --- /dev/null +++ b/chalk/plugins/tools/defaulttools/kis_tool_rectangle.cpp @@ -0,0 +1,187 @@ +/* + * kis_tool_rectangle.cpp - part of Chalk + * + * Copyright (c) 2000 John Califf + * Copyright (c) 2002 Patrick Julien + * Copyright (c) 2004 Boudewijn Rempt + * Copyright (c) 2004 Clarence Dang + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include + +#include +#include +#include + +#include "kis_button_press_event.h" +#include "kis_button_release_event.h" +#include "kis_canvas_controller.h" +#include "kis_canvas_subject.h" +#include "kis_move_event.h" +#include "kis_painter.h" +#include "kis_paintop_registry.h" +#include "kis_tool_rectangle.h" +#include "kis_undo_adapter.h" +#include "kis_canvas.h" +#include "kis_canvas_painter.h" +#include "kis_cursor.h" +#include "kis_layer.h" + +KisToolRectangle::KisToolRectangle() + : super(i18n ("Rectangle")), + m_dragging (false), + m_currentImage (0) +{ + setName("tool_rectangle"); + setCursor(KisCursor::load("tool_rectangle_cursor.png", 6, 6)); +} + +KisToolRectangle::~KisToolRectangle() +{ +} + +void KisToolRectangle::update (KisCanvasSubject *subject) +{ + super::update (subject); + if (m_subject) + m_currentImage = m_subject->currentImg (); +} + +void KisToolRectangle::buttonPress(KisButtonPressEvent *event) +{ + if (m_currentImage && event->button() == Qt::LeftButton) { + m_dragging = true; + m_dragStart = m_dragCenter = m_dragEnd = event->pos(); + draw(m_dragStart, m_dragEnd); + } +} + +void KisToolRectangle::move(KisMoveEvent *event) +{ + if (m_dragging) { + // erase old lines on canvas + draw(m_dragStart, m_dragEnd); + // move (alt) or resize rectangle + if (event->state() & TQt::AltButton) { + KisPoint trans = event->pos() - m_dragEnd; + m_dragStart += trans; + m_dragEnd += trans; + } else { + KisPoint diag = event->pos() - (event->state() & TQt::ControlButton + ? m_dragCenter : m_dragStart); + // square? + if (event->state() & TQt::ShiftButton) { + double size = TQMAX(fabs(diag.x()), fabs(diag.y())); + double w = diag.x() < 0 ? -size : size; + double h = diag.y() < 0 ? -size : size; + diag = KisPoint(w, h); + } + + // resize around center point? + if (event->state() & TQt::ControlButton) { + m_dragStart = m_dragCenter - diag; + m_dragEnd = m_dragCenter + diag; + } else { + m_dragEnd = m_dragStart + diag; + } + } + // draw new lines on canvas + draw(m_dragStart, m_dragEnd); + m_dragCenter = KisPoint((m_dragStart.x() + m_dragEnd.x()) / 2, + (m_dragStart.y() + m_dragEnd.y()) / 2); + } +} + +void KisToolRectangle::buttonRelease(KisButtonReleaseEvent *event) +{ + if (!m_subject) + return; + + if (!m_currentImage) + return; + + KisPaintDeviceSP device = m_currentImage->activeDevice (); + if (!device) return; + + if (m_dragging && event->button() == Qt::LeftButton) { + // erase old lines on canvas + draw(m_dragStart, m_dragEnd); + m_dragging = false; + + if (m_dragStart == m_dragEnd) + return; + + if (!m_currentImage) + return; + + + KisPainter painter (device); + if (m_currentImage->undo()) painter.beginTransaction (i18n ("Rectangle")); + + painter.setPaintColor(m_subject->fgColor()); + painter.setBackgroundColor(m_subject->bgColor()); + painter.setFillStyle(fillStyle()); + painter.setBrush(m_subject->currentBrush()); + painter.setPattern(m_subject->currentPattern()); + painter.setOpacity(m_opacity); + painter.setCompositeOp(m_compositeOp); + KisPaintOp * op = KisPaintOpRegistry::instance()->paintOp(m_subject->currentPaintop(), m_subject->currentPaintopSettings(), &painter); + painter.setPaintOp(op); + + painter.paintRect(m_dragStart, m_dragEnd, PRESSURE_DEFAULT/*event->pressure()*/, event->xTilt(), event->yTilt()); + device->setDirty( painter.dirtyRect() ); + notifyModified(); + + if (m_currentImage->undo()) { + m_currentImage->undoAdapter()->addCommand(painter.endTransaction()); + } + } +} + +void KisToolRectangle::draw(const KisPoint& start, const KisPoint& end ) +{ + if (!m_subject) + return; + + KisCanvasController *controller = m_subject->canvasController (); + KisCanvas *canvas = controller->kiscanvas(); + KisCanvasPainter p (canvas); + + p.setRasterOp (TQt::NotROP); + p.drawRect (TQRect (controller->windowToView (start).floorTQPoint(), controller->windowToView (end).floorTQPoint())); + p.end (); +} + +void KisToolRectangle::setup(TDEActionCollection *collection) +{ + m_action = static_cast(collection->action(name())); + + if (m_action == 0) { + m_action = new TDERadioAction(i18n("&Rectangle"), + "tool_rectangle", + TQt::Key_F6, + this, + TQT_SLOT(activate()), + collection, + name()); + m_action->setToolTip(i18n("Draw a rectangle")); + m_action->setExclusiveGroup("tools"); + m_ownAction = true; + } +} + +#include "kis_tool_rectangle.moc" diff --git a/chalk/plugins/tools/defaulttools/kis_tool_text.cc b/chalk/plugins/tools/defaulttools/kis_tool_text.cpp similarity index 100% rename from chalk/plugins/tools/defaulttools/kis_tool_text.cc rename to chalk/plugins/tools/defaulttools/kis_tool_text.cpp diff --git a/chalk/plugins/tools/defaulttools/kis_tool_zoom.cc b/chalk/plugins/tools/defaulttools/kis_tool_zoom.cpp similarity index 100% rename from chalk/plugins/tools/defaulttools/kis_tool_zoom.cc rename to chalk/plugins/tools/defaulttools/kis_tool_zoom.cpp diff --git a/chalk/plugins/tools/selectiontools/Makefile.am b/chalk/plugins/tools/selectiontools/Makefile.am index febfd514c..0f1b8474d 100644 --- a/chalk/plugins/tools/selectiontools/Makefile.am +++ b/chalk/plugins/tools/selectiontools/Makefile.am @@ -9,10 +9,10 @@ INCLUDES = -I$(srcdir)/../../../sdk \ $(KOFFICE_INCLUDES) \ $(all_includes) -chalkselectiontools_la_SOURCES = kis_tool_move_selection.cc \ - kis_tool_select_brush.cc kis_tool_select_contiguous.cc kis_tool_select_elliptical.cc \ - kis_tool_select_eraser.cc kis_tool_select_outline.cc kis_tool_select_polygonal.cc \ - kis_tool_select_rectangular.cc selection_tools.cc +chalkselectiontools_la_SOURCES = kis_tool_move_selection.cpp \ + kis_tool_select_brush.cpp kis_tool_select_contiguous.cpp kis_tool_select_elliptical.cpp \ + kis_tool_select_eraser.cpp kis_tool_select_outline.cpp kis_tool_select_polygonal.cpp \ + kis_tool_select_rectangular.cpp selection_tools.cpp # Install this plugin in the KDE modules directory kde_module_LTLIBRARIES = chalkselectiontools.la diff --git a/chalk/plugins/tools/selectiontools/kis_tool_move_selection.cc b/chalk/plugins/tools/selectiontools/kis_tool_move_selection.cpp similarity index 100% rename from chalk/plugins/tools/selectiontools/kis_tool_move_selection.cc rename to chalk/plugins/tools/selectiontools/kis_tool_move_selection.cpp diff --git a/chalk/plugins/tools/selectiontools/kis_tool_select_brush.cc b/chalk/plugins/tools/selectiontools/kis_tool_select_brush.cc deleted file mode 100644 index acc903620..000000000 --- a/chalk/plugins/tools/selectiontools/kis_tool_select_brush.cc +++ /dev/null @@ -1,168 +0,0 @@ -/* - * kis_tool_select_brush.cc - part of Chalk - * - * Copyright (c) 2004 Boudewijn Rempt - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include "kis_brush.h" -#include "kis_button_press_event.h" -#include "kis_button_release_event.h" -#include "kis_cmb_composite.h" -#include "kis_cursor.h" -#include "kis_doc.h" -#include "kis_paintop.h" -#include "kis_paintop_registry.h" -#include "kis_move_event.h" -#include "kis_painter.h" -#include "kis_selection.h" -#include "kis_tool_select_brush.h" -#include "kis_types.h" -#include "kis_layer.h" -#include "kis_view.h" -#include "kis_selection_options.h" -#include "kis_selected_transaction.h" - -KisToolSelectBrush::KisToolSelectBrush() - : super(i18n("SelectBrush")) -{ - setName("tool_select_brush"); - m_optWidget = 0; - setCursor(KisCursor::load("tool_brush_selection_cursor.png", 5, 5)); - m_paintOnSelection = true; -} - -KisToolSelectBrush::~KisToolSelectBrush() -{ -} - -void KisToolSelectBrush::activate() -{ - super::activate(); - - if (!m_optWidget) - return; - - m_optWidget->slotActivated(); -} - -void KisToolSelectBrush::initPaint(KisEvent* /*e*/) -{ - if (!m_currentImage || !m_currentImage->activeDevice()) return; - - m_mode = PAINT; - m_dragDist = 0; - - // Create painter - KisPaintDeviceSP dev = m_currentImage->activeDevice(); - if (m_painter) - delete m_painter; - bool hasSelection = dev->hasSelection(); - if (m_currentImage->undo()) m_transaction = new KisSelectedTransaction(i18n("Selection Brush"), dev); - if(! hasSelection) - { - dev->selection()->clear(); - dev->emitSelectionChanged(); - } - KisSelectionSP selection = dev->selection(); - - m_target = selection; - m_painter = new KisPainter(selection.data()); - TQ_CHECK_PTR(m_painter); - m_painter->setPaintColor(KisColor(TQt::black, selection->colorSpace())); - m_painter->setBrush(m_subject->currentBrush()); - m_painter->setOpacity(OPACITY_OPAQUE);//m_subject->fgColor().colorSpace()->intensity8(m_subject->fgColor().data())); - m_painter->setCompositeOp(COMPOSITE_OVER); - KisPaintOp * op = KisPaintOpRegistry::instance()->paintOp("paintbrush", 0, painter()); - painter()->setPaintOp(op); // And now the painter owns the op and will destroy it. - - // Set the cursor -- ideally. this should be a mask created from the brush, - // now that X11 can handle colored cursors. -#if 0 - // Setting cursors has no effect until the tool is selected again; this - // should be fixed. - setCursor(KisCursor::brushCursor()); -#endif -} - -void KisToolSelectBrush::endPaint() -{ - m_mode = HOVER; - if (m_currentImage && m_currentImage->activeLayer()) { - if (m_currentImage->undo() && m_painter) { - // If painting in mouse release, make sure painter - // is destructed or end()ed - m_currentImage->undoAdapter()->addCommand(m_transaction); - } - delete m_painter; - m_painter = 0; - if (m_currentImage->activeDevice()) - m_currentImage->activeDevice()->emitSelectionChanged(); - notifyModified(); - } -} - - -void KisToolSelectBrush::setup(TDEActionCollection *collection) -{ - m_action = static_cast(collection->action(name())); - - if (m_action == 0) { - m_action = new TDERadioAction(i18n("&Selection Brush"), - "tool_brush_selection", "Ctrl+Shift+B", this, - TQT_SLOT(activate()), collection, - name()); - TQ_CHECK_PTR(m_action); - m_action->setToolTip(i18n("Paint a selection")); - m_action->setExclusiveGroup("tools"); - m_ownAction = true; - } -} - -TQWidget* KisToolSelectBrush::createOptionWidget(TQWidget* parent) -{ - Q_UNUSED(parent); - // Commented out due to the fact that this doesn't actually work if you change the action -#if 0 - m_optWidget = new KisSelectionOptions(parent, m_subject); - TQ_CHECK_PTR(m_optWidget); - m_optWidget->setCaption(i18n("Selection Brush")); - - TQVBoxLayout * l = dynamic_cast(m_optWidget->layout()); - l->addItem(new TQSpacerItem(1, 1, TQSizePolicy::Fixed, TQSizePolicy::Expanding)); - - return m_optWidget; -#endif - return 0; -} - -TQWidget* KisToolSelectBrush::optionWidget() -{ - return m_optWidget; -} - -#include "kis_tool_select_brush.moc" diff --git a/chalk/plugins/tools/selectiontools/kis_tool_select_brush.cpp b/chalk/plugins/tools/selectiontools/kis_tool_select_brush.cpp new file mode 100644 index 000000000..ba80434f3 --- /dev/null +++ b/chalk/plugins/tools/selectiontools/kis_tool_select_brush.cpp @@ -0,0 +1,168 @@ +/* + * kis_tool_select_brush.cpp - part of Chalk + * + * Copyright (c) 2004 Boudewijn Rempt + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "kis_brush.h" +#include "kis_button_press_event.h" +#include "kis_button_release_event.h" +#include "kis_cmb_composite.h" +#include "kis_cursor.h" +#include "kis_doc.h" +#include "kis_paintop.h" +#include "kis_paintop_registry.h" +#include "kis_move_event.h" +#include "kis_painter.h" +#include "kis_selection.h" +#include "kis_tool_select_brush.h" +#include "kis_types.h" +#include "kis_layer.h" +#include "kis_view.h" +#include "kis_selection_options.h" +#include "kis_selected_transaction.h" + +KisToolSelectBrush::KisToolSelectBrush() + : super(i18n("SelectBrush")) +{ + setName("tool_select_brush"); + m_optWidget = 0; + setCursor(KisCursor::load("tool_brush_selection_cursor.png", 5, 5)); + m_paintOnSelection = true; +} + +KisToolSelectBrush::~KisToolSelectBrush() +{ +} + +void KisToolSelectBrush::activate() +{ + super::activate(); + + if (!m_optWidget) + return; + + m_optWidget->slotActivated(); +} + +void KisToolSelectBrush::initPaint(KisEvent* /*e*/) +{ + if (!m_currentImage || !m_currentImage->activeDevice()) return; + + m_mode = PAINT; + m_dragDist = 0; + + // Create painter + KisPaintDeviceSP dev = m_currentImage->activeDevice(); + if (m_painter) + delete m_painter; + bool hasSelection = dev->hasSelection(); + if (m_currentImage->undo()) m_transaction = new KisSelectedTransaction(i18n("Selection Brush"), dev); + if(! hasSelection) + { + dev->selection()->clear(); + dev->emitSelectionChanged(); + } + KisSelectionSP selection = dev->selection(); + + m_target = selection; + m_painter = new KisPainter(selection.data()); + TQ_CHECK_PTR(m_painter); + m_painter->setPaintColor(KisColor(TQt::black, selection->colorSpace())); + m_painter->setBrush(m_subject->currentBrush()); + m_painter->setOpacity(OPACITY_OPAQUE);//m_subject->fgColor().colorSpace()->intensity8(m_subject->fgColor().data())); + m_painter->setCompositeOp(COMPOSITE_OVER); + KisPaintOp * op = KisPaintOpRegistry::instance()->paintOp("paintbrush", 0, painter()); + painter()->setPaintOp(op); // And now the painter owns the op and will destroy it. + + // Set the cursor -- ideally. this should be a mask created from the brush, + // now that X11 can handle colored cursors. +#if 0 + // Setting cursors has no effect until the tool is selected again; this + // should be fixed. + setCursor(KisCursor::brushCursor()); +#endif +} + +void KisToolSelectBrush::endPaint() +{ + m_mode = HOVER; + if (m_currentImage && m_currentImage->activeLayer()) { + if (m_currentImage->undo() && m_painter) { + // If painting in mouse release, make sure painter + // is destructed or end()ed + m_currentImage->undoAdapter()->addCommand(m_transaction); + } + delete m_painter; + m_painter = 0; + if (m_currentImage->activeDevice()) + m_currentImage->activeDevice()->emitSelectionChanged(); + notifyModified(); + } +} + + +void KisToolSelectBrush::setup(TDEActionCollection *collection) +{ + m_action = static_cast(collection->action(name())); + + if (m_action == 0) { + m_action = new TDERadioAction(i18n("&Selection Brush"), + "tool_brush_selection", "Ctrl+Shift+B", this, + TQT_SLOT(activate()), collection, + name()); + TQ_CHECK_PTR(m_action); + m_action->setToolTip(i18n("Paint a selection")); + m_action->setExclusiveGroup("tools"); + m_ownAction = true; + } +} + +TQWidget* KisToolSelectBrush::createOptionWidget(TQWidget* parent) +{ + Q_UNUSED(parent); + // Commented out due to the fact that this doesn't actually work if you change the action +#if 0 + m_optWidget = new KisSelectionOptions(parent, m_subject); + TQ_CHECK_PTR(m_optWidget); + m_optWidget->setCaption(i18n("Selection Brush")); + + TQVBoxLayout * l = dynamic_cast(m_optWidget->layout()); + l->addItem(new TQSpacerItem(1, 1, TQSizePolicy::Fixed, TQSizePolicy::Expanding)); + + return m_optWidget; +#endif + return 0; +} + +TQWidget* KisToolSelectBrush::optionWidget() +{ + return m_optWidget; +} + +#include "kis_tool_select_brush.moc" diff --git a/chalk/plugins/tools/selectiontools/kis_tool_select_contiguous.cc b/chalk/plugins/tools/selectiontools/kis_tool_select_contiguous.cpp similarity index 100% rename from chalk/plugins/tools/selectiontools/kis_tool_select_contiguous.cc rename to chalk/plugins/tools/selectiontools/kis_tool_select_contiguous.cpp diff --git a/chalk/plugins/tools/selectiontools/kis_tool_select_elliptical.cc b/chalk/plugins/tools/selectiontools/kis_tool_select_elliptical.cc deleted file mode 100644 index def162ef4..000000000 --- a/chalk/plugins/tools/selectiontools/kis_tool_select_elliptical.cc +++ /dev/null @@ -1,321 +0,0 @@ -/* - * kis_tool_select_elliptical.cc -- part of Chalk - * - * Copyright (c) 2004 Boudewijn Rempt (boud@valdyas.org) - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include -#include -#include -#include - -#include -#include -#include -#include - -#include "kis_autobrush_resource.h" -#include "kis_canvas_controller.h" -#include "kis_canvas_subject.h" -#include "kis_cursor.h" -#include "kis_image.h" -#include "kis_painter.h" -#include "kis_tool_select_elliptical.h" -#include "kis_layer.h" -#include "kis_undo_adapter.h" -#include "kis_button_press_event.h" -#include "kis_button_release_event.h" -#include "kis_move_event.h" -#include "kis_selection.h" -#include "kis_selection_options.h" -#include "kis_selected_transaction.h" -#include "kis_canvas.h" -#include "kis_canvas_painter.h" - -KisToolSelectElliptical::KisToolSelectElliptical() - : super(i18n("Elliptical Select")) -{ - setName("tool_select_elliptical"); - setCursor(KisCursor::load("tool_elliptical_selection_cursor.png", 6, 6)); - - m_subject = 0; - m_selecting = false; - m_centerPos = KisPoint(0, 0); - m_startPos = KisPoint(0, 0); - m_endPos = KisPoint(0, 0); - m_optWidget = 0; - m_selectAction = SELECTION_ADD; -} - -KisToolSelectElliptical::~KisToolSelectElliptical() -{ -} - -void KisToolSelectElliptical::activate() -{ - super::activate(); - - if (!m_optWidget) - return; - - m_optWidget->slotActivated(); -} - -void KisToolSelectElliptical::update(KisCanvasSubject *subject) -{ - m_subject = subject; - super::update(m_subject); -} - -void KisToolSelectElliptical::paint(KisCanvasPainter& gc) -{ - if (m_selecting) - paintOutline(gc, TQRect()); -} - -void KisToolSelectElliptical::paint(KisCanvasPainter& gc, const TQRect& rc) -{ - if (m_selecting) - paintOutline(gc, rc); -} - -void KisToolSelectElliptical::clearSelection() -{ - if (m_subject) { - KisCanvasController *controller = m_subject->canvasController(); - KisImageSP img = m_subject->currentImg(); - - Q_ASSERT(controller); - -// if (img && img->floatingSelection().data() != 0) { -// img->unsetFloatingSelection(); -// controller->canvas()->update(); -// } - - m_startPos = KisPoint(0, 0); - m_endPos = KisPoint(0, 0); - m_selecting = false; - } -} - -void KisToolSelectElliptical::buttonPress(KisButtonPressEvent *e) -{ - if (m_subject) { - KisImageSP img = m_subject->currentImg(); - - if (img && img->activeDevice() && e->button() == Qt::LeftButton) { - clearSelection(); - m_startPos = m_endPos = m_centerPos = e->pos(); - m_selecting = true; - paintOutline(); - } - } -} - -void KisToolSelectElliptical::move(KisMoveEvent *e) -{ - if (m_subject && m_selecting) { - paintOutline(); - // move (alt) or resize ellipse - if (e->state() & TQt::AltButton) { - KisPoint trans = e->pos() - m_endPos; - m_startPos += trans; - m_endPos += trans; - } else { - KisPoint diag = e->pos() - (e->state() & TQt::ControlButton - ? m_centerPos : m_startPos); - // circle? - if (e->state() & TQt::ShiftButton) { - double size = TQMAX(fabs(diag.x()), fabs(diag.y())); - double w = diag.x() < 0 ? -size : size; - double h = diag.y() < 0 ? -size : size; - diag = KisPoint(w, h); - } - - // resize around center point? - if (e->state() & TQt::ControlButton) { - m_startPos = m_centerPos - diag; - m_endPos = m_centerPos + diag; - } else { - m_endPos = m_startPos + diag; - } - } - paintOutline(); - m_centerPos = KisPoint((m_startPos.x() + m_endPos.x()) / 2, - (m_startPos.y() + m_endPos.y()) / 2); - } -} - -void KisToolSelectElliptical::buttonRelease(KisButtonReleaseEvent *e) -{ - if (m_subject && m_selecting && e->button() == Qt::LeftButton) { - - paintOutline(); - - if (m_startPos == m_endPos) { - clearSelection(); - } else { - TQApplication::setOverrideCursor(KisCursor::waitCursor()); - KisImageSP img = m_subject->currentImg(); - - if (!img) - return; - - if (m_endPos.y() < 0) - m_endPos.setY(0); - - if (m_endPos.y() > img->height()) - m_endPos.setY(img->height()); - - if (m_endPos.x() < 0) - m_endPos.setX(0); - - if (m_endPos.x() > img->width()) - m_endPos.setX(img->width()); - - if (img && img->activeDevice()) { - KisPaintDeviceSP dev = img->activeDevice(); - KisSelectedTransaction *t = 0; - if (img->undo()) t = new KisSelectedTransaction(i18n("Elliptical Selection"), dev); - - bool hasSelection = dev->hasSelection(); - if(! hasSelection) - { - dev->selection()->clear(); - if(m_selectAction==SELECTION_SUBTRACT) - dev->selection()->invert(); - } - TQRect rc( m_startPos.floorTQPoint(), m_endPos.floorTQPoint()); - rc = rc.normalize(); - - KisSelectionSP tmpSel = new KisSelection(dev); - KisAutobrushCircleShape shape(rc.width(),rc.height(), 1, 1); - TQ_UINT8 value; - for (int y = 0; y <= rc.height(); y++) - for (int x = 0; x <= rc.width(); x++) - { - value = MAX_SELECTED - shape.valueAt(x,y); - tmpSel->setSelected( x+rc.x(), y+rc.y(), value); - } - switch(m_selectAction) - { - case SELECTION_ADD: - dev->addSelection(tmpSel); - break; - case SELECTION_SUBTRACT: - dev->subtractSelection(tmpSel); - break; - } - - if(hasSelection) { - dev->setDirty(rc); - dev->emitSelectionChanged(rc); - } else { - dev->setDirty(); - dev->emitSelectionChanged(); - } - - if (img->undo()) - img->undoAdapter()->addCommand(t); - - TQApplication::restoreOverrideCursor(); - } - } - m_selecting = false; - } -} - -void KisToolSelectElliptical::paintOutline() -{ - if (m_subject) { - KisCanvasController *controller = m_subject->canvasController(); - KisCanvas *canvas = controller->kiscanvas(); - KisCanvasPainter gc(canvas); - TQRect rc; - - paintOutline(gc, rc); - } -} - -void KisToolSelectElliptical::paintOutline(KisCanvasPainter& gc, const TQRect&) -{ - if (m_subject) { - KisCanvasController *controller = m_subject->canvasController(); - RasterOp op = gc.rasterOp(); - TQPen old = gc.pen(); - TQPen pen(TQt::DotLine); - TQPoint start; - TQPoint end; - - Q_ASSERT(controller); - start = controller->windowToView(m_startPos).floorTQPoint(); - end = controller->windowToView(m_endPos).floorTQPoint(); - - gc.setRasterOp(TQt::NotROP); - gc.setPen(pen); - gc.drawEllipse(TQRect(start, end)); - gc.setRasterOp(op); - gc.setPen(old); - } -} - -void KisToolSelectElliptical::slotSetAction(int action) { - if (action >= SELECTION_ADD && action <= SELECTION_SUBTRACT) - m_selectAction =(enumSelectionMode)action; -} - -void KisToolSelectElliptical::setup(TDEActionCollection *collection) -{ - m_action = static_cast(collection->action(name())); - - if (m_action == 0) { - m_action = new TDERadioAction(i18n("&Elliptical Selection"), - "tool_elliptical_selection" , - TQt::Key_J, - this, - TQT_SLOT(activate()), - collection, - name()); - TQ_CHECK_PTR(m_action); - m_action->setToolTip(i18n("Select an elliptical area")); - m_action->setExclusiveGroup("tools"); - m_ownAction = true; - } -} - -TQWidget* KisToolSelectElliptical::createOptionWidget(TQWidget* parent) -{ - m_optWidget = new KisSelectionOptions(parent, m_subject); - TQ_CHECK_PTR(m_optWidget); - m_optWidget->setCaption(i18n("Elliptical Selection")); - - connect (m_optWidget, TQT_SIGNAL(actionChanged(int)), this, TQT_SLOT(slotSetAction(int))); - - TQVBoxLayout * l = dynamic_cast(m_optWidget->layout()); - l->addItem(new TQSpacerItem(1, 1, TQSizePolicy::Fixed, TQSizePolicy::Expanding)); - - return m_optWidget; -} - -TQWidget* KisToolSelectElliptical::optionWidget() -{ - return m_optWidget; -} - - - -#include "kis_tool_select_elliptical.moc" diff --git a/chalk/plugins/tools/selectiontools/kis_tool_select_elliptical.cpp b/chalk/plugins/tools/selectiontools/kis_tool_select_elliptical.cpp new file mode 100644 index 000000000..f85da3327 --- /dev/null +++ b/chalk/plugins/tools/selectiontools/kis_tool_select_elliptical.cpp @@ -0,0 +1,321 @@ +/* + * kis_tool_select_elliptical.cpp -- part of Chalk + * + * Copyright (c) 2004 Boudewijn Rempt (boud@valdyas.org) + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "kis_autobrush_resource.h" +#include "kis_canvas_controller.h" +#include "kis_canvas_subject.h" +#include "kis_cursor.h" +#include "kis_image.h" +#include "kis_painter.h" +#include "kis_tool_select_elliptical.h" +#include "kis_layer.h" +#include "kis_undo_adapter.h" +#include "kis_button_press_event.h" +#include "kis_button_release_event.h" +#include "kis_move_event.h" +#include "kis_selection.h" +#include "kis_selection_options.h" +#include "kis_selected_transaction.h" +#include "kis_canvas.h" +#include "kis_canvas_painter.h" + +KisToolSelectElliptical::KisToolSelectElliptical() + : super(i18n("Elliptical Select")) +{ + setName("tool_select_elliptical"); + setCursor(KisCursor::load("tool_elliptical_selection_cursor.png", 6, 6)); + + m_subject = 0; + m_selecting = false; + m_centerPos = KisPoint(0, 0); + m_startPos = KisPoint(0, 0); + m_endPos = KisPoint(0, 0); + m_optWidget = 0; + m_selectAction = SELECTION_ADD; +} + +KisToolSelectElliptical::~KisToolSelectElliptical() +{ +} + +void KisToolSelectElliptical::activate() +{ + super::activate(); + + if (!m_optWidget) + return; + + m_optWidget->slotActivated(); +} + +void KisToolSelectElliptical::update(KisCanvasSubject *subject) +{ + m_subject = subject; + super::update(m_subject); +} + +void KisToolSelectElliptical::paint(KisCanvasPainter& gc) +{ + if (m_selecting) + paintOutline(gc, TQRect()); +} + +void KisToolSelectElliptical::paint(KisCanvasPainter& gc, const TQRect& rc) +{ + if (m_selecting) + paintOutline(gc, rc); +} + +void KisToolSelectElliptical::clearSelection() +{ + if (m_subject) { + KisCanvasController *controller = m_subject->canvasController(); + KisImageSP img = m_subject->currentImg(); + + Q_ASSERT(controller); + +// if (img && img->floatingSelection().data() != 0) { +// img->unsetFloatingSelection(); +// controller->canvas()->update(); +// } + + m_startPos = KisPoint(0, 0); + m_endPos = KisPoint(0, 0); + m_selecting = false; + } +} + +void KisToolSelectElliptical::buttonPress(KisButtonPressEvent *e) +{ + if (m_subject) { + KisImageSP img = m_subject->currentImg(); + + if (img && img->activeDevice() && e->button() == Qt::LeftButton) { + clearSelection(); + m_startPos = m_endPos = m_centerPos = e->pos(); + m_selecting = true; + paintOutline(); + } + } +} + +void KisToolSelectElliptical::move(KisMoveEvent *e) +{ + if (m_subject && m_selecting) { + paintOutline(); + // move (alt) or resize ellipse + if (e->state() & TQt::AltButton) { + KisPoint trans = e->pos() - m_endPos; + m_startPos += trans; + m_endPos += trans; + } else { + KisPoint diag = e->pos() - (e->state() & TQt::ControlButton + ? m_centerPos : m_startPos); + // circle? + if (e->state() & TQt::ShiftButton) { + double size = TQMAX(fabs(diag.x()), fabs(diag.y())); + double w = diag.x() < 0 ? -size : size; + double h = diag.y() < 0 ? -size : size; + diag = KisPoint(w, h); + } + + // resize around center point? + if (e->state() & TQt::ControlButton) { + m_startPos = m_centerPos - diag; + m_endPos = m_centerPos + diag; + } else { + m_endPos = m_startPos + diag; + } + } + paintOutline(); + m_centerPos = KisPoint((m_startPos.x() + m_endPos.x()) / 2, + (m_startPos.y() + m_endPos.y()) / 2); + } +} + +void KisToolSelectElliptical::buttonRelease(KisButtonReleaseEvent *e) +{ + if (m_subject && m_selecting && e->button() == Qt::LeftButton) { + + paintOutline(); + + if (m_startPos == m_endPos) { + clearSelection(); + } else { + TQApplication::setOverrideCursor(KisCursor::waitCursor()); + KisImageSP img = m_subject->currentImg(); + + if (!img) + return; + + if (m_endPos.y() < 0) + m_endPos.setY(0); + + if (m_endPos.y() > img->height()) + m_endPos.setY(img->height()); + + if (m_endPos.x() < 0) + m_endPos.setX(0); + + if (m_endPos.x() > img->width()) + m_endPos.setX(img->width()); + + if (img && img->activeDevice()) { + KisPaintDeviceSP dev = img->activeDevice(); + KisSelectedTransaction *t = 0; + if (img->undo()) t = new KisSelectedTransaction(i18n("Elliptical Selection"), dev); + + bool hasSelection = dev->hasSelection(); + if(! hasSelection) + { + dev->selection()->clear(); + if(m_selectAction==SELECTION_SUBTRACT) + dev->selection()->invert(); + } + TQRect rc( m_startPos.floorTQPoint(), m_endPos.floorTQPoint()); + rc = rc.normalize(); + + KisSelectionSP tmpSel = new KisSelection(dev); + KisAutobrushCircleShape shape(rc.width(),rc.height(), 1, 1); + TQ_UINT8 value; + for (int y = 0; y <= rc.height(); y++) + for (int x = 0; x <= rc.width(); x++) + { + value = MAX_SELECTED - shape.valueAt(x,y); + tmpSel->setSelected( x+rc.x(), y+rc.y(), value); + } + switch(m_selectAction) + { + case SELECTION_ADD: + dev->addSelection(tmpSel); + break; + case SELECTION_SUBTRACT: + dev->subtractSelection(tmpSel); + break; + } + + if(hasSelection) { + dev->setDirty(rc); + dev->emitSelectionChanged(rc); + } else { + dev->setDirty(); + dev->emitSelectionChanged(); + } + + if (img->undo()) + img->undoAdapter()->addCommand(t); + + TQApplication::restoreOverrideCursor(); + } + } + m_selecting = false; + } +} + +void KisToolSelectElliptical::paintOutline() +{ + if (m_subject) { + KisCanvasController *controller = m_subject->canvasController(); + KisCanvas *canvas = controller->kiscanvas(); + KisCanvasPainter gc(canvas); + TQRect rc; + + paintOutline(gc, rc); + } +} + +void KisToolSelectElliptical::paintOutline(KisCanvasPainter& gc, const TQRect&) +{ + if (m_subject) { + KisCanvasController *controller = m_subject->canvasController(); + RasterOp op = gc.rasterOp(); + TQPen old = gc.pen(); + TQPen pen(TQt::DotLine); + TQPoint start; + TQPoint end; + + Q_ASSERT(controller); + start = controller->windowToView(m_startPos).floorTQPoint(); + end = controller->windowToView(m_endPos).floorTQPoint(); + + gc.setRasterOp(TQt::NotROP); + gc.setPen(pen); + gc.drawEllipse(TQRect(start, end)); + gc.setRasterOp(op); + gc.setPen(old); + } +} + +void KisToolSelectElliptical::slotSetAction(int action) { + if (action >= SELECTION_ADD && action <= SELECTION_SUBTRACT) + m_selectAction =(enumSelectionMode)action; +} + +void KisToolSelectElliptical::setup(TDEActionCollection *collection) +{ + m_action = static_cast(collection->action(name())); + + if (m_action == 0) { + m_action = new TDERadioAction(i18n("&Elliptical Selection"), + "tool_elliptical_selection" , + TQt::Key_J, + this, + TQT_SLOT(activate()), + collection, + name()); + TQ_CHECK_PTR(m_action); + m_action->setToolTip(i18n("Select an elliptical area")); + m_action->setExclusiveGroup("tools"); + m_ownAction = true; + } +} + +TQWidget* KisToolSelectElliptical::createOptionWidget(TQWidget* parent) +{ + m_optWidget = new KisSelectionOptions(parent, m_subject); + TQ_CHECK_PTR(m_optWidget); + m_optWidget->setCaption(i18n("Elliptical Selection")); + + connect (m_optWidget, TQT_SIGNAL(actionChanged(int)), this, TQT_SLOT(slotSetAction(int))); + + TQVBoxLayout * l = dynamic_cast(m_optWidget->layout()); + l->addItem(new TQSpacerItem(1, 1, TQSizePolicy::Fixed, TQSizePolicy::Expanding)); + + return m_optWidget; +} + +TQWidget* KisToolSelectElliptical::optionWidget() +{ + return m_optWidget; +} + + + +#include "kis_tool_select_elliptical.moc" diff --git a/chalk/plugins/tools/selectiontools/kis_tool_select_eraser.cc b/chalk/plugins/tools/selectiontools/kis_tool_select_eraser.cc deleted file mode 100644 index af7f8d84a..000000000 --- a/chalk/plugins/tools/selectiontools/kis_tool_select_eraser.cc +++ /dev/null @@ -1,156 +0,0 @@ -/* - * kis_tool_select_brush.cc - part of Chalk - * - * Copyright (c) 2004 Boudewijn Rempt - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include -#include -#include -#include - -#include -#include -#include -#include - -#include "kis_brush.h" -#include "kis_layer.h" -#include "kis_paintop.h" -#include "kis_paintop_registry.h" -#include "kis_button_press_event.h" -#include "kis_button_release_event.h" -#include "kis_cmb_composite.h" -#include "kis_cursor.h" -#include "kis_doc.h" -#include "kis_move_event.h" -#include "kis_painter.h" -#include "kis_selection.h" -#include "kis_tool_select_eraser.h" -#include "kis_types.h" -#include "kis_view.h" -#include "kis_selection_options.h" - -KisToolSelectEraser::KisToolSelectEraser() - : super(i18n("SelectEraser")) -{ - setName("tool_select_eraser"); - setCursor(KisCursor::load("tool_eraser_selection_cursor.png", 5, 5)); - m_optWidget = 0; - m_paintOnSelection = true; -} - -KisToolSelectEraser::~KisToolSelectEraser() -{ -} - -void KisToolSelectEraser::activate() -{ - super::activate(); - - if (!m_optWidget) - return; - - m_optWidget->slotActivated(); -} - -void KisToolSelectEraser::initPaint(KisEvent */*e*/) -{ - if (!m_currentImage || !m_currentImage->activeDevice()) return; - - m_mode = PAINT; - m_dragDist = 0; - - // Create painter - KisPaintDeviceSP dev = m_currentImage->activeDevice(); - - if (dev == 0) return; - - if (m_painter) - delete m_painter; - if(! dev->hasSelection()) - { - dev->selection()->clear(); - dev->emitSelectionChanged(); - } - KisSelectionSP selection = dev->selection(); - - m_target = selection; - m_painter = new KisPainter(selection.data()); - TQ_CHECK_PTR(m_painter); - m_painter->beginTransaction(i18n("Selection Eraser")); - m_painter->setPaintColor(KisColor(TQt::white, selection->colorSpace())); - m_painter->setBrush(m_subject->currentBrush()); - m_painter->setOpacity(OPACITY_OPAQUE); - m_painter->setCompositeOp(COMPOSITE_ERASE); - KisPaintOp * op = KisPaintOpRegistry::instance()->paintOp("eraser", 0, painter()); - painter()->setPaintOp(op); // And now the painter owns the op and will destroy it. - - // Set the cursor -- ideally. this should be a mask created from the brush, - // now that X11 can handle colored cursors. -#if 0 - // Setting cursors has no effect until the tool is selected again; this - // should be fixed. - setCursor(KisCursor::eraserCursor()); -#endif -} - -void KisToolSelectEraser::endPaint() { - super::endPaint(); - if (m_currentImage && m_currentImage->activeDevice()) - m_currentImage->activeDevice()->emitSelectionChanged(); -} -void KisToolSelectEraser::setup(TDEActionCollection *collection) -{ - m_action = static_cast(collection->action(name())); - - if (m_action == 0) { - m_action = new TDERadioAction(i18n("Selection &Eraser"), - "tool_eraser_selection", "Ctrl+Shift+E", this, - TQT_SLOT(activate()), collection, - name()); - TQ_CHECK_PTR(m_action); - m_action->setToolTip(i18n("Erase parts of a selection")); - m_action->setExclusiveGroup("tools"); - m_ownAction = true; - } -} - -TQWidget* KisToolSelectEraser::createOptionWidget(TQWidget* parent) -{ - Q_UNUSED(parent); - // Commented out due to the fact that this doesn't actually work if you change the action -#if 0 - m_optWidget = new KisSelectionOptions(parent, m_subject); - TQ_CHECK_PTR(m_optWidget); - m_optWidget->setCaption(i18n("Selection Eraser")); - - TQVBoxLayout * l = dynamic_cast(m_optWidget->layout()); - l->addItem(new TQSpacerItem(1, 1, TQSizePolicy::Fixed, TQSizePolicy::Expanding)); - - return m_optWidget; -#endif - return 0; -} - -TQWidget* KisToolSelectEraser::optionWidget() -{ - return m_optWidget; -} - -#include "kis_tool_select_eraser.moc" - diff --git a/chalk/plugins/tools/selectiontools/kis_tool_select_eraser.cpp b/chalk/plugins/tools/selectiontools/kis_tool_select_eraser.cpp new file mode 100644 index 000000000..9cfef0a80 --- /dev/null +++ b/chalk/plugins/tools/selectiontools/kis_tool_select_eraser.cpp @@ -0,0 +1,156 @@ +/* + * kis_tool_select_brush.cpp - part of Chalk + * + * Copyright (c) 2004 Boudewijn Rempt + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "kis_brush.h" +#include "kis_layer.h" +#include "kis_paintop.h" +#include "kis_paintop_registry.h" +#include "kis_button_press_event.h" +#include "kis_button_release_event.h" +#include "kis_cmb_composite.h" +#include "kis_cursor.h" +#include "kis_doc.h" +#include "kis_move_event.h" +#include "kis_painter.h" +#include "kis_selection.h" +#include "kis_tool_select_eraser.h" +#include "kis_types.h" +#include "kis_view.h" +#include "kis_selection_options.h" + +KisToolSelectEraser::KisToolSelectEraser() + : super(i18n("SelectEraser")) +{ + setName("tool_select_eraser"); + setCursor(KisCursor::load("tool_eraser_selection_cursor.png", 5, 5)); + m_optWidget = 0; + m_paintOnSelection = true; +} + +KisToolSelectEraser::~KisToolSelectEraser() +{ +} + +void KisToolSelectEraser::activate() +{ + super::activate(); + + if (!m_optWidget) + return; + + m_optWidget->slotActivated(); +} + +void KisToolSelectEraser::initPaint(KisEvent */*e*/) +{ + if (!m_currentImage || !m_currentImage->activeDevice()) return; + + m_mode = PAINT; + m_dragDist = 0; + + // Create painter + KisPaintDeviceSP dev = m_currentImage->activeDevice(); + + if (dev == 0) return; + + if (m_painter) + delete m_painter; + if(! dev->hasSelection()) + { + dev->selection()->clear(); + dev->emitSelectionChanged(); + } + KisSelectionSP selection = dev->selection(); + + m_target = selection; + m_painter = new KisPainter(selection.data()); + TQ_CHECK_PTR(m_painter); + m_painter->beginTransaction(i18n("Selection Eraser")); + m_painter->setPaintColor(KisColor(TQt::white, selection->colorSpace())); + m_painter->setBrush(m_subject->currentBrush()); + m_painter->setOpacity(OPACITY_OPAQUE); + m_painter->setCompositeOp(COMPOSITE_ERASE); + KisPaintOp * op = KisPaintOpRegistry::instance()->paintOp("eraser", 0, painter()); + painter()->setPaintOp(op); // And now the painter owns the op and will destroy it. + + // Set the cursor -- ideally. this should be a mask created from the brush, + // now that X11 can handle colored cursors. +#if 0 + // Setting cursors has no effect until the tool is selected again; this + // should be fixed. + setCursor(KisCursor::eraserCursor()); +#endif +} + +void KisToolSelectEraser::endPaint() { + super::endPaint(); + if (m_currentImage && m_currentImage->activeDevice()) + m_currentImage->activeDevice()->emitSelectionChanged(); +} +void KisToolSelectEraser::setup(TDEActionCollection *collection) +{ + m_action = static_cast(collection->action(name())); + + if (m_action == 0) { + m_action = new TDERadioAction(i18n("Selection &Eraser"), + "tool_eraser_selection", "Ctrl+Shift+E", this, + TQT_SLOT(activate()), collection, + name()); + TQ_CHECK_PTR(m_action); + m_action->setToolTip(i18n("Erase parts of a selection")); + m_action->setExclusiveGroup("tools"); + m_ownAction = true; + } +} + +TQWidget* KisToolSelectEraser::createOptionWidget(TQWidget* parent) +{ + Q_UNUSED(parent); + // Commented out due to the fact that this doesn't actually work if you change the action +#if 0 + m_optWidget = new KisSelectionOptions(parent, m_subject); + TQ_CHECK_PTR(m_optWidget); + m_optWidget->setCaption(i18n("Selection Eraser")); + + TQVBoxLayout * l = dynamic_cast(m_optWidget->layout()); + l->addItem(new TQSpacerItem(1, 1, TQSizePolicy::Fixed, TQSizePolicy::Expanding)); + + return m_optWidget; +#endif + return 0; +} + +TQWidget* KisToolSelectEraser::optionWidget() +{ + return m_optWidget; +} + +#include "kis_tool_select_eraser.moc" + diff --git a/chalk/plugins/tools/selectiontools/kis_tool_select_outline.cc b/chalk/plugins/tools/selectiontools/kis_tool_select_outline.cpp similarity index 100% rename from chalk/plugins/tools/selectiontools/kis_tool_select_outline.cc rename to chalk/plugins/tools/selectiontools/kis_tool_select_outline.cpp diff --git a/chalk/plugins/tools/selectiontools/kis_tool_select_polygonal.cc b/chalk/plugins/tools/selectiontools/kis_tool_select_polygonal.cpp similarity index 100% rename from chalk/plugins/tools/selectiontools/kis_tool_select_polygonal.cc rename to chalk/plugins/tools/selectiontools/kis_tool_select_polygonal.cpp diff --git a/chalk/plugins/tools/selectiontools/kis_tool_select_rectangular.cc b/chalk/plugins/tools/selectiontools/kis_tool_select_rectangular.cc deleted file mode 100644 index 09d338663..000000000 --- a/chalk/plugins/tools/selectiontools/kis_tool_select_rectangular.cc +++ /dev/null @@ -1,323 +0,0 @@ - -/* - * kis_tool_select_rectangular.cc -- part of Chalk - * - * Copyright (c) 1999 Michael Koch - * 2001 John Califf - * 2002 Patrick Julien - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include -#include -#include -#include - -#include -#include -#include -#include - -#include "kis_canvas_controller.h" -#include "kis_canvas_subject.h" -#include "kis_cursor.h" -#include "kis_image.h" -#include "kis_painter.h" -#include "kis_layer.h" -#include "kis_tool_select_rectangular.h" -#include "kis_undo_adapter.h" -#include "kis_button_press_event.h" -#include "kis_button_release_event.h" -#include "kis_move_event.h" -#include "kis_selection.h" -#include "kis_selection_options.h" -#include -#include "kis_canvas.h" -#include "kis_canvas_painter.h" - -KisToolSelectRectangular::KisToolSelectRectangular() - : super(i18n("Rectangular Select Tool")) -{ - setName("tool_select_rectangular"); - setCursor(KisCursor::load("tool_rectangular_selection_cursor.png", 6, 6)); - m_subject = 0; - m_selecting = false; - m_centerPos = KisPoint(0, 0); - m_startPos = KisPoint(0, 0); - m_endPos = KisPoint(0, 0); - m_optWidget = 0; - m_selectAction = SELECTION_ADD; -} - -KisToolSelectRectangular::~KisToolSelectRectangular() -{ -} - -void KisToolSelectRectangular::activate() -{ - super::activate(); - - if (!m_optWidget) - return; - - m_optWidget->slotActivated(); -} - -void KisToolSelectRectangular::update(KisCanvasSubject *subject) -{ - m_subject = subject; - super::update(m_subject); -} - -void KisToolSelectRectangular::paint(KisCanvasPainter& gc) -{ - if (m_selecting) - paintOutline(gc, TQRect()); -} - -void KisToolSelectRectangular::paint(KisCanvasPainter& gc, const TQRect& rc) -{ - if (m_selecting) - paintOutline(gc, rc); -} - -void KisToolSelectRectangular::clearSelection() -{ - if (m_subject) { - KisCanvasController *controller = m_subject->canvasController(); - KisImageSP img = m_subject->currentImg(); - - Q_ASSERT(controller); - - m_centerPos = KisPoint(0, 0); - m_startPos = KisPoint(0, 0); - m_endPos = KisPoint(0, 0); - m_selecting = false; - } -} - -void KisToolSelectRectangular::buttonPress(KisButtonPressEvent *e) -{ - if (m_subject) { - KisImageSP img = m_subject->currentImg(); - - if (img && img->activeDevice() && e->button() == Qt::LeftButton) { - clearSelection(); - m_startPos = m_endPos = m_centerPos = e->pos(); - m_selecting = true; - } - } -} - -void KisToolSelectRectangular::move(KisMoveEvent *e) -{ - if (m_subject && m_selecting) { - paintOutline(); - // move (alt) or resize rectangle - if (e->state() & TQt::AltButton) { - KisPoint trans = e->pos() - m_endPos; - m_startPos += trans; - m_endPos += trans; - } else { - KisPoint diag = e->pos() - (e->state() & TQt::ControlButton - ? m_centerPos : m_startPos); - // square? - if (e->state() & TQt::ShiftButton) { - double size = TQMAX(fabs(diag.x()), fabs(diag.y())); - double w = diag.x() < 0 ? -size : size; - double h = diag.y() < 0 ? -size : size; - diag = KisPoint(w, h); - } - - // resize around center point? - if (e->state() & TQt::ControlButton) { - m_startPos = m_centerPos - diag; - m_endPos = m_centerPos + diag; - } else { - m_endPos = m_startPos + diag; - } - } - paintOutline(); - m_centerPos = KisPoint((m_startPos.x() + m_endPos.x()) / 2, - (m_startPos.y() + m_endPos.y()) / 2); - } -} - -void KisToolSelectRectangular::buttonRelease(KisButtonReleaseEvent *e) -{ - if (m_subject && m_selecting && e->button() == Qt::LeftButton) { - - paintOutline(); - - if (m_startPos == m_endPos) { - clearSelection(); - } else { - KisImageSP img = m_subject->currentImg(); - - if (!img) - return; - - if (m_endPos.y() < 0) - m_endPos.setY(0); - - if (m_endPos.y() > img->height()) - m_endPos.setY(img->height()); - - if (m_endPos.x() < 0) - m_endPos.setX(0); - - if (m_endPos.x() > img->width()) - m_endPos.setX(img->width()); - if (img && img->activeDevice()) { - - TQApplication::setOverrideCursor(KisCursor::waitCursor()); - KisPaintDeviceSP dev = img->activeDevice(); - bool hasSelection = dev->hasSelection(); - - KisSelectedTransaction *t = 0; - if (img->undo()) t = new KisSelectedTransaction(i18n("Rectangular Selection"), dev); - KisSelectionSP selection = dev->selection(); - TQRect rc(m_startPos.floorTQPoint(), m_endPos.floorTQPoint()); - rc = rc.normalize(); - - // We don't want the border of the 'rectangle' to be included in our selection - rc.setSize(rc.size() - TQSize(1,1)); - - if(! hasSelection) - { - selection->clear(); - if(m_selectAction==SELECTION_SUBTRACT) - selection->invert(); - } - - KisSelectionSP tmpSel = new KisSelection(dev); - tmpSel->select(rc); - switch(m_selectAction) - { - case SELECTION_ADD: - dev->addSelection(tmpSel); - break; - case SELECTION_SUBTRACT: - dev->subtractSelection(tmpSel); - break; - default: - break; - } - - - if(hasSelection) { - dev->setDirty(rc); - dev->emitSelectionChanged(rc); - } else { - dev->setDirty(); - dev->emitSelectionChanged(); - } - - if (img->undo()) - img->undoAdapter()->addCommand(t); - - KisCanvasController *controller = m_subject -> canvasController(); - controller -> kiscanvas() -> update(); - - TQApplication::restoreOverrideCursor(); - } - } - - m_selecting = false; - } -} - -void KisToolSelectRectangular::paintOutline() -{ - if (m_subject) { - KisCanvasController *controller = m_subject->canvasController(); - KisCanvas *canvas = controller->kiscanvas(); - KisCanvasPainter gc(canvas); - TQRect rc; - - paintOutline(gc, rc); - } -} - -void KisToolSelectRectangular::paintOutline(KisCanvasPainter& gc, const TQRect&) -{ - if (m_subject) { - KisCanvasController *controller = m_subject->canvasController(); - RasterOp op = gc.rasterOp(); - TQPen old = gc.pen(); - TQPen pen(TQt::DotLine); - TQPoint start; - TQPoint end; - - Q_ASSERT(controller); - start = controller->windowToView(m_startPos.floorTQPoint()); - end = controller->windowToView(m_endPos.floorTQPoint()); - - gc.setRasterOp(TQt::NotROP); - gc.setPen(pen); - gc.drawRect(TQRect(start, end)); - gc.setRasterOp(op); - gc.setPen(old); - } -} - -void KisToolSelectRectangular::slotSetAction(int action) { - if (action >= SELECTION_ADD && action <= SELECTION_SUBTRACT) - m_selectAction =(enumSelectionMode)action; -} - -void KisToolSelectRectangular::setup(TDEActionCollection *collection) -{ - m_action = static_cast(collection->action(name())); - - if (m_action == 0) { - m_action = new TDERadioAction(i18n("&Rectangular Selection"), - "tool_rect_selection", - TQt::Key_R, - this, - TQT_SLOT(activate()), - collection, - name()); - TQ_CHECK_PTR(m_action); - m_action->setExclusiveGroup("tools"); - m_action->setToolTip(i18n("Select a rectangular area")); - m_ownAction = true; - } -} - -TQWidget* KisToolSelectRectangular::createOptionWidget(TQWidget* parent) -{ - m_optWidget = new KisSelectionOptions(parent, m_subject); - TQ_CHECK_PTR(m_optWidget); - m_optWidget->setCaption(i18n("Rectangular Selection")); - - connect (m_optWidget, TQT_SIGNAL(actionChanged(int)), this, TQT_SLOT(slotSetAction(int))); - - TQVBoxLayout * l = dynamic_cast(m_optWidget->layout()); - l->addItem(new TQSpacerItem(1, 1, TQSizePolicy::Fixed, TQSizePolicy::Expanding)); - - return m_optWidget; -} - -TQWidget* KisToolSelectRectangular::optionWidget() -{ - return m_optWidget; -} - - - - -#include "kis_tool_select_rectangular.moc" diff --git a/chalk/plugins/tools/selectiontools/kis_tool_select_rectangular.cpp b/chalk/plugins/tools/selectiontools/kis_tool_select_rectangular.cpp new file mode 100644 index 000000000..5a6772bac --- /dev/null +++ b/chalk/plugins/tools/selectiontools/kis_tool_select_rectangular.cpp @@ -0,0 +1,323 @@ + +/* + * kis_tool_select_rectangular.cpp -- part of Chalk + * + * Copyright (c) 1999 Michael Koch + * 2001 John Califf + * 2002 Patrick Julien + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "kis_canvas_controller.h" +#include "kis_canvas_subject.h" +#include "kis_cursor.h" +#include "kis_image.h" +#include "kis_painter.h" +#include "kis_layer.h" +#include "kis_tool_select_rectangular.h" +#include "kis_undo_adapter.h" +#include "kis_button_press_event.h" +#include "kis_button_release_event.h" +#include "kis_move_event.h" +#include "kis_selection.h" +#include "kis_selection_options.h" +#include +#include "kis_canvas.h" +#include "kis_canvas_painter.h" + +KisToolSelectRectangular::KisToolSelectRectangular() + : super(i18n("Rectangular Select Tool")) +{ + setName("tool_select_rectangular"); + setCursor(KisCursor::load("tool_rectangular_selection_cursor.png", 6, 6)); + m_subject = 0; + m_selecting = false; + m_centerPos = KisPoint(0, 0); + m_startPos = KisPoint(0, 0); + m_endPos = KisPoint(0, 0); + m_optWidget = 0; + m_selectAction = SELECTION_ADD; +} + +KisToolSelectRectangular::~KisToolSelectRectangular() +{ +} + +void KisToolSelectRectangular::activate() +{ + super::activate(); + + if (!m_optWidget) + return; + + m_optWidget->slotActivated(); +} + +void KisToolSelectRectangular::update(KisCanvasSubject *subject) +{ + m_subject = subject; + super::update(m_subject); +} + +void KisToolSelectRectangular::paint(KisCanvasPainter& gc) +{ + if (m_selecting) + paintOutline(gc, TQRect()); +} + +void KisToolSelectRectangular::paint(KisCanvasPainter& gc, const TQRect& rc) +{ + if (m_selecting) + paintOutline(gc, rc); +} + +void KisToolSelectRectangular::clearSelection() +{ + if (m_subject) { + KisCanvasController *controller = m_subject->canvasController(); + KisImageSP img = m_subject->currentImg(); + + Q_ASSERT(controller); + + m_centerPos = KisPoint(0, 0); + m_startPos = KisPoint(0, 0); + m_endPos = KisPoint(0, 0); + m_selecting = false; + } +} + +void KisToolSelectRectangular::buttonPress(KisButtonPressEvent *e) +{ + if (m_subject) { + KisImageSP img = m_subject->currentImg(); + + if (img && img->activeDevice() && e->button() == Qt::LeftButton) { + clearSelection(); + m_startPos = m_endPos = m_centerPos = e->pos(); + m_selecting = true; + } + } +} + +void KisToolSelectRectangular::move(KisMoveEvent *e) +{ + if (m_subject && m_selecting) { + paintOutline(); + // move (alt) or resize rectangle + if (e->state() & TQt::AltButton) { + KisPoint trans = e->pos() - m_endPos; + m_startPos += trans; + m_endPos += trans; + } else { + KisPoint diag = e->pos() - (e->state() & TQt::ControlButton + ? m_centerPos : m_startPos); + // square? + if (e->state() & TQt::ShiftButton) { + double size = TQMAX(fabs(diag.x()), fabs(diag.y())); + double w = diag.x() < 0 ? -size : size; + double h = diag.y() < 0 ? -size : size; + diag = KisPoint(w, h); + } + + // resize around center point? + if (e->state() & TQt::ControlButton) { + m_startPos = m_centerPos - diag; + m_endPos = m_centerPos + diag; + } else { + m_endPos = m_startPos + diag; + } + } + paintOutline(); + m_centerPos = KisPoint((m_startPos.x() + m_endPos.x()) / 2, + (m_startPos.y() + m_endPos.y()) / 2); + } +} + +void KisToolSelectRectangular::buttonRelease(KisButtonReleaseEvent *e) +{ + if (m_subject && m_selecting && e->button() == Qt::LeftButton) { + + paintOutline(); + + if (m_startPos == m_endPos) { + clearSelection(); + } else { + KisImageSP img = m_subject->currentImg(); + + if (!img) + return; + + if (m_endPos.y() < 0) + m_endPos.setY(0); + + if (m_endPos.y() > img->height()) + m_endPos.setY(img->height()); + + if (m_endPos.x() < 0) + m_endPos.setX(0); + + if (m_endPos.x() > img->width()) + m_endPos.setX(img->width()); + if (img && img->activeDevice()) { + + TQApplication::setOverrideCursor(KisCursor::waitCursor()); + KisPaintDeviceSP dev = img->activeDevice(); + bool hasSelection = dev->hasSelection(); + + KisSelectedTransaction *t = 0; + if (img->undo()) t = new KisSelectedTransaction(i18n("Rectangular Selection"), dev); + KisSelectionSP selection = dev->selection(); + TQRect rc(m_startPos.floorTQPoint(), m_endPos.floorTQPoint()); + rc = rc.normalize(); + + // We don't want the border of the 'rectangle' to be included in our selection + rc.setSize(rc.size() - TQSize(1,1)); + + if(! hasSelection) + { + selection->clear(); + if(m_selectAction==SELECTION_SUBTRACT) + selection->invert(); + } + + KisSelectionSP tmpSel = new KisSelection(dev); + tmpSel->select(rc); + switch(m_selectAction) + { + case SELECTION_ADD: + dev->addSelection(tmpSel); + break; + case SELECTION_SUBTRACT: + dev->subtractSelection(tmpSel); + break; + default: + break; + } + + + if(hasSelection) { + dev->setDirty(rc); + dev->emitSelectionChanged(rc); + } else { + dev->setDirty(); + dev->emitSelectionChanged(); + } + + if (img->undo()) + img->undoAdapter()->addCommand(t); + + KisCanvasController *controller = m_subject -> canvasController(); + controller -> kiscanvas() -> update(); + + TQApplication::restoreOverrideCursor(); + } + } + + m_selecting = false; + } +} + +void KisToolSelectRectangular::paintOutline() +{ + if (m_subject) { + KisCanvasController *controller = m_subject->canvasController(); + KisCanvas *canvas = controller->kiscanvas(); + KisCanvasPainter gc(canvas); + TQRect rc; + + paintOutline(gc, rc); + } +} + +void KisToolSelectRectangular::paintOutline(KisCanvasPainter& gc, const TQRect&) +{ + if (m_subject) { + KisCanvasController *controller = m_subject->canvasController(); + RasterOp op = gc.rasterOp(); + TQPen old = gc.pen(); + TQPen pen(TQt::DotLine); + TQPoint start; + TQPoint end; + + Q_ASSERT(controller); + start = controller->windowToView(m_startPos.floorTQPoint()); + end = controller->windowToView(m_endPos.floorTQPoint()); + + gc.setRasterOp(TQt::NotROP); + gc.setPen(pen); + gc.drawRect(TQRect(start, end)); + gc.setRasterOp(op); + gc.setPen(old); + } +} + +void KisToolSelectRectangular::slotSetAction(int action) { + if (action >= SELECTION_ADD && action <= SELECTION_SUBTRACT) + m_selectAction =(enumSelectionMode)action; +} + +void KisToolSelectRectangular::setup(TDEActionCollection *collection) +{ + m_action = static_cast(collection->action(name())); + + if (m_action == 0) { + m_action = new TDERadioAction(i18n("&Rectangular Selection"), + "tool_rect_selection", + TQt::Key_R, + this, + TQT_SLOT(activate()), + collection, + name()); + TQ_CHECK_PTR(m_action); + m_action->setExclusiveGroup("tools"); + m_action->setToolTip(i18n("Select a rectangular area")); + m_ownAction = true; + } +} + +TQWidget* KisToolSelectRectangular::createOptionWidget(TQWidget* parent) +{ + m_optWidget = new KisSelectionOptions(parent, m_subject); + TQ_CHECK_PTR(m_optWidget); + m_optWidget->setCaption(i18n("Rectangular Selection")); + + connect (m_optWidget, TQT_SIGNAL(actionChanged(int)), this, TQT_SLOT(slotSetAction(int))); + + TQVBoxLayout * l = dynamic_cast(m_optWidget->layout()); + l->addItem(new TQSpacerItem(1, 1, TQSizePolicy::Fixed, TQSizePolicy::Expanding)); + + return m_optWidget; +} + +TQWidget* KisToolSelectRectangular::optionWidget() +{ + return m_optWidget; +} + + + + +#include "kis_tool_select_rectangular.moc" diff --git a/chalk/plugins/tools/selectiontools/selection_tools.cc b/chalk/plugins/tools/selectiontools/selection_tools.cc deleted file mode 100644 index 8407a076e..000000000 --- a/chalk/plugins/tools/selectiontools/selection_tools.cc +++ /dev/null @@ -1,77 +0,0 @@ -/* - * selection_tools.cc -- Part of Chalk - * - * Copyright (c) 2004 Boudewijn Rempt (boud@valdyas.org) - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -#include -#include - -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include "selection_tools.h" - -#include "kis_tool_select_outline.h" -#include "kis_tool_select_polygonal.h" -#include "kis_tool_select_rectangular.h" -#include "kis_tool_select_contiguous.h" -#include "kis_tool_select_elliptical.h" -#include "kis_tool_select_eraser.h" -#include "kis_tool_select_brush.h" -#include "kis_tool_move_selection.h" - -typedef KGenericFactory SelectionToolsFactory; -K_EXPORT_COMPONENT_FACTORY( chalkselectiontools, SelectionToolsFactory( "chalk" ) ) - - -SelectionTools::SelectionTools(TQObject *parent, const char *name, const TQStringList &) - : KParts::Plugin(parent, name) -{ - setInstance(SelectionToolsFactory::instance()); - - if ( parent->inherits("KisToolRegistry") ) - { - KisToolRegistry * r = dynamic_cast(parent); - r->add(new KisToolSelectOutlineFactory()); - r->add(new KisToolSelectPolygonalFactory()); - r->add(new KisToolSelectRectangularFactory()); - r->add(new KisToolSelectBrushFactory()); - r->add(new KisToolSelectContiguousFactory()); - r->add(new KisToolSelectEllipticalFactory()); - r->add(new KisToolSelectEraserFactory()); - r->add(new KisToolMoveSelectionFactory()); - } -} - -SelectionTools::~SelectionTools() -{ -} - -#include "selection_tools.moc" diff --git a/chalk/plugins/tools/selectiontools/selection_tools.cpp b/chalk/plugins/tools/selectiontools/selection_tools.cpp new file mode 100644 index 000000000..f34a3b34c --- /dev/null +++ b/chalk/plugins/tools/selectiontools/selection_tools.cpp @@ -0,0 +1,77 @@ +/* + * selection_tools.cpp -- Part of Chalk + * + * Copyright (c) 2004 Boudewijn Rempt (boud@valdyas.org) + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "selection_tools.h" + +#include "kis_tool_select_outline.h" +#include "kis_tool_select_polygonal.h" +#include "kis_tool_select_rectangular.h" +#include "kis_tool_select_contiguous.h" +#include "kis_tool_select_elliptical.h" +#include "kis_tool_select_eraser.h" +#include "kis_tool_select_brush.h" +#include "kis_tool_move_selection.h" + +typedef KGenericFactory SelectionToolsFactory; +K_EXPORT_COMPONENT_FACTORY( chalkselectiontools, SelectionToolsFactory( "chalk" ) ) + + +SelectionTools::SelectionTools(TQObject *parent, const char *name, const TQStringList &) + : KParts::Plugin(parent, name) +{ + setInstance(SelectionToolsFactory::instance()); + + if ( parent->inherits("KisToolRegistry") ) + { + KisToolRegistry * r = dynamic_cast(parent); + r->add(new KisToolSelectOutlineFactory()); + r->add(new KisToolSelectPolygonalFactory()); + r->add(new KisToolSelectRectangularFactory()); + r->add(new KisToolSelectBrushFactory()); + r->add(new KisToolSelectContiguousFactory()); + r->add(new KisToolSelectEllipticalFactory()); + r->add(new KisToolSelectEraserFactory()); + r->add(new KisToolMoveSelectionFactory()); + } +} + +SelectionTools::~SelectionTools() +{ +} + +#include "selection_tools.moc" diff --git a/chalk/plugins/tools/tool_crop/Makefile.am b/chalk/plugins/tools/tool_crop/Makefile.am index fe320b849..5bf3c1f6d 100644 --- a/chalk/plugins/tools/tool_crop/Makefile.am +++ b/chalk/plugins/tools/tool_crop/Makefile.am @@ -11,8 +11,8 @@ INCLUDES = -I$(srcdir)/../../../sdk \ chalktoolcrop_la_SOURCES = \ wdg_tool_crop.ui \ - tool_crop.cc \ - kis_tool_crop.cc + tool_crop.cpp \ + kis_tool_crop.cpp # Install this plugin in the KDE modules directory kde_module_LTLIBRARIES = chalktoolcrop.la diff --git a/chalk/plugins/tools/tool_crop/kis_tool_crop.cc b/chalk/plugins/tools/tool_crop/kis_tool_crop.cc deleted file mode 100644 index 11a47590c..000000000 --- a/chalk/plugins/tools/tool_crop/kis_tool_crop.cc +++ /dev/null @@ -1,925 +0,0 @@ -/* - * kis_tool_crop.cc -- part of Chalk - * - * Copyright (c) 2004 Boudewijn Rempt - * Copyright (c) 2005 Michael Thaler - * Copyright (c) 2006 Cyrille Berger - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "kis_tool_crop.h" -#include "wdg_tool_crop.h" - -#include "kis_canvas.h" -#include "kis_canvas_painter.h" - - - -KisToolCrop::KisToolCrop() - : super(i18n("Crop")) -{ - setName("tool_crop"); - m_cropCursor = KisCursor::load("tool_crop_cursor.png", 6, 6); - setCursor(m_cropCursor); - m_subject = 0; - m_selecting = false; - m_rectCrop = TQRect(0, 0, 0, 0); - m_handleSize = 13; - m_haveCropSelection = false; - m_optWidget = 0; -} - -KisToolCrop::~KisToolCrop() -{ -} - -void KisToolCrop::update(KisCanvasSubject *subject) -{ - m_subject = subject; - super::update(m_subject); -} - -void KisToolCrop::activate() -{ - super::activate(); - - // No current crop rectangle, try to use the selection of the device to make a rectangle - if (m_subject && m_subject->currentImg() && m_subject->currentImg()->activeDevice()) { - KisPaintDeviceSP device = m_subject->currentImg()->activeDevice(); - if (!device->hasSelection()) { - //m_rectCrop = m_subject->currentImg()->bounds(); - //validateSelection(); - m_haveCropSelection = false; - m_selecting = false; - } - else { - - m_rectCrop = device->selection()->selectedRect(); - validateSelection(); - crop(); - } - } -} - -void KisToolCrop::deactivate() -{ - clearRect(); -} - - -void KisToolCrop::paint(KisCanvasPainter& gc) -{ - paintOutlineWithHandles(gc, TQRect()); -} - -void KisToolCrop::paint(KisCanvasPainter& gc, const TQRect& rc) -{ - paintOutlineWithHandles(gc, rc); -} - -void KisToolCrop::clearRect() -{ - kdDebug() << "Clearing\n"; - if (m_subject) { - - KisCanvasController *controller = m_subject->canvasController(); - KisImageSP img = m_subject->currentImg(); - - Q_ASSERT(controller); - - controller->kiscanvas()->update(); - - m_rectCrop = TQRect(0,0,0,0); - - updateWidgetValues(); - m_selecting = false; - } -} - -void KisToolCrop::buttonPress(KisButtonPressEvent *e) -{ - if (m_subject) { - KisImageSP img = m_subject->currentImg(); - - if (img && img->activeDevice() && e->button() == Qt::LeftButton) { - - TQPoint pos = e->pos().floorTQPoint(); - TQRect b = img->bounds(); - - if (pos.x() < b.x()) - pos.setX(b.x()); - else if (pos.x() > b.x() + b.width()) - pos.setX(b.x() + b.width()); - - if (pos.y() < b.y()) - pos.setY(b.y()); - else if (pos.y() > b.y() + b.height()) - pos.setY(b.y() + b.height()); - - m_selecting = true; - - if( !m_haveCropSelection ) //if the selection is not set - { - m_rectCrop = TQRect( pos.x(), pos.y(), 0, 0); - paintOutlineWithHandles(); - } - else - { - KisCanvasController *controller = m_subject->canvasController(); - m_mouseOnHandleType = mouseOnHandle(controller ->windowToView(pos)); - m_dragStart = pos; - } - - updateWidgetValues(); - } - } -} - -void KisToolCrop::move(KisMoveEvent *e) -{ - if ( m_subject && m_subject->currentImg()) - { - if( m_selecting ) //if the user selects - { - if( !m_haveCropSelection ) //if the cropSelection is not yet set - { - paintOutlineWithHandles(); - - m_rectCrop.setBottomRight( e->pos().floorTQPoint()); - - KisImageSP image = m_subject->currentImg(); - - m_rectCrop.setRight( TQMIN(m_rectCrop.right(), image->width())); - m_rectCrop.setBottom( TQMIN(m_rectCrop.bottom(), image->width())); - m_rectCrop = m_rectCrop.normalize(); - - paintOutlineWithHandles(); - } - else //if the crop selection is set - { - m_dragStop = e->pos().floorTQPoint(); - if (m_mouseOnHandleType != None && m_dragStart != m_dragStop ) { - - - TQ_INT32 imageWidth = m_subject->currentImg()->width(); - TQ_INT32 imageHeight = m_subject->currentImg()->height(); - - paintOutlineWithHandles(); - - TQPoint pos = e->pos().floorTQPoint(); - if( m_mouseOnHandleType == Inside ) - { - m_rectCrop.moveBy( ( m_dragStop.x() - m_dragStart.x() ), ( m_dragStop.y() - m_dragStart.y() ) ); - if( m_rectCrop.left() < 0 ) - { - m_rectCrop.moveLeft( 0 ); - } - if( m_rectCrop.right() > imageWidth ) - { - m_rectCrop.moveRight( imageWidth ); - } - if( m_rectCrop.top() < 0 ) - { - m_rectCrop.moveTop( 0 ); - } - if( m_rectCrop.bottom() > imageHeight ) - { - m_rectCrop.moveBottom( imageHeight ); - } - } else if(m_optWidget->boolRatio->isChecked()) - { - TQPoint drag = m_dragStop - m_dragStart; - if( ! m_optWidget->boolWidth->isChecked() && !m_optWidget->boolHeight->isChecked() ) - { - switch (m_mouseOnHandleType) - { - case (UpperLeft): - { - TQ_INT32 dep = (drag.x() + drag.y()) / 2; - m_rectCrop.setTop( m_rectCrop.top() + dep ); - m_rectCrop.setLeft( (int) ( m_rectCrop.right() - m_optWidget->doubleRatio->value() * m_rectCrop.height() ) ); - } - break; - case (LowerRight): - { - TQ_INT32 dep = (drag.x() + drag.y()) / 2; - m_rectCrop.setBottom( m_rectCrop.bottom() + dep ); - m_rectCrop.setWidth( (int) ( m_optWidget->doubleRatio->value() * m_rectCrop.height() ) ); - break; - } - case (UpperRight): - { - TQ_INT32 dep = (drag.x() - drag.y()) / 2; - m_rectCrop.setTop( m_rectCrop.top() - dep ); - m_rectCrop.setWidth( (int) ( m_optWidget->doubleRatio->value() * m_rectCrop.height() ) ); - break; - } - case (LowerLeft): - { - TQ_INT32 dep = (drag.x() - drag.y()) / 2; - m_rectCrop.setBottom( m_rectCrop.bottom() - dep ); - m_rectCrop.setLeft( (int) ( m_rectCrop.right() - m_optWidget->doubleRatio->value() * m_rectCrop.height() ) ); - break; - } - case (Upper): - m_rectCrop.setTop( pos.y() + m_dy ); - m_rectCrop.setWidth( (int) (m_rectCrop.height() * m_optWidget->doubleRatio->value()) ); - break; - case (Lower): - m_rectCrop.setBottom( pos.y() + m_dy ); - m_rectCrop.setWidth( (int) (m_rectCrop.height() * m_optWidget->doubleRatio->value()) ); - break; - case (Left): - m_rectCrop.setLeft( pos.x() + m_dx ); - m_rectCrop.setHeight( (int) (m_rectCrop.width() / m_optWidget->doubleRatio->value()) ); - break; - case (Right): - m_rectCrop.setRight( pos.x() + m_dx ); - m_rectCrop.setHeight( (int) (m_rectCrop.width() / m_optWidget->doubleRatio->value()) ); - break; - case (Inside): // never happen - break; - } - } - } else { - if( m_optWidget->boolWidth->isChecked() ) - { - m_rectCrop.setWidth( m_optWidget->intWidth->value() + 1 ); - } else { - switch (m_mouseOnHandleType) - { - case (LowerLeft): - case (Left): - case (UpperLeft): - m_rectCrop.setLeft( pos.x() + m_dx ); - break; - case (Right): - case (UpperRight): - case (LowerRight): - m_rectCrop.setRight( pos.x() + m_dx ); - break; - default: - break; - } - } - if( m_optWidget->boolHeight->isChecked() ) - { - m_rectCrop.setHeight( m_optWidget->intHeight->value() + 1 ); - } else { - switch (m_mouseOnHandleType) - { - case (UpperLeft): - case (Upper): - case (UpperRight): - m_rectCrop.setTop( pos.y() + m_dy ); - break; - case (LowerRight): - case (LowerLeft): - case (Lower): - m_rectCrop.setBottom( pos.y() + m_dy ); - break; - default: - break; - } - } - } - if( m_rectCrop.height() < 0) - { - if( m_mouseOnHandleType == Lower) - m_mouseOnHandleType = Upper; - else if( m_mouseOnHandleType == LowerLeft) - m_mouseOnHandleType = UpperLeft; - else if( m_mouseOnHandleType == LowerRight) - m_mouseOnHandleType = UpperRight; - else if( m_mouseOnHandleType == Upper) - m_mouseOnHandleType = Lower; - else if( m_mouseOnHandleType == UpperLeft) - m_mouseOnHandleType = LowerLeft; - else if( m_mouseOnHandleType == UpperRight) - m_mouseOnHandleType = LowerRight; - } - if( m_rectCrop.width() < 0) - { - if( m_mouseOnHandleType == Right) - m_mouseOnHandleType = Left; - else if( m_mouseOnHandleType == UpperRight) - m_mouseOnHandleType = UpperLeft; - else if( m_mouseOnHandleType == LowerRight) - m_mouseOnHandleType = LowerLeft; - else if( m_mouseOnHandleType == Left) - m_mouseOnHandleType = Right; - else if( m_mouseOnHandleType == UpperLeft) - m_mouseOnHandleType = UpperRight; - else if( m_mouseOnHandleType == LowerLeft) - m_mouseOnHandleType = LowerRight; - } - - m_rectCrop = m_rectCrop.normalize(); - m_rectCrop = m_rectCrop.intersect( TQRect(0,0, imageWidth + 1, imageHeight + 1 ) ); - m_dragStart = e->pos().floorTQPoint(); - paintOutlineWithHandles(); - } - } - updateWidgetValues(); - } - else //if we are not selecting - { - if ( m_haveCropSelection ) //if the crop selection is set - { - KisCanvasController *controller = m_subject->canvasController(); - TQ_INT32 type = mouseOnHandle(controller->windowToView(e->pos().floorTQPoint())); - //set resize cursor if we are on one of the handles - setMoveResizeCursor(type); - } - } - } -} - -void KisToolCrop::updateWidgetValues(bool updateratio) -{ - TQRect r = realRectCrop(); - setOptionWidgetX(r.x()); - setOptionWidgetY(r.y()); - setOptionWidgetWidth(r.width() ); - setOptionWidgetHeight(r.height() ); - if(updateratio && !m_optWidget->boolRatio->isChecked() ) - setOptionWidgetRatio((double)r.width() / (double)r.height() ); -} - -void KisToolCrop::buttonRelease(KisButtonReleaseEvent *e) -{ - if (m_subject && m_subject->currentImg() && m_selecting && e->button() == Qt::LeftButton) { - - m_selecting = false; - m_haveCropSelection = true; - - paintOutlineWithHandles(); - validateSelection(); - paintOutlineWithHandles(); - } -} - -void KisToolCrop::doubleClick(KisDoubleClickEvent *) -{ - if (m_haveCropSelection) crop(); -} - -void KisToolCrop::validateSelection(bool updateratio) -{ - if (m_subject) { - KisImageSP image = m_subject->currentImg(); - - if (image) { - TQ_INT32 imageWidth = image->width(); - TQ_INT32 imageHeight = image->height(); - m_rectCrop.setLeft(TQMAX(0, m_rectCrop.left())); - m_rectCrop.setTop(TQMAX(0, m_rectCrop.top())); - m_rectCrop.setRight(TQMIN(imageWidth, m_rectCrop.right())); - m_rectCrop.setBottom(TQMIN(imageHeight, m_rectCrop.bottom())); - - updateWidgetValues(updateratio); - } - } -} - -void KisToolCrop::paintOutlineWithHandles() -{ - if (m_subject) { - KisCanvasController *controller = m_subject->canvasController(); - KisCanvas *canvas = controller->kiscanvas(); - KisCanvasPainter gc(canvas); - TQRect rc; - - paintOutlineWithHandles(gc, rc); - } -} - -void KisToolCrop::paintOutlineWithHandles(KisCanvasPainter& gc, const TQRect&) -{ - if (m_subject && (m_selecting || m_haveCropSelection)) { - KisCanvasController *controller = m_subject->canvasController(); - RasterOp op = gc.rasterOp(); - TQPen old = gc.pen(); - TQPen pen(TQt::SolidLine); - pen.setWidth(1); - TQPoint start; - TQPoint end; - - Q_ASSERT(controller); - start = controller->windowToView(m_rectCrop.topLeft()); - end = controller->windowToView(m_rectCrop.bottomRight()); - - gc.setRasterOp(TQt::NotROP); - gc.setPen(pen); - //draw handles - m_handlesRegion = handles(TQRect(start, end)); - - TQ_INT32 startx; - TQ_INT32 starty; - TQ_INT32 endx; - TQ_INT32 endy; - if(start.x()<=end.x()) - { - startx=start.x(); - endx=end.x(); - } - else - { - startx=end.x(); - endx=start.x(); - } - if(start.y()<=end.y()) - { - starty=start.y(); - endy=end.y(); - } - else - { - starty=end.y(); - endy=start.y(); - } - //draw upper line of selection - gc.drawLine(startx + m_handleSize / 2 + 1, starty, startx + (endx - startx - m_handleSize) / 2 + 1, starty); - gc.drawLine(startx + (endx - startx + m_handleSize) / 2 + 1, starty, endx - m_handleSize / 2, starty); - //draw lower line of selection - gc.drawLine(startx + m_handleSize / 2 + 1, endy, startx + (endx - startx - m_handleSize) / 2 + 1, endy); - gc.drawLine(startx + (endx - startx + m_handleSize) / 2 + 1, endy, endx - m_handleSize / 2 , endy); - //draw right line of selection - gc.drawLine(startx, starty + m_handleSize / 2 + 1, startx, starty + (endy - starty - m_handleSize) / 2 + 1); - gc.drawLine(startx, starty + (endy - starty + m_handleSize) / 2 + 1, startx, endy - m_handleSize / 2); - //draw left line of selection - gc.drawLine(endx, starty + m_handleSize / 2 + 1, endx, starty + (endy - starty - m_handleSize) / 2 + 1); - gc.drawLine(endx, starty + (endy - starty + m_handleSize) / 2 + 1, endx, endy - m_handleSize / 2); - - //draw guides - gc.drawLine(0,endy,startx - m_handleSize / 2,endy); - gc.drawLine(startx,endy + m_handleSize / 2 + 1, startx, controller->kiscanvas()->height()); - gc.drawLine(endx,0,endx,starty - m_handleSize / 2); - gc.drawLine(endx + m_handleSize / 2 + 1,starty, controller->kiscanvas()->width(), starty); - TQMemArray rects = m_handlesRegion.rects (); - for (TQMemArray ::ConstIterator it = rects.begin (); it != rects.end (); ++it) - { - gc.fillRect (*it, TQt::black); - } - - - gc.setRasterOp(op); - gc.setPen(old); - } -} - -void KisToolCrop::crop() { - // XXX: Should cropping be part of KisImage/KisPaintDevice's API? - - m_haveCropSelection = false; - setCursor(m_cropCursor); - - KisImageSP img = m_subject->currentImg(); - - if (!img) - return; - - TQRect rc = realRectCrop().normalize(); - - // The visitor adds the undo steps to the macro - if (m_optWidget->cmbType->currentItem() == 0) { - - TQRect dirty = img->bounds(); - - // The layer(s) under the current layer will take care of adding - // undo information to the Crop macro. - if (img->undo()) - img->undoAdapter()->beginMacro(i18n("Crop")); - - KisCropVisitor v(rc, false); - KisLayerSP layer = img->activeLayer(); - layer->accept(v); - layer->setDirty( dirty ); - if (img->undo()) - img->undoAdapter()->endMacro(); - - } - else { - // Resize creates the undo macro itself - img->resize(rc, true); - } - - m_rectCrop = TQRect(0,0,0,0); - - updateWidgetValues(); -} - -void KisToolCrop::setCropX(int x) -{ - if (!m_haveCropSelection) { - m_haveCropSelection = true; - } - else { - paintOutlineWithHandles(); // remove outlines - } - - m_rectCrop.setX(x); - - validateSelection(); - paintOutlineWithHandles(); -} - -void KisToolCrop::setCropY(int y) -{ - if (!m_haveCropSelection) { - m_haveCropSelection = true; - } - else { - paintOutlineWithHandles(); // remove outlines - } - - m_rectCrop.setY(y); - - validateSelection(); - paintOutlineWithHandles(); - -} - -void KisToolCrop::setCropWidth(int w) -{ - if (!m_haveCropSelection) { - m_haveCropSelection = true; - } - else { - paintOutlineWithHandles(); // remove outlines - } - - m_rectCrop.setWidth(w + 1); - - if( m_optWidget->boolRatio->isChecked() ) - { - m_rectCrop.setHeight( (int) ( w / m_optWidget->doubleRatio->value() ) ); - } else { - setOptionWidgetRatio((double)m_rectCrop.width() / (double)m_rectCrop.height() ); - } - - validateSelection(); - paintOutlineWithHandles(); - -} - -void KisToolCrop::setCropHeight(int h) -{ - if (!m_haveCropSelection) { - m_haveCropSelection = true; - } - else { - paintOutlineWithHandles(); // remove outlines - } - - m_rectCrop.setHeight(h + 1); - - if( m_optWidget->boolRatio->isChecked() ) - { - m_rectCrop.setWidth( (int) ( h * m_optWidget->doubleRatio->value() ) ); - } else { - setOptionWidgetRatio((double)m_rectCrop.width() / (double)m_rectCrop.height() ); - } - - validateSelection(); - paintOutlineWithHandles(); - -} - -void KisToolCrop::setRatio(double ) -{ - if( ! (m_optWidget->boolWidth->isChecked() && m_optWidget->boolHeight->isChecked() )) - { - if (!m_haveCropSelection) { - m_haveCropSelection = true; - } - else { - paintOutlineWithHandles(); // remove outlines - } - if( m_optWidget->boolWidth->isChecked() ) - { - m_rectCrop.setHeight( (int) ( m_rectCrop.width() / m_optWidget->doubleRatio->value()) ); - setOptionWidgetHeight( m_rectCrop.height() ); - } else if(m_optWidget->boolHeight->isChecked()) { - m_rectCrop.setWidth( (int) (m_rectCrop.height() * m_optWidget->doubleRatio->value()) ); - setOptionWidgetWidth( m_rectCrop.width() ); - } else { - int newwidth = (int) (m_optWidget->doubleRatio->value() * m_rectCrop.height()); - newwidth = (newwidth + m_rectCrop.width()) / 2; - m_rectCrop.setWidth( newwidth + 1); - setOptionWidgetWidth( newwidth ); - m_rectCrop.setHeight( (int) (newwidth / m_optWidget->doubleRatio->value()) + 1 ); - setOptionWidgetHeight( m_rectCrop.height() - 1 ); - } - validateSelection(false); - paintOutlineWithHandles(); - } -} - -void KisToolCrop::setOptionWidgetX(TQ_INT32 x) -{ - // Disable signals otherwise we get the valueChanged signal, which we don't want - // to go through the logic for setting values that way. - m_optWidget->intX->blockSignals(true); - m_optWidget->intX->setValue(x); - m_optWidget->intX->blockSignals(false); -} - -void KisToolCrop::setOptionWidgetY(TQ_INT32 y) -{ - m_optWidget->intY->blockSignals(true); - m_optWidget->intY->setValue(y); - m_optWidget->intY->blockSignals(false); -} - -void KisToolCrop::setOptionWidgetWidth(TQ_INT32 x) -{ - m_optWidget->intWidth->blockSignals(true); - m_optWidget->intWidth->setValue(x); - m_optWidget->intWidth->blockSignals(false); -} - -void KisToolCrop::setOptionWidgetHeight(TQ_INT32 y) -{ - m_optWidget->intHeight->blockSignals(true); - m_optWidget->intHeight->setValue(y); - m_optWidget->intHeight->blockSignals(false); -} - -void KisToolCrop::setOptionWidgetRatio(double ratio) -{ - m_optWidget->doubleRatio->blockSignals(true); - m_optWidget->doubleRatio->setValue(ratio); - m_optWidget->doubleRatio->blockSignals(false); -} - - -TQWidget* KisToolCrop::createOptionWidget(TQWidget* parent) -{ - m_optWidget = new WdgToolCrop(parent); - TQ_CHECK_PTR(m_optWidget); - - connect(m_optWidget->bnCrop, TQT_SIGNAL(clicked()), this, TQT_SLOT(crop())); - - connect(m_optWidget->intX, TQT_SIGNAL(valueChanged(int)), this, TQT_SLOT(setCropX(int))); - connect(m_optWidget->intY, TQT_SIGNAL(valueChanged(int)), this, TQT_SLOT(setCropY(int))); - connect(m_optWidget->intWidth, TQT_SIGNAL(valueChanged(int)), this, TQT_SLOT(setCropWidth(int))); - connect(m_optWidget->intHeight, TQT_SIGNAL(valueChanged(int)), this, TQT_SLOT(setCropHeight(int))); - connect(m_optWidget->doubleRatio, TQT_SIGNAL(valueChanged(double)), this, TQT_SLOT(setRatio( double ))); - - return m_optWidget; -} - -TQWidget* KisToolCrop::optionWidget() -{ - return m_optWidget; -} - -void KisToolCrop::setup(TDEActionCollection *collection) -{ - m_action = static_cast(collection->action(name())); - - if (m_action == 0) { - m_action = new TDERadioAction(i18n("&Crop"), - "tool_crop", - 0, - this, - TQT_SLOT(activate()), - collection, - name()); - TQ_CHECK_PTR(m_action); - - m_action->setToolTip(i18n("Crop an area")); - m_action->setExclusiveGroup("tools"); - - m_ownAction = true; - } -} - -TQRect toTQRect(double x, double y, int w, int h) -{ - return TQRect(int(x), int(y), w, h); -} - -TQRegion KisToolCrop::handles(TQRect rect) -{ - TQRegion handlesRegion; - - //add handle at the lower right corner - handlesRegion += toTQRect( TQABS( rect.width() ) - m_handleSize / 2.0, TQABS( rect.height() ) - m_handleSize / 2.0, m_handleSize, m_handleSize ); - //add handle at the upper right corner - handlesRegion += toTQRect( TQABS( rect.width() ) - m_handleSize / 2.0 , 0 - m_handleSize / 2.0, m_handleSize, m_handleSize ); - //add rectangle at the lower left corner - handlesRegion += toTQRect( 0 - m_handleSize / 2.0 , TQABS( rect.height() ) - m_handleSize / 2.0, m_handleSize, m_handleSize ); - //add rectangle at the upper left corner - handlesRegion += toTQRect( 0 - m_handleSize / 2.0, 0 - m_handleSize / 2.0, m_handleSize, m_handleSize ); - //add handle at the lower edge of the rectangle - handlesRegion += toTQRect( ( TQABS( rect.width() ) - m_handleSize ) / 2.0 , TQABS( rect.height() ) - m_handleSize / 2.0, m_handleSize, m_handleSize ); - //add handle at the right edge of the rectangle - handlesRegion += toTQRect( TQABS( rect.width() ) - m_handleSize / 2.0 , ( TQABS( rect.height() ) - m_handleSize ) / 2.0, m_handleSize, m_handleSize ); - //add handle at the upper edge of the rectangle - handlesRegion += toTQRect( ( TQABS( rect.width() ) - m_handleSize ) / 2.0 , 0 - m_handleSize / 2.0, m_handleSize, m_handleSize ); - //add handle at the left edge of the rectangle - handlesRegion += toTQRect( 0 - m_handleSize / 2.0, ( TQABS( rect.height() ) - m_handleSize ) / 2.0, m_handleSize, m_handleSize ); - - //move the handles to the correct position - if( rect.width() >= 0 && rect.height() >= 0) - { - handlesRegion.translate ( rect.x(), rect.y() ); - } - else if( rect.width() < 0 && rect.height() >= 0) - { - handlesRegion.translate ( rect.x() - TQABS( rect.width() ), rect.y() ); - } - else if( rect.width() >= 0 && rect.height() < 0) - { - handlesRegion.translate ( rect.x(), rect.y() - TQABS( rect.height() ) ); - } - else if( rect.width() < 0 && rect.height() < 0) - { - handlesRegion.translate ( rect.x() - TQABS( rect.width() ), rect.y() - TQABS( rect.height() ) ); - } - return handlesRegion; -} - -TQ_INT32 KisToolCrop::mouseOnHandle(TQPoint currentViewPoint) -{ - KisCanvasController *controller = m_subject->canvasController(); - Q_ASSERT(controller); - TQPoint start = controller->windowToView(m_rectCrop.topLeft()); - TQPoint end = controller->windowToView(m_rectCrop.bottomRight()); - - TQ_INT32 startx; - TQ_INT32 starty; - TQ_INT32 endx; - TQ_INT32 endy; - if(start.x()<=end.x()) - { - startx=start.x(); - endx=end.x(); - } - else - { - startx=end.x(); - endx=start.x(); - } - if(start.y()<=end.y()) - { - starty=start.y(); - endy=end.y(); - } - else - { - starty=end.y(); - endy=start.y(); - } - - if ( toTQRect ( startx - m_handleSize / 2.0, starty - m_handleSize / 2.0, m_handleSize, m_handleSize ).contains( currentViewPoint ) ) - { - if( !m_selecting ) - { - m_dx= startx-currentViewPoint.x(); - m_dy = starty - currentViewPoint.y(); - } - return UpperLeft; - } - else if ( toTQRect ( startx - m_handleSize / 2.0, endy - m_handleSize / 2.0, m_handleSize, m_handleSize ).contains( currentViewPoint ) ) - { - if( !m_selecting ) - { - m_dx = startx-currentViewPoint.x(); - m_dy = endy-currentViewPoint.y(); - } - return LowerLeft; - } - else if ( toTQRect ( endx - m_handleSize / 2.0, starty - m_handleSize / 2.0, m_handleSize, m_handleSize ).contains( currentViewPoint ) ) - { - if( !m_selecting ) - { - m_dx = endx - currentViewPoint.x(); - m_dy = starty - currentViewPoint.y() ; - } - return UpperRight; - } - else if ( toTQRect ( endx - m_handleSize / 2.0, endy - m_handleSize / 2.0, m_handleSize, m_handleSize ).contains( currentViewPoint ) ) - { - if( !m_selecting ) - { - m_dx = endx - currentViewPoint.x(); - m_dy= endy - currentViewPoint.y(); - } - return LowerRight; - } - else if ( toTQRect ( startx + ( endx - startx - m_handleSize ) / 2.0, starty - m_handleSize / 2.0, m_handleSize, m_handleSize ).contains( currentViewPoint ) ) - { - if( !m_selecting ) - { - m_dy = starty - currentViewPoint.y() ; - } - return Upper; - } - else if ( toTQRect ( startx + ( endx - startx - m_handleSize ) / 2.0, endy - m_handleSize / 2, m_handleSize, m_handleSize ).contains( currentViewPoint ) ) - { - if( !m_selecting ) - { - m_dy = endy - currentViewPoint.y(); - } - return Lower; - } - else if ( toTQRect ( startx - m_handleSize / 2.0, starty + ( endy - starty - m_handleSize ) / 2.0, m_handleSize, m_handleSize ).contains( currentViewPoint ) ) - { - if( !m_selecting ) - { - m_dx = startx - currentViewPoint.x() ; - } - return Left; - } - else if ( toTQRect ( endx - m_handleSize / 2.0 , starty + ( endy - starty - m_handleSize ) / 2.0, m_handleSize, m_handleSize ).contains( currentViewPoint ) ) - { - if( !m_selecting ) - { - m_dx = endx-currentViewPoint.x(); - } - return Right; - } - else if ( toTQRect ( startx , starty, endx - startx , endy - starty ).contains( currentViewPoint ) ) - { - return Inside; - } - else return None; -} - -void KisToolCrop::setMoveResizeCursor (TQ_INT32 handle) -{ - switch (handle) - { - case (UpperLeft): - case (LowerRight): - m_subject->canvasController()->setCanvasCursor(KisCursor::sizeFDiagCursor()); - return; - case (LowerLeft): - case (UpperRight): - m_subject->canvasController()->setCanvasCursor(KisCursor::sizeBDiagCursor()); - return; - case (Upper): - case (Lower): - m_subject->canvasController()->setCanvasCursor(KisCursor::sizeVerCursor()); - return; - case (Left): - case (Right): - m_subject->canvasController()->setCanvasCursor(KisCursor::sizeHorCursor()); - return; - case (Inside): - m_subject->canvasController()->setCanvasCursor(KisCursor::sizeAllCursor()); - return; - } - m_subject->canvasController()->setCanvasCursor(KisCursor::arrowCursor()); - return; -} - - -#include "kis_tool_crop.moc" diff --git a/chalk/plugins/tools/tool_crop/kis_tool_crop.cpp b/chalk/plugins/tools/tool_crop/kis_tool_crop.cpp new file mode 100644 index 000000000..58454b4f5 --- /dev/null +++ b/chalk/plugins/tools/tool_crop/kis_tool_crop.cpp @@ -0,0 +1,925 @@ +/* + * kis_tool_crop.cpp -- part of Chalk + * + * Copyright (c) 2004 Boudewijn Rempt + * Copyright (c) 2005 Michael Thaler + * Copyright (c) 2006 Cyrille Berger + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "kis_tool_crop.h" +#include "wdg_tool_crop.h" + +#include "kis_canvas.h" +#include "kis_canvas_painter.h" + + + +KisToolCrop::KisToolCrop() + : super(i18n("Crop")) +{ + setName("tool_crop"); + m_cropCursor = KisCursor::load("tool_crop_cursor.png", 6, 6); + setCursor(m_cropCursor); + m_subject = 0; + m_selecting = false; + m_rectCrop = TQRect(0, 0, 0, 0); + m_handleSize = 13; + m_haveCropSelection = false; + m_optWidget = 0; +} + +KisToolCrop::~KisToolCrop() +{ +} + +void KisToolCrop::update(KisCanvasSubject *subject) +{ + m_subject = subject; + super::update(m_subject); +} + +void KisToolCrop::activate() +{ + super::activate(); + + // No current crop rectangle, try to use the selection of the device to make a rectangle + if (m_subject && m_subject->currentImg() && m_subject->currentImg()->activeDevice()) { + KisPaintDeviceSP device = m_subject->currentImg()->activeDevice(); + if (!device->hasSelection()) { + //m_rectCrop = m_subject->currentImg()->bounds(); + //validateSelection(); + m_haveCropSelection = false; + m_selecting = false; + } + else { + + m_rectCrop = device->selection()->selectedRect(); + validateSelection(); + crop(); + } + } +} + +void KisToolCrop::deactivate() +{ + clearRect(); +} + + +void KisToolCrop::paint(KisCanvasPainter& gc) +{ + paintOutlineWithHandles(gc, TQRect()); +} + +void KisToolCrop::paint(KisCanvasPainter& gc, const TQRect& rc) +{ + paintOutlineWithHandles(gc, rc); +} + +void KisToolCrop::clearRect() +{ + kdDebug() << "Clearing\n"; + if (m_subject) { + + KisCanvasController *controller = m_subject->canvasController(); + KisImageSP img = m_subject->currentImg(); + + Q_ASSERT(controller); + + controller->kiscanvas()->update(); + + m_rectCrop = TQRect(0,0,0,0); + + updateWidgetValues(); + m_selecting = false; + } +} + +void KisToolCrop::buttonPress(KisButtonPressEvent *e) +{ + if (m_subject) { + KisImageSP img = m_subject->currentImg(); + + if (img && img->activeDevice() && e->button() == Qt::LeftButton) { + + TQPoint pos = e->pos().floorTQPoint(); + TQRect b = img->bounds(); + + if (pos.x() < b.x()) + pos.setX(b.x()); + else if (pos.x() > b.x() + b.width()) + pos.setX(b.x() + b.width()); + + if (pos.y() < b.y()) + pos.setY(b.y()); + else if (pos.y() > b.y() + b.height()) + pos.setY(b.y() + b.height()); + + m_selecting = true; + + if( !m_haveCropSelection ) //if the selection is not set + { + m_rectCrop = TQRect( pos.x(), pos.y(), 0, 0); + paintOutlineWithHandles(); + } + else + { + KisCanvasController *controller = m_subject->canvasController(); + m_mouseOnHandleType = mouseOnHandle(controller ->windowToView(pos)); + m_dragStart = pos; + } + + updateWidgetValues(); + } + } +} + +void KisToolCrop::move(KisMoveEvent *e) +{ + if ( m_subject && m_subject->currentImg()) + { + if( m_selecting ) //if the user selects + { + if( !m_haveCropSelection ) //if the cropSelection is not yet set + { + paintOutlineWithHandles(); + + m_rectCrop.setBottomRight( e->pos().floorTQPoint()); + + KisImageSP image = m_subject->currentImg(); + + m_rectCrop.setRight( TQMIN(m_rectCrop.right(), image->width())); + m_rectCrop.setBottom( TQMIN(m_rectCrop.bottom(), image->width())); + m_rectCrop = m_rectCrop.normalize(); + + paintOutlineWithHandles(); + } + else //if the crop selection is set + { + m_dragStop = e->pos().floorTQPoint(); + if (m_mouseOnHandleType != None && m_dragStart != m_dragStop ) { + + + TQ_INT32 imageWidth = m_subject->currentImg()->width(); + TQ_INT32 imageHeight = m_subject->currentImg()->height(); + + paintOutlineWithHandles(); + + TQPoint pos = e->pos().floorTQPoint(); + if( m_mouseOnHandleType == Inside ) + { + m_rectCrop.moveBy( ( m_dragStop.x() - m_dragStart.x() ), ( m_dragStop.y() - m_dragStart.y() ) ); + if( m_rectCrop.left() < 0 ) + { + m_rectCrop.moveLeft( 0 ); + } + if( m_rectCrop.right() > imageWidth ) + { + m_rectCrop.moveRight( imageWidth ); + } + if( m_rectCrop.top() < 0 ) + { + m_rectCrop.moveTop( 0 ); + } + if( m_rectCrop.bottom() > imageHeight ) + { + m_rectCrop.moveBottom( imageHeight ); + } + } else if(m_optWidget->boolRatio->isChecked()) + { + TQPoint drag = m_dragStop - m_dragStart; + if( ! m_optWidget->boolWidth->isChecked() && !m_optWidget->boolHeight->isChecked() ) + { + switch (m_mouseOnHandleType) + { + case (UpperLeft): + { + TQ_INT32 dep = (drag.x() + drag.y()) / 2; + m_rectCrop.setTop( m_rectCrop.top() + dep ); + m_rectCrop.setLeft( (int) ( m_rectCrop.right() - m_optWidget->doubleRatio->value() * m_rectCrop.height() ) ); + } + break; + case (LowerRight): + { + TQ_INT32 dep = (drag.x() + drag.y()) / 2; + m_rectCrop.setBottom( m_rectCrop.bottom() + dep ); + m_rectCrop.setWidth( (int) ( m_optWidget->doubleRatio->value() * m_rectCrop.height() ) ); + break; + } + case (UpperRight): + { + TQ_INT32 dep = (drag.x() - drag.y()) / 2; + m_rectCrop.setTop( m_rectCrop.top() - dep ); + m_rectCrop.setWidth( (int) ( m_optWidget->doubleRatio->value() * m_rectCrop.height() ) ); + break; + } + case (LowerLeft): + { + TQ_INT32 dep = (drag.x() - drag.y()) / 2; + m_rectCrop.setBottom( m_rectCrop.bottom() - dep ); + m_rectCrop.setLeft( (int) ( m_rectCrop.right() - m_optWidget->doubleRatio->value() * m_rectCrop.height() ) ); + break; + } + case (Upper): + m_rectCrop.setTop( pos.y() + m_dy ); + m_rectCrop.setWidth( (int) (m_rectCrop.height() * m_optWidget->doubleRatio->value()) ); + break; + case (Lower): + m_rectCrop.setBottom( pos.y() + m_dy ); + m_rectCrop.setWidth( (int) (m_rectCrop.height() * m_optWidget->doubleRatio->value()) ); + break; + case (Left): + m_rectCrop.setLeft( pos.x() + m_dx ); + m_rectCrop.setHeight( (int) (m_rectCrop.width() / m_optWidget->doubleRatio->value()) ); + break; + case (Right): + m_rectCrop.setRight( pos.x() + m_dx ); + m_rectCrop.setHeight( (int) (m_rectCrop.width() / m_optWidget->doubleRatio->value()) ); + break; + case (Inside): // never happen + break; + } + } + } else { + if( m_optWidget->boolWidth->isChecked() ) + { + m_rectCrop.setWidth( m_optWidget->intWidth->value() + 1 ); + } else { + switch (m_mouseOnHandleType) + { + case (LowerLeft): + case (Left): + case (UpperLeft): + m_rectCrop.setLeft( pos.x() + m_dx ); + break; + case (Right): + case (UpperRight): + case (LowerRight): + m_rectCrop.setRight( pos.x() + m_dx ); + break; + default: + break; + } + } + if( m_optWidget->boolHeight->isChecked() ) + { + m_rectCrop.setHeight( m_optWidget->intHeight->value() + 1 ); + } else { + switch (m_mouseOnHandleType) + { + case (UpperLeft): + case (Upper): + case (UpperRight): + m_rectCrop.setTop( pos.y() + m_dy ); + break; + case (LowerRight): + case (LowerLeft): + case (Lower): + m_rectCrop.setBottom( pos.y() + m_dy ); + break; + default: + break; + } + } + } + if( m_rectCrop.height() < 0) + { + if( m_mouseOnHandleType == Lower) + m_mouseOnHandleType = Upper; + else if( m_mouseOnHandleType == LowerLeft) + m_mouseOnHandleType = UpperLeft; + else if( m_mouseOnHandleType == LowerRight) + m_mouseOnHandleType = UpperRight; + else if( m_mouseOnHandleType == Upper) + m_mouseOnHandleType = Lower; + else if( m_mouseOnHandleType == UpperLeft) + m_mouseOnHandleType = LowerLeft; + else if( m_mouseOnHandleType == UpperRight) + m_mouseOnHandleType = LowerRight; + } + if( m_rectCrop.width() < 0) + { + if( m_mouseOnHandleType == Right) + m_mouseOnHandleType = Left; + else if( m_mouseOnHandleType == UpperRight) + m_mouseOnHandleType = UpperLeft; + else if( m_mouseOnHandleType == LowerRight) + m_mouseOnHandleType = LowerLeft; + else if( m_mouseOnHandleType == Left) + m_mouseOnHandleType = Right; + else if( m_mouseOnHandleType == UpperLeft) + m_mouseOnHandleType = UpperRight; + else if( m_mouseOnHandleType == LowerLeft) + m_mouseOnHandleType = LowerRight; + } + + m_rectCrop = m_rectCrop.normalize(); + m_rectCrop = m_rectCrop.intersect( TQRect(0,0, imageWidth + 1, imageHeight + 1 ) ); + m_dragStart = e->pos().floorTQPoint(); + paintOutlineWithHandles(); + } + } + updateWidgetValues(); + } + else //if we are not selecting + { + if ( m_haveCropSelection ) //if the crop selection is set + { + KisCanvasController *controller = m_subject->canvasController(); + TQ_INT32 type = mouseOnHandle(controller->windowToView(e->pos().floorTQPoint())); + //set resize cursor if we are on one of the handles + setMoveResizeCursor(type); + } + } + } +} + +void KisToolCrop::updateWidgetValues(bool updateratio) +{ + TQRect r = realRectCrop(); + setOptionWidgetX(r.x()); + setOptionWidgetY(r.y()); + setOptionWidgetWidth(r.width() ); + setOptionWidgetHeight(r.height() ); + if(updateratio && !m_optWidget->boolRatio->isChecked() ) + setOptionWidgetRatio((double)r.width() / (double)r.height() ); +} + +void KisToolCrop::buttonRelease(KisButtonReleaseEvent *e) +{ + if (m_subject && m_subject->currentImg() && m_selecting && e->button() == Qt::LeftButton) { + + m_selecting = false; + m_haveCropSelection = true; + + paintOutlineWithHandles(); + validateSelection(); + paintOutlineWithHandles(); + } +} + +void KisToolCrop::doubleClick(KisDoubleClickEvent *) +{ + if (m_haveCropSelection) crop(); +} + +void KisToolCrop::validateSelection(bool updateratio) +{ + if (m_subject) { + KisImageSP image = m_subject->currentImg(); + + if (image) { + TQ_INT32 imageWidth = image->width(); + TQ_INT32 imageHeight = image->height(); + m_rectCrop.setLeft(TQMAX(0, m_rectCrop.left())); + m_rectCrop.setTop(TQMAX(0, m_rectCrop.top())); + m_rectCrop.setRight(TQMIN(imageWidth, m_rectCrop.right())); + m_rectCrop.setBottom(TQMIN(imageHeight, m_rectCrop.bottom())); + + updateWidgetValues(updateratio); + } + } +} + +void KisToolCrop::paintOutlineWithHandles() +{ + if (m_subject) { + KisCanvasController *controller = m_subject->canvasController(); + KisCanvas *canvas = controller->kiscanvas(); + KisCanvasPainter gc(canvas); + TQRect rc; + + paintOutlineWithHandles(gc, rc); + } +} + +void KisToolCrop::paintOutlineWithHandles(KisCanvasPainter& gc, const TQRect&) +{ + if (m_subject && (m_selecting || m_haveCropSelection)) { + KisCanvasController *controller = m_subject->canvasController(); + RasterOp op = gc.rasterOp(); + TQPen old = gc.pen(); + TQPen pen(TQt::SolidLine); + pen.setWidth(1); + TQPoint start; + TQPoint end; + + Q_ASSERT(controller); + start = controller->windowToView(m_rectCrop.topLeft()); + end = controller->windowToView(m_rectCrop.bottomRight()); + + gc.setRasterOp(TQt::NotROP); + gc.setPen(pen); + //draw handles + m_handlesRegion = handles(TQRect(start, end)); + + TQ_INT32 startx; + TQ_INT32 starty; + TQ_INT32 endx; + TQ_INT32 endy; + if(start.x()<=end.x()) + { + startx=start.x(); + endx=end.x(); + } + else + { + startx=end.x(); + endx=start.x(); + } + if(start.y()<=end.y()) + { + starty=start.y(); + endy=end.y(); + } + else + { + starty=end.y(); + endy=start.y(); + } + //draw upper line of selection + gc.drawLine(startx + m_handleSize / 2 + 1, starty, startx + (endx - startx - m_handleSize) / 2 + 1, starty); + gc.drawLine(startx + (endx - startx + m_handleSize) / 2 + 1, starty, endx - m_handleSize / 2, starty); + //draw lower line of selection + gc.drawLine(startx + m_handleSize / 2 + 1, endy, startx + (endx - startx - m_handleSize) / 2 + 1, endy); + gc.drawLine(startx + (endx - startx + m_handleSize) / 2 + 1, endy, endx - m_handleSize / 2 , endy); + //draw right line of selection + gc.drawLine(startx, starty + m_handleSize / 2 + 1, startx, starty + (endy - starty - m_handleSize) / 2 + 1); + gc.drawLine(startx, starty + (endy - starty + m_handleSize) / 2 + 1, startx, endy - m_handleSize / 2); + //draw left line of selection + gc.drawLine(endx, starty + m_handleSize / 2 + 1, endx, starty + (endy - starty - m_handleSize) / 2 + 1); + gc.drawLine(endx, starty + (endy - starty + m_handleSize) / 2 + 1, endx, endy - m_handleSize / 2); + + //draw guides + gc.drawLine(0,endy,startx - m_handleSize / 2,endy); + gc.drawLine(startx,endy + m_handleSize / 2 + 1, startx, controller->kiscanvas()->height()); + gc.drawLine(endx,0,endx,starty - m_handleSize / 2); + gc.drawLine(endx + m_handleSize / 2 + 1,starty, controller->kiscanvas()->width(), starty); + TQMemArray rects = m_handlesRegion.rects (); + for (TQMemArray ::ConstIterator it = rects.begin (); it != rects.end (); ++it) + { + gc.fillRect (*it, TQt::black); + } + + + gc.setRasterOp(op); + gc.setPen(old); + } +} + +void KisToolCrop::crop() { + // XXX: Should cropping be part of KisImage/KisPaintDevice's API? + + m_haveCropSelection = false; + setCursor(m_cropCursor); + + KisImageSP img = m_subject->currentImg(); + + if (!img) + return; + + TQRect rc = realRectCrop().normalize(); + + // The visitor adds the undo steps to the macro + if (m_optWidget->cmbType->currentItem() == 0) { + + TQRect dirty = img->bounds(); + + // The layer(s) under the current layer will take care of adding + // undo information to the Crop macro. + if (img->undo()) + img->undoAdapter()->beginMacro(i18n("Crop")); + + KisCropVisitor v(rc, false); + KisLayerSP layer = img->activeLayer(); + layer->accept(v); + layer->setDirty( dirty ); + if (img->undo()) + img->undoAdapter()->endMacro(); + + } + else { + // Resize creates the undo macro itself + img->resize(rc, true); + } + + m_rectCrop = TQRect(0,0,0,0); + + updateWidgetValues(); +} + +void KisToolCrop::setCropX(int x) +{ + if (!m_haveCropSelection) { + m_haveCropSelection = true; + } + else { + paintOutlineWithHandles(); // remove outlines + } + + m_rectCrop.setX(x); + + validateSelection(); + paintOutlineWithHandles(); +} + +void KisToolCrop::setCropY(int y) +{ + if (!m_haveCropSelection) { + m_haveCropSelection = true; + } + else { + paintOutlineWithHandles(); // remove outlines + } + + m_rectCrop.setY(y); + + validateSelection(); + paintOutlineWithHandles(); + +} + +void KisToolCrop::setCropWidth(int w) +{ + if (!m_haveCropSelection) { + m_haveCropSelection = true; + } + else { + paintOutlineWithHandles(); // remove outlines + } + + m_rectCrop.setWidth(w + 1); + + if( m_optWidget->boolRatio->isChecked() ) + { + m_rectCrop.setHeight( (int) ( w / m_optWidget->doubleRatio->value() ) ); + } else { + setOptionWidgetRatio((double)m_rectCrop.width() / (double)m_rectCrop.height() ); + } + + validateSelection(); + paintOutlineWithHandles(); + +} + +void KisToolCrop::setCropHeight(int h) +{ + if (!m_haveCropSelection) { + m_haveCropSelection = true; + } + else { + paintOutlineWithHandles(); // remove outlines + } + + m_rectCrop.setHeight(h + 1); + + if( m_optWidget->boolRatio->isChecked() ) + { + m_rectCrop.setWidth( (int) ( h * m_optWidget->doubleRatio->value() ) ); + } else { + setOptionWidgetRatio((double)m_rectCrop.width() / (double)m_rectCrop.height() ); + } + + validateSelection(); + paintOutlineWithHandles(); + +} + +void KisToolCrop::setRatio(double ) +{ + if( ! (m_optWidget->boolWidth->isChecked() && m_optWidget->boolHeight->isChecked() )) + { + if (!m_haveCropSelection) { + m_haveCropSelection = true; + } + else { + paintOutlineWithHandles(); // remove outlines + } + if( m_optWidget->boolWidth->isChecked() ) + { + m_rectCrop.setHeight( (int) ( m_rectCrop.width() / m_optWidget->doubleRatio->value()) ); + setOptionWidgetHeight( m_rectCrop.height() ); + } else if(m_optWidget->boolHeight->isChecked()) { + m_rectCrop.setWidth( (int) (m_rectCrop.height() * m_optWidget->doubleRatio->value()) ); + setOptionWidgetWidth( m_rectCrop.width() ); + } else { + int newwidth = (int) (m_optWidget->doubleRatio->value() * m_rectCrop.height()); + newwidth = (newwidth + m_rectCrop.width()) / 2; + m_rectCrop.setWidth( newwidth + 1); + setOptionWidgetWidth( newwidth ); + m_rectCrop.setHeight( (int) (newwidth / m_optWidget->doubleRatio->value()) + 1 ); + setOptionWidgetHeight( m_rectCrop.height() - 1 ); + } + validateSelection(false); + paintOutlineWithHandles(); + } +} + +void KisToolCrop::setOptionWidgetX(TQ_INT32 x) +{ + // Disable signals otherwise we get the valueChanged signal, which we don't want + // to go through the logic for setting values that way. + m_optWidget->intX->blockSignals(true); + m_optWidget->intX->setValue(x); + m_optWidget->intX->blockSignals(false); +} + +void KisToolCrop::setOptionWidgetY(TQ_INT32 y) +{ + m_optWidget->intY->blockSignals(true); + m_optWidget->intY->setValue(y); + m_optWidget->intY->blockSignals(false); +} + +void KisToolCrop::setOptionWidgetWidth(TQ_INT32 x) +{ + m_optWidget->intWidth->blockSignals(true); + m_optWidget->intWidth->setValue(x); + m_optWidget->intWidth->blockSignals(false); +} + +void KisToolCrop::setOptionWidgetHeight(TQ_INT32 y) +{ + m_optWidget->intHeight->blockSignals(true); + m_optWidget->intHeight->setValue(y); + m_optWidget->intHeight->blockSignals(false); +} + +void KisToolCrop::setOptionWidgetRatio(double ratio) +{ + m_optWidget->doubleRatio->blockSignals(true); + m_optWidget->doubleRatio->setValue(ratio); + m_optWidget->doubleRatio->blockSignals(false); +} + + +TQWidget* KisToolCrop::createOptionWidget(TQWidget* parent) +{ + m_optWidget = new WdgToolCrop(parent); + TQ_CHECK_PTR(m_optWidget); + + connect(m_optWidget->bnCrop, TQT_SIGNAL(clicked()), this, TQT_SLOT(crop())); + + connect(m_optWidget->intX, TQT_SIGNAL(valueChanged(int)), this, TQT_SLOT(setCropX(int))); + connect(m_optWidget->intY, TQT_SIGNAL(valueChanged(int)), this, TQT_SLOT(setCropY(int))); + connect(m_optWidget->intWidth, TQT_SIGNAL(valueChanged(int)), this, TQT_SLOT(setCropWidth(int))); + connect(m_optWidget->intHeight, TQT_SIGNAL(valueChanged(int)), this, TQT_SLOT(setCropHeight(int))); + connect(m_optWidget->doubleRatio, TQT_SIGNAL(valueChanged(double)), this, TQT_SLOT(setRatio( double ))); + + return m_optWidget; +} + +TQWidget* KisToolCrop::optionWidget() +{ + return m_optWidget; +} + +void KisToolCrop::setup(TDEActionCollection *collection) +{ + m_action = static_cast(collection->action(name())); + + if (m_action == 0) { + m_action = new TDERadioAction(i18n("&Crop"), + "tool_crop", + 0, + this, + TQT_SLOT(activate()), + collection, + name()); + TQ_CHECK_PTR(m_action); + + m_action->setToolTip(i18n("Crop an area")); + m_action->setExclusiveGroup("tools"); + + m_ownAction = true; + } +} + +TQRect toTQRect(double x, double y, int w, int h) +{ + return TQRect(int(x), int(y), w, h); +} + +TQRegion KisToolCrop::handles(TQRect rect) +{ + TQRegion handlesRegion; + + //add handle at the lower right corner + handlesRegion += toTQRect( TQABS( rect.width() ) - m_handleSize / 2.0, TQABS( rect.height() ) - m_handleSize / 2.0, m_handleSize, m_handleSize ); + //add handle at the upper right corner + handlesRegion += toTQRect( TQABS( rect.width() ) - m_handleSize / 2.0 , 0 - m_handleSize / 2.0, m_handleSize, m_handleSize ); + //add rectangle at the lower left corner + handlesRegion += toTQRect( 0 - m_handleSize / 2.0 , TQABS( rect.height() ) - m_handleSize / 2.0, m_handleSize, m_handleSize ); + //add rectangle at the upper left corner + handlesRegion += toTQRect( 0 - m_handleSize / 2.0, 0 - m_handleSize / 2.0, m_handleSize, m_handleSize ); + //add handle at the lower edge of the rectangle + handlesRegion += toTQRect( ( TQABS( rect.width() ) - m_handleSize ) / 2.0 , TQABS( rect.height() ) - m_handleSize / 2.0, m_handleSize, m_handleSize ); + //add handle at the right edge of the rectangle + handlesRegion += toTQRect( TQABS( rect.width() ) - m_handleSize / 2.0 , ( TQABS( rect.height() ) - m_handleSize ) / 2.0, m_handleSize, m_handleSize ); + //add handle at the upper edge of the rectangle + handlesRegion += toTQRect( ( TQABS( rect.width() ) - m_handleSize ) / 2.0 , 0 - m_handleSize / 2.0, m_handleSize, m_handleSize ); + //add handle at the left edge of the rectangle + handlesRegion += toTQRect( 0 - m_handleSize / 2.0, ( TQABS( rect.height() ) - m_handleSize ) / 2.0, m_handleSize, m_handleSize ); + + //move the handles to the correct position + if( rect.width() >= 0 && rect.height() >= 0) + { + handlesRegion.translate ( rect.x(), rect.y() ); + } + else if( rect.width() < 0 && rect.height() >= 0) + { + handlesRegion.translate ( rect.x() - TQABS( rect.width() ), rect.y() ); + } + else if( rect.width() >= 0 && rect.height() < 0) + { + handlesRegion.translate ( rect.x(), rect.y() - TQABS( rect.height() ) ); + } + else if( rect.width() < 0 && rect.height() < 0) + { + handlesRegion.translate ( rect.x() - TQABS( rect.width() ), rect.y() - TQABS( rect.height() ) ); + } + return handlesRegion; +} + +TQ_INT32 KisToolCrop::mouseOnHandle(TQPoint currentViewPoint) +{ + KisCanvasController *controller = m_subject->canvasController(); + Q_ASSERT(controller); + TQPoint start = controller->windowToView(m_rectCrop.topLeft()); + TQPoint end = controller->windowToView(m_rectCrop.bottomRight()); + + TQ_INT32 startx; + TQ_INT32 starty; + TQ_INT32 endx; + TQ_INT32 endy; + if(start.x()<=end.x()) + { + startx=start.x(); + endx=end.x(); + } + else + { + startx=end.x(); + endx=start.x(); + } + if(start.y()<=end.y()) + { + starty=start.y(); + endy=end.y(); + } + else + { + starty=end.y(); + endy=start.y(); + } + + if ( toTQRect ( startx - m_handleSize / 2.0, starty - m_handleSize / 2.0, m_handleSize, m_handleSize ).contains( currentViewPoint ) ) + { + if( !m_selecting ) + { + m_dx= startx-currentViewPoint.x(); + m_dy = starty - currentViewPoint.y(); + } + return UpperLeft; + } + else if ( toTQRect ( startx - m_handleSize / 2.0, endy - m_handleSize / 2.0, m_handleSize, m_handleSize ).contains( currentViewPoint ) ) + { + if( !m_selecting ) + { + m_dx = startx-currentViewPoint.x(); + m_dy = endy-currentViewPoint.y(); + } + return LowerLeft; + } + else if ( toTQRect ( endx - m_handleSize / 2.0, starty - m_handleSize / 2.0, m_handleSize, m_handleSize ).contains( currentViewPoint ) ) + { + if( !m_selecting ) + { + m_dx = endx - currentViewPoint.x(); + m_dy = starty - currentViewPoint.y() ; + } + return UpperRight; + } + else if ( toTQRect ( endx - m_handleSize / 2.0, endy - m_handleSize / 2.0, m_handleSize, m_handleSize ).contains( currentViewPoint ) ) + { + if( !m_selecting ) + { + m_dx = endx - currentViewPoint.x(); + m_dy= endy - currentViewPoint.y(); + } + return LowerRight; + } + else if ( toTQRect ( startx + ( endx - startx - m_handleSize ) / 2.0, starty - m_handleSize / 2.0, m_handleSize, m_handleSize ).contains( currentViewPoint ) ) + { + if( !m_selecting ) + { + m_dy = starty - currentViewPoint.y() ; + } + return Upper; + } + else if ( toTQRect ( startx + ( endx - startx - m_handleSize ) / 2.0, endy - m_handleSize / 2, m_handleSize, m_handleSize ).contains( currentViewPoint ) ) + { + if( !m_selecting ) + { + m_dy = endy - currentViewPoint.y(); + } + return Lower; + } + else if ( toTQRect ( startx - m_handleSize / 2.0, starty + ( endy - starty - m_handleSize ) / 2.0, m_handleSize, m_handleSize ).contains( currentViewPoint ) ) + { + if( !m_selecting ) + { + m_dx = startx - currentViewPoint.x() ; + } + return Left; + } + else if ( toTQRect ( endx - m_handleSize / 2.0 , starty + ( endy - starty - m_handleSize ) / 2.0, m_handleSize, m_handleSize ).contains( currentViewPoint ) ) + { + if( !m_selecting ) + { + m_dx = endx-currentViewPoint.x(); + } + return Right; + } + else if ( toTQRect ( startx , starty, endx - startx , endy - starty ).contains( currentViewPoint ) ) + { + return Inside; + } + else return None; +} + +void KisToolCrop::setMoveResizeCursor (TQ_INT32 handle) +{ + switch (handle) + { + case (UpperLeft): + case (LowerRight): + m_subject->canvasController()->setCanvasCursor(KisCursor::sizeFDiagCursor()); + return; + case (LowerLeft): + case (UpperRight): + m_subject->canvasController()->setCanvasCursor(KisCursor::sizeBDiagCursor()); + return; + case (Upper): + case (Lower): + m_subject->canvasController()->setCanvasCursor(KisCursor::sizeVerCursor()); + return; + case (Left): + case (Right): + m_subject->canvasController()->setCanvasCursor(KisCursor::sizeHorCursor()); + return; + case (Inside): + m_subject->canvasController()->setCanvasCursor(KisCursor::sizeAllCursor()); + return; + } + m_subject->canvasController()->setCanvasCursor(KisCursor::arrowCursor()); + return; +} + + +#include "kis_tool_crop.moc" diff --git a/chalk/plugins/tools/tool_crop/tool_crop.cc b/chalk/plugins/tools/tool_crop/tool_crop.cc deleted file mode 100644 index 97f6e0e85..000000000 --- a/chalk/plugins/tools/tool_crop/tool_crop.cc +++ /dev/null @@ -1,62 +0,0 @@ -/* - * tool_crop.cc -- Part of Chalk - * - * Copyright (c) 2004 Boudewijn Rempt (boud@valdyas.org) - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -#include -#include - -#include - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include "tool_crop.h" -#include "kis_tool_crop.h" - - -typedef KGenericFactory ToolCropFactory; -K_EXPORT_COMPONENT_FACTORY( chalktoolcrop, ToolCropFactory( "chalk" ) ) - - -ToolCrop::ToolCrop(TQObject *parent, const char *name, const TQStringList &) - : KParts::Plugin(parent, name) -{ - setInstance(ToolCropFactory::instance()); - - if ( parent->inherits("KisToolRegistry") ) - { - KisToolRegistry * r = dynamic_cast(parent); - r->add(new KisToolCropFactory()); - } - -} - -ToolCrop::~ToolCrop() -{ -} - -#include "tool_crop.moc" diff --git a/chalk/plugins/tools/tool_crop/tool_crop.cpp b/chalk/plugins/tools/tool_crop/tool_crop.cpp new file mode 100644 index 000000000..30df11ec3 --- /dev/null +++ b/chalk/plugins/tools/tool_crop/tool_crop.cpp @@ -0,0 +1,62 @@ +/* + * tool_crop.cpp -- Part of Chalk + * + * Copyright (c) 2004 Boudewijn Rempt (boud@valdyas.org) + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "tool_crop.h" +#include "kis_tool_crop.h" + + +typedef KGenericFactory ToolCropFactory; +K_EXPORT_COMPONENT_FACTORY( chalktoolcrop, ToolCropFactory( "chalk" ) ) + + +ToolCrop::ToolCrop(TQObject *parent, const char *name, const TQStringList &) + : KParts::Plugin(parent, name) +{ + setInstance(ToolCropFactory::instance()); + + if ( parent->inherits("KisToolRegistry") ) + { + KisToolRegistry * r = dynamic_cast(parent); + r->add(new KisToolCropFactory()); + } + +} + +ToolCrop::~ToolCrop() +{ +} + +#include "tool_crop.moc" diff --git a/chalk/plugins/tools/tool_curves/Makefile.am b/chalk/plugins/tools/tool_curves/Makefile.am index 92366e55c..75a515f29 100644 --- a/chalk/plugins/tools/tool_curves/Makefile.am +++ b/chalk/plugins/tools/tool_curves/Makefile.am @@ -10,15 +10,15 @@ INCLUDES = -I$(srcdir)/../../../sdk \ $(all_includes) chalktoolcurves_la_SOURCES = \ - kis_curve_framework.cc \ - kis_tool_curve.cc \ - tool_curves.cc \ + kis_curve_framework.cpp \ + kis_tool_curve.cpp \ + tool_curves.cpp \ wdg_tool_example.ui \ - kis_tool_example.cc \ - kis_tool_bezier.cc \ - kis_tool_bezier_paint.cc \ - kis_tool_bezier_select.cc \ - kis_tool_moutline.cc + kis_tool_example.cpp \ + kis_tool_bezier.cpp \ + kis_tool_bezier_paint.cpp \ + kis_tool_bezier_select.cpp \ + kis_tool_moutline.cpp # Install this plugin in the KDE modules directory kde_module_LTLIBRARIES = chalktoolcurves.la diff --git a/chalk/plugins/tools/tool_curves/kis_curve_framework.cc b/chalk/plugins/tools/tool_curves/kis_curve_framework.cpp similarity index 100% rename from chalk/plugins/tools/tool_curves/kis_curve_framework.cc rename to chalk/plugins/tools/tool_curves/kis_curve_framework.cpp diff --git a/chalk/plugins/tools/tool_curves/kis_tool_bezier.cc b/chalk/plugins/tools/tool_curves/kis_tool_bezier.cc deleted file mode 100644 index e4c1d05d0..000000000 --- a/chalk/plugins/tools/tool_curves/kis_tool_bezier.cc +++ /dev/null @@ -1,366 +0,0 @@ -/* - * kis_tool_bezier.cc -- part of Chalk - * - * Copyright (c) 2006 Emanuele Tamponi - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include - -#include -#include -#include - -#include -#include -#include -#include -#include - -#include "kis_global.h" -#include "kis_doc.h" -#include "kis_painter.h" -#include "kis_point.h" -#include "kis_canvas_subject.h" -#include "kis_canvas_controller.h" -#include "kis_canvas.h" -#include "kis_canvas_painter.h" -#include "kis_cursor.h" -#include "kis_vec.h" - -#include "kis_curve_framework.h" -#include "kis_tool_bezier.h" - -KisCurve::iterator KisCurveBezier::groupEndpoint (KisCurve::iterator it) const -{ - iterator temp = it; - if ((*it).hint() == BEZIERNEXTCONTROLHINT) - temp -= 1; - if ((*it).hint() == BEZIERPREVCONTROLHINT) - temp += 1; - return temp; -} - -KisCurve::iterator KisCurveBezier::groupPrevControl (KisCurve::iterator it) const -{ - iterator temp = it; - if ((*it).hint() == BEZIERENDHINT) - temp -= 1; - if ((*it).hint() == BEZIERNEXTCONTROLHINT) - temp -= 2; - return temp; -} - -KisCurve::iterator KisCurveBezier::groupNextControl (KisCurve::iterator it) const -{ - iterator temp = it; - if ((*it).hint() == BEZIERENDHINT) - temp += 1; - if ((*it).hint() == BEZIERPREVCONTROLHINT) - temp += 2; - return temp; -} - -bool KisCurveBezier::groupSelected (KisCurve::iterator it) const -{ - if ((*groupPrevControl(it)).isSelected() || (*groupEndpoint(it)).isSelected() || (*groupNextControl(it)).isSelected()) - return true; - return false; -} - -KisCurve::iterator KisCurveBezier::nextGroupEndpoint (KisCurve::iterator it) const -{ - iterator temp = it; - if ((*it).hint() == BEZIERPREVCONTROLHINT) { - temp += 2; - temp = temp.nextPivot(); - } - if ((*it).hint() == BEZIERENDHINT) { - temp += 1; - temp = temp.nextPivot(); - } - if ((*it).hint() == BEZIERNEXTCONTROLHINT) { - temp = temp.nextPivot(); - } - temp = temp.nextPivot(); - return temp; -} - -KisCurve::iterator KisCurveBezier::prevGroupEndpoint (KisCurve::iterator it) const -{ - iterator temp = it; - if ((*it).hint() == BEZIERNEXTCONTROLHINT) { - temp -= 1; - temp = temp.previousPivot().previousPivot(); - } - if ((*it).hint() == BEZIERENDHINT) { - temp = temp.previousPivot().previousPivot(); - } - if ((*it).hint() == BEZIERPREVCONTROLHINT) { - temp = temp.previousPivot(); - } - temp = temp.previousPivot(); - return temp; -} - -KisPoint KisCurveBezier::midpoint (const KisPoint& P1, const KisPoint& P2) -{ - KisPoint temp; - temp.setX((P1.x()+P2.x())/2); - temp.setY((P1.y()+P2.y())/2); - return temp; -} - -void KisCurveBezier::recursiveCurve (const KisPoint& P1, const KisPoint& P2, const KisPoint& P3, - const KisPoint& P4, int level, KisCurve::iterator it) -{ - if (level > m_maxLevel) { - addPoint(it,midpoint(P1,P4),false,false,LINEHINT); - return; - } - - KisPoint L1, L2, L3, L4; - KisPoint H, R1, R2, R3, R4; - - L1 = P1; - L2 = midpoint(P1, P2); - H = midpoint(P2, P3); - R3 = midpoint(P3, P4); - R4 = P4; - L3 = midpoint(L2, H); - R2 = midpoint(R3, H); - L4 = midpoint(L3, R2); - R1 = L4; - recursiveCurve(L1, L2, L3, L4, level + 1, it); - recursiveCurve(R1, R2, R3, R4, level + 1, it); -} - -void KisCurveBezier::calculateCurve(KisCurve::iterator tstart, KisCurve::iterator tend, KisCurve::iterator) -{ - if (pivots().count() < 4) - return; - - iterator origin, dest, control1, control2; - - if ((*tstart).hint() == BEZIERENDHINT) { - origin = tstart; - control1 = tstart.nextPivot(); - } else if ((*tstart).hint() == BEZIERNEXTCONTROLHINT) { - origin = tstart.previousPivot(); - control1 = tstart; - } else if ((*tstart).hint() == BEZIERPREVCONTROLHINT) { - origin = tstart.nextPivot(); - control1 = origin.nextPivot(); - } else - return; - - if ((*tend).hint() == BEZIERENDHINT) { - dest = tend; - control2 = tend.previousPivot(); - } else if ((*tend).hint() == BEZIERPREVCONTROLHINT) { - dest = tend.nextPivot(); - control2 = tend; - } else if ((*tend).hint() == BEZIERNEXTCONTROLHINT) { - dest = tend.previousPivot(); - control2 = dest.previousPivot(); - } else - return; - - deleteCurve(control1,control2); - recursiveCurve((*origin).point(),(*control1).point(),(*control2).point(),(*dest).point(),1,control2); - -} - -KisCurve::iterator KisCurveBezier::pushPivot (const KisPoint& point) -{ - iterator it; - - it = pushPoint(point,true,false,BEZIERENDHINT); - if (count() > 1) - addPoint(it,point,true,false,BEZIERPREVCONTROLHINT); - - it = pushPoint(point,true,false,BEZIERNEXTCONTROLHINT); - - return selectPivot(it); -} - -KisCurve::iterator KisCurveBezier::movePivot(KisCurve::iterator it, const KisPoint& newPt) -{ - if (!(*it).isPivot()) - return end(); - - int hint = (*it).hint(); - iterator thisEnd, prevEnd, nextEnd; - - thisEnd = groupEndpoint(it); - prevEnd = prevGroupEndpoint(it); - nextEnd = nextGroupEndpoint(it); - - if (hint == BEZIERENDHINT) { - KisPoint trans = newPt - (*it).point(); - (*thisEnd).setPoint((*thisEnd).point()+trans); - (*thisEnd.previous()).setPoint((*thisEnd.previous()).point()+trans); - (*thisEnd.next()).setPoint((*thisEnd.next()).point()+trans); - } else if (!(m_actionOptions & KEEPSELECTEDOPTION)) - (*it).setPoint(newPt); - if (!(m_actionOptions & KEEPSELECTEDOPTION) && hint != BEZIERENDHINT) { - if (nextEnd == end() || (m_actionOptions & SYMMETRICALCONTROLSOPTION)) { - KisPoint trans = (*it).point() - (*thisEnd).point(); - trans = KisPoint(-trans.x()*2,-trans.y()*2); - if (hint == BEZIERNEXTCONTROLHINT) - (*groupPrevControl(it)).setPoint(newPt+trans); - else - (*groupNextControl(it)).setPoint(newPt+trans); - } - } - - if (nextEnd != end() && count() > 4) - calculateCurve (thisEnd,nextEnd,iterator()); - if (prevEnd != thisEnd && count() > 4) - calculateCurve (prevEnd,thisEnd,iterator()); - - return it; -} - -void KisCurveBezier::deletePivot (KisCurve::iterator it) -{ - if (!(*it).isPivot()) - return; - - iterator prevControl,thisEnd,nextControl; - - prevControl = prevGroupEndpoint(it).nextPivot(); - thisEnd = groupEndpoint(it); - nextControl = nextGroupEndpoint(it).previousPivot(); - - if ((*thisEnd) == first()) { - deleteFirstPivot(); - deleteFirstPivot(); - deleteFirstPivot(); - } else if ((*thisEnd.next()) == last()) { - deleteLastPivot(); - deleteLastPivot(); - deleteLastPivot(); - } else { - deleteCurve(prevControl,nextControl); - calculateCurve(prevControl,nextControl,iterator()); - } -} - -KisToolBezier::KisToolBezier(const TQString& UIName) - : super(UIName) -{ - m_derivated = new KisCurveBezier; - m_curve = m_derivated; - - m_supportMinimalDraw = false; - - m_transactionMessage = i18n("Bezier Curve"); -} - -KisToolBezier::~KisToolBezier() -{ - -} - -KisCurve::iterator KisToolBezier::handleUnderMouse(const TQPoint& pos) -{ - TQPoint qpos; - KisCurve pivs = m_curve->pivots(), inHandle; - KisCurve::iterator it; - int hint; - for (it = pivs.begin(); it != pivs.end(); it++) { - qpos = m_subject->canvasController()->windowToView((*it).point().toTQPoint()); - hint = (*it).hint(); - if (hint != BEZIERENDHINT && !m_derivated->groupSelected(it)) - continue; - if (hint == BEZIERENDHINT && (m_actionOptions & SHIFTOPTION)) - continue; - if (pivotRect(qpos).contains(pos)) { - inHandle.pushPoint((*it)); - if (hint == BEZIERENDHINT && !(m_actionOptions & SHIFTOPTION)) - break; - if (hint != BEZIERENDHINT && (m_actionOptions & SHIFTOPTION)) - break; - } - } - if (inHandle.isEmpty()) - return m_curve->end(); - - return m_curve->find(inHandle.last()); -} - -KisCurve::iterator KisToolBezier::drawPoint (KisCanvasPainter& gc, KisCurve::iterator point) -{ - if ((*point).hint() != BEZIERENDHINT) - return ++point; - - KisCanvasController *controller = m_subject->canvasController(); - - // Now draw the bezier - - KisCurve::iterator origin,control1,control2,destination; - - origin = point; - control1 = origin.next(); - control2 = control1.nextPivot(); - destination = control2.next(); - - if (control2 != m_curve->end()) { - point = control2; - TQPointArray vec(4); - vec[0] = controller->windowToView((*origin).point().toTQPoint()); - vec[1] = controller->windowToView((*control1).point().toTQPoint()); - vec[2] = controller->windowToView((*control2).point().toTQPoint()); - vec[3] = controller->windowToView((*destination).point().toTQPoint()); - gc.drawCubicBezier(vec); - } - - point += 1; - - return point; -} - -void KisToolBezier::drawPivotHandle (KisCanvasPainter& gc, KisCurve::iterator point) -{ - if ((*point).hint() != BEZIERENDHINT) - return; - - KisCanvasController *controller = m_subject->canvasController(); - - TQPoint endpPos = controller->windowToView((*point).point().toTQPoint()); - - if (!m_derivated->groupSelected(point)) { - gc.setPen(m_pivotPen); - gc.drawRoundRect(pivotRect(endpPos),m_pivotRounding,m_pivotRounding); - } else { - TQPoint nextControlPos = controller->windowToView((*point.next()).point().toTQPoint()); - TQPoint prevControlPos = controller->windowToView((*point.previousPivot()).point().toTQPoint()); - - gc.setPen(m_selectedPivotPen); - gc.drawRoundRect(selectedPivotRect(endpPos),m_selectedPivotRounding,m_selectedPivotRounding); - if ((prevControlPos != endpPos || nextControlPos != endpPos) && !(m_actionOptions & CONTROLOPTION)) { - gc.drawRoundRect(pivotRect(nextControlPos),m_pivotRounding,m_pivotRounding); - gc.drawLine(endpPos,nextControlPos); - gc.drawRoundRect(pivotRect(prevControlPos),m_pivotRounding,m_pivotRounding); - gc.drawLine(prevControlPos,endpPos); - } - } - - gc.setPen(m_drawingPen); -} - -#include "kis_tool_bezier.moc" diff --git a/chalk/plugins/tools/tool_curves/kis_tool_bezier.cpp b/chalk/plugins/tools/tool_curves/kis_tool_bezier.cpp new file mode 100644 index 000000000..9195dfbd7 --- /dev/null +++ b/chalk/plugins/tools/tool_curves/kis_tool_bezier.cpp @@ -0,0 +1,366 @@ +/* + * kis_tool_bezier.cpp -- part of Chalk + * + * Copyright (c) 2006 Emanuele Tamponi + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "kis_global.h" +#include "kis_doc.h" +#include "kis_painter.h" +#include "kis_point.h" +#include "kis_canvas_subject.h" +#include "kis_canvas_controller.h" +#include "kis_canvas.h" +#include "kis_canvas_painter.h" +#include "kis_cursor.h" +#include "kis_vec.h" + +#include "kis_curve_framework.h" +#include "kis_tool_bezier.h" + +KisCurve::iterator KisCurveBezier::groupEndpoint (KisCurve::iterator it) const +{ + iterator temp = it; + if ((*it).hint() == BEZIERNEXTCONTROLHINT) + temp -= 1; + if ((*it).hint() == BEZIERPREVCONTROLHINT) + temp += 1; + return temp; +} + +KisCurve::iterator KisCurveBezier::groupPrevControl (KisCurve::iterator it) const +{ + iterator temp = it; + if ((*it).hint() == BEZIERENDHINT) + temp -= 1; + if ((*it).hint() == BEZIERNEXTCONTROLHINT) + temp -= 2; + return temp; +} + +KisCurve::iterator KisCurveBezier::groupNextControl (KisCurve::iterator it) const +{ + iterator temp = it; + if ((*it).hint() == BEZIERENDHINT) + temp += 1; + if ((*it).hint() == BEZIERPREVCONTROLHINT) + temp += 2; + return temp; +} + +bool KisCurveBezier::groupSelected (KisCurve::iterator it) const +{ + if ((*groupPrevControl(it)).isSelected() || (*groupEndpoint(it)).isSelected() || (*groupNextControl(it)).isSelected()) + return true; + return false; +} + +KisCurve::iterator KisCurveBezier::nextGroupEndpoint (KisCurve::iterator it) const +{ + iterator temp = it; + if ((*it).hint() == BEZIERPREVCONTROLHINT) { + temp += 2; + temp = temp.nextPivot(); + } + if ((*it).hint() == BEZIERENDHINT) { + temp += 1; + temp = temp.nextPivot(); + } + if ((*it).hint() == BEZIERNEXTCONTROLHINT) { + temp = temp.nextPivot(); + } + temp = temp.nextPivot(); + return temp; +} + +KisCurve::iterator KisCurveBezier::prevGroupEndpoint (KisCurve::iterator it) const +{ + iterator temp = it; + if ((*it).hint() == BEZIERNEXTCONTROLHINT) { + temp -= 1; + temp = temp.previousPivot().previousPivot(); + } + if ((*it).hint() == BEZIERENDHINT) { + temp = temp.previousPivot().previousPivot(); + } + if ((*it).hint() == BEZIERPREVCONTROLHINT) { + temp = temp.previousPivot(); + } + temp = temp.previousPivot(); + return temp; +} + +KisPoint KisCurveBezier::midpoint (const KisPoint& P1, const KisPoint& P2) +{ + KisPoint temp; + temp.setX((P1.x()+P2.x())/2); + temp.setY((P1.y()+P2.y())/2); + return temp; +} + +void KisCurveBezier::recursiveCurve (const KisPoint& P1, const KisPoint& P2, const KisPoint& P3, + const KisPoint& P4, int level, KisCurve::iterator it) +{ + if (level > m_maxLevel) { + addPoint(it,midpoint(P1,P4),false,false,LINEHINT); + return; + } + + KisPoint L1, L2, L3, L4; + KisPoint H, R1, R2, R3, R4; + + L1 = P1; + L2 = midpoint(P1, P2); + H = midpoint(P2, P3); + R3 = midpoint(P3, P4); + R4 = P4; + L3 = midpoint(L2, H); + R2 = midpoint(R3, H); + L4 = midpoint(L3, R2); + R1 = L4; + recursiveCurve(L1, L2, L3, L4, level + 1, it); + recursiveCurve(R1, R2, R3, R4, level + 1, it); +} + +void KisCurveBezier::calculateCurve(KisCurve::iterator tstart, KisCurve::iterator tend, KisCurve::iterator) +{ + if (pivots().count() < 4) + return; + + iterator origin, dest, control1, control2; + + if ((*tstart).hint() == BEZIERENDHINT) { + origin = tstart; + control1 = tstart.nextPivot(); + } else if ((*tstart).hint() == BEZIERNEXTCONTROLHINT) { + origin = tstart.previousPivot(); + control1 = tstart; + } else if ((*tstart).hint() == BEZIERPREVCONTROLHINT) { + origin = tstart.nextPivot(); + control1 = origin.nextPivot(); + } else + return; + + if ((*tend).hint() == BEZIERENDHINT) { + dest = tend; + control2 = tend.previousPivot(); + } else if ((*tend).hint() == BEZIERPREVCONTROLHINT) { + dest = tend.nextPivot(); + control2 = tend; + } else if ((*tend).hint() == BEZIERNEXTCONTROLHINT) { + dest = tend.previousPivot(); + control2 = dest.previousPivot(); + } else + return; + + deleteCurve(control1,control2); + recursiveCurve((*origin).point(),(*control1).point(),(*control2).point(),(*dest).point(),1,control2); + +} + +KisCurve::iterator KisCurveBezier::pushPivot (const KisPoint& point) +{ + iterator it; + + it = pushPoint(point,true,false,BEZIERENDHINT); + if (count() > 1) + addPoint(it,point,true,false,BEZIERPREVCONTROLHINT); + + it = pushPoint(point,true,false,BEZIERNEXTCONTROLHINT); + + return selectPivot(it); +} + +KisCurve::iterator KisCurveBezier::movePivot(KisCurve::iterator it, const KisPoint& newPt) +{ + if (!(*it).isPivot()) + return end(); + + int hint = (*it).hint(); + iterator thisEnd, prevEnd, nextEnd; + + thisEnd = groupEndpoint(it); + prevEnd = prevGroupEndpoint(it); + nextEnd = nextGroupEndpoint(it); + + if (hint == BEZIERENDHINT) { + KisPoint trans = newPt - (*it).point(); + (*thisEnd).setPoint((*thisEnd).point()+trans); + (*thisEnd.previous()).setPoint((*thisEnd.previous()).point()+trans); + (*thisEnd.next()).setPoint((*thisEnd.next()).point()+trans); + } else if (!(m_actionOptions & KEEPSELECTEDOPTION)) + (*it).setPoint(newPt); + if (!(m_actionOptions & KEEPSELECTEDOPTION) && hint != BEZIERENDHINT) { + if (nextEnd == end() || (m_actionOptions & SYMMETRICALCONTROLSOPTION)) { + KisPoint trans = (*it).point() - (*thisEnd).point(); + trans = KisPoint(-trans.x()*2,-trans.y()*2); + if (hint == BEZIERNEXTCONTROLHINT) + (*groupPrevControl(it)).setPoint(newPt+trans); + else + (*groupNextControl(it)).setPoint(newPt+trans); + } + } + + if (nextEnd != end() && count() > 4) + calculateCurve (thisEnd,nextEnd,iterator()); + if (prevEnd != thisEnd && count() > 4) + calculateCurve (prevEnd,thisEnd,iterator()); + + return it; +} + +void KisCurveBezier::deletePivot (KisCurve::iterator it) +{ + if (!(*it).isPivot()) + return; + + iterator prevControl,thisEnd,nextControl; + + prevControl = prevGroupEndpoint(it).nextPivot(); + thisEnd = groupEndpoint(it); + nextControl = nextGroupEndpoint(it).previousPivot(); + + if ((*thisEnd) == first()) { + deleteFirstPivot(); + deleteFirstPivot(); + deleteFirstPivot(); + } else if ((*thisEnd.next()) == last()) { + deleteLastPivot(); + deleteLastPivot(); + deleteLastPivot(); + } else { + deleteCurve(prevControl,nextControl); + calculateCurve(prevControl,nextControl,iterator()); + } +} + +KisToolBezier::KisToolBezier(const TQString& UIName) + : super(UIName) +{ + m_derivated = new KisCurveBezier; + m_curve = m_derivated; + + m_supportMinimalDraw = false; + + m_transactionMessage = i18n("Bezier Curve"); +} + +KisToolBezier::~KisToolBezier() +{ + +} + +KisCurve::iterator KisToolBezier::handleUnderMouse(const TQPoint& pos) +{ + TQPoint qpos; + KisCurve pivs = m_curve->pivots(), inHandle; + KisCurve::iterator it; + int hint; + for (it = pivs.begin(); it != pivs.end(); it++) { + qpos = m_subject->canvasController()->windowToView((*it).point().toTQPoint()); + hint = (*it).hint(); + if (hint != BEZIERENDHINT && !m_derivated->groupSelected(it)) + continue; + if (hint == BEZIERENDHINT && (m_actionOptions & SHIFTOPTION)) + continue; + if (pivotRect(qpos).contains(pos)) { + inHandle.pushPoint((*it)); + if (hint == BEZIERENDHINT && !(m_actionOptions & SHIFTOPTION)) + break; + if (hint != BEZIERENDHINT && (m_actionOptions & SHIFTOPTION)) + break; + } + } + if (inHandle.isEmpty()) + return m_curve->end(); + + return m_curve->find(inHandle.last()); +} + +KisCurve::iterator KisToolBezier::drawPoint (KisCanvasPainter& gc, KisCurve::iterator point) +{ + if ((*point).hint() != BEZIERENDHINT) + return ++point; + + KisCanvasController *controller = m_subject->canvasController(); + + // Now draw the bezier + + KisCurve::iterator origin,control1,control2,destination; + + origin = point; + control1 = origin.next(); + control2 = control1.nextPivot(); + destination = control2.next(); + + if (control2 != m_curve->end()) { + point = control2; + TQPointArray vec(4); + vec[0] = controller->windowToView((*origin).point().toTQPoint()); + vec[1] = controller->windowToView((*control1).point().toTQPoint()); + vec[2] = controller->windowToView((*control2).point().toTQPoint()); + vec[3] = controller->windowToView((*destination).point().toTQPoint()); + gc.drawCubicBezier(vec); + } + + point += 1; + + return point; +} + +void KisToolBezier::drawPivotHandle (KisCanvasPainter& gc, KisCurve::iterator point) +{ + if ((*point).hint() != BEZIERENDHINT) + return; + + KisCanvasController *controller = m_subject->canvasController(); + + TQPoint endpPos = controller->windowToView((*point).point().toTQPoint()); + + if (!m_derivated->groupSelected(point)) { + gc.setPen(m_pivotPen); + gc.drawRoundRect(pivotRect(endpPos),m_pivotRounding,m_pivotRounding); + } else { + TQPoint nextControlPos = controller->windowToView((*point.next()).point().toTQPoint()); + TQPoint prevControlPos = controller->windowToView((*point.previousPivot()).point().toTQPoint()); + + gc.setPen(m_selectedPivotPen); + gc.drawRoundRect(selectedPivotRect(endpPos),m_selectedPivotRounding,m_selectedPivotRounding); + if ((prevControlPos != endpPos || nextControlPos != endpPos) && !(m_actionOptions & CONTROLOPTION)) { + gc.drawRoundRect(pivotRect(nextControlPos),m_pivotRounding,m_pivotRounding); + gc.drawLine(endpPos,nextControlPos); + gc.drawRoundRect(pivotRect(prevControlPos),m_pivotRounding,m_pivotRounding); + gc.drawLine(prevControlPos,endpPos); + } + } + + gc.setPen(m_drawingPen); +} + +#include "kis_tool_bezier.moc" diff --git a/chalk/plugins/tools/tool_curves/kis_tool_bezier_paint.cc b/chalk/plugins/tools/tool_curves/kis_tool_bezier_paint.cc deleted file mode 100644 index 06f34f8cc..000000000 --- a/chalk/plugins/tools/tool_curves/kis_tool_bezier_paint.cc +++ /dev/null @@ -1,115 +0,0 @@ -/* - * kis_tool_curve.cc -- part of Chalk - * - * Copyright (c) 2006 Emanuele Tamponi - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include "kis_cmb_composite.h" -#include "kis_colorspace.h" -#include "kis_config.h" -#include "kis_cursor.h" -#include "kis_doc.h" -#include "kis_global.h" -#include "kis_image.h" -#include "kis_int_spinbox.h" -#include "kis_paint_device.h" -#include "kis_painter.h" -#include "kis_paintop_registry.h" -#include "kis_point.h" -#include "kis_tool_controller.h" -#include "kis_tool_paint.h" - -#include "kis_canvas.h" -#include "kis_canvas_painter.h" -#include "kis_canvas_subject.h" - -#include "kis_curve_framework.h" -#include "kis_tool_bezier_paint.h" - -KisToolBezierPaint::KisToolBezierPaint() - : super(i18n("Bezier Painting Tool")) -{ - setName("tool_bezier_paint"); - m_cursor = "tool_bezier_cursor.png"; - setCursor(KisCursor::load(m_cursor, 6, 6)); -} - -KisToolBezierPaint::~KisToolBezierPaint() -{ - -} - -KisCurve::iterator KisToolBezierPaint::paintPoint (KisPainter& painter, KisCurve::iterator point) -{ - KisCurve::iterator origin,destination,control1,control2; - switch ((*point).hint()) { - case BEZIERENDHINT: - origin = point++; - control1 = point; - control2 = control1.nextPivot(); - destination = control2.next(); - if (m_curve->count() > 4 && (*point) != m_curve->last()) { - point = point.nextPivot().next(); - painter.paintAt((*origin).point(),PRESSURE_DEFAULT,0,0); - painter.paintBezierCurve((*origin).point(),PRESSURE_DEFAULT,0,0,(*control1).point(), - (*control2).point(),(*destination).point(),PRESSURE_DEFAULT,0,0,0); - } - break; - default: - point = super::paintPoint(painter,point); - } - - return point; -} - -void KisToolBezierPaint::setup(TDEActionCollection *collection) -{ - m_action = static_cast(collection->action(name())); - - if (m_action == 0) { - TDEShortcut shortcut(TQt::Key_Plus); - shortcut.append(TDEShortcut(TQt::Key_F9)); - m_action = new TDERadioAction(i18n("&Bezier"), - "tool_bezier_paint", - shortcut, - this, - TQT_SLOT(activate()), - collection, - name()); - TQ_CHECK_PTR(m_action); - - m_action->setToolTip(i18n("Draw cubic beziers. Keep Alt, Control or Shift pressed for options. Return or double-click to finish.")); - m_action->setExclusiveGroup("tools"); - m_ownAction = true; - } -} - -#include "kis_tool_bezier_paint.moc" diff --git a/chalk/plugins/tools/tool_curves/kis_tool_bezier_paint.cpp b/chalk/plugins/tools/tool_curves/kis_tool_bezier_paint.cpp new file mode 100644 index 000000000..a8d1514be --- /dev/null +++ b/chalk/plugins/tools/tool_curves/kis_tool_bezier_paint.cpp @@ -0,0 +1,115 @@ +/* + * kis_tool_curve.cpp -- part of Chalk + * + * Copyright (c) 2006 Emanuele Tamponi + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "kis_cmb_composite.h" +#include "kis_colorspace.h" +#include "kis_config.h" +#include "kis_cursor.h" +#include "kis_doc.h" +#include "kis_global.h" +#include "kis_image.h" +#include "kis_int_spinbox.h" +#include "kis_paint_device.h" +#include "kis_painter.h" +#include "kis_paintop_registry.h" +#include "kis_point.h" +#include "kis_tool_controller.h" +#include "kis_tool_paint.h" + +#include "kis_canvas.h" +#include "kis_canvas_painter.h" +#include "kis_canvas_subject.h" + +#include "kis_curve_framework.h" +#include "kis_tool_bezier_paint.h" + +KisToolBezierPaint::KisToolBezierPaint() + : super(i18n("Bezier Painting Tool")) +{ + setName("tool_bezier_paint"); + m_cursor = "tool_bezier_cursor.png"; + setCursor(KisCursor::load(m_cursor, 6, 6)); +} + +KisToolBezierPaint::~KisToolBezierPaint() +{ + +} + +KisCurve::iterator KisToolBezierPaint::paintPoint (KisPainter& painter, KisCurve::iterator point) +{ + KisCurve::iterator origin,destination,control1,control2; + switch ((*point).hint()) { + case BEZIERENDHINT: + origin = point++; + control1 = point; + control2 = control1.nextPivot(); + destination = control2.next(); + if (m_curve->count() > 4 && (*point) != m_curve->last()) { + point = point.nextPivot().next(); + painter.paintAt((*origin).point(),PRESSURE_DEFAULT,0,0); + painter.paintBezierCurve((*origin).point(),PRESSURE_DEFAULT,0,0,(*control1).point(), + (*control2).point(),(*destination).point(),PRESSURE_DEFAULT,0,0,0); + } + break; + default: + point = super::paintPoint(painter,point); + } + + return point; +} + +void KisToolBezierPaint::setup(TDEActionCollection *collection) +{ + m_action = static_cast(collection->action(name())); + + if (m_action == 0) { + TDEShortcut shortcut(TQt::Key_Plus); + shortcut.append(TDEShortcut(TQt::Key_F9)); + m_action = new TDERadioAction(i18n("&Bezier"), + "tool_bezier_paint", + shortcut, + this, + TQT_SLOT(activate()), + collection, + name()); + TQ_CHECK_PTR(m_action); + + m_action->setToolTip(i18n("Draw cubic beziers. Keep Alt, Control or Shift pressed for options. Return or double-click to finish.")); + m_action->setExclusiveGroup("tools"); + m_ownAction = true; + } +} + +#include "kis_tool_bezier_paint.moc" diff --git a/chalk/plugins/tools/tool_curves/kis_tool_bezier_select.cc b/chalk/plugins/tools/tool_curves/kis_tool_bezier_select.cc deleted file mode 100644 index 724189208..000000000 --- a/chalk/plugins/tools/tool_curves/kis_tool_bezier_select.cc +++ /dev/null @@ -1,104 +0,0 @@ -/* - * kis_tool_curve.cc -- part of Chalk - * - * Copyright (c) 2006 Emanuele Tamponi - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include "kis_cmb_composite.h" -#include "kis_colorspace.h" -#include "kis_config.h" -#include "kis_cursor.h" -#include "kis_doc.h" -#include "kis_global.h" -#include "kis_image.h" -#include "kis_int_spinbox.h" -#include "kis_paint_device.h" -#include "kis_painter.h" -#include "kis_paintop_registry.h" -#include "kis_point.h" -#include "kis_tool_controller.h" -#include "kis_tool_paint.h" - -#include "kis_canvas.h" -#include "kis_canvas_painter.h" -#include "kis_canvas_subject.h" - -#include "kis_curve_framework.h" -#include "kis_tool_bezier_select.h" - -KisToolBezierSelect::KisToolBezierSelect() - : super(i18n("Bezier Selection Tool")) -{ - setName("tool_bezier_select"); - m_cursor = "tool_bezier_cursor.png"; - setCursor(KisCursor::load(m_cursor, 6, 6)); -} - -KisToolBezierSelect::~KisToolBezierSelect() -{ - -} - -TQValueVector KisToolBezierSelect::convertCurve() -{ - TQValueVector points; - - for (KisCurve::iterator i = m_curve->begin(); i != m_curve->end(); i++) { - if (((*i).hint() != BEZIERPREVCONTROLHINT) && ((*i).hint() != BEZIERNEXTCONTROLHINT)) - points.append((*i).point()); - } - - return points; -} - -void KisToolBezierSelect::setup(TDEActionCollection *collection) -{ - m_action = static_cast(collection->action(name())); - - if (m_action == 0) { - TDEShortcut shortcut(TQt::Key_Plus); - shortcut.append(TDEShortcut(TQt::Key_F9)); - m_action = new TDERadioAction(i18n("&Bezier"), - "tool_bezier_select", - shortcut, - this, - TQT_SLOT(activate()), - collection, - name()); - TQ_CHECK_PTR(m_action); - - m_action->setToolTip(i18n("Select areas of the image with bezier paths.")); - m_action->setExclusiveGroup("tools"); - m_ownAction = true; - } -} - -#include "kis_tool_bezier_select.moc" diff --git a/chalk/plugins/tools/tool_curves/kis_tool_bezier_select.cpp b/chalk/plugins/tools/tool_curves/kis_tool_bezier_select.cpp new file mode 100644 index 000000000..657358609 --- /dev/null +++ b/chalk/plugins/tools/tool_curves/kis_tool_bezier_select.cpp @@ -0,0 +1,104 @@ +/* + * kis_tool_curve.cpp -- part of Chalk + * + * Copyright (c) 2006 Emanuele Tamponi + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "kis_cmb_composite.h" +#include "kis_colorspace.h" +#include "kis_config.h" +#include "kis_cursor.h" +#include "kis_doc.h" +#include "kis_global.h" +#include "kis_image.h" +#include "kis_int_spinbox.h" +#include "kis_paint_device.h" +#include "kis_painter.h" +#include "kis_paintop_registry.h" +#include "kis_point.h" +#include "kis_tool_controller.h" +#include "kis_tool_paint.h" + +#include "kis_canvas.h" +#include "kis_canvas_painter.h" +#include "kis_canvas_subject.h" + +#include "kis_curve_framework.h" +#include "kis_tool_bezier_select.h" + +KisToolBezierSelect::KisToolBezierSelect() + : super(i18n("Bezier Selection Tool")) +{ + setName("tool_bezier_select"); + m_cursor = "tool_bezier_cursor.png"; + setCursor(KisCursor::load(m_cursor, 6, 6)); +} + +KisToolBezierSelect::~KisToolBezierSelect() +{ + +} + +TQValueVector KisToolBezierSelect::convertCurve() +{ + TQValueVector points; + + for (KisCurve::iterator i = m_curve->begin(); i != m_curve->end(); i++) { + if (((*i).hint() != BEZIERPREVCONTROLHINT) && ((*i).hint() != BEZIERNEXTCONTROLHINT)) + points.append((*i).point()); + } + + return points; +} + +void KisToolBezierSelect::setup(TDEActionCollection *collection) +{ + m_action = static_cast(collection->action(name())); + + if (m_action == 0) { + TDEShortcut shortcut(TQt::Key_Plus); + shortcut.append(TDEShortcut(TQt::Key_F9)); + m_action = new TDERadioAction(i18n("&Bezier"), + "tool_bezier_select", + shortcut, + this, + TQT_SLOT(activate()), + collection, + name()); + TQ_CHECK_PTR(m_action); + + m_action->setToolTip(i18n("Select areas of the image with bezier paths.")); + m_action->setExclusiveGroup("tools"); + m_ownAction = true; + } +} + +#include "kis_tool_bezier_select.moc" diff --git a/chalk/plugins/tools/tool_curves/kis_tool_curve.cc b/chalk/plugins/tools/tool_curves/kis_tool_curve.cc deleted file mode 100644 index 7449e5817..000000000 --- a/chalk/plugins/tools/tool_curves/kis_tool_curve.cc +++ /dev/null @@ -1,593 +0,0 @@ -/* - * kis_tool_curve.cc -- part of Chalk - * - * Copyright (c) 2006 Emanuele Tamponi - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include -#include - -#include -#include -#include -#include - -#include -#include -#include -#include - -#include "kis_global.h" -#include "kis_doc.h" -#include "kis_painter.h" -#include "kis_point.h" -#include "kis_canvas_subject.h" -#include "kis_canvas_controller.h" -#include "kis_button_press_event.h" -#include "kis_button_release_event.h" -#include "kis_move_event.h" -#include "kis_canvas.h" -#include "kis_canvas_painter.h" -#include "kis_cursor.h" -#include "kis_tool_controller.h" -#include "kis_vec.h" -#include "kis_selection.h" -#include "kis_selection_options.h" -#include "kis_selected_transaction.h" -#include "kis_paintop_registry.h" - -#include "kis_curve_framework.h" -#include "kis_tool_curve.h" - -TQRect KisToolCurve::pivotRect (const TQPoint& pos) -{ - return TQRect (pos-TQPoint(4,4),pos+TQPoint(4,4)); -} - -TQRect KisToolCurve::selectedPivotRect (const TQPoint& pos) -{ - return TQRect (pos-TQPoint(5,5),pos+TQPoint(5,5)); -} - -KisToolCurve::KisToolCurve(const TQString& UIName) - : super(UIName) -{ - m_UIName = UIName; - m_currentImage = 0; - m_optWidget = 0; - - m_curve = 0; - - m_dragging = false; - m_draggingCursor = false; - m_drawPivots = true; - m_drawingPen = TQPen(TQt::white, 0, TQt::SolidLine); - m_pivotPen = TQPen(TQt::gray, 0, TQt::SolidLine); - m_selectedPivotPen = TQPen(TQt::yellow, 0, TQt::SolidLine); - m_pivotRounding = m_selectedPivotRounding = 55; - - m_actionOptions = NOOPTIONS; - m_supportMinimalDraw = true; - m_selectAction = SELECTION_ADD; -} - -KisToolCurve::~KisToolCurve() -{ - -} - -void KisToolCurve::update (KisCanvasSubject *subject) -{ - super::update(subject); - if (m_subject) - m_currentImage = m_subject->currentImg(); -} - -void KisToolCurve::deactivate() -{ - draw(false); - if (m_curve) { - m_curve->clear(); - m_curve->endActionOptions(); - } - - m_actionOptions = NOOPTIONS; - m_dragging = false; - m_drawPivots = true; -} - -void KisToolCurve::buttonPress(KisButtonPressEvent *event) -{ - updateOptions(event->state()); - if (!m_currentImage) - return; - if (event->button() == Qt::LeftButton) { - m_dragging = true; - m_currentPoint = event->pos(); - PointPair temp = pointUnderMouse (m_subject->canvasController()->windowToView(event->pos().toTQPoint())); - if (temp.first == m_curve->end() && !(m_actionOptions)) { - draw(true, true); - m_curve->selectAll(false); - draw(true, true); - draw(m_curve->end()); - m_previous = m_curve->find(m_curve->last()); - m_current = m_curve->pushPivot(event->pos()); - if (m_curve->pivots().count() > 1) - m_curve->calculateCurve(m_previous,m_current,m_current); - draw(m_current); - } else { - draw(true, true); - if (temp.second) - m_current = m_curve->selectPivot(temp.first); - else - m_current = selectByMouse(temp.first); - - if (!(*m_current).isSelected()) - m_dragging = false; - draw(true, true); - } - } -} - -void KisToolCurve::keyPress(TQKeyEvent *event) -{ - if (event->key() == TQt::Key_Return) { - m_dragging = false; - commitCurve(); - } else - if (event->key() == TQt::Key_Escape) { - m_dragging = false; - draw(false); - m_curve->clear(); - } else - if (event->key() == TQt::Key_Delete) { - draw(false); - m_dragging = false; - m_curve->deleteSelected(); - m_current = m_curve->find(m_curve->last()); - m_previous = m_curve->selectPivot(m_current); - draw(false); - } -} - -void KisToolCurve::keyRelease(TQKeyEvent *) -{ - -} - -void KisToolCurve::buttonRelease(KisButtonReleaseEvent *event) -{ - updateOptions(event->state()); - m_dragging = false; -} - -void KisToolCurve::doubleClick(KisDoubleClickEvent *) -{ - commitCurve(); -} - -void KisToolCurve::move(KisMoveEvent *event) -{ - updateOptions(event->state()); - PointPair temp = pointUnderMouse(m_subject->canvasController()->windowToView(event->pos().toTQPoint())); - if (temp.first == m_curve->end() && !m_dragging) { - if (m_draggingCursor) { - setCursor(KisCursor::load(m_cursor, 6, 6)); - m_draggingCursor = false; - } - } else { - setCursor(KisCursor::load("tool_curve_dragging.png", 6, 6)); - m_draggingCursor = true; - } - if (m_dragging) { - draw(); - KisPoint trans = event->pos() - m_currentPoint; - m_curve->moveSelected(trans); - m_currentPoint = event->pos(); - draw(); - } -} - -double pointToSegmentDistance(const KisPoint& p, const KisPoint& l0, const KisPoint& l1) -{ - double lineLength = sqrt((l1.x() - l0.x()) * (l1.x() - l0.x()) + (l1.y() - l0.y()) * (l1.y() - l0.y())); - double distance = 0; - KisVector2D v0(l0), v1(l1), v(p), seg(v0-v1), dist0(v0-p), dist1(v1-p); - - if (seg.length() < dist0.length() || - seg.length() < dist1.length()) // the point doesn't perpendicolarly intersecate the segment (or it's too far from the segment) - return (double)INT_MAX; - - if (lineLength > DBL_EPSILON) { - distance = ((l0.y() - l1.y()) * p.x() + (l1.x() - l0.x()) * p.y() + l0.x() * l1.y() - l1.x() * l0.y()) / lineLength; - distance = fabs(distance); - } - - return distance; -} - -PointPair KisToolCurve::pointUnderMouse(const TQPoint& pos) -{ - KisCurve::iterator it, next; - TQPoint pos1, pos2; - it = handleUnderMouse(pos); - if (it != m_curve->end()) - return PointPair(it,true); - - for (it = m_curve->begin(); it != m_curve->end(); it++) { - next = it.next(); - if (next == m_curve->end() || it == m_curve->end()) - return PointPair(m_curve->end(),false); - if ((*it).hint() > LINEHINT || (*next).hint() > LINEHINT) - continue; - pos1 = m_subject->canvasController()->windowToView((*it).point().toTQPoint()); - pos2 = m_subject->canvasController()->windowToView((*next).point().toTQPoint()); - if (pos1 == pos2) - continue; - if (pointToSegmentDistance(pos,pos1,pos2) <= MAXDISTANCE) - break; - } - - return PointPair(it,false); -} - -KisCurve::iterator KisToolCurve::handleUnderMouse(const TQPoint& pos) -{ - KisCurve pivs = m_curve->pivots(), inHandle; - KisCurve::iterator it; - for (it = pivs.begin(); it != pivs.end(); it++) { - if (pivotRect(m_subject->canvasController()->windowToView((*it).point().toTQPoint())).contains(pos)) - inHandle.pushPoint((*it)); - } - if (inHandle.isEmpty()) - return m_curve->end(); - return m_curve->find(inHandle.last()); -} - -KisCurve::iterator KisToolCurve::selectByMouse(KisCurve::iterator it) -{ - KisCurve::iterator prevPivot, nextPivot; - - if ((*it).isPivot()) - prevPivot = it; - else - prevPivot = it.previousPivot(); - nextPivot = it.nextPivot(); - - m_curve->selectPivot(prevPivot); - (*nextPivot).setSelected(true); - - return prevPivot; -} - -int KisToolCurve::updateOptions(int key) -{ - int options = 0x0000; - - if (key & TQt::ControlButton) - options |= CONTROLOPTION; - - if (key & TQt::ShiftButton) - options |= SHIFTOPTION; - - if (key & TQt::AltButton) - options |= ALTOPTION; - - if (options != m_actionOptions) { - draw(false); - m_actionOptions = options; - m_curve->setActionOptions(m_actionOptions); - draw(false); - } - - return m_actionOptions; -} - -void KisToolCurve::draw(bool m, bool o) -{ - draw(KisCurve::iterator(), o, m); -} - -void KisToolCurve::draw(KisCurve::iterator inf, bool pivotonly, bool minimal) -{ - if (m_curve->isEmpty()) - return; - KisCanvasPainter *gc; - KisCanvasController *controller; - KisCanvas *canvas; - if (m_subject && m_currentImage) { - controller = m_subject->canvasController(); - canvas = controller->kiscanvas(); - gc = new KisCanvasPainter(canvas); - } else - return; - - gc->setPen(m_drawingPen); - gc->setRasterOp(TQt::XorROP); - - KisCurve::iterator it, finish; - - if (minimal && m_supportMinimalDraw) { - if (pivotonly) { - KisCurve p = m_curve->pivots(); - for (KisCurve::iterator i = p.begin(); i != p.end(); i++) - drawPivotHandle (*gc, i); - delete gc; - return; - } - if (inf.target() != 0) { - if (inf != m_curve->end()) { - it = inf.previousPivot(); - finish = inf.nextPivot(); - } else { - it = --m_curve->end(); - finish = m_curve->end(); - } - } else { - KisCurve sel = m_curve->selectedPivots(); - if (sel.isEmpty()) { - delete gc; - return; - } - for (KisCurve::iterator i = sel.begin(); i != sel.end(); i++) { - it = m_curve->find(*i).previousPivot(); - finish = m_curve->find(*i).nextPivot(); - if ((*finish).isSelected()) - finish = finish.previousPivot(); - while (it != finish) { - if ((*it).isPivot()) - drawPivotHandle (*gc, it); - it = drawPoint (*gc, it); - } - } - delete gc; - return; - } - } else { - it = m_curve->begin(); - finish = m_curve->end(); - } - while (it != finish) { - if ((*it).isPivot()) - drawPivotHandle (*gc, it); - it = drawPoint (*gc, it); - } - - delete gc; -} - -KisCurve::iterator KisToolCurve::drawPoint(KisCanvasPainter& gc, KisCurve::iterator point) -{ - KisCanvasController *controller = m_subject->canvasController(); - - TQPoint pos1, pos2; - pos1 = controller->windowToView((*point).point().toTQPoint()); - - switch ((*point).hint()) { - case POINTHINT: - gc.drawPoint(pos1); - point += 1; - break; - case LINEHINT: - gc.drawPoint(pos1); - if (++point != m_curve->end() && (*point).hint() <= LINEHINT) { - pos2 = controller->windowToView((*point).point().toTQPoint()); - gc.drawLine(pos1,pos2); - } - break; - default: - point += 1; - } - - return point; -} - -void KisToolCurve::drawPivotHandle(KisCanvasPainter& gc, KisCurve::iterator point) -{ - KisCanvasController *controller = m_subject->canvasController(); - - if (m_drawPivots) { - TQPoint pos = controller->windowToView((*point).point().toTQPoint()); - if ((*point).isSelected()) { - gc.setPen(m_selectedPivotPen); - gc.drawRoundRect(selectedPivotRect(pos),m_selectedPivotRounding,m_selectedPivotRounding); - } else { - gc.setPen(m_pivotPen); - gc.drawRoundRect(pivotRect(pos),m_pivotRounding,m_pivotRounding); - } - gc.setPen(m_drawingPen); - } -} - -void KisToolCurve::paint(KisCanvasPainter&) -{ - draw(false); -} - -void KisToolCurve::paint(KisCanvasPainter&, const TQRect&) -{ - draw(false); -} - -void KisToolCurve::commitCurve() -{ - if (toolType() == TOOL_SHAPE || toolType() == TOOL_FREEHAND) - paintCurve(); - else if (toolType() == TOOL_SELECT) - selectCurve(); - else - kdDebug(0) << "NO SUPPORT FOR THIS TYPE OF TOOL" << endl; - - m_curve->clear(); - m_curve->endActionOptions(); -} - -void KisToolCurve::paintCurve() -{ - KisPaintDeviceSP device = m_currentImage->activeDevice (); - if (!device) return; - - KisPainter painter (device); - if (m_currentImage->undo()) painter.beginTransaction (m_transactionMessage); - - painter.setPaintColor(m_subject->fgColor()); - painter.setBrush(m_subject->currentBrush()); - painter.setOpacity(m_opacity); - painter.setCompositeOp(m_compositeOp); - KisPaintOp * op = KisPaintOpRegistry::instance()->paintOp(m_subject->currentPaintop(), m_subject->currentPaintopSettings(), &painter); - painter.setPaintOp(op); // Painter takes ownership - -// Call paintPoint - KisCurve::iterator it = m_curve->begin(); - while (it != m_curve->end()) - it = paintPoint(painter,it); -// Finish - - device->setDirty( painter.dirtyRect() ); - notifyModified(); - - if (m_currentImage->undo()) { - m_currentImage->undoAdapter()->addCommand(painter.endTransaction()); - } - - draw(false); -} - -KisCurve::iterator KisToolCurve::paintPoint (KisPainter& painter, KisCurve::iterator point) -{ - KisCurve::iterator next = point; next+=1; - switch ((*point).hint()) { - case POINTHINT: - painter.paintAt((*point++).point(), PRESSURE_DEFAULT, 0, 0); - break; - case LINEHINT: - if (next != m_curve->end() && (*next).hint() <= LINEHINT) - painter.paintLine((*point++).point(), PRESSURE_DEFAULT, 0, 0, (*next).point(), PRESSURE_DEFAULT, 0, 0); - else - painter.paintAt((*point++).point(), PRESSURE_DEFAULT, 0, 0); - break; - default: - point += 1; - } - - return point; -} - -TQValueVector KisToolCurve::convertCurve() -{ - TQValueVector points; - - for (KisCurve::iterator i = m_curve->begin(); i != m_curve->end(); i++) - if ((*i).hint() != NOHINTS) - points.append((*i).point()); - - return points; -} - -void KisToolCurve::selectCurve() -{ - TQApplication::setOverrideCursor(KisCursor::waitCursor()); - KisPaintDeviceSP dev = m_currentImage->activeDevice(); - bool hasSelection = dev->hasSelection(); - KisSelectedTransaction *t = 0; - if (m_currentImage->undo()) t = new KisSelectedTransaction(m_transactionMessage, dev); - KisSelectionSP selection = dev->selection(); - - if (!hasSelection) { - selection->clear(); - } - - KisPainter painter(selection.data()); - - painter.setPaintColor(KisColor(TQt::black, selection->colorSpace())); - painter.setFillStyle(KisPainter::FillStyleForegroundColor); - painter.setStrokeStyle(KisPainter::StrokeStyleNone); - painter.setBrush(m_subject->currentBrush()); - painter.setOpacity(OPACITY_OPAQUE); - KisPaintOp * op = KisPaintOpRegistry::instance()->paintOp("paintbrush", 0, &painter); - painter.setPaintOp(op); // And now the painter owns the op and will destroy it. - - switch (m_selectAction) { - case SELECTION_ADD: - painter.setCompositeOp(COMPOSITE_OVER); - break; - case SELECTION_SUBTRACT: - painter.setCompositeOp(COMPOSITE_SUBTRACT); - break; - default: - break; - } - - painter.paintPolygon(convertCurve()); - - - if(hasSelection) { - TQRect dirty(painter.dirtyRect()); - dev->setDirty(dirty); - dev->emitSelectionChanged(dirty); - } else { - dev->setDirty(); - dev->emitSelectionChanged(); - } - - if (m_currentImage->undo()) - m_currentImage->undoAdapter()->addCommand(t); - - TQApplication::restoreOverrideCursor(); - - draw(false); -} - -TQWidget* KisToolCurve::createOptionWidget(TQWidget* parent) -{ - if (toolType() == TOOL_SHAPE || toolType() == TOOL_FREEHAND) - return super::createOptionWidget(parent); - else if (toolType() == TOOL_SELECT) - return createSelectionOptionWidget(parent); - else - kdDebug(0) << "NO SUPPORT FOR THIS TOOL TYPE" << endl; - return 0; -} - -void KisToolCurve::slotSetAction(int action) { - if (action >= SELECTION_ADD && action <= SELECTION_SUBTRACT) - m_selectAction =(enumSelectionMode)action; -} - -TQWidget* KisToolCurve::createSelectionOptionWidget(TQWidget* parent) -{ - m_optWidget = new KisSelectionOptions(parent, m_subject); - TQ_CHECK_PTR(m_optWidget); - m_optWidget->setCaption(m_UIName); - - connect (m_optWidget, TQT_SIGNAL(actionChanged(int)), this, TQT_SLOT(slotSetAction(int))); - - TQVBoxLayout * l = dynamic_cast(m_optWidget->layout()); - l->addItem(new TQSpacerItem(1, 1, TQSizePolicy::Fixed, TQSizePolicy::Expanding)); - - return m_optWidget; -} - -TQWidget* KisToolCurve::optionWidget() -{ - if (toolType() == TOOL_SELECT) - return m_optWidget; - else - return super::optionWidget(); -} - -#include "kis_tool_curve.moc" diff --git a/chalk/plugins/tools/tool_curves/kis_tool_curve.cpp b/chalk/plugins/tools/tool_curves/kis_tool_curve.cpp new file mode 100644 index 000000000..ea1f9a773 --- /dev/null +++ b/chalk/plugins/tools/tool_curves/kis_tool_curve.cpp @@ -0,0 +1,593 @@ +/* + * kis_tool_curve.cpp -- part of Chalk + * + * Copyright (c) 2006 Emanuele Tamponi + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "kis_global.h" +#include "kis_doc.h" +#include "kis_painter.h" +#include "kis_point.h" +#include "kis_canvas_subject.h" +#include "kis_canvas_controller.h" +#include "kis_button_press_event.h" +#include "kis_button_release_event.h" +#include "kis_move_event.h" +#include "kis_canvas.h" +#include "kis_canvas_painter.h" +#include "kis_cursor.h" +#include "kis_tool_controller.h" +#include "kis_vec.h" +#include "kis_selection.h" +#include "kis_selection_options.h" +#include "kis_selected_transaction.h" +#include "kis_paintop_registry.h" + +#include "kis_curve_framework.h" +#include "kis_tool_curve.h" + +TQRect KisToolCurve::pivotRect (const TQPoint& pos) +{ + return TQRect (pos-TQPoint(4,4),pos+TQPoint(4,4)); +} + +TQRect KisToolCurve::selectedPivotRect (const TQPoint& pos) +{ + return TQRect (pos-TQPoint(5,5),pos+TQPoint(5,5)); +} + +KisToolCurve::KisToolCurve(const TQString& UIName) + : super(UIName) +{ + m_UIName = UIName; + m_currentImage = 0; + m_optWidget = 0; + + m_curve = 0; + + m_dragging = false; + m_draggingCursor = false; + m_drawPivots = true; + m_drawingPen = TQPen(TQt::white, 0, TQt::SolidLine); + m_pivotPen = TQPen(TQt::gray, 0, TQt::SolidLine); + m_selectedPivotPen = TQPen(TQt::yellow, 0, TQt::SolidLine); + m_pivotRounding = m_selectedPivotRounding = 55; + + m_actionOptions = NOOPTIONS; + m_supportMinimalDraw = true; + m_selectAction = SELECTION_ADD; +} + +KisToolCurve::~KisToolCurve() +{ + +} + +void KisToolCurve::update (KisCanvasSubject *subject) +{ + super::update(subject); + if (m_subject) + m_currentImage = m_subject->currentImg(); +} + +void KisToolCurve::deactivate() +{ + draw(false); + if (m_curve) { + m_curve->clear(); + m_curve->endActionOptions(); + } + + m_actionOptions = NOOPTIONS; + m_dragging = false; + m_drawPivots = true; +} + +void KisToolCurve::buttonPress(KisButtonPressEvent *event) +{ + updateOptions(event->state()); + if (!m_currentImage) + return; + if (event->button() == Qt::LeftButton) { + m_dragging = true; + m_currentPoint = event->pos(); + PointPair temp = pointUnderMouse (m_subject->canvasController()->windowToView(event->pos().toTQPoint())); + if (temp.first == m_curve->end() && !(m_actionOptions)) { + draw(true, true); + m_curve->selectAll(false); + draw(true, true); + draw(m_curve->end()); + m_previous = m_curve->find(m_curve->last()); + m_current = m_curve->pushPivot(event->pos()); + if (m_curve->pivots().count() > 1) + m_curve->calculateCurve(m_previous,m_current,m_current); + draw(m_current); + } else { + draw(true, true); + if (temp.second) + m_current = m_curve->selectPivot(temp.first); + else + m_current = selectByMouse(temp.first); + + if (!(*m_current).isSelected()) + m_dragging = false; + draw(true, true); + } + } +} + +void KisToolCurve::keyPress(TQKeyEvent *event) +{ + if (event->key() == TQt::Key_Return) { + m_dragging = false; + commitCurve(); + } else + if (event->key() == TQt::Key_Escape) { + m_dragging = false; + draw(false); + m_curve->clear(); + } else + if (event->key() == TQt::Key_Delete) { + draw(false); + m_dragging = false; + m_curve->deleteSelected(); + m_current = m_curve->find(m_curve->last()); + m_previous = m_curve->selectPivot(m_current); + draw(false); + } +} + +void KisToolCurve::keyRelease(TQKeyEvent *) +{ + +} + +void KisToolCurve::buttonRelease(KisButtonReleaseEvent *event) +{ + updateOptions(event->state()); + m_dragging = false; +} + +void KisToolCurve::doubleClick(KisDoubleClickEvent *) +{ + commitCurve(); +} + +void KisToolCurve::move(KisMoveEvent *event) +{ + updateOptions(event->state()); + PointPair temp = pointUnderMouse(m_subject->canvasController()->windowToView(event->pos().toTQPoint())); + if (temp.first == m_curve->end() && !m_dragging) { + if (m_draggingCursor) { + setCursor(KisCursor::load(m_cursor, 6, 6)); + m_draggingCursor = false; + } + } else { + setCursor(KisCursor::load("tool_curve_dragging.png", 6, 6)); + m_draggingCursor = true; + } + if (m_dragging) { + draw(); + KisPoint trans = event->pos() - m_currentPoint; + m_curve->moveSelected(trans); + m_currentPoint = event->pos(); + draw(); + } +} + +double pointToSegmentDistance(const KisPoint& p, const KisPoint& l0, const KisPoint& l1) +{ + double lineLength = sqrt((l1.x() - l0.x()) * (l1.x() - l0.x()) + (l1.y() - l0.y()) * (l1.y() - l0.y())); + double distance = 0; + KisVector2D v0(l0), v1(l1), v(p), seg(v0-v1), dist0(v0-p), dist1(v1-p); + + if (seg.length() < dist0.length() || + seg.length() < dist1.length()) // the point doesn't perpendicolarly intersecate the segment (or it's too far from the segment) + return (double)INT_MAX; + + if (lineLength > DBL_EPSILON) { + distance = ((l0.y() - l1.y()) * p.x() + (l1.x() - l0.x()) * p.y() + l0.x() * l1.y() - l1.x() * l0.y()) / lineLength; + distance = fabs(distance); + } + + return distance; +} + +PointPair KisToolCurve::pointUnderMouse(const TQPoint& pos) +{ + KisCurve::iterator it, next; + TQPoint pos1, pos2; + it = handleUnderMouse(pos); + if (it != m_curve->end()) + return PointPair(it,true); + + for (it = m_curve->begin(); it != m_curve->end(); it++) { + next = it.next(); + if (next == m_curve->end() || it == m_curve->end()) + return PointPair(m_curve->end(),false); + if ((*it).hint() > LINEHINT || (*next).hint() > LINEHINT) + continue; + pos1 = m_subject->canvasController()->windowToView((*it).point().toTQPoint()); + pos2 = m_subject->canvasController()->windowToView((*next).point().toTQPoint()); + if (pos1 == pos2) + continue; + if (pointToSegmentDistance(pos,pos1,pos2) <= MAXDISTANCE) + break; + } + + return PointPair(it,false); +} + +KisCurve::iterator KisToolCurve::handleUnderMouse(const TQPoint& pos) +{ + KisCurve pivs = m_curve->pivots(), inHandle; + KisCurve::iterator it; + for (it = pivs.begin(); it != pivs.end(); it++) { + if (pivotRect(m_subject->canvasController()->windowToView((*it).point().toTQPoint())).contains(pos)) + inHandle.pushPoint((*it)); + } + if (inHandle.isEmpty()) + return m_curve->end(); + return m_curve->find(inHandle.last()); +} + +KisCurve::iterator KisToolCurve::selectByMouse(KisCurve::iterator it) +{ + KisCurve::iterator prevPivot, nextPivot; + + if ((*it).isPivot()) + prevPivot = it; + else + prevPivot = it.previousPivot(); + nextPivot = it.nextPivot(); + + m_curve->selectPivot(prevPivot); + (*nextPivot).setSelected(true); + + return prevPivot; +} + +int KisToolCurve::updateOptions(int key) +{ + int options = 0x0000; + + if (key & TQt::ControlButton) + options |= CONTROLOPTION; + + if (key & TQt::ShiftButton) + options |= SHIFTOPTION; + + if (key & TQt::AltButton) + options |= ALTOPTION; + + if (options != m_actionOptions) { + draw(false); + m_actionOptions = options; + m_curve->setActionOptions(m_actionOptions); + draw(false); + } + + return m_actionOptions; +} + +void KisToolCurve::draw(bool m, bool o) +{ + draw(KisCurve::iterator(), o, m); +} + +void KisToolCurve::draw(KisCurve::iterator inf, bool pivotonly, bool minimal) +{ + if (m_curve->isEmpty()) + return; + KisCanvasPainter *gc; + KisCanvasController *controller; + KisCanvas *canvas; + if (m_subject && m_currentImage) { + controller = m_subject->canvasController(); + canvas = controller->kiscanvas(); + gc = new KisCanvasPainter(canvas); + } else + return; + + gc->setPen(m_drawingPen); + gc->setRasterOp(TQt::XorROP); + + KisCurve::iterator it, finish; + + if (minimal && m_supportMinimalDraw) { + if (pivotonly) { + KisCurve p = m_curve->pivots(); + for (KisCurve::iterator i = p.begin(); i != p.end(); i++) + drawPivotHandle (*gc, i); + delete gc; + return; + } + if (inf.target() != 0) { + if (inf != m_curve->end()) { + it = inf.previousPivot(); + finish = inf.nextPivot(); + } else { + it = --m_curve->end(); + finish = m_curve->end(); + } + } else { + KisCurve sel = m_curve->selectedPivots(); + if (sel.isEmpty()) { + delete gc; + return; + } + for (KisCurve::iterator i = sel.begin(); i != sel.end(); i++) { + it = m_curve->find(*i).previousPivot(); + finish = m_curve->find(*i).nextPivot(); + if ((*finish).isSelected()) + finish = finish.previousPivot(); + while (it != finish) { + if ((*it).isPivot()) + drawPivotHandle (*gc, it); + it = drawPoint (*gc, it); + } + } + delete gc; + return; + } + } else { + it = m_curve->begin(); + finish = m_curve->end(); + } + while (it != finish) { + if ((*it).isPivot()) + drawPivotHandle (*gc, it); + it = drawPoint (*gc, it); + } + + delete gc; +} + +KisCurve::iterator KisToolCurve::drawPoint(KisCanvasPainter& gc, KisCurve::iterator point) +{ + KisCanvasController *controller = m_subject->canvasController(); + + TQPoint pos1, pos2; + pos1 = controller->windowToView((*point).point().toTQPoint()); + + switch ((*point).hint()) { + case POINTHINT: + gc.drawPoint(pos1); + point += 1; + break; + case LINEHINT: + gc.drawPoint(pos1); + if (++point != m_curve->end() && (*point).hint() <= LINEHINT) { + pos2 = controller->windowToView((*point).point().toTQPoint()); + gc.drawLine(pos1,pos2); + } + break; + default: + point += 1; + } + + return point; +} + +void KisToolCurve::drawPivotHandle(KisCanvasPainter& gc, KisCurve::iterator point) +{ + KisCanvasController *controller = m_subject->canvasController(); + + if (m_drawPivots) { + TQPoint pos = controller->windowToView((*point).point().toTQPoint()); + if ((*point).isSelected()) { + gc.setPen(m_selectedPivotPen); + gc.drawRoundRect(selectedPivotRect(pos),m_selectedPivotRounding,m_selectedPivotRounding); + } else { + gc.setPen(m_pivotPen); + gc.drawRoundRect(pivotRect(pos),m_pivotRounding,m_pivotRounding); + } + gc.setPen(m_drawingPen); + } +} + +void KisToolCurve::paint(KisCanvasPainter&) +{ + draw(false); +} + +void KisToolCurve::paint(KisCanvasPainter&, const TQRect&) +{ + draw(false); +} + +void KisToolCurve::commitCurve() +{ + if (toolType() == TOOL_SHAPE || toolType() == TOOL_FREEHAND) + paintCurve(); + else if (toolType() == TOOL_SELECT) + selectCurve(); + else + kdDebug(0) << "NO SUPPORT FOR THIS TYPE OF TOOL" << endl; + + m_curve->clear(); + m_curve->endActionOptions(); +} + +void KisToolCurve::paintCurve() +{ + KisPaintDeviceSP device = m_currentImage->activeDevice (); + if (!device) return; + + KisPainter painter (device); + if (m_currentImage->undo()) painter.beginTransaction (m_transactionMessage); + + painter.setPaintColor(m_subject->fgColor()); + painter.setBrush(m_subject->currentBrush()); + painter.setOpacity(m_opacity); + painter.setCompositeOp(m_compositeOp); + KisPaintOp * op = KisPaintOpRegistry::instance()->paintOp(m_subject->currentPaintop(), m_subject->currentPaintopSettings(), &painter); + painter.setPaintOp(op); // Painter takes ownership + +// Call paintPoint + KisCurve::iterator it = m_curve->begin(); + while (it != m_curve->end()) + it = paintPoint(painter,it); +// Finish + + device->setDirty( painter.dirtyRect() ); + notifyModified(); + + if (m_currentImage->undo()) { + m_currentImage->undoAdapter()->addCommand(painter.endTransaction()); + } + + draw(false); +} + +KisCurve::iterator KisToolCurve::paintPoint (KisPainter& painter, KisCurve::iterator point) +{ + KisCurve::iterator next = point; next+=1; + switch ((*point).hint()) { + case POINTHINT: + painter.paintAt((*point++).point(), PRESSURE_DEFAULT, 0, 0); + break; + case LINEHINT: + if (next != m_curve->end() && (*next).hint() <= LINEHINT) + painter.paintLine((*point++).point(), PRESSURE_DEFAULT, 0, 0, (*next).point(), PRESSURE_DEFAULT, 0, 0); + else + painter.paintAt((*point++).point(), PRESSURE_DEFAULT, 0, 0); + break; + default: + point += 1; + } + + return point; +} + +TQValueVector KisToolCurve::convertCurve() +{ + TQValueVector points; + + for (KisCurve::iterator i = m_curve->begin(); i != m_curve->end(); i++) + if ((*i).hint() != NOHINTS) + points.append((*i).point()); + + return points; +} + +void KisToolCurve::selectCurve() +{ + TQApplication::setOverrideCursor(KisCursor::waitCursor()); + KisPaintDeviceSP dev = m_currentImage->activeDevice(); + bool hasSelection = dev->hasSelection(); + KisSelectedTransaction *t = 0; + if (m_currentImage->undo()) t = new KisSelectedTransaction(m_transactionMessage, dev); + KisSelectionSP selection = dev->selection(); + + if (!hasSelection) { + selection->clear(); + } + + KisPainter painter(selection.data()); + + painter.setPaintColor(KisColor(TQt::black, selection->colorSpace())); + painter.setFillStyle(KisPainter::FillStyleForegroundColor); + painter.setStrokeStyle(KisPainter::StrokeStyleNone); + painter.setBrush(m_subject->currentBrush()); + painter.setOpacity(OPACITY_OPAQUE); + KisPaintOp * op = KisPaintOpRegistry::instance()->paintOp("paintbrush", 0, &painter); + painter.setPaintOp(op); // And now the painter owns the op and will destroy it. + + switch (m_selectAction) { + case SELECTION_ADD: + painter.setCompositeOp(COMPOSITE_OVER); + break; + case SELECTION_SUBTRACT: + painter.setCompositeOp(COMPOSITE_SUBTRACT); + break; + default: + break; + } + + painter.paintPolygon(convertCurve()); + + + if(hasSelection) { + TQRect dirty(painter.dirtyRect()); + dev->setDirty(dirty); + dev->emitSelectionChanged(dirty); + } else { + dev->setDirty(); + dev->emitSelectionChanged(); + } + + if (m_currentImage->undo()) + m_currentImage->undoAdapter()->addCommand(t); + + TQApplication::restoreOverrideCursor(); + + draw(false); +} + +TQWidget* KisToolCurve::createOptionWidget(TQWidget* parent) +{ + if (toolType() == TOOL_SHAPE || toolType() == TOOL_FREEHAND) + return super::createOptionWidget(parent); + else if (toolType() == TOOL_SELECT) + return createSelectionOptionWidget(parent); + else + kdDebug(0) << "NO SUPPORT FOR THIS TOOL TYPE" << endl; + return 0; +} + +void KisToolCurve::slotSetAction(int action) { + if (action >= SELECTION_ADD && action <= SELECTION_SUBTRACT) + m_selectAction =(enumSelectionMode)action; +} + +TQWidget* KisToolCurve::createSelectionOptionWidget(TQWidget* parent) +{ + m_optWidget = new KisSelectionOptions(parent, m_subject); + TQ_CHECK_PTR(m_optWidget); + m_optWidget->setCaption(m_UIName); + + connect (m_optWidget, TQT_SIGNAL(actionChanged(int)), this, TQT_SLOT(slotSetAction(int))); + + TQVBoxLayout * l = dynamic_cast(m_optWidget->layout()); + l->addItem(new TQSpacerItem(1, 1, TQSizePolicy::Fixed, TQSizePolicy::Expanding)); + + return m_optWidget; +} + +TQWidget* KisToolCurve::optionWidget() +{ + if (toolType() == TOOL_SELECT) + return m_optWidget; + else + return super::optionWidget(); +} + +#include "kis_tool_curve.moc" diff --git a/chalk/plugins/tools/tool_curves/kis_tool_example.cc b/chalk/plugins/tools/tool_curves/kis_tool_example.cc deleted file mode 100644 index 75e3da2be..000000000 --- a/chalk/plugins/tools/tool_curves/kis_tool_example.cc +++ /dev/null @@ -1,108 +0,0 @@ -/* - * kis_tool_example.cc -- part of Chalk - * - * Copyright (c) 2006 Emanuele Tamponi - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - - -#include -#include -#include - -#include -#include -#include -#include -#include - -#include "kis_global.h" -#include "kis_doc.h" -#include "kis_painter.h" -#include "kis_point.h" -#include "kis_canvas_subject.h" -#include "kis_canvas_controller.h" -#include "kis_button_press_event.h" -#include "kis_button_release_event.h" -#include "kis_move_event.h" -#include "kis_paintop_registry.h" -#include "kis_canvas.h" -#include "kis_canvas_painter.h" -#include "kis_cursor.h" -#include "kis_vec.h" - -#include "kis_curve_framework.h" - -#include "kis_tool_example.h" - - -class KisCurveExample : public KisCurve { - - typedef KisCurve super; - -public: - - KisCurveExample() : super() {} - - ~KisCurveExample() {} - - virtual iterator pushPivot (const KisPoint&); - -}; - -KisCurve::iterator KisCurveExample::pushPivot (const KisPoint& point) -{ - return selectPivot(iterator(*this,m_curve.append(CurvePoint(point,true,false,LINEHINT))), true); -} - -KisToolExample::KisToolExample() - : super(i18n("Tool for Curves - Example")) -{ - setName("tool_example"); - m_cursor = "tool_example_cursor.png"; - setCursor(KisCursor::load(m_cursor, 6, 6)); - - m_curve = new KisCurveExample; -} - -KisToolExample::~KisToolExample() -{ - -} - -void KisToolExample::setup(TDEActionCollection *collection) -{ - m_action = static_cast(collection->action(name())); - - if (m_action == 0) { - TDEShortcut shortcut(TQt::Key_Plus); - shortcut.append(TDEShortcut(TQt::Key_F9)); - m_action = new TDERadioAction(i18n("&Example"), - "tool_example", - shortcut, - this, - TQT_SLOT(activate()), - collection, - name()); - TQ_CHECK_PTR(m_action); - - m_action->setToolTip(i18n("This is a test tool for the Curve Framework.")); - m_action->setExclusiveGroup("tools"); - m_ownAction = true; - } -} - -#include "kis_tool_example.moc" diff --git a/chalk/plugins/tools/tool_curves/kis_tool_example.cpp b/chalk/plugins/tools/tool_curves/kis_tool_example.cpp new file mode 100644 index 000000000..a21bb8089 --- /dev/null +++ b/chalk/plugins/tools/tool_curves/kis_tool_example.cpp @@ -0,0 +1,108 @@ +/* + * kis_tool_example.cpp -- part of Chalk + * + * Copyright (c) 2006 Emanuele Tamponi + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "kis_global.h" +#include "kis_doc.h" +#include "kis_painter.h" +#include "kis_point.h" +#include "kis_canvas_subject.h" +#include "kis_canvas_controller.h" +#include "kis_button_press_event.h" +#include "kis_button_release_event.h" +#include "kis_move_event.h" +#include "kis_paintop_registry.h" +#include "kis_canvas.h" +#include "kis_canvas_painter.h" +#include "kis_cursor.h" +#include "kis_vec.h" + +#include "kis_curve_framework.h" + +#include "kis_tool_example.h" + + +class KisCurveExample : public KisCurve { + + typedef KisCurve super; + +public: + + KisCurveExample() : super() {} + + ~KisCurveExample() {} + + virtual iterator pushPivot (const KisPoint&); + +}; + +KisCurve::iterator KisCurveExample::pushPivot (const KisPoint& point) +{ + return selectPivot(iterator(*this,m_curve.append(CurvePoint(point,true,false,LINEHINT))), true); +} + +KisToolExample::KisToolExample() + : super(i18n("Tool for Curves - Example")) +{ + setName("tool_example"); + m_cursor = "tool_example_cursor.png"; + setCursor(KisCursor::load(m_cursor, 6, 6)); + + m_curve = new KisCurveExample; +} + +KisToolExample::~KisToolExample() +{ + +} + +void KisToolExample::setup(TDEActionCollection *collection) +{ + m_action = static_cast(collection->action(name())); + + if (m_action == 0) { + TDEShortcut shortcut(TQt::Key_Plus); + shortcut.append(TDEShortcut(TQt::Key_F9)); + m_action = new TDERadioAction(i18n("&Example"), + "tool_example", + shortcut, + this, + TQT_SLOT(activate()), + collection, + name()); + TQ_CHECK_PTR(m_action); + + m_action->setToolTip(i18n("This is a test tool for the Curve Framework.")); + m_action->setExclusiveGroup("tools"); + m_ownAction = true; + } +} + +#include "kis_tool_example.moc" diff --git a/chalk/plugins/tools/tool_curves/kis_tool_moutline.cc b/chalk/plugins/tools/tool_curves/kis_tool_moutline.cc deleted file mode 100644 index 178ff278f..000000000 --- a/chalk/plugins/tools/tool_curves/kis_tool_moutline.cc +++ /dev/null @@ -1,809 +0,0 @@ -/* - * kis_tool_moutline.cc -- part of Chalk - * - * Copyright (c) 2006 Emanuele Tamponi - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include -#include - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include "kis_global.h" -#include "kis_iterators_pixel.h" -#include "kis_colorspace.h" -#include "kis_channelinfo.h" -#include "kis_doc.h" -#include "kis_painter.h" -#include "kis_point.h" -#include "kis_canvas_subject.h" -#include "kis_canvas_controller.h" -#include "kis_button_press_event.h" -#include "kis_button_release_event.h" -#include "kis_move_event.h" -#include "kis_canvas.h" -#include "kis_canvas_painter.h" -#include "kis_cursor.h" -#include "kis_tool_controller.h" -#include "kis_vec.h" -#include "kis_selection.h" -#include "kis_selection_options.h" -#include "kis_selected_transaction.h" -#include "kis_paintop_registry.h" -#include "kis_convolution_painter.h" - -#include "kis_tool_moutline.h" - -using namespace std; - -#define RMS(a, b) (sqrt ((a) * (a) + (b) * (b))) -#define ROUND(x) ((int) ((x) + 0.5)) - -const int NOEDGE = 0x0000; - -const int ORTHOGONAL_COST = 10; // 1*10 -const int DIAGONAL_COST = 14; // sqrt(2)*10 -const int MALUS = 20; // This applies to NOEDGE nodes - -const int DEFAULTDIST = 40; // Default distance between two automatic pivots -const int MAXDIST = 55; // Max distance -const int MINDIST = 15; -const int PAGESTEP = 5; - -class Node { - - TQPoint m_pos; - int m_gCost; - int m_hCost; - int m_tCost; - bool m_malus; - TQPoint m_parent; - -public: - - Node() - { - m_pos = m_parent = TQPoint(-1,-1); - m_gCost = m_hCost = m_tCost = 0; - m_malus = false; - } - - Node(const Node& node) - { - m_pos = node.pos(); - m_gCost = node.gCost(); - m_hCost = node.hCost(); - m_tCost = node.tCost(); - m_malus = node.malus(); - m_parent = node.parent(); - } - - Node(const TQPoint& parent, const TQPoint& pos, int g, int h, bool malus) - : m_pos(pos), m_hCost(h), m_malus(malus) - { - setGCost(g); - m_parent = parent; - } - ~Node () - { - } - - int gCost () const {return m_gCost;} - int hCost () const {return m_hCost;} - int tCost () const {return m_tCost;} - bool malus () const {return m_malus;} - TQPoint pos () const {return m_pos;} - int col () const {return m_pos.x();} - int row () const {return m_pos.y();} - TQPoint parent () const {return m_parent;} - - void setGCost (int g) - { - m_gCost = g+(m_malus?MALUS:0); - m_tCost = m_gCost+m_hCost; - } - void setHCost (int h) - { - m_hCost = h; - m_tCost = m_gCost+m_hCost; - } - void setPos (const TQPoint& pos) - { - m_pos = pos; - } - void setMalus (bool malus) - { - m_malus = malus; - } - void clear () - { - m_pos = TQPoint(-1,-1); - } - - bool operator== (const Node& n2) const - { - return m_pos == n2.pos(); - } - bool operator!= (const Node& n2) const - { - return m_pos != n2.pos(); - } - bool operator== (const TQPoint& n2) const - { - return m_pos == n2; - } - bool operator!= (const TQPoint& n2) const - { - return m_pos != n2; - } - bool operator< (const Node& n2) const - { - return m_tCost < n2.tCost(); - } - bool operator> (const Node& n2) const - { - return m_tCost > n2.tCost(); - } - - TQValueList getNeighbor(const GrayMatrix& src, const Node& end) - { - TQPoint tmpdist; - TQValueList temp; - int dcol, drow; - int g, h; - bool malus; - int x[8] = { 1, 1, 0,-1,-1,-1, 0, 1}, - y[8] = { 0,-1,-1,-1, 0, 1, 1, 1}; - - for (int i = 0; i < 8; i++) { - dcol = m_pos.x() + x[i]; - drow = m_pos.y() + y[i]; - tmpdist = TQPoint(dcol,drow) - end.pos(); - // I use src[0] here because all cols have same number of rows - if (dcol == (int)src.count() || dcol < 0 || - drow == (int)src[0].count() || drow < 0) - continue; - if (src[dcol][drow]) - malus = false; - else - malus = true; - if (i%2) - g = m_gCost + DIAGONAL_COST; - else - g = m_gCost + ORTHOGONAL_COST; - h = ORTHOGONAL_COST * (abs(tmpdist.x()) + abs(tmpdist.y())); - temp.append(Node(m_pos,TQPoint(dcol,drow),g,h,malus)); - } - return temp; - } - -}; - -KisKernelSP createKernel( TQ_INT32 i0, TQ_INT32 i1, TQ_INT32 i2, - TQ_INT32 i3, TQ_INT32 i4, TQ_INT32 i5, - TQ_INT32 i6, TQ_INT32 i7, TQ_INT32 i8, - TQ_INT32 factor, TQ_INT32 offset ) -{ - KisKernelSP kernel = new KisKernel(); - kernel->width = 3; - kernel->height = 3; - - kernel->factor = factor; - kernel->offset = offset; - - kernel->data = new TQ_INT32[9]; - kernel->data[0] = i0; - kernel->data[1] = i1; - kernel->data[2] = i2; - kernel->data[3] = i3; - kernel->data[4] = i4; - kernel->data[5] = i5; - kernel->data[6] = i6; - kernel->data[7] = i7; - kernel->data[8] = i8; - - return kernel; -} - -KisCurveMagnetic::KisCurveMagnetic (KisToolMagnetic *parent) - : m_parent(parent) -{ - m_standardkeepselected = false; -} - -KisCurveMagnetic::~KisCurveMagnetic () -{ - -} - -KisCurve::iterator KisCurveMagnetic::addPivot (KisCurve::iterator it, const KisPoint& point) -{ - return iterator(*this,m_curve.insert(it.position(), CurvePoint(point,true,false,LINEHINT))); -} - -KisCurve::iterator KisCurveMagnetic::pushPivot (const KisPoint& point) -{ - iterator it; - - it = pushPoint(point,true,false,LINEHINT); -// if (count() == 1 && !m_parent->editingMode()) -// addPoint(it,point,true,false,LINEHINT); - - return selectPivot(it); -} - -void KisCurveMagnetic::calculateCurve (KisCurve::iterator p1, KisCurve::iterator p2, KisCurve::iterator it) -{ - if (p1 == m_curve.end() || p2 == m_curve.end()) // It happens sometimes, for example on the first click - return; - if (m_parent->editingMode()) - return; - TQPoint start = (*p1).point().roundTQPoint(); - TQPoint end = (*p2).point().roundTQPoint(); - TQRect rc = TQRect(start,end).normalize(); - rc.setTopLeft(rc.topLeft()+TQPoint(-8,-8)); // Enlarge the view, so problems with gaussian blur can be removed - rc.setBottomRight(rc.bottomRight()+TQPoint(8,8)); // and we are able to find paths that go beyond the rect. - - KisPaintDeviceSP src = m_parent->m_currentImage->activeDevice(); - GrayMatrix dst = GrayMatrix(rc.width(),GrayCol(rc.height())); - - detectEdges (rc, src, dst); - reduceMatrix (rc, dst, 3, 3, 3, 3); - - Node startNode, endNode; - multiset openSet; - NodeMatrix openMatrix = NodeMatrix(rc.width(),NodeCol(rc.height())); - NodeMatrix closedMatrix = NodeMatrix(rc.width(),NodeCol(rc.height())); - - TQPoint tl(rc.topLeft().x(),rc.topLeft().y()); - start -= tl; // Relative to the matrix - end -= tl; // Relative to the matrix - - findEdge (start.x(), start.y(), dst, startNode); - openMatrix[startNode.col()][startNode.row()] = *openSet.insert(startNode); - endNode.setPos(end); - - while (!openSet.empty()) { - Node current = *openSet.begin(); - - openSet.erase(openSet.begin()); - openMatrix[current.col()][current.row()].clear(); - - TQValueList successors = current.getNeighbor(dst,endNode); - for (TQValueList::iterator i = successors.begin(); i != successors.end(); i++) { - int col = (*i).col(); - int row = (*i).row(); - if ((*i) == endNode) { - while (current.parent() != TQPoint(-1,-1)) { - it = addPoint(it,KisPoint(tl+current.pos()),false,false,LINEHINT); - current = closedMatrix[current.parent().x()][current.parent().y()]; - } - return; - } - Node *openNode = &openMatrix[col][row]; - if (*openNode != TQPoint(-1,-1)) { - if (*i > *openNode) - continue; - else { - openSet.erase(tqFind(openSet.begin(),openSet.end(),*openNode)); - openNode->clear(); // Clear the Node - } - } - Node *closedNode = &closedMatrix[col][row]; - if (*closedNode != TQPoint(-1,-1)) { - if ((*i) > (*closedNode)) - continue; - else { - openMatrix[col][row] = *openSet.insert(*closedNode); - closedNode->clear(); // Clear the Node - continue; - } - } - openMatrix[col][row] = *openSet.insert(*i); - } - closedMatrix[current.col()][current.row()] = current; - } -} - -void KisCurveMagnetic::findEdge (int col, int row, const GrayMatrix& src, Node& node) -{ - int x = -1; - int y = -1; - - // tmpdist out of range - KisVector2D mindist(5.0,5.0), tmpdist(1000.0,1000.0); - for (int i = -5; i < 6; i++) { - for (int j = -5; j < 6; j++) { - if (src[col+i][row+j] != NOEDGE) { - tmpdist = KisVector2D(i,j); - if (tmpdist.length() < mindist.length()) - mindist = tmpdist; - } - } - } - if (tmpdist.x() == 1000.0) - mindist = KisVector2D(0.0,0.0); - - x = (int)(col + mindist.x()); - y = (int)(row + mindist.y()); - - node.setPos(TQPoint(x,y)); -} - -void KisCurveMagnetic::reduceMatrix (TQRect& rc, GrayMatrix& m, int top, int right, int bottom, int left) -{ - TQPoint topleft(top, left); - TQPoint bottomright(bottom, right); - - rc.setTopLeft(rc.topLeft()+topleft); - rc.setBottomRight(rc.bottomRight()-bottomright); - - if (left) - m.erase(m.begin(),m.begin()+left); - if (right) - m.erase(m.end()-right,m.end()); - if (top) { - for (uint i = 0; i < m.count(); i++) - m[i].erase(m[i].begin(),m[i].begin()+top); - } - if (bottom) { - for (uint i = 0; i < m.count(); i++) - m[i].erase(m[i].end()-bottom,m[i].end()); - } -} - -void KisCurveMagnetic::detectEdges (const TQRect & rect, KisPaintDeviceSP src, GrayMatrix& dst) -{ - GrayMatrix graysrc(rect.width(),GrayCol(rect.height())); - GrayMatrix xdeltas(rect.width(),GrayCol(rect.height())); - GrayMatrix ydeltas(rect.width(),GrayCol(rect.height())); - GrayMatrix magnitude(rect.width(),GrayCol(rect.height())); - KisPaintDeviceSP smooth = new KisPaintDevice(src->colorSpace()); - - gaussianBlur(rect, src, smooth); - toGrayScale(rect, smooth, graysrc); - getDeltas(graysrc, xdeltas, ydeltas); - getMagnitude(xdeltas, ydeltas, magnitude); - nonMaxSupp(magnitude, xdeltas, ydeltas, dst); -} - -void KisCurveMagnetic::gaussianBlur (const TQRect& rect, KisPaintDeviceSP src, KisPaintDeviceSP dst) -{ - int grectx = rect.x(); - int grecty = rect.y(); - int grectw = rect.width(); - int grecth = rect.height(); - if (dst != src) { - KisPainter gc(dst); - gc.bitBlt(grectx, grecty, COMPOSITE_COPY, src, grectx, grecty, grectw, grecth); - gc.end(); - } - - KisConvolutionPainter painter( dst ); - // FIXME createKernel could create dynamic gaussian kernels having sigma as argument - KisKernelSP kernel = createKernel( 1, 1, 1, 1, 24, 1, 1, 1, 1, 32, 0); - painter.applyMatrix(kernel, grectx, grecty, grectw, grecth, BORDER_AVOID); -} - -void KisCurveMagnetic::toGrayScale (const TQRect& rect, KisPaintDeviceSP src, GrayMatrix& dst) -{ - int grectx = rect.x(); - int grecty = rect.y(); - int grectw = rect.width(); - int grecth = rect.height(); - TQColor c; - KisColorSpace *cs = src->colorSpace(); - - for (int row = 0; row < grecth; row++) { - KisHLineIteratorPixel srcIt = src->createHLineIterator(grectx, grecty+row, grectw, false); - for (int col = 0; col < grectw; col++) { - cs->toTQColor(srcIt.rawData(),&c); - dst[col][row] = tqGray(c.rgb()); - ++srcIt; - } - } -} - -void KisCurveMagnetic::getDeltas (const GrayMatrix& src, GrayMatrix& xdelta, GrayMatrix& ydelta) -{ - uint start = 1, xend = src[0].count()-1, yend = src.count()-1; - TQ_INT16 deri; - for (uint col = 0; col < src.count(); col++) { - for (uint row = 0; row < src[col].count(); row++) { - if (row >= start && row < xend) { - deri = src[col][row+1] - src[col][row-1]; - xdelta[col][row] = deri; - } else - xdelta[col][row] = 0; - if (col >= start && col < yend) { - deri = src[col+1][row] - src[col-1][row]; - ydelta[col][row] = deri; - } else - ydelta[col][row] = 0; - } - } -} - -void KisCurveMagnetic::getMagnitude (const GrayMatrix& xdelta, const GrayMatrix& ydelta, GrayMatrix& gradient) -{ - for (uint col = 0; col < xdelta.count(); col++) { - for (uint row = 0; row < xdelta[col].count(); row++) - gradient[col][row] = (TQ_INT16)(ROUND(RMS(xdelta[col][row],ydelta[col][row]))); - } -} - -void KisCurveMagnetic::nonMaxSupp (const GrayMatrix& magnitude, const GrayMatrix& xdelta, const GrayMatrix& ydelta, GrayMatrix& nms) -{ - // Directions: - // 1: 0 - 22.5 degrees - // 2: 22.5 - 67.5 degrees - // 3: 67.5 - 90 degrees - // Second direction is relative to a quadrant. The quadrant is known by looking at x and y derivatives - // First quadrant: Gx < 0 & Gy >= 0 - // Second quadrant: Gx < 0 & Gy < 0 - // Third quadrant: Gx >= 0 & Gy < 0 - // Fourth quadrant: Gx >= 0 & Gy >= 0 - // For this reason: first direction is relative to Gy only and third direction to Gx only - - double theta; // theta = invtan (|Gy| / |Gx|) This give the direction relative to a quadrant - TQ_INT16 mag; // Current magnitude - TQ_INT16 lmag; // Magnitude at the left (So this pixel is "more internal" than the current - TQ_INT16 rmag; // Magnitude at the right (So this pixel is "more external") - double xdel; // Current xdelta - double ydel; // Current ydelta - TQ_INT16 result; - - for (uint col = 0; col < magnitude.count(); col++) { - for (uint row = 0; row < magnitude[col].count(); row++) { - mag = magnitude[col][row]; - if (!mag || row == 0 || row == (magnitude[col].count()-1) || - col == 0 || col == (magnitude.count()-1)) - { - result = NOEDGE; - } else { - xdel = (double)xdelta[col][row]; - ydel = (double)ydelta[col][row]; - theta = atan(fabs(ydel)/fabs(xdel)); - if (theta < 0) - theta = fabs(theta)+M_PI_2; - theta = (theta * 360.0) / (2.0*M_PI); // Radians -> degrees - if (theta >= 0 && theta < 22.5) { // .0 - .3926990816 - if (ydel >= 0) { - lmag = magnitude[col][row-1]; - rmag = magnitude[col][row+1]; - } else { - lmag = magnitude[col][row+1]; - rmag = magnitude[col][row-1]; - } - } - if (theta >= 22.5 && theta < 67.5) { // .3926990816 - 1.1780972449 - if (xdel >= 0) { - if (ydel >= 0) { - lmag = magnitude[col-1][row-1]; - rmag = magnitude[col+1][row+1]; - } else { - lmag = magnitude[col+1][row-1]; - rmag = magnitude[col-1][row+1]; - } - } else { - if (ydel >= 0) { - lmag = magnitude[col-1][row+1]; - rmag = magnitude[col+1][row-1]; - } else { - lmag = magnitude[col+1][row+1]; - rmag = magnitude[col-1][row-1]; - } - } - } - if (theta >= 67.5 && theta <= 90.0) { // 1.1780972449 - 1.5707963266 - if (xdel >= 0) { - lmag = magnitude[col+1][row]; - rmag = magnitude[col-1][row]; - } else { - lmag = magnitude[col-1][row]; - rmag = magnitude[col+1][row]; - } - } - - if ((mag < lmag) || (mag < rmag)) { - result = NOEDGE; - } else { - if (rmag == mag) // If the external magnitude is equal to the current, suppress current. - result = NOEDGE; - else - result = (mag > 255) ? 255 : mag; - } - } - nms[col][row] = result; - } - } -} - -KisToolMagnetic::KisToolMagnetic () - : super("Magnetic Outline Tool") -{ - setName("tool_moutline"); - setCursor(KisCursor::load("tool_moutline_cursor.png", 6, 6)); - - m_editingMode = false; - m_editingCursor = m_draggingCursor = false; - - m_mode = 0; - m_curve = m_derived = 0; - m_current = m_previous = 0; - - m_distance = DEFAULTDIST; - - m_transactionMessage = i18n("Magnetic Outline Selection"); -} - -KisToolMagnetic::~KisToolMagnetic () -{ - m_curve = 0; - delete m_derived; -} - -void KisToolMagnetic::update (KisCanvasSubject *subject) -{ - super::update(subject); -} - -void KisToolMagnetic::activate () -{ - super::activate(); - if (!m_derived) { - m_derived = new KisCurveMagnetic(this); - m_curve = m_derived; - } -} - -void KisToolMagnetic::deactivate () -{ - m_curve->endActionOptions(); - m_actionOptions = NOOPTIONS; - m_dragging = false; - m_drawPivots = true; -} - -void KisToolMagnetic::keyPress(TQKeyEvent *event) -{ - if (event->key() == TQt::Key_Control) { - draw(false); - if (m_editingMode) { - m_editingMode = false; - if (m_current != 0) - m_curve->selectPivot(m_current,false); - m_mode->setText(i18n("Automatic Mode")); - } else { - m_editingMode = true; - m_mode->setText(i18n("Manual Mode")); - } - draw(false); - } else if (event->key() == TQt::Key_Delete && m_curve->count()) { - draw(false); - m_dragging = false; - if (m_curve->pivots().count() == 2) - m_curve->clear(); - else { - if ((*m_current) == m_curve->last() && !(m_editingMode)) { - m_curve->deletePivot(m_current.previousPivot()); - m_previous = m_current.previousPivot(); - } else { - m_editingMode = false; - m_curve->deletePivot(m_current); - m_previous = m_current = m_curve->selectPivot(m_curve->lastIterator()); - m_editingMode = true; - } - } - draw(false); - } else - super::keyPress(event); -} - -void KisToolMagnetic::buttonRelease(KisButtonReleaseEvent *event) -{ - if (m_editingMode) { - draw(m_current); - m_editingMode = false; - if (!m_curve->isEmpty()) - m_curve->movePivot(m_current, m_currentPoint); - m_editingMode = true; - draw(m_current); - } - super::buttonRelease(event); -} - -void KisToolMagnetic::buttonPress(KisButtonPressEvent *event) -{ - updateOptions(event->state()); - if (!m_currentImage) - return; - if (event->button() == Qt::LeftButton) { - m_dragging = true; - m_currentPoint = event->pos(); - PointPair temp(m_curve->end(),false); - if (m_editingMode) - temp = pointUnderMouse (m_subject->canvasController()->windowToView(event->pos().toTQPoint())); - if (temp.first == m_curve->end() && !(m_actionOptions)) { - if (m_editingMode) { - draw(true, true); - m_curve->selectAll(false); - draw(true, true); - } - draw(m_curve->end()); - if (!m_curve->isEmpty()) { - m_previous = m_current; - m_current = m_curve->pushPivot(event->pos()); - } else { - m_previous = m_current = m_curve->pushPivot(event->pos()); - } - if (m_curve->pivots().count() > 1) - m_curve->calculateCurve(m_previous,m_current,m_current); - if (m_editingMode) - draw(); - else { - if ((*m_previous).point() == (*m_current).point()) - draw(m_curve->end()); - else - draw(); - } - } else if (temp.first != m_curve->end() && m_editingMode) { - if (temp.second) { - draw(true, true); - m_current = m_curve->selectPivot(temp.first); - draw(true, true); - } else { - draw(false); - m_current = selectByMouse(temp.first); - draw(false); - } - if (!(*m_current).isSelected()) - m_dragging = false; - } - } -} - -void KisToolMagnetic::move(KisMoveEvent *event) -{ - updateOptions(event->state()); - if (m_currentPoint == event->pos().floorTQPoint()) - return; - if (m_editingMode) { - PointPair temp = pointUnderMouse(m_subject->canvasController()->windowToView(event->pos().toTQPoint())); - if (temp.first == m_curve->end() && !m_dragging) { - if (m_editingCursor || m_draggingCursor) { - setCursor(KisCursor::load("tool_moutline_cursor.png", 6, 6)); - m_editingCursor = m_draggingCursor = false; - } - } else { - if (!m_draggingCursor && temp.second) { - setCursor(KisCursor::load("tool_moutline_dragging.png", 6, 6)); - m_editingCursor = false; - m_draggingCursor = true; - } - if (!m_editingCursor && !temp.second) { - setCursor(KisCursor::load("tool_moutline_editing.png", 6, 6)); - m_editingCursor = true; - m_draggingCursor = false; - } - } - if (!m_dragging) - return; - } else { - if (m_editingCursor || m_draggingCursor) { - setCursor(KisCursor::load("tool_moutline_cursor.png", 6, 6)); - m_editingCursor = m_draggingCursor = false; - } - } - if (m_curve->selectedPivots().isEmpty()) - return; - - KisPoint trans = event->pos() - m_currentPoint; - KisPoint dist; - dist = (*m_current).point() - (*m_current.previousPivot()).point(); - if ((m_distance >= MINDIST && (fabs(dist.x()) + fabs(dist.y())) > m_distance && !(m_editingMode)) - || m_curve->pivots().count() == 1) { - draw(m_curve->end()); - m_previous = m_current; - m_current = m_curve->pushPivot(event->pos()); - } else if ((*m_previous).point() == (*m_current).point() && (*m_previous).point() == m_curve->last().point()) - draw(m_curve->end()); - else - draw(m_current); - m_curve->movePivot(m_current,event->pos()); - m_currentPoint = event->pos().floorTQPoint(); - draw(m_current); -} - -KisCurve::iterator KisToolMagnetic::selectByMouse(KisCurve::iterator it) -{ - KisCurve::iterator currPivot = m_curve->selectPivot(m_curve->addPivot(it, KisPoint(0,0))); - m_curve->movePivot(currPivot,(*it).point()); - - return currPivot; -} - -void KisToolMagnetic::slotCommitCurve () -{ - if (!m_curve->isEmpty()) - commitCurve(); -} - -void KisToolMagnetic::slotSetDistance (int dist) -{ - m_distance = dist; -} - -TQWidget* KisToolMagnetic::createOptionWidget(TQWidget* parent) -{ - m_optWidget = super::createOptionWidget(parent); - TQVBoxLayout * l = dynamic_cast(m_optWidget->layout()); - TQGridLayout *box = new TQGridLayout(l, 2, 2, 3); - box->setColStretch(0, 1); - box->setColStretch(1, 1); - TQ_CHECK_PTR(box); - - m_mode = new TQLabel(i18n("Automatic mode"), m_optWidget); - m_lbDistance = new TQLabel(i18n("Distance: "), m_optWidget); - TQPushButton *finish = new TQPushButton(i18n("To Selection"), m_optWidget); - m_slDistance = new TQSlider(MINDIST, MAXDIST, PAGESTEP, m_distance, Qt::Horizontal, m_optWidget); - - connect(m_slDistance, TQT_SIGNAL(valueChanged(int)), this, TQT_SLOT(slotSetDistance(int))); - connect(finish, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotCommitCurve())); - - box->addWidget(m_lbDistance, 0, 0); - box->addWidget(m_slDistance, 0, 1); - box->addWidget(m_mode, 1, 0); - box->addWidget(finish, 1, 1); - - return m_optWidget; -} - -void KisToolMagnetic::setup(TDEActionCollection *collection) -{ - m_action = static_cast(collection->action(name())); - - if (m_action == 0) { - TDEShortcut shortcut(TQt::Key_Plus); - shortcut.append(TDEShortcut(TQt::Key_F9)); - m_action = new TDERadioAction(i18n("Magnetic Outline"), - "tool_moutline", - shortcut, - this, - TQT_SLOT(activate()), - collection, - name()); - TQ_CHECK_PTR(m_action); - - m_action->setToolTip(i18n("Magnetic Selection: move around an edge to select it. Hit Ctrl to enter/quit manual mode, and double click to finish.")); - m_action->setExclusiveGroup("tools"); - m_ownAction = true; - } -} - -#include "kis_tool_moutline.moc" diff --git a/chalk/plugins/tools/tool_curves/kis_tool_moutline.cpp b/chalk/plugins/tools/tool_curves/kis_tool_moutline.cpp new file mode 100644 index 000000000..ebf82634f --- /dev/null +++ b/chalk/plugins/tools/tool_curves/kis_tool_moutline.cpp @@ -0,0 +1,809 @@ +/* + * kis_tool_moutline.cpp -- part of Chalk + * + * Copyright (c) 2006 Emanuele Tamponi + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "kis_global.h" +#include "kis_iterators_pixel.h" +#include "kis_colorspace.h" +#include "kis_channelinfo.h" +#include "kis_doc.h" +#include "kis_painter.h" +#include "kis_point.h" +#include "kis_canvas_subject.h" +#include "kis_canvas_controller.h" +#include "kis_button_press_event.h" +#include "kis_button_release_event.h" +#include "kis_move_event.h" +#include "kis_canvas.h" +#include "kis_canvas_painter.h" +#include "kis_cursor.h" +#include "kis_tool_controller.h" +#include "kis_vec.h" +#include "kis_selection.h" +#include "kis_selection_options.h" +#include "kis_selected_transaction.h" +#include "kis_paintop_registry.h" +#include "kis_convolution_painter.h" + +#include "kis_tool_moutline.h" + +using namespace std; + +#define RMS(a, b) (sqrt ((a) * (a) + (b) * (b))) +#define ROUND(x) ((int) ((x) + 0.5)) + +const int NOEDGE = 0x0000; + +const int ORTHOGONAL_COST = 10; // 1*10 +const int DIAGONAL_COST = 14; // sqrt(2)*10 +const int MALUS = 20; // This applies to NOEDGE nodes + +const int DEFAULTDIST = 40; // Default distance between two automatic pivots +const int MAXDIST = 55; // Max distance +const int MINDIST = 15; +const int PAGESTEP = 5; + +class Node { + + TQPoint m_pos; + int m_gCost; + int m_hCost; + int m_tCost; + bool m_malus; + TQPoint m_parent; + +public: + + Node() + { + m_pos = m_parent = TQPoint(-1,-1); + m_gCost = m_hCost = m_tCost = 0; + m_malus = false; + } + + Node(const Node& node) + { + m_pos = node.pos(); + m_gCost = node.gCost(); + m_hCost = node.hCost(); + m_tCost = node.tCost(); + m_malus = node.malus(); + m_parent = node.parent(); + } + + Node(const TQPoint& parent, const TQPoint& pos, int g, int h, bool malus) + : m_pos(pos), m_hCost(h), m_malus(malus) + { + setGCost(g); + m_parent = parent; + } + ~Node () + { + } + + int gCost () const {return m_gCost;} + int hCost () const {return m_hCost;} + int tCost () const {return m_tCost;} + bool malus () const {return m_malus;} + TQPoint pos () const {return m_pos;} + int col () const {return m_pos.x();} + int row () const {return m_pos.y();} + TQPoint parent () const {return m_parent;} + + void setGCost (int g) + { + m_gCost = g+(m_malus?MALUS:0); + m_tCost = m_gCost+m_hCost; + } + void setHCost (int h) + { + m_hCost = h; + m_tCost = m_gCost+m_hCost; + } + void setPos (const TQPoint& pos) + { + m_pos = pos; + } + void setMalus (bool malus) + { + m_malus = malus; + } + void clear () + { + m_pos = TQPoint(-1,-1); + } + + bool operator== (const Node& n2) const + { + return m_pos == n2.pos(); + } + bool operator!= (const Node& n2) const + { + return m_pos != n2.pos(); + } + bool operator== (const TQPoint& n2) const + { + return m_pos == n2; + } + bool operator!= (const TQPoint& n2) const + { + return m_pos != n2; + } + bool operator< (const Node& n2) const + { + return m_tCost < n2.tCost(); + } + bool operator> (const Node& n2) const + { + return m_tCost > n2.tCost(); + } + + TQValueList getNeighbor(const GrayMatrix& src, const Node& end) + { + TQPoint tmpdist; + TQValueList temp; + int dcol, drow; + int g, h; + bool malus; + int x[8] = { 1, 1, 0,-1,-1,-1, 0, 1}, + y[8] = { 0,-1,-1,-1, 0, 1, 1, 1}; + + for (int i = 0; i < 8; i++) { + dcol = m_pos.x() + x[i]; + drow = m_pos.y() + y[i]; + tmpdist = TQPoint(dcol,drow) - end.pos(); + // I use src[0] here because all cols have same number of rows + if (dcol == (int)src.count() || dcol < 0 || + drow == (int)src[0].count() || drow < 0) + continue; + if (src[dcol][drow]) + malus = false; + else + malus = true; + if (i%2) + g = m_gCost + DIAGONAL_COST; + else + g = m_gCost + ORTHOGONAL_COST; + h = ORTHOGONAL_COST * (abs(tmpdist.x()) + abs(tmpdist.y())); + temp.append(Node(m_pos,TQPoint(dcol,drow),g,h,malus)); + } + return temp; + } + +}; + +KisKernelSP createKernel( TQ_INT32 i0, TQ_INT32 i1, TQ_INT32 i2, + TQ_INT32 i3, TQ_INT32 i4, TQ_INT32 i5, + TQ_INT32 i6, TQ_INT32 i7, TQ_INT32 i8, + TQ_INT32 factor, TQ_INT32 offset ) +{ + KisKernelSP kernel = new KisKernel(); + kernel->width = 3; + kernel->height = 3; + + kernel->factor = factor; + kernel->offset = offset; + + kernel->data = new TQ_INT32[9]; + kernel->data[0] = i0; + kernel->data[1] = i1; + kernel->data[2] = i2; + kernel->data[3] = i3; + kernel->data[4] = i4; + kernel->data[5] = i5; + kernel->data[6] = i6; + kernel->data[7] = i7; + kernel->data[8] = i8; + + return kernel; +} + +KisCurveMagnetic::KisCurveMagnetic (KisToolMagnetic *parent) + : m_parent(parent) +{ + m_standardkeepselected = false; +} + +KisCurveMagnetic::~KisCurveMagnetic () +{ + +} + +KisCurve::iterator KisCurveMagnetic::addPivot (KisCurve::iterator it, const KisPoint& point) +{ + return iterator(*this,m_curve.insert(it.position(), CurvePoint(point,true,false,LINEHINT))); +} + +KisCurve::iterator KisCurveMagnetic::pushPivot (const KisPoint& point) +{ + iterator it; + + it = pushPoint(point,true,false,LINEHINT); +// if (count() == 1 && !m_parent->editingMode()) +// addPoint(it,point,true,false,LINEHINT); + + return selectPivot(it); +} + +void KisCurveMagnetic::calculateCurve (KisCurve::iterator p1, KisCurve::iterator p2, KisCurve::iterator it) +{ + if (p1 == m_curve.end() || p2 == m_curve.end()) // It happens sometimes, for example on the first click + return; + if (m_parent->editingMode()) + return; + TQPoint start = (*p1).point().roundTQPoint(); + TQPoint end = (*p2).point().roundTQPoint(); + TQRect rc = TQRect(start,end).normalize(); + rc.setTopLeft(rc.topLeft()+TQPoint(-8,-8)); // Enlarge the view, so problems with gaussian blur can be removed + rc.setBottomRight(rc.bottomRight()+TQPoint(8,8)); // and we are able to find paths that go beyond the rect. + + KisPaintDeviceSP src = m_parent->m_currentImage->activeDevice(); + GrayMatrix dst = GrayMatrix(rc.width(),GrayCol(rc.height())); + + detectEdges (rc, src, dst); + reduceMatrix (rc, dst, 3, 3, 3, 3); + + Node startNode, endNode; + multiset openSet; + NodeMatrix openMatrix = NodeMatrix(rc.width(),NodeCol(rc.height())); + NodeMatrix closedMatrix = NodeMatrix(rc.width(),NodeCol(rc.height())); + + TQPoint tl(rc.topLeft().x(),rc.topLeft().y()); + start -= tl; // Relative to the matrix + end -= tl; // Relative to the matrix + + findEdge (start.x(), start.y(), dst, startNode); + openMatrix[startNode.col()][startNode.row()] = *openSet.insert(startNode); + endNode.setPos(end); + + while (!openSet.empty()) { + Node current = *openSet.begin(); + + openSet.erase(openSet.begin()); + openMatrix[current.col()][current.row()].clear(); + + TQValueList successors = current.getNeighbor(dst,endNode); + for (TQValueList::iterator i = successors.begin(); i != successors.end(); i++) { + int col = (*i).col(); + int row = (*i).row(); + if ((*i) == endNode) { + while (current.parent() != TQPoint(-1,-1)) { + it = addPoint(it,KisPoint(tl+current.pos()),false,false,LINEHINT); + current = closedMatrix[current.parent().x()][current.parent().y()]; + } + return; + } + Node *openNode = &openMatrix[col][row]; + if (*openNode != TQPoint(-1,-1)) { + if (*i > *openNode) + continue; + else { + openSet.erase(tqFind(openSet.begin(),openSet.end(),*openNode)); + openNode->clear(); // Clear the Node + } + } + Node *closedNode = &closedMatrix[col][row]; + if (*closedNode != TQPoint(-1,-1)) { + if ((*i) > (*closedNode)) + continue; + else { + openMatrix[col][row] = *openSet.insert(*closedNode); + closedNode->clear(); // Clear the Node + continue; + } + } + openMatrix[col][row] = *openSet.insert(*i); + } + closedMatrix[current.col()][current.row()] = current; + } +} + +void KisCurveMagnetic::findEdge (int col, int row, const GrayMatrix& src, Node& node) +{ + int x = -1; + int y = -1; + + // tmpdist out of range + KisVector2D mindist(5.0,5.0), tmpdist(1000.0,1000.0); + for (int i = -5; i < 6; i++) { + for (int j = -5; j < 6; j++) { + if (src[col+i][row+j] != NOEDGE) { + tmpdist = KisVector2D(i,j); + if (tmpdist.length() < mindist.length()) + mindist = tmpdist; + } + } + } + if (tmpdist.x() == 1000.0) + mindist = KisVector2D(0.0,0.0); + + x = (int)(col + mindist.x()); + y = (int)(row + mindist.y()); + + node.setPos(TQPoint(x,y)); +} + +void KisCurveMagnetic::reduceMatrix (TQRect& rc, GrayMatrix& m, int top, int right, int bottom, int left) +{ + TQPoint topleft(top, left); + TQPoint bottomright(bottom, right); + + rc.setTopLeft(rc.topLeft()+topleft); + rc.setBottomRight(rc.bottomRight()-bottomright); + + if (left) + m.erase(m.begin(),m.begin()+left); + if (right) + m.erase(m.end()-right,m.end()); + if (top) { + for (uint i = 0; i < m.count(); i++) + m[i].erase(m[i].begin(),m[i].begin()+top); + } + if (bottom) { + for (uint i = 0; i < m.count(); i++) + m[i].erase(m[i].end()-bottom,m[i].end()); + } +} + +void KisCurveMagnetic::detectEdges (const TQRect & rect, KisPaintDeviceSP src, GrayMatrix& dst) +{ + GrayMatrix graysrc(rect.width(),GrayCol(rect.height())); + GrayMatrix xdeltas(rect.width(),GrayCol(rect.height())); + GrayMatrix ydeltas(rect.width(),GrayCol(rect.height())); + GrayMatrix magnitude(rect.width(),GrayCol(rect.height())); + KisPaintDeviceSP smooth = new KisPaintDevice(src->colorSpace()); + + gaussianBlur(rect, src, smooth); + toGrayScale(rect, smooth, graysrc); + getDeltas(graysrc, xdeltas, ydeltas); + getMagnitude(xdeltas, ydeltas, magnitude); + nonMaxSupp(magnitude, xdeltas, ydeltas, dst); +} + +void KisCurveMagnetic::gaussianBlur (const TQRect& rect, KisPaintDeviceSP src, KisPaintDeviceSP dst) +{ + int grectx = rect.x(); + int grecty = rect.y(); + int grectw = rect.width(); + int grecth = rect.height(); + if (dst != src) { + KisPainter gc(dst); + gc.bitBlt(grectx, grecty, COMPOSITE_COPY, src, grectx, grecty, grectw, grecth); + gc.end(); + } + + KisConvolutionPainter painter( dst ); + // FIXME createKernel could create dynamic gaussian kernels having sigma as argument + KisKernelSP kernel = createKernel( 1, 1, 1, 1, 24, 1, 1, 1, 1, 32, 0); + painter.applyMatrix(kernel, grectx, grecty, grectw, grecth, BORDER_AVOID); +} + +void KisCurveMagnetic::toGrayScale (const TQRect& rect, KisPaintDeviceSP src, GrayMatrix& dst) +{ + int grectx = rect.x(); + int grecty = rect.y(); + int grectw = rect.width(); + int grecth = rect.height(); + TQColor c; + KisColorSpace *cs = src->colorSpace(); + + for (int row = 0; row < grecth; row++) { + KisHLineIteratorPixel srcIt = src->createHLineIterator(grectx, grecty+row, grectw, false); + for (int col = 0; col < grectw; col++) { + cs->toTQColor(srcIt.rawData(),&c); + dst[col][row] = tqGray(c.rgb()); + ++srcIt; + } + } +} + +void KisCurveMagnetic::getDeltas (const GrayMatrix& src, GrayMatrix& xdelta, GrayMatrix& ydelta) +{ + uint start = 1, xend = src[0].count()-1, yend = src.count()-1; + TQ_INT16 deri; + for (uint col = 0; col < src.count(); col++) { + for (uint row = 0; row < src[col].count(); row++) { + if (row >= start && row < xend) { + deri = src[col][row+1] - src[col][row-1]; + xdelta[col][row] = deri; + } else + xdelta[col][row] = 0; + if (col >= start && col < yend) { + deri = src[col+1][row] - src[col-1][row]; + ydelta[col][row] = deri; + } else + ydelta[col][row] = 0; + } + } +} + +void KisCurveMagnetic::getMagnitude (const GrayMatrix& xdelta, const GrayMatrix& ydelta, GrayMatrix& gradient) +{ + for (uint col = 0; col < xdelta.count(); col++) { + for (uint row = 0; row < xdelta[col].count(); row++) + gradient[col][row] = (TQ_INT16)(ROUND(RMS(xdelta[col][row],ydelta[col][row]))); + } +} + +void KisCurveMagnetic::nonMaxSupp (const GrayMatrix& magnitude, const GrayMatrix& xdelta, const GrayMatrix& ydelta, GrayMatrix& nms) +{ + // Directions: + // 1: 0 - 22.5 degrees + // 2: 22.5 - 67.5 degrees + // 3: 67.5 - 90 degrees + // Second direction is relative to a quadrant. The quadrant is known by looking at x and y derivatives + // First quadrant: Gx < 0 & Gy >= 0 + // Second quadrant: Gx < 0 & Gy < 0 + // Third quadrant: Gx >= 0 & Gy < 0 + // Fourth quadrant: Gx >= 0 & Gy >= 0 + // For this reason: first direction is relative to Gy only and third direction to Gx only + + double theta; // theta = invtan (|Gy| / |Gx|) This give the direction relative to a quadrant + TQ_INT16 mag; // Current magnitude + TQ_INT16 lmag; // Magnitude at the left (So this pixel is "more internal" than the current + TQ_INT16 rmag; // Magnitude at the right (So this pixel is "more external") + double xdel; // Current xdelta + double ydel; // Current ydelta + TQ_INT16 result; + + for (uint col = 0; col < magnitude.count(); col++) { + for (uint row = 0; row < magnitude[col].count(); row++) { + mag = magnitude[col][row]; + if (!mag || row == 0 || row == (magnitude[col].count()-1) || + col == 0 || col == (magnitude.count()-1)) + { + result = NOEDGE; + } else { + xdel = (double)xdelta[col][row]; + ydel = (double)ydelta[col][row]; + theta = atan(fabs(ydel)/fabs(xdel)); + if (theta < 0) + theta = fabs(theta)+M_PI_2; + theta = (theta * 360.0) / (2.0*M_PI); // Radians -> degrees + if (theta >= 0 && theta < 22.5) { // .0 - .3926990816 + if (ydel >= 0) { + lmag = magnitude[col][row-1]; + rmag = magnitude[col][row+1]; + } else { + lmag = magnitude[col][row+1]; + rmag = magnitude[col][row-1]; + } + } + if (theta >= 22.5 && theta < 67.5) { // .3926990816 - 1.1780972449 + if (xdel >= 0) { + if (ydel >= 0) { + lmag = magnitude[col-1][row-1]; + rmag = magnitude[col+1][row+1]; + } else { + lmag = magnitude[col+1][row-1]; + rmag = magnitude[col-1][row+1]; + } + } else { + if (ydel >= 0) { + lmag = magnitude[col-1][row+1]; + rmag = magnitude[col+1][row-1]; + } else { + lmag = magnitude[col+1][row+1]; + rmag = magnitude[col-1][row-1]; + } + } + } + if (theta >= 67.5 && theta <= 90.0) { // 1.1780972449 - 1.5707963266 + if (xdel >= 0) { + lmag = magnitude[col+1][row]; + rmag = magnitude[col-1][row]; + } else { + lmag = magnitude[col-1][row]; + rmag = magnitude[col+1][row]; + } + } + + if ((mag < lmag) || (mag < rmag)) { + result = NOEDGE; + } else { + if (rmag == mag) // If the external magnitude is equal to the current, suppress current. + result = NOEDGE; + else + result = (mag > 255) ? 255 : mag; + } + } + nms[col][row] = result; + } + } +} + +KisToolMagnetic::KisToolMagnetic () + : super("Magnetic Outline Tool") +{ + setName("tool_moutline"); + setCursor(KisCursor::load("tool_moutline_cursor.png", 6, 6)); + + m_editingMode = false; + m_editingCursor = m_draggingCursor = false; + + m_mode = 0; + m_curve = m_derived = 0; + m_current = m_previous = 0; + + m_distance = DEFAULTDIST; + + m_transactionMessage = i18n("Magnetic Outline Selection"); +} + +KisToolMagnetic::~KisToolMagnetic () +{ + m_curve = 0; + delete m_derived; +} + +void KisToolMagnetic::update (KisCanvasSubject *subject) +{ + super::update(subject); +} + +void KisToolMagnetic::activate () +{ + super::activate(); + if (!m_derived) { + m_derived = new KisCurveMagnetic(this); + m_curve = m_derived; + } +} + +void KisToolMagnetic::deactivate () +{ + m_curve->endActionOptions(); + m_actionOptions = NOOPTIONS; + m_dragging = false; + m_drawPivots = true; +} + +void KisToolMagnetic::keyPress(TQKeyEvent *event) +{ + if (event->key() == TQt::Key_Control) { + draw(false); + if (m_editingMode) { + m_editingMode = false; + if (m_current != 0) + m_curve->selectPivot(m_current,false); + m_mode->setText(i18n("Automatic Mode")); + } else { + m_editingMode = true; + m_mode->setText(i18n("Manual Mode")); + } + draw(false); + } else if (event->key() == TQt::Key_Delete && m_curve->count()) { + draw(false); + m_dragging = false; + if (m_curve->pivots().count() == 2) + m_curve->clear(); + else { + if ((*m_current) == m_curve->last() && !(m_editingMode)) { + m_curve->deletePivot(m_current.previousPivot()); + m_previous = m_current.previousPivot(); + } else { + m_editingMode = false; + m_curve->deletePivot(m_current); + m_previous = m_current = m_curve->selectPivot(m_curve->lastIterator()); + m_editingMode = true; + } + } + draw(false); + } else + super::keyPress(event); +} + +void KisToolMagnetic::buttonRelease(KisButtonReleaseEvent *event) +{ + if (m_editingMode) { + draw(m_current); + m_editingMode = false; + if (!m_curve->isEmpty()) + m_curve->movePivot(m_current, m_currentPoint); + m_editingMode = true; + draw(m_current); + } + super::buttonRelease(event); +} + +void KisToolMagnetic::buttonPress(KisButtonPressEvent *event) +{ + updateOptions(event->state()); + if (!m_currentImage) + return; + if (event->button() == Qt::LeftButton) { + m_dragging = true; + m_currentPoint = event->pos(); + PointPair temp(m_curve->end(),false); + if (m_editingMode) + temp = pointUnderMouse (m_subject->canvasController()->windowToView(event->pos().toTQPoint())); + if (temp.first == m_curve->end() && !(m_actionOptions)) { + if (m_editingMode) { + draw(true, true); + m_curve->selectAll(false); + draw(true, true); + } + draw(m_curve->end()); + if (!m_curve->isEmpty()) { + m_previous = m_current; + m_current = m_curve->pushPivot(event->pos()); + } else { + m_previous = m_current = m_curve->pushPivot(event->pos()); + } + if (m_curve->pivots().count() > 1) + m_curve->calculateCurve(m_previous,m_current,m_current); + if (m_editingMode) + draw(); + else { + if ((*m_previous).point() == (*m_current).point()) + draw(m_curve->end()); + else + draw(); + } + } else if (temp.first != m_curve->end() && m_editingMode) { + if (temp.second) { + draw(true, true); + m_current = m_curve->selectPivot(temp.first); + draw(true, true); + } else { + draw(false); + m_current = selectByMouse(temp.first); + draw(false); + } + if (!(*m_current).isSelected()) + m_dragging = false; + } + } +} + +void KisToolMagnetic::move(KisMoveEvent *event) +{ + updateOptions(event->state()); + if (m_currentPoint == event->pos().floorTQPoint()) + return; + if (m_editingMode) { + PointPair temp = pointUnderMouse(m_subject->canvasController()->windowToView(event->pos().toTQPoint())); + if (temp.first == m_curve->end() && !m_dragging) { + if (m_editingCursor || m_draggingCursor) { + setCursor(KisCursor::load("tool_moutline_cursor.png", 6, 6)); + m_editingCursor = m_draggingCursor = false; + } + } else { + if (!m_draggingCursor && temp.second) { + setCursor(KisCursor::load("tool_moutline_dragging.png", 6, 6)); + m_editingCursor = false; + m_draggingCursor = true; + } + if (!m_editingCursor && !temp.second) { + setCursor(KisCursor::load("tool_moutline_editing.png", 6, 6)); + m_editingCursor = true; + m_draggingCursor = false; + } + } + if (!m_dragging) + return; + } else { + if (m_editingCursor || m_draggingCursor) { + setCursor(KisCursor::load("tool_moutline_cursor.png", 6, 6)); + m_editingCursor = m_draggingCursor = false; + } + } + if (m_curve->selectedPivots().isEmpty()) + return; + + KisPoint trans = event->pos() - m_currentPoint; + KisPoint dist; + dist = (*m_current).point() - (*m_current.previousPivot()).point(); + if ((m_distance >= MINDIST && (fabs(dist.x()) + fabs(dist.y())) > m_distance && !(m_editingMode)) + || m_curve->pivots().count() == 1) { + draw(m_curve->end()); + m_previous = m_current; + m_current = m_curve->pushPivot(event->pos()); + } else if ((*m_previous).point() == (*m_current).point() && (*m_previous).point() == m_curve->last().point()) + draw(m_curve->end()); + else + draw(m_current); + m_curve->movePivot(m_current,event->pos()); + m_currentPoint = event->pos().floorTQPoint(); + draw(m_current); +} + +KisCurve::iterator KisToolMagnetic::selectByMouse(KisCurve::iterator it) +{ + KisCurve::iterator currPivot = m_curve->selectPivot(m_curve->addPivot(it, KisPoint(0,0))); + m_curve->movePivot(currPivot,(*it).point()); + + return currPivot; +} + +void KisToolMagnetic::slotCommitCurve () +{ + if (!m_curve->isEmpty()) + commitCurve(); +} + +void KisToolMagnetic::slotSetDistance (int dist) +{ + m_distance = dist; +} + +TQWidget* KisToolMagnetic::createOptionWidget(TQWidget* parent) +{ + m_optWidget = super::createOptionWidget(parent); + TQVBoxLayout * l = dynamic_cast(m_optWidget->layout()); + TQGridLayout *box = new TQGridLayout(l, 2, 2, 3); + box->setColStretch(0, 1); + box->setColStretch(1, 1); + TQ_CHECK_PTR(box); + + m_mode = new TQLabel(i18n("Automatic mode"), m_optWidget); + m_lbDistance = new TQLabel(i18n("Distance: "), m_optWidget); + TQPushButton *finish = new TQPushButton(i18n("To Selection"), m_optWidget); + m_slDistance = new TQSlider(MINDIST, MAXDIST, PAGESTEP, m_distance, Qt::Horizontal, m_optWidget); + + connect(m_slDistance, TQT_SIGNAL(valueChanged(int)), this, TQT_SLOT(slotSetDistance(int))); + connect(finish, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotCommitCurve())); + + box->addWidget(m_lbDistance, 0, 0); + box->addWidget(m_slDistance, 0, 1); + box->addWidget(m_mode, 1, 0); + box->addWidget(finish, 1, 1); + + return m_optWidget; +} + +void KisToolMagnetic::setup(TDEActionCollection *collection) +{ + m_action = static_cast(collection->action(name())); + + if (m_action == 0) { + TDEShortcut shortcut(TQt::Key_Plus); + shortcut.append(TDEShortcut(TQt::Key_F9)); + m_action = new TDERadioAction(i18n("Magnetic Outline"), + "tool_moutline", + shortcut, + this, + TQT_SLOT(activate()), + collection, + name()); + TQ_CHECK_PTR(m_action); + + m_action->setToolTip(i18n("Magnetic Selection: move around an edge to select it. Hit Ctrl to enter/quit manual mode, and double click to finish.")); + m_action->setExclusiveGroup("tools"); + m_ownAction = true; + } +} + +#include "kis_tool_moutline.moc" diff --git a/chalk/plugins/tools/tool_curves/tool_curves.cc b/chalk/plugins/tools/tool_curves/tool_curves.cc deleted file mode 100644 index b21f5aae3..000000000 --- a/chalk/plugins/tools/tool_curves/tool_curves.cc +++ /dev/null @@ -1,67 +0,0 @@ -/* - * tool_bezier.cc -- part of Chalk - * - * Copyright (c) 2006 Emanuele Tamponi - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include -#include - -#include - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include "tool_curves.h" -#include "kis_tool_bezier_paint.h" -#include "kis_tool_bezier_select.h" -#include "kis_tool_moutline.h" - - -typedef KGenericFactory ToolCurvesFactory; -K_EXPORT_COMPONENT_FACTORY( chalktoolcurves, ToolCurvesFactory( "chalk" ) ) - - -ToolCurves::ToolCurves(TQObject *parent, const char *name, const TQStringList &) - : KParts::Plugin(parent, name) -{ - setInstance(ToolCurvesFactory::instance()); - - if ( parent->inherits("KisToolRegistry") ) - { - KisToolRegistry * r = dynamic_cast( parent ); - r->add(new KisToolBezierPaintFactory()); - r->add(new KisToolBezierSelectFactory()); - r->add(new KisToolMagneticFactory()); - } - -} - -ToolCurves::~ToolCurves() -{ -} - -#include "tool_curves.moc" diff --git a/chalk/plugins/tools/tool_curves/tool_curves.cpp b/chalk/plugins/tools/tool_curves/tool_curves.cpp new file mode 100644 index 000000000..28f65604a --- /dev/null +++ b/chalk/plugins/tools/tool_curves/tool_curves.cpp @@ -0,0 +1,67 @@ +/* + * tool_bezier.cpp -- part of Chalk + * + * Copyright (c) 2006 Emanuele Tamponi + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "tool_curves.h" +#include "kis_tool_bezier_paint.h" +#include "kis_tool_bezier_select.h" +#include "kis_tool_moutline.h" + + +typedef KGenericFactory ToolCurvesFactory; +K_EXPORT_COMPONENT_FACTORY( chalktoolcurves, ToolCurvesFactory( "chalk" ) ) + + +ToolCurves::ToolCurves(TQObject *parent, const char *name, const TQStringList &) + : KParts::Plugin(parent, name) +{ + setInstance(ToolCurvesFactory::instance()); + + if ( parent->inherits("KisToolRegistry") ) + { + KisToolRegistry * r = dynamic_cast( parent ); + r->add(new KisToolBezierPaintFactory()); + r->add(new KisToolBezierSelectFactory()); + r->add(new KisToolMagneticFactory()); + } + +} + +ToolCurves::~ToolCurves() +{ +} + +#include "tool_curves.moc" diff --git a/chalk/plugins/tools/tool_filter/Makefile.am b/chalk/plugins/tools/tool_filter/Makefile.am index d99a39249..b12ab69b5 100644 --- a/chalk/plugins/tools/tool_filter/Makefile.am +++ b/chalk/plugins/tools/tool_filter/Makefile.am @@ -10,9 +10,9 @@ INCLUDES = -I$(srcdir)/../../../sdk \ $(all_includes) chalktoolfilter_la_SOURCES = \ - kis_filterop.cc \ - kis_tool_filter.cc \ - tool_filter.cc + kis_filterop.cpp \ + kis_tool_filter.cpp \ + tool_filter.cpp # Install this plugin in the KDE modules directory kde_module_LTLIBRARIES = chalktoolfilter.la diff --git a/chalk/plugins/tools/tool_filter/kis_filterop.cc b/chalk/plugins/tools/tool_filter/kis_filterop.cpp similarity index 100% rename from chalk/plugins/tools/tool_filter/kis_filterop.cc rename to chalk/plugins/tools/tool_filter/kis_filterop.cpp diff --git a/chalk/plugins/tools/tool_filter/kis_tool_filter.cc b/chalk/plugins/tools/tool_filter/kis_tool_filter.cc deleted file mode 100644 index 07133d3bb..000000000 --- a/chalk/plugins/tools/tool_filter/kis_tool_filter.cc +++ /dev/null @@ -1,154 +0,0 @@ -/* - * kis_tool_filter.cc - part of Chalk - * - * Copyright (c) 2004 Cyrille Berger - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include -#include -#include -#include -#include - -#include -#include -#include - -#include "kis_filter_config_widget.h" -#include "kis_tool_filter.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -KisToolFilter::KisToolFilter() - : super(i18n("Filter Brush")), m_filterConfigurationWidget(0) -{ - setName("tool_filter"); - m_subject = 0; - setCursor(KisCursor::load("tool_filter_cursor.png", 5, 5)); -} - -KisToolFilter::~KisToolFilter() -{ -} - -void KisToolFilter::setup(TDEActionCollection *collection) -{ - m_action = static_cast(collection->action(name())); - - if (m_action == 0) { - m_action = new TDERadioAction(i18n("&Filter Brush"), - "tool_filter", 0, this, - TQT_SLOT(activate()), collection, - name()); - TQ_CHECK_PTR(m_action); - m_action->setToolTip(i18n("Paint with filters")); - m_action->setExclusiveGroup("tools"); - m_ownAction = true; - } -} - -void KisToolFilter::initPaint(KisEvent *e) -{ - // Some filters want to paint directly on the current state of - // the canvas, others cannot handle that and need a temporary layer - // so they can work on the old data before painting started. - m_paintIncremental = m_filter->supportsIncrementalPainting(); - - super::initPaint(e); - KisPaintOp * op = KisPaintOpRegistry::instance()->paintOp("filter", 0, painter()); - op->setSource ( m_source ); - painter()->setPaintOp(op); // And now the painter owns the op and will destroy it. - painter()->setFilter( m_filter ); - - // XXX: Isn't there a better way to set the config? The filter config widget needs to - // to go into the tool options widget, and just the data carried over to the filter. - // I've got a bit of a problem with core classes having too much GUI about them. - // BSAR. - dynamic_cast(op)->setFilterConfiguration( m_filter->configuration( m_filterConfigurationWidget) ); -} - -TQWidget* KisToolFilter::createOptionWidget(TQWidget* parent) -{ - TQWidget *widget = super::createOptionWidget(parent); - - m_cbFilter = new KisCmbIDList(widget); - TQ_CHECK_PTR(m_cbFilter); - - TQLabel* lbFilter = new TQLabel(i18n("Filter:"), widget); - TQ_CHECK_PTR(lbFilter); - - // Check which filters support painting - KisIDList l = KisFilterRegistry::instance()->listKeys(); - KisIDList l2; - KisIDList::iterator it; - for (it = l.begin(); it != l.end(); ++it) { - KisFilterSP f = KisFilterRegistry::instance()->get(*it); - if (f->supportsPainting()) { - l2.push_back(*it); - } - } - m_cbFilter ->setIDList( l2 ); - - addOptionWidgetOption(m_cbFilter, lbFilter); - - m_optionLayout = new TQGridLayout(widget, 1, 1, 0, 6); - TQ_CHECK_PTR(m_optionLayout); - super::addOptionWidgetLayout(m_optionLayout); - - connect(m_cbFilter, TQT_SIGNAL(activated ( const KisID& )), this, TQT_SLOT( changeFilter( const KisID& ) ) ); - changeFilter( m_cbFilter->currentItem () ); - - return widget; -} - -void KisToolFilter::changeFilter( const KisID & id) -{ - m_filter = KisFilterRegistry::instance()->get( id ); - Q_ASSERT(m_filter != 0); - if( m_filterConfigurationWidget != 0 ) - { - m_optionLayout->remove ( m_filterConfigurationWidget ); - delete m_filterConfigurationWidget; - } - - m_source = m_currentImage->activeDevice(); - if (!m_source) return; - - m_filterConfigurationWidget = m_filter->createConfigurationWidget( optionWidget(), m_source ); - if( m_filterConfigurationWidget != 0 ) - { - m_optionLayout->addMultiCellWidget ( m_filterConfigurationWidget, 2, 2, 0, 1 ); - m_filterConfigurationWidget->show(); - } -} - -#include "kis_tool_filter.moc" diff --git a/chalk/plugins/tools/tool_filter/kis_tool_filter.cpp b/chalk/plugins/tools/tool_filter/kis_tool_filter.cpp new file mode 100644 index 000000000..14e2d6168 --- /dev/null +++ b/chalk/plugins/tools/tool_filter/kis_tool_filter.cpp @@ -0,0 +1,154 @@ +/* + * kis_tool_filter.cpp - part of Chalk + * + * Copyright (c) 2004 Cyrille Berger + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "kis_filter_config_widget.h" +#include "kis_tool_filter.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +KisToolFilter::KisToolFilter() + : super(i18n("Filter Brush")), m_filterConfigurationWidget(0) +{ + setName("tool_filter"); + m_subject = 0; + setCursor(KisCursor::load("tool_filter_cursor.png", 5, 5)); +} + +KisToolFilter::~KisToolFilter() +{ +} + +void KisToolFilter::setup(TDEActionCollection *collection) +{ + m_action = static_cast(collection->action(name())); + + if (m_action == 0) { + m_action = new TDERadioAction(i18n("&Filter Brush"), + "tool_filter", 0, this, + TQT_SLOT(activate()), collection, + name()); + TQ_CHECK_PTR(m_action); + m_action->setToolTip(i18n("Paint with filters")); + m_action->setExclusiveGroup("tools"); + m_ownAction = true; + } +} + +void KisToolFilter::initPaint(KisEvent *e) +{ + // Some filters want to paint directly on the current state of + // the canvas, others cannot handle that and need a temporary layer + // so they can work on the old data before painting started. + m_paintIncremental = m_filter->supportsIncrementalPainting(); + + super::initPaint(e); + KisPaintOp * op = KisPaintOpRegistry::instance()->paintOp("filter", 0, painter()); + op->setSource ( m_source ); + painter()->setPaintOp(op); // And now the painter owns the op and will destroy it. + painter()->setFilter( m_filter ); + + // XXX: Isn't there a better way to set the config? The filter config widget needs to + // to go into the tool options widget, and just the data carried over to the filter. + // I've got a bit of a problem with core classes having too much GUI about them. + // BSAR. + dynamic_cast(op)->setFilterConfiguration( m_filter->configuration( m_filterConfigurationWidget) ); +} + +TQWidget* KisToolFilter::createOptionWidget(TQWidget* parent) +{ + TQWidget *widget = super::createOptionWidget(parent); + + m_cbFilter = new KisCmbIDList(widget); + TQ_CHECK_PTR(m_cbFilter); + + TQLabel* lbFilter = new TQLabel(i18n("Filter:"), widget); + TQ_CHECK_PTR(lbFilter); + + // Check which filters support painting + KisIDList l = KisFilterRegistry::instance()->listKeys(); + KisIDList l2; + KisIDList::iterator it; + for (it = l.begin(); it != l.end(); ++it) { + KisFilterSP f = KisFilterRegistry::instance()->get(*it); + if (f->supportsPainting()) { + l2.push_back(*it); + } + } + m_cbFilter ->setIDList( l2 ); + + addOptionWidgetOption(m_cbFilter, lbFilter); + + m_optionLayout = new TQGridLayout(widget, 1, 1, 0, 6); + TQ_CHECK_PTR(m_optionLayout); + super::addOptionWidgetLayout(m_optionLayout); + + connect(m_cbFilter, TQT_SIGNAL(activated ( const KisID& )), this, TQT_SLOT( changeFilter( const KisID& ) ) ); + changeFilter( m_cbFilter->currentItem () ); + + return widget; +} + +void KisToolFilter::changeFilter( const KisID & id) +{ + m_filter = KisFilterRegistry::instance()->get( id ); + Q_ASSERT(m_filter != 0); + if( m_filterConfigurationWidget != 0 ) + { + m_optionLayout->remove ( m_filterConfigurationWidget ); + delete m_filterConfigurationWidget; + } + + m_source = m_currentImage->activeDevice(); + if (!m_source) return; + + m_filterConfigurationWidget = m_filter->createConfigurationWidget( optionWidget(), m_source ); + if( m_filterConfigurationWidget != 0 ) + { + m_optionLayout->addMultiCellWidget ( m_filterConfigurationWidget, 2, 2, 0, 1 ); + m_filterConfigurationWidget->show(); + } +} + +#include "kis_tool_filter.moc" diff --git a/chalk/plugins/tools/tool_filter/tool_filter.cc b/chalk/plugins/tools/tool_filter/tool_filter.cc deleted file mode 100644 index bda2357e3..000000000 --- a/chalk/plugins/tools/tool_filter/tool_filter.cc +++ /dev/null @@ -1,68 +0,0 @@ -/* - * tool_filter.cc -- Part of Chalk - * - * Copyright (c) 2004 Boudewijn Rempt (boud@valdyas.org) - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -#include -#include - -#include - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include "tool_filter.h" -#include "kis_filterop.h" -#include "kis_tool_filter.h" - - -typedef KGenericFactory ToolFilterFactory; -K_EXPORT_COMPONENT_FACTORY( chalktoolfilter, ToolFilterFactory( "chalk" ) ) - - -ToolFilter::ToolFilter(TQObject *parent, const char *name, const TQStringList &) - : KParts::Plugin(parent, name) -{ - setInstance(ToolFilterFactory::instance()); - - if ( parent->inherits("KisToolRegistry") ) - { - KisToolRegistry * r = dynamic_cast(parent); - r->add( new KisToolFilterFactory()); - - // XXX: Put this in a separate plugin? - KisPaintOpRegistry * pr = KisPaintOpRegistry::instance(); - pr->add( new KisFilterOpFactory ); - - } -} - -ToolFilter::~ToolFilter() -{ -} - -#include "tool_filter.moc" diff --git a/chalk/plugins/tools/tool_filter/tool_filter.cpp b/chalk/plugins/tools/tool_filter/tool_filter.cpp new file mode 100644 index 000000000..484a7d9f3 --- /dev/null +++ b/chalk/plugins/tools/tool_filter/tool_filter.cpp @@ -0,0 +1,68 @@ +/* + * tool_filter.cpp -- Part of Chalk + * + * Copyright (c) 2004 Boudewijn Rempt (boud@valdyas.org) + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "tool_filter.h" +#include "kis_filterop.h" +#include "kis_tool_filter.h" + + +typedef KGenericFactory ToolFilterFactory; +K_EXPORT_COMPONENT_FACTORY( chalktoolfilter, ToolFilterFactory( "chalk" ) ) + + +ToolFilter::ToolFilter(TQObject *parent, const char *name, const TQStringList &) + : KParts::Plugin(parent, name) +{ + setInstance(ToolFilterFactory::instance()); + + if ( parent->inherits("KisToolRegistry") ) + { + KisToolRegistry * r = dynamic_cast(parent); + r->add( new KisToolFilterFactory()); + + // XXX: Put this in a separate plugin? + KisPaintOpRegistry * pr = KisPaintOpRegistry::instance(); + pr->add( new KisFilterOpFactory ); + + } +} + +ToolFilter::~ToolFilter() +{ +} + +#include "tool_filter.moc" diff --git a/chalk/plugins/tools/tool_perspectivegrid/Makefile.am b/chalk/plugins/tools/tool_perspectivegrid/Makefile.am index 8544c078a..c15df2687 100644 --- a/chalk/plugins/tools/tool_perspectivegrid/Makefile.am +++ b/chalk/plugins/tools/tool_perspectivegrid/Makefile.am @@ -10,8 +10,8 @@ INCLUDES = -I$(srcdir)/../../../sdk \ $(all_includes) chalktoolperspectivegrid_la_SOURCES = \ - tool_perspectivegrid.cc \ - kis_tool_perspectivegrid.cc + tool_perspectivegrid.cpp \ + kis_tool_perspectivegrid.cpp # Install this plugin in the KDE modules directory kde_module_LTLIBRARIES = chalktoolperspectivegrid.la diff --git a/chalk/plugins/tools/tool_perspectivegrid/kis_tool_perspectivegrid.cc b/chalk/plugins/tools/tool_perspectivegrid/kis_tool_perspectivegrid.cc deleted file mode 100644 index 2dbe56d3d..000000000 --- a/chalk/plugins/tools/tool_perspectivegrid/kis_tool_perspectivegrid.cc +++ /dev/null @@ -1,499 +0,0 @@ -/* - * kis_tool_perspectivegrid.cc - part of Chalk - * - * Copyright (c) 2006 Cyrille Berger - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -#include - -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -KisToolPerspectiveGrid::KisToolPerspectiveGrid() - : super(i18n("Perspective Grid")), m_handleSize(13), m_handleHalfSize(6) - -{ - setName("tool_perspectivegrid"); - - m_subject = 0; - m_dragging = false; -} - -KisToolPerspectiveGrid::~KisToolPerspectiveGrid() -{ -} - -void KisToolPerspectiveGrid::activate() -{ - m_subject->perspectiveGridManager()->startEdition(); - if( ! m_subject->currentImg()->perspectiveGrid()->hasSubGrids() ) - { - m_mode = MODE_CREATION; - m_points.clear(); - } else { - m_mode = MODE_EDITING; - drawGrid(); - } - super::activate(); -} - -void KisToolPerspectiveGrid::deactivate() -{ - m_subject->perspectiveGridManager()->stopEdition(); - m_subject->perspectiveGridManager()->setGridVisible( true); - if( m_mode == MODE_CREATION ) - { - drawGridCreation(); - m_points.clear(); - m_dragging = false; - } else { - drawGrid(); - } -} - - -void KisToolPerspectiveGrid::update (KisCanvasSubject *subject) -{ - m_subject = subject; - super::update(m_subject); -} - -bool KisToolPerspectiveGrid::mouseNear(const TQPoint& mousep, const TQPoint point) -{ - return (TQRect( (point.x() - m_handleHalfSize), (point.y() - m_handleHalfSize), m_handleSize, m_handleSize).contains(mousep) ); -} - -void KisToolPerspectiveGrid::buttonPress(KisButtonPressEvent *event) -{ - KisPerspectiveGrid* pGrid = m_subject->currentImg()->perspectiveGrid(); - if(!pGrid->hasSubGrids() && m_mode != MODE_CREATION) - { // it's possible that the perspectiv grid was cleared - m_mode = MODE_CREATION; - m_points.clear(); - } - if( m_mode == MODE_CREATION && event->button() == Qt::LeftButton) - { - m_dragging = true; - - if (m_points.isEmpty()) - { - m_dragStart = event->pos(); - m_dragEnd = event->pos(); - m_points.append(m_dragStart); - } else { - m_dragStart = m_dragEnd; - m_dragEnd = event->pos(); - drawGridCreation(); - } - } else if(m_mode == MODE_EDITING && event->button() == Qt::LeftButton){ - // Look for the handle which was pressed - if (!m_subject) - return; - KisCanvasController *controller = m_subject->canvasController(); - Q_ASSERT(controller); - TQPoint mousep = controller->windowToView( event->pos().roundTQPoint() ); - - for( TQValueList::const_iterator it = pGrid->begin(); it != pGrid->end(); ++it) - { - KisSubPerspectiveGrid* grid = *it; - if( mouseNear( mousep, controller->windowToView(grid->topLeft()->roundTQPoint() ) ) ) - { - kdDebug() << " PRESS TOPLEFT HANDLE " << endl; - m_mode = MODE_DRAGING_NODE; - m_selectedNode1 = grid->topLeft(); - break; - } - else if( mouseNear( mousep, controller->windowToView(grid->topRight()->roundTQPoint() ) ) ) - { - kdDebug() << " PRESS TOPRIGHT HANDLE " << endl; - m_mode = MODE_DRAGING_NODE; - m_selectedNode1 = grid->topRight(); - break; - } - else if( mouseNear( mousep, controller->windowToView(grid->bottomLeft()->roundTQPoint() ) ) ) - { - kdDebug() << " PRESS BOTTOMLEFT HANDLE " << endl; - m_mode = MODE_DRAGING_NODE; - m_selectedNode1 = grid->bottomLeft(); - break; - } - else if( mouseNear( mousep, controller->windowToView(grid->bottomRight()->roundTQPoint() ) ) ) - { - kdDebug() << " PRESS BOTTOMRIGHT HANDLE " << endl; - m_mode = MODE_DRAGING_NODE; - m_selectedNode1 = grid->bottomRight(); - break; - } - else if( !grid->leftGrid() && mouseNear( mousep, controller->windowToView( ((*grid->topLeft() + *grid->bottomLeft() )*0.5) ).roundTQPoint() ) ) - { - kdDebug() << " PRESS LEFT HANDLE " << endl; - m_mode = MODE_DRAGING_TRANSLATING_TWONODES; - drawGrid(); - m_selectedNode1 = new KisPerspectiveGridNode( *grid->topLeft() ); - m_selectedNode2 = new KisPerspectiveGridNode( *grid->bottomLeft() ); - KisSubPerspectiveGrid* newsubgrid = new KisSubPerspectiveGrid( m_selectedNode1, grid->topLeft() , grid->bottomLeft(), m_selectedNode2); - m_dragEnd = event->pos(); - newsubgrid->setRightGrid( grid); - grid->setLeftGrid( newsubgrid); - pGrid->addNewSubGrid( newsubgrid); - drawGrid(); - break; - } - else if( !grid->rightGrid() && mouseNear( mousep, controller->windowToView( ((*grid->topRight() + *grid->bottomRight() )*0.5) ).roundTQPoint() ) ) - { - kdDebug() << " PRESS RIGHT HANDLE " << endl; - m_mode = MODE_DRAGING_TRANSLATING_TWONODES; - drawGrid(); - m_selectedNode1 = new KisPerspectiveGridNode( *grid->topRight() ); - m_selectedNode2 = new KisPerspectiveGridNode( *grid->bottomRight() ); - KisSubPerspectiveGrid* newsubgrid = new KisSubPerspectiveGrid( grid->topRight(), m_selectedNode1, m_selectedNode2, grid->bottomRight()); - m_dragEnd = event->pos(); - newsubgrid->setLeftGrid( grid); - grid->setRightGrid( newsubgrid); - pGrid->addNewSubGrid( newsubgrid); - drawGrid(); - break; - } - else if( !grid->topGrid() && mouseNear( mousep, controller->windowToView( ((*grid->topLeft() + *grid->topRight() )*0.5) ).roundTQPoint() ) ) - { - kdDebug() << " PRESS TOP HANDLE " << endl; - m_mode = MODE_DRAGING_TRANSLATING_TWONODES; - drawGrid(); - m_selectedNode1 = new KisPerspectiveGridNode( *grid->topLeft() ); - m_selectedNode2 = new KisPerspectiveGridNode( *grid->topRight() ); - KisSubPerspectiveGrid* newsubgrid = new KisSubPerspectiveGrid( m_selectedNode1, m_selectedNode2, grid->topRight(), grid->topLeft() ); - m_dragEnd = event->pos(); - newsubgrid->setBottomGrid( grid); - grid->setTopGrid( newsubgrid); - pGrid->addNewSubGrid( newsubgrid); - drawGrid(); - break; - } - else if( !grid->bottomGrid() && mouseNear( mousep, controller->windowToView( ((*grid->bottomLeft() + *grid->bottomRight() )*0.5) ).roundTQPoint() ) ) - { - kdDebug() << " PRESS BOTTOM HANDLE " << endl; - m_mode = MODE_DRAGING_TRANSLATING_TWONODES; - drawGrid(); - m_selectedNode1 = new KisPerspectiveGridNode( *grid->bottomLeft() ); - m_selectedNode2 = new KisPerspectiveGridNode( *grid->bottomRight() ); - KisSubPerspectiveGrid* newsubgrid = new KisSubPerspectiveGrid( grid->bottomLeft(), grid->bottomRight(), m_selectedNode2, m_selectedNode1); - m_dragEnd = event->pos(); - newsubgrid->setTopGrid( grid); - grid->setBottomGrid( newsubgrid); - pGrid->addNewSubGrid( newsubgrid); - drawGrid(); - break; - } - } - } -} - - -void KisToolPerspectiveGrid::move(KisMoveEvent *event) -{ - if( m_mode == MODE_CREATION ) - { - if (m_dragging) { - // erase old lines on canvas - drawGridCreation(); - // get current mouse position - m_dragEnd = event->pos(); - // draw new lines on canvas - drawGridCreation(); - } - } else { - if( m_mode == MODE_DRAGING_NODE) - { - drawGrid(); - m_selectedNode1->setX( event->pos().x() ); - m_selectedNode1->setY( event->pos().y() ); - drawGrid(); - } - if( m_mode == MODE_DRAGING_TRANSLATING_TWONODES) - { - drawGrid(); - KisPoint translate = event->pos() - m_dragEnd; - m_dragEnd = event->pos(); - *m_selectedNode1 += translate;; - *m_selectedNode2 += translate;; - drawGrid(); - } - } -} - -void KisToolPerspectiveGrid::buttonRelease(KisButtonReleaseEvent *event) -{ - if (!m_subject) - return; - - if( m_mode == MODE_CREATION ) - { - if (m_dragging && event->button() == Qt::LeftButton) { - m_dragging = false; - m_points.append (m_dragEnd); - if( m_points.size() == 4) - { // wow we have a grid, isn't that cool ? - drawGridCreation(); // Clean - m_subject->currentImg()->perspectiveGrid()->addNewSubGrid( new KisSubPerspectiveGrid( new KisPerspectiveGridNode(m_points[0]), new KisPerspectiveGridNode(m_points[1]), new KisPerspectiveGridNode(m_points[2]), new KisPerspectiveGridNode(m_points[3]) ) ); - drawGrid(); - m_mode = MODE_EDITING; - } - } - } else { - m_mode = MODE_EDITING; - m_selectedNode1 = 0; - m_selectedNode2 = 0; - } - -/* if (m_dragging && event->button() == RightButton) { - - }*/ -} - -void KisToolPerspectiveGrid::paint(KisCanvasPainter& gc) -{ - if( m_mode == MODE_CREATION ) - { - drawGridCreation(gc); - } else { - drawGrid(gc); - } -} - -void KisToolPerspectiveGrid::paint(KisCanvasPainter& gc, const TQRect&) -{ - if( m_mode == MODE_CREATION ) - { - drawGridCreation(gc); - } else { - drawGrid(gc); - } -} - -void KisToolPerspectiveGrid::drawGridCreation() -{ - if (m_subject) { - KisCanvasController *controller = m_subject->canvasController(); - KisCanvas *canvas = controller->kiscanvas(); - KisCanvasPainter gc(canvas); - - drawGridCreation(gc); - } -} - - -void KisToolPerspectiveGrid::drawGridCreation(KisCanvasPainter& gc) -{ - if (!m_subject) - return; - - TQPen pen(TQt::white); - - gc.setPen(pen); - gc.setRasterOp(TQt::XorROP); - - KisCanvasController *controller = m_subject->canvasController(); - KisPoint start, end; - TQPoint startPos; - TQPoint endPos; - - if (m_dragging) { - startPos = controller->windowToView(m_dragStart.floorTQPoint()); - endPos = controller->windowToView(m_dragEnd.floorTQPoint()); - gc.drawLine(startPos, endPos); - } else { - for (KisPointVector::iterator it = m_points.begin(); it != m_points.end(); ++it) { - - if (it == m_points.begin()) - { - start = (*it); - } else { - end = (*it); - - startPos = controller->windowToView(start.floorTQPoint()); - endPos = controller->windowToView(end.floorTQPoint()); - - gc.drawLine(startPos, endPos); - - start = end; - } - } - } -} - -void KisToolPerspectiveGrid::drawSmallRectangle(KisCanvasPainter& gc, TQPoint p) -{ - gc.drawRect( p.x() - m_handleHalfSize - 1, p.y() - m_handleHalfSize - 1, m_handleSize, m_handleSize); -} - -void KisToolPerspectiveGrid::drawGrid(KisCanvasPainter& gc) -{ - - if (!m_subject) - return; - - KisCanvasController *controller = m_subject->canvasController(); - - TQPen pen(TQt::white); - TQPoint startPos; - TQPoint endPos; - - gc.setPen(pen); - gc.setRasterOp(TQt::XorROP); - KisPerspectiveGrid* pGrid = m_subject->currentImg()->perspectiveGrid(); - - for( TQValueList::const_iterator it = pGrid->begin(); it != pGrid->end(); ++it) - { - KisSubPerspectiveGrid* grid = *it; - int index = grid->index(); - bool drawLeft = !(grid->leftGrid() && (index > grid->leftGrid()->index() ) ); - bool drawRight = !(grid->rightGrid() && (index > grid->rightGrid()->index() ) ); - bool drawTop = !(grid->topGrid() && (index > grid->topGrid()->index() ) ); - bool drawBottom = !(grid->bottomGrid() && (index > grid->bottomGrid()->index() ) ); - if(drawTop) { - startPos = controller->windowToView(grid->topLeft()->roundTQPoint()); - endPos = controller->windowToView(grid->topRight()->roundTQPoint()); - gc.drawLine( startPos, endPos ); - if( !grid->topGrid() ) - { - drawSmallRectangle(gc, (endPos + startPos) / 2); - } - if(drawLeft) { - drawSmallRectangle(gc, startPos); - } - if(drawRight) { - drawSmallRectangle(gc, endPos); - } - } - if(drawRight) { - startPos = controller->windowToView(grid->topRight()->roundTQPoint()); - endPos = controller->windowToView(grid->bottomRight()->roundTQPoint()); - gc.drawLine( startPos, endPos ); - if( !grid->rightGrid() ) - { - drawSmallRectangle(gc, (endPos + startPos) / 2); - } - } - if(drawBottom) { - startPos = controller->windowToView(grid->bottomRight()->roundTQPoint()); - endPos = controller->windowToView(grid->bottomLeft()->roundTQPoint()); - gc.drawLine( startPos, endPos ); - if( !grid->bottomGrid() ) - { - drawSmallRectangle(gc, (endPos + startPos) / 2); - } - if(drawLeft) { - drawSmallRectangle(gc, endPos); - } - if(drawRight) { - drawSmallRectangle(gc, startPos); - } - } - if(drawLeft) { - startPos = controller->windowToView(grid->bottomLeft()->roundTQPoint()); - endPos = controller->windowToView(grid->topLeft()->roundTQPoint()); - gc.drawLine( startPos, endPos ); - if( !grid->leftGrid() ) - { - drawSmallRectangle(gc, (endPos + startPos) / 2); - } - } - KisPoint tbVpf = grid->topBottomVanishingPoint(); - if( fabs(tbVpf.x()) < 30000000. && fabs(tbVpf.y()) < 30000000.) - { - TQPoint tbVp = controller->windowToView(tbVpf.roundTQPoint()); - gc.drawLine( tbVp.x() - m_handleHalfSize, tbVp.y() - m_handleHalfSize, tbVp.x() + m_handleHalfSize, tbVp.y() + m_handleHalfSize); - gc.drawLine( tbVp.x() - m_handleHalfSize, tbVp.y() + m_handleHalfSize, tbVp.x() + m_handleHalfSize, tbVp.y() - m_handleHalfSize); - } - KisPoint lrVpf = grid->leftRightVanishingPoint(); - if( fabs(lrVpf.x()) < 30000000. && fabs(lrVpf.y()) < 30000000.) - { // Don't display it, if it is too far, or you get funny results - TQPoint lrVp = controller->windowToView(lrVpf.roundTQPoint()); - gc.drawLine( lrVp.x() - m_handleHalfSize, lrVp.y() - m_handleHalfSize, lrVp.x() + m_handleHalfSize, lrVp.y() + m_handleHalfSize); - gc.drawLine( lrVp.x() - m_handleHalfSize, lrVp.y() + m_handleHalfSize, lrVp.x() + m_handleHalfSize, lrVp.y() - m_handleHalfSize); - } - } -} - -void KisToolPerspectiveGrid::drawGrid() -{ - if (m_subject) { - KisCanvasController *controller = m_subject->canvasController(); - KisCanvas *canvas = controller->kiscanvas(); - KisCanvasPainter gc(canvas); - - drawGrid(gc); - } - -} - - -void KisToolPerspectiveGrid::setup(TDEActionCollection *collection) -{ - m_action = static_cast(collection->action(name())); - - if (m_action == 0) { - m_action = new TDERadioAction(i18n("&Perspective Grid"), - "tool_perspectivegrid" , - 0, - this, - TQT_SLOT(activate()), - collection, - name()); - TQ_CHECK_PTR(m_action); - m_action->setExclusiveGroup("tools"); - m_action->setToolTip(i18n("Edit the perspective grid")); - m_ownAction = true; - } -} - - -// TQWidget* KisToolPerspectiveGrid::createOptionWidget(TQWidget* parent) -// { -// return 0; -// } -// -// TQWidget* KisToolPerspectiveGrid::optionWidget() -// { -// return 0; -// } - - -#include "kis_tool_perspectivegrid.moc" diff --git a/chalk/plugins/tools/tool_perspectivegrid/kis_tool_perspectivegrid.cpp b/chalk/plugins/tools/tool_perspectivegrid/kis_tool_perspectivegrid.cpp new file mode 100644 index 000000000..7d5df0f2b --- /dev/null +++ b/chalk/plugins/tools/tool_perspectivegrid/kis_tool_perspectivegrid.cpp @@ -0,0 +1,499 @@ +/* + * kis_tool_perspectivegrid.cpp - part of Chalk + * + * Copyright (c) 2006 Cyrille Berger + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +KisToolPerspectiveGrid::KisToolPerspectiveGrid() + : super(i18n("Perspective Grid")), m_handleSize(13), m_handleHalfSize(6) + +{ + setName("tool_perspectivegrid"); + + m_subject = 0; + m_dragging = false; +} + +KisToolPerspectiveGrid::~KisToolPerspectiveGrid() +{ +} + +void KisToolPerspectiveGrid::activate() +{ + m_subject->perspectiveGridManager()->startEdition(); + if( ! m_subject->currentImg()->perspectiveGrid()->hasSubGrids() ) + { + m_mode = MODE_CREATION; + m_points.clear(); + } else { + m_mode = MODE_EDITING; + drawGrid(); + } + super::activate(); +} + +void KisToolPerspectiveGrid::deactivate() +{ + m_subject->perspectiveGridManager()->stopEdition(); + m_subject->perspectiveGridManager()->setGridVisible( true); + if( m_mode == MODE_CREATION ) + { + drawGridCreation(); + m_points.clear(); + m_dragging = false; + } else { + drawGrid(); + } +} + + +void KisToolPerspectiveGrid::update (KisCanvasSubject *subject) +{ + m_subject = subject; + super::update(m_subject); +} + +bool KisToolPerspectiveGrid::mouseNear(const TQPoint& mousep, const TQPoint point) +{ + return (TQRect( (point.x() - m_handleHalfSize), (point.y() - m_handleHalfSize), m_handleSize, m_handleSize).contains(mousep) ); +} + +void KisToolPerspectiveGrid::buttonPress(KisButtonPressEvent *event) +{ + KisPerspectiveGrid* pGrid = m_subject->currentImg()->perspectiveGrid(); + if(!pGrid->hasSubGrids() && m_mode != MODE_CREATION) + { // it's possible that the perspectiv grid was cleared + m_mode = MODE_CREATION; + m_points.clear(); + } + if( m_mode == MODE_CREATION && event->button() == Qt::LeftButton) + { + m_dragging = true; + + if (m_points.isEmpty()) + { + m_dragStart = event->pos(); + m_dragEnd = event->pos(); + m_points.append(m_dragStart); + } else { + m_dragStart = m_dragEnd; + m_dragEnd = event->pos(); + drawGridCreation(); + } + } else if(m_mode == MODE_EDITING && event->button() == Qt::LeftButton){ + // Look for the handle which was pressed + if (!m_subject) + return; + KisCanvasController *controller = m_subject->canvasController(); + Q_ASSERT(controller); + TQPoint mousep = controller->windowToView( event->pos().roundTQPoint() ); + + for( TQValueList::const_iterator it = pGrid->begin(); it != pGrid->end(); ++it) + { + KisSubPerspectiveGrid* grid = *it; + if( mouseNear( mousep, controller->windowToView(grid->topLeft()->roundTQPoint() ) ) ) + { + kdDebug() << " PRESS TOPLEFT HANDLE " << endl; + m_mode = MODE_DRAGING_NODE; + m_selectedNode1 = grid->topLeft(); + break; + } + else if( mouseNear( mousep, controller->windowToView(grid->topRight()->roundTQPoint() ) ) ) + { + kdDebug() << " PRESS TOPRIGHT HANDLE " << endl; + m_mode = MODE_DRAGING_NODE; + m_selectedNode1 = grid->topRight(); + break; + } + else if( mouseNear( mousep, controller->windowToView(grid->bottomLeft()->roundTQPoint() ) ) ) + { + kdDebug() << " PRESS BOTTOMLEFT HANDLE " << endl; + m_mode = MODE_DRAGING_NODE; + m_selectedNode1 = grid->bottomLeft(); + break; + } + else if( mouseNear( mousep, controller->windowToView(grid->bottomRight()->roundTQPoint() ) ) ) + { + kdDebug() << " PRESS BOTTOMRIGHT HANDLE " << endl; + m_mode = MODE_DRAGING_NODE; + m_selectedNode1 = grid->bottomRight(); + break; + } + else if( !grid->leftGrid() && mouseNear( mousep, controller->windowToView( ((*grid->topLeft() + *grid->bottomLeft() )*0.5) ).roundTQPoint() ) ) + { + kdDebug() << " PRESS LEFT HANDLE " << endl; + m_mode = MODE_DRAGING_TRANSLATING_TWONODES; + drawGrid(); + m_selectedNode1 = new KisPerspectiveGridNode( *grid->topLeft() ); + m_selectedNode2 = new KisPerspectiveGridNode( *grid->bottomLeft() ); + KisSubPerspectiveGrid* newsubgrid = new KisSubPerspectiveGrid( m_selectedNode1, grid->topLeft() , grid->bottomLeft(), m_selectedNode2); + m_dragEnd = event->pos(); + newsubgrid->setRightGrid( grid); + grid->setLeftGrid( newsubgrid); + pGrid->addNewSubGrid( newsubgrid); + drawGrid(); + break; + } + else if( !grid->rightGrid() && mouseNear( mousep, controller->windowToView( ((*grid->topRight() + *grid->bottomRight() )*0.5) ).roundTQPoint() ) ) + { + kdDebug() << " PRESS RIGHT HANDLE " << endl; + m_mode = MODE_DRAGING_TRANSLATING_TWONODES; + drawGrid(); + m_selectedNode1 = new KisPerspectiveGridNode( *grid->topRight() ); + m_selectedNode2 = new KisPerspectiveGridNode( *grid->bottomRight() ); + KisSubPerspectiveGrid* newsubgrid = new KisSubPerspectiveGrid( grid->topRight(), m_selectedNode1, m_selectedNode2, grid->bottomRight()); + m_dragEnd = event->pos(); + newsubgrid->setLeftGrid( grid); + grid->setRightGrid( newsubgrid); + pGrid->addNewSubGrid( newsubgrid); + drawGrid(); + break; + } + else if( !grid->topGrid() && mouseNear( mousep, controller->windowToView( ((*grid->topLeft() + *grid->topRight() )*0.5) ).roundTQPoint() ) ) + { + kdDebug() << " PRESS TOP HANDLE " << endl; + m_mode = MODE_DRAGING_TRANSLATING_TWONODES; + drawGrid(); + m_selectedNode1 = new KisPerspectiveGridNode( *grid->topLeft() ); + m_selectedNode2 = new KisPerspectiveGridNode( *grid->topRight() ); + KisSubPerspectiveGrid* newsubgrid = new KisSubPerspectiveGrid( m_selectedNode1, m_selectedNode2, grid->topRight(), grid->topLeft() ); + m_dragEnd = event->pos(); + newsubgrid->setBottomGrid( grid); + grid->setTopGrid( newsubgrid); + pGrid->addNewSubGrid( newsubgrid); + drawGrid(); + break; + } + else if( !grid->bottomGrid() && mouseNear( mousep, controller->windowToView( ((*grid->bottomLeft() + *grid->bottomRight() )*0.5) ).roundTQPoint() ) ) + { + kdDebug() << " PRESS BOTTOM HANDLE " << endl; + m_mode = MODE_DRAGING_TRANSLATING_TWONODES; + drawGrid(); + m_selectedNode1 = new KisPerspectiveGridNode( *grid->bottomLeft() ); + m_selectedNode2 = new KisPerspectiveGridNode( *grid->bottomRight() ); + KisSubPerspectiveGrid* newsubgrid = new KisSubPerspectiveGrid( grid->bottomLeft(), grid->bottomRight(), m_selectedNode2, m_selectedNode1); + m_dragEnd = event->pos(); + newsubgrid->setTopGrid( grid); + grid->setBottomGrid( newsubgrid); + pGrid->addNewSubGrid( newsubgrid); + drawGrid(); + break; + } + } + } +} + + +void KisToolPerspectiveGrid::move(KisMoveEvent *event) +{ + if( m_mode == MODE_CREATION ) + { + if (m_dragging) { + // erase old lines on canvas + drawGridCreation(); + // get current mouse position + m_dragEnd = event->pos(); + // draw new lines on canvas + drawGridCreation(); + } + } else { + if( m_mode == MODE_DRAGING_NODE) + { + drawGrid(); + m_selectedNode1->setX( event->pos().x() ); + m_selectedNode1->setY( event->pos().y() ); + drawGrid(); + } + if( m_mode == MODE_DRAGING_TRANSLATING_TWONODES) + { + drawGrid(); + KisPoint translate = event->pos() - m_dragEnd; + m_dragEnd = event->pos(); + *m_selectedNode1 += translate;; + *m_selectedNode2 += translate;; + drawGrid(); + } + } +} + +void KisToolPerspectiveGrid::buttonRelease(KisButtonReleaseEvent *event) +{ + if (!m_subject) + return; + + if( m_mode == MODE_CREATION ) + { + if (m_dragging && event->button() == Qt::LeftButton) { + m_dragging = false; + m_points.append (m_dragEnd); + if( m_points.size() == 4) + { // wow we have a grid, isn't that cool ? + drawGridCreation(); // Clean + m_subject->currentImg()->perspectiveGrid()->addNewSubGrid( new KisSubPerspectiveGrid( new KisPerspectiveGridNode(m_points[0]), new KisPerspectiveGridNode(m_points[1]), new KisPerspectiveGridNode(m_points[2]), new KisPerspectiveGridNode(m_points[3]) ) ); + drawGrid(); + m_mode = MODE_EDITING; + } + } + } else { + m_mode = MODE_EDITING; + m_selectedNode1 = 0; + m_selectedNode2 = 0; + } + +/* if (m_dragging && event->button() == RightButton) { + + }*/ +} + +void KisToolPerspectiveGrid::paint(KisCanvasPainter& gc) +{ + if( m_mode == MODE_CREATION ) + { + drawGridCreation(gc); + } else { + drawGrid(gc); + } +} + +void KisToolPerspectiveGrid::paint(KisCanvasPainter& gc, const TQRect&) +{ + if( m_mode == MODE_CREATION ) + { + drawGridCreation(gc); + } else { + drawGrid(gc); + } +} + +void KisToolPerspectiveGrid::drawGridCreation() +{ + if (m_subject) { + KisCanvasController *controller = m_subject->canvasController(); + KisCanvas *canvas = controller->kiscanvas(); + KisCanvasPainter gc(canvas); + + drawGridCreation(gc); + } +} + + +void KisToolPerspectiveGrid::drawGridCreation(KisCanvasPainter& gc) +{ + if (!m_subject) + return; + + TQPen pen(TQt::white); + + gc.setPen(pen); + gc.setRasterOp(TQt::XorROP); + + KisCanvasController *controller = m_subject->canvasController(); + KisPoint start, end; + TQPoint startPos; + TQPoint endPos; + + if (m_dragging) { + startPos = controller->windowToView(m_dragStart.floorTQPoint()); + endPos = controller->windowToView(m_dragEnd.floorTQPoint()); + gc.drawLine(startPos, endPos); + } else { + for (KisPointVector::iterator it = m_points.begin(); it != m_points.end(); ++it) { + + if (it == m_points.begin()) + { + start = (*it); + } else { + end = (*it); + + startPos = controller->windowToView(start.floorTQPoint()); + endPos = controller->windowToView(end.floorTQPoint()); + + gc.drawLine(startPos, endPos); + + start = end; + } + } + } +} + +void KisToolPerspectiveGrid::drawSmallRectangle(KisCanvasPainter& gc, TQPoint p) +{ + gc.drawRect( p.x() - m_handleHalfSize - 1, p.y() - m_handleHalfSize - 1, m_handleSize, m_handleSize); +} + +void KisToolPerspectiveGrid::drawGrid(KisCanvasPainter& gc) +{ + + if (!m_subject) + return; + + KisCanvasController *controller = m_subject->canvasController(); + + TQPen pen(TQt::white); + TQPoint startPos; + TQPoint endPos; + + gc.setPen(pen); + gc.setRasterOp(TQt::XorROP); + KisPerspectiveGrid* pGrid = m_subject->currentImg()->perspectiveGrid(); + + for( TQValueList::const_iterator it = pGrid->begin(); it != pGrid->end(); ++it) + { + KisSubPerspectiveGrid* grid = *it; + int index = grid->index(); + bool drawLeft = !(grid->leftGrid() && (index > grid->leftGrid()->index() ) ); + bool drawRight = !(grid->rightGrid() && (index > grid->rightGrid()->index() ) ); + bool drawTop = !(grid->topGrid() && (index > grid->topGrid()->index() ) ); + bool drawBottom = !(grid->bottomGrid() && (index > grid->bottomGrid()->index() ) ); + if(drawTop) { + startPos = controller->windowToView(grid->topLeft()->roundTQPoint()); + endPos = controller->windowToView(grid->topRight()->roundTQPoint()); + gc.drawLine( startPos, endPos ); + if( !grid->topGrid() ) + { + drawSmallRectangle(gc, (endPos + startPos) / 2); + } + if(drawLeft) { + drawSmallRectangle(gc, startPos); + } + if(drawRight) { + drawSmallRectangle(gc, endPos); + } + } + if(drawRight) { + startPos = controller->windowToView(grid->topRight()->roundTQPoint()); + endPos = controller->windowToView(grid->bottomRight()->roundTQPoint()); + gc.drawLine( startPos, endPos ); + if( !grid->rightGrid() ) + { + drawSmallRectangle(gc, (endPos + startPos) / 2); + } + } + if(drawBottom) { + startPos = controller->windowToView(grid->bottomRight()->roundTQPoint()); + endPos = controller->windowToView(grid->bottomLeft()->roundTQPoint()); + gc.drawLine( startPos, endPos ); + if( !grid->bottomGrid() ) + { + drawSmallRectangle(gc, (endPos + startPos) / 2); + } + if(drawLeft) { + drawSmallRectangle(gc, endPos); + } + if(drawRight) { + drawSmallRectangle(gc, startPos); + } + } + if(drawLeft) { + startPos = controller->windowToView(grid->bottomLeft()->roundTQPoint()); + endPos = controller->windowToView(grid->topLeft()->roundTQPoint()); + gc.drawLine( startPos, endPos ); + if( !grid->leftGrid() ) + { + drawSmallRectangle(gc, (endPos + startPos) / 2); + } + } + KisPoint tbVpf = grid->topBottomVanishingPoint(); + if( fabs(tbVpf.x()) < 30000000. && fabs(tbVpf.y()) < 30000000.) + { + TQPoint tbVp = controller->windowToView(tbVpf.roundTQPoint()); + gc.drawLine( tbVp.x() - m_handleHalfSize, tbVp.y() - m_handleHalfSize, tbVp.x() + m_handleHalfSize, tbVp.y() + m_handleHalfSize); + gc.drawLine( tbVp.x() - m_handleHalfSize, tbVp.y() + m_handleHalfSize, tbVp.x() + m_handleHalfSize, tbVp.y() - m_handleHalfSize); + } + KisPoint lrVpf = grid->leftRightVanishingPoint(); + if( fabs(lrVpf.x()) < 30000000. && fabs(lrVpf.y()) < 30000000.) + { // Don't display it, if it is too far, or you get funny results + TQPoint lrVp = controller->windowToView(lrVpf.roundTQPoint()); + gc.drawLine( lrVp.x() - m_handleHalfSize, lrVp.y() - m_handleHalfSize, lrVp.x() + m_handleHalfSize, lrVp.y() + m_handleHalfSize); + gc.drawLine( lrVp.x() - m_handleHalfSize, lrVp.y() + m_handleHalfSize, lrVp.x() + m_handleHalfSize, lrVp.y() - m_handleHalfSize); + } + } +} + +void KisToolPerspectiveGrid::drawGrid() +{ + if (m_subject) { + KisCanvasController *controller = m_subject->canvasController(); + KisCanvas *canvas = controller->kiscanvas(); + KisCanvasPainter gc(canvas); + + drawGrid(gc); + } + +} + + +void KisToolPerspectiveGrid::setup(TDEActionCollection *collection) +{ + m_action = static_cast(collection->action(name())); + + if (m_action == 0) { + m_action = new TDERadioAction(i18n("&Perspective Grid"), + "tool_perspectivegrid" , + 0, + this, + TQT_SLOT(activate()), + collection, + name()); + TQ_CHECK_PTR(m_action); + m_action->setExclusiveGroup("tools"); + m_action->setToolTip(i18n("Edit the perspective grid")); + m_ownAction = true; + } +} + + +// TQWidget* KisToolPerspectiveGrid::createOptionWidget(TQWidget* parent) +// { +// return 0; +// } +// +// TQWidget* KisToolPerspectiveGrid::optionWidget() +// { +// return 0; +// } + + +#include "kis_tool_perspectivegrid.moc" diff --git a/chalk/plugins/tools/tool_perspectivegrid/tool_perspectivegrid.cc b/chalk/plugins/tools/tool_perspectivegrid/tool_perspectivegrid.cc deleted file mode 100644 index f2800a594..000000000 --- a/chalk/plugins/tools/tool_perspectivegrid/tool_perspectivegrid.cc +++ /dev/null @@ -1,62 +0,0 @@ -/* - * tool_perspectivegrid.cc -- Part of Chalk - * - * Copyright (c) 2006 Cyrille Berger - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -#include -#include - -#include - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include "tool_perspectivegrid.h" -#include "kis_tool_perspectivegrid.h" - - -typedef KGenericFactory ToolPerspectiveGridFactory; -K_EXPORT_COMPONENT_FACTORY( chalktoolperspectivegrid, ToolPerspectiveGridFactory( "chalk" ) ) - - -ToolPerspectiveGrid::ToolPerspectiveGrid(TQObject *parent, const char *name, const TQStringList &) - : KParts::Plugin(parent, name) -{ - setInstance(ToolPerspectiveGridFactory::instance()); - - if ( parent->inherits("KisToolRegistry") ) - { - KisToolRegistry * r = dynamic_cast(parent); - r->add(new KisToolPerspectiveGridFactory()); - } - -} - -ToolPerspectiveGrid::~ToolPerspectiveGrid() -{ -} - -#include "tool_perspectivegrid.moc" diff --git a/chalk/plugins/tools/tool_perspectivegrid/tool_perspectivegrid.cpp b/chalk/plugins/tools/tool_perspectivegrid/tool_perspectivegrid.cpp new file mode 100644 index 000000000..2f326965b --- /dev/null +++ b/chalk/plugins/tools/tool_perspectivegrid/tool_perspectivegrid.cpp @@ -0,0 +1,62 @@ +/* + * tool_perspectivegrid.cpp -- Part of Chalk + * + * Copyright (c) 2006 Cyrille Berger + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "tool_perspectivegrid.h" +#include "kis_tool_perspectivegrid.h" + + +typedef KGenericFactory ToolPerspectiveGridFactory; +K_EXPORT_COMPONENT_FACTORY( chalktoolperspectivegrid, ToolPerspectiveGridFactory( "chalk" ) ) + + +ToolPerspectiveGrid::ToolPerspectiveGrid(TQObject *parent, const char *name, const TQStringList &) + : KParts::Plugin(parent, name) +{ + setInstance(ToolPerspectiveGridFactory::instance()); + + if ( parent->inherits("KisToolRegistry") ) + { + KisToolRegistry * r = dynamic_cast(parent); + r->add(new KisToolPerspectiveGridFactory()); + } + +} + +ToolPerspectiveGrid::~ToolPerspectiveGrid() +{ +} + +#include "tool_perspectivegrid.moc" diff --git a/chalk/plugins/tools/tool_perspectivetransform/Makefile.am b/chalk/plugins/tools/tool_perspectivetransform/Makefile.am index 08c8d7079..275f6413d 100644 --- a/chalk/plugins/tools/tool_perspectivetransform/Makefile.am +++ b/chalk/plugins/tools/tool_perspectivetransform/Makefile.am @@ -10,8 +10,8 @@ INCLUDES = -I$(srcdir)/../../../sdk \ $(all_includes) chalktoolperspectivetransform_la_SOURCES = \ - tool_perspectivetransform.cc \ - kis_tool_perspectivetransform.cc + tool_perspectivetransform.cpp \ + kis_tool_perspectivetransform.cpp # Install this plugin in the KDE modules directory kde_module_LTLIBRARIES = chalktoolperspectivetransform.la diff --git a/chalk/plugins/tools/tool_perspectivetransform/kis_tool_perspectivetransform.cc b/chalk/plugins/tools/tool_perspectivetransform/kis_tool_perspectivetransform.cc deleted file mode 100644 index ae334e627..000000000 --- a/chalk/plugins/tools/tool_perspectivetransform/kis_tool_perspectivetransform.cc +++ /dev/null @@ -1,742 +0,0 @@ -/* - * kis_tool_transform.cc -- part of Chalk - * - * Copyright (c) 2006 Cyrille Berger - * - * Based on the transform tool from : - * Copyright (c) 2004 Boudewijn Rempt - * Copyright (c) 2005 Casper Boemann - * - * 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; version 2 of the License. - * - * 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include "kis_tool_perspectivetransform.h" - - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -//#include "wdg_tool_transform.h" -#include "kis_canvas.h" -#include "kis_canvas_painter.h" - -namespace { - class PerspectiveTransformCmd : public KisSelectedTransaction { - typedef KisSelectedTransaction super; - - public: - PerspectiveTransformCmd(KisToolPerspectiveTransform *tool, KisPaintDeviceSP device, KisPaintDeviceSP origDevice, KisPoint topleft, KisPoint topright, KisPoint bottomleft, KisPoint bottomright, KisSelectionSP origSel, TQRect initialRect); - virtual ~PerspectiveTransformCmd(); - - public: - virtual void execute(); - virtual void unexecute(); - void transformArgs(KisPoint &topleft, KisPoint &topright, KisPoint &bottomleft, KisPoint& bottomright) const; - KisSelectionSP origSelection(TQRect& initialRect) const; - KisPaintDeviceSP theDevice(); - KisPaintDeviceSP origDevice(); - - private: - TQRect m_initialRect; - KisPoint m_topleft, m_topright, m_bottomleft, m_bottomright; - KisToolPerspectiveTransform *m_tool; - KisSelectionSP m_origSelection; - KisPaintDeviceSP m_device; - KisPaintDeviceSP m_origDevice; - }; - - PerspectiveTransformCmd::PerspectiveTransformCmd(KisToolPerspectiveTransform *tool, KisPaintDeviceSP device, KisPaintDeviceSP origDevice, KisPoint topleft, KisPoint topright, KisPoint bottomleft, KisPoint bottomright, KisSelectionSP origSel, TQRect initialRect) : - super(i18n("Perspective Transform"), device), m_initialRect(initialRect) - , m_topleft(topleft), m_topright(topright), m_bottomleft(bottomleft), m_bottomright(bottomright) - , m_tool(tool), m_origSelection(origSel), m_device(device), m_origDevice(origDevice) - { - } - - PerspectiveTransformCmd::~PerspectiveTransformCmd() - { - } - - void PerspectiveTransformCmd::transformArgs(KisPoint &topleft, KisPoint &topright, KisPoint &bottomleft, KisPoint& bottomright) const - { - topleft = m_topleft; - topright = m_topright; - bottomleft = m_bottomleft; - bottomright = m_bottomright; - } - - KisSelectionSP PerspectiveTransformCmd::origSelection(TQRect& initialRect) const - { - initialRect = m_initialRect; - return m_origSelection; - } - - void PerspectiveTransformCmd::execute() - { - super::execute(); - } - - void PerspectiveTransformCmd::unexecute() - { - super::unexecute(); - } - - KisPaintDeviceSP PerspectiveTransformCmd::theDevice() - { - return m_device; - } - - KisPaintDeviceSP PerspectiveTransformCmd::origDevice() - { - return m_origDevice; - } -} - -KisToolPerspectiveTransform::KisToolPerspectiveTransform() - : super(i18n("Perspective Transform")) -{ - setName("tool_perspectivetransform"); - setCursor(KisCursor::selectCursor()); - m_subject = 0; - m_origDevice = 0; - m_origSelection = 0; - m_handleHalfSize = 8; - m_handleSize = 2 * m_handleHalfSize; - m_handleSelected = NOHANDLE; -} - -KisToolPerspectiveTransform::~KisToolPerspectiveTransform() -{ -} - -void KisToolPerspectiveTransform::deactivate() -{ - if (m_subject && m_subject->undoAdapter()) m_subject->undoAdapter()->removeCommandHistoryListener( this ); - - KisImageSP img = m_subject->currentImg(); - if (!img) return; - - paintOutline(); - - disconnect(m_subject->currentImg().data(), TQT_SIGNAL(sigLayerActivated(KisLayerSP)), this, TQT_SLOT(slotLayerActivated(KisLayerSP))); -} - -void KisToolPerspectiveTransform::activate() -{ - super::activate(); - m_currentSelectedPoint = 0; - if(m_subject && m_subject->currentImg() && m_subject->currentImg()->activeDevice()) - { - //connect(m_subject, commandExecuted(KCommand *c), this, notifyCommandAdded( KCommand * c)); - m_subject->undoAdapter()->setCommandHistoryListener( this ); - -// KisToolControllerInterface *controller = m_subject->toolController(); -// if (controller) -// controller->setCurrentTool(this); - - PerspectiveTransformCmd * cmd=0; - - if(m_subject->currentImg()->undoAdapter()->presentCommand()) - cmd = dynamic_cast(m_subject->currentImg()->undoAdapter()->presentCommand()); - - // One of our commands is on top - if(cmd &&cmd->theDevice() == m_subject->currentImg()->activeDevice()) - { - m_interractionMode = EDITRECTINTERRACTION; - // and it even has the same device - // We should ask for tool args and orig selection - m_origDevice = cmd->origDevice(); - cmd->transformArgs(m_topleft, m_topright, m_bottomleft, m_bottomright); - m_origSelection = cmd->origSelection(m_initialRect); - paintOutline(); - } - else - { - m_interractionMode = DRAWRECTINTERRACTION; - m_points.clear(); - initHandles(); - } - } - connect(m_subject->currentImg(), TQT_SIGNAL(sigLayerActivated(KisLayerSP)), this, TQT_SLOT(slotLayerActivated(KisLayerSP))); -} - -void KisToolPerspectiveTransform::initHandles() -{ -// TQ_INT32 x,y,w,h; - KisImageSP img = m_subject->currentImg(); - - KisPaintDeviceSP dev = img->activeDevice(); - if (!dev ) return; - - // Create a lazy copy of the current state - m_origDevice = new KisPaintDevice(*dev.data()); - Q_ASSERT(m_origDevice); - - if(dev->hasSelection()) - { - KisSelectionSP sel = dev->selection(); - m_origSelection = new KisSelection(*sel.data()); - m_initialRect = sel->selectedExactRect(); - } - else { - m_initialRect = dev->exactBounds(); - } - m_topleft = KisPoint(m_initialRect.topLeft()); - m_topright = KisPoint(m_initialRect.topRight()); - m_bottomleft = KisPoint(m_initialRect.bottomLeft()); - m_bottomright = KisPoint(m_initialRect.bottomRight()); - - m_subject->canvasController() ->updateCanvas(); -} - -void KisToolPerspectiveTransform::paint(KisCanvasPainter& gc) -{ - paintOutline(gc, TQRect()); -} - -void KisToolPerspectiveTransform::paint(KisCanvasPainter& gc, const TQRect& rc) -{ - paintOutline(gc, rc); -} - -bool KisToolPerspectiveTransform::mouseNear(const TQPoint& mousep, const TQPoint point) -{ - return (TQRect( (point.x() - m_handleHalfSize), (point.y() - m_handleHalfSize), m_handleSize, m_handleSize).contains(mousep) ); -} - -void KisToolPerspectiveTransform::buttonPress(KisButtonPressEvent *event) -{ - if (m_subject) { - switch(m_interractionMode) - { - case DRAWRECTINTERRACTION: - { - if (m_points.isEmpty()) - { - m_dragging = false; - m_dragStart = event->pos(); - m_dragEnd = event->pos(); - m_points.append(m_dragStart); - paintOutline(); - } else { - m_dragging = true; - m_dragStart = m_dragEnd; - m_dragEnd = event->pos(); - paintOutline(); - } - } - case EDITRECTINTERRACTION: - { - KisImageSP img = m_subject->currentImg(); - - if (img && img->activeDevice() && event->button() == Qt::LeftButton) { - m_actualyMoveWhileSelected = false; - m_dragEnd = event->pos(); - KisCanvasController *controller = m_subject->canvasController(); - TQPoint mousep = controller->windowToView( event->pos().roundTQPoint() ); - if( mouseNear( mousep, controller->windowToView(m_topleft.roundTQPoint() ) ) ) - { - kdDebug() << " PRESS TOPLEFT HANDLE " << endl; - m_currentSelectedPoint = &m_topleft; - } - else if( mouseNear( mousep, controller->windowToView(m_topright.roundTQPoint() ) ) ) - { - kdDebug() << " PRESS TOPRIGHT HANDLE " << endl; - m_currentSelectedPoint = &m_topright; - } - else if( mouseNear( mousep, controller->windowToView(m_bottomleft.roundTQPoint() ) ) ) - { - kdDebug() << " PRESS BOTTOMLEFT HANDLE " << endl; - m_currentSelectedPoint = &m_bottomleft; - } - else if( mouseNear( mousep, controller->windowToView(m_bottomright.roundTQPoint() ) ) ) - { - kdDebug() << " PRESS BOTTOMRIGHT HANDLE " << endl; - m_currentSelectedPoint = &m_bottomright; - } else if( mouseNear( mousep, controller->windowToView(KisPoint((m_topleft+m_topright)*0.5).roundTQPoint() ) ) ) - { - kdDebug() << " PRESS TOP HANDLE " << endl; - m_handleSelected = TOPHANDLE; - }else if( mouseNear( mousep, controller->windowToView(KisPoint((m_topleft+m_bottomleft)*0.5).roundTQPoint() ) ) ) - { - kdDebug() << " PRESS LEFT HANDLE " << endl; - m_handleSelected = LEFTHANDLE; - }else if( mouseNear( mousep, controller->windowToView(KisPoint((m_bottomleft+m_bottomright)*0.5).roundTQPoint() ) ) ) - { - kdDebug() << " PRESS BOTTOM HANDLE " << endl; - m_handleSelected = BOTTOMHANDLE; - }else if( mouseNear( mousep, controller->windowToView(KisPoint((m_bottomright+m_topright)*0.5).roundTQPoint() ) ) ) - { - kdDebug() << " PRESS RIGHT HANDLE " << endl; - m_handleSelected = RIGHTHANDLE; - }else if( mouseNear( mousep, controller->windowToView(KisPoint((m_topleft+m_bottomleft + m_bottomright+m_topright)*0.25).roundTQPoint() ) ) ) - { - kdDebug() << " PRESS MIDDLE HANDLE " << endl; - m_handleSelected = MIDDLEHANDLE; - } - } - } - } - } -} - -void KisToolPerspectiveTransform::move(KisMoveEvent *event) -{ - switch(m_interractionMode) - { - case DRAWRECTINTERRACTION: - { - if (m_dragging) { - // erase old lines on canvas - paintOutline(); - // get current mouse position - m_dragEnd = event->pos(); - // draw new lines on canvas - paintOutline(); - } - } - - case EDITRECTINTERRACTION: - { - if(m_currentSelectedPoint) - { - paintOutline(); - KisPoint translate = event->pos() - m_dragEnd; - m_dragEnd = event->pos(); - *m_currentSelectedPoint += translate;; - paintOutline(); - m_actualyMoveWhileSelected = true; - } - else if(m_handleSelected == TOPHANDLE || m_handleSelected == LEFTHANDLE || m_handleSelected == BOTTOMHANDLE || m_handleSelected == RIGHTHANDLE) - { - paintOutline(); - - KisPoint translate = event->pos() - m_dragEnd; - m_dragEnd = event->pos(); - - double matrixFrom[3][3]; - double* b = KisPerspectiveMath::computeMatrixTransfoToPerspective(m_topleft, m_topright, m_bottomleft, m_bottomright, m_initialRect); - for(int i = 0; i < 3; i++) - { - for(int j = 0; j < 3; j++) - { - matrixFrom[i][j] = b[3*i+j]; - } - } - delete b; - - KisPoint topLeft = KisPerspectiveMath::matProd(matrixFrom, KisPoint(m_initialRect.topLeft()) ); - KisPoint topRight = KisPerspectiveMath::matProd(matrixFrom, KisPoint(m_initialRect.topRight()) ); - KisPoint bottomLeft = KisPerspectiveMath::matProd(matrixFrom, KisPoint(m_initialRect.bottomLeft()) ); - KisPoint bottomRight = KisPerspectiveMath::matProd(matrixFrom, KisPoint(m_initialRect.bottomRight()) ); - TQRect dstRect = m_initialRect; - switch(m_handleSelected) - { - case TOPHANDLE: - dstRect.setTop( static_cast( dstRect.top() + translate.y() ) ) ; - break; - case LEFTHANDLE: - dstRect.setLeft( static_cast( dstRect.left() + translate.x() ) ); - break; - case BOTTOMHANDLE: - dstRect.setBottom( static_cast( dstRect.bottom() + translate.y() ) ); - break; - case RIGHTHANDLE: - dstRect.setRight( static_cast( dstRect.right() + translate.x() ) ); - break; - case MIDDLEHANDLE: - case NOHANDLE: - kdDebug() << "Should NOT happen" << endl; - } - double matrixTo[3][3]; - b = KisPerspectiveMath::computeMatrixTransfoToPerspective(topLeft, topRight, bottomLeft, bottomRight, dstRect ); - for(int i = 0; i < 3; i++) - { - for(int j = 0; j < 3; j++) - { - matrixTo[i][j] = b[3*i+j]; - } - } - delete b; - m_topleft = KisPerspectiveMath::matProd(matrixTo, KisPoint(m_initialRect.topLeft())); - m_topright = KisPerspectiveMath::matProd(matrixTo, KisPoint(m_initialRect.topRight())); - m_bottomleft = KisPerspectiveMath::matProd(matrixTo, KisPoint(m_initialRect.bottomLeft())); - m_bottomright = KisPerspectiveMath::matProd(matrixTo, KisPoint(m_initialRect.bottomRight())); - - paintOutline(); - m_actualyMoveWhileSelected = true; - } else if (m_handleSelected == MIDDLEHANDLE) { - paintOutline(); - KisPoint translate = event->pos() - m_dragEnd; - m_dragEnd = event->pos(); - m_topleft += translate; - m_topright += translate; - m_bottomleft += translate; - m_bottomright += translate; - paintOutline(); - m_actualyMoveWhileSelected = true; - } - } - }; -} - -void KisToolPerspectiveTransform::buttonRelease(KisButtonReleaseEvent * event) -{ - KisImageSP img = m_subject->currentImg(); - - if (!img) - return; - if( event->button() == Qt::LeftButton) - { - switch(m_interractionMode) - { - case DRAWRECTINTERRACTION: - { - if (m_dragging && event->button() == Qt::LeftButton) { - paintOutline(); - m_dragging = false; - m_points.append (m_dragEnd); - if( m_points.size() == 4) - { - // from the points, select which is topleft ? topright ? bottomright ? and bottomleft ? - m_topleft = m_points[0]; - m_topright = m_points[1]; - m_bottomleft = m_points[3]; - m_bottomright = m_points[2]; - double matrix[3][3]; - double* b = KisPerspectiveMath::computeMatrixTransfoToPerspective(m_topleft, m_topright, m_bottomleft, m_bottomright, m_initialRect ); - for(int i = 0; i < 3; i++) - { - for(int j = 0; j < 3; j++) - { - kdDebug() << "sol[" << 3*i+j << "]=" << b[3*i+j] << endl; - matrix[i][j] = b[3*i+j]; - } - } - m_topleft = KisPerspectiveMath::matProd(matrix, KisPoint(m_initialRect.topLeft())); - m_topright = KisPerspectiveMath::matProd(matrix, KisPoint(m_initialRect.topRight())); - m_bottomleft = KisPerspectiveMath::matProd(matrix, KisPoint(m_initialRect.bottomLeft())); - m_bottomright = KisPerspectiveMath::matProd(matrix, KisPoint(m_initialRect.bottomRight())); - m_interractionMode = EDITRECTINTERRACTION; - paintOutline(); - TQApplication::setOverrideCursor(KisCursor::waitCursor()); - transform(); - TQApplication::restoreOverrideCursor(); - } else { - paintOutline(); - } - } - } - break; - case EDITRECTINTERRACTION: - { - if(m_currentSelectedPoint ) - { - m_currentSelectedPoint = 0; - if(m_actualyMoveWhileSelected) - { - paintOutline(); - TQApplication::setOverrideCursor(KisCursor::waitCursor()); - transform(); - TQApplication::restoreOverrideCursor(); - } - } - if(m_handleSelected != NOHANDLE) - { - m_handleSelected = NOHANDLE; - if(m_actualyMoveWhileSelected) - { -// paintOutline(); - TQApplication::setOverrideCursor(KisCursor::waitCursor()); - transform(); - TQApplication::restoreOverrideCursor(); - } - } - } - break; - } - } -} - -void KisToolPerspectiveTransform::paintOutline() -{ - if (m_subject) { - KisCanvasController *controller = m_subject->canvasController(); - KisCanvas *canvas = controller->kiscanvas(); - KisCanvasPainter gc(canvas); - TQRect rc; - - paintOutline(gc, rc); - } -} - -void KisToolPerspectiveTransform::paintOutline(KisCanvasPainter& gc, const TQRect&) -{ - if (m_subject) { - KisCanvasController *controller = m_subject->canvasController(); - RasterOp op = gc.rasterOp(); - TQPen old = gc.pen(); - TQPen pen(TQt::SolidLine); - pen.setWidth(1); - Q_ASSERT(controller); - - switch(m_interractionMode) - { - case DRAWRECTINTERRACTION: - { - kdDebug() << "DRAWRECTINTERRACTION paintOutline " << m_points.size() << endl; - KisPoint start, end; - TQPoint startPos; - TQPoint endPos; - for (KisPointVector::iterator it = m_points.begin(); it != m_points.end(); ++it) { - - if (it == m_points.begin()) - { - start = (*it); - } else { - end = (*it); - - startPos = controller->windowToView(start.floorTQPoint()); - endPos = controller->windowToView(end.floorTQPoint()); - - gc.drawLine(startPos, endPos); - - start = end; - } - } - } - break; - case EDITRECTINTERRACTION: - { - TQPoint topleft = controller->windowToView(m_topleft ).roundTQPoint(); - TQPoint topright = controller->windowToView(m_topright).roundTQPoint(); - TQPoint bottomleft = controller->windowToView(m_bottomleft).roundTQPoint(); - TQPoint bottomright = controller->windowToView(m_bottomright).roundTQPoint(); - - gc.setRasterOp(TQt::NotROP); - gc.setPen(pen); - gc.drawRect(topleft.x()-4, topleft.y()-4, 8, 8); - gc.drawLine(topleft.x(), topleft.y(), (topleft.x()+topright.x())/2, (topleft.y()+topright.y())/2); - gc.drawRect((topleft.x()+topright.x())/2-4, (topleft.y()+topright.y())/2-4, 8, 8); - gc.drawLine((topleft.x()+topright.x())/2, (topleft.y()+topright.y())/2, topright.x(), topright.y()); - gc.drawRect(topright.x()-4, topright.y()-4, 8, 8); - gc.drawLine(topright.x(), topright.y(), (topright.x()+bottomright.x())/2, (topright.y()+bottomright.y())/2); - gc.drawRect((topright.x()+bottomright.x())/2-4, (topright.y()+bottomright.y())/2-4, 8, 8); - gc.drawLine((topright.x()+bottomright.x())/2, (topright.y()+bottomright.y())/2,bottomright.x(), bottomright.y()); - gc.drawRect(bottomright.x()-4, bottomright.y()-4, 8, 8); - gc.drawLine(bottomright.x(), bottomright.y(), (bottomleft.x()+bottomright.x())/2, (bottomleft.y()+bottomright.y())/2); - gc.drawRect((bottomleft.x()+bottomright.x())/2-4, (bottomleft.y()+bottomright.y())/2-4, 8, 8); - gc.drawLine((bottomleft.x()+bottomright.x())/2, (bottomleft.y()+bottomright.y())/2, bottomleft.x(), bottomleft.y()); - gc.drawRect(bottomleft.x()-4, bottomleft.y()-4, 8, 8); - gc.drawLine(bottomleft.x(), bottomleft.y(), (topleft.x()+bottomleft.x())/2, (topleft.y()+bottomleft.y())/2); - gc.drawRect((topleft.x()+bottomleft.x())/2-4, (topleft.y()+bottomleft.y())/2-4, 8, 8); - gc.drawLine((topleft.x()+bottomleft.x())/2, (topleft.y()+bottomleft.y())/2, topleft.x(), topleft.y()); - gc.drawRect((bottomleft.x()+bottomright.x()+topleft.x()+topright.x())/4-4, (bottomleft.y()+bottomright.y()+topleft.y()+topright.y())/4-4, 8, 8); - } - break; - } - gc.setRasterOp(op); - gc.setPen(old); - } -} - -void KisToolPerspectiveTransform::transform() -{ - KisImageSP img = m_subject->currentImg(); - - if (!img || !img->activeDevice()) - return; - - KisProgressDisplayInterface *progress = m_subject->progressDisplay(); - - // This mementoes the current state of the active device. - PerspectiveTransformCmd * transaction = new PerspectiveTransformCmd(this, img->activeDevice(), m_origDevice, - m_topleft, m_topright, m_bottomleft, m_bottomright, m_origSelection, m_initialRect); - - // Copy the original state back. - TQRect rc = m_origDevice->extent(); - rc = rc.normalize(); - img->activeDevice()->clear(); - KisPainter gc(img->activeDevice()); - gc.bitBlt(rc.x(), rc.y(), COMPOSITE_COPY, m_origDevice, rc.x(), rc.y(), rc.width(), rc.height()); - gc.end(); - - // Also restore the original selection. - if(m_origSelection) - { - TQRect rc = m_origSelection->selectedRect(); - rc = rc.normalize(); - img->activeDevice()->selection()->clear(); - KisPainter sgc(img->activeDevice()->selection().data()); - sgc.bitBlt(rc.x(), rc.y(), COMPOSITE_COPY, m_origSelection.data(), rc.x(), rc.y(), rc.width(), rc.height()); - sgc.end(); - } - else - if(img->activeDevice()->hasSelection()) - img->activeDevice()->selection()->clear(); - - // Perform the transform. Since we copied the original state back, this doesn't degrade - // after many tweaks. Since we started the transaction before the copy back, the memento - // has the previous state. - KisPerspectiveTransformWorker t(img->activeDevice(),m_topleft, m_topright, m_bottomleft, m_bottomright, progress); - t.run(); - - // If canceled, go back to the memento - if(t.isCanceled()) - { - transaction->unexecute(); - delete transaction; - return; - } - - img->activeDevice()->setDirty(rc); // XXX: This is not enough - should union with new extent - - // Else add the command -- this will have the memento from the previous state, - // and the transformed state from the original device we cached in our activated() - // method. - if (transaction) { - if (img->undo()) - img->undoAdapter()->addCommand(transaction); - else - delete transaction; - } -} - -void KisToolPerspectiveTransform::notifyCommandAdded( KCommand * command) -{ - PerspectiveTransformCmd * cmd = dynamic_cast(command); - if (cmd == 0) { - // The last added command wasn't one of ours; - // we should reset to the new state of the canvas. - // In effect we should treat this as if the tool has been just activated - initHandles(); - } -} - -void KisToolPerspectiveTransform::notifyCommandExecuted( KCommand * command) -{ - Q_UNUSED(command); - PerspectiveTransformCmd * cmd=0; - if(m_subject->currentImg()->undoAdapter()->presentCommand()) - cmd = dynamic_cast(m_subject->currentImg()->undoAdapter()->presentCommand()); - - if (cmd == 0) { - // The command now on the top of the stack isn't one of ours - // We should treat this as if the tool has been just activated - initHandles(); - } - else - { - // One of our commands is now on top - // We should ask for tool args and orig selection - m_origDevice = cmd->origDevice(); - cmd->transformArgs(m_topleft, m_topright, m_bottomleft, m_bottomright); - m_origSelection = cmd->origSelection(m_initialRect); - m_subject->canvasController() ->updateCanvas(); - } -} - -void KisToolPerspectiveTransform::slotLayerActivated(KisLayerSP) -{ - activate(); -} - - -TQWidget* KisToolPerspectiveTransform::createOptionWidget(TQWidget* /*parent*/) -{ -#if 0 - m_optWidget = new WdgToolPerspectiveTransform(parent); - TQ_CHECK_PTR(m_optWidget); - - m_optWidget->cmbFilter->clear(); - m_optWidget->cmbFilter->setIDList(KisFilterStrategyRegistry::instance()->listKeys()); - - m_optWidget->cmbFilter->setCurrentText("Mitchell"); - connect(m_optWidget->cmbFilter, TQT_SIGNAL(activated(const KisID &)), - this, TQT_SLOT(slotSetFilter(const KisID &))); - - KisID filterID = m_optWidget->cmbFilter->currentItem(); - m_filter = KisFilterStrategyRegistry::instance()->get(filterID); - -/* - connect(m_optWidget->intStartX, TQT_SIGNAL(valueChanged(int)), this, TQT_SLOT(setStartX(int))); - connect(m_optWidget->intStartY, TQT_SIGNAL(valueChanged(int)), this, TQT_SLOT(setStartY(int))); - connect(m_optWidget->intEndX, TQT_SIGNAL(valueChanged(int)), this, TQT_SLOT(setEndX(int))); - connect(m_optWidget->intEndY, TQT_SIGNAL(valueChanged(int)), this, TQT_SLOT(setEndY(int))); -*/ - m_optWidget->intStartX->hide(); - m_optWidget->intStartY->hide(); - m_optWidget->intEndX->hide(); - m_optWidget->intEndY->hide(); - m_optWidget->textLabel1->hide(); - m_optWidget->textLabel2->hide(); - m_optWidget->textLabel3->hide(); - m_optWidget->textLabel4->hide(); -#endif - return 0; -} - -TQWidget* KisToolPerspectiveTransform::optionWidget() -{ - return 0; -} - -void KisToolPerspectiveTransform::setup(TDEActionCollection *collection) -{ - m_action = static_cast(collection->action(name())); - - if (m_action == 0) { - m_action = new TDERadioAction(i18n("&Perspective Transform"), - "tool_perspectivetransform", - 0, - this, - TQT_SLOT(activate()), - collection, - name()); - TQ_CHECK_PTR(m_action); - m_action->setToolTip(i18n("Perspective transform a layer or a selection")); - m_action->setExclusiveGroup("tools"); - m_ownAction = true; - } -} - -#include "kis_tool_perspectivetransform.moc" diff --git a/chalk/plugins/tools/tool_perspectivetransform/kis_tool_perspectivetransform.cpp b/chalk/plugins/tools/tool_perspectivetransform/kis_tool_perspectivetransform.cpp new file mode 100644 index 000000000..e73f5da3c --- /dev/null +++ b/chalk/plugins/tools/tool_perspectivetransform/kis_tool_perspectivetransform.cpp @@ -0,0 +1,742 @@ +/* + * kis_tool_transform.cpp -- part of Chalk + * + * Copyright (c) 2006 Cyrille Berger + * + * Based on the transform tool from : + * Copyright (c) 2004 Boudewijn Rempt + * Copyright (c) 2005 Casper Boemann + * + * 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; version 2 of the License. + * + * 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "kis_tool_perspectivetransform.h" + + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +//#include "wdg_tool_transform.h" +#include "kis_canvas.h" +#include "kis_canvas_painter.h" + +namespace { + class PerspectiveTransformCmd : public KisSelectedTransaction { + typedef KisSelectedTransaction super; + + public: + PerspectiveTransformCmd(KisToolPerspectiveTransform *tool, KisPaintDeviceSP device, KisPaintDeviceSP origDevice, KisPoint topleft, KisPoint topright, KisPoint bottomleft, KisPoint bottomright, KisSelectionSP origSel, TQRect initialRect); + virtual ~PerspectiveTransformCmd(); + + public: + virtual void execute(); + virtual void unexecute(); + void transformArgs(KisPoint &topleft, KisPoint &topright, KisPoint &bottomleft, KisPoint& bottomright) const; + KisSelectionSP origSelection(TQRect& initialRect) const; + KisPaintDeviceSP theDevice(); + KisPaintDeviceSP origDevice(); + + private: + TQRect m_initialRect; + KisPoint m_topleft, m_topright, m_bottomleft, m_bottomright; + KisToolPerspectiveTransform *m_tool; + KisSelectionSP m_origSelection; + KisPaintDeviceSP m_device; + KisPaintDeviceSP m_origDevice; + }; + + PerspectiveTransformCmd::PerspectiveTransformCmd(KisToolPerspectiveTransform *tool, KisPaintDeviceSP device, KisPaintDeviceSP origDevice, KisPoint topleft, KisPoint topright, KisPoint bottomleft, KisPoint bottomright, KisSelectionSP origSel, TQRect initialRect) : + super(i18n("Perspective Transform"), device), m_initialRect(initialRect) + , m_topleft(topleft), m_topright(topright), m_bottomleft(bottomleft), m_bottomright(bottomright) + , m_tool(tool), m_origSelection(origSel), m_device(device), m_origDevice(origDevice) + { + } + + PerspectiveTransformCmd::~PerspectiveTransformCmd() + { + } + + void PerspectiveTransformCmd::transformArgs(KisPoint &topleft, KisPoint &topright, KisPoint &bottomleft, KisPoint& bottomright) const + { + topleft = m_topleft; + topright = m_topright; + bottomleft = m_bottomleft; + bottomright = m_bottomright; + } + + KisSelectionSP PerspectiveTransformCmd::origSelection(TQRect& initialRect) const + { + initialRect = m_initialRect; + return m_origSelection; + } + + void PerspectiveTransformCmd::execute() + { + super::execute(); + } + + void PerspectiveTransformCmd::unexecute() + { + super::unexecute(); + } + + KisPaintDeviceSP PerspectiveTransformCmd::theDevice() + { + return m_device; + } + + KisPaintDeviceSP PerspectiveTransformCmd::origDevice() + { + return m_origDevice; + } +} + +KisToolPerspectiveTransform::KisToolPerspectiveTransform() + : super(i18n("Perspective Transform")) +{ + setName("tool_perspectivetransform"); + setCursor(KisCursor::selectCursor()); + m_subject = 0; + m_origDevice = 0; + m_origSelection = 0; + m_handleHalfSize = 8; + m_handleSize = 2 * m_handleHalfSize; + m_handleSelected = NOHANDLE; +} + +KisToolPerspectiveTransform::~KisToolPerspectiveTransform() +{ +} + +void KisToolPerspectiveTransform::deactivate() +{ + if (m_subject && m_subject->undoAdapter()) m_subject->undoAdapter()->removeCommandHistoryListener( this ); + + KisImageSP img = m_subject->currentImg(); + if (!img) return; + + paintOutline(); + + disconnect(m_subject->currentImg().data(), TQT_SIGNAL(sigLayerActivated(KisLayerSP)), this, TQT_SLOT(slotLayerActivated(KisLayerSP))); +} + +void KisToolPerspectiveTransform::activate() +{ + super::activate(); + m_currentSelectedPoint = 0; + if(m_subject && m_subject->currentImg() && m_subject->currentImg()->activeDevice()) + { + //connect(m_subject, commandExecuted(KCommand *c), this, notifyCommandAdded( KCommand * c)); + m_subject->undoAdapter()->setCommandHistoryListener( this ); + +// KisToolControllerInterface *controller = m_subject->toolController(); +// if (controller) +// controller->setCurrentTool(this); + + PerspectiveTransformCmd * cmd=0; + + if(m_subject->currentImg()->undoAdapter()->presentCommand()) + cmd = dynamic_cast(m_subject->currentImg()->undoAdapter()->presentCommand()); + + // One of our commands is on top + if(cmd &&cmd->theDevice() == m_subject->currentImg()->activeDevice()) + { + m_interractionMode = EDITRECTINTERRACTION; + // and it even has the same device + // We should ask for tool args and orig selection + m_origDevice = cmd->origDevice(); + cmd->transformArgs(m_topleft, m_topright, m_bottomleft, m_bottomright); + m_origSelection = cmd->origSelection(m_initialRect); + paintOutline(); + } + else + { + m_interractionMode = DRAWRECTINTERRACTION; + m_points.clear(); + initHandles(); + } + } + connect(m_subject->currentImg(), TQT_SIGNAL(sigLayerActivated(KisLayerSP)), this, TQT_SLOT(slotLayerActivated(KisLayerSP))); +} + +void KisToolPerspectiveTransform::initHandles() +{ +// TQ_INT32 x,y,w,h; + KisImageSP img = m_subject->currentImg(); + + KisPaintDeviceSP dev = img->activeDevice(); + if (!dev ) return; + + // Create a lazy copy of the current state + m_origDevice = new KisPaintDevice(*dev.data()); + Q_ASSERT(m_origDevice); + + if(dev->hasSelection()) + { + KisSelectionSP sel = dev->selection(); + m_origSelection = new KisSelection(*sel.data()); + m_initialRect = sel->selectedExactRect(); + } + else { + m_initialRect = dev->exactBounds(); + } + m_topleft = KisPoint(m_initialRect.topLeft()); + m_topright = KisPoint(m_initialRect.topRight()); + m_bottomleft = KisPoint(m_initialRect.bottomLeft()); + m_bottomright = KisPoint(m_initialRect.bottomRight()); + + m_subject->canvasController() ->updateCanvas(); +} + +void KisToolPerspectiveTransform::paint(KisCanvasPainter& gc) +{ + paintOutline(gc, TQRect()); +} + +void KisToolPerspectiveTransform::paint(KisCanvasPainter& gc, const TQRect& rc) +{ + paintOutline(gc, rc); +} + +bool KisToolPerspectiveTransform::mouseNear(const TQPoint& mousep, const TQPoint point) +{ + return (TQRect( (point.x() - m_handleHalfSize), (point.y() - m_handleHalfSize), m_handleSize, m_handleSize).contains(mousep) ); +} + +void KisToolPerspectiveTransform::buttonPress(KisButtonPressEvent *event) +{ + if (m_subject) { + switch(m_interractionMode) + { + case DRAWRECTINTERRACTION: + { + if (m_points.isEmpty()) + { + m_dragging = false; + m_dragStart = event->pos(); + m_dragEnd = event->pos(); + m_points.append(m_dragStart); + paintOutline(); + } else { + m_dragging = true; + m_dragStart = m_dragEnd; + m_dragEnd = event->pos(); + paintOutline(); + } + } + case EDITRECTINTERRACTION: + { + KisImageSP img = m_subject->currentImg(); + + if (img && img->activeDevice() && event->button() == Qt::LeftButton) { + m_actualyMoveWhileSelected = false; + m_dragEnd = event->pos(); + KisCanvasController *controller = m_subject->canvasController(); + TQPoint mousep = controller->windowToView( event->pos().roundTQPoint() ); + if( mouseNear( mousep, controller->windowToView(m_topleft.roundTQPoint() ) ) ) + { + kdDebug() << " PRESS TOPLEFT HANDLE " << endl; + m_currentSelectedPoint = &m_topleft; + } + else if( mouseNear( mousep, controller->windowToView(m_topright.roundTQPoint() ) ) ) + { + kdDebug() << " PRESS TOPRIGHT HANDLE " << endl; + m_currentSelectedPoint = &m_topright; + } + else if( mouseNear( mousep, controller->windowToView(m_bottomleft.roundTQPoint() ) ) ) + { + kdDebug() << " PRESS BOTTOMLEFT HANDLE " << endl; + m_currentSelectedPoint = &m_bottomleft; + } + else if( mouseNear( mousep, controller->windowToView(m_bottomright.roundTQPoint() ) ) ) + { + kdDebug() << " PRESS BOTTOMRIGHT HANDLE " << endl; + m_currentSelectedPoint = &m_bottomright; + } else if( mouseNear( mousep, controller->windowToView(KisPoint((m_topleft+m_topright)*0.5).roundTQPoint() ) ) ) + { + kdDebug() << " PRESS TOP HANDLE " << endl; + m_handleSelected = TOPHANDLE; + }else if( mouseNear( mousep, controller->windowToView(KisPoint((m_topleft+m_bottomleft)*0.5).roundTQPoint() ) ) ) + { + kdDebug() << " PRESS LEFT HANDLE " << endl; + m_handleSelected = LEFTHANDLE; + }else if( mouseNear( mousep, controller->windowToView(KisPoint((m_bottomleft+m_bottomright)*0.5).roundTQPoint() ) ) ) + { + kdDebug() << " PRESS BOTTOM HANDLE " << endl; + m_handleSelected = BOTTOMHANDLE; + }else if( mouseNear( mousep, controller->windowToView(KisPoint((m_bottomright+m_topright)*0.5).roundTQPoint() ) ) ) + { + kdDebug() << " PRESS RIGHT HANDLE " << endl; + m_handleSelected = RIGHTHANDLE; + }else if( mouseNear( mousep, controller->windowToView(KisPoint((m_topleft+m_bottomleft + m_bottomright+m_topright)*0.25).roundTQPoint() ) ) ) + { + kdDebug() << " PRESS MIDDLE HANDLE " << endl; + m_handleSelected = MIDDLEHANDLE; + } + } + } + } + } +} + +void KisToolPerspectiveTransform::move(KisMoveEvent *event) +{ + switch(m_interractionMode) + { + case DRAWRECTINTERRACTION: + { + if (m_dragging) { + // erase old lines on canvas + paintOutline(); + // get current mouse position + m_dragEnd = event->pos(); + // draw new lines on canvas + paintOutline(); + } + } + + case EDITRECTINTERRACTION: + { + if(m_currentSelectedPoint) + { + paintOutline(); + KisPoint translate = event->pos() - m_dragEnd; + m_dragEnd = event->pos(); + *m_currentSelectedPoint += translate;; + paintOutline(); + m_actualyMoveWhileSelected = true; + } + else if(m_handleSelected == TOPHANDLE || m_handleSelected == LEFTHANDLE || m_handleSelected == BOTTOMHANDLE || m_handleSelected == RIGHTHANDLE) + { + paintOutline(); + + KisPoint translate = event->pos() - m_dragEnd; + m_dragEnd = event->pos(); + + double matrixFrom[3][3]; + double* b = KisPerspectiveMath::computeMatrixTransfoToPerspective(m_topleft, m_topright, m_bottomleft, m_bottomright, m_initialRect); + for(int i = 0; i < 3; i++) + { + for(int j = 0; j < 3; j++) + { + matrixFrom[i][j] = b[3*i+j]; + } + } + delete b; + + KisPoint topLeft = KisPerspectiveMath::matProd(matrixFrom, KisPoint(m_initialRect.topLeft()) ); + KisPoint topRight = KisPerspectiveMath::matProd(matrixFrom, KisPoint(m_initialRect.topRight()) ); + KisPoint bottomLeft = KisPerspectiveMath::matProd(matrixFrom, KisPoint(m_initialRect.bottomLeft()) ); + KisPoint bottomRight = KisPerspectiveMath::matProd(matrixFrom, KisPoint(m_initialRect.bottomRight()) ); + TQRect dstRect = m_initialRect; + switch(m_handleSelected) + { + case TOPHANDLE: + dstRect.setTop( static_cast( dstRect.top() + translate.y() ) ) ; + break; + case LEFTHANDLE: + dstRect.setLeft( static_cast( dstRect.left() + translate.x() ) ); + break; + case BOTTOMHANDLE: + dstRect.setBottom( static_cast( dstRect.bottom() + translate.y() ) ); + break; + case RIGHTHANDLE: + dstRect.setRight( static_cast( dstRect.right() + translate.x() ) ); + break; + case MIDDLEHANDLE: + case NOHANDLE: + kdDebug() << "Should NOT happen" << endl; + } + double matrixTo[3][3]; + b = KisPerspectiveMath::computeMatrixTransfoToPerspective(topLeft, topRight, bottomLeft, bottomRight, dstRect ); + for(int i = 0; i < 3; i++) + { + for(int j = 0; j < 3; j++) + { + matrixTo[i][j] = b[3*i+j]; + } + } + delete b; + m_topleft = KisPerspectiveMath::matProd(matrixTo, KisPoint(m_initialRect.topLeft())); + m_topright = KisPerspectiveMath::matProd(matrixTo, KisPoint(m_initialRect.topRight())); + m_bottomleft = KisPerspectiveMath::matProd(matrixTo, KisPoint(m_initialRect.bottomLeft())); + m_bottomright = KisPerspectiveMath::matProd(matrixTo, KisPoint(m_initialRect.bottomRight())); + + paintOutline(); + m_actualyMoveWhileSelected = true; + } else if (m_handleSelected == MIDDLEHANDLE) { + paintOutline(); + KisPoint translate = event->pos() - m_dragEnd; + m_dragEnd = event->pos(); + m_topleft += translate; + m_topright += translate; + m_bottomleft += translate; + m_bottomright += translate; + paintOutline(); + m_actualyMoveWhileSelected = true; + } + } + }; +} + +void KisToolPerspectiveTransform::buttonRelease(KisButtonReleaseEvent * event) +{ + KisImageSP img = m_subject->currentImg(); + + if (!img) + return; + if( event->button() == Qt::LeftButton) + { + switch(m_interractionMode) + { + case DRAWRECTINTERRACTION: + { + if (m_dragging && event->button() == Qt::LeftButton) { + paintOutline(); + m_dragging = false; + m_points.append (m_dragEnd); + if( m_points.size() == 4) + { + // from the points, select which is topleft ? topright ? bottomright ? and bottomleft ? + m_topleft = m_points[0]; + m_topright = m_points[1]; + m_bottomleft = m_points[3]; + m_bottomright = m_points[2]; + double matrix[3][3]; + double* b = KisPerspectiveMath::computeMatrixTransfoToPerspective(m_topleft, m_topright, m_bottomleft, m_bottomright, m_initialRect ); + for(int i = 0; i < 3; i++) + { + for(int j = 0; j < 3; j++) + { + kdDebug() << "sol[" << 3*i+j << "]=" << b[3*i+j] << endl; + matrix[i][j] = b[3*i+j]; + } + } + m_topleft = KisPerspectiveMath::matProd(matrix, KisPoint(m_initialRect.topLeft())); + m_topright = KisPerspectiveMath::matProd(matrix, KisPoint(m_initialRect.topRight())); + m_bottomleft = KisPerspectiveMath::matProd(matrix, KisPoint(m_initialRect.bottomLeft())); + m_bottomright = KisPerspectiveMath::matProd(matrix, KisPoint(m_initialRect.bottomRight())); + m_interractionMode = EDITRECTINTERRACTION; + paintOutline(); + TQApplication::setOverrideCursor(KisCursor::waitCursor()); + transform(); + TQApplication::restoreOverrideCursor(); + } else { + paintOutline(); + } + } + } + break; + case EDITRECTINTERRACTION: + { + if(m_currentSelectedPoint ) + { + m_currentSelectedPoint = 0; + if(m_actualyMoveWhileSelected) + { + paintOutline(); + TQApplication::setOverrideCursor(KisCursor::waitCursor()); + transform(); + TQApplication::restoreOverrideCursor(); + } + } + if(m_handleSelected != NOHANDLE) + { + m_handleSelected = NOHANDLE; + if(m_actualyMoveWhileSelected) + { +// paintOutline(); + TQApplication::setOverrideCursor(KisCursor::waitCursor()); + transform(); + TQApplication::restoreOverrideCursor(); + } + } + } + break; + } + } +} + +void KisToolPerspectiveTransform::paintOutline() +{ + if (m_subject) { + KisCanvasController *controller = m_subject->canvasController(); + KisCanvas *canvas = controller->kiscanvas(); + KisCanvasPainter gc(canvas); + TQRect rc; + + paintOutline(gc, rc); + } +} + +void KisToolPerspectiveTransform::paintOutline(KisCanvasPainter& gc, const TQRect&) +{ + if (m_subject) { + KisCanvasController *controller = m_subject->canvasController(); + RasterOp op = gc.rasterOp(); + TQPen old = gc.pen(); + TQPen pen(TQt::SolidLine); + pen.setWidth(1); + Q_ASSERT(controller); + + switch(m_interractionMode) + { + case DRAWRECTINTERRACTION: + { + kdDebug() << "DRAWRECTINTERRACTION paintOutline " << m_points.size() << endl; + KisPoint start, end; + TQPoint startPos; + TQPoint endPos; + for (KisPointVector::iterator it = m_points.begin(); it != m_points.end(); ++it) { + + if (it == m_points.begin()) + { + start = (*it); + } else { + end = (*it); + + startPos = controller->windowToView(start.floorTQPoint()); + endPos = controller->windowToView(end.floorTQPoint()); + + gc.drawLine(startPos, endPos); + + start = end; + } + } + } + break; + case EDITRECTINTERRACTION: + { + TQPoint topleft = controller->windowToView(m_topleft ).roundTQPoint(); + TQPoint topright = controller->windowToView(m_topright).roundTQPoint(); + TQPoint bottomleft = controller->windowToView(m_bottomleft).roundTQPoint(); + TQPoint bottomright = controller->windowToView(m_bottomright).roundTQPoint(); + + gc.setRasterOp(TQt::NotROP); + gc.setPen(pen); + gc.drawRect(topleft.x()-4, topleft.y()-4, 8, 8); + gc.drawLine(topleft.x(), topleft.y(), (topleft.x()+topright.x())/2, (topleft.y()+topright.y())/2); + gc.drawRect((topleft.x()+topright.x())/2-4, (topleft.y()+topright.y())/2-4, 8, 8); + gc.drawLine((topleft.x()+topright.x())/2, (topleft.y()+topright.y())/2, topright.x(), topright.y()); + gc.drawRect(topright.x()-4, topright.y()-4, 8, 8); + gc.drawLine(topright.x(), topright.y(), (topright.x()+bottomright.x())/2, (topright.y()+bottomright.y())/2); + gc.drawRect((topright.x()+bottomright.x())/2-4, (topright.y()+bottomright.y())/2-4, 8, 8); + gc.drawLine((topright.x()+bottomright.x())/2, (topright.y()+bottomright.y())/2,bottomright.x(), bottomright.y()); + gc.drawRect(bottomright.x()-4, bottomright.y()-4, 8, 8); + gc.drawLine(bottomright.x(), bottomright.y(), (bottomleft.x()+bottomright.x())/2, (bottomleft.y()+bottomright.y())/2); + gc.drawRect((bottomleft.x()+bottomright.x())/2-4, (bottomleft.y()+bottomright.y())/2-4, 8, 8); + gc.drawLine((bottomleft.x()+bottomright.x())/2, (bottomleft.y()+bottomright.y())/2, bottomleft.x(), bottomleft.y()); + gc.drawRect(bottomleft.x()-4, bottomleft.y()-4, 8, 8); + gc.drawLine(bottomleft.x(), bottomleft.y(), (topleft.x()+bottomleft.x())/2, (topleft.y()+bottomleft.y())/2); + gc.drawRect((topleft.x()+bottomleft.x())/2-4, (topleft.y()+bottomleft.y())/2-4, 8, 8); + gc.drawLine((topleft.x()+bottomleft.x())/2, (topleft.y()+bottomleft.y())/2, topleft.x(), topleft.y()); + gc.drawRect((bottomleft.x()+bottomright.x()+topleft.x()+topright.x())/4-4, (bottomleft.y()+bottomright.y()+topleft.y()+topright.y())/4-4, 8, 8); + } + break; + } + gc.setRasterOp(op); + gc.setPen(old); + } +} + +void KisToolPerspectiveTransform::transform() +{ + KisImageSP img = m_subject->currentImg(); + + if (!img || !img->activeDevice()) + return; + + KisProgressDisplayInterface *progress = m_subject->progressDisplay(); + + // This mementoes the current state of the active device. + PerspectiveTransformCmd * transaction = new PerspectiveTransformCmd(this, img->activeDevice(), m_origDevice, + m_topleft, m_topright, m_bottomleft, m_bottomright, m_origSelection, m_initialRect); + + // Copy the original state back. + TQRect rc = m_origDevice->extent(); + rc = rc.normalize(); + img->activeDevice()->clear(); + KisPainter gc(img->activeDevice()); + gc.bitBlt(rc.x(), rc.y(), COMPOSITE_COPY, m_origDevice, rc.x(), rc.y(), rc.width(), rc.height()); + gc.end(); + + // Also restore the original selection. + if(m_origSelection) + { + TQRect rc = m_origSelection->selectedRect(); + rc = rc.normalize(); + img->activeDevice()->selection()->clear(); + KisPainter sgc(img->activeDevice()->selection().data()); + sgc.bitBlt(rc.x(), rc.y(), COMPOSITE_COPY, m_origSelection.data(), rc.x(), rc.y(), rc.width(), rc.height()); + sgc.end(); + } + else + if(img->activeDevice()->hasSelection()) + img->activeDevice()->selection()->clear(); + + // Perform the transform. Since we copied the original state back, this doesn't degrade + // after many tweaks. Since we started the transaction before the copy back, the memento + // has the previous state. + KisPerspectiveTransformWorker t(img->activeDevice(),m_topleft, m_topright, m_bottomleft, m_bottomright, progress); + t.run(); + + // If canceled, go back to the memento + if(t.isCanceled()) + { + transaction->unexecute(); + delete transaction; + return; + } + + img->activeDevice()->setDirty(rc); // XXX: This is not enough - should union with new extent + + // Else add the command -- this will have the memento from the previous state, + // and the transformed state from the original device we cached in our activated() + // method. + if (transaction) { + if (img->undo()) + img->undoAdapter()->addCommand(transaction); + else + delete transaction; + } +} + +void KisToolPerspectiveTransform::notifyCommandAdded( KCommand * command) +{ + PerspectiveTransformCmd * cmd = dynamic_cast(command); + if (cmd == 0) { + // The last added command wasn't one of ours; + // we should reset to the new state of the canvas. + // In effect we should treat this as if the tool has been just activated + initHandles(); + } +} + +void KisToolPerspectiveTransform::notifyCommandExecuted( KCommand * command) +{ + Q_UNUSED(command); + PerspectiveTransformCmd * cmd=0; + if(m_subject->currentImg()->undoAdapter()->presentCommand()) + cmd = dynamic_cast(m_subject->currentImg()->undoAdapter()->presentCommand()); + + if (cmd == 0) { + // The command now on the top of the stack isn't one of ours + // We should treat this as if the tool has been just activated + initHandles(); + } + else + { + // One of our commands is now on top + // We should ask for tool args and orig selection + m_origDevice = cmd->origDevice(); + cmd->transformArgs(m_topleft, m_topright, m_bottomleft, m_bottomright); + m_origSelection = cmd->origSelection(m_initialRect); + m_subject->canvasController() ->updateCanvas(); + } +} + +void KisToolPerspectiveTransform::slotLayerActivated(KisLayerSP) +{ + activate(); +} + + +TQWidget* KisToolPerspectiveTransform::createOptionWidget(TQWidget* /*parent*/) +{ +#if 0 + m_optWidget = new WdgToolPerspectiveTransform(parent); + TQ_CHECK_PTR(m_optWidget); + + m_optWidget->cmbFilter->clear(); + m_optWidget->cmbFilter->setIDList(KisFilterStrategyRegistry::instance()->listKeys()); + + m_optWidget->cmbFilter->setCurrentText("Mitchell"); + connect(m_optWidget->cmbFilter, TQT_SIGNAL(activated(const KisID &)), + this, TQT_SLOT(slotSetFilter(const KisID &))); + + KisID filterID = m_optWidget->cmbFilter->currentItem(); + m_filter = KisFilterStrategyRegistry::instance()->get(filterID); + +/* + connect(m_optWidget->intStartX, TQT_SIGNAL(valueChanged(int)), this, TQT_SLOT(setStartX(int))); + connect(m_optWidget->intStartY, TQT_SIGNAL(valueChanged(int)), this, TQT_SLOT(setStartY(int))); + connect(m_optWidget->intEndX, TQT_SIGNAL(valueChanged(int)), this, TQT_SLOT(setEndX(int))); + connect(m_optWidget->intEndY, TQT_SIGNAL(valueChanged(int)), this, TQT_SLOT(setEndY(int))); +*/ + m_optWidget->intStartX->hide(); + m_optWidget->intStartY->hide(); + m_optWidget->intEndX->hide(); + m_optWidget->intEndY->hide(); + m_optWidget->textLabel1->hide(); + m_optWidget->textLabel2->hide(); + m_optWidget->textLabel3->hide(); + m_optWidget->textLabel4->hide(); +#endif + return 0; +} + +TQWidget* KisToolPerspectiveTransform::optionWidget() +{ + return 0; +} + +void KisToolPerspectiveTransform::setup(TDEActionCollection *collection) +{ + m_action = static_cast(collection->action(name())); + + if (m_action == 0) { + m_action = new TDERadioAction(i18n("&Perspective Transform"), + "tool_perspectivetransform", + 0, + this, + TQT_SLOT(activate()), + collection, + name()); + TQ_CHECK_PTR(m_action); + m_action->setToolTip(i18n("Perspective transform a layer or a selection")); + m_action->setExclusiveGroup("tools"); + m_ownAction = true; + } +} + +#include "kis_tool_perspectivetransform.moc" diff --git a/chalk/plugins/tools/tool_perspectivetransform/tool_perspectivetransform.cc b/chalk/plugins/tools/tool_perspectivetransform/tool_perspectivetransform.cc deleted file mode 100644 index 0c4023cce..000000000 --- a/chalk/plugins/tools/tool_perspectivetransform/tool_perspectivetransform.cc +++ /dev/null @@ -1,63 +0,0 @@ -/* - * tool_perspectivetransform.cc -- Part of Chalk - * - * Copyright (c) 2006 Cyrille Berger - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -#include -#include - -#include - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include "tool_perspectivetransform.h" -#include "kis_tool_perspectivetransform.h" - - -typedef KGenericFactory ToolPerspectiveTransformFactory; -K_EXPORT_COMPONENT_FACTORY( chalktoolperspectivetransform, ToolPerspectiveTransformFactory( "chalk" ) ) - - -ToolPerspectiveTransform::ToolPerspectiveTransform(TQObject *parent, const char *name, const TQStringList &) - : KParts::Plugin(parent, name) -{ - setInstance(ToolPerspectiveTransformFactory::instance()); - - if ( parent->inherits("KisToolRegistry") ) - { - kdDebug() << " add perspective transform tool to the registry" << endl; - KisToolRegistry * r = dynamic_cast(parent); - r->add(new KisToolPerspectiveTransformFactory()); - } - -} - -ToolPerspectiveTransform::~ToolPerspectiveTransform() -{ -} - -#include "tool_perspectivetransform.moc" diff --git a/chalk/plugins/tools/tool_perspectivetransform/tool_perspectivetransform.cpp b/chalk/plugins/tools/tool_perspectivetransform/tool_perspectivetransform.cpp new file mode 100644 index 000000000..73705264b --- /dev/null +++ b/chalk/plugins/tools/tool_perspectivetransform/tool_perspectivetransform.cpp @@ -0,0 +1,63 @@ +/* + * tool_perspectivetransform.cpp -- Part of Chalk + * + * Copyright (c) 2006 Cyrille Berger + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "tool_perspectivetransform.h" +#include "kis_tool_perspectivetransform.h" + + +typedef KGenericFactory ToolPerspectiveTransformFactory; +K_EXPORT_COMPONENT_FACTORY( chalktoolperspectivetransform, ToolPerspectiveTransformFactory( "chalk" ) ) + + +ToolPerspectiveTransform::ToolPerspectiveTransform(TQObject *parent, const char *name, const TQStringList &) + : KParts::Plugin(parent, name) +{ + setInstance(ToolPerspectiveTransformFactory::instance()); + + if ( parent->inherits("KisToolRegistry") ) + { + kdDebug() << " add perspective transform tool to the registry" << endl; + KisToolRegistry * r = dynamic_cast(parent); + r->add(new KisToolPerspectiveTransformFactory()); + } + +} + +ToolPerspectiveTransform::~ToolPerspectiveTransform() +{ +} + +#include "tool_perspectivetransform.moc" diff --git a/chalk/plugins/tools/tool_polygon/Makefile.am b/chalk/plugins/tools/tool_polygon/Makefile.am index 555f59a0e..4ad417da0 100644 --- a/chalk/plugins/tools/tool_polygon/Makefile.am +++ b/chalk/plugins/tools/tool_polygon/Makefile.am @@ -10,8 +10,8 @@ INCLUDES = -I$(srcdir)/../../../sdk \ $(all_includes) chalktoolpolygon_la_SOURCES = \ - tool_polygon.cc \ - kis_tool_polygon.cc + tool_polygon.cpp \ + kis_tool_polygon.cpp # Install this plugin in the KDE modules directory kde_module_LTLIBRARIES = chalktoolpolygon.la diff --git a/chalk/plugins/tools/tool_polygon/kis_tool_polygon.cc b/chalk/plugins/tools/tool_polygon/kis_tool_polygon.cc deleted file mode 100644 index a7371e49f..000000000 --- a/chalk/plugins/tools/tool_polygon/kis_tool_polygon.cc +++ /dev/null @@ -1,252 +0,0 @@ -/* - * kis_tool_polygon.cc -- part of Chalk - * - * Copyright (c) 2004 Michael Thaler - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - - -#include - -#include -#include - -#include -#include -#include -#include -#include - -#include "kis_doc.h" -#include "kis_view.h" -#include "kis_painter.h" -#include "kis_canvas_subject.h" -#include "kis_canvas_controller.h" -#include "kis_button_press_event.h" -#include "kis_button_release_event.h" -#include "kis_move_event.h" -#include "kis_paintop_registry.h" -#include "kis_canvas.h" -#include "kis_canvas_painter.h" -#include "kis_cursor.h" - -#include "kis_tool_polygon.h" - -KisToolPolygon::KisToolPolygon() - : super(i18n ("Polygon")), - m_dragging (false), - m_currentImage (0) -{ - setName("tool_polygon"); - setCursor(KisCursor::load("tool_polygon_cursor.png", 6, 6)); -} - -KisToolPolygon::~KisToolPolygon() -{ -} - -void KisToolPolygon::update (KisCanvasSubject *subject) -{ - super::update (subject); - if (m_subject) - m_currentImage = m_subject->currentImg (); -} - -void KisToolPolygon::buttonPress(KisButtonPressEvent *event) -{ - if (m_currentImage) { - if (event->button() == Qt::LeftButton && event->state() != ShiftButton) { - - m_dragging = true; - - if (m_points.isEmpty()) - { - m_dragStart = event->pos(); - m_dragEnd = event->pos(); - m_points.append(m_dragStart); - } else { - m_dragStart = m_dragEnd; - m_dragEnd = event->pos(); - draw(); - } - } else if (event->button() == Qt::LeftButton && event->state() == ShiftButton) { - finish(); - } - } -} - -void KisToolPolygon::finish() -{ - // erase old lines on canvas - draw(); - m_dragging = false; - - KisPaintDeviceSP device = m_currentImage->activeDevice (); - if (!device) return; - - KisPainter painter (device); - if (m_currentImage->undo()) painter.beginTransaction (i18n ("Polygon")); - - painter.setPaintColor(m_subject->fgColor()); - painter.setBackgroundColor(m_subject->bgColor()); - painter.setFillStyle(fillStyle()); - painter.setBrush(m_subject->currentBrush()); - painter.setPattern(m_subject->currentPattern()); - painter.setOpacity(m_opacity); - painter.setCompositeOp(m_compositeOp); - KisPaintOp * op = KisPaintOpRegistry::instance()->paintOp(m_subject->currentPaintop(), m_subject->currentPaintopSettings(), &painter); - painter.setPaintOp(op); // Painter takes ownership - - painter.paintPolygon(m_points); - - m_points.clear(); - - device->setDirty( painter.dirtyRect() ); - notifyModified(); - - if (m_currentImage->undo()) { - m_currentImage->undoAdapter()->addCommand(painter.endTransaction()); - } -} - -void KisToolPolygon::doubleClick( KisDoubleClickEvent * ) -{ - finish(); -} - -void KisToolPolygon::move(KisMoveEvent *event) -{ - if (m_dragging) { - // erase old lines on canvas - draw(); - // get current mouse position - m_dragEnd = event->pos(); - // draw new lines on canvas - draw(); - } -} - -void KisToolPolygon::buttonRelease(KisButtonReleaseEvent *event) -{ - if (!m_subject || !m_currentImage) - return; - - if (m_dragging && event->button() == Qt::LeftButton) { - m_dragging = false; - m_points.append (m_dragEnd); - } - - if (m_dragging && event->button() == Qt::RightButton) { - - } -} - -void KisToolPolygon::paint(KisCanvasPainter& gc) -{ - draw(gc); -} - -void KisToolPolygon::paint(KisCanvasPainter& gc, const TQRect&) -{ - draw(gc); -} - -void KisToolPolygon::draw() -{ - if (m_subject) { - KisCanvasController *controller = m_subject->canvasController(); - KisCanvas *canvas = controller->kiscanvas(); - KisCanvasPainter gc(canvas); - - draw(gc); - } -} - -void KisToolPolygon::draw(KisCanvasPainter& gc) -{ - if (!m_subject || !m_currentImage) - return; - - TQPen pen(TQt::white, 0, TQt::SolidLine); - - gc.setPen(pen); - gc.setRasterOp(TQt::XorROP); - - KisCanvasController *controller = m_subject->canvasController(); - KisPoint start, end; - TQPoint startPos; - TQPoint endPos; - - if (m_dragging) { - startPos = controller->windowToView(m_dragStart.floorTQPoint()); - endPos = controller->windowToView(m_dragEnd.floorTQPoint()); - gc.drawLine(startPos, endPos); - } else { - for (KisPointVector::iterator it = m_points.begin(); it != m_points.end(); ++it) { - - if (it == m_points.begin()) - { - start = (*it); - } else { - end = (*it); - - startPos = controller->windowToView(start.floorTQPoint()); - endPos = controller->windowToView(end.floorTQPoint()); - - gc.drawLine(startPos, endPos); - - start = end; - } - } - } -} - - - -void KisToolPolygon::setup(TDEActionCollection *collection) -{ - m_action = static_cast(collection->action(name())); - - if (m_action == 0) { - TDEShortcut shortcut(TQt::Key_Plus); - shortcut.append(TDEShortcut(TQt::Key_F9)); - m_action = new TDERadioAction(i18n("&Polygon"), - "tool_polygon", - shortcut, - this, - TQT_SLOT(activate()), - collection, - name()); - TQ_CHECK_PTR(m_action); - - m_action->setToolTip(i18n("Draw a polygon. Shift-mouseclick ends the polygon.")); - m_action->setExclusiveGroup("tools"); - m_ownAction = true; - } -} - -void KisToolPolygon::keyPress(TQKeyEvent *e) -{ - if (e->key()==TQt::Key_Escape) { - // erase old lines on canvas - draw(); - m_dragging = false; - m_points.clear(); - } -} - - -#include "kis_tool_polygon.moc" diff --git a/chalk/plugins/tools/tool_polygon/kis_tool_polygon.cpp b/chalk/plugins/tools/tool_polygon/kis_tool_polygon.cpp new file mode 100644 index 000000000..601fc6907 --- /dev/null +++ b/chalk/plugins/tools/tool_polygon/kis_tool_polygon.cpp @@ -0,0 +1,252 @@ +/* + * kis_tool_polygon.cpp -- part of Chalk + * + * Copyright (c) 2004 Michael Thaler + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + + +#include + +#include +#include + +#include +#include +#include +#include +#include + +#include "kis_doc.h" +#include "kis_view.h" +#include "kis_painter.h" +#include "kis_canvas_subject.h" +#include "kis_canvas_controller.h" +#include "kis_button_press_event.h" +#include "kis_button_release_event.h" +#include "kis_move_event.h" +#include "kis_paintop_registry.h" +#include "kis_canvas.h" +#include "kis_canvas_painter.h" +#include "kis_cursor.h" + +#include "kis_tool_polygon.h" + +KisToolPolygon::KisToolPolygon() + : super(i18n ("Polygon")), + m_dragging (false), + m_currentImage (0) +{ + setName("tool_polygon"); + setCursor(KisCursor::load("tool_polygon_cursor.png", 6, 6)); +} + +KisToolPolygon::~KisToolPolygon() +{ +} + +void KisToolPolygon::update (KisCanvasSubject *subject) +{ + super::update (subject); + if (m_subject) + m_currentImage = m_subject->currentImg (); +} + +void KisToolPolygon::buttonPress(KisButtonPressEvent *event) +{ + if (m_currentImage) { + if (event->button() == Qt::LeftButton && event->state() != ShiftButton) { + + m_dragging = true; + + if (m_points.isEmpty()) + { + m_dragStart = event->pos(); + m_dragEnd = event->pos(); + m_points.append(m_dragStart); + } else { + m_dragStart = m_dragEnd; + m_dragEnd = event->pos(); + draw(); + } + } else if (event->button() == Qt::LeftButton && event->state() == ShiftButton) { + finish(); + } + } +} + +void KisToolPolygon::finish() +{ + // erase old lines on canvas + draw(); + m_dragging = false; + + KisPaintDeviceSP device = m_currentImage->activeDevice (); + if (!device) return; + + KisPainter painter (device); + if (m_currentImage->undo()) painter.beginTransaction (i18n ("Polygon")); + + painter.setPaintColor(m_subject->fgColor()); + painter.setBackgroundColor(m_subject->bgColor()); + painter.setFillStyle(fillStyle()); + painter.setBrush(m_subject->currentBrush()); + painter.setPattern(m_subject->currentPattern()); + painter.setOpacity(m_opacity); + painter.setCompositeOp(m_compositeOp); + KisPaintOp * op = KisPaintOpRegistry::instance()->paintOp(m_subject->currentPaintop(), m_subject->currentPaintopSettings(), &painter); + painter.setPaintOp(op); // Painter takes ownership + + painter.paintPolygon(m_points); + + m_points.clear(); + + device->setDirty( painter.dirtyRect() ); + notifyModified(); + + if (m_currentImage->undo()) { + m_currentImage->undoAdapter()->addCommand(painter.endTransaction()); + } +} + +void KisToolPolygon::doubleClick( KisDoubleClickEvent * ) +{ + finish(); +} + +void KisToolPolygon::move(KisMoveEvent *event) +{ + if (m_dragging) { + // erase old lines on canvas + draw(); + // get current mouse position + m_dragEnd = event->pos(); + // draw new lines on canvas + draw(); + } +} + +void KisToolPolygon::buttonRelease(KisButtonReleaseEvent *event) +{ + if (!m_subject || !m_currentImage) + return; + + if (m_dragging && event->button() == Qt::LeftButton) { + m_dragging = false; + m_points.append (m_dragEnd); + } + + if (m_dragging && event->button() == Qt::RightButton) { + + } +} + +void KisToolPolygon::paint(KisCanvasPainter& gc) +{ + draw(gc); +} + +void KisToolPolygon::paint(KisCanvasPainter& gc, const TQRect&) +{ + draw(gc); +} + +void KisToolPolygon::draw() +{ + if (m_subject) { + KisCanvasController *controller = m_subject->canvasController(); + KisCanvas *canvas = controller->kiscanvas(); + KisCanvasPainter gc(canvas); + + draw(gc); + } +} + +void KisToolPolygon::draw(KisCanvasPainter& gc) +{ + if (!m_subject || !m_currentImage) + return; + + TQPen pen(TQt::white, 0, TQt::SolidLine); + + gc.setPen(pen); + gc.setRasterOp(TQt::XorROP); + + KisCanvasController *controller = m_subject->canvasController(); + KisPoint start, end; + TQPoint startPos; + TQPoint endPos; + + if (m_dragging) { + startPos = controller->windowToView(m_dragStart.floorTQPoint()); + endPos = controller->windowToView(m_dragEnd.floorTQPoint()); + gc.drawLine(startPos, endPos); + } else { + for (KisPointVector::iterator it = m_points.begin(); it != m_points.end(); ++it) { + + if (it == m_points.begin()) + { + start = (*it); + } else { + end = (*it); + + startPos = controller->windowToView(start.floorTQPoint()); + endPos = controller->windowToView(end.floorTQPoint()); + + gc.drawLine(startPos, endPos); + + start = end; + } + } + } +} + + + +void KisToolPolygon::setup(TDEActionCollection *collection) +{ + m_action = static_cast(collection->action(name())); + + if (m_action == 0) { + TDEShortcut shortcut(TQt::Key_Plus); + shortcut.append(TDEShortcut(TQt::Key_F9)); + m_action = new TDERadioAction(i18n("&Polygon"), + "tool_polygon", + shortcut, + this, + TQT_SLOT(activate()), + collection, + name()); + TQ_CHECK_PTR(m_action); + + m_action->setToolTip(i18n("Draw a polygon. Shift-mouseclick ends the polygon.")); + m_action->setExclusiveGroup("tools"); + m_ownAction = true; + } +} + +void KisToolPolygon::keyPress(TQKeyEvent *e) +{ + if (e->key()==TQt::Key_Escape) { + // erase old lines on canvas + draw(); + m_dragging = false; + m_points.clear(); + } +} + + +#include "kis_tool_polygon.moc" diff --git a/chalk/plugins/tools/tool_polygon/tool_polygon.cc b/chalk/plugins/tools/tool_polygon/tool_polygon.cc deleted file mode 100644 index 626a773d3..000000000 --- a/chalk/plugins/tools/tool_polygon/tool_polygon.cc +++ /dev/null @@ -1,62 +0,0 @@ -/* - * tool_polygon.cc -- Part of Chalk - * - * Copyright (c) 2004 Michael Thaler - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -#include -#include - -#include - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include "tool_polygon.h" -#include "tool_polygon.moc" -#include "kis_tool_polygon.h" - - -typedef KGenericFactory ToolPolygonFactory; -K_EXPORT_COMPONENT_FACTORY( chalktoolpolygon, ToolPolygonFactory( "chalk" ) ) - - -ToolPolygon::ToolPolygon(TQObject *parent, const char *name, const TQStringList &) - : KParts::Plugin(parent, name) -{ - setInstance(ToolPolygonFactory::instance()); - - if ( parent->inherits("KisToolRegistry") ) - { - KisToolRegistry * r = dynamic_cast( parent ); - r->add(new KisToolPolygonFactory()); - } - -} - -ToolPolygon::~ToolPolygon() -{ -} - -//#include "tool_polygon.moc" diff --git a/chalk/plugins/tools/tool_polygon/tool_polygon.cpp b/chalk/plugins/tools/tool_polygon/tool_polygon.cpp new file mode 100644 index 000000000..f903551fb --- /dev/null +++ b/chalk/plugins/tools/tool_polygon/tool_polygon.cpp @@ -0,0 +1,62 @@ +/* + * tool_polygon.cpp -- Part of Chalk + * + * Copyright (c) 2004 Michael Thaler + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include "tool_polygon.h" +#include "tool_polygon.moc" +#include "kis_tool_polygon.h" + + +typedef KGenericFactory ToolPolygonFactory; +K_EXPORT_COMPONENT_FACTORY( chalktoolpolygon, ToolPolygonFactory( "chalk" ) ) + + +ToolPolygon::ToolPolygon(TQObject *parent, const char *name, const TQStringList &) + : KParts::Plugin(parent, name) +{ + setInstance(ToolPolygonFactory::instance()); + + if ( parent->inherits("KisToolRegistry") ) + { + KisToolRegistry * r = dynamic_cast( parent ); + r->add(new KisToolPolygonFactory()); + } + +} + +ToolPolygon::~ToolPolygon() +{ +} + +//#include "tool_polygon.moc" diff --git a/chalk/plugins/tools/tool_polyline/Makefile.am b/chalk/plugins/tools/tool_polyline/Makefile.am index 1812b13bc..87fa1ce27 100644 --- a/chalk/plugins/tools/tool_polyline/Makefile.am +++ b/chalk/plugins/tools/tool_polyline/Makefile.am @@ -10,8 +10,8 @@ INCLUDES = -I$(srcdir)/../../../sdk \ $(all_includes) chalktoolpolyline_la_SOURCES = \ - tool_polyline.cc \ - kis_tool_polyline.cc + tool_polyline.cpp \ + kis_tool_polyline.cpp # Install this plugin in the KDE modules directory kde_module_LTLIBRARIES = chalktoolpolyline.la diff --git a/chalk/plugins/tools/tool_polyline/kis_tool_polyline.cc b/chalk/plugins/tools/tool_polyline/kis_tool_polyline.cc deleted file mode 100644 index c99513f47..000000000 --- a/chalk/plugins/tools/tool_polyline/kis_tool_polyline.cc +++ /dev/null @@ -1,271 +0,0 @@ -/* - * kis_tool_polyline.cc -- part of Chalk - * - * Copyright (c) 2004 Michael Thaler - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - - -#include - -#include -#include - -#include -#include -#include -#include -#include - -#include "kis_doc.h" -#include "kis_view.h" -#include "kis_painter.h" -#include "kis_canvas_subject.h" -#include "kis_canvas_controller.h" -#include "kis_button_press_event.h" -#include "kis_button_release_event.h" -#include "kis_move_event.h" -#include "kis_paintop_registry.h" -#include "kis_canvas.h" -#include "kis_canvas_painter.h" -#include "kis_cursor.h" - -#include "kis_tool_polyline.h" - -KisToolPolyline::KisToolPolyline() - : super(i18n ("Polyline")), - m_dragging (false), - m_currentImage (0) -{ - setName("tool_polyline"); - setCursor(KisCursor::load("tool_polyline_cursor.png", 6, 6)); -} - -KisToolPolyline::~KisToolPolyline() -{ -} - -void KisToolPolyline::update (KisCanvasSubject *subject) -{ - super::update (subject); - if (m_subject) - m_currentImage = m_subject->currentImg (); -} - -void KisToolPolyline::buttonPress(KisButtonPressEvent *event) -{ - if (m_currentImage) { - if (event->button() == Qt::LeftButton && event->state() != TQt::ShiftButton ) { - - m_dragging = true; - - if (m_points.isEmpty()) - { - m_dragStart = event->pos(); - m_dragEnd = event->pos(); - m_points.append(m_dragStart); - } else { - m_dragStart = m_dragEnd; - m_dragEnd = event->pos(); - draw(); - } - } else if (event->button() == Qt::LeftButton && event->state() == TQt::ShiftButton ) { - finish(); - } - } -} - -void KisToolPolyline::deactivate() -{ - draw(); - m_points.clear(); - m_dragging = false; -} - -void KisToolPolyline::finish() -{ - // erase old lines on canvas - draw(); - m_dragging = false; - - KisPaintDeviceSP device = m_currentImage->activeDevice (); - if (!device) return; - - KisPainter painter (device); - if (m_currentImage->undo()) painter.beginTransaction (i18n ("Polyline")); - - painter.setPaintColor(m_subject->fgColor()); - painter.setBrush(m_subject->currentBrush()); - painter.setOpacity(m_opacity); - painter.setCompositeOp(m_compositeOp); - KisPaintOp * op = KisPaintOpRegistry::instance()->paintOp(m_subject->currentPaintop(), m_subject->currentPaintopSettings(), &painter); - painter.setPaintOp(op); // Painter takes ownership - - KisPoint start,end; - KisPointVector::iterator it; - for( it = m_points.begin(); it != m_points.end(); ++it ) - { - if( it == m_points.begin() ) - { - start = (*it); - } else { - end = (*it); - painter.paintLine(start, PRESSURE_DEFAULT, 0, 0, end, PRESSURE_DEFAULT, 0, 0); - start = end; - } - } - m_points.clear(); - - device->setDirty( painter.dirtyRect() ); - notifyModified(); - - if (m_currentImage->undo()) { - m_currentImage->undoAdapter()->addCommand(painter.endTransaction()); - } - -} -void KisToolPolyline::move(KisMoveEvent *event) -{ - if (m_dragging) { - // erase old lines on canvas - draw(); - // get current mouse position - m_dragEnd = event->pos(); - // draw new lines on canvas - draw(); - } -} - -void KisToolPolyline::buttonRelease(KisButtonReleaseEvent *event) -{ - if (!m_subject || !m_currentImage) - return; - - if (m_dragging && event->button() == Qt::LeftButton) { - m_dragging = false; - m_points.append (m_dragEnd); - } - - if (m_dragging && event->button() == Qt::RightButton) { - - } -} - - -void KisToolPolyline::doubleClick(KisDoubleClickEvent *) -{ - finish(); -} - - -void KisToolPolyline::paint(KisCanvasPainter& gc) -{ - draw(gc); -} - -void KisToolPolyline::paint(KisCanvasPainter& gc, const TQRect&) -{ - draw(gc); -} - -void KisToolPolyline::draw() -{ - if (m_subject) { - KisCanvasController *controller = m_subject->canvasController(); - KisCanvas *canvas = controller->kiscanvas(); - KisCanvasPainter gc(canvas); - - draw(gc); - } -} - -void KisToolPolyline::draw(KisCanvasPainter& gc) -{ - if (!m_subject || !m_currentImage) - return; - - TQPen pen(TQt::white, 0, TQt::SolidLine); - - gc.setPen(pen); - gc.setRasterOp(TQt::XorROP); - - KisCanvasController *controller = m_subject->canvasController(); - KisPoint start, end; - TQPoint startPos; - TQPoint endPos; - - if (m_dragging) { - startPos = controller->windowToView(m_dragStart.floorTQPoint()); - endPos = controller->windowToView(m_dragEnd.floorTQPoint()); - gc.drawLine(startPos, endPos); - } else { - for (KisPointVector::iterator it = m_points.begin(); it != m_points.end(); ++it) { - - if (it == m_points.begin()) - { - start = (*it); - } else { - end = (*it); - - startPos = controller->windowToView(start.floorTQPoint()); - endPos = controller->windowToView(end.floorTQPoint()); - - gc.drawLine(startPos, endPos); - - start = end; - } - } - } -} - -void KisToolPolyline::setup(TDEActionCollection *collection) -{ - m_action = static_cast(collection->action(name())); - - if (m_action == 0) { - TDEShortcut shortcut(TQt::Key_Plus); - shortcut.append(TDEShortcut(TQt::Key_F9)); - m_action = new TDERadioAction(i18n("&Polyline"), - "polyline", - shortcut, - this, - TQT_SLOT(activate()), - collection, - name()); - TQ_CHECK_PTR(m_action); - - m_action->setToolTip(i18n("Draw a polyline. Shift-mouseclick ends the polyline.")); - m_action->setExclusiveGroup("tools"); - m_ownAction = true; - } -} - -TQString KisToolPolyline::quickHelp() const -{ - return i18n("Press shift-mouseclick to end the polyline."); -} - -void KisToolPolyline::keyPress(TQKeyEvent *e) -{ - if (e->key()==TQt::Key_Escape) { - // erase old lines on canvas - draw(); - m_dragging = false; - m_points.clear(); - } -} - -#include "kis_tool_polyline.moc" diff --git a/chalk/plugins/tools/tool_polyline/kis_tool_polyline.cpp b/chalk/plugins/tools/tool_polyline/kis_tool_polyline.cpp new file mode 100644 index 000000000..ab89cf3f4 --- /dev/null +++ b/chalk/plugins/tools/tool_polyline/kis_tool_polyline.cpp @@ -0,0 +1,271 @@ +/* + * kis_tool_polyline.cpp -- part of Chalk + * + * Copyright (c) 2004 Michael Thaler + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + + +#include + +#include +#include + +#include +#include +#include +#include +#include + +#include "kis_doc.h" +#include "kis_view.h" +#include "kis_painter.h" +#include "kis_canvas_subject.h" +#include "kis_canvas_controller.h" +#include "kis_button_press_event.h" +#include "kis_button_release_event.h" +#include "kis_move_event.h" +#include "kis_paintop_registry.h" +#include "kis_canvas.h" +#include "kis_canvas_painter.h" +#include "kis_cursor.h" + +#include "kis_tool_polyline.h" + +KisToolPolyline::KisToolPolyline() + : super(i18n ("Polyline")), + m_dragging (false), + m_currentImage (0) +{ + setName("tool_polyline"); + setCursor(KisCursor::load("tool_polyline_cursor.png", 6, 6)); +} + +KisToolPolyline::~KisToolPolyline() +{ +} + +void KisToolPolyline::update (KisCanvasSubject *subject) +{ + super::update (subject); + if (m_subject) + m_currentImage = m_subject->currentImg (); +} + +void KisToolPolyline::buttonPress(KisButtonPressEvent *event) +{ + if (m_currentImage) { + if (event->button() == Qt::LeftButton && event->state() != TQt::ShiftButton ) { + + m_dragging = true; + + if (m_points.isEmpty()) + { + m_dragStart = event->pos(); + m_dragEnd = event->pos(); + m_points.append(m_dragStart); + } else { + m_dragStart = m_dragEnd; + m_dragEnd = event->pos(); + draw(); + } + } else if (event->button() == Qt::LeftButton && event->state() == TQt::ShiftButton ) { + finish(); + } + } +} + +void KisToolPolyline::deactivate() +{ + draw(); + m_points.clear(); + m_dragging = false; +} + +void KisToolPolyline::finish() +{ + // erase old lines on canvas + draw(); + m_dragging = false; + + KisPaintDeviceSP device = m_currentImage->activeDevice (); + if (!device) return; + + KisPainter painter (device); + if (m_currentImage->undo()) painter.beginTransaction (i18n ("Polyline")); + + painter.setPaintColor(m_subject->fgColor()); + painter.setBrush(m_subject->currentBrush()); + painter.setOpacity(m_opacity); + painter.setCompositeOp(m_compositeOp); + KisPaintOp * op = KisPaintOpRegistry::instance()->paintOp(m_subject->currentPaintop(), m_subject->currentPaintopSettings(), &painter); + painter.setPaintOp(op); // Painter takes ownership + + KisPoint start,end; + KisPointVector::iterator it; + for( it = m_points.begin(); it != m_points.end(); ++it ) + { + if( it == m_points.begin() ) + { + start = (*it); + } else { + end = (*it); + painter.paintLine(start, PRESSURE_DEFAULT, 0, 0, end, PRESSURE_DEFAULT, 0, 0); + start = end; + } + } + m_points.clear(); + + device->setDirty( painter.dirtyRect() ); + notifyModified(); + + if (m_currentImage->undo()) { + m_currentImage->undoAdapter()->addCommand(painter.endTransaction()); + } + +} +void KisToolPolyline::move(KisMoveEvent *event) +{ + if (m_dragging) { + // erase old lines on canvas + draw(); + // get current mouse position + m_dragEnd = event->pos(); + // draw new lines on canvas + draw(); + } +} + +void KisToolPolyline::buttonRelease(KisButtonReleaseEvent *event) +{ + if (!m_subject || !m_currentImage) + return; + + if (m_dragging && event->button() == Qt::LeftButton) { + m_dragging = false; + m_points.append (m_dragEnd); + } + + if (m_dragging && event->button() == Qt::RightButton) { + + } +} + + +void KisToolPolyline::doubleClick(KisDoubleClickEvent *) +{ + finish(); +} + + +void KisToolPolyline::paint(KisCanvasPainter& gc) +{ + draw(gc); +} + +void KisToolPolyline::paint(KisCanvasPainter& gc, const TQRect&) +{ + draw(gc); +} + +void KisToolPolyline::draw() +{ + if (m_subject) { + KisCanvasController *controller = m_subject->canvasController(); + KisCanvas *canvas = controller->kiscanvas(); + KisCanvasPainter gc(canvas); + + draw(gc); + } +} + +void KisToolPolyline::draw(KisCanvasPainter& gc) +{ + if (!m_subject || !m_currentImage) + return; + + TQPen pen(TQt::white, 0, TQt::SolidLine); + + gc.setPen(pen); + gc.setRasterOp(TQt::XorROP); + + KisCanvasController *controller = m_subject->canvasController(); + KisPoint start, end; + TQPoint startPos; + TQPoint endPos; + + if (m_dragging) { + startPos = controller->windowToView(m_dragStart.floorTQPoint()); + endPos = controller->windowToView(m_dragEnd.floorTQPoint()); + gc.drawLine(startPos, endPos); + } else { + for (KisPointVector::iterator it = m_points.begin(); it != m_points.end(); ++it) { + + if (it == m_points.begin()) + { + start = (*it); + } else { + end = (*it); + + startPos = controller->windowToView(start.floorTQPoint()); + endPos = controller->windowToView(end.floorTQPoint()); + + gc.drawLine(startPos, endPos); + + start = end; + } + } + } +} + +void KisToolPolyline::setup(TDEActionCollection *collection) +{ + m_action = static_cast(collection->action(name())); + + if (m_action == 0) { + TDEShortcut shortcut(TQt::Key_Plus); + shortcut.append(TDEShortcut(TQt::Key_F9)); + m_action = new TDERadioAction(i18n("&Polyline"), + "polyline", + shortcut, + this, + TQT_SLOT(activate()), + collection, + name()); + TQ_CHECK_PTR(m_action); + + m_action->setToolTip(i18n("Draw a polyline. Shift-mouseclick ends the polyline.")); + m_action->setExclusiveGroup("tools"); + m_ownAction = true; + } +} + +TQString KisToolPolyline::quickHelp() const +{ + return i18n("Press shift-mouseclick to end the polyline."); +} + +void KisToolPolyline::keyPress(TQKeyEvent *e) +{ + if (e->key()==TQt::Key_Escape) { + // erase old lines on canvas + draw(); + m_dragging = false; + m_points.clear(); + } +} + +#include "kis_tool_polyline.moc" diff --git a/chalk/plugins/tools/tool_polyline/tool_polyline.cc b/chalk/plugins/tools/tool_polyline/tool_polyline.cc deleted file mode 100644 index a5bfa27f2..000000000 --- a/chalk/plugins/tools/tool_polyline/tool_polyline.cc +++ /dev/null @@ -1,64 +0,0 @@ -/* - * tool_polyline.cc -- Part of Chalk - * - * Copyright (c) 2004 Michael Thaler - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -#include -#include - -#include - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include "tool_polyline.h" -#include "kis_tool_polyline.h" - - -typedef KGenericFactory ToolPolylineFactory; -K_EXPORT_COMPONENT_FACTORY( chalktoolpolyline, ToolPolylineFactory( "chalk" ) ) - - -ToolPolyline::ToolPolyline(TQObject *parent, const char *name, const TQStringList &) - : KParts::Plugin(parent, name) -{ - setInstance(ToolPolylineFactory::instance()); - - if ( parent->inherits("KisToolRegistry") ) - { - KisToolRegistry * r = dynamic_cast(parent); - - r->add(new KisToolPolylineFactory()); - } - -} - -ToolPolyline::~ToolPolyline() -{ -} - -#include "tool_polyline.moc" diff --git a/chalk/plugins/tools/tool_polyline/tool_polyline.cpp b/chalk/plugins/tools/tool_polyline/tool_polyline.cpp new file mode 100644 index 000000000..d6abff71a --- /dev/null +++ b/chalk/plugins/tools/tool_polyline/tool_polyline.cpp @@ -0,0 +1,64 @@ +/* + * tool_polyline.cpp -- Part of Chalk + * + * Copyright (c) 2004 Michael Thaler + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "tool_polyline.h" +#include "kis_tool_polyline.h" + + +typedef KGenericFactory ToolPolylineFactory; +K_EXPORT_COMPONENT_FACTORY( chalktoolpolyline, ToolPolylineFactory( "chalk" ) ) + + +ToolPolyline::ToolPolyline(TQObject *parent, const char *name, const TQStringList &) + : KParts::Plugin(parent, name) +{ + setInstance(ToolPolylineFactory::instance()); + + if ( parent->inherits("KisToolRegistry") ) + { + KisToolRegistry * r = dynamic_cast(parent); + + r->add(new KisToolPolylineFactory()); + } + +} + +ToolPolyline::~ToolPolyline() +{ +} + +#include "tool_polyline.moc" diff --git a/chalk/plugins/tools/tool_selectsimilar/Makefile.am b/chalk/plugins/tools/tool_selectsimilar/Makefile.am index 5c1897f40..224f67ba4 100644 --- a/chalk/plugins/tools/tool_selectsimilar/Makefile.am +++ b/chalk/plugins/tools/tool_selectsimilar/Makefile.am @@ -9,7 +9,7 @@ INCLUDES = -I$(srcdir)/../../../sdk \ $(all_includes) -chalktoolselectsimilar_la_SOURCES = selectsimilar.cc kis_tool_selectsimilar.cc +chalktoolselectsimilar_la_SOURCES = selectsimilar.cpp kis_tool_selectsimilar.cpp noinst_HEADERS = selectsimilar.h kis_tool_selectsimilar.h kde_module_LTLIBRARIES = chalktoolselectsimilar.la diff --git a/chalk/plugins/tools/tool_selectsimilar/kis_tool_selectsimilar.cc b/chalk/plugins/tools/tool_selectsimilar/kis_tool_selectsimilar.cpp similarity index 100% rename from chalk/plugins/tools/tool_selectsimilar/kis_tool_selectsimilar.cc rename to chalk/plugins/tools/tool_selectsimilar/kis_tool_selectsimilar.cpp diff --git a/chalk/plugins/tools/tool_selectsimilar/selectsimilar.cc b/chalk/plugins/tools/tool_selectsimilar/selectsimilar.cpp similarity index 100% rename from chalk/plugins/tools/tool_selectsimilar/selectsimilar.cc rename to chalk/plugins/tools/tool_selectsimilar/selectsimilar.cpp diff --git a/chalk/plugins/tools/tool_star/Makefile.am b/chalk/plugins/tools/tool_star/Makefile.am index ed88d27ed..1f4627dd6 100644 --- a/chalk/plugins/tools/tool_star/Makefile.am +++ b/chalk/plugins/tools/tool_star/Makefile.am @@ -11,8 +11,8 @@ INCLUDES = -I$(srcdir)/../../../sdk \ chalktoolstar_la_SOURCES = \ wdg_tool_star.ui \ - tool_star.cc \ - kis_tool_star.cc + tool_star.cpp \ + kis_tool_star.cpp # Install this plugin in the KDE modules directory kde_module_LTLIBRARIES = chalktoolstar.la diff --git a/chalk/plugins/tools/tool_star/kis_tool_star.cc b/chalk/plugins/tools/tool_star/kis_tool_star.cc deleted file mode 100644 index cd4bb0b2e..000000000 --- a/chalk/plugins/tools/tool_star/kis_tool_star.cc +++ /dev/null @@ -1,245 +0,0 @@ -/* - * kis_tool_star.cc -- part of Chalk - * - * Copyright (c) 2004 Michael Thaler - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - - -#include - -#include -#include -#include - -#include -#include -#include -#include -#include - -#include "kis_doc.h" -#include "kis_view.h" -#include "kis_painter.h" -#include "kis_int_spinbox.h" -#include "kis_canvas_subject.h" -#include "kis_canvas_controller.h" -#include "kis_button_press_event.h" -#include "kis_button_release_event.h" -#include "kis_move_event.h" -#include "kis_paintop_registry.h" -#include "kis_canvas.h" -#include "kis_canvas_painter.h" -#include "kis_cursor.h" -#include "kis_int_spinbox.h" - -#include "kis_tool_star.h" -#include "wdg_tool_star.h" - -KisToolStar::KisToolStar() - : super(i18n("Star")), - m_dragging (false), - m_currentImage (0) -{ - setName("tool_star"); - setCursor(KisCursor::load("tool_star_cursor.png", 6, 6)); - m_innerOuterRatio=40; - m_vertices=5; -} - -KisToolStar::~KisToolStar() -{ -} - -void KisToolStar::update (KisCanvasSubject *subject) -{ - super::update (subject); - if (m_subject) - m_currentImage = m_subject->currentImg (); -} - -void KisToolStar::buttonPress(KisButtonPressEvent *event) -{ - if (m_currentImage && event->button() == Qt::LeftButton) { - m_dragging = true; - m_dragStart = event->pos(); - m_dragEnd = event->pos(); - m_vertices = m_optWidget->verticesSpinBox->value(); - m_innerOuterRatio = m_optWidget->ratioSpinBox->value(); - } -} - -void KisToolStar::move(KisMoveEvent *event) -{ - if (m_dragging) { - // erase old lines on canvas - draw(m_dragStart, m_dragEnd); - // move (alt) or resize star - if (event->state() & TQt::AltButton) { - KisPoint trans = event->pos() - m_dragEnd; - m_dragStart += trans; - m_dragEnd += trans; - } else { - m_dragEnd = event->pos(); - } - // draw new lines on canvas - draw(m_dragStart, m_dragEnd); - } -} - -void KisToolStar::buttonRelease(KisButtonReleaseEvent *event) -{ - if (!m_subject || !m_currentImage) - return; - - if (m_dragging && event->button() == Qt::LeftButton) { - // erase old lines on canvas - draw(m_dragStart, m_dragEnd); - m_dragging = false; - - if (m_dragStart == m_dragEnd) - return; - - if (!m_currentImage) - return; - - if (!m_currentImage->activeDevice()) - return; - - KisPaintDeviceSP device = m_currentImage->activeDevice ();; - KisPainter painter (device); - if (m_currentImage->undo()) painter.beginTransaction (i18n("Star")); - - painter.setPaintColor(m_subject->fgColor()); - painter.setBackgroundColor(m_subject->bgColor()); - painter.setFillStyle(fillStyle()); - painter.setBrush(m_subject->currentBrush()); - painter.setPattern(m_subject->currentPattern()); - painter.setOpacity(m_opacity); - painter.setCompositeOp(m_compositeOp); - KisPaintOp * op = KisPaintOpRegistry::instance()->paintOp(m_subject->currentPaintop(), m_subject->currentPaintopSettings(), &painter); - painter.setPaintOp(op); // Painter takes ownership - - vKisPoint coord = starCoordinates(m_vertices, m_dragStart.x(), m_dragStart.y(), m_dragEnd.x(), m_dragEnd.y()); - - painter.paintPolygon(coord); - - device->setDirty( painter.dirtyRect() ); - notifyModified(); - - if (m_currentImage->undo()) { - m_currentImage->undoAdapter()->addCommand(painter.endTransaction()); - } - } -} - -void KisToolStar::draw(const KisPoint& start, const KisPoint& end ) -{ - if (!m_subject || !m_currentImage) - return; - - KisCanvasController *controller = m_subject->canvasController(); - KisCanvas *canvas = controller->kiscanvas(); - KisCanvasPainter p (canvas); - TQPen pen(TQt::SolidLine); - - KisPoint startPos; - KisPoint endPos; - startPos = controller->windowToView(start); - endPos = controller->windowToView(end); - - p.setRasterOp(TQt::NotROP); - - vKisPoint points = starCoordinates(m_vertices, startPos.x(), startPos.y(), endPos.x(), endPos.y()); - - for (uint i = 0; i < points.count() - 1; i++) { - p.drawLine(points[i].floorTQPoint(), points[i + 1].floorTQPoint()); - } - p.drawLine(points[points.count() - 1].floorTQPoint(), points[0].floorTQPoint()); - - p.end (); -} - -void KisToolStar::setup(TDEActionCollection *collection) -{ - m_action = static_cast(collection->action(name())); - - if (m_action == 0) { - TDEShortcut shortcut(TQt::Key_Plus); - shortcut.append(TDEShortcut(TQt::Key_F9)); - m_action = new TDERadioAction(i18n("&Star"), - "tool_star", - shortcut, - this, - TQT_SLOT(activate()), - collection, - name()); - TQ_CHECK_PTR(m_action); - - m_action->setToolTip(i18n("Draw a star")); - m_action->setExclusiveGroup("tools"); - m_ownAction = true; - } -} - -vKisPoint KisToolStar::starCoordinates(int N, double mx, double my, double x, double y) -{ - double R=0, r=0; - TQ_INT32 n=0; - double angle; - - vKisPoint starCoordinatesArray(2*N); - - // the radius of the outer edges - R=sqrt((x-mx)*(x-mx)+(y-my)*(y-my)); - - // the radius of the inner edges - r=R*m_innerOuterRatio/100.0; - - // the angle - angle=-atan2((x-mx),(y-my)); - - //set outer edges - for(n=0;nratioSpinBox->setValue(m_innerOuterRatio); - - TQGridLayout *optionLayout = new TQGridLayout(widget, 1, 1); - super::addOptionWidgetLayout(optionLayout); - - optionLayout->addWidget(m_optWidget, 0, 0); - - return widget; -} - -#include "kis_tool_star.moc" diff --git a/chalk/plugins/tools/tool_star/kis_tool_star.cpp b/chalk/plugins/tools/tool_star/kis_tool_star.cpp new file mode 100644 index 000000000..3a260545b --- /dev/null +++ b/chalk/plugins/tools/tool_star/kis_tool_star.cpp @@ -0,0 +1,245 @@ +/* + * kis_tool_star.cpp -- part of Chalk + * + * Copyright (c) 2004 Michael Thaler + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + + +#include + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "kis_doc.h" +#include "kis_view.h" +#include "kis_painter.h" +#include "kis_int_spinbox.h" +#include "kis_canvas_subject.h" +#include "kis_canvas_controller.h" +#include "kis_button_press_event.h" +#include "kis_button_release_event.h" +#include "kis_move_event.h" +#include "kis_paintop_registry.h" +#include "kis_canvas.h" +#include "kis_canvas_painter.h" +#include "kis_cursor.h" +#include "kis_int_spinbox.h" + +#include "kis_tool_star.h" +#include "wdg_tool_star.h" + +KisToolStar::KisToolStar() + : super(i18n("Star")), + m_dragging (false), + m_currentImage (0) +{ + setName("tool_star"); + setCursor(KisCursor::load("tool_star_cursor.png", 6, 6)); + m_innerOuterRatio=40; + m_vertices=5; +} + +KisToolStar::~KisToolStar() +{ +} + +void KisToolStar::update (KisCanvasSubject *subject) +{ + super::update (subject); + if (m_subject) + m_currentImage = m_subject->currentImg (); +} + +void KisToolStar::buttonPress(KisButtonPressEvent *event) +{ + if (m_currentImage && event->button() == Qt::LeftButton) { + m_dragging = true; + m_dragStart = event->pos(); + m_dragEnd = event->pos(); + m_vertices = m_optWidget->verticesSpinBox->value(); + m_innerOuterRatio = m_optWidget->ratioSpinBox->value(); + } +} + +void KisToolStar::move(KisMoveEvent *event) +{ + if (m_dragging) { + // erase old lines on canvas + draw(m_dragStart, m_dragEnd); + // move (alt) or resize star + if (event->state() & TQt::AltButton) { + KisPoint trans = event->pos() - m_dragEnd; + m_dragStart += trans; + m_dragEnd += trans; + } else { + m_dragEnd = event->pos(); + } + // draw new lines on canvas + draw(m_dragStart, m_dragEnd); + } +} + +void KisToolStar::buttonRelease(KisButtonReleaseEvent *event) +{ + if (!m_subject || !m_currentImage) + return; + + if (m_dragging && event->button() == Qt::LeftButton) { + // erase old lines on canvas + draw(m_dragStart, m_dragEnd); + m_dragging = false; + + if (m_dragStart == m_dragEnd) + return; + + if (!m_currentImage) + return; + + if (!m_currentImage->activeDevice()) + return; + + KisPaintDeviceSP device = m_currentImage->activeDevice ();; + KisPainter painter (device); + if (m_currentImage->undo()) painter.beginTransaction (i18n("Star")); + + painter.setPaintColor(m_subject->fgColor()); + painter.setBackgroundColor(m_subject->bgColor()); + painter.setFillStyle(fillStyle()); + painter.setBrush(m_subject->currentBrush()); + painter.setPattern(m_subject->currentPattern()); + painter.setOpacity(m_opacity); + painter.setCompositeOp(m_compositeOp); + KisPaintOp * op = KisPaintOpRegistry::instance()->paintOp(m_subject->currentPaintop(), m_subject->currentPaintopSettings(), &painter); + painter.setPaintOp(op); // Painter takes ownership + + vKisPoint coord = starCoordinates(m_vertices, m_dragStart.x(), m_dragStart.y(), m_dragEnd.x(), m_dragEnd.y()); + + painter.paintPolygon(coord); + + device->setDirty( painter.dirtyRect() ); + notifyModified(); + + if (m_currentImage->undo()) { + m_currentImage->undoAdapter()->addCommand(painter.endTransaction()); + } + } +} + +void KisToolStar::draw(const KisPoint& start, const KisPoint& end ) +{ + if (!m_subject || !m_currentImage) + return; + + KisCanvasController *controller = m_subject->canvasController(); + KisCanvas *canvas = controller->kiscanvas(); + KisCanvasPainter p (canvas); + TQPen pen(TQt::SolidLine); + + KisPoint startPos; + KisPoint endPos; + startPos = controller->windowToView(start); + endPos = controller->windowToView(end); + + p.setRasterOp(TQt::NotROP); + + vKisPoint points = starCoordinates(m_vertices, startPos.x(), startPos.y(), endPos.x(), endPos.y()); + + for (uint i = 0; i < points.count() - 1; i++) { + p.drawLine(points[i].floorTQPoint(), points[i + 1].floorTQPoint()); + } + p.drawLine(points[points.count() - 1].floorTQPoint(), points[0].floorTQPoint()); + + p.end (); +} + +void KisToolStar::setup(TDEActionCollection *collection) +{ + m_action = static_cast(collection->action(name())); + + if (m_action == 0) { + TDEShortcut shortcut(TQt::Key_Plus); + shortcut.append(TDEShortcut(TQt::Key_F9)); + m_action = new TDERadioAction(i18n("&Star"), + "tool_star", + shortcut, + this, + TQT_SLOT(activate()), + collection, + name()); + TQ_CHECK_PTR(m_action); + + m_action->setToolTip(i18n("Draw a star")); + m_action->setExclusiveGroup("tools"); + m_ownAction = true; + } +} + +vKisPoint KisToolStar::starCoordinates(int N, double mx, double my, double x, double y) +{ + double R=0, r=0; + TQ_INT32 n=0; + double angle; + + vKisPoint starCoordinatesArray(2*N); + + // the radius of the outer edges + R=sqrt((x-mx)*(x-mx)+(y-my)*(y-my)); + + // the radius of the inner edges + r=R*m_innerOuterRatio/100.0; + + // the angle + angle=-atan2((x-mx),(y-my)); + + //set outer edges + for(n=0;nratioSpinBox->setValue(m_innerOuterRatio); + + TQGridLayout *optionLayout = new TQGridLayout(widget, 1, 1); + super::addOptionWidgetLayout(optionLayout); + + optionLayout->addWidget(m_optWidget, 0, 0); + + return widget; +} + +#include "kis_tool_star.moc" diff --git a/chalk/plugins/tools/tool_star/tool_star.cc b/chalk/plugins/tools/tool_star/tool_star.cc deleted file mode 100644 index 9ac1b62f8..000000000 --- a/chalk/plugins/tools/tool_star/tool_star.cc +++ /dev/null @@ -1,62 +0,0 @@ -/* - * tool_star.cc -- Part of Chalk - * - * Copyright (c) 2004 Michael Thaler - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -#include -#include - -#include - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include "tool_star.h" -#include "kis_tool_star.h" - - -typedef KGenericFactory ToolStarFactory; -K_EXPORT_COMPONENT_FACTORY( chalktoolstar, ToolStarFactory( "chalk" ) ) - - -ToolStar::ToolStar(TQObject *parent, const char *name, const TQStringList &) - : KParts::Plugin(parent, name) -{ - setInstance(ToolStarFactory::instance()); - - if ( parent->inherits("KisToolRegistry") ) - { - KisToolRegistry * r = dynamic_cast( parent ); - r->add(new KisToolStarFactory()); - } - -} - -ToolStar::~ToolStar() -{ -} - -#include "tool_star.moc" diff --git a/chalk/plugins/tools/tool_star/tool_star.cpp b/chalk/plugins/tools/tool_star/tool_star.cpp new file mode 100644 index 000000000..7309e8a1a --- /dev/null +++ b/chalk/plugins/tools/tool_star/tool_star.cpp @@ -0,0 +1,62 @@ +/* + * tool_star.cpp -- Part of Chalk + * + * Copyright (c) 2004 Michael Thaler + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "tool_star.h" +#include "kis_tool_star.h" + + +typedef KGenericFactory ToolStarFactory; +K_EXPORT_COMPONENT_FACTORY( chalktoolstar, ToolStarFactory( "chalk" ) ) + + +ToolStar::ToolStar(TQObject *parent, const char *name, const TQStringList &) + : KParts::Plugin(parent, name) +{ + setInstance(ToolStarFactory::instance()); + + if ( parent->inherits("KisToolRegistry") ) + { + KisToolRegistry * r = dynamic_cast( parent ); + r->add(new KisToolStarFactory()); + } + +} + +ToolStar::~ToolStar() +{ +} + +#include "tool_star.moc" diff --git a/chalk/plugins/tools/tool_transform/Makefile.am b/chalk/plugins/tools/tool_transform/Makefile.am index 12a32774c..a5adea177 100644 --- a/chalk/plugins/tools/tool_transform/Makefile.am +++ b/chalk/plugins/tools/tool_transform/Makefile.am @@ -11,8 +11,8 @@ INCLUDES = -I$(srcdir)/../../../sdk \ chalktooltransform_la_SOURCES = \ wdg_tool_transform.ui \ - tool_transform.cc \ - kis_tool_transform.cc + tool_transform.cpp \ + kis_tool_transform.cpp # Install this plugin in the KDE modules directory kde_module_LTLIBRARIES = chalktooltransform.la diff --git a/chalk/plugins/tools/tool_transform/kis_tool_transform.cc b/chalk/plugins/tools/tool_transform/kis_tool_transform.cc deleted file mode 100644 index de20ce7f6..000000000 --- a/chalk/plugins/tools/tool_transform/kis_tool_transform.cc +++ /dev/null @@ -1,916 +0,0 @@ -/* - * kis_tool_transform.cc -- part of Chalk - * - * Copyright (c) 2004 Boudewijn Rempt - * Copyright (c) 2005 Casper Boemann - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "kis_tool_transform.h" -#include "wdg_tool_transform.h" -#include "kis_canvas.h" -#include "kis_canvas_painter.h" - -namespace { - class TransformCmd : public KisSelectedTransaction { - typedef KisSelectedTransaction super; - - public: - TransformCmd(KisToolTransform *tool, KisPaintDeviceSP device, KisPaintDeviceSP origDevice, double scaleX, double scaleY, double tX, double tY, double a, KisSelectionSP origSel, TQPoint startPos, TQPoint endPos); - virtual ~TransformCmd(); - - public: - virtual void execute(); - virtual void unexecute(); - void transformArgs(double &sx, double &sy, double &tx, double &ty, double &a); - KisSelectionSP origSelection(TQPoint &startPos, TQPoint &endPos); - KisPaintDeviceSP theDevice(); - KisPaintDeviceSP origDevice(); - - private: - double m_scaleX; - double m_scaleY; - double m_translateX; - double m_translateY; - double m_a; - KisToolTransform *m_tool; - KisSelectionSP m_origSelection; - TQPoint m_startPos; - TQPoint m_endPos; - KisPaintDeviceSP m_device; - KisPaintDeviceSP m_origDevice; - }; - - TransformCmd::TransformCmd(KisToolTransform *tool, KisPaintDeviceSP device, KisPaintDeviceSP origDevice, double scaleX, double scaleY, double tX, double tY, double a, KisSelectionSP origSel, TQPoint startPos, TQPoint endPos) : - super(i18n("Transform"), device) - , m_scaleX(scaleX) - , m_scaleY(scaleY) - , m_translateX(tX) - , m_translateY(tY) - , m_a(a) - , m_tool(tool) - , m_origSelection(origSel) - , m_startPos(startPos) - , m_endPos(endPos) - , m_device(device) - , m_origDevice(origDevice) - { - } - - TransformCmd::~TransformCmd() - { - } - - void TransformCmd::transformArgs(double &sx, double &sy, double &tx, double &ty, double &a) - { - sx = m_scaleX; - sy = m_scaleY; - tx= m_translateX; - ty = m_translateY; - a = m_a; - } - - KisSelectionSP TransformCmd::origSelection(TQPoint &startPos, TQPoint &endPos) - { - startPos = m_startPos; - endPos = m_endPos; - return m_origSelection; - } - - void TransformCmd::execute() - { - super::execute(); - } - - void TransformCmd::unexecute() - { - super::unexecute(); - } - - KisPaintDeviceSP TransformCmd::theDevice() - { - return m_device; - } - - KisPaintDeviceSP TransformCmd::origDevice() - { - return m_origDevice; - } -} - -KisToolTransform::KisToolTransform() - : super(i18n("Transform")) - , m_wasPressed( false ) -{ - setName("tool_transform"); - setCursor(KisCursor::selectCursor()); - m_subject = 0; - m_selecting = false; - m_startPos = TQPoint(0, 0); - m_endPos = TQPoint(0, 0); - m_optWidget = 0; - m_sizeCursors[0] = KisCursor::sizeVerCursor(); - m_sizeCursors[1] = KisCursor::sizeBDiagCursor(); - m_sizeCursors[2] = KisCursor::sizeHorCursor(); - m_sizeCursors[3] = KisCursor::sizeFDiagCursor(); - m_sizeCursors[4] = KisCursor::sizeVerCursor(); - m_sizeCursors[5] = KisCursor::sizeBDiagCursor(); - m_sizeCursors[6] = KisCursor::sizeHorCursor(); - m_sizeCursors[7] = KisCursor::sizeFDiagCursor(); - m_origDevice = 0; - m_origSelection = 0; - -} - -KisToolTransform::~KisToolTransform() -{ -} - -void KisToolTransform::deactivate() -{ - if (m_subject && m_subject->undoAdapter()) m_subject->undoAdapter()->removeCommandHistoryListener( this ); - - KisImageSP img = m_subject->currentImg(); - if (!img) return; - - paintOutline(); - - disconnect(m_subject->currentImg().data(), TQT_SIGNAL(sigLayerActivated(KisLayerSP)), this, TQT_SLOT(slotLayerActivated(KisLayerSP))); -} - -void KisToolTransform::activate() -{ - if(m_subject && m_subject->currentImg() && m_subject->currentImg()->activeDevice()) - { - //connect(m_subject, commandExecuted(KCommand *c), this, notifyCommandAdded( KCommand * c)); - m_subject->undoAdapter()->setCommandHistoryListener( this ); - - KisToolControllerInterface *controller = m_subject->toolController(); - - if (controller) - controller->setCurrentTool(this); - - TransformCmd * cmd=0; - - if(m_subject->currentImg()->undoAdapter()->presentCommand()) - cmd = dynamic_cast(m_subject->currentImg()->undoAdapter()->presentCommand()); - - if (cmd == 0) { - initHandles(); - } - else - { - // One of our commands is on top - if(cmd->theDevice() == m_subject->currentImg()->activeDevice()) - { - // and it even has the same device - // We should ask for tool args and orig selection - m_origDevice = cmd->origDevice(); - cmd->transformArgs(m_scaleX, m_scaleY, m_translateX, m_translateY, m_a); - m_origSelection = cmd->origSelection(m_startPos, m_endPos); - m_org_cenX = (m_startPos.x() + m_endPos.x()) / 2.0; - m_org_cenY = (m_startPos.y() + m_endPos.y()) / 2.0; - paintOutline(); - } - else - initHandles(); - } - } - connect(m_subject->currentImg(), TQT_SIGNAL(sigLayerActivated(KisLayerSP)), this, TQT_SLOT(slotLayerActivated(KisLayerSP))); -} - -void KisToolTransform::initHandles() -{ - TQ_INT32 x,y,w,h; - KisImageSP img = m_subject->currentImg(); - - KisPaintDeviceSP dev = img->activeDevice(); - if (!dev ) return; - - // Create a lazy copy of the current state - m_origDevice = new KisPaintDevice(*dev.data()); - Q_ASSERT(m_origDevice); - - if(dev->hasSelection()) - { - KisSelectionSP sel = dev->selection(); - m_origSelection = new KisSelection(*sel.data()); - TQRect r = sel->selectedExactRect(); - r.rect(&x, &y, &w, &h); - } - else { - dev->exactBounds(x,y,w,h); - m_origSelection = 0; - } - m_startPos = TQPoint(x, y); - m_endPos = TQPoint(x+w-1, y+h-1); - m_org_cenX = (m_startPos.x() + m_endPos.x()) / 2.0; - m_org_cenY = (m_startPos.y() + m_endPos.y()) / 2.0; - - m_a = 0.0; - m_scaleX = 1.0; - m_scaleY = 1.0; - m_translateX = m_org_cenX; - m_translateY = m_org_cenY; - - m_subject->canvasController() ->updateCanvas(); -} - -void KisToolTransform::paint(KisCanvasPainter& gc) -{ - paintOutline(gc, TQRect()); -} - -void KisToolTransform::paint(KisCanvasPainter& gc, const TQRect& rc) -{ - paintOutline(gc, rc); -} - - -void KisToolTransform::buttonPress(KisButtonPressEvent *e) -{ - if (m_subject && e->button() == Qt::LeftButton) { - m_wasPressed = true; - } - - if (m_subject) { - KisImageSP img = m_subject->currentImg(); - - if (img && img->activeDevice() && e->button() == Qt::LeftButton) { - switch(m_function) - { - case ROTATE: - m_clickoffset = e->pos().floorTQPoint() - - TQPoint(static_cast(m_translateX),static_cast(m_translateY)); - m_clickangle = -m_a - atan2(m_clickoffset.x(),m_clickoffset.y()); - m_clickoffset = TQPoint(0, 0); - break; - case MOVE: - m_clickoffset = e->pos().floorTQPoint() - - TQPoint(static_cast(m_translateX),static_cast(m_translateY)); - break; - case TOPSCALE: - m_clickoffset = e->pos().floorTQPoint() - - TQPoint((m_topleft + m_topright)/2); - break; - case TOPRIGHTSCALE: - m_clickoffset = e->pos().floorTQPoint() - m_topright; - break; - case RIGHTSCALE: - m_clickoffset = e->pos().floorTQPoint() - - TQPoint((m_topright + m_bottomright)/2); - break; - case BOTTOMRIGHTSCALE: - m_clickoffset = e->pos().floorTQPoint() - m_bottomright; - break; - case BOTTOMSCALE: - m_clickoffset = e->pos().floorTQPoint() - - TQPoint((m_bottomleft + m_bottomright)/2); - break; - case BOTTOMLEFTSCALE: - m_clickoffset = e->pos().floorTQPoint() - m_bottomleft; - break; - case LEFTSCALE: - m_clickoffset = e->pos().floorTQPoint() - - TQPoint((m_topleft + m_bottomleft)/2); - break; - case TOPLEFTSCALE: - m_clickoffset = e->pos().floorTQPoint() - m_topleft; - break; - } - m_selecting = true; - m_actualyMoveWhileSelected = false; - } - } -} - -int KisToolTransform::det(TQPoint v,TQPoint w) -{ - return v.x()*w.y()-v.y()*w.x(); -} -int KisToolTransform::distsq(TQPoint v,TQPoint w) -{ - v -= w; - return v.x()*v.x() + v.y()*v.y(); -} - -void KisToolTransform::setFunctionalCursor() -{ - int rotOctant = 8 + int(8.5 + m_a* 4 / M_PI); - - int s; - if(m_scaleX*m_scaleY<0) - s = -1; - else - s=1; - - switch(m_function) - { - case MOVE: - setCursor(KisCursor::moveCursor()); - break; - case ROTATE: - setCursor(KisCursor::rotateCursor()); - break; - case TOPSCALE: - setCursor(m_sizeCursors[(0*s +rotOctant)%8]); - break; - case TOPRIGHTSCALE: - setCursor(m_sizeCursors[(1*s +rotOctant)%8]); - break; - case RIGHTSCALE: - setCursor(m_sizeCursors[(2*s +rotOctant)%8]); - break; - case BOTTOMRIGHTSCALE: - setCursor(m_sizeCursors[(3*s +rotOctant)%8]); - break; - case BOTTOMSCALE: - setCursor(m_sizeCursors[(4*s +rotOctant)%8]); - break; - case BOTTOMLEFTSCALE: - setCursor(m_sizeCursors[(5*s +rotOctant)%8]); - break; - case LEFTSCALE: - setCursor(m_sizeCursors[(6*s +rotOctant)%8]); - break; - case TOPLEFTSCALE: - setCursor(m_sizeCursors[(7*s +rotOctant)%8]); - break; - } -} - -void KisToolTransform::move(KisMoveEvent *e) -{ - if (m_subject) { - KisCanvasController *controller = m_subject->canvasController(); - - Q_ASSERT(controller); - TQPoint topleft = m_topleft; - TQPoint topright = m_topright; - TQPoint bottomleft = m_bottomleft; - TQPoint bottomright = m_bottomright; - - TQPoint mousePos = e->pos().floorTQPoint(); - - if (m_subject && m_selecting) { - paintOutline(); - m_actualyMoveWhileSelected = true; - mousePos -= m_clickoffset; - - // transform mousePos coords, so it seems like it isn't rotated and centered at 0,0 - double newX = invrotX(mousePos.x() - m_translateX, mousePos.y() - m_translateY); - double newY = invrotY(mousePos.x() - m_translateX, mousePos.y() - m_translateY); - double dx=0, dy=0; - double oldScaleX = m_scaleX; - double oldScaleY = m_scaleY; - - if(m_function == MOVE) - { - m_translateX += mousePos.x() - m_translateX; - m_translateY += mousePos.y() - m_translateY; - } - - if(m_function == ROTATE) - { - m_a = -atan2(mousePos.x() - m_translateX, mousePos.y() - m_translateY) - - m_clickangle; - } - - if(m_function == TOPSCALE) - { - dy = (newY - m_scaleY * (m_startPos.y() - m_org_cenY)) / 2; - m_scaleY = (newY - dy) / (m_startPos.y() - m_org_cenY); - - // enforce same acpect if shift button is pressed - if(e->state() & TQt::ShiftButton) - { - if(m_scaleX>0) // handle the mirrored cases - m_scaleX = fabs(m_scaleY); - else - m_scaleX = -fabs(m_scaleY); - } - } - - if(m_function == TOPRIGHTSCALE) - { - dx = (newX - m_scaleX * (m_endPos.x() - m_org_cenX)) / 2; - m_scaleX = (newX - dx) / (m_endPos.x() - m_org_cenX); - - dy = (newY - m_scaleY * (m_startPos.y() - m_org_cenY)) / 2; - m_scaleY = (newY - dy) / (m_startPos.y() - m_org_cenY); - - // enforce same aspect if shift button is pressed - if(e->state() & TQt::ShiftButton) - { - if(m_scaleX < m_scaleY) - { - if(m_scaleX>0) // handle the mirrored cases - m_scaleX = fabs(m_scaleY); - else - m_scaleX = -fabs(m_scaleY); - dx = (m_scaleX - oldScaleX) * (m_endPos.x() - m_org_cenX); - } - else - { - if(m_scaleY>0) // handle the mirrored cases - m_scaleY = fabs(m_scaleX); - else - m_scaleY = -fabs(m_scaleX); - dy = (m_scaleY - oldScaleY) * (m_startPos.y() - m_org_cenY); - } - } - } - - if(m_function == RIGHTSCALE) - { - dx = (newX - m_scaleX * (m_endPos.x() - m_org_cenX)) / 2; - m_scaleX = (newX - dx) / (m_endPos.x() - m_org_cenX); - - // enforce same acpect if shift button is pressed - if(e->state() & TQt::ShiftButton) - { - if(m_scaleY>0) // handle the mirrored cases - m_scaleY = fabs(m_scaleX); - else - m_scaleY = -fabs(m_scaleX); - } - } - - if(m_function == BOTTOMRIGHTSCALE) - { - dx = (newX - m_scaleX * (m_endPos.x() - m_org_cenX)) / 2; - m_scaleX = (newX - dx) / (m_endPos.x() - m_org_cenX); - - dy = (newY - m_scaleY * (m_endPos.y() - m_org_cenY)) / 2; - m_scaleY = (newY - dy) / (m_endPos.y() - m_org_cenY); - - // enforce same acpect if shift button is pressed - if(e->state() & TQt::ShiftButton) - { - if(m_scaleX < m_scaleY) - { - if(m_scaleX>0) // handle the mirrored cases - m_scaleX = fabs(m_scaleY); - else - m_scaleX = -fabs(m_scaleY); - dx = (m_scaleX - oldScaleX) * (m_endPos.x() - m_org_cenX); - } - else - { - if(m_scaleY>0) // handle the mirrored cases - m_scaleY = fabs(m_scaleX); - else - m_scaleY = -fabs(m_scaleX); - dy = (m_scaleY - oldScaleY) * (m_endPos.y() - m_org_cenY); - } - } - } - - if(m_function == BOTTOMSCALE) - { - dy = (newY - m_scaleY * (m_endPos.y() - m_org_cenY)) / 2; - m_scaleY = (newY - dy) / (m_endPos.y() - m_org_cenY); - - // enforce same acpect if shift button is pressed - if(e->state() & TQt::ShiftButton) - { - if(m_scaleX>0) // handle the mirrored cases - m_scaleX = fabs(m_scaleY); - else - m_scaleX = -fabs(m_scaleY); - } - } - - if(m_function == BOTTOMLEFTSCALE) - { - dx = (newX - m_scaleX * (m_startPos.x() - m_org_cenX)) / 2; - m_scaleX = (newX - dx) / (m_startPos.x() - m_org_cenX); - - dy = (newY - m_scaleY * (m_endPos.y() - m_org_cenY)) / 2; - m_scaleY = (newY - dy) / (m_endPos.y() - m_org_cenY); - - // enforce same acpect if shift button is pressed - if(e->state() & TQt::ShiftButton) - { - if(m_scaleX < m_scaleY) - { - if(m_scaleX>0) // handle the mirrored cases - m_scaleX = fabs(m_scaleY); - else - m_scaleX = -fabs(m_scaleY); - dx = (m_scaleX - oldScaleX) * (m_startPos.x() - m_org_cenX); - } - else - { - if(m_scaleY>0) // handle the mirrored cases - m_scaleY = fabs(m_scaleX); - else - m_scaleY = -fabs(m_scaleX); - dy = (m_scaleY - oldScaleY) * (m_endPos.y() - m_org_cenY); - } - } - } - - if(m_function == LEFTSCALE) - { - dx = (newX - m_scaleX * (m_startPos.x() - m_org_cenX)) / 2; - m_scaleX = (newX - dx) / (m_startPos.x() - m_org_cenX); - - // enforce same acpect if shift button is pressed - if(e->state() & TQt::ShiftButton) - { - if(m_scaleY>0) // handle the mirrored cases - m_scaleY = fabs(m_scaleX); - else - m_scaleY = -fabs(m_scaleX); - } - } - - if(m_function == TOPLEFTSCALE) - { - dx = (newX - m_scaleX * (m_startPos.x() - m_org_cenX)) / 2; - m_scaleX = (newX - dx) / (m_startPos.x() - m_org_cenX); - - dy = (newY - m_scaleY * (m_startPos.y() - m_org_cenY)) / 2; - m_scaleY = (newY - dy) / (m_startPos.y() - m_org_cenY); - - // enforce same acpect if shift button is pressed - if(e->state() & TQt::ShiftButton) - { - if(m_scaleX < m_scaleY) - { - if(m_scaleX>0) // handle the mirrored cases - m_scaleX = fabs(m_scaleY); - else - m_scaleX = -fabs(m_scaleY); - dx = (m_scaleX - oldScaleX) * (m_startPos.x() - m_org_cenX); - } - else - { - if(m_scaleY>0) // handle the mirrored cases - m_scaleY = fabs(m_scaleX); - else - m_scaleY = -fabs(m_scaleX); - dy = (m_scaleY - oldScaleY) * (m_startPos.y() - m_org_cenY); - } - } - } - - m_translateX += rotX(dx, dy); - m_translateY += rotY(dx, dy); - - paintOutline(); - } - else - { - if(det(mousePos - topleft, topright - topleft)>0) - m_function = ROTATE; - else if(det(mousePos - topright, bottomright - topright)>0) - m_function = ROTATE; - else if(det(mousePos - bottomright, bottomleft - bottomright)>0) - m_function = ROTATE; - else if(det(mousePos - bottomleft, topleft - bottomleft)>0) - m_function = ROTATE; - else - m_function = MOVE; - - int handleradius = int( 25 / (m_subject->zoomFactor() * m_subject->zoomFactor()) ); - - if(distsq(mousePos, (m_topleft + m_topright)/2)<=handleradius) - m_function = TOPSCALE; - if(distsq(mousePos, m_topright)<=handleradius) - m_function = TOPRIGHTSCALE; - if(distsq(mousePos, (m_topright + m_bottomright)/2)<=handleradius) - m_function = RIGHTSCALE; - if(distsq(mousePos, m_bottomright)<=handleradius) - m_function = BOTTOMRIGHTSCALE; - if(distsq(mousePos, (m_bottomleft + m_bottomright)/2)<=handleradius) - m_function = BOTTOMSCALE; - if(distsq(mousePos, m_bottomleft)<=handleradius) - m_function = BOTTOMLEFTSCALE; - if(distsq(mousePos, (m_topleft + m_bottomleft)/2)<=handleradius) - m_function = LEFTSCALE; - if(distsq(mousePos, m_topleft)<=handleradius) - m_function = TOPLEFTSCALE; - - setFunctionalCursor(); - } - } -} - -void KisToolTransform::buttonRelease(KisButtonReleaseEvent *e) -{ - if (m_subject && e->button() == Qt::LeftButton) { - if(!m_wasPressed) return; - m_wasPressed = false; - - KisImageSP img = m_subject->currentImg(); - - if (!img) - return; - - m_selecting = false; - - if(m_actualyMoveWhileSelected) - { - paintOutline(); - TQApplication::setOverrideCursor(KisCursor::waitCursor()); - transform(); - TQApplication::restoreOverrideCursor(); - } - } -} - -void KisToolTransform::paintOutline() -{ - if (m_subject) { - KisCanvasController *controller = m_subject->canvasController(); - KisCanvas *canvas = controller->kiscanvas(); - KisCanvasPainter gc(canvas); - TQRect rc; - - paintOutline(gc, rc); - } -} - -void KisToolTransform::recalcOutline() -{ - double x,y; - - m_sina = sin(m_a); - m_cosa = cos(m_a); - - x = (m_startPos.x() - m_org_cenX) * m_scaleX; - y = (m_startPos.y() - m_org_cenY) * m_scaleY; - m_topleft = TQPoint(int(rotX(x,y) + m_translateX+0.5), int(rotY(x,y) + m_translateY+0.5)); - - x = (m_endPos.x() - m_org_cenX) * m_scaleX; - y = (m_startPos.y() - m_org_cenY) * m_scaleY; - m_topright = TQPoint(int(rotX(x,y) + m_translateX+0.5), int(rotY(x,y) + m_translateY+0.5)); - - x = (m_startPos.x() - m_org_cenX) * m_scaleX; - y = (m_endPos.y() - m_org_cenY) * m_scaleY; - m_bottomleft = TQPoint(int(rotX(x,y) + m_translateX+0.5), int(rotY(x,y) + m_translateY+0.5)); - - x = (m_endPos.x() - m_org_cenX) * m_scaleX; - y = (m_endPos.y() - m_org_cenY) * m_scaleY; - m_bottomright = TQPoint(int(rotX(x,y) + m_translateX+0.5), int(rotY(x,y) + m_translateY+0.5)); -} - -void KisToolTransform::paintOutline(KisCanvasPainter& gc, const TQRect&) -{ - if (m_subject) { - KisCanvasController *controller = m_subject->canvasController(); - RasterOp op = gc.rasterOp(); - TQPen old = gc.pen(); - TQPen pen(TQt::SolidLine); - pen.setWidth(1); - Q_ASSERT(controller); - - recalcOutline(); - TQPoint topleft = controller->windowToView(m_topleft); - TQPoint topright = controller->windowToView(m_topright); - TQPoint bottomleft = controller->windowToView(m_bottomleft); - TQPoint bottomright = controller->windowToView(m_bottomright); - - gc.setRasterOp(TQt::NotROP); - gc.setPen(pen); - gc.drawRect(topleft.x()-4, topleft.y()-4, 8, 8); - gc.drawLine(topleft.x(), topleft.y(), (topleft.x()+topright.x())/2, (topleft.y()+topright.y())/2); - gc.drawRect((topleft.x()+topright.x())/2-4, (topleft.y()+topright.y())/2-4, 8, 8); - gc.drawLine((topleft.x()+topright.x())/2, (topleft.y()+topright.y())/2, topright.x(), topright.y()); - gc.drawRect(topright.x()-4, topright.y()-4, 8, 8); - gc.drawLine(topright.x(), topright.y(), (topright.x()+bottomright.x())/2, (topright.y()+bottomright.y())/2); - gc.drawRect((topright.x()+bottomright.x())/2-4, (topright.y()+bottomright.y())/2-4, 8, 8); - gc.drawLine((topright.x()+bottomright.x())/2, (topright.y()+bottomright.y())/2,bottomright.x(), bottomright.y()); - gc.drawRect(bottomright.x()-4, bottomright.y()-4, 8, 8); - gc.drawLine(bottomright.x(), bottomright.y(), (bottomleft.x()+bottomright.x())/2, (bottomleft.y()+bottomright.y())/2); - gc.drawRect((bottomleft.x()+bottomright.x())/2-4, (bottomleft.y()+bottomright.y())/2-4, 8, 8); - gc.drawLine((bottomleft.x()+bottomright.x())/2, (bottomleft.y()+bottomright.y())/2, bottomleft.x(), bottomleft.y()); - gc.drawRect(bottomleft.x()-4, bottomleft.y()-4, 8, 8); - gc.drawLine(bottomleft.x(), bottomleft.y(), (topleft.x()+bottomleft.x())/2, (topleft.y()+bottomleft.y())/2); - gc.drawRect((topleft.x()+bottomleft.x())/2-4, (topleft.y()+bottomleft.y())/2-4, 8, 8); - gc.drawLine((topleft.x()+bottomleft.x())/2, (topleft.y()+bottomleft.y())/2, topleft.x(), topleft.y()); - gc.setRasterOp(op); - gc.setPen(old); - } -} - -void KisToolTransform::transform() -{ - - KisImageSP img = m_subject->currentImg(); - - if (!img || !img->activeDevice()) - return; - - double tx = m_translateX - rotX(m_org_cenX * m_scaleX, m_org_cenY * m_scaleY); - double ty = m_translateY - rotY(m_org_cenX * m_scaleX, m_org_cenY * m_scaleY); - KisProgressDisplayInterface *progress = m_subject->progressDisplay(); - - // This mementoes the current state of the active device. - TransformCmd * transaction = new TransformCmd(this, img->activeDevice(), m_origDevice, - m_scaleX, m_scaleY, m_translateX, m_translateY, m_a, m_origSelection, m_startPos, m_endPos); - - // Copy the original state back. - TQRect rc = m_origDevice->extent(); - rc = rc.normalize(); - img->activeDevice()->clear(); - KisPainter gc(img->activeDevice()); - gc.bitBlt(rc.x(), rc.y(), COMPOSITE_COPY, m_origDevice, rc.x(), rc.y(), rc.width(), rc.height()); - gc.end(); - - // Also restore the original selection. - if(m_origSelection) - { - //TQRect rc = m_origSelection->extent(); - TQRect rc = m_origSelection->selectedRect(); - rc = rc.normalize(); - img->activeDevice()->selection()->clear(); - KisPainter sgc(img->activeDevice()->selection().data()); - sgc.bitBlt(rc.x(), rc.y(), COMPOSITE_COPY, m_origSelection.data(), rc.x(), rc.y(), rc.width(), rc.height()); - sgc.end(); - } - else - if(img->activeDevice()->hasSelection()) - img->activeDevice()->selection()->clear(); - - // Perform the transform. Since we copied the original state back, this doesn't degrade - // after many tweaks. Since we started the transaction before the copy back, the memento - // has the previous state. - KisTransformWorker t(img->activeDevice(), m_scaleX, m_scaleY, 0, 0, m_a, int(tx), int(ty), progress, m_filter); - t.run(); - - // If canceled, go back to the memento - if(t.isCanceled()) - { - transaction->unexecute(); - delete transaction; - return; - } - - img->activeDevice()->setDirty(rc); // XXX: This is not enough - should union with new extent - - // Else add the command -- this will have the memento from the previous state, - // and the transformed state from the original device we cached in our activated() - // method. - if (transaction) { - if (img->undo()) - img->undoAdapter()->addCommand(transaction); - else - delete transaction; - } -} - -void KisToolTransform::notifyCommandAdded( KCommand * command) -{ - TransformCmd * cmd = dynamic_cast(command); - if (cmd == 0) { - // The last added command wasn't one of ours; - // we should reset to the new state of the canvas. - // In effect we should treat this as if the tool has been just activated - initHandles(); - } -} - -void KisToolTransform::notifyCommandExecuted( KCommand * command) -{ - Q_UNUSED(command); - TransformCmd * cmd=0; - - if(m_subject->currentImg()->undoAdapter()->presentCommand()) - cmd = dynamic_cast(m_subject->currentImg()->undoAdapter()->presentCommand()); - - if (cmd == 0) { - // The command now on the top of the stack isn't one of ours - // We should treat this as if the tool has been just activated - initHandles(); - } - else - { - // One of our commands is now on top - // We should ask for tool args and orig selection - cmd->transformArgs(m_scaleX, m_scaleY, m_translateX, m_translateY, m_a); - m_origSelection = cmd->origSelection(m_startPos, m_endPos); - m_origDevice = cmd->origDevice(); - m_org_cenX = (m_startPos.x() + m_endPos.x()) / 2.0; - m_org_cenY = (m_startPos.y() + m_endPos.y()) / 2.0; - m_subject->canvasController() ->updateCanvas(); - } -} - -void KisToolTransform::slotSetFilter(const KisID &filterID) -{ - m_filter = KisFilterStrategyRegistry::instance()->get(filterID); -} - -void KisToolTransform::slotLayerActivated(KisLayerSP) -{ - activate(); -} - - -TQWidget* KisToolTransform::createOptionWidget(TQWidget* parent) -{ - - m_optWidget = new WdgToolTransform(parent); - TQ_CHECK_PTR(m_optWidget); - - m_optWidget->cmbFilter->clear(); - m_optWidget->cmbFilter->setIDList(KisFilterStrategyRegistry::instance()->listKeys()); - - m_optWidget->cmbFilter->setCurrentText("Mitchell"); - connect(m_optWidget->cmbFilter, TQT_SIGNAL(activated(const KisID &)), - this, TQT_SLOT(slotSetFilter(const KisID &))); - - KisID filterID = m_optWidget->cmbFilter->currentItem(); - m_filter = KisFilterStrategyRegistry::instance()->get(filterID); - -/* - connect(m_optWidget->intStartX, TQT_SIGNAL(valueChanged(int)), this, TQT_SLOT(setStartX(int))); - connect(m_optWidget->intStartY, TQT_SIGNAL(valueChanged(int)), this, TQT_SLOT(setStartY(int))); - connect(m_optWidget->intEndX, TQT_SIGNAL(valueChanged(int)), this, TQT_SLOT(setEndX(int))); - connect(m_optWidget->intEndY, TQT_SIGNAL(valueChanged(int)), this, TQT_SLOT(setEndY(int))); -*/ - m_optWidget->intStartX->hide(); - m_optWidget->intStartY->hide(); - m_optWidget->intEndX->hide(); - m_optWidget->intEndY->hide(); - m_optWidget->textLabel1->hide(); - m_optWidget->textLabel2->hide(); - m_optWidget->textLabel3->hide(); - m_optWidget->textLabel4->hide(); - return m_optWidget; -} - -TQWidget* KisToolTransform::optionWidget() -{ - return m_optWidget; -} - -void KisToolTransform::setup(TDEActionCollection *collection) -{ - m_action = static_cast(collection->action(name())); - - if (m_action == 0) { - m_action = new TDERadioAction(i18n("&Transform"), - "tool_transform", - 0, - this, - TQT_SLOT(activate()), - collection, - name()); - TQ_CHECK_PTR(m_action); - m_action->setToolTip(i18n("Transform a layer or a selection")); - m_action->setExclusiveGroup("tools"); - m_ownAction = true; - } -} - -#include "kis_tool_transform.moc" diff --git a/chalk/plugins/tools/tool_transform/kis_tool_transform.cpp b/chalk/plugins/tools/tool_transform/kis_tool_transform.cpp new file mode 100644 index 000000000..88a675663 --- /dev/null +++ b/chalk/plugins/tools/tool_transform/kis_tool_transform.cpp @@ -0,0 +1,916 @@ +/* + * kis_tool_transform.cpp -- part of Chalk + * + * Copyright (c) 2004 Boudewijn Rempt + * Copyright (c) 2005 Casper Boemann + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "kis_tool_transform.h" +#include "wdg_tool_transform.h" +#include "kis_canvas.h" +#include "kis_canvas_painter.h" + +namespace { + class TransformCmd : public KisSelectedTransaction { + typedef KisSelectedTransaction super; + + public: + TransformCmd(KisToolTransform *tool, KisPaintDeviceSP device, KisPaintDeviceSP origDevice, double scaleX, double scaleY, double tX, double tY, double a, KisSelectionSP origSel, TQPoint startPos, TQPoint endPos); + virtual ~TransformCmd(); + + public: + virtual void execute(); + virtual void unexecute(); + void transformArgs(double &sx, double &sy, double &tx, double &ty, double &a); + KisSelectionSP origSelection(TQPoint &startPos, TQPoint &endPos); + KisPaintDeviceSP theDevice(); + KisPaintDeviceSP origDevice(); + + private: + double m_scaleX; + double m_scaleY; + double m_translateX; + double m_translateY; + double m_a; + KisToolTransform *m_tool; + KisSelectionSP m_origSelection; + TQPoint m_startPos; + TQPoint m_endPos; + KisPaintDeviceSP m_device; + KisPaintDeviceSP m_origDevice; + }; + + TransformCmd::TransformCmd(KisToolTransform *tool, KisPaintDeviceSP device, KisPaintDeviceSP origDevice, double scaleX, double scaleY, double tX, double tY, double a, KisSelectionSP origSel, TQPoint startPos, TQPoint endPos) : + super(i18n("Transform"), device) + , m_scaleX(scaleX) + , m_scaleY(scaleY) + , m_translateX(tX) + , m_translateY(tY) + , m_a(a) + , m_tool(tool) + , m_origSelection(origSel) + , m_startPos(startPos) + , m_endPos(endPos) + , m_device(device) + , m_origDevice(origDevice) + { + } + + TransformCmd::~TransformCmd() + { + } + + void TransformCmd::transformArgs(double &sx, double &sy, double &tx, double &ty, double &a) + { + sx = m_scaleX; + sy = m_scaleY; + tx= m_translateX; + ty = m_translateY; + a = m_a; + } + + KisSelectionSP TransformCmd::origSelection(TQPoint &startPos, TQPoint &endPos) + { + startPos = m_startPos; + endPos = m_endPos; + return m_origSelection; + } + + void TransformCmd::execute() + { + super::execute(); + } + + void TransformCmd::unexecute() + { + super::unexecute(); + } + + KisPaintDeviceSP TransformCmd::theDevice() + { + return m_device; + } + + KisPaintDeviceSP TransformCmd::origDevice() + { + return m_origDevice; + } +} + +KisToolTransform::KisToolTransform() + : super(i18n("Transform")) + , m_wasPressed( false ) +{ + setName("tool_transform"); + setCursor(KisCursor::selectCursor()); + m_subject = 0; + m_selecting = false; + m_startPos = TQPoint(0, 0); + m_endPos = TQPoint(0, 0); + m_optWidget = 0; + m_sizeCursors[0] = KisCursor::sizeVerCursor(); + m_sizeCursors[1] = KisCursor::sizeBDiagCursor(); + m_sizeCursors[2] = KisCursor::sizeHorCursor(); + m_sizeCursors[3] = KisCursor::sizeFDiagCursor(); + m_sizeCursors[4] = KisCursor::sizeVerCursor(); + m_sizeCursors[5] = KisCursor::sizeBDiagCursor(); + m_sizeCursors[6] = KisCursor::sizeHorCursor(); + m_sizeCursors[7] = KisCursor::sizeFDiagCursor(); + m_origDevice = 0; + m_origSelection = 0; + +} + +KisToolTransform::~KisToolTransform() +{ +} + +void KisToolTransform::deactivate() +{ + if (m_subject && m_subject->undoAdapter()) m_subject->undoAdapter()->removeCommandHistoryListener( this ); + + KisImageSP img = m_subject->currentImg(); + if (!img) return; + + paintOutline(); + + disconnect(m_subject->currentImg().data(), TQT_SIGNAL(sigLayerActivated(KisLayerSP)), this, TQT_SLOT(slotLayerActivated(KisLayerSP))); +} + +void KisToolTransform::activate() +{ + if(m_subject && m_subject->currentImg() && m_subject->currentImg()->activeDevice()) + { + //connect(m_subject, commandExecuted(KCommand *c), this, notifyCommandAdded( KCommand * c)); + m_subject->undoAdapter()->setCommandHistoryListener( this ); + + KisToolControllerInterface *controller = m_subject->toolController(); + + if (controller) + controller->setCurrentTool(this); + + TransformCmd * cmd=0; + + if(m_subject->currentImg()->undoAdapter()->presentCommand()) + cmd = dynamic_cast(m_subject->currentImg()->undoAdapter()->presentCommand()); + + if (cmd == 0) { + initHandles(); + } + else + { + // One of our commands is on top + if(cmd->theDevice() == m_subject->currentImg()->activeDevice()) + { + // and it even has the same device + // We should ask for tool args and orig selection + m_origDevice = cmd->origDevice(); + cmd->transformArgs(m_scaleX, m_scaleY, m_translateX, m_translateY, m_a); + m_origSelection = cmd->origSelection(m_startPos, m_endPos); + m_org_cenX = (m_startPos.x() + m_endPos.x()) / 2.0; + m_org_cenY = (m_startPos.y() + m_endPos.y()) / 2.0; + paintOutline(); + } + else + initHandles(); + } + } + connect(m_subject->currentImg(), TQT_SIGNAL(sigLayerActivated(KisLayerSP)), this, TQT_SLOT(slotLayerActivated(KisLayerSP))); +} + +void KisToolTransform::initHandles() +{ + TQ_INT32 x,y,w,h; + KisImageSP img = m_subject->currentImg(); + + KisPaintDeviceSP dev = img->activeDevice(); + if (!dev ) return; + + // Create a lazy copy of the current state + m_origDevice = new KisPaintDevice(*dev.data()); + Q_ASSERT(m_origDevice); + + if(dev->hasSelection()) + { + KisSelectionSP sel = dev->selection(); + m_origSelection = new KisSelection(*sel.data()); + TQRect r = sel->selectedExactRect(); + r.rect(&x, &y, &w, &h); + } + else { + dev->exactBounds(x,y,w,h); + m_origSelection = 0; + } + m_startPos = TQPoint(x, y); + m_endPos = TQPoint(x+w-1, y+h-1); + m_org_cenX = (m_startPos.x() + m_endPos.x()) / 2.0; + m_org_cenY = (m_startPos.y() + m_endPos.y()) / 2.0; + + m_a = 0.0; + m_scaleX = 1.0; + m_scaleY = 1.0; + m_translateX = m_org_cenX; + m_translateY = m_org_cenY; + + m_subject->canvasController() ->updateCanvas(); +} + +void KisToolTransform::paint(KisCanvasPainter& gc) +{ + paintOutline(gc, TQRect()); +} + +void KisToolTransform::paint(KisCanvasPainter& gc, const TQRect& rc) +{ + paintOutline(gc, rc); +} + + +void KisToolTransform::buttonPress(KisButtonPressEvent *e) +{ + if (m_subject && e->button() == Qt::LeftButton) { + m_wasPressed = true; + } + + if (m_subject) { + KisImageSP img = m_subject->currentImg(); + + if (img && img->activeDevice() && e->button() == Qt::LeftButton) { + switch(m_function) + { + case ROTATE: + m_clickoffset = e->pos().floorTQPoint() + - TQPoint(static_cast(m_translateX),static_cast(m_translateY)); + m_clickangle = -m_a - atan2(m_clickoffset.x(),m_clickoffset.y()); + m_clickoffset = TQPoint(0, 0); + break; + case MOVE: + m_clickoffset = e->pos().floorTQPoint() + - TQPoint(static_cast(m_translateX),static_cast(m_translateY)); + break; + case TOPSCALE: + m_clickoffset = e->pos().floorTQPoint() + - TQPoint((m_topleft + m_topright)/2); + break; + case TOPRIGHTSCALE: + m_clickoffset = e->pos().floorTQPoint() - m_topright; + break; + case RIGHTSCALE: + m_clickoffset = e->pos().floorTQPoint() + - TQPoint((m_topright + m_bottomright)/2); + break; + case BOTTOMRIGHTSCALE: + m_clickoffset = e->pos().floorTQPoint() - m_bottomright; + break; + case BOTTOMSCALE: + m_clickoffset = e->pos().floorTQPoint() + - TQPoint((m_bottomleft + m_bottomright)/2); + break; + case BOTTOMLEFTSCALE: + m_clickoffset = e->pos().floorTQPoint() - m_bottomleft; + break; + case LEFTSCALE: + m_clickoffset = e->pos().floorTQPoint() + - TQPoint((m_topleft + m_bottomleft)/2); + break; + case TOPLEFTSCALE: + m_clickoffset = e->pos().floorTQPoint() - m_topleft; + break; + } + m_selecting = true; + m_actualyMoveWhileSelected = false; + } + } +} + +int KisToolTransform::det(TQPoint v,TQPoint w) +{ + return v.x()*w.y()-v.y()*w.x(); +} +int KisToolTransform::distsq(TQPoint v,TQPoint w) +{ + v -= w; + return v.x()*v.x() + v.y()*v.y(); +} + +void KisToolTransform::setFunctionalCursor() +{ + int rotOctant = 8 + int(8.5 + m_a* 4 / M_PI); + + int s; + if(m_scaleX*m_scaleY<0) + s = -1; + else + s=1; + + switch(m_function) + { + case MOVE: + setCursor(KisCursor::moveCursor()); + break; + case ROTATE: + setCursor(KisCursor::rotateCursor()); + break; + case TOPSCALE: + setCursor(m_sizeCursors[(0*s +rotOctant)%8]); + break; + case TOPRIGHTSCALE: + setCursor(m_sizeCursors[(1*s +rotOctant)%8]); + break; + case RIGHTSCALE: + setCursor(m_sizeCursors[(2*s +rotOctant)%8]); + break; + case BOTTOMRIGHTSCALE: + setCursor(m_sizeCursors[(3*s +rotOctant)%8]); + break; + case BOTTOMSCALE: + setCursor(m_sizeCursors[(4*s +rotOctant)%8]); + break; + case BOTTOMLEFTSCALE: + setCursor(m_sizeCursors[(5*s +rotOctant)%8]); + break; + case LEFTSCALE: + setCursor(m_sizeCursors[(6*s +rotOctant)%8]); + break; + case TOPLEFTSCALE: + setCursor(m_sizeCursors[(7*s +rotOctant)%8]); + break; + } +} + +void KisToolTransform::move(KisMoveEvent *e) +{ + if (m_subject) { + KisCanvasController *controller = m_subject->canvasController(); + + Q_ASSERT(controller); + TQPoint topleft = m_topleft; + TQPoint topright = m_topright; + TQPoint bottomleft = m_bottomleft; + TQPoint bottomright = m_bottomright; + + TQPoint mousePos = e->pos().floorTQPoint(); + + if (m_subject && m_selecting) { + paintOutline(); + m_actualyMoveWhileSelected = true; + mousePos -= m_clickoffset; + + // transform mousePos coords, so it seems like it isn't rotated and centered at 0,0 + double newX = invrotX(mousePos.x() - m_translateX, mousePos.y() - m_translateY); + double newY = invrotY(mousePos.x() - m_translateX, mousePos.y() - m_translateY); + double dx=0, dy=0; + double oldScaleX = m_scaleX; + double oldScaleY = m_scaleY; + + if(m_function == MOVE) + { + m_translateX += mousePos.x() - m_translateX; + m_translateY += mousePos.y() - m_translateY; + } + + if(m_function == ROTATE) + { + m_a = -atan2(mousePos.x() - m_translateX, mousePos.y() - m_translateY) + - m_clickangle; + } + + if(m_function == TOPSCALE) + { + dy = (newY - m_scaleY * (m_startPos.y() - m_org_cenY)) / 2; + m_scaleY = (newY - dy) / (m_startPos.y() - m_org_cenY); + + // enforce same acpect if shift button is pressed + if(e->state() & TQt::ShiftButton) + { + if(m_scaleX>0) // handle the mirrored cases + m_scaleX = fabs(m_scaleY); + else + m_scaleX = -fabs(m_scaleY); + } + } + + if(m_function == TOPRIGHTSCALE) + { + dx = (newX - m_scaleX * (m_endPos.x() - m_org_cenX)) / 2; + m_scaleX = (newX - dx) / (m_endPos.x() - m_org_cenX); + + dy = (newY - m_scaleY * (m_startPos.y() - m_org_cenY)) / 2; + m_scaleY = (newY - dy) / (m_startPos.y() - m_org_cenY); + + // enforce same aspect if shift button is pressed + if(e->state() & TQt::ShiftButton) + { + if(m_scaleX < m_scaleY) + { + if(m_scaleX>0) // handle the mirrored cases + m_scaleX = fabs(m_scaleY); + else + m_scaleX = -fabs(m_scaleY); + dx = (m_scaleX - oldScaleX) * (m_endPos.x() - m_org_cenX); + } + else + { + if(m_scaleY>0) // handle the mirrored cases + m_scaleY = fabs(m_scaleX); + else + m_scaleY = -fabs(m_scaleX); + dy = (m_scaleY - oldScaleY) * (m_startPos.y() - m_org_cenY); + } + } + } + + if(m_function == RIGHTSCALE) + { + dx = (newX - m_scaleX * (m_endPos.x() - m_org_cenX)) / 2; + m_scaleX = (newX - dx) / (m_endPos.x() - m_org_cenX); + + // enforce same acpect if shift button is pressed + if(e->state() & TQt::ShiftButton) + { + if(m_scaleY>0) // handle the mirrored cases + m_scaleY = fabs(m_scaleX); + else + m_scaleY = -fabs(m_scaleX); + } + } + + if(m_function == BOTTOMRIGHTSCALE) + { + dx = (newX - m_scaleX * (m_endPos.x() - m_org_cenX)) / 2; + m_scaleX = (newX - dx) / (m_endPos.x() - m_org_cenX); + + dy = (newY - m_scaleY * (m_endPos.y() - m_org_cenY)) / 2; + m_scaleY = (newY - dy) / (m_endPos.y() - m_org_cenY); + + // enforce same acpect if shift button is pressed + if(e->state() & TQt::ShiftButton) + { + if(m_scaleX < m_scaleY) + { + if(m_scaleX>0) // handle the mirrored cases + m_scaleX = fabs(m_scaleY); + else + m_scaleX = -fabs(m_scaleY); + dx = (m_scaleX - oldScaleX) * (m_endPos.x() - m_org_cenX); + } + else + { + if(m_scaleY>0) // handle the mirrored cases + m_scaleY = fabs(m_scaleX); + else + m_scaleY = -fabs(m_scaleX); + dy = (m_scaleY - oldScaleY) * (m_endPos.y() - m_org_cenY); + } + } + } + + if(m_function == BOTTOMSCALE) + { + dy = (newY - m_scaleY * (m_endPos.y() - m_org_cenY)) / 2; + m_scaleY = (newY - dy) / (m_endPos.y() - m_org_cenY); + + // enforce same acpect if shift button is pressed + if(e->state() & TQt::ShiftButton) + { + if(m_scaleX>0) // handle the mirrored cases + m_scaleX = fabs(m_scaleY); + else + m_scaleX = -fabs(m_scaleY); + } + } + + if(m_function == BOTTOMLEFTSCALE) + { + dx = (newX - m_scaleX * (m_startPos.x() - m_org_cenX)) / 2; + m_scaleX = (newX - dx) / (m_startPos.x() - m_org_cenX); + + dy = (newY - m_scaleY * (m_endPos.y() - m_org_cenY)) / 2; + m_scaleY = (newY - dy) / (m_endPos.y() - m_org_cenY); + + // enforce same acpect if shift button is pressed + if(e->state() & TQt::ShiftButton) + { + if(m_scaleX < m_scaleY) + { + if(m_scaleX>0) // handle the mirrored cases + m_scaleX = fabs(m_scaleY); + else + m_scaleX = -fabs(m_scaleY); + dx = (m_scaleX - oldScaleX) * (m_startPos.x() - m_org_cenX); + } + else + { + if(m_scaleY>0) // handle the mirrored cases + m_scaleY = fabs(m_scaleX); + else + m_scaleY = -fabs(m_scaleX); + dy = (m_scaleY - oldScaleY) * (m_endPos.y() - m_org_cenY); + } + } + } + + if(m_function == LEFTSCALE) + { + dx = (newX - m_scaleX * (m_startPos.x() - m_org_cenX)) / 2; + m_scaleX = (newX - dx) / (m_startPos.x() - m_org_cenX); + + // enforce same acpect if shift button is pressed + if(e->state() & TQt::ShiftButton) + { + if(m_scaleY>0) // handle the mirrored cases + m_scaleY = fabs(m_scaleX); + else + m_scaleY = -fabs(m_scaleX); + } + } + + if(m_function == TOPLEFTSCALE) + { + dx = (newX - m_scaleX * (m_startPos.x() - m_org_cenX)) / 2; + m_scaleX = (newX - dx) / (m_startPos.x() - m_org_cenX); + + dy = (newY - m_scaleY * (m_startPos.y() - m_org_cenY)) / 2; + m_scaleY = (newY - dy) / (m_startPos.y() - m_org_cenY); + + // enforce same acpect if shift button is pressed + if(e->state() & TQt::ShiftButton) + { + if(m_scaleX < m_scaleY) + { + if(m_scaleX>0) // handle the mirrored cases + m_scaleX = fabs(m_scaleY); + else + m_scaleX = -fabs(m_scaleY); + dx = (m_scaleX - oldScaleX) * (m_startPos.x() - m_org_cenX); + } + else + { + if(m_scaleY>0) // handle the mirrored cases + m_scaleY = fabs(m_scaleX); + else + m_scaleY = -fabs(m_scaleX); + dy = (m_scaleY - oldScaleY) * (m_startPos.y() - m_org_cenY); + } + } + } + + m_translateX += rotX(dx, dy); + m_translateY += rotY(dx, dy); + + paintOutline(); + } + else + { + if(det(mousePos - topleft, topright - topleft)>0) + m_function = ROTATE; + else if(det(mousePos - topright, bottomright - topright)>0) + m_function = ROTATE; + else if(det(mousePos - bottomright, bottomleft - bottomright)>0) + m_function = ROTATE; + else if(det(mousePos - bottomleft, topleft - bottomleft)>0) + m_function = ROTATE; + else + m_function = MOVE; + + int handleradius = int( 25 / (m_subject->zoomFactor() * m_subject->zoomFactor()) ); + + if(distsq(mousePos, (m_topleft + m_topright)/2)<=handleradius) + m_function = TOPSCALE; + if(distsq(mousePos, m_topright)<=handleradius) + m_function = TOPRIGHTSCALE; + if(distsq(mousePos, (m_topright + m_bottomright)/2)<=handleradius) + m_function = RIGHTSCALE; + if(distsq(mousePos, m_bottomright)<=handleradius) + m_function = BOTTOMRIGHTSCALE; + if(distsq(mousePos, (m_bottomleft + m_bottomright)/2)<=handleradius) + m_function = BOTTOMSCALE; + if(distsq(mousePos, m_bottomleft)<=handleradius) + m_function = BOTTOMLEFTSCALE; + if(distsq(mousePos, (m_topleft + m_bottomleft)/2)<=handleradius) + m_function = LEFTSCALE; + if(distsq(mousePos, m_topleft)<=handleradius) + m_function = TOPLEFTSCALE; + + setFunctionalCursor(); + } + } +} + +void KisToolTransform::buttonRelease(KisButtonReleaseEvent *e) +{ + if (m_subject && e->button() == Qt::LeftButton) { + if(!m_wasPressed) return; + m_wasPressed = false; + + KisImageSP img = m_subject->currentImg(); + + if (!img) + return; + + m_selecting = false; + + if(m_actualyMoveWhileSelected) + { + paintOutline(); + TQApplication::setOverrideCursor(KisCursor::waitCursor()); + transform(); + TQApplication::restoreOverrideCursor(); + } + } +} + +void KisToolTransform::paintOutline() +{ + if (m_subject) { + KisCanvasController *controller = m_subject->canvasController(); + KisCanvas *canvas = controller->kiscanvas(); + KisCanvasPainter gc(canvas); + TQRect rc; + + paintOutline(gc, rc); + } +} + +void KisToolTransform::recalcOutline() +{ + double x,y; + + m_sina = sin(m_a); + m_cosa = cos(m_a); + + x = (m_startPos.x() - m_org_cenX) * m_scaleX; + y = (m_startPos.y() - m_org_cenY) * m_scaleY; + m_topleft = TQPoint(int(rotX(x,y) + m_translateX+0.5), int(rotY(x,y) + m_translateY+0.5)); + + x = (m_endPos.x() - m_org_cenX) * m_scaleX; + y = (m_startPos.y() - m_org_cenY) * m_scaleY; + m_topright = TQPoint(int(rotX(x,y) + m_translateX+0.5), int(rotY(x,y) + m_translateY+0.5)); + + x = (m_startPos.x() - m_org_cenX) * m_scaleX; + y = (m_endPos.y() - m_org_cenY) * m_scaleY; + m_bottomleft = TQPoint(int(rotX(x,y) + m_translateX+0.5), int(rotY(x,y) + m_translateY+0.5)); + + x = (m_endPos.x() - m_org_cenX) * m_scaleX; + y = (m_endPos.y() - m_org_cenY) * m_scaleY; + m_bottomright = TQPoint(int(rotX(x,y) + m_translateX+0.5), int(rotY(x,y) + m_translateY+0.5)); +} + +void KisToolTransform::paintOutline(KisCanvasPainter& gc, const TQRect&) +{ + if (m_subject) { + KisCanvasController *controller = m_subject->canvasController(); + RasterOp op = gc.rasterOp(); + TQPen old = gc.pen(); + TQPen pen(TQt::SolidLine); + pen.setWidth(1); + Q_ASSERT(controller); + + recalcOutline(); + TQPoint topleft = controller->windowToView(m_topleft); + TQPoint topright = controller->windowToView(m_topright); + TQPoint bottomleft = controller->windowToView(m_bottomleft); + TQPoint bottomright = controller->windowToView(m_bottomright); + + gc.setRasterOp(TQt::NotROP); + gc.setPen(pen); + gc.drawRect(topleft.x()-4, topleft.y()-4, 8, 8); + gc.drawLine(topleft.x(), topleft.y(), (topleft.x()+topright.x())/2, (topleft.y()+topright.y())/2); + gc.drawRect((topleft.x()+topright.x())/2-4, (topleft.y()+topright.y())/2-4, 8, 8); + gc.drawLine((topleft.x()+topright.x())/2, (topleft.y()+topright.y())/2, topright.x(), topright.y()); + gc.drawRect(topright.x()-4, topright.y()-4, 8, 8); + gc.drawLine(topright.x(), topright.y(), (topright.x()+bottomright.x())/2, (topright.y()+bottomright.y())/2); + gc.drawRect((topright.x()+bottomright.x())/2-4, (topright.y()+bottomright.y())/2-4, 8, 8); + gc.drawLine((topright.x()+bottomright.x())/2, (topright.y()+bottomright.y())/2,bottomright.x(), bottomright.y()); + gc.drawRect(bottomright.x()-4, bottomright.y()-4, 8, 8); + gc.drawLine(bottomright.x(), bottomright.y(), (bottomleft.x()+bottomright.x())/2, (bottomleft.y()+bottomright.y())/2); + gc.drawRect((bottomleft.x()+bottomright.x())/2-4, (bottomleft.y()+bottomright.y())/2-4, 8, 8); + gc.drawLine((bottomleft.x()+bottomright.x())/2, (bottomleft.y()+bottomright.y())/2, bottomleft.x(), bottomleft.y()); + gc.drawRect(bottomleft.x()-4, bottomleft.y()-4, 8, 8); + gc.drawLine(bottomleft.x(), bottomleft.y(), (topleft.x()+bottomleft.x())/2, (topleft.y()+bottomleft.y())/2); + gc.drawRect((topleft.x()+bottomleft.x())/2-4, (topleft.y()+bottomleft.y())/2-4, 8, 8); + gc.drawLine((topleft.x()+bottomleft.x())/2, (topleft.y()+bottomleft.y())/2, topleft.x(), topleft.y()); + gc.setRasterOp(op); + gc.setPen(old); + } +} + +void KisToolTransform::transform() +{ + + KisImageSP img = m_subject->currentImg(); + + if (!img || !img->activeDevice()) + return; + + double tx = m_translateX - rotX(m_org_cenX * m_scaleX, m_org_cenY * m_scaleY); + double ty = m_translateY - rotY(m_org_cenX * m_scaleX, m_org_cenY * m_scaleY); + KisProgressDisplayInterface *progress = m_subject->progressDisplay(); + + // This mementoes the current state of the active device. + TransformCmd * transaction = new TransformCmd(this, img->activeDevice(), m_origDevice, + m_scaleX, m_scaleY, m_translateX, m_translateY, m_a, m_origSelection, m_startPos, m_endPos); + + // Copy the original state back. + TQRect rc = m_origDevice->extent(); + rc = rc.normalize(); + img->activeDevice()->clear(); + KisPainter gc(img->activeDevice()); + gc.bitBlt(rc.x(), rc.y(), COMPOSITE_COPY, m_origDevice, rc.x(), rc.y(), rc.width(), rc.height()); + gc.end(); + + // Also restore the original selection. + if(m_origSelection) + { + //TQRect rc = m_origSelection->extent(); + TQRect rc = m_origSelection->selectedRect(); + rc = rc.normalize(); + img->activeDevice()->selection()->clear(); + KisPainter sgc(img->activeDevice()->selection().data()); + sgc.bitBlt(rc.x(), rc.y(), COMPOSITE_COPY, m_origSelection.data(), rc.x(), rc.y(), rc.width(), rc.height()); + sgc.end(); + } + else + if(img->activeDevice()->hasSelection()) + img->activeDevice()->selection()->clear(); + + // Perform the transform. Since we copied the original state back, this doesn't degrade + // after many tweaks. Since we started the transaction before the copy back, the memento + // has the previous state. + KisTransformWorker t(img->activeDevice(), m_scaleX, m_scaleY, 0, 0, m_a, int(tx), int(ty), progress, m_filter); + t.run(); + + // If canceled, go back to the memento + if(t.isCanceled()) + { + transaction->unexecute(); + delete transaction; + return; + } + + img->activeDevice()->setDirty(rc); // XXX: This is not enough - should union with new extent + + // Else add the command -- this will have the memento from the previous state, + // and the transformed state from the original device we cached in our activated() + // method. + if (transaction) { + if (img->undo()) + img->undoAdapter()->addCommand(transaction); + else + delete transaction; + } +} + +void KisToolTransform::notifyCommandAdded( KCommand * command) +{ + TransformCmd * cmd = dynamic_cast(command); + if (cmd == 0) { + // The last added command wasn't one of ours; + // we should reset to the new state of the canvas. + // In effect we should treat this as if the tool has been just activated + initHandles(); + } +} + +void KisToolTransform::notifyCommandExecuted( KCommand * command) +{ + Q_UNUSED(command); + TransformCmd * cmd=0; + + if(m_subject->currentImg()->undoAdapter()->presentCommand()) + cmd = dynamic_cast(m_subject->currentImg()->undoAdapter()->presentCommand()); + + if (cmd == 0) { + // The command now on the top of the stack isn't one of ours + // We should treat this as if the tool has been just activated + initHandles(); + } + else + { + // One of our commands is now on top + // We should ask for tool args and orig selection + cmd->transformArgs(m_scaleX, m_scaleY, m_translateX, m_translateY, m_a); + m_origSelection = cmd->origSelection(m_startPos, m_endPos); + m_origDevice = cmd->origDevice(); + m_org_cenX = (m_startPos.x() + m_endPos.x()) / 2.0; + m_org_cenY = (m_startPos.y() + m_endPos.y()) / 2.0; + m_subject->canvasController() ->updateCanvas(); + } +} + +void KisToolTransform::slotSetFilter(const KisID &filterID) +{ + m_filter = KisFilterStrategyRegistry::instance()->get(filterID); +} + +void KisToolTransform::slotLayerActivated(KisLayerSP) +{ + activate(); +} + + +TQWidget* KisToolTransform::createOptionWidget(TQWidget* parent) +{ + + m_optWidget = new WdgToolTransform(parent); + TQ_CHECK_PTR(m_optWidget); + + m_optWidget->cmbFilter->clear(); + m_optWidget->cmbFilter->setIDList(KisFilterStrategyRegistry::instance()->listKeys()); + + m_optWidget->cmbFilter->setCurrentText("Mitchell"); + connect(m_optWidget->cmbFilter, TQT_SIGNAL(activated(const KisID &)), + this, TQT_SLOT(slotSetFilter(const KisID &))); + + KisID filterID = m_optWidget->cmbFilter->currentItem(); + m_filter = KisFilterStrategyRegistry::instance()->get(filterID); + +/* + connect(m_optWidget->intStartX, TQT_SIGNAL(valueChanged(int)), this, TQT_SLOT(setStartX(int))); + connect(m_optWidget->intStartY, TQT_SIGNAL(valueChanged(int)), this, TQT_SLOT(setStartY(int))); + connect(m_optWidget->intEndX, TQT_SIGNAL(valueChanged(int)), this, TQT_SLOT(setEndX(int))); + connect(m_optWidget->intEndY, TQT_SIGNAL(valueChanged(int)), this, TQT_SLOT(setEndY(int))); +*/ + m_optWidget->intStartX->hide(); + m_optWidget->intStartY->hide(); + m_optWidget->intEndX->hide(); + m_optWidget->intEndY->hide(); + m_optWidget->textLabel1->hide(); + m_optWidget->textLabel2->hide(); + m_optWidget->textLabel3->hide(); + m_optWidget->textLabel4->hide(); + return m_optWidget; +} + +TQWidget* KisToolTransform::optionWidget() +{ + return m_optWidget; +} + +void KisToolTransform::setup(TDEActionCollection *collection) +{ + m_action = static_cast(collection->action(name())); + + if (m_action == 0) { + m_action = new TDERadioAction(i18n("&Transform"), + "tool_transform", + 0, + this, + TQT_SLOT(activate()), + collection, + name()); + TQ_CHECK_PTR(m_action); + m_action->setToolTip(i18n("Transform a layer or a selection")); + m_action->setExclusiveGroup("tools"); + m_ownAction = true; + } +} + +#include "kis_tool_transform.moc" diff --git a/chalk/plugins/tools/tool_transform/tool_transform.cc b/chalk/plugins/tools/tool_transform/tool_transform.cc deleted file mode 100644 index 82941e92c..000000000 --- a/chalk/plugins/tools/tool_transform/tool_transform.cc +++ /dev/null @@ -1,64 +0,0 @@ -/* - * tool_transform.cc -- Part of Chalk - * - * Copyright (c) 2004 Boudewijn Rempt (boud@valdyas.org) - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -#include -#include - -#include - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include "tool_transform.h" -#include "kis_tool_transform.h" - - -typedef KGenericFactory ToolTransformFactory; -K_EXPORT_COMPONENT_FACTORY( chalktooltransform, ToolTransformFactory( "chalk" ) ) - - -ToolTransform::ToolTransform(TQObject *parent, const char *name, const TQStringList &) - : KParts::Plugin(parent, name) -{ - setInstance(ToolTransformFactory::instance()); - - if ( parent->inherits("KisToolRegistry") ) - { - KisToolRegistry * r = dynamic_cast(parent); - KisToolTransformFactory * f = new KisToolTransformFactory(); - TQ_CHECK_PTR(f); - r->add(f); - } - -} - -ToolTransform::~ToolTransform() -{ -} - -#include "tool_transform.moc" diff --git a/chalk/plugins/tools/tool_transform/tool_transform.cpp b/chalk/plugins/tools/tool_transform/tool_transform.cpp new file mode 100644 index 000000000..0f0dde27d --- /dev/null +++ b/chalk/plugins/tools/tool_transform/tool_transform.cpp @@ -0,0 +1,64 @@ +/* + * tool_transform.cpp -- Part of Chalk + * + * Copyright (c) 2004 Boudewijn Rempt (boud@valdyas.org) + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "tool_transform.h" +#include "kis_tool_transform.h" + + +typedef KGenericFactory ToolTransformFactory; +K_EXPORT_COMPONENT_FACTORY( chalktooltransform, ToolTransformFactory( "chalk" ) ) + + +ToolTransform::ToolTransform(TQObject *parent, const char *name, const TQStringList &) + : KParts::Plugin(parent, name) +{ + setInstance(ToolTransformFactory::instance()); + + if ( parent->inherits("KisToolRegistry") ) + { + KisToolRegistry * r = dynamic_cast(parent); + KisToolTransformFactory * f = new KisToolTransformFactory(); + TQ_CHECK_PTR(f); + r->add(f); + } + +} + +ToolTransform::~ToolTransform() +{ +} + +#include "tool_transform.moc" diff --git a/chalk/plugins/viewplugins/colorrange/Makefile.am b/chalk/plugins/viewplugins/colorrange/Makefile.am index 1c8547e29..c072f78cb 100644 --- a/chalk/plugins/viewplugins/colorrange/Makefile.am +++ b/chalk/plugins/viewplugins/colorrange/Makefile.am @@ -7,7 +7,7 @@ INCLUDES = -I$(srcdir)/../../../sdk \ kde_module_LTLIBRARIES = chalkcolorrange.la -chalkcolorrange_la_SOURCES = colorrange.cc dlg_colorrange.cc wdg_colorrange.ui +chalkcolorrange_la_SOURCES = colorrange.cpp dlg_colorrange.cpp wdg_colorrange.ui noinst_HEADERS = wdg_colorrange.h dlg_colorrange.h colorrange.h chalkcolorrange_la_LIBADD = $(LIB_KOFFICEUI) ../../../libchalkcommon.la \ diff --git a/chalk/plugins/viewplugins/colorrange/colorrange.cc b/chalk/plugins/viewplugins/colorrange/colorrange.cpp similarity index 100% rename from chalk/plugins/viewplugins/colorrange/colorrange.cc rename to chalk/plugins/viewplugins/colorrange/colorrange.cpp diff --git a/chalk/plugins/viewplugins/colorrange/dlg_colorrange.cc b/chalk/plugins/viewplugins/colorrange/dlg_colorrange.cc deleted file mode 100644 index 453bbec27..000000000 --- a/chalk/plugins/viewplugins/colorrange/dlg_colorrange.cc +++ /dev/null @@ -1,351 +0,0 @@ -/* - * dlg_colorrange.cc - part of KimageShop^WKrayon^WChalk - * - * Copyright (c) 2004 Boudewijn Rempt - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "dlg_colorrange.h" -#include "wdg_colorrange.h" - -namespace { - -// XXX: Poynton says: hsv/hls is not what one ought to use for colour calculations. -// Unfortunately, I don't know enough to be able to use anything else. - - bool isReddish(int h) - { - return ((h > 330 && h < 360) || ( h > 0 && h < 40)); - } - - bool isYellowish(int h) - { - return (h> 40 && h < 65); - } - - bool isGreenish(int h) - { - return (h > 70 && h < 155); - } - - bool isCyanish(int h) - { - return (h > 150 && h < 190); - } - - bool isBlueish(int h) - { - return (h > 185 && h < 270); - } - - bool isMagentaish(int h) - { - return (h > 265 && h < 330); - } - - bool isHighlight(int v) - { - return (v > 200); - } - - bool isMidTone(int v) - { - return (v > 100 && v < 200); - } - - bool isShadow(int v) - { - return (v < 100); - } - -} - -TQ_UINT32 matchColors(const TQColor & c, enumAction action) -{ - int r = c.red(); - int g = c.green(); - int b = c.blue(); - - int h, s, v; - rgb_to_hsv(r, g, b, &h, &s, &v); - - - - // XXX: Map the degree in which the colors conform to the requirement - // to a range of selectedness between 0 and 255 - - // XXX: Implement out-of-gamut using lcms - - switch(action) { - - case REDS: - if (isReddish(h)) - return MAX_SELECTED; - else - return MIN_SELECTED; - case YELLOWS: - if (isYellowish(h)) { - return MAX_SELECTED; - } - else - return MIN_SELECTED; - case GREENS: - if (isGreenish(h)) - return MAX_SELECTED; - else - return MIN_SELECTED; - case CYANS: - if (isCyanish(h)) - return MAX_SELECTED; - else - return MIN_SELECTED; - case BLUES: - if (isBlueish(h)) - return MAX_SELECTED; - else - return MIN_SELECTED; - case MAGENTAS: - if (isMagentaish(h)) - return MAX_SELECTED; - else - return MIN_SELECTED; - case HIGHLIGHTS: - if (isHighlight(v)) - return MAX_SELECTED; - else - return MIN_SELECTED; - case MIDTONES: - if (isMidTone(v)) - return MAX_SELECTED; - else - return MIN_SELECTED; - case SHADOWS: - if (isShadow(v)) - return MAX_SELECTED; - else - return MIN_SELECTED; - }; - - return MIN_SELECTED; -} - - - -DlgColorRange::DlgColorRange( KisView * view, KisPaintDeviceSP dev, TQWidget * parent, const char * name) - : super (parent, name, true, i18n("Color Range"), Ok | Cancel, Ok) -{ - m_dev = dev; - m_view = view; - - m_subject = view->canvasSubject(); - - m_page = new WdgColorRange(this, "color_range"); - TQ_CHECK_PTR(m_page); - - setCaption(i18n("Color Range")); - setMainWidget(m_page); - resize(m_page->sizeHint()); - - if (m_dev->image()->undo()) m_transaction = new KisSelectedTransaction(i18n("Select by Color Range"), m_dev); - - if(! m_dev->hasSelection()) - m_dev->selection()->clear(); - m_selection = m_dev->selection(); - - updatePreview(); - - m_invert = false; - m_mode = SELECTION_ADD; - m_currentAction = REDS; - - connect(this, TQT_SIGNAL(okClicked()), - this, TQT_SLOT(okClicked())); - - connect(this, TQT_SIGNAL(cancelClicked()), - this, TQT_SLOT(cancelClicked())); - - connect(m_page->chkInvert, TQT_SIGNAL(clicked()), - this, TQT_SLOT(slotInvertClicked())); - - connect(m_page->cmbSelect, TQT_SIGNAL(activated(int)), - this, TQT_SLOT(slotSelectionTypeChanged(int))); - - connect (m_page->radioAdd, TQT_SIGNAL(toggled(bool)), - this, TQT_SLOT(slotAdd(bool))); - - connect (m_page->radioSubtract, TQT_SIGNAL(toggled(bool)), - this, TQT_SLOT(slotSubtract(bool))); - - connect (m_page->bnSelect, TQT_SIGNAL(clicked()), - this, TQT_SLOT(slotSelectClicked())); - - connect (m_page->bnDeselect, TQT_SIGNAL(clicked()), - this, TQT_SLOT(slotDeselectClicked())); - -} - -DlgColorRange::~DlgColorRange() -{ - delete m_page; -} - - -void DlgColorRange::updatePreview() -{ - if (!m_selection) return; - - TQ_INT32 x, y, w, h; - m_dev->exactBounds(x, y, w, h); - TQPixmap pix = TQPixmap(m_selection->maskImage().smoothScale(350, 350, TQ_ScaleMin)); - m_subject->canvasController()->updateCanvas(); - m_page->pixSelection->setPixmap(pix); -} - -void DlgColorRange::okClicked() -{ - m_dev->setDirty(); - m_dev->emitSelectionChanged(); - - if (m_dev->image()->undo()) m_subject->undoAdapter()->addCommand(m_transaction); - accept(); -} - -void DlgColorRange::cancelClicked() -{ - if (m_dev->image()->undo()) m_transaction->unexecute(); - - m_subject->canvasController()->updateCanvas(); - reject(); -} - -void DlgColorRange::slotInvertClicked() -{ - m_invert = m_page->chkInvert->isChecked(); -} - -void DlgColorRange::slotSelectionTypeChanged(int index) -{ - m_currentAction = (enumAction)index; -} - -void DlgColorRange::slotSubtract(bool on) -{ - if (on) - m_mode = SELECTION_SUBTRACT; -} -void DlgColorRange::slotAdd(bool on) -{ - if (on) - m_mode = SELECTION_ADD; -} - -void DlgColorRange::slotSelectClicked() -{ - TQApplication::setOverrideCursor(KisCursor::waitCursor()); - // XXX: Multithread this! - TQ_INT32 x, y, w, h; - m_dev->exactBounds(x, y, w, h); - KisColorSpace * cs = m_dev->colorSpace(); - TQ_UINT8 opacity; - for (int y2 = y; y2 < h - y; ++y2) { - KisHLineIterator hiter = m_dev->createHLineIterator(x, y2, w, false); - KisHLineIterator selIter = m_selection ->createHLineIterator(x, y2, w, true); - while (!hiter.isDone()) { - TQColor c; - - cs->toTQColor(hiter.rawData(), &c, &opacity); - // Don't try to select transparent pixels. - if (opacity > OPACITY_TRANSPARENT) { - TQ_UINT8 match = matchColors(c, m_currentAction); - - if (match) { - // Personally, I think the invert option a bit silly. But it's possible I don't quite understand it. BSAR. - if (!m_invert) { - if (m_mode == SELECTION_ADD) { - *(selIter.rawData()) = match; - } - else if (m_mode == SELECTION_SUBTRACT) { - TQ_UINT8 selectedness = *(selIter.rawData()); - if (match < selectedness) { - *(selIter.rawData()) = selectedness - match; - } - else { - *(selIter.rawData()) = 0; - } - } - } - else { - if (m_mode == SELECTION_ADD) { - TQ_UINT8 selectedness = *(selIter.rawData()); - if (match < selectedness) { - *(selIter.rawData()) = selectedness - match; - } - else { - *(selIter.rawData()) = 0; - } - } - else if (m_mode == SELECTION_SUBTRACT) { - *(selIter.rawData()) = match; - } - } - } - } - ++hiter; - ++selIter; - } - } - updatePreview(); - TQApplication::restoreOverrideCursor(); -} - -void DlgColorRange::slotDeselectClicked() -{ - m_dev->selection()->clear(); - updatePreview(); -} - - -#include "dlg_colorrange.moc" diff --git a/chalk/plugins/viewplugins/colorrange/dlg_colorrange.cpp b/chalk/plugins/viewplugins/colorrange/dlg_colorrange.cpp new file mode 100644 index 000000000..82748f4c8 --- /dev/null +++ b/chalk/plugins/viewplugins/colorrange/dlg_colorrange.cpp @@ -0,0 +1,351 @@ +/* + * dlg_colorrange.cpp - part of KimageShop^WKrayon^WChalk + * + * Copyright (c) 2004 Boudewijn Rempt + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "dlg_colorrange.h" +#include "wdg_colorrange.h" + +namespace { + +// XXX: Poynton says: hsv/hls is not what one ought to use for colour calculations. +// Unfortunately, I don't know enough to be able to use anything else. + + bool isReddish(int h) + { + return ((h > 330 && h < 360) || ( h > 0 && h < 40)); + } + + bool isYellowish(int h) + { + return (h> 40 && h < 65); + } + + bool isGreenish(int h) + { + return (h > 70 && h < 155); + } + + bool isCyanish(int h) + { + return (h > 150 && h < 190); + } + + bool isBlueish(int h) + { + return (h > 185 && h < 270); + } + + bool isMagentaish(int h) + { + return (h > 265 && h < 330); + } + + bool isHighlight(int v) + { + return (v > 200); + } + + bool isMidTone(int v) + { + return (v > 100 && v < 200); + } + + bool isShadow(int v) + { + return (v < 100); + } + +} + +TQ_UINT32 matchColors(const TQColor & c, enumAction action) +{ + int r = c.red(); + int g = c.green(); + int b = c.blue(); + + int h, s, v; + rgb_to_hsv(r, g, b, &h, &s, &v); + + + + // XXX: Map the degree in which the colors conform to the requirement + // to a range of selectedness between 0 and 255 + + // XXX: Implement out-of-gamut using lcms + + switch(action) { + + case REDS: + if (isReddish(h)) + return MAX_SELECTED; + else + return MIN_SELECTED; + case YELLOWS: + if (isYellowish(h)) { + return MAX_SELECTED; + } + else + return MIN_SELECTED; + case GREENS: + if (isGreenish(h)) + return MAX_SELECTED; + else + return MIN_SELECTED; + case CYANS: + if (isCyanish(h)) + return MAX_SELECTED; + else + return MIN_SELECTED; + case BLUES: + if (isBlueish(h)) + return MAX_SELECTED; + else + return MIN_SELECTED; + case MAGENTAS: + if (isMagentaish(h)) + return MAX_SELECTED; + else + return MIN_SELECTED; + case HIGHLIGHTS: + if (isHighlight(v)) + return MAX_SELECTED; + else + return MIN_SELECTED; + case MIDTONES: + if (isMidTone(v)) + return MAX_SELECTED; + else + return MIN_SELECTED; + case SHADOWS: + if (isShadow(v)) + return MAX_SELECTED; + else + return MIN_SELECTED; + }; + + return MIN_SELECTED; +} + + + +DlgColorRange::DlgColorRange( KisView * view, KisPaintDeviceSP dev, TQWidget * parent, const char * name) + : super (parent, name, true, i18n("Color Range"), Ok | Cancel, Ok) +{ + m_dev = dev; + m_view = view; + + m_subject = view->canvasSubject(); + + m_page = new WdgColorRange(this, "color_range"); + TQ_CHECK_PTR(m_page); + + setCaption(i18n("Color Range")); + setMainWidget(m_page); + resize(m_page->sizeHint()); + + if (m_dev->image()->undo()) m_transaction = new KisSelectedTransaction(i18n("Select by Color Range"), m_dev); + + if(! m_dev->hasSelection()) + m_dev->selection()->clear(); + m_selection = m_dev->selection(); + + updatePreview(); + + m_invert = false; + m_mode = SELECTION_ADD; + m_currentAction = REDS; + + connect(this, TQT_SIGNAL(okClicked()), + this, TQT_SLOT(okClicked())); + + connect(this, TQT_SIGNAL(cancelClicked()), + this, TQT_SLOT(cancelClicked())); + + connect(m_page->chkInvert, TQT_SIGNAL(clicked()), + this, TQT_SLOT(slotInvertClicked())); + + connect(m_page->cmbSelect, TQT_SIGNAL(activated(int)), + this, TQT_SLOT(slotSelectionTypeChanged(int))); + + connect (m_page->radioAdd, TQT_SIGNAL(toggled(bool)), + this, TQT_SLOT(slotAdd(bool))); + + connect (m_page->radioSubtract, TQT_SIGNAL(toggled(bool)), + this, TQT_SLOT(slotSubtract(bool))); + + connect (m_page->bnSelect, TQT_SIGNAL(clicked()), + this, TQT_SLOT(slotSelectClicked())); + + connect (m_page->bnDeselect, TQT_SIGNAL(clicked()), + this, TQT_SLOT(slotDeselectClicked())); + +} + +DlgColorRange::~DlgColorRange() +{ + delete m_page; +} + + +void DlgColorRange::updatePreview() +{ + if (!m_selection) return; + + TQ_INT32 x, y, w, h; + m_dev->exactBounds(x, y, w, h); + TQPixmap pix = TQPixmap(m_selection->maskImage().smoothScale(350, 350, TQ_ScaleMin)); + m_subject->canvasController()->updateCanvas(); + m_page->pixSelection->setPixmap(pix); +} + +void DlgColorRange::okClicked() +{ + m_dev->setDirty(); + m_dev->emitSelectionChanged(); + + if (m_dev->image()->undo()) m_subject->undoAdapter()->addCommand(m_transaction); + accept(); +} + +void DlgColorRange::cancelClicked() +{ + if (m_dev->image()->undo()) m_transaction->unexecute(); + + m_subject->canvasController()->updateCanvas(); + reject(); +} + +void DlgColorRange::slotInvertClicked() +{ + m_invert = m_page->chkInvert->isChecked(); +} + +void DlgColorRange::slotSelectionTypeChanged(int index) +{ + m_currentAction = (enumAction)index; +} + +void DlgColorRange::slotSubtract(bool on) +{ + if (on) + m_mode = SELECTION_SUBTRACT; +} +void DlgColorRange::slotAdd(bool on) +{ + if (on) + m_mode = SELECTION_ADD; +} + +void DlgColorRange::slotSelectClicked() +{ + TQApplication::setOverrideCursor(KisCursor::waitCursor()); + // XXX: Multithread this! + TQ_INT32 x, y, w, h; + m_dev->exactBounds(x, y, w, h); + KisColorSpace * cs = m_dev->colorSpace(); + TQ_UINT8 opacity; + for (int y2 = y; y2 < h - y; ++y2) { + KisHLineIterator hiter = m_dev->createHLineIterator(x, y2, w, false); + KisHLineIterator selIter = m_selection ->createHLineIterator(x, y2, w, true); + while (!hiter.isDone()) { + TQColor c; + + cs->toTQColor(hiter.rawData(), &c, &opacity); + // Don't try to select transparent pixels. + if (opacity > OPACITY_TRANSPARENT) { + TQ_UINT8 match = matchColors(c, m_currentAction); + + if (match) { + // Personally, I think the invert option a bit silly. But it's possible I don't quite understand it. BSAR. + if (!m_invert) { + if (m_mode == SELECTION_ADD) { + *(selIter.rawData()) = match; + } + else if (m_mode == SELECTION_SUBTRACT) { + TQ_UINT8 selectedness = *(selIter.rawData()); + if (match < selectedness) { + *(selIter.rawData()) = selectedness - match; + } + else { + *(selIter.rawData()) = 0; + } + } + } + else { + if (m_mode == SELECTION_ADD) { + TQ_UINT8 selectedness = *(selIter.rawData()); + if (match < selectedness) { + *(selIter.rawData()) = selectedness - match; + } + else { + *(selIter.rawData()) = 0; + } + } + else if (m_mode == SELECTION_SUBTRACT) { + *(selIter.rawData()) = match; + } + } + } + } + ++hiter; + ++selIter; + } + } + updatePreview(); + TQApplication::restoreOverrideCursor(); +} + +void DlgColorRange::slotDeselectClicked() +{ + m_dev->selection()->clear(); + updatePreview(); +} + + +#include "dlg_colorrange.moc" diff --git a/chalk/plugins/viewplugins/colorspaceconversion/Makefile.am b/chalk/plugins/viewplugins/colorspaceconversion/Makefile.am index 7439813c2..06b2ab88f 100644 --- a/chalk/plugins/viewplugins/colorspaceconversion/Makefile.am +++ b/chalk/plugins/viewplugins/colorspaceconversion/Makefile.am @@ -14,7 +14,7 @@ INCLUDES = -I$(srcdir)/../../../sdk \ kde_module_LTLIBRARIES = chalkcolorspaceconversion.la -chalkcolorspaceconversion_la_SOURCES = wdgconvertcolorspace.ui colorspaceconversion.cc dlg_colorspaceconversion.cc +chalkcolorspaceconversion_la_SOURCES = wdgconvertcolorspace.ui colorspaceconversion.cpp dlg_colorspaceconversion.cpp noinst_HEADERS = wdgconvertcolorspace.h dlg_colorspaceconversion.h colorspaceconversion.h chalkcolorspaceconversion_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) $(LIB_TQT) -ltdecore -ltdeui -lkjs -ltdefx -ltdeio -ltdeparts diff --git a/chalk/plugins/viewplugins/colorspaceconversion/colorspaceconversion.cc b/chalk/plugins/viewplugins/colorspaceconversion/colorspaceconversion.cc deleted file mode 100644 index d956ee460..000000000 --- a/chalk/plugins/viewplugins/colorspaceconversion/colorspaceconversion.cc +++ /dev/null @@ -1,155 +0,0 @@ -/* - * colorspaceconversion.cc -- Part of Chalk - * - * Copyright (c) 2004 Boudewijn Rempt (boud@valdyas.org) - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -#include - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include "kis_meta_registry.h" -#include -#include -#include -#include -#include - -#include "colorspaceconversion.h" -#include "dlg_colorspaceconversion.h" -#include "wdgconvertcolorspace.h" - -typedef KGenericFactory ColorSpaceConversionFactory; -K_EXPORT_COMPONENT_FACTORY( chalkcolorspaceconversion, ColorSpaceConversionFactory( "chalk" ) ) - - -ColorSpaceConversion::ColorSpaceConversion(TQObject *parent, const char *name, const TQStringList &) - : KParts::Plugin(parent, name) -{ - - if ( parent->inherits("KisView") ) - { - m_view = (KisView*) parent; - - setInstance(ColorSpaceConversionFactory::instance()); - setXMLFile(locate("data","chalkplugins/colorspaceconversion.rc"), true); - - (void) new TDEAction(i18n("&Convert Image Type..."), 0, 0, this, TQT_SLOT(slotImgColorSpaceConversion()), actionCollection(), "imgcolorspaceconversion"); - (void) new TDEAction(i18n("&Convert Layer Type..."), 0, 0, this, TQT_SLOT(slotLayerColorSpaceConversion()), actionCollection(), "layercolorspaceconversion"); - - } -} - -ColorSpaceConversion::~ColorSpaceConversion() -{ - m_view = 0; -} - -void ColorSpaceConversion::slotImgColorSpaceConversion() -{ - KisImageSP image = m_view->canvasSubject()->currentImg(); - - if (!image) return; - - - if (image->colorSpace()->willDegrade(TO_LAB16)) { - if (KMessageBox::warningContinueCancel(m_view, - i18n("This conversion will convert your %1 image through 16-bit L*a*b* and back.\n" - "Watercolor and openEXR colorspaces will even be converted through 8-bit RGB.\n") - .arg(image->colorSpace()->id().name()), - i18n("Colorspace Conversion"), - KGuiItem(i18n("Continue")), - "lab16degradation") != KMessageBox::Continue) return; - - } - - DlgColorSpaceConversion * dlgColorSpaceConversion = new DlgColorSpaceConversion(m_view, "ColorSpaceConversion"); - TQ_CHECK_PTR(dlgColorSpaceConversion); - - dlgColorSpaceConversion->setCaption(i18n("Convert All Layers From ") + image->colorSpace()->id().name()); - - if (dlgColorSpaceConversion->exec() == TQDialog::Accepted) { - // XXX: Do the rest of the stuff - KisID cspace = dlgColorSpaceConversion->m_page->cmbColorSpaces->currentItem(); - KisColorSpace * cs = KisMetaRegistry::instance()->csRegistry()->getColorSpace(cspace, dlgColorSpaceConversion->m_page->cmbDestProfile->currentText()); - - TQApplication::setOverrideCursor(KisCursor::waitCursor()); - image->convertTo(cs, dlgColorSpaceConversion->m_page->grpIntent->selectedId()); - TQApplication::restoreOverrideCursor(); - } - delete dlgColorSpaceConversion; -} - -void ColorSpaceConversion::slotLayerColorSpaceConversion() -{ - - KisImageSP image = m_view->canvasSubject()->currentImg(); - if (!image) return; - - KisPaintDeviceSP dev = image->activeDevice(); - if (!dev) return; - - if (dev->colorSpace()->willDegrade(TO_LAB16)) { - if (KMessageBox::warningContinueCancel(m_view, - i18n("This conversion will convert your %1 layer through 16-bit L*a*b* and back.\n" - "Watercolor and openEXR colorspaces will even be converted through 8-bit RGB.\n") - .arg(dev->colorSpace()->id().name()), - i18n("Colorspace Conversion"), - KGuiItem(i18n("Continue")), - "lab16degradation") != KMessageBox::Continue) return; - - } - - DlgColorSpaceConversion * dlgColorSpaceConversion = new DlgColorSpaceConversion(m_view, "ColorSpaceConversion"); - TQ_CHECK_PTR(dlgColorSpaceConversion); - - dlgColorSpaceConversion->setCaption(i18n("Convert Current Layer From") + dev->colorSpace()->id().name()); - - if (dlgColorSpaceConversion->exec() == TQDialog::Accepted) { - KisID cspace = dlgColorSpaceConversion->m_page->cmbColorSpaces->currentItem(); - KisColorSpace * cs = KisMetaRegistry::instance()->csRegistry() -> - getColorSpace(cspace, dlgColorSpaceConversion->m_page->cmbDestProfile->currentText()); - - TQApplication::setOverrideCursor(KisCursor::waitCursor()); - dev->convertTo(cs, dlgColorSpaceConversion->m_page->grpIntent->selectedId()); - TQApplication::restoreOverrideCursor(); - } - delete dlgColorSpaceConversion; -} - -#include "colorspaceconversion.moc" diff --git a/chalk/plugins/viewplugins/colorspaceconversion/colorspaceconversion.cpp b/chalk/plugins/viewplugins/colorspaceconversion/colorspaceconversion.cpp new file mode 100644 index 000000000..377f0569d --- /dev/null +++ b/chalk/plugins/viewplugins/colorspaceconversion/colorspaceconversion.cpp @@ -0,0 +1,155 @@ +/* + * colorspaceconversion.cpp -- Part of Chalk + * + * Copyright (c) 2004 Boudewijn Rempt (boud@valdyas.org) + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include "kis_meta_registry.h" +#include +#include +#include +#include +#include + +#include "colorspaceconversion.h" +#include "dlg_colorspaceconversion.h" +#include "wdgconvertcolorspace.h" + +typedef KGenericFactory ColorSpaceConversionFactory; +K_EXPORT_COMPONENT_FACTORY( chalkcolorspaceconversion, ColorSpaceConversionFactory( "chalk" ) ) + + +ColorSpaceConversion::ColorSpaceConversion(TQObject *parent, const char *name, const TQStringList &) + : KParts::Plugin(parent, name) +{ + + if ( parent->inherits("KisView") ) + { + m_view = (KisView*) parent; + + setInstance(ColorSpaceConversionFactory::instance()); + setXMLFile(locate("data","chalkplugins/colorspaceconversion.rc"), true); + + (void) new TDEAction(i18n("&Convert Image Type..."), 0, 0, this, TQT_SLOT(slotImgColorSpaceConversion()), actionCollection(), "imgcolorspaceconversion"); + (void) new TDEAction(i18n("&Convert Layer Type..."), 0, 0, this, TQT_SLOT(slotLayerColorSpaceConversion()), actionCollection(), "layercolorspaceconversion"); + + } +} + +ColorSpaceConversion::~ColorSpaceConversion() +{ + m_view = 0; +} + +void ColorSpaceConversion::slotImgColorSpaceConversion() +{ + KisImageSP image = m_view->canvasSubject()->currentImg(); + + if (!image) return; + + + if (image->colorSpace()->willDegrade(TO_LAB16)) { + if (KMessageBox::warningContinueCancel(m_view, + i18n("This conversion will convert your %1 image through 16-bit L*a*b* and back.\n" + "Watercolor and openEXR colorspaces will even be converted through 8-bit RGB.\n") + .arg(image->colorSpace()->id().name()), + i18n("Colorspace Conversion"), + KGuiItem(i18n("Continue")), + "lab16degradation") != KMessageBox::Continue) return; + + } + + DlgColorSpaceConversion * dlgColorSpaceConversion = new DlgColorSpaceConversion(m_view, "ColorSpaceConversion"); + TQ_CHECK_PTR(dlgColorSpaceConversion); + + dlgColorSpaceConversion->setCaption(i18n("Convert All Layers From ") + image->colorSpace()->id().name()); + + if (dlgColorSpaceConversion->exec() == TQDialog::Accepted) { + // XXX: Do the rest of the stuff + KisID cspace = dlgColorSpaceConversion->m_page->cmbColorSpaces->currentItem(); + KisColorSpace * cs = KisMetaRegistry::instance()->csRegistry()->getColorSpace(cspace, dlgColorSpaceConversion->m_page->cmbDestProfile->currentText()); + + TQApplication::setOverrideCursor(KisCursor::waitCursor()); + image->convertTo(cs, dlgColorSpaceConversion->m_page->grpIntent->selectedId()); + TQApplication::restoreOverrideCursor(); + } + delete dlgColorSpaceConversion; +} + +void ColorSpaceConversion::slotLayerColorSpaceConversion() +{ + + KisImageSP image = m_view->canvasSubject()->currentImg(); + if (!image) return; + + KisPaintDeviceSP dev = image->activeDevice(); + if (!dev) return; + + if (dev->colorSpace()->willDegrade(TO_LAB16)) { + if (KMessageBox::warningContinueCancel(m_view, + i18n("This conversion will convert your %1 layer through 16-bit L*a*b* and back.\n" + "Watercolor and openEXR colorspaces will even be converted through 8-bit RGB.\n") + .arg(dev->colorSpace()->id().name()), + i18n("Colorspace Conversion"), + KGuiItem(i18n("Continue")), + "lab16degradation") != KMessageBox::Continue) return; + + } + + DlgColorSpaceConversion * dlgColorSpaceConversion = new DlgColorSpaceConversion(m_view, "ColorSpaceConversion"); + TQ_CHECK_PTR(dlgColorSpaceConversion); + + dlgColorSpaceConversion->setCaption(i18n("Convert Current Layer From") + dev->colorSpace()->id().name()); + + if (dlgColorSpaceConversion->exec() == TQDialog::Accepted) { + KisID cspace = dlgColorSpaceConversion->m_page->cmbColorSpaces->currentItem(); + KisColorSpace * cs = KisMetaRegistry::instance()->csRegistry() -> + getColorSpace(cspace, dlgColorSpaceConversion->m_page->cmbDestProfile->currentText()); + + TQApplication::setOverrideCursor(KisCursor::waitCursor()); + dev->convertTo(cs, dlgColorSpaceConversion->m_page->grpIntent->selectedId()); + TQApplication::restoreOverrideCursor(); + } + delete dlgColorSpaceConversion; +} + +#include "colorspaceconversion.moc" diff --git a/chalk/plugins/viewplugins/colorspaceconversion/dlg_colorspaceconversion.cc b/chalk/plugins/viewplugins/colorspaceconversion/dlg_colorspaceconversion.cc deleted file mode 100644 index 8159ad73f..000000000 --- a/chalk/plugins/viewplugins/colorspaceconversion/dlg_colorspaceconversion.cc +++ /dev/null @@ -1,91 +0,0 @@ -/* - * dlg_colorspaceconversion.cc - part of KimageShop^WKrayon^WChalk - * - * Copyright (c) 2004 Boudewijn Rempt - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include -#include -#include -#include -#include - -#include -#include -#include - -#include "kis_meta_registry.h" -#include -#include "kis_profile.h" -#include "kis_colorspace.h" -#include -#include -#include - -#include "wdgconvertcolorspace.h" -#include "dlg_colorspaceconversion.h" - -DlgColorSpaceConversion::DlgColorSpaceConversion( TQWidget * parent, - const char * name) - : super (parent, name, true, i18n("Image Size"), Ok | Cancel, Ok) -{ - m_page = new WdgConvertColorSpace(this, "colorspace_conversion"); - TQ_CHECK_PTR(m_page); - - setMainWidget(m_page); - resize(m_page->sizeHint()); - - m_page->cmbColorSpaces->setIDList(KisMetaRegistry::instance()->csRegistry()->listKeys()); - - fillCmbDestProfile(m_page->cmbColorSpaces->currentItem()); - - connect(m_page->cmbColorSpaces, TQT_SIGNAL(activated(const KisID &)), - this, TQT_SLOT(fillCmbDestProfile(const KisID &))); - - - connect(this, TQT_SIGNAL(okClicked()), - this, TQT_SLOT(okClicked())); - -} - -DlgColorSpaceConversion::~DlgColorSpaceConversion() -{ - delete m_page; -} - -// SLOTS - -void DlgColorSpaceConversion::okClicked() -{ - accept(); -} - - -void DlgColorSpaceConversion::fillCmbDestProfile(const KisID & s) -{ - m_page->cmbDestProfile->clear(); - - TQValueVector profileList = KisMetaRegistry::instance()->csRegistry()->profilesFor(s); - TQValueVector ::iterator it; - for ( it = profileList.begin(); it != profileList.end(); ++it ) { - m_page->cmbDestProfile->insertItem((*it)->productName()); - - } -} - - -#include "dlg_colorspaceconversion.moc" diff --git a/chalk/plugins/viewplugins/colorspaceconversion/dlg_colorspaceconversion.cpp b/chalk/plugins/viewplugins/colorspaceconversion/dlg_colorspaceconversion.cpp new file mode 100644 index 000000000..259c6f470 --- /dev/null +++ b/chalk/plugins/viewplugins/colorspaceconversion/dlg_colorspaceconversion.cpp @@ -0,0 +1,91 @@ +/* + * dlg_colorspaceconversion.cpp - part of KimageShop^WKrayon^WChalk + * + * Copyright (c) 2004 Boudewijn Rempt + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "kis_meta_registry.h" +#include +#include "kis_profile.h" +#include "kis_colorspace.h" +#include +#include +#include + +#include "wdgconvertcolorspace.h" +#include "dlg_colorspaceconversion.h" + +DlgColorSpaceConversion::DlgColorSpaceConversion( TQWidget * parent, + const char * name) + : super (parent, name, true, i18n("Image Size"), Ok | Cancel, Ok) +{ + m_page = new WdgConvertColorSpace(this, "colorspace_conversion"); + TQ_CHECK_PTR(m_page); + + setMainWidget(m_page); + resize(m_page->sizeHint()); + + m_page->cmbColorSpaces->setIDList(KisMetaRegistry::instance()->csRegistry()->listKeys()); + + fillCmbDestProfile(m_page->cmbColorSpaces->currentItem()); + + connect(m_page->cmbColorSpaces, TQT_SIGNAL(activated(const KisID &)), + this, TQT_SLOT(fillCmbDestProfile(const KisID &))); + + + connect(this, TQT_SIGNAL(okClicked()), + this, TQT_SLOT(okClicked())); + +} + +DlgColorSpaceConversion::~DlgColorSpaceConversion() +{ + delete m_page; +} + +// SLOTS + +void DlgColorSpaceConversion::okClicked() +{ + accept(); +} + + +void DlgColorSpaceConversion::fillCmbDestProfile(const KisID & s) +{ + m_page->cmbDestProfile->clear(); + + TQValueVector profileList = KisMetaRegistry::instance()->csRegistry()->profilesFor(s); + TQValueVector ::iterator it; + for ( it = profileList.begin(); it != profileList.end(); ++it ) { + m_page->cmbDestProfile->insertItem((*it)->productName()); + + } +} + + +#include "dlg_colorspaceconversion.moc" diff --git a/chalk/plugins/viewplugins/dropshadow/Makefile.am b/chalk/plugins/viewplugins/dropshadow/Makefile.am index fb6c48ce4..3c9728e00 100644 --- a/chalk/plugins/viewplugins/dropshadow/Makefile.am +++ b/chalk/plugins/viewplugins/dropshadow/Makefile.am @@ -14,8 +14,8 @@ INCLUDES = -I$(srcdir)/../../../sdk \ kde_module_LTLIBRARIES = chalkdropshadow.la chalkdropshadow_la_SOURCES = wdg_dropshadow.ui \ - kis_dropshadow.cc dlg_dropshadow.cc \ - kis_dropshadow_plugin.cc + kis_dropshadow.cpp dlg_dropshadow.cpp \ + kis_dropshadow_plugin.cpp noinst_HEADERS = wdg_dropshadow.h kis_dropshadow_plugin.h \ kis_dropshadow.h dlg_dropshadow.h diff --git a/chalk/plugins/viewplugins/dropshadow/dlg_dropshadow.cc b/chalk/plugins/viewplugins/dropshadow/dlg_dropshadow.cc deleted file mode 100644 index 59019489c..000000000 --- a/chalk/plugins/viewplugins/dropshadow/dlg_dropshadow.cc +++ /dev/null @@ -1,117 +0,0 @@ -/* - * dlg_dropshadow.cc - part of KimageShop^WKrayon^WChalk - * - * Copyright (c) 2005 Michael Thaler - * Copyright (c) 2006 Cyrille Berger - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include "dlg_dropshadow.h" -#include "wdg_dropshadow.h" - -DlgDropshadow::DlgDropshadow( const TQString & /*imageCS*/, - const TQString & /*layerCS*/, - TQWidget * parent, - const char * name) - : super (parent, name, true, i18n("Drop Shadow"), Ok | Cancel, Ok) -{ - m_page = new WdgDropshadow(this, "dropshadow"); - TQ_CHECK_PTR(m_page); - setMainWidget(m_page); - resize(m_page->sizeHint()); - - TDEConfig * cfg = TDEGlobal::config(); - m_page->xOffsetSpinBox->setValue( cfg->readNumEntry("dropshadow_x", 8) ); - m_page->yOffsetSpinBox->setValue( cfg->readNumEntry("dropshadow_y", 8) ); - m_page->blurRadiusSpinBox->setValue( cfg->readNumEntry("dropshadow_blurRadius", 5) ); - TQColor black(0,0,0); - m_page->shadowColorButton->setColor( cfg->readColorEntry("dropshadow_color", &black) ); - m_page->opacitySlider->setValue( cfg->readNumEntry("dropshadow_opacity", 80 ) ); - m_page->opacitySpinBox->setValue( cfg->readNumEntry("dropshadow_opacity", 80 ) ); - m_page->allowResizingCheckBox->setChecked( cfg->readBoolEntry("dropshadow_resizing", true ) ); - - connect(this, TQT_SIGNAL(okClicked()), - this, TQT_SLOT(okClicked())); -} - -DlgDropshadow::~DlgDropshadow() -{ - delete m_page; -} - -TQ_INT32 DlgDropshadow::getXOffset() -{ - return m_page->xOffsetSpinBox->value(); -} - -TQ_INT32 DlgDropshadow::getYOffset() -{ - return m_page->yOffsetSpinBox->value(); -} - -TQ_INT32 DlgDropshadow::getBlurRadius() -{ - return m_page->blurRadiusSpinBox->value(); -} - -TQ_UINT8 DlgDropshadow::getShadowOpacity() -{ - double opacity = (double)m_page->opacitySpinBox->value(); - //convert percent to a 8 bit opacity value - return (TQ_UINT8)(opacity / 100 * 255); -} - -TQColor DlgDropshadow::getShadowColor() -{ - return m_page->shadowColorButton->color(); -} - -bool DlgDropshadow::allowResizingChecked() -{ - return m_page->allowResizingCheckBox->isChecked(); -} - -// SLOTS - -void DlgDropshadow::okClicked() -{ - TDEConfig * cfg = TDEGlobal::config(); - cfg->writeEntry("dropshadow_x", m_page->xOffsetSpinBox->value()); - cfg->writeEntry("dropshadow_y", m_page->yOffsetSpinBox->value()); - cfg->writeEntry("dropshadow_blurRadius", m_page->blurRadiusSpinBox->value()); - cfg->writeEntry("dropshadow_color", m_page->shadowColorButton->color()); - cfg->writeEntry("dropshadow_opacity", m_page->opacitySpinBox->value()); - cfg->writeEntry("dropshadow_resizing", m_page->allowResizingCheckBox->isChecked()); - - accept(); -} - -#include "dlg_dropshadow.moc" diff --git a/chalk/plugins/viewplugins/dropshadow/dlg_dropshadow.cpp b/chalk/plugins/viewplugins/dropshadow/dlg_dropshadow.cpp new file mode 100644 index 000000000..c82bbbad6 --- /dev/null +++ b/chalk/plugins/viewplugins/dropshadow/dlg_dropshadow.cpp @@ -0,0 +1,117 @@ +/* + * dlg_dropshadow.cpp - part of KimageShop^WKrayon^WChalk + * + * Copyright (c) 2005 Michael Thaler + * Copyright (c) 2006 Cyrille Berger + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "dlg_dropshadow.h" +#include "wdg_dropshadow.h" + +DlgDropshadow::DlgDropshadow( const TQString & /*imageCS*/, + const TQString & /*layerCS*/, + TQWidget * parent, + const char * name) + : super (parent, name, true, i18n("Drop Shadow"), Ok | Cancel, Ok) +{ + m_page = new WdgDropshadow(this, "dropshadow"); + TQ_CHECK_PTR(m_page); + setMainWidget(m_page); + resize(m_page->sizeHint()); + + TDEConfig * cfg = TDEGlobal::config(); + m_page->xOffsetSpinBox->setValue( cfg->readNumEntry("dropshadow_x", 8) ); + m_page->yOffsetSpinBox->setValue( cfg->readNumEntry("dropshadow_y", 8) ); + m_page->blurRadiusSpinBox->setValue( cfg->readNumEntry("dropshadow_blurRadius", 5) ); + TQColor black(0,0,0); + m_page->shadowColorButton->setColor( cfg->readColorEntry("dropshadow_color", &black) ); + m_page->opacitySlider->setValue( cfg->readNumEntry("dropshadow_opacity", 80 ) ); + m_page->opacitySpinBox->setValue( cfg->readNumEntry("dropshadow_opacity", 80 ) ); + m_page->allowResizingCheckBox->setChecked( cfg->readBoolEntry("dropshadow_resizing", true ) ); + + connect(this, TQT_SIGNAL(okClicked()), + this, TQT_SLOT(okClicked())); +} + +DlgDropshadow::~DlgDropshadow() +{ + delete m_page; +} + +TQ_INT32 DlgDropshadow::getXOffset() +{ + return m_page->xOffsetSpinBox->value(); +} + +TQ_INT32 DlgDropshadow::getYOffset() +{ + return m_page->yOffsetSpinBox->value(); +} + +TQ_INT32 DlgDropshadow::getBlurRadius() +{ + return m_page->blurRadiusSpinBox->value(); +} + +TQ_UINT8 DlgDropshadow::getShadowOpacity() +{ + double opacity = (double)m_page->opacitySpinBox->value(); + //convert percent to a 8 bit opacity value + return (TQ_UINT8)(opacity / 100 * 255); +} + +TQColor DlgDropshadow::getShadowColor() +{ + return m_page->shadowColorButton->color(); +} + +bool DlgDropshadow::allowResizingChecked() +{ + return m_page->allowResizingCheckBox->isChecked(); +} + +// SLOTS + +void DlgDropshadow::okClicked() +{ + TDEConfig * cfg = TDEGlobal::config(); + cfg->writeEntry("dropshadow_x", m_page->xOffsetSpinBox->value()); + cfg->writeEntry("dropshadow_y", m_page->yOffsetSpinBox->value()); + cfg->writeEntry("dropshadow_blurRadius", m_page->blurRadiusSpinBox->value()); + cfg->writeEntry("dropshadow_color", m_page->shadowColorButton->color()); + cfg->writeEntry("dropshadow_opacity", m_page->opacitySpinBox->value()); + cfg->writeEntry("dropshadow_resizing", m_page->allowResizingCheckBox->isChecked()); + + accept(); +} + +#include "dlg_dropshadow.moc" diff --git a/chalk/plugins/viewplugins/dropshadow/kis_dropshadow.cc b/chalk/plugins/viewplugins/dropshadow/kis_dropshadow.cpp similarity index 100% rename from chalk/plugins/viewplugins/dropshadow/kis_dropshadow.cc rename to chalk/plugins/viewplugins/dropshadow/kis_dropshadow.cpp diff --git a/chalk/plugins/viewplugins/dropshadow/kis_dropshadow_plugin.cc b/chalk/plugins/viewplugins/dropshadow/kis_dropshadow_plugin.cpp similarity index 100% rename from chalk/plugins/viewplugins/dropshadow/kis_dropshadow_plugin.cc rename to chalk/plugins/viewplugins/dropshadow/kis_dropshadow_plugin.cpp diff --git a/chalk/plugins/viewplugins/filtersgallery/Makefile.am b/chalk/plugins/viewplugins/filtersgallery/Makefile.am index 6c3ca3e87..bd80954f6 100644 --- a/chalk/plugins/viewplugins/filtersgallery/Makefile.am +++ b/chalk/plugins/viewplugins/filtersgallery/Makefile.am @@ -11,8 +11,8 @@ INCLUDES = -I$(srcdir)/../../../sdk \ $(KOFFICE_INCLUDES) \ $(all_includes) -chalkfiltersgallery_la_SOURCES = filters_gallery.cc \ - kis_dlg_filtersgallery.cc kis_wdg_filtersgallery.ui +chalkfiltersgallery_la_SOURCES = filters_gallery.cpp \ + kis_dlg_filtersgallery.cpp kis_wdg_filtersgallery.ui kde_module_LTLIBRARIES = chalkfiltersgallery.la noinst_HEADERS = filters_gallery.h kis_dlg_filtersgallery.h diff --git a/chalk/plugins/viewplugins/filtersgallery/filters_gallery.cc b/chalk/plugins/viewplugins/filtersgallery/filters_gallery.cpp similarity index 100% rename from chalk/plugins/viewplugins/filtersgallery/filters_gallery.cc rename to chalk/plugins/viewplugins/filtersgallery/filters_gallery.cpp diff --git a/chalk/plugins/viewplugins/filtersgallery/kis_dlg_filtersgallery.cc b/chalk/plugins/viewplugins/filtersgallery/kis_dlg_filtersgallery.cpp similarity index 100% rename from chalk/plugins/viewplugins/filtersgallery/kis_dlg_filtersgallery.cc rename to chalk/plugins/viewplugins/filtersgallery/kis_dlg_filtersgallery.cpp diff --git a/chalk/plugins/viewplugins/histogram/Makefile.am b/chalk/plugins/viewplugins/histogram/Makefile.am index f5f8db376..9afb9726c 100644 --- a/chalk/plugins/viewplugins/histogram/Makefile.am +++ b/chalk/plugins/viewplugins/histogram/Makefile.am @@ -13,7 +13,7 @@ INCLUDES = -I$(srcdir)/../../../sdk \ kde_module_LTLIBRARIES = chalkhistogram.la -chalkhistogram_la_SOURCES = histogram.cc dlg_histogram.cc wdghistogram.ui kis_histogram_widget.cc +chalkhistogram_la_SOURCES = histogram.cpp dlg_histogram.cpp wdghistogram.ui kis_histogram_widget.cpp noinst_HEADERS = dlg_histogram.h histogram.h wdghistogram.h kis_histogram_widget.h kde_services_DATA = chalkhistogram.desktop diff --git a/chalk/plugins/viewplugins/histogram/dlg_histogram.cc b/chalk/plugins/viewplugins/histogram/dlg_histogram.cc deleted file mode 100644 index 448a58cfc..000000000 --- a/chalk/plugins/viewplugins/histogram/dlg_histogram.cc +++ /dev/null @@ -1,68 +0,0 @@ -/* - * dlg_histogram.cc - part of KimageShop^WKrayon^WChalk - * - * Copyright (c) 2004 Boudewijn Rempt - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include "kis_types.h" -#include "kis_histogram.h" -#include "kis_layer.h" -#include "kis_paint_device.h" - -#include "dlg_histogram.h" -#include "kis_histogram_widget.h" - - -DlgHistogram::DlgHistogram( TQWidget * parent, const char * name) - : super (parent, name, true, i18n("Histogram"), Ok | Cancel, Ok) -{ - m_page = new KisHistogramWidget(this, "histogram"); - TQ_CHECK_PTR(m_page); - - setCaption(i18n("Histogram")); - setMainWidget(m_page); - resize(m_page->sizeHint()); -} - -DlgHistogram::~DlgHistogram() -{ - delete m_page; -} - -void DlgHistogram::setPaintDevice(KisPaintDeviceSP dev) -{ - m_page->setPaintDevice(dev); -} - -void DlgHistogram::okClicked() -{ - accept(); -} - -#include "dlg_histogram.moc" diff --git a/chalk/plugins/viewplugins/histogram/dlg_histogram.cpp b/chalk/plugins/viewplugins/histogram/dlg_histogram.cpp new file mode 100644 index 000000000..77ad06686 --- /dev/null +++ b/chalk/plugins/viewplugins/histogram/dlg_histogram.cpp @@ -0,0 +1,68 @@ +/* + * dlg_histogram.cpp - part of KimageShop^WKrayon^WChalk + * + * Copyright (c) 2004 Boudewijn Rempt + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "kis_types.h" +#include "kis_histogram.h" +#include "kis_layer.h" +#include "kis_paint_device.h" + +#include "dlg_histogram.h" +#include "kis_histogram_widget.h" + + +DlgHistogram::DlgHistogram( TQWidget * parent, const char * name) + : super (parent, name, true, i18n("Histogram"), Ok | Cancel, Ok) +{ + m_page = new KisHistogramWidget(this, "histogram"); + TQ_CHECK_PTR(m_page); + + setCaption(i18n("Histogram")); + setMainWidget(m_page); + resize(m_page->sizeHint()); +} + +DlgHistogram::~DlgHistogram() +{ + delete m_page; +} + +void DlgHistogram::setPaintDevice(KisPaintDeviceSP dev) +{ + m_page->setPaintDevice(dev); +} + +void DlgHistogram::okClicked() +{ + accept(); +} + +#include "dlg_histogram.moc" diff --git a/chalk/plugins/viewplugins/histogram/histogram.cc b/chalk/plugins/viewplugins/histogram/histogram.cpp similarity index 100% rename from chalk/plugins/viewplugins/histogram/histogram.cc rename to chalk/plugins/viewplugins/histogram/histogram.cpp diff --git a/chalk/plugins/viewplugins/histogram/kis_histogram_widget.cc b/chalk/plugins/viewplugins/histogram/kis_histogram_widget.cpp similarity index 100% rename from chalk/plugins/viewplugins/histogram/kis_histogram_widget.cc rename to chalk/plugins/viewplugins/histogram/kis_histogram_widget.cpp diff --git a/chalk/plugins/viewplugins/histogram_docker/Makefile.am b/chalk/plugins/viewplugins/histogram_docker/Makefile.am index 6d2b905db..299920871 100644 --- a/chalk/plugins/viewplugins/histogram_docker/Makefile.am +++ b/chalk/plugins/viewplugins/histogram_docker/Makefile.am @@ -10,7 +10,7 @@ INCLUDES = -I$(srcdir)/../../../sdk \ $(KOFFICE_INCLUDES) \ $(all_includes) -chalkhistogramdocker_la_SOURCES = histogramdocker.cc kis_imagerasteredcache.cc kis_cachedhistogram.cc kis_accumulating_producer.cc +chalkhistogramdocker_la_SOURCES = histogramdocker.cpp kis_imagerasteredcache.cpp kis_cachedhistogram.cpp kis_accumulating_producer.cpp kde_module_LTLIBRARIES = chalkhistogramdocker.la noinst_HEADERS = histogramdocker.h kis_imagerasteredcache.h kis_cachedhistogram.h kis_accumulating_producer.h diff --git a/chalk/plugins/viewplugins/histogram_docker/histogramdocker.cc b/chalk/plugins/viewplugins/histogram_docker/histogramdocker.cpp similarity index 100% rename from chalk/plugins/viewplugins/histogram_docker/histogramdocker.cc rename to chalk/plugins/viewplugins/histogram_docker/histogramdocker.cpp diff --git a/chalk/plugins/viewplugins/histogram_docker/kis_accumulating_producer.cc b/chalk/plugins/viewplugins/histogram_docker/kis_accumulating_producer.cpp similarity index 100% rename from chalk/plugins/viewplugins/histogram_docker/kis_accumulating_producer.cc rename to chalk/plugins/viewplugins/histogram_docker/kis_accumulating_producer.cpp diff --git a/chalk/plugins/viewplugins/histogram_docker/kis_cachedhistogram.cc b/chalk/plugins/viewplugins/histogram_docker/kis_cachedhistogram.cpp similarity index 100% rename from chalk/plugins/viewplugins/histogram_docker/kis_cachedhistogram.cc rename to chalk/plugins/viewplugins/histogram_docker/kis_cachedhistogram.cpp diff --git a/chalk/plugins/viewplugins/histogram_docker/kis_imagerasteredcache.cc b/chalk/plugins/viewplugins/histogram_docker/kis_imagerasteredcache.cpp similarity index 100% rename from chalk/plugins/viewplugins/histogram_docker/kis_imagerasteredcache.cc rename to chalk/plugins/viewplugins/histogram_docker/kis_imagerasteredcache.cpp diff --git a/chalk/plugins/viewplugins/history_docker/Makefile.am b/chalk/plugins/viewplugins/history_docker/Makefile.am index 53511b3d9..c77357f23 100644 --- a/chalk/plugins/viewplugins/history_docker/Makefile.am +++ b/chalk/plugins/viewplugins/history_docker/Makefile.am @@ -7,7 +7,7 @@ INCLUDES = -I$(srcdir)/../../../sdk \ $(KOFFICE_INCLUDES) \ $(all_includes) -chalkhistorydocker_la_SOURCES = historydocker.cc +chalkhistorydocker_la_SOURCES = historydocker.cpp kde_module_LTLIBRARIES = chalkhistorydocker.la noinst_HEADERS = historydocker.h diff --git a/chalk/plugins/viewplugins/history_docker/historydocker.cc b/chalk/plugins/viewplugins/history_docker/historydocker.cpp similarity index 100% rename from chalk/plugins/viewplugins/history_docker/historydocker.cc rename to chalk/plugins/viewplugins/history_docker/historydocker.cpp diff --git a/chalk/plugins/viewplugins/imagesize/Makefile.am b/chalk/plugins/viewplugins/imagesize/Makefile.am index 00d58340c..5fe1756ab 100644 --- a/chalk/plugins/viewplugins/imagesize/Makefile.am +++ b/chalk/plugins/viewplugins/imagesize/Makefile.am @@ -12,7 +12,7 @@ INCLUDES = -I$(srcdir)/../../../sdk \ $(KOFFICE_INCLUDES) \ $(all_includes) -chalkimagesize_la_SOURCES = wdg_imagesize.ui wdg_layersize.ui imagesize.cc dlg_imagesize.cc dlg_layersize.cc wdg_resolution.ui +chalkimagesize_la_SOURCES = wdg_imagesize.ui wdg_layersize.ui imagesize.cpp dlg_imagesize.cpp dlg_layersize.cpp wdg_resolution.ui noinst_HEADERS = wdg_imagesize.h dlg_imagesize.h imagesize.h dlg_layersize.h diff --git a/chalk/plugins/viewplugins/imagesize/dlg_imagesize.cc b/chalk/plugins/viewplugins/imagesize/dlg_imagesize.cc deleted file mode 100644 index 8a9a8c098..000000000 --- a/chalk/plugins/viewplugins/imagesize/dlg_imagesize.cc +++ /dev/null @@ -1,277 +0,0 @@ -/* - * dlg_imagesize.cc - part of KimageShop^WKrayon^WChalk - * - * Copyright (c) 2004 Boudewijn Rempt - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include - -#include - -#include - -using namespace std; - -#include -#include -#include -#include -#include - -#include -#include -#include - -#include -#include - -#include "dlg_imagesize.h" -#include "wdg_imagesize.h" - - -// XXX: I'm really real bad at arithmetic, let alone math. Here -// be rounding errors. (Boudewijn) -DlgImageSize::DlgImageSize( TQWidget * parent, - const char * name) - : super (parent, name, true, i18n("Image Size"), Ok | Cancel, Ok) -{ - m_lock = false; - - m_page = new WdgImageSize(this, "image_size"); - TQ_CHECK_PTR(m_page); - - m_page->cmbFilterType->setIDList(KisFilterStrategyRegistry::instance()->listKeys()); - m_page->cmbFilterType->setCurrentText("Mitchell"); - - setMainWidget(m_page); - resize(m_page->sizeHint()); - - unblockAll(); - - - connect(this, TQT_SIGNAL(okClicked()), - this, TQT_SLOT(okClicked())); - -} - -DlgImageSize::~DlgImageSize() -{ - delete m_page; -} - -void DlgImageSize::hideScaleBox() -{ - m_page->grpResizeScale->hide(); -} - -void DlgImageSize::setWidth(TQ_UINT32 w) -{ - blockAll(); - - m_page->lblWidthOriginal->setNum((int)w); - m_page->intWidth->setValue(w); - m_oldW = w; - m_origW = w; - - unblockAll(); -} - -void DlgImageSize::setWidthPercent(TQ_UINT32 w) -{ - blockAll(); - - m_page->intWidthPercent->setValue(w); - m_oldWPercent = w; - - unblockAll(); -} - - -void DlgImageSize::setMaximumWidth(TQ_UINT32 w) -{ - m_page->intWidth->setMaxValue(w); - m_maxW = w; -} - -TQ_INT32 DlgImageSize::width() -{ - //return (TQ_INT32)tqRound(m_oldW); - return (TQ_INT32)tqRound(m_page->intWidth->value()); -} - -void DlgImageSize::setHeight(TQ_UINT32 h) -{ - blockAll(); - - m_page->lblHeightOriginal->setNum((int)h); - m_page->intHeight->setValue(h); - m_oldH = h; - m_origH = h; - - unblockAll(); -} - - -void DlgImageSize::setHeightPercent(TQ_UINT32 h) -{ - blockAll(); - - m_page->intHeightPercent->setValue(h); - m_oldHPercent = h; - - unblockAll(); -} - - - -void DlgImageSize::setMaximumHeight(TQ_UINT32 h) -{ - m_page->intHeight->setMaxValue(h); - m_maxH = h; -} - - -TQ_INT32 DlgImageSize::height() -{ - //return (TQ_INT32)tqRound(m_oldH); - return (TQ_INT32)tqRound(m_page->intHeight->value()); -} - -bool DlgImageSize::scale() -{ - return m_page->radioScale->isChecked(); -} - -bool DlgImageSize::cropLayers() -{ - return m_page->chkCrop->isChecked(); -} - -KisFilterStrategy *DlgImageSize::filterType() -{ - KisID filterID = m_page->cmbFilterType->currentItem(); - KisFilterStrategy *filter = KisFilterStrategyRegistry::instance()->get(filterID); - return filter; -} - -// SLOTS - -void DlgImageSize::okClicked() -{ - accept(); -} - -void DlgImageSize::slotWidthPixelsChanged(int w) -{ - blockAll(); - - double wPercent = double(w) * 100 / double(m_origW); - - m_page->intWidthPercent->setValue(tqRound(wPercent)); - - // Set height in pixels and percent of necessary - if (m_page->chkConstrain->isChecked()) { - m_page->intHeightPercent->setValue(tqRound(wPercent)); - - m_oldH = tqRound(m_origH * wPercent / 100); - m_page->intHeight->setValue(tqRound(m_oldH)); - - } - m_oldW = w; - - unblockAll(); -} - -void DlgImageSize::slotHeightPixelsChanged(int h) -{ - blockAll(); - - double hPercent = double(h) * 100 / double(m_origH); - - m_page->intHeightPercent->setValue(tqRound(hPercent)); - - // Set width in pixels and percent of necessary - if (m_page->chkConstrain->isChecked()) { - m_page->intWidthPercent->setValue(tqRound(hPercent)); - - m_oldW = tqRound(m_origW * hPercent / 100); - m_page->intWidth->setValue(tqRound(m_oldW)); - - } - m_oldH = h; - - unblockAll(); -} - -void DlgImageSize::slotWidthPercentChanged(int w) -{ - blockAll(); - - m_page->intWidth->setValue(tqRound(w * m_origW / 100)); - - if (m_page->chkConstrain->isChecked()) { - m_page->intHeightPercent->setValue(w); - m_page->intHeight->setValue(tqRound( w * m_origH / 100)); - } - - unblockAll(); -} - -void DlgImageSize::slotHeightPercentChanged(int h) -{ - blockAll(); - - m_page->intHeight->setValue(tqRound(h * m_origH / 100)); - if (m_page->chkConstrain->isChecked()) { - m_page->intWidthPercent->setValue(h); - m_page->intWidth->setValue(tqRound( h * m_origW / 100)); - } - - unblockAll(); - -} - - -void DlgImageSize::blockAll() -{ - // XXX: more efficient to use blockSignals? - m_page->intWidth->disconnect(); - m_page->intHeight->disconnect(); - m_page->intWidthPercent->disconnect(); - m_page->intHeightPercent->disconnect(); - -} - -void DlgImageSize::unblockAll() -{ - // XXX: more efficient to use blockSignals? - connect (m_page->intWidth, TQT_SIGNAL(valueChanged(int)), - this, TQT_SLOT(slotWidthPixelsChanged(int))); - - connect (m_page->intHeight, TQT_SIGNAL(valueChanged(int)), - this, TQT_SLOT(slotHeightPixelsChanged(int))); - - connect (m_page->intWidthPercent, TQT_SIGNAL(valueChanged(int)), - this, TQT_SLOT(slotWidthPercentChanged(int))); - - connect (m_page->intHeightPercent, TQT_SIGNAL(valueChanged(int)), - this, TQT_SLOT(slotHeightPercentChanged(int))); - - -} - -#include "dlg_imagesize.moc" diff --git a/chalk/plugins/viewplugins/imagesize/dlg_imagesize.cpp b/chalk/plugins/viewplugins/imagesize/dlg_imagesize.cpp new file mode 100644 index 000000000..c455af8cc --- /dev/null +++ b/chalk/plugins/viewplugins/imagesize/dlg_imagesize.cpp @@ -0,0 +1,277 @@ +/* + * dlg_imagesize.cpp - part of KimageShop^WKrayon^WChalk + * + * Copyright (c) 2004 Boudewijn Rempt + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include + +#include + +#include + +using namespace std; + +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include + +#include "dlg_imagesize.h" +#include "wdg_imagesize.h" + + +// XXX: I'm really real bad at arithmetic, let alone math. Here +// be rounding errors. (Boudewijn) +DlgImageSize::DlgImageSize( TQWidget * parent, + const char * name) + : super (parent, name, true, i18n("Image Size"), Ok | Cancel, Ok) +{ + m_lock = false; + + m_page = new WdgImageSize(this, "image_size"); + TQ_CHECK_PTR(m_page); + + m_page->cmbFilterType->setIDList(KisFilterStrategyRegistry::instance()->listKeys()); + m_page->cmbFilterType->setCurrentText("Mitchell"); + + setMainWidget(m_page); + resize(m_page->sizeHint()); + + unblockAll(); + + + connect(this, TQT_SIGNAL(okClicked()), + this, TQT_SLOT(okClicked())); + +} + +DlgImageSize::~DlgImageSize() +{ + delete m_page; +} + +void DlgImageSize::hideScaleBox() +{ + m_page->grpResizeScale->hide(); +} + +void DlgImageSize::setWidth(TQ_UINT32 w) +{ + blockAll(); + + m_page->lblWidthOriginal->setNum((int)w); + m_page->intWidth->setValue(w); + m_oldW = w; + m_origW = w; + + unblockAll(); +} + +void DlgImageSize::setWidthPercent(TQ_UINT32 w) +{ + blockAll(); + + m_page->intWidthPercent->setValue(w); + m_oldWPercent = w; + + unblockAll(); +} + + +void DlgImageSize::setMaximumWidth(TQ_UINT32 w) +{ + m_page->intWidth->setMaxValue(w); + m_maxW = w; +} + +TQ_INT32 DlgImageSize::width() +{ + //return (TQ_INT32)tqRound(m_oldW); + return (TQ_INT32)tqRound(m_page->intWidth->value()); +} + +void DlgImageSize::setHeight(TQ_UINT32 h) +{ + blockAll(); + + m_page->lblHeightOriginal->setNum((int)h); + m_page->intHeight->setValue(h); + m_oldH = h; + m_origH = h; + + unblockAll(); +} + + +void DlgImageSize::setHeightPercent(TQ_UINT32 h) +{ + blockAll(); + + m_page->intHeightPercent->setValue(h); + m_oldHPercent = h; + + unblockAll(); +} + + + +void DlgImageSize::setMaximumHeight(TQ_UINT32 h) +{ + m_page->intHeight->setMaxValue(h); + m_maxH = h; +} + + +TQ_INT32 DlgImageSize::height() +{ + //return (TQ_INT32)tqRound(m_oldH); + return (TQ_INT32)tqRound(m_page->intHeight->value()); +} + +bool DlgImageSize::scale() +{ + return m_page->radioScale->isChecked(); +} + +bool DlgImageSize::cropLayers() +{ + return m_page->chkCrop->isChecked(); +} + +KisFilterStrategy *DlgImageSize::filterType() +{ + KisID filterID = m_page->cmbFilterType->currentItem(); + KisFilterStrategy *filter = KisFilterStrategyRegistry::instance()->get(filterID); + return filter; +} + +// SLOTS + +void DlgImageSize::okClicked() +{ + accept(); +} + +void DlgImageSize::slotWidthPixelsChanged(int w) +{ + blockAll(); + + double wPercent = double(w) * 100 / double(m_origW); + + m_page->intWidthPercent->setValue(tqRound(wPercent)); + + // Set height in pixels and percent of necessary + if (m_page->chkConstrain->isChecked()) { + m_page->intHeightPercent->setValue(tqRound(wPercent)); + + m_oldH = tqRound(m_origH * wPercent / 100); + m_page->intHeight->setValue(tqRound(m_oldH)); + + } + m_oldW = w; + + unblockAll(); +} + +void DlgImageSize::slotHeightPixelsChanged(int h) +{ + blockAll(); + + double hPercent = double(h) * 100 / double(m_origH); + + m_page->intHeightPercent->setValue(tqRound(hPercent)); + + // Set width in pixels and percent of necessary + if (m_page->chkConstrain->isChecked()) { + m_page->intWidthPercent->setValue(tqRound(hPercent)); + + m_oldW = tqRound(m_origW * hPercent / 100); + m_page->intWidth->setValue(tqRound(m_oldW)); + + } + m_oldH = h; + + unblockAll(); +} + +void DlgImageSize::slotWidthPercentChanged(int w) +{ + blockAll(); + + m_page->intWidth->setValue(tqRound(w * m_origW / 100)); + + if (m_page->chkConstrain->isChecked()) { + m_page->intHeightPercent->setValue(w); + m_page->intHeight->setValue(tqRound( w * m_origH / 100)); + } + + unblockAll(); +} + +void DlgImageSize::slotHeightPercentChanged(int h) +{ + blockAll(); + + m_page->intHeight->setValue(tqRound(h * m_origH / 100)); + if (m_page->chkConstrain->isChecked()) { + m_page->intWidthPercent->setValue(h); + m_page->intWidth->setValue(tqRound( h * m_origW / 100)); + } + + unblockAll(); + +} + + +void DlgImageSize::blockAll() +{ + // XXX: more efficient to use blockSignals? + m_page->intWidth->disconnect(); + m_page->intHeight->disconnect(); + m_page->intWidthPercent->disconnect(); + m_page->intHeightPercent->disconnect(); + +} + +void DlgImageSize::unblockAll() +{ + // XXX: more efficient to use blockSignals? + connect (m_page->intWidth, TQT_SIGNAL(valueChanged(int)), + this, TQT_SLOT(slotWidthPixelsChanged(int))); + + connect (m_page->intHeight, TQT_SIGNAL(valueChanged(int)), + this, TQT_SLOT(slotHeightPixelsChanged(int))); + + connect (m_page->intWidthPercent, TQT_SIGNAL(valueChanged(int)), + this, TQT_SLOT(slotWidthPercentChanged(int))); + + connect (m_page->intHeightPercent, TQT_SIGNAL(valueChanged(int)), + this, TQT_SLOT(slotHeightPercentChanged(int))); + + +} + +#include "dlg_imagesize.moc" diff --git a/chalk/plugins/viewplugins/imagesize/dlg_layersize.cc b/chalk/plugins/viewplugins/imagesize/dlg_layersize.cc deleted file mode 100644 index 1d30db6a0..000000000 --- a/chalk/plugins/viewplugins/imagesize/dlg_layersize.cc +++ /dev/null @@ -1,261 +0,0 @@ -/* - * dlg_layersize.cc - part of Chalk - * - * Copyright (c) 2004 Boudewijn Rempt - * Copyright (c) 2005 Sven Langkamp - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include - -#include - -#include - -using namespace std; - -#include -#include -#include -#include -#include - -#include -#include -#include - -#include -#include - -#include "dlg_layersize.h" -#include "wdg_layersize.h" - - -// XXX: I'm really real bad at arithmetic, let alone math. Here -// be rounding errors. (Boudewijn) -DlgLayerSize::DlgLayerSize( TQWidget * parent, - const char * name) - : super (parent, name, true, i18n("Scale Layer"), Ok | Cancel, Ok) -{ - m_lock = false; - - m_page = new WdgLayerSize(this, "layer_size"); - TQ_CHECK_PTR(m_page); - - m_page->cmbFilterType->setIDList(KisFilterStrategyRegistry::instance()->listKeys()); - m_page->cmbFilterType->setCurrentText("Mitchell"); - - setMainWidget(m_page); - resize(m_page->sizeHint()); - - unblockAll(); - - - connect(this, TQT_SIGNAL(okClicked()), - this, TQT_SLOT(okClicked())); - -} - -DlgLayerSize::~DlgLayerSize() -{ - delete m_page; -} - -void DlgLayerSize::setWidth(TQ_UINT32 w) -{ - blockAll(); - - m_page->lblWidthOriginal->setNum((int)w); - m_page->intWidth->setValue(w); - m_oldW = w; - m_origW = w; - - unblockAll(); -} - -void DlgLayerSize::setWidthPercent(TQ_UINT32 w) -{ - blockAll(); - - m_page->intWidthPercent->setValue(w); - m_oldWPercent = w; - - unblockAll(); -} - - -void DlgLayerSize::setMaximumWidth(TQ_UINT32 w) -{ - m_page->intWidth->setMaxValue(w); - m_maxW = w; -} - -TQ_INT32 DlgLayerSize::width() -{ - //return (TQ_INT32)tqRound(m_oldW); - return (TQ_INT32)tqRound(m_page->intWidth->value()); -} - -void DlgLayerSize::setHeight(TQ_UINT32 h) -{ - blockAll(); - - m_page->lblHeightOriginal->setNum((int)h); - m_page->intHeight->setValue(h); - m_oldH = h; - m_origH = h; - - unblockAll(); -} - - -void DlgLayerSize::setHeightPercent(TQ_UINT32 h) -{ - blockAll(); - - m_page->intHeightPercent->setValue(h); - m_oldHPercent = h; - - unblockAll(); -} - -void DlgLayerSize::setMaximumHeight(TQ_UINT32 h) -{ - m_page->intHeight->setMaxValue(h); - m_maxH = h; -} - -TQ_INT32 DlgLayerSize::height() -{ - //return (TQ_INT32)tqRound(m_oldH); - return (TQ_INT32)tqRound(m_page->intHeight->value()); -} - -KisFilterStrategy *DlgLayerSize::filterType() -{ - KisID filterID = m_page->cmbFilterType->currentItem(); - KisFilterStrategy *filter = KisFilterStrategyRegistry::instance()->get(filterID); - return filter; -} - - -// SLOTS - -void DlgLayerSize::okClicked() -{ - accept(); -} - -void DlgLayerSize::slotWidthPixelsChanged(int w) -{ - blockAll(); - - double wPercent = double(w) * 100 / double(m_origW); - - m_page->intWidthPercent->setValue(tqRound(wPercent)); - - // Set height in pixels and percent of necessary - if (m_page->chkConstrain->isChecked()) { - m_page->intHeightPercent->setValue(tqRound(wPercent)); - - m_oldH = tqRound(m_origH * wPercent / 100); - m_page->intHeight->setValue(tqRound(m_oldH)); - - } - m_oldW = w; - - unblockAll(); -} - -void DlgLayerSize::slotHeightPixelsChanged(int h) -{ - blockAll(); - - double hPercent = double(h) * 100 / double(m_origH); - - m_page->intHeightPercent->setValue(tqRound(hPercent)); - - // Set width in pixels and percent of necessary - if (m_page->chkConstrain->isChecked()) { - m_page->intWidthPercent->setValue(tqRound(hPercent)); - - m_oldW = tqRound(m_origW * hPercent / 100); - m_page->intWidth->setValue(tqRound(m_oldW)); - - } - m_oldH = h; - - unblockAll(); -} - -void DlgLayerSize::slotWidthPercentChanged(int w) -{ - blockAll(); - - m_page->intWidth->setValue(tqRound(w * m_origW / 100)); - - if (m_page->chkConstrain->isChecked()) { - m_page->intHeightPercent->setValue(w); - m_page->intHeight->setValue(tqRound( w * m_origH / 100)); - } - - unblockAll(); -} - -void DlgLayerSize::slotHeightPercentChanged(int h) -{ - blockAll(); - - m_page->intHeight->setValue(tqRound(h * m_origH / 100)); - if (m_page->chkConstrain->isChecked()) { - m_page->intWidthPercent->setValue(h); - m_page->intWidth->setValue(tqRound( h * m_origW / 100)); - } - - unblockAll(); - -} - - -void DlgLayerSize::blockAll() -{ - // XXX: more efficient to use blockSignals? - m_page->intWidth->disconnect(); - m_page->intHeight->disconnect(); - m_page->intWidthPercent->disconnect(); - m_page->intHeightPercent->disconnect(); - -} - -void DlgLayerSize::unblockAll() -{ - // XXX: more efficient to use blockSignals? - connect (m_page->intWidth, TQT_SIGNAL(valueChanged(int)), - this, TQT_SLOT(slotWidthPixelsChanged(int))); - - connect (m_page->intHeight, TQT_SIGNAL(valueChanged(int)), - this, TQT_SLOT(slotHeightPixelsChanged(int))); - - connect (m_page->intWidthPercent, TQT_SIGNAL(valueChanged(int)), - this, TQT_SLOT(slotWidthPercentChanged(int))); - - connect (m_page->intHeightPercent, TQT_SIGNAL(valueChanged(int)), - this, TQT_SLOT(slotHeightPercentChanged(int))); - - -} - -#include "dlg_layersize.moc" diff --git a/chalk/plugins/viewplugins/imagesize/dlg_layersize.cpp b/chalk/plugins/viewplugins/imagesize/dlg_layersize.cpp new file mode 100644 index 000000000..779798056 --- /dev/null +++ b/chalk/plugins/viewplugins/imagesize/dlg_layersize.cpp @@ -0,0 +1,261 @@ +/* + * dlg_layersize.cpp - part of Chalk + * + * Copyright (c) 2004 Boudewijn Rempt + * Copyright (c) 2005 Sven Langkamp + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include + +#include + +#include + +using namespace std; + +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include + +#include "dlg_layersize.h" +#include "wdg_layersize.h" + + +// XXX: I'm really real bad at arithmetic, let alone math. Here +// be rounding errors. (Boudewijn) +DlgLayerSize::DlgLayerSize( TQWidget * parent, + const char * name) + : super (parent, name, true, i18n("Scale Layer"), Ok | Cancel, Ok) +{ + m_lock = false; + + m_page = new WdgLayerSize(this, "layer_size"); + TQ_CHECK_PTR(m_page); + + m_page->cmbFilterType->setIDList(KisFilterStrategyRegistry::instance()->listKeys()); + m_page->cmbFilterType->setCurrentText("Mitchell"); + + setMainWidget(m_page); + resize(m_page->sizeHint()); + + unblockAll(); + + + connect(this, TQT_SIGNAL(okClicked()), + this, TQT_SLOT(okClicked())); + +} + +DlgLayerSize::~DlgLayerSize() +{ + delete m_page; +} + +void DlgLayerSize::setWidth(TQ_UINT32 w) +{ + blockAll(); + + m_page->lblWidthOriginal->setNum((int)w); + m_page->intWidth->setValue(w); + m_oldW = w; + m_origW = w; + + unblockAll(); +} + +void DlgLayerSize::setWidthPercent(TQ_UINT32 w) +{ + blockAll(); + + m_page->intWidthPercent->setValue(w); + m_oldWPercent = w; + + unblockAll(); +} + + +void DlgLayerSize::setMaximumWidth(TQ_UINT32 w) +{ + m_page->intWidth->setMaxValue(w); + m_maxW = w; +} + +TQ_INT32 DlgLayerSize::width() +{ + //return (TQ_INT32)tqRound(m_oldW); + return (TQ_INT32)tqRound(m_page->intWidth->value()); +} + +void DlgLayerSize::setHeight(TQ_UINT32 h) +{ + blockAll(); + + m_page->lblHeightOriginal->setNum((int)h); + m_page->intHeight->setValue(h); + m_oldH = h; + m_origH = h; + + unblockAll(); +} + + +void DlgLayerSize::setHeightPercent(TQ_UINT32 h) +{ + blockAll(); + + m_page->intHeightPercent->setValue(h); + m_oldHPercent = h; + + unblockAll(); +} + +void DlgLayerSize::setMaximumHeight(TQ_UINT32 h) +{ + m_page->intHeight->setMaxValue(h); + m_maxH = h; +} + +TQ_INT32 DlgLayerSize::height() +{ + //return (TQ_INT32)tqRound(m_oldH); + return (TQ_INT32)tqRound(m_page->intHeight->value()); +} + +KisFilterStrategy *DlgLayerSize::filterType() +{ + KisID filterID = m_page->cmbFilterType->currentItem(); + KisFilterStrategy *filter = KisFilterStrategyRegistry::instance()->get(filterID); + return filter; +} + + +// SLOTS + +void DlgLayerSize::okClicked() +{ + accept(); +} + +void DlgLayerSize::slotWidthPixelsChanged(int w) +{ + blockAll(); + + double wPercent = double(w) * 100 / double(m_origW); + + m_page->intWidthPercent->setValue(tqRound(wPercent)); + + // Set height in pixels and percent of necessary + if (m_page->chkConstrain->isChecked()) { + m_page->intHeightPercent->setValue(tqRound(wPercent)); + + m_oldH = tqRound(m_origH * wPercent / 100); + m_page->intHeight->setValue(tqRound(m_oldH)); + + } + m_oldW = w; + + unblockAll(); +} + +void DlgLayerSize::slotHeightPixelsChanged(int h) +{ + blockAll(); + + double hPercent = double(h) * 100 / double(m_origH); + + m_page->intHeightPercent->setValue(tqRound(hPercent)); + + // Set width in pixels and percent of necessary + if (m_page->chkConstrain->isChecked()) { + m_page->intWidthPercent->setValue(tqRound(hPercent)); + + m_oldW = tqRound(m_origW * hPercent / 100); + m_page->intWidth->setValue(tqRound(m_oldW)); + + } + m_oldH = h; + + unblockAll(); +} + +void DlgLayerSize::slotWidthPercentChanged(int w) +{ + blockAll(); + + m_page->intWidth->setValue(tqRound(w * m_origW / 100)); + + if (m_page->chkConstrain->isChecked()) { + m_page->intHeightPercent->setValue(w); + m_page->intHeight->setValue(tqRound( w * m_origH / 100)); + } + + unblockAll(); +} + +void DlgLayerSize::slotHeightPercentChanged(int h) +{ + blockAll(); + + m_page->intHeight->setValue(tqRound(h * m_origH / 100)); + if (m_page->chkConstrain->isChecked()) { + m_page->intWidthPercent->setValue(h); + m_page->intWidth->setValue(tqRound( h * m_origW / 100)); + } + + unblockAll(); + +} + + +void DlgLayerSize::blockAll() +{ + // XXX: more efficient to use blockSignals? + m_page->intWidth->disconnect(); + m_page->intHeight->disconnect(); + m_page->intWidthPercent->disconnect(); + m_page->intHeightPercent->disconnect(); + +} + +void DlgLayerSize::unblockAll() +{ + // XXX: more efficient to use blockSignals? + connect (m_page->intWidth, TQT_SIGNAL(valueChanged(int)), + this, TQT_SLOT(slotWidthPixelsChanged(int))); + + connect (m_page->intHeight, TQT_SIGNAL(valueChanged(int)), + this, TQT_SLOT(slotHeightPixelsChanged(int))); + + connect (m_page->intWidthPercent, TQT_SIGNAL(valueChanged(int)), + this, TQT_SLOT(slotWidthPercentChanged(int))); + + connect (m_page->intHeightPercent, TQT_SIGNAL(valueChanged(int)), + this, TQT_SLOT(slotHeightPercentChanged(int))); + + +} + +#include "dlg_layersize.moc" diff --git a/chalk/plugins/viewplugins/imagesize/imagesize.cc b/chalk/plugins/viewplugins/imagesize/imagesize.cc deleted file mode 100644 index c795924e1..000000000 --- a/chalk/plugins/viewplugins/imagesize/imagesize.cc +++ /dev/null @@ -1,190 +0,0 @@ -/* - * imagesize.cc -- Part of Chalk - * - * Copyright (c) 2004 Boudewijn Rempt (boud@valdyas.org) - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - - -#include - -#include - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "imagesize.h" -#include "dlg_imagesize.h" -#include "dlg_layersize.h" -#include "kis_filter_strategy.h" - -typedef KGenericFactory ImageSizeFactory; -K_EXPORT_COMPONENT_FACTORY( chalkimagesize, ImageSizeFactory( "chalk" ) ) - -ImageSize::ImageSize(TQObject *parent, const char *name, const TQStringList &) - : KParts::Plugin(parent, name) -{ - if ( parent->inherits("KisView") ) - { - setInstance(ImageSizeFactory::instance()); - setXMLFile(locate("data","chalkplugins/imagesize.rc"), true); - - (void) new TDEAction(i18n("Change &Image Size..."), 0, "Shift-s", this, TQT_SLOT(slotImageSize()), actionCollection(), "imagesize"); - (void) new TDEAction(i18n("&Scale Layer..."), 0, 0, this, TQT_SLOT(slotLayerSize()), actionCollection(), "layerscale"); - - - m_view = (KisView*) parent; - // Selection manager takes ownership? - TDEAction * a = new TDEAction(i18n("&Scale Selection..."), 0, 0, this, TQT_SLOT(slotSelectionScale()), actionCollection(), "selectionscale"); - TQ_CHECK_PTR(a); - m_view ->canvasSubject()-> selectionManager()->addSelectionAction(a); - } -} - -ImageSize::~ImageSize() -{ - m_view = 0; -} - -void ImageSize::slotImageSize() -{ - KisImageSP image = m_view->canvasSubject()->currentImg(); - - if (!image) return; - - DlgImageSize * dlgImageSize = new DlgImageSize(m_view, "ImageSize"); - TQ_CHECK_PTR(dlgImageSize); - - dlgImageSize->setCaption(i18n("Image Size")); - - KisConfig cfg; - - dlgImageSize->setWidth(image->width()); - dlgImageSize->setHeight(image->height()); - - if (dlgImageSize->exec() == TQDialog::Accepted) { - TQ_INT32 w = dlgImageSize->width(); - TQ_INT32 h = dlgImageSize->height(); - - if (dlgImageSize->scale()) { - m_view->scaleCurrentImage((double)w / ((double)(image->width())), - (double)h / ((double)(image->height())), - dlgImageSize->filterType()); - } - else { - m_view->resizeCurrentImage(w, h, dlgImageSize->cropLayers()); - } - } - - delete dlgImageSize; -} - -void ImageSize::slotLayerSize() -{ - KisImageSP image = m_view->canvasSubject()->currentImg(); - - if (!image) return; - - DlgLayerSize * dlgLayerSize = new DlgLayerSize(m_view, "LayerSize"); - TQ_CHECK_PTR(dlgLayerSize); - - dlgLayerSize->setCaption(i18n("Layer Size")); - - KisConfig cfg; - KisPaintDeviceSP dev = image->activeDevice(); - - TQRect rc = dev->exactBounds(); - - dlgLayerSize->setWidth(rc.width()); - dlgLayerSize->setHeight(rc.height()); - - if (dlgLayerSize->exec() == TQDialog::Accepted) { - TQ_INT32 w = dlgLayerSize->width(); - TQ_INT32 h = dlgLayerSize->height(); - - m_view->scaleLayer((double)w / ((double)(rc.width())), - (double)h / ((double)(rc.height())), - dlgLayerSize->filterType()); - } - delete dlgLayerSize; -} - -void ImageSize::slotSelectionScale() -{ - KisImageSP image = m_view->canvasSubject()->currentImg(); - - if (!image) return; - - KisPaintDeviceSP layer = image->activeDevice(); - - if (!layer) return; - - if (!layer->hasSelection()) return; - - - DlgLayerSize * dlgLayerSize = new DlgLayerSize(m_view, "SelectionScale"); - TQ_CHECK_PTR(dlgLayerSize); - - dlgLayerSize->setCaption(i18n("Scale Selection")); - - KisConfig cfg; - TQRect rc = layer->selection()->selectedRect(); - - dlgLayerSize->setWidth(rc.width()); - dlgLayerSize->setHeight(rc.height()); - - if (dlgLayerSize->exec() == TQDialog::Accepted) { - TQ_INT32 w = dlgLayerSize->width(); - TQ_INT32 h = dlgLayerSize->height(); - - KisScaleWorker worker (layer->selection().data(), - (double)w / ((double)(rc.width())), - (double)h / ((double)(rc.height())), - dlgLayerSize->filterType()); - worker.run(); - - m_view->getCanvasController()->updateCanvas(); - - } - delete dlgLayerSize; -} - - -#include "imagesize.moc" diff --git a/chalk/plugins/viewplugins/imagesize/imagesize.cpp b/chalk/plugins/viewplugins/imagesize/imagesize.cpp new file mode 100644 index 000000000..af9c2570f --- /dev/null +++ b/chalk/plugins/viewplugins/imagesize/imagesize.cpp @@ -0,0 +1,190 @@ +/* + * imagesize.cpp -- Part of Chalk + * + * Copyright (c) 2004 Boudewijn Rempt (boud@valdyas.org) + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + + +#include + +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "imagesize.h" +#include "dlg_imagesize.h" +#include "dlg_layersize.h" +#include "kis_filter_strategy.h" + +typedef KGenericFactory ImageSizeFactory; +K_EXPORT_COMPONENT_FACTORY( chalkimagesize, ImageSizeFactory( "chalk" ) ) + +ImageSize::ImageSize(TQObject *parent, const char *name, const TQStringList &) + : KParts::Plugin(parent, name) +{ + if ( parent->inherits("KisView") ) + { + setInstance(ImageSizeFactory::instance()); + setXMLFile(locate("data","chalkplugins/imagesize.rc"), true); + + (void) new TDEAction(i18n("Change &Image Size..."), 0, "Shift-s", this, TQT_SLOT(slotImageSize()), actionCollection(), "imagesize"); + (void) new TDEAction(i18n("&Scale Layer..."), 0, 0, this, TQT_SLOT(slotLayerSize()), actionCollection(), "layerscale"); + + + m_view = (KisView*) parent; + // Selection manager takes ownership? + TDEAction * a = new TDEAction(i18n("&Scale Selection..."), 0, 0, this, TQT_SLOT(slotSelectionScale()), actionCollection(), "selectionscale"); + TQ_CHECK_PTR(a); + m_view ->canvasSubject()-> selectionManager()->addSelectionAction(a); + } +} + +ImageSize::~ImageSize() +{ + m_view = 0; +} + +void ImageSize::slotImageSize() +{ + KisImageSP image = m_view->canvasSubject()->currentImg(); + + if (!image) return; + + DlgImageSize * dlgImageSize = new DlgImageSize(m_view, "ImageSize"); + TQ_CHECK_PTR(dlgImageSize); + + dlgImageSize->setCaption(i18n("Image Size")); + + KisConfig cfg; + + dlgImageSize->setWidth(image->width()); + dlgImageSize->setHeight(image->height()); + + if (dlgImageSize->exec() == TQDialog::Accepted) { + TQ_INT32 w = dlgImageSize->width(); + TQ_INT32 h = dlgImageSize->height(); + + if (dlgImageSize->scale()) { + m_view->scaleCurrentImage((double)w / ((double)(image->width())), + (double)h / ((double)(image->height())), + dlgImageSize->filterType()); + } + else { + m_view->resizeCurrentImage(w, h, dlgImageSize->cropLayers()); + } + } + + delete dlgImageSize; +} + +void ImageSize::slotLayerSize() +{ + KisImageSP image = m_view->canvasSubject()->currentImg(); + + if (!image) return; + + DlgLayerSize * dlgLayerSize = new DlgLayerSize(m_view, "LayerSize"); + TQ_CHECK_PTR(dlgLayerSize); + + dlgLayerSize->setCaption(i18n("Layer Size")); + + KisConfig cfg; + KisPaintDeviceSP dev = image->activeDevice(); + + TQRect rc = dev->exactBounds(); + + dlgLayerSize->setWidth(rc.width()); + dlgLayerSize->setHeight(rc.height()); + + if (dlgLayerSize->exec() == TQDialog::Accepted) { + TQ_INT32 w = dlgLayerSize->width(); + TQ_INT32 h = dlgLayerSize->height(); + + m_view->scaleLayer((double)w / ((double)(rc.width())), + (double)h / ((double)(rc.height())), + dlgLayerSize->filterType()); + } + delete dlgLayerSize; +} + +void ImageSize::slotSelectionScale() +{ + KisImageSP image = m_view->canvasSubject()->currentImg(); + + if (!image) return; + + KisPaintDeviceSP layer = image->activeDevice(); + + if (!layer) return; + + if (!layer->hasSelection()) return; + + + DlgLayerSize * dlgLayerSize = new DlgLayerSize(m_view, "SelectionScale"); + TQ_CHECK_PTR(dlgLayerSize); + + dlgLayerSize->setCaption(i18n("Scale Selection")); + + KisConfig cfg; + TQRect rc = layer->selection()->selectedRect(); + + dlgLayerSize->setWidth(rc.width()); + dlgLayerSize->setHeight(rc.height()); + + if (dlgLayerSize->exec() == TQDialog::Accepted) { + TQ_INT32 w = dlgLayerSize->width(); + TQ_INT32 h = dlgLayerSize->height(); + + KisScaleWorker worker (layer->selection().data(), + (double)w / ((double)(rc.width())), + (double)h / ((double)(rc.height())), + dlgLayerSize->filterType()); + worker.run(); + + m_view->getCanvasController()->updateCanvas(); + + } + delete dlgLayerSize; +} + + +#include "imagesize.moc" diff --git a/chalk/plugins/viewplugins/modify_selection/Makefile.am b/chalk/plugins/viewplugins/modify_selection/Makefile.am index ea0f48429..a1eb18cb3 100644 --- a/chalk/plugins/viewplugins/modify_selection/Makefile.am +++ b/chalk/plugins/viewplugins/modify_selection/Makefile.am @@ -13,7 +13,7 @@ INCLUDES = -I$(srcdir)/../../../sdk \ $(all_includes) chalkmodifyselection_la_SOURCES = wdg_grow_selection.ui wdg_shrink_selection.ui wdg_border_selection.ui \ -dlg_grow_selection.cc dlg_shrink_selection.cc dlg_border_selection.cc modify_selection.cc +dlg_grow_selection.cpp dlg_shrink_selection.cpp dlg_border_selection.cpp modify_selection.cpp noinst_HEADERS = wdg_grow_selection.h wdg_shrink_selection.h wdg_border_selection.h dlg_grow_selection.h \ dlg_shrink_selection.h dlg_border_selection.h modify_selection.h diff --git a/chalk/plugins/viewplugins/modify_selection/dlg_border_selection.cc b/chalk/plugins/viewplugins/modify_selection/dlg_border_selection.cc deleted file mode 100644 index 7cd1c335d..000000000 --- a/chalk/plugins/viewplugins/modify_selection/dlg_border_selection.cc +++ /dev/null @@ -1,76 +0,0 @@ -/* - * dlg_border_selection.cc - part of Chalk - * - * Copyright (c) 2006 Michael Thaler - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include - -#include - -#include - -using namespace std; - -#include -#include -#include -#include -#include - -#include -#include -#include - -#include "dlg_border_selection.h" -#include "wdg_border_selection.h" - -DlgBorderSelection::DlgBorderSelection( TQWidget * parent, const char * name) : super (parent, name, true, i18n("Border Selection"), Ok | Cancel, Ok) -{ - m_page = new WdgBorderSelection(this, "border_selection"); - TQ_CHECK_PTR(m_page); - - setMainWidget(m_page); - resize(m_page->sizeHint()); - - connect(this, TQT_SIGNAL(okClicked()), this, TQT_SLOT(okClicked())); -} - -DlgBorderSelection::~DlgBorderSelection() -{ - delete m_page; -} - -TQ_INT32 DlgBorderSelection::xradius() -{ - return m_page->radiusSpinBox->value(); -} - -TQ_INT32 DlgBorderSelection::yradius() -{ - return m_page->radiusSpinBox->value(); -} - - -// SLOTS - -void DlgBorderSelection::okClicked() -{ - accept(); -} - -#include "dlg_border_selection.moc" diff --git a/chalk/plugins/viewplugins/modify_selection/dlg_border_selection.cpp b/chalk/plugins/viewplugins/modify_selection/dlg_border_selection.cpp new file mode 100644 index 000000000..8e2bc4de8 --- /dev/null +++ b/chalk/plugins/viewplugins/modify_selection/dlg_border_selection.cpp @@ -0,0 +1,76 @@ +/* + * dlg_border_selection.cpp - part of Chalk + * + * Copyright (c) 2006 Michael Thaler + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include + +#include + +#include + +using namespace std; + +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "dlg_border_selection.h" +#include "wdg_border_selection.h" + +DlgBorderSelection::DlgBorderSelection( TQWidget * parent, const char * name) : super (parent, name, true, i18n("Border Selection"), Ok | Cancel, Ok) +{ + m_page = new WdgBorderSelection(this, "border_selection"); + TQ_CHECK_PTR(m_page); + + setMainWidget(m_page); + resize(m_page->sizeHint()); + + connect(this, TQT_SIGNAL(okClicked()), this, TQT_SLOT(okClicked())); +} + +DlgBorderSelection::~DlgBorderSelection() +{ + delete m_page; +} + +TQ_INT32 DlgBorderSelection::xradius() +{ + return m_page->radiusSpinBox->value(); +} + +TQ_INT32 DlgBorderSelection::yradius() +{ + return m_page->radiusSpinBox->value(); +} + + +// SLOTS + +void DlgBorderSelection::okClicked() +{ + accept(); +} + +#include "dlg_border_selection.moc" diff --git a/chalk/plugins/viewplugins/modify_selection/dlg_grow_selection.cc b/chalk/plugins/viewplugins/modify_selection/dlg_grow_selection.cc deleted file mode 100644 index 38c445b01..000000000 --- a/chalk/plugins/viewplugins/modify_selection/dlg_grow_selection.cc +++ /dev/null @@ -1,76 +0,0 @@ -/* - * dlg_grow_selection.cc - part of Chalk - * - * Copyright (c) 2006 Michael Thaler - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include - -#include - -#include - -using namespace std; - -#include -#include -#include -#include -#include - -#include -#include -#include - -#include "dlg_grow_selection.h" -#include "wdg_grow_selection.h" - -DlgGrowSelection::DlgGrowSelection( TQWidget * parent, const char * name) : super (parent, name, true, i18n("Grow Selection"), Ok | Cancel, Ok) -{ - m_page = new WdgGrowSelection(this, "grow_selection"); - TQ_CHECK_PTR(m_page); - - setMainWidget(m_page); - resize(m_page->sizeHint()); - - connect(this, TQT_SIGNAL(okClicked()), this, TQT_SLOT(okClicked())); -} - -DlgGrowSelection::~DlgGrowSelection() -{ - delete m_page; -} - -TQ_INT32 DlgGrowSelection::xradius() -{ - return m_page->radiusSpinBox->value(); -} - -TQ_INT32 DlgGrowSelection::yradius() -{ - return m_page->radiusSpinBox->value(); -} - - -// SLOTS - -void DlgGrowSelection::okClicked() -{ - accept(); -} - -#include "dlg_grow_selection.moc" diff --git a/chalk/plugins/viewplugins/modify_selection/dlg_grow_selection.cpp b/chalk/plugins/viewplugins/modify_selection/dlg_grow_selection.cpp new file mode 100644 index 000000000..ae590eba9 --- /dev/null +++ b/chalk/plugins/viewplugins/modify_selection/dlg_grow_selection.cpp @@ -0,0 +1,76 @@ +/* + * dlg_grow_selection.cpp - part of Chalk + * + * Copyright (c) 2006 Michael Thaler + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include + +#include + +#include + +using namespace std; + +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "dlg_grow_selection.h" +#include "wdg_grow_selection.h" + +DlgGrowSelection::DlgGrowSelection( TQWidget * parent, const char * name) : super (parent, name, true, i18n("Grow Selection"), Ok | Cancel, Ok) +{ + m_page = new WdgGrowSelection(this, "grow_selection"); + TQ_CHECK_PTR(m_page); + + setMainWidget(m_page); + resize(m_page->sizeHint()); + + connect(this, TQT_SIGNAL(okClicked()), this, TQT_SLOT(okClicked())); +} + +DlgGrowSelection::~DlgGrowSelection() +{ + delete m_page; +} + +TQ_INT32 DlgGrowSelection::xradius() +{ + return m_page->radiusSpinBox->value(); +} + +TQ_INT32 DlgGrowSelection::yradius() +{ + return m_page->radiusSpinBox->value(); +} + + +// SLOTS + +void DlgGrowSelection::okClicked() +{ + accept(); +} + +#include "dlg_grow_selection.moc" diff --git a/chalk/plugins/viewplugins/modify_selection/dlg_shrink_selection.cc b/chalk/plugins/viewplugins/modify_selection/dlg_shrink_selection.cc deleted file mode 100644 index f0129e742..000000000 --- a/chalk/plugins/viewplugins/modify_selection/dlg_shrink_selection.cc +++ /dev/null @@ -1,81 +0,0 @@ -/* - * dlg_shrink_selection.cc - part of Chalk - * - * Copyright (c) 2006 Michael Thaler - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include - -#include - -#include - -using namespace std; - -#include -#include -#include -#include -#include - -#include -#include -#include - -#include "dlg_shrink_selection.h" -#include "wdg_shrink_selection.h" - -DlgShrinkSelection::DlgShrinkSelection( TQWidget * parent, const char * name) : super (parent, name, true, i18n("Shrink Selection"), Ok | Cancel, Ok) -{ - m_page = new WdgShrinkSelection(this, "shrink_selection"); - TQ_CHECK_PTR(m_page); - - setMainWidget(m_page); - resize(m_page->sizeHint()); - - connect(this, TQT_SIGNAL(okClicked()), this, TQT_SLOT(okClicked())); -} - -DlgShrinkSelection::~DlgShrinkSelection() -{ - delete m_page; -} - -TQ_INT32 DlgShrinkSelection::xradius() -{ - return m_page->radiusSpinBox->value(); -} - -TQ_INT32 DlgShrinkSelection::yradius() -{ - return m_page->radiusSpinBox->value(); -} - -bool DlgShrinkSelection::shrinkFromImageBorder() -{ - return m_page->shrinkFromImageBorderCheckBox->isChecked(); -} - - -// SLOTS - -void DlgShrinkSelection::okClicked() -{ - accept(); -} - -#include "dlg_shrink_selection.moc" diff --git a/chalk/plugins/viewplugins/modify_selection/dlg_shrink_selection.cpp b/chalk/plugins/viewplugins/modify_selection/dlg_shrink_selection.cpp new file mode 100644 index 000000000..ce4ce9d3b --- /dev/null +++ b/chalk/plugins/viewplugins/modify_selection/dlg_shrink_selection.cpp @@ -0,0 +1,81 @@ +/* + * dlg_shrink_selection.cpp - part of Chalk + * + * Copyright (c) 2006 Michael Thaler + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include + +#include + +#include + +using namespace std; + +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "dlg_shrink_selection.h" +#include "wdg_shrink_selection.h" + +DlgShrinkSelection::DlgShrinkSelection( TQWidget * parent, const char * name) : super (parent, name, true, i18n("Shrink Selection"), Ok | Cancel, Ok) +{ + m_page = new WdgShrinkSelection(this, "shrink_selection"); + TQ_CHECK_PTR(m_page); + + setMainWidget(m_page); + resize(m_page->sizeHint()); + + connect(this, TQT_SIGNAL(okClicked()), this, TQT_SLOT(okClicked())); +} + +DlgShrinkSelection::~DlgShrinkSelection() +{ + delete m_page; +} + +TQ_INT32 DlgShrinkSelection::xradius() +{ + return m_page->radiusSpinBox->value(); +} + +TQ_INT32 DlgShrinkSelection::yradius() +{ + return m_page->radiusSpinBox->value(); +} + +bool DlgShrinkSelection::shrinkFromImageBorder() +{ + return m_page->shrinkFromImageBorderCheckBox->isChecked(); +} + + +// SLOTS + +void DlgShrinkSelection::okClicked() +{ + accept(); +} + +#include "dlg_shrink_selection.moc" diff --git a/chalk/plugins/viewplugins/modify_selection/modify_selection.cc b/chalk/plugins/viewplugins/modify_selection/modify_selection.cc deleted file mode 100644 index 92d50ef7a..000000000 --- a/chalk/plugins/viewplugins/modify_selection/modify_selection.cc +++ /dev/null @@ -1,158 +0,0 @@ -/* - * modify_selection.cc -- Part of Chalk - * - * Copyright (c) 2006 Michael Thaler (michael.thaler@physik.tu-muenchen.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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - - -#include - -#include - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "modify_selection.h" -#include "dlg_grow_selection.h" -#include "dlg_shrink_selection.h" -#include "dlg_border_selection.h" - -typedef KGenericFactory ModifySelectionFactory; -K_EXPORT_COMPONENT_FACTORY( chalkmodifyselection, ModifySelectionFactory( "chalk" ) ) - -ModifySelection::ModifySelection(TQObject *parent, const char *name, const TQStringList &) - : KParts::Plugin(parent, name) -{ - if ( parent->inherits("KisView") ) - { - setInstance(ModifySelectionFactory::instance()); - setXMLFile(locate("data","chalkplugins/modify_selection.rc"), true); - - m_view = (KisView*) parent; - - // Selection manager takes ownership? - TDEAction* a = new TDEAction(i18n("Grow Selection..."), 0, 0, this, TQT_SLOT(slotGrowSelection()), actionCollection(), "growselection"); - TDEAction* b = new TDEAction(i18n("Shrink Selection..."), 0, 0, this, TQT_SLOT(slotShrinkSelection()), actionCollection(), "shrinkselection"); - TDEAction* c = new TDEAction(i18n("Border Selection..."), 0, 0, this, TQT_SLOT(slotBorderSelection()), actionCollection(), "borderselection"); - - TQ_CHECK_PTR(a); - TQ_CHECK_PTR(b); - TQ_CHECK_PTR(c); - - m_view ->canvasSubject()-> selectionManager()->addSelectionAction(a); - m_view ->canvasSubject()-> selectionManager()->addSelectionAction(b); - m_view ->canvasSubject()-> selectionManager()->addSelectionAction(c); - } -} - -ModifySelection::~ModifySelection() -{ - m_view = 0; -} - -void ModifySelection::slotGrowSelection() -{ - KisImageSP image = m_view->canvasSubject()->currentImg(); - - if (!image) return; - - DlgGrowSelection * dlgGrowSelection = new DlgGrowSelection(m_view, "GrowSelection"); - TQ_CHECK_PTR(dlgGrowSelection); - - dlgGrowSelection->setCaption(i18n("Grow Selection")); - - KisConfig cfg; - - if (dlgGrowSelection->exec() == TQDialog::Accepted) { - TQ_INT32 xradius = dlgGrowSelection->xradius(); - TQ_INT32 yradius = dlgGrowSelection->yradius(); - - m_view ->canvasSubject()-> selectionManager()->grow(xradius, yradius); - } - - delete dlgGrowSelection; -} - -void ModifySelection::slotShrinkSelection() -{ - KisImageSP image = m_view->canvasSubject()->currentImg(); - - if (!image) return; - - DlgShrinkSelection * dlgShrinkSelection = new DlgShrinkSelection(m_view, "ShrinkSelection"); - TQ_CHECK_PTR(dlgShrinkSelection); - - dlgShrinkSelection->setCaption(i18n("Shrink Selection")); - - KisConfig cfg; - - if (dlgShrinkSelection->exec() == TQDialog::Accepted) { - TQ_INT32 xradius = dlgShrinkSelection->xradius(); - TQ_INT32 yradius = dlgShrinkSelection->yradius(); - bool shrinkFromImageBorder = dlgShrinkSelection->shrinkFromImageBorder(); - - m_view ->canvasSubject()-> selectionManager()->shrink(xradius, yradius, shrinkFromImageBorder); - } - - delete dlgShrinkSelection; -} - -void ModifySelection::slotBorderSelection() -{ - KisImageSP image = m_view->canvasSubject()->currentImg(); - - if (!image) return; - - DlgBorderSelection * dlgBorderSelection = new DlgBorderSelection(m_view, "BorderSelection"); - TQ_CHECK_PTR(dlgBorderSelection); - - dlgBorderSelection->setCaption(i18n("Border Selection")); - - KisConfig cfg; - - if (dlgBorderSelection->exec() == TQDialog::Accepted) { - TQ_INT32 xradius = dlgBorderSelection->xradius(); - TQ_INT32 yradius = dlgBorderSelection->yradius(); - - m_view ->canvasSubject()-> selectionManager()->border(xradius, yradius); - } - - delete dlgBorderSelection; -} - -#include "modify_selection.moc" diff --git a/chalk/plugins/viewplugins/modify_selection/modify_selection.cpp b/chalk/plugins/viewplugins/modify_selection/modify_selection.cpp new file mode 100644 index 000000000..823899958 --- /dev/null +++ b/chalk/plugins/viewplugins/modify_selection/modify_selection.cpp @@ -0,0 +1,158 @@ +/* + * modify_selection.cpp -- Part of Chalk + * + * Copyright (c) 2006 Michael Thaler (michael.thaler@physik.tu-muenchen.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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + + +#include + +#include + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "modify_selection.h" +#include "dlg_grow_selection.h" +#include "dlg_shrink_selection.h" +#include "dlg_border_selection.h" + +typedef KGenericFactory ModifySelectionFactory; +K_EXPORT_COMPONENT_FACTORY( chalkmodifyselection, ModifySelectionFactory( "chalk" ) ) + +ModifySelection::ModifySelection(TQObject *parent, const char *name, const TQStringList &) + : KParts::Plugin(parent, name) +{ + if ( parent->inherits("KisView") ) + { + setInstance(ModifySelectionFactory::instance()); + setXMLFile(locate("data","chalkplugins/modify_selection.rc"), true); + + m_view = (KisView*) parent; + + // Selection manager takes ownership? + TDEAction* a = new TDEAction(i18n("Grow Selection..."), 0, 0, this, TQT_SLOT(slotGrowSelection()), actionCollection(), "growselection"); + TDEAction* b = new TDEAction(i18n("Shrink Selection..."), 0, 0, this, TQT_SLOT(slotShrinkSelection()), actionCollection(), "shrinkselection"); + TDEAction* c = new TDEAction(i18n("Border Selection..."), 0, 0, this, TQT_SLOT(slotBorderSelection()), actionCollection(), "borderselection"); + + TQ_CHECK_PTR(a); + TQ_CHECK_PTR(b); + TQ_CHECK_PTR(c); + + m_view ->canvasSubject()-> selectionManager()->addSelectionAction(a); + m_view ->canvasSubject()-> selectionManager()->addSelectionAction(b); + m_view ->canvasSubject()-> selectionManager()->addSelectionAction(c); + } +} + +ModifySelection::~ModifySelection() +{ + m_view = 0; +} + +void ModifySelection::slotGrowSelection() +{ + KisImageSP image = m_view->canvasSubject()->currentImg(); + + if (!image) return; + + DlgGrowSelection * dlgGrowSelection = new DlgGrowSelection(m_view, "GrowSelection"); + TQ_CHECK_PTR(dlgGrowSelection); + + dlgGrowSelection->setCaption(i18n("Grow Selection")); + + KisConfig cfg; + + if (dlgGrowSelection->exec() == TQDialog::Accepted) { + TQ_INT32 xradius = dlgGrowSelection->xradius(); + TQ_INT32 yradius = dlgGrowSelection->yradius(); + + m_view ->canvasSubject()-> selectionManager()->grow(xradius, yradius); + } + + delete dlgGrowSelection; +} + +void ModifySelection::slotShrinkSelection() +{ + KisImageSP image = m_view->canvasSubject()->currentImg(); + + if (!image) return; + + DlgShrinkSelection * dlgShrinkSelection = new DlgShrinkSelection(m_view, "ShrinkSelection"); + TQ_CHECK_PTR(dlgShrinkSelection); + + dlgShrinkSelection->setCaption(i18n("Shrink Selection")); + + KisConfig cfg; + + if (dlgShrinkSelection->exec() == TQDialog::Accepted) { + TQ_INT32 xradius = dlgShrinkSelection->xradius(); + TQ_INT32 yradius = dlgShrinkSelection->yradius(); + bool shrinkFromImageBorder = dlgShrinkSelection->shrinkFromImageBorder(); + + m_view ->canvasSubject()-> selectionManager()->shrink(xradius, yradius, shrinkFromImageBorder); + } + + delete dlgShrinkSelection; +} + +void ModifySelection::slotBorderSelection() +{ + KisImageSP image = m_view->canvasSubject()->currentImg(); + + if (!image) return; + + DlgBorderSelection * dlgBorderSelection = new DlgBorderSelection(m_view, "BorderSelection"); + TQ_CHECK_PTR(dlgBorderSelection); + + dlgBorderSelection->setCaption(i18n("Border Selection")); + + KisConfig cfg; + + if (dlgBorderSelection->exec() == TQDialog::Accepted) { + TQ_INT32 xradius = dlgBorderSelection->xradius(); + TQ_INT32 yradius = dlgBorderSelection->yradius(); + + m_view ->canvasSubject()-> selectionManager()->border(xradius, yradius); + } + + delete dlgBorderSelection; +} + +#include "modify_selection.moc" diff --git a/chalk/plugins/viewplugins/performancetest/Makefile.am b/chalk/plugins/viewplugins/performancetest/Makefile.am index 47906073b..eebf1f4d6 100644 --- a/chalk/plugins/viewplugins/performancetest/Makefile.am +++ b/chalk/plugins/viewplugins/performancetest/Makefile.am @@ -13,7 +13,7 @@ INCLUDES = -I$(srcdir)/../../../sdk \ kde_module_LTLIBRARIES = chalkperftest.la -chalkperftest_la_SOURCES = wdg_perftest.ui perftest.cc dlg_perftest.cc +chalkperftest_la_SOURCES = wdg_perftest.ui perftest.cpp dlg_perftest.cpp noinst_HEADERS = wdg_perftest.h dlg_perftest.h perftest.h chalkperftest_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) $(LIB_TQT) -ltdecore -ltdeui -lkjs -ltdefx -ltdeio -ltdeparts diff --git a/chalk/plugins/viewplugins/performancetest/dlg_perftest.cc b/chalk/plugins/viewplugins/performancetest/dlg_perftest.cc deleted file mode 100644 index b2a723069..000000000 --- a/chalk/plugins/viewplugins/performancetest/dlg_perftest.cc +++ /dev/null @@ -1,110 +0,0 @@ -/* - * dlg_perftest.cc - part of KimageShop^WKrayon^WChalk - * - * Copyright (c) 2004 Michael Thaler - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include - -#include - -#include - -using namespace std; - -#include -#include -#include -#include - -#include -#include -#include - -#include "dlg_perftest.h" -#include "wdg_perftest.h" - - -DlgPerfTest::DlgPerfTest( TQWidget * parent, - const char * name) - : super (parent, name, true, i18n("Performance Test"), Ok | Cancel, Ok) -{ - m_lock = false; - - m_page = new WdgPerfTest(this, "perf_test"); - TQ_CHECK_PTR(m_page); - - setMainWidget(m_page); - resize(m_page->sizeHint()); - - connect(this, TQT_SIGNAL(okClicked()), - this, TQT_SLOT(okClicked())); - - connect(m_page->btnSelectAll, TQT_SIGNAL(clicked()), this, TQT_SLOT(selectAllClicked())); - connect(m_page->btnDeselectAll, TQT_SIGNAL(clicked()), this, TQT_SLOT(deselectAllClicked())); -} - -DlgPerfTest::~DlgPerfTest() -{ - delete m_page; -} - -WdgPerfTest * DlgPerfTest::page() -{ - return m_page; -} - -// SLOTS - -void DlgPerfTest::okClicked() -{ - accept(); -} - -void DlgPerfTest::setAllTestCheckBoxes(bool checked) -{ - m_page->chkBitBlt->setChecked(checked); - m_page->chkFill->setChecked(checked); - m_page->chkGradient->setChecked(checked); - m_page->chkPixel->setChecked(checked); - m_page->chkShape->setChecked(checked); - m_page->chkLayer->setChecked(checked); - m_page->chkScale->setChecked(checked); - m_page->chkRotate->setChecked(checked); - m_page->chkRender->setChecked(checked); - m_page->chkSelection->setChecked(checked); - m_page->chkColorConversion->setChecked(checked); - m_page->chkFilter->setChecked(checked); - m_page->chkReadBytes->setChecked(checked); - m_page->chkWriteBytes->setChecked(checked); - m_page->chkIterators->setChecked(checked); - m_page->chkPaintView->setChecked(checked); - m_page->chkPaintViewFPS->setChecked(checked); -} - -void DlgPerfTest::selectAllClicked() -{ - setAllTestCheckBoxes(true); -} - -void DlgPerfTest::deselectAllClicked() -{ - setAllTestCheckBoxes(false); -} - - -#include "dlg_perftest.moc" diff --git a/chalk/plugins/viewplugins/performancetest/dlg_perftest.cpp b/chalk/plugins/viewplugins/performancetest/dlg_perftest.cpp new file mode 100644 index 000000000..326d97272 --- /dev/null +++ b/chalk/plugins/viewplugins/performancetest/dlg_perftest.cpp @@ -0,0 +1,110 @@ +/* + * dlg_perftest.cpp - part of KimageShop^WKrayon^WChalk + * + * Copyright (c) 2004 Michael Thaler + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include + +#include + +#include + +using namespace std; + +#include +#include +#include +#include + +#include +#include +#include + +#include "dlg_perftest.h" +#include "wdg_perftest.h" + + +DlgPerfTest::DlgPerfTest( TQWidget * parent, + const char * name) + : super (parent, name, true, i18n("Performance Test"), Ok | Cancel, Ok) +{ + m_lock = false; + + m_page = new WdgPerfTest(this, "perf_test"); + TQ_CHECK_PTR(m_page); + + setMainWidget(m_page); + resize(m_page->sizeHint()); + + connect(this, TQT_SIGNAL(okClicked()), + this, TQT_SLOT(okClicked())); + + connect(m_page->btnSelectAll, TQT_SIGNAL(clicked()), this, TQT_SLOT(selectAllClicked())); + connect(m_page->btnDeselectAll, TQT_SIGNAL(clicked()), this, TQT_SLOT(deselectAllClicked())); +} + +DlgPerfTest::~DlgPerfTest() +{ + delete m_page; +} + +WdgPerfTest * DlgPerfTest::page() +{ + return m_page; +} + +// SLOTS + +void DlgPerfTest::okClicked() +{ + accept(); +} + +void DlgPerfTest::setAllTestCheckBoxes(bool checked) +{ + m_page->chkBitBlt->setChecked(checked); + m_page->chkFill->setChecked(checked); + m_page->chkGradient->setChecked(checked); + m_page->chkPixel->setChecked(checked); + m_page->chkShape->setChecked(checked); + m_page->chkLayer->setChecked(checked); + m_page->chkScale->setChecked(checked); + m_page->chkRotate->setChecked(checked); + m_page->chkRender->setChecked(checked); + m_page->chkSelection->setChecked(checked); + m_page->chkColorConversion->setChecked(checked); + m_page->chkFilter->setChecked(checked); + m_page->chkReadBytes->setChecked(checked); + m_page->chkWriteBytes->setChecked(checked); + m_page->chkIterators->setChecked(checked); + m_page->chkPaintView->setChecked(checked); + m_page->chkPaintViewFPS->setChecked(checked); +} + +void DlgPerfTest::selectAllClicked() +{ + setAllTestCheckBoxes(true); +} + +void DlgPerfTest::deselectAllClicked() +{ + setAllTestCheckBoxes(false); +} + + +#include "dlg_perftest.moc" diff --git a/chalk/plugins/viewplugins/performancetest/perftest.cc b/chalk/plugins/viewplugins/performancetest/perftest.cc deleted file mode 100644 index f728043cd..000000000 --- a/chalk/plugins/viewplugins/performancetest/perftest.cc +++ /dev/null @@ -1,1198 +0,0 @@ -/* - * perftest.cc -- Part of Chalk - * - * Copyright (c) 2004 Boudewijn Rempt - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include - -#include - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include "kis_meta_registry.h" -#include -#include "kis_cursor.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "perftest.h" -#include "kis_filter_config_widget.h" -#include "kis_factory.h" - -#include "dlg_perftest.h" -#include "wdg_perftest.h" - -#define USE_CALLGRIND 0 - -#if USE_CALLGRIND -#include -#endif - - -typedef KGenericFactory PerfTestFactory; -K_EXPORT_COMPONENT_FACTORY( chalkperftest, PerfTestFactory( "chalk" ) ) - -PerfTest::PerfTest(TQObject *parent, const char *name, const TQStringList &) - : KParts::Plugin(parent, name) -{ - if ( parent->inherits("KisView") ) - { - setInstance(PerfTestFactory::instance()); - setXMLFile(locate("data","chalkplugins/perftest.rc"), true); - - (void) new TDEAction(i18n("&Performance Test..."), 0, 0, this, TQT_SLOT(slotPerfTest()), actionCollection(), "perf_test"); - - m_view = (KisView*) parent; - } -} - -PerfTest::~PerfTest() -{ - m_view = 0; -} - -void PerfTest::slotPerfTest() -{ - KisImageSP image = m_view->canvasSubject()->currentImg(); - - if (!image) return; - - DlgPerfTest * dlgPerfTest = new DlgPerfTest(m_view, "PerfTest"); - TQ_CHECK_PTR(dlgPerfTest); - - dlgPerfTest->setCaption(i18n("Performance Test")); - - TQString report = TQString(""); - - if (dlgPerfTest->exec() == TQDialog::Accepted) { - - TQ_INT32 testCount = (TQ_INT32)tqRound(dlgPerfTest->page()->intTestCount->value()); - - if (dlgPerfTest->page()->chkBitBlt->isChecked()) { - kdDebug() << "bltTest:\n"; - TQString s = bltTest(testCount); - report = report.append(s); - kdDebug() << s << "\n"; - } - if (dlgPerfTest->page()->chkFill->isChecked()) { - kdDebug() << "Filltest\n"; - TQString s= fillTest(testCount); - report = report.append(s); - kdDebug() << s << "\n"; - } - if (dlgPerfTest->page()->chkGradient->isChecked()) { - kdDebug() << "Gradienttest\n"; - TQString s = gradientTest(testCount); - report = report.append(s); - kdDebug() << s << "\n"; - } - if (dlgPerfTest->page()->chkPixel->isChecked()) { - kdDebug() << "Pixeltest\n"; - TQString s = pixelTest(testCount); - report = report.append(s); - kdDebug() << s << "\n"; - } - if (dlgPerfTest->page()->chkShape->isChecked()) { - kdDebug() << "Shapetest\n"; - TQString s = shapeTest(testCount); - report = report.append(s); - kdDebug() << s << "\n"; - } - if (dlgPerfTest->page()->chkLayer->isChecked()) { - kdDebug() << "LayerTest\n"; - TQString s = layerTest(testCount); - report = report.append(s); - kdDebug() << s << "\n"; - } - if (dlgPerfTest->page()->chkScale->isChecked()) { - kdDebug() << "Scaletest\n"; - TQString s = scaleTest(testCount); - report = report.append(s); - kdDebug() << s << "\n"; - } - if (dlgPerfTest->page()->chkRotate->isChecked()) { - kdDebug() << "Rotatetest\n"; - TQString s = rotateTest(testCount); - report = report.append(s); - kdDebug() << s << "\n"; - } - if (dlgPerfTest->page()->chkRender->isChecked()) { - kdDebug() << "Rendertest\n"; - TQString s = renderTest(testCount); - report = report.append(s); - kdDebug() << s << "\n"; - } - if (dlgPerfTest->page()->chkSelection->isChecked()) { - kdDebug() << "Selectiontest\n"; - TQString s = selectionTest(testCount); - report = report.append(s); - kdDebug() << s << "\n"; - } - if (dlgPerfTest->page()->chkColorConversion->isChecked()) { - kdDebug() << "Colorconversiontest\n"; - TQString s = colorConversionTest(testCount); - report = report.append(s); - kdDebug() << s << "\n"; - } - if (dlgPerfTest->page()->chkFilter-> isChecked()) { - kdDebug() << "filtertest\n"; - TQString s = filterTest(testCount); - report = report.append(s); - kdDebug() << s << "\n"; - } - if (dlgPerfTest->page()->chkReadBytes->isChecked()) { - kdDebug() << "Readbytes test\n"; - TQString s = readBytesTest(testCount); - report = report.append(s); - kdDebug() << s << "\n"; - } - if (dlgPerfTest->page()->chkWriteBytes-> isChecked()) { - kdDebug() << "Writebytes test\n"; - TQString s = writeBytesTest(testCount); - report = report.append(s); - kdDebug() << s << "\n"; - } - if (dlgPerfTest->page()->chkIterators->isChecked()) { - kdDebug() << "Iterators test\n"; - TQString s = iteratorTest(testCount); - report = report.append(s); - kdDebug() << s << "\n"; - } - if (dlgPerfTest->page()->chkPaintView->isChecked()) { - kdDebug() << "paintview test\n"; - TQString s = paintViewTest(testCount); - report = report.append(s); - kdDebug() << s << "\n"; - } - if (dlgPerfTest->page()->chkPaintViewFPS->isChecked()) { - kdDebug() << "paint current view (fps) test\n"; - TQString s = paintViewFPSTest(); - report = report.append(s); - kdDebug() << s << "\n"; - } - KDialogBase * d = new KDialogBase(m_view, "", true, "", KDialogBase::Ok); - TQ_CHECK_PTR(d); - - d->setCaption("Performance test results"); - TQTextEdit * e = new TQTextEdit(d); - TQ_CHECK_PTR(e); - d->setMainWidget(e); - e->setText(report); - e->setMinimumWidth(600); - e->setMinimumHeight(600); - d->exec(); - delete d; - - } - delete dlgPerfTest; -} - -TQString PerfTest::bltTest(TQ_UINT32 testCount) -{ - TQString report = TQString("* bitBlt test\n"); - - KisDoc * doc = m_view->canvasSubject()->document(); - KisIDList l = KisMetaRegistry::instance()->csRegistry()->listKeys(); - - for (KisIDList::Iterator it = l.begin(); it != l.end(); ++it) { - - kdDebug() << "Image->" << (*it).name() << "\n"; - - report = report.append( " Testing blitting on " + (*it).name() + "\n"); - - KisImageSP img = doc->newImage("blt-" + (*it).name(), 1000, 1000, - KisMetaRegistry::instance()->csRegistry()->getColorSpace(*it,"")); - - report = report.append(doBlit(COMPOSITE_OVER, *it, OPACITY_OPAQUE, testCount, img)); - report = report.append( "\n"); - report = report.append(doBlit(COMPOSITE_OVER, *it, OPACITY_OPAQUE / 2, testCount, img)); - report = report.append( "\n"); - report = report.append(doBlit(COMPOSITE_COPY, *it, OPACITY_OPAQUE, testCount, img)); - report = report.append( "\n"); - report = report.append(doBlit(COMPOSITE_COPY, *it, OPACITY_OPAQUE / 2, testCount, img)); - report = report.append( "\n"); - } - - return report; - - -} - - -TQString PerfTest::doBlit(const KisCompositeOp& op, - KisID cspace, - TQ_UINT8 opacity, - TQ_UINT32 testCount, - KisImageSP img) -{ - - TQTime t; - TQString report; - - // ------------------------------------------------------------------------------ - // Small - - KisPaintDeviceSP small = new KisPaintDevice(KisMetaRegistry::instance()->csRegistry()->getColorSpace(cspace,""), "small blit"); - TQ_CHECK_PTR(small); - - KisFillPainter pf(small.data()) ; - pf.fillRect(0, 0, 32, 32, KisColor(TQt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8())); - pf.end(); - - t.restart(); - KisPainter p(img->activeDevice()); - for (TQ_UINT32 i = 0; i < testCount; ++i) { - p.bitBlt(0, 0, op, small.data(),0,0,32, 32); - } - p.end(); - - report = report.append(TQString(" %1 blits of rectangles < tilesize with opacity %2 and composite op %3: %4ms\n") - .arg(testCount) - .arg(opacity) - .arg(op.id().name()) - .arg(t.elapsed())); - - - // ------------------------------------------------------------------------------ - // Medium - KisPaintDeviceSP medium = new KisPaintDevice(KisMetaRegistry::instance()->csRegistry()->getColorSpace(cspace,""), "medium blit"); - TQ_CHECK_PTR(medium); - - pf.begin(medium.data()) ; - pf.fillRect(0, 0, 64 * 3, 64 * 3, KisColor(TQt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8())); - pf.end(); - - t.restart(); - p.begin(img->activeDevice().data()); - for (TQ_UINT32 i = 0; i < testCount; ++i) { - p.bitBlt(0, 0, op, medium.data(),0,0,96, 96); - } - p.end(); - - report = report.append(TQString(" %1 blits of rectangles 3 * tilesize with opacity %2 and composite op %3: %4ms\n") - .arg(testCount) - .arg(opacity) - .arg(op.id().name()) - .arg(t.elapsed())); - - - // ------------------------------------------------------------------------------ - // Big - KisPaintDeviceSP big = new KisPaintDevice(KisMetaRegistry::instance()->csRegistry()->getColorSpace(cspace,""), "big blit"); - TQ_CHECK_PTR(big); - - pf.begin(big.data()) ; - pf.fillRect(0, 0, 800, 800, KisColor(TQt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8())); - pf.end(); - - t.restart(); - p.begin(img->activeDevice().data()); - for (TQ_UINT32 i = 0; i < testCount; ++i) { - p.bitBlt(0, 0, op, big.data(),0,0,800,800); - - } - p.end(); - report = report.append(TQString(" %1 blits of rectangles 800 x 800 with opacity %2 and composite op %3: %4ms\n") - .arg(testCount) - .arg(opacity) - .arg(op.id().name()) - .arg(t.elapsed())); - - - // ------------------------------------------------------------------------------ - // Outside - - KisPaintDeviceSP outside = new KisPaintDevice(KisMetaRegistry::instance()->csRegistry()->getColorSpace(cspace,""), "outside blit"); - TQ_CHECK_PTR(outside); - pf.begin(outside.data()) ; - pf.fillRect(0, 0, 500, 500, KisColor(TQt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8())); - pf.end(); - - t.restart(); - p.begin(img->activeDevice().data()); - for (TQ_UINT32 i = 0; i < testCount; ++i) { - p.bitBlt(600, 600, op, outside.data(),0,0,500,500); - - } - p.end(); - report = report.append(TQString(" %1 blits of rectangles 500 x 500 at 600,600 with opacity %2 and composite op %3: %4ms\n") - .arg(testCount) - .arg(opacity) - .arg(op.id().name()) - .arg(t.elapsed())); - - // ------------------------------------------------------------------------------ - // Small with varied source opacity - - KisPaintDeviceSP small_with_alpha = new KisPaintDevice(KisMetaRegistry::instance()->csRegistry()->getColorSpace(cspace,""), "small blit with alpha"); - TQ_CHECK_PTR(small_with_alpha); - - pf.begin(small_with_alpha.data()) ; - pf.fillRect(0, 0, 32, 32, KisColor(TQt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8()), OPACITY_TRANSPARENT); - pf.fillRect(4, 4, 24, 24, KisColor(TQt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8()), OPACITY_OPAQUE / 2); - pf.fillRect(8, 8, 16, 16, KisColor(TQt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8()), OPACITY_OPAQUE); - pf.end(); - - t.restart(); - p.begin(img->activeDevice().data()); - for (TQ_UINT32 i = 0; i < testCount; ++i) { - p.bitBlt(0, 0, op, small_with_alpha.data(), 0, 0, 32, 32); - } - p.end(); - - report = report.append(TQString(" %1 blits of rectangles < tilesize with source alpha, with opacity %2 and composite op %3: %4ms\n") - .arg(testCount) - .arg(opacity) - .arg(op.id().name()) - .arg(t.elapsed())); - - return report; - -} - -TQString PerfTest::fillTest(TQ_UINT32 testCount) -{ - TQString report = TQString("* Fill test\n"); - - KisDoc * doc = m_view->canvasSubject()->document(); - KisIDList l = KisMetaRegistry::instance()->csRegistry()->listKeys(); - - for (KisIDList::Iterator it = l.begin(); it != l.end(); ++it) { - kdDebug() << "Filltest on " << (*it).name() + "\n"; - - report = report.append( " Testing blitting on " + (*it).name() + "\n"); - - KisImageSP img = doc->newImage("fill-" + (*it).name(), 1000, 1000, KisMetaRegistry::instance()->csRegistry()->getColorSpace(*it,"")); - KisPaintDeviceSP l = img->activeDevice(); - - // Rect fill - KisFillPainter p(l.data()); - TQTime t; - t.restart(); - for (TQ_UINT32 i = 0; i < testCount; ++i) { - p.eraseRect(0, 0, 1000, 1000); - } - report = report.append(TQString(" Erased 1000 x 1000 layer %1 times: %2\n").arg(testCount).arg(t.elapsed())); - - - t.restart(); - for (TQ_UINT32 i = 0; i < testCount; ++i) { - p.eraseRect(50, 50, 500, 500); - } - report = report.append(TQString(" Erased 500 x 500 layer %1 times: %2\n").arg(testCount).arg(t.elapsed())); - - - t.restart(); - for (TQ_UINT32 i = 0; i < testCount; ++i) { - p.eraseRect(-50, -50, 1100, 1100); - } - report = report.append(TQString(" Erased rect bigger than layer %1 times: %2\n").arg(testCount).arg(t.elapsed())); - - - // Opaque Rect fill - t.restart(); - for (TQ_UINT32 i = 0; i < testCount; ++i) { - p.fillRect(0, 0, 1000, 1000, KisColor(TQt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8())); - } - report = report.append(TQString(" Opaque fill 1000 x 1000 layer %1 times: %2\n").arg(testCount).arg(t.elapsed())); - - - t.restart(); - for (TQ_UINT32 i = 0; i < testCount; ++i) { - p.fillRect(50, 50, 500, 500, KisColor(TQt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8())); - } - report = report.append(TQString(" Opaque fill 500 x 500 layer %1 times: %2\n").arg(testCount).arg(t.elapsed())); - - - t.restart(); - for (TQ_UINT32 i = 0; i < testCount; ++i) { - p.fillRect(-50, -50, 1100, 1100, KisColor(TQt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8())); - } - report = report.append(TQString(" Opaque fill rect bigger than layer %1 times: %2\n").arg(testCount).arg(t.elapsed())); - - // Transparent rect fill - - t.restart(); - for (TQ_UINT32 i = 0; i < testCount; ++i) { - p.fillRect(0, 0, 1000, 1000, KisColor(TQt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8()), OPACITY_OPAQUE / 2); - } - report = report.append(TQString(" Opaque fill 1000 x 1000 layer %1 times: %2\n").arg(testCount).arg(t.elapsed())); - - - t.restart(); - for (TQ_UINT32 i = 0; i < testCount; ++i) { - p.fillRect(50, 50, 500, 500, KisColor(TQt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8()), OPACITY_OPAQUE / 2); - } - report = report.append(TQString(" Opaque fill 500 x 500 layer %1 times: %2\n").arg(testCount).arg(t.elapsed())); - - - t.restart(); - for (TQ_UINT32 i = 0; i < testCount; ++i) { - p.fillRect(-50, -50, 1100, 1100, KisColor(TQt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8()), OPACITY_OPAQUE / 2); - } - report = report.append(TQString(" Opaque fill rect bigger than layer %1 times: %2\n").arg(testCount).arg(t.elapsed())); - - // Colour fill - - t.restart(); - for (TQ_UINT32 i = 0; i < testCount; ++i) { - p.eraseRect(0, 0, 1000, 1000); -// p.paintEllipse(500, 1000, 100, 0, 0); - p.setPaintColor(KisColor(TQt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8())); - p.setFillThreshold(15); - p.setCompositeOp(COMPOSITE_OVER); - p.fillColor(0,0); - } - report = report.append(TQString(" Opaque floodfill of whole circle (incl. erase and painting of circle) %1 times: %2\n").arg(testCount).arg(t.elapsed())); - - - // Pattern fill - t.restart(); - for (TQ_UINT32 i = 0; i < testCount; ++i) { - p.eraseRect(0, 0, 1000, 1000); -// p.paintEllipse(500, 1000, 100, 0, 0); - p.setPaintColor(KisColor(TQt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8())); - KisResourceServerBase* r = KisResourceServerRegistry::instance()->get("PatternServer"); - TQ_CHECK_PTR(r); - p.setPattern((KisPattern*)r->resources().first()); - p.setFillThreshold(15); - p.setCompositeOp(COMPOSITE_OVER); - p.fillPattern(0,0); - } - report = report.append(TQString(" Opaque patternfill of whole circle (incl. erase and painting of circle) %1 times: %2\n").arg(testCount).arg(t.elapsed())); - - - - } - - - - return report; - -} - -TQString PerfTest::gradientTest(TQ_UINT32 testCount) -{ - return TQString("Gradient test\n"); -} - -TQString PerfTest::pixelTest(TQ_UINT32 testCount) -{ - TQString report = TQString("* pixel/setpixel test\n"); - - KisDoc * doc = m_view->canvasSubject()->document(); - KisIDList l = KisMetaRegistry::instance()->csRegistry()->listKeys(); - - - for (KisIDList::Iterator it = l.begin(); it != l.end(); ++it) { - report = report.append( " Testing pixel/setpixel on " + (*it).name() + "\n"); - - KisImageSP img = doc->newImage("fill-" + (*it).name(), 1000, 1000, KisMetaRegistry::instance()->csRegistry()->getColorSpace(*it,"")); - - KisPaintDeviceSP l = img->activeDevice(); - - TQTime t; - t.restart(); - - TQColor c = TQt::black; - TQ_UINT8 opacity = OPACITY_OPAQUE; - for (TQ_UINT32 i = 0; i < testCount; ++i) { - for (TQ_UINT32 x = 0; x < 1000; ++x) { - for (TQ_UINT32 y = 0; y < 1000; ++y) { - l->pixel(x, y, &c, &opacity); - } - } - } - report = report.append(TQString(" read 1000 x 1000 pixels %1 times: %2\n").arg(testCount).arg(t.elapsed())); - - c= TQt::black; - t.restart(); - for (TQ_UINT32 i = 0; i < testCount; ++i) { - for (TQ_UINT32 x = 0; x < 1000; ++x) { - for (TQ_UINT32 y = 0; y < 1000; ++y) { - l->setPixel(x, y, c, 128); - } - } - } - report = report.append(TQString(" written 1000 x 1000 pixels %1 times: %2\n").arg(testCount).arg(t.elapsed())); - - } - - - - - return report; - -} - -TQString PerfTest::shapeTest(TQ_UINT32 testCount) -{ - return TQString("Shape test\n"); -} - -TQString PerfTest::layerTest(TQ_UINT32 testCount) -{ - return TQString("Layer test\n"); -} - -TQString PerfTest::scaleTest(TQ_UINT32 testCount) -{ - return TQString("Scale test\n"); -} - -TQString PerfTest::rotateTest(TQ_UINT32 testCount) -{ - TQString report = TQString("* Rotate test\n"); - - KisDoc * doc = m_view->canvasSubject()->document(); - KisIDList l = KisMetaRegistry::instance()->csRegistry()->listKeys(); - for (KisIDList::Iterator it = l.begin(); it != l.end(); ++it) { - - doc->undoAdapter()->setUndo( false ); - TQTime t; - - for (uint i = 0; i < testCount; ++i) { - for (double angle = 0; angle < 360; ++angle) { - kdDebug() << "Rotating " << (*it).name() << " at " << angle << " degrees\n"; - KisImage * img = doc->newImage("cs-" + (*it).name(), 1000, 1000, KisMetaRegistry::instance()->csRegistry()->getColorSpace(*it,"")); - img->rotate(angle, m_view->canvasSubject()->progressDisplay()); - kdDebug() << "Size: " << img->projection()->extent() << endl; - delete img; - } - } - report = report.append(TQString(" rotated 1000 x 1000 pixels over 360 degrees, degree by degree, %1 times: %2\n").arg(testCount).arg(t.elapsed())); - } - return report; -} - -TQString PerfTest::renderTest(TQ_UINT32 restCount) -{ - return TQString("Render test\n"); -} - -TQString PerfTest::selectionTest(TQ_UINT32 testCount) -{ - return TQString("Selection test\n"); -} - -TQString PerfTest::colorConversionTest(TQ_UINT32 testCount) -{ - TQString report = TQString("* Colorspace conversion test\n"); - - KisDoc * doc = m_view->canvasSubject()->document(); - KisIDList l = KisMetaRegistry::instance()->csRegistry()->listKeys(); - for (KisIDList::Iterator it = l.begin(); it != l.end(); ++it) { - - KisImage * img = doc->newImage("cs-" + (*it).name(), 1000, 1000, KisMetaRegistry::instance()->csRegistry()->getColorSpace(*it,"")); - - TQTime t; - - KisIDList l2 = KisMetaRegistry::instance()->csRegistry()->listKeys(); - for (KisIDList::Iterator it2 = l2.begin(); it2 != l2.end(); ++it2) { - kdDebug() << "test conversion from " << (*it).name() << " to " << (*it2).name() << endl; - - t.restart(); - for (uint i = 0; i < testCount; ++i) { - KisImage * img2 = new KisImage(*img); - img2->convertTo(KisMetaRegistry::instance()->csRegistry()->getColorSpace(*it2,"")); - delete img2; - } - report = report.append(TQString(" converted from " + (*it).name() + " to " + (*it2).name() + " 1000 x 1000 pixels %1 times: %2\n").arg(testCount).arg(t.elapsed())); - - } - - delete img; - - } - return report; - -} - -TQString PerfTest::filterTest(TQ_UINT32 testCount) -{ - - TQString report = TQString("* Filter test\n"); - - KisIDList filters = KisFilterRegistry::instance()->listKeys(); - KisDoc * doc = m_view->canvasSubject()->document(); - KisIDList l = KisMetaRegistry::instance()->csRegistry()->listKeys(); - - for (KisIDList::Iterator it = l.begin(); it != l.end(); ++it) { - report = report.append( " Testing filtering on " + (*it).name() + "\n"); - - KisImageSP img = doc->newImage("filter-" + (*it).name(), 1000, 1000, KisMetaRegistry::instance()->csRegistry()->getColorSpace(*it,"")); - KisPaintDeviceSP l = img->activeDevice(); - - TQTime t; - - for (KisIDList::Iterator it = filters.begin(); it != filters.end(); ++it) { - - KisFilterSP f = KisFilterRegistry::instance()->get(*it); - t.restart(); - kdDebug() << "test filter " << f->id().name() << " on " << img->colorSpace()->id().name() << endl; - for (TQ_UINT32 i = 0; i < testCount; ++i) { - f->enableProgress(); - f->process(l.data(), l.data(), f->configuration(f->createConfigurationWidget(m_view, l.data())), TQRect(0, 0, 1000, 1000)); - f->disableProgress(); - } - report = report.append(TQString(" filtered " + (*it).name() + "1000 x 1000 pixels %1 times: %2\n").arg(testCount).arg(t.elapsed())); - - } - - } - return report; - -} - -TQString PerfTest::readBytesTest(TQ_UINT32 testCount) -{ - TQString report = TQString("* Read bytes test\n\n"); - - // On default tiles - KisDoc * doc = m_view->canvasSubject()->document(); - KisImageSP img = doc->newImage("Readbytes ", 1000, 1000, KisMetaRegistry::instance()->csRegistry()->getColorSpace(KisID("RGBA",""),"")); - KisPaintDeviceSP l = img->activeDevice(); - - TQTime t; - t.restart(); - - for (TQ_UINT32 i = 0; i < testCount; ++i) { - TQ_UINT8 * newData = new TQ_UINT8[1000 * 1000 * l->pixelSize()]; - TQ_CHECK_PTR(newData); - l->readBytes(newData, 0, 0, 1000, 1000); - delete[] newData; - } - - report = report.append(TQString(" read 1000 x 1000 pixels %1 times from empty image: %2\n").arg(testCount).arg(t.elapsed())); - - // On tiles with data - - KisFillPainter p(l.data()); - p.fillRect(0, 0, 1000, 1000, KisColor(TQt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8())); - p.end(); - - t.restart(); - - for (TQ_UINT32 i = 0; i < testCount; ++i) { - TQ_UINT8 * newData = new TQ_UINT8[1000 * 1000 * l->pixelSize()]; - TQ_CHECK_PTR(newData); - l->readBytes(newData, 0, 0, 1000, 1000); - delete[] newData; - } - - report = report.append(TQString(" read 1000 x 1000 pixels %1 times from filled image: %2\n").arg(testCount).arg(t.elapsed())); - - return report; -} - - -TQString PerfTest::writeBytesTest(TQ_UINT32 testCount) -{ - TQString report = TQString("* Write bytes test"); - - // On default tiles - KisDoc * doc = m_view->canvasSubject()->document(); - KisImageSP img = doc->newImage("Writebytes ", 1000, 1000, KisMetaRegistry::instance()->csRegistry()->getColorSpace(KisID("RGBA", ""),"")); - KisPaintDeviceSP l = img->activeDevice(); - KisFillPainter p(l.data()); - p.fillRect(0, 0, 1000, 1000, KisColor(TQt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8())); - p.end(); - - - TQ_UINT8 * data = new TQ_UINT8[1000 * 1000 * l->pixelSize()]; - TQ_CHECK_PTR(data); - l->readBytes(data, 0, 0, 1000, 1000); - - TQTime t; - t.restart(); - for (TQ_UINT32 i = 0; i < testCount; ++i) { - l->writeBytes(data, 0, 0, 1000, 1000); - } - delete[] data; - report = report.append(TQString(" written 1000 x 1000 pixels %1 times: %2\n").arg(testCount).arg(t.elapsed())); - return report; - - -} - -/////// Iterator tests - - -TQString hlineRODefault(KisDoc * doc, TQ_UINT32 testCount) -{ - KisImageSP img = doc->newImage("", 1000, 1000, KisMetaRegistry::instance()->csRegistry()->getColorSpace(KisID("RGBA", ""),"")); - KisPaintDeviceSP l = img->activeDevice(); - - TQTime t; - t.restart(); - - - for (TQ_UINT32 i = 0; i < testCount; ++i) { - int adv; - - for(TQ_INT32 y2 = 0; y2 < 0 + 1000; y2++) - { - KisHLineIterator hiter = l->createHLineIterator(0, y2, 1000, false); - while(! hiter.isDone()) - { - adv = hiter.nConseqHPixels(); - hiter += adv; - } - } - - } - - return TQString(" hline iterated read-only 1000 x 1000 pixels %1 times over default tile: %2\n").arg(testCount).arg(t.elapsed()); - - -} - -TQString hlineRO(KisDoc * doc, TQ_UINT32 testCount) -{ - KisImageSP img = doc->newImage("", 1000, 1000, KisMetaRegistry::instance()->csRegistry()->getColorSpace(KisID("RGBA", ""),"")); - KisPaintDeviceSP l = img->activeDevice(); - - KisFillPainter p(l.data()); - p.fillRect(0, 0, 1000, 1000, KisColor(TQt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8())); - p.end(); - - TQTime t; - t.restart(); - - for (TQ_UINT32 i = 0; i < testCount; ++i) { - int adv; - - for(TQ_INT32 y2 = 0; y2 < 0 + 1000; y2++) - { - KisHLineIterator hiter = l->createHLineIterator(0, y2, 1000, false); - while(! hiter.isDone()) - { - adv = hiter.nConseqHPixels(); - hiter += adv; - } - } - - } - - return TQString(" hline iterated read-only 1000 x 1000 pixels %1 times over existing tile: %2\n").arg(testCount).arg(t.elapsed()); - -} - -TQString hlineWRDefault(KisDoc * doc, TQ_UINT32 testCount) -{ - KisImageSP img = doc->newImage("", 1000, 1000, KisMetaRegistry::instance()->csRegistry()->getColorSpace(KisID("RGBA", ""),"")); - KisPaintDeviceSP l = img->activeDevice(); - - TQTime t; - t.restart(); - - for (TQ_UINT32 i = 0; i < testCount; ++i) { - int adv; - - for(TQ_INT32 y2 = 0; y2 < 0 + 1000; y2++) - { - KisHLineIterator hiter = l->createHLineIterator(0, y2, 1000, true); - while(! hiter.isDone()) - { - adv = hiter.nConseqHPixels(); - hiter += adv; - } - } - - } - - return TQString(" hline iterated writable 1000 x 1000 pixels %1 times over default tile: %2\n").arg(testCount).arg(t.elapsed()); - -} - -TQString hlineWR(KisDoc * doc, TQ_UINT32 testCount) -{ - KisImageSP img = doc->newImage("", 1000, 1000, KisMetaRegistry::instance()->csRegistry()->getColorSpace(KisID("RGBA", ""),"")); - KisPaintDeviceSP l = img->activeDevice(); - - KisFillPainter p(l.data()); - p.fillRect(0, 0, 1000, 1000, KisColor(TQt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8())); - p.end(); - - - TQTime t; - t.restart(); - - for (TQ_UINT32 i = 0; i < testCount; ++i) { - int adv; - for(TQ_INT32 y2 = 0; y2 < 0 + 1000; y2++) - { - KisHLineIterator hiter = l->createHLineIterator(0, y2, 1000, true); - while(! hiter.isDone()) - { - adv = hiter.nConseqHPixels(); - hiter += adv; - } - } - - } - - return TQString(" hline iterated writable 1000 x 1000 pixels %1 times over existing tile: %2\n").arg(testCount).arg(t.elapsed()); - -} - - -TQString vlineRODefault(KisDoc * doc, TQ_UINT32 testCount) -{ - KisImageSP img = doc->newImage("", 1000, 1000, KisMetaRegistry::instance()->csRegistry()->getColorSpace(KisID("RGBA", ""),"")); - KisPaintDeviceSP l = img->activeDevice(); - - TQTime t; - t.restart(); - - for (TQ_UINT32 i = 0; i < testCount; ++i) { - for(TQ_INT32 y2 = 0; y2 < 0 + 1000; y2++) - { - KisVLineIterator hiter = l->createVLineIterator(y2, 0, 1000, true); - while(! hiter.isDone()) - { - ++hiter; - } - } - - } - - return TQString(" vline iterated read-only 1000 x 1000 pixels %1 times over default tile: %2\n").arg(testCount).arg(t.elapsed()); - -} - -TQString vlineRO(KisDoc * doc, TQ_UINT32 testCount) -{ - KisImageSP img = doc->newImage("", 1000, 1000, KisMetaRegistry::instance()->csRegistry()->getColorSpace(KisID("RGBA", ""),"")); - KisPaintDeviceSP l = img->activeDevice(); - - KisFillPainter p(l.data()); - p.fillRect(0, 0, 1000, 1000, KisColor(TQt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8())); - p.end(); - - - TQTime t; - t.restart(); - - for (TQ_UINT32 i = 0; i < testCount; ++i) { - for(TQ_INT32 y2 = 0; y2 < 0 + 1000; y2++) - { - KisVLineIterator hiter = l->createVLineIterator(y2, 0, 1000, true); - while(! hiter.isDone()) - { - ++hiter; - } - } - - } - - return TQString(" vline iterated read-only 1000 x 1000 pixels %1 times over existing tile: %2\n").arg(testCount).arg(t.elapsed()); - -} - -TQString vlineWRDefault(KisDoc * doc, TQ_UINT32 testCount) -{ - KisImageSP img = doc->newImage("", 1000, 1000, KisMetaRegistry::instance()->csRegistry()->getColorSpace(KisID("RGBA", ""),"")); - KisPaintDeviceSP l = img->activeDevice(); - - TQTime t; - t.restart(); - - for (TQ_UINT32 i = 0; i < testCount; ++i) { - - for(TQ_INT32 y2 = 0; y2 < 0 + 1000; y2++) - { - KisVLineIterator hiter = l->createVLineIterator(y2, 0, 1000, true); - while(! hiter.isDone()) - { - ++hiter; - } - } - - } - - return TQString(" vline iterated writable 1000 x 1000 pixels %1 times over default tile: %2\n").arg(testCount).arg(t.elapsed()); -} - -TQString vlineWR(KisDoc * doc, TQ_UINT32 testCount) -{ - - KisImageSP img = doc->newImage("", 1000, 1000, KisMetaRegistry::instance()->csRegistry()->getColorSpace(KisID("RGBA", ""),"")); - KisPaintDeviceSP l = img->activeDevice(); - - KisFillPainter p(l.data()); - p.fillRect(0, 0, 1000, 1000, KisColor(TQt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8())); - p.end(); - - TQTime t; - t.restart(); - - for (TQ_UINT32 i = 0; i < testCount; ++i) { - for(TQ_INT32 y2 = 0; y2 < 0 + 1000; y2++) - { - KisHLineIterator hiter = l->createHLineIterator(y2, 0, 1000, true); - while(! hiter.isDone()) - { - ++hiter; - } - } - - } - - return TQString(" vline iterated writable 1000 x 1000 pixels %1 times over existing tile: %2\n").arg(testCount).arg(t.elapsed()); - -} - -TQString rectRODefault(KisDoc * doc, TQ_UINT32 testCount) -{ - KisImageSP img = doc->newImage("", 1000, 1000, KisMetaRegistry::instance()->csRegistry()->getColorSpace(KisID("RGBA", ""),"")); - KisPaintDeviceSP l = img->activeDevice(); -; - TQTime t; - t.restart(); - - for (TQ_UINT32 i = 0; i < testCount; ++i) { - KisRectIterator r = l->createRectIterator(0, 0, 1000, 1000, false); - while(! r.isDone()) - { - ++r; - } - } - - return TQString(" rect iterated read-only 1000 x 1000 pixels %1 times over default tile: %2\n").arg(testCount).arg(t.elapsed()); - - -} - -TQString rectRO(KisDoc * doc, TQ_UINT32 testCount) -{ - KisImageSP img = doc->newImage("", 1000, 1000, KisMetaRegistry::instance()->csRegistry()->getColorSpace(KisID("RGBA", ""),"")); - KisPaintDeviceSP l = img->activeDevice(); - - KisFillPainter p(l.data()); - p.fillRect(0, 0, 1000, 1000, KisColor(TQt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8())); - p.end(); - - TQTime t; - t.restart(); - - for (TQ_UINT32 i = 0; i < testCount; ++i) { - KisRectIterator r = l->createRectIterator(0, 0, 1000, 1000, false); - while(! r.isDone()) - { - ++r; - } - } - - return TQString(" rect iterated read-only 1000 x 1000 pixels %1 times over existing tile: %2\n").arg(testCount).arg(t.elapsed()); - -} - -TQString rectWRDefault(KisDoc * doc, TQ_UINT32 testCount) -{ - - - KisImageSP img = doc->newImage("", 1000, 1000, KisMetaRegistry::instance()->csRegistry()->getColorSpace(KisID("RGBA", ""),"")); - KisPaintDeviceSP l = img->activeDevice(); - - TQTime t; - t.restart(); - - for (TQ_UINT32 i = 0; i < testCount; ++i) { - KisRectIterator r = l->createRectIterator(0, 0, 1000, 1000, true); - while(! r.isDone()) - { - ++r; - } - } - - return TQString(" rect iterated writable 1000 x 1000 pixels %1 times over default tile: %2\n").arg(testCount).arg(t.elapsed()); - -} - -TQString rectWR(KisDoc * doc, TQ_UINT32 testCount) -{ - KisImageSP img = doc->newImage("", 1000, 1000, KisMetaRegistry::instance()->csRegistry()->getColorSpace(KisID("RGBA", ""),"")); - KisPaintDeviceSP l = img->activeDevice(); - - KisFillPainter p(l.data()); - p.fillRect(0, 0, 1000, 1000, KisColor(TQt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8())); - p.end(); - - - TQTime t; - t.restart(); - - - for (TQ_UINT32 i = 0; i < testCount; ++i) { - KisRectIterator r = l->createRectIterator(0, 0, 1000, 1000, true); - while(! r.isDone()) - { - ++r; - } - } - - - return TQString(" rect iterated writable 1000 x 1000 pixels %1 times over existing tile: %2\n").arg(testCount).arg(t.elapsed()); - - -} -TQString PerfTest::iteratorTest(TQ_UINT32 testCount) -{ - TQString report = "Iterator test"; - - KisDoc * doc = m_view->canvasSubject()->document(); - - report = report.append(hlineRODefault(doc, testCount)); - report = report.append(hlineRO(doc, testCount)); - report = report.append(hlineWRDefault(doc, testCount)); - report = report.append(hlineWR(doc, testCount)); - - report = report.append(vlineRODefault(doc, testCount)); - report = report.append(vlineRO(doc, testCount)); - report = report.append(vlineWRDefault(doc, testCount)); - report = report.append(vlineWR(doc, testCount)); - - report = report.append(rectRODefault(doc, testCount)); - report = report.append(rectRO(doc, testCount)); - report = report.append(rectWRDefault(doc, testCount)); - report = report.append(rectWR(doc, testCount)); - - return report; - - -} - -TQString PerfTest::paintViewTest(TQ_UINT32 testCount) -{ - TQString report = TQString("* paintView test\n\n"); - - KisDoc * doc = m_view->canvasSubject()->document(); - - KisImageSP img = doc->currentImage(); - img->resize(512,512); - - - KisPaintDeviceSP l = img->activeDevice(); - - KisFillPainter p(l.data()); - p.fillRect(0, 0, 512, 512, KisColor(TQt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8())); - p.end(); - - TQTime t; - t.restart(); - -#if USE_CALLGRIND - CALLGRIND_ZERO_STATS(); -#endif - - for (TQ_UINT32 i = 0; i < testCount; ++i) { - m_view->getCanvasController()->updateCanvas(TQRect(0, 0, 512, 512)); - } - -#if USE_CALLGRIND - CALLGRIND_DUMP_STATS(); -#endif - - report = report.append(TQString(" painted a 512 x 512 image %1 times: %2 ms\n").arg(testCount).arg(t.elapsed())); - - img->newLayer("layer 2", OPACITY_OPAQUE); - l = img->activeDevice(); - - p.begin(l.data()); - p.fillRect(0, 0, 512, 512, KisColor(TQt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8())); - p.end(); - - img->newLayer("layer 3", OPACITY_OPAQUE); - l = img->activeDevice(); - - p.begin(l.data()); - p.fillRect(0, 0, 512, 512, KisColor(TQt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8())); - p.end(); - - t.restart(); - - for (TQ_UINT32 i = 0; i < testCount; ++i) { - m_view->getCanvasController()->updateCanvas(TQRect(0, 0, 512, 512)); - } - - report = report.append(TQString(" painted a 512 x 512 image with 3 layers %1 times: %2 ms\n").arg(testCount).arg(t.elapsed())); - - return report; -} - -TQString PerfTest::paintViewFPSTest() -{ - TQString report = TQString("* paintView (fps) test\n\n"); - - TQTime t; - t.restart(); - -#if USE_CALLGRIND - CALLGRIND_ZERO_STATS(); -#endif - - int numViewsPainted = 0; - const int millisecondsPerSecond = 1000; - - while (t.elapsed() < millisecondsPerSecond) { - m_view->getCanvasController()->updateCanvas(); - numViewsPainted++; - } - -#if USE_CALLGRIND - CALLGRIND_DUMP_STATS(); -#endif - - report = report.append(TQString(" painted current view at %1 frames per second\n").arg(numViewsPainted)); - - return report; -} - -#include "perftest.moc" diff --git a/chalk/plugins/viewplugins/performancetest/perftest.cpp b/chalk/plugins/viewplugins/performancetest/perftest.cpp new file mode 100644 index 000000000..fa5445516 --- /dev/null +++ b/chalk/plugins/viewplugins/performancetest/perftest.cpp @@ -0,0 +1,1198 @@ +/* + * perftest.cpp -- Part of Chalk + * + * Copyright (c) 2004 Boudewijn Rempt + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "kis_meta_registry.h" +#include +#include "kis_cursor.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "perftest.h" +#include "kis_filter_config_widget.h" +#include "kis_factory.h" + +#include "dlg_perftest.h" +#include "wdg_perftest.h" + +#define USE_CALLGRIND 0 + +#if USE_CALLGRIND +#include +#endif + + +typedef KGenericFactory PerfTestFactory; +K_EXPORT_COMPONENT_FACTORY( chalkperftest, PerfTestFactory( "chalk" ) ) + +PerfTest::PerfTest(TQObject *parent, const char *name, const TQStringList &) + : KParts::Plugin(parent, name) +{ + if ( parent->inherits("KisView") ) + { + setInstance(PerfTestFactory::instance()); + setXMLFile(locate("data","chalkplugins/perftest.rc"), true); + + (void) new TDEAction(i18n("&Performance Test..."), 0, 0, this, TQT_SLOT(slotPerfTest()), actionCollection(), "perf_test"); + + m_view = (KisView*) parent; + } +} + +PerfTest::~PerfTest() +{ + m_view = 0; +} + +void PerfTest::slotPerfTest() +{ + KisImageSP image = m_view->canvasSubject()->currentImg(); + + if (!image) return; + + DlgPerfTest * dlgPerfTest = new DlgPerfTest(m_view, "PerfTest"); + TQ_CHECK_PTR(dlgPerfTest); + + dlgPerfTest->setCaption(i18n("Performance Test")); + + TQString report = TQString(""); + + if (dlgPerfTest->exec() == TQDialog::Accepted) { + + TQ_INT32 testCount = (TQ_INT32)tqRound(dlgPerfTest->page()->intTestCount->value()); + + if (dlgPerfTest->page()->chkBitBlt->isChecked()) { + kdDebug() << "bltTest:\n"; + TQString s = bltTest(testCount); + report = report.append(s); + kdDebug() << s << "\n"; + } + if (dlgPerfTest->page()->chkFill->isChecked()) { + kdDebug() << "Filltest\n"; + TQString s= fillTest(testCount); + report = report.append(s); + kdDebug() << s << "\n"; + } + if (dlgPerfTest->page()->chkGradient->isChecked()) { + kdDebug() << "Gradienttest\n"; + TQString s = gradientTest(testCount); + report = report.append(s); + kdDebug() << s << "\n"; + } + if (dlgPerfTest->page()->chkPixel->isChecked()) { + kdDebug() << "Pixeltest\n"; + TQString s = pixelTest(testCount); + report = report.append(s); + kdDebug() << s << "\n"; + } + if (dlgPerfTest->page()->chkShape->isChecked()) { + kdDebug() << "Shapetest\n"; + TQString s = shapeTest(testCount); + report = report.append(s); + kdDebug() << s << "\n"; + } + if (dlgPerfTest->page()->chkLayer->isChecked()) { + kdDebug() << "LayerTest\n"; + TQString s = layerTest(testCount); + report = report.append(s); + kdDebug() << s << "\n"; + } + if (dlgPerfTest->page()->chkScale->isChecked()) { + kdDebug() << "Scaletest\n"; + TQString s = scaleTest(testCount); + report = report.append(s); + kdDebug() << s << "\n"; + } + if (dlgPerfTest->page()->chkRotate->isChecked()) { + kdDebug() << "Rotatetest\n"; + TQString s = rotateTest(testCount); + report = report.append(s); + kdDebug() << s << "\n"; + } + if (dlgPerfTest->page()->chkRender->isChecked()) { + kdDebug() << "Rendertest\n"; + TQString s = renderTest(testCount); + report = report.append(s); + kdDebug() << s << "\n"; + } + if (dlgPerfTest->page()->chkSelection->isChecked()) { + kdDebug() << "Selectiontest\n"; + TQString s = selectionTest(testCount); + report = report.append(s); + kdDebug() << s << "\n"; + } + if (dlgPerfTest->page()->chkColorConversion->isChecked()) { + kdDebug() << "Colorconversiontest\n"; + TQString s = colorConversionTest(testCount); + report = report.append(s); + kdDebug() << s << "\n"; + } + if (dlgPerfTest->page()->chkFilter-> isChecked()) { + kdDebug() << "filtertest\n"; + TQString s = filterTest(testCount); + report = report.append(s); + kdDebug() << s << "\n"; + } + if (dlgPerfTest->page()->chkReadBytes->isChecked()) { + kdDebug() << "Readbytes test\n"; + TQString s = readBytesTest(testCount); + report = report.append(s); + kdDebug() << s << "\n"; + } + if (dlgPerfTest->page()->chkWriteBytes-> isChecked()) { + kdDebug() << "Writebytes test\n"; + TQString s = writeBytesTest(testCount); + report = report.append(s); + kdDebug() << s << "\n"; + } + if (dlgPerfTest->page()->chkIterators->isChecked()) { + kdDebug() << "Iterators test\n"; + TQString s = iteratorTest(testCount); + report = report.append(s); + kdDebug() << s << "\n"; + } + if (dlgPerfTest->page()->chkPaintView->isChecked()) { + kdDebug() << "paintview test\n"; + TQString s = paintViewTest(testCount); + report = report.append(s); + kdDebug() << s << "\n"; + } + if (dlgPerfTest->page()->chkPaintViewFPS->isChecked()) { + kdDebug() << "paint current view (fps) test\n"; + TQString s = paintViewFPSTest(); + report = report.append(s); + kdDebug() << s << "\n"; + } + KDialogBase * d = new KDialogBase(m_view, "", true, "", KDialogBase::Ok); + TQ_CHECK_PTR(d); + + d->setCaption("Performance test results"); + TQTextEdit * e = new TQTextEdit(d); + TQ_CHECK_PTR(e); + d->setMainWidget(e); + e->setText(report); + e->setMinimumWidth(600); + e->setMinimumHeight(600); + d->exec(); + delete d; + + } + delete dlgPerfTest; +} + +TQString PerfTest::bltTest(TQ_UINT32 testCount) +{ + TQString report = TQString("* bitBlt test\n"); + + KisDoc * doc = m_view->canvasSubject()->document(); + KisIDList l = KisMetaRegistry::instance()->csRegistry()->listKeys(); + + for (KisIDList::Iterator it = l.begin(); it != l.end(); ++it) { + + kdDebug() << "Image->" << (*it).name() << "\n"; + + report = report.append( " Testing blitting on " + (*it).name() + "\n"); + + KisImageSP img = doc->newImage("blt-" + (*it).name(), 1000, 1000, + KisMetaRegistry::instance()->csRegistry()->getColorSpace(*it,"")); + + report = report.append(doBlit(COMPOSITE_OVER, *it, OPACITY_OPAQUE, testCount, img)); + report = report.append( "\n"); + report = report.append(doBlit(COMPOSITE_OVER, *it, OPACITY_OPAQUE / 2, testCount, img)); + report = report.append( "\n"); + report = report.append(doBlit(COMPOSITE_COPY, *it, OPACITY_OPAQUE, testCount, img)); + report = report.append( "\n"); + report = report.append(doBlit(COMPOSITE_COPY, *it, OPACITY_OPAQUE / 2, testCount, img)); + report = report.append( "\n"); + } + + return report; + + +} + + +TQString PerfTest::doBlit(const KisCompositeOp& op, + KisID cspace, + TQ_UINT8 opacity, + TQ_UINT32 testCount, + KisImageSP img) +{ + + TQTime t; + TQString report; + + // ------------------------------------------------------------------------------ + // Small + + KisPaintDeviceSP small = new KisPaintDevice(KisMetaRegistry::instance()->csRegistry()->getColorSpace(cspace,""), "small blit"); + TQ_CHECK_PTR(small); + + KisFillPainter pf(small.data()) ; + pf.fillRect(0, 0, 32, 32, KisColor(TQt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8())); + pf.end(); + + t.restart(); + KisPainter p(img->activeDevice()); + for (TQ_UINT32 i = 0; i < testCount; ++i) { + p.bitBlt(0, 0, op, small.data(),0,0,32, 32); + } + p.end(); + + report = report.append(TQString(" %1 blits of rectangles < tilesize with opacity %2 and composite op %3: %4ms\n") + .arg(testCount) + .arg(opacity) + .arg(op.id().name()) + .arg(t.elapsed())); + + + // ------------------------------------------------------------------------------ + // Medium + KisPaintDeviceSP medium = new KisPaintDevice(KisMetaRegistry::instance()->csRegistry()->getColorSpace(cspace,""), "medium blit"); + TQ_CHECK_PTR(medium); + + pf.begin(medium.data()) ; + pf.fillRect(0, 0, 64 * 3, 64 * 3, KisColor(TQt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8())); + pf.end(); + + t.restart(); + p.begin(img->activeDevice().data()); + for (TQ_UINT32 i = 0; i < testCount; ++i) { + p.bitBlt(0, 0, op, medium.data(),0,0,96, 96); + } + p.end(); + + report = report.append(TQString(" %1 blits of rectangles 3 * tilesize with opacity %2 and composite op %3: %4ms\n") + .arg(testCount) + .arg(opacity) + .arg(op.id().name()) + .arg(t.elapsed())); + + + // ------------------------------------------------------------------------------ + // Big + KisPaintDeviceSP big = new KisPaintDevice(KisMetaRegistry::instance()->csRegistry()->getColorSpace(cspace,""), "big blit"); + TQ_CHECK_PTR(big); + + pf.begin(big.data()) ; + pf.fillRect(0, 0, 800, 800, KisColor(TQt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8())); + pf.end(); + + t.restart(); + p.begin(img->activeDevice().data()); + for (TQ_UINT32 i = 0; i < testCount; ++i) { + p.bitBlt(0, 0, op, big.data(),0,0,800,800); + + } + p.end(); + report = report.append(TQString(" %1 blits of rectangles 800 x 800 with opacity %2 and composite op %3: %4ms\n") + .arg(testCount) + .arg(opacity) + .arg(op.id().name()) + .arg(t.elapsed())); + + + // ------------------------------------------------------------------------------ + // Outside + + KisPaintDeviceSP outside = new KisPaintDevice(KisMetaRegistry::instance()->csRegistry()->getColorSpace(cspace,""), "outside blit"); + TQ_CHECK_PTR(outside); + pf.begin(outside.data()) ; + pf.fillRect(0, 0, 500, 500, KisColor(TQt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8())); + pf.end(); + + t.restart(); + p.begin(img->activeDevice().data()); + for (TQ_UINT32 i = 0; i < testCount; ++i) { + p.bitBlt(600, 600, op, outside.data(),0,0,500,500); + + } + p.end(); + report = report.append(TQString(" %1 blits of rectangles 500 x 500 at 600,600 with opacity %2 and composite op %3: %4ms\n") + .arg(testCount) + .arg(opacity) + .arg(op.id().name()) + .arg(t.elapsed())); + + // ------------------------------------------------------------------------------ + // Small with varied source opacity + + KisPaintDeviceSP small_with_alpha = new KisPaintDevice(KisMetaRegistry::instance()->csRegistry()->getColorSpace(cspace,""), "small blit with alpha"); + TQ_CHECK_PTR(small_with_alpha); + + pf.begin(small_with_alpha.data()) ; + pf.fillRect(0, 0, 32, 32, KisColor(TQt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8()), OPACITY_TRANSPARENT); + pf.fillRect(4, 4, 24, 24, KisColor(TQt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8()), OPACITY_OPAQUE / 2); + pf.fillRect(8, 8, 16, 16, KisColor(TQt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8()), OPACITY_OPAQUE); + pf.end(); + + t.restart(); + p.begin(img->activeDevice().data()); + for (TQ_UINT32 i = 0; i < testCount; ++i) { + p.bitBlt(0, 0, op, small_with_alpha.data(), 0, 0, 32, 32); + } + p.end(); + + report = report.append(TQString(" %1 blits of rectangles < tilesize with source alpha, with opacity %2 and composite op %3: %4ms\n") + .arg(testCount) + .arg(opacity) + .arg(op.id().name()) + .arg(t.elapsed())); + + return report; + +} + +TQString PerfTest::fillTest(TQ_UINT32 testCount) +{ + TQString report = TQString("* Fill test\n"); + + KisDoc * doc = m_view->canvasSubject()->document(); + KisIDList l = KisMetaRegistry::instance()->csRegistry()->listKeys(); + + for (KisIDList::Iterator it = l.begin(); it != l.end(); ++it) { + kdDebug() << "Filltest on " << (*it).name() + "\n"; + + report = report.append( " Testing blitting on " + (*it).name() + "\n"); + + KisImageSP img = doc->newImage("fill-" + (*it).name(), 1000, 1000, KisMetaRegistry::instance()->csRegistry()->getColorSpace(*it,"")); + KisPaintDeviceSP l = img->activeDevice(); + + // Rect fill + KisFillPainter p(l.data()); + TQTime t; + t.restart(); + for (TQ_UINT32 i = 0; i < testCount; ++i) { + p.eraseRect(0, 0, 1000, 1000); + } + report = report.append(TQString(" Erased 1000 x 1000 layer %1 times: %2\n").arg(testCount).arg(t.elapsed())); + + + t.restart(); + for (TQ_UINT32 i = 0; i < testCount; ++i) { + p.eraseRect(50, 50, 500, 500); + } + report = report.append(TQString(" Erased 500 x 500 layer %1 times: %2\n").arg(testCount).arg(t.elapsed())); + + + t.restart(); + for (TQ_UINT32 i = 0; i < testCount; ++i) { + p.eraseRect(-50, -50, 1100, 1100); + } + report = report.append(TQString(" Erased rect bigger than layer %1 times: %2\n").arg(testCount).arg(t.elapsed())); + + + // Opaque Rect fill + t.restart(); + for (TQ_UINT32 i = 0; i < testCount; ++i) { + p.fillRect(0, 0, 1000, 1000, KisColor(TQt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8())); + } + report = report.append(TQString(" Opaque fill 1000 x 1000 layer %1 times: %2\n").arg(testCount).arg(t.elapsed())); + + + t.restart(); + for (TQ_UINT32 i = 0; i < testCount; ++i) { + p.fillRect(50, 50, 500, 500, KisColor(TQt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8())); + } + report = report.append(TQString(" Opaque fill 500 x 500 layer %1 times: %2\n").arg(testCount).arg(t.elapsed())); + + + t.restart(); + for (TQ_UINT32 i = 0; i < testCount; ++i) { + p.fillRect(-50, -50, 1100, 1100, KisColor(TQt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8())); + } + report = report.append(TQString(" Opaque fill rect bigger than layer %1 times: %2\n").arg(testCount).arg(t.elapsed())); + + // Transparent rect fill + + t.restart(); + for (TQ_UINT32 i = 0; i < testCount; ++i) { + p.fillRect(0, 0, 1000, 1000, KisColor(TQt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8()), OPACITY_OPAQUE / 2); + } + report = report.append(TQString(" Opaque fill 1000 x 1000 layer %1 times: %2\n").arg(testCount).arg(t.elapsed())); + + + t.restart(); + for (TQ_UINT32 i = 0; i < testCount; ++i) { + p.fillRect(50, 50, 500, 500, KisColor(TQt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8()), OPACITY_OPAQUE / 2); + } + report = report.append(TQString(" Opaque fill 500 x 500 layer %1 times: %2\n").arg(testCount).arg(t.elapsed())); + + + t.restart(); + for (TQ_UINT32 i = 0; i < testCount; ++i) { + p.fillRect(-50, -50, 1100, 1100, KisColor(TQt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8()), OPACITY_OPAQUE / 2); + } + report = report.append(TQString(" Opaque fill rect bigger than layer %1 times: %2\n").arg(testCount).arg(t.elapsed())); + + // Colour fill + + t.restart(); + for (TQ_UINT32 i = 0; i < testCount; ++i) { + p.eraseRect(0, 0, 1000, 1000); +// p.paintEllipse(500, 1000, 100, 0, 0); + p.setPaintColor(KisColor(TQt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8())); + p.setFillThreshold(15); + p.setCompositeOp(COMPOSITE_OVER); + p.fillColor(0,0); + } + report = report.append(TQString(" Opaque floodfill of whole circle (incl. erase and painting of circle) %1 times: %2\n").arg(testCount).arg(t.elapsed())); + + + // Pattern fill + t.restart(); + for (TQ_UINT32 i = 0; i < testCount; ++i) { + p.eraseRect(0, 0, 1000, 1000); +// p.paintEllipse(500, 1000, 100, 0, 0); + p.setPaintColor(KisColor(TQt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8())); + KisResourceServerBase* r = KisResourceServerRegistry::instance()->get("PatternServer"); + TQ_CHECK_PTR(r); + p.setPattern((KisPattern*)r->resources().first()); + p.setFillThreshold(15); + p.setCompositeOp(COMPOSITE_OVER); + p.fillPattern(0,0); + } + report = report.append(TQString(" Opaque patternfill of whole circle (incl. erase and painting of circle) %1 times: %2\n").arg(testCount).arg(t.elapsed())); + + + + } + + + + return report; + +} + +TQString PerfTest::gradientTest(TQ_UINT32 testCount) +{ + return TQString("Gradient test\n"); +} + +TQString PerfTest::pixelTest(TQ_UINT32 testCount) +{ + TQString report = TQString("* pixel/setpixel test\n"); + + KisDoc * doc = m_view->canvasSubject()->document(); + KisIDList l = KisMetaRegistry::instance()->csRegistry()->listKeys(); + + + for (KisIDList::Iterator it = l.begin(); it != l.end(); ++it) { + report = report.append( " Testing pixel/setpixel on " + (*it).name() + "\n"); + + KisImageSP img = doc->newImage("fill-" + (*it).name(), 1000, 1000, KisMetaRegistry::instance()->csRegistry()->getColorSpace(*it,"")); + + KisPaintDeviceSP l = img->activeDevice(); + + TQTime t; + t.restart(); + + TQColor c = TQt::black; + TQ_UINT8 opacity = OPACITY_OPAQUE; + for (TQ_UINT32 i = 0; i < testCount; ++i) { + for (TQ_UINT32 x = 0; x < 1000; ++x) { + for (TQ_UINT32 y = 0; y < 1000; ++y) { + l->pixel(x, y, &c, &opacity); + } + } + } + report = report.append(TQString(" read 1000 x 1000 pixels %1 times: %2\n").arg(testCount).arg(t.elapsed())); + + c= TQt::black; + t.restart(); + for (TQ_UINT32 i = 0; i < testCount; ++i) { + for (TQ_UINT32 x = 0; x < 1000; ++x) { + for (TQ_UINT32 y = 0; y < 1000; ++y) { + l->setPixel(x, y, c, 128); + } + } + } + report = report.append(TQString(" written 1000 x 1000 pixels %1 times: %2\n").arg(testCount).arg(t.elapsed())); + + } + + + + + return report; + +} + +TQString PerfTest::shapeTest(TQ_UINT32 testCount) +{ + return TQString("Shape test\n"); +} + +TQString PerfTest::layerTest(TQ_UINT32 testCount) +{ + return TQString("Layer test\n"); +} + +TQString PerfTest::scaleTest(TQ_UINT32 testCount) +{ + return TQString("Scale test\n"); +} + +TQString PerfTest::rotateTest(TQ_UINT32 testCount) +{ + TQString report = TQString("* Rotate test\n"); + + KisDoc * doc = m_view->canvasSubject()->document(); + KisIDList l = KisMetaRegistry::instance()->csRegistry()->listKeys(); + for (KisIDList::Iterator it = l.begin(); it != l.end(); ++it) { + + doc->undoAdapter()->setUndo( false ); + TQTime t; + + for (uint i = 0; i < testCount; ++i) { + for (double angle = 0; angle < 360; ++angle) { + kdDebug() << "Rotating " << (*it).name() << " at " << angle << " degrees\n"; + KisImage * img = doc->newImage("cs-" + (*it).name(), 1000, 1000, KisMetaRegistry::instance()->csRegistry()->getColorSpace(*it,"")); + img->rotate(angle, m_view->canvasSubject()->progressDisplay()); + kdDebug() << "Size: " << img->projection()->extent() << endl; + delete img; + } + } + report = report.append(TQString(" rotated 1000 x 1000 pixels over 360 degrees, degree by degree, %1 times: %2\n").arg(testCount).arg(t.elapsed())); + } + return report; +} + +TQString PerfTest::renderTest(TQ_UINT32 restCount) +{ + return TQString("Render test\n"); +} + +TQString PerfTest::selectionTest(TQ_UINT32 testCount) +{ + return TQString("Selection test\n"); +} + +TQString PerfTest::colorConversionTest(TQ_UINT32 testCount) +{ + TQString report = TQString("* Colorspace conversion test\n"); + + KisDoc * doc = m_view->canvasSubject()->document(); + KisIDList l = KisMetaRegistry::instance()->csRegistry()->listKeys(); + for (KisIDList::Iterator it = l.begin(); it != l.end(); ++it) { + + KisImage * img = doc->newImage("cs-" + (*it).name(), 1000, 1000, KisMetaRegistry::instance()->csRegistry()->getColorSpace(*it,"")); + + TQTime t; + + KisIDList l2 = KisMetaRegistry::instance()->csRegistry()->listKeys(); + for (KisIDList::Iterator it2 = l2.begin(); it2 != l2.end(); ++it2) { + kdDebug() << "test conversion from " << (*it).name() << " to " << (*it2).name() << endl; + + t.restart(); + for (uint i = 0; i < testCount; ++i) { + KisImage * img2 = new KisImage(*img); + img2->convertTo(KisMetaRegistry::instance()->csRegistry()->getColorSpace(*it2,"")); + delete img2; + } + report = report.append(TQString(" converted from " + (*it).name() + " to " + (*it2).name() + " 1000 x 1000 pixels %1 times: %2\n").arg(testCount).arg(t.elapsed())); + + } + + delete img; + + } + return report; + +} + +TQString PerfTest::filterTest(TQ_UINT32 testCount) +{ + + TQString report = TQString("* Filter test\n"); + + KisIDList filters = KisFilterRegistry::instance()->listKeys(); + KisDoc * doc = m_view->canvasSubject()->document(); + KisIDList l = KisMetaRegistry::instance()->csRegistry()->listKeys(); + + for (KisIDList::Iterator it = l.begin(); it != l.end(); ++it) { + report = report.append( " Testing filtering on " + (*it).name() + "\n"); + + KisImageSP img = doc->newImage("filter-" + (*it).name(), 1000, 1000, KisMetaRegistry::instance()->csRegistry()->getColorSpace(*it,"")); + KisPaintDeviceSP l = img->activeDevice(); + + TQTime t; + + for (KisIDList::Iterator it = filters.begin(); it != filters.end(); ++it) { + + KisFilterSP f = KisFilterRegistry::instance()->get(*it); + t.restart(); + kdDebug() << "test filter " << f->id().name() << " on " << img->colorSpace()->id().name() << endl; + for (TQ_UINT32 i = 0; i < testCount; ++i) { + f->enableProgress(); + f->process(l.data(), l.data(), f->configuration(f->createConfigurationWidget(m_view, l.data())), TQRect(0, 0, 1000, 1000)); + f->disableProgress(); + } + report = report.append(TQString(" filtered " + (*it).name() + "1000 x 1000 pixels %1 times: %2\n").arg(testCount).arg(t.elapsed())); + + } + + } + return report; + +} + +TQString PerfTest::readBytesTest(TQ_UINT32 testCount) +{ + TQString report = TQString("* Read bytes test\n\n"); + + // On default tiles + KisDoc * doc = m_view->canvasSubject()->document(); + KisImageSP img = doc->newImage("Readbytes ", 1000, 1000, KisMetaRegistry::instance()->csRegistry()->getColorSpace(KisID("RGBA",""),"")); + KisPaintDeviceSP l = img->activeDevice(); + + TQTime t; + t.restart(); + + for (TQ_UINT32 i = 0; i < testCount; ++i) { + TQ_UINT8 * newData = new TQ_UINT8[1000 * 1000 * l->pixelSize()]; + TQ_CHECK_PTR(newData); + l->readBytes(newData, 0, 0, 1000, 1000); + delete[] newData; + } + + report = report.append(TQString(" read 1000 x 1000 pixels %1 times from empty image: %2\n").arg(testCount).arg(t.elapsed())); + + // On tiles with data + + KisFillPainter p(l.data()); + p.fillRect(0, 0, 1000, 1000, KisColor(TQt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8())); + p.end(); + + t.restart(); + + for (TQ_UINT32 i = 0; i < testCount; ++i) { + TQ_UINT8 * newData = new TQ_UINT8[1000 * 1000 * l->pixelSize()]; + TQ_CHECK_PTR(newData); + l->readBytes(newData, 0, 0, 1000, 1000); + delete[] newData; + } + + report = report.append(TQString(" read 1000 x 1000 pixels %1 times from filled image: %2\n").arg(testCount).arg(t.elapsed())); + + return report; +} + + +TQString PerfTest::writeBytesTest(TQ_UINT32 testCount) +{ + TQString report = TQString("* Write bytes test"); + + // On default tiles + KisDoc * doc = m_view->canvasSubject()->document(); + KisImageSP img = doc->newImage("Writebytes ", 1000, 1000, KisMetaRegistry::instance()->csRegistry()->getColorSpace(KisID("RGBA", ""),"")); + KisPaintDeviceSP l = img->activeDevice(); + KisFillPainter p(l.data()); + p.fillRect(0, 0, 1000, 1000, KisColor(TQt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8())); + p.end(); + + + TQ_UINT8 * data = new TQ_UINT8[1000 * 1000 * l->pixelSize()]; + TQ_CHECK_PTR(data); + l->readBytes(data, 0, 0, 1000, 1000); + + TQTime t; + t.restart(); + for (TQ_UINT32 i = 0; i < testCount; ++i) { + l->writeBytes(data, 0, 0, 1000, 1000); + } + delete[] data; + report = report.append(TQString(" written 1000 x 1000 pixels %1 times: %2\n").arg(testCount).arg(t.elapsed())); + return report; + + +} + +/////// Iterator tests + + +TQString hlineRODefault(KisDoc * doc, TQ_UINT32 testCount) +{ + KisImageSP img = doc->newImage("", 1000, 1000, KisMetaRegistry::instance()->csRegistry()->getColorSpace(KisID("RGBA", ""),"")); + KisPaintDeviceSP l = img->activeDevice(); + + TQTime t; + t.restart(); + + + for (TQ_UINT32 i = 0; i < testCount; ++i) { + int adv; + + for(TQ_INT32 y2 = 0; y2 < 0 + 1000; y2++) + { + KisHLineIterator hiter = l->createHLineIterator(0, y2, 1000, false); + while(! hiter.isDone()) + { + adv = hiter.nConseqHPixels(); + hiter += adv; + } + } + + } + + return TQString(" hline iterated read-only 1000 x 1000 pixels %1 times over default tile: %2\n").arg(testCount).arg(t.elapsed()); + + +} + +TQString hlineRO(KisDoc * doc, TQ_UINT32 testCount) +{ + KisImageSP img = doc->newImage("", 1000, 1000, KisMetaRegistry::instance()->csRegistry()->getColorSpace(KisID("RGBA", ""),"")); + KisPaintDeviceSP l = img->activeDevice(); + + KisFillPainter p(l.data()); + p.fillRect(0, 0, 1000, 1000, KisColor(TQt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8())); + p.end(); + + TQTime t; + t.restart(); + + for (TQ_UINT32 i = 0; i < testCount; ++i) { + int adv; + + for(TQ_INT32 y2 = 0; y2 < 0 + 1000; y2++) + { + KisHLineIterator hiter = l->createHLineIterator(0, y2, 1000, false); + while(! hiter.isDone()) + { + adv = hiter.nConseqHPixels(); + hiter += adv; + } + } + + } + + return TQString(" hline iterated read-only 1000 x 1000 pixels %1 times over existing tile: %2\n").arg(testCount).arg(t.elapsed()); + +} + +TQString hlineWRDefault(KisDoc * doc, TQ_UINT32 testCount) +{ + KisImageSP img = doc->newImage("", 1000, 1000, KisMetaRegistry::instance()->csRegistry()->getColorSpace(KisID("RGBA", ""),"")); + KisPaintDeviceSP l = img->activeDevice(); + + TQTime t; + t.restart(); + + for (TQ_UINT32 i = 0; i < testCount; ++i) { + int adv; + + for(TQ_INT32 y2 = 0; y2 < 0 + 1000; y2++) + { + KisHLineIterator hiter = l->createHLineIterator(0, y2, 1000, true); + while(! hiter.isDone()) + { + adv = hiter.nConseqHPixels(); + hiter += adv; + } + } + + } + + return TQString(" hline iterated writable 1000 x 1000 pixels %1 times over default tile: %2\n").arg(testCount).arg(t.elapsed()); + +} + +TQString hlineWR(KisDoc * doc, TQ_UINT32 testCount) +{ + KisImageSP img = doc->newImage("", 1000, 1000, KisMetaRegistry::instance()->csRegistry()->getColorSpace(KisID("RGBA", ""),"")); + KisPaintDeviceSP l = img->activeDevice(); + + KisFillPainter p(l.data()); + p.fillRect(0, 0, 1000, 1000, KisColor(TQt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8())); + p.end(); + + + TQTime t; + t.restart(); + + for (TQ_UINT32 i = 0; i < testCount; ++i) { + int adv; + for(TQ_INT32 y2 = 0; y2 < 0 + 1000; y2++) + { + KisHLineIterator hiter = l->createHLineIterator(0, y2, 1000, true); + while(! hiter.isDone()) + { + adv = hiter.nConseqHPixels(); + hiter += adv; + } + } + + } + + return TQString(" hline iterated writable 1000 x 1000 pixels %1 times over existing tile: %2\n").arg(testCount).arg(t.elapsed()); + +} + + +TQString vlineRODefault(KisDoc * doc, TQ_UINT32 testCount) +{ + KisImageSP img = doc->newImage("", 1000, 1000, KisMetaRegistry::instance()->csRegistry()->getColorSpace(KisID("RGBA", ""),"")); + KisPaintDeviceSP l = img->activeDevice(); + + TQTime t; + t.restart(); + + for (TQ_UINT32 i = 0; i < testCount; ++i) { + for(TQ_INT32 y2 = 0; y2 < 0 + 1000; y2++) + { + KisVLineIterator hiter = l->createVLineIterator(y2, 0, 1000, true); + while(! hiter.isDone()) + { + ++hiter; + } + } + + } + + return TQString(" vline iterated read-only 1000 x 1000 pixels %1 times over default tile: %2\n").arg(testCount).arg(t.elapsed()); + +} + +TQString vlineRO(KisDoc * doc, TQ_UINT32 testCount) +{ + KisImageSP img = doc->newImage("", 1000, 1000, KisMetaRegistry::instance()->csRegistry()->getColorSpace(KisID("RGBA", ""),"")); + KisPaintDeviceSP l = img->activeDevice(); + + KisFillPainter p(l.data()); + p.fillRect(0, 0, 1000, 1000, KisColor(TQt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8())); + p.end(); + + + TQTime t; + t.restart(); + + for (TQ_UINT32 i = 0; i < testCount; ++i) { + for(TQ_INT32 y2 = 0; y2 < 0 + 1000; y2++) + { + KisVLineIterator hiter = l->createVLineIterator(y2, 0, 1000, true); + while(! hiter.isDone()) + { + ++hiter; + } + } + + } + + return TQString(" vline iterated read-only 1000 x 1000 pixels %1 times over existing tile: %2\n").arg(testCount).arg(t.elapsed()); + +} + +TQString vlineWRDefault(KisDoc * doc, TQ_UINT32 testCount) +{ + KisImageSP img = doc->newImage("", 1000, 1000, KisMetaRegistry::instance()->csRegistry()->getColorSpace(KisID("RGBA", ""),"")); + KisPaintDeviceSP l = img->activeDevice(); + + TQTime t; + t.restart(); + + for (TQ_UINT32 i = 0; i < testCount; ++i) { + + for(TQ_INT32 y2 = 0; y2 < 0 + 1000; y2++) + { + KisVLineIterator hiter = l->createVLineIterator(y2, 0, 1000, true); + while(! hiter.isDone()) + { + ++hiter; + } + } + + } + + return TQString(" vline iterated writable 1000 x 1000 pixels %1 times over default tile: %2\n").arg(testCount).arg(t.elapsed()); +} + +TQString vlineWR(KisDoc * doc, TQ_UINT32 testCount) +{ + + KisImageSP img = doc->newImage("", 1000, 1000, KisMetaRegistry::instance()->csRegistry()->getColorSpace(KisID("RGBA", ""),"")); + KisPaintDeviceSP l = img->activeDevice(); + + KisFillPainter p(l.data()); + p.fillRect(0, 0, 1000, 1000, KisColor(TQt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8())); + p.end(); + + TQTime t; + t.restart(); + + for (TQ_UINT32 i = 0; i < testCount; ++i) { + for(TQ_INT32 y2 = 0; y2 < 0 + 1000; y2++) + { + KisHLineIterator hiter = l->createHLineIterator(y2, 0, 1000, true); + while(! hiter.isDone()) + { + ++hiter; + } + } + + } + + return TQString(" vline iterated writable 1000 x 1000 pixels %1 times over existing tile: %2\n").arg(testCount).arg(t.elapsed()); + +} + +TQString rectRODefault(KisDoc * doc, TQ_UINT32 testCount) +{ + KisImageSP img = doc->newImage("", 1000, 1000, KisMetaRegistry::instance()->csRegistry()->getColorSpace(KisID("RGBA", ""),"")); + KisPaintDeviceSP l = img->activeDevice(); +; + TQTime t; + t.restart(); + + for (TQ_UINT32 i = 0; i < testCount; ++i) { + KisRectIterator r = l->createRectIterator(0, 0, 1000, 1000, false); + while(! r.isDone()) + { + ++r; + } + } + + return TQString(" rect iterated read-only 1000 x 1000 pixels %1 times over default tile: %2\n").arg(testCount).arg(t.elapsed()); + + +} + +TQString rectRO(KisDoc * doc, TQ_UINT32 testCount) +{ + KisImageSP img = doc->newImage("", 1000, 1000, KisMetaRegistry::instance()->csRegistry()->getColorSpace(KisID("RGBA", ""),"")); + KisPaintDeviceSP l = img->activeDevice(); + + KisFillPainter p(l.data()); + p.fillRect(0, 0, 1000, 1000, KisColor(TQt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8())); + p.end(); + + TQTime t; + t.restart(); + + for (TQ_UINT32 i = 0; i < testCount; ++i) { + KisRectIterator r = l->createRectIterator(0, 0, 1000, 1000, false); + while(! r.isDone()) + { + ++r; + } + } + + return TQString(" rect iterated read-only 1000 x 1000 pixels %1 times over existing tile: %2\n").arg(testCount).arg(t.elapsed()); + +} + +TQString rectWRDefault(KisDoc * doc, TQ_UINT32 testCount) +{ + + + KisImageSP img = doc->newImage("", 1000, 1000, KisMetaRegistry::instance()->csRegistry()->getColorSpace(KisID("RGBA", ""),"")); + KisPaintDeviceSP l = img->activeDevice(); + + TQTime t; + t.restart(); + + for (TQ_UINT32 i = 0; i < testCount; ++i) { + KisRectIterator r = l->createRectIterator(0, 0, 1000, 1000, true); + while(! r.isDone()) + { + ++r; + } + } + + return TQString(" rect iterated writable 1000 x 1000 pixels %1 times over default tile: %2\n").arg(testCount).arg(t.elapsed()); + +} + +TQString rectWR(KisDoc * doc, TQ_UINT32 testCount) +{ + KisImageSP img = doc->newImage("", 1000, 1000, KisMetaRegistry::instance()->csRegistry()->getColorSpace(KisID("RGBA", ""),"")); + KisPaintDeviceSP l = img->activeDevice(); + + KisFillPainter p(l.data()); + p.fillRect(0, 0, 1000, 1000, KisColor(TQt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8())); + p.end(); + + + TQTime t; + t.restart(); + + + for (TQ_UINT32 i = 0; i < testCount; ++i) { + KisRectIterator r = l->createRectIterator(0, 0, 1000, 1000, true); + while(! r.isDone()) + { + ++r; + } + } + + + return TQString(" rect iterated writable 1000 x 1000 pixels %1 times over existing tile: %2\n").arg(testCount).arg(t.elapsed()); + + +} +TQString PerfTest::iteratorTest(TQ_UINT32 testCount) +{ + TQString report = "Iterator test"; + + KisDoc * doc = m_view->canvasSubject()->document(); + + report = report.append(hlineRODefault(doc, testCount)); + report = report.append(hlineRO(doc, testCount)); + report = report.append(hlineWRDefault(doc, testCount)); + report = report.append(hlineWR(doc, testCount)); + + report = report.append(vlineRODefault(doc, testCount)); + report = report.append(vlineRO(doc, testCount)); + report = report.append(vlineWRDefault(doc, testCount)); + report = report.append(vlineWR(doc, testCount)); + + report = report.append(rectRODefault(doc, testCount)); + report = report.append(rectRO(doc, testCount)); + report = report.append(rectWRDefault(doc, testCount)); + report = report.append(rectWR(doc, testCount)); + + return report; + + +} + +TQString PerfTest::paintViewTest(TQ_UINT32 testCount) +{ + TQString report = TQString("* paintView test\n\n"); + + KisDoc * doc = m_view->canvasSubject()->document(); + + KisImageSP img = doc->currentImage(); + img->resize(512,512); + + + KisPaintDeviceSP l = img->activeDevice(); + + KisFillPainter p(l.data()); + p.fillRect(0, 0, 512, 512, KisColor(TQt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8())); + p.end(); + + TQTime t; + t.restart(); + +#if USE_CALLGRIND + CALLGRIND_ZERO_STATS(); +#endif + + for (TQ_UINT32 i = 0; i < testCount; ++i) { + m_view->getCanvasController()->updateCanvas(TQRect(0, 0, 512, 512)); + } + +#if USE_CALLGRIND + CALLGRIND_DUMP_STATS(); +#endif + + report = report.append(TQString(" painted a 512 x 512 image %1 times: %2 ms\n").arg(testCount).arg(t.elapsed())); + + img->newLayer("layer 2", OPACITY_OPAQUE); + l = img->activeDevice(); + + p.begin(l.data()); + p.fillRect(0, 0, 512, 512, KisColor(TQt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8())); + p.end(); + + img->newLayer("layer 3", OPACITY_OPAQUE); + l = img->activeDevice(); + + p.begin(l.data()); + p.fillRect(0, 0, 512, 512, KisColor(TQt::black, KisMetaRegistry::instance()->csRegistry()->getRGB8())); + p.end(); + + t.restart(); + + for (TQ_UINT32 i = 0; i < testCount; ++i) { + m_view->getCanvasController()->updateCanvas(TQRect(0, 0, 512, 512)); + } + + report = report.append(TQString(" painted a 512 x 512 image with 3 layers %1 times: %2 ms\n").arg(testCount).arg(t.elapsed())); + + return report; +} + +TQString PerfTest::paintViewFPSTest() +{ + TQString report = TQString("* paintView (fps) test\n\n"); + + TQTime t; + t.restart(); + +#if USE_CALLGRIND + CALLGRIND_ZERO_STATS(); +#endif + + int numViewsPainted = 0; + const int millisecondsPerSecond = 1000; + + while (t.elapsed() < millisecondsPerSecond) { + m_view->getCanvasController()->updateCanvas(); + numViewsPainted++; + } + +#if USE_CALLGRIND + CALLGRIND_DUMP_STATS(); +#endif + + report = report.append(TQString(" painted current view at %1 frames per second\n").arg(numViewsPainted)); + + return report; +} + +#include "perftest.moc" diff --git a/chalk/plugins/viewplugins/rotateimage/Makefile.am b/chalk/plugins/viewplugins/rotateimage/Makefile.am index 757682e4d..bccf04096 100644 --- a/chalk/plugins/viewplugins/rotateimage/Makefile.am +++ b/chalk/plugins/viewplugins/rotateimage/Makefile.am @@ -13,7 +13,7 @@ INCLUDES = -I$(srcdir)/../../../sdk \ kde_module_LTLIBRARIES = chalkrotateimage.la -chalkrotateimage_la_SOURCES = wdg_rotateimage.ui rotateimage.cc dlg_rotateimage.cc +chalkrotateimage_la_SOURCES = wdg_rotateimage.ui rotateimage.cpp dlg_rotateimage.cpp noinst_HEADERS = wdg_rotateimage.h dlg_rotateimage.h rotateimage.h chalkrotateimage_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) $(LIB_TQT) -ltdecore -ltdeui -lkjs -ltdefx -ltdeio -ltdeparts diff --git a/chalk/plugins/viewplugins/rotateimage/dlg_rotateimage.cc b/chalk/plugins/viewplugins/rotateimage/dlg_rotateimage.cc deleted file mode 100644 index 84c11ffb5..000000000 --- a/chalk/plugins/viewplugins/rotateimage/dlg_rotateimage.cc +++ /dev/null @@ -1,147 +0,0 @@ -/* - * dlg_rotateimage.cc - part of KimageShop^WKrayon^WChalk - * - * Copyright (c) 2004 Michael Thaler - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include - -#include - -#include - -using namespace std; - -#include -#include -#include -#include - -#include -#include -#include - -#include "dlg_rotateimage.h" -#include "wdg_rotateimage.h" - - -DlgRotateImage::DlgRotateImage( TQWidget * parent, - const char * name) - : super (parent, name, true, i18n("Rotate Image"), Ok | Cancel, Ok) -{ - m_lock = false; - - m_page = new WdgRotateImage(this, "rotate_image"); - TQ_CHECK_PTR(m_page); - - setMainWidget(m_page); - resize(m_page->sizeHint()); - - connect(this, TQT_SIGNAL(okClicked()), - this, TQT_SLOT(okClicked())); - connect( m_page->doubleCustom, TQT_SIGNAL( valueChanged ( double ) ), - this, TQT_SLOT( slotAngleValueChanged( double ) ) ); - -} - -DlgRotateImage::~DlgRotateImage() -{ - delete m_page; -} - -void DlgRotateImage::slotAngleValueChanged( double ) -{ - m_page->radioCustom->setChecked(true); -} - -void DlgRotateImage::setAngle(double angle) -{ - if (angle == 90) { - m_page->radio90->setChecked(true); - } - else if (angle == 180) { - m_page->radio180->setChecked(true); - } - else if (angle == 270) { - m_page->radio270->setChecked(true); - } - else { - m_page->radioCustom->setChecked(true); - m_page->doubleCustom->setValue(angle); - } - - if (m_oldAngle != angle) - resetPreview(); - - m_oldAngle = angle; - -} - -double DlgRotateImage::angle() -{ - double angle = 0; - if (m_page->radio90->isChecked()) { - angle = 90; - } - else if (m_page->radio180->isChecked()) { - angle = 180; - } - else if (m_page->radio270->isChecked()) { - angle = 270; - } - else { - angle = tqRound(m_page->doubleCustom->value()); - } - if (m_page->radioCW->isChecked()) { - return angle; - } - else { - return -angle; - } -} - -void DlgRotateImage::setDirection (enumRotationDirection direction) -{ - if (direction == CLOCKWISE) { - m_page->radioCW->setChecked(true); - } - else if (direction== COUNTERCLOCKWISE) { - m_page->radioCCW->setChecked(true); - } -} - -enumRotationDirection DlgRotateImage::direction() -{ - if (m_page->radioCCW->isChecked()) { - return COUNTERCLOCKWISE; - } - else { - return CLOCKWISE; - } -} - -void DlgRotateImage::okClicked() -{ - accept(); -} - -void DlgRotateImage::resetPreview() -{ - // Code to update preview here. -} - -#include "dlg_rotateimage.moc" diff --git a/chalk/plugins/viewplugins/rotateimage/dlg_rotateimage.cpp b/chalk/plugins/viewplugins/rotateimage/dlg_rotateimage.cpp new file mode 100644 index 000000000..e7c3a8ce9 --- /dev/null +++ b/chalk/plugins/viewplugins/rotateimage/dlg_rotateimage.cpp @@ -0,0 +1,147 @@ +/* + * dlg_rotateimage.cpp - part of KimageShop^WKrayon^WChalk + * + * Copyright (c) 2004 Michael Thaler + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include + +#include + +#include + +using namespace std; + +#include +#include +#include +#include + +#include +#include +#include + +#include "dlg_rotateimage.h" +#include "wdg_rotateimage.h" + + +DlgRotateImage::DlgRotateImage( TQWidget * parent, + const char * name) + : super (parent, name, true, i18n("Rotate Image"), Ok | Cancel, Ok) +{ + m_lock = false; + + m_page = new WdgRotateImage(this, "rotate_image"); + TQ_CHECK_PTR(m_page); + + setMainWidget(m_page); + resize(m_page->sizeHint()); + + connect(this, TQT_SIGNAL(okClicked()), + this, TQT_SLOT(okClicked())); + connect( m_page->doubleCustom, TQT_SIGNAL( valueChanged ( double ) ), + this, TQT_SLOT( slotAngleValueChanged( double ) ) ); + +} + +DlgRotateImage::~DlgRotateImage() +{ + delete m_page; +} + +void DlgRotateImage::slotAngleValueChanged( double ) +{ + m_page->radioCustom->setChecked(true); +} + +void DlgRotateImage::setAngle(double angle) +{ + if (angle == 90) { + m_page->radio90->setChecked(true); + } + else if (angle == 180) { + m_page->radio180->setChecked(true); + } + else if (angle == 270) { + m_page->radio270->setChecked(true); + } + else { + m_page->radioCustom->setChecked(true); + m_page->doubleCustom->setValue(angle); + } + + if (m_oldAngle != angle) + resetPreview(); + + m_oldAngle = angle; + +} + +double DlgRotateImage::angle() +{ + double angle = 0; + if (m_page->radio90->isChecked()) { + angle = 90; + } + else if (m_page->radio180->isChecked()) { + angle = 180; + } + else if (m_page->radio270->isChecked()) { + angle = 270; + } + else { + angle = tqRound(m_page->doubleCustom->value()); + } + if (m_page->radioCW->isChecked()) { + return angle; + } + else { + return -angle; + } +} + +void DlgRotateImage::setDirection (enumRotationDirection direction) +{ + if (direction == CLOCKWISE) { + m_page->radioCW->setChecked(true); + } + else if (direction== COUNTERCLOCKWISE) { + m_page->radioCCW->setChecked(true); + } +} + +enumRotationDirection DlgRotateImage::direction() +{ + if (m_page->radioCCW->isChecked()) { + return COUNTERCLOCKWISE; + } + else { + return CLOCKWISE; + } +} + +void DlgRotateImage::okClicked() +{ + accept(); +} + +void DlgRotateImage::resetPreview() +{ + // Code to update preview here. +} + +#include "dlg_rotateimage.moc" diff --git a/chalk/plugins/viewplugins/rotateimage/rotateimage.cc b/chalk/plugins/viewplugins/rotateimage/rotateimage.cc deleted file mode 100644 index 8a0985cc3..000000000 --- a/chalk/plugins/viewplugins/rotateimage/rotateimage.cc +++ /dev/null @@ -1,134 +0,0 @@ -/* - * rotateimage.cc -- Part of Chalk - * - * Copyright (c) 2004 Michael Thaler - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - - -#include - -#include - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "rotateimage.h" -#include "dlg_rotateimage.h" - -typedef KGenericFactory RotateImageFactory; -K_EXPORT_COMPONENT_FACTORY( chalkrotateimage, RotateImageFactory( "chalk" ) ) - -// XXX: this plugin could also provide layer scaling/resizing -RotateImage::RotateImage(TQObject *parent, const char *name, const TQStringList &) - : KParts::Plugin(parent, name) -{ - - if ( parent->inherits("KisView") ) { - setInstance(RotateImageFactory::instance()); - setXMLFile(locate("data","chalkplugins/rotateimage.rc"), true); - m_view = (KisView*) parent; - (void) new TDEAction(i18n("&Rotate Image..."), 0, 0, TQT_TQOBJECT(this), TQT_SLOT(slotRotateImage()), actionCollection(), "rotateimage"); - (void) new TDEAction(i18n("Rotate Image CW"), "object-rotate-right", 0, TQT_TQOBJECT(this), TQT_SLOT(slotRotateImage90()), actionCollection(), "rotateImageCW90"); - (void) new TDEAction(i18n("Rotate Image 1&80"), 0, 0, TQT_TQOBJECT(this), TQT_SLOT(slotRotateImage180()), actionCollection(), "rotateImage180"); - (void) new TDEAction(i18n("Rotate Image CCW"), "object-rotate-left", 0, TQT_TQOBJECT(this), TQT_SLOT(slotRotateImage270()), actionCollection(), "rotateImageCCW90"); - - (void) new TDEAction(i18n("&Rotate Layer..."), 0, 0, TQT_TQOBJECT(this), TQT_SLOT(slotRotateLayer()), actionCollection(), "rotatelayer"); - - (void)new TDEAction(i18n("Rotate 1&80"), 0, TQT_TQOBJECT(m_view), TQT_SLOT(rotateLayer180()), actionCollection(), "rotateLayer180"); - (void)new TDEAction(i18n("Rotate CCW"), "object-rotate-left", 0, TQT_TQOBJECT(m_view), TQT_SLOT(rotateLayerLeft90()), actionCollection(), "rotateLayerCCW90"); - (void)new TDEAction(i18n("Rotate CW"), "object-rotate-right", 0, TQT_TQOBJECT(m_view), TQT_SLOT(rotateLayerRight90()), actionCollection(), "rotateLayerCW90"); - } -} - -RotateImage::~RotateImage() -{ - m_view = 0; -} - -void RotateImage::slotRotateImage() -{ - KisImageSP image = m_view->canvasSubject()->currentImg(); - - if (!image) return; - - DlgRotateImage * dlgRotateImage = new DlgRotateImage(m_view, "RotateImage"); - TQ_CHECK_PTR(dlgRotateImage); - - dlgRotateImage->setCaption(i18n("Rotate Image")); - - if (dlgRotateImage->exec() == TQDialog::Accepted) { - double angle = dlgRotateImage->angle(); - angle *= M_PI/180; - m_view->rotateCurrentImage(angle); - } - delete dlgRotateImage; -} - -void RotateImage::slotRotateImage90() -{ - m_view->rotateCurrentImage( M_PI/2); -} - -void RotateImage::slotRotateImage180() -{ - m_view->rotateCurrentImage( M_PI ); -} - - -void RotateImage::slotRotateImage270() -{ - m_view->rotateCurrentImage( - M_PI/2 + M_PI*2 ); -} - -void RotateImage::slotRotateLayer() -{ - KisImageSP image = m_view->canvasSubject()->currentImg(); - - if (!image) return; - - DlgRotateImage * dlgRotateImage = new DlgRotateImage(m_view, "RotateLayer"); - TQ_CHECK_PTR(dlgRotateImage); - - dlgRotateImage->setCaption(i18n("Rotate Layer")); - - if (dlgRotateImage->exec() == TQDialog::Accepted) { - double angle = dlgRotateImage->angle(); - angle *= M_PI/180; - m_view->rotateLayer(angle); - } - delete dlgRotateImage; -} - -#include "rotateimage.moc" diff --git a/chalk/plugins/viewplugins/rotateimage/rotateimage.cpp b/chalk/plugins/viewplugins/rotateimage/rotateimage.cpp new file mode 100644 index 000000000..f58f78168 --- /dev/null +++ b/chalk/plugins/viewplugins/rotateimage/rotateimage.cpp @@ -0,0 +1,134 @@ +/* + * rotateimage.cpp -- Part of Chalk + * + * Copyright (c) 2004 Michael Thaler + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + + +#include + +#include + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "rotateimage.h" +#include "dlg_rotateimage.h" + +typedef KGenericFactory RotateImageFactory; +K_EXPORT_COMPONENT_FACTORY( chalkrotateimage, RotateImageFactory( "chalk" ) ) + +// XXX: this plugin could also provide layer scaling/resizing +RotateImage::RotateImage(TQObject *parent, const char *name, const TQStringList &) + : KParts::Plugin(parent, name) +{ + + if ( parent->inherits("KisView") ) { + setInstance(RotateImageFactory::instance()); + setXMLFile(locate("data","chalkplugins/rotateimage.rc"), true); + m_view = (KisView*) parent; + (void) new TDEAction(i18n("&Rotate Image..."), 0, 0, TQT_TQOBJECT(this), TQT_SLOT(slotRotateImage()), actionCollection(), "rotateimage"); + (void) new TDEAction(i18n("Rotate Image CW"), "object-rotate-right", 0, TQT_TQOBJECT(this), TQT_SLOT(slotRotateImage90()), actionCollection(), "rotateImageCW90"); + (void) new TDEAction(i18n("Rotate Image 1&80"), 0, 0, TQT_TQOBJECT(this), TQT_SLOT(slotRotateImage180()), actionCollection(), "rotateImage180"); + (void) new TDEAction(i18n("Rotate Image CCW"), "object-rotate-left", 0, TQT_TQOBJECT(this), TQT_SLOT(slotRotateImage270()), actionCollection(), "rotateImageCCW90"); + + (void) new TDEAction(i18n("&Rotate Layer..."), 0, 0, TQT_TQOBJECT(this), TQT_SLOT(slotRotateLayer()), actionCollection(), "rotatelayer"); + + (void)new TDEAction(i18n("Rotate 1&80"), 0, TQT_TQOBJECT(m_view), TQT_SLOT(rotateLayer180()), actionCollection(), "rotateLayer180"); + (void)new TDEAction(i18n("Rotate CCW"), "object-rotate-left", 0, TQT_TQOBJECT(m_view), TQT_SLOT(rotateLayerLeft90()), actionCollection(), "rotateLayerCCW90"); + (void)new TDEAction(i18n("Rotate CW"), "object-rotate-right", 0, TQT_TQOBJECT(m_view), TQT_SLOT(rotateLayerRight90()), actionCollection(), "rotateLayerCW90"); + } +} + +RotateImage::~RotateImage() +{ + m_view = 0; +} + +void RotateImage::slotRotateImage() +{ + KisImageSP image = m_view->canvasSubject()->currentImg(); + + if (!image) return; + + DlgRotateImage * dlgRotateImage = new DlgRotateImage(m_view, "RotateImage"); + TQ_CHECK_PTR(dlgRotateImage); + + dlgRotateImage->setCaption(i18n("Rotate Image")); + + if (dlgRotateImage->exec() == TQDialog::Accepted) { + double angle = dlgRotateImage->angle(); + angle *= M_PI/180; + m_view->rotateCurrentImage(angle); + } + delete dlgRotateImage; +} + +void RotateImage::slotRotateImage90() +{ + m_view->rotateCurrentImage( M_PI/2); +} + +void RotateImage::slotRotateImage180() +{ + m_view->rotateCurrentImage( M_PI ); +} + + +void RotateImage::slotRotateImage270() +{ + m_view->rotateCurrentImage( - M_PI/2 + M_PI*2 ); +} + +void RotateImage::slotRotateLayer() +{ + KisImageSP image = m_view->canvasSubject()->currentImg(); + + if (!image) return; + + DlgRotateImage * dlgRotateImage = new DlgRotateImage(m_view, "RotateLayer"); + TQ_CHECK_PTR(dlgRotateImage); + + dlgRotateImage->setCaption(i18n("Rotate Layer")); + + if (dlgRotateImage->exec() == TQDialog::Accepted) { + double angle = dlgRotateImage->angle(); + angle *= M_PI/180; + m_view->rotateLayer(angle); + } + delete dlgRotateImage; +} + +#include "rotateimage.moc" diff --git a/chalk/plugins/viewplugins/scripting/Makefile.am b/chalk/plugins/viewplugins/scripting/Makefile.am index 1f0c431d4..2b4270197 100644 --- a/chalk/plugins/viewplugins/scripting/Makefile.am +++ b/chalk/plugins/viewplugins/scripting/Makefile.am @@ -15,7 +15,7 @@ INCLUDES = -I$(top_srcdir)/chalk/sdk \ $(KOFFICE_INCLUDES) \ $(all_includes) -chalkscripting_la_SOURCES = scripting.cc +chalkscripting_la_SOURCES = scripting.cpp kde_module_LTLIBRARIES = chalkscripting.la noinst_HEADERS = scripting.h diff --git a/chalk/plugins/viewplugins/scripting/scripting.cc b/chalk/plugins/viewplugins/scripting/scripting.cpp similarity index 100% rename from chalk/plugins/viewplugins/scripting/scripting.cc rename to chalk/plugins/viewplugins/scripting/scripting.cpp diff --git a/chalk/plugins/viewplugins/selectopaque/Makefile.am b/chalk/plugins/viewplugins/selectopaque/Makefile.am index 7814c7afd..dab67d5ec 100644 --- a/chalk/plugins/viewplugins/selectopaque/Makefile.am +++ b/chalk/plugins/viewplugins/selectopaque/Makefile.am @@ -7,7 +7,7 @@ INCLUDES = -I$(srcdir)/../../../sdk \ kde_module_LTLIBRARIES = chalkselectopaque.la -chalkselectopaque_la_SOURCES = selectopaque.cc +chalkselectopaque_la_SOURCES = selectopaque.cpp noinst_HEADERS = selectopaque.h chalkselectopaque_la_LIBADD = $(LIB_KOFFICEUI) ../../../libchalkcommon.la \ diff --git a/chalk/plugins/viewplugins/selectopaque/selectopaque.cc b/chalk/plugins/viewplugins/selectopaque/selectopaque.cpp similarity index 100% rename from chalk/plugins/viewplugins/selectopaque/selectopaque.cc rename to chalk/plugins/viewplugins/selectopaque/selectopaque.cpp diff --git a/chalk/plugins/viewplugins/separate_channels/Makefile.am b/chalk/plugins/viewplugins/separate_channels/Makefile.am index d6a2fa77e..03117232e 100644 --- a/chalk/plugins/viewplugins/separate_channels/Makefile.am +++ b/chalk/plugins/viewplugins/separate_channels/Makefile.am @@ -12,8 +12,8 @@ INCLUDES = -I$(srcdir)/../../../sdk \ kde_module_LTLIBRARIES = chalkseparatechannels.la chalkseparatechannels_la_SOURCES = wdg_separations.ui \ - kis_channel_separator.cc dlg_separate.cc \ - kis_separate_channels_plugin.cc + kis_channel_separator.cpp dlg_separate.cpp \ + kis_separate_channels_plugin.cpp noinst_HEADERS = wdg_separations.h kis_separate_channels_plugin.h \ kis_channel_separator.h dlg_separate.h diff --git a/chalk/plugins/viewplugins/separate_channels/dlg_separate.cc b/chalk/plugins/viewplugins/separate_channels/dlg_separate.cc deleted file mode 100644 index 6d2a59c32..000000000 --- a/chalk/plugins/viewplugins/separate_channels/dlg_separate.cc +++ /dev/null @@ -1,110 +0,0 @@ -/* - * dlg_separate.cc - part of KimageShop^WKrayon^WChalk - * - * Copyright (c) 2004 Boudewijn Rempt - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include "dlg_separate.h" -#include "wdg_separations.h" - -DlgSeparate::DlgSeparate( const TQString & imageCS, - const TQString & layerCS, - TQWidget * parent, - const char * name) - : super (parent, name, true, i18n("Separate Image"), Ok | Cancel, Ok), - m_imageCS(imageCS), - m_layerCS(layerCS) -{ - m_page = new WdgSeparations(this, "separate_image"); - TQ_CHECK_PTR(m_page); - setMainWidget(m_page); - resize(m_page->sizeHint()); - - m_page->lblColormodel->setText(layerCS); - m_page->grpOutput->hide(); - connect(m_page->grpSource, TQT_SIGNAL(clicked(int)), this, TQT_SLOT(slotSetColorSpaceLabel(int))); - connect(m_page->chkColors, TQT_SIGNAL(toggled(bool)), m_page->chkDownscale, TQT_SLOT(setDisabled(bool))); - - connect(this, TQT_SIGNAL(okClicked()), - this, TQT_SLOT(okClicked())); -} - -DlgSeparate::~DlgSeparate() -{ - delete m_page; -} - - - -enumSepAlphaOptions DlgSeparate::getAlphaOptions() -{ - return (enumSepAlphaOptions)m_page->grpAlpha->selectedId(); -} - -enumSepSource DlgSeparate::getSource() -{ - return (enumSepSource)m_page->grpSource->selectedId(); -} - -enumSepOutput DlgSeparate::getOutput() -{ - return (enumSepOutput)m_page->grpOutput->selectedId(); -} - - -bool DlgSeparate::getDownscale() -{ - return m_page->chkDownscale->isChecked(); -} - -bool DlgSeparate::getToColor() -{ - return m_page->chkColors->isChecked(); -} - -// SLOTS - -void DlgSeparate::okClicked() -{ - accept(); -} - -void DlgSeparate::slotSetColorSpaceLabel(int buttonid) -{ - if (buttonid == 0) { - m_page->lblColormodel->setText(m_layerCS); - } - else { - m_page->lblColormodel->setText(m_imageCS); - } -} -void DlgSeparate::enableDownscale(bool enable) { - m_page->chkDownscale->setEnabled(enable); -} - -#include "dlg_separate.moc" diff --git a/chalk/plugins/viewplugins/separate_channels/dlg_separate.cpp b/chalk/plugins/viewplugins/separate_channels/dlg_separate.cpp new file mode 100644 index 000000000..d650a045a --- /dev/null +++ b/chalk/plugins/viewplugins/separate_channels/dlg_separate.cpp @@ -0,0 +1,110 @@ +/* + * dlg_separate.cpp - part of KimageShop^WKrayon^WChalk + * + * Copyright (c) 2004 Boudewijn Rempt + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "dlg_separate.h" +#include "wdg_separations.h" + +DlgSeparate::DlgSeparate( const TQString & imageCS, + const TQString & layerCS, + TQWidget * parent, + const char * name) + : super (parent, name, true, i18n("Separate Image"), Ok | Cancel, Ok), + m_imageCS(imageCS), + m_layerCS(layerCS) +{ + m_page = new WdgSeparations(this, "separate_image"); + TQ_CHECK_PTR(m_page); + setMainWidget(m_page); + resize(m_page->sizeHint()); + + m_page->lblColormodel->setText(layerCS); + m_page->grpOutput->hide(); + connect(m_page->grpSource, TQT_SIGNAL(clicked(int)), this, TQT_SLOT(slotSetColorSpaceLabel(int))); + connect(m_page->chkColors, TQT_SIGNAL(toggled(bool)), m_page->chkDownscale, TQT_SLOT(setDisabled(bool))); + + connect(this, TQT_SIGNAL(okClicked()), + this, TQT_SLOT(okClicked())); +} + +DlgSeparate::~DlgSeparate() +{ + delete m_page; +} + + + +enumSepAlphaOptions DlgSeparate::getAlphaOptions() +{ + return (enumSepAlphaOptions)m_page->grpAlpha->selectedId(); +} + +enumSepSource DlgSeparate::getSource() +{ + return (enumSepSource)m_page->grpSource->selectedId(); +} + +enumSepOutput DlgSeparate::getOutput() +{ + return (enumSepOutput)m_page->grpOutput->selectedId(); +} + + +bool DlgSeparate::getDownscale() +{ + return m_page->chkDownscale->isChecked(); +} + +bool DlgSeparate::getToColor() +{ + return m_page->chkColors->isChecked(); +} + +// SLOTS + +void DlgSeparate::okClicked() +{ + accept(); +} + +void DlgSeparate::slotSetColorSpaceLabel(int buttonid) +{ + if (buttonid == 0) { + m_page->lblColormodel->setText(m_layerCS); + } + else { + m_page->lblColormodel->setText(m_imageCS); + } +} +void DlgSeparate::enableDownscale(bool enable) { + m_page->chkDownscale->setEnabled(enable); +} + +#include "dlg_separate.moc" diff --git a/chalk/plugins/viewplugins/separate_channels/kis_channel_separator.cc b/chalk/plugins/viewplugins/separate_channels/kis_channel_separator.cpp similarity index 100% rename from chalk/plugins/viewplugins/separate_channels/kis_channel_separator.cc rename to chalk/plugins/viewplugins/separate_channels/kis_channel_separator.cpp diff --git a/chalk/plugins/viewplugins/separate_channels/kis_separate_channels_plugin.cc b/chalk/plugins/viewplugins/separate_channels/kis_separate_channels_plugin.cpp similarity index 100% rename from chalk/plugins/viewplugins/separate_channels/kis_separate_channels_plugin.cc rename to chalk/plugins/viewplugins/separate_channels/kis_separate_channels_plugin.cpp diff --git a/chalk/plugins/viewplugins/shearimage/Makefile.am b/chalk/plugins/viewplugins/shearimage/Makefile.am index 7134779c3..b96067895 100644 --- a/chalk/plugins/viewplugins/shearimage/Makefile.am +++ b/chalk/plugins/viewplugins/shearimage/Makefile.am @@ -15,7 +15,7 @@ kde_module_LTLIBRARIES = chalkshearimage.la kde_services_DATA = chalkshearimage.desktop -chalkshearimage_la_SOURCES = wdg_shearimage.ui shearimage.cc dlg_shearimage.cc +chalkshearimage_la_SOURCES = wdg_shearimage.ui shearimage.cpp dlg_shearimage.cpp noinst_HEADERS = wdg_shearimage.h dlg_shearimage.h shearimage.h chalkshearimage_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) $(LIB_TQT) -ltdecore -ltdeui -lkjs -ltdefx -ltdeio -ltdeparts diff --git a/chalk/plugins/viewplugins/shearimage/dlg_shearimage.cc b/chalk/plugins/viewplugins/shearimage/dlg_shearimage.cc deleted file mode 100644 index e7a63180b..000000000 --- a/chalk/plugins/viewplugins/shearimage/dlg_shearimage.cc +++ /dev/null @@ -1,96 +0,0 @@ -/* - * dlg_shearimage.cc - part of KimageShop^WKrayon^WChalk - * - * Copyright (c) 2004 Michael Thaler - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include - -#include - -#include - -using namespace std; - -#include -#include -#include -#include - -#include -#include -#include - -#include "dlg_shearimage.h" -#include "wdg_shearimage.h" - - -DlgShearImage::DlgShearImage( TQWidget * parent, - const char * name) - : super (parent, name, true, i18n("Shear Image"), Ok | Cancel, Ok) -{ - m_lock = false; - - m_page = new WdgShearImage(this, "shear_image"); - m_page->layout()->setMargin(0); - TQ_CHECK_PTR(m_page); - - setMainWidget(m_page); - resize(m_page->sizeHint()); - - connect(this, TQT_SIGNAL(okClicked()), - this, TQT_SLOT(okClicked())); - -} - -DlgShearImage::~DlgShearImage() -{ - delete m_page; -} - -void DlgShearImage::setAngleX(TQ_UINT32 angle) -{ - m_page->shearAngleX->setValue(angle); - m_oldAngle = angle; - -} - -void DlgShearImage::setAngleY(TQ_UINT32 angle) -{ - m_page->shearAngleY->setValue(angle); - m_oldAngle = angle; - -} - -TQ_INT32 DlgShearImage::angleX() -{ - return (TQ_INT32)tqRound(m_page->shearAngleX->value()); -} - -TQ_INT32 DlgShearImage::angleY() -{ - return (TQ_INT32)tqRound(m_page->shearAngleY->value()); -} - -// SLOTS - -void DlgShearImage::okClicked() -{ - accept(); -} - -#include "dlg_shearimage.moc" diff --git a/chalk/plugins/viewplugins/shearimage/dlg_shearimage.cpp b/chalk/plugins/viewplugins/shearimage/dlg_shearimage.cpp new file mode 100644 index 000000000..d295493d0 --- /dev/null +++ b/chalk/plugins/viewplugins/shearimage/dlg_shearimage.cpp @@ -0,0 +1,96 @@ +/* + * dlg_shearimage.cpp - part of KimageShop^WKrayon^WChalk + * + * Copyright (c) 2004 Michael Thaler + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include + +#include + +#include + +using namespace std; + +#include +#include +#include +#include + +#include +#include +#include + +#include "dlg_shearimage.h" +#include "wdg_shearimage.h" + + +DlgShearImage::DlgShearImage( TQWidget * parent, + const char * name) + : super (parent, name, true, i18n("Shear Image"), Ok | Cancel, Ok) +{ + m_lock = false; + + m_page = new WdgShearImage(this, "shear_image"); + m_page->layout()->setMargin(0); + TQ_CHECK_PTR(m_page); + + setMainWidget(m_page); + resize(m_page->sizeHint()); + + connect(this, TQT_SIGNAL(okClicked()), + this, TQT_SLOT(okClicked())); + +} + +DlgShearImage::~DlgShearImage() +{ + delete m_page; +} + +void DlgShearImage::setAngleX(TQ_UINT32 angle) +{ + m_page->shearAngleX->setValue(angle); + m_oldAngle = angle; + +} + +void DlgShearImage::setAngleY(TQ_UINT32 angle) +{ + m_page->shearAngleY->setValue(angle); + m_oldAngle = angle; + +} + +TQ_INT32 DlgShearImage::angleX() +{ + return (TQ_INT32)tqRound(m_page->shearAngleX->value()); +} + +TQ_INT32 DlgShearImage::angleY() +{ + return (TQ_INT32)tqRound(m_page->shearAngleY->value()); +} + +// SLOTS + +void DlgShearImage::okClicked() +{ + accept(); +} + +#include "dlg_shearimage.moc" diff --git a/chalk/plugins/viewplugins/shearimage/shearimage.cc b/chalk/plugins/viewplugins/shearimage/shearimage.cc deleted file mode 100644 index 8e20b58d6..000000000 --- a/chalk/plugins/viewplugins/shearimage/shearimage.cc +++ /dev/null @@ -1,113 +0,0 @@ -/* - * shearimage.cc -- Part of Chalk - * - * Copyright (c) 2004 Michael Thaler - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - - -#include - -#include - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "shearimage.h" -#include "dlg_shearimage.h" - -typedef KGenericFactory ShearImageFactory; -K_EXPORT_COMPONENT_FACTORY( chalkshearimage, ShearImageFactory( "chalk" ) ) - -// XXX: this plugin could also provide layer scaling/resizing -ShearImage::ShearImage(TQObject *parent, const char *name, const TQStringList &) - : KParts::Plugin(parent, name) -{ - if ( parent->inherits("KisView") ) - { - setInstance(ShearImageFactory::instance()); - setXMLFile(locate("data","chalkplugins/shearimage.rc"), true); - - (void) new TDEAction(i18n("&Shear Image..."), 0, 0, this, TQT_SLOT(slotShearImage()), actionCollection(), "shearimage"); - (void) new TDEAction(i18n("&Shear Layer..."), 0, 0, this, TQT_SLOT(slotShearLayer()), actionCollection(), "shearlayer"); - - m_view = (KisView*) parent; - } -} - -ShearImage::~ShearImage() -{ - m_view = 0; -} - -void ShearImage::slotShearImage() -{ - KisImageSP image = m_view->canvasSubject()->currentImg(); - - if (!image) return; - - DlgShearImage * dlgShearImage = new DlgShearImage(m_view, "ShearImage"); - TQ_CHECK_PTR(dlgShearImage); - - dlgShearImage->setCaption(i18n("Shear Image")); - - if (dlgShearImage->exec() == TQDialog::Accepted) { - TQ_INT32 angleX = dlgShearImage->angleX(); - TQ_INT32 angleY = dlgShearImage->angleY(); - m_view->shearCurrentImage(angleX, angleY); - } - delete dlgShearImage; -} - -void ShearImage::slotShearLayer() -{ - KisImageSP image = m_view->canvasSubject()->currentImg(); - - if (!image) return; - - DlgShearImage * dlgShearImage = new DlgShearImage(m_view, "ShearLayer"); - TQ_CHECK_PTR(dlgShearImage); - - dlgShearImage->setCaption(i18n("Shear Layer")); - - if (dlgShearImage->exec() == TQDialog::Accepted) { - TQ_INT32 angleX = dlgShearImage->angleX(); - TQ_INT32 angleY = dlgShearImage->angleY(); - m_view->shearLayer(angleX, angleY); - - } - delete dlgShearImage; -} - -#include "shearimage.moc" diff --git a/chalk/plugins/viewplugins/shearimage/shearimage.cpp b/chalk/plugins/viewplugins/shearimage/shearimage.cpp new file mode 100644 index 000000000..2596e62ee --- /dev/null +++ b/chalk/plugins/viewplugins/shearimage/shearimage.cpp @@ -0,0 +1,113 @@ +/* + * shearimage.cpp -- Part of Chalk + * + * Copyright (c) 2004 Michael Thaler + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + + +#include + +#include + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "shearimage.h" +#include "dlg_shearimage.h" + +typedef KGenericFactory ShearImageFactory; +K_EXPORT_COMPONENT_FACTORY( chalkshearimage, ShearImageFactory( "chalk" ) ) + +// XXX: this plugin could also provide layer scaling/resizing +ShearImage::ShearImage(TQObject *parent, const char *name, const TQStringList &) + : KParts::Plugin(parent, name) +{ + if ( parent->inherits("KisView") ) + { + setInstance(ShearImageFactory::instance()); + setXMLFile(locate("data","chalkplugins/shearimage.rc"), true); + + (void) new TDEAction(i18n("&Shear Image..."), 0, 0, this, TQT_SLOT(slotShearImage()), actionCollection(), "shearimage"); + (void) new TDEAction(i18n("&Shear Layer..."), 0, 0, this, TQT_SLOT(slotShearLayer()), actionCollection(), "shearlayer"); + + m_view = (KisView*) parent; + } +} + +ShearImage::~ShearImage() +{ + m_view = 0; +} + +void ShearImage::slotShearImage() +{ + KisImageSP image = m_view->canvasSubject()->currentImg(); + + if (!image) return; + + DlgShearImage * dlgShearImage = new DlgShearImage(m_view, "ShearImage"); + TQ_CHECK_PTR(dlgShearImage); + + dlgShearImage->setCaption(i18n("Shear Image")); + + if (dlgShearImage->exec() == TQDialog::Accepted) { + TQ_INT32 angleX = dlgShearImage->angleX(); + TQ_INT32 angleY = dlgShearImage->angleY(); + m_view->shearCurrentImage(angleX, angleY); + } + delete dlgShearImage; +} + +void ShearImage::slotShearLayer() +{ + KisImageSP image = m_view->canvasSubject()->currentImg(); + + if (!image) return; + + DlgShearImage * dlgShearImage = new DlgShearImage(m_view, "ShearLayer"); + TQ_CHECK_PTR(dlgShearImage); + + dlgShearImage->setCaption(i18n("Shear Layer")); + + if (dlgShearImage->exec() == TQDialog::Accepted) { + TQ_INT32 angleX = dlgShearImage->angleX(); + TQ_INT32 angleY = dlgShearImage->angleY(); + m_view->shearLayer(angleX, angleY); + + } + delete dlgShearImage; +} + +#include "shearimage.moc" diff --git a/chalk/plugins/viewplugins/substrate/Makefile.am b/chalk/plugins/viewplugins/substrate/Makefile.am index 8c0e6ef6e..c868d28b0 100644 --- a/chalk/plugins/viewplugins/substrate/Makefile.am +++ b/chalk/plugins/viewplugins/substrate/Makefile.am @@ -14,7 +14,7 @@ INCLUDES = -I$(srcdir)/../../../sdk \ kde_module_LTLIBRARIES = chalksubstrate.la -chalksubstrate_la_SOURCES = substrate.cc dlg_substrate.cc wdgsubstrate.ui kis_repeating_substrate.cc +chalksubstrate_la_SOURCES = substrate.cpp dlg_substrate.cpp wdgsubstrate.ui kis_repeating_substrate.cpp noinst_HEADERS = wdgsubstrate.h dlg_substrate.h kis_repeating_substrate.h substrate.h chalksubstrate_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) $(LIB_TQT) -ltdecore -ltdeui -lkjs -ltdefx -ltdeio -ltdeparts diff --git a/chalk/plugins/viewplugins/substrate/dlg_substrate.cc b/chalk/plugins/viewplugins/substrate/dlg_substrate.cc deleted file mode 100644 index a0dbc5aa2..000000000 --- a/chalk/plugins/viewplugins/substrate/dlg_substrate.cc +++ /dev/null @@ -1,59 +0,0 @@ -/* - * dlg_substrate.cc - part of KimageShop^WKrayon^WChalk - * - * Copyright (c) 2004 Boudewijn Rempt - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include - -#include "dlg_substrate.h" -#include "wdgsubstrate.h" - - -DlgSubstrate::DlgSubstrate( TQWidget * parent, - const char * name) - : super (parent, name, true, i18n("Color Range"), Ok | Cancel, Ok) -{ - m_previewPix = TQPixmap(); - m_page = new WdgSubstrate(this, "substrate"); - TQ_CHECK_PTR(m_page); - setCaption(i18n("Substrate")); - setMainWidget(m_page); - resize(m_page -> size()); - - connect(this, TQT_SIGNAL(okClicked()), - this, TQT_SLOT(okClicked())); -} - -DlgSubstrate::~DlgSubstrate() -{ - delete m_page; -} - -void DlgSubstrate::setPixmap(TQPixmap pix) -{ - m_previewPix = pix; - m_previewPix.detach(); -} - -void DlgSubstrate::okClicked() -{ - accept(); -} - -#include "dlg_substrate.moc" - diff --git a/chalk/plugins/viewplugins/substrate/dlg_substrate.cpp b/chalk/plugins/viewplugins/substrate/dlg_substrate.cpp new file mode 100644 index 000000000..78847f056 --- /dev/null +++ b/chalk/plugins/viewplugins/substrate/dlg_substrate.cpp @@ -0,0 +1,59 @@ +/* + * dlg_substrate.cpp - part of KimageShop^WKrayon^WChalk + * + * Copyright (c) 2004 Boudewijn Rempt + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include + +#include "dlg_substrate.h" +#include "wdgsubstrate.h" + + +DlgSubstrate::DlgSubstrate( TQWidget * parent, + const char * name) + : super (parent, name, true, i18n("Color Range"), Ok | Cancel, Ok) +{ + m_previewPix = TQPixmap(); + m_page = new WdgSubstrate(this, "substrate"); + TQ_CHECK_PTR(m_page); + setCaption(i18n("Substrate")); + setMainWidget(m_page); + resize(m_page -> size()); + + connect(this, TQT_SIGNAL(okClicked()), + this, TQT_SLOT(okClicked())); +} + +DlgSubstrate::~DlgSubstrate() +{ + delete m_page; +} + +void DlgSubstrate::setPixmap(TQPixmap pix) +{ + m_previewPix = pix; + m_previewPix.detach(); +} + +void DlgSubstrate::okClicked() +{ + accept(); +} + +#include "dlg_substrate.moc" + diff --git a/chalk/plugins/viewplugins/substrate/kis_repeating_substrate.cc b/chalk/plugins/viewplugins/substrate/kis_repeating_substrate.cpp similarity index 100% rename from chalk/plugins/viewplugins/substrate/kis_repeating_substrate.cc rename to chalk/plugins/viewplugins/substrate/kis_repeating_substrate.cpp diff --git a/chalk/plugins/viewplugins/substrate/substrate.cc b/chalk/plugins/viewplugins/substrate/substrate.cpp similarity index 100% rename from chalk/plugins/viewplugins/substrate/substrate.cc rename to chalk/plugins/viewplugins/substrate/substrate.cpp diff --git a/chalk/plugins/viewplugins/variations/Makefile.am b/chalk/plugins/viewplugins/variations/Makefile.am index 21d4e63f6..cd75fc9cf 100644 --- a/chalk/plugins/viewplugins/variations/Makefile.am +++ b/chalk/plugins/viewplugins/variations/Makefile.am @@ -14,7 +14,7 @@ INCLUDES = -I$(srcdir)/../../../sdk \ kde_module_LTLIBRARIES = chalkvariations.la -chalkvariations_la_SOURCES = variations.cc dlg_variations.cc wdg_variations.ui +chalkvariations_la_SOURCES = variations.cpp dlg_variations.cpp wdg_variations.ui noinst_HEADERS = wdg_variations.h chalkvariations_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) $(LIB_TQT) -ltdecore -ltdeui -lkjs -ltdefx -ltdeio -ltdeparts diff --git a/chalk/plugins/viewplugins/variations/dlg_variations.cc b/chalk/plugins/viewplugins/variations/dlg_variations.cc deleted file mode 100644 index afa6a3d74..000000000 --- a/chalk/plugins/viewplugins/variations/dlg_variations.cc +++ /dev/null @@ -1,58 +0,0 @@ -/* - * dlg_variations.cc - part of KimageShop^WKrayon^WChalk - * - * Copyright (c) 2004 Boudewijn Rempt - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include - -#include "dlg_variations.h" -#include "wdg_variations.h" - - -DlgVariations::DlgVariations( TQWidget * parent, - const char * name) - : super (parent, name, true, i18n("Color Range"), Ok | Cancel, Ok) -{ - m_previewPix = TQPixmap(); - m_page = new WdgVariations(this, "variations"); - TQ_CHECK_PTR(m_page); - setCaption(i18n("Variations")); - setMainWidget(m_page); - resize(m_page -> size()); - - connect(this, TQT_SIGNAL(okClicked()), - this, TQT_SLOT(okClicked())); -} - -DlgVariations::~DlgVariations() -{ - delete m_page; -} - -void DlgVariations::setPixmap(TQPixmap pix) -{ - m_previewPix = pix; - m_previewPix.detach(); -} - -void DlgVariations::okClicked() -{ - accept(); -} - -#include "dlg_variations.moc" diff --git a/chalk/plugins/viewplugins/variations/dlg_variations.cpp b/chalk/plugins/viewplugins/variations/dlg_variations.cpp new file mode 100644 index 000000000..4decbbd41 --- /dev/null +++ b/chalk/plugins/viewplugins/variations/dlg_variations.cpp @@ -0,0 +1,58 @@ +/* + * dlg_variations.cpp - part of KimageShop^WKrayon^WChalk + * + * Copyright (c) 2004 Boudewijn Rempt + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include + +#include "dlg_variations.h" +#include "wdg_variations.h" + + +DlgVariations::DlgVariations( TQWidget * parent, + const char * name) + : super (parent, name, true, i18n("Color Range"), Ok | Cancel, Ok) +{ + m_previewPix = TQPixmap(); + m_page = new WdgVariations(this, "variations"); + TQ_CHECK_PTR(m_page); + setCaption(i18n("Variations")); + setMainWidget(m_page); + resize(m_page -> size()); + + connect(this, TQT_SIGNAL(okClicked()), + this, TQT_SLOT(okClicked())); +} + +DlgVariations::~DlgVariations() +{ + delete m_page; +} + +void DlgVariations::setPixmap(TQPixmap pix) +{ + m_previewPix = pix; + m_previewPix.detach(); +} + +void DlgVariations::okClicked() +{ + accept(); +} + +#include "dlg_variations.moc" diff --git a/chalk/plugins/viewplugins/variations/variations.cc b/chalk/plugins/viewplugins/variations/variations.cpp similarity index 100% rename from chalk/plugins/viewplugins/variations/variations.cc rename to chalk/plugins/viewplugins/variations/variations.cpp diff --git a/chalk/sdk/Makefile.am b/chalk/sdk/Makefile.am index 0c7f4c186..869b2c362 100644 --- a/chalk/sdk/Makefile.am +++ b/chalk/sdk/Makefile.am @@ -4,7 +4,7 @@ INCLUDES = $(KOFFICE_INCLUDES) $(KOPAINTER_INCLUDES) \ $(all_includes) noinst_LTLIBRARIES = libchalksdk.la -libchalksdk_la_SOURCES = kis_progress_subject.cc +libchalksdk_la_SOURCES = kis_progress_subject.cpp libchalksdk_la_METASOURCES = AUTO include_HEADERS = \ diff --git a/chalk/sdk/kis_progress_subject.cc b/chalk/sdk/kis_progress_subject.cpp similarity index 100% rename from chalk/sdk/kis_progress_subject.cc rename to chalk/sdk/kis_progress_subject.cpp diff --git a/chalk/ui/Makefile.am b/chalk/ui/Makefile.am index 34f67c916..3a2bff125 100644 --- a/chalk/ui/Makefile.am +++ b/chalk/ui/Makefile.am @@ -13,34 +13,34 @@ libchalkui_la_LDFLAGS = -version-info 1:0:0 -no-undefined $(all_libraries) libchalkui_la_LIBADD = ../sdk/libchalksdk.la ../core/libchalkimage.la ../chalkcolor/libchalkcolor.la \ $(LCMS_LIBS) $(LIB_KOFFICEUI) $(LIB_KOPAINTER) $(LIB_KOPALETTE) $(LIB_XINPUTEXT) $(GLLIB) -libchalkui_la_SOURCES = kis_import_catcher.cc kis_histogram_view.cc imageviewer.cc kcurve.cc \ - kis_autobrush.cc kis_autogradient.cc kis_boundary_painter.cc kis_brush_chooser.cc \ - kis_canvas.cc kis_canvas_painter.cc kis_clipboard.cc kis_cmb_composite.cc \ - kis_cmb_idlist.cc kis_color_cup.cc kis_config.cc kis_controlframe.cc kis_cursor.cc \ - kis_dlg_apply_profile.cc kis_dlg_image_properties.cc kis_dlg_layer_properties.cc \ - kis_dlg_new_layer.cc kis_dlg_preferences.cc kis_doc.cc kis_doc_iface.cc kis_doc_iface.skel \ - kis_double_widget.cc kis_factory.cc kis_filter_manager.cc kis_gradient_chooser.cc \ - kis_gradient_slider_widget.cc kis_icon_item.cc kis_iconwidget.cc kis_int_spinbox.cc \ - kis_itemchooser.cc kis_label_cursor_pos.cc kis_label_progress.cc kis_label_zoom.cc \ - kis_layerbox.cc kis_layerlist.cc kis_multi_bool_filter_widget.cc \ - kis_multi_double_filter_widget.cc kis_multi_integer_filter_widget.cc kis_opengl_canvas.cc \ - kis_opengl_canvas_painter.cc kis_opengl_image_context.cc kis_paintop_box.cc kis_palette_view.cc \ - kis_palette_widget.cc kis_part_layer.cc kis_pattern_chooser.cc kis_previewdialog.cc \ - kis_previewwidget.cc kis_qpaintdevice_canvas.cc kis_qpaintdevice_canvas_painter.cc \ - kis_resource_mediator.cc kis_resourceserver.cc kis_ruler.cc kis_selection_manager.cc \ - kis_selection_options.cc kis_text_brush.cc kis_tool.cc kis_tool_dummy.cc kis_tool_freehand.cc \ - kis_tool_manager.cc kis_tool_non_paint.cc kis_tool_paint.cc kis_tool_registry.cc \ - kis_tool_shape.cc kis_birdeye_box.cc kis_view.cc kis_view_iface.cc kis_custom_brush.cc \ - kis_custom_palette.cc kis_custom_pattern.cc kis_custom_image_widget.cc kis_view_iface.skel \ +libchalkui_la_SOURCES = kis_import_catcher.cpp kis_histogram_view.cpp imageviewer.cpp kcurve.cpp \ + kis_autobrush.cpp kis_autogradient.cpp kis_boundary_painter.cpp kis_brush_chooser.cpp \ + kis_canvas.cpp kis_canvas_painter.cpp kis_clipboard.cpp kis_cmb_composite.cpp \ + kis_cmb_idlist.cpp kis_color_cup.cpp kis_config.cpp kis_controlframe.cpp kis_cursor.cpp \ + kis_dlg_apply_profile.cpp kis_dlg_image_properties.cpp kis_dlg_layer_properties.cpp \ + kis_dlg_new_layer.cpp kis_dlg_preferences.cpp kis_doc.cpp kis_doc_iface.cpp kis_doc_iface.skel \ + kis_double_widget.cpp kis_factory.cpp kis_filter_manager.cpp kis_gradient_chooser.cpp \ + kis_gradient_slider_widget.cpp kis_icon_item.cpp kis_iconwidget.cpp kis_int_spinbox.cpp \ + kis_itemchooser.cpp kis_label_cursor_pos.cpp kis_label_progress.cpp kis_label_zoom.cpp \ + kis_layerbox.cpp kis_layerlist.cpp kis_multi_bool_filter_widget.cpp \ + kis_multi_double_filter_widget.cpp kis_multi_integer_filter_widget.cpp kis_opengl_canvas.cpp \ + kis_opengl_canvas_painter.cpp kis_opengl_image_context.cpp kis_paintop_box.cpp kis_palette_view.cpp \ + kis_palette_widget.cpp kis_part_layer.cpp kis_pattern_chooser.cpp kis_previewdialog.cpp \ + kis_previewwidget.cpp kis_qpaintdevice_canvas.cpp kis_qpaintdevice_canvas_painter.cpp \ + kis_resource_mediator.cpp kis_resourceserver.cpp kis_ruler.cpp kis_selection_manager.cpp \ + kis_selection_options.cpp kis_text_brush.cpp kis_tool.cpp kis_tool_dummy.cpp kis_tool_freehand.cpp \ + kis_tool_manager.cpp kis_tool_non_paint.cpp kis_tool_paint.cpp kis_tool_registry.cpp \ + kis_tool_shape.cpp kis_birdeye_box.cpp kis_view.cpp kis_view_iface.cpp kis_custom_brush.cpp \ + kis_custom_palette.cpp kis_custom_pattern.cpp kis_custom_image_widget.cpp kis_view_iface.skel \ kobirdeyepanel.cpp kis_matrix_widget.ui kis_previewwidgetbase.ui layerlist.cpp \ wdgapplyprofile.ui wdgautobrush.ui wdgautogradient.ui wdgbirdeye.ui wdgcolorsettings.ui \ wdgdisplaysettings.ui wdggeneralsettings.ui wdglayerproperties.ui wdglayerbox.ui \ wdgnewimage.ui wdgperformancesettings.ui wdgselectionoptions.ui wdgshapeoptions.ui \ wdgpressuresettings.ui wdgcustombrush.ui wdgcustompalette.ui wdgcustompattern.ui \ - wdgtextbrush.ui kis_dlg_adjustment_layer.cc kis_filters_listview.cc \ + wdgtextbrush.ui kis_dlg_adjustment_layer.cpp kis_filters_listview.cpp \ wdgpalettechooser.ui wdggridsettings.ui kis_grid_manager.cpp wdgtabletdevicesettings.ui \ - wdgtabletsettings.ui kis_input_device.cc kis_part_layer_handler.cc \ - kis_dlg_adj_layer_props.cc squeezedcombobox.cpp kis_perspective_grid_manager.cpp \ + wdgtabletsettings.ui kis_input_device.cpp kis_part_layer_handler.cpp \ + kis_dlg_adj_layer_props.cpp squeezedcombobox.cpp kis_perspective_grid_manager.cpp \ kis_grid_drawer.cpp noinst_HEADERS = kis_aboutdata.h imageviewer.h layerlist.h kcurve.h \ diff --git a/chalk/ui/imageviewer.cc b/chalk/ui/imageviewer.cpp similarity index 100% rename from chalk/ui/imageviewer.cc rename to chalk/ui/imageviewer.cpp diff --git a/chalk/ui/kcurve.cc b/chalk/ui/kcurve.cpp similarity index 100% rename from chalk/ui/kcurve.cc rename to chalk/ui/kcurve.cpp diff --git a/chalk/ui/kis_autobrush.cc b/chalk/ui/kis_autobrush.cpp similarity index 100% rename from chalk/ui/kis_autobrush.cc rename to chalk/ui/kis_autobrush.cpp diff --git a/chalk/ui/kis_autogradient.cc b/chalk/ui/kis_autogradient.cpp similarity index 100% rename from chalk/ui/kis_autogradient.cc rename to chalk/ui/kis_autogradient.cpp diff --git a/chalk/ui/kis_birdeye_box.cc b/chalk/ui/kis_birdeye_box.cpp similarity index 100% rename from chalk/ui/kis_birdeye_box.cc rename to chalk/ui/kis_birdeye_box.cpp diff --git a/chalk/ui/kis_boundary_painter.cc b/chalk/ui/kis_boundary_painter.cpp similarity index 100% rename from chalk/ui/kis_boundary_painter.cc rename to chalk/ui/kis_boundary_painter.cpp diff --git a/chalk/ui/kis_brush_chooser.cc b/chalk/ui/kis_brush_chooser.cpp similarity index 100% rename from chalk/ui/kis_brush_chooser.cc rename to chalk/ui/kis_brush_chooser.cpp diff --git a/chalk/ui/kis_canvas.cc b/chalk/ui/kis_canvas.cpp similarity index 100% rename from chalk/ui/kis_canvas.cc rename to chalk/ui/kis_canvas.cpp diff --git a/chalk/ui/kis_canvas_painter.cc b/chalk/ui/kis_canvas_painter.cpp similarity index 100% rename from chalk/ui/kis_canvas_painter.cc rename to chalk/ui/kis_canvas_painter.cpp diff --git a/chalk/ui/kis_clipboard.cc b/chalk/ui/kis_clipboard.cpp similarity index 100% rename from chalk/ui/kis_clipboard.cc rename to chalk/ui/kis_clipboard.cpp diff --git a/chalk/ui/kis_cmb_composite.cc b/chalk/ui/kis_cmb_composite.cc deleted file mode 100644 index 66e3a6b39..000000000 --- a/chalk/ui/kis_cmb_composite.cc +++ /dev/null @@ -1,88 +0,0 @@ -/* - * kis_cmb_composite.cc - part of KImageShop/Krayon/Chalk - * - * Copyright (c) 2004 Boudewijn Rempt (boud@valdyas.org) - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include - -#include -#include - -#include "kis_cmb_composite.h" - -KisCmbComposite::KisCmbComposite(TQWidget * parent, const char * name) - : super( false, parent, name ) -{ - connect(this, TQT_SIGNAL(activated(int)), this, TQT_SLOT(slotOpActivated(int))); - connect(this, TQT_SIGNAL(highlighted(int)), this, TQT_SLOT(slotOpHighlighted(int))); -} - -KisCmbComposite::~KisCmbComposite() -{ -} - -void KisCmbComposite::setCompositeOpList(const KisCompositeOpList & list) -{ - super::clear(); - m_list = list; - KisCompositeOpList::iterator it; - for( it = m_list.begin(); it != m_list.end(); ++it ) - insertItem((*it).id().name()); -} - -KisCompositeOp KisCmbComposite::currentItem() const -{ - TQ_UINT32 i = super::currentItem(); - if (i > m_list.count()) return KisCompositeOp(); - - return m_list[i]; -} - -void KisCmbComposite::setCurrentItem(const KisCompositeOp& op) -{ - if (m_list.find(op) != m_list.end()) { - super::setCurrentText(op.id().name()); - } -} - -void KisCmbComposite::setCurrentText(const TQString & s) -{ - KisCompositeOpList::iterator it; - for( it = m_list.begin(); it != m_list.end(); ++it ) - if ((*it).id().id() == s) { - super::setCurrentText((*it).id().name()); - } -} - -void KisCmbComposite::slotOpActivated(int i) -{ - if ((TQ_UINT32)i > m_list.count()) return; - - emit activated(m_list[i]); -} - -void KisCmbComposite::slotOpHighlighted(int i) -{ - if ((TQ_UINT32)i > m_list.count()) return; - - emit highlighted(m_list[i]); -} - - -#include "kis_cmb_composite.moc" - diff --git a/chalk/ui/kis_cmb_composite.cpp b/chalk/ui/kis_cmb_composite.cpp new file mode 100644 index 000000000..631f602e9 --- /dev/null +++ b/chalk/ui/kis_cmb_composite.cpp @@ -0,0 +1,88 @@ +/* + * kis_cmb_composite.cpp - part of KImageShop/Krayon/Chalk + * + * Copyright (c) 2004 Boudewijn Rempt (boud@valdyas.org) + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include + +#include +#include + +#include "kis_cmb_composite.h" + +KisCmbComposite::KisCmbComposite(TQWidget * parent, const char * name) + : super( false, parent, name ) +{ + connect(this, TQT_SIGNAL(activated(int)), this, TQT_SLOT(slotOpActivated(int))); + connect(this, TQT_SIGNAL(highlighted(int)), this, TQT_SLOT(slotOpHighlighted(int))); +} + +KisCmbComposite::~KisCmbComposite() +{ +} + +void KisCmbComposite::setCompositeOpList(const KisCompositeOpList & list) +{ + super::clear(); + m_list = list; + KisCompositeOpList::iterator it; + for( it = m_list.begin(); it != m_list.end(); ++it ) + insertItem((*it).id().name()); +} + +KisCompositeOp KisCmbComposite::currentItem() const +{ + TQ_UINT32 i = super::currentItem(); + if (i > m_list.count()) return KisCompositeOp(); + + return m_list[i]; +} + +void KisCmbComposite::setCurrentItem(const KisCompositeOp& op) +{ + if (m_list.find(op) != m_list.end()) { + super::setCurrentText(op.id().name()); + } +} + +void KisCmbComposite::setCurrentText(const TQString & s) +{ + KisCompositeOpList::iterator it; + for( it = m_list.begin(); it != m_list.end(); ++it ) + if ((*it).id().id() == s) { + super::setCurrentText((*it).id().name()); + } +} + +void KisCmbComposite::slotOpActivated(int i) +{ + if ((TQ_UINT32)i > m_list.count()) return; + + emit activated(m_list[i]); +} + +void KisCmbComposite::slotOpHighlighted(int i) +{ + if ((TQ_UINT32)i > m_list.count()) return; + + emit highlighted(m_list[i]); +} + + +#include "kis_cmb_composite.moc" + diff --git a/chalk/ui/kis_cmb_idlist.cc b/chalk/ui/kis_cmb_idlist.cc deleted file mode 100644 index 92dc608f6..000000000 --- a/chalk/ui/kis_cmb_idlist.cc +++ /dev/null @@ -1,97 +0,0 @@ -/* - * kis_cmb_idlist.cc - part of KImageShop/Krayon/Chalk - * - * Copyright (c) 2005 Boudewijn Rempt (boud@valdyas.org) - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include - -#include -#include - -#include "kis_id.h" -#include "kis_cmb_idlist.h" - -KisCmbIDList::KisCmbIDList(TQWidget * parent, const char * name) - : super( false, parent, name ) -{ - connect(this, TQT_SIGNAL(activated(int)), this, TQT_SLOT(slotIDActivated(int))); - connect(this, TQT_SIGNAL(highlighted(int)), this, TQT_SLOT(slotIDHighlighted(int))); -} - -KisCmbIDList::~KisCmbIDList() -{ -} - - -void KisCmbIDList::setIDList(const KisIDList & list) -{ - m_list = list; - KisIDList::iterator it; - for( it = m_list.begin(); it != m_list.end(); ++it ) - insertItem((*it).name()); -} - - -KisID KisCmbIDList::currentItem() const -{ - TQ_UINT32 i = super::currentItem(); - if (i > m_list.count()) return KisID(); - - return m_list[i]; -} - -void KisCmbIDList::setCurrent(const KisID id) -{ - if (m_list.find(id) != m_list.end()) - super::setCurrentText(id.name()); - else { - m_list.push_back(id); - insertItem(id.name()); - super::setCurrentText(id.name()); - } -} - -void KisCmbIDList::setCurrentText(const TQString & s) -{ - KisIDList::iterator it; - for( it = m_list.begin(); it != m_list.end(); ++it ) - if ((*it).id() == s) { - super::setCurrentText((*it).name()); - } -} - -void KisCmbIDList::slotIDActivated(int i) -{ - if ((uint)i > m_list.count()) return; - - emit activated(m_list[i]); - -} - -void KisCmbIDList::slotIDHighlighted(int i) -{ - if ((uint)i > m_list.count()) return; - - emit highlighted(m_list[i]); - -} - - - -#include "kis_cmb_idlist.moc" - diff --git a/chalk/ui/kis_cmb_idlist.cpp b/chalk/ui/kis_cmb_idlist.cpp new file mode 100644 index 000000000..39937752a --- /dev/null +++ b/chalk/ui/kis_cmb_idlist.cpp @@ -0,0 +1,97 @@ +/* + * kis_cmb_idlist.cpp - part of KImageShop/Krayon/Chalk + * + * Copyright (c) 2005 Boudewijn Rempt (boud@valdyas.org) + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include + +#include +#include + +#include "kis_id.h" +#include "kis_cmb_idlist.h" + +KisCmbIDList::KisCmbIDList(TQWidget * parent, const char * name) + : super( false, parent, name ) +{ + connect(this, TQT_SIGNAL(activated(int)), this, TQT_SLOT(slotIDActivated(int))); + connect(this, TQT_SIGNAL(highlighted(int)), this, TQT_SLOT(slotIDHighlighted(int))); +} + +KisCmbIDList::~KisCmbIDList() +{ +} + + +void KisCmbIDList::setIDList(const KisIDList & list) +{ + m_list = list; + KisIDList::iterator it; + for( it = m_list.begin(); it != m_list.end(); ++it ) + insertItem((*it).name()); +} + + +KisID KisCmbIDList::currentItem() const +{ + TQ_UINT32 i = super::currentItem(); + if (i > m_list.count()) return KisID(); + + return m_list[i]; +} + +void KisCmbIDList::setCurrent(const KisID id) +{ + if (m_list.find(id) != m_list.end()) + super::setCurrentText(id.name()); + else { + m_list.push_back(id); + insertItem(id.name()); + super::setCurrentText(id.name()); + } +} + +void KisCmbIDList::setCurrentText(const TQString & s) +{ + KisIDList::iterator it; + for( it = m_list.begin(); it != m_list.end(); ++it ) + if ((*it).id() == s) { + super::setCurrentText((*it).name()); + } +} + +void KisCmbIDList::slotIDActivated(int i) +{ + if ((uint)i > m_list.count()) return; + + emit activated(m_list[i]); + +} + +void KisCmbIDList::slotIDHighlighted(int i) +{ + if ((uint)i > m_list.count()) return; + + emit highlighted(m_list[i]); + +} + + + +#include "kis_cmb_idlist.moc" + diff --git a/chalk/ui/kis_color_cup.cc b/chalk/ui/kis_color_cup.cpp similarity index 100% rename from chalk/ui/kis_color_cup.cc rename to chalk/ui/kis_color_cup.cpp diff --git a/chalk/ui/kis_config.cc b/chalk/ui/kis_config.cpp similarity index 100% rename from chalk/ui/kis_config.cc rename to chalk/ui/kis_config.cpp diff --git a/chalk/ui/kis_controlframe.cc b/chalk/ui/kis_controlframe.cc deleted file mode 100644 index 6c57a7e6a..000000000 --- a/chalk/ui/kis_controlframe.cc +++ /dev/null @@ -1,343 +0,0 @@ -/* - * kis_controlframe.cc - part of Chalk - * - * Copyright (c) 1999 Matthias Elter - * Copyright (c) 2003 Patrick Julien - * Copyright (c) 2004 Sven Langkamp - * - * 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 of the License, 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.g - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "kis_resourceserver.h" -#include "kis_controlframe.h" -#include "kis_resource_mediator.h" -#include "kis_itemchooser.h" -#include "kis_pattern_chooser.h" -#include "kis_gradient_chooser.h" -#include "kis_icon_item.h" -#include "kis_iconwidget.h" -#include "kis_brush.h" -#include "kis_pattern.h" -#include "kis_gradient.h" -#include "kis_brush_chooser.h" -#include "kis_view.h" -#include "kis_autobrush.h" -#include "kis_autogradient.h" -#include "kis_config.h" -#include "kis_paintop_box.h" -#include "kis_custom_brush.h" -#include "kis_custom_pattern.h" -#ifdef HAVE_TEXT_BRUSH -#include "kis_text_brush.h" -#endif -KisPopupFrame::KisPopupFrame(TQWidget * parent, const char* name) - : TQPopupMenu(parent, name) -{ - setFocusPolicy(TQ_StrongFocus); -} - -void KisPopupFrame::keyPressEvent(TQKeyEvent * e) -{ - if (e->key()== TQt::Key_Escape) - { - hide(); - e->accept(); - } - else { - e->ignore(); - } -} - - -KisControlFrame::KisControlFrame( TDEMainWindow * /*window*/, KisView * view, const char* name ) - : TQObject(view, name) - //: TDEToolBar ( window, TQt::DockTop, false, name, true, true ) - , m_view(view) - , m_brushWidget(0) - , m_patternWidget(0) - , m_gradientWidget(0) - , m_brushChooserPopup(0) - , m_patternChooserPopup(0) - , m_gradientChooserPopup(0) - , m_brushMediator(0) - , m_patternMediator(0) - , m_gradientMediator(0) - , m_paintopBox(0) -{ - - KisConfig cfg; - m_font = TDEGlobalSettings::generalFont(); - m_font.setPointSize((int)cfg.dockerFontSize()); - - m_brushWidget = new KisIconWidget(view, "brushes"); - m_brushWidget->setTextLabel( i18n("Brush Shapes") ); - // XXX: An action without a slot -- that's silly, what kind of action could we use here? - TDEAction * action = new KWidgetAction(m_brushWidget, - i18n("&Brush"), - 0, - TQT_TQOBJECT(view), - 0, - view->actionCollection(), - "brushes"); - - - m_patternWidget = new KisIconWidget(view, "patterns"); - m_patternWidget->setTextLabel( i18n("Fill Patterns") ); - action = new KWidgetAction(m_patternWidget, - i18n("&Patterns"), - 0, - TQT_TQOBJECT(view), - 0, - view->actionCollection(), - "patterns"); - - m_gradientWidget = new KisIconWidget(view, "gradients"); - m_gradientWidget->setTextLabel( i18n("Gradients") ); - action = new KWidgetAction(m_gradientWidget, - i18n("&Gradients"), - 0, - TQT_TQOBJECT(view), - 0, - view->actionCollection(), - "gradients"); - - m_paintopBox = new KisPaintopBox( view, view, "paintopbox" ); - action = new KWidgetAction(m_paintopBox, - i18n("&Painter's Tools"), - 0, - TQT_TQOBJECT(view), - 0, - view->actionCollection(), - "paintops"); - - m_brushWidget->setFixedSize( 26, 26 ); - m_patternWidget->setFixedSize( 26, 26 ); - m_gradientWidget->setFixedSize( 26, 26 ); - - createBrushesChooser(m_view); - createPatternsChooser(m_view); - createGradientsChooser(m_view); - - m_brushWidget->setPopup(m_brushChooserPopup); - m_brushWidget->setPopupDelay(1); - m_patternWidget->setPopup(m_patternChooserPopup); - m_patternWidget->setPopupDelay(1); - m_gradientWidget->setPopup(m_gradientChooserPopup); - m_gradientWidget->setPopupDelay(1); -} - - -void KisControlFrame::slotSetBrush(KoIconItem *item) -{ - if (item) - m_brushWidget->slotSetItem(*item); -} - -void KisControlFrame::slotSetPattern(KoIconItem *item) -{ - if (item) - m_patternWidget->slotSetItem(*item); -} - -void KisControlFrame::slotSetGradient(KoIconItem *item) -{ - if (item) - m_gradientWidget->slotSetItem(*item); -} - -void KisControlFrame::slotBrushChanged(KisBrush * brush) -{ - KisIconItem *item; - - if((item = m_brushMediator->itemFor(brush))) - { - slotSetBrush(item); - } else { - slotSetBrush( new KisIconItem(brush) ); - } - -} - -void KisControlFrame::slotPatternChanged(KisPattern * pattern) -{ - KisIconItem *item; - if (!pattern) - return; - - if ( (item = m_patternMediator->itemFor(pattern)) ) - slotSetPattern(item); - else - slotSetPattern( new KisIconItem(pattern) ); -} - - -void KisControlFrame::slotGradientChanged(KisGradient * gradient) -{ - KisIconItem *item; - if (!gradient) - return; - - if ( (item = m_gradientMediator->itemFor(gradient)) ) - slotSetGradient(item); - else - slotSetGradient( new KisIconItem(gradient) ); -} - -void KisControlFrame::createBrushesChooser(KisView * view) -{ - - m_brushChooserPopup = new KisPopupFrame(m_brushWidget, "brush_chooser_popup"); - - TQHBoxLayout * l = new TQHBoxLayout(m_brushChooserPopup, 2, 2, "brushpopuplayout"); - - TQTabWidget * m_brushesTab = new TQTabWidget(m_brushChooserPopup, "brushestab"); - m_brushesTab->setTabShape(TQTabWidget::Triangular); - m_brushesTab->setFocusPolicy(TQ_NoFocus); - m_brushesTab->setFont(m_font); - m_brushesTab->setMargin(1); - - l->add(m_brushesTab); - - KisAutobrush * m_autobrush = new KisAutobrush(m_brushesTab, "autobrush", i18n("Autobrush")); - m_brushesTab->addTab( m_autobrush, i18n("Autobrush")); - connect(m_autobrush, TQT_SIGNAL(activatedResource(KisResource*)), m_view, TQT_SLOT(brushActivated( KisResource* ))); - - KisBrushChooser * m_brushChooser = new KisBrushChooser(m_brushesTab, "brush_chooser"); - m_brushesTab->addTab( m_brushChooser, i18n("Predefined Brushes")); - - KisCustomBrush* customBrushes = new KisCustomBrush(m_brushesTab, "custombrush", - i18n("Custom Brush"), m_view); - m_brushesTab->addTab( customBrushes, i18n("Custom Brush")); - connect(customBrushes, TQT_SIGNAL(activatedResource(KisResource*)), - m_view, TQT_SLOT(brushActivated(KisResource*))); -#ifdef HAVE_TEXT_BRUSH - KisTextBrush* textBrushes = new KisTextBrush(m_brushesTab, "textbrush", - i18n("Text Brush")/*, m_view*/); - m_brushesTab->addTab( textBrushes, i18n("Text Brush")); - connect(textBrushes, TQT_SIGNAL(activatedResource(KisResource*)), - m_view, TQT_SLOT(brushActivated(KisResource*))); -#endif - - m_brushChooser->setFont(m_font); - m_brushMediator = new KisResourceMediator( m_brushChooser, this); - connect(m_brushMediator, TQT_SIGNAL(activatedResource(KisResource*)), m_view, TQT_SLOT(brushActivated(KisResource*))); - - KisResourceServerBase* rServer; - rServer = KisResourceServerRegistry::instance()->get("ImagePipeBrushServer"); - m_brushMediator->connectServer(rServer); - rServer = KisResourceServerRegistry::instance()->get("BrushServer"); - m_brushMediator->connectServer(rServer); - - KisControlFrame::connect(view, TQT_SIGNAL(brushChanged(KisBrush *)), this, TQT_SLOT(slotBrushChanged( KisBrush *))); - m_brushChooser->setCurrent( 0 ); - m_brushMediator->setActiveItem( m_brushChooser->currentItem() ); - customBrushes->setResourceServer(rServer); - - m_autobrush->activate(); -} - -void KisControlFrame::createPatternsChooser(KisView * view) -{ - m_patternChooserPopup = new KisPopupFrame(m_patternWidget, "pattern_chooser_popup"); - - TQHBoxLayout * l2 = new TQHBoxLayout(m_patternChooserPopup, 2, 2, "patternpopuplayout"); - - TQTabWidget * m_patternsTab = new TQTabWidget(m_patternChooserPopup, "patternstab"); - m_patternsTab->setTabShape(TQTabWidget::Triangular); - m_patternsTab->setFocusPolicy(TQ_NoFocus); - m_patternsTab->setFont(m_font); - m_patternsTab->setMargin(1); - l2->add( m_patternsTab ); - - KisPatternChooser * chooser = new KisPatternChooser(m_patternChooserPopup, "pattern_chooser"); - chooser->setFont(m_font); - chooser->setMinimumSize(200, 150); - m_patternsTab->addTab(chooser, i18n("Patterns")); - - KisCustomPattern* customPatterns = new KisCustomPattern(m_patternsTab, "custompatterns", - i18n("Custom Pattern"), m_view); - customPatterns->setFont(m_font); - m_patternsTab->addTab( customPatterns, i18n("Custom Pattern")); - - - m_patternMediator = new KisResourceMediator( chooser, TQT_TQOBJECT(view)); - connect( m_patternMediator, TQT_SIGNAL(activatedResource(KisResource*)), view, TQT_SLOT(patternActivated(KisResource*))); - connect(customPatterns, TQT_SIGNAL(activatedResource(KisResource*)), - TQT_TQOBJECT(view), TQT_SLOT(patternActivated(KisResource*))); - - KisResourceServerBase* rServer; - rServer = KisResourceServerRegistry::instance()->get("PatternServer"); - m_patternMediator->connectServer(rServer); - - KisControlFrame::connect(view, TQT_SIGNAL(patternChanged(KisPattern *)), this, TQT_SLOT(slotPatternChanged( KisPattern *))); - chooser->setCurrent( 0 ); - m_patternMediator->setActiveItem( chooser->currentItem() ); - - customPatterns->setResourceServer(rServer); -} - - -void KisControlFrame::createGradientsChooser(KisView * view) -{ - m_gradientChooserPopup = new KisPopupFrame(m_gradientWidget, "gradient_chooser_popup"); - - TQHBoxLayout * l2 = new TQHBoxLayout(m_gradientChooserPopup, 2, 2, "gradientpopuplayout"); - - TQTabWidget * m_gradientTab = new TQTabWidget(m_gradientChooserPopup, "gradientstab"); - m_gradientTab->setTabShape(TQTabWidget::Triangular); - m_gradientTab->setFocusPolicy(TQ_NoFocus); - m_gradientTab->setFont(m_font); - m_gradientTab->setMargin(1); - - l2->add( m_gradientTab); - - KisGradientChooser * m_gradientChooser = new KisGradientChooser(m_view, m_gradientChooserPopup, "gradient_chooser"); - m_gradientChooser->setFont(m_font); - m_gradientChooser->setMinimumSize(200, 150); - m_gradientTab->addTab( m_gradientChooser, i18n("Gradients")); - - m_gradientMediator = new KisResourceMediator( m_gradientChooser, TQT_TQOBJECT(view)); - connect(m_gradientMediator, TQT_SIGNAL(activatedResource(KisResource*)), view, TQT_SLOT(gradientActivated(KisResource*))); - - KisResourceServerBase* rServer; - rServer = KisResourceServerRegistry::instance()->get("GradientServer"); - m_gradientMediator->connectServer(rServer); - - connect(view, TQT_SIGNAL(gradientChanged(KisGradient *)), this, TQT_SLOT(slotGradientChanged( KisGradient *))); - m_gradientChooser->setCurrent( 0 ); - m_gradientMediator->setActiveItem( m_gradientChooser->currentItem() ); -} - - -#include "kis_controlframe.moc" - diff --git a/chalk/ui/kis_controlframe.cpp b/chalk/ui/kis_controlframe.cpp new file mode 100644 index 000000000..e5a8ce1bb --- /dev/null +++ b/chalk/ui/kis_controlframe.cpp @@ -0,0 +1,343 @@ +/* + * kis_controlframe.cpp - part of Chalk + * + * Copyright (c) 1999 Matthias Elter + * Copyright (c) 2003 Patrick Julien + * Copyright (c) 2004 Sven Langkamp + * + * 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 of the License, 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.g + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "kis_resourceserver.h" +#include "kis_controlframe.h" +#include "kis_resource_mediator.h" +#include "kis_itemchooser.h" +#include "kis_pattern_chooser.h" +#include "kis_gradient_chooser.h" +#include "kis_icon_item.h" +#include "kis_iconwidget.h" +#include "kis_brush.h" +#include "kis_pattern.h" +#include "kis_gradient.h" +#include "kis_brush_chooser.h" +#include "kis_view.h" +#include "kis_autobrush.h" +#include "kis_autogradient.h" +#include "kis_config.h" +#include "kis_paintop_box.h" +#include "kis_custom_brush.h" +#include "kis_custom_pattern.h" +#ifdef HAVE_TEXT_BRUSH +#include "kis_text_brush.h" +#endif +KisPopupFrame::KisPopupFrame(TQWidget * parent, const char* name) + : TQPopupMenu(parent, name) +{ + setFocusPolicy(TQ_StrongFocus); +} + +void KisPopupFrame::keyPressEvent(TQKeyEvent * e) +{ + if (e->key()== TQt::Key_Escape) + { + hide(); + e->accept(); + } + else { + e->ignore(); + } +} + + +KisControlFrame::KisControlFrame( TDEMainWindow * /*window*/, KisView * view, const char* name ) + : TQObject(view, name) + //: TDEToolBar ( window, TQt::DockTop, false, name, true, true ) + , m_view(view) + , m_brushWidget(0) + , m_patternWidget(0) + , m_gradientWidget(0) + , m_brushChooserPopup(0) + , m_patternChooserPopup(0) + , m_gradientChooserPopup(0) + , m_brushMediator(0) + , m_patternMediator(0) + , m_gradientMediator(0) + , m_paintopBox(0) +{ + + KisConfig cfg; + m_font = TDEGlobalSettings::generalFont(); + m_font.setPointSize((int)cfg.dockerFontSize()); + + m_brushWidget = new KisIconWidget(view, "brushes"); + m_brushWidget->setTextLabel( i18n("Brush Shapes") ); + // XXX: An action without a slot -- that's silly, what kind of action could we use here? + TDEAction * action = new KWidgetAction(m_brushWidget, + i18n("&Brush"), + 0, + TQT_TQOBJECT(view), + 0, + view->actionCollection(), + "brushes"); + + + m_patternWidget = new KisIconWidget(view, "patterns"); + m_patternWidget->setTextLabel( i18n("Fill Patterns") ); + action = new KWidgetAction(m_patternWidget, + i18n("&Patterns"), + 0, + TQT_TQOBJECT(view), + 0, + view->actionCollection(), + "patterns"); + + m_gradientWidget = new KisIconWidget(view, "gradients"); + m_gradientWidget->setTextLabel( i18n("Gradients") ); + action = new KWidgetAction(m_gradientWidget, + i18n("&Gradients"), + 0, + TQT_TQOBJECT(view), + 0, + view->actionCollection(), + "gradients"); + + m_paintopBox = new KisPaintopBox( view, view, "paintopbox" ); + action = new KWidgetAction(m_paintopBox, + i18n("&Painter's Tools"), + 0, + TQT_TQOBJECT(view), + 0, + view->actionCollection(), + "paintops"); + + m_brushWidget->setFixedSize( 26, 26 ); + m_patternWidget->setFixedSize( 26, 26 ); + m_gradientWidget->setFixedSize( 26, 26 ); + + createBrushesChooser(m_view); + createPatternsChooser(m_view); + createGradientsChooser(m_view); + + m_brushWidget->setPopup(m_brushChooserPopup); + m_brushWidget->setPopupDelay(1); + m_patternWidget->setPopup(m_patternChooserPopup); + m_patternWidget->setPopupDelay(1); + m_gradientWidget->setPopup(m_gradientChooserPopup); + m_gradientWidget->setPopupDelay(1); +} + + +void KisControlFrame::slotSetBrush(KoIconItem *item) +{ + if (item) + m_brushWidget->slotSetItem(*item); +} + +void KisControlFrame::slotSetPattern(KoIconItem *item) +{ + if (item) + m_patternWidget->slotSetItem(*item); +} + +void KisControlFrame::slotSetGradient(KoIconItem *item) +{ + if (item) + m_gradientWidget->slotSetItem(*item); +} + +void KisControlFrame::slotBrushChanged(KisBrush * brush) +{ + KisIconItem *item; + + if((item = m_brushMediator->itemFor(brush))) + { + slotSetBrush(item); + } else { + slotSetBrush( new KisIconItem(brush) ); + } + +} + +void KisControlFrame::slotPatternChanged(KisPattern * pattern) +{ + KisIconItem *item; + if (!pattern) + return; + + if ( (item = m_patternMediator->itemFor(pattern)) ) + slotSetPattern(item); + else + slotSetPattern( new KisIconItem(pattern) ); +} + + +void KisControlFrame::slotGradientChanged(KisGradient * gradient) +{ + KisIconItem *item; + if (!gradient) + return; + + if ( (item = m_gradientMediator->itemFor(gradient)) ) + slotSetGradient(item); + else + slotSetGradient( new KisIconItem(gradient) ); +} + +void KisControlFrame::createBrushesChooser(KisView * view) +{ + + m_brushChooserPopup = new KisPopupFrame(m_brushWidget, "brush_chooser_popup"); + + TQHBoxLayout * l = new TQHBoxLayout(m_brushChooserPopup, 2, 2, "brushpopuplayout"); + + TQTabWidget * m_brushesTab = new TQTabWidget(m_brushChooserPopup, "brushestab"); + m_brushesTab->setTabShape(TQTabWidget::Triangular); + m_brushesTab->setFocusPolicy(TQ_NoFocus); + m_brushesTab->setFont(m_font); + m_brushesTab->setMargin(1); + + l->add(m_brushesTab); + + KisAutobrush * m_autobrush = new KisAutobrush(m_brushesTab, "autobrush", i18n("Autobrush")); + m_brushesTab->addTab( m_autobrush, i18n("Autobrush")); + connect(m_autobrush, TQT_SIGNAL(activatedResource(KisResource*)), m_view, TQT_SLOT(brushActivated( KisResource* ))); + + KisBrushChooser * m_brushChooser = new KisBrushChooser(m_brushesTab, "brush_chooser"); + m_brushesTab->addTab( m_brushChooser, i18n("Predefined Brushes")); + + KisCustomBrush* customBrushes = new KisCustomBrush(m_brushesTab, "custombrush", + i18n("Custom Brush"), m_view); + m_brushesTab->addTab( customBrushes, i18n("Custom Brush")); + connect(customBrushes, TQT_SIGNAL(activatedResource(KisResource*)), + m_view, TQT_SLOT(brushActivated(KisResource*))); +#ifdef HAVE_TEXT_BRUSH + KisTextBrush* textBrushes = new KisTextBrush(m_brushesTab, "textbrush", + i18n("Text Brush")/*, m_view*/); + m_brushesTab->addTab( textBrushes, i18n("Text Brush")); + connect(textBrushes, TQT_SIGNAL(activatedResource(KisResource*)), + m_view, TQT_SLOT(brushActivated(KisResource*))); +#endif + + m_brushChooser->setFont(m_font); + m_brushMediator = new KisResourceMediator( m_brushChooser, this); + connect(m_brushMediator, TQT_SIGNAL(activatedResource(KisResource*)), m_view, TQT_SLOT(brushActivated(KisResource*))); + + KisResourceServerBase* rServer; + rServer = KisResourceServerRegistry::instance()->get("ImagePipeBrushServer"); + m_brushMediator->connectServer(rServer); + rServer = KisResourceServerRegistry::instance()->get("BrushServer"); + m_brushMediator->connectServer(rServer); + + KisControlFrame::connect(view, TQT_SIGNAL(brushChanged(KisBrush *)), this, TQT_SLOT(slotBrushChanged( KisBrush *))); + m_brushChooser->setCurrent( 0 ); + m_brushMediator->setActiveItem( m_brushChooser->currentItem() ); + customBrushes->setResourceServer(rServer); + + m_autobrush->activate(); +} + +void KisControlFrame::createPatternsChooser(KisView * view) +{ + m_patternChooserPopup = new KisPopupFrame(m_patternWidget, "pattern_chooser_popup"); + + TQHBoxLayout * l2 = new TQHBoxLayout(m_patternChooserPopup, 2, 2, "patternpopuplayout"); + + TQTabWidget * m_patternsTab = new TQTabWidget(m_patternChooserPopup, "patternstab"); + m_patternsTab->setTabShape(TQTabWidget::Triangular); + m_patternsTab->setFocusPolicy(TQ_NoFocus); + m_patternsTab->setFont(m_font); + m_patternsTab->setMargin(1); + l2->add( m_patternsTab ); + + KisPatternChooser * chooser = new KisPatternChooser(m_patternChooserPopup, "pattern_chooser"); + chooser->setFont(m_font); + chooser->setMinimumSize(200, 150); + m_patternsTab->addTab(chooser, i18n("Patterns")); + + KisCustomPattern* customPatterns = new KisCustomPattern(m_patternsTab, "custompatterns", + i18n("Custom Pattern"), m_view); + customPatterns->setFont(m_font); + m_patternsTab->addTab( customPatterns, i18n("Custom Pattern")); + + + m_patternMediator = new KisResourceMediator( chooser, TQT_TQOBJECT(view)); + connect( m_patternMediator, TQT_SIGNAL(activatedResource(KisResource*)), view, TQT_SLOT(patternActivated(KisResource*))); + connect(customPatterns, TQT_SIGNAL(activatedResource(KisResource*)), + TQT_TQOBJECT(view), TQT_SLOT(patternActivated(KisResource*))); + + KisResourceServerBase* rServer; + rServer = KisResourceServerRegistry::instance()->get("PatternServer"); + m_patternMediator->connectServer(rServer); + + KisControlFrame::connect(view, TQT_SIGNAL(patternChanged(KisPattern *)), this, TQT_SLOT(slotPatternChanged( KisPattern *))); + chooser->setCurrent( 0 ); + m_patternMediator->setActiveItem( chooser->currentItem() ); + + customPatterns->setResourceServer(rServer); +} + + +void KisControlFrame::createGradientsChooser(KisView * view) +{ + m_gradientChooserPopup = new KisPopupFrame(m_gradientWidget, "gradient_chooser_popup"); + + TQHBoxLayout * l2 = new TQHBoxLayout(m_gradientChooserPopup, 2, 2, "gradientpopuplayout"); + + TQTabWidget * m_gradientTab = new TQTabWidget(m_gradientChooserPopup, "gradientstab"); + m_gradientTab->setTabShape(TQTabWidget::Triangular); + m_gradientTab->setFocusPolicy(TQ_NoFocus); + m_gradientTab->setFont(m_font); + m_gradientTab->setMargin(1); + + l2->add( m_gradientTab); + + KisGradientChooser * m_gradientChooser = new KisGradientChooser(m_view, m_gradientChooserPopup, "gradient_chooser"); + m_gradientChooser->setFont(m_font); + m_gradientChooser->setMinimumSize(200, 150); + m_gradientTab->addTab( m_gradientChooser, i18n("Gradients")); + + m_gradientMediator = new KisResourceMediator( m_gradientChooser, TQT_TQOBJECT(view)); + connect(m_gradientMediator, TQT_SIGNAL(activatedResource(KisResource*)), view, TQT_SLOT(gradientActivated(KisResource*))); + + KisResourceServerBase* rServer; + rServer = KisResourceServerRegistry::instance()->get("GradientServer"); + m_gradientMediator->connectServer(rServer); + + connect(view, TQT_SIGNAL(gradientChanged(KisGradient *)), this, TQT_SLOT(slotGradientChanged( KisGradient *))); + m_gradientChooser->setCurrent( 0 ); + m_gradientMediator->setActiveItem( m_gradientChooser->currentItem() ); +} + + +#include "kis_controlframe.moc" + diff --git a/chalk/ui/kis_cursor.cc b/chalk/ui/kis_cursor.cc deleted file mode 100644 index c4281eac9..000000000 --- a/chalk/ui/kis_cursor.cc +++ /dev/null @@ -1,374 +0,0 @@ -/* - * kis_cursor.cc - part of KImageShop - * - * Copyright (c) 1999 Matthias Elter - * Copyright (c) 2004 Adrian Page - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include -#include -#include -#include - -#include -#include -#include - -#include "kis_cursor.h" -#include "kis_factory.h" - -KisCursor::KisCursor() {} - -/* - * Predefined TQt cursors - */ -TQCursor KisCursor::arrowCursor() -{ - return TQt::arrowCursor; -} - -TQCursor KisCursor::upArrowCursor() -{ - return TQt::upArrowCursor; -} - -TQCursor KisCursor::crossCursor() -{ - return TQt::crossCursor; -} - -TQCursor KisCursor::waitCursor() -{ - return TQt::waitCursor; -} - -TQCursor KisCursor::ibeamCursor() -{ - return TQt::ibeamCursor; -} - -TQCursor KisCursor::sizeVerCursor() -{ - return TQt::sizeVerCursor; -} - -TQCursor KisCursor::sizeHorCursor() -{ - return TQt::sizeHorCursor; -} - -TQCursor KisCursor::sizeBDiagCursor() -{ - return TQt::sizeBDiagCursor; -} - -TQCursor KisCursor::sizeFDiagCursor() -{ - return TQt::sizeFDiagCursor; -} - -TQCursor KisCursor::sizeAllCursor() -{ - return TQt::sizeAllCursor; -} - -TQCursor KisCursor::blankCursor() -{ - return TQt::blankCursor; -} - -TQCursor KisCursor::splitVCursor() -{ - return TQt::splitVCursor; -} - -TQCursor KisCursor::splitHCursor() -{ - return TQt::splitHCursor; -} - -TQCursor KisCursor::pointingHandCursor() -{ - return TQt::pointingHandCursor; -} - - -/* - * Existing custom KimageShop cursors. Use the 'load' function for all new cursors. - */ - -TQCursor KisCursor::pickerCursor() -{ - static unsigned char picker_bits[] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x34, 0x00, 0x00, 0x7a, - 0x00, 0x00, 0x7d, 0x00, 0x80, 0x7e, 0x00, 0x60, 0x3f, 0x00, 0xd0, 0x1f, - 0x00, 0xa0, 0x0f, 0x00, 0x50, 0x07, 0x00, 0xc8, 0x06, 0x00, 0xe4, 0x02, - 0x00, 0x72, 0x01, 0x00, 0x39, 0x00, 0x80, 0x1c, 0x00, 0x40, 0x0e, 0x00, - 0x20, 0x07, 0x00, 0x90, 0x03, 0x00, 0xc8, 0x01, 0x00, 0xe4, 0x00, 0x00, - 0x74, 0x00, 0x00, 0x32, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00}; - - TQBitmap picker_bitmap(24, 24, picker_bits, true); - TQBitmap picker_mask = picker_bitmap.createHeuristicMask( false ); - - return TQCursor( picker_bitmap, picker_mask, 1, 22 ); -} - - -TQCursor KisCursor::pickerPlusCursor() -{ - static unsigned char pickerplus_bits[] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x34, 0x00, 0x00, 0x7a, - 0x00, 0x00, 0x7d, 0x00, 0x80, 0x7e, 0x00, 0x60, 0x3f, 0x00, 0xd0, 0x1f, - 0x00, 0xa0, 0x0f, 0x00, 0x50, 0x07, 0x00, 0xc8, 0x06, 0x00, 0xe4, 0x02, - 0x00, 0x72, 0x01, 0x00, 0x39, 0x0c, 0x80, 0x1c, 0x0c, 0x40, 0x0e, 0x0c, - 0x20, 0x07, 0x0c, 0x90, 0x83, 0x7f, 0xc8, 0x81, 0x7f, 0xe4, 0x00, 0x0c, - 0x74, 0x00, 0x0c, 0x32, 0x00, 0x0c, 0x0a, 0x00, 0x0c, 0x00, 0x00, 0x00}; - - TQBitmap picker_bitmap(24, 24, pickerplus_bits, true); - TQBitmap picker_mask = picker_bitmap.createHeuristicMask( false ); - - return TQCursor( picker_bitmap, picker_mask, 1, 22 ); -} - - -TQCursor KisCursor::pickerMinusCursor() -{ - static unsigned char pickerminus_bits[] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x34, 0x00, 0x00, 0x7a, - 0x00, 0x00, 0x7d, 0x00, 0x80, 0x7e, 0x00, 0x60, 0x3f, 0x00, 0xd0, 0x1f, - 0x00, 0xa0, 0x0f, 0x00, 0x50, 0x07, 0x00, 0xc8, 0x06, 0x00, 0xe4, 0x02, - 0x00, 0x72, 0x01, 0x00, 0x39, 0x00, 0x80, 0x1c, 0x00, 0x40, 0x0e, 0x00, - 0x20, 0x07, 0x00, 0x90, 0xc3, 0x7f, 0xc8, 0xc1, 0x7f, 0xe4, 0x00, 0x00, - 0x74, 0x00, 0x00, 0x32, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00}; - - TQBitmap picker_bitmap(24, 24, pickerminus_bits, true); - TQBitmap picker_mask = picker_bitmap.createHeuristicMask( false ); - - return TQCursor( picker_bitmap, picker_mask, 1, 22 ); -} - - - -TQCursor KisCursor::penCursor() -{ - static unsigned char pen_bits[] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x3a, 0x00, 0x00, 0x7d, - 0x00, 0x80, 0x7e, 0x00, 0x40, 0x7f, 0x00, 0xa0, 0x3f, 0x00, 0xd0, 0x1f, - 0x00, 0xe8, 0x0f, 0x00, 0xf4, 0x07, 0x00, 0xfa, 0x03, 0x00, 0xfd, 0x01, - 0x80, 0xfe, 0x00, 0x40, 0x7f, 0x00, 0xa0, 0x3f, 0x00, 0xf0, 0x1f, 0x00, - 0xd0, 0x0f, 0x00, 0x88, 0x07, 0x00, 0x88, 0x03, 0x00, 0xe4, 0x01, 0x00, - 0x7c, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00}; - - TQBitmap pen_bitmap( 24, 24, pen_bits, true ); - TQBitmap pen_mask = pen_bitmap.createHeuristicMask( false ); - - return TQCursor( pen_bitmap, pen_mask, 1, 22 ); -} - -TQCursor KisCursor::brushCursor() -{ - static unsigned char brush_bits[] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x68, 0x00, - 0x00, 0x00, 0xf4, 0x00, 0x00, 0x00, 0xfa, 0x00, 0x00, 0x00, 0xfd, 0x00, - 0x00, 0x80, 0x7e, 0x00, 0x00, 0x40, 0x3f, 0x00, 0x00, 0xa0, 0x1f, 0x00, - 0x00, 0xd0, 0x0f, 0x00, 0x00, 0xe8, 0x07, 0x00, 0x00, 0xf4, 0x03, 0x00, - 0x00, 0xe4, 0x01, 0x00, 0x00, 0xc2, 0x00, 0x00, 0x80, 0x41, 0x00, 0x00, - 0x40, 0x32, 0x00, 0x00, 0xa0, 0x0f, 0x00, 0x00, 0xd0, 0x0f, 0x00, 0x00, - 0xd0, 0x0f, 0x00, 0x00, 0xe8, 0x07, 0x00, 0x00, 0xf4, 0x01, 0x00, 0x00, - 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - - TQBitmap brush_bitmap( 25, 23, brush_bits, true ); - TQBitmap brush_mask = brush_bitmap.createHeuristicMask( false ); - - return TQCursor( brush_bitmap, brush_mask, 1, 21 ); -} - -TQCursor KisCursor::airbrushCursor() -{ - static unsigned char airbrush_bits[] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x68, 0x00, 0x00, 0x74, - 0x00, 0x00, 0x7a, 0xf0, 0x00, 0x3d, 0x08, 0x81, 0x1e, 0xe8, 0x41, 0x0f, - 0xe8, 0xa1, 0x07, 0xe8, 0xd1, 0x03, 0xe8, 0xe9, 0x01, 0xe8, 0xf5, 0x00, - 0xe8, 0x7b, 0x00, 0xf0, 0x33, 0x00, 0xf0, 0x23, 0x1f, 0xa0, 0x9f, 0x3f, - 0xd0, 0xff, 0x31, 0xe8, 0xf7, 0x30, 0xf4, 0x03, 0x18, 0xfc, 0x01, 0x0c, - 0xf8, 0x00, 0x06, 0x76, 0x00, 0x03, 0x36, 0x00, 0x03, 0x00, 0x00, 0x00}; - - TQBitmap airbrush_bitmap( 24, 24, airbrush_bits, true ); - TQBitmap airbrush_mask = airbrush_bitmap.createHeuristicMask( false ); - - return TQCursor( airbrush_bitmap, airbrush_mask, 1, 22 ); -} - -TQCursor KisCursor::eraserCursor() -{ - static unsigned char eraser_bits[] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x1d, 0x00, - 0x00, 0x80, 0x3e, 0x00, 0x00, 0x40, 0x7f, 0x00, 0x00, 0xa0, 0xff, 0x00, - 0x00, 0xd0, 0xff, 0x00, 0x00, 0xe8, 0x7f, 0x00, 0x00, 0xf4, 0x3f, 0x00, - 0x00, 0xfe, 0x1f, 0x00, 0x00, 0xf9, 0x0f, 0x00, 0x80, 0xf2, 0x07, 0x00, - 0x40, 0xe7, 0x03, 0x00, 0xa0, 0xcf, 0x01, 0x00, 0xd0, 0x9f, 0x00, 0x00, - 0xe8, 0x7f, 0x00, 0x00, 0xfc, 0x3f, 0x00, 0x00, 0xf2, 0x1f, 0x00, 0x00, - 0xe2, 0x0f, 0x00, 0x00, 0xc4, 0x07, 0x00, 0x00, 0x88, 0x03, 0x00, 0x00, - 0x10, 0x01, 0x00, 0x00, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - - TQBitmap eraser_bitmap( 25, 24, eraser_bits, true ); - TQBitmap eraser_mask = eraser_bitmap.createHeuristicMask( false ); - - return TQCursor( eraser_bitmap, eraser_mask, 7, 22 ); -} - -TQCursor KisCursor::fillerCursor() -{ - static unsigned char filler_bits[] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x28, 0x00, - 0x00, 0x54, 0x00, 0x00, 0x4e, 0x00, 0x00, 0x85, 0x00, 0x80, 0x0a, 0x01, - 0x40, 0x11, 0x01, 0xe0, 0x00, 0x02, 0x58, 0x01, 0x04, 0x2c, 0x02, 0x04, - 0x44, 0x04, 0x08, 0x0c, 0x08, 0x18, 0x3c, 0x00, 0x14, 0x5c, 0x00, 0x0a, - 0x9c, 0x01, 0x05, 0x1c, 0x82, 0x02, 0x18, 0x4c, 0x01, 0x18, 0xb0, 0x00, - 0x08, 0x60, 0x00, 0x00, 0x00, 0x00}; - - TQBitmap filler_bitmap( 22, 22, filler_bits, true ); - TQBitmap filler_mask = filler_bitmap.createHeuristicMask( false ); - - return TQCursor( filler_bitmap, filler_mask, 3, 20 ); -} - -TQCursor KisCursor::colorChangerCursor() -{ - static unsigned char colorChanger_bits[] = { - 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00, 0x10, 0x01, 0x0e, 0x08, 0x02, 0x11, - 0x04, 0x82, 0x20, 0x64, 0x84, 0x20, 0x92, 0x44, 0x46, 0x12, 0x49, 0x5f, - 0x12, 0x31, 0x5f, 0x22, 0x01, 0x5f, 0xc2, 0x00, 0x4e, 0x02, 0x00, 0x40, - 0xc2, 0x00, 0x46, 0xe2, 0x01, 0x4f, 0xe4, 0x19, 0x2f, 0xe4, 0x3d, 0x2f, - 0xe8, 0x3d, 0x17, 0xd0, 0x3c, 0x10, 0x20, 0x38, 0x08, 0x40, 0x00, 0x06, - 0x80, 0x81, 0x01, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x00}; - - TQBitmap colorChanger_bitmap( 24, 23, colorChanger_bits, true ); - TQBitmap colorChanger_mask = colorChanger_bitmap.createHeuristicMask( false ); - - return TQCursor( colorChanger_bitmap, colorChanger_mask, 12, 10 ); -} - -TQCursor KisCursor::zoomCursor() -{ - static unsigned char zoom_bits[] = { - 0x00, 0x00, 0x00, 0xc0, 0x0f, 0x00, 0xf0, 0x3f, 0x00, 0x38, 0x70, 0x00, - 0x8c, 0xcf, 0x00, 0x0c, 0xdf, 0x00, 0x36, 0xbf, 0x01, 0xb6, 0xbf, 0x01, - 0xf6, 0xbf, 0x01, 0xf6, 0xbf, 0x01, 0xe6, 0x9f, 0x00, 0xcc, 0xcf, 0x00, - 0x9c, 0xe7, 0x01, 0x38, 0x70, 0x03, 0xf0, 0xbf, 0x05, 0xc0, 0xef, 0x0b, - 0x00, 0xc0, 0x17, 0x00, 0x80, 0x2f, 0x00, 0x00, 0x5f, 0x00, 0x00, 0x7e, - 0x00, 0x00, 0x7c, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00}; - - TQBitmap zoom_bitmap( 24, 23, zoom_bits, true ); - TQBitmap zoom_mask = zoom_bitmap.createHeuristicMask( false ); - - return TQCursor( zoom_bitmap, zoom_mask, 9, 8 ); -} - -TQCursor KisCursor::moveCursor() -{ - static unsigned char move_bits[] = { - 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x7e, 0x00, - 0x00, 0xff, 0x00, 0x00, 0x18, 0x00, 0x00, 0x18, 0x00, 0x00, 0x18, 0x00, - 0x10, 0x18, 0x08, 0x18, 0x18, 0x18, 0x1c, 0x18, 0x38, 0xfe, 0xff, 0x7f, - 0xfe, 0xff, 0x7f, 0x1c, 0x18, 0x38, 0x18, 0x18, 0x18, 0x10, 0x18, 0x08, - 0x00, 0x18, 0x00, 0x00, 0x18, 0x00, 0x00, 0x18, 0x00, 0x00, 0xff, 0x00, - 0x00, 0x7e, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00}; - - TQBitmap move_bitmap( 24, 24, move_bits, true ); - TQBitmap move_mask = move_bitmap.createHeuristicMask( false ); - - return TQCursor( move_bitmap, move_mask, 12, 11 ); -} - -TQCursor KisCursor::handCursor() -{ - return KCursor::handCursor(); -} - -TQCursor KisCursor::selectCursor() -{ - static unsigned char select_bits[] = { - 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, - 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, - 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0xff, 0xff, 0x7f, - 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, - 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, - 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00}; - - TQBitmap select_bitmap(23, 23, select_bits, true); - TQBitmap select_mask = select_bitmap.createHeuristicMask( false ); - - return TQCursor( select_bitmap, select_mask, 11, 11 ); -} - -TQCursor KisCursor::openHandCursor() -{ - return load("openhand_cursor.xpm"); -} - -TQCursor KisCursor::closedHandCursor() -{ - return load("closedhand_cursor.xpm"); -} - -TQCursor KisCursor::rotateCursor() -{ - return load("rotate_cursor.xpm"); -} - -TQCursor KisCursor::load(const TQString & iconName, int hotspotX, int hotspotY) -{ - TQString filename = KisFactory::instance()->dirs()->findResource("kis_pics", iconName); - TQImage cursorImage; - - cursorImage.load(filename); - Q_ASSERT(!cursorImage.isNull()); - Q_ASSERT(cursorImage.hasAlphaBuffer()); - - TQBitmap bitmap(cursorImage.width(), cursorImage.height()); - TQBitmap mask(cursorImage.width(), cursorImage.height()); - - TQPainter bitmapPainter(&bitmap); - TQPainter maskPainter(&mask); - - for (TQ_INT32 x = 0; x < cursorImage.width(); ++x) { - for (TQ_INT32 y = 0; y < cursorImage.height(); ++y) { - - TQRgb pixel = cursorImage.pixel(x, y); - - if (tqAlpha(pixel) < 128) { - bitmapPainter.setPen(TQt::color0); - maskPainter.setPen(TQt::color0); - } else { - maskPainter.setPen(TQt::color1); - - if (tqGray(pixel) < 128) { - bitmapPainter.setPen(TQt::color1); - } else { - bitmapPainter.setPen(TQt::color0); - } - } - - bitmapPainter.drawPoint(x, y); - maskPainter.drawPoint(x, y); - } - } - - return TQCursor(bitmap, mask, hotspotX, hotspotY); -} - diff --git a/chalk/ui/kis_cursor.cpp b/chalk/ui/kis_cursor.cpp new file mode 100644 index 000000000..146dc2863 --- /dev/null +++ b/chalk/ui/kis_cursor.cpp @@ -0,0 +1,374 @@ +/* + * kis_cursor.cpp - part of KImageShop + * + * Copyright (c) 1999 Matthias Elter + * Copyright (c) 2004 Adrian Page + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include +#include +#include +#include + +#include +#include +#include + +#include "kis_cursor.h" +#include "kis_factory.h" + +KisCursor::KisCursor() {} + +/* + * Predefined TQt cursors + */ +TQCursor KisCursor::arrowCursor() +{ + return TQt::arrowCursor; +} + +TQCursor KisCursor::upArrowCursor() +{ + return TQt::upArrowCursor; +} + +TQCursor KisCursor::crossCursor() +{ + return TQt::crossCursor; +} + +TQCursor KisCursor::waitCursor() +{ + return TQt::waitCursor; +} + +TQCursor KisCursor::ibeamCursor() +{ + return TQt::ibeamCursor; +} + +TQCursor KisCursor::sizeVerCursor() +{ + return TQt::sizeVerCursor; +} + +TQCursor KisCursor::sizeHorCursor() +{ + return TQt::sizeHorCursor; +} + +TQCursor KisCursor::sizeBDiagCursor() +{ + return TQt::sizeBDiagCursor; +} + +TQCursor KisCursor::sizeFDiagCursor() +{ + return TQt::sizeFDiagCursor; +} + +TQCursor KisCursor::sizeAllCursor() +{ + return TQt::sizeAllCursor; +} + +TQCursor KisCursor::blankCursor() +{ + return TQt::blankCursor; +} + +TQCursor KisCursor::splitVCursor() +{ + return TQt::splitVCursor; +} + +TQCursor KisCursor::splitHCursor() +{ + return TQt::splitHCursor; +} + +TQCursor KisCursor::pointingHandCursor() +{ + return TQt::pointingHandCursor; +} + + +/* + * Existing custom KimageShop cursors. Use the 'load' function for all new cursors. + */ + +TQCursor KisCursor::pickerCursor() +{ + static unsigned char picker_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x34, 0x00, 0x00, 0x7a, + 0x00, 0x00, 0x7d, 0x00, 0x80, 0x7e, 0x00, 0x60, 0x3f, 0x00, 0xd0, 0x1f, + 0x00, 0xa0, 0x0f, 0x00, 0x50, 0x07, 0x00, 0xc8, 0x06, 0x00, 0xe4, 0x02, + 0x00, 0x72, 0x01, 0x00, 0x39, 0x00, 0x80, 0x1c, 0x00, 0x40, 0x0e, 0x00, + 0x20, 0x07, 0x00, 0x90, 0x03, 0x00, 0xc8, 0x01, 0x00, 0xe4, 0x00, 0x00, + 0x74, 0x00, 0x00, 0x32, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00}; + + TQBitmap picker_bitmap(24, 24, picker_bits, true); + TQBitmap picker_mask = picker_bitmap.createHeuristicMask( false ); + + return TQCursor( picker_bitmap, picker_mask, 1, 22 ); +} + + +TQCursor KisCursor::pickerPlusCursor() +{ + static unsigned char pickerplus_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x34, 0x00, 0x00, 0x7a, + 0x00, 0x00, 0x7d, 0x00, 0x80, 0x7e, 0x00, 0x60, 0x3f, 0x00, 0xd0, 0x1f, + 0x00, 0xa0, 0x0f, 0x00, 0x50, 0x07, 0x00, 0xc8, 0x06, 0x00, 0xe4, 0x02, + 0x00, 0x72, 0x01, 0x00, 0x39, 0x0c, 0x80, 0x1c, 0x0c, 0x40, 0x0e, 0x0c, + 0x20, 0x07, 0x0c, 0x90, 0x83, 0x7f, 0xc8, 0x81, 0x7f, 0xe4, 0x00, 0x0c, + 0x74, 0x00, 0x0c, 0x32, 0x00, 0x0c, 0x0a, 0x00, 0x0c, 0x00, 0x00, 0x00}; + + TQBitmap picker_bitmap(24, 24, pickerplus_bits, true); + TQBitmap picker_mask = picker_bitmap.createHeuristicMask( false ); + + return TQCursor( picker_bitmap, picker_mask, 1, 22 ); +} + + +TQCursor KisCursor::pickerMinusCursor() +{ + static unsigned char pickerminus_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x34, 0x00, 0x00, 0x7a, + 0x00, 0x00, 0x7d, 0x00, 0x80, 0x7e, 0x00, 0x60, 0x3f, 0x00, 0xd0, 0x1f, + 0x00, 0xa0, 0x0f, 0x00, 0x50, 0x07, 0x00, 0xc8, 0x06, 0x00, 0xe4, 0x02, + 0x00, 0x72, 0x01, 0x00, 0x39, 0x00, 0x80, 0x1c, 0x00, 0x40, 0x0e, 0x00, + 0x20, 0x07, 0x00, 0x90, 0xc3, 0x7f, 0xc8, 0xc1, 0x7f, 0xe4, 0x00, 0x00, + 0x74, 0x00, 0x00, 0x32, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00}; + + TQBitmap picker_bitmap(24, 24, pickerminus_bits, true); + TQBitmap picker_mask = picker_bitmap.createHeuristicMask( false ); + + return TQCursor( picker_bitmap, picker_mask, 1, 22 ); +} + + + +TQCursor KisCursor::penCursor() +{ + static unsigned char pen_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x3a, 0x00, 0x00, 0x7d, + 0x00, 0x80, 0x7e, 0x00, 0x40, 0x7f, 0x00, 0xa0, 0x3f, 0x00, 0xd0, 0x1f, + 0x00, 0xe8, 0x0f, 0x00, 0xf4, 0x07, 0x00, 0xfa, 0x03, 0x00, 0xfd, 0x01, + 0x80, 0xfe, 0x00, 0x40, 0x7f, 0x00, 0xa0, 0x3f, 0x00, 0xf0, 0x1f, 0x00, + 0xd0, 0x0f, 0x00, 0x88, 0x07, 0x00, 0x88, 0x03, 0x00, 0xe4, 0x01, 0x00, + 0x7c, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00}; + + TQBitmap pen_bitmap( 24, 24, pen_bits, true ); + TQBitmap pen_mask = pen_bitmap.createHeuristicMask( false ); + + return TQCursor( pen_bitmap, pen_mask, 1, 22 ); +} + +TQCursor KisCursor::brushCursor() +{ + static unsigned char brush_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x68, 0x00, + 0x00, 0x00, 0xf4, 0x00, 0x00, 0x00, 0xfa, 0x00, 0x00, 0x00, 0xfd, 0x00, + 0x00, 0x80, 0x7e, 0x00, 0x00, 0x40, 0x3f, 0x00, 0x00, 0xa0, 0x1f, 0x00, + 0x00, 0xd0, 0x0f, 0x00, 0x00, 0xe8, 0x07, 0x00, 0x00, 0xf4, 0x03, 0x00, + 0x00, 0xe4, 0x01, 0x00, 0x00, 0xc2, 0x00, 0x00, 0x80, 0x41, 0x00, 0x00, + 0x40, 0x32, 0x00, 0x00, 0xa0, 0x0f, 0x00, 0x00, 0xd0, 0x0f, 0x00, 0x00, + 0xd0, 0x0f, 0x00, 0x00, 0xe8, 0x07, 0x00, 0x00, 0xf4, 0x01, 0x00, 0x00, + 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + + TQBitmap brush_bitmap( 25, 23, brush_bits, true ); + TQBitmap brush_mask = brush_bitmap.createHeuristicMask( false ); + + return TQCursor( brush_bitmap, brush_mask, 1, 21 ); +} + +TQCursor KisCursor::airbrushCursor() +{ + static unsigned char airbrush_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x68, 0x00, 0x00, 0x74, + 0x00, 0x00, 0x7a, 0xf0, 0x00, 0x3d, 0x08, 0x81, 0x1e, 0xe8, 0x41, 0x0f, + 0xe8, 0xa1, 0x07, 0xe8, 0xd1, 0x03, 0xe8, 0xe9, 0x01, 0xe8, 0xf5, 0x00, + 0xe8, 0x7b, 0x00, 0xf0, 0x33, 0x00, 0xf0, 0x23, 0x1f, 0xa0, 0x9f, 0x3f, + 0xd0, 0xff, 0x31, 0xe8, 0xf7, 0x30, 0xf4, 0x03, 0x18, 0xfc, 0x01, 0x0c, + 0xf8, 0x00, 0x06, 0x76, 0x00, 0x03, 0x36, 0x00, 0x03, 0x00, 0x00, 0x00}; + + TQBitmap airbrush_bitmap( 24, 24, airbrush_bits, true ); + TQBitmap airbrush_mask = airbrush_bitmap.createHeuristicMask( false ); + + return TQCursor( airbrush_bitmap, airbrush_mask, 1, 22 ); +} + +TQCursor KisCursor::eraserCursor() +{ + static unsigned char eraser_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x1d, 0x00, + 0x00, 0x80, 0x3e, 0x00, 0x00, 0x40, 0x7f, 0x00, 0x00, 0xa0, 0xff, 0x00, + 0x00, 0xd0, 0xff, 0x00, 0x00, 0xe8, 0x7f, 0x00, 0x00, 0xf4, 0x3f, 0x00, + 0x00, 0xfe, 0x1f, 0x00, 0x00, 0xf9, 0x0f, 0x00, 0x80, 0xf2, 0x07, 0x00, + 0x40, 0xe7, 0x03, 0x00, 0xa0, 0xcf, 0x01, 0x00, 0xd0, 0x9f, 0x00, 0x00, + 0xe8, 0x7f, 0x00, 0x00, 0xfc, 0x3f, 0x00, 0x00, 0xf2, 0x1f, 0x00, 0x00, + 0xe2, 0x0f, 0x00, 0x00, 0xc4, 0x07, 0x00, 0x00, 0x88, 0x03, 0x00, 0x00, + 0x10, 0x01, 0x00, 0x00, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + + TQBitmap eraser_bitmap( 25, 24, eraser_bits, true ); + TQBitmap eraser_mask = eraser_bitmap.createHeuristicMask( false ); + + return TQCursor( eraser_bitmap, eraser_mask, 7, 22 ); +} + +TQCursor KisCursor::fillerCursor() +{ + static unsigned char filler_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x28, 0x00, + 0x00, 0x54, 0x00, 0x00, 0x4e, 0x00, 0x00, 0x85, 0x00, 0x80, 0x0a, 0x01, + 0x40, 0x11, 0x01, 0xe0, 0x00, 0x02, 0x58, 0x01, 0x04, 0x2c, 0x02, 0x04, + 0x44, 0x04, 0x08, 0x0c, 0x08, 0x18, 0x3c, 0x00, 0x14, 0x5c, 0x00, 0x0a, + 0x9c, 0x01, 0x05, 0x1c, 0x82, 0x02, 0x18, 0x4c, 0x01, 0x18, 0xb0, 0x00, + 0x08, 0x60, 0x00, 0x00, 0x00, 0x00}; + + TQBitmap filler_bitmap( 22, 22, filler_bits, true ); + TQBitmap filler_mask = filler_bitmap.createHeuristicMask( false ); + + return TQCursor( filler_bitmap, filler_mask, 3, 20 ); +} + +TQCursor KisCursor::colorChangerCursor() +{ + static unsigned char colorChanger_bits[] = { + 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00, 0x10, 0x01, 0x0e, 0x08, 0x02, 0x11, + 0x04, 0x82, 0x20, 0x64, 0x84, 0x20, 0x92, 0x44, 0x46, 0x12, 0x49, 0x5f, + 0x12, 0x31, 0x5f, 0x22, 0x01, 0x5f, 0xc2, 0x00, 0x4e, 0x02, 0x00, 0x40, + 0xc2, 0x00, 0x46, 0xe2, 0x01, 0x4f, 0xe4, 0x19, 0x2f, 0xe4, 0x3d, 0x2f, + 0xe8, 0x3d, 0x17, 0xd0, 0x3c, 0x10, 0x20, 0x38, 0x08, 0x40, 0x00, 0x06, + 0x80, 0x81, 0x01, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x00}; + + TQBitmap colorChanger_bitmap( 24, 23, colorChanger_bits, true ); + TQBitmap colorChanger_mask = colorChanger_bitmap.createHeuristicMask( false ); + + return TQCursor( colorChanger_bitmap, colorChanger_mask, 12, 10 ); +} + +TQCursor KisCursor::zoomCursor() +{ + static unsigned char zoom_bits[] = { + 0x00, 0x00, 0x00, 0xc0, 0x0f, 0x00, 0xf0, 0x3f, 0x00, 0x38, 0x70, 0x00, + 0x8c, 0xcf, 0x00, 0x0c, 0xdf, 0x00, 0x36, 0xbf, 0x01, 0xb6, 0xbf, 0x01, + 0xf6, 0xbf, 0x01, 0xf6, 0xbf, 0x01, 0xe6, 0x9f, 0x00, 0xcc, 0xcf, 0x00, + 0x9c, 0xe7, 0x01, 0x38, 0x70, 0x03, 0xf0, 0xbf, 0x05, 0xc0, 0xef, 0x0b, + 0x00, 0xc0, 0x17, 0x00, 0x80, 0x2f, 0x00, 0x00, 0x5f, 0x00, 0x00, 0x7e, + 0x00, 0x00, 0x7c, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00}; + + TQBitmap zoom_bitmap( 24, 23, zoom_bits, true ); + TQBitmap zoom_mask = zoom_bitmap.createHeuristicMask( false ); + + return TQCursor( zoom_bitmap, zoom_mask, 9, 8 ); +} + +TQCursor KisCursor::moveCursor() +{ + static unsigned char move_bits[] = { + 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x7e, 0x00, + 0x00, 0xff, 0x00, 0x00, 0x18, 0x00, 0x00, 0x18, 0x00, 0x00, 0x18, 0x00, + 0x10, 0x18, 0x08, 0x18, 0x18, 0x18, 0x1c, 0x18, 0x38, 0xfe, 0xff, 0x7f, + 0xfe, 0xff, 0x7f, 0x1c, 0x18, 0x38, 0x18, 0x18, 0x18, 0x10, 0x18, 0x08, + 0x00, 0x18, 0x00, 0x00, 0x18, 0x00, 0x00, 0x18, 0x00, 0x00, 0xff, 0x00, + 0x00, 0x7e, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00}; + + TQBitmap move_bitmap( 24, 24, move_bits, true ); + TQBitmap move_mask = move_bitmap.createHeuristicMask( false ); + + return TQCursor( move_bitmap, move_mask, 12, 11 ); +} + +TQCursor KisCursor::handCursor() +{ + return KCursor::handCursor(); +} + +TQCursor KisCursor::selectCursor() +{ + static unsigned char select_bits[] = { + 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, + 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, + 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0xff, 0xff, 0x7f, + 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, + 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, + 0x00, 0x08, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00}; + + TQBitmap select_bitmap(23, 23, select_bits, true); + TQBitmap select_mask = select_bitmap.createHeuristicMask( false ); + + return TQCursor( select_bitmap, select_mask, 11, 11 ); +} + +TQCursor KisCursor::openHandCursor() +{ + return load("openhand_cursor.xpm"); +} + +TQCursor KisCursor::closedHandCursor() +{ + return load("closedhand_cursor.xpm"); +} + +TQCursor KisCursor::rotateCursor() +{ + return load("rotate_cursor.xpm"); +} + +TQCursor KisCursor::load(const TQString & iconName, int hotspotX, int hotspotY) +{ + TQString filename = KisFactory::instance()->dirs()->findResource("kis_pics", iconName); + TQImage cursorImage; + + cursorImage.load(filename); + Q_ASSERT(!cursorImage.isNull()); + Q_ASSERT(cursorImage.hasAlphaBuffer()); + + TQBitmap bitmap(cursorImage.width(), cursorImage.height()); + TQBitmap mask(cursorImage.width(), cursorImage.height()); + + TQPainter bitmapPainter(&bitmap); + TQPainter maskPainter(&mask); + + for (TQ_INT32 x = 0; x < cursorImage.width(); ++x) { + for (TQ_INT32 y = 0; y < cursorImage.height(); ++y) { + + TQRgb pixel = cursorImage.pixel(x, y); + + if (tqAlpha(pixel) < 128) { + bitmapPainter.setPen(TQt::color0); + maskPainter.setPen(TQt::color0); + } else { + maskPainter.setPen(TQt::color1); + + if (tqGray(pixel) < 128) { + bitmapPainter.setPen(TQt::color1); + } else { + bitmapPainter.setPen(TQt::color0); + } + } + + bitmapPainter.drawPoint(x, y); + maskPainter.drawPoint(x, y); + } + } + + return TQCursor(bitmap, mask, hotspotX, hotspotY); +} + diff --git a/chalk/ui/kis_custom_brush.cc b/chalk/ui/kis_custom_brush.cpp similarity index 100% rename from chalk/ui/kis_custom_brush.cc rename to chalk/ui/kis_custom_brush.cpp diff --git a/chalk/ui/kis_custom_image_widget.cc b/chalk/ui/kis_custom_image_widget.cpp similarity index 100% rename from chalk/ui/kis_custom_image_widget.cc rename to chalk/ui/kis_custom_image_widget.cpp diff --git a/chalk/ui/kis_custom_palette.cc b/chalk/ui/kis_custom_palette.cpp similarity index 100% rename from chalk/ui/kis_custom_palette.cc rename to chalk/ui/kis_custom_palette.cpp diff --git a/chalk/ui/kis_custom_pattern.cc b/chalk/ui/kis_custom_pattern.cpp similarity index 100% rename from chalk/ui/kis_custom_pattern.cc rename to chalk/ui/kis_custom_pattern.cpp diff --git a/chalk/ui/kis_dlg_adj_layer_props.cc b/chalk/ui/kis_dlg_adj_layer_props.cpp similarity index 100% rename from chalk/ui/kis_dlg_adj_layer_props.cc rename to chalk/ui/kis_dlg_adj_layer_props.cpp diff --git a/chalk/ui/kis_dlg_adjustment_layer.cc b/chalk/ui/kis_dlg_adjustment_layer.cpp similarity index 100% rename from chalk/ui/kis_dlg_adjustment_layer.cc rename to chalk/ui/kis_dlg_adjustment_layer.cpp diff --git a/chalk/ui/kis_dlg_apply_profile.cc b/chalk/ui/kis_dlg_apply_profile.cpp similarity index 100% rename from chalk/ui/kis_dlg_apply_profile.cc rename to chalk/ui/kis_dlg_apply_profile.cpp diff --git a/chalk/ui/kis_dlg_image_properties.cc b/chalk/ui/kis_dlg_image_properties.cpp similarity index 100% rename from chalk/ui/kis_dlg_image_properties.cc rename to chalk/ui/kis_dlg_image_properties.cpp diff --git a/chalk/ui/kis_dlg_layer_properties.cc b/chalk/ui/kis_dlg_layer_properties.cpp similarity index 100% rename from chalk/ui/kis_dlg_layer_properties.cc rename to chalk/ui/kis_dlg_layer_properties.cpp diff --git a/chalk/ui/kis_dlg_new_layer.cc b/chalk/ui/kis_dlg_new_layer.cpp similarity index 100% rename from chalk/ui/kis_dlg_new_layer.cc rename to chalk/ui/kis_dlg_new_layer.cpp diff --git a/chalk/ui/kis_dlg_preferences.cc b/chalk/ui/kis_dlg_preferences.cc deleted file mode 100644 index 61811d31f..000000000 --- a/chalk/ui/kis_dlg_preferences.cc +++ /dev/null @@ -1,821 +0,0 @@ -/* - * preferencesdlg.cc - part of KImageShop - * - * Copyright (c) 1999 Michael Koch - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef HAVE_GL -#include -#endif - -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "squeezedcombobox.h" -#include "kis_cmb_idlist.h" -#include "kis_colorspace.h" -#include "kis_colorspace_factory_registry.h" -#include "kis_cursor.h" -#include "kis_config.h" -#include "kis_dlg_preferences.h" -#include "kis_factory.h" -#include "kis_id.h" -#include "kis_meta_registry.h" -#include "kis_profile.h" - -#include "kis_canvas.h" - -#include "wdgcolorsettings.h" -#include "wdgperformancesettings.h" -#include "wdggeneralsettings.h" - -// for the performance update -#include "tiles/kis_tilemanager.h" - -GeneralTab::GeneralTab( TQWidget *_parent, const char *_name ) - : WdgGeneralSettings( _parent, _name ) -{ - - KisConfig cfg; - - m_cmbCursorShape->setCurrentItem(cfg.cursorStyle()); - grpDockability->setButton(cfg.dockability()); - numDockerFontSize->setValue((int)cfg.dockerFontSize()); -} - -void GeneralTab::setDefault() -{ - KisConfig cfg; - - m_cmbCursorShape->setCurrentItem( cfg.getDefaultCursorStyle()); - grpDockability->setButton(cfg.getDefaultDockability()); - numDockerFontSize->setValue((int)(cfg.getDefaultDockerFontSize())); -} - -enumCursorStyle GeneralTab::cursorStyle() -{ - return (enumCursorStyle)m_cmbCursorShape->currentItem(); -} - -enumKoDockability GeneralTab::dockability() -{ - return (enumKoDockability)grpDockability->selectedId(); -} - -float GeneralTab::dockerFontSize() -{ - return (float)numDockerFontSize->value(); -} - -//--------------------------------------------------------------------------------------------------- - -ColorSettingsTab::ColorSettingsTab(TQWidget *parent, const char *name ) - : TQWidget(parent, name) -{ - // XXX: Make sure only profiles that fit the specified color model - // are shown in the profile combos - - TQGridLayout * l = new TQGridLayout( this, 1, 1, KDialog::marginHint(), KDialog::spacingHint()); - l->setMargin(0); - m_page = new WdgColorSettings(this); - l->addWidget( m_page, 0, 0); - - KisConfig cfg; - - m_page->cmbWorkingColorSpace->setIDList(KisMetaRegistry::instance()->csRegistry()->listKeys()); - m_page->cmbWorkingColorSpace->setCurrentText(cfg.workingColorSpace()); - - m_page->cmbPrintingColorSpace->setIDList(KisMetaRegistry::instance()->csRegistry()->listKeys()); - m_page->cmbPrintingColorSpace->setCurrentText(cfg.printerColorSpace()); - - refillMonitorProfiles(KisID("RGBA", "")); - refillPrintProfiles(KisID(cfg.printerColorSpace(), "")); - - if(m_page->cmbMonitorProfile->contains(cfg.monitorProfile())) - m_page->cmbMonitorProfile->setCurrentText(cfg.monitorProfile()); - if(m_page->cmbPrintProfile->contains(cfg.printerProfile())) - m_page->cmbPrintProfile->setCurrentText(cfg.printerProfile()); - m_page->chkBlackpoint->setChecked(cfg.useBlackPointCompensation()); - m_page->grpPasteBehaviour->setButton(cfg.pasteBehaviour()); - m_page->cmbMonitorIntent->setCurrentItem(cfg.renderIntent()); - - connect(m_page->cmbPrintingColorSpace, TQT_SIGNAL(activated(const KisID &)), - this, TQT_SLOT(refillPrintProfiles(const KisID &))); -} - -void ColorSettingsTab::setDefault() -{ - m_page->cmbWorkingColorSpace->setCurrentText("RGBA"); - - m_page->cmbPrintingColorSpace->setCurrentText("CMYK"); - refillPrintProfiles(KisID("CMYK", "")); - - m_page->chkBlackpoint->setChecked(false); - m_page->cmbMonitorIntent->setCurrentItem(INTENT_PERCEPTUAL); - m_page->grpPasteBehaviour->setButton(2); -} - - -void ColorSettingsTab::refillMonitorProfiles(const KisID & s) -{ - KisColorSpaceFactory * csf = KisMetaRegistry::instance()->csRegistry()->get(s); - - m_page->cmbMonitorProfile->clear(); - - if ( !csf ) - return; - - TQValueVector profileList = KisMetaRegistry::instance()->csRegistry()->profilesFor( csf ); - TQValueVector ::iterator it; - for ( it = profileList.begin(); it != profileList.end(); ++it ) { - if ((*it)->deviceClass() == icSigDisplayClass) - m_page->cmbMonitorProfile->insertItem((*it)->productName()); - } - - m_page->cmbMonitorProfile->setCurrentText(csf->defaultProfile()); -} - -void ColorSettingsTab::refillPrintProfiles(const KisID & s) -{ - KisColorSpaceFactory * csf = KisMetaRegistry::instance()->csRegistry()->get(s); - - m_page->cmbPrintProfile->clear(); - - if ( !csf ) - return; - - TQValueVector profileList = KisMetaRegistry::instance()->csRegistry()->profilesFor( csf ); - TQValueVector ::iterator it; - for ( it = profileList.begin(); it != profileList.end(); ++it ) { - if ((*it)->deviceClass() == icSigOutputClass) - m_page->cmbPrintProfile->insertItem((*it)->productName()); - } - - m_page->cmbPrintProfile->setCurrentText(csf->defaultProfile()); -} - -//--------------------------------------------------------------------------------------------------- - -PerformanceTab::PerformanceTab(TQWidget *parent, const char *name ) - : WdgPerformanceSettings(parent, name) -{ - // XXX: Make sure only profiles that fit the specified color model - // are shown in the profile combos - - KisConfig cfg; - - // it's scaled from 0 - 6, but the config is in 0 - 300 - m_swappiness->setValue(cfg.swappiness() / 50); - m_maxTiles->setValue(cfg.maxTilesInMem()); -} - -void PerformanceTab::setDefault() -{ - m_swappiness->setValue(3); - m_maxTiles->setValue(500); -} - -//--------------------------------------------------------------------------------------------------- - -TabletSettingsTab::TabletSettingsTab( TQWidget *parent, const char *name) - : WdgTabletSettings( parent, name ) -{ -#ifdef EXTENDED_X11_TABLET_SUPPORT - initTabletDevices(); -#else - grpTabletDevices->hide(); -#endif -} - -void TabletSettingsTab::setDefault() -{ -} - -void TabletSettingsTab::applySettings() -{ - -#ifdef EXTENDED_X11_TABLET_SUPPORT - applyTabletDeviceSettings(); -#endif -} - -#ifdef EXTENDED_X11_TABLET_SUPPORT -TabletSettingsTab::DeviceSettings::DeviceSettings(KisCanvasWidget::X11TabletDevice *tabletDevice, bool enabled, - TQ_INT32 xAxis, TQ_INT32 yAxis, TQ_INT32 pressureAxis, - TQ_INT32 xTiltAxis, TQ_INT32 yTiltAxis, TQ_INT32 wheelAxis, - TQ_INT32 toolIDAxis, TQ_INT32 serialNumberAxis) - : m_tabletDevice(tabletDevice), - m_enabled(enabled), - m_xAxis(xAxis), - m_yAxis(yAxis), - m_pressureAxis(pressureAxis), - m_xTiltAxis(xTiltAxis), - m_yTiltAxis(yTiltAxis), - m_wheelAxis(wheelAxis), - m_toolIDAxis(toolIDAxis), - m_serialNumberAxis(serialNumberAxis) -{ -} - -TabletSettingsTab::DeviceSettings::DeviceSettings() - : m_tabletDevice(0), - m_enabled(false), - m_xAxis(KisCanvasWidget::X11TabletDevice::NoAxis), - m_yAxis(KisCanvasWidget::X11TabletDevice::NoAxis), - m_pressureAxis(KisCanvasWidget::X11TabletDevice::NoAxis), - m_xTiltAxis(KisCanvasWidget::X11TabletDevice::NoAxis), - m_yTiltAxis(KisCanvasWidget::X11TabletDevice::NoAxis), - m_wheelAxis(KisCanvasWidget::X11TabletDevice::NoAxis), - m_toolIDAxis(KisCanvasWidget::X11TabletDevice::NoAxis), - m_serialNumberAxis(KisCanvasWidget::X11TabletDevice::NoAxis) -{ -} - -void TabletSettingsTab::DeviceSettings::applySettings() -{ - m_tabletDevice->setEnabled(enabled()); - m_tabletDevice->setXAxis(xAxis()); - m_tabletDevice->setYAxis(yAxis()); - m_tabletDevice->setPressureAxis(pressureAxis()); - m_tabletDevice->setXTiltAxis(xTiltAxis()); - m_tabletDevice->setYTiltAxis(yTiltAxis()); - m_tabletDevice->setWheelAxis(wheelAxis()); - m_tabletDevice->setToolIDAxis(toolIDAxis()); - m_tabletDevice->setSerialNumberAxis(serialNumberAxis()); - m_tabletDevice->writeSettingsToConfig(); -} - -void TabletSettingsTab::DeviceSettings::setEnabled(bool enabled) -{ - m_enabled = enabled; -} - -bool TabletSettingsTab::DeviceSettings::enabled() const -{ - return m_enabled; -} - -TQ_INT32 TabletSettingsTab::DeviceSettings::numAxes() const -{ - return m_tabletDevice->numAxes(); -} - -void TabletSettingsTab::DeviceSettings::setXAxis(TQ_INT32 axis) -{ - m_xAxis = axis; -} - -void TabletSettingsTab::DeviceSettings::setYAxis(TQ_INT32 axis) -{ - m_yAxis = axis; -} - -void TabletSettingsTab::DeviceSettings::setPressureAxis(TQ_INT32 axis) -{ - m_pressureAxis = axis; -} - -void TabletSettingsTab::DeviceSettings::setXTiltAxis(TQ_INT32 axis) -{ - m_xTiltAxis = axis; -} - -void TabletSettingsTab::DeviceSettings::setYTiltAxis(TQ_INT32 axis) -{ - m_yTiltAxis = axis; -} - -void TabletSettingsTab::DeviceSettings::setWheelAxis(TQ_INT32 axis) -{ - m_wheelAxis = axis; -} - -void TabletSettingsTab::DeviceSettings::setToolIDAxis(TQ_INT32 axis) -{ - m_toolIDAxis = axis; -} - -void TabletSettingsTab::DeviceSettings::setSerialNumberAxis(TQ_INT32 axis) -{ - m_serialNumberAxis = axis; -} - -TQ_INT32 TabletSettingsTab::DeviceSettings::xAxis() const -{ - return m_xAxis; -} - -TQ_INT32 TabletSettingsTab::DeviceSettings::yAxis() const -{ - return m_yAxis; -} - -TQ_INT32 TabletSettingsTab::DeviceSettings::pressureAxis() const -{ - return m_pressureAxis; -} - -TQ_INT32 TabletSettingsTab::DeviceSettings::xTiltAxis() const -{ - return m_xTiltAxis; -} - -TQ_INT32 TabletSettingsTab::DeviceSettings::yTiltAxis() const -{ - return m_yTiltAxis; -} - -TQ_INT32 TabletSettingsTab::DeviceSettings::wheelAxis() const -{ - return m_wheelAxis; -} - -TQ_INT32 TabletSettingsTab::DeviceSettings::toolIDAxis() const -{ - return m_toolIDAxis; -} - -TQ_INT32 TabletSettingsTab::DeviceSettings::serialNumberAxis() const -{ - return m_serialNumberAxis; -} - -TabletSettingsTab::TabletDeviceSettingsDialog::TabletDeviceSettingsDialog(const TQString& deviceName, DeviceSettings settings, - TQWidget *parent, const char *name) - : super(parent, name, true, "", Ok | Cancel) -{ - setCaption(i18n("Configure %1").arg(deviceName)); - - m_page = new WdgTabletDeviceSettings(this); - - setMainWidget(m_page); - resize(m_page->sizeHint()); - - for (TQ_INT32 axis = 0; axis < settings.numAxes(); axis++) { - TQString axisString; - - axisString.setNum(axis); - - m_page->cbX->insertItem(axisString); - m_page->cbY->insertItem(axisString); - m_page->cbPressure->insertItem(axisString); - m_page->cbXTilt->insertItem(axisString); - m_page->cbYTilt->insertItem(axisString); - m_page->cbWheel->insertItem(axisString); -// m_page->cbToolID->insertItem(axisString); -// m_page->cbSerialNumber->insertItem(axisString); - } - - m_page->cbX->insertItem(i18n("None")); - m_page->cbY->insertItem(i18n("None")); - m_page->cbPressure->insertItem(i18n("None")); - m_page->cbXTilt->insertItem(i18n("None")); - m_page->cbYTilt->insertItem(i18n("None")); - m_page->cbWheel->insertItem(i18n("None")); -// m_page->cbToolID->insertItem(i18n("None")); -// m_page->cbSerialNumber->insertItem(i18n("None")); - - if (settings.xAxis() != KisCanvasWidget::X11TabletDevice::NoAxis) { - m_page->cbX->setCurrentItem(settings.xAxis()); - } else { - m_page->cbX->setCurrentItem(settings.numAxes()); - } - - if (settings.yAxis() != KisCanvasWidget::X11TabletDevice::NoAxis) { - m_page->cbY->setCurrentItem(settings.yAxis()); - } else { - m_page->cbY->setCurrentItem(settings.numAxes()); - } - - if (settings.pressureAxis() != KisCanvasWidget::X11TabletDevice::NoAxis) { - m_page->cbPressure->setCurrentItem(settings.pressureAxis()); - } else { - m_page->cbPressure->setCurrentItem(settings.numAxes()); - } - - if (settings.xTiltAxis() != KisCanvasWidget::X11TabletDevice::NoAxis) { - m_page->cbXTilt->setCurrentItem(settings.xTiltAxis()); - } else { - m_page->cbXTilt->setCurrentItem(settings.numAxes()); - } - - if (settings.yTiltAxis() != KisCanvasWidget::X11TabletDevice::NoAxis) { - m_page->cbYTilt->setCurrentItem(settings.yTiltAxis()); - } else { - m_page->cbYTilt->setCurrentItem(settings.numAxes()); - } - - if (settings.wheelAxis() != KisCanvasWidget::X11TabletDevice::NoAxis) { - m_page->cbWheel->setCurrentItem(settings.wheelAxis()); - } else { - m_page->cbWheel->setCurrentItem(settings.numAxes()); - } - -// if (settings.toolIDAxis() != KisCanvasWidget::X11TabletDevice::NoAxis) { -// m_page->cbToolID->setCurrentItem(settings.toolIDAxis()); -// } else { -// m_page->cbToolID->setCurrentItem(settings.numAxes()); -// } -// -// if (settings.serialNumberAxis() != KisCanvasWidget::X11TabletDevice::NoAxis) { -// m_page->cbSerialNumber->setCurrentItem(settings.serialNumberAxis()); -// } else { -// m_page->cbSerialNumber->setCurrentItem(settings.numAxes()); -// } - - m_settings = settings; -} - -TabletSettingsTab::TabletDeviceSettingsDialog::~TabletDeviceSettingsDialog() -{ - delete m_page; -} - -TabletSettingsTab::DeviceSettings TabletSettingsTab::TabletDeviceSettingsDialog::settings() -{ - const TQ_INT32 noAxis = m_settings.numAxes(); - - if (m_page->cbX->currentItem() != noAxis ) { - m_settings.setXAxis(m_page->cbX->currentItem()); - } else { - m_settings.setXAxis(KisCanvasWidget::X11TabletDevice::NoAxis); - } - - if (m_page->cbY->currentItem() != noAxis ) { - m_settings.setYAxis(m_page->cbY->currentItem()); - } else { - m_settings.setYAxis(KisCanvasWidget::X11TabletDevice::NoAxis); - } - - if (m_page->cbPressure->currentItem() != noAxis ) { - m_settings.setPressureAxis(m_page->cbPressure->currentItem()); - } else { - m_settings.setPressureAxis(KisCanvasWidget::X11TabletDevice::NoAxis); - } - - if (m_page->cbXTilt->currentItem() != noAxis ) { - m_settings.setXTiltAxis(m_page->cbXTilt->currentItem()); - } else { - m_settings.setXTiltAxis(KisCanvasWidget::X11TabletDevice::NoAxis); - } - - if (m_page->cbYTilt->currentItem() != noAxis ) { - m_settings.setYTiltAxis(m_page->cbYTilt->currentItem()); - } else { - m_settings.setYTiltAxis(KisCanvasWidget::X11TabletDevice::NoAxis); - } - - if (m_page->cbWheel->currentItem() != noAxis ) { - m_settings.setWheelAxis(m_page->cbWheel->currentItem()); - } else { - m_settings.setWheelAxis(KisCanvasWidget::X11TabletDevice::NoAxis); - } - -// if (m_page->cbToolID->currentItem() != noAxis ) { -// m_settings.setToolIDAxis(m_page->cbToolID->currentItem()); -// } else { -// m_settings.setToolIDAxis(KisCanvasWidget::X11TabletDevice::NoAxis); -// } -// -// if (m_page->cbSerialNumber->currentItem() != noAxis ) { -// m_settings.setSerialNumberAxis(m_page->cbSerialNumber->currentItem()); -// } else { -// m_settings.setSerialNumberAxis(KisCanvasWidget::X11TabletDevice::NoAxis); -// } - - return m_settings; -} - -void TabletSettingsTab::initTabletDevices() -{ - connect(cbTabletDevice, TQT_SIGNAL(activated(int)), TQT_SLOT(slotActivateDevice(int))); - connect(chkEnableTabletDevice, TQT_SIGNAL(toggled(bool)), TQT_SLOT(slotSetDeviceEnabled(bool))); - connect(btnConfigureTabletDevice, TQT_SIGNAL(clicked()), TQT_SLOT(slotConfigureDevice())); - - KisCanvasWidget::X11XIDTabletDeviceMap& tabletDevices = KisCanvasWidget::tabletDeviceMap(); - - cbTabletDevice->clear(); - - if (!tabletDevices.empty()) { - KisCanvasWidget::X11XIDTabletDeviceMap::iterator it; - - for (it = tabletDevices.begin(); it != tabletDevices.end(); ++it) { - KisCanvasWidget::X11TabletDevice& device = (*it).second; - - m_deviceSettings.append(DeviceSettings(&device, device.enabled(), device.xAxis(), device.yAxis(), - device.pressureAxis(), device.xTiltAxis(), device.yTiltAxis(), device.wheelAxis(), - device.toolIDAxis(), device.serialNumberAxis())); - cbTabletDevice->insertItem(device.name()); - } - slotActivateDevice(0); - } else { - cbTabletDevice->insertItem(i18n("No devices detected")); - cbTabletDevice->setEnabled(false); - chkEnableTabletDevice->setEnabled(false); - btnConfigureTabletDevice->setEnabled(false); - } -} - -void TabletSettingsTab::slotActivateDevice(int deviceIndex) -{ - bool deviceEnabled = m_deviceSettings[deviceIndex].enabled(); - - chkEnableTabletDevice->setChecked(deviceEnabled); - slotSetDeviceEnabled(deviceEnabled); -} - -void TabletSettingsTab::slotSetDeviceEnabled(bool enabled) -{ - btnConfigureTabletDevice->setEnabled(enabled); - m_deviceSettings[cbTabletDevice->currentItem()].setEnabled(enabled); -} - -void TabletSettingsTab::slotConfigureDevice() -{ - TabletDeviceSettingsDialog dialog(cbTabletDevice->currentText(), m_deviceSettings[cbTabletDevice->currentItem()], - this, "TabletDeviceSettings"); - - if (dialog.exec() == TQDialog::Accepted) - { - m_deviceSettings[cbTabletDevice->currentItem()] = dialog.settings(); - } -} - -void TabletSettingsTab::applyTabletDeviceSettings() -{ - for (TQ_UINT32 deviceIndex = 0; deviceIndex < m_deviceSettings.count(); ++deviceIndex) { - m_deviceSettings[deviceIndex].applySettings(); - } -} - -#else // EXTENDED_X11_TABLET_SUPPORT - -// Fix compilation. moc seems to not see the undefined symbol needed -// for these slots to be declared. -void TabletSettingsTab::slotActivateDevice(int /*deviceIndex*/) -{ -} - -void TabletSettingsTab::slotSetDeviceEnabled(bool /*enabled*/) -{ -} - -void TabletSettingsTab::slotConfigureDevice() -{ -} - -void TabletSettingsTab::applyTabletDeviceSettings() -{ -} - -#endif - -//--------------------------------------------------------------------------------------------------- - -DisplaySettingsTab::DisplaySettingsTab( TQWidget *parent, const char *name) - : WdgDisplaySettings( parent, name ) -{ -#ifdef HAVE_GL - KisConfig cfg; - - if (!TQGLFormat::hasOpenGL()) { - cbUseOpenGL->setEnabled(false); - //cbUseOpenGLShaders->setEnabled(false); - } else { - cbUseOpenGL->setChecked(cfg.useOpenGL()); - //cbUseOpenGLShaders->setChecked(cfg.useOpenGLShaders()); - //cbUseOpenGLShaders->setEnabled(cfg.useOpenGL()); - } -#else - cbUseOpenGL->setEnabled(false); - //cbUseOpenGLShaders->setEnabled(false); -#endif - - connect(cbUseOpenGL, TQT_SIGNAL(toggled(bool)), TQT_SLOT(slotUseOpenGLToggled(bool))); -} - -void DisplaySettingsTab::setDefault() -{ - cbUseOpenGL->setChecked(false); - //cbUseOpenGLShaders->setChecked(false); - //cbUseOpenGLShaders->setEnabled(false); -} - -void DisplaySettingsTab::slotUseOpenGLToggled(bool /*isChecked*/) -{ - //cbUseOpenGLShaders->setEnabled(isChecked); -} - -//--------------------------------------------------------------------------------------------------- -GridSettingsTab::GridSettingsTab(TQWidget* parent) : WdgGridSettingsBase(parent) -{ - KisConfig cfg; - selectMainStyle->setCurrentItem(cfg.getGridMainStyle()); - selectSubdivisionStyle->setCurrentItem(cfg.getGridSubdivisionStyle()); - -#if KDE_IS_VERSION(3,4,0) - colorMain->setDefaultColor( TQColor( 99, 99, 99 ) ); - colorSubdivision->setDefaultColor( TQColor( 200, 200, 200 ) ); -#endif - colorMain->setColor(cfg.getGridMainColor()); - colorSubdivision->setColor(cfg.getGridSubdivisionColor()); - - intHSpacing->setValue( cfg.getGridHSpacing() ); - intVSpacing->setValue( cfg.getGridVSpacing() ); - intSubdivision->setValue( cfg.getGridSubdivisions()); - intOffsetX->setValue( cfg.getGridOffsetX()); - intOffsetY->setValue( cfg.getGridOffsetY()); - - linkSpacingToggled(true); - connect(bnLinkSpacing, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(linkSpacingToggled( bool ))); - - connect(intHSpacing, TQT_SIGNAL(valueChanged(int)),this,TQT_SLOT(spinBoxHSpacingChanged(int))); - connect(intVSpacing, TQT_SIGNAL(valueChanged(int)),this,TQT_SLOT(spinBoxVSpacingChanged(int))); - - -} - -void GridSettingsTab::setDefault() -{ - KisConfig cfg; - selectMainStyle->setCurrentItem(0); - selectSubdivisionStyle->setCurrentItem(1); - - colorMain->setColor(TQColor(99,99,99)); - colorSubdivision->setColor(TQColor(199,199,199)); - - intHSpacing->setValue( 10 ); - intVSpacing->setValue( 10 ); - intSubdivision->setValue( 1 ); - intOffsetX->setValue( 0 ); - intOffsetY->setValue( 0 ); -} - -void GridSettingsTab::spinBoxHSpacingChanged(int v) -{ - if(m_linkSpacing) - { - intVSpacing->setValue(v); - } -} - -void GridSettingsTab::spinBoxVSpacingChanged(int v ) -{ - if(m_linkSpacing) - { - intHSpacing->setValue(v); - } -} - - -void GridSettingsTab::linkSpacingToggled(bool b) -{ - m_linkSpacing = b; - - KoImageResource kir; - if (b) { - bnLinkSpacing->setPixmap(kir.chain()); - } - else { - bnLinkSpacing->setPixmap(kir.chainBroken()); - } -} - - -//--------------------------------------------------------------------------------------------------- - -PreferencesDialog::PreferencesDialog( TQWidget* parent, const char* name ) - : KDialogBase( IconList, i18n("Preferences"), Ok | Cancel | Help | Default /*| Apply*/, Ok, parent, name, true, true ) -{ - TQVBox *vbox; - - vbox = addVBoxPage( i18n( "General"), i18n( "General"), BarIcon( "misc", TDEIcon::SizeMedium )); - m_general = new GeneralTab( vbox ); -#ifdef HAVE_GL - vbox = addVBoxPage ( i18n( "Display" ), i18n( "Display" ), BarIcon( "tdescreensaver", TDEIcon::SizeMedium )); - m_displaySettings = new DisplaySettingsTab( vbox ); -#endif - vbox = addVBoxPage( i18n( "Color Management"), i18n( "Color"), BarIcon( "colorize", TDEIcon::SizeMedium )); - m_colorSettings = new ColorSettingsTab( vbox ); - - vbox = addVBoxPage( i18n( "Performance"), i18n( "Performance"), BarIcon( "fork", TDEIcon::SizeMedium )); - m_performanceSettings = new PerformanceTab ( vbox ); - - vbox = addVBoxPage ( i18n( "Tablet" ), i18n( "Tablet" ), BarIcon( "input-tablet", TDEIcon::SizeMedium )); - m_tabletSettings = new TabletSettingsTab( vbox ); - - vbox = addVBoxPage ( i18n( "Grid" ), i18n( "Grid" ), BarIcon( "grid", TDEIcon::SizeMedium )); - m_gridSettings = new GridSettingsTab( vbox ); - -} - -PreferencesDialog::~PreferencesDialog() -{ -} - -void PreferencesDialog::slotDefault() -{ - m_general->setDefault(); - m_colorSettings->setDefault(); - m_tabletSettings->setDefault(); - m_performanceSettings->setDefault(); -#ifdef HAVE_GL - m_displaySettings->setDefault(); -#endif - m_gridSettings->setDefault(); -} - -bool PreferencesDialog::editPreferences() -{ - PreferencesDialog* dialog; - - dialog = new PreferencesDialog(); - bool baccept = ( dialog->exec() == Accepted ); - if( baccept ) - { - KisConfig cfg; - cfg.setCursorStyle(dialog->m_general->cursorStyle()); - cfg.setDockability( dialog->m_general->dockability() ); - cfg.setDockerFontSize( dialog->m_general->dockerFontSize() ); - - // Color settings - cfg.setMonitorProfile( dialog->m_colorSettings->m_page->cmbMonitorProfile->currentText()); - cfg.setWorkingColorSpace( dialog->m_colorSettings->m_page->cmbWorkingColorSpace->currentText()); - cfg.setPrinterColorSpace( dialog->m_colorSettings->m_page->cmbPrintingColorSpace->currentText()); - cfg.setPrinterProfile( dialog->m_colorSettings->m_page->cmbPrintProfile->currentText()); - - cfg.setUseBlackPointCompensation( dialog->m_colorSettings->m_page->chkBlackpoint->isChecked()); - cfg.setPasteBehaviour( dialog->m_colorSettings->m_page->grpPasteBehaviour->selectedId()); - cfg.setRenderIntent( dialog->m_colorSettings->m_page->cmbMonitorIntent->currentItem()); - - // it's scaled from 0 - 6, but the config is in 0 - 300 - cfg.setSwappiness(dialog->m_performanceSettings->m_swappiness->value() * 50); - cfg.setMaxTilesInMem(dialog->m_performanceSettings->m_maxTiles->value()); - // let the tile manager know - KisTileManager::instance()->configChanged(); - - dialog->m_tabletSettings->applySettings(); - -#ifdef HAVE_GL - cfg.setUseOpenGL(dialog->m_displaySettings->cbUseOpenGL->isChecked()); - //cfg.setUseOpenGLShaders(dialog->m_displaySettings->cbUseOpenGLShaders->isChecked()); -#endif - - // Grid settings - cfg.setGridMainStyle( dialog->m_gridSettings->selectMainStyle->currentItem() ); - cfg.setGridSubdivisionStyle( dialog->m_gridSettings->selectSubdivisionStyle->currentItem() ); - - cfg.setGridMainColor( dialog->m_gridSettings->colorMain->color() ); - cfg.setGridSubdivisionColor(dialog->m_gridSettings->colorSubdivision->color() ); - - cfg.setGridHSpacing( dialog->m_gridSettings->intHSpacing->value( )); - cfg.setGridVSpacing( dialog->m_gridSettings->intVSpacing->value( )); - cfg.setGridSubdivisions( dialog->m_gridSettings->intSubdivision->value( )); - cfg.setGridOffsetX( dialog->m_gridSettings->intOffsetX->value( )); - cfg.setGridOffsetY( dialog->m_gridSettings->intOffsetY->value( )); - - } - delete dialog; - return baccept; -} - -#include "kis_dlg_preferences.moc" diff --git a/chalk/ui/kis_dlg_preferences.cpp b/chalk/ui/kis_dlg_preferences.cpp new file mode 100644 index 000000000..e35477dc5 --- /dev/null +++ b/chalk/ui/kis_dlg_preferences.cpp @@ -0,0 +1,821 @@ +/* + * preferencesdlg.cpp - part of KImageShop + * + * Copyright (c) 1999 Michael Koch + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef HAVE_GL +#include +#endif + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "squeezedcombobox.h" +#include "kis_cmb_idlist.h" +#include "kis_colorspace.h" +#include "kis_colorspace_factory_registry.h" +#include "kis_cursor.h" +#include "kis_config.h" +#include "kis_dlg_preferences.h" +#include "kis_factory.h" +#include "kis_id.h" +#include "kis_meta_registry.h" +#include "kis_profile.h" + +#include "kis_canvas.h" + +#include "wdgcolorsettings.h" +#include "wdgperformancesettings.h" +#include "wdggeneralsettings.h" + +// for the performance update +#include "tiles/kis_tilemanager.h" + +GeneralTab::GeneralTab( TQWidget *_parent, const char *_name ) + : WdgGeneralSettings( _parent, _name ) +{ + + KisConfig cfg; + + m_cmbCursorShape->setCurrentItem(cfg.cursorStyle()); + grpDockability->setButton(cfg.dockability()); + numDockerFontSize->setValue((int)cfg.dockerFontSize()); +} + +void GeneralTab::setDefault() +{ + KisConfig cfg; + + m_cmbCursorShape->setCurrentItem( cfg.getDefaultCursorStyle()); + grpDockability->setButton(cfg.getDefaultDockability()); + numDockerFontSize->setValue((int)(cfg.getDefaultDockerFontSize())); +} + +enumCursorStyle GeneralTab::cursorStyle() +{ + return (enumCursorStyle)m_cmbCursorShape->currentItem(); +} + +enumKoDockability GeneralTab::dockability() +{ + return (enumKoDockability)grpDockability->selectedId(); +} + +float GeneralTab::dockerFontSize() +{ + return (float)numDockerFontSize->value(); +} + +//--------------------------------------------------------------------------------------------------- + +ColorSettingsTab::ColorSettingsTab(TQWidget *parent, const char *name ) + : TQWidget(parent, name) +{ + // XXX: Make sure only profiles that fit the specified color model + // are shown in the profile combos + + TQGridLayout * l = new TQGridLayout( this, 1, 1, KDialog::marginHint(), KDialog::spacingHint()); + l->setMargin(0); + m_page = new WdgColorSettings(this); + l->addWidget( m_page, 0, 0); + + KisConfig cfg; + + m_page->cmbWorkingColorSpace->setIDList(KisMetaRegistry::instance()->csRegistry()->listKeys()); + m_page->cmbWorkingColorSpace->setCurrentText(cfg.workingColorSpace()); + + m_page->cmbPrintingColorSpace->setIDList(KisMetaRegistry::instance()->csRegistry()->listKeys()); + m_page->cmbPrintingColorSpace->setCurrentText(cfg.printerColorSpace()); + + refillMonitorProfiles(KisID("RGBA", "")); + refillPrintProfiles(KisID(cfg.printerColorSpace(), "")); + + if(m_page->cmbMonitorProfile->contains(cfg.monitorProfile())) + m_page->cmbMonitorProfile->setCurrentText(cfg.monitorProfile()); + if(m_page->cmbPrintProfile->contains(cfg.printerProfile())) + m_page->cmbPrintProfile->setCurrentText(cfg.printerProfile()); + m_page->chkBlackpoint->setChecked(cfg.useBlackPointCompensation()); + m_page->grpPasteBehaviour->setButton(cfg.pasteBehaviour()); + m_page->cmbMonitorIntent->setCurrentItem(cfg.renderIntent()); + + connect(m_page->cmbPrintingColorSpace, TQT_SIGNAL(activated(const KisID &)), + this, TQT_SLOT(refillPrintProfiles(const KisID &))); +} + +void ColorSettingsTab::setDefault() +{ + m_page->cmbWorkingColorSpace->setCurrentText("RGBA"); + + m_page->cmbPrintingColorSpace->setCurrentText("CMYK"); + refillPrintProfiles(KisID("CMYK", "")); + + m_page->chkBlackpoint->setChecked(false); + m_page->cmbMonitorIntent->setCurrentItem(INTENT_PERCEPTUAL); + m_page->grpPasteBehaviour->setButton(2); +} + + +void ColorSettingsTab::refillMonitorProfiles(const KisID & s) +{ + KisColorSpaceFactory * csf = KisMetaRegistry::instance()->csRegistry()->get(s); + + m_page->cmbMonitorProfile->clear(); + + if ( !csf ) + return; + + TQValueVector profileList = KisMetaRegistry::instance()->csRegistry()->profilesFor( csf ); + TQValueVector ::iterator it; + for ( it = profileList.begin(); it != profileList.end(); ++it ) { + if ((*it)->deviceClass() == icSigDisplayClass) + m_page->cmbMonitorProfile->insertItem((*it)->productName()); + } + + m_page->cmbMonitorProfile->setCurrentText(csf->defaultProfile()); +} + +void ColorSettingsTab::refillPrintProfiles(const KisID & s) +{ + KisColorSpaceFactory * csf = KisMetaRegistry::instance()->csRegistry()->get(s); + + m_page->cmbPrintProfile->clear(); + + if ( !csf ) + return; + + TQValueVector profileList = KisMetaRegistry::instance()->csRegistry()->profilesFor( csf ); + TQValueVector ::iterator it; + for ( it = profileList.begin(); it != profileList.end(); ++it ) { + if ((*it)->deviceClass() == icSigOutputClass) + m_page->cmbPrintProfile->insertItem((*it)->productName()); + } + + m_page->cmbPrintProfile->setCurrentText(csf->defaultProfile()); +} + +//--------------------------------------------------------------------------------------------------- + +PerformanceTab::PerformanceTab(TQWidget *parent, const char *name ) + : WdgPerformanceSettings(parent, name) +{ + // XXX: Make sure only profiles that fit the specified color model + // are shown in the profile combos + + KisConfig cfg; + + // it's scaled from 0 - 6, but the config is in 0 - 300 + m_swappiness->setValue(cfg.swappiness() / 50); + m_maxTiles->setValue(cfg.maxTilesInMem()); +} + +void PerformanceTab::setDefault() +{ + m_swappiness->setValue(3); + m_maxTiles->setValue(500); +} + +//--------------------------------------------------------------------------------------------------- + +TabletSettingsTab::TabletSettingsTab( TQWidget *parent, const char *name) + : WdgTabletSettings( parent, name ) +{ +#ifdef EXTENDED_X11_TABLET_SUPPORT + initTabletDevices(); +#else + grpTabletDevices->hide(); +#endif +} + +void TabletSettingsTab::setDefault() +{ +} + +void TabletSettingsTab::applySettings() +{ + +#ifdef EXTENDED_X11_TABLET_SUPPORT + applyTabletDeviceSettings(); +#endif +} + +#ifdef EXTENDED_X11_TABLET_SUPPORT +TabletSettingsTab::DeviceSettings::DeviceSettings(KisCanvasWidget::X11TabletDevice *tabletDevice, bool enabled, + TQ_INT32 xAxis, TQ_INT32 yAxis, TQ_INT32 pressureAxis, + TQ_INT32 xTiltAxis, TQ_INT32 yTiltAxis, TQ_INT32 wheelAxis, + TQ_INT32 toolIDAxis, TQ_INT32 serialNumberAxis) + : m_tabletDevice(tabletDevice), + m_enabled(enabled), + m_xAxis(xAxis), + m_yAxis(yAxis), + m_pressureAxis(pressureAxis), + m_xTiltAxis(xTiltAxis), + m_yTiltAxis(yTiltAxis), + m_wheelAxis(wheelAxis), + m_toolIDAxis(toolIDAxis), + m_serialNumberAxis(serialNumberAxis) +{ +} + +TabletSettingsTab::DeviceSettings::DeviceSettings() + : m_tabletDevice(0), + m_enabled(false), + m_xAxis(KisCanvasWidget::X11TabletDevice::NoAxis), + m_yAxis(KisCanvasWidget::X11TabletDevice::NoAxis), + m_pressureAxis(KisCanvasWidget::X11TabletDevice::NoAxis), + m_xTiltAxis(KisCanvasWidget::X11TabletDevice::NoAxis), + m_yTiltAxis(KisCanvasWidget::X11TabletDevice::NoAxis), + m_wheelAxis(KisCanvasWidget::X11TabletDevice::NoAxis), + m_toolIDAxis(KisCanvasWidget::X11TabletDevice::NoAxis), + m_serialNumberAxis(KisCanvasWidget::X11TabletDevice::NoAxis) +{ +} + +void TabletSettingsTab::DeviceSettings::applySettings() +{ + m_tabletDevice->setEnabled(enabled()); + m_tabletDevice->setXAxis(xAxis()); + m_tabletDevice->setYAxis(yAxis()); + m_tabletDevice->setPressureAxis(pressureAxis()); + m_tabletDevice->setXTiltAxis(xTiltAxis()); + m_tabletDevice->setYTiltAxis(yTiltAxis()); + m_tabletDevice->setWheelAxis(wheelAxis()); + m_tabletDevice->setToolIDAxis(toolIDAxis()); + m_tabletDevice->setSerialNumberAxis(serialNumberAxis()); + m_tabletDevice->writeSettingsToConfig(); +} + +void TabletSettingsTab::DeviceSettings::setEnabled(bool enabled) +{ + m_enabled = enabled; +} + +bool TabletSettingsTab::DeviceSettings::enabled() const +{ + return m_enabled; +} + +TQ_INT32 TabletSettingsTab::DeviceSettings::numAxes() const +{ + return m_tabletDevice->numAxes(); +} + +void TabletSettingsTab::DeviceSettings::setXAxis(TQ_INT32 axis) +{ + m_xAxis = axis; +} + +void TabletSettingsTab::DeviceSettings::setYAxis(TQ_INT32 axis) +{ + m_yAxis = axis; +} + +void TabletSettingsTab::DeviceSettings::setPressureAxis(TQ_INT32 axis) +{ + m_pressureAxis = axis; +} + +void TabletSettingsTab::DeviceSettings::setXTiltAxis(TQ_INT32 axis) +{ + m_xTiltAxis = axis; +} + +void TabletSettingsTab::DeviceSettings::setYTiltAxis(TQ_INT32 axis) +{ + m_yTiltAxis = axis; +} + +void TabletSettingsTab::DeviceSettings::setWheelAxis(TQ_INT32 axis) +{ + m_wheelAxis = axis; +} + +void TabletSettingsTab::DeviceSettings::setToolIDAxis(TQ_INT32 axis) +{ + m_toolIDAxis = axis; +} + +void TabletSettingsTab::DeviceSettings::setSerialNumberAxis(TQ_INT32 axis) +{ + m_serialNumberAxis = axis; +} + +TQ_INT32 TabletSettingsTab::DeviceSettings::xAxis() const +{ + return m_xAxis; +} + +TQ_INT32 TabletSettingsTab::DeviceSettings::yAxis() const +{ + return m_yAxis; +} + +TQ_INT32 TabletSettingsTab::DeviceSettings::pressureAxis() const +{ + return m_pressureAxis; +} + +TQ_INT32 TabletSettingsTab::DeviceSettings::xTiltAxis() const +{ + return m_xTiltAxis; +} + +TQ_INT32 TabletSettingsTab::DeviceSettings::yTiltAxis() const +{ + return m_yTiltAxis; +} + +TQ_INT32 TabletSettingsTab::DeviceSettings::wheelAxis() const +{ + return m_wheelAxis; +} + +TQ_INT32 TabletSettingsTab::DeviceSettings::toolIDAxis() const +{ + return m_toolIDAxis; +} + +TQ_INT32 TabletSettingsTab::DeviceSettings::serialNumberAxis() const +{ + return m_serialNumberAxis; +} + +TabletSettingsTab::TabletDeviceSettingsDialog::TabletDeviceSettingsDialog(const TQString& deviceName, DeviceSettings settings, + TQWidget *parent, const char *name) + : super(parent, name, true, "", Ok | Cancel) +{ + setCaption(i18n("Configure %1").arg(deviceName)); + + m_page = new WdgTabletDeviceSettings(this); + + setMainWidget(m_page); + resize(m_page->sizeHint()); + + for (TQ_INT32 axis = 0; axis < settings.numAxes(); axis++) { + TQString axisString; + + axisString.setNum(axis); + + m_page->cbX->insertItem(axisString); + m_page->cbY->insertItem(axisString); + m_page->cbPressure->insertItem(axisString); + m_page->cbXTilt->insertItem(axisString); + m_page->cbYTilt->insertItem(axisString); + m_page->cbWheel->insertItem(axisString); +// m_page->cbToolID->insertItem(axisString); +// m_page->cbSerialNumber->insertItem(axisString); + } + + m_page->cbX->insertItem(i18n("None")); + m_page->cbY->insertItem(i18n("None")); + m_page->cbPressure->insertItem(i18n("None")); + m_page->cbXTilt->insertItem(i18n("None")); + m_page->cbYTilt->insertItem(i18n("None")); + m_page->cbWheel->insertItem(i18n("None")); +// m_page->cbToolID->insertItem(i18n("None")); +// m_page->cbSerialNumber->insertItem(i18n("None")); + + if (settings.xAxis() != KisCanvasWidget::X11TabletDevice::NoAxis) { + m_page->cbX->setCurrentItem(settings.xAxis()); + } else { + m_page->cbX->setCurrentItem(settings.numAxes()); + } + + if (settings.yAxis() != KisCanvasWidget::X11TabletDevice::NoAxis) { + m_page->cbY->setCurrentItem(settings.yAxis()); + } else { + m_page->cbY->setCurrentItem(settings.numAxes()); + } + + if (settings.pressureAxis() != KisCanvasWidget::X11TabletDevice::NoAxis) { + m_page->cbPressure->setCurrentItem(settings.pressureAxis()); + } else { + m_page->cbPressure->setCurrentItem(settings.numAxes()); + } + + if (settings.xTiltAxis() != KisCanvasWidget::X11TabletDevice::NoAxis) { + m_page->cbXTilt->setCurrentItem(settings.xTiltAxis()); + } else { + m_page->cbXTilt->setCurrentItem(settings.numAxes()); + } + + if (settings.yTiltAxis() != KisCanvasWidget::X11TabletDevice::NoAxis) { + m_page->cbYTilt->setCurrentItem(settings.yTiltAxis()); + } else { + m_page->cbYTilt->setCurrentItem(settings.numAxes()); + } + + if (settings.wheelAxis() != KisCanvasWidget::X11TabletDevice::NoAxis) { + m_page->cbWheel->setCurrentItem(settings.wheelAxis()); + } else { + m_page->cbWheel->setCurrentItem(settings.numAxes()); + } + +// if (settings.toolIDAxis() != KisCanvasWidget::X11TabletDevice::NoAxis) { +// m_page->cbToolID->setCurrentItem(settings.toolIDAxis()); +// } else { +// m_page->cbToolID->setCurrentItem(settings.numAxes()); +// } +// +// if (settings.serialNumberAxis() != KisCanvasWidget::X11TabletDevice::NoAxis) { +// m_page->cbSerialNumber->setCurrentItem(settings.serialNumberAxis()); +// } else { +// m_page->cbSerialNumber->setCurrentItem(settings.numAxes()); +// } + + m_settings = settings; +} + +TabletSettingsTab::TabletDeviceSettingsDialog::~TabletDeviceSettingsDialog() +{ + delete m_page; +} + +TabletSettingsTab::DeviceSettings TabletSettingsTab::TabletDeviceSettingsDialog::settings() +{ + const TQ_INT32 noAxis = m_settings.numAxes(); + + if (m_page->cbX->currentItem() != noAxis ) { + m_settings.setXAxis(m_page->cbX->currentItem()); + } else { + m_settings.setXAxis(KisCanvasWidget::X11TabletDevice::NoAxis); + } + + if (m_page->cbY->currentItem() != noAxis ) { + m_settings.setYAxis(m_page->cbY->currentItem()); + } else { + m_settings.setYAxis(KisCanvasWidget::X11TabletDevice::NoAxis); + } + + if (m_page->cbPressure->currentItem() != noAxis ) { + m_settings.setPressureAxis(m_page->cbPressure->currentItem()); + } else { + m_settings.setPressureAxis(KisCanvasWidget::X11TabletDevice::NoAxis); + } + + if (m_page->cbXTilt->currentItem() != noAxis ) { + m_settings.setXTiltAxis(m_page->cbXTilt->currentItem()); + } else { + m_settings.setXTiltAxis(KisCanvasWidget::X11TabletDevice::NoAxis); + } + + if (m_page->cbYTilt->currentItem() != noAxis ) { + m_settings.setYTiltAxis(m_page->cbYTilt->currentItem()); + } else { + m_settings.setYTiltAxis(KisCanvasWidget::X11TabletDevice::NoAxis); + } + + if (m_page->cbWheel->currentItem() != noAxis ) { + m_settings.setWheelAxis(m_page->cbWheel->currentItem()); + } else { + m_settings.setWheelAxis(KisCanvasWidget::X11TabletDevice::NoAxis); + } + +// if (m_page->cbToolID->currentItem() != noAxis ) { +// m_settings.setToolIDAxis(m_page->cbToolID->currentItem()); +// } else { +// m_settings.setToolIDAxis(KisCanvasWidget::X11TabletDevice::NoAxis); +// } +// +// if (m_page->cbSerialNumber->currentItem() != noAxis ) { +// m_settings.setSerialNumberAxis(m_page->cbSerialNumber->currentItem()); +// } else { +// m_settings.setSerialNumberAxis(KisCanvasWidget::X11TabletDevice::NoAxis); +// } + + return m_settings; +} + +void TabletSettingsTab::initTabletDevices() +{ + connect(cbTabletDevice, TQT_SIGNAL(activated(int)), TQT_SLOT(slotActivateDevice(int))); + connect(chkEnableTabletDevice, TQT_SIGNAL(toggled(bool)), TQT_SLOT(slotSetDeviceEnabled(bool))); + connect(btnConfigureTabletDevice, TQT_SIGNAL(clicked()), TQT_SLOT(slotConfigureDevice())); + + KisCanvasWidget::X11XIDTabletDeviceMap& tabletDevices = KisCanvasWidget::tabletDeviceMap(); + + cbTabletDevice->clear(); + + if (!tabletDevices.empty()) { + KisCanvasWidget::X11XIDTabletDeviceMap::iterator it; + + for (it = tabletDevices.begin(); it != tabletDevices.end(); ++it) { + KisCanvasWidget::X11TabletDevice& device = (*it).second; + + m_deviceSettings.append(DeviceSettings(&device, device.enabled(), device.xAxis(), device.yAxis(), + device.pressureAxis(), device.xTiltAxis(), device.yTiltAxis(), device.wheelAxis(), + device.toolIDAxis(), device.serialNumberAxis())); + cbTabletDevice->insertItem(device.name()); + } + slotActivateDevice(0); + } else { + cbTabletDevice->insertItem(i18n("No devices detected")); + cbTabletDevice->setEnabled(false); + chkEnableTabletDevice->setEnabled(false); + btnConfigureTabletDevice->setEnabled(false); + } +} + +void TabletSettingsTab::slotActivateDevice(int deviceIndex) +{ + bool deviceEnabled = m_deviceSettings[deviceIndex].enabled(); + + chkEnableTabletDevice->setChecked(deviceEnabled); + slotSetDeviceEnabled(deviceEnabled); +} + +void TabletSettingsTab::slotSetDeviceEnabled(bool enabled) +{ + btnConfigureTabletDevice->setEnabled(enabled); + m_deviceSettings[cbTabletDevice->currentItem()].setEnabled(enabled); +} + +void TabletSettingsTab::slotConfigureDevice() +{ + TabletDeviceSettingsDialog dialog(cbTabletDevice->currentText(), m_deviceSettings[cbTabletDevice->currentItem()], + this, "TabletDeviceSettings"); + + if (dialog.exec() == TQDialog::Accepted) + { + m_deviceSettings[cbTabletDevice->currentItem()] = dialog.settings(); + } +} + +void TabletSettingsTab::applyTabletDeviceSettings() +{ + for (TQ_UINT32 deviceIndex = 0; deviceIndex < m_deviceSettings.count(); ++deviceIndex) { + m_deviceSettings[deviceIndex].applySettings(); + } +} + +#else // EXTENDED_X11_TABLET_SUPPORT + +// Fix compilation. moc seems to not see the undefined symbol needed +// for these slots to be declared. +void TabletSettingsTab::slotActivateDevice(int /*deviceIndex*/) +{ +} + +void TabletSettingsTab::slotSetDeviceEnabled(bool /*enabled*/) +{ +} + +void TabletSettingsTab::slotConfigureDevice() +{ +} + +void TabletSettingsTab::applyTabletDeviceSettings() +{ +} + +#endif + +//--------------------------------------------------------------------------------------------------- + +DisplaySettingsTab::DisplaySettingsTab( TQWidget *parent, const char *name) + : WdgDisplaySettings( parent, name ) +{ +#ifdef HAVE_GL + KisConfig cfg; + + if (!TQGLFormat::hasOpenGL()) { + cbUseOpenGL->setEnabled(false); + //cbUseOpenGLShaders->setEnabled(false); + } else { + cbUseOpenGL->setChecked(cfg.useOpenGL()); + //cbUseOpenGLShaders->setChecked(cfg.useOpenGLShaders()); + //cbUseOpenGLShaders->setEnabled(cfg.useOpenGL()); + } +#else + cbUseOpenGL->setEnabled(false); + //cbUseOpenGLShaders->setEnabled(false); +#endif + + connect(cbUseOpenGL, TQT_SIGNAL(toggled(bool)), TQT_SLOT(slotUseOpenGLToggled(bool))); +} + +void DisplaySettingsTab::setDefault() +{ + cbUseOpenGL->setChecked(false); + //cbUseOpenGLShaders->setChecked(false); + //cbUseOpenGLShaders->setEnabled(false); +} + +void DisplaySettingsTab::slotUseOpenGLToggled(bool /*isChecked*/) +{ + //cbUseOpenGLShaders->setEnabled(isChecked); +} + +//--------------------------------------------------------------------------------------------------- +GridSettingsTab::GridSettingsTab(TQWidget* parent) : WdgGridSettingsBase(parent) +{ + KisConfig cfg; + selectMainStyle->setCurrentItem(cfg.getGridMainStyle()); + selectSubdivisionStyle->setCurrentItem(cfg.getGridSubdivisionStyle()); + +#if KDE_IS_VERSION(3,4,0) + colorMain->setDefaultColor( TQColor( 99, 99, 99 ) ); + colorSubdivision->setDefaultColor( TQColor( 200, 200, 200 ) ); +#endif + colorMain->setColor(cfg.getGridMainColor()); + colorSubdivision->setColor(cfg.getGridSubdivisionColor()); + + intHSpacing->setValue( cfg.getGridHSpacing() ); + intVSpacing->setValue( cfg.getGridVSpacing() ); + intSubdivision->setValue( cfg.getGridSubdivisions()); + intOffsetX->setValue( cfg.getGridOffsetX()); + intOffsetY->setValue( cfg.getGridOffsetY()); + + linkSpacingToggled(true); + connect(bnLinkSpacing, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(linkSpacingToggled( bool ))); + + connect(intHSpacing, TQT_SIGNAL(valueChanged(int)),this,TQT_SLOT(spinBoxHSpacingChanged(int))); + connect(intVSpacing, TQT_SIGNAL(valueChanged(int)),this,TQT_SLOT(spinBoxVSpacingChanged(int))); + + +} + +void GridSettingsTab::setDefault() +{ + KisConfig cfg; + selectMainStyle->setCurrentItem(0); + selectSubdivisionStyle->setCurrentItem(1); + + colorMain->setColor(TQColor(99,99,99)); + colorSubdivision->setColor(TQColor(199,199,199)); + + intHSpacing->setValue( 10 ); + intVSpacing->setValue( 10 ); + intSubdivision->setValue( 1 ); + intOffsetX->setValue( 0 ); + intOffsetY->setValue( 0 ); +} + +void GridSettingsTab::spinBoxHSpacingChanged(int v) +{ + if(m_linkSpacing) + { + intVSpacing->setValue(v); + } +} + +void GridSettingsTab::spinBoxVSpacingChanged(int v ) +{ + if(m_linkSpacing) + { + intHSpacing->setValue(v); + } +} + + +void GridSettingsTab::linkSpacingToggled(bool b) +{ + m_linkSpacing = b; + + KoImageResource kir; + if (b) { + bnLinkSpacing->setPixmap(kir.chain()); + } + else { + bnLinkSpacing->setPixmap(kir.chainBroken()); + } +} + + +//--------------------------------------------------------------------------------------------------- + +PreferencesDialog::PreferencesDialog( TQWidget* parent, const char* name ) + : KDialogBase( IconList, i18n("Preferences"), Ok | Cancel | Help | Default /*| Apply*/, Ok, parent, name, true, true ) +{ + TQVBox *vbox; + + vbox = addVBoxPage( i18n( "General"), i18n( "General"), BarIcon( "misc", TDEIcon::SizeMedium )); + m_general = new GeneralTab( vbox ); +#ifdef HAVE_GL + vbox = addVBoxPage ( i18n( "Display" ), i18n( "Display" ), BarIcon( "tdescreensaver", TDEIcon::SizeMedium )); + m_displaySettings = new DisplaySettingsTab( vbox ); +#endif + vbox = addVBoxPage( i18n( "Color Management"), i18n( "Color"), BarIcon( "colorize", TDEIcon::SizeMedium )); + m_colorSettings = new ColorSettingsTab( vbox ); + + vbox = addVBoxPage( i18n( "Performance"), i18n( "Performance"), BarIcon( "fork", TDEIcon::SizeMedium )); + m_performanceSettings = new PerformanceTab ( vbox ); + + vbox = addVBoxPage ( i18n( "Tablet" ), i18n( "Tablet" ), BarIcon( "input-tablet", TDEIcon::SizeMedium )); + m_tabletSettings = new TabletSettingsTab( vbox ); + + vbox = addVBoxPage ( i18n( "Grid" ), i18n( "Grid" ), BarIcon( "grid", TDEIcon::SizeMedium )); + m_gridSettings = new GridSettingsTab( vbox ); + +} + +PreferencesDialog::~PreferencesDialog() +{ +} + +void PreferencesDialog::slotDefault() +{ + m_general->setDefault(); + m_colorSettings->setDefault(); + m_tabletSettings->setDefault(); + m_performanceSettings->setDefault(); +#ifdef HAVE_GL + m_displaySettings->setDefault(); +#endif + m_gridSettings->setDefault(); +} + +bool PreferencesDialog::editPreferences() +{ + PreferencesDialog* dialog; + + dialog = new PreferencesDialog(); + bool baccept = ( dialog->exec() == Accepted ); + if( baccept ) + { + KisConfig cfg; + cfg.setCursorStyle(dialog->m_general->cursorStyle()); + cfg.setDockability( dialog->m_general->dockability() ); + cfg.setDockerFontSize( dialog->m_general->dockerFontSize() ); + + // Color settings + cfg.setMonitorProfile( dialog->m_colorSettings->m_page->cmbMonitorProfile->currentText()); + cfg.setWorkingColorSpace( dialog->m_colorSettings->m_page->cmbWorkingColorSpace->currentText()); + cfg.setPrinterColorSpace( dialog->m_colorSettings->m_page->cmbPrintingColorSpace->currentText()); + cfg.setPrinterProfile( dialog->m_colorSettings->m_page->cmbPrintProfile->currentText()); + + cfg.setUseBlackPointCompensation( dialog->m_colorSettings->m_page->chkBlackpoint->isChecked()); + cfg.setPasteBehaviour( dialog->m_colorSettings->m_page->grpPasteBehaviour->selectedId()); + cfg.setRenderIntent( dialog->m_colorSettings->m_page->cmbMonitorIntent->currentItem()); + + // it's scaled from 0 - 6, but the config is in 0 - 300 + cfg.setSwappiness(dialog->m_performanceSettings->m_swappiness->value() * 50); + cfg.setMaxTilesInMem(dialog->m_performanceSettings->m_maxTiles->value()); + // let the tile manager know + KisTileManager::instance()->configChanged(); + + dialog->m_tabletSettings->applySettings(); + +#ifdef HAVE_GL + cfg.setUseOpenGL(dialog->m_displaySettings->cbUseOpenGL->isChecked()); + //cfg.setUseOpenGLShaders(dialog->m_displaySettings->cbUseOpenGLShaders->isChecked()); +#endif + + // Grid settings + cfg.setGridMainStyle( dialog->m_gridSettings->selectMainStyle->currentItem() ); + cfg.setGridSubdivisionStyle( dialog->m_gridSettings->selectSubdivisionStyle->currentItem() ); + + cfg.setGridMainColor( dialog->m_gridSettings->colorMain->color() ); + cfg.setGridSubdivisionColor(dialog->m_gridSettings->colorSubdivision->color() ); + + cfg.setGridHSpacing( dialog->m_gridSettings->intHSpacing->value( )); + cfg.setGridVSpacing( dialog->m_gridSettings->intVSpacing->value( )); + cfg.setGridSubdivisions( dialog->m_gridSettings->intSubdivision->value( )); + cfg.setGridOffsetX( dialog->m_gridSettings->intOffsetX->value( )); + cfg.setGridOffsetY( dialog->m_gridSettings->intOffsetY->value( )); + + } + delete dialog; + return baccept; +} + +#include "kis_dlg_preferences.moc" diff --git a/chalk/ui/kis_doc.cc b/chalk/ui/kis_doc.cpp similarity index 100% rename from chalk/ui/kis_doc.cc rename to chalk/ui/kis_doc.cpp diff --git a/chalk/ui/kis_doc_iface.cc b/chalk/ui/kis_doc_iface.cpp similarity index 100% rename from chalk/ui/kis_doc_iface.cc rename to chalk/ui/kis_doc_iface.cpp diff --git a/chalk/ui/kis_double_widget.cc b/chalk/ui/kis_double_widget.cc deleted file mode 100644 index a966691dd..000000000 --- a/chalk/ui/kis_double_widget.cc +++ /dev/null @@ -1,147 +0,0 @@ -/* - * kis_double_widget.cc - part of Chalk - * - * Copyright (c) 1999 Carsten Pfeiffer - * Copyright (c) 2004 Adrian Page - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include -#include -#include - -#include - -#include "kis_double_widget.h" - -KisDoubleWidget::KisDoubleWidget(TQWidget* parent, const char* name) - : super(parent, name) -{ - init(0, 1); -} - -KisDoubleWidget::KisDoubleWidget(double min, double max, TQWidget* parent, const char* name) - : super(parent, name) -{ - init(min, max); -} - -KisDoubleWidget::~KisDoubleWidget() -{ -} - -void KisDoubleWidget::init(double min, double max) -{ - m_spinBox = new KDoubleSpinBox(min, max, 0.05, 0, 2, this, "spinbox"); - connect(m_spinBox, TQT_SIGNAL(valueChanged(double)), this, TQT_SLOT(setSliderValue(double))); - - m_slider = new TQSlider(static_cast(min * 100 + 0.5), static_cast(max * 100 + 0.5), 1, 0, Qt::Horizontal, this, "sld"); - connect(m_slider, TQT_SIGNAL(valueChanged(int)), this, TQT_SLOT(sliderValueChanged(int))); - connect(m_slider, TQT_SIGNAL(sliderPressed()), TQT_SIGNAL(sliderPressed())); - connect(m_slider, TQT_SIGNAL(sliderReleased()), TQT_SIGNAL(sliderReleased())); - - m_layout = new TQHBoxLayout(this, 0, -1, "hbox layout"); - - m_layout->addWidget(m_slider); - m_layout->addSpacing(5); - m_layout->addWidget(m_spinBox); - m_layout->addItem(new TQSpacerItem(5,1,TQSizePolicy::Expanding, TQSizePolicy::Minimum)); -} - -double KisDoubleWidget::value() const -{ - return m_spinBox->value(); -} - -void KisDoubleWidget::setValue(double value) -{ - int intValue; - - if (value < 0) { - intValue = static_cast(value * 100 - 0.5); - } else { - intValue = static_cast(value * 100 + 0.5); - } - m_slider->setValue(intValue); -} - -void KisDoubleWidget::setRange(double min, double max) -{ - m_spinBox->setRange(min, max); - m_slider->setRange(static_cast(min * 100 + 0.5), static_cast(max * 100 + 0.5)); -} - -void KisDoubleWidget::setTickmarks(TQSlider::TickSetting tickSetting) -{ - m_slider->setTickmarks(tickSetting); -} - -void KisDoubleWidget::setTickInterval(double value) -{ - m_slider->setTickInterval(static_cast(value * 100 + 0.5)); -} - -double KisDoubleWidget::tickInterval() const -{ - return m_slider->tickInterval() / 100.0; -} - -void KisDoubleWidget::setSliderValue(double value) -{ - int intValue; - - if (value < 0) { - intValue = static_cast(value * 100 - 0.5); - } else { - intValue = static_cast(value * 100 + 0.5); - } - m_slider->setValue(intValue); - emit valueChanged(value); -} - -void KisDoubleWidget::sliderValueChanged(int value) -{ - m_spinBox->setValue(value / 100.0); -} - -void KisDoubleWidget::setPrecision(int precision) -{ - m_spinBox->setPrecision(precision); -} - -void KisDoubleWidget::setLineStep(double step) -{ - m_spinBox->setLineStep(step); - m_slider->setLineStep(static_cast(step * 100)); -} - -void KisDoubleWidget::setPageStep(double step) -{ - m_slider->setPageStep(static_cast(step * 100)); -} - -void KisDoubleWidget::setTracking(bool tracking) -{ - m_slider->setTracking(tracking); -} - -bool KisDoubleWidget::tracking() const -{ - return m_slider->tracking(); -} - -#include "kis_double_widget.moc" - diff --git a/chalk/ui/kis_double_widget.cpp b/chalk/ui/kis_double_widget.cpp new file mode 100644 index 000000000..3325f07bb --- /dev/null +++ b/chalk/ui/kis_double_widget.cpp @@ -0,0 +1,147 @@ +/* + * kis_double_widget.cpp - part of Chalk + * + * Copyright (c) 1999 Carsten Pfeiffer + * Copyright (c) 2004 Adrian Page + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include +#include +#include + +#include + +#include "kis_double_widget.h" + +KisDoubleWidget::KisDoubleWidget(TQWidget* parent, const char* name) + : super(parent, name) +{ + init(0, 1); +} + +KisDoubleWidget::KisDoubleWidget(double min, double max, TQWidget* parent, const char* name) + : super(parent, name) +{ + init(min, max); +} + +KisDoubleWidget::~KisDoubleWidget() +{ +} + +void KisDoubleWidget::init(double min, double max) +{ + m_spinBox = new KDoubleSpinBox(min, max, 0.05, 0, 2, this, "spinbox"); + connect(m_spinBox, TQT_SIGNAL(valueChanged(double)), this, TQT_SLOT(setSliderValue(double))); + + m_slider = new TQSlider(static_cast(min * 100 + 0.5), static_cast(max * 100 + 0.5), 1, 0, Qt::Horizontal, this, "sld"); + connect(m_slider, TQT_SIGNAL(valueChanged(int)), this, TQT_SLOT(sliderValueChanged(int))); + connect(m_slider, TQT_SIGNAL(sliderPressed()), TQT_SIGNAL(sliderPressed())); + connect(m_slider, TQT_SIGNAL(sliderReleased()), TQT_SIGNAL(sliderReleased())); + + m_layout = new TQHBoxLayout(this, 0, -1, "hbox layout"); + + m_layout->addWidget(m_slider); + m_layout->addSpacing(5); + m_layout->addWidget(m_spinBox); + m_layout->addItem(new TQSpacerItem(5,1,TQSizePolicy::Expanding, TQSizePolicy::Minimum)); +} + +double KisDoubleWidget::value() const +{ + return m_spinBox->value(); +} + +void KisDoubleWidget::setValue(double value) +{ + int intValue; + + if (value < 0) { + intValue = static_cast(value * 100 - 0.5); + } else { + intValue = static_cast(value * 100 + 0.5); + } + m_slider->setValue(intValue); +} + +void KisDoubleWidget::setRange(double min, double max) +{ + m_spinBox->setRange(min, max); + m_slider->setRange(static_cast(min * 100 + 0.5), static_cast(max * 100 + 0.5)); +} + +void KisDoubleWidget::setTickmarks(TQSlider::TickSetting tickSetting) +{ + m_slider->setTickmarks(tickSetting); +} + +void KisDoubleWidget::setTickInterval(double value) +{ + m_slider->setTickInterval(static_cast(value * 100 + 0.5)); +} + +double KisDoubleWidget::tickInterval() const +{ + return m_slider->tickInterval() / 100.0; +} + +void KisDoubleWidget::setSliderValue(double value) +{ + int intValue; + + if (value < 0) { + intValue = static_cast(value * 100 - 0.5); + } else { + intValue = static_cast(value * 100 + 0.5); + } + m_slider->setValue(intValue); + emit valueChanged(value); +} + +void KisDoubleWidget::sliderValueChanged(int value) +{ + m_spinBox->setValue(value / 100.0); +} + +void KisDoubleWidget::setPrecision(int precision) +{ + m_spinBox->setPrecision(precision); +} + +void KisDoubleWidget::setLineStep(double step) +{ + m_spinBox->setLineStep(step); + m_slider->setLineStep(static_cast(step * 100)); +} + +void KisDoubleWidget::setPageStep(double step) +{ + m_slider->setPageStep(static_cast(step * 100)); +} + +void KisDoubleWidget::setTracking(bool tracking) +{ + m_slider->setTracking(tracking); +} + +bool KisDoubleWidget::tracking() const +{ + return m_slider->tracking(); +} + +#include "kis_double_widget.moc" + diff --git a/chalk/ui/kis_factory.cc b/chalk/ui/kis_factory.cc deleted file mode 100644 index 154213b49..000000000 --- a/chalk/ui/kis_factory.cc +++ /dev/null @@ -1,153 +0,0 @@ -/* - * kis_factory.cc - part of Krayon - * - * Copyright (c) 1999 Matthias Elter - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -#include -#include LCMS_HEADER - -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "kis_aboutdata.h" -#include "kis_resourceserver.h" -#include "kis_paintop_registry.h" -#include "kis_filter_registry.h" -#include "kis_tool_registry.h" -#include "kis_doc.h" -#include "kis_brush.h" -#include "kis_imagepipe_brush.h" -#include "kis_gradient.h" -#include "kis_pattern.h" -#include "kis_palette.h" -#include - -#include "kis_factory.h" - -TDEAboutData* KisFactory::s_aboutData = 0; -TDEInstance* KisFactory::s_instance = 0; - - - -KisFactory::KisFactory( TQObject* parent, const char* name ) - : KoFactory( parent, name ) -{ - s_aboutData = newChalkAboutData(); - - (void)instance(); - - // Load extension modules and plugins - KisToolRegistry::instance(); - KisPaintOpRegistry::instance(); - KisFilterRegistry::instance(); - KisResourceServerRegistry::instance(); - - - -} - -KisFactory::~KisFactory() -{ - delete s_aboutData; - s_aboutData = 0L; - delete s_instance; - s_instance = 0L; -} - -/** - * Create the document - */ -KParts::Part* KisFactory::createPartObject( TQWidget *parentWidget, - const char *widgetName, TQObject* parent, - const char* name, const char* classname, const TQStringList & ) -{ - bool bWantKoDocument = ( strcmp( classname, "KoDocument" ) == 0 ); - - KisDoc *doc = new KisDoc( parentWidget, - widgetName, parent, name, !bWantKoDocument ); - TQ_CHECK_PTR(doc); - - if ( !bWantKoDocument ) - doc->setReadWrite( false ); - - return doc; -} - - -TDEAboutData* KisFactory::aboutData() -{ - return s_aboutData; -} - -TDEInstance* KisFactory::instance() -{ - TQString homedir = getenv("HOME"); - - if ( !s_instance ) - { - s_instance = new TDEInstance(s_aboutData); - TQ_CHECK_PTR(s_instance); - - s_instance->dirs()->addResourceType("chalk_template", TDEStandardDirs::kde_default("data") + "chalk/templates"); - - // XXX: Are these obsolete? - s_instance->dirs()->addResourceType("kis", TDEStandardDirs::kde_default("data") + "chalk/"); - - s_instance->dirs()->addResourceType("kis_pics", TDEStandardDirs::kde_default("data") + "chalk/pics/"); - - s_instance->dirs()->addResourceType("kis_images", TDEStandardDirs::kde_default("data") + "chalk/images/"); - - s_instance->dirs()->addResourceType("toolbars", TDEStandardDirs::kde_default("data") + "koffice/toolbar/"); - - // Create spec - - s_instance->dirs()->addResourceType("kis_brushes", TDEStandardDirs::kde_default("data") + "chalk/brushes/"); - s_instance->dirs()->addResourceDir("kis_brushes", "/usr/share/create/brushes/gimp"); - s_instance->dirs()->addResourceDir("kis_brushes", TQDir::homeDirPath() + TQString("/.create/brushes/gimp")); - - s_instance->dirs()->addResourceType("kis_patterns", TDEStandardDirs::kde_default("data") + "chalk/patterns/"); - s_instance->dirs()->addResourceDir("kis_patterns", "/usr/share/create/patterns/gimp"); - s_instance->dirs()->addResourceDir("kis_patterns", TQDir::homeDirPath() + TQString("/.create/patterns/gimp")); - - s_instance->dirs()->addResourceType("kis_gradients", TDEStandardDirs::kde_default("data") + "chalk/gradients/"); - s_instance->dirs()->addResourceDir("kis_gradients", "/usr/share/create/gradients/gimp"); - s_instance->dirs()->addResourceDir("kis_gradients", TQDir::homeDirPath() + TQString("/.create/gradients/gimp")); - - s_instance->dirs()->addResourceType("kis_profiles", TDEStandardDirs::kde_default("data") + "chalk/profiles/"); - s_instance->dirs()->addResourceDir("kis_profiles", "/usr/share/color/icc"); - s_instance->dirs()->addResourceDir("kis_profiles", TQDir::homeDirPath() + TQString("/.icc")); - s_instance->dirs()->addResourceDir("kis_profiles", TQDir::homeDirPath() + TQString("/.color/icc")); - - s_instance->dirs()->addResourceType("kis_palettes", TDEStandardDirs::kde_default("data") + "chalk/palettes/"); - s_instance->dirs()->addResourceDir("kis_palettes", "/usr/share/create/swatches"); - s_instance->dirs()->addResourceDir("kis_palettes", TQDir::homeDirPath() + TQString("/.create/swatches")); - - // Tell the iconloader about share/apps/koffice/icons - s_instance->iconLoader()->addAppDir("koffice"); - } - - return s_instance; -} - -#include "kis_factory.moc" diff --git a/chalk/ui/kis_factory.cpp b/chalk/ui/kis_factory.cpp new file mode 100644 index 000000000..e9e51e487 --- /dev/null +++ b/chalk/ui/kis_factory.cpp @@ -0,0 +1,153 @@ +/* + * kis_factory.cpp - part of Krayon + * + * Copyright (c) 1999 Matthias Elter + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +#include +#include LCMS_HEADER + +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "kis_aboutdata.h" +#include "kis_resourceserver.h" +#include "kis_paintop_registry.h" +#include "kis_filter_registry.h" +#include "kis_tool_registry.h" +#include "kis_doc.h" +#include "kis_brush.h" +#include "kis_imagepipe_brush.h" +#include "kis_gradient.h" +#include "kis_pattern.h" +#include "kis_palette.h" +#include + +#include "kis_factory.h" + +TDEAboutData* KisFactory::s_aboutData = 0; +TDEInstance* KisFactory::s_instance = 0; + + + +KisFactory::KisFactory( TQObject* parent, const char* name ) + : KoFactory( parent, name ) +{ + s_aboutData = newChalkAboutData(); + + (void)instance(); + + // Load extension modules and plugins + KisToolRegistry::instance(); + KisPaintOpRegistry::instance(); + KisFilterRegistry::instance(); + KisResourceServerRegistry::instance(); + + + +} + +KisFactory::~KisFactory() +{ + delete s_aboutData; + s_aboutData = 0L; + delete s_instance; + s_instance = 0L; +} + +/** + * Create the document + */ +KParts::Part* KisFactory::createPartObject( TQWidget *parentWidget, + const char *widgetName, TQObject* parent, + const char* name, const char* classname, const TQStringList & ) +{ + bool bWantKoDocument = ( strcmp( classname, "KoDocument" ) == 0 ); + + KisDoc *doc = new KisDoc( parentWidget, + widgetName, parent, name, !bWantKoDocument ); + TQ_CHECK_PTR(doc); + + if ( !bWantKoDocument ) + doc->setReadWrite( false ); + + return doc; +} + + +TDEAboutData* KisFactory::aboutData() +{ + return s_aboutData; +} + +TDEInstance* KisFactory::instance() +{ + TQString homedir = getenv("HOME"); + + if ( !s_instance ) + { + s_instance = new TDEInstance(s_aboutData); + TQ_CHECK_PTR(s_instance); + + s_instance->dirs()->addResourceType("chalk_template", TDEStandardDirs::kde_default("data") + "chalk/templates"); + + // XXX: Are these obsolete? + s_instance->dirs()->addResourceType("kis", TDEStandardDirs::kde_default("data") + "chalk/"); + + s_instance->dirs()->addResourceType("kis_pics", TDEStandardDirs::kde_default("data") + "chalk/pics/"); + + s_instance->dirs()->addResourceType("kis_images", TDEStandardDirs::kde_default("data") + "chalk/images/"); + + s_instance->dirs()->addResourceType("toolbars", TDEStandardDirs::kde_default("data") + "koffice/toolbar/"); + + // Create spec + + s_instance->dirs()->addResourceType("kis_brushes", TDEStandardDirs::kde_default("data") + "chalk/brushes/"); + s_instance->dirs()->addResourceDir("kis_brushes", "/usr/share/create/brushes/gimp"); + s_instance->dirs()->addResourceDir("kis_brushes", TQDir::homeDirPath() + TQString("/.create/brushes/gimp")); + + s_instance->dirs()->addResourceType("kis_patterns", TDEStandardDirs::kde_default("data") + "chalk/patterns/"); + s_instance->dirs()->addResourceDir("kis_patterns", "/usr/share/create/patterns/gimp"); + s_instance->dirs()->addResourceDir("kis_patterns", TQDir::homeDirPath() + TQString("/.create/patterns/gimp")); + + s_instance->dirs()->addResourceType("kis_gradients", TDEStandardDirs::kde_default("data") + "chalk/gradients/"); + s_instance->dirs()->addResourceDir("kis_gradients", "/usr/share/create/gradients/gimp"); + s_instance->dirs()->addResourceDir("kis_gradients", TQDir::homeDirPath() + TQString("/.create/gradients/gimp")); + + s_instance->dirs()->addResourceType("kis_profiles", TDEStandardDirs::kde_default("data") + "chalk/profiles/"); + s_instance->dirs()->addResourceDir("kis_profiles", "/usr/share/color/icc"); + s_instance->dirs()->addResourceDir("kis_profiles", TQDir::homeDirPath() + TQString("/.icc")); + s_instance->dirs()->addResourceDir("kis_profiles", TQDir::homeDirPath() + TQString("/.color/icc")); + + s_instance->dirs()->addResourceType("kis_palettes", TDEStandardDirs::kde_default("data") + "chalk/palettes/"); + s_instance->dirs()->addResourceDir("kis_palettes", "/usr/share/create/swatches"); + s_instance->dirs()->addResourceDir("kis_palettes", TQDir::homeDirPath() + TQString("/.create/swatches")); + + // Tell the iconloader about share/apps/koffice/icons + s_instance->iconLoader()->addAppDir("koffice"); + } + + return s_instance; +} + +#include "kis_factory.moc" diff --git a/chalk/ui/kis_filter_manager.cc b/chalk/ui/kis_filter_manager.cpp similarity index 100% rename from chalk/ui/kis_filter_manager.cc rename to chalk/ui/kis_filter_manager.cpp diff --git a/chalk/ui/kis_filters_listview.cc b/chalk/ui/kis_filters_listview.cpp similarity index 100% rename from chalk/ui/kis_filters_listview.cc rename to chalk/ui/kis_filters_listview.cpp diff --git a/chalk/ui/kis_gradient_chooser.cc b/chalk/ui/kis_gradient_chooser.cpp similarity index 100% rename from chalk/ui/kis_gradient_chooser.cc rename to chalk/ui/kis_gradient_chooser.cpp diff --git a/chalk/ui/kis_gradient_slider_widget.cc b/chalk/ui/kis_gradient_slider_widget.cpp similarity index 100% rename from chalk/ui/kis_gradient_slider_widget.cc rename to chalk/ui/kis_gradient_slider_widget.cpp diff --git a/chalk/ui/kis_histogram_view.cc b/chalk/ui/kis_histogram_view.cpp similarity index 100% rename from chalk/ui/kis_histogram_view.cc rename to chalk/ui/kis_histogram_view.cpp diff --git a/chalk/ui/kis_icon_item.cc b/chalk/ui/kis_icon_item.cpp similarity index 100% rename from chalk/ui/kis_icon_item.cc rename to chalk/ui/kis_icon_item.cpp diff --git a/chalk/ui/kis_iconwidget.cc b/chalk/ui/kis_iconwidget.cpp similarity index 100% rename from chalk/ui/kis_iconwidget.cc rename to chalk/ui/kis_iconwidget.cpp diff --git a/chalk/ui/kis_import_catcher.cc b/chalk/ui/kis_import_catcher.cpp similarity index 100% rename from chalk/ui/kis_import_catcher.cc rename to chalk/ui/kis_import_catcher.cpp diff --git a/chalk/ui/kis_input_device.cc b/chalk/ui/kis_input_device.cpp similarity index 100% rename from chalk/ui/kis_input_device.cc rename to chalk/ui/kis_input_device.cpp diff --git a/chalk/ui/kis_int_spinbox.cc b/chalk/ui/kis_int_spinbox.cpp similarity index 100% rename from chalk/ui/kis_int_spinbox.cc rename to chalk/ui/kis_int_spinbox.cpp diff --git a/chalk/ui/kis_itemchooser.cc b/chalk/ui/kis_itemchooser.cpp similarity index 100% rename from chalk/ui/kis_itemchooser.cc rename to chalk/ui/kis_itemchooser.cpp diff --git a/chalk/ui/kis_label_cursor_pos.cc b/chalk/ui/kis_label_cursor_pos.cpp similarity index 100% rename from chalk/ui/kis_label_cursor_pos.cc rename to chalk/ui/kis_label_cursor_pos.cpp diff --git a/chalk/ui/kis_label_progress.cc b/chalk/ui/kis_label_progress.cpp similarity index 100% rename from chalk/ui/kis_label_progress.cc rename to chalk/ui/kis_label_progress.cpp diff --git a/chalk/ui/kis_label_zoom.cc b/chalk/ui/kis_label_zoom.cpp similarity index 100% rename from chalk/ui/kis_label_zoom.cc rename to chalk/ui/kis_label_zoom.cpp diff --git a/chalk/ui/kis_layerbox.cc b/chalk/ui/kis_layerbox.cc deleted file mode 100644 index 058eb2f96..000000000 --- a/chalk/ui/kis_layerbox.cc +++ /dev/null @@ -1,675 +0,0 @@ -/* - * kis_layerbox.cc - part of Chalk aka Krayon aka KimageShop - * - * Copyright (c) 2002 Patrick Julien - * Copyright (C) 2006 Gábor Lehel - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include "kis_layerlist.h" -#include "kis_cmb_composite.h" -#include "kis_int_spinbox.h" -#include "wdglayerbox.h" -#include "kis_colorspace.h" -#include "kis_paint_device.h" -#include "kis_layer.h" -#include "kis_group_layer.h" -#include "kis_image.h" - -#include "kis_populate_visitor.h" - -#include "kis_layerbox.h" - -KisLayerBox::KisLayerBox(KisCanvasSubject *subject, TQWidget *parent, const char *name) - : super(parent, name), m_image(0) -{ - TQVBoxLayout *vbox = new TQVBoxLayout(this); - vbox->setAutoAdd(true); - - m_lst = new WdgLayerBox(this); - setMinimumSize(m_lst->minimumSizeHint()); - - TQToolTip::add(m_lst->bnAdd, i18n("Create new layer")); - - TQToolTip::add(m_lst->bnDelete, i18n("Remove current layer")); - - TQToolTip::add(m_lst->bnRaise, i18n("Raise current layer")); - m_lst->bnRaise->setEnabled(false); - - m_lst->bnLower->setEnabled(false); - TQToolTip::add(m_lst->bnLower, i18n("Lower current layer")); - - TQToolTip::add(m_lst->bnProperties, i18n("Properties for layer")); - - TDEIconLoader il( "chalk" ); - - list()->setPreviewsShown(true); - - list()->setFoldersCanBeActive(true); - - list()->addProperty("visible", i18n("Visible"), loadPixmap("visible.png", il, TDEIcon::SizeSmallMedium), - loadPixmap("novisible.png", il, TDEIcon::SizeSmallMedium), true); - - list()->addProperty("locked", i18n("Locked"), loadPixmap("locked.png", il, TDEIcon::SizeSmallMedium), - loadPixmap("unlocked.png", il, TDEIcon::SizeSmallMedium)); - - - connect(list()->contextMenu(), TQT_SIGNAL(aboutToShow()), TQT_SLOT(slotAboutToShow())); - connect(list(), TQT_SIGNAL(activated(LayerItem*)), - TQT_SLOT(slotLayerActivated(LayerItem*))); - connect(list(), TQT_SIGNAL(displayNameChanged(LayerItem*, const TQString&)), - TQT_SLOT(slotLayerDisplayNameChanged(LayerItem*, const TQString&))); - connect(list(), TQT_SIGNAL(propertyChanged(LayerItem*, const TQString&, bool)), - TQT_SLOT(slotLayerPropertyChanged(LayerItem*, const TQString&, bool))); - connect(list(), TQT_SIGNAL(layerMoved(LayerItem*, LayerItem*, LayerItem*)), - TQT_SLOT(slotLayerMoved(LayerItem*, LayerItem*, LayerItem*))); - connect(list(), TQT_SIGNAL(requestNewLayer(LayerItem*, LayerItem*)), - TQT_SLOT(slotRequestNewLayer(LayerItem*, LayerItem*))); - connect(list(), TQT_SIGNAL(requestNewFolder(LayerItem*, LayerItem*)), - TQT_SLOT(slotRequestNewFolder(LayerItem*, LayerItem*))); - connect(list(), TQT_SIGNAL(requestNewAdjustmentLayer(LayerItem*, LayerItem*)), - TQT_SLOT(slotRequestNewAdjustmentLayer(LayerItem*, LayerItem*))); - connect(list(), TQT_SIGNAL(requestNewObjectLayer(LayerItem*, LayerItem*, const KoDocumentEntry&)), - TQT_SLOT(slotRequestNewObjectLayer(LayerItem*, LayerItem*, const KoDocumentEntry&))); - connect(list(), TQT_SIGNAL(requestRemoveLayer(LayerItem*)), - TQT_SLOT(slotRequestRemoveLayer(LayerItem*))); - connect(list(), TQT_SIGNAL(requestLayerProperties(LayerItem*)), - TQT_SLOT(slotRequestLayerProperties(LayerItem*))); - - m_newLayerMenu = new TDEPopupMenu(this); - m_lst->bnAdd->setPopup(m_newLayerMenu); - m_lst->bnAdd->setPopupDelay(1); - m_newLayerMenu->insertItem( SmallIconSet( "document-new" ), i18n( "&New Layer..." ), PAINT_LAYER ); - m_newLayerMenu->insertItem( SmallIconSet( "folder" ), i18n( "New &Group Layer..." ), GROUP_LAYER ); - m_newLayerMenu->insertItem( SmallIconSet( "tool_filter" ), i18n( "New &Adjustment Layer..." ), ADJUSTMENT_LAYER ); - m_partLayerAction = new KoPartSelectAction( i18n( "New &Object Layer" ), "gear", TQT_TQOBJECT(this) ); - m_partLayerAction->plug( m_newLayerMenu ); - connect(m_partLayerAction, TQT_SIGNAL(activated()), this, TQT_SLOT(slotAddMenuActivated())); - connect(m_newLayerMenu, TQT_SIGNAL(activated(int)), this, TQT_SLOT(slotAddMenuActivated(int))); - - - connect(m_lst->bnDelete, TQT_SIGNAL(clicked()), TQT_SLOT(slotRmClicked())); - connect(m_lst->bnRaise, TQT_SIGNAL(clicked()), TQT_SLOT(slotRaiseClicked())); - connect(m_lst->bnLower, TQT_SIGNAL(clicked()), TQT_SLOT(slotLowerClicked())); - connect(m_lst->bnProperties, TQT_SIGNAL(clicked()), TQT_SLOT(slotPropertiesClicked())); - connect(m_lst->intOpacity, TQT_SIGNAL(valueChanged(int, bool)), TQT_SIGNAL(sigOpacityChanged(int, bool))); - connect(m_lst->intOpacity, TQT_SIGNAL(finishedChanging(int, int)), TQT_SIGNAL(sigOpacityFinishedChanging(int, int))); - connect(m_lst->cmbComposite, TQT_SIGNAL(activated(const KisCompositeOp&)), TQT_SIGNAL(sigItemComposite(const KisCompositeOp&))); - - Q_ASSERT(subject->document() != 0); - - if (subject->document()) { - connect(subject->document(), TQT_SIGNAL(sigCommandExecuted()), TQT_SLOT(updateThumbnails())); - } -} - -KisLayerBox::~KisLayerBox() -{ -} - -KisLayerList* KisLayerBox::list() const -{ - return m_lst->listLayers; -} - -void KisLayerBox::setImage(KisImageSP img) -{ - if (m_image == img) - return; - - if (m_image) - m_image->disconnect(this); - - m_image = img; - - if (img) - { - connect(img, TQT_SIGNAL(sigLayerActivated(KisLayerSP)), this, TQT_SLOT(slotLayerActivated(KisLayerSP))); - connect(img, TQT_SIGNAL(sigLayerAdded(KisLayerSP)), this, TQT_SLOT(slotLayerAdded(KisLayerSP))); - connect(img, TQT_SIGNAL(sigLayerRemoved(KisLayerSP, KisGroupLayerSP, KisLayerSP)), - this, TQT_SLOT(slotLayerRemoved(KisLayerSP, KisGroupLayerSP, KisLayerSP))); - connect(img, TQT_SIGNAL(sigLayerPropertiesChanged(KisLayerSP)), - this, TQT_SLOT(slotLayerPropertiesChanged(KisLayerSP))); - connect(img, TQT_SIGNAL(sigLayerMoved(KisLayerSP, KisGroupLayerSP, KisLayerSP)), - this, TQT_SLOT(slotLayerMoved(KisLayerSP, KisGroupLayerSP, KisLayerSP))); - connect(img, TQT_SIGNAL(sigLayersChanged(KisGroupLayerSP)), this, TQT_SLOT(slotLayersChanged(KisGroupLayerSP))); - connect(img, TQT_SIGNAL(sigLayerUpdated(KisLayerSP, TQRect)), this, TQT_SLOT(slotLayerUpdated(KisLayerSP, TQRect))); - slotLayersChanged(img->rootLayer()); - updateThumbnails(); - } - else - { - clear(); - } -} - -void KisLayerBox::slotLayerActivated(KisLayerSP layer) -{ - if (layer) - list()->setActiveLayer(layer->id()); - else - list()->setActiveLayer(-1); - updateUI(); -} - -void KisLayerBox::slotLayerAdded(KisLayerSP layer) -{ - if (layer.data() == m_image->rootLayer().data() || list()->layer(layer->id())) - return; - - vKisLayerSP layersAdded; - - if (layer->parent() == m_image->rootLayer()) - { - KisPopulateVisitor visitor(list()); - layer->accept(visitor); - layersAdded = visitor.layersAdded(); - } - else - { - KisPopulateVisitor visitor(static_cast(list()->layer(layer->parent()->id()))); - layer->accept(visitor); - layersAdded = visitor.layersAdded(); - } - - for (vKisLayerSP::iterator it = layersAdded.begin(); it != layersAdded.end(); ++it) { - markModified(*it); - } - updateUI(); -} - -void KisLayerBox::slotLayerRemoved(KisLayerSP layer, KisGroupLayerSP wasParent, KisLayerSP) -{ - list()->removeLayer(layer->id()); - m_modified.remove(layer->id()); - markModified(wasParent); - updateUI(); -} - -void KisLayerBox::slotLayerMoved(KisLayerSP layer, KisGroupLayerSP wasParent, KisLayerSP) -{ - int parentID = layer->parent()->id(); - if (layer->parent() == m_image->rootLayer()) - parentID = -1; - - int siblingID = -1; - if (layer->prevSibling()) - siblingID = layer->prevSibling()->id(); - - list()->moveLayer(layer->id(), parentID, siblingID); - - markModified(layer->parent()); - markModified(wasParent); - updateUI(); -} - -void KisLayerBox::slotLayerPropertiesChanged(KisLayerSP layer) -{ - if (KisLayerItem* item = dynamic_cast(list()->layer(layer->id()))) - { - Q_ASSERT(item->layer() == layer.data()); - item->sync(); - updateUI(); - markModified(layer); - } -} - -void KisLayerBox::slotLayersChanged(KisGroupLayerSP rootLayer) -{ - list()->clear(); - KisPopulateVisitor visitor(list()); - for (KisLayerSP layer = rootLayer->firstChild(); layer; layer = layer->nextSibling()) - layer->accept(visitor); - m_modified.clear(); - for (TQListViewItemIterator it(list()->lastItem()); *it; --it) - m_modified.append(static_cast(*it)->id()); - updateUI(); -} - -void KisLayerBox::slotLayerUpdated(KisLayerSP layer, TQRect) -{ - markModified(layer); -} - -void KisLayerBox::slotLayerActivated(LayerItem* item) -{ - if (item) - m_image->activate(m_image->findLayer(item->id())); - else - m_image->activate(0); - updateUI(); -} - -void KisLayerBox::slotLayerDisplayNameChanged(LayerItem* item, const TQString& displayName) -{ - if(KisLayerSP layer = m_image->findLayer(item->id())) - layer->setName(displayName); - updateUI(); -} - -void KisLayerBox::slotLayerPropertyChanged(LayerItem* item, const TQString& name, bool on) -{ - if (KisLayerSP layer = m_image->findLayer(item->id())) - { - if (name == "visible") - layer->setVisible(on); - else if (name == "locked") - layer->setLocked(on); - } -} - -void KisLayerBox::slotLayerMoved(LayerItem* item, LayerItem*, LayerItem*) -{ - KisLayerSP layer = m_image->findLayer(item->id()); - KisGroupLayerSP parent; - if( item->parent() ) - parent = dynamic_cast(m_image->findLayer(item->parent()->id()).data()); - if( !parent ) - parent = m_image->rootLayer(); - KisLayerSP above = 0; - if (item->nextSibling()) - above = m_image->findLayer(item->nextSibling()->id()); - if (layer) - m_image->moveLayer(layer, parent.data(), above); - updateUI(); -} - -void KisLayerBox::slotRequestNewLayer(LayerItem* p, LayerItem* after) -{ - KisLayer* l = m_image->rootLayer().data(); - if (p) - l = m_image->findLayer(p->id()).data(); - KisGroupLayerSP parent = dynamic_cast(l); - - KisLayerSP above = 0; - if (after && after->nextSibling()) - above = m_image->findLayer(after->nextSibling()->id()); - else if (after) - above = 0; - else if (p && p->firstChild()) - above = parent->firstChild(); - else if (!p && m_image->rootLayer()->childCount()) - above = m_image->rootLayer()->firstChild(); - emit sigRequestLayer(parent, above); -} - -void KisLayerBox::slotRequestNewFolder(LayerItem* p, LayerItem* after) -{ - KisLayer* l = m_image->rootLayer().data(); //FIXME I hate copy-pasting like this. - if (p) - l = m_image->findLayer(p->id()).data(); - KisGroupLayerSP parent = dynamic_cast(l); - - KisLayerSP above = 0; - if (after && after->nextSibling()) - above = m_image->findLayer(after->nextSibling()->id()); - else if (after) - above = 0; - else if (p && p->firstChild()) - above = parent->firstChild(); - else if (!p && m_image->rootLayer()->childCount()) - above = m_image->rootLayer()->firstChild(); - emit sigRequestGroupLayer(parent, above); -} - -void KisLayerBox::slotRequestNewAdjustmentLayer(LayerItem* p, LayerItem* after) -{ - KisLayer* l = m_image->rootLayer().data(); //FIXME here too. - if (p) - l = m_image->findLayer(p->id()).data(); - KisGroupLayerSP parent = dynamic_cast(l); - - KisLayerSP above = 0; - if (after && after->nextSibling()) - above = m_image->findLayer(after->nextSibling()->id()); - else if (after) - above = 0; - else if (p && p->firstChild()) - above = parent->firstChild(); - else if (!p && m_image->rootLayer()->childCount()) - above = m_image->rootLayer()->firstChild(); - emit sigRequestAdjustmentLayer(parent, above); -} - -void KisLayerBox::slotRequestNewObjectLayer(LayerItem* p, LayerItem* after, const KoDocumentEntry& entry) -{ - KisLayer* l = m_image->rootLayer().data(); //FIXME and here. - if (p) - l = m_image->findLayer(p->id()).data(); - KisGroupLayerSP parent = dynamic_cast(l); - - KisLayerSP above = 0; - if (after && after->nextSibling()) - above = m_image->findLayer(after->nextSibling()->id()); - else if (after) - above = 0; - else if (p && p->firstChild()) - above = parent->firstChild(); - else if (!p && m_image->rootLayer()->childCount()) - above = m_image->rootLayer()->firstChild(); - emit sigRequestPartLayer(parent, above, entry); -} - -void KisLayerBox::slotRequestRemoveLayer(LayerItem* item) -{ - if (KisLayerSP layer = m_image->findLayer(item->id())) { - m_image->removeLayer(layer); - } - updateUI(); -} - -void KisLayerBox::slotRequestLayerProperties(LayerItem* item) -{ - if (KisLayerSP layer = m_image->findLayer(item->id())) - { - emit sigRequestLayerProperties(layer); - } -} - -void KisLayerBox::updateUI() -{ - m_lst->bnDelete->setEnabled(list()->activeLayer()); - m_lst->bnRaise->setEnabled(list()->activeLayer() && (list()->activeLayer()->prevSibling() || list()->activeLayer()->parent())); - m_lst->bnLower->setEnabled(list()->activeLayer() && list()->activeLayer()->nextSibling()); - m_lst->intOpacity->setEnabled(list()->activeLayer()); - m_lst->cmbComposite->setEnabled(list()->activeLayer()); - if (m_image) - if (KisLayerSP active = m_image->activeLayer()) - { - if (m_image->activeDevice()) - slotSetColorSpace(m_image->activeDevice()->colorSpace()); - else - slotSetColorSpace(m_image->colorSpace()); - slotSetOpacity(int(float(active->opacity() * 100) / 255 + 0.5)); - slotSetCompositeOp(active->compositeOp()); - } -} - -void KisLayerBox::slotAboutToShow() -{ -} - -void KisLayerBox::slotSetCompositeOp(const KisCompositeOp& compositeOp) -{ - m_lst->cmbComposite->blockSignals(true); - m_lst->cmbComposite->setCurrentItem(compositeOp); - m_lst->cmbComposite->blockSignals(false); -} - -void KisLayerBox::slotSetColorSpace(const KisColorSpace * colorSpace) -{ - m_lst->cmbComposite->blockSignals(true); - m_lst->cmbComposite->setCompositeOpList(colorSpace->userVisiblecompositeOps()); - m_lst->cmbComposite->blockSignals(false); -} - -// range: 0-100 -void KisLayerBox::slotSetOpacity(int opacity) -{ - m_lst->intOpacity->blockSignals(true); - m_lst->intOpacity->setValue(opacity); - m_lst->intOpacity->blockSignals(false); -} - -void KisLayerBox::clear() -{ - list()->clear(); - updateUI(); -} - -void KisLayerBox::slotAddMenuActivated(int type) -{ - if(type == -1) - return; - - KisGroupLayerSP root = m_image->rootLayer(); - KisGroupLayerSP parent; - KisLayerSP above; - if (KisLayerSP active = m_image->activeLayer()) - { - parent = root; - above = active; - if (active->parent()) - parent = active->parent(); - } - else - { - parent = root; - above = m_image->rootLayer()->firstChild(); - } - - switch (type) - { - case PAINT_LAYER: - emit sigRequestLayer(parent, above); - break; - case GROUP_LAYER: - emit sigRequestGroupLayer(parent, above); - break; - case ADJUSTMENT_LAYER: - emit sigRequestAdjustmentLayer(parent, above); - break; - case OBJECT_LAYER: - default: //TQt doesn't emit activated for default-assigned IDs, so this does nothing - emit sigRequestPartLayer(parent, above, m_partLayerAction->documentEntry()); - } -} - -void KisLayerBox::slotRmClicked() -{ - TQValueList l = list()->selectedLayerIDs(); - if (l.count() < 2 && list()->activeLayer() && !l.contains(list()->activeLayer()->id())) - { - l.clear(); - l.append(list()->activeLayer()->id()); - } - - for (int i = 0, n = l.count(); i < n; ++i) - { - m_modified.remove(l[i]); - m_image->removeLayer(m_image->findLayer(l[i])); - } -} - -void KisLayerBox::slotRaiseClicked() -{ - TQValueList l = list()->selectedLayerIDs(); - if (l.count() < 2 && list()->activeLayer() && !l.contains(list()->activeLayer()->id())) - { - l.clear(); - l.append(list()->activeLayer()->id()); - } - - KisLayerSP layer = m_image->findLayer(l.first()); - if( l.count() == 1 && layer == layer->parent()->firstChild() && layer->parent() != m_image->rootLayer()) - { - if (KisGroupLayerSP grandparent = layer->parent()->parent()) - m_image->moveLayer(layer, grandparent, layer->parent().data()); - } - else - { - for (int i = 0, n = l.count(); i < n; ++i) - if (KisLayerSP li = m_image->findLayer(l[i])) - if (li->prevSibling()) - m_image->moveLayer(li, li->parent(), li->prevSibling()); - } - - if( !l.isEmpty() ) - list()->ensureItemVisible( list()->layer( l.first() ) ); -} - -void KisLayerBox::slotLowerClicked() -{ - TQValueList l = list()->selectedLayers(); - if (l.count() < 2 && list()->activeLayer() && !l.contains(list()->activeLayer())) - { - l.clear(); - l.append(list()->activeLayer()); - } - - for (int i = l.count() - 1; i >= 0; --i) - if (LayerItem *layer = l[i]) - if (layer->nextSibling()) - list()->moveLayer(layer, layer->parent(), layer->nextSibling()); - - if( !l.isEmpty() ) - list()->ensureItemVisible( l.last() ); -} - -void KisLayerBox::slotPropertiesClicked() -{ - if (KisLayerSP active = m_image->activeLayer()) - emit sigRequestLayerProperties(active); -} - -void KisLayerBox::updateThumbnails() -{ - bool again = true; - while (m_modified.count() && again) - { - //again = false; - KisLayerItem* item = static_cast(list()->layer(m_modified.last())); - m_modified.pop_back(); - if (!item || !item->updatePreview()) - again = true; - } -} - -void KisLayerBox::setUpdatesAndSignalsEnabled(bool enable) -{ - setUpdatesEnabled(enable); - m_lst->intOpacity->setUpdatesEnabled(enable); - m_lst->cmbComposite->setUpdatesEnabled(enable); - - list()->blockSignals(!enable); - m_lst->intOpacity->blockSignals(!enable); - m_lst->cmbComposite->blockSignals(!enable); -} - - -TQPixmap KisLayerBox::loadPixmap(const TQString& filename, const TDEIconLoader& - il, int size) -{ - TQPixmap pixmap = il.loadIcon(filename, TDEIcon::NoGroup, size); - - if (pixmap.isNull()) - KMessageBox::error(0, i18n("Cannot find %1").arg(filename), - i18n("Canvas")); - - return pixmap; -} - -void KisLayerBox::markModified(KisLayer* layer) -{ - if( !layer ) - return; - - TQValueList v; - while (layer && layer != m_image->rootLayer().data()) - { - v.append(layer->id()); - layer = layer->parent(); - } - for (int i = v.count() - 1; i >= 0; --i) - if (!m_modified.contains(v[i])) - m_modified.append(v[i]); -} - -void KisLayerBox::printChalkLayers() const -{ - static int indent = 0; - static KisLayer *root = 0; - if( !root ) - root = m_image->rootLayer(); - if( !root ) - return; - TQString s = root->name(); - if( dynamic_cast( root ) ) - s = TQString("[%1]").arg( s ); - if( m_image->activeLayer().data() == root ) - s.prepend("*"); - kdDebug() << (TQString().fill(' ', indent) + s) << endl; - for (KisLayer* layer = root->firstChild(); layer; layer = layer->nextSibling()) - { - indent += 2; - root = layer; - printChalkLayers(); - indent -= 2; - root = layer->parent(); - } -} - -void KisLayerBox::printLayerboxLayers() const -{ - static int indent = 0; - static LayerItem *root = 0; - if( !root ) - { - for (LayerItem* layer = list()->firstChild(); layer; layer = layer->nextSibling()) - { - indent += 2; - root = layer; - printLayerboxLayers(); - indent -= 2; - root = layer->parent(); - } - return; - } - TQString s = root->displayName(); - if( root->isFolder() ) - s = TQString("[%1]").arg( s ); - if( list()->activeLayer() == root ) - s.prepend("*"); - kdDebug() << (TQString().fill(' ', indent) + s) << endl; - for (LayerItem* layer = root->firstChild(); layer; layer = layer->nextSibling()) - { - indent += 2; - root = layer; - printLayerboxLayers(); - indent -= 2; - root = layer->parent(); - } -} - -#include "kis_layerbox.moc" diff --git a/chalk/ui/kis_layerbox.cpp b/chalk/ui/kis_layerbox.cpp new file mode 100644 index 000000000..1d769fb42 --- /dev/null +++ b/chalk/ui/kis_layerbox.cpp @@ -0,0 +1,675 @@ +/* + * kis_layerbox.cpp - part of Chalk aka Krayon aka KimageShop + * + * Copyright (c) 2002 Patrick Julien + * Copyright (C) 2006 Gábor Lehel + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "kis_layerlist.h" +#include "kis_cmb_composite.h" +#include "kis_int_spinbox.h" +#include "wdglayerbox.h" +#include "kis_colorspace.h" +#include "kis_paint_device.h" +#include "kis_layer.h" +#include "kis_group_layer.h" +#include "kis_image.h" + +#include "kis_populate_visitor.h" + +#include "kis_layerbox.h" + +KisLayerBox::KisLayerBox(KisCanvasSubject *subject, TQWidget *parent, const char *name) + : super(parent, name), m_image(0) +{ + TQVBoxLayout *vbox = new TQVBoxLayout(this); + vbox->setAutoAdd(true); + + m_lst = new WdgLayerBox(this); + setMinimumSize(m_lst->minimumSizeHint()); + + TQToolTip::add(m_lst->bnAdd, i18n("Create new layer")); + + TQToolTip::add(m_lst->bnDelete, i18n("Remove current layer")); + + TQToolTip::add(m_lst->bnRaise, i18n("Raise current layer")); + m_lst->bnRaise->setEnabled(false); + + m_lst->bnLower->setEnabled(false); + TQToolTip::add(m_lst->bnLower, i18n("Lower current layer")); + + TQToolTip::add(m_lst->bnProperties, i18n("Properties for layer")); + + TDEIconLoader il( "chalk" ); + + list()->setPreviewsShown(true); + + list()->setFoldersCanBeActive(true); + + list()->addProperty("visible", i18n("Visible"), loadPixmap("visible.png", il, TDEIcon::SizeSmallMedium), + loadPixmap("novisible.png", il, TDEIcon::SizeSmallMedium), true); + + list()->addProperty("locked", i18n("Locked"), loadPixmap("locked.png", il, TDEIcon::SizeSmallMedium), + loadPixmap("unlocked.png", il, TDEIcon::SizeSmallMedium)); + + + connect(list()->contextMenu(), TQT_SIGNAL(aboutToShow()), TQT_SLOT(slotAboutToShow())); + connect(list(), TQT_SIGNAL(activated(LayerItem*)), + TQT_SLOT(slotLayerActivated(LayerItem*))); + connect(list(), TQT_SIGNAL(displayNameChanged(LayerItem*, const TQString&)), + TQT_SLOT(slotLayerDisplayNameChanged(LayerItem*, const TQString&))); + connect(list(), TQT_SIGNAL(propertyChanged(LayerItem*, const TQString&, bool)), + TQT_SLOT(slotLayerPropertyChanged(LayerItem*, const TQString&, bool))); + connect(list(), TQT_SIGNAL(layerMoved(LayerItem*, LayerItem*, LayerItem*)), + TQT_SLOT(slotLayerMoved(LayerItem*, LayerItem*, LayerItem*))); + connect(list(), TQT_SIGNAL(requestNewLayer(LayerItem*, LayerItem*)), + TQT_SLOT(slotRequestNewLayer(LayerItem*, LayerItem*))); + connect(list(), TQT_SIGNAL(requestNewFolder(LayerItem*, LayerItem*)), + TQT_SLOT(slotRequestNewFolder(LayerItem*, LayerItem*))); + connect(list(), TQT_SIGNAL(requestNewAdjustmentLayer(LayerItem*, LayerItem*)), + TQT_SLOT(slotRequestNewAdjustmentLayer(LayerItem*, LayerItem*))); + connect(list(), TQT_SIGNAL(requestNewObjectLayer(LayerItem*, LayerItem*, const KoDocumentEntry&)), + TQT_SLOT(slotRequestNewObjectLayer(LayerItem*, LayerItem*, const KoDocumentEntry&))); + connect(list(), TQT_SIGNAL(requestRemoveLayer(LayerItem*)), + TQT_SLOT(slotRequestRemoveLayer(LayerItem*))); + connect(list(), TQT_SIGNAL(requestLayerProperties(LayerItem*)), + TQT_SLOT(slotRequestLayerProperties(LayerItem*))); + + m_newLayerMenu = new TDEPopupMenu(this); + m_lst->bnAdd->setPopup(m_newLayerMenu); + m_lst->bnAdd->setPopupDelay(1); + m_newLayerMenu->insertItem( SmallIconSet( "document-new" ), i18n( "&New Layer..." ), PAINT_LAYER ); + m_newLayerMenu->insertItem( SmallIconSet( "folder" ), i18n( "New &Group Layer..." ), GROUP_LAYER ); + m_newLayerMenu->insertItem( SmallIconSet( "tool_filter" ), i18n( "New &Adjustment Layer..." ), ADJUSTMENT_LAYER ); + m_partLayerAction = new KoPartSelectAction( i18n( "New &Object Layer" ), "gear", TQT_TQOBJECT(this) ); + m_partLayerAction->plug( m_newLayerMenu ); + connect(m_partLayerAction, TQT_SIGNAL(activated()), this, TQT_SLOT(slotAddMenuActivated())); + connect(m_newLayerMenu, TQT_SIGNAL(activated(int)), this, TQT_SLOT(slotAddMenuActivated(int))); + + + connect(m_lst->bnDelete, TQT_SIGNAL(clicked()), TQT_SLOT(slotRmClicked())); + connect(m_lst->bnRaise, TQT_SIGNAL(clicked()), TQT_SLOT(slotRaiseClicked())); + connect(m_lst->bnLower, TQT_SIGNAL(clicked()), TQT_SLOT(slotLowerClicked())); + connect(m_lst->bnProperties, TQT_SIGNAL(clicked()), TQT_SLOT(slotPropertiesClicked())); + connect(m_lst->intOpacity, TQT_SIGNAL(valueChanged(int, bool)), TQT_SIGNAL(sigOpacityChanged(int, bool))); + connect(m_lst->intOpacity, TQT_SIGNAL(finishedChanging(int, int)), TQT_SIGNAL(sigOpacityFinishedChanging(int, int))); + connect(m_lst->cmbComposite, TQT_SIGNAL(activated(const KisCompositeOp&)), TQT_SIGNAL(sigItemComposite(const KisCompositeOp&))); + + Q_ASSERT(subject->document() != 0); + + if (subject->document()) { + connect(subject->document(), TQT_SIGNAL(sigCommandExecuted()), TQT_SLOT(updateThumbnails())); + } +} + +KisLayerBox::~KisLayerBox() +{ +} + +KisLayerList* KisLayerBox::list() const +{ + return m_lst->listLayers; +} + +void KisLayerBox::setImage(KisImageSP img) +{ + if (m_image == img) + return; + + if (m_image) + m_image->disconnect(this); + + m_image = img; + + if (img) + { + connect(img, TQT_SIGNAL(sigLayerActivated(KisLayerSP)), this, TQT_SLOT(slotLayerActivated(KisLayerSP))); + connect(img, TQT_SIGNAL(sigLayerAdded(KisLayerSP)), this, TQT_SLOT(slotLayerAdded(KisLayerSP))); + connect(img, TQT_SIGNAL(sigLayerRemoved(KisLayerSP, KisGroupLayerSP, KisLayerSP)), + this, TQT_SLOT(slotLayerRemoved(KisLayerSP, KisGroupLayerSP, KisLayerSP))); + connect(img, TQT_SIGNAL(sigLayerPropertiesChanged(KisLayerSP)), + this, TQT_SLOT(slotLayerPropertiesChanged(KisLayerSP))); + connect(img, TQT_SIGNAL(sigLayerMoved(KisLayerSP, KisGroupLayerSP, KisLayerSP)), + this, TQT_SLOT(slotLayerMoved(KisLayerSP, KisGroupLayerSP, KisLayerSP))); + connect(img, TQT_SIGNAL(sigLayersChanged(KisGroupLayerSP)), this, TQT_SLOT(slotLayersChanged(KisGroupLayerSP))); + connect(img, TQT_SIGNAL(sigLayerUpdated(KisLayerSP, TQRect)), this, TQT_SLOT(slotLayerUpdated(KisLayerSP, TQRect))); + slotLayersChanged(img->rootLayer()); + updateThumbnails(); + } + else + { + clear(); + } +} + +void KisLayerBox::slotLayerActivated(KisLayerSP layer) +{ + if (layer) + list()->setActiveLayer(layer->id()); + else + list()->setActiveLayer(-1); + updateUI(); +} + +void KisLayerBox::slotLayerAdded(KisLayerSP layer) +{ + if (layer.data() == m_image->rootLayer().data() || list()->layer(layer->id())) + return; + + vKisLayerSP layersAdded; + + if (layer->parent() == m_image->rootLayer()) + { + KisPopulateVisitor visitor(list()); + layer->accept(visitor); + layersAdded = visitor.layersAdded(); + } + else + { + KisPopulateVisitor visitor(static_cast(list()->layer(layer->parent()->id()))); + layer->accept(visitor); + layersAdded = visitor.layersAdded(); + } + + for (vKisLayerSP::iterator it = layersAdded.begin(); it != layersAdded.end(); ++it) { + markModified(*it); + } + updateUI(); +} + +void KisLayerBox::slotLayerRemoved(KisLayerSP layer, KisGroupLayerSP wasParent, KisLayerSP) +{ + list()->removeLayer(layer->id()); + m_modified.remove(layer->id()); + markModified(wasParent); + updateUI(); +} + +void KisLayerBox::slotLayerMoved(KisLayerSP layer, KisGroupLayerSP wasParent, KisLayerSP) +{ + int parentID = layer->parent()->id(); + if (layer->parent() == m_image->rootLayer()) + parentID = -1; + + int siblingID = -1; + if (layer->prevSibling()) + siblingID = layer->prevSibling()->id(); + + list()->moveLayer(layer->id(), parentID, siblingID); + + markModified(layer->parent()); + markModified(wasParent); + updateUI(); +} + +void KisLayerBox::slotLayerPropertiesChanged(KisLayerSP layer) +{ + if (KisLayerItem* item = dynamic_cast(list()->layer(layer->id()))) + { + Q_ASSERT(item->layer() == layer.data()); + item->sync(); + updateUI(); + markModified(layer); + } +} + +void KisLayerBox::slotLayersChanged(KisGroupLayerSP rootLayer) +{ + list()->clear(); + KisPopulateVisitor visitor(list()); + for (KisLayerSP layer = rootLayer->firstChild(); layer; layer = layer->nextSibling()) + layer->accept(visitor); + m_modified.clear(); + for (TQListViewItemIterator it(list()->lastItem()); *it; --it) + m_modified.append(static_cast(*it)->id()); + updateUI(); +} + +void KisLayerBox::slotLayerUpdated(KisLayerSP layer, TQRect) +{ + markModified(layer); +} + +void KisLayerBox::slotLayerActivated(LayerItem* item) +{ + if (item) + m_image->activate(m_image->findLayer(item->id())); + else + m_image->activate(0); + updateUI(); +} + +void KisLayerBox::slotLayerDisplayNameChanged(LayerItem* item, const TQString& displayName) +{ + if(KisLayerSP layer = m_image->findLayer(item->id())) + layer->setName(displayName); + updateUI(); +} + +void KisLayerBox::slotLayerPropertyChanged(LayerItem* item, const TQString& name, bool on) +{ + if (KisLayerSP layer = m_image->findLayer(item->id())) + { + if (name == "visible") + layer->setVisible(on); + else if (name == "locked") + layer->setLocked(on); + } +} + +void KisLayerBox::slotLayerMoved(LayerItem* item, LayerItem*, LayerItem*) +{ + KisLayerSP layer = m_image->findLayer(item->id()); + KisGroupLayerSP parent; + if( item->parent() ) + parent = dynamic_cast(m_image->findLayer(item->parent()->id()).data()); + if( !parent ) + parent = m_image->rootLayer(); + KisLayerSP above = 0; + if (item->nextSibling()) + above = m_image->findLayer(item->nextSibling()->id()); + if (layer) + m_image->moveLayer(layer, parent.data(), above); + updateUI(); +} + +void KisLayerBox::slotRequestNewLayer(LayerItem* p, LayerItem* after) +{ + KisLayer* l = m_image->rootLayer().data(); + if (p) + l = m_image->findLayer(p->id()).data(); + KisGroupLayerSP parent = dynamic_cast(l); + + KisLayerSP above = 0; + if (after && after->nextSibling()) + above = m_image->findLayer(after->nextSibling()->id()); + else if (after) + above = 0; + else if (p && p->firstChild()) + above = parent->firstChild(); + else if (!p && m_image->rootLayer()->childCount()) + above = m_image->rootLayer()->firstChild(); + emit sigRequestLayer(parent, above); +} + +void KisLayerBox::slotRequestNewFolder(LayerItem* p, LayerItem* after) +{ + KisLayer* l = m_image->rootLayer().data(); //FIXME I hate copy-pasting like this. + if (p) + l = m_image->findLayer(p->id()).data(); + KisGroupLayerSP parent = dynamic_cast(l); + + KisLayerSP above = 0; + if (after && after->nextSibling()) + above = m_image->findLayer(after->nextSibling()->id()); + else if (after) + above = 0; + else if (p && p->firstChild()) + above = parent->firstChild(); + else if (!p && m_image->rootLayer()->childCount()) + above = m_image->rootLayer()->firstChild(); + emit sigRequestGroupLayer(parent, above); +} + +void KisLayerBox::slotRequestNewAdjustmentLayer(LayerItem* p, LayerItem* after) +{ + KisLayer* l = m_image->rootLayer().data(); //FIXME here too. + if (p) + l = m_image->findLayer(p->id()).data(); + KisGroupLayerSP parent = dynamic_cast(l); + + KisLayerSP above = 0; + if (after && after->nextSibling()) + above = m_image->findLayer(after->nextSibling()->id()); + else if (after) + above = 0; + else if (p && p->firstChild()) + above = parent->firstChild(); + else if (!p && m_image->rootLayer()->childCount()) + above = m_image->rootLayer()->firstChild(); + emit sigRequestAdjustmentLayer(parent, above); +} + +void KisLayerBox::slotRequestNewObjectLayer(LayerItem* p, LayerItem* after, const KoDocumentEntry& entry) +{ + KisLayer* l = m_image->rootLayer().data(); //FIXME and here. + if (p) + l = m_image->findLayer(p->id()).data(); + KisGroupLayerSP parent = dynamic_cast(l); + + KisLayerSP above = 0; + if (after && after->nextSibling()) + above = m_image->findLayer(after->nextSibling()->id()); + else if (after) + above = 0; + else if (p && p->firstChild()) + above = parent->firstChild(); + else if (!p && m_image->rootLayer()->childCount()) + above = m_image->rootLayer()->firstChild(); + emit sigRequestPartLayer(parent, above, entry); +} + +void KisLayerBox::slotRequestRemoveLayer(LayerItem* item) +{ + if (KisLayerSP layer = m_image->findLayer(item->id())) { + m_image->removeLayer(layer); + } + updateUI(); +} + +void KisLayerBox::slotRequestLayerProperties(LayerItem* item) +{ + if (KisLayerSP layer = m_image->findLayer(item->id())) + { + emit sigRequestLayerProperties(layer); + } +} + +void KisLayerBox::updateUI() +{ + m_lst->bnDelete->setEnabled(list()->activeLayer()); + m_lst->bnRaise->setEnabled(list()->activeLayer() && (list()->activeLayer()->prevSibling() || list()->activeLayer()->parent())); + m_lst->bnLower->setEnabled(list()->activeLayer() && list()->activeLayer()->nextSibling()); + m_lst->intOpacity->setEnabled(list()->activeLayer()); + m_lst->cmbComposite->setEnabled(list()->activeLayer()); + if (m_image) + if (KisLayerSP active = m_image->activeLayer()) + { + if (m_image->activeDevice()) + slotSetColorSpace(m_image->activeDevice()->colorSpace()); + else + slotSetColorSpace(m_image->colorSpace()); + slotSetOpacity(int(float(active->opacity() * 100) / 255 + 0.5)); + slotSetCompositeOp(active->compositeOp()); + } +} + +void KisLayerBox::slotAboutToShow() +{ +} + +void KisLayerBox::slotSetCompositeOp(const KisCompositeOp& compositeOp) +{ + m_lst->cmbComposite->blockSignals(true); + m_lst->cmbComposite->setCurrentItem(compositeOp); + m_lst->cmbComposite->blockSignals(false); +} + +void KisLayerBox::slotSetColorSpace(const KisColorSpace * colorSpace) +{ + m_lst->cmbComposite->blockSignals(true); + m_lst->cmbComposite->setCompositeOpList(colorSpace->userVisiblecompositeOps()); + m_lst->cmbComposite->blockSignals(false); +} + +// range: 0-100 +void KisLayerBox::slotSetOpacity(int opacity) +{ + m_lst->intOpacity->blockSignals(true); + m_lst->intOpacity->setValue(opacity); + m_lst->intOpacity->blockSignals(false); +} + +void KisLayerBox::clear() +{ + list()->clear(); + updateUI(); +} + +void KisLayerBox::slotAddMenuActivated(int type) +{ + if(type == -1) + return; + + KisGroupLayerSP root = m_image->rootLayer(); + KisGroupLayerSP parent; + KisLayerSP above; + if (KisLayerSP active = m_image->activeLayer()) + { + parent = root; + above = active; + if (active->parent()) + parent = active->parent(); + } + else + { + parent = root; + above = m_image->rootLayer()->firstChild(); + } + + switch (type) + { + case PAINT_LAYER: + emit sigRequestLayer(parent, above); + break; + case GROUP_LAYER: + emit sigRequestGroupLayer(parent, above); + break; + case ADJUSTMENT_LAYER: + emit sigRequestAdjustmentLayer(parent, above); + break; + case OBJECT_LAYER: + default: //TQt doesn't emit activated for default-assigned IDs, so this does nothing + emit sigRequestPartLayer(parent, above, m_partLayerAction->documentEntry()); + } +} + +void KisLayerBox::slotRmClicked() +{ + TQValueList l = list()->selectedLayerIDs(); + if (l.count() < 2 && list()->activeLayer() && !l.contains(list()->activeLayer()->id())) + { + l.clear(); + l.append(list()->activeLayer()->id()); + } + + for (int i = 0, n = l.count(); i < n; ++i) + { + m_modified.remove(l[i]); + m_image->removeLayer(m_image->findLayer(l[i])); + } +} + +void KisLayerBox::slotRaiseClicked() +{ + TQValueList l = list()->selectedLayerIDs(); + if (l.count() < 2 && list()->activeLayer() && !l.contains(list()->activeLayer()->id())) + { + l.clear(); + l.append(list()->activeLayer()->id()); + } + + KisLayerSP layer = m_image->findLayer(l.first()); + if( l.count() == 1 && layer == layer->parent()->firstChild() && layer->parent() != m_image->rootLayer()) + { + if (KisGroupLayerSP grandparent = layer->parent()->parent()) + m_image->moveLayer(layer, grandparent, layer->parent().data()); + } + else + { + for (int i = 0, n = l.count(); i < n; ++i) + if (KisLayerSP li = m_image->findLayer(l[i])) + if (li->prevSibling()) + m_image->moveLayer(li, li->parent(), li->prevSibling()); + } + + if( !l.isEmpty() ) + list()->ensureItemVisible( list()->layer( l.first() ) ); +} + +void KisLayerBox::slotLowerClicked() +{ + TQValueList l = list()->selectedLayers(); + if (l.count() < 2 && list()->activeLayer() && !l.contains(list()->activeLayer())) + { + l.clear(); + l.append(list()->activeLayer()); + } + + for (int i = l.count() - 1; i >= 0; --i) + if (LayerItem *layer = l[i]) + if (layer->nextSibling()) + list()->moveLayer(layer, layer->parent(), layer->nextSibling()); + + if( !l.isEmpty() ) + list()->ensureItemVisible( l.last() ); +} + +void KisLayerBox::slotPropertiesClicked() +{ + if (KisLayerSP active = m_image->activeLayer()) + emit sigRequestLayerProperties(active); +} + +void KisLayerBox::updateThumbnails() +{ + bool again = true; + while (m_modified.count() && again) + { + //again = false; + KisLayerItem* item = static_cast(list()->layer(m_modified.last())); + m_modified.pop_back(); + if (!item || !item->updatePreview()) + again = true; + } +} + +void KisLayerBox::setUpdatesAndSignalsEnabled(bool enable) +{ + setUpdatesEnabled(enable); + m_lst->intOpacity->setUpdatesEnabled(enable); + m_lst->cmbComposite->setUpdatesEnabled(enable); + + list()->blockSignals(!enable); + m_lst->intOpacity->blockSignals(!enable); + m_lst->cmbComposite->blockSignals(!enable); +} + + +TQPixmap KisLayerBox::loadPixmap(const TQString& filename, const TDEIconLoader& + il, int size) +{ + TQPixmap pixmap = il.loadIcon(filename, TDEIcon::NoGroup, size); + + if (pixmap.isNull()) + KMessageBox::error(0, i18n("Cannot find %1").arg(filename), + i18n("Canvas")); + + return pixmap; +} + +void KisLayerBox::markModified(KisLayer* layer) +{ + if( !layer ) + return; + + TQValueList v; + while (layer && layer != m_image->rootLayer().data()) + { + v.append(layer->id()); + layer = layer->parent(); + } + for (int i = v.count() - 1; i >= 0; --i) + if (!m_modified.contains(v[i])) + m_modified.append(v[i]); +} + +void KisLayerBox::printChalkLayers() const +{ + static int indent = 0; + static KisLayer *root = 0; + if( !root ) + root = m_image->rootLayer(); + if( !root ) + return; + TQString s = root->name(); + if( dynamic_cast( root ) ) + s = TQString("[%1]").arg( s ); + if( m_image->activeLayer().data() == root ) + s.prepend("*"); + kdDebug() << (TQString().fill(' ', indent) + s) << endl; + for (KisLayer* layer = root->firstChild(); layer; layer = layer->nextSibling()) + { + indent += 2; + root = layer; + printChalkLayers(); + indent -= 2; + root = layer->parent(); + } +} + +void KisLayerBox::printLayerboxLayers() const +{ + static int indent = 0; + static LayerItem *root = 0; + if( !root ) + { + for (LayerItem* layer = list()->firstChild(); layer; layer = layer->nextSibling()) + { + indent += 2; + root = layer; + printLayerboxLayers(); + indent -= 2; + root = layer->parent(); + } + return; + } + TQString s = root->displayName(); + if( root->isFolder() ) + s = TQString("[%1]").arg( s ); + if( list()->activeLayer() == root ) + s.prepend("*"); + kdDebug() << (TQString().fill(' ', indent) + s) << endl; + for (LayerItem* layer = root->firstChild(); layer; layer = layer->nextSibling()) + { + indent += 2; + root = layer; + printLayerboxLayers(); + indent -= 2; + root = layer->parent(); + } +} + +#include "kis_layerbox.moc" diff --git a/chalk/ui/kis_layerlist.cc b/chalk/ui/kis_layerlist.cpp similarity index 100% rename from chalk/ui/kis_layerlist.cc rename to chalk/ui/kis_layerlist.cpp diff --git a/chalk/ui/kis_multi_bool_filter_widget.cc b/chalk/ui/kis_multi_bool_filter_widget.cpp similarity index 100% rename from chalk/ui/kis_multi_bool_filter_widget.cc rename to chalk/ui/kis_multi_bool_filter_widget.cpp diff --git a/chalk/ui/kis_multi_double_filter_widget.cc b/chalk/ui/kis_multi_double_filter_widget.cpp similarity index 100% rename from chalk/ui/kis_multi_double_filter_widget.cc rename to chalk/ui/kis_multi_double_filter_widget.cpp diff --git a/chalk/ui/kis_multi_integer_filter_widget.cc b/chalk/ui/kis_multi_integer_filter_widget.cpp similarity index 100% rename from chalk/ui/kis_multi_integer_filter_widget.cc rename to chalk/ui/kis_multi_integer_filter_widget.cpp diff --git a/chalk/ui/kis_opengl_canvas.cc b/chalk/ui/kis_opengl_canvas.cpp similarity index 100% rename from chalk/ui/kis_opengl_canvas.cc rename to chalk/ui/kis_opengl_canvas.cpp diff --git a/chalk/ui/kis_opengl_canvas_painter.cc b/chalk/ui/kis_opengl_canvas_painter.cpp similarity index 100% rename from chalk/ui/kis_opengl_canvas_painter.cc rename to chalk/ui/kis_opengl_canvas_painter.cpp diff --git a/chalk/ui/kis_opengl_image_context.cc b/chalk/ui/kis_opengl_image_context.cpp similarity index 100% rename from chalk/ui/kis_opengl_image_context.cc rename to chalk/ui/kis_opengl_image_context.cpp diff --git a/chalk/ui/kis_paintop_box.cc b/chalk/ui/kis_paintop_box.cc deleted file mode 100644 index 6036ef74c..000000000 --- a/chalk/ui/kis_paintop_box.cc +++ /dev/null @@ -1,249 +0,0 @@ -/* - * kis_paintop_box.cc - part of KImageShop/Krayon/Chalk - * - * Copyright (c) 2004 Boudewijn Rempt (boud@valdyas.org) - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "kis_paintop_box.h" - -KisPaintopBox::KisPaintopBox (KisView * view, TQWidget *parent, const char * name) - : super (parent, name), - m_canvasController(view->getCanvasController()) -{ -#if TDE_VERSION >= TDE_MAKE_VERSION(3,3,90) - TDEAcceleratorManager::setNoAccel(this); -#endif - - Q_ASSERT(m_canvasController != 0); - - setCaption(i18n("Painter's Toolchest")); - m_optionWidget = 0; - m_paintops = new TQValueList(); - m_displayedOps = new TQValueList(); - - m_cmbPaintops = new TQComboBox(this, "KisPaintopBox::m_cmbPaintops"); - m_cmbPaintops->setMinimumWidth(150); - TQToolTip::add(m_cmbPaintops, i18n("Styles of painting for the painting tools")); - m_layout = new TQHBoxLayout(this, 1, 1); - m_layout->addWidget(m_cmbPaintops); - - connect(this, TQT_SIGNAL(selected(const KisID &, const KisPaintOpSettings *)), view, TQT_SLOT(paintopActivated(const KisID &, const KisPaintOpSettings *))); - connect(m_cmbPaintops, TQT_SIGNAL(activated(int)), this, TQT_SLOT(slotItemSelected(int))); - - // XXX: Let's see... Are all paintops loaded and ready? - KisIDList keys = KisPaintOpRegistry::instance()->listKeys(); - for ( KisIDList::Iterator it = keys.begin(); it != keys.end(); ++it ) { - // add all paintops, and show/hide them afterwards - addItem(*it); - } - - connect(view, TQT_SIGNAL(currentColorSpaceChanged(KisColorSpace*)), - this, TQT_SLOT(colorSpaceChanged(KisColorSpace*))); - connect(view, TQT_SIGNAL(sigInputDeviceChanged(const KisInputDevice&)), - this, TQT_SLOT(slotInputDeviceChanged(const KisInputDevice&))); - - setCurrentPaintop(defaultPaintop(m_canvasController->currentInputDevice())); -} - -KisPaintopBox::~KisPaintopBox() -{ - delete m_paintops; - delete m_displayedOps; -} - -void KisPaintopBox::addItem(const KisID & paintop, const TQString & /*category*/) -{ - m_paintops->append(paintop); -} - -void KisPaintopBox::slotItemSelected(int index) -{ - if ((uint)index > m_displayedOps->count()) { - return; - } - - KisID paintop = *m_displayedOps->at(index); - - setCurrentPaintop(paintop); -} - -void KisPaintopBox::colorSpaceChanged(KisColorSpace *cs) -{ - TQValueList::iterator it = m_paintops->begin(); - TQValueList::iterator end = m_paintops->end(); - m_displayedOps->clear(); - m_cmbPaintops->clear(); - - for ( ; it != end; ++it ) { - if (KisPaintOpRegistry::instance()->userVisible(*it, cs)) { - TQPixmap pm = paintopPixmap(*it); - if (pm.isNull()) { - TQPixmap p = TQPixmap( 16, 16 ); - p.fill(); - m_cmbPaintops->insertItem(p, (*it).name()); - } - else { - m_cmbPaintops->insertItem(pm, (*it).name()); - } - m_displayedOps->append(*it); - } - } - - int index = m_displayedOps->findIndex(currentPaintop()); - - if (index == -1) { - // Must change the paintop as the current one is not supported - // by the new colourspace. - index = 0; - } - - m_cmbPaintops->setCurrentItem( index ); - slotItemSelected( index ); -} - -TQPixmap KisPaintopBox::paintopPixmap(const KisID & paintop) -{ - TQString pixmapName = KisPaintOpRegistry::instance()->pixmap(paintop); - - if (pixmapName.isEmpty()) { - return TQPixmap(); - } - - TQString fname = KisFactory::instance()->dirs()->findResource("kis_images", pixmapName); - - return TQPixmap(fname); -} - -void KisPaintopBox::slotInputDeviceChanged(const KisInputDevice & inputDevice) -{ - KisID paintop; - InputDevicePaintopMap::iterator it = m_currentID.find(inputDevice); - - if (it == m_currentID.end()) { - paintop = defaultPaintop(inputDevice); - } else { - paintop = (*it).second; - } - - int index = m_displayedOps->findIndex(paintop); - - if (index == -1) { - // Must change the paintop as the current one is not supported - // by the new colourspace. - index = 0; - paintop = *m_displayedOps->at(index); - } - - m_cmbPaintops->setCurrentItem(index); - setCurrentPaintop(paintop); -} - -void KisPaintopBox::updateOptionWidget() -{ - if (m_optionWidget != 0) { - m_layout->remove(m_optionWidget); - m_optionWidget->hide(); - m_layout->invalidate(); - } - - const KisPaintOpSettings *settings = paintopSettings(currentPaintop(), m_canvasController->currentInputDevice()); - - if (settings != 0) { - m_optionWidget = settings->widget(); - Q_ASSERT(m_optionWidget != 0); - - m_layout->addWidget(m_optionWidget); - updateGeometry(); - m_optionWidget->show(); - } -} - -const KisID& KisPaintopBox::currentPaintop() -{ - return m_currentID[m_canvasController->currentInputDevice()]; -} - -void KisPaintopBox::setCurrentPaintop(const KisID & paintop) -{ - m_currentID[m_canvasController->currentInputDevice()] = paintop; - - updateOptionWidget(); - - emit selected(paintop, paintopSettings(paintop, m_canvasController->currentInputDevice())); -} - -KisID KisPaintopBox::defaultPaintop(const KisInputDevice& inputDevice) -{ - if (inputDevice == KisInputDevice::eraser()) { - return KisID("eraser",""); - } else { - return KisID("paintbrush",""); - } -} - -const KisPaintOpSettings *KisPaintopBox::paintopSettings(const KisID & paintop, const KisInputDevice & inputDevice) -{ - TQValueVector settingsArray; - InputDevicePaintopSettingsMap::iterator it = m_inputDevicePaintopSettings.find(inputDevice); - - if (it == m_inputDevicePaintopSettings.end()) { - // Create settings for each paintop. - - for (TQValueList::const_iterator pit = m_paintops->begin(); pit != m_paintops->end(); ++pit) { - KisPaintOpSettings *settings = KisPaintOpRegistry::instance()->settings(*pit, this, inputDevice); - settingsArray.append(settings); - if (settings && settings->widget()) { - settings->widget()->hide(); - } - } - m_inputDevicePaintopSettings[inputDevice] = settingsArray; - } else { - settingsArray = (*it).second; - } - - const int index = m_paintops->findIndex(paintop); - if (index >= 0 && index < (int)settingsArray.count()) - return settingsArray[index]; - else - return 0; -} - -#include "kis_paintop_box.moc" - diff --git a/chalk/ui/kis_paintop_box.cpp b/chalk/ui/kis_paintop_box.cpp new file mode 100644 index 000000000..57ed7a736 --- /dev/null +++ b/chalk/ui/kis_paintop_box.cpp @@ -0,0 +1,249 @@ +/* + * kis_paintop_box.cpp - part of KImageShop/Krayon/Chalk + * + * Copyright (c) 2004 Boudewijn Rempt (boud@valdyas.org) + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "kis_paintop_box.h" + +KisPaintopBox::KisPaintopBox (KisView * view, TQWidget *parent, const char * name) + : super (parent, name), + m_canvasController(view->getCanvasController()) +{ +#if TDE_VERSION >= TDE_MAKE_VERSION(3,3,90) + TDEAcceleratorManager::setNoAccel(this); +#endif + + Q_ASSERT(m_canvasController != 0); + + setCaption(i18n("Painter's Toolchest")); + m_optionWidget = 0; + m_paintops = new TQValueList(); + m_displayedOps = new TQValueList(); + + m_cmbPaintops = new TQComboBox(this, "KisPaintopBox::m_cmbPaintops"); + m_cmbPaintops->setMinimumWidth(150); + TQToolTip::add(m_cmbPaintops, i18n("Styles of painting for the painting tools")); + m_layout = new TQHBoxLayout(this, 1, 1); + m_layout->addWidget(m_cmbPaintops); + + connect(this, TQT_SIGNAL(selected(const KisID &, const KisPaintOpSettings *)), view, TQT_SLOT(paintopActivated(const KisID &, const KisPaintOpSettings *))); + connect(m_cmbPaintops, TQT_SIGNAL(activated(int)), this, TQT_SLOT(slotItemSelected(int))); + + // XXX: Let's see... Are all paintops loaded and ready? + KisIDList keys = KisPaintOpRegistry::instance()->listKeys(); + for ( KisIDList::Iterator it = keys.begin(); it != keys.end(); ++it ) { + // add all paintops, and show/hide them afterwards + addItem(*it); + } + + connect(view, TQT_SIGNAL(currentColorSpaceChanged(KisColorSpace*)), + this, TQT_SLOT(colorSpaceChanged(KisColorSpace*))); + connect(view, TQT_SIGNAL(sigInputDeviceChanged(const KisInputDevice&)), + this, TQT_SLOT(slotInputDeviceChanged(const KisInputDevice&))); + + setCurrentPaintop(defaultPaintop(m_canvasController->currentInputDevice())); +} + +KisPaintopBox::~KisPaintopBox() +{ + delete m_paintops; + delete m_displayedOps; +} + +void KisPaintopBox::addItem(const KisID & paintop, const TQString & /*category*/) +{ + m_paintops->append(paintop); +} + +void KisPaintopBox::slotItemSelected(int index) +{ + if ((uint)index > m_displayedOps->count()) { + return; + } + + KisID paintop = *m_displayedOps->at(index); + + setCurrentPaintop(paintop); +} + +void KisPaintopBox::colorSpaceChanged(KisColorSpace *cs) +{ + TQValueList::iterator it = m_paintops->begin(); + TQValueList::iterator end = m_paintops->end(); + m_displayedOps->clear(); + m_cmbPaintops->clear(); + + for ( ; it != end; ++it ) { + if (KisPaintOpRegistry::instance()->userVisible(*it, cs)) { + TQPixmap pm = paintopPixmap(*it); + if (pm.isNull()) { + TQPixmap p = TQPixmap( 16, 16 ); + p.fill(); + m_cmbPaintops->insertItem(p, (*it).name()); + } + else { + m_cmbPaintops->insertItem(pm, (*it).name()); + } + m_displayedOps->append(*it); + } + } + + int index = m_displayedOps->findIndex(currentPaintop()); + + if (index == -1) { + // Must change the paintop as the current one is not supported + // by the new colourspace. + index = 0; + } + + m_cmbPaintops->setCurrentItem( index ); + slotItemSelected( index ); +} + +TQPixmap KisPaintopBox::paintopPixmap(const KisID & paintop) +{ + TQString pixmapName = KisPaintOpRegistry::instance()->pixmap(paintop); + + if (pixmapName.isEmpty()) { + return TQPixmap(); + } + + TQString fname = KisFactory::instance()->dirs()->findResource("kis_images", pixmapName); + + return TQPixmap(fname); +} + +void KisPaintopBox::slotInputDeviceChanged(const KisInputDevice & inputDevice) +{ + KisID paintop; + InputDevicePaintopMap::iterator it = m_currentID.find(inputDevice); + + if (it == m_currentID.end()) { + paintop = defaultPaintop(inputDevice); + } else { + paintop = (*it).second; + } + + int index = m_displayedOps->findIndex(paintop); + + if (index == -1) { + // Must change the paintop as the current one is not supported + // by the new colourspace. + index = 0; + paintop = *m_displayedOps->at(index); + } + + m_cmbPaintops->setCurrentItem(index); + setCurrentPaintop(paintop); +} + +void KisPaintopBox::updateOptionWidget() +{ + if (m_optionWidget != 0) { + m_layout->remove(m_optionWidget); + m_optionWidget->hide(); + m_layout->invalidate(); + } + + const KisPaintOpSettings *settings = paintopSettings(currentPaintop(), m_canvasController->currentInputDevice()); + + if (settings != 0) { + m_optionWidget = settings->widget(); + Q_ASSERT(m_optionWidget != 0); + + m_layout->addWidget(m_optionWidget); + updateGeometry(); + m_optionWidget->show(); + } +} + +const KisID& KisPaintopBox::currentPaintop() +{ + return m_currentID[m_canvasController->currentInputDevice()]; +} + +void KisPaintopBox::setCurrentPaintop(const KisID & paintop) +{ + m_currentID[m_canvasController->currentInputDevice()] = paintop; + + updateOptionWidget(); + + emit selected(paintop, paintopSettings(paintop, m_canvasController->currentInputDevice())); +} + +KisID KisPaintopBox::defaultPaintop(const KisInputDevice& inputDevice) +{ + if (inputDevice == KisInputDevice::eraser()) { + return KisID("eraser",""); + } else { + return KisID("paintbrush",""); + } +} + +const KisPaintOpSettings *KisPaintopBox::paintopSettings(const KisID & paintop, const KisInputDevice & inputDevice) +{ + TQValueVector settingsArray; + InputDevicePaintopSettingsMap::iterator it = m_inputDevicePaintopSettings.find(inputDevice); + + if (it == m_inputDevicePaintopSettings.end()) { + // Create settings for each paintop. + + for (TQValueList::const_iterator pit = m_paintops->begin(); pit != m_paintops->end(); ++pit) { + KisPaintOpSettings *settings = KisPaintOpRegistry::instance()->settings(*pit, this, inputDevice); + settingsArray.append(settings); + if (settings && settings->widget()) { + settings->widget()->hide(); + } + } + m_inputDevicePaintopSettings[inputDevice] = settingsArray; + } else { + settingsArray = (*it).second; + } + + const int index = m_paintops->findIndex(paintop); + if (index >= 0 && index < (int)settingsArray.count()) + return settingsArray[index]; + else + return 0; +} + +#include "kis_paintop_box.moc" + diff --git a/chalk/ui/kis_palette_view.cc b/chalk/ui/kis_palette_view.cpp similarity index 100% rename from chalk/ui/kis_palette_view.cc rename to chalk/ui/kis_palette_view.cpp diff --git a/chalk/ui/kis_palette_widget.cc b/chalk/ui/kis_palette_widget.cpp similarity index 100% rename from chalk/ui/kis_palette_widget.cc rename to chalk/ui/kis_palette_widget.cpp diff --git a/chalk/ui/kis_part_layer.cc b/chalk/ui/kis_part_layer.cpp similarity index 100% rename from chalk/ui/kis_part_layer.cc rename to chalk/ui/kis_part_layer.cpp diff --git a/chalk/ui/kis_part_layer_handler.cc b/chalk/ui/kis_part_layer_handler.cpp similarity index 100% rename from chalk/ui/kis_part_layer_handler.cc rename to chalk/ui/kis_part_layer_handler.cpp diff --git a/chalk/ui/kis_pattern_chooser.cc b/chalk/ui/kis_pattern_chooser.cpp similarity index 100% rename from chalk/ui/kis_pattern_chooser.cc rename to chalk/ui/kis_pattern_chooser.cpp diff --git a/chalk/ui/kis_previewdialog.cc b/chalk/ui/kis_previewdialog.cc deleted file mode 100644 index d67d5e58b..000000000 --- a/chalk/ui/kis_previewdialog.cc +++ /dev/null @@ -1,46 +0,0 @@ -/* - * kis_previewdialog.cc - part of Chalk - * - * Copyright (c) 2005 Sven Langkamp - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -#include -#include -#include -#include - -#include "kis_previewwidget.h" -#include "kis_previewdialog.h" - -KisPreviewDialog::KisPreviewDialog( TQWidget * parent, const char * name, bool modal, const TQString &caption) - : super (parent, name, modal, caption, Ok | Cancel, Ok) -{ - TQHBox* layout = new TQHBox(this); - layout->setSpacing( 6 ); - - m_containerFrame = new TQFrame( layout, "container" ); - - m_preview = new KisPreviewWidget( layout, "previewWidget" ); - - setMainWidget(layout); -} - -KisPreviewDialog::~KisPreviewDialog() -{ - -} - -#include "kis_previewdialog.moc" diff --git a/chalk/ui/kis_previewdialog.cpp b/chalk/ui/kis_previewdialog.cpp new file mode 100644 index 000000000..cfbe05b23 --- /dev/null +++ b/chalk/ui/kis_previewdialog.cpp @@ -0,0 +1,46 @@ +/* + * kis_previewdialog.cpp - part of Chalk + * + * Copyright (c) 2005 Sven Langkamp + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +#include +#include +#include +#include + +#include "kis_previewwidget.h" +#include "kis_previewdialog.h" + +KisPreviewDialog::KisPreviewDialog( TQWidget * parent, const char * name, bool modal, const TQString &caption) + : super (parent, name, modal, caption, Ok | Cancel, Ok) +{ + TQHBox* layout = new TQHBox(this); + layout->setSpacing( 6 ); + + m_containerFrame = new TQFrame( layout, "container" ); + + m_preview = new KisPreviewWidget( layout, "previewWidget" ); + + setMainWidget(layout); +} + +KisPreviewDialog::~KisPreviewDialog() +{ + +} + +#include "kis_previewdialog.moc" diff --git a/chalk/ui/kis_previewwidget.cc b/chalk/ui/kis_previewwidget.cc deleted file mode 100644 index 29a91fbdb..000000000 --- a/chalk/ui/kis_previewwidget.cc +++ /dev/null @@ -1,409 +0,0 @@ -/* - * kis_previewwidget.cc - part of Chalk - * - * Copyright (c) 2001 John Califf - * Copyright (c) 2004 Bart Coppens - * Copyright (c) 2005 Cyrille Berger - * Copyright (c) 2007 Ben Schleimer - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "kis_previewwidgetbase.h" -#include "kis_previewwidget.h" -#include "imageviewer.h" - -static const int ZOOM_PAUSE = 100; -static const int FILTER_PAUSE = 500; -static const double ZOOM_FACTOR = 1.1; - -KisPreviewWidget::KisPreviewWidget( TQWidget* parent, const char* name ) - : PreviewWidgetBase( parent, name ) - , m_autoupdate(true) - , m_previewIsDisplayed(true) - , m_scaledOriginal() - , m_dirtyOriginal(true) - , m_origDevice(new KisPaintDevice(KisMetaRegistry::instance()->csRegistry()->getRGB8(), "temp")) - , m_scaledPreview() - , m_dirtyPreview(true) - , m_previewDevice(new KisPaintDevice(KisMetaRegistry::instance()->csRegistry()->getRGB8(), "temp")) - , m_scaledImage(NULL) - , m_filterZoom(1.0) - , m_zoom(-1.0) - , m_profile(NULL) - , m_progress( 0 ) - , m_zoomTimer(new TQTimer(this)) - , m_filterTimer(new TQTimer(this)) - , m_firstFilter(true) - , m_firstZoom(true) -{ - btnZoomIn->setIconSet(TDEGlobal::instance()->iconLoader()->loadIconSet( "zoom-in", TDEIcon::MainToolbar, 16 )); - connect(btnZoomIn, TQT_SIGNAL(clicked()), this, TQT_SLOT(zoomIn())); - btnZoomOut->setIconSet(TDEGlobal::instance()->iconLoader()->loadIconSet( "zoom-out", TDEIcon::MainToolbar, 16 )); - connect(btnZoomOut, TQT_SIGNAL(clicked()), this, TQT_SLOT(zoomOut())); - btnUpdate->setIconSet(TDEGlobal::instance()->iconLoader()->loadIconSet( "reload", TDEIcon::MainToolbar, 16 )); - connect(btnUpdate, TQT_SIGNAL(clicked()), this, TQT_SLOT(forceUpdate())); - - connect(radioBtnPreview, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(setPreviewDisplayed(bool))); - - connect(checkBoxAutoUpdate, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotSetAutoUpdate(bool))); - btnZoomOneToOne->setIconSet(TDEGlobal::instance()->iconLoader()->loadIconSet( "zoom-original", TDEIcon::MainToolbar, 16 )); - connect(btnZoomOneToOne, TQT_SIGNAL(clicked()), this, TQT_SLOT(zoomOneToOne())); - - m_progress = new KisLabelProgress(frmProgress); - m_progress->setMaximumHeight(fontMetrics().height() ); - TQVBoxLayout *vbox = new TQVBoxLayout( frmProgress ); - vbox->addWidget(m_progress); - m_progress->hide(); - - connect(m_zoomTimer, TQT_SIGNAL(timeout()), this, TQT_SLOT(updateZoom())); - connect(m_filterTimer, TQT_SIGNAL(timeout()), this, TQT_SLOT(runFilterHelper())); - -/* kToolBar1->insertLineSeparator(); - kToolBar1->insertButton("reload",2, true, i18n("Update")); - connect(kToolBar1->getButton(2),TQT_SIGNAL(clicked()),this,TQT_SLOT(forceUpdate())); - - kToolBar1->insertButton("",3, true, i18n("Auto Update")); - connect(kToolBar1->getButton(3),TQT_SIGNAL(clicked()),this,TQT_SLOT(toggleAutoUpdate())); - - kToolBar1->insertButton("",4, true, i18n("Switch")); - connect(kToolBar1->getButton(4),TQT_SIGNAL(clicked()),this,TQT_SLOT(toggleImageDisplayed()));*/ -// these currently don't yet work, reenable when they do work :) (TZ-12-2005) -// TODO reenable these -// kToolBar1->insertButton("",5, true, i18n("Popup Original and Preview")); -} - -KisPreviewWidget::~KisPreviewWidget() { } - -void KisPreviewWidget::forceUpdate() -{ - if(m_previewIsDisplayed) - { - m_groupBox->setTitle(m_origDevice->name()); - emit updated(); - } -} - -void KisPreviewWidget::slotSetDevice(KisPaintDeviceSP dev) -{ - Q_ASSERT( dev ); - - if (!dev) return; - - m_origDevice = dev; - m_previewDevice = dev; - m_filterZoom = 1.0; - - KisConfig cfg; - TQString monitorProfileName = cfg.monitorProfile(); - m_profile = KisMetaRegistry::instance()->csRegistry()->getProfileByName(monitorProfileName); - - TQRect r = dev->exactBounds(); - - m_groupBox->setTitle(i18n("Preview: ") + dev->name()); - m_previewIsDisplayed = true; - - m_zoom = -1.0; - zoomChanged(double(m_preview->width()) / double(r.width()) ); -} - -void KisPreviewWidget::updateZoom() -{ - TQApplication::setOverrideCursor(KisCursor::waitCursor()); - - if(m_previewIsDisplayed) - { - if(m_dirtyPreview) - { - TQSize r = m_previewDevice->extent().size(); - int w = r.width(), h = r.height(); - int sw = int(ceil(m_zoom * w / m_filterZoom)); - int sh = int(ceil(m_zoom * h / m_filterZoom)); - m_dirtyPreview = false; - m_scaledPreview = m_previewDevice->convertToTQImage(m_profile, 0, 0, w, h); - m_scaledPreview = m_scaledPreview.scale(sw,sh, TQ_ScaleMax); // Use scale instead of smoothScale for speed up - } - m_preview->setImage(m_scaledPreview); - } else - { - if(m_dirtyOriginal) - { - TQSize r = m_origDevice->extent().size(); - int w = r.width(), h = r.height(); - int sw = int(ceil(m_zoom * w)); - int sh = int(ceil(m_zoom * h)); - m_dirtyOriginal = false; - m_scaledOriginal = m_origDevice->convertToTQImage(m_profile, 0, 0, w, h); - m_scaledOriginal = m_scaledOriginal.scale(sw,sh, TQ_ScaleMax); // Use scale instead of smoothScale for speed up - } - m_preview->setImage(m_scaledOriginal); - } - - TQApplication::restoreOverrideCursor(); -} - -void KisPreviewWidget::slotSetAutoUpdate(bool set) { - m_autoupdate = set; -} - -void KisPreviewWidget::wheelEvent(TQWheelEvent * e) -{ - if (e->delta() > 0) { - zoomIn(); - } else { - zoomOut(); - } - e->accept(); -} - -void KisPreviewWidget::setPreviewDisplayed(bool v) -{ - if(v != m_previewIsDisplayed) - { - m_previewIsDisplayed = v; - if(m_previewIsDisplayed) { - m_groupBox->setTitle(i18n("Preview: ") + m_origDevice->name()); - } else { - m_groupBox->setTitle(i18n("Original: ") + m_origDevice->name()); - } - // Call directly without any pause because there is no scaling - updateZoom(); - } -} - -void KisPreviewWidget::needUpdate() -{ - if(m_previewIsDisplayed) - m_groupBox->setTitle(i18n("Preview (needs update)")); -} - -bool KisPreviewWidget::getAutoUpdate() const { - return m_autoupdate; -} - -void KisPreviewWidget::zoomChanged(const double zoom) -{ - // constrain the zoom - double tZoom = zoom; - if(zoom <= 1./8.) { tZoom = 1./8.; } - if(zoom > 8.) { tZoom = 8.; } - - if(tZoom != m_zoom) - { - m_zoom = tZoom; - m_dirtyOriginal = true; - m_dirtyPreview = true; - - if(m_firstZoom) { - m_firstZoom = false; - updateZoom(); - } else { - m_zoomTimer->start(ZOOM_PAUSE, true); - } - } -} - -void KisPreviewWidget::zoomIn() { - zoomChanged(m_zoom * ZOOM_FACTOR); -} - -void KisPreviewWidget::zoomOut() { - zoomChanged(m_zoom / ZOOM_FACTOR); -} - -void KisPreviewWidget::zoomOneToOne() { - zoomChanged(1.0); -} - -static inline void cropDevice(KisPaintDevice * device, const double & zoom) { - TQRect r = device->exactBounds(); - r.setX(int(zoom * r.x()) ); - r.setY(int(zoom * r.y()) ); - r.setWidth(int(zoom * r.width()) ); - r.setHeight(int(zoom * r.height()) ); - device->crop(r); -} - -class MyCropVisitor : public KisLayerVisitor { - const double m_zoom; - -public: - MyCropVisitor(const double & z) : m_zoom(z) { } - virtual ~MyCropVisitor() { } - - virtual bool visit(KisPaintLayer *layer) { - KisPaintDeviceSP device = layer->paintDevice(); - ::cropDevice(device.data(), m_zoom); - // Make sure we have a tight fit for the selection - if(device->hasSelection()) { - ::cropDevice(device->selection().data(), m_zoom); - } - - return true; - } - virtual bool visit(KisGroupLayer *layer) { - for(KisLayerSP l = layer->firstChild(); l; l = l->nextSibling()) { - l->accept(*this); - } - return true; - } - virtual bool visit(KisPartLayer *) { return true; } - virtual bool visit(KisAdjustmentLayer *) { return true; } -}; - -void KisPreviewWidget::runFilter(KisFilter * filter, KisFilterConfiguration * config) { - if(!filter) return; - if(!config) return; - - m_filter = filter; - m_config = config; - - if(m_firstFilter) { - m_firstFilter = false; - runFilterHelper(); - } else { - m_filterTimer->start(FILTER_PAUSE, true); - } -} - -/** - * XXX: Fix the situations which m_origDevice is NOT associated with a image. - * If it comes from a adjustment layer or projection or thumbnail. Currently, nothing happens - */ -void KisPreviewWidget::runFilterHelper() { - - m_filterZoom = m_zoom; - // Dont scale more then 1.0 so we don't waste time in preview widget for large scaling. - if(m_filterZoom > 1.0) { - m_filterZoom = 1.0; - } - - KisPaintDeviceSP scaledDevice; - KisHermiteFilterStrategy strategy; - - // Copy the image and scale - if (m_origDevice->image()) - { - m_scaledImage = new KisImage(*m_origDevice->image()); - if(!m_origDevice->parentLayer()) return; - TQString layerName = m_origDevice->parentLayer()->name(); - KisPaintLayerSP pl = ::tqqt_cast(m_scaledImage->findLayer(layerName)); - if(!pl) return; - scaledDevice = pl->paintDevice(); - - KisSelectionSP select; - if(scaledDevice->hasSelection()) - { - select = new KisSelection(*scaledDevice->selection()); - scaledDevice->deselect(); - } - // Scale - m_scaledImage->setUndoAdapter(NULL); - m_scaledImage->scale(m_filterZoom, m_filterZoom, NULL, &strategy); - // Scale the selection - if(select) - { - KisPaintDeviceSP t = select.data(); - KisTransformWorker tw(t, m_filterZoom, m_filterZoom, - 0.0, 0.0, 0.0, 0, 0, NULL, &strategy); - tw.run(); - scaledDevice->setSelection(select); - select->setParentLayer(scaledDevice->parentLayer()); - } - - // Crop by the zoom value instead of cropping by rectangle. It gives better results - MyCropVisitor v(m_filterZoom); - m_scaledImage->rootLayer()->accept(v); - } else - { - scaledDevice = new KisPaintDevice(*m_origDevice); - KisSelectionSP select; - if(scaledDevice->hasSelection()) - { - select = new KisSelection(*scaledDevice->selection()); - scaledDevice->deselect(); - } - KisTransformWorker tw(scaledDevice, m_filterZoom, m_filterZoom, - 0.0, 0.0, 0.0, 0, 0, NULL, &strategy); - tw.run(); - // Scale the selection - if(select) - { - KisPaintDeviceSP t = select.data(); - KisTransformWorker tw(t, m_filterZoom, m_filterZoom, - 0.0, 0.0, 0.0, 0, 0, NULL, &strategy); - tw.run(); - scaledDevice->setSelection(select); - ::cropDevice(select.data(), m_filterZoom); - } - ::cropDevice(scaledDevice.data(), m_filterZoom); - } - - m_previewDevice = new KisPaintDevice(*scaledDevice); - - // Setup the progress display - m_filter->enableProgress(); - m_progress->setSubject(m_filter, true, true); - m_filter->setProgressDisplay(m_progress); - m_filter->process(scaledDevice, m_previewDevice, m_config, scaledDevice->exactBounds()); - m_filter->disableProgress(); - - m_dirtyPreview = true; - - if(m_firstZoom) { - m_firstZoom = false; - updateZoom(); - } else { - m_zoomTimer->start(ZOOM_PAUSE, true); - } -} - -#include "kis_previewwidget.moc" diff --git a/chalk/ui/kis_previewwidget.cpp b/chalk/ui/kis_previewwidget.cpp new file mode 100644 index 000000000..f60755a14 --- /dev/null +++ b/chalk/ui/kis_previewwidget.cpp @@ -0,0 +1,409 @@ +/* + * kis_previewwidget.cpp - part of Chalk + * + * Copyright (c) 2001 John Califf + * Copyright (c) 2004 Bart Coppens + * Copyright (c) 2005 Cyrille Berger + * Copyright (c) 2007 Ben Schleimer + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "kis_previewwidgetbase.h" +#include "kis_previewwidget.h" +#include "imageviewer.h" + +static const int ZOOM_PAUSE = 100; +static const int FILTER_PAUSE = 500; +static const double ZOOM_FACTOR = 1.1; + +KisPreviewWidget::KisPreviewWidget( TQWidget* parent, const char* name ) + : PreviewWidgetBase( parent, name ) + , m_autoupdate(true) + , m_previewIsDisplayed(true) + , m_scaledOriginal() + , m_dirtyOriginal(true) + , m_origDevice(new KisPaintDevice(KisMetaRegistry::instance()->csRegistry()->getRGB8(), "temp")) + , m_scaledPreview() + , m_dirtyPreview(true) + , m_previewDevice(new KisPaintDevice(KisMetaRegistry::instance()->csRegistry()->getRGB8(), "temp")) + , m_scaledImage(NULL) + , m_filterZoom(1.0) + , m_zoom(-1.0) + , m_profile(NULL) + , m_progress( 0 ) + , m_zoomTimer(new TQTimer(this)) + , m_filterTimer(new TQTimer(this)) + , m_firstFilter(true) + , m_firstZoom(true) +{ + btnZoomIn->setIconSet(TDEGlobal::instance()->iconLoader()->loadIconSet( "zoom-in", TDEIcon::MainToolbar, 16 )); + connect(btnZoomIn, TQT_SIGNAL(clicked()), this, TQT_SLOT(zoomIn())); + btnZoomOut->setIconSet(TDEGlobal::instance()->iconLoader()->loadIconSet( "zoom-out", TDEIcon::MainToolbar, 16 )); + connect(btnZoomOut, TQT_SIGNAL(clicked()), this, TQT_SLOT(zoomOut())); + btnUpdate->setIconSet(TDEGlobal::instance()->iconLoader()->loadIconSet( "reload", TDEIcon::MainToolbar, 16 )); + connect(btnUpdate, TQT_SIGNAL(clicked()), this, TQT_SLOT(forceUpdate())); + + connect(radioBtnPreview, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(setPreviewDisplayed(bool))); + + connect(checkBoxAutoUpdate, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(slotSetAutoUpdate(bool))); + btnZoomOneToOne->setIconSet(TDEGlobal::instance()->iconLoader()->loadIconSet( "zoom-original", TDEIcon::MainToolbar, 16 )); + connect(btnZoomOneToOne, TQT_SIGNAL(clicked()), this, TQT_SLOT(zoomOneToOne())); + + m_progress = new KisLabelProgress(frmProgress); + m_progress->setMaximumHeight(fontMetrics().height() ); + TQVBoxLayout *vbox = new TQVBoxLayout( frmProgress ); + vbox->addWidget(m_progress); + m_progress->hide(); + + connect(m_zoomTimer, TQT_SIGNAL(timeout()), this, TQT_SLOT(updateZoom())); + connect(m_filterTimer, TQT_SIGNAL(timeout()), this, TQT_SLOT(runFilterHelper())); + +/* kToolBar1->insertLineSeparator(); + kToolBar1->insertButton("reload",2, true, i18n("Update")); + connect(kToolBar1->getButton(2),TQT_SIGNAL(clicked()),this,TQT_SLOT(forceUpdate())); + + kToolBar1->insertButton("",3, true, i18n("Auto Update")); + connect(kToolBar1->getButton(3),TQT_SIGNAL(clicked()),this,TQT_SLOT(toggleAutoUpdate())); + + kToolBar1->insertButton("",4, true, i18n("Switch")); + connect(kToolBar1->getButton(4),TQT_SIGNAL(clicked()),this,TQT_SLOT(toggleImageDisplayed()));*/ +// these currently don't yet work, reenable when they do work :) (TZ-12-2005) +// TODO reenable these +// kToolBar1->insertButton("",5, true, i18n("Popup Original and Preview")); +} + +KisPreviewWidget::~KisPreviewWidget() { } + +void KisPreviewWidget::forceUpdate() +{ + if(m_previewIsDisplayed) + { + m_groupBox->setTitle(m_origDevice->name()); + emit updated(); + } +} + +void KisPreviewWidget::slotSetDevice(KisPaintDeviceSP dev) +{ + Q_ASSERT( dev ); + + if (!dev) return; + + m_origDevice = dev; + m_previewDevice = dev; + m_filterZoom = 1.0; + + KisConfig cfg; + TQString monitorProfileName = cfg.monitorProfile(); + m_profile = KisMetaRegistry::instance()->csRegistry()->getProfileByName(monitorProfileName); + + TQRect r = dev->exactBounds(); + + m_groupBox->setTitle(i18n("Preview: ") + dev->name()); + m_previewIsDisplayed = true; + + m_zoom = -1.0; + zoomChanged(double(m_preview->width()) / double(r.width()) ); +} + +void KisPreviewWidget::updateZoom() +{ + TQApplication::setOverrideCursor(KisCursor::waitCursor()); + + if(m_previewIsDisplayed) + { + if(m_dirtyPreview) + { + TQSize r = m_previewDevice->extent().size(); + int w = r.width(), h = r.height(); + int sw = int(ceil(m_zoom * w / m_filterZoom)); + int sh = int(ceil(m_zoom * h / m_filterZoom)); + m_dirtyPreview = false; + m_scaledPreview = m_previewDevice->convertToTQImage(m_profile, 0, 0, w, h); + m_scaledPreview = m_scaledPreview.scale(sw,sh, TQ_ScaleMax); // Use scale instead of smoothScale for speed up + } + m_preview->setImage(m_scaledPreview); + } else + { + if(m_dirtyOriginal) + { + TQSize r = m_origDevice->extent().size(); + int w = r.width(), h = r.height(); + int sw = int(ceil(m_zoom * w)); + int sh = int(ceil(m_zoom * h)); + m_dirtyOriginal = false; + m_scaledOriginal = m_origDevice->convertToTQImage(m_profile, 0, 0, w, h); + m_scaledOriginal = m_scaledOriginal.scale(sw,sh, TQ_ScaleMax); // Use scale instead of smoothScale for speed up + } + m_preview->setImage(m_scaledOriginal); + } + + TQApplication::restoreOverrideCursor(); +} + +void KisPreviewWidget::slotSetAutoUpdate(bool set) { + m_autoupdate = set; +} + +void KisPreviewWidget::wheelEvent(TQWheelEvent * e) +{ + if (e->delta() > 0) { + zoomIn(); + } else { + zoomOut(); + } + e->accept(); +} + +void KisPreviewWidget::setPreviewDisplayed(bool v) +{ + if(v != m_previewIsDisplayed) + { + m_previewIsDisplayed = v; + if(m_previewIsDisplayed) { + m_groupBox->setTitle(i18n("Preview: ") + m_origDevice->name()); + } else { + m_groupBox->setTitle(i18n("Original: ") + m_origDevice->name()); + } + // Call directly without any pause because there is no scaling + updateZoom(); + } +} + +void KisPreviewWidget::needUpdate() +{ + if(m_previewIsDisplayed) + m_groupBox->setTitle(i18n("Preview (needs update)")); +} + +bool KisPreviewWidget::getAutoUpdate() const { + return m_autoupdate; +} + +void KisPreviewWidget::zoomChanged(const double zoom) +{ + // constrain the zoom + double tZoom = zoom; + if(zoom <= 1./8.) { tZoom = 1./8.; } + if(zoom > 8.) { tZoom = 8.; } + + if(tZoom != m_zoom) + { + m_zoom = tZoom; + m_dirtyOriginal = true; + m_dirtyPreview = true; + + if(m_firstZoom) { + m_firstZoom = false; + updateZoom(); + } else { + m_zoomTimer->start(ZOOM_PAUSE, true); + } + } +} + +void KisPreviewWidget::zoomIn() { + zoomChanged(m_zoom * ZOOM_FACTOR); +} + +void KisPreviewWidget::zoomOut() { + zoomChanged(m_zoom / ZOOM_FACTOR); +} + +void KisPreviewWidget::zoomOneToOne() { + zoomChanged(1.0); +} + +static inline void cropDevice(KisPaintDevice * device, const double & zoom) { + TQRect r = device->exactBounds(); + r.setX(int(zoom * r.x()) ); + r.setY(int(zoom * r.y()) ); + r.setWidth(int(zoom * r.width()) ); + r.setHeight(int(zoom * r.height()) ); + device->crop(r); +} + +class MyCropVisitor : public KisLayerVisitor { + const double m_zoom; + +public: + MyCropVisitor(const double & z) : m_zoom(z) { } + virtual ~MyCropVisitor() { } + + virtual bool visit(KisPaintLayer *layer) { + KisPaintDeviceSP device = layer->paintDevice(); + ::cropDevice(device.data(), m_zoom); + // Make sure we have a tight fit for the selection + if(device->hasSelection()) { + ::cropDevice(device->selection().data(), m_zoom); + } + + return true; + } + virtual bool visit(KisGroupLayer *layer) { + for(KisLayerSP l = layer->firstChild(); l; l = l->nextSibling()) { + l->accept(*this); + } + return true; + } + virtual bool visit(KisPartLayer *) { return true; } + virtual bool visit(KisAdjustmentLayer *) { return true; } +}; + +void KisPreviewWidget::runFilter(KisFilter * filter, KisFilterConfiguration * config) { + if(!filter) return; + if(!config) return; + + m_filter = filter; + m_config = config; + + if(m_firstFilter) { + m_firstFilter = false; + runFilterHelper(); + } else { + m_filterTimer->start(FILTER_PAUSE, true); + } +} + +/** + * XXX: Fix the situations which m_origDevice is NOT associated with a image. + * If it comes from a adjustment layer or projection or thumbnail. Currently, nothing happens + */ +void KisPreviewWidget::runFilterHelper() { + + m_filterZoom = m_zoom; + // Dont scale more then 1.0 so we don't waste time in preview widget for large scaling. + if(m_filterZoom > 1.0) { + m_filterZoom = 1.0; + } + + KisPaintDeviceSP scaledDevice; + KisHermiteFilterStrategy strategy; + + // Copy the image and scale + if (m_origDevice->image()) + { + m_scaledImage = new KisImage(*m_origDevice->image()); + if(!m_origDevice->parentLayer()) return; + TQString layerName = m_origDevice->parentLayer()->name(); + KisPaintLayerSP pl = ::tqqt_cast(m_scaledImage->findLayer(layerName)); + if(!pl) return; + scaledDevice = pl->paintDevice(); + + KisSelectionSP select; + if(scaledDevice->hasSelection()) + { + select = new KisSelection(*scaledDevice->selection()); + scaledDevice->deselect(); + } + // Scale + m_scaledImage->setUndoAdapter(NULL); + m_scaledImage->scale(m_filterZoom, m_filterZoom, NULL, &strategy); + // Scale the selection + if(select) + { + KisPaintDeviceSP t = select.data(); + KisTransformWorker tw(t, m_filterZoom, m_filterZoom, + 0.0, 0.0, 0.0, 0, 0, NULL, &strategy); + tw.run(); + scaledDevice->setSelection(select); + select->setParentLayer(scaledDevice->parentLayer()); + } + + // Crop by the zoom value instead of cropping by rectangle. It gives better results + MyCropVisitor v(m_filterZoom); + m_scaledImage->rootLayer()->accept(v); + } else + { + scaledDevice = new KisPaintDevice(*m_origDevice); + KisSelectionSP select; + if(scaledDevice->hasSelection()) + { + select = new KisSelection(*scaledDevice->selection()); + scaledDevice->deselect(); + } + KisTransformWorker tw(scaledDevice, m_filterZoom, m_filterZoom, + 0.0, 0.0, 0.0, 0, 0, NULL, &strategy); + tw.run(); + // Scale the selection + if(select) + { + KisPaintDeviceSP t = select.data(); + KisTransformWorker tw(t, m_filterZoom, m_filterZoom, + 0.0, 0.0, 0.0, 0, 0, NULL, &strategy); + tw.run(); + scaledDevice->setSelection(select); + ::cropDevice(select.data(), m_filterZoom); + } + ::cropDevice(scaledDevice.data(), m_filterZoom); + } + + m_previewDevice = new KisPaintDevice(*scaledDevice); + + // Setup the progress display + m_filter->enableProgress(); + m_progress->setSubject(m_filter, true, true); + m_filter->setProgressDisplay(m_progress); + m_filter->process(scaledDevice, m_previewDevice, m_config, scaledDevice->exactBounds()); + m_filter->disableProgress(); + + m_dirtyPreview = true; + + if(m_firstZoom) { + m_firstZoom = false; + updateZoom(); + } else { + m_zoomTimer->start(ZOOM_PAUSE, true); + } +} + +#include "kis_previewwidget.moc" diff --git a/chalk/ui/kis_qpaintdevice_canvas.cc b/chalk/ui/kis_qpaintdevice_canvas.cpp similarity index 100% rename from chalk/ui/kis_qpaintdevice_canvas.cc rename to chalk/ui/kis_qpaintdevice_canvas.cpp diff --git a/chalk/ui/kis_qpaintdevice_canvas_painter.cc b/chalk/ui/kis_qpaintdevice_canvas_painter.cpp similarity index 100% rename from chalk/ui/kis_qpaintdevice_canvas_painter.cc rename to chalk/ui/kis_qpaintdevice_canvas_painter.cpp diff --git a/chalk/ui/kis_resource_mediator.cc b/chalk/ui/kis_resource_mediator.cpp similarity index 100% rename from chalk/ui/kis_resource_mediator.cc rename to chalk/ui/kis_resource_mediator.cpp diff --git a/chalk/ui/kis_resourceserver.cc b/chalk/ui/kis_resourceserver.cc deleted file mode 100644 index 3076bc00d..000000000 --- a/chalk/ui/kis_resourceserver.cc +++ /dev/null @@ -1,199 +0,0 @@ -/* - * kis_resourceserver.cc - part of KImageShop - * - * Copyright (c) 1999 Matthias Elter - * Copyright (c) 2003 Patrick Julien - * Copyright (c) 2005 Sven Langkamp - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -#include -#include -#include -#include - -#include -#include -#include -#include - -#include "kis_resource.h" -#include "kis_factory.h" -#include "kis_generic_registry.h" -#include "kis_resourceserver.h" -#include "kis_brush.h" -#include "kis_imagepipe_brush.h" -#include "kis_gradient.h" -#include "kis_pattern.h" -#include "kis_palette.h" -#include - -KisResourceServerBase::KisResourceServerBase(TQString type) - : m_type(type), m_loaded(false) -{ -} - -KisResourceServerBase::~KisResourceServerBase() -{ -} - -void KisResourceServerBase::loadResources(TQStringList filenames) -{ - TQStringList uniqueFiles; - - while( !filenames.empty() ) - { - - TQString front = *filenames.begin(); - filenames.pop_front(); - - TQString fname = TQFileInfo(front).fileName(); - //ebug() << "Loading " << fname << "\n"; - // XXX: Don't load resources with the same filename. Actually, we should look inside - // the resource to find out whether they are really the same, but for now this - // will prevent the same brush etc. showing up twice. - if (uniqueFiles.empty() || uniqueFiles.find(fname) == uniqueFiles.end()) { - uniqueFiles.append(fname); - KisResource *resource; - resource = createResource(front); - if(resource->load() && resource->valid()) - { - m_resources.append(resource); - TQ_CHECK_PTR(resource); - emit resourceAdded(resource); - } - else { - delete resource; - } - } - } - m_loaded = true; -} - -TQValueList KisResourceServerBase::resources() -{ - if(!m_loaded) { - return TQValueList(); - } - - return m_resources; -} - -void KisResourceServerBase::addResource(KisResource* resource) -{ - if (!resource->valid()) { - kdWarning(41001) << "Tried to add an invalid resource!" << endl; - return; - } - - m_resources.append(resource); - emit resourceAdded(resource); -} - - -class ResourceLoaderThread : public TQThread { - -public: - - ResourceLoaderThread(KisResourceServerBase * server, TQStringList files) - : TQThread() - , m_server(server) - , m_fileNames( files ) - { - } - - - void run() - { - m_server->loadResources(m_fileNames); - } - -private: - - KisResourceServerBase * m_server; - TQStringList m_fileNames; - -}; - -TQStringList getFileNames( TQString extensions, TQString type ) -{ - TQStringList extensionList = TQStringList::split(":", extensions); - TQStringList fileNames; - - TQStringList::Iterator it; - for ( it = extensionList.begin(); it != extensionList.end(); ++it ) { - TQString s = (*it); - fileNames += KisFactory::instance()->dirs()->findAllResources(type.ascii(), (*it)); - } - return fileNames; -} - - -KisResourceServerRegistry *KisResourceServerRegistry::m_singleton = 0; - -KisResourceServerRegistry::KisResourceServerRegistry() -{ - - KisResourceServer* brushServer = new KisResourceServer("kis_brushes"); - ResourceLoaderThread t1 (brushServer, getFileNames( "*.gbr","kis_brushes" )); - t1.start(); - - KisResourceServer* imagePipeBrushServer = new KisResourceServer("kis_brushes"); - ResourceLoaderThread t2 (imagePipeBrushServer, getFileNames( "*.gih", "kis_brushes")); - t2.start(); - - KisResourceServer* patternServer = new KisResourceServer("kis_patterns"); - ResourceLoaderThread t3 (patternServer, getFileNames("*.pat", "kis_patterns")); - t3.start(); - - KisResourceServer* gradientServer = new KisResourceServer("kis_gradients"); - ResourceLoaderThread t4 (gradientServer, getFileNames(KoGradientManager::filters().join( ":" ), "kis_gradients")); - t4.start(); - - - KisResourceServer* paletteServer = new KisResourceServer("kis_palettes"); - ResourceLoaderThread t5 (paletteServer, getFileNames("*.gpl:*.pal:*.act", "kis_palettes") ); - t5.start(); - - t1.wait(); - t2.wait(); - t3.wait(); - t4.wait(); - t5.wait(); - - add( KisID( "BrushServer", ""), brushServer ); - add( KisID( "ImagePipeBrushServer", ""), imagePipeBrushServer ); - add( KisID( "PatternServer", ""), patternServer ); - add( KisID( "GradientServer", ""), gradientServer ); - add( KisID( "PaletteServer", ""), paletteServer ); - -} - -KisResourceServerRegistry::~KisResourceServerRegistry() -{ -} - -KisResourceServerRegistry* KisResourceServerRegistry::instance() -{ - if(KisResourceServerRegistry::m_singleton == 0) - { - KisResourceServerRegistry::m_singleton = new KisResourceServerRegistry(); - } - return KisResourceServerRegistry::m_singleton; -} - - -#include "kis_resourceserver.moc" - diff --git a/chalk/ui/kis_resourceserver.cpp b/chalk/ui/kis_resourceserver.cpp new file mode 100644 index 000000000..333bccd1d --- /dev/null +++ b/chalk/ui/kis_resourceserver.cpp @@ -0,0 +1,199 @@ +/* + * kis_resourceserver.cpp - part of KImageShop + * + * Copyright (c) 1999 Matthias Elter + * Copyright (c) 2003 Patrick Julien + * Copyright (c) 2005 Sven Langkamp + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "kis_resource.h" +#include "kis_factory.h" +#include "kis_generic_registry.h" +#include "kis_resourceserver.h" +#include "kis_brush.h" +#include "kis_imagepipe_brush.h" +#include "kis_gradient.h" +#include "kis_pattern.h" +#include "kis_palette.h" +#include + +KisResourceServerBase::KisResourceServerBase(TQString type) + : m_type(type), m_loaded(false) +{ +} + +KisResourceServerBase::~KisResourceServerBase() +{ +} + +void KisResourceServerBase::loadResources(TQStringList filenames) +{ + TQStringList uniqueFiles; + + while( !filenames.empty() ) + { + + TQString front = *filenames.begin(); + filenames.pop_front(); + + TQString fname = TQFileInfo(front).fileName(); + //ebug() << "Loading " << fname << "\n"; + // XXX: Don't load resources with the same filename. Actually, we should look inside + // the resource to find out whether they are really the same, but for now this + // will prevent the same brush etc. showing up twice. + if (uniqueFiles.empty() || uniqueFiles.find(fname) == uniqueFiles.end()) { + uniqueFiles.append(fname); + KisResource *resource; + resource = createResource(front); + if(resource->load() && resource->valid()) + { + m_resources.append(resource); + TQ_CHECK_PTR(resource); + emit resourceAdded(resource); + } + else { + delete resource; + } + } + } + m_loaded = true; +} + +TQValueList KisResourceServerBase::resources() +{ + if(!m_loaded) { + return TQValueList(); + } + + return m_resources; +} + +void KisResourceServerBase::addResource(KisResource* resource) +{ + if (!resource->valid()) { + kdWarning(41001) << "Tried to add an invalid resource!" << endl; + return; + } + + m_resources.append(resource); + emit resourceAdded(resource); +} + + +class ResourceLoaderThread : public TQThread { + +public: + + ResourceLoaderThread(KisResourceServerBase * server, TQStringList files) + : TQThread() + , m_server(server) + , m_fileNames( files ) + { + } + + + void run() + { + m_server->loadResources(m_fileNames); + } + +private: + + KisResourceServerBase * m_server; + TQStringList m_fileNames; + +}; + +TQStringList getFileNames( TQString extensions, TQString type ) +{ + TQStringList extensionList = TQStringList::split(":", extensions); + TQStringList fileNames; + + TQStringList::Iterator it; + for ( it = extensionList.begin(); it != extensionList.end(); ++it ) { + TQString s = (*it); + fileNames += KisFactory::instance()->dirs()->findAllResources(type.ascii(), (*it)); + } + return fileNames; +} + + +KisResourceServerRegistry *KisResourceServerRegistry::m_singleton = 0; + +KisResourceServerRegistry::KisResourceServerRegistry() +{ + + KisResourceServer* brushServer = new KisResourceServer("kis_brushes"); + ResourceLoaderThread t1 (brushServer, getFileNames( "*.gbr","kis_brushes" )); + t1.start(); + + KisResourceServer* imagePipeBrushServer = new KisResourceServer("kis_brushes"); + ResourceLoaderThread t2 (imagePipeBrushServer, getFileNames( "*.gih", "kis_brushes")); + t2.start(); + + KisResourceServer* patternServer = new KisResourceServer("kis_patterns"); + ResourceLoaderThread t3 (patternServer, getFileNames("*.pat", "kis_patterns")); + t3.start(); + + KisResourceServer* gradientServer = new KisResourceServer("kis_gradients"); + ResourceLoaderThread t4 (gradientServer, getFileNames(KoGradientManager::filters().join( ":" ), "kis_gradients")); + t4.start(); + + + KisResourceServer* paletteServer = new KisResourceServer("kis_palettes"); + ResourceLoaderThread t5 (paletteServer, getFileNames("*.gpl:*.pal:*.act", "kis_palettes") ); + t5.start(); + + t1.wait(); + t2.wait(); + t3.wait(); + t4.wait(); + t5.wait(); + + add( KisID( "BrushServer", ""), brushServer ); + add( KisID( "ImagePipeBrushServer", ""), imagePipeBrushServer ); + add( KisID( "PatternServer", ""), patternServer ); + add( KisID( "GradientServer", ""), gradientServer ); + add( KisID( "PaletteServer", ""), paletteServer ); + +} + +KisResourceServerRegistry::~KisResourceServerRegistry() +{ +} + +KisResourceServerRegistry* KisResourceServerRegistry::instance() +{ + if(KisResourceServerRegistry::m_singleton == 0) + { + KisResourceServerRegistry::m_singleton = new KisResourceServerRegistry(); + } + return KisResourceServerRegistry::m_singleton; +} + + +#include "kis_resourceserver.moc" + diff --git a/chalk/ui/kis_ruler.cc b/chalk/ui/kis_ruler.cpp similarity index 100% rename from chalk/ui/kis_ruler.cc rename to chalk/ui/kis_ruler.cpp diff --git a/chalk/ui/kis_selection_manager.cc b/chalk/ui/kis_selection_manager.cpp similarity index 100% rename from chalk/ui/kis_selection_manager.cc rename to chalk/ui/kis_selection_manager.cpp diff --git a/chalk/ui/kis_selection_options.cc b/chalk/ui/kis_selection_options.cpp similarity index 100% rename from chalk/ui/kis_selection_options.cc rename to chalk/ui/kis_selection_options.cpp diff --git a/chalk/ui/kis_text_brush.cc b/chalk/ui/kis_text_brush.cpp similarity index 100% rename from chalk/ui/kis_text_brush.cc rename to chalk/ui/kis_text_brush.cpp diff --git a/chalk/ui/kis_tool.cc b/chalk/ui/kis_tool.cpp similarity index 100% rename from chalk/ui/kis_tool.cc rename to chalk/ui/kis_tool.cpp diff --git a/chalk/ui/kis_tool_dummy.cc b/chalk/ui/kis_tool_dummy.cpp similarity index 100% rename from chalk/ui/kis_tool_dummy.cc rename to chalk/ui/kis_tool_dummy.cpp diff --git a/chalk/ui/kis_tool_freehand.cc b/chalk/ui/kis_tool_freehand.cc deleted file mode 100644 index 787afee47..000000000 --- a/chalk/ui/kis_tool_freehand.cc +++ /dev/null @@ -1,354 +0,0 @@ -/* - * kis_tool_brush.cc - part of Chalk - * - * Copyright (c) 2003-2004 Boudewijn Rempt - * Copyright (c) 2004 Bart Coppens - * - * 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 of the License, 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include "kis_canvas_subject.h" -#include "kis_undo_adapter.h" -#include "kis_selection.h" -#include "kis_painter.h" -#include "kis_fill_painter.h" -#include "kis_tool_freehand.h" -#include "kis_cursor.h" -#include "kis_button_press_event.h" -#include "kis_button_release_event.h" -#include "kis_move_event.h" -#include "kis_layer.h" -#include "kis_group_layer.h" -#include "kis_paint_layer.h" -#include "kis_canvas.h" -#include "kis_canvas_painter.h" -#include "kis_boundary_painter.h" -#include "kis_brush.h" - -KisToolFreehand::KisToolFreehand(TQString transactionText) - : super(transactionText), - m_dragDist ( 0 ), - m_transactionText(transactionText), - m_mode( HOVER ) -{ - m_painter = 0; - m_currentImage = 0; - m_tempLayer = 0; - m_paintIncremental = true; - m_paintOnSelection = false; - m_paintedOutline = false; -} - -KisToolFreehand::~KisToolFreehand() -{ -} - -void KisToolFreehand::update(KisCanvasSubject *subject) -{ - super::update(subject); - m_currentImage = m_subject->currentImg(); -} - -void KisToolFreehand::buttonPress(KisButtonPressEvent *e) -{ - if (!m_subject) return; - - if (!m_subject->currentBrush()) return; - - if (!m_currentImage || !m_currentImage->activeDevice()) return; - - if (e->button() == Qt::LeftButton) { - - m_currentImage->activeDevice()->lock( true ); - kdDebug() << ">>>>>>>>>>>>>>>>>>>Locking paint device\n"; - - // People complain that they can't start brush strokes outside of the image boundaries. - // This makes sense, especially when combined with BUG:132759, so commenting out the - // next line makes sense. - //if (!m_currentImage->bounds().contains(e->pos().floorTQPoint())) return; - - initPaint(e); - paintAt(e->pos(), e->pressure(), e->xTilt(), e->yTilt()); - - m_prevPos = e->pos(); - m_prevPressure = e->pressure(); - m_prevXTilt = e->xTilt(); - m_prevYTilt = e->yTilt(); - - TQRect r = m_painter->dirtyRect(); - if ( r.isValid() ) { - m_dirtyRect = r; - - r = TQRect(r.left()-1, r.top()-1, r.width()+2, r.height()+2); //needed to update selectionvisualization - if (!m_paintOnSelection) { - m_currentImage->activeLayer()->setDirty(r); - } - else { - m_target->setDirty(r); - // Just update the canvas. XXX: After 1.5, find a better way to make sure tools don't set dirty what they didn't touch. - m_subject->canvasController()->updateCanvas( r ); - } - } - } -} - -void KisToolFreehand::buttonRelease(KisButtonReleaseEvent* e) -{ - if (e->button() == Qt::LeftButton && m_mode == PAINT) { - endPaint(); - m_currentImage->activeDevice()->lock( false ); - kdDebug() << ">>>>>>>>>>>>>>>>>>>UNLocking paint device\n"; - - } - KisToolPaint::buttonRelease(e); -} - -void KisToolFreehand::move(KisMoveEvent *e) -{ - if (m_mode == PAINT) { - - paintLine(m_prevPos, m_prevPressure, m_prevXTilt, m_prevYTilt, e->pos(), e->pressure(), e->xTilt(), e->yTilt()); - - m_prevPos = e->pos(); - m_prevPressure = e->pressure(); - m_prevXTilt = e->xTilt(); - m_prevYTilt = e->yTilt(); - - TQRect r = m_painter->dirtyRect(); - - if (r.isValid()) { - m_dirtyRect |= r; - - if (!m_paintOnSelection) { - m_currentImage->activeLayer()->setDirty(r); - } - else { - // Just update the canvas - r = TQRect(r.left()-1, r.top()-1, r.width()+2, r.height()+2); //needed to update selectionvisualization - m_target->setDirty(r); - m_subject->canvasController()->updateCanvas( r ); - } - } - } -} - -void KisToolFreehand::initPaint(KisEvent *) -{ - if (!m_currentImage || !m_currentImage->activeDevice()) return; - - m_mode = PAINT; - m_dragDist = 0; - - // Create painter - KisPaintDeviceSP device; - if (m_currentImage && (device = m_currentImage->activeDevice())) { - - if (m_painter) - delete m_painter; - - if (!m_paintIncremental) { - if (m_currentImage->undo()) - m_currentImage->undoAdapter()->beginMacro(m_transactionText); - - KisLayerSupportsIndirectPainting* layer; - if ((layer = dynamic_cast( - m_currentImage->activeLayer().data()))) { - - // Hack for the painting of single-layered layers using indirect painting, - // because the group layer would not have a correctly synched cache ( - // because of an optimization that would happen, having this layer as - // projection). - KisLayer* l = layer->layer(); - KisPaintLayer* pl = dynamic_cast(l); - if (l->parent() && (l->parent()->parent() == 0) - && (l->parent()->childCount() == 1) - && l->parent()->paintLayerInducesProjectionOptimization(pl)) { - // If there's a mask, device could've been the mask. The induce function - // should catch this, but better safe than sorry - l->parent()->resetProjection(pl->paintDevice()); - } - - m_target = new KisPaintDevice(m_currentImage->activeLayer(), - device->colorSpace()); - layer->setTemporaryTarget(m_target); - layer->setTemporaryCompositeOp(m_compositeOp); - layer->setTemporaryOpacity(m_opacity); - - if (device->hasSelection()) - m_target->setSelection(device->selection()); - } - } else { - m_target = device; - } - if(m_target->hasSelection()) m_target->selection()->startCachingExactRect(); - m_painter = new KisPainter( m_target ); - TQ_CHECK_PTR(m_painter); - m_source = device; - if (currentImage()->undo()) m_painter->beginTransaction(m_transactionText); - } - - m_painter->setPaintColor(m_subject->fgColor()); - m_painter->setBackgroundColor(m_subject->bgColor()); - m_painter->setBrush(m_subject->currentBrush()); - - - // if you're drawing on a temporary layer, the layer already sets this - if (m_paintIncremental) { - m_painter->setCompositeOp(m_compositeOp); - m_painter->setOpacity(m_opacity); - } else { - m_painter->setCompositeOp(COMPOSITE_ALPHA_DARKEN); - m_painter->setOpacity( OPACITY_OPAQUE ); - - } - -/* kdDebug() << "target: " << m_target << "( " << m_target->name() << " )" - << " source: " << m_source << "( " << m_source->name() << " )" - << ", incremental " << m_paintIncremental - << ", paint on selection: " << m_paintOnSelection - << ", active device has selection: " << device->hasSelection() - << ", target has selection: " << m_target->hasSelection() - << endl; -*/ -} - -void KisToolFreehand::endPaint() -{ - m_mode = HOVER; - if (m_currentImage) { - - if (m_painter) { - // If painting in mouse release, make sure painter - // is destructed or end()ed - if (!m_paintIncremental) { - if (m_currentImage->undo()) - m_painter->endTransaction(); - KisPainter painter( m_source ); - painter.setCompositeOp(m_compositeOp); - if (m_currentImage->undo()) - painter.beginTransaction(m_transactionText); - painter.bitBlt(m_dirtyRect.x(), m_dirtyRect.y(), m_compositeOp, m_target, - m_opacity, - m_dirtyRect.x(), m_dirtyRect.y(), - m_dirtyRect.width(), m_dirtyRect.height()); - - KisLayerSupportsIndirectPainting* layer = - dynamic_cast(m_source->parentLayer()); - layer->setTemporaryTarget(0); - m_source->parentLayer()->setDirty(m_dirtyRect); - - if (m_currentImage->undo()) { - m_currentImage->undoAdapter()->addCommand(painter.endTransaction()); - m_currentImage->undoAdapter()->endMacro(); - } - } else { - if (m_currentImage->undo()) - m_currentImage->undoAdapter()->addCommand(m_painter->endTransaction()); - } - } - delete m_painter; - m_painter = 0; - notifyModified(); - if(m_target->hasSelection()) m_target->selection()->stopCachingExactRect(); - } -} - -void KisToolFreehand::paintAt(const KisPoint &pos, - const double pressure, - const double xTilt, - const double yTilt) -{ - painter()->paintAt(pos, pressure, xTilt, yTilt); -} - -void KisToolFreehand::paintLine(const KisPoint & pos1, - const double pressure1, - const double xtilt1, - const double ytilt1, - const KisPoint & pos2, - const double pressure2, - const double xtilt2, - const double ytilt2) -{ - m_dragDist = painter()->paintLine(pos1, pressure1, xtilt1, ytilt1, pos2, pressure2, xtilt2, ytilt2, m_dragDist); -} - - -KisImageSP KisToolFreehand::currentImage() -{ - return m_currentImage; -} - - -void KisToolFreehand::paintOutline(const KisPoint& point) { - if (!m_subject) { - return; - } - - KisCanvasController *controller = m_subject->canvasController(); - - if (currentImage() && !currentImage()->bounds().contains(point.floorTQPoint())) { - if (m_paintedOutline) { - controller->kiscanvas()->update(); - m_paintedOutline = false; - } - return; - } - - KisCanvas *canvas = controller->kiscanvas(); - canvas->repaint(); - - KisBrush *brush = m_subject->currentBrush(); - // There may not be a brush present, and we shouldn't crash in that case - if (brush) { - KisCanvasPainter gc(canvas); - TQPen pen(TQt::SolidLine); - - KisPoint hotSpot = brush->hotSpot(); - - gc.setRasterOp(TQt::NotROP); - gc.setPen(pen); - gc.setViewport(0, 0, static_cast(canvas->width() * m_subject->zoomFactor()), - static_cast(canvas->height() * m_subject->zoomFactor())); - gc.translate((- controller->horzValue()) / m_subject->zoomFactor(), - (- controller->vertValue()) / m_subject->zoomFactor()); - - KisPoint topLeft = point - hotSpot; - - if (m_subject->currentPaintop().id() == "pen") { - // Pen paints on whole pixels only. - topLeft = topLeft.roundTQPoint(); - } - - gc.translate(topLeft.x(), topLeft.y()); - - KisBoundaryPainter::paint(brush->boundary(), gc); - m_paintedOutline = true; - } -} - - -#include "kis_tool_freehand.moc" - diff --git a/chalk/ui/kis_tool_freehand.cpp b/chalk/ui/kis_tool_freehand.cpp new file mode 100644 index 000000000..74eec4066 --- /dev/null +++ b/chalk/ui/kis_tool_freehand.cpp @@ -0,0 +1,354 @@ +/* + * kis_tool_brush.cpp - part of Chalk + * + * Copyright (c) 2003-2004 Boudewijn Rempt + * Copyright (c) 2004 Bart Coppens + * + * 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 of the License, 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "kis_canvas_subject.h" +#include "kis_undo_adapter.h" +#include "kis_selection.h" +#include "kis_painter.h" +#include "kis_fill_painter.h" +#include "kis_tool_freehand.h" +#include "kis_cursor.h" +#include "kis_button_press_event.h" +#include "kis_button_release_event.h" +#include "kis_move_event.h" +#include "kis_layer.h" +#include "kis_group_layer.h" +#include "kis_paint_layer.h" +#include "kis_canvas.h" +#include "kis_canvas_painter.h" +#include "kis_boundary_painter.h" +#include "kis_brush.h" + +KisToolFreehand::KisToolFreehand(TQString transactionText) + : super(transactionText), + m_dragDist ( 0 ), + m_transactionText(transactionText), + m_mode( HOVER ) +{ + m_painter = 0; + m_currentImage = 0; + m_tempLayer = 0; + m_paintIncremental = true; + m_paintOnSelection = false; + m_paintedOutline = false; +} + +KisToolFreehand::~KisToolFreehand() +{ +} + +void KisToolFreehand::update(KisCanvasSubject *subject) +{ + super::update(subject); + m_currentImage = m_subject->currentImg(); +} + +void KisToolFreehand::buttonPress(KisButtonPressEvent *e) +{ + if (!m_subject) return; + + if (!m_subject->currentBrush()) return; + + if (!m_currentImage || !m_currentImage->activeDevice()) return; + + if (e->button() == Qt::LeftButton) { + + m_currentImage->activeDevice()->lock( true ); + kdDebug() << ">>>>>>>>>>>>>>>>>>>Locking paint device\n"; + + // People complain that they can't start brush strokes outside of the image boundaries. + // This makes sense, especially when combined with BUG:132759, so commenting out the + // next line makes sense. + //if (!m_currentImage->bounds().contains(e->pos().floorTQPoint())) return; + + initPaint(e); + paintAt(e->pos(), e->pressure(), e->xTilt(), e->yTilt()); + + m_prevPos = e->pos(); + m_prevPressure = e->pressure(); + m_prevXTilt = e->xTilt(); + m_prevYTilt = e->yTilt(); + + TQRect r = m_painter->dirtyRect(); + if ( r.isValid() ) { + m_dirtyRect = r; + + r = TQRect(r.left()-1, r.top()-1, r.width()+2, r.height()+2); //needed to update selectionvisualization + if (!m_paintOnSelection) { + m_currentImage->activeLayer()->setDirty(r); + } + else { + m_target->setDirty(r); + // Just update the canvas. XXX: After 1.5, find a better way to make sure tools don't set dirty what they didn't touch. + m_subject->canvasController()->updateCanvas( r ); + } + } + } +} + +void KisToolFreehand::buttonRelease(KisButtonReleaseEvent* e) +{ + if (e->button() == Qt::LeftButton && m_mode == PAINT) { + endPaint(); + m_currentImage->activeDevice()->lock( false ); + kdDebug() << ">>>>>>>>>>>>>>>>>>>UNLocking paint device\n"; + + } + KisToolPaint::buttonRelease(e); +} + +void KisToolFreehand::move(KisMoveEvent *e) +{ + if (m_mode == PAINT) { + + paintLine(m_prevPos, m_prevPressure, m_prevXTilt, m_prevYTilt, e->pos(), e->pressure(), e->xTilt(), e->yTilt()); + + m_prevPos = e->pos(); + m_prevPressure = e->pressure(); + m_prevXTilt = e->xTilt(); + m_prevYTilt = e->yTilt(); + + TQRect r = m_painter->dirtyRect(); + + if (r.isValid()) { + m_dirtyRect |= r; + + if (!m_paintOnSelection) { + m_currentImage->activeLayer()->setDirty(r); + } + else { + // Just update the canvas + r = TQRect(r.left()-1, r.top()-1, r.width()+2, r.height()+2); //needed to update selectionvisualization + m_target->setDirty(r); + m_subject->canvasController()->updateCanvas( r ); + } + } + } +} + +void KisToolFreehand::initPaint(KisEvent *) +{ + if (!m_currentImage || !m_currentImage->activeDevice()) return; + + m_mode = PAINT; + m_dragDist = 0; + + // Create painter + KisPaintDeviceSP device; + if (m_currentImage && (device = m_currentImage->activeDevice())) { + + if (m_painter) + delete m_painter; + + if (!m_paintIncremental) { + if (m_currentImage->undo()) + m_currentImage->undoAdapter()->beginMacro(m_transactionText); + + KisLayerSupportsIndirectPainting* layer; + if ((layer = dynamic_cast( + m_currentImage->activeLayer().data()))) { + + // Hack for the painting of single-layered layers using indirect painting, + // because the group layer would not have a correctly synched cache ( + // because of an optimization that would happen, having this layer as + // projection). + KisLayer* l = layer->layer(); + KisPaintLayer* pl = dynamic_cast(l); + if (l->parent() && (l->parent()->parent() == 0) + && (l->parent()->childCount() == 1) + && l->parent()->paintLayerInducesProjectionOptimization(pl)) { + // If there's a mask, device could've been the mask. The induce function + // should catch this, but better safe than sorry + l->parent()->resetProjection(pl->paintDevice()); + } + + m_target = new KisPaintDevice(m_currentImage->activeLayer(), + device->colorSpace()); + layer->setTemporaryTarget(m_target); + layer->setTemporaryCompositeOp(m_compositeOp); + layer->setTemporaryOpacity(m_opacity); + + if (device->hasSelection()) + m_target->setSelection(device->selection()); + } + } else { + m_target = device; + } + if(m_target->hasSelection()) m_target->selection()->startCachingExactRect(); + m_painter = new KisPainter( m_target ); + TQ_CHECK_PTR(m_painter); + m_source = device; + if (currentImage()->undo()) m_painter->beginTransaction(m_transactionText); + } + + m_painter->setPaintColor(m_subject->fgColor()); + m_painter->setBackgroundColor(m_subject->bgColor()); + m_painter->setBrush(m_subject->currentBrush()); + + + // if you're drawing on a temporary layer, the layer already sets this + if (m_paintIncremental) { + m_painter->setCompositeOp(m_compositeOp); + m_painter->setOpacity(m_opacity); + } else { + m_painter->setCompositeOp(COMPOSITE_ALPHA_DARKEN); + m_painter->setOpacity( OPACITY_OPAQUE ); + + } + +/* kdDebug() << "target: " << m_target << "( " << m_target->name() << " )" + << " source: " << m_source << "( " << m_source->name() << " )" + << ", incremental " << m_paintIncremental + << ", paint on selection: " << m_paintOnSelection + << ", active device has selection: " << device->hasSelection() + << ", target has selection: " << m_target->hasSelection() + << endl; +*/ +} + +void KisToolFreehand::endPaint() +{ + m_mode = HOVER; + if (m_currentImage) { + + if (m_painter) { + // If painting in mouse release, make sure painter + // is destructed or end()ed + if (!m_paintIncremental) { + if (m_currentImage->undo()) + m_painter->endTransaction(); + KisPainter painter( m_source ); + painter.setCompositeOp(m_compositeOp); + if (m_currentImage->undo()) + painter.beginTransaction(m_transactionText); + painter.bitBlt(m_dirtyRect.x(), m_dirtyRect.y(), m_compositeOp, m_target, + m_opacity, + m_dirtyRect.x(), m_dirtyRect.y(), + m_dirtyRect.width(), m_dirtyRect.height()); + + KisLayerSupportsIndirectPainting* layer = + dynamic_cast(m_source->parentLayer()); + layer->setTemporaryTarget(0); + m_source->parentLayer()->setDirty(m_dirtyRect); + + if (m_currentImage->undo()) { + m_currentImage->undoAdapter()->addCommand(painter.endTransaction()); + m_currentImage->undoAdapter()->endMacro(); + } + } else { + if (m_currentImage->undo()) + m_currentImage->undoAdapter()->addCommand(m_painter->endTransaction()); + } + } + delete m_painter; + m_painter = 0; + notifyModified(); + if(m_target->hasSelection()) m_target->selection()->stopCachingExactRect(); + } +} + +void KisToolFreehand::paintAt(const KisPoint &pos, + const double pressure, + const double xTilt, + const double yTilt) +{ + painter()->paintAt(pos, pressure, xTilt, yTilt); +} + +void KisToolFreehand::paintLine(const KisPoint & pos1, + const double pressure1, + const double xtilt1, + const double ytilt1, + const KisPoint & pos2, + const double pressure2, + const double xtilt2, + const double ytilt2) +{ + m_dragDist = painter()->paintLine(pos1, pressure1, xtilt1, ytilt1, pos2, pressure2, xtilt2, ytilt2, m_dragDist); +} + + +KisImageSP KisToolFreehand::currentImage() +{ + return m_currentImage; +} + + +void KisToolFreehand::paintOutline(const KisPoint& point) { + if (!m_subject) { + return; + } + + KisCanvasController *controller = m_subject->canvasController(); + + if (currentImage() && !currentImage()->bounds().contains(point.floorTQPoint())) { + if (m_paintedOutline) { + controller->kiscanvas()->update(); + m_paintedOutline = false; + } + return; + } + + KisCanvas *canvas = controller->kiscanvas(); + canvas->repaint(); + + KisBrush *brush = m_subject->currentBrush(); + // There may not be a brush present, and we shouldn't crash in that case + if (brush) { + KisCanvasPainter gc(canvas); + TQPen pen(TQt::SolidLine); + + KisPoint hotSpot = brush->hotSpot(); + + gc.setRasterOp(TQt::NotROP); + gc.setPen(pen); + gc.setViewport(0, 0, static_cast(canvas->width() * m_subject->zoomFactor()), + static_cast(canvas->height() * m_subject->zoomFactor())); + gc.translate((- controller->horzValue()) / m_subject->zoomFactor(), + (- controller->vertValue()) / m_subject->zoomFactor()); + + KisPoint topLeft = point - hotSpot; + + if (m_subject->currentPaintop().id() == "pen") { + // Pen paints on whole pixels only. + topLeft = topLeft.roundTQPoint(); + } + + gc.translate(topLeft.x(), topLeft.y()); + + KisBoundaryPainter::paint(brush->boundary(), gc); + m_paintedOutline = true; + } +} + + +#include "kis_tool_freehand.moc" + diff --git a/chalk/ui/kis_tool_manager.cc b/chalk/ui/kis_tool_manager.cpp similarity index 100% rename from chalk/ui/kis_tool_manager.cc rename to chalk/ui/kis_tool_manager.cpp diff --git a/chalk/ui/kis_tool_non_paint.cc b/chalk/ui/kis_tool_non_paint.cpp similarity index 100% rename from chalk/ui/kis_tool_non_paint.cc rename to chalk/ui/kis_tool_non_paint.cpp diff --git a/chalk/ui/kis_tool_paint.cc b/chalk/ui/kis_tool_paint.cpp similarity index 100% rename from chalk/ui/kis_tool_paint.cc rename to chalk/ui/kis_tool_paint.cpp diff --git a/chalk/ui/kis_tool_registry.cc b/chalk/ui/kis_tool_registry.cpp similarity index 100% rename from chalk/ui/kis_tool_registry.cc rename to chalk/ui/kis_tool_registry.cpp diff --git a/chalk/ui/kis_tool_shape.cc b/chalk/ui/kis_tool_shape.cpp similarity index 100% rename from chalk/ui/kis_tool_shape.cc rename to chalk/ui/kis_tool_shape.cpp diff --git a/chalk/ui/kis_view.cc b/chalk/ui/kis_view.cpp similarity index 100% rename from chalk/ui/kis_view.cc rename to chalk/ui/kis_view.cpp diff --git a/chalk/ui/kis_view_iface.cc b/chalk/ui/kis_view_iface.cpp similarity index 100% rename from chalk/ui/kis_view_iface.cc rename to chalk/ui/kis_view_iface.cpp diff --git a/doc/chalk/developers-plugins.docbook b/doc/chalk/developers-plugins.docbook index 029af8d7e..bf5fab62f 100644 --- a/doc/chalk/developers-plugins.docbook +++ b/doc/chalk/developers-plugins.docbook @@ -195,7 +195,7 @@ kde_services_DATA = chalkLIBRARYNAME.desktop INCLUDES = $(all_includes) -chalkLIBRARYNAME_la_SOURCES = sourcefile1.cc sourcefile2.cc +chalkLIBRARYNAME_la_SOURCES = sourcefile1.cpp sourcefile2.cpp kde_module_LTLIBRARIES = chalkLIBRARYNAME.la noinst_HEADERS = header1.h header2.h @@ -878,14 +878,14 @@ A good example of a tool is the star tool: -kis_tool_star.cc Makefile.am tool_star_cursor.png wdg_tool_star.ui +kis_tool_star.cpp Makefile.am tool_star_cursor.png wdg_tool_star.ui kis_tool_star.h Makefile.in tool_star.h -chalktoolstar.desktop tool_star.cc tool_star.png +chalktoolstar.desktop tool_star.cpp tool_star.png As you see, you need two images: one for the cursor and one for the toolbox. -tool_star.cc is just the plugin loader, similar to what +tool_star.cpp is just the plugin loader, similar to what we have seen above. The real meat is in the implementation: diff --git a/example/Makefile.am b/example/Makefile.am index 96799ae0a..0bcdf91bb 100644 --- a/example/Makefile.am +++ b/example/Makefile.am @@ -3,8 +3,8 @@ INCLUDES = $(KOFFICE_INCLUDES) $(all_includes) ## The part kde_module_LTLIBRARIES = libexamplepart.la -libexamplepart_la_SOURCES = example_part.cc \ - example_view.cc example_factory.cc +libexamplepart_la_SOURCES = example_part.cpp \ + example_view.cpp example_factory.cpp libexamplepart_la_LDFLAGS = $(KDE_PLUGIN) libexamplepart_la_LIBADD = $(LIB_KOFFICEUI) @@ -12,7 +12,7 @@ libexamplepart_la_LIBADD = $(LIB_KOFFICEUI) tdeinit_LTLIBRARIES = example.la lib_LTLIBRARIES = bin_PROGRAMS = -example_la_SOURCES = main.cc +example_la_SOURCES = main.cpp example_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) example_la_LIBADD = $(LIB_KOFFICEUI) @@ -32,7 +32,7 @@ rc_DATA = example.rc example_readonly.rc rcdir = $(kde_datadir)/example messages: rc.cpp - $(XGETTEXT) rc.cpp *.cc example_aboutdata.h -o $(podir)/example.pot + $(XGETTEXT) rc.cpp *.cpp example_aboutdata.h -o $(podir)/example.pot kde_services_DATA = examplepart.desktop include $(top_srcdir)/admin/Doxyfile.am diff --git a/example/example_factory.cc b/example/example_factory.cpp similarity index 100% rename from example/example_factory.cc rename to example/example_factory.cpp diff --git a/example/example_part.cc b/example/example_part.cpp similarity index 100% rename from example/example_part.cc rename to example/example_part.cpp diff --git a/example/example_view.cc b/example/example_view.cpp similarity index 100% rename from example/example_view.cc rename to example/example_view.cpp diff --git a/example/main.cc b/example/main.cpp similarity index 100% rename from example/main.cc rename to example/main.cpp diff --git a/filters/Makefile.am b/filters/Makefile.am index e8473741e..83ea4f863 100644 --- a/filters/Makefile.am +++ b/filters/Makefile.am @@ -43,6 +43,6 @@ SUBDIRS = generic_wrapper libdialogfilter liboofilter $(KSPREADDIR) $(KCHARTDIR) messages: $(EXTRACTRC) `find . -name \*.ui` > rc.cpp - $(XGETTEXT) `find . -name \*.cpp -o -name \*.cc` -o $(podir)/kofficefilters.pot + $(XGETTEXT) `find . -name \*.cpp` -o $(podir)/kofficefilters.pot include $(top_srcdir)/admin/Doxyfile.am diff --git a/filters/chalk/gmagick/Makefile.am b/filters/chalk/gmagick/Makefile.am index 410c95ea2..431704334 100644 --- a/filters/chalk/gmagick/Makefile.am +++ b/filters/chalk/gmagick/Makefile.am @@ -39,8 +39,8 @@ servicedir = $(kde_servicesdir) kdelnk_DATA = chalk_magick.desktop kdelnkdir = $(kde_appsdir)/.hidden -libchalkgmagickimport_la_SOURCES = magickimport.cpp kis_image_magick_converter.cc -libchalkgmagickexport_la_SOURCES = magickexport.cpp kis_image_magick_converter.cc +libchalkgmagickimport_la_SOURCES = magickimport.cpp kis_image_magick_converter.cpp +libchalkgmagickexport_la_SOURCES = magickexport.cpp kis_image_magick_converter.cpp METASOURCES = AUTO diff --git a/filters/chalk/gmagick/kis_image_magick_converter.cc b/filters/chalk/gmagick/kis_image_magick_converter.cpp similarity index 100% rename from filters/chalk/gmagick/kis_image_magick_converter.cc rename to filters/chalk/gmagick/kis_image_magick_converter.cpp diff --git a/filters/chalk/jpeg/Makefile.am b/filters/chalk/jpeg/Makefile.am index 9e84cfa15..d12b57ed5 100644 --- a/filters/chalk/jpeg/Makefile.am +++ b/filters/chalk/jpeg/Makefile.am @@ -3,7 +3,7 @@ kde_module_LTLIBRARIES = libchalkjpegimport.la libchalkjpegexport.la libchalkconverter_la_LDFLAGS = $(all_libraries) -ltdecore -ltdeui $(LIB_TQT) -lkjs -ltdefx -ltdeio -ltdeparts \ -llcms -libchalkconverter_la_SOURCES = kis_jpeg_converter.cc iccjpeg.c +libchalkconverter_la_SOURCES = kis_jpeg_converter.cpp iccjpeg.c libchalkconverter_la_LIBADD = $(KOFFICE_LIBS) $(top_builddir)/filters/chalk/libkisexif/libkisexif.la \ ../../../chalk/core/libchalkimage.la \ ../../../chalk/ui/libchalkui.la \ @@ -49,8 +49,8 @@ servicedir = $(kde_servicesdir) kdelnk_DATA = chalk_jpeg.desktop kdelnkdir = $(kde_appsdir)/.hidden -libchalkjpegimport_la_SOURCES = kis_jpeg_import.cc -libchalkjpegexport_la_SOURCES = kis_wdg_options_jpeg.ui kis_jpeg_export.cc +libchalkjpegimport_la_SOURCES = kis_jpeg_import.cpp +libchalkjpegexport_la_SOURCES = kis_wdg_options_jpeg.ui kis_jpeg_export.cpp METASOURCES = AUTO diff --git a/filters/chalk/jpeg/kis_jpeg_converter.cc b/filters/chalk/jpeg/kis_jpeg_converter.cpp similarity index 100% rename from filters/chalk/jpeg/kis_jpeg_converter.cc rename to filters/chalk/jpeg/kis_jpeg_converter.cpp diff --git a/filters/chalk/jpeg/kis_jpeg_export.cc b/filters/chalk/jpeg/kis_jpeg_export.cpp similarity index 100% rename from filters/chalk/jpeg/kis_jpeg_export.cc rename to filters/chalk/jpeg/kis_jpeg_export.cpp diff --git a/filters/chalk/jpeg/kis_jpeg_import.cc b/filters/chalk/jpeg/kis_jpeg_import.cpp similarity index 100% rename from filters/chalk/jpeg/kis_jpeg_import.cc rename to filters/chalk/jpeg/kis_jpeg_import.cpp diff --git a/filters/chalk/magick/Makefile.am b/filters/chalk/magick/Makefile.am index e6bfcf29a..b41d09585 100644 --- a/filters/chalk/magick/Makefile.am +++ b/filters/chalk/magick/Makefile.am @@ -39,8 +39,8 @@ servicedir = $(kde_servicesdir) kdelnk_DATA = chalk_magick.desktop kdelnkdir = $(kde_appsdir)/Office -libchalkmagickimport_la_SOURCES = magickimport.cpp kis_image_magick_converter.cc -libchalkmagickexport_la_SOURCES = magickexport.cpp kis_image_magick_converter.cc +libchalkmagickimport_la_SOURCES = magickimport.cpp kis_image_magick_converter.cpp +libchalkmagickexport_la_SOURCES = magickexport.cpp kis_image_magick_converter.cpp METASOURCES = AUTO diff --git a/filters/chalk/magick/kis_image_magick_converter.cc b/filters/chalk/magick/kis_image_magick_converter.cpp similarity index 100% rename from filters/chalk/magick/kis_image_magick_converter.cc rename to filters/chalk/magick/kis_image_magick_converter.cpp diff --git a/filters/chalk/png/Makefile.am b/filters/chalk/png/Makefile.am index d314e65a3..93822d1fc 100644 --- a/filters/chalk/png/Makefile.am +++ b/filters/chalk/png/Makefile.am @@ -39,8 +39,8 @@ servicedir = $(kde_servicesdir) kdelnk_DATA = chalk_png.desktop kdelnkdir = $(kde_appsdir)/.hidden -libchalkpngimport_la_SOURCES = kis_png_import.cc kis_png_converter.cc -libchalkpngexport_la_SOURCES = kis_wdg_options_png.ui kis_png_export.cc kis_png_converter.cc +libchalkpngimport_la_SOURCES = kis_png_import.cpp kis_png_converter.cpp +libchalkpngexport_la_SOURCES = kis_wdg_options_png.ui kis_png_export.cpp kis_png_converter.cpp METASOURCES = AUTO diff --git a/filters/chalk/png/kis_png_converter.cc b/filters/chalk/png/kis_png_converter.cpp similarity index 100% rename from filters/chalk/png/kis_png_converter.cc rename to filters/chalk/png/kis_png_converter.cpp diff --git a/filters/chalk/png/kis_png_export.cc b/filters/chalk/png/kis_png_export.cpp similarity index 100% rename from filters/chalk/png/kis_png_export.cc rename to filters/chalk/png/kis_png_export.cpp diff --git a/filters/chalk/png/kis_png_import.cc b/filters/chalk/png/kis_png_import.cpp similarity index 100% rename from filters/chalk/png/kis_png_import.cc rename to filters/chalk/png/kis_png_import.cpp diff --git a/filters/chalk/tiff/Makefile.am b/filters/chalk/tiff/Makefile.am index b07e3eee7..f53432aba 100644 --- a/filters/chalk/tiff/Makefile.am +++ b/filters/chalk/tiff/Makefile.am @@ -46,8 +46,8 @@ METASOURCES = AUTO KDE_CXXFLAGS = $(USE_EXCEPTIONS) -libchalktiffimport_la_SOURCES = kis_tiff_import.cc -libchalktiffexport_la_SOURCES = kis_tiff_export.cc kis_wdg_options_tiff.ui \ +libchalktiffimport_la_SOURCES = kis_tiff_import.cpp +libchalktiffexport_la_SOURCES = kis_tiff_export.cpp kis_wdg_options_tiff.ui \ kis_dlg_options_tiff.cpp service_DATA = chalk_tiff_export.desktop chalk_tiff_import.desktop kdelnk_DATA = chalk_tiff.desktop @@ -60,5 +60,5 @@ libchalktiffconverter_la_LIBADD = $(KOFFICE_LIBS) \ ../../../chalk/ui/libchalkui.la \ ../../../chalk/chalkcolor/libchalkcolor.la noinst_LTLIBRARIES = libchalktiffconverter.la -libchalktiffconverter_la_SOURCES = kis_tiff_converter.cc kis_tiff_stream.cc \ - kis_tiff_writer_visitor.cpp kis_tiff_reader.cc kis_tiff_ycbcr_reader.cc +libchalktiffconverter_la_SOURCES = kis_tiff_converter.cpp kis_tiff_stream.cpp \ + kis_tiff_writer_visitor.cpp kis_tiff_reader.cpp kis_tiff_ycbcr_reader.cpp diff --git a/filters/chalk/tiff/kis_tiff_converter.cc b/filters/chalk/tiff/kis_tiff_converter.cpp similarity index 100% rename from filters/chalk/tiff/kis_tiff_converter.cc rename to filters/chalk/tiff/kis_tiff_converter.cpp diff --git a/filters/chalk/tiff/kis_tiff_export.cc b/filters/chalk/tiff/kis_tiff_export.cpp similarity index 100% rename from filters/chalk/tiff/kis_tiff_export.cc rename to filters/chalk/tiff/kis_tiff_export.cpp diff --git a/filters/chalk/tiff/kis_tiff_import.cc b/filters/chalk/tiff/kis_tiff_import.cpp similarity index 100% rename from filters/chalk/tiff/kis_tiff_import.cc rename to filters/chalk/tiff/kis_tiff_import.cpp diff --git a/filters/chalk/tiff/kis_tiff_reader.cc b/filters/chalk/tiff/kis_tiff_reader.cpp similarity index 100% rename from filters/chalk/tiff/kis_tiff_reader.cc rename to filters/chalk/tiff/kis_tiff_reader.cpp diff --git a/filters/chalk/tiff/kis_tiff_stream.cc b/filters/chalk/tiff/kis_tiff_stream.cpp similarity index 100% rename from filters/chalk/tiff/kis_tiff_stream.cc rename to filters/chalk/tiff/kis_tiff_stream.cpp diff --git a/filters/chalk/tiff/kis_tiff_ycbcr_reader.cc b/filters/chalk/tiff/kis_tiff_ycbcr_reader.cpp similarity index 100% rename from filters/chalk/tiff/kis_tiff_ycbcr_reader.cc rename to filters/chalk/tiff/kis_tiff_ycbcr_reader.cpp diff --git a/filters/chalk/xcf/xcf/xcf-load.cc b/filters/chalk/xcf/xcf/xcf-load.cpp similarity index 100% rename from filters/chalk/xcf/xcf/xcf-load.cc rename to filters/chalk/xcf/xcf/xcf-load.cpp diff --git a/filters/chalk/xcf/xcf/xcf-read.cc b/filters/chalk/xcf/xcf/xcf-read.cpp similarity index 100% rename from filters/chalk/xcf/xcf/xcf-read.cc rename to filters/chalk/xcf/xcf/xcf-read.cpp diff --git a/filters/chalk/xcf/xcf/xcf-save.cc b/filters/chalk/xcf/xcf/xcf-save.cpp similarity index 100% rename from filters/chalk/xcf/xcf/xcf-save.cc rename to filters/chalk/xcf/xcf/xcf-save.cpp diff --git a/filters/chalk/xcf/xcf/xcf-seek.cc b/filters/chalk/xcf/xcf/xcf-seek.cpp similarity index 100% rename from filters/chalk/xcf/xcf/xcf-seek.cc rename to filters/chalk/xcf/xcf/xcf-seek.cpp diff --git a/filters/chalk/xcf/xcf/xcf-write.cc b/filters/chalk/xcf/xcf/xcf-write.cpp similarity index 100% rename from filters/chalk/xcf/xcf/xcf-write.cc rename to filters/chalk/xcf/xcf/xcf-write.cpp diff --git a/filters/generic_wrapper/Makefile.am b/filters/generic_wrapper/Makefile.am index 8d1cb7a05..66d95473f 100644 --- a/filters/generic_wrapper/Makefile.am +++ b/filters/generic_wrapper/Makefile.am @@ -6,7 +6,7 @@ INCLUDES= -I$(srcdir) $(KOFFICE_INCLUDES) $(all_includes) kde_module_LTLIBRARIES = libgenerickofilter.la -libgenerickofilter_la_SOURCES = generic_filter.cc +libgenerickofilter_la_SOURCES = generic_filter.cpp libgenerickofilter_la_LDFLAGS = $(all_libraries) -module -avoid-version -no-undefined libgenerickofilter_la_LIBADD = $(KOFFICE_LIBS) $(LIB_TDEIO) diff --git a/filters/generic_wrapper/generic_filter.cc b/filters/generic_wrapper/generic_filter.cpp similarity index 100% rename from filters/generic_wrapper/generic_filter.cc rename to filters/generic_wrapper/generic_filter.cpp diff --git a/filters/karbon/ai/Makefile.am b/filters/karbon/ai/Makefile.am index 761feaffd..2bbc124df 100644 --- a/filters/karbon/ai/Makefile.am +++ b/filters/karbon/ai/Makefile.am @@ -30,14 +30,14 @@ noinst_HEADERS = \ karbonaiparserbase.h libkarbonaiimport_la_SOURCES = \ - aicolor.cc \ - aielement.cc \ - aiimport.cc \ - ailexer.cc \ - aiparserbase.cc \ - ai88handler.cc \ - ai3handler.cc \ - karbonaiparserbase.cc + aicolor.cpp \ + aielement.cpp \ + aiimport.cpp \ + ailexer.cpp \ + aiparserbase.cpp \ + ai88handler.cpp \ + ai3handler.cpp \ + karbonaiparserbase.cpp libkarbonaiimport_la_METASOURCES = \ AUTO diff --git a/filters/karbon/ai/ai3handler.cc b/filters/karbon/ai/ai3handler.cpp similarity index 100% rename from filters/karbon/ai/ai3handler.cc rename to filters/karbon/ai/ai3handler.cpp diff --git a/filters/karbon/ai/ai88handler.cc b/filters/karbon/ai/ai88handler.cpp similarity index 100% rename from filters/karbon/ai/ai88handler.cc rename to filters/karbon/ai/ai88handler.cpp diff --git a/filters/karbon/ai/aicolor.cc b/filters/karbon/ai/aicolor.cpp similarity index 100% rename from filters/karbon/ai/aicolor.cc rename to filters/karbon/ai/aicolor.cpp diff --git a/filters/karbon/ai/aielement.cc b/filters/karbon/ai/aielement.cpp similarity index 100% rename from filters/karbon/ai/aielement.cc rename to filters/karbon/ai/aielement.cpp diff --git a/filters/karbon/ai/aiimport.cc b/filters/karbon/ai/aiimport.cpp similarity index 100% rename from filters/karbon/ai/aiimport.cc rename to filters/karbon/ai/aiimport.cpp diff --git a/filters/karbon/ai/ailexer.cc b/filters/karbon/ai/ailexer.cpp similarity index 100% rename from filters/karbon/ai/ailexer.cc rename to filters/karbon/ai/ailexer.cpp diff --git a/filters/karbon/ai/aiparserbase.cc b/filters/karbon/ai/aiparserbase.cpp similarity index 100% rename from filters/karbon/ai/aiparserbase.cc rename to filters/karbon/ai/aiparserbase.cpp diff --git a/filters/karbon/ai/karbonaiparserbase.cc b/filters/karbon/ai/karbonaiparserbase.cpp similarity index 100% rename from filters/karbon/ai/karbonaiparserbase.cc rename to filters/karbon/ai/karbonaiparserbase.cpp diff --git a/filters/karbon/applixgraphics/Makefile.am b/filters/karbon/applixgraphics/Makefile.am index b3c03f384..83fefb227 100644 --- a/filters/karbon/applixgraphics/Makefile.am +++ b/filters/karbon/applixgraphics/Makefile.am @@ -7,7 +7,7 @@ libapplixgraphicimport_la_LDFLAGS = -module -avoid-version -no-undefined $(all_l kde_module_LTLIBRARIES = libapplixgraphicimport.la -libapplixgraphicimport_la_SOURCES = applixgraphicimport.cc +libapplixgraphicimport_la_SOURCES = applixgraphicimport.cpp libapplixgraphicimport_la_LIBADD = $(KOFFICE_LIBS) noinst_HEADERS = applixgraphicimport.h @@ -17,4 +17,4 @@ service_DATA = kontour_applixgraphic_import.desktop servicedir = $(kde_servicesdir) messages: rc.cpp - $(XGETTEXT) *.cc *.cpp -o $(podir)/kontourapplixgraphicsfilter.pot + $(XGETTEXT) *.cpp -o $(podir)/kontourapplixgraphicsfilter.pot diff --git a/filters/karbon/applixgraphics/applixgraphicimport.cc b/filters/karbon/applixgraphics/applixgraphicimport.cpp similarity index 100% rename from filters/karbon/applixgraphics/applixgraphicimport.cc rename to filters/karbon/applixgraphics/applixgraphicimport.cpp diff --git a/filters/karbon/eps/Makefile.am b/filters/karbon/eps/Makefile.am index 035a188e0..ccf3503eb 100644 --- a/filters/karbon/eps/Makefile.am +++ b/filters/karbon/eps/Makefile.am @@ -3,13 +3,13 @@ kde_module_LTLIBRARIES = \ libkarbonepsimport.la libkarbonepsexport_la_SOURCES = \ - epsexport.cc \ - epsexportdlg.cc + epsexport.cpp \ + epsexportdlg.cpp libkarbonepsexport_la_LDFLAGS = $(KDE_PLUGIN) $(all_libraries) -ltdecore -ltdeui $(LIB_TQT) -lkjs -ltdefx -ltdeio -ltdeparts libkarbonepsexport_la_LIBADD = $(KOFFICE_LIBS) ../../../karbon/libkarboncommon.la -libkarbonepsimport_la_SOURCES = epsimport.cc pscommentlexer.cc +libkarbonepsimport_la_SOURCES = epsimport.cpp pscommentlexer.cpp libkarbonepsimport_la_LDFLAGS = $(KDE_PLUGIN) $(all_libraries) -ltdecore -ltdeui $(LIB_TQT) -lkjs -ltdefx -ltdeio -ltdeparts libkarbonepsimport_la_LIBADD = $(KOFFICE_LIBS) diff --git a/filters/karbon/eps/epsexport.cc b/filters/karbon/eps/epsexport.cpp similarity index 100% rename from filters/karbon/eps/epsexport.cc rename to filters/karbon/eps/epsexport.cpp diff --git a/filters/karbon/eps/epsexportdlg.cc b/filters/karbon/eps/epsexportdlg.cpp similarity index 100% rename from filters/karbon/eps/epsexportdlg.cc rename to filters/karbon/eps/epsexportdlg.cpp diff --git a/filters/karbon/eps/epsimport.cc b/filters/karbon/eps/epsimport.cpp similarity index 100% rename from filters/karbon/eps/epsimport.cc rename to filters/karbon/eps/epsimport.cpp diff --git a/filters/karbon/eps/pscommentlexer.cc b/filters/karbon/eps/pscommentlexer.cpp similarity index 100% rename from filters/karbon/eps/pscommentlexer.cc rename to filters/karbon/eps/pscommentlexer.cpp diff --git a/filters/karbon/kontour/Makefile.am b/filters/karbon/kontour/Makefile.am index be0b835ff..d955dbef0 100644 --- a/filters/karbon/kontour/Makefile.am +++ b/filters/karbon/kontour/Makefile.am @@ -5,7 +5,7 @@ INCLUDES= -I$(srcdir) $(KOFFICE_INCLUDES) $(KOPAINTER_INCLUDES) -I$(top_srcdir)/ ####### Files # Obviously you have to change "foo" (and maybe "import") to # reflect the name of your filter. If you have more files -# than just fooimport.cc please add them to the _SOURCES line. +# than just fooimport.cpp please add them to the _SOURCES line. kde_module_LTLIBRARIES = libkarbonkontourimport.la diff --git a/filters/karbon/msod/Makefile.am b/filters/karbon/msod/Makefile.am index f7191cd11..a555234a4 100644 --- a/filters/karbon/msod/Makefile.am +++ b/filters/karbon/msod/Makefile.am @@ -8,7 +8,7 @@ libkarbonmsodimport_la_LIBADD = $(KOFFICE_LIBS) $(LIBZ) kde_module_LTLIBRARIES = libkarbonmsodimport.la -libkarbonmsodimport_la_SOURCES = msodimport.cc msod.cc +libkarbonmsodimport_la_SOURCES = msodimport.cpp msod.cpp noinst_HEADERS = msodimport.h msod.h diff --git a/filters/karbon/msod/msod.cc b/filters/karbon/msod/msod.cpp similarity index 100% rename from filters/karbon/msod/msod.cc rename to filters/karbon/msod/msod.cpp diff --git a/filters/karbon/msod/msodimport.cc b/filters/karbon/msod/msodimport.cpp similarity index 100% rename from filters/karbon/msod/msodimport.cc rename to filters/karbon/msod/msodimport.cpp diff --git a/filters/karbon/oodraw/Makefile.am b/filters/karbon/oodraw/Makefile.am index 4cca1e325..3ace9839b 100644 --- a/filters/karbon/oodraw/Makefile.am +++ b/filters/karbon/oodraw/Makefile.am @@ -11,7 +11,7 @@ INCLUDES= -I$(srcdir)/../../liboofilter \ kde_module_LTLIBRARIES = liboodrawimport.la -liboodrawimport_la_SOURCES = oodrawimport.cc +liboodrawimport_la_SOURCES = oodrawimport.cpp liboodrawimport_la_LDFLAGS = $(all_libraries) -module -avoid-version -no-undefined liboodrawimport_la_LIBADD = ../../liboofilter/liboofilter.la \ ../../../karbon/libkarboncommon.la \ diff --git a/filters/karbon/oodraw/oodrawimport.cc b/filters/karbon/oodraw/oodrawimport.cpp similarity index 100% rename from filters/karbon/oodraw/oodrawimport.cc rename to filters/karbon/oodraw/oodrawimport.cpp diff --git a/filters/karbon/png/Makefile.am b/filters/karbon/png/Makefile.am index 86d7e4114..2a12d23b6 100644 --- a/filters/karbon/png/Makefile.am +++ b/filters/karbon/png/Makefile.am @@ -20,7 +20,7 @@ noinst_HEADERS = \ pngexport.h libkarbonpngexport_la_SOURCES = \ - pngexport.cc + pngexport.cpp libkarbonpngexport_la_METASOURCES = \ AUTO diff --git a/filters/karbon/png/pngexport.cc b/filters/karbon/png/pngexport.cpp similarity index 100% rename from filters/karbon/png/pngexport.cc rename to filters/karbon/png/pngexport.cpp diff --git a/filters/karbon/svg/Makefile.am b/filters/karbon/svg/Makefile.am index b8e08060f..289f689a7 100644 --- a/filters/karbon/svg/Makefile.am +++ b/filters/karbon/svg/Makefile.am @@ -25,10 +25,10 @@ noinst_HEADERS = \ svgexport.h libkarbonsvgexport_la_SOURCES = \ - svgexport.cc + svgexport.cpp METASOURCES = AUTO libkarbonsvgimport_la_SOURCES = \ - svgimport.cc + svgimport.cpp diff --git a/filters/karbon/svg/svgexport.cc b/filters/karbon/svg/svgexport.cpp similarity index 100% rename from filters/karbon/svg/svgexport.cc rename to filters/karbon/svg/svgexport.cpp diff --git a/filters/karbon/svg/svgimport.cc b/filters/karbon/svg/svgimport.cpp similarity index 100% rename from filters/karbon/svg/svgimport.cc rename to filters/karbon/svg/svgimport.cpp diff --git a/filters/karbon/wmf/Makefile.am b/filters/karbon/wmf/Makefile.am index 54bae415f..976888ac1 100644 --- a/filters/karbon/wmf/Makefile.am +++ b/filters/karbon/wmf/Makefile.am @@ -13,11 +13,11 @@ kde_module_LTLIBRARIES = libwmfimport.la libwmfexport.la libwmfimport_la_LDFLAGS = -module $(KDE_PLUGIN) $(all_libraries) -ltdecore -ltdeui $(LIB_TQT) -lkjs -ltdefx -ltdeio -ltdeparts libwmfimport_la_LIBADD = $(KOFFICE_LIBS) $(LIB_KOWMF) ../../../karbon/libkarboncommon.la -libwmfimport_la_SOURCES = wmfimport.cc wmfimportparser.cc +libwmfimport_la_SOURCES = wmfimport.cpp wmfimportparser.cpp libwmfexport_la_LDFLAGS = -module $(KDE_PLUGIN) $(all_libraries) -ltdecore -ltdeui $(LIB_TQT) -lkjs -ltdefx -ltdeio -ltdeparts libwmfexport_la_LIBADD = $(KOFFICE_LIBS) $(LIB_KOWMF) ../../../karbon/libkarboncommon.la -libwmfexport_la_SOURCES = wmfexport.cc +libwmfexport_la_SOURCES = wmfexport.cpp noinst_HEADERS = wmfimport.h wmfimportparser.h wmfexport.h diff --git a/filters/karbon/wmf/wmfexport.cc b/filters/karbon/wmf/wmfexport.cpp similarity index 100% rename from filters/karbon/wmf/wmfexport.cc rename to filters/karbon/wmf/wmfexport.cpp diff --git a/filters/karbon/wmf/wmfimport.cc b/filters/karbon/wmf/wmfimport.cpp similarity index 100% rename from filters/karbon/wmf/wmfimport.cc rename to filters/karbon/wmf/wmfimport.cpp diff --git a/filters/karbon/wmf/wmfimportparser.cc b/filters/karbon/wmf/wmfimportparser.cpp similarity index 100% rename from filters/karbon/wmf/wmfimportparser.cc rename to filters/karbon/wmf/wmfimportparser.cpp diff --git a/filters/karbon/xaml/Makefile.am b/filters/karbon/xaml/Makefile.am index f7036adac..9bf1e0686 100644 --- a/filters/karbon/xaml/Makefile.am +++ b/filters/karbon/xaml/Makefile.am @@ -26,10 +26,10 @@ noinst_HEADERS = \ xamlimport.h libkarbonxamlexport_la_SOURCES = \ - xamlexport.cc + xamlexport.cpp libkarbonxamlimport_la_SOURCES = \ - xamlimport.cc + xamlimport.cpp METASOURCES = AUTO diff --git a/filters/karbon/xaml/xamlexport.cc b/filters/karbon/xaml/xamlexport.cpp similarity index 100% rename from filters/karbon/xaml/xamlexport.cc rename to filters/karbon/xaml/xamlexport.cpp diff --git a/filters/karbon/xaml/xamlimport.cc b/filters/karbon/xaml/xamlimport.cpp similarity index 100% rename from filters/karbon/xaml/xamlimport.cc rename to filters/karbon/xaml/xamlimport.cpp diff --git a/filters/karbon/xcf/Makefile.am b/filters/karbon/xcf/Makefile.am index f3a1b3ac2..bc16ca76d 100644 --- a/filters/karbon/xcf/Makefile.am +++ b/filters/karbon/xcf/Makefile.am @@ -20,7 +20,7 @@ noinst_HEADERS = \ xcfexport.h libkarbonxcfexport_la_SOURCES = \ - xcfexport.cc + xcfexport.cpp libkarbonxcfexport_la_METASOURCES = \ AUTO diff --git a/filters/karbon/xcf/xcfexport.cc b/filters/karbon/xcf/xcfexport.cpp similarity index 100% rename from filters/karbon/xcf/xcfexport.cc rename to filters/karbon/xcf/xcfexport.cpp diff --git a/filters/karbon/xfig/xfigimport.cc b/filters/karbon/xfig/xfigimport.cpp similarity index 100% rename from filters/karbon/xfig/xfigimport.cc rename to filters/karbon/xfig/xfigimport.cpp diff --git a/filters/karbon/xfig/xfigimport_factory.cc b/filters/karbon/xfig/xfigimport_factory.cpp similarity index 100% rename from filters/karbon/xfig/xfigimport_factory.cc rename to filters/karbon/xfig/xfigimport_factory.cpp diff --git a/filters/kchart/svg/Makefile.am b/filters/kchart/svg/Makefile.am index 6c440ed1b..864653e33 100644 --- a/filters/kchart/svg/Makefile.am +++ b/filters/kchart/svg/Makefile.am @@ -9,7 +9,7 @@ INCLUDES= -I$(srcdir) $(KOFFICE_INCLUDES) \ ####### Files kde_module_LTLIBRARIES = libkchartsvgexport.la -libkchartsvgexport_la_SOURCES = svgexport.cc +libkchartsvgexport_la_SOURCES = svgexport.cpp libkchartsvgexport_la_LDFLAGS = -module $(KDE_PLUGIN) -no-undefined $(all_libraries) -ltdecore -ltdeui $(LIB_TQT) -lkjs -ltdefx -ltdeio -ltdeparts libkchartsvgexport_la_LIBADD = ../../../kchart/libkchartcommon.la $(KOFFICE_LIBS) noinst_HEADERS = \ diff --git a/filters/kchart/svg/svgexport.cc b/filters/kchart/svg/svgexport.cpp similarity index 100% rename from filters/kchart/svg/svgexport.cc rename to filters/kchart/svg/svgexport.cpp diff --git a/filters/kformula/latex/Makefile.am b/filters/kformula/latex/Makefile.am index 95bee7d58..25bf902f8 100644 --- a/filters/kformula/latex/Makefile.am +++ b/filters/kformula/latex/Makefile.am @@ -8,13 +8,13 @@ libkfolatexexport_la_LIBADD = $(KOFFICE_LIBS) $(LIB_KFORMULA) kde_module_LTLIBRARIES = libkfolatexexport.la -libkfolatexexport_la_SOURCES = latexexport.cc +libkfolatexexport_la_SOURCES = latexexport.cpp noinst_HEADERS = latexexport.h ######## Debug #check_PROGRAMS = texlauncher -#texlauncher_SOURCES = texlauncher.cc +#texlauncher_SOURCES = texlauncher.cpp #texlauncher_LDADD = liblatexexport.la #texlauncher_LDFLAGS = $(all_libraries) $(KDE_RPATH) $(LIB_TQT) -lDCOP $(LIB_TDECORE) $(LIB_TDEUI) -ltdefx $(LIB_TDEIO) -ltdetexteditor diff --git a/filters/kformula/latex/latexexport.cc b/filters/kformula/latex/latexexport.cpp similarity index 100% rename from filters/kformula/latex/latexexport.cc rename to filters/kformula/latex/latexexport.cpp diff --git a/filters/kformula/mathml/Makefile.am b/filters/kformula/mathml/Makefile.am index cdd07955a..0d2a9c386 100644 --- a/filters/kformula/mathml/Makefile.am +++ b/filters/kformula/mathml/Makefile.am @@ -10,9 +10,9 @@ libkfomathmlimport_la_LIBADD = $(KOFFICE_LIBS) $(LIB_KFORMULA) kde_module_LTLIBRARIES = libkfomathmlexport.la libkfomathmlimport.la -libkfomathmlexport_la_SOURCES = mathmlexport.cc +libkfomathmlexport_la_SOURCES = mathmlexport.cpp -libkfomathmlimport_la_SOURCES = mathmlimport.cc +libkfomathmlimport_la_SOURCES = mathmlimport.cpp noinst_HEADERS = mathmlexport.h mathmlimport.h diff --git a/filters/kformula/mathml/mathmlexport.cc b/filters/kformula/mathml/mathmlexport.cpp similarity index 100% rename from filters/kformula/mathml/mathmlexport.cc rename to filters/kformula/mathml/mathmlexport.cpp diff --git a/filters/kformula/mathml/mathmlimport.cc b/filters/kformula/mathml/mathmlimport.cpp similarity index 100% rename from filters/kformula/mathml/mathmlimport.cc rename to filters/kformula/mathml/mathmlimport.cpp diff --git a/filters/kformula/png/Makefile.am b/filters/kformula/png/Makefile.am index 277f063d2..43b599bf2 100644 --- a/filters/kformula/png/Makefile.am +++ b/filters/kformula/png/Makefile.am @@ -8,13 +8,13 @@ libkfopngexport_la_LIBADD = $(KOFFICE_LIBS) $(LIB_KFORMULA) kde_module_LTLIBRARIES = libkfopngexport.la -libkfopngexport_la_SOURCES = pngexport.cc pngexportdia.cc +libkfopngexport_la_SOURCES = pngexport.cpp pngexportdia.cpp noinst_HEADERS = pngexport.h pngexportdia.h ######## Debug #check_PROGRAMS = texlauncher -#texlauncher_SOURCES = texlauncher.cc +#texlauncher_SOURCES = texlauncher.cpp #texlauncher_LDADD = liblatexexport.la #texlauncher_LDFLAGS = $(all_libraries) $(KDE_RPATH) $(LIB_TQT) -lDCOP $(LIB_TDECORE) $(LIB_TDEUI) -ltdefx $(LIB_TDEIO) -ltdetexteditor diff --git a/filters/kformula/png/pngexport.cc b/filters/kformula/png/pngexport.cpp similarity index 100% rename from filters/kformula/png/pngexport.cc rename to filters/kformula/png/pngexport.cpp diff --git a/filters/kformula/png/pngexportdia.cc b/filters/kformula/png/pngexportdia.cpp similarity index 100% rename from filters/kformula/png/pngexportdia.cc rename to filters/kformula/png/pngexportdia.cpp diff --git a/filters/kformula/svg/Makefile.am b/filters/kformula/svg/Makefile.am index 144cfbb2a..9ef58a21a 100644 --- a/filters/kformula/svg/Makefile.am +++ b/filters/kformula/svg/Makefile.am @@ -8,13 +8,13 @@ libkfosvgexport_la_LIBADD = $(KOFFICE_LIBS) $(LIB_KFORMULA) kde_module_LTLIBRARIES = libkfosvgexport.la -libkfosvgexport_la_SOURCES = svgexport.cc +libkfosvgexport_la_SOURCES = svgexport.cpp noinst_HEADERS = svgexport.h ######## Debug #check_PROGRAMS = texlauncher -#texlauncher_SOURCES = texlauncher.cc +#texlauncher_SOURCES = texlauncher.cpp #texlauncher_LDADD = liblatexexport.la #texlauncher_LDFLAGS = $(all_libraries) $(KDE_RPATH) $(LIB_TQT) -lDCOP $(LIB_TDECORE) $(LIB_TDEUI) -ltdefx $(LIB_TDEIO) -ltdetexteditor diff --git a/filters/kformula/svg/svgexport.cc b/filters/kformula/svg/svgexport.cpp similarity index 100% rename from filters/kformula/svg/svgexport.cc rename to filters/kformula/svg/svgexport.cpp diff --git a/filters/kpresenter/kword/Makefile.am b/filters/kpresenter/kword/Makefile.am index 0e579f5cb..829aa93c9 100644 --- a/filters/kpresenter/kword/Makefile.am +++ b/filters/kpresenter/kword/Makefile.am @@ -2,7 +2,7 @@ INCLUDES= -I$(srcdir) $(KOFFICE_INCLUDES) $(all_includes) kde_module_LTLIBRARIES = libkprkword.la -libkprkword_la_SOURCES = kprkword.cc +libkprkword_la_SOURCES = kprkword.cpp libkprkword_la_LDFLAGS = $(all_libraries) -module -avoid-version -no-undefined libkprkword_la_LIBADD = $(KOFFICE_LIBS) diff --git a/filters/kpresenter/kword/kprkword.cc b/filters/kpresenter/kword/kprkword.cpp similarity index 100% rename from filters/kpresenter/kword/kprkword.cc rename to filters/kpresenter/kword/kprkword.cpp diff --git a/filters/kpresenter/ooimpress/Makefile.am b/filters/kpresenter/ooimpress/Makefile.am index b69dc04cf..f17330405 100644 --- a/filters/kpresenter/ooimpress/Makefile.am +++ b/filters/kpresenter/ooimpress/Makefile.am @@ -6,11 +6,11 @@ INCLUDES= -I$(srcdir)/../../liboofilter $(KOFFICE_INCLUDES) $(all_includes) kde_module_LTLIBRARIES = libooimpressimport.la libooimpressexport.la -libooimpressimport_la_SOURCES = ooimpressimport.cc +libooimpressimport_la_SOURCES = ooimpressimport.cpp libooimpressimport_la_LDFLAGS = $(all_libraries) -module -avoid-version -no-undefined libooimpressimport_la_LIBADD = ../../liboofilter/liboofilter.la $(KOFFICE_LIBS) -libooimpressexport_la_SOURCES = ooimpressexport.cc stylefactory.cc +libooimpressexport_la_SOURCES = ooimpressexport.cpp stylefactory.cpp libooimpressexport_la_LDFLAGS = $(all_libraries) -module -avoid-version -no-undefined libooimpressexport_la_LIBADD = ../../liboofilter/liboofilter.la $(KOFFICE_LIBS) diff --git a/filters/kpresenter/ooimpress/ooimpressexport.cc b/filters/kpresenter/ooimpress/ooimpressexport.cpp similarity index 100% rename from filters/kpresenter/ooimpress/ooimpressexport.cc rename to filters/kpresenter/ooimpress/ooimpressexport.cpp diff --git a/filters/kpresenter/ooimpress/ooimpressimport.cc b/filters/kpresenter/ooimpress/ooimpressimport.cpp similarity index 100% rename from filters/kpresenter/ooimpress/ooimpressimport.cc rename to filters/kpresenter/ooimpress/ooimpressimport.cpp diff --git a/filters/kpresenter/ooimpress/stylefactory.cc b/filters/kpresenter/ooimpress/stylefactory.cpp similarity index 100% rename from filters/kpresenter/ooimpress/stylefactory.cc rename to filters/kpresenter/ooimpress/stylefactory.cpp diff --git a/filters/kpresenter/powerpoint/import/Makefile.am b/filters/kpresenter/powerpoint/import/Makefile.am index 91f27887b..0034dfbb5 100644 --- a/filters/kpresenter/powerpoint/import/Makefile.am +++ b/filters/kpresenter/powerpoint/import/Makefile.am @@ -2,7 +2,7 @@ INCLUDES = -I$(srcdir) -I$(srcdir)/../libppt $(KOFFICE_INCLUDES) $(all_includes) kde_module_LTLIBRARIES = libpowerpointimport.la -libpowerpointimport_la_SOURCES = powerpointimport.cc +libpowerpointimport_la_SOURCES = powerpointimport.cpp libpowerpointimport_la_LIBADD = $(KOFFICE_LIBS) ../libppt/libppt.la libpowerpointimport_la_LDFLAGS = -module $(KDE_PLUGIN) noinst_HEADERS = powerpointimport.h diff --git a/filters/kpresenter/powerpoint/import/powerpointimport.cc b/filters/kpresenter/powerpoint/import/powerpointimport.cpp similarity index 100% rename from filters/kpresenter/powerpoint/import/powerpointimport.cc rename to filters/kpresenter/powerpoint/import/powerpointimport.cpp diff --git a/filters/kpresenter/svg/Makefile.am b/filters/kpresenter/svg/Makefile.am index dcfa91f28..c1024e311 100644 --- a/filters/kpresenter/svg/Makefile.am +++ b/filters/kpresenter/svg/Makefile.am @@ -8,7 +8,7 @@ INCLUDES= -I$(srcdir) $(KOFFICE_INCLUDES) \ ####### Files kde_module_LTLIBRARIES = libkpresentersvgexport.la -libkpresentersvgexport_la_SOURCES = svgexport.cc +libkpresentersvgexport_la_SOURCES = svgexport.cpp libkpresentersvgexport_la_LDFLAGS = -module $(KDE_PLUGIN) -no-undefined $(all_libraries) -ltdecore -ltdeui $(LIB_TQT) -lkjs -ltdefx -ltdeio -ltdeparts libkpresentersvgexport_la_LIBADD = ../../../kpresenter/libkpresenterprivate.la $(KOFFICE_LIBS) noinst_HEADERS = \ diff --git a/filters/kpresenter/svg/svgexport.cc b/filters/kpresenter/svg/svgexport.cc deleted file mode 100644 index 5b6ed8928..000000000 --- a/filters/kpresenter/svg/svgexport.cc +++ /dev/null @@ -1,100 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2005 Laurent Montel - code based on svgexport.cc from Inge Wallin - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301 USA. -*/ - -#include -#include - -#include - -#include -#include -//#include -#include - -#include "KPrDocument.h" -#include "KPrView.h" -#include "KPrCanvas.h" - -#include "svgexport.h" - - -typedef KGenericFactory SvgExportFactory; -K_EXPORT_COMPONENT_FACTORY( libkpresentersvgexport, SvgExportFactory( "svgexport" ) ) - -SvgExport::SvgExport(KoFilter *, const char *, const TQStringList&) - : KoFilter() -{ -} - -SvgExport::~SvgExport() -{ -} - - -KoFilter::ConversionStatus -SvgExport::convert(const TQCString& from, const TQCString& to) -{ - KoDocument * document = m_chain->inputDocument(); - - if ( !document ) - return KoFilter::StupidError; - - if ( strcmp(document->className(), "KPrDocument") != 0) - { - kdWarning() << "document isn't a KPrDocument but a " - << document->className() << endl; - return KoFilter::NotImplemented; - } - - // Check for proper conversion. - if ( from != "application/x-kpresenter" || to != "image/svg+xml" ) - { - kdWarning() << "Invalid mimetypes " << to << " " << from << endl; - return KoFilter::NotImplemented; - } - KPrDocument * kpresenterdoc = const_cast(static_cast(document)); - - if ( kpresenterdoc->mimeType() != "application/x-kpresenter" ) - { - kdWarning() << "Invalid document mimetype " << kpresenterdoc->mimeType() << endl; - return KoFilter::NotImplemented; - } - KoPageLayout layoutPage= kpresenterdoc->pageLayout(); - int width = int( layoutPage.ptWidth ); - int height = int( layoutPage.ptHeight ); - - TQPicture picture; - TQPainter painter(&picture); - TQRect rect(TQPoint(0, 0), TQPoint(width, height)); - kpresenterdoc->paintContent(painter, rect, false); - painter.end(); - - if ( !picture.save( m_chain->outputFile(), "SVG" ) ) { - KMessageBox::error( 0, i18n( "Failed to write file." ), - i18n( "SVG Export Error" ) ); - } - - return KoFilter::OK; -} - - -#include "svgexport.moc" - - diff --git a/filters/kpresenter/svg/svgexport.cpp b/filters/kpresenter/svg/svgexport.cpp new file mode 100644 index 000000000..711864df4 --- /dev/null +++ b/filters/kpresenter/svg/svgexport.cpp @@ -0,0 +1,100 @@ +/* This file is part of the KDE project + Copyright (C) 2005 Laurent Montel + code based on svgexport.cpp from Inge Wallin + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301 USA. +*/ + +#include +#include + +#include + +#include +#include +//#include +#include + +#include "KPrDocument.h" +#include "KPrView.h" +#include "KPrCanvas.h" + +#include "svgexport.h" + + +typedef KGenericFactory SvgExportFactory; +K_EXPORT_COMPONENT_FACTORY( libkpresentersvgexport, SvgExportFactory( "svgexport" ) ) + +SvgExport::SvgExport(KoFilter *, const char *, const TQStringList&) + : KoFilter() +{ +} + +SvgExport::~SvgExport() +{ +} + + +KoFilter::ConversionStatus +SvgExport::convert(const TQCString& from, const TQCString& to) +{ + KoDocument * document = m_chain->inputDocument(); + + if ( !document ) + return KoFilter::StupidError; + + if ( strcmp(document->className(), "KPrDocument") != 0) + { + kdWarning() << "document isn't a KPrDocument but a " + << document->className() << endl; + return KoFilter::NotImplemented; + } + + // Check for proper conversion. + if ( from != "application/x-kpresenter" || to != "image/svg+xml" ) + { + kdWarning() << "Invalid mimetypes " << to << " " << from << endl; + return KoFilter::NotImplemented; + } + KPrDocument * kpresenterdoc = const_cast(static_cast(document)); + + if ( kpresenterdoc->mimeType() != "application/x-kpresenter" ) + { + kdWarning() << "Invalid document mimetype " << kpresenterdoc->mimeType() << endl; + return KoFilter::NotImplemented; + } + KoPageLayout layoutPage= kpresenterdoc->pageLayout(); + int width = int( layoutPage.ptWidth ); + int height = int( layoutPage.ptHeight ); + + TQPicture picture; + TQPainter painter(&picture); + TQRect rect(TQPoint(0, 0), TQPoint(width, height)); + kpresenterdoc->paintContent(painter, rect, false); + painter.end(); + + if ( !picture.save( m_chain->outputFile(), "SVG" ) ) { + KMessageBox::error( 0, i18n( "Failed to write file." ), + i18n( "SVG Export Error" ) ); + } + + return KoFilter::OK; +} + + +#include "svgexport.moc" + + diff --git a/filters/kpresenter/svg/svgexport.h b/filters/kpresenter/svg/svgexport.h index d46ba5faa..e08171ec5 100644 --- a/filters/kpresenter/svg/svgexport.h +++ b/filters/kpresenter/svg/svgexport.h @@ -1,6 +1,6 @@ /* This file is part of the KDE project Copyright (C) 2005 Laurent Montel - code based on svgexport.cc from Inge Wallin + code based on svgexport.cpp from Inge Wallin This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public diff --git a/filters/kspread/applixspread/Makefile.am b/filters/kspread/applixspread/Makefile.am index 5d2d42e4e..667c76494 100644 --- a/filters/kspread/applixspread/Makefile.am +++ b/filters/kspread/applixspread/Makefile.am @@ -6,7 +6,7 @@ INCLUDES= -I$(srcdir) $(KOFFICE_INCLUDES) $(all_includes) kde_module_LTLIBRARIES = libapplixspreadimport.la -libapplixspreadimport_la_SOURCES = applixspreadimport.cc +libapplixspreadimport_la_SOURCES = applixspreadimport.cpp libapplixspreadimport_la_LIBADD = $(KOFFICE_LIBS) libapplixspreadimport_la_LDFLAGS = -module $(KDE_PLUGIN) $(all_libraries) -ltdecore -ltdeui $(LIB_TQT) -lkjs -ltdefx -ltdeio -ltdeparts noinst_HEADERS = applixspreadimport.h diff --git a/filters/kspread/applixspread/applixspreadimport.cc b/filters/kspread/applixspread/applixspreadimport.cpp similarity index 100% rename from filters/kspread/applixspread/applixspreadimport.cc rename to filters/kspread/applixspread/applixspreadimport.cpp diff --git a/filters/kspread/applixspread/status.html b/filters/kspread/applixspread/status.html index c944ef5c0..859f8b155 100644 --- a/filters/kspread/applixspread/status.html +++ b/filters/kspread/applixspread/status.html @@ -236,7 +236,7 @@ If the value of r, g or b if less then 0 you must set it to 0 .

For examples inside koffice look a this files too
- koffice/kimageshop/core/kis_color.cc and kis_color.h
+ koffice/kimageshop/core/kis_color.cpp and kis_color.h


2.3. Colormap end:
diff --git a/filters/kspread/csv/DESIGN b/filters/kspread/csv/DESIGN index 9c6c4c909..5f9a3ed13 100644 --- a/filters/kspread/csv/DESIGN +++ b/filters/kspread/csv/DESIGN @@ -32,6 +32,6 @@ EOL : End Of Line. Ugly isn't it ? :) One can't be good in drawings AND in hacking :) -That's all. For the rest, see csvfilter.cc +That's all. For the rest, see csvfilter.cpp David Faure , 1999 diff --git a/filters/kspread/csv/Makefile.am b/filters/kspread/csv/Makefile.am index 32c8408a5..c46b0302a 100644 --- a/filters/kspread/csv/Makefile.am +++ b/filters/kspread/csv/Makefile.am @@ -7,11 +7,11 @@ INCLUDES= -I$(srcdir) -I$(top_srcdir)/kspread $(KOFFICE_INCLUDES) \ kde_module_LTLIBRARIES = libcsvimport.la libcsvexport.la -libcsvimport_la_SOURCES = csvimport.cc xmltree.cc csvdialog.cpp dialogui.ui +libcsvimport_la_SOURCES = csvimport.cpp xmltree.cpp csvdialog.cpp dialogui.ui libcsvimport_la_LDFLAGS = $(all_libraries) -module -avoid-version -no-undefined libcsvimport_la_LIBADD = $(KOFFICE_LIBS) ../../../kspread/libkspreadcommon.la -libcsvexport_la_SOURCES = csvexport.cc csvexportdialog.cpp exportdialogui.ui +libcsvexport_la_SOURCES = csvexport.cpp csvexportdialog.cpp exportdialogui.ui libcsvexport_la_LDFLAGS = $(all_libraries) -module -avoid-version -no-undefined libcsvexport_la_LIBADD = $(KOFFICE_LIBS) ../../../kspread/libkspreadcommon.la diff --git a/filters/kspread/csv/csvexport.cc b/filters/kspread/csv/csvexport.cpp similarity index 100% rename from filters/kspread/csv/csvexport.cc rename to filters/kspread/csv/csvexport.cpp diff --git a/filters/kspread/csv/csvimport.cc b/filters/kspread/csv/csvimport.cpp similarity index 100% rename from filters/kspread/csv/csvimport.cc rename to filters/kspread/csv/csvimport.cpp diff --git a/filters/kspread/csv/status.html b/filters/kspread/csv/status.html index c4379ade8..e31c27613 100644 --- a/filters/kspread/csv/status.html +++ b/filters/kspread/csv/status.html @@ -117,7 +117,7 @@ EOL : End Of Line. Ugly isn't it ? :) One can't be good in drawings AND in hacking :) -That's all. For the rest, see csvfilter.cc +That's all. For the rest, see csvfilter.cpp David Faure <faure@kde.org>, 1999 diff --git a/filters/kspread/csv/xmltree.cc b/filters/kspread/csv/xmltree.cpp similarity index 100% rename from filters/kspread/csv/xmltree.cc rename to filters/kspread/csv/xmltree.cpp diff --git a/filters/kspread/dbase/Makefile.am b/filters/kspread/dbase/Makefile.am index ea7713283..5802ff7ea 100644 --- a/filters/kspread/dbase/Makefile.am +++ b/filters/kspread/dbase/Makefile.am @@ -6,7 +6,7 @@ INCLUDES= -I$(srcdir) $(KOFFICE_INCLUDES) $(all_includes) kde_module_LTLIBRARIES = libdbaseimport.la -libdbaseimport_la_SOURCES = dbaseimport.cc dbase.cpp +libdbaseimport_la_SOURCES = dbaseimport.cpp dbase.cpp libdbaseimport_la_LIBADD = $(KOFFICE_LIBS) libdbaseimport_la_LDFLAGS = -module $(KDE_PLUGIN) $(all_libraries) -ltdecore -ltdeui $(LIB_TQT) -lkjs -ltdefx -ltdeio -ltdeparts noinst_HEADERS = dbaseimport.h dbase.h diff --git a/filters/kspread/dbase/dbaseimport.cc b/filters/kspread/dbase/dbaseimport.cpp similarity index 100% rename from filters/kspread/dbase/dbaseimport.cc rename to filters/kspread/dbase/dbaseimport.cpp diff --git a/filters/kspread/excel/Makefile.am b/filters/kspread/excel/Makefile.am index 73d5db56a..329f247c4 100644 --- a/filters/kspread/excel/Makefile.am +++ b/filters/kspread/excel/Makefile.am @@ -12,4 +12,4 @@ METASOURCES = AUTO servicedir = $(kde_servicesdir) messages: rc.cpp - $(XGETTEXT) *.cc *.cpp -o $(podir)/kspreadexcelfilter.pot + $(XGETTEXT) *.cpp *.cpp -o $(podir)/kspreadexcelfilter.pot diff --git a/filters/kspread/excel/excelexport.cc b/filters/kspread/excel/excelexport.cpp similarity index 100% rename from filters/kspread/excel/excelexport.cc rename to filters/kspread/excel/excelexport.cpp diff --git a/filters/kspread/excel/import/Makefile.am b/filters/kspread/excel/import/Makefile.am index 9f371d22d..1f966ef73 100644 --- a/filters/kspread/excel/import/Makefile.am +++ b/filters/kspread/excel/import/Makefile.am @@ -6,7 +6,7 @@ INCLUDES= -I$(srcdir) -I$(srcdir)/../sidewinder $(KOFFICE_INCLUDES) $(all_includ kde_module_LTLIBRARIES = libexcelimport.la -libexcelimport_la_SOURCES = excelimport.cc +libexcelimport_la_SOURCES = excelimport.cpp libexcelimport_la_LIBADD = $(KOFFICE_LIBS) ../sidewinder/libsidewinder.la libexcelimport_la_LDFLAGS = -module $(KDE_PLUGIN) $(all_libraries) -ltdecore -ltdeui $(LIB_TQT) -lkjs -ltdefx -ltdeio -ltdeparts noinst_HEADERS = excelimport.h diff --git a/filters/kspread/excel/import/excelimport.cc b/filters/kspread/excel/import/excelimport.cpp similarity index 100% rename from filters/kspread/excel/import/excelimport.cc rename to filters/kspread/excel/import/excelimport.cpp diff --git a/filters/kspread/gnumeric/Makefile.am b/filters/kspread/gnumeric/Makefile.am index 6bb9608ed..a16f0024e 100644 --- a/filters/kspread/gnumeric/Makefile.am +++ b/filters/kspread/gnumeric/Makefile.am @@ -6,11 +6,11 @@ INCLUDES= -I$(srcdir) -I$(top_srcdir)/kspread $(KOFFICE_INCLUDES) \ ####### Files kde_module_LTLIBRARIES = libgnumericexport.la libgnumericimport.la -libgnumericexport_la_SOURCES = gnumericexport.cc +libgnumericexport_la_SOURCES = gnumericexport.cpp libgnumericexport_la_LDFLAGS = $(all_libraries) -module -avoid-version -no-undefined libgnumericexport_la_LIBADD = $(KOFFICE_LIBS) ../../../kspread/libkspreadcommon.la -libgnumericimport_la_SOURCES = gnumericimport.cc +libgnumericimport_la_SOURCES = gnumericimport.cpp libgnumericimport_la_LDFLAGS = $(all_libraries) -module -avoid-version -no-undefined libgnumericimport_la_LIBADD = $(KOFFICE_LIBS) ../../../kspread/libkspreadcommon.la diff --git a/filters/kspread/gnumeric/gnumericexport.cc b/filters/kspread/gnumeric/gnumericexport.cpp similarity index 100% rename from filters/kspread/gnumeric/gnumericexport.cc rename to filters/kspread/gnumeric/gnumericexport.cpp diff --git a/filters/kspread/gnumeric/gnumericimport.cc b/filters/kspread/gnumeric/gnumericimport.cpp similarity index 100% rename from filters/kspread/gnumeric/gnumericimport.cc rename to filters/kspread/gnumeric/gnumericimport.cpp diff --git a/filters/kspread/html/Makefile.am b/filters/kspread/html/Makefile.am index 87018febd..b170396fd 100644 --- a/filters/kspread/html/Makefile.am +++ b/filters/kspread/html/Makefile.am @@ -7,7 +7,7 @@ INCLUDES= -I$(srcdir) -I$(top_srcdir)/kspread $(KOFFICE_INCLUDES) \ kde_module_LTLIBRARIES = libkspreadhtmlexport.la -libkspreadhtmlexport_la_SOURCES = htmlexport.cc exportdialog.cc exportwidget.ui +libkspreadhtmlexport_la_SOURCES = htmlexport.cpp exportdialog.cpp exportwidget.ui libkspreadhtmlexport_la_LDFLAGS = $(all_libraries) -module -avoid-version -no-undefined libkspreadhtmlexport_la_LIBADD = $(KOFFICE_LIBS) ../../../kspread/libkspreadcommon.la diff --git a/filters/kspread/html/exportdialog.cc b/filters/kspread/html/exportdialog.cpp similarity index 100% rename from filters/kspread/html/exportdialog.cc rename to filters/kspread/html/exportdialog.cpp diff --git a/filters/kspread/html/htmlexport.cc b/filters/kspread/html/htmlexport.cpp similarity index 100% rename from filters/kspread/html/htmlexport.cc rename to filters/kspread/html/htmlexport.cpp diff --git a/filters/kspread/kexi/Makefile.am b/filters/kspread/kexi/Makefile.am index 6f76a2969..acfedf973 100644 --- a/filters/kspread/kexi/Makefile.am +++ b/filters/kspread/kexi/Makefile.am @@ -7,9 +7,9 @@ INCLUDES= -I$(srcdir) -I$(top_srcdir)/kspread -I$(top_srcdir)/kexi $(KOFFICE_INC kde_module_LTLIBRARIES = libkspreadkexiimport.la -libkspreadkexiimport_la_SOURCES = kspread_kexiimport.cc \ +libkspreadkexiimport_la_SOURCES = kspread_kexiimport.cpp \ kspread_kexiimportdialogbase.ui \ - kspread_kexiimportdialog.cc + kspread_kexiimportdialog.cpp libkspreadkexiimport_la_LDFLAGS = -avoid-version -module -no-undefined \ $(all_libraries) libkspreadkexiimport_la_LIBADD = ../../../kexi/kexidb/libkexidb.la \ diff --git a/filters/kspread/kexi/kspread_kexiimport.cc b/filters/kspread/kexi/kspread_kexiimport.cpp similarity index 100% rename from filters/kspread/kexi/kspread_kexiimport.cc rename to filters/kspread/kexi/kspread_kexiimport.cpp diff --git a/filters/kspread/kexi/kspread_kexiimportdialog.cc b/filters/kspread/kexi/kspread_kexiimportdialog.cpp similarity index 100% rename from filters/kspread/kexi/kspread_kexiimportdialog.cc rename to filters/kspread/kexi/kspread_kexiimportdialog.cpp diff --git a/filters/kspread/latex/export/Makefile.am b/filters/kspread/latex/export/Makefile.am index 053dd4323..0460b4be6 100644 --- a/filters/kspread/latex/export/Makefile.am +++ b/filters/kspread/latex/export/Makefile.am @@ -8,11 +8,11 @@ libkspreadlatexexport_la_LIBADD = $(KOFFICE_LIBS) $(LIB_KFORMULA) kde_module_LTLIBRARIES = libkspreadlatexexport.la -libkspreadlatexexport_la_SOURCES = cell.cc column.cc config.cc document.cc fileheader.cc \ - format.cc latexexportdia.ui kspreadlatexexportdiaImpl.cc \ - latexexport.cc latexexportIface.cc latexexportIface.skel \ - map.cc pen.cc row.cc spreadsheet.cc table.cc \ - xmlparser.cc +libkspreadlatexexport_la_SOURCES = cell.cpp column.cpp config.cpp document.cpp fileheader.cpp \ + format.cpp latexexportdia.ui kspreadlatexexportdiaImpl.cpp \ + latexexport.cpp latexexportIface.cpp latexexportIface.skel \ + map.cpp pen.cpp row.cpp spreadsheet.cpp table.cpp \ + xmlparser.cpp noinst_HEADERS = cell.h column.h config.h document.h fileheader.h format.h \ kspreadlatexexportdiaImpl.h latexexport.h latexexportIface.h \ @@ -20,7 +20,7 @@ noinst_HEADERS = cell.h column.h config.h document.h fileheader.h format.h \ ######## Debug #check_PROGRAMS = texlauncher -#texlauncher_SOURCES = texlauncher.cc +#texlauncher_SOURCES = texlauncher.cpp #texlauncher_LDADD = liblatexexport.la #texlauncher_LDFLAGS = $(all_libraries) $(KDE_RPATH) $(LIB_TQT) -lDCOP $(LIB_TDECORE) $(LIB_TDEUI) -ltdefx $(LIB_TDEIO) -ltdetexteditor diff --git a/filters/kspread/latex/export/cell.cc b/filters/kspread/latex/export/cell.cpp similarity index 100% rename from filters/kspread/latex/export/cell.cc rename to filters/kspread/latex/export/cell.cpp diff --git a/filters/kspread/latex/export/column.cc b/filters/kspread/latex/export/column.cpp similarity index 100% rename from filters/kspread/latex/export/column.cc rename to filters/kspread/latex/export/column.cpp diff --git a/filters/kspread/latex/export/config.cc b/filters/kspread/latex/export/config.cpp similarity index 100% rename from filters/kspread/latex/export/config.cc rename to filters/kspread/latex/export/config.cpp diff --git a/filters/kspread/latex/export/document.cc b/filters/kspread/latex/export/document.cpp similarity index 100% rename from filters/kspread/latex/export/document.cc rename to filters/kspread/latex/export/document.cpp diff --git a/filters/kspread/latex/export/fileheader.cc b/filters/kspread/latex/export/fileheader.cpp similarity index 100% rename from filters/kspread/latex/export/fileheader.cc rename to filters/kspread/latex/export/fileheader.cpp diff --git a/filters/kspread/latex/export/format.cc b/filters/kspread/latex/export/format.cpp similarity index 100% rename from filters/kspread/latex/export/format.cc rename to filters/kspread/latex/export/format.cpp diff --git a/filters/kspread/latex/export/formula.cc b/filters/kspread/latex/export/formula.cpp similarity index 100% rename from filters/kspread/latex/export/formula.cc rename to filters/kspread/latex/export/formula.cpp diff --git a/filters/kspread/latex/export/kspreadlatexexportdiaImpl.cc b/filters/kspread/latex/export/kspreadlatexexportdiaImpl.cpp similarity index 100% rename from filters/kspread/latex/export/kspreadlatexexportdiaImpl.cc rename to filters/kspread/latex/export/kspreadlatexexportdiaImpl.cpp diff --git a/filters/kspread/latex/export/latexexport.cc b/filters/kspread/latex/export/latexexport.cpp similarity index 100% rename from filters/kspread/latex/export/latexexport.cc rename to filters/kspread/latex/export/latexexport.cpp diff --git a/filters/kspread/latex/export/latexexportIface.cc b/filters/kspread/latex/export/latexexportIface.cpp similarity index 100% rename from filters/kspread/latex/export/latexexportIface.cc rename to filters/kspread/latex/export/latexexportIface.cpp diff --git a/filters/kspread/latex/export/map.cc b/filters/kspread/latex/export/map.cpp similarity index 100% rename from filters/kspread/latex/export/map.cc rename to filters/kspread/latex/export/map.cpp diff --git a/filters/kspread/latex/export/pen.cc b/filters/kspread/latex/export/pen.cpp similarity index 100% rename from filters/kspread/latex/export/pen.cc rename to filters/kspread/latex/export/pen.cpp diff --git a/filters/kspread/latex/export/row.cc b/filters/kspread/latex/export/row.cpp similarity index 100% rename from filters/kspread/latex/export/row.cc rename to filters/kspread/latex/export/row.cpp diff --git a/filters/kspread/latex/export/spreadsheet.cc b/filters/kspread/latex/export/spreadsheet.cpp similarity index 100% rename from filters/kspread/latex/export/spreadsheet.cc rename to filters/kspread/latex/export/spreadsheet.cpp diff --git a/filters/kspread/latex/export/table.cc b/filters/kspread/latex/export/table.cpp similarity index 100% rename from filters/kspread/latex/export/table.cc rename to filters/kspread/latex/export/table.cpp diff --git a/filters/kspread/latex/export/xmlparser.cc b/filters/kspread/latex/export/xmlparser.cpp similarity index 100% rename from filters/kspread/latex/export/xmlparser.cc rename to filters/kspread/latex/export/xmlparser.cpp diff --git a/filters/kspread/libkspreadexport/KSpreadBaseWorker.cc b/filters/kspread/libkspreadexport/KSpreadBaseWorker.cpp similarity index 100% rename from filters/kspread/libkspreadexport/KSpreadBaseWorker.cc rename to filters/kspread/libkspreadexport/KSpreadBaseWorker.cpp diff --git a/filters/kspread/libkspreadexport/KSpreadLeader.cc b/filters/kspread/libkspreadexport/KSpreadLeader.cpp similarity index 100% rename from filters/kspread/libkspreadexport/KSpreadLeader.cc rename to filters/kspread/libkspreadexport/KSpreadLeader.cpp diff --git a/filters/kspread/libkspreadexport/Makefile.am b/filters/kspread/libkspreadexport/Makefile.am index a36b3ad92..4411804a5 100644 --- a/filters/kspread/libkspreadexport/Makefile.am +++ b/filters/kspread/libkspreadexport/Makefile.am @@ -11,7 +11,7 @@ libkspreadexport_la_LIBADD = $(KOFFICE_LIBS) ../../../kspread/libkspreadcommon.l lib_LTLIBRARIES = libkspreadexport.la -libkspreadexport_la_SOURCES = KSpreadLeader.cc KSpreadBaseWorker.cc +libkspreadexport_la_SOURCES = KSpreadLeader.cpp KSpreadBaseWorker.cpp noinst_HEADERS = KSpreadLeader.h KSpreadBaseWorker.h diff --git a/filters/kspread/opencalc/Makefile.am b/filters/kspread/opencalc/Makefile.am index 65741b1d7..1312119fa 100644 --- a/filters/kspread/opencalc/Makefile.am +++ b/filters/kspread/opencalc/Makefile.am @@ -6,11 +6,11 @@ INCLUDES= -I$(srcdir)/../../liboofilter -I$(srcdir) -I$(top_srcdir)/kspread $(KO ####### Files kde_module_LTLIBRARIES = libopencalcimport.la libopencalcexport.la -libopencalcexport_la_SOURCES = opencalcexport.cc opencalcstyleexport.cc +libopencalcexport_la_SOURCES = opencalcexport.cpp opencalcstyleexport.cpp libopencalcexport_la_LDFLAGS = $(all_libraries) -module -avoid-version -no-undefined libopencalcexport_la_LIBADD = ../../../kspread/libkspreadcommon.la ../../liboofilter/liboofilter.la $(KOFFICE_LIBS) -libopencalcimport_la_SOURCES = opencalcimport.cc +libopencalcimport_la_SOURCES = opencalcimport.cpp libopencalcimport_la_LDFLAGS = $(all_libraries) -module -avoid-version -no-undefined libopencalcimport_la_LIBADD = ../../../kspread/libkspreadcommon.la ../../liboofilter/liboofilter.la $(KOFFICE_LIBS) diff --git a/filters/kspread/opencalc/opencalcexport.cc b/filters/kspread/opencalc/opencalcexport.cpp similarity index 100% rename from filters/kspread/opencalc/opencalcexport.cc rename to filters/kspread/opencalc/opencalcexport.cpp diff --git a/filters/kspread/opencalc/opencalcimport.cc b/filters/kspread/opencalc/opencalcimport.cpp similarity index 100% rename from filters/kspread/opencalc/opencalcimport.cc rename to filters/kspread/opencalc/opencalcimport.cpp diff --git a/filters/kspread/opencalc/opencalcstyleexport.cc b/filters/kspread/opencalc/opencalcstyleexport.cpp similarity index 100% rename from filters/kspread/opencalc/opencalcstyleexport.cc rename to filters/kspread/opencalc/opencalcstyleexport.cpp diff --git a/filters/kspread/qpro/Makefile.am b/filters/kspread/qpro/Makefile.am index 9f34af473..95ecdb8aa 100644 --- a/filters/kspread/qpro/Makefile.am +++ b/filters/kspread/qpro/Makefile.am @@ -10,7 +10,7 @@ SUBDIRS = libqpro kde_module_LTLIBRARIES = libqproimport.la -libqproimport_la_SOURCES = qproimport.cc qproformula.cc +libqproimport_la_SOURCES = qproimport.cpp qproformula.cpp libqproimport_la_LDFLAGS = $(all_libraries) -module -avoid-version -no-undefined libqproimport_la_LIBADD = $(KOFFICE_LIBS) ../../../kspread/libkspreadcommon.la \ diff --git a/filters/kspread/qpro/libqpro/ChangeLog b/filters/kspread/qpro/libqpro/ChangeLog index 35dbf4c2f..18a733a2e 100644 --- a/filters/kspread/qpro/libqpro/ChangeLog +++ b/filters/kspread/qpro/libqpro/ChangeLog @@ -6,16 +6,16 @@ * /cvsroot/libqpro/libqpro/Makefile.in: Update version number to 0.2 - * /cvsroot/libqpro/libqpro/src/record.cc, /cvsroot/libqpro/libqpro/src/record_factory.cc, /cvsroot/libqpro/libqpro/src/stream.cc, /cvsroot/libqpro/libqpro/src/tablenames.cc: + * /cvsroot/libqpro/libqpro/src/record.cpp, /cvsroot/libqpro/libqpro/src/record_factory.cpp, /cvsroot/libqpro/libqpro/src/stream.cpp, /cvsroot/libqpro/libqpro/src/tablenames.cpp: libqpro library. C++ libray for reading & writing Quattro Pro spreadsheet files. - * /cvsroot/libqpro/libqpro/src/record.cc, /cvsroot/libqpro/libqpro/src/record_factory.cc, /cvsroot/libqpro/libqpro/src/stream.cc, /cvsroot/libqpro/libqpro/src/tablenames.cc: + * /cvsroot/libqpro/libqpro/src/record.cpp, /cvsroot/libqpro/libqpro/src/record_factory.cpp, /cvsroot/libqpro/libqpro/src/stream.cpp, /cvsroot/libqpro/libqpro/src/tablenames.cpp: New file. - * /cvsroot/libqpro/libqpro/src/formula.cc: + * /cvsroot/libqpro/libqpro/src/formula.cpp: libqpro library. C++ libray for reading & writing Quattro Pro spreadsheet files. - * /cvsroot/libqpro/libqpro/src/formula.cc: New file. + * /cvsroot/libqpro/libqpro/src/formula.cpp: New file. * /cvsroot/libqpro/libqpro/src/Makefile.am, /cvsroot/libqpro/libqpro/src/Makefile.in: libqpro library. C++ libray for reading & writing Quattro Pro spreadsheet files. diff --git a/filters/kspread/qpro/libqpro/src/Makefile.am b/filters/kspread/qpro/libqpro/src/Makefile.am index 9eac256cd..1a6393bbd 100644 --- a/filters/kspread/qpro/libqpro/src/Makefile.am +++ b/filters/kspread/qpro/libqpro/src/Makefile.am @@ -1,5 +1,5 @@ INCLUDES= -I$(srcdir) -I$(srcdir)/.. $(all_includes) noinst_LTLIBRARIES = libqpro.la -libqpro_la_SOURCES = formula.cc record.cc record_factory.cc stream.cc tablenames.cc +libqpro_la_SOURCES = formula.cpp record.cpp record_factory.cpp stream.cpp tablenames.cpp diff --git a/filters/kspread/qpro/libqpro/src/formula.cc b/filters/kspread/qpro/libqpro/src/formula.cpp similarity index 100% rename from filters/kspread/qpro/libqpro/src/formula.cc rename to filters/kspread/qpro/libqpro/src/formula.cpp diff --git a/filters/kspread/qpro/libqpro/src/record.cc b/filters/kspread/qpro/libqpro/src/record.cpp similarity index 100% rename from filters/kspread/qpro/libqpro/src/record.cc rename to filters/kspread/qpro/libqpro/src/record.cpp diff --git a/filters/kspread/qpro/libqpro/src/record_factory.cc b/filters/kspread/qpro/libqpro/src/record_factory.cpp similarity index 100% rename from filters/kspread/qpro/libqpro/src/record_factory.cc rename to filters/kspread/qpro/libqpro/src/record_factory.cpp diff --git a/filters/kspread/qpro/libqpro/src/stream.cc b/filters/kspread/qpro/libqpro/src/stream.cpp similarity index 100% rename from filters/kspread/qpro/libqpro/src/stream.cc rename to filters/kspread/qpro/libqpro/src/stream.cpp diff --git a/filters/kspread/qpro/libqpro/src/tablenames.cc b/filters/kspread/qpro/libqpro/src/tablenames.cpp similarity index 100% rename from filters/kspread/qpro/libqpro/src/tablenames.cc rename to filters/kspread/qpro/libqpro/src/tablenames.cpp diff --git a/filters/kspread/qpro/qproformula.cc b/filters/kspread/qpro/qproformula.cpp similarity index 100% rename from filters/kspread/qpro/qproformula.cc rename to filters/kspread/qpro/qproformula.cpp diff --git a/filters/kspread/qpro/qproimport.cc b/filters/kspread/qpro/qproimport.cpp similarity index 100% rename from filters/kspread/qpro/qproimport.cc rename to filters/kspread/qpro/qproimport.cpp diff --git a/filters/kword/abiword/ImportField.cc b/filters/kword/abiword/ImportField.cpp similarity index 100% rename from filters/kword/abiword/ImportField.cc rename to filters/kword/abiword/ImportField.cpp diff --git a/filters/kword/abiword/ImportFormatting.cc b/filters/kword/abiword/ImportFormatting.cpp similarity index 100% rename from filters/kword/abiword/ImportFormatting.cc rename to filters/kword/abiword/ImportFormatting.cpp diff --git a/filters/kword/abiword/ImportHelpers.cc b/filters/kword/abiword/ImportHelpers.cpp similarity index 100% rename from filters/kword/abiword/ImportHelpers.cc rename to filters/kword/abiword/ImportHelpers.cpp diff --git a/filters/kword/abiword/ImportStyle.cc b/filters/kword/abiword/ImportStyle.cpp similarity index 100% rename from filters/kword/abiword/ImportStyle.cc rename to filters/kword/abiword/ImportStyle.cpp diff --git a/filters/kword/abiword/Makefile.am b/filters/kword/abiword/Makefile.am index 0a0f1f824..098266e96 100644 --- a/filters/kword/abiword/Makefile.am +++ b/filters/kword/abiword/Makefile.am @@ -12,10 +12,10 @@ libabiwordexport_la_LIBADD = $(KOFFICE_LIBS) ../libexport/libkwordexportfilters. kde_module_LTLIBRARIES = libabiwordimport.la libabiwordexport.la -libabiwordimport_la_SOURCES = abiwordimport.cc ImportHelpers.cc\ -ImportFormatting.cc ImportStyle.cc ImportField.cc +libabiwordimport_la_SOURCES = abiwordimport.cpp ImportHelpers.cpp\ +ImportFormatting.cpp ImportStyle.cpp ImportField.cpp -libabiwordexport_la_SOURCES = abiwordexport.cc +libabiwordexport_la_SOURCES = abiwordexport.cpp noinst_HEADERS = abiwordimport.h ImportHelpers.h ImportFormatting.h\ ImportStyle.h ImportField.h abiwordexport.h diff --git a/filters/kword/abiword/abiwordexport.cc b/filters/kword/abiword/abiwordexport.cc deleted file mode 100644 index 11f5d2dd7..000000000 --- a/filters/kword/abiword/abiwordexport.cc +++ /dev/null @@ -1,1261 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2001, 2002, 2003, 2004 Nicolas GOUTTE - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. -*/ - -/* - This file is based on the old file: - /home/kde/koffice/filters/kword/ascii/asciiexport.cc - - The old file was copyrighted by - Copyright (C) 1998, 1999 Reginald Stadlbauer - Copyright (c) 2000 ID-PRO Deutschland GmbH. All rights reserved. - Contact: Wolf-Michael Bolle - - The old file was licensed under the terms of the GNU Library General Public - License version 2. -*/ - -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include -#include -#include - -#include -#include -#include -#include - -#include -#include - -class ABIWORDExportFactory : KGenericFactory -{ -public: - ABIWORDExportFactory(void) : KGenericFactory ("kwordabiwordexport") - {} -protected: - virtual void setupTranslations( void ) - { - TDEGlobal::locale()->insertCatalogue( "kofficefilters" ); - } -}; - -K_EXPORT_COMPONENT_FACTORY( libabiwordexport, ABIWORDExportFactory() ) - -class StyleMap : public TQMap -{ -public: - StyleMap(void) {} - ~StyleMap(void) {} -}; - -class AbiWordWorker : public KWEFBaseWorker -{ -public: - AbiWordWorker(void); - virtual ~AbiWordWorker(void) { delete m_streamOut; delete m_ioDevice; } -public: - virtual bool doOpenFile(const TQString& filenameOut, const TQString& to); - virtual bool doCloseFile(void); // Close file in normal conditions - virtual bool doOpenDocument(void); - virtual bool doCloseDocument(void); - virtual bool doFullParagraph(const TQString& paraText, const LayoutData& layout, - const ValueListFormatData& paraFormatDataList); - virtual bool doOpenTextFrameSet(void); // AbiWord's
- virtual bool doCloseTextFrameSet(void); // AbiWord's
- virtual bool doFullPaperFormat(const int format, - const double width, const double height, const int orientation); // Calc AbiWord's - virtual bool doFullPaperBorders (const double top, const double left, - const double bottom, const double right); // Like KWord's - virtual bool doCloseHead(void); // Write - virtual bool doOpenStyles(void); // AbiWord's - virtual bool doCloseStyles(void); // AbiWord's - virtual bool doFullDefineStyle(LayoutData& layout); // AbiWord's - virtual bool doOpenSpellCheckIgnoreList (void); // AbiWord's - virtual bool doCloseSpellCheckIgnoreList (void); // AbiWord's - virtual bool doFullSpellCheckIgnoreWord (const TQString& ignoreword); // AbiWord's - virtual bool doFullDocumentInfo(const KWEFDocumentInfo& docInfo); // AbiWord's -private: - void processParagraphData (const TQString& paraText, - const TextFormatting& formatLayout, - const ValueListFormatData& paraFormatDataList); - void processNormalText ( const TQString& paraText, - const TextFormatting& formatLayout, - const FormatData& formatData); - void processVariable ( const TQString& paraText, - const TextFormatting& formatLayout, - const FormatData& formatData); - void processAnchor ( const TQString& paraText, - const TextFormatting& formatLayout, - const FormatData& formatData); - TQString textFormatToAbiProps(const TextFormatting& formatOrigin, - const TextFormatting& formatData, const bool force) const; - TQString layoutToCss(const LayoutData& layoutOrigin, - const LayoutData& layout, const bool force) const; - TQString escapeAbiWordText(const TQString& strText) const; - bool makeTable(const FrameAnchor& anchor); - bool makePicture(const FrameAnchor& anchor); - void writeAbiProps(const TextFormatting& formatLayout, const TextFormatting& format); - void writePictureData(const TQString& koStoreName, const TQString& keyName); - TQString transformToTextDate(const TQDateTime& dt); -private: - TQIODevice* m_ioDevice; - TQTextStream* m_streamOut; - TQString m_pagesize; // Buffer for the tag - TQMap m_mapPictureData; - StyleMap m_styleMap; - double m_paperBorderTop,m_paperBorderLeft,m_paperBorderBottom,m_paperBorderRight; - bool m_inIgnoreWords; // true if has been written - KWEFDocumentInfo m_docInfo; // document information -}; - -AbiWordWorker::AbiWordWorker(void) : m_ioDevice(NULL), m_streamOut(NULL), - m_paperBorderTop(0.0),m_paperBorderLeft(0.0), - m_paperBorderBottom(0.0),m_paperBorderRight(0.0) -{ -} - -TQString AbiWordWorker::escapeAbiWordText(const TQString& strText) const -{ - // Escape quotes (needed in attributes) - // Escape apostrophs (allowed by XML) - return KWEFUtil::EscapeSgmlText(NULL,strText,true,true); -} - -bool AbiWordWorker::doOpenFile(const TQString& filenameOut, const TQString& ) -{ - kdDebug(30506) << "Opening file: " << filenameOut - << " (in AbiWordWorker::doOpenFile)" << endl; - //Find the last extension - TQString strExt; - const int result=filenameOut.findRev('.'); - if (result>=0) - { - strExt=filenameOut.mid(result); - } - - TQString strMimeType; // Mime type of the compressor - - if ((strExt==".gz")||(strExt==".GZ") //in case of .abw.gz (logical extension) - ||(strExt==".zabw")||(strExt==".ZABW")) //in case of .zabw (extension used prioritary with AbiWord) - { - // Compressed with gzip - strMimeType="application/x-gzip"; - } - else if ((strExt==".bz2")||(strExt==".BZ2") //in case of .abw.bz2 (logical extension) - ||(strExt==".bzabw")||(strExt==".BZABW")) //in case of .bzabw (extension used prioritary with AbiWord) - { - // Compressed with bzip2 - strMimeType="application/x-bzip2"; - } - else - { - // No compression - strMimeType="text/plain"; - } - - kdDebug(30506) << "Compression: " << strMimeType << endl; - - m_ioDevice = KFilterDev::deviceForFile(filenameOut,strMimeType); - - if (!m_ioDevice) - { - kdError(30506) << "No output file! Aborting!" << endl; - return false; - } - - if ( !m_ioDevice->open (IO_WriteOnly) ) - { - kdError(30506) << "Unable to open output file! Aborting!" << endl; - return false; - } - - m_streamOut=new TQTextStream(m_ioDevice); - - // We only export in UTF-8 (are there AbiWord ports that cannot read UTF-8? Be careful SVG uses UTF-8 too!) - m_streamOut->setEncoding( TQTextStream::UnicodeUTF8 ); - return true; -} - -bool AbiWordWorker::doCloseFile(void) -{ - delete m_streamOut; - m_streamOut=NULL; - if (m_ioDevice) - m_ioDevice->close(); - return (m_ioDevice); -} - -bool AbiWordWorker::doOpenDocument(void) -{ - kdDebug(30506)<< "AbiWordWorker::doOpenDocument" << endl; - // Make the file header - - // First the XML header in UTF-8 version - // (AbiWord and QT handle UTF-8 well, so we stay with this encoding!) - *m_streamOut << "\n"; - - // NOTE: AbiWord CVS 2002-02-?? has a new DOCTYPE - *m_streamOut << "\n"; - - // First magic: "\n"; - // Second magic: "\n"; - // We have chosen NOT to have the full comment header that AbiWord files normally have. - // ### TODO: perhaps we should add the comment: do not edit the file - *m_streamOut << "\n"; - - - return true; -} - -void AbiWordWorker::writePictureData(const TQString& koStoreName, const TQString& keyName) -{ - kdDebug(30506) << "AbiWordWorker::writeImageData" << endl; - - TQByteArray image; - - TQString strExtension(koStoreName.lower()); - const int result=koStoreName.findRev("."); - if (result>=0) - { - strExtension=koStoreName.mid(result+1); - } - - bool isImageLoaded=false; - - if (strExtension=="png") - { - isImageLoaded=loadSubFile(koStoreName,image); - } - else - { - // All other picture types must be converted to PNG - // (yes, even JPEG, SVG or WMF!) - isImageLoaded=loadAndConvertToImage(koStoreName,strExtension,"PNG",image); - } - - if (isImageLoaded) - { - *m_streamOut << "\n"; - - TQCString base64=KCodecs::base64Encode(image,true); - - *m_streamOut << base64 << "\n"; // TQCString is taken as Latin1 by TQTextStream - - *m_streamOut << "\n"; - } - else - { - kdWarning(30506) << "Unable to load picture: " << koStoreName << endl; - } -} - -bool AbiWordWorker::doCloseDocument(void) -{ - // Before writing the element, - // we must be sure that we have data and that we can retrieve it. - - if (m_kwordLeader && !m_mapPictureData.isEmpty()) - { - *m_streamOut << "\n"; - - TQMap::ConstIterator it; - TQMap::ConstIterator end(m_mapPictureData.end()); - // all images first - for (it=m_mapPictureData.begin(); it!=end; ++it) - { - // Warning: do not mix up KWord's key and the iterator's key! - writePictureData(it.key(),it.data().filename()); - } - - *m_streamOut << "\n"; - } - - *m_streamOut << "\n"; //Close the file for XML - return true; -} - -bool AbiWordWorker::doOpenTextFrameSet(void) -{ - *m_streamOut << "
\n"; - return true; -} - -bool AbiWordWorker::doCloseTextFrameSet(void) -{ - *m_streamOut << "
\n"; - return true; -} - -bool AbiWordWorker::doOpenStyles(void) -{ - *m_streamOut << "\n"; - return true; -} - -bool AbiWordWorker::doCloseStyles(void) -{ - *m_streamOut << "\n"; - return true; -} - -TQString AbiWordWorker::textFormatToAbiProps(const TextFormatting& formatOrigin, - const TextFormatting& formatData, const bool force) const -{ - // TODO: rename variable formatData - TQString strElement; // TODO: rename this variable - - // Font name - TQString fontName = formatData.fontName; - if ( !fontName.isEmpty() - && (force || (formatOrigin.fontName!=formatData.fontName))) - { - strElement+="font-family: "; - strElement+= escapeAbiWordText(fontName); // TODO: add alternative font names - strElement+="; "; - } - - if (force || (formatOrigin.italic!=formatData.italic)) - { - // Font style - strElement+="font-style: "; - if ( formatData.italic ) - { - strElement+="italic"; - } - else - { - strElement+="normal"; - } - strElement+="; "; - } - - if (force || ((formatOrigin.weight>=75)!=(formatData.weight>=75))) - { - strElement+="font-weight: "; - if ( formatData.weight >= 75 ) - { - strElement+="bold"; - } - else - { - strElement+="normal"; - } - strElement+="; "; - } - - if (force || (formatOrigin.fontSize!=formatData.fontSize)) - { - const int size=formatData.fontSize; - if (size>0) - { - // We use absolute font sizes. - strElement+="font-size: "; - strElement+=TQString::number(size,10); - strElement+="pt; "; - } - } - - if (force || (formatOrigin.fgColor!=formatData.fgColor)) - { - if ( formatData.fgColor.isValid() ) - { - // Give colour - strElement+="color: "; - - // No leading # (unlike CSS2) - // We must have two hex digits for each colour channel! - const int red=formatData.fgColor.red(); - strElement += TQString::number((red&0xf0)>>4,16); - strElement += TQString::number(red&0x0f,16); - - const int green=formatData.fgColor.green(); - strElement += TQString::number((green&0xf0)>>4,16); - strElement += TQString::number(green&0x0f,16); - - const int blue=formatData.fgColor.blue(); - strElement += TQString::number((blue&0xf0)>>4,16); - strElement += TQString::number(blue&0x0f,16); - - strElement+="; "; - } - } - - if (force || (formatOrigin.bgColor!=formatData.bgColor)) - { - if ( formatData.bgColor.isValid() ) - { - // Give background colour - strElement+="bgcolor: "; - - // No leading # (unlike CSS2) - // We must have two hex digits for each colour channel! - const int red=formatData.bgColor.red(); - strElement += TQString::number((red&0xf0)>>4,16); - strElement += TQString::number(red&0x0f,16); - - const int green=formatData.bgColor.green(); - strElement += TQString::number((green&0xf0)>>4,16); - strElement += TQString::number(green&0x0f,16); - - const int blue=formatData.bgColor.blue(); - strElement += TQString::number((blue&0xf0)>>4,16); - strElement += TQString::number(blue&0x0f,16); - - strElement+="; "; - } - } - - if (force || (formatOrigin.underline!=formatData.underline) - || (formatOrigin.strikeout!=formatData.strikeout)) - { - strElement+="text-decoration: "; - if ( formatData.underline ) - { - strElement+="underline"; - } - else if ( formatData.strikeout ) - { - strElement+="line-through"; - } - else - { - strElement+="none"; - } - strElement+="; "; - } - - return strElement; -} - -bool AbiWordWorker::makeTable(const FrameAnchor& anchor) -{ -#if 0 - *m_streamOut << "

\n"; // Close previous paragraph ### TODO: do it correctly like for HTML - *m_streamOut << "\n"; -#endif - - TQValueList::ConstIterator itCell; - for (itCell=anchor.table.cellList.begin(); - itCell!=anchor.table.cellList.end(); itCell++) - { -#if 0 - // ### TODO: rowspan, colspan - - // AbiWord seems to work by attaching to the cell borders - *m_streamOut << "\n"; -#endif - if (!doFullAllParagraphs(*(*itCell).paraList)) - { - return false; - } -#if 0 - *m_streamOut << "\n"; -#endif - } -#if 0 - *m_streamOut << "
\n"; - *m_streamOut << "

\n"; // Re-open the "previous" paragraph ### TODO: do it correctly like for HTML -#endif - return true; -} - -bool AbiWordWorker::makePicture(const FrameAnchor& anchor) -{ - kdDebug(30506) << "New image/clipart: " << anchor.picture.koStoreName - << " , " << anchor.picture.key.toString() << endl; - - const double height=anchor.frame.bottom - anchor.frame.top; - const double width =anchor.frame.right - anchor.frame.left; - - // TODO: we are only using the filename, not the rest of the key - // TODO: (bad if there are two images of the same name, but of a different key) - *m_streamOut << ""; // NO end of line! - // TODO: other props for image - - m_mapPictureData[anchor.picture.koStoreName]=anchor.picture.key; - - return true; -} - -void AbiWordWorker::writeAbiProps (const TextFormatting& formatLayout, const TextFormatting& format) -{ - TQString abiprops=textFormatToAbiProps(formatLayout,format,false); - - // Erase the last semi-comma (as in CSS2, semi-commas only separate instructions and do not terminate them) - const int result=abiprops.findRev(";"); - - if (result>=0) - { - // Remove the last semi-comma and the space thereafter - abiprops.remove(result,2); - } - - if (!abiprops.isEmpty()) - { - *m_streamOut << " props=\"" << abiprops << "\""; - } -} - -void AbiWordWorker::processNormalText ( const TQString ¶Text, - const TextFormatting& formatLayout, - const FormatData& formatData) -{ - // Retrieve text and escape it - TQString partialText=escapeAbiWordText(paraText.mid(formatData.pos,formatData.len)); - - // Replace line feeds by line breaks - int pos; - while ((pos=partialText.find(TQChar(10)))>-1) - { - partialText.replace(pos,1,"
"); - } - - if (formatData.text.missing) - { - // It's just normal text, so we do not need a element! - *m_streamOut << partialText; - } - else - { // Text with properties, so use a element! - *m_streamOut << "" << partialText << ""; - } -} - -void AbiWordWorker::processVariable ( const TQString&, - const TextFormatting& formatLayout, - const FormatData& formatData) -{ - if (0==formatData.variable.m_type) - { - // As AbiWord's field is inflexible, we cannot make the date custom - *m_streamOut << ""; - } - else if (2==formatData.variable.m_type) - { - // As AbiWord's field is inflexible, we cannot make the time custom - *m_streamOut << ""; - } - else if (4==formatData.variable.m_type) - { - // As AbiWord's field is inflexible, we cannot make the time custom - TQString strFieldType; - if (formatData.variable.isPageNumber()) - { - strFieldType="page_number"; - } - else if (formatData.variable.isPageCount()) - { - strFieldType="page_count"; - } - if (strFieldType.isEmpty()) - { - // Unknown subtype, therefore write out the result - *m_streamOut << formatData.variable.m_text; - } - else - { - *m_streamOut << ""; - } - } - else if (9==formatData.variable.m_type) - { - // A link - *m_streamOut << " has always a child - writeAbiProps(formatLayout,formatData.text); - *m_streamOut << ">" - << escapeAbiWordText(formatData.variable.getLinkName()) - << ""; - } -#if 0 - else if (11==(*paraFormatDataIt).variable.m_type) - { - // Footnote - TQString value = (*paraFormatDataIt).variable.getFootnoteValue(); - bool automatic = (*paraFormatDataIt).variable.getFootnoteAuto(); - TQValueList *paraList = (*paraFormatDataIt).variable.getFootnotePara(); - if( paraList ) - { - TQString fstr; - TQValueList::ConstIterator it; - for (it=paraList->begin();it!=paraList->end();it++) - fstr += ProcessParagraphData( (*it).text, (*it).layout,(*it).formattingList); - str += "{\\super "; - str += automatic ? "\\chftn " : value; - str += "{\\footnote "; - str += "{\\super "; - str += automatic ? "\\chftn " : value; - str += fstr; - str += " }"; - str += " }"; - str += " }"; - } - } -#endif - else - { - // Generic variable - *m_streamOut << formatData.variable.m_text; - } -} - -void AbiWordWorker::processAnchor ( const TQString&, - const TextFormatting& /*formatLayout*/, //TODO - const FormatData& formatData) -{ - // We have an image or a table - if ( (2==formatData.frameAnchor.type) // or - || (5==formatData.frameAnchor.type) ) // - { - makePicture(formatData.frameAnchor); - } - else if (6==formatData.frameAnchor.type) - { - makeTable(formatData.frameAnchor); - } - else - { - kdWarning(30506) << "Unsupported anchor type: " - << formatData.frameAnchor.type << endl; - } -} - -void AbiWordWorker::processParagraphData ( const TQString ¶Text, - const TextFormatting& formatLayout, - const ValueListFormatData ¶FormatDataList) -{ - if ( paraText.length () > 0 ) - { - ValueListFormatData::ConstIterator paraFormatDataIt; - - for ( paraFormatDataIt = paraFormatDataList.begin (); - paraFormatDataIt != paraFormatDataList.end (); - paraFormatDataIt++ ) - { - if (1==(*paraFormatDataIt).id) - { - processNormalText(paraText, formatLayout, (*paraFormatDataIt)); - } - else if (4==(*paraFormatDataIt).id) - { - processVariable(paraText, formatLayout, (*paraFormatDataIt)); - } - else if (6==(*paraFormatDataIt).id) - { - processAnchor(paraText, formatLayout, (*paraFormatDataIt)); - } - } - } -} - -TQString AbiWordWorker::layoutToCss(const LayoutData& layoutOrigin, - const LayoutData& layout, const bool force) const -{ - TQString props; - - if (force || (layoutOrigin.alignment!=layout.alignment)) - { - // Check if the current alignment is a valid one for AbiWord. - if ((layout.alignment == "left") || (layout.alignment == "right") - || (layout.alignment == "center") || (layout.alignment == "justify")) - { - props += "text-align:"; - props += layout.alignment; - props += "; "; - } - else if (layout.alignment == "auto") - { - // We assume a left alignment as AbiWord is not really bi-di (and this filter even less.) - props += "text-align:left; "; - } - else - { - kdWarning(30506) << "Unknown alignment: " << layout.alignment << endl; - } - } - - // TODO/FIXME: what if all tabulators must be erased? -#if 0 - // DEPRECATED! - if (!layout.tabulator.isEmpty() - && (force || (layoutOrigin.tabulator!=layout.tabulator))) - { - props += "tabstops:"; - props += layout.tabulator; - props += "; "; - } -#endif - if (!layout.tabulatorList.isEmpty() - && (force || (layoutOrigin.tabulatorList!=layout.tabulatorList) )) - { - props += "tabstops:"; - bool first=true; - TabulatorList::ConstIterator it; - TabulatorList::ConstIterator end(layout.tabulatorList.end()); - for (it=layout.tabulatorList.begin();it!=end;++it) - { - if (first) - { - first=false; - } - else - { - props += ","; - } - props += TQString::number((*it).m_ptpos); - props += "pt"; - - switch ((*it).m_type) - { - case 0: props += "/L"; break; - case 1: props += "/C"; break; - case 2: props += "/R"; break; - case 3: props += "/D"; break; - default: props += "/L"; - } - - props += "0"; // No filling - } - props += "; "; - } - - if ((layout.indentLeft>=0.0) - && (force || (layoutOrigin.indentLeft!=layout.indentLeft))) - { - props += TQString("margin-left:%1pt; ").arg(layout.indentLeft); - } - - if ((layout.indentRight>=0.0) - && (force || (layoutOrigin.indentRight!=layout.indentRight))) - { - props += TQString("margin-right:%1pt; ").arg(layout.indentRight); - } - - if (force || (layoutOrigin.indentLeft!=layout.indentLeft)) - { - props += "text-indent: "; - props += TQString::number(layout.indentFirst); - props += "pt; "; - } - - if ((layout.marginBottom>=0.0) - && ( force || ( layoutOrigin.marginBottom != layout.marginBottom ) ) ) - { - props += TQString("margin-bottom:%1pt; ").arg(layout.marginBottom); - } - - if ((layout.marginTop>=0.0) - && ( force || ( layoutOrigin.marginTop != layout.marginTop ) ) ) - { - props += TQString("margin-top:%1pt; ").arg(layout.marginTop); - } - - if (force - || ( layoutOrigin.lineSpacingType != layout.lineSpacingType ) - || ( layoutOrigin.lineSpacing != layout.lineSpacing ) ) - { - switch ( layout.lineSpacingType ) - { - case LayoutData::LS_CUSTOM: - { - // We have a custom line spacing (in points). However AbiWord cannot do it, so transform in "at-least" - props += "line-height=:"; - props += TQString::number( layout.lineSpacing ); // ### TODO: rounding? - props += "pt+; "; - break; - } - case LayoutData::LS_SINGLE: - { - props += "line-height:1.0; "; // One - break; - } - case LayoutData::LS_ONEANDHALF: - { - props += "line-height:1.5; "; // One-and-half - break; - } - case LayoutData::LS_DOUBLE: - { - props += "line-height:2.0; "; // Two - break; - } - case LayoutData::LS_MULTIPLE: - { - props += "line-height:"; - props += TQString::number( layout.lineSpacing ); // ### TODO: rounding? - props += "; "; - break; - } - case LayoutData::LS_FIXED: - { - // We have a fixed line height (in points) - props += "line-height:"; - props += TQString::number( layout.lineSpacing ); // ### TODO: rounding? - props += "pt; "; - break; - } - case LayoutData::LS_ATLEAST: - { - // We have an "at-least" line height (in points) - props += "line-height=:"; - props += TQString::number( layout.lineSpacing ); // ### TODO: rounding? - props += "pt+; "; // The + makes the difference - break; - } - default: - { - kdWarning(30506) << "Unsupported lineSpacingType: " << layout.lineSpacingType << " (Ignoring!)" << endl; - break; - } - } - } - - // Add all AbiWord properties collected in the element - props += textFormatToAbiProps(layoutOrigin.formatData.text,layout.formatData.text,force); - - return props; -} - -bool AbiWordWorker::doFullParagraph(const TQString& paraText, const LayoutData& layout, - const ValueListFormatData& paraFormatDataList) -{ - TQString style=layout.styleName; - - const LayoutData& styleLayout=m_styleMap[style]; - - TQString props=layoutToCss(styleLayout,layout,false); - - *m_streamOut << "=0) - { - // Remove the last semi-comma and the space thereafter - props.remove(result,2); - } - - *m_streamOut << " props=\"" << props << "\""; - } - *m_streamOut << ">"; //Warning: No trailing white space or else it's in the text!!! - - // Before processing the text, test if we have a page break - if (layout.pageBreakBefore) - { - // We have a page break before the paragraph - *m_streamOut << ""; - } - - processParagraphData(paraText, layout.formatData.text, paraFormatDataList); - - // Before closing the paragraph, test if we have a page break - if (layout.pageBreakAfter) - { - // We have a page break after the paragraph - *m_streamOut << ""; - } - - *m_streamOut << "

\n"; - return true; -} - -bool AbiWordWorker::doFullDefineStyle(LayoutData& layout) -{ - //Register style in the style map - m_styleMap[layout.styleName]=layout; - - *m_streamOut << "=0) - { - // Remove the last semi-comma and the space thereafter - abiprops.remove(result,2); - } - - *m_streamOut << " props=\"" << abiprops << "\""; - - *m_streamOut << "/>\n"; - - return true; -} - -bool AbiWordWorker::doFullPaperFormat(const int format, - const double width, const double height, const int orientation) -{ - TQString outputText = "\n"; // KWord has no page scale, so assume 100% - - m_pagesize=outputText; - return true; -} - -bool AbiWordWorker::doFullPaperBorders (const double top, const double left, - const double bottom, const double right) -{ - m_paperBorderTop=top; - m_paperBorderLeft=left; - m_paperBorderBottom=bottom; - m_paperBorderRight=right; - return true; -} - -bool AbiWordWorker::doCloseHead(void) -{ - if (!m_pagesize.isEmpty()) - { - *m_streamOut << m_pagesize; - } - return true; -} - -bool AbiWordWorker::doOpenSpellCheckIgnoreList (void) -{ - kdDebug(30506) << "AbiWordWorker::doOpenSpellCheckIgnoreList" << endl; - m_inIgnoreWords=false; // reset - return true; -} - -bool AbiWordWorker::doCloseSpellCheckIgnoreList (void) -{ - kdDebug(30506) << "AbiWordWorker::doCloseSpellCheckIgnoreList" << endl; - if (m_inIgnoreWords) - *m_streamOut << "
\n"; - return true; -} - -bool AbiWordWorker::doFullSpellCheckIgnoreWord (const TQString& ignoreword) -{ - kdDebug(30506) << "AbiWordWorker::doFullSpellCheckIgnoreWord: " << ignoreword << endl; - if (!m_inIgnoreWords) - { - *m_streamOut << "\n"; - m_inIgnoreWords=true; - } - *m_streamOut << " " << ignoreword << "\n"; - return true; -} - -// Similar to TQDateTime::toString, but guaranteed *not* to be translated -TQString AbiWordWorker::transformToTextDate(const TQDateTime& dt) -{ - if (dt.isValid()) - { - TQString result; - - const TQDate date(dt.date()); - - const char* dayName[7] = { "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" }; - const int dow = date.dayOfWeek() - 1; - if ((dow<0) || (dow>6)) - result += "Mon"; // Unknown day, rename it Monday. - else - result += dayName[dow]; - result += ' '; - - const char* monthName[12] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; - const int month = date.month() - 1; - if ((month<0) || (month>11)) - result += "Jan"; // Unknown month, rename it January - else - result += monthName[month]; - result += ' '; - - TQString temp; - - temp = "00"; - temp += TQString::number(date.day(), 10); - result += temp.right(2); - result += ' '; - - const TQTime time(dt.time()); - - temp = "00"; - temp += TQString::number(time.hour(), 10); - result += temp.right(2); - result += ':'; - - temp = "00"; - temp += TQString::number(time.minute(), 10); - result += temp.right(2); - result += ':'; - - temp = "00"; - temp += TQString::number(time.second(), 10); - result += temp.right(2); - result += ' '; - - temp = "0000"; - temp += TQString::number(date.year(), 10); - result += temp.right(4); - - return result; - } - else - { - // Invalid, so give back 1970-01-01 - return "Thu Jan 01 00:00:00 1970"; - } -} - -bool AbiWordWorker::doFullDocumentInfo(const KWEFDocumentInfo& docInfo) -{ - m_docInfo=docInfo; - - *m_streamOut << "\n"; - - // First all Dublin Core data - *m_streamOut << "application/x-abiword\n"; - if (!m_docInfo.title.isEmpty()) - { - *m_streamOut << "" << escapeAbiWordText(m_docInfo.title) << "\n"; - } - if (!m_docInfo.abstract.isEmpty()) - { - *m_streamOut << "" << escapeAbiWordText(m_docInfo.abstract) << "\n"; - } - - if ( !m_docInfo.keywords.isEmpty() ) - { - *m_streamOut << "" << escapeAbiWordText(m_docInfo.keywords) << "\n"; - } - if ( !m_docInfo.subject.isEmpty() ) - { - *m_streamOut << "" << escapeAbiWordText(m_docInfo.subject) << "\n"; - } - - // Say who we are (with the CVS revision number) in case we have a bug in our filter output! - *m_streamOut << "KWord Export Filter"; - - TQString strVersion("$Revision: 508787 $"); - // Remove the dollar signs - // (We don't want that the version number changes if the AbiWord file is itself put in a CVS storage.) - *m_streamOut << strVersion.mid(10).remove('$'); - - *m_streamOut << "\n"; - - TQDateTime now (TQDateTime::currentDateTime(Qt::UTC)); // current time in UTC - *m_streamOut << "" - << escapeAbiWordText(transformToTextDate(now)) - << "\n"; - - *m_streamOut << "\n"; - - return true; -} - - -// ========================================================================================== - -ABIWORDExport::ABIWORDExport(KoFilter */*parent*/, const char */*name*/, const TQStringList &) : - KoFilter() { -} - -KoFilter::ConversionStatus ABIWORDExport::convert( const TQCString& from, const TQCString& to ) -{ - if ( to != "application/x-abiword" || from != "application/x-kword" ) - { - return KoFilter::NotImplemented; - } - - // We need KimageIO's help in AbiWordWorker::convertUnknownImage - KImageIO::registerFormats(); - - AbiWordWorker* worker=new AbiWordWorker(); - - if (!worker) - { - kdError(30506) << "Cannot create Worker! Aborting!" << endl; - return KoFilter::StupidError; - } - - KWEFKWordLeader* leader=new KWEFKWordLeader(worker); - - if (!leader) - { - kdError(30506) << "Cannot create Worker! Aborting!" << endl; - delete worker; - return KoFilter::StupidError; - } - - KoFilter::ConversionStatus result=leader->convert(m_chain,from,to); - - delete leader; - delete worker; - - return result; -} diff --git a/filters/kword/abiword/abiwordexport.cpp b/filters/kword/abiword/abiwordexport.cpp new file mode 100644 index 000000000..d1b5a98a2 --- /dev/null +++ b/filters/kword/abiword/abiwordexport.cpp @@ -0,0 +1,1261 @@ +/* This file is part of the KDE project + Copyright (C) 2001, 2002, 2003, 2004 Nicolas GOUTTE + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +/* + This file is based on the old file: + /home/kde/koffice/filters/kword/ascii/asciiexport.cpp + + The old file was copyrighted by + Copyright (C) 1998, 1999 Reginald Stadlbauer + Copyright (c) 2000 ID-PRO Deutschland GmbH. All rights reserved. + Contact: Wolf-Michael Bolle + + The old file was licensed under the terms of the GNU Library General Public + License version 2. +*/ + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include + +#include +#include + +class ABIWORDExportFactory : KGenericFactory +{ +public: + ABIWORDExportFactory(void) : KGenericFactory ("kwordabiwordexport") + {} +protected: + virtual void setupTranslations( void ) + { + TDEGlobal::locale()->insertCatalogue( "kofficefilters" ); + } +}; + +K_EXPORT_COMPONENT_FACTORY( libabiwordexport, ABIWORDExportFactory() ) + +class StyleMap : public TQMap +{ +public: + StyleMap(void) {} + ~StyleMap(void) {} +}; + +class AbiWordWorker : public KWEFBaseWorker +{ +public: + AbiWordWorker(void); + virtual ~AbiWordWorker(void) { delete m_streamOut; delete m_ioDevice; } +public: + virtual bool doOpenFile(const TQString& filenameOut, const TQString& to); + virtual bool doCloseFile(void); // Close file in normal conditions + virtual bool doOpenDocument(void); + virtual bool doCloseDocument(void); + virtual bool doFullParagraph(const TQString& paraText, const LayoutData& layout, + const ValueListFormatData& paraFormatDataList); + virtual bool doOpenTextFrameSet(void); // AbiWord's
+ virtual bool doCloseTextFrameSet(void); // AbiWord's
+ virtual bool doFullPaperFormat(const int format, + const double width, const double height, const int orientation); // Calc AbiWord's + virtual bool doFullPaperBorders (const double top, const double left, + const double bottom, const double right); // Like KWord's + virtual bool doCloseHead(void); // Write + virtual bool doOpenStyles(void); // AbiWord's + virtual bool doCloseStyles(void); // AbiWord's + virtual bool doFullDefineStyle(LayoutData& layout); // AbiWord's + virtual bool doOpenSpellCheckIgnoreList (void); // AbiWord's + virtual bool doCloseSpellCheckIgnoreList (void); // AbiWord's + virtual bool doFullSpellCheckIgnoreWord (const TQString& ignoreword); // AbiWord's + virtual bool doFullDocumentInfo(const KWEFDocumentInfo& docInfo); // AbiWord's +private: + void processParagraphData (const TQString& paraText, + const TextFormatting& formatLayout, + const ValueListFormatData& paraFormatDataList); + void processNormalText ( const TQString& paraText, + const TextFormatting& formatLayout, + const FormatData& formatData); + void processVariable ( const TQString& paraText, + const TextFormatting& formatLayout, + const FormatData& formatData); + void processAnchor ( const TQString& paraText, + const TextFormatting& formatLayout, + const FormatData& formatData); + TQString textFormatToAbiProps(const TextFormatting& formatOrigin, + const TextFormatting& formatData, const bool force) const; + TQString layoutToCss(const LayoutData& layoutOrigin, + const LayoutData& layout, const bool force) const; + TQString escapeAbiWordText(const TQString& strText) const; + bool makeTable(const FrameAnchor& anchor); + bool makePicture(const FrameAnchor& anchor); + void writeAbiProps(const TextFormatting& formatLayout, const TextFormatting& format); + void writePictureData(const TQString& koStoreName, const TQString& keyName); + TQString transformToTextDate(const TQDateTime& dt); +private: + TQIODevice* m_ioDevice; + TQTextStream* m_streamOut; + TQString m_pagesize; // Buffer for the tag + TQMap m_mapPictureData; + StyleMap m_styleMap; + double m_paperBorderTop,m_paperBorderLeft,m_paperBorderBottom,m_paperBorderRight; + bool m_inIgnoreWords; // true if has been written + KWEFDocumentInfo m_docInfo; // document information +}; + +AbiWordWorker::AbiWordWorker(void) : m_ioDevice(NULL), m_streamOut(NULL), + m_paperBorderTop(0.0),m_paperBorderLeft(0.0), + m_paperBorderBottom(0.0),m_paperBorderRight(0.0) +{ +} + +TQString AbiWordWorker::escapeAbiWordText(const TQString& strText) const +{ + // Escape quotes (needed in attributes) + // Escape apostrophs (allowed by XML) + return KWEFUtil::EscapeSgmlText(NULL,strText,true,true); +} + +bool AbiWordWorker::doOpenFile(const TQString& filenameOut, const TQString& ) +{ + kdDebug(30506) << "Opening file: " << filenameOut + << " (in AbiWordWorker::doOpenFile)" << endl; + //Find the last extension + TQString strExt; + const int result=filenameOut.findRev('.'); + if (result>=0) + { + strExt=filenameOut.mid(result); + } + + TQString strMimeType; // Mime type of the compressor + + if ((strExt==".gz")||(strExt==".GZ") //in case of .abw.gz (logical extension) + ||(strExt==".zabw")||(strExt==".ZABW")) //in case of .zabw (extension used prioritary with AbiWord) + { + // Compressed with gzip + strMimeType="application/x-gzip"; + } + else if ((strExt==".bz2")||(strExt==".BZ2") //in case of .abw.bz2 (logical extension) + ||(strExt==".bzabw")||(strExt==".BZABW")) //in case of .bzabw (extension used prioritary with AbiWord) + { + // Compressed with bzip2 + strMimeType="application/x-bzip2"; + } + else + { + // No compression + strMimeType="text/plain"; + } + + kdDebug(30506) << "Compression: " << strMimeType << endl; + + m_ioDevice = KFilterDev::deviceForFile(filenameOut,strMimeType); + + if (!m_ioDevice) + { + kdError(30506) << "No output file! Aborting!" << endl; + return false; + } + + if ( !m_ioDevice->open (IO_WriteOnly) ) + { + kdError(30506) << "Unable to open output file! Aborting!" << endl; + return false; + } + + m_streamOut=new TQTextStream(m_ioDevice); + + // We only export in UTF-8 (are there AbiWord ports that cannot read UTF-8? Be careful SVG uses UTF-8 too!) + m_streamOut->setEncoding( TQTextStream::UnicodeUTF8 ); + return true; +} + +bool AbiWordWorker::doCloseFile(void) +{ + delete m_streamOut; + m_streamOut=NULL; + if (m_ioDevice) + m_ioDevice->close(); + return (m_ioDevice); +} + +bool AbiWordWorker::doOpenDocument(void) +{ + kdDebug(30506)<< "AbiWordWorker::doOpenDocument" << endl; + // Make the file header + + // First the XML header in UTF-8 version + // (AbiWord and QT handle UTF-8 well, so we stay with this encoding!) + *m_streamOut << "\n"; + + // NOTE: AbiWord CVS 2002-02-?? has a new DOCTYPE + *m_streamOut << "\n"; + + // First magic: "\n"; + // Second magic: "\n"; + // We have chosen NOT to have the full comment header that AbiWord files normally have. + // ### TODO: perhaps we should add the comment: do not edit the file + *m_streamOut << "\n"; + + + return true; +} + +void AbiWordWorker::writePictureData(const TQString& koStoreName, const TQString& keyName) +{ + kdDebug(30506) << "AbiWordWorker::writeImageData" << endl; + + TQByteArray image; + + TQString strExtension(koStoreName.lower()); + const int result=koStoreName.findRev("."); + if (result>=0) + { + strExtension=koStoreName.mid(result+1); + } + + bool isImageLoaded=false; + + if (strExtension=="png") + { + isImageLoaded=loadSubFile(koStoreName,image); + } + else + { + // All other picture types must be converted to PNG + // (yes, even JPEG, SVG or WMF!) + isImageLoaded=loadAndConvertToImage(koStoreName,strExtension,"PNG",image); + } + + if (isImageLoaded) + { + *m_streamOut << "\n"; + + TQCString base64=KCodecs::base64Encode(image,true); + + *m_streamOut << base64 << "\n"; // TQCString is taken as Latin1 by TQTextStream + + *m_streamOut << "\n"; + } + else + { + kdWarning(30506) << "Unable to load picture: " << koStoreName << endl; + } +} + +bool AbiWordWorker::doCloseDocument(void) +{ + // Before writing the element, + // we must be sure that we have data and that we can retrieve it. + + if (m_kwordLeader && !m_mapPictureData.isEmpty()) + { + *m_streamOut << "\n"; + + TQMap::ConstIterator it; + TQMap::ConstIterator end(m_mapPictureData.end()); + // all images first + for (it=m_mapPictureData.begin(); it!=end; ++it) + { + // Warning: do not mix up KWord's key and the iterator's key! + writePictureData(it.key(),it.data().filename()); + } + + *m_streamOut << "\n"; + } + + *m_streamOut << "\n"; //Close the file for XML + return true; +} + +bool AbiWordWorker::doOpenTextFrameSet(void) +{ + *m_streamOut << "
\n"; + return true; +} + +bool AbiWordWorker::doCloseTextFrameSet(void) +{ + *m_streamOut << "
\n"; + return true; +} + +bool AbiWordWorker::doOpenStyles(void) +{ + *m_streamOut << "\n"; + return true; +} + +bool AbiWordWorker::doCloseStyles(void) +{ + *m_streamOut << "\n"; + return true; +} + +TQString AbiWordWorker::textFormatToAbiProps(const TextFormatting& formatOrigin, + const TextFormatting& formatData, const bool force) const +{ + // TODO: rename variable formatData + TQString strElement; // TODO: rename this variable + + // Font name + TQString fontName = formatData.fontName; + if ( !fontName.isEmpty() + && (force || (formatOrigin.fontName!=formatData.fontName))) + { + strElement+="font-family: "; + strElement+= escapeAbiWordText(fontName); // TODO: add alternative font names + strElement+="; "; + } + + if (force || (formatOrigin.italic!=formatData.italic)) + { + // Font style + strElement+="font-style: "; + if ( formatData.italic ) + { + strElement+="italic"; + } + else + { + strElement+="normal"; + } + strElement+="; "; + } + + if (force || ((formatOrigin.weight>=75)!=(formatData.weight>=75))) + { + strElement+="font-weight: "; + if ( formatData.weight >= 75 ) + { + strElement+="bold"; + } + else + { + strElement+="normal"; + } + strElement+="; "; + } + + if (force || (formatOrigin.fontSize!=formatData.fontSize)) + { + const int size=formatData.fontSize; + if (size>0) + { + // We use absolute font sizes. + strElement+="font-size: "; + strElement+=TQString::number(size,10); + strElement+="pt; "; + } + } + + if (force || (formatOrigin.fgColor!=formatData.fgColor)) + { + if ( formatData.fgColor.isValid() ) + { + // Give colour + strElement+="color: "; + + // No leading # (unlike CSS2) + // We must have two hex digits for each colour channel! + const int red=formatData.fgColor.red(); + strElement += TQString::number((red&0xf0)>>4,16); + strElement += TQString::number(red&0x0f,16); + + const int green=formatData.fgColor.green(); + strElement += TQString::number((green&0xf0)>>4,16); + strElement += TQString::number(green&0x0f,16); + + const int blue=formatData.fgColor.blue(); + strElement += TQString::number((blue&0xf0)>>4,16); + strElement += TQString::number(blue&0x0f,16); + + strElement+="; "; + } + } + + if (force || (formatOrigin.bgColor!=formatData.bgColor)) + { + if ( formatData.bgColor.isValid() ) + { + // Give background colour + strElement+="bgcolor: "; + + // No leading # (unlike CSS2) + // We must have two hex digits for each colour channel! + const int red=formatData.bgColor.red(); + strElement += TQString::number((red&0xf0)>>4,16); + strElement += TQString::number(red&0x0f,16); + + const int green=formatData.bgColor.green(); + strElement += TQString::number((green&0xf0)>>4,16); + strElement += TQString::number(green&0x0f,16); + + const int blue=formatData.bgColor.blue(); + strElement += TQString::number((blue&0xf0)>>4,16); + strElement += TQString::number(blue&0x0f,16); + + strElement+="; "; + } + } + + if (force || (formatOrigin.underline!=formatData.underline) + || (formatOrigin.strikeout!=formatData.strikeout)) + { + strElement+="text-decoration: "; + if ( formatData.underline ) + { + strElement+="underline"; + } + else if ( formatData.strikeout ) + { + strElement+="line-through"; + } + else + { + strElement+="none"; + } + strElement+="; "; + } + + return strElement; +} + +bool AbiWordWorker::makeTable(const FrameAnchor& anchor) +{ +#if 0 + *m_streamOut << "

\n"; // Close previous paragraph ### TODO: do it correctly like for HTML + *m_streamOut << "\n"; +#endif + + TQValueList::ConstIterator itCell; + for (itCell=anchor.table.cellList.begin(); + itCell!=anchor.table.cellList.end(); itCell++) + { +#if 0 + // ### TODO: rowspan, colspan + + // AbiWord seems to work by attaching to the cell borders + *m_streamOut << "\n"; +#endif + if (!doFullAllParagraphs(*(*itCell).paraList)) + { + return false; + } +#if 0 + *m_streamOut << "\n"; +#endif + } +#if 0 + *m_streamOut << "
\n"; + *m_streamOut << "

\n"; // Re-open the "previous" paragraph ### TODO: do it correctly like for HTML +#endif + return true; +} + +bool AbiWordWorker::makePicture(const FrameAnchor& anchor) +{ + kdDebug(30506) << "New image/clipart: " << anchor.picture.koStoreName + << " , " << anchor.picture.key.toString() << endl; + + const double height=anchor.frame.bottom - anchor.frame.top; + const double width =anchor.frame.right - anchor.frame.left; + + // TODO: we are only using the filename, not the rest of the key + // TODO: (bad if there are two images of the same name, but of a different key) + *m_streamOut << ""; // NO end of line! + // TODO: other props for image + + m_mapPictureData[anchor.picture.koStoreName]=anchor.picture.key; + + return true; +} + +void AbiWordWorker::writeAbiProps (const TextFormatting& formatLayout, const TextFormatting& format) +{ + TQString abiprops=textFormatToAbiProps(formatLayout,format,false); + + // Erase the last semi-comma (as in CSS2, semi-commas only separate instructions and do not terminate them) + const int result=abiprops.findRev(";"); + + if (result>=0) + { + // Remove the last semi-comma and the space thereafter + abiprops.remove(result,2); + } + + if (!abiprops.isEmpty()) + { + *m_streamOut << " props=\"" << abiprops << "\""; + } +} + +void AbiWordWorker::processNormalText ( const TQString ¶Text, + const TextFormatting& formatLayout, + const FormatData& formatData) +{ + // Retrieve text and escape it + TQString partialText=escapeAbiWordText(paraText.mid(formatData.pos,formatData.len)); + + // Replace line feeds by line breaks + int pos; + while ((pos=partialText.find(TQChar(10)))>-1) + { + partialText.replace(pos,1,"
"); + } + + if (formatData.text.missing) + { + // It's just normal text, so we do not need a element! + *m_streamOut << partialText; + } + else + { // Text with properties, so use a element! + *m_streamOut << "" << partialText << ""; + } +} + +void AbiWordWorker::processVariable ( const TQString&, + const TextFormatting& formatLayout, + const FormatData& formatData) +{ + if (0==formatData.variable.m_type) + { + // As AbiWord's field is inflexible, we cannot make the date custom + *m_streamOut << ""; + } + else if (2==formatData.variable.m_type) + { + // As AbiWord's field is inflexible, we cannot make the time custom + *m_streamOut << ""; + } + else if (4==formatData.variable.m_type) + { + // As AbiWord's field is inflexible, we cannot make the time custom + TQString strFieldType; + if (formatData.variable.isPageNumber()) + { + strFieldType="page_number"; + } + else if (formatData.variable.isPageCount()) + { + strFieldType="page_count"; + } + if (strFieldType.isEmpty()) + { + // Unknown subtype, therefore write out the result + *m_streamOut << formatData.variable.m_text; + } + else + { + *m_streamOut << ""; + } + } + else if (9==formatData.variable.m_type) + { + // A link + *m_streamOut << " has always a child + writeAbiProps(formatLayout,formatData.text); + *m_streamOut << ">" + << escapeAbiWordText(formatData.variable.getLinkName()) + << ""; + } +#if 0 + else if (11==(*paraFormatDataIt).variable.m_type) + { + // Footnote + TQString value = (*paraFormatDataIt).variable.getFootnoteValue(); + bool automatic = (*paraFormatDataIt).variable.getFootnoteAuto(); + TQValueList *paraList = (*paraFormatDataIt).variable.getFootnotePara(); + if( paraList ) + { + TQString fstr; + TQValueList::ConstIterator it; + for (it=paraList->begin();it!=paraList->end();it++) + fstr += ProcessParagraphData( (*it).text, (*it).layout,(*it).formattingList); + str += "{\\super "; + str += automatic ? "\\chftn " : value; + str += "{\\footnote "; + str += "{\\super "; + str += automatic ? "\\chftn " : value; + str += fstr; + str += " }"; + str += " }"; + str += " }"; + } + } +#endif + else + { + // Generic variable + *m_streamOut << formatData.variable.m_text; + } +} + +void AbiWordWorker::processAnchor ( const TQString&, + const TextFormatting& /*formatLayout*/, //TODO + const FormatData& formatData) +{ + // We have an image or a table + if ( (2==formatData.frameAnchor.type) // or + || (5==formatData.frameAnchor.type) ) // + { + makePicture(formatData.frameAnchor); + } + else if (6==formatData.frameAnchor.type) + { + makeTable(formatData.frameAnchor); + } + else + { + kdWarning(30506) << "Unsupported anchor type: " + << formatData.frameAnchor.type << endl; + } +} + +void AbiWordWorker::processParagraphData ( const TQString ¶Text, + const TextFormatting& formatLayout, + const ValueListFormatData ¶FormatDataList) +{ + if ( paraText.length () > 0 ) + { + ValueListFormatData::ConstIterator paraFormatDataIt; + + for ( paraFormatDataIt = paraFormatDataList.begin (); + paraFormatDataIt != paraFormatDataList.end (); + paraFormatDataIt++ ) + { + if (1==(*paraFormatDataIt).id) + { + processNormalText(paraText, formatLayout, (*paraFormatDataIt)); + } + else if (4==(*paraFormatDataIt).id) + { + processVariable(paraText, formatLayout, (*paraFormatDataIt)); + } + else if (6==(*paraFormatDataIt).id) + { + processAnchor(paraText, formatLayout, (*paraFormatDataIt)); + } + } + } +} + +TQString AbiWordWorker::layoutToCss(const LayoutData& layoutOrigin, + const LayoutData& layout, const bool force) const +{ + TQString props; + + if (force || (layoutOrigin.alignment!=layout.alignment)) + { + // Check if the current alignment is a valid one for AbiWord. + if ((layout.alignment == "left") || (layout.alignment == "right") + || (layout.alignment == "center") || (layout.alignment == "justify")) + { + props += "text-align:"; + props += layout.alignment; + props += "; "; + } + else if (layout.alignment == "auto") + { + // We assume a left alignment as AbiWord is not really bi-di (and this filter even less.) + props += "text-align:left; "; + } + else + { + kdWarning(30506) << "Unknown alignment: " << layout.alignment << endl; + } + } + + // TODO/FIXME: what if all tabulators must be erased? +#if 0 + // DEPRECATED! + if (!layout.tabulator.isEmpty() + && (force || (layoutOrigin.tabulator!=layout.tabulator))) + { + props += "tabstops:"; + props += layout.tabulator; + props += "; "; + } +#endif + if (!layout.tabulatorList.isEmpty() + && (force || (layoutOrigin.tabulatorList!=layout.tabulatorList) )) + { + props += "tabstops:"; + bool first=true; + TabulatorList::ConstIterator it; + TabulatorList::ConstIterator end(layout.tabulatorList.end()); + for (it=layout.tabulatorList.begin();it!=end;++it) + { + if (first) + { + first=false; + } + else + { + props += ","; + } + props += TQString::number((*it).m_ptpos); + props += "pt"; + + switch ((*it).m_type) + { + case 0: props += "/L"; break; + case 1: props += "/C"; break; + case 2: props += "/R"; break; + case 3: props += "/D"; break; + default: props += "/L"; + } + + props += "0"; // No filling + } + props += "; "; + } + + if ((layout.indentLeft>=0.0) + && (force || (layoutOrigin.indentLeft!=layout.indentLeft))) + { + props += TQString("margin-left:%1pt; ").arg(layout.indentLeft); + } + + if ((layout.indentRight>=0.0) + && (force || (layoutOrigin.indentRight!=layout.indentRight))) + { + props += TQString("margin-right:%1pt; ").arg(layout.indentRight); + } + + if (force || (layoutOrigin.indentLeft!=layout.indentLeft)) + { + props += "text-indent: "; + props += TQString::number(layout.indentFirst); + props += "pt; "; + } + + if ((layout.marginBottom>=0.0) + && ( force || ( layoutOrigin.marginBottom != layout.marginBottom ) ) ) + { + props += TQString("margin-bottom:%1pt; ").arg(layout.marginBottom); + } + + if ((layout.marginTop>=0.0) + && ( force || ( layoutOrigin.marginTop != layout.marginTop ) ) ) + { + props += TQString("margin-top:%1pt; ").arg(layout.marginTop); + } + + if (force + || ( layoutOrigin.lineSpacingType != layout.lineSpacingType ) + || ( layoutOrigin.lineSpacing != layout.lineSpacing ) ) + { + switch ( layout.lineSpacingType ) + { + case LayoutData::LS_CUSTOM: + { + // We have a custom line spacing (in points). However AbiWord cannot do it, so transform in "at-least" + props += "line-height=:"; + props += TQString::number( layout.lineSpacing ); // ### TODO: rounding? + props += "pt+; "; + break; + } + case LayoutData::LS_SINGLE: + { + props += "line-height:1.0; "; // One + break; + } + case LayoutData::LS_ONEANDHALF: + { + props += "line-height:1.5; "; // One-and-half + break; + } + case LayoutData::LS_DOUBLE: + { + props += "line-height:2.0; "; // Two + break; + } + case LayoutData::LS_MULTIPLE: + { + props += "line-height:"; + props += TQString::number( layout.lineSpacing ); // ### TODO: rounding? + props += "; "; + break; + } + case LayoutData::LS_FIXED: + { + // We have a fixed line height (in points) + props += "line-height:"; + props += TQString::number( layout.lineSpacing ); // ### TODO: rounding? + props += "pt; "; + break; + } + case LayoutData::LS_ATLEAST: + { + // We have an "at-least" line height (in points) + props += "line-height=:"; + props += TQString::number( layout.lineSpacing ); // ### TODO: rounding? + props += "pt+; "; // The + makes the difference + break; + } + default: + { + kdWarning(30506) << "Unsupported lineSpacingType: " << layout.lineSpacingType << " (Ignoring!)" << endl; + break; + } + } + } + + // Add all AbiWord properties collected in the element + props += textFormatToAbiProps(layoutOrigin.formatData.text,layout.formatData.text,force); + + return props; +} + +bool AbiWordWorker::doFullParagraph(const TQString& paraText, const LayoutData& layout, + const ValueListFormatData& paraFormatDataList) +{ + TQString style=layout.styleName; + + const LayoutData& styleLayout=m_styleMap[style]; + + TQString props=layoutToCss(styleLayout,layout,false); + + *m_streamOut << "=0) + { + // Remove the last semi-comma and the space thereafter + props.remove(result,2); + } + + *m_streamOut << " props=\"" << props << "\""; + } + *m_streamOut << ">"; //Warning: No trailing white space or else it's in the text!!! + + // Before processing the text, test if we have a page break + if (layout.pageBreakBefore) + { + // We have a page break before the paragraph + *m_streamOut << ""; + } + + processParagraphData(paraText, layout.formatData.text, paraFormatDataList); + + // Before closing the paragraph, test if we have a page break + if (layout.pageBreakAfter) + { + // We have a page break after the paragraph + *m_streamOut << ""; + } + + *m_streamOut << "

\n"; + return true; +} + +bool AbiWordWorker::doFullDefineStyle(LayoutData& layout) +{ + //Register style in the style map + m_styleMap[layout.styleName]=layout; + + *m_streamOut << "=0) + { + // Remove the last semi-comma and the space thereafter + abiprops.remove(result,2); + } + + *m_streamOut << " props=\"" << abiprops << "\""; + + *m_streamOut << "/>\n"; + + return true; +} + +bool AbiWordWorker::doFullPaperFormat(const int format, + const double width, const double height, const int orientation) +{ + TQString outputText = "\n"; // KWord has no page scale, so assume 100% + + m_pagesize=outputText; + return true; +} + +bool AbiWordWorker::doFullPaperBorders (const double top, const double left, + const double bottom, const double right) +{ + m_paperBorderTop=top; + m_paperBorderLeft=left; + m_paperBorderBottom=bottom; + m_paperBorderRight=right; + return true; +} + +bool AbiWordWorker::doCloseHead(void) +{ + if (!m_pagesize.isEmpty()) + { + *m_streamOut << m_pagesize; + } + return true; +} + +bool AbiWordWorker::doOpenSpellCheckIgnoreList (void) +{ + kdDebug(30506) << "AbiWordWorker::doOpenSpellCheckIgnoreList" << endl; + m_inIgnoreWords=false; // reset + return true; +} + +bool AbiWordWorker::doCloseSpellCheckIgnoreList (void) +{ + kdDebug(30506) << "AbiWordWorker::doCloseSpellCheckIgnoreList" << endl; + if (m_inIgnoreWords) + *m_streamOut << "
\n"; + return true; +} + +bool AbiWordWorker::doFullSpellCheckIgnoreWord (const TQString& ignoreword) +{ + kdDebug(30506) << "AbiWordWorker::doFullSpellCheckIgnoreWord: " << ignoreword << endl; + if (!m_inIgnoreWords) + { + *m_streamOut << "\n"; + m_inIgnoreWords=true; + } + *m_streamOut << " " << ignoreword << "\n"; + return true; +} + +// Similar to TQDateTime::toString, but guaranteed *not* to be translated +TQString AbiWordWorker::transformToTextDate(const TQDateTime& dt) +{ + if (dt.isValid()) + { + TQString result; + + const TQDate date(dt.date()); + + const char* dayName[7] = { "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" }; + const int dow = date.dayOfWeek() - 1; + if ((dow<0) || (dow>6)) + result += "Mon"; // Unknown day, rename it Monday. + else + result += dayName[dow]; + result += ' '; + + const char* monthName[12] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; + const int month = date.month() - 1; + if ((month<0) || (month>11)) + result += "Jan"; // Unknown month, rename it January + else + result += monthName[month]; + result += ' '; + + TQString temp; + + temp = "00"; + temp += TQString::number(date.day(), 10); + result += temp.right(2); + result += ' '; + + const TQTime time(dt.time()); + + temp = "00"; + temp += TQString::number(time.hour(), 10); + result += temp.right(2); + result += ':'; + + temp = "00"; + temp += TQString::number(time.minute(), 10); + result += temp.right(2); + result += ':'; + + temp = "00"; + temp += TQString::number(time.second(), 10); + result += temp.right(2); + result += ' '; + + temp = "0000"; + temp += TQString::number(date.year(), 10); + result += temp.right(4); + + return result; + } + else + { + // Invalid, so give back 1970-01-01 + return "Thu Jan 01 00:00:00 1970"; + } +} + +bool AbiWordWorker::doFullDocumentInfo(const KWEFDocumentInfo& docInfo) +{ + m_docInfo=docInfo; + + *m_streamOut << "\n"; + + // First all Dublin Core data + *m_streamOut << "application/x-abiword\n"; + if (!m_docInfo.title.isEmpty()) + { + *m_streamOut << "" << escapeAbiWordText(m_docInfo.title) << "\n"; + } + if (!m_docInfo.abstract.isEmpty()) + { + *m_streamOut << "" << escapeAbiWordText(m_docInfo.abstract) << "\n"; + } + + if ( !m_docInfo.keywords.isEmpty() ) + { + *m_streamOut << "" << escapeAbiWordText(m_docInfo.keywords) << "\n"; + } + if ( !m_docInfo.subject.isEmpty() ) + { + *m_streamOut << "" << escapeAbiWordText(m_docInfo.subject) << "\n"; + } + + // Say who we are (with the CVS revision number) in case we have a bug in our filter output! + *m_streamOut << "KWord Export Filter"; + + TQString strVersion("$Revision: 508787 $"); + // Remove the dollar signs + // (We don't want that the version number changes if the AbiWord file is itself put in a CVS storage.) + *m_streamOut << strVersion.mid(10).remove('$'); + + *m_streamOut << "\n"; + + TQDateTime now (TQDateTime::currentDateTime(Qt::UTC)); // current time in UTC + *m_streamOut << "" + << escapeAbiWordText(transformToTextDate(now)) + << "\n"; + + *m_streamOut << "\n"; + + return true; +} + + +// ========================================================================================== + +ABIWORDExport::ABIWORDExport(KoFilter */*parent*/, const char */*name*/, const TQStringList &) : + KoFilter() { +} + +KoFilter::ConversionStatus ABIWORDExport::convert( const TQCString& from, const TQCString& to ) +{ + if ( to != "application/x-abiword" || from != "application/x-kword" ) + { + return KoFilter::NotImplemented; + } + + // We need KimageIO's help in AbiWordWorker::convertUnknownImage + KImageIO::registerFormats(); + + AbiWordWorker* worker=new AbiWordWorker(); + + if (!worker) + { + kdError(30506) << "Cannot create Worker! Aborting!" << endl; + return KoFilter::StupidError; + } + + KWEFKWordLeader* leader=new KWEFKWordLeader(worker); + + if (!leader) + { + kdError(30506) << "Cannot create Worker! Aborting!" << endl; + delete worker; + return KoFilter::StupidError; + } + + KoFilter::ConversionStatus result=leader->convert(m_chain,from,to); + + delete leader; + delete worker; + + return result; +} diff --git a/filters/kword/abiword/abiwordimport.cc b/filters/kword/abiword/abiwordimport.cpp similarity index 100% rename from filters/kword/abiword/abiwordimport.cc rename to filters/kword/abiword/abiwordimport.cpp diff --git a/filters/kword/amipro/Makefile.am b/filters/kword/amipro/Makefile.am index f872af037..845049868 100644 --- a/filters/kword/amipro/Makefile.am +++ b/filters/kword/amipro/Makefile.am @@ -11,8 +11,8 @@ libamiproexport_la_LIBADD = $(KOFFICE_LIBS) ../libexport/libkwordexportfilters.l kde_module_LTLIBRARIES = libamiproimport.la libamiproexport.la -libamiproimport_la_SOURCES = amiproimport.cc amiproparser.cpp -libamiproexport_la_SOURCES = amiproexport.cc +libamiproimport_la_SOURCES = amiproimport.cpp amiproparser.cpp +libamiproexport_la_SOURCES = amiproexport.cpp noinst_HEADERS = amiproparser.h diff --git a/filters/kword/amipro/amiproexport.cc b/filters/kword/amipro/amiproexport.cpp similarity index 100% rename from filters/kword/amipro/amiproexport.cc rename to filters/kword/amipro/amiproexport.cpp diff --git a/filters/kword/amipro/amiproimport.cc b/filters/kword/amipro/amiproimport.cpp similarity index 100% rename from filters/kword/amipro/amiproimport.cc rename to filters/kword/amipro/amiproimport.cpp diff --git a/filters/kword/applixword/Makefile.am b/filters/kword/applixword/Makefile.am index 14e899746..7bc406c7d 100644 --- a/filters/kword/applixword/Makefile.am +++ b/filters/kword/applixword/Makefile.am @@ -7,7 +7,7 @@ libapplixwordimport_la_LDFLAGS = $(all_libraries) -module -avoid-version -no-und kde_module_LTLIBRARIES = libapplixwordimport.la -libapplixwordimport_la_SOURCES = applixwordimport.cc +libapplixwordimport_la_SOURCES = applixwordimport.cpp libapplixwordimport_la_LIBADD = $(KOFFICE_LIBS) noinst_HEADERS = applixwordimport.h diff --git a/filters/kword/applixword/applixwordimport.cc b/filters/kword/applixword/applixwordimport.cpp similarity index 100% rename from filters/kword/applixword/applixwordimport.cc rename to filters/kword/applixword/applixwordimport.cpp diff --git a/filters/kword/ascii/ExportDialog.cc b/filters/kword/ascii/ExportDialog.cpp similarity index 100% rename from filters/kword/ascii/ExportDialog.cc rename to filters/kword/ascii/ExportDialog.cpp diff --git a/filters/kword/ascii/ImportDialog.cc b/filters/kword/ascii/ImportDialog.cpp similarity index 100% rename from filters/kword/ascii/ImportDialog.cc rename to filters/kword/ascii/ImportDialog.cpp diff --git a/filters/kword/ascii/Makefile.am b/filters/kword/ascii/Makefile.am index 74b9dde20..22a5d5555 100644 --- a/filters/kword/ascii/Makefile.am +++ b/filters/kword/ascii/Makefile.am @@ -12,9 +12,9 @@ libasciiexport_la_LIBADD = $(KOFFICE_LIBS) ../libexport/libkwordexportfilters.la kde_module_LTLIBRARIES = libasciiimport.la libasciiexport.la -libasciiimport_la_SOURCES = asciiimport.cc ImportDialogUI.ui ImportDialog.cc +libasciiimport_la_SOURCES = asciiimport.cpp ImportDialogUI.ui ImportDialog.cpp -libasciiexport_la_SOURCES = asciiexport.cc ExportDialogUI.ui ExportDialog.cc +libasciiexport_la_SOURCES = asciiexport.cpp ExportDialogUI.ui ExportDialog.cpp noinst_HEADERS = asciiimport.h ImportDialog.h asciiexport.h ExportDialog.h diff --git a/filters/kword/ascii/asciiexport.cc b/filters/kword/ascii/asciiexport.cpp similarity index 100% rename from filters/kword/ascii/asciiexport.cc rename to filters/kword/ascii/asciiexport.cpp diff --git a/filters/kword/ascii/asciiimport.cc b/filters/kword/ascii/asciiimport.cpp similarity index 100% rename from filters/kword/ascii/asciiimport.cc rename to filters/kword/ascii/asciiimport.cpp diff --git a/filters/kword/docbook/Makefile.am b/filters/kword/docbook/Makefile.am index 9ce299cbb..93967bc11 100644 --- a/filters/kword/docbook/Makefile.am +++ b/filters/kword/docbook/Makefile.am @@ -8,7 +8,7 @@ libdocbookexport_la_LIBADD = $(KOFFICE_LIBS) ../libexport/libkwordexportfilters. kde_module_LTLIBRARIES = libdocbookexport.la -libdocbookexport_la_SOURCES = docbookexport.cc +libdocbookexport_la_SOURCES = docbookexport.cpp noinst_HEADERS = docbookexport.h diff --git a/filters/kword/docbook/docbookexport.cc b/filters/kword/docbook/docbookexport.cpp similarity index 100% rename from filters/kword/docbook/docbookexport.cc rename to filters/kword/docbook/docbookexport.cpp diff --git a/filters/kword/html/export/ExportBasic.cc b/filters/kword/html/export/ExportBasic.cpp similarity index 100% rename from filters/kword/html/export/ExportBasic.cc rename to filters/kword/html/export/ExportBasic.cpp diff --git a/filters/kword/html/export/ExportCss.cc b/filters/kword/html/export/ExportCss.cpp similarity index 100% rename from filters/kword/html/export/ExportCss.cc rename to filters/kword/html/export/ExportCss.cpp diff --git a/filters/kword/html/export/ExportDialog.cc b/filters/kword/html/export/ExportDialog.cpp similarity index 100% rename from filters/kword/html/export/ExportDialog.cc rename to filters/kword/html/export/ExportDialog.cpp diff --git a/filters/kword/html/export/ExportDocStruct.cc b/filters/kword/html/export/ExportDocStruct.cpp similarity index 100% rename from filters/kword/html/export/ExportDocStruct.cc rename to filters/kword/html/export/ExportDocStruct.cpp diff --git a/filters/kword/html/export/ExportFilter.cc b/filters/kword/html/export/ExportFilter.cpp similarity index 100% rename from filters/kword/html/export/ExportFilter.cc rename to filters/kword/html/export/ExportFilter.cpp diff --git a/filters/kword/html/export/Makefile.am b/filters/kword/html/export/Makefile.am index e35b70a5a..280dbb5e4 100644 --- a/filters/kword/html/export/Makefile.am +++ b/filters/kword/html/export/Makefile.am @@ -10,8 +10,8 @@ libhtmlexport_la_LIBADD = $(KOFFICE_LIBS) ../../libexport/libkwordexportfilters. kde_module_LTLIBRARIES = libhtmlexport.la -libhtmlexport_la_SOURCES = htmlexport.cc ExportDialog.cc ExportDialogUI.ui \ -ExportFilter.cc ExportCss.cc ExportDocStruct.cc ExportBasic.cc +libhtmlexport_la_SOURCES = htmlexport.cpp ExportDialog.cpp ExportDialogUI.ui \ +ExportFilter.cpp ExportCss.cpp ExportDocStruct.cpp ExportBasic.cpp noinst_HEADERS = htmlexport.h ExportDialog.h ExportDialogUI.h ExportFilter.h \ ExportCss.h ExportDocStruct.h ExportBasic.h diff --git a/filters/kword/html/export/htmlexport.cc b/filters/kword/html/export/htmlexport.cc deleted file mode 100644 index 285735176..000000000 --- a/filters/kword/html/export/htmlexport.cc +++ /dev/null @@ -1,127 +0,0 @@ -/* - This file is part of the KDE project - Copyright (C) 2001, 2002, 2004 Nicolas GOUTTE - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. -*/ - -/* - This file is based on the old file: - /home/kde/koffice/filters/kword/ascii/asciiexport.cc - - The old file was copyrighted by - Copyright (C) 1998, 1999 Reginald Stadlbauer - Copyright (c) 2000 ID-PRO Deutschland GmbH. All rights reserved. - Contact: Wolf-Michael Bolle - - The old file was licensed under the terms of the GNU Library General Public - License version 2. -*/ - -#include - -#include -#include -#include -#include - -#include -#include - -#include "ExportDialog.h" -#include "ExportFilter.h" -#include "ExportCss.h" -#include "ExportBasic.h" -#include "ExportDocStruct.h" - -#include -#include - -typedef KGenericFactory HTMLExportFactory; -K_EXPORT_COMPONENT_FACTORY( libhtmlexport, HTMLExportFactory( "kofficefilters" ) ) - -// -// HTMLExport -// - -HTMLExport::HTMLExport(KoFilter *, const char *, const TQStringList &) : - KoFilter() { -} - -KoFilter::ConversionStatus HTMLExport::convert( const TQCString& from, const TQCString& to ) -{ - if ((from != "application/x-kword") || (to != "text/html")) - { - return KoFilter::NotImplemented; - } - - bool batch=false; - if ( m_chain->manager() ) - batch = m_chain->manager()->getBatchMode(); - - HtmlWorker* worker; - - if (batch) - { - worker=new HtmlCssWorker(); - worker->setXML(true); - worker->setCodec(TQTextCodec::codecForName("UTF-8")); - } - else - { - HtmlExportDialog dialog; - - if (!dialog.exec()) - { - kdDebug(30503) << "Dialog was aborted! Aborting filter!" << endl; - return KoFilter::UserCancelled; - } - - const HtmlExportDialog::Mode mode = dialog.getMode(); - switch (mode) - { - case HtmlExportDialog::Light: - worker=new HtmlDocStructWorker(); - break; - case HtmlExportDialog::Basic: - worker=new HtmlBasicWorker(); - break; - case HtmlExportDialog::CustomCSS: - worker=new HtmlBasicWorker( dialog.cssURL() ); - break; - default: // Default CSS - worker=new HtmlCssWorker(); - } - - worker->setXML(dialog.isXHtml()); - worker->setCodec(dialog.getCodec()); - } - - KWEFKWordLeader* leader=new KWEFKWordLeader(worker); - - if (!leader) - { - kdError(30503) << "Cannot create Worker! Aborting!" << endl; - delete worker; - return KoFilter::StupidError; - } - KoFilter::ConversionStatus result=leader->convert(m_chain,from,to); - - delete leader; - delete worker; - - return result; -} diff --git a/filters/kword/html/export/htmlexport.cpp b/filters/kword/html/export/htmlexport.cpp new file mode 100644 index 000000000..76d780527 --- /dev/null +++ b/filters/kword/html/export/htmlexport.cpp @@ -0,0 +1,127 @@ +/* + This file is part of the KDE project + Copyright (C) 2001, 2002, 2004 Nicolas GOUTTE + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +/* + This file is based on the old file: + /home/kde/koffice/filters/kword/ascii/asciiexport.cpp + + The old file was copyrighted by + Copyright (C) 1998, 1999 Reginald Stadlbauer + Copyright (c) 2000 ID-PRO Deutschland GmbH. All rights reserved. + Contact: Wolf-Michael Bolle + + The old file was licensed under the terms of the GNU Library General Public + License version 2. +*/ + +#include + +#include +#include +#include +#include + +#include +#include + +#include "ExportDialog.h" +#include "ExportFilter.h" +#include "ExportCss.h" +#include "ExportBasic.h" +#include "ExportDocStruct.h" + +#include +#include + +typedef KGenericFactory HTMLExportFactory; +K_EXPORT_COMPONENT_FACTORY( libhtmlexport, HTMLExportFactory( "kofficefilters" ) ) + +// +// HTMLExport +// + +HTMLExport::HTMLExport(KoFilter *, const char *, const TQStringList &) : + KoFilter() { +} + +KoFilter::ConversionStatus HTMLExport::convert( const TQCString& from, const TQCString& to ) +{ + if ((from != "application/x-kword") || (to != "text/html")) + { + return KoFilter::NotImplemented; + } + + bool batch=false; + if ( m_chain->manager() ) + batch = m_chain->manager()->getBatchMode(); + + HtmlWorker* worker; + + if (batch) + { + worker=new HtmlCssWorker(); + worker->setXML(true); + worker->setCodec(TQTextCodec::codecForName("UTF-8")); + } + else + { + HtmlExportDialog dialog; + + if (!dialog.exec()) + { + kdDebug(30503) << "Dialog was aborted! Aborting filter!" << endl; + return KoFilter::UserCancelled; + } + + const HtmlExportDialog::Mode mode = dialog.getMode(); + switch (mode) + { + case HtmlExportDialog::Light: + worker=new HtmlDocStructWorker(); + break; + case HtmlExportDialog::Basic: + worker=new HtmlBasicWorker(); + break; + case HtmlExportDialog::CustomCSS: + worker=new HtmlBasicWorker( dialog.cssURL() ); + break; + default: // Default CSS + worker=new HtmlCssWorker(); + } + + worker->setXML(dialog.isXHtml()); + worker->setCodec(dialog.getCodec()); + } + + KWEFKWordLeader* leader=new KWEFKWordLeader(worker); + + if (!leader) + { + kdError(30503) << "Cannot create Worker! Aborting!" << endl; + delete worker; + return KoFilter::StupidError; + } + KoFilter::ConversionStatus result=leader->convert(m_chain,from,to); + + delete leader; + delete worker; + + return result; +} diff --git a/filters/kword/latex/export/Makefile.am b/filters/kword/latex/export/Makefile.am index 75552b425..85488d7bd 100644 --- a/filters/kword/latex/export/Makefile.am +++ b/filters/kword/latex/export/Makefile.am @@ -8,17 +8,17 @@ libkwordlatexexport_la_LIBADD = $(KOFFICE_LIBS) $(LIB_KFORMULA) $(LIBMAGICK_LIB kde_module_LTLIBRARIES = libkwordlatexexport.la -libkwordlatexexport_la_SOURCES = anchor.cc config.cc document.cc element.cc fileheader.cc \ - latexexportdia.ui footnote.cc format.cc formula.cc key.cc \ - kwordlatexexportdia.cc latexexport.cc latexexportIface.cc \ - latexexportIface.skel layout.cc listtable.cc para.cc \ - pixmapFrame.cc table.cc \ - textFrame.cc textformat.cc textzone.cc variableformat.cc \ - variablezone.cc xml2latexparser.cc xmlparser.cc +libkwordlatexexport_la_SOURCES = anchor.cpp config.cpp document.cpp element.cpp fileheader.cpp \ + latexexportdia.ui footnote.cpp format.cpp formula.cpp key.cpp \ + kwordlatexexportdia.cpp latexexport.cpp latexexportIface.cpp \ + latexexportIface.skel layout.cpp listtable.cpp para.cpp \ + pixmapFrame.cpp table.cpp \ + textFrame.cpp textformat.cpp textzone.cpp variableformat.cpp \ + variablezone.cpp xml2latexparser.cpp xmlparser.cpp ######## Debug #check_PROGRAMS = texlauncher -#texlauncher_SOURCES = texlauncher.cc +#texlauncher_SOURCES = texlauncher.cpp #texlauncher_LDADD = liblatexexport.la #texlauncher_LDFLAGS = $(all_libraries) $(KDE_RPATH) $(LIB_TQT) -lDCOP $(LIB_TDECORE) $(LIB_TDEUI) -ltdefx $(LIB_TDEIO) -ltdetexteditor diff --git a/filters/kword/latex/export/anchor.cc b/filters/kword/latex/export/anchor.cpp similarity index 100% rename from filters/kword/latex/export/anchor.cc rename to filters/kword/latex/export/anchor.cpp diff --git a/filters/kword/latex/export/config.cc b/filters/kword/latex/export/config.cpp similarity index 100% rename from filters/kword/latex/export/config.cc rename to filters/kword/latex/export/config.cpp diff --git a/filters/kword/latex/export/document.cc b/filters/kword/latex/export/document.cpp similarity index 100% rename from filters/kword/latex/export/document.cc rename to filters/kword/latex/export/document.cpp diff --git a/filters/kword/latex/export/element.cc b/filters/kword/latex/export/element.cpp similarity index 100% rename from filters/kword/latex/export/element.cc rename to filters/kword/latex/export/element.cpp diff --git a/filters/kword/latex/export/fileheader.cc b/filters/kword/latex/export/fileheader.cpp similarity index 100% rename from filters/kword/latex/export/fileheader.cc rename to filters/kword/latex/export/fileheader.cpp diff --git a/filters/kword/latex/export/footnote.cc b/filters/kword/latex/export/footnote.cpp similarity index 100% rename from filters/kword/latex/export/footnote.cc rename to filters/kword/latex/export/footnote.cpp diff --git a/filters/kword/latex/export/format.cc b/filters/kword/latex/export/format.cpp similarity index 100% rename from filters/kword/latex/export/format.cc rename to filters/kword/latex/export/format.cpp diff --git a/filters/kword/latex/export/formula.cc b/filters/kword/latex/export/formula.cpp similarity index 100% rename from filters/kword/latex/export/formula.cc rename to filters/kword/latex/export/formula.cpp diff --git a/filters/kword/latex/export/key.cc b/filters/kword/latex/export/key.cpp similarity index 100% rename from filters/kword/latex/export/key.cc rename to filters/kword/latex/export/key.cpp diff --git a/filters/kword/latex/export/kwordlatexexportdia.cc b/filters/kword/latex/export/kwordlatexexportdia.cpp similarity index 100% rename from filters/kword/latex/export/kwordlatexexportdia.cc rename to filters/kword/latex/export/kwordlatexexportdia.cpp diff --git a/filters/kword/latex/export/latexexport.cc b/filters/kword/latex/export/latexexport.cpp similarity index 100% rename from filters/kword/latex/export/latexexport.cc rename to filters/kword/latex/export/latexexport.cpp diff --git a/filters/kword/latex/export/latexexportIface.cc b/filters/kword/latex/export/latexexportIface.cpp similarity index 100% rename from filters/kword/latex/export/latexexportIface.cc rename to filters/kword/latex/export/latexexportIface.cpp diff --git a/filters/kword/latex/export/layout.cc b/filters/kword/latex/export/layout.cpp similarity index 100% rename from filters/kword/latex/export/layout.cc rename to filters/kword/latex/export/layout.cpp diff --git a/filters/kword/latex/export/listeformat.cc b/filters/kword/latex/export/listeformat.cpp similarity index 100% rename from filters/kword/latex/export/listeformat.cc rename to filters/kword/latex/export/listeformat.cpp diff --git a/filters/kword/latex/export/listelement.cc b/filters/kword/latex/export/listelement.cpp similarity index 100% rename from filters/kword/latex/export/listelement.cc rename to filters/kword/latex/export/listelement.cpp diff --git a/filters/kword/latex/export/listepara.cc b/filters/kword/latex/export/listepara.cpp similarity index 100% rename from filters/kword/latex/export/listepara.cc rename to filters/kword/latex/export/listepara.cpp diff --git a/filters/kword/latex/export/listtable.cc b/filters/kword/latex/export/listtable.cpp similarity index 100% rename from filters/kword/latex/export/listtable.cc rename to filters/kword/latex/export/listtable.cpp diff --git a/filters/kword/latex/export/para.cc b/filters/kword/latex/export/para.cpp similarity index 100% rename from filters/kword/latex/export/para.cc rename to filters/kword/latex/export/para.cpp diff --git a/filters/kword/latex/export/pixmapFrame.cc b/filters/kword/latex/export/pixmapFrame.cpp similarity index 100% rename from filters/kword/latex/export/pixmapFrame.cc rename to filters/kword/latex/export/pixmapFrame.cpp diff --git a/filters/kword/latex/export/table.cc b/filters/kword/latex/export/table.cpp similarity index 100% rename from filters/kword/latex/export/table.cc rename to filters/kword/latex/export/table.cpp diff --git a/filters/kword/latex/export/texlauncher.cc b/filters/kword/latex/export/texlauncher.cpp similarity index 100% rename from filters/kword/latex/export/texlauncher.cc rename to filters/kword/latex/export/texlauncher.cpp diff --git a/filters/kword/latex/export/textFrame.cc b/filters/kword/latex/export/textFrame.cpp similarity index 100% rename from filters/kword/latex/export/textFrame.cc rename to filters/kword/latex/export/textFrame.cpp diff --git a/filters/kword/latex/export/textformat.cc b/filters/kword/latex/export/textformat.cpp similarity index 100% rename from filters/kword/latex/export/textformat.cc rename to filters/kword/latex/export/textformat.cpp diff --git a/filters/kword/latex/export/textzone.cc b/filters/kword/latex/export/textzone.cpp similarity index 100% rename from filters/kword/latex/export/textzone.cc rename to filters/kword/latex/export/textzone.cpp diff --git a/filters/kword/latex/export/variableformat.cc b/filters/kword/latex/export/variableformat.cpp similarity index 100% rename from filters/kword/latex/export/variableformat.cc rename to filters/kword/latex/export/variableformat.cpp diff --git a/filters/kword/latex/export/variablezone.cc b/filters/kword/latex/export/variablezone.cpp similarity index 100% rename from filters/kword/latex/export/variablezone.cc rename to filters/kword/latex/export/variablezone.cpp diff --git a/filters/kword/latex/export/xml2latexparser.cc b/filters/kword/latex/export/xml2latexparser.cpp similarity index 100% rename from filters/kword/latex/export/xml2latexparser.cc rename to filters/kword/latex/export/xml2latexparser.cpp diff --git a/filters/kword/latex/export/xmlparser.cc b/filters/kword/latex/export/xmlparser.cpp similarity index 100% rename from filters/kword/latex/export/xmlparser.cc rename to filters/kword/latex/export/xmlparser.cpp diff --git a/filters/kword/latex/import/Makefile.am b/filters/kword/latex/import/Makefile.am index e55af45a2..f766e72a8 100644 --- a/filters/kword/latex/import/Makefile.am +++ b/filters/kword/latex/import/Makefile.am @@ -10,14 +10,14 @@ libkwordlateximport_la_LIBADD = $(KOFFICE_LIBS) parser/liblatexparser.la generat kde_module_LTLIBRARIES = libkwordlateximport.la -libkwordlateximport_la_SOURCES = config.cc lateximport.cc \ - lateximportdia.cc lateximportdia.skel +libkwordlateximport_la_SOURCES = config.cpp lateximport.cpp \ + lateximportdia.cpp lateximportdia.skel noinst_HEADERS = config.h lateximport.h lateximportdia.h ######## Debug #check_PROGRAMS = texlauncher -#texlauncher_SOURCES = texlauncher.cc +#texlauncher_SOURCES = texlauncher.cpp #texlauncher_LDADD = liblatexexport.la #texlauncher_LDFLAGS = $(all_libraries) $(KDE_RPATH) $(LIB_TQT) -lDCOP $(LIB_TDECORE) $(LIB_TDEUI) -ltdefx $(LIB_TDEIO) -ltdetexteditor diff --git a/filters/kword/latex/import/config.cc b/filters/kword/latex/import/config.cpp similarity index 100% rename from filters/kword/latex/import/config.cc rename to filters/kword/latex/import/config.cpp diff --git a/filters/kword/latex/import/generator/Makefile.am b/filters/kword/latex/import/generator/Makefile.am index 089014e34..308e11c69 100644 --- a/filters/kword/latex/import/generator/Makefile.am +++ b/filters/kword/latex/import/generator/Makefile.am @@ -8,7 +8,7 @@ liblatexgenerator_la_LIBADD = -lm $(KOFFICE_LIBS) kde_module_LTLIBRARIES = liblatexgenerator.la -liblatexgenerator_la_SOURCES = body.cc document.cc kwordgenerator.cc latex.cc paragraph.cc +liblatexgenerator_la_SOURCES = body.cpp document.cpp kwordgenerator.cpp latex.cpp paragraph.cpp noinst_HEADERS = body.h document.h kwordgenerator.h latex.h paragraph.h diff --git a/filters/kword/latex/import/generator/body.cc b/filters/kword/latex/import/generator/body.cpp similarity index 100% rename from filters/kword/latex/import/generator/body.cc rename to filters/kword/latex/import/generator/body.cpp diff --git a/filters/kword/latex/import/generator/document.cc b/filters/kword/latex/import/generator/document.cpp similarity index 100% rename from filters/kword/latex/import/generator/document.cc rename to filters/kword/latex/import/generator/document.cpp diff --git a/filters/kword/latex/import/generator/kwordgenerator.cc b/filters/kword/latex/import/generator/kwordgenerator.cpp similarity index 100% rename from filters/kword/latex/import/generator/kwordgenerator.cc rename to filters/kword/latex/import/generator/kwordgenerator.cpp diff --git a/filters/kword/latex/import/generator/latex.cc b/filters/kword/latex/import/generator/latex.cpp similarity index 100% rename from filters/kword/latex/import/generator/latex.cc rename to filters/kword/latex/import/generator/latex.cpp diff --git a/filters/kword/latex/import/generator/paragraph.cc b/filters/kword/latex/import/generator/paragraph.cpp similarity index 100% rename from filters/kword/latex/import/generator/paragraph.cc rename to filters/kword/latex/import/generator/paragraph.cpp diff --git a/filters/kword/latex/import/lateximport.cc b/filters/kword/latex/import/lateximport.cpp similarity index 100% rename from filters/kword/latex/import/lateximport.cc rename to filters/kword/latex/import/lateximport.cpp diff --git a/filters/kword/latex/import/lateximportdia.cc b/filters/kword/latex/import/lateximportdia.cc deleted file mode 100644 index c69b7e901..000000000 --- a/filters/kword/latex/import/lateximportdia.cc +++ /dev/null @@ -1,170 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2001 Robert JACOLIN - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. -*/ - -/* - This file is based on the file : - koffice/filters/kword/html/htmlexportdia.cc - Copyright (C) 2001 Nicolas Goutte - - which was based on the old file: - /home/kde/koffice/filters/kspread/csv/csvfilterdia.cc - - The old file was copyrighted by - Copyright (C) 1999 David Faure - - The old file was licensed under the terms of the GNU Library General Public - License version 2. -*/ - -#include -#include -#include -#include -#include -#include - -#include "latexparser.h" -#include "config.h" - -#include "generator/kwordgenerator.h" - -LATEXImportDia::LATEXImportDia(KoStore* out, TQWidget *parent, const char *name) : - KDialogBase(parent, name, true, i18n("Latex Import Filter Parameters"), - Ok|Cancel), - DCOPObject("FilterConfigDia"), _out(out) -{ - _out = out; - kapp->restoreOverrideCursor(); - createDialog(); - if(!kapp->dcopClient()->isRegistered() ) - { - kapp->dcopClient()->registerAs("FilterConfigDia"); - kapp->dcopClient()->setDefaultObject(objId()); - } -} - -void LATEXImportDia::createDialog() -{ - resize(size()); - TQWidget *page = new TQWidget( this ); - setMainWidget(page); - TQBoxLayout *mainLayout = new TQVBoxLayout(page, KDialog::marginHint(), KDialog::spacingHint()); - styleBox = new TQVButtonGroup(i18n("Document Style"), page); - mainLayout->addWidget(styleBox); - - /* First part */ - TQBoxLayout *styleLayout = new TQVBoxLayout(page); - - latexStyleRBtn = new TQRadioButton(i18n("Latex style"), styleBox); - styleLayout->addWidget(latexStyleRBtn); - - kwordStyleRBtn = new TQRadioButton(i18n("KWord style"), styleBox); - styleLayout->addWidget(kwordStyleRBtn); - - /*typeLabel = new ... - styleLayout->addWidget(typeLabel); - typeCBox = new ... - styleLayout->addWidget(typeCBox); - */ - styleBox->setExclusive(true); - styleBox->setButton(0); /* LATEX STYLE IS DEFAULT */ - styleLayout->activate(); - - /* Second part */ - langBox = new TQVButtonGroup(i18n("Language"), page); - mainLayout->addWidget(langBox); - - TQBoxLayout *langLayout = new TQVBoxLayout(langBox); - - unicodeRBtn = new TQRadioButton(i18n("Unicode"), langBox); - langLayout->addWidget(unicodeRBtn); - - latin1RBtn = new TQRadioButton(i18n("latin1"), langBox); - langLayout->addWidget(latin1RBtn); - - /*babelCheckBox = new ... - langLayout->addWidget(babelCheckBox); - - babelCBox = new ... - langLayout->addWidget(babelCBox); - */ - langBox->setExclusive(true); - langBox->setButton(1); /* LATIN1 IS THE DEFAULT. */ - langLayout->activate(); - - /* Third part */ - docBox = new TQVButtonGroup(i18n("Document Type"), page); - mainLayout->addWidget(docBox); - - TQBoxLayout *docLayout = new TQVBoxLayout(docBox); - - newDocRBtn = new TQRadioButton(i18n("New document"), docBox); - docLayout->addWidget(newDocRBtn); - - embededRBtn = new TQRadioButton(i18n("Embedded document"), docBox); - docLayout->addWidget(embededRBtn); - - docBox->setExclusive(true); - docBox->setButton(0); /* NEW DOC IS THE DEFAULT. */ - docLayout->activate(); - - /* Display the main layout */ - mainLayout->addStretch(5); - mainLayout->activate(); -} - -void LATEXImportDia::state() -{ - Config config; - - if(newDocRBtn == docBox->selected()) - config.setType(TYPE_DOC); - else if(embededRBtn == docBox->selected()) - config.setType(TYPE_EMBEDED); - - if(unicodeRBtn == langBox->selected()) - config.setEncoding(ENC_UNICODE); - else if(latin1RBtn == langBox->selected()) - config.setEncoding(ENC_LATIN1); - - /*if(latexStyleRBtn == styleBox->selected()) - config.result += "LATEX"; - else if(kwordStyleRBtn == styleBox->selected()) - result += "KWORD";*/ -} - -void LATEXImportDia::slotOk() -{ - hide(); - state(); - kdDebug(30522) << "LATEX FILTER --> BEGIN" << endl; - LatexParser parser(_fileIn); - TQPtrList* root = parser.parse(); - kdDebug(30522) << "---------- generate file -------------" << endl; - kdDebug(30522) << "command: " << root->count() << endl; - Element* elt; - for(elt = root->first(); elt; elt = root->next()) - { - elt->print(); - } - KwordGenerator generator(root); - generator.convert(_out); - kdDebug(30522) << "LATEX FILTER --> END" << endl; - reject(); -} diff --git a/filters/kword/latex/import/lateximportdia.cpp b/filters/kword/latex/import/lateximportdia.cpp new file mode 100644 index 000000000..f0dd908bd --- /dev/null +++ b/filters/kword/latex/import/lateximportdia.cpp @@ -0,0 +1,170 @@ +/* This file is part of the KDE project + Copyright (C) 2001 Robert JACOLIN + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +/* + This file is based on the file : + koffice/filters/kword/html/htmlexportdia.cpp + Copyright (C) 2001 Nicolas Goutte + + which was based on the old file: + /home/kde/koffice/filters/kspread/csv/csvfilterdia.cpp + + The old file was copyrighted by + Copyright (C) 1999 David Faure + + The old file was licensed under the terms of the GNU Library General Public + License version 2. +*/ + +#include +#include +#include +#include +#include +#include + +#include "latexparser.h" +#include "config.h" + +#include "generator/kwordgenerator.h" + +LATEXImportDia::LATEXImportDia(KoStore* out, TQWidget *parent, const char *name) : + KDialogBase(parent, name, true, i18n("Latex Import Filter Parameters"), + Ok|Cancel), + DCOPObject("FilterConfigDia"), _out(out) +{ + _out = out; + kapp->restoreOverrideCursor(); + createDialog(); + if(!kapp->dcopClient()->isRegistered() ) + { + kapp->dcopClient()->registerAs("FilterConfigDia"); + kapp->dcopClient()->setDefaultObject(objId()); + } +} + +void LATEXImportDia::createDialog() +{ + resize(size()); + TQWidget *page = new TQWidget( this ); + setMainWidget(page); + TQBoxLayout *mainLayout = new TQVBoxLayout(page, KDialog::marginHint(), KDialog::spacingHint()); + styleBox = new TQVButtonGroup(i18n("Document Style"), page); + mainLayout->addWidget(styleBox); + + /* First part */ + TQBoxLayout *styleLayout = new TQVBoxLayout(page); + + latexStyleRBtn = new TQRadioButton(i18n("Latex style"), styleBox); + styleLayout->addWidget(latexStyleRBtn); + + kwordStyleRBtn = new TQRadioButton(i18n("KWord style"), styleBox); + styleLayout->addWidget(kwordStyleRBtn); + + /*typeLabel = new ... + styleLayout->addWidget(typeLabel); + typeCBox = new ... + styleLayout->addWidget(typeCBox); + */ + styleBox->setExclusive(true); + styleBox->setButton(0); /* LATEX STYLE IS DEFAULT */ + styleLayout->activate(); + + /* Second part */ + langBox = new TQVButtonGroup(i18n("Language"), page); + mainLayout->addWidget(langBox); + + TQBoxLayout *langLayout = new TQVBoxLayout(langBox); + + unicodeRBtn = new TQRadioButton(i18n("Unicode"), langBox); + langLayout->addWidget(unicodeRBtn); + + latin1RBtn = new TQRadioButton(i18n("latin1"), langBox); + langLayout->addWidget(latin1RBtn); + + /*babelCheckBox = new ... + langLayout->addWidget(babelCheckBox); + + babelCBox = new ... + langLayout->addWidget(babelCBox); + */ + langBox->setExclusive(true); + langBox->setButton(1); /* LATIN1 IS THE DEFAULT. */ + langLayout->activate(); + + /* Third part */ + docBox = new TQVButtonGroup(i18n("Document Type"), page); + mainLayout->addWidget(docBox); + + TQBoxLayout *docLayout = new TQVBoxLayout(docBox); + + newDocRBtn = new TQRadioButton(i18n("New document"), docBox); + docLayout->addWidget(newDocRBtn); + + embededRBtn = new TQRadioButton(i18n("Embedded document"), docBox); + docLayout->addWidget(embededRBtn); + + docBox->setExclusive(true); + docBox->setButton(0); /* NEW DOC IS THE DEFAULT. */ + docLayout->activate(); + + /* Display the main layout */ + mainLayout->addStretch(5); + mainLayout->activate(); +} + +void LATEXImportDia::state() +{ + Config config; + + if(newDocRBtn == docBox->selected()) + config.setType(TYPE_DOC); + else if(embededRBtn == docBox->selected()) + config.setType(TYPE_EMBEDED); + + if(unicodeRBtn == langBox->selected()) + config.setEncoding(ENC_UNICODE); + else if(latin1RBtn == langBox->selected()) + config.setEncoding(ENC_LATIN1); + + /*if(latexStyleRBtn == styleBox->selected()) + config.result += "LATEX"; + else if(kwordStyleRBtn == styleBox->selected()) + result += "KWORD";*/ +} + +void LATEXImportDia::slotOk() +{ + hide(); + state(); + kdDebug(30522) << "LATEX FILTER --> BEGIN" << endl; + LatexParser parser(_fileIn); + TQPtrList* root = parser.parse(); + kdDebug(30522) << "---------- generate file -------------" << endl; + kdDebug(30522) << "command: " << root->count() << endl; + Element* elt; + for(elt = root->first(); elt; elt = root->next()) + { + elt->print(); + } + KwordGenerator generator(root); + generator.convert(_out); + kdDebug(30522) << "LATEX FILTER --> END" << endl; + reject(); +} diff --git a/filters/kword/latex/import/parser/Makefile.am b/filters/kword/latex/import/parser/Makefile.am index 7cb99e348..4a3b963cf 100644 --- a/filters/kword/latex/import/parser/Makefile.am +++ b/filters/kword/latex/import/parser/Makefile.am @@ -8,22 +8,22 @@ liblatexparser_la_LIBADD = -lm $(KOFFICE_LIBS) kde_module_LTLIBRARIES = liblatexparser.la -liblatexparser_la_SOURCES = command.cc comment.cc element.cc env.cc group.cc \ - latexparser.cc param.cc text.cc texparser.cc \ - texscaner.cc +liblatexparser_la_SOURCES = command.cpp comment.cpp element.cpp env.cpp group.cpp \ + latexparser.cpp param.cpp text.cpp texparser.cpp \ + texscaner.cpp noinst_HEADERS = command.h comment.h element.h env.h group.h \ latexparser.h param.h text.h -texparser.cc: $(srcdir)/texparser.l texscaner.cc - flex -B -8 -otexparser.cc $(srcdir)/texparser.l +texparser.cpp: $(srcdir)/texparser.l texscaner.cpp + flex -B -8 -otexparser.cpp $(srcdir)/texparser.l -texscaner.cc: $(srcdir)/texscaner.y - bison --debug --verbose -d -o texscaner.cc $(srcdir)/texscaner.y && mv -f texscaner.cc.h texscaner.hh +texscaner.cpp: $(srcdir)/texscaner.y + bison --debug --verbose -d -o texscaner.cpp $(srcdir)/texscaner.y && mv -f texscaner.cpp.h texscaner.hh # -p texparser ######## Debug check_PROGRAMS = texlauncher -texlauncher_SOURCES = texlauncher.cc +texlauncher_SOURCES = texlauncher.cpp texlauncher_LDADD = liblatexexport.la texlauncher_LDFLAGS = $(all_libraries) $(KDE_RPATH) $(LIB_TQT) -lDCOP $(LIB_TDECORE) $(LIB_TDEUI) -ltdefx $(LIB_TDEIO) -ltdetexteditor diff --git a/filters/kword/latex/import/parser/command.cc b/filters/kword/latex/import/parser/command.cpp similarity index 100% rename from filters/kword/latex/import/parser/command.cc rename to filters/kword/latex/import/parser/command.cpp diff --git a/filters/kword/latex/import/parser/comment.cc b/filters/kword/latex/import/parser/comment.cpp similarity index 100% rename from filters/kword/latex/import/parser/comment.cc rename to filters/kword/latex/import/parser/comment.cpp diff --git a/filters/kword/latex/import/parser/element.cc b/filters/kword/latex/import/parser/element.cpp similarity index 100% rename from filters/kword/latex/import/parser/element.cc rename to filters/kword/latex/import/parser/element.cpp diff --git a/filters/kword/latex/import/parser/env.cc b/filters/kword/latex/import/parser/env.cpp similarity index 100% rename from filters/kword/latex/import/parser/env.cc rename to filters/kword/latex/import/parser/env.cpp diff --git a/filters/kword/latex/import/parser/group.cc b/filters/kword/latex/import/parser/group.cpp similarity index 100% rename from filters/kword/latex/import/parser/group.cc rename to filters/kword/latex/import/parser/group.cpp diff --git a/filters/kword/latex/import/parser/latexparser.cc b/filters/kword/latex/import/parser/latexparser.cpp similarity index 100% rename from filters/kword/latex/import/parser/latexparser.cc rename to filters/kword/latex/import/parser/latexparser.cpp diff --git a/filters/kword/latex/import/parser/main.cc b/filters/kword/latex/import/parser/main.cpp similarity index 100% rename from filters/kword/latex/import/parser/main.cc rename to filters/kword/latex/import/parser/main.cpp diff --git a/filters/kword/latex/import/parser/param.cc b/filters/kword/latex/import/parser/param.cpp similarity index 100% rename from filters/kword/latex/import/parser/param.cc rename to filters/kword/latex/import/parser/param.cpp diff --git a/filters/kword/latex/import/parser/texparser.l b/filters/kword/latex/import/parser/texparser.l index c187f29d6..ea78619fe 100644 --- a/filters/kword/latex/import/parser/texparser.l +++ b/filters/kword/latex/import/parser/texparser.l @@ -2,8 +2,8 @@ * Ajouter une pile contenant tout les environnements. * * To compil : - * flex -+ -otexparser.cc texparser.lex - * g++ -o texparser texparser.cc -lfl -lm + * flex -+ -otexparser.cpp texparser.lex + * g++ -o texparser texparser.cpp -lfl -lm * */ diff --git a/filters/kword/latex/import/parser/texparser.lex b/filters/kword/latex/import/parser/texparser.lex index eb9b27aac..e945f48dd 100644 --- a/filters/kword/latex/import/parser/texparser.lex +++ b/filters/kword/latex/import/parser/texparser.lex @@ -2,8 +2,8 @@ * Ajouter une pile contenant tout les environnements. * * To compil : - * flex -+ -otexparser.cc texparser.lex - * g++ -o texparser texparser.cc -lfl -lm + * flex -+ -otexparser.cpp texparser.lex + * g++ -o texparser texparser.cpp -lfl -lm * */ diff --git a/filters/kword/latex/import/parser/text.cc b/filters/kword/latex/import/parser/text.cpp similarity index 100% rename from filters/kword/latex/import/parser/text.cc rename to filters/kword/latex/import/parser/text.cpp diff --git a/filters/kword/libexport/KWEFBaseWorker.cc b/filters/kword/libexport/KWEFBaseWorker.cpp similarity index 100% rename from filters/kword/libexport/KWEFBaseWorker.cc rename to filters/kword/libexport/KWEFBaseWorker.cpp diff --git a/filters/kword/libexport/KWEFKWordLeader.cc b/filters/kword/libexport/KWEFKWordLeader.cc deleted file mode 100644 index b0a7913d8..000000000 --- a/filters/kword/libexport/KWEFKWordLeader.cc +++ /dev/null @@ -1,1430 +0,0 @@ -/* - This file is part of the KDE project - Copyright (C) 2001, 2002, 2004 Nicolas GOUTTE - Copyright (c) 2001 IABG mbH. All rights reserved. - Contact: Wolf-Michael Bolle - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. -*/ - -/* - Part of this code comes from the old file: - /home/kde/koffice/filters/kword/ascii/asciiexport.cc - - The old file was copyrighted by - Copyright (C) 1998, 1999 Reginald Stadlbauer - Copyright (c) 2000 ID-PRO Deutschland GmbH. All rights reserved. - Contact: Wolf-Michael Bolle - - The old file was licensed under the terms of the GNU Library General Public - License version 2. -*/ - -#include -#include - -#include -#include -#include - -#include -#include - -#include "KWEFStructures.h" -#include "TagProcessing.h" -#include "ProcessDocument.h" -#include "KWEFBaseWorker.h" -#include "KWEFKWordLeader.h" - -KWEFKWordLeader::KWEFKWordLeader(void) - : m_syntaxVersion(-1), m_oldSyntax(false), m_worker(NULL), m_chain(NULL), m_hType(0), m_fType(0) -{ -} - -KWEFKWordLeader::KWEFKWordLeader(KWEFBaseWorker* newWorker) - : m_syntaxVersion(-1), m_oldSyntax(false), m_worker(newWorker), m_chain(NULL) -{ - if (newWorker) newWorker->registerKWordLeader(this); -} - -KWEFKWordLeader::~KWEFKWordLeader(void) -{ -} - -static FrameAnchor *findAnchor ( const KoPictureKey& key, - TQValueList& paraList ) -{ - kdDebug(30508) << "findAnchor " << key.toString() << endl; - TQValueList::Iterator paraIt; - - for ( paraIt = paraList.begin (); paraIt != paraList.end (); ++paraIt ) - { - ValueListFormatData::Iterator formattingIt; - - for ( formattingIt = (*paraIt).formattingList.begin (); - formattingIt != (*paraIt).formattingList.end (); - formattingIt++ ) - { - if ( (*formattingIt).id == 6 && - (*formattingIt).frameAnchor.key == key ) - { - kdDebug(30508) << "Found anchor " << (*formattingIt).frameAnchor.key.toString() << endl; - return &(*formattingIt).frameAnchor; - } - } - } - - kdWarning(30508) << "findAnchor returning NULL!" << endl; - return NULL; -} - -static void ProcessHardBrkTag ( TQDomNode myNode, void* tagData, KWEFKWordLeader* ) -{ - // - bool* flag = (bool*) tagData; - TQValueList attrProcessingList; - attrProcessingList << AttrProcessing ( "frame", *flag ); - ProcessAttributes (myNode, attrProcessingList); - if (*flag) - kdDebug(30508) << " found" << endl; -} - -static void InsertBookmarkFormatData (const int pos, const TQString& name, const bool start, - ValueListFormatData ¶FormatDataList) -{ - ValueListFormatData::Iterator paraFormatDataIt; - - FormatData book( start ? 1001 : 1002 , pos, 0 ); - book.variable.m_text = name; - - for (paraFormatDataIt = paraFormatDataList.begin (); - paraFormatDataIt != paraFormatDataList.end (); - paraFormatDataIt++) - { - if ( pos <= (*paraFormatDataIt).pos ) - { - paraFormatDataList.insert ( paraFormatDataIt, book ); - return; - - } - if ( ( pos > (*paraFormatDataIt).pos ) && ( pos < (*paraFormatDataIt).pos + (*paraFormatDataIt).len ) ) - { - // Somewhere in the middle, we have to split the FormatData - FormatData split ( *paraFormatDataIt ); - //const int oldlen = (*paraFormatDataIt).len; - split.len = pos - (*paraFormatDataIt).pos; - (*paraFormatDataIt).len -= split.len; - (*paraFormatDataIt).pos = pos; - paraFormatDataList.insert ( paraFormatDataIt, split ); - paraFormatDataList.insert ( paraFormatDataIt, book ); - return; - } - } - - // Still here? So we need to put the bookmark here: - paraFormatDataList.append ( book ); -} - - -void KWEFKWordLeader::createBookmarkFormatData( ParaData& paraData ) -{ - const int paraCount = m_paraCountMap[ m_currentFramesetName ]; - - TQValueList::ConstIterator it; - for (it = m_bookmarkList.begin(); it != m_bookmarkList.end(); ++it ) - { - if ( (*(it)).m_frameset != m_currentFramesetName ) - { - continue; - } - // As we always insert before, make first endings, then startings (problem is zero-length bookmark) - if ( (*(it)).m_endparag == paraCount ) - { - kdDebug(30508) << "Paragraph: " << paraCount << " end: " << (*(it)).m_name << endl; - InsertBookmarkFormatData( (*(it)).m_cursorIndexEnd, (*(it)).m_name, false, paraData.formattingList); - - } - if ( (*(it)).m_startparag == paraCount ) - { - kdDebug(30508) << "Paragraph: " << paraCount << " begin: " << (*(it)).m_name << endl; - InsertBookmarkFormatData( (*(it)).m_cursorIndexStart, (*(it)).m_name, true, paraData.formattingList); - } - } -} - -static void ProcessParagraphTag ( TQDomNode myNode, - void *tagData, - KWEFKWordLeader *leader ) -{ -#if 0 - kdDebug (30508) << "ProcessParagraphTag () - Begin" << endl; -#endif - - TQValueList *paraList = (TQValueList *) tagData; - - AllowNoAttributes (myNode); - - // We need to adjust the paragraph number (0 if first) - TQMap::Iterator it = leader->m_paraCountMap.find( leader->m_currentFramesetName ); - if ( it == leader->m_paraCountMap.end() ) - leader->m_paraCountMap.insert( leader->m_currentFramesetName, 0 ); - else - ++(*it); - - ParaData paraData; - - TQValueList tagProcessingList; - tagProcessingList << TagProcessing ( "TEXT", ProcessTextTag, ¶Data.text ) - << TagProcessing ( "FORMATS", ProcessFormatsTag, ¶Data.formattingList ) - << TagProcessing ( "LAYOUT", ProcessLayoutTag, ¶Data.layout ); - - if ( leader->m_oldSyntax ) - { - tagProcessingList.append( TagProcessing( "HARDBRK", ProcessHardBrkTag, ¶Data.layout.pageBreakBefore ) ); - } - ProcessSubtags (myNode, tagProcessingList, leader); - - leader->createBookmarkFormatData( paraData ); - CreateMissingFormatData (paraData.text, paraData.formattingList); - - // TODO/FIXME: why !paraData.text.isEmpty() - if ( paraData.formattingList.isEmpty () && !paraData.text.isEmpty () ) - { - if ( paraData.layout.formatData.id == 1 ) - { - paraData.formattingList << paraData.layout.formatData; - } - else - { - kdWarning (30508) << "No useful FORMAT tag found for text in PARAGRAPH" << endl; - } - } - - - *paraList << paraData; - -#if 0 - kdDebug (30508) << "ProcessParagraphTag () - End " << paraText << endl; -#endif -} - - -static void ProcessFrameTag ( TQDomNode myNode, void *tagData, - KWEFKWordLeader *leader ) -{ - FrameAnchor* frameAnchor= (FrameAnchor*) tagData; - - int lRed=0, lBlue=0, lGreen=0; - int rRed=0, rBlue=0, rGreen=0; - int tRed=0, tBlue=0, tGreen=0; - int bRed=0, bBlue=0, bGreen=0; - int bkRed=255, bkBlue=255, bkGreen=255; - - frameAnchor->frame.lWidth=0.0; - frameAnchor->frame.rWidth=0.0; - frameAnchor->frame.tWidth=0.0; - frameAnchor->frame.bWidth=0.0; - - TQValueList attrProcessingList; - attrProcessingList - << AttrProcessing ( "right", frameAnchor->frame.right ) - << AttrProcessing ( "left", frameAnchor->frame.left ) - << AttrProcessing ( "top", frameAnchor->frame.top ) - << AttrProcessing ( "bottom", frameAnchor->frame.bottom ) - - << AttrProcessing ( "min-height", frameAnchor->frame.minHeight ) - - << AttrProcessing ( "runaround", frameAnchor->frame.runaround ) - << AttrProcessing ( "runaroundSide", frameAnchor->frame.runaroundSide ) - << AttrProcessing ( "runaroundGap", frameAnchor->frame.runaroundGap ) - - << AttrProcessing ( "autoCreateNewFrame", frameAnchor->frame.autoCreateNewFrame ) - << AttrProcessing ( "newFrameBehavior", frameAnchor->frame.newFrameBehavior ) - << AttrProcessing ( "newFrameBehaviour", frameAnchor->frame.newFrameBehavior ) // Depreciated name - - << AttrProcessing ( "copy", frameAnchor->frame.copy ) - << AttrProcessing ( "sheetSide", frameAnchor->frame.sheetSide ) - - << AttrProcessing ( "lWidth", frameAnchor->frame.lWidth ) - << AttrProcessing ( "rWidth", frameAnchor->frame.rWidth ) - << AttrProcessing ( "tWidth", frameAnchor->frame.tWidth ) - << AttrProcessing ( "bWidth", frameAnchor->frame.bWidth ) - - << AttrProcessing ( "lRed", lRed ) - << AttrProcessing ( "lGreen", lGreen ) - << AttrProcessing ( "lBlue", lBlue ) - - << AttrProcessing ( "rRed", rRed ) - << AttrProcessing ( "rGreen", rGreen ) - << AttrProcessing ( "rBlue", rBlue ) - - << AttrProcessing ( "tRed", tRed ) - << AttrProcessing ( "tGreen", tGreen ) - << AttrProcessing ( "tBlue", tBlue ) - - << AttrProcessing ( "bRed", bRed ) - << AttrProcessing ( "bGreen", bGreen ) - << AttrProcessing ( "bBlue", bBlue ) - - << AttrProcessing ( "lStyle", frameAnchor->frame.lStyle ) - << AttrProcessing ( "rStyle", frameAnchor->frame.rStyle ) - << AttrProcessing ( "tStyle", frameAnchor->frame.tStyle ) - << AttrProcessing ( "bStyle", frameAnchor->frame.bStyle ) - - << AttrProcessing ( "bkRed", bkRed ) - << AttrProcessing ( "bkGreen", bkGreen ) - << AttrProcessing ( "bkBlue", bkBlue ) - - << AttrProcessing ( "bkStyle", frameAnchor->frame.bkStyle ) - - << AttrProcessing ( "bleftpt", frameAnchor->frame.bleftpt ) - << AttrProcessing ( "brightpt", frameAnchor->frame.brightpt ) - << AttrProcessing ( "btoppt", frameAnchor->frame.btoppt ) - << AttrProcessing ( "bbottompt", frameAnchor->frame.bbottompt ) - ; - - if ( leader->m_oldSyntax ) - { - attrProcessingList - << AttrProcessing ( "bleftmm" ) - << AttrProcessing ( "bleftinch" ) - << AttrProcessing ( "brightmm" ) - << AttrProcessing ( "brightinch" ) - << AttrProcessing ( "btopmm" ) - << AttrProcessing ( "btopinch" ) - << AttrProcessing ( "bbottommm" ) - << AttrProcessing ( "bbottominch" ) - ; - } - - ProcessAttributes (myNode, attrProcessingList); - - frameAnchor->frame.lColor.setRgb( lRed, lGreen, lBlue ); - frameAnchor->frame.rColor.setRgb( rRed, rGreen, rBlue ); - frameAnchor->frame.tColor.setRgb( tRed, tGreen, tBlue ); - frameAnchor->frame.bColor.setRgb( bRed, bGreen, bBlue ); - frameAnchor->frame.bkColor.setRgb( bkRed, bkGreen, bkBlue ); - - AllowNoSubtags (myNode, leader); -} - -static void ProcessPictureAnchor( TQDomNode myNode, KWEFKWordLeader *leader, FrameAnchor* frameAnchor, const int frameType ) -{ - frameAnchor->type = frameType; - - TQValueList tagProcessingList; - tagProcessingList - << TagProcessing ( "FRAME", ProcessFrameTag, frameAnchor ) - << TagProcessing ( "PICTURE", ProcessImageTag, &frameAnchor->picture.key ) - << TagProcessing ( "IMAGE", ProcessImageTag, &frameAnchor->picture.key ) - << TagProcessing ( "CLIPART", ProcessImageTag, &frameAnchor->picture.key ) - ; - ProcessSubtags (myNode, tagProcessingList, leader); - - kdDebug (30508) << "FRAMESET PICTURE KEY " << frameAnchor->picture.key.toString() << endl; - - frameAnchor->key = frameAnchor->picture.key; -} - -static void ProcessTableAnchor( TQDomNode myNode, KWEFKWordLeader *leader, FrameAnchor* frameAnchor, - const int col, const int row, const int cols, const int rows ) -{ - frameAnchor->type = 6; // Table - - TQValueList cellParaList; - TQValueList tagProcessingList; - tagProcessingList << TagProcessing ( "FRAME", ProcessFrameTag, frameAnchor ) - << TagProcessing ( "PARAGRAPH", ProcessParagraphTag, &cellParaList ); - ProcessSubtags (myNode, tagProcessingList, leader); - - frameAnchor->table.addCell (col, row, cols, rows, cellParaList, frameAnchor->frame); -} - -static void ProcessFramesetTag ( TQDomNode myNode, - void *tagData, - KWEFKWordLeader *leader ) -{ -#if 0 - kdDebug (30508) << "ProcessFramesetTag () - Begin" << endl; -#endif - - TQValueList *paraList = (TQValueList *) tagData; - - int frameType = -1; - int frameInfo = -1; - int col = -1; - int row = -1; - int cols = -1; - int rows = -1; - TQString grpMgr; - - const TQString oldName ( leader->m_currentFramesetName ); - - TQValueList attrProcessingList; - attrProcessingList << AttrProcessing ( "name", leader->m_currentFramesetName ) - << AttrProcessing ( "frameType", frameType ) - << AttrProcessing ( "frameInfo", frameInfo ) - << AttrProcessing ( "removable" ) - << AttrProcessing ( "visible" ) - << AttrProcessing ( "grpMgr", grpMgr ) - << AttrProcessing ( "row", row ) - << AttrProcessing ( "col", col ) - << AttrProcessing ( "rows", rows ) - << AttrProcessing ( "cols", cols ) - << AttrProcessing ( "protectSize" ) - ; - ProcessAttributes (myNode, attrProcessingList); - - switch ( frameType ) - { - case 1: - if ( grpMgr.isEmpty () ) - { - // As we do not support anything else than normal text, process only normal text. - // TODO: Treat the other types of frames (frameType) - if (frameInfo==0) - { - // Normal Text - kdDebug(30508) << "Processing Frameset: " << leader->m_currentFramesetName << endl; - TQValueList tagProcessingList; - tagProcessingList.append(TagProcessing ( "FRAME" )); - tagProcessingList.append(TagProcessing ( "PARAGRAPH", ProcessParagraphTag, paraList )); - ProcessSubtags (myNode, tagProcessingList, leader); - } - else if (frameInfo==1) - { - // header for first page - HeaderData header; - header.page = HeaderData::PAGE_FIRST; - TQValueList tagProcessingList; - tagProcessingList.append(TagProcessing ( "FRAME" )); - tagProcessingList.append(TagProcessing ( "PARAGRAPH", ProcessParagraphTag, &header.para )); - - ProcessSubtags (myNode, tagProcessingList, leader); - leader->doHeader( header ); - } - else if (frameInfo==2) - { - // header for even page - HeaderData header; - header.page = HeaderData::PAGE_EVEN; - TQValueList tagProcessingList; - tagProcessingList.append(TagProcessing ( "FRAME" )); - tagProcessingList.append(TagProcessing ( "PARAGRAPH", ProcessParagraphTag, &header.para )); - ProcessSubtags (myNode, tagProcessingList, leader); - leader->doHeader( header ); - } - else if (frameInfo==3) - { - // header for odd page (or all page, if hType=0) - HeaderData header; - header.page = (leader->headerType() != 0 ) ? HeaderData::PAGE_ODD : HeaderData::PAGE_ALL; - TQValueList tagProcessingList; - tagProcessingList.append(TagProcessing ( "FRAME" )); - tagProcessingList.append(TagProcessing ( "PARAGRAPH", ProcessParagraphTag, &header.para )); - ProcessSubtags (myNode, tagProcessingList, leader); - leader->doHeader( header ); - } - else if (frameInfo==4) - { - // footer for first page - FooterData footer; - footer.page = FooterData::PAGE_FIRST; - TQValueList tagProcessingList; - tagProcessingList.append(TagProcessing ( "FRAME" )); - tagProcessingList.append(TagProcessing ( "PARAGRAPH", ProcessParagraphTag, &footer.para )); - ProcessSubtags (myNode, tagProcessingList, leader); - leader->doFooter( footer ); - } - else if (frameInfo==5) - { - // footer for even page - FooterData footer; - footer.page = FooterData::PAGE_EVEN; - TQValueList tagProcessingList; - tagProcessingList.append(TagProcessing ( "FRAME" )); - tagProcessingList.append(TagProcessing ( "PARAGRAPH", ProcessParagraphTag, &footer.para )); - ProcessSubtags (myNode, tagProcessingList, leader); - leader->doFooter( footer ); - } - else if (frameInfo==6) - { - // footer for odd page (or all page, if fType=0) - FooterData footer; - footer.page = (leader->footerType() != 0) ? FooterData::PAGE_ODD : FooterData::PAGE_ALL; - TQValueList tagProcessingList; - tagProcessingList.append(TagProcessing ( "FRAME" )); - tagProcessingList.append(TagProcessing ( "PARAGRAPH", ProcessParagraphTag, &footer.para )); - ProcessSubtags (myNode, tagProcessingList, leader); - leader->doFooter( footer ); - } - } - else - { - if ( col != -1 && row != -1 ) - { - if ( cols > 0 && rows > 0 ) - { -#if 0 - kdDebug (30508) << "DEBUG - FRAMESET: table " << name << " col, row = " - << col << ", " << row << ", Mgr = "<< grpMgr << endl; -#endif - FrameAnchor *frameAnchor = findAnchor (grpMgr, *paraList); - if ( frameAnchor ) - { - ProcessTableAnchor( myNode, leader, frameAnchor, col, row, cols, rows ); - } - else - { - bool found = false; - KoPictureKey key( grpMgr ); - TQValueList::Iterator it; - for ( it = leader->m_nonInlinedTableAnchors.begin(); it != leader->m_nonInlinedTableAnchors.end(); ++it ) - { - if ( (*it).key == key ) - { - kdDebug(30508) << "Found pseudo-anchor for table: " << (*it).key.toString() << endl; - found = true; - break; - } - } - - if ( found ) - { - ProcessTableAnchor( myNode, leader, &(*it), col, row, cols, rows ); - } - else - { - kdWarning(30508) << "Table anchor not found: " << grpMgr << endl; - FrameAnchor anchor; - ProcessTableAnchor( myNode, leader, &anchor, col, row, cols, rows ); - anchor.key = key; // Needed, so that the pseudo-anchor can be found again - leader->m_nonInlinedTableAnchors << anchor; - leader->m_unanchoredFramesets.append( grpMgr ); - } - } - } - else - { - kdWarning (30508) << "Unexpected value for one of, or all FRAMESET attribute cols, rows: " - << cols << ", " << rows << "!" << endl; - AllowNoSubtags (myNode, leader); - } - } - else - { - kdWarning (30508) << "Unset value for one of, or all FRAMESET attributes col, row: " - << col << ", " << row << "!" << endl; - AllowNoSubtags (myNode, leader); - leader->m_unanchoredFramesets.append( leader->m_currentFramesetName ); - } - } - break; - - case 2: // PICTURE - case 5: // CLIPART: deprecated (up to KOffice 1.2 Beta 2) - { -#if 0 - kdDebug (30508) << "DEBUG: FRAMESET name of picture is " << name << endl; -#endif - - FrameAnchor *frameAnchor = findAnchor ( leader->m_currentFramesetName, *paraList ); - - if ( frameAnchor ) - { - ProcessPictureAnchor( myNode, leader, frameAnchor, frameType ); - } - else - { - // ### TODO: non-inlined picture? - // No anchor found, so the picture is not inlined - kdDebug (30508) << "ProcessFramesetTag: Couldn't find anchor " << leader->m_currentFramesetName << endl; - FrameAnchor anchor; - ProcessPictureAnchor( myNode, leader, &anchor, frameType ); - leader->m_nonInlinedPictureAnchors << anchor; - leader->m_unanchoredFramesets.append( leader->m_currentFramesetName ); // DEBUG - } - - break; - } - - case 4: // KFormula - { - kdWarning(30508) << "KFormula frameset not supported yet!" << endl; // ### TODO - break; - } - default: - kdWarning (30508) << "Unexpected frametype " << frameType << " (in ProcessFramesetTag)" << endl; - } - - leader->m_currentFramesetName = oldName; - -#if 0 - kdDebug (30508) << "ProcessFramesetTag () - End" << endl; -#endif -} - - -static void ProcessFramesetsTag ( TQDomNode myNode, - void *tagData, - KWEFKWordLeader *leader ) -{ - AllowNoAttributes (myNode); - TQValueList tagProcessingList; - tagProcessingList << TagProcessing ( "FRAMESET", ProcessFramesetTag, tagData ); - ProcessSubtags (myNode, tagProcessingList, leader); -} - - -static void ProcessStyleTag (TQDomNode myNode, void *, KWEFKWordLeader *leader ) -{ - LayoutData layout; - - ProcessLayoutTag (myNode, &layout, leader); - - leader->doFullDefineStyle (layout); -} - - -static void ProcessStylesPluralTag (TQDomNode myNode, void *, KWEFKWordLeader *leader ) -{ - AllowNoAttributes (myNode); - - leader->doOpenStyles (); - - TQValueList tagProcessingList; - tagProcessingList << TagProcessing ( "STYLE", ProcessStyleTag, leader ); - ProcessSubtags (myNode, tagProcessingList, leader); - - leader->doCloseStyles (); -} - - -static void ProcessPaperBordersTag (TQDomNode myNode, void*, KWEFKWordLeader* leader) -{ - - double left = 0.0; - double right = 0.0; - double top = 0.0; - double bottom = 0.0; - - TQValueList attrProcessingList; - if ( leader->m_oldSyntax ) - { - attrProcessingList - << AttrProcessing ( "ptLeft", left ) - << AttrProcessing ( "ptRight", right ) - << AttrProcessing ( "ptTop", top ) - << AttrProcessing ( "ptBottom", bottom ) - << AttrProcessing ( "mmLeft" ) - << AttrProcessing ( "mmRight" ) - << AttrProcessing ( "mmTop" ) - << AttrProcessing ( "mmBottom" ) - << AttrProcessing ( "inchLeft" ) - << AttrProcessing ( "inchRight" ) - << AttrProcessing ( "inchTop" ) - << AttrProcessing ( "inchBottom" ) - ; - } - else - { - attrProcessingList - << AttrProcessing ( "left", left ) - << AttrProcessing ( "right", right ) - << AttrProcessing ( "top", top ) - << AttrProcessing ( "bottom", bottom ) - ; - } - ProcessAttributes (myNode, attrProcessingList); - - leader->doFullPaperBorders(top, left, bottom, right); - - AllowNoSubtags (myNode, leader); -} - -static void ProcessPaperTag (TQDomNode myNode, void *, KWEFKWordLeader *leader) -{ - - int format = -1; - int orientation = -1; - double width = -1.0; - double height = -1.0; - int hType = -1; - int fType = -1; - int columns = 1; - double columnspacing = 36.0; // Half-inch - int numPages = -1; - - TQValueList attrProcessingList; - attrProcessingList << AttrProcessing ( "format", format ) - << AttrProcessing ( "width", width ) - << AttrProcessing ( "height", height ) - << AttrProcessing ( "orientation", orientation ) - << AttrProcessing ( "columns", columns ) - << AttrProcessing ( "columnspacing", columnspacing ) - << AttrProcessing ( "pages", numPages ) - << AttrProcessing ( "hType", hType ) - << AttrProcessing ( "fType", fType ) - << AttrProcessing ( "spHeadBody" ) - << AttrProcessing ( "spFootBody" ) - << AttrProcessing ( "spFootNoteBody" ) - << AttrProcessing ( "slFootNotePosition" ) - << AttrProcessing ( "slFootNoteLength" ) - << AttrProcessing ( "slFootNoteWidth" ) - << AttrProcessing ( "slFootNoteType" ); - - if ( leader->m_oldSyntax ) - { - // ### TODO: in syntax 1 hType and fType have other values! - attrProcessingList - << AttrProcessing ( "ptWidth", width ) - << AttrProcessing ( "ptHeight", height ) - << AttrProcessing ( "ptColumnspc", columnspacing ) - << AttrProcessing ( "mmWidth" ) - << AttrProcessing ( "mmHeight" ) - << AttrProcessing ( "mmColumnspc" ) - << AttrProcessing ( "inchWidth" ) - << AttrProcessing ( "inchHeight" ) - << AttrProcessing ( "inchColumnspc" ) - ; - } - - ProcessAttributes (myNode, attrProcessingList); - - leader->setHeaderType( hType ); - leader->setFooterType( fType ); - - leader->doPageInfo ( hType, fType ); - leader->doFullPaperFormat (format, width, height, orientation); - leader->doFullPaperFormatOther( columns, columnspacing, numPages ); - - TQValueList tagProcessingList; - tagProcessingList - << TagProcessing ( "PAPERBORDERS", ProcessPaperBordersTag, NULL ) - ; - - ProcessSubtags (myNode, tagProcessingList, leader); -} - -static void ProcessVariableSettingsTag (TQDomNode myNode, void *, KWEFKWordLeader *leader) -{ - VariableSettingsData vs; - TQString print, creation, modification; // Dates (in ISO 8601 format) - int creationYear = -1; - int creationMonth = -1; - int creationDay = -1; - int modificationYear = -1; - int modificationMonth = -1; - int modificationDay = -1; - - TQValueList attrProcessingList; - attrProcessingList << AttrProcessing ( "startingPageNumber", vs.startingPageNumber ) - << AttrProcessing ( "displaylink", vs.displaylink ) - << AttrProcessing ( "underlinelink", vs.underlinelink ) - << AttrProcessing ( "displaycomment", vs.displaycomment ) - << AttrProcessing ( "displayfieldcode", vs.displayfieldcode ) - ; - - - // The following 3 attributes are from syntax 3 but at least the RTF import filter generate them with syntax 2. - attrProcessingList - << AttrProcessing ( "lastPrintingDate", print ) - << AttrProcessing ( "creationDate", creation ) - << AttrProcessing ( "modificationDate", modification ); - ; - - // Some files have the creation and modification date not in one attribute but in an attribute for each the year, the month, the day - // ( e.g. syntax 2 file kofficetests/documents/export/kword/text/all.kwd ) - attrProcessingList - << AttrProcessing( "modifyFileYear", modificationYear ) - << AttrProcessing( "modifyFileMonth", modificationMonth ) - << AttrProcessing( "modifyFileDay", modificationDay ) - << AttrProcessing( "createFileYear", creationYear ) - << AttrProcessing( "createFileMonth", creationMonth ) - << AttrProcessing( "createFileDay", creationDay ) - ; - - ProcessAttributes (myNode, attrProcessingList); - - if ( creation.isEmpty() ) - { - if ( ( creationYear >= 1970 ) && TQDate::isValid( creationYear, creationMonth, creationDay ) ) - { - vs.creationTime = TQDateTime( TQDate( creationYear, creationMonth, creationDay ) ); - } - } - else - vs.creationTime=TQDateTime::fromString(creation, Qt::ISODate); - //kdDebug(30508) << "Creation time: " << vs.creationTime.toString( Qt::ISODate ) << endl; - - if ( modification.isEmpty() ) - { - if ( ( modificationYear >= 1970 ) && TQDate::isValid( modificationYear, modificationMonth, modificationDay ) ) - { - vs.modificationTime = TQDateTime( TQDate( modificationYear, modificationMonth, modificationDay ) ); - } - } - else - vs.modificationTime=TQDateTime::fromString(modification, Qt::ISODate); - //kdDebug(30508) << "Modification time: " << vs.modificationTime.toString( Qt::ISODate ) << endl; - - if (!print.isEmpty()) - vs.printTime=TQDateTime::fromString(print, Qt::ISODate); - //kdDebug(30508) << "Print time: " << vs.printTime.toString( Qt::ISODate ) << endl; - - leader->doVariableSettings (vs); -} - -static void ProcessSpellCheckIgnoreWordTag (TQDomNode myNode, void *, KWEFKWordLeader *leader ) -{ - TQString ignoreword; - - TQValueList attrProcessingList; - attrProcessingList - << AttrProcessing ( "word", ignoreword ) - ; - ProcessAttributes (myNode, attrProcessingList); - - leader->doFullSpellCheckIgnoreWord (ignoreword); - - AllowNoSubtags (myNode, leader); -} - - -static void ProcessSpellCheckIgnoreListTag (TQDomNode myNode, void *, KWEFKWordLeader *leader ) -{ - AllowNoAttributes (myNode); - - leader->doOpenSpellCheckIgnoreList (); - - TQValueList tagProcessingList; - tagProcessingList << TagProcessing ( "SPELLCHECKIGNOREWORD", ProcessSpellCheckIgnoreWordTag, leader ); - ProcessSubtags (myNode, tagProcessingList, leader); - - leader->doCloseSpellCheckIgnoreList (); -} - - -static void ProcessPixmapsKeyTag ( TQDomNode myNode, - void *tagData, - KWEFKWordLeader *leader ) -{ - TQValueList *paraList = (TQValueList *) tagData; - - KoPictureKey key; - - // Let KoPictureKey do most of the loading - key.loadAttributes(myNode.toElement()); - const TQString name(myNode.toElement().attribute("name")); - - kdDebug(30508) << "search anchors: " << key.toString() << endl; - bool found = false; - - // NOTE: we must always search in both inlined and non-inlined pictures. A picture can be used in both ways and a few times in each! - - // Process inlined pictures - TQValueList::Iterator paraIt; - - for ( paraIt = paraList->begin(); paraIt != paraList->end(); ++paraIt ) - { - ValueListFormatData::Iterator formattingIt; - for ( formattingIt = (*paraIt).formattingList.begin(); - formattingIt != (*paraIt).formattingList.end(); - formattingIt++ ) - { - if ( ( ( (*formattingIt).id == 6 ) || ( (*formattingIt).id == 2 ) ) - && (*formattingIt).frameAnchor.key == key ) - { - kdDebug(30508) << "Found anchor for inlined picture: " << (*formattingIt).frameAnchor.key.toString() << endl; - (*formattingIt).frameAnchor.picture.koStoreName = name; - found = true; - } - } - } - // Process non-inline pictures - TQValueList::Iterator it; - for ( it = leader->m_nonInlinedPictureAnchors.begin(); it != leader->m_nonInlinedPictureAnchors.end(); ++it ) - { - if ( (*it).key == key ) - { - kdDebug(30508) << "Found pseudo-anchor for non-inlined picture: " << (*it).key.toString() << endl; - (*it).picture.koStoreName = name; - found = true; - } - } - - if ( !found ) - { - kdWarning (30508) << "Could not find any anchor for picture " << key.toString() << endl; - } - - AllowNoSubtags (myNode, leader); -} - - -static void ProcessPixmapsTag ( TQDomNode myNode, - void *tagData, - KWEFKWordLeader *leader ) -{ - AllowNoAttributes (myNode); - - TQValueList tagProcessingList; - tagProcessingList << TagProcessing ( "KEY", ProcessPixmapsKeyTag, tagData ); - ProcessSubtags (myNode, tagProcessingList, leader); -} - - -static void FreeCellParaLists ( TQValueList ¶List ) -{ - TQValueList::Iterator paraIt; - - for ( paraIt = paraList.begin (); paraIt != paraList.end (); ++paraIt ) - { - ValueListFormatData::Iterator formattingIt; - - for ( formattingIt = (*paraIt).formattingList.begin (); - formattingIt != (*paraIt).formattingList.end (); - formattingIt++ ) - { - if ( (*formattingIt).id == 6 && (*formattingIt).frameAnchor.type == 6 ) - { - TQValueList::Iterator cellIt; - - for ( cellIt = (*formattingIt).frameAnchor.table.cellList.begin (); - cellIt != (*formattingIt).frameAnchor.table.cellList.end (); - cellIt++ ) - { - FreeCellParaLists ( *(*cellIt).paraList ); // recursion is great - delete (*cellIt).paraList; - } - } - } - } -} - -// like ProcessFramesetTag, but only handle footnotes -static void ProcessFootnoteFramesetTag ( TQDomNode myNode, void *tagData, KWEFKWordLeader *leader ) -{ - TQString frameName; - int frameType = -1, frameInfo = -1; - bool visible = false; - - TQValueList attrProcessingList; - attrProcessingList - << AttrProcessing ( "name", frameName ) - << AttrProcessing ( "frameType", frameType ) - << AttrProcessing ( "frameInfo", frameInfo ) - << AttrProcessing ( "removable" ) - << AttrProcessing ( "visible", visible ) - << AttrProcessing ( "grpMgr" ) - << AttrProcessing ( "row" ) - << AttrProcessing ( "col" ) - << AttrProcessing ( "rows" ) - << AttrProcessing ( "cols" ) - << AttrProcessing ( "protectSize" ) - ; - ProcessAttributes (myNode, attrProcessingList); - - // for footnote frame, frameType is 1 and frameInfo is 7 - if( ( frameType == 1 ) && ( frameInfo == 7 ) ) - { - FootnoteData footnote; - footnote.frameName = frameName; - TQValueList tagProcessingList; - tagProcessingList.append(TagProcessing ( "FRAME" )); - tagProcessingList.append(TagProcessing ( "PARAGRAPH", ProcessParagraphTag, &footnote.para )); - ProcessSubtags (myNode, tagProcessingList, leader); - leader->footnoteList.append( footnote ); - } -} - -// like ProcessFramesetsTag, but only handle footnotes -static void ProcessFootnoteFramesetsTag ( TQDomNode myNode, void *tagData, KWEFKWordLeader *leader ) -{ - AllowNoAttributes (myNode); - - TQValueList tagProcessingList; - tagProcessingList << TagProcessing ( "FRAMESET", ProcessFootnoteFramesetTag, tagData ); - ProcessSubtags (myNode, tagProcessingList, leader); -} - -static void ProcessBookmarkItemTag ( TQDomNode myNode, void* tag, KWEFKWordLeader *leader ) -{ - TQValueList * bookmarkList = static_cast< TQValueList * > ( tag ); - - Bookmark bookmark; - - TQValueList attrProcessingList; - attrProcessingList - << AttrProcessing ( "name", bookmark.m_name ) - << AttrProcessing ( "cursorIndexStart", bookmark.m_cursorIndexStart ) - << AttrProcessing ( "cursorIndexEnd", bookmark.m_cursorIndexEnd ) - << AttrProcessing ( "frameset", bookmark.m_frameset ) - << AttrProcessing ( "startparag", bookmark.m_startparag ) - << AttrProcessing ( "endparag", bookmark.m_endparag ) - ; - - ProcessAttributes (myNode, attrProcessingList); - - AllowNoSubtags( myNode, leader ); - - // ### TODO: some verifications - - kdDebug(30508) << "Bookmark: " << bookmark.m_name << " in frameset " << bookmark.m_frameset << endl; - - bookmarkList->append( bookmark ); -} - -static void ProcessBookmarksTag ( TQDomNode myNode, void* tag, KWEFKWordLeader *leader ) -{ - AllowNoAttributes (myNode); - - TQValueList tagProcessingList; - tagProcessingList << TagProcessing ( "BOOKMARKITEM", ProcessBookmarkItemTag, tag ); - ProcessSubtags (myNode, tagProcessingList, leader); -} - -void ProcessDocTag ( TQDomNode myNode, - void* /*tagData*/, KWEFKWordLeader* leader ) -{ - //kdDebug (30508) << "Entering ProcessDocTag" << endl; - - TQString editor, author; - - TQValueList attrProcessingList; - - attrProcessingList - << AttrProcessing ( "xmlns" ) - << AttrProcessing ( "editor", editor ) - << AttrProcessing ( "mime" ) - << AttrProcessing ( "syntaxVersion", leader->m_syntaxVersion ) - << AttrProcessing ( "author", author ) - << AttrProcessing ( "email" ) - ; - - ProcessAttributes( myNode, attrProcessingList ); - - kdDebug(30508) << "Document written by " << editor << endl; - kdDebug(30508) << "Document of syntax version " << leader->m_syntaxVersion << endl; - - if ( leader->m_syntaxVersion == 1 ) - { - leader->m_oldSyntax = true; // Syntax 1 is old syntax - } - else if ( leader->m_syntaxVersion == -1 ) - { - // We do not know the version, but it still might be an old syntax. - // However such old documents have still an author attribute, so check its value - if ( author == "Reginald Stadlbauer and Torben Weis" ) - { - kdDebug(30508) << "No syntax version but author attribute matches => assuming old syntax" << endl; - leader->m_oldSyntax = true; - } - else - { - kdWarning(30508) << "No syntax version found, author attribute does not match => assuming new syntax" << endl; - } - } - - leader->doOpenHead(); - - // At first, process , even if mostly it will not be needed - TQDomNode nodeIgnoreList=myNode.namedItem("SPELLCHECKIGNORELIST"); - if ( nodeIgnoreList.isNull () ) - kdDebug (30508) << "No " << endl; // Most files will not have it! - else - ProcessSpellCheckIgnoreListTag (nodeIgnoreList, NULL, leader); - - // Process now, even if mostly the output will need to be delayed. - TQDomNode nodePaper=myNode.namedItem("PAPER"); - if ( nodePaper.isNull () ) - kdWarning (30508) << "No " << endl; - else - ProcessPaperTag (nodePaper, NULL, leader); - - // Process - TQDomNode nodeVariableSettings=myNode.namedItem("VARIABLESETTINGS"); - if ( nodeVariableSettings.isNull () ) - kdWarning (30508) << "No " << endl; - else - ProcessVariableSettingsTag (nodeVariableSettings, NULL, leader); - - // Then we process the styles - TQDomNode nodeStyles=myNode.namedItem("STYLES"); - if ( nodeStyles.isNull () ) - kdWarning (30508) << "No " << endl; - else - ProcessStylesPluralTag (nodeStyles, NULL, leader); - - // Process framesets, but only to find and extract footnotes (also endnotes) - TQValueList footnotes; - TQDomNode nodeFramesets=myNode.namedItem("FRAMESETS"); - if ( !nodeFramesets.isNull() ) - ProcessFootnoteFramesetsTag(nodeFramesets, &footnotes, leader ); - - // Process all framesets and pictures - TQValueList tagProcessingList; - TQValueList paraList; - - tagProcessingList - << TagProcessing ( "PAPER" ) // Already done - << TagProcessing ( "ATTRIBUTES" ) - << TagProcessing ( "FRAMESETS", ProcessFramesetsTag, ¶List ) - << TagProcessing ( "STYLES" ) // Already done - << TagProcessing ( "PICTURES", ProcessPixmapsTag, ¶List ) - << TagProcessing ( "PIXMAPS", ProcessPixmapsTag, ¶List ) - << TagProcessing ( "CLIPARTS", ProcessPixmapsTag, ¶List ) - << TagProcessing ( "EMBEDDED" ) - << TagProcessing ( "BOOKMARKS", ProcessBookmarksTag, &leader->m_bookmarkList ) - ; - - // TODO: why are the followings used by KWord 1.2 but are not in its DTD? - tagProcessingList << TagProcessing ( "SERIALL" ); - tagProcessingList << TagProcessing ( "FOOTNOTEMGR" ); - - ProcessSubtags (myNode, tagProcessingList, leader); - - leader->doCloseHead(); - leader->doDeclareNonInlinedFramesets( leader->m_nonInlinedPictureAnchors, leader->m_nonInlinedTableAnchors ); - leader->doOpenBody(); - - leader->doFullDocument (paraList); - - kdDebug(30508) << "Unachored Framesets : START" << endl; - TQStringList::ConstIterator it; - for ( it = leader->m_unanchoredFramesets.begin(); it != leader->m_unanchoredFramesets.end(); ++it ) - { - kdDebug(30508) << (*it) << endl; - } - kdDebug(30508) << "Unachored Framesets : END" << endl; - - FreeCellParaLists (paraList); - - leader->doCloseBody(); - - //kdDebug (30508) << "Exiting ProcessDocTag" << endl; -} - - -void KWEFKWordLeader::setWorker ( KWEFBaseWorker *newWorker ) -{ - m_worker = newWorker; - - if (newWorker) - newWorker->registerKWordLeader(this); -} - - -KWEFBaseWorker *KWEFKWordLeader::getWorker(void) const -{ - return m_worker; -} - - -// Short simple definition for methods with void parameter -#define DO_VOID_DEFINITION(string) \ - bool KWEFKWordLeader::string() \ - {\ - if (m_worker) \ - return m_worker->string(); \ - return false; \ - } - - -bool KWEFKWordLeader::doOpenFile ( const TQString &filenameOut, const TQString &to ) -{ - if ( m_worker ) - return m_worker->doOpenFile (filenameOut, to); - - // As it would be the first method to be called, warn if worker is NULL - kdError (30508) << "No Worker! (in KWEFKWordLeader::doOpenFile)" << endl; - - return false; -} - - -DO_VOID_DEFINITION (doCloseFile) -DO_VOID_DEFINITION (doAbortFile) -DO_VOID_DEFINITION (doOpenDocument) -DO_VOID_DEFINITION (doCloseDocument) -DO_VOID_DEFINITION (doOpenStyles) -DO_VOID_DEFINITION (doCloseStyles) -DO_VOID_DEFINITION (doOpenHead) -DO_VOID_DEFINITION (doCloseHead) -DO_VOID_DEFINITION (doOpenBody) -DO_VOID_DEFINITION (doCloseBody) -DO_VOID_DEFINITION (doOpenSpellCheckIgnoreList) -DO_VOID_DEFINITION (doCloseSpellCheckIgnoreList) - -bool KWEFKWordLeader::doFullDocumentInfo (const KWEFDocumentInfo &docInfo) -{ - if ( m_worker ) - return m_worker->doFullDocumentInfo (docInfo); - - return false; -} - - -bool KWEFKWordLeader::doVariableSettings (const VariableSettingsData &varSettings) -{ - if ( m_worker ) - return m_worker->doVariableSettings (varSettings); - - return false; -} - - -bool KWEFKWordLeader::doFullDocument (const TQValueList ¶List) -{ - if ( m_worker ) - return m_worker->doFullDocument (paraList); - - return false; -} - -bool KWEFKWordLeader::doPageInfo ( const int headerType, const int footerType ) -{ - if ( m_worker ) - return m_worker->doPageInfo ( headerType, footerType ); - - return false; -} - -bool KWEFKWordLeader::doFullPaperFormat ( const int format, const double width, const double height, const int orientation ) -{ - if ( m_worker ) - return m_worker->doFullPaperFormat (format, width, height, orientation); - - return false; -} - -bool KWEFKWordLeader::doFullPaperBorders (const double top, const double left, const double bottom, const double right) -{ - if ( m_worker ) - return m_worker->doFullPaperBorders (top, left, bottom, right); - - return false; -} - -bool KWEFKWordLeader::doFullPaperFormatOther ( const int columns, const double columnspacing, const int numPages ) -{ - if ( m_worker ) - return m_worker->doFullPaperFormatOther ( columns, columnspacing, numPages ); - - return false; -} - -bool KWEFKWordLeader::doFullDefineStyle ( LayoutData &layout ) -{ - if ( m_worker ) - return m_worker->doFullDefineStyle (layout); - - return false; -} - -bool KWEFKWordLeader::doFullSpellCheckIgnoreWord (const TQString& ignoreword) -{ - if ( m_worker ) - return m_worker->doFullSpellCheckIgnoreWord (ignoreword); - - return false; -} - -bool KWEFKWordLeader::doHeader ( const HeaderData& header ) -{ - if ( m_worker ) - return m_worker->doHeader (header); - - return false; -} - -bool KWEFKWordLeader::doFooter ( const FooterData& footer ) -{ - if ( m_worker ) - return m_worker->doFooter (footer); - - return false; -} - -bool KWEFKWordLeader::doDeclareNonInlinedFramesets( TQValueList& pictureAnchors, TQValueList& tableAnchors ) -{ - if ( m_worker ) - return m_worker->doDeclareNonInlinedFramesets( pictureAnchors, tableAnchors ); - - return false; -} - -static bool ParseFile ( TQIODevice* subFile, TQDomDocument& doc) -{ - TQString errorMsg; - int errorLine; - int errorColumn; - - if ( !doc.setContent (subFile, &errorMsg, &errorLine, &errorColumn) ) - { - kdError (30508) << "Parsing Error! Aborting! (in ParseFile)" << endl - << " Line: " << errorLine << " Column: " << errorColumn << endl - << " Message: " << errorMsg << endl; - // ### TODO: the error is in which sub-file? - KMessageBox::error( 0L, i18n("An error has occurred while parsing the KWord file.\nAt line: %1, column %2\nError message: %3") - .arg( errorLine ).arg( errorColumn ).arg(i18n( "TQXml", errorMsg.utf8() ) ), - i18n("KWord Export Filter Library"), 0 ); - return false; - } - return true; -} - -static bool ProcessStoreFile ( TQIODevice* subFile, - void (*processor) (TQDomNode, void *, KWEFKWordLeader *), - KWEFKWordLeader* leader) -{ - if (!subFile) - { - kdWarning(30508) << "Could not get a device for the document!" << endl; - } - else if ( subFile->open ( IO_ReadOnly ) ) - { - kdDebug (30508) << "Processing Document..." << endl; - TQDomDocument doc; - if (!ParseFile(subFile, doc)) - { - subFile->close(); - return false; - } - // We must close the subFile before processing, - // as the processing could open other sub files. - // However, it would crash if two sub files are opened together - subFile->close(); - - TQDomNode docNode = doc.documentElement(); - processor (docNode, NULL, leader); - return true; - } - else - { - // Note: we do not worry too much if we cannot open the document info! - kdWarning (30508) << "Unable to open document!" << endl; - } - return false; -} - -TQIODevice* KWEFKWordLeader::getSubFileDevice(const TQString& fileName) -{ - KoStoreDevice* subFile; - - subFile=m_chain->storageFile(fileName,KoStore::Read); - - if (!subFile) - { - kdError(30508) << "Could not get a device for sub-file: " << fileName << endl; - return NULL; - } - return subFile; -} - - -bool KWEFKWordLeader::loadSubFile(const TQString& fileName, TQByteArray& array) -{ - KoStoreDevice* subFile; - - subFile=m_chain->storageFile(fileName,KoStore::Read); - - if (!subFile) - { - kdError(30508) << "Could not get a device for sub-file: " << fileName << endl; - return false; - } - else if ( subFile->open ( IO_ReadOnly ) ) - { - array = subFile->readAll(); - subFile->close (); - } - else - { - kdError(30508) << "Unable to open " << fileName << " sub-file" << endl; - return false; - } - - return true; -} - -KoFilter::ConversionStatus KWEFKWordLeader::convert( KoFilterChain* chain, - const TQCString& from, const TQCString& to) -{ - if ( from != "application/x-kword" ) - { - return KoFilter::NotImplemented; - } - - if (!chain) - { - kdError(30508) << "'Chain' is NULL! Internal error of the filter system?" << endl; - return KoFilter::StupidError; - } - - m_chain=chain; - - if ( !doOpenFile (chain->outputFile(),to) ) - { - kdError (30508) << "Worker could not open export file! Aborting!" << endl; - return KoFilter::StupidError; - } - - if ( !doOpenDocument () ) - { - kdError (30508) << "Worker could not open document! Aborting!" << endl; - doAbortFile (); - return KoFilter::StupidError; - } - - KoStoreDevice* subFile; - - subFile=chain->storageFile("documentinfo.xml",KoStore::Read); - kdDebug (30508) << "Processing documentinfo.xml..." << endl; - // Do not care if we cannot open the document info. - ProcessStoreFile (subFile, ProcessDocumentInfoTag, this); - - subFile=chain->storageFile("root",KoStore::Read); - kdDebug (30508) << "Processing root..." << endl; - if (!ProcessStoreFile (subFile, ProcessDocTag, this)) - { - kdWarning(30508) << "Opening root has failed. Trying raw XML file!" << endl; - - const TQString filename( chain->inputFile() ); - if (filename.isEmpty() ) - { - kdError(30508) << "Could not open document as raw XML! Aborting!" << endl; - doAbortFile(); - return KoFilter::StupidError; - } - else - { - TQFile file( filename ); - if ( ! ProcessStoreFile( TQT_TQIODEVICE(&file), ProcessDocTag, this ) ) - { - kdError(30508) << "Could not process document! Aborting!" << endl; - doAbortFile(); - return KoFilter::StupidError; - } - } - } - - doCloseDocument (); - - doCloseFile (); - - return KoFilter::OK; -} diff --git a/filters/kword/libexport/KWEFKWordLeader.cpp b/filters/kword/libexport/KWEFKWordLeader.cpp new file mode 100644 index 000000000..05e4024a5 --- /dev/null +++ b/filters/kword/libexport/KWEFKWordLeader.cpp @@ -0,0 +1,1430 @@ +/* + This file is part of the KDE project + Copyright (C) 2001, 2002, 2004 Nicolas GOUTTE + Copyright (c) 2001 IABG mbH. All rights reserved. + Contact: Wolf-Michael Bolle + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ + +/* + Part of this code comes from the old file: + /home/kde/koffice/filters/kword/ascii/asciiexport.cpp + + The old file was copyrighted by + Copyright (C) 1998, 1999 Reginald Stadlbauer + Copyright (c) 2000 ID-PRO Deutschland GmbH. All rights reserved. + Contact: Wolf-Michael Bolle + + The old file was licensed under the terms of the GNU Library General Public + License version 2. +*/ + +#include +#include + +#include +#include +#include + +#include +#include + +#include "KWEFStructures.h" +#include "TagProcessing.h" +#include "ProcessDocument.h" +#include "KWEFBaseWorker.h" +#include "KWEFKWordLeader.h" + +KWEFKWordLeader::KWEFKWordLeader(void) + : m_syntaxVersion(-1), m_oldSyntax(false), m_worker(NULL), m_chain(NULL), m_hType(0), m_fType(0) +{ +} + +KWEFKWordLeader::KWEFKWordLeader(KWEFBaseWorker* newWorker) + : m_syntaxVersion(-1), m_oldSyntax(false), m_worker(newWorker), m_chain(NULL) +{ + if (newWorker) newWorker->registerKWordLeader(this); +} + +KWEFKWordLeader::~KWEFKWordLeader(void) +{ +} + +static FrameAnchor *findAnchor ( const KoPictureKey& key, + TQValueList& paraList ) +{ + kdDebug(30508) << "findAnchor " << key.toString() << endl; + TQValueList::Iterator paraIt; + + for ( paraIt = paraList.begin (); paraIt != paraList.end (); ++paraIt ) + { + ValueListFormatData::Iterator formattingIt; + + for ( formattingIt = (*paraIt).formattingList.begin (); + formattingIt != (*paraIt).formattingList.end (); + formattingIt++ ) + { + if ( (*formattingIt).id == 6 && + (*formattingIt).frameAnchor.key == key ) + { + kdDebug(30508) << "Found anchor " << (*formattingIt).frameAnchor.key.toString() << endl; + return &(*formattingIt).frameAnchor; + } + } + } + + kdWarning(30508) << "findAnchor returning NULL!" << endl; + return NULL; +} + +static void ProcessHardBrkTag ( TQDomNode myNode, void* tagData, KWEFKWordLeader* ) +{ + // + bool* flag = (bool*) tagData; + TQValueList attrProcessingList; + attrProcessingList << AttrProcessing ( "frame", *flag ); + ProcessAttributes (myNode, attrProcessingList); + if (*flag) + kdDebug(30508) << " found" << endl; +} + +static void InsertBookmarkFormatData (const int pos, const TQString& name, const bool start, + ValueListFormatData ¶FormatDataList) +{ + ValueListFormatData::Iterator paraFormatDataIt; + + FormatData book( start ? 1001 : 1002 , pos, 0 ); + book.variable.m_text = name; + + for (paraFormatDataIt = paraFormatDataList.begin (); + paraFormatDataIt != paraFormatDataList.end (); + paraFormatDataIt++) + { + if ( pos <= (*paraFormatDataIt).pos ) + { + paraFormatDataList.insert ( paraFormatDataIt, book ); + return; + + } + if ( ( pos > (*paraFormatDataIt).pos ) && ( pos < (*paraFormatDataIt).pos + (*paraFormatDataIt).len ) ) + { + // Somewhere in the middle, we have to split the FormatData + FormatData split ( *paraFormatDataIt ); + //const int oldlen = (*paraFormatDataIt).len; + split.len = pos - (*paraFormatDataIt).pos; + (*paraFormatDataIt).len -= split.len; + (*paraFormatDataIt).pos = pos; + paraFormatDataList.insert ( paraFormatDataIt, split ); + paraFormatDataList.insert ( paraFormatDataIt, book ); + return; + } + } + + // Still here? So we need to put the bookmark here: + paraFormatDataList.append ( book ); +} + + +void KWEFKWordLeader::createBookmarkFormatData( ParaData& paraData ) +{ + const int paraCount = m_paraCountMap[ m_currentFramesetName ]; + + TQValueList::ConstIterator it; + for (it = m_bookmarkList.begin(); it != m_bookmarkList.end(); ++it ) + { + if ( (*(it)).m_frameset != m_currentFramesetName ) + { + continue; + } + // As we always insert before, make first endings, then startings (problem is zero-length bookmark) + if ( (*(it)).m_endparag == paraCount ) + { + kdDebug(30508) << "Paragraph: " << paraCount << " end: " << (*(it)).m_name << endl; + InsertBookmarkFormatData( (*(it)).m_cursorIndexEnd, (*(it)).m_name, false, paraData.formattingList); + + } + if ( (*(it)).m_startparag == paraCount ) + { + kdDebug(30508) << "Paragraph: " << paraCount << " begin: " << (*(it)).m_name << endl; + InsertBookmarkFormatData( (*(it)).m_cursorIndexStart, (*(it)).m_name, true, paraData.formattingList); + } + } +} + +static void ProcessParagraphTag ( TQDomNode myNode, + void *tagData, + KWEFKWordLeader *leader ) +{ +#if 0 + kdDebug (30508) << "ProcessParagraphTag () - Begin" << endl; +#endif + + TQValueList *paraList = (TQValueList *) tagData; + + AllowNoAttributes (myNode); + + // We need to adjust the paragraph number (0 if first) + TQMap::Iterator it = leader->m_paraCountMap.find( leader->m_currentFramesetName ); + if ( it == leader->m_paraCountMap.end() ) + leader->m_paraCountMap.insert( leader->m_currentFramesetName, 0 ); + else + ++(*it); + + ParaData paraData; + + TQValueList tagProcessingList; + tagProcessingList << TagProcessing ( "TEXT", ProcessTextTag, ¶Data.text ) + << TagProcessing ( "FORMATS", ProcessFormatsTag, ¶Data.formattingList ) + << TagProcessing ( "LAYOUT", ProcessLayoutTag, ¶Data.layout ); + + if ( leader->m_oldSyntax ) + { + tagProcessingList.append( TagProcessing( "HARDBRK", ProcessHardBrkTag, ¶Data.layout.pageBreakBefore ) ); + } + ProcessSubtags (myNode, tagProcessingList, leader); + + leader->createBookmarkFormatData( paraData ); + CreateMissingFormatData (paraData.text, paraData.formattingList); + + // TODO/FIXME: why !paraData.text.isEmpty() + if ( paraData.formattingList.isEmpty () && !paraData.text.isEmpty () ) + { + if ( paraData.layout.formatData.id == 1 ) + { + paraData.formattingList << paraData.layout.formatData; + } + else + { + kdWarning (30508) << "No useful FORMAT tag found for text in PARAGRAPH" << endl; + } + } + + + *paraList << paraData; + +#if 0 + kdDebug (30508) << "ProcessParagraphTag () - End " << paraText << endl; +#endif +} + + +static void ProcessFrameTag ( TQDomNode myNode, void *tagData, + KWEFKWordLeader *leader ) +{ + FrameAnchor* frameAnchor= (FrameAnchor*) tagData; + + int lRed=0, lBlue=0, lGreen=0; + int rRed=0, rBlue=0, rGreen=0; + int tRed=0, tBlue=0, tGreen=0; + int bRed=0, bBlue=0, bGreen=0; + int bkRed=255, bkBlue=255, bkGreen=255; + + frameAnchor->frame.lWidth=0.0; + frameAnchor->frame.rWidth=0.0; + frameAnchor->frame.tWidth=0.0; + frameAnchor->frame.bWidth=0.0; + + TQValueList attrProcessingList; + attrProcessingList + << AttrProcessing ( "right", frameAnchor->frame.right ) + << AttrProcessing ( "left", frameAnchor->frame.left ) + << AttrProcessing ( "top", frameAnchor->frame.top ) + << AttrProcessing ( "bottom", frameAnchor->frame.bottom ) + + << AttrProcessing ( "min-height", frameAnchor->frame.minHeight ) + + << AttrProcessing ( "runaround", frameAnchor->frame.runaround ) + << AttrProcessing ( "runaroundSide", frameAnchor->frame.runaroundSide ) + << AttrProcessing ( "runaroundGap", frameAnchor->frame.runaroundGap ) + + << AttrProcessing ( "autoCreateNewFrame", frameAnchor->frame.autoCreateNewFrame ) + << AttrProcessing ( "newFrameBehavior", frameAnchor->frame.newFrameBehavior ) + << AttrProcessing ( "newFrameBehaviour", frameAnchor->frame.newFrameBehavior ) // Depreciated name + + << AttrProcessing ( "copy", frameAnchor->frame.copy ) + << AttrProcessing ( "sheetSide", frameAnchor->frame.sheetSide ) + + << AttrProcessing ( "lWidth", frameAnchor->frame.lWidth ) + << AttrProcessing ( "rWidth", frameAnchor->frame.rWidth ) + << AttrProcessing ( "tWidth", frameAnchor->frame.tWidth ) + << AttrProcessing ( "bWidth", frameAnchor->frame.bWidth ) + + << AttrProcessing ( "lRed", lRed ) + << AttrProcessing ( "lGreen", lGreen ) + << AttrProcessing ( "lBlue", lBlue ) + + << AttrProcessing ( "rRed", rRed ) + << AttrProcessing ( "rGreen", rGreen ) + << AttrProcessing ( "rBlue", rBlue ) + + << AttrProcessing ( "tRed", tRed ) + << AttrProcessing ( "tGreen", tGreen ) + << AttrProcessing ( "tBlue", tBlue ) + + << AttrProcessing ( "bRed", bRed ) + << AttrProcessing ( "bGreen", bGreen ) + << AttrProcessing ( "bBlue", bBlue ) + + << AttrProcessing ( "lStyle", frameAnchor->frame.lStyle ) + << AttrProcessing ( "rStyle", frameAnchor->frame.rStyle ) + << AttrProcessing ( "tStyle", frameAnchor->frame.tStyle ) + << AttrProcessing ( "bStyle", frameAnchor->frame.bStyle ) + + << AttrProcessing ( "bkRed", bkRed ) + << AttrProcessing ( "bkGreen", bkGreen ) + << AttrProcessing ( "bkBlue", bkBlue ) + + << AttrProcessing ( "bkStyle", frameAnchor->frame.bkStyle ) + + << AttrProcessing ( "bleftpt", frameAnchor->frame.bleftpt ) + << AttrProcessing ( "brightpt", frameAnchor->frame.brightpt ) + << AttrProcessing ( "btoppt", frameAnchor->frame.btoppt ) + << AttrProcessing ( "bbottompt", frameAnchor->frame.bbottompt ) + ; + + if ( leader->m_oldSyntax ) + { + attrProcessingList + << AttrProcessing ( "bleftmm" ) + << AttrProcessing ( "bleftinch" ) + << AttrProcessing ( "brightmm" ) + << AttrProcessing ( "brightinch" ) + << AttrProcessing ( "btopmm" ) + << AttrProcessing ( "btopinch" ) + << AttrProcessing ( "bbottommm" ) + << AttrProcessing ( "bbottominch" ) + ; + } + + ProcessAttributes (myNode, attrProcessingList); + + frameAnchor->frame.lColor.setRgb( lRed, lGreen, lBlue ); + frameAnchor->frame.rColor.setRgb( rRed, rGreen, rBlue ); + frameAnchor->frame.tColor.setRgb( tRed, tGreen, tBlue ); + frameAnchor->frame.bColor.setRgb( bRed, bGreen, bBlue ); + frameAnchor->frame.bkColor.setRgb( bkRed, bkGreen, bkBlue ); + + AllowNoSubtags (myNode, leader); +} + +static void ProcessPictureAnchor( TQDomNode myNode, KWEFKWordLeader *leader, FrameAnchor* frameAnchor, const int frameType ) +{ + frameAnchor->type = frameType; + + TQValueList tagProcessingList; + tagProcessingList + << TagProcessing ( "FRAME", ProcessFrameTag, frameAnchor ) + << TagProcessing ( "PICTURE", ProcessImageTag, &frameAnchor->picture.key ) + << TagProcessing ( "IMAGE", ProcessImageTag, &frameAnchor->picture.key ) + << TagProcessing ( "CLIPART", ProcessImageTag, &frameAnchor->picture.key ) + ; + ProcessSubtags (myNode, tagProcessingList, leader); + + kdDebug (30508) << "FRAMESET PICTURE KEY " << frameAnchor->picture.key.toString() << endl; + + frameAnchor->key = frameAnchor->picture.key; +} + +static void ProcessTableAnchor( TQDomNode myNode, KWEFKWordLeader *leader, FrameAnchor* frameAnchor, + const int col, const int row, const int cols, const int rows ) +{ + frameAnchor->type = 6; // Table + + TQValueList cellParaList; + TQValueList tagProcessingList; + tagProcessingList << TagProcessing ( "FRAME", ProcessFrameTag, frameAnchor ) + << TagProcessing ( "PARAGRAPH", ProcessParagraphTag, &cellParaList ); + ProcessSubtags (myNode, tagProcessingList, leader); + + frameAnchor->table.addCell (col, row, cols, rows, cellParaList, frameAnchor->frame); +} + +static void ProcessFramesetTag ( TQDomNode myNode, + void *tagData, + KWEFKWordLeader *leader ) +{ +#if 0 + kdDebug (30508) << "ProcessFramesetTag () - Begin" << endl; +#endif + + TQValueList *paraList = (TQValueList *) tagData; + + int frameType = -1; + int frameInfo = -1; + int col = -1; + int row = -1; + int cols = -1; + int rows = -1; + TQString grpMgr; + + const TQString oldName ( leader->m_currentFramesetName ); + + TQValueList attrProcessingList; + attrProcessingList << AttrProcessing ( "name", leader->m_currentFramesetName ) + << AttrProcessing ( "frameType", frameType ) + << AttrProcessing ( "frameInfo", frameInfo ) + << AttrProcessing ( "removable" ) + << AttrProcessing ( "visible" ) + << AttrProcessing ( "grpMgr", grpMgr ) + << AttrProcessing ( "row", row ) + << AttrProcessing ( "col", col ) + << AttrProcessing ( "rows", rows ) + << AttrProcessing ( "cols", cols ) + << AttrProcessing ( "protectSize" ) + ; + ProcessAttributes (myNode, attrProcessingList); + + switch ( frameType ) + { + case 1: + if ( grpMgr.isEmpty () ) + { + // As we do not support anything else than normal text, process only normal text. + // TODO: Treat the other types of frames (frameType) + if (frameInfo==0) + { + // Normal Text + kdDebug(30508) << "Processing Frameset: " << leader->m_currentFramesetName << endl; + TQValueList tagProcessingList; + tagProcessingList.append(TagProcessing ( "FRAME" )); + tagProcessingList.append(TagProcessing ( "PARAGRAPH", ProcessParagraphTag, paraList )); + ProcessSubtags (myNode, tagProcessingList, leader); + } + else if (frameInfo==1) + { + // header for first page + HeaderData header; + header.page = HeaderData::PAGE_FIRST; + TQValueList tagProcessingList; + tagProcessingList.append(TagProcessing ( "FRAME" )); + tagProcessingList.append(TagProcessing ( "PARAGRAPH", ProcessParagraphTag, &header.para )); + + ProcessSubtags (myNode, tagProcessingList, leader); + leader->doHeader( header ); + } + else if (frameInfo==2) + { + // header for even page + HeaderData header; + header.page = HeaderData::PAGE_EVEN; + TQValueList tagProcessingList; + tagProcessingList.append(TagProcessing ( "FRAME" )); + tagProcessingList.append(TagProcessing ( "PARAGRAPH", ProcessParagraphTag, &header.para )); + ProcessSubtags (myNode, tagProcessingList, leader); + leader->doHeader( header ); + } + else if (frameInfo==3) + { + // header for odd page (or all page, if hType=0) + HeaderData header; + header.page = (leader->headerType() != 0 ) ? HeaderData::PAGE_ODD : HeaderData::PAGE_ALL; + TQValueList tagProcessingList; + tagProcessingList.append(TagProcessing ( "FRAME" )); + tagProcessingList.append(TagProcessing ( "PARAGRAPH", ProcessParagraphTag, &header.para )); + ProcessSubtags (myNode, tagProcessingList, leader); + leader->doHeader( header ); + } + else if (frameInfo==4) + { + // footer for first page + FooterData footer; + footer.page = FooterData::PAGE_FIRST; + TQValueList tagProcessingList; + tagProcessingList.append(TagProcessing ( "FRAME" )); + tagProcessingList.append(TagProcessing ( "PARAGRAPH", ProcessParagraphTag, &footer.para )); + ProcessSubtags (myNode, tagProcessingList, leader); + leader->doFooter( footer ); + } + else if (frameInfo==5) + { + // footer for even page + FooterData footer; + footer.page = FooterData::PAGE_EVEN; + TQValueList tagProcessingList; + tagProcessingList.append(TagProcessing ( "FRAME" )); + tagProcessingList.append(TagProcessing ( "PARAGRAPH", ProcessParagraphTag, &footer.para )); + ProcessSubtags (myNode, tagProcessingList, leader); + leader->doFooter( footer ); + } + else if (frameInfo==6) + { + // footer for odd page (or all page, if fType=0) + FooterData footer; + footer.page = (leader->footerType() != 0) ? FooterData::PAGE_ODD : FooterData::PAGE_ALL; + TQValueList tagProcessingList; + tagProcessingList.append(TagProcessing ( "FRAME" )); + tagProcessingList.append(TagProcessing ( "PARAGRAPH", ProcessParagraphTag, &footer.para )); + ProcessSubtags (myNode, tagProcessingList, leader); + leader->doFooter( footer ); + } + } + else + { + if ( col != -1 && row != -1 ) + { + if ( cols > 0 && rows > 0 ) + { +#if 0 + kdDebug (30508) << "DEBUG - FRAMESET: table " << name << " col, row = " + << col << ", " << row << ", Mgr = "<< grpMgr << endl; +#endif + FrameAnchor *frameAnchor = findAnchor (grpMgr, *paraList); + if ( frameAnchor ) + { + ProcessTableAnchor( myNode, leader, frameAnchor, col, row, cols, rows ); + } + else + { + bool found = false; + KoPictureKey key( grpMgr ); + TQValueList::Iterator it; + for ( it = leader->m_nonInlinedTableAnchors.begin(); it != leader->m_nonInlinedTableAnchors.end(); ++it ) + { + if ( (*it).key == key ) + { + kdDebug(30508) << "Found pseudo-anchor for table: " << (*it).key.toString() << endl; + found = true; + break; + } + } + + if ( found ) + { + ProcessTableAnchor( myNode, leader, &(*it), col, row, cols, rows ); + } + else + { + kdWarning(30508) << "Table anchor not found: " << grpMgr << endl; + FrameAnchor anchor; + ProcessTableAnchor( myNode, leader, &anchor, col, row, cols, rows ); + anchor.key = key; // Needed, so that the pseudo-anchor can be found again + leader->m_nonInlinedTableAnchors << anchor; + leader->m_unanchoredFramesets.append( grpMgr ); + } + } + } + else + { + kdWarning (30508) << "Unexpected value for one of, or all FRAMESET attribute cols, rows: " + << cols << ", " << rows << "!" << endl; + AllowNoSubtags (myNode, leader); + } + } + else + { + kdWarning (30508) << "Unset value for one of, or all FRAMESET attributes col, row: " + << col << ", " << row << "!" << endl; + AllowNoSubtags (myNode, leader); + leader->m_unanchoredFramesets.append( leader->m_currentFramesetName ); + } + } + break; + + case 2: // PICTURE + case 5: // CLIPART: deprecated (up to KOffice 1.2 Beta 2) + { +#if 0 + kdDebug (30508) << "DEBUG: FRAMESET name of picture is " << name << endl; +#endif + + FrameAnchor *frameAnchor = findAnchor ( leader->m_currentFramesetName, *paraList ); + + if ( frameAnchor ) + { + ProcessPictureAnchor( myNode, leader, frameAnchor, frameType ); + } + else + { + // ### TODO: non-inlined picture? + // No anchor found, so the picture is not inlined + kdDebug (30508) << "ProcessFramesetTag: Couldn't find anchor " << leader->m_currentFramesetName << endl; + FrameAnchor anchor; + ProcessPictureAnchor( myNode, leader, &anchor, frameType ); + leader->m_nonInlinedPictureAnchors << anchor; + leader->m_unanchoredFramesets.append( leader->m_currentFramesetName ); // DEBUG + } + + break; + } + + case 4: // KFormula + { + kdWarning(30508) << "KFormula frameset not supported yet!" << endl; // ### TODO + break; + } + default: + kdWarning (30508) << "Unexpected frametype " << frameType << " (in ProcessFramesetTag)" << endl; + } + + leader->m_currentFramesetName = oldName; + +#if 0 + kdDebug (30508) << "ProcessFramesetTag () - End" << endl; +#endif +} + + +static void ProcessFramesetsTag ( TQDomNode myNode, + void *tagData, + KWEFKWordLeader *leader ) +{ + AllowNoAttributes (myNode); + TQValueList tagProcessingList; + tagProcessingList << TagProcessing ( "FRAMESET", ProcessFramesetTag, tagData ); + ProcessSubtags (myNode, tagProcessingList, leader); +} + + +static void ProcessStyleTag (TQDomNode myNode, void *, KWEFKWordLeader *leader ) +{ + LayoutData layout; + + ProcessLayoutTag (myNode, &layout, leader); + + leader->doFullDefineStyle (layout); +} + + +static void ProcessStylesPluralTag (TQDomNode myNode, void *, KWEFKWordLeader *leader ) +{ + AllowNoAttributes (myNode); + + leader->doOpenStyles (); + + TQValueList tagProcessingList; + tagProcessingList << TagProcessing ( "STYLE", ProcessStyleTag, leader ); + ProcessSubtags (myNode, tagProcessingList, leader); + + leader->doCloseStyles (); +} + + +static void ProcessPaperBordersTag (TQDomNode myNode, void*, KWEFKWordLeader* leader) +{ + + double left = 0.0; + double right = 0.0; + double top = 0.0; + double bottom = 0.0; + + TQValueList attrProcessingList; + if ( leader->m_oldSyntax ) + { + attrProcessingList + << AttrProcessing ( "ptLeft", left ) + << AttrProcessing ( "ptRight", right ) + << AttrProcessing ( "ptTop", top ) + << AttrProcessing ( "ptBottom", bottom ) + << AttrProcessing ( "mmLeft" ) + << AttrProcessing ( "mmRight" ) + << AttrProcessing ( "mmTop" ) + << AttrProcessing ( "mmBottom" ) + << AttrProcessing ( "inchLeft" ) + << AttrProcessing ( "inchRight" ) + << AttrProcessing ( "inchTop" ) + << AttrProcessing ( "inchBottom" ) + ; + } + else + { + attrProcessingList + << AttrProcessing ( "left", left ) + << AttrProcessing ( "right", right ) + << AttrProcessing ( "top", top ) + << AttrProcessing ( "bottom", bottom ) + ; + } + ProcessAttributes (myNode, attrProcessingList); + + leader->doFullPaperBorders(top, left, bottom, right); + + AllowNoSubtags (myNode, leader); +} + +static void ProcessPaperTag (TQDomNode myNode, void *, KWEFKWordLeader *leader) +{ + + int format = -1; + int orientation = -1; + double width = -1.0; + double height = -1.0; + int hType = -1; + int fType = -1; + int columns = 1; + double columnspacing = 36.0; // Half-inch + int numPages = -1; + + TQValueList attrProcessingList; + attrProcessingList << AttrProcessing ( "format", format ) + << AttrProcessing ( "width", width ) + << AttrProcessing ( "height", height ) + << AttrProcessing ( "orientation", orientation ) + << AttrProcessing ( "columns", columns ) + << AttrProcessing ( "columnspacing", columnspacing ) + << AttrProcessing ( "pages", numPages ) + << AttrProcessing ( "hType", hType ) + << AttrProcessing ( "fType", fType ) + << AttrProcessing ( "spHeadBody" ) + << AttrProcessing ( "spFootBody" ) + << AttrProcessing ( "spFootNoteBody" ) + << AttrProcessing ( "slFootNotePosition" ) + << AttrProcessing ( "slFootNoteLength" ) + << AttrProcessing ( "slFootNoteWidth" ) + << AttrProcessing ( "slFootNoteType" ); + + if ( leader->m_oldSyntax ) + { + // ### TODO: in syntax 1 hType and fType have other values! + attrProcessingList + << AttrProcessing ( "ptWidth", width ) + << AttrProcessing ( "ptHeight", height ) + << AttrProcessing ( "ptColumnspc", columnspacing ) + << AttrProcessing ( "mmWidth" ) + << AttrProcessing ( "mmHeight" ) + << AttrProcessing ( "mmColumnspc" ) + << AttrProcessing ( "inchWidth" ) + << AttrProcessing ( "inchHeight" ) + << AttrProcessing ( "inchColumnspc" ) + ; + } + + ProcessAttributes (myNode, attrProcessingList); + + leader->setHeaderType( hType ); + leader->setFooterType( fType ); + + leader->doPageInfo ( hType, fType ); + leader->doFullPaperFormat (format, width, height, orientation); + leader->doFullPaperFormatOther( columns, columnspacing, numPages ); + + TQValueList tagProcessingList; + tagProcessingList + << TagProcessing ( "PAPERBORDERS", ProcessPaperBordersTag, NULL ) + ; + + ProcessSubtags (myNode, tagProcessingList, leader); +} + +static void ProcessVariableSettingsTag (TQDomNode myNode, void *, KWEFKWordLeader *leader) +{ + VariableSettingsData vs; + TQString print, creation, modification; // Dates (in ISO 8601 format) + int creationYear = -1; + int creationMonth = -1; + int creationDay = -1; + int modificationYear = -1; + int modificationMonth = -1; + int modificationDay = -1; + + TQValueList attrProcessingList; + attrProcessingList << AttrProcessing ( "startingPageNumber", vs.startingPageNumber ) + << AttrProcessing ( "displaylink", vs.displaylink ) + << AttrProcessing ( "underlinelink", vs.underlinelink ) + << AttrProcessing ( "displaycomment", vs.displaycomment ) + << AttrProcessing ( "displayfieldcode", vs.displayfieldcode ) + ; + + + // The following 3 attributes are from syntax 3 but at least the RTF import filter generate them with syntax 2. + attrProcessingList + << AttrProcessing ( "lastPrintingDate", print ) + << AttrProcessing ( "creationDate", creation ) + << AttrProcessing ( "modificationDate", modification ); + ; + + // Some files have the creation and modification date not in one attribute but in an attribute for each the year, the month, the day + // ( e.g. syntax 2 file kofficetests/documents/export/kword/text/all.kwd ) + attrProcessingList + << AttrProcessing( "modifyFileYear", modificationYear ) + << AttrProcessing( "modifyFileMonth", modificationMonth ) + << AttrProcessing( "modifyFileDay", modificationDay ) + << AttrProcessing( "createFileYear", creationYear ) + << AttrProcessing( "createFileMonth", creationMonth ) + << AttrProcessing( "createFileDay", creationDay ) + ; + + ProcessAttributes (myNode, attrProcessingList); + + if ( creation.isEmpty() ) + { + if ( ( creationYear >= 1970 ) && TQDate::isValid( creationYear, creationMonth, creationDay ) ) + { + vs.creationTime = TQDateTime( TQDate( creationYear, creationMonth, creationDay ) ); + } + } + else + vs.creationTime=TQDateTime::fromString(creation, Qt::ISODate); + //kdDebug(30508) << "Creation time: " << vs.creationTime.toString( Qt::ISODate ) << endl; + + if ( modification.isEmpty() ) + { + if ( ( modificationYear >= 1970 ) && TQDate::isValid( modificationYear, modificationMonth, modificationDay ) ) + { + vs.modificationTime = TQDateTime( TQDate( modificationYear, modificationMonth, modificationDay ) ); + } + } + else + vs.modificationTime=TQDateTime::fromString(modification, Qt::ISODate); + //kdDebug(30508) << "Modification time: " << vs.modificationTime.toString( Qt::ISODate ) << endl; + + if (!print.isEmpty()) + vs.printTime=TQDateTime::fromString(print, Qt::ISODate); + //kdDebug(30508) << "Print time: " << vs.printTime.toString( Qt::ISODate ) << endl; + + leader->doVariableSettings (vs); +} + +static void ProcessSpellCheckIgnoreWordTag (TQDomNode myNode, void *, KWEFKWordLeader *leader ) +{ + TQString ignoreword; + + TQValueList attrProcessingList; + attrProcessingList + << AttrProcessing ( "word", ignoreword ) + ; + ProcessAttributes (myNode, attrProcessingList); + + leader->doFullSpellCheckIgnoreWord (ignoreword); + + AllowNoSubtags (myNode, leader); +} + + +static void ProcessSpellCheckIgnoreListTag (TQDomNode myNode, void *, KWEFKWordLeader *leader ) +{ + AllowNoAttributes (myNode); + + leader->doOpenSpellCheckIgnoreList (); + + TQValueList tagProcessingList; + tagProcessingList << TagProcessing ( "SPELLCHECKIGNOREWORD", ProcessSpellCheckIgnoreWordTag, leader ); + ProcessSubtags (myNode, tagProcessingList, leader); + + leader->doCloseSpellCheckIgnoreList (); +} + + +static void ProcessPixmapsKeyTag ( TQDomNode myNode, + void *tagData, + KWEFKWordLeader *leader ) +{ + TQValueList *paraList = (TQValueList *) tagData; + + KoPictureKey key; + + // Let KoPictureKey do most of the loading + key.loadAttributes(myNode.toElement()); + const TQString name(myNode.toElement().attribute("name")); + + kdDebug(30508) << "search anchors: " << key.toString() << endl; + bool found = false; + + // NOTE: we must always search in both inlined and non-inlined pictures. A picture can be used in both ways and a few times in each! + + // Process inlined pictures + TQValueList::Iterator paraIt; + + for ( paraIt = paraList->begin(); paraIt != paraList->end(); ++paraIt ) + { + ValueListFormatData::Iterator formattingIt; + for ( formattingIt = (*paraIt).formattingList.begin(); + formattingIt != (*paraIt).formattingList.end(); + formattingIt++ ) + { + if ( ( ( (*formattingIt).id == 6 ) || ( (*formattingIt).id == 2 ) ) + && (*formattingIt).frameAnchor.key == key ) + { + kdDebug(30508) << "Found anchor for inlined picture: " << (*formattingIt).frameAnchor.key.toString() << endl; + (*formattingIt).frameAnchor.picture.koStoreName = name; + found = true; + } + } + } + // Process non-inline pictures + TQValueList::Iterator it; + for ( it = leader->m_nonInlinedPictureAnchors.begin(); it != leader->m_nonInlinedPictureAnchors.end(); ++it ) + { + if ( (*it).key == key ) + { + kdDebug(30508) << "Found pseudo-anchor for non-inlined picture: " << (*it).key.toString() << endl; + (*it).picture.koStoreName = name; + found = true; + } + } + + if ( !found ) + { + kdWarning (30508) << "Could not find any anchor for picture " << key.toString() << endl; + } + + AllowNoSubtags (myNode, leader); +} + + +static void ProcessPixmapsTag ( TQDomNode myNode, + void *tagData, + KWEFKWordLeader *leader ) +{ + AllowNoAttributes (myNode); + + TQValueList tagProcessingList; + tagProcessingList << TagProcessing ( "KEY", ProcessPixmapsKeyTag, tagData ); + ProcessSubtags (myNode, tagProcessingList, leader); +} + + +static void FreeCellParaLists ( TQValueList ¶List ) +{ + TQValueList::Iterator paraIt; + + for ( paraIt = paraList.begin (); paraIt != paraList.end (); ++paraIt ) + { + ValueListFormatData::Iterator formattingIt; + + for ( formattingIt = (*paraIt).formattingList.begin (); + formattingIt != (*paraIt).formattingList.end (); + formattingIt++ ) + { + if ( (*formattingIt).id == 6 && (*formattingIt).frameAnchor.type == 6 ) + { + TQValueList::Iterator cellIt; + + for ( cellIt = (*formattingIt).frameAnchor.table.cellList.begin (); + cellIt != (*formattingIt).frameAnchor.table.cellList.end (); + cellIt++ ) + { + FreeCellParaLists ( *(*cellIt).paraList ); // recursion is great + delete (*cellIt).paraList; + } + } + } + } +} + +// like ProcessFramesetTag, but only handle footnotes +static void ProcessFootnoteFramesetTag ( TQDomNode myNode, void *tagData, KWEFKWordLeader *leader ) +{ + TQString frameName; + int frameType = -1, frameInfo = -1; + bool visible = false; + + TQValueList attrProcessingList; + attrProcessingList + << AttrProcessing ( "name", frameName ) + << AttrProcessing ( "frameType", frameType ) + << AttrProcessing ( "frameInfo", frameInfo ) + << AttrProcessing ( "removable" ) + << AttrProcessing ( "visible", visible ) + << AttrProcessing ( "grpMgr" ) + << AttrProcessing ( "row" ) + << AttrProcessing ( "col" ) + << AttrProcessing ( "rows" ) + << AttrProcessing ( "cols" ) + << AttrProcessing ( "protectSize" ) + ; + ProcessAttributes (myNode, attrProcessingList); + + // for footnote frame, frameType is 1 and frameInfo is 7 + if( ( frameType == 1 ) && ( frameInfo == 7 ) ) + { + FootnoteData footnote; + footnote.frameName = frameName; + TQValueList tagProcessingList; + tagProcessingList.append(TagProcessing ( "FRAME" )); + tagProcessingList.append(TagProcessing ( "PARAGRAPH", ProcessParagraphTag, &footnote.para )); + ProcessSubtags (myNode, tagProcessingList, leader); + leader->footnoteList.append( footnote ); + } +} + +// like ProcessFramesetsTag, but only handle footnotes +static void ProcessFootnoteFramesetsTag ( TQDomNode myNode, void *tagData, KWEFKWordLeader *leader ) +{ + AllowNoAttributes (myNode); + + TQValueList tagProcessingList; + tagProcessingList << TagProcessing ( "FRAMESET", ProcessFootnoteFramesetTag, tagData ); + ProcessSubtags (myNode, tagProcessingList, leader); +} + +static void ProcessBookmarkItemTag ( TQDomNode myNode, void* tag, KWEFKWordLeader *leader ) +{ + TQValueList * bookmarkList = static_cast< TQValueList * > ( tag ); + + Bookmark bookmark; + + TQValueList attrProcessingList; + attrProcessingList + << AttrProcessing ( "name", bookmark.m_name ) + << AttrProcessing ( "cursorIndexStart", bookmark.m_cursorIndexStart ) + << AttrProcessing ( "cursorIndexEnd", bookmark.m_cursorIndexEnd ) + << AttrProcessing ( "frameset", bookmark.m_frameset ) + << AttrProcessing ( "startparag", bookmark.m_startparag ) + << AttrProcessing ( "endparag", bookmark.m_endparag ) + ; + + ProcessAttributes (myNode, attrProcessingList); + + AllowNoSubtags( myNode, leader ); + + // ### TODO: some verifications + + kdDebug(30508) << "Bookmark: " << bookmark.m_name << " in frameset " << bookmark.m_frameset << endl; + + bookmarkList->append( bookmark ); +} + +static void ProcessBookmarksTag ( TQDomNode myNode, void* tag, KWEFKWordLeader *leader ) +{ + AllowNoAttributes (myNode); + + TQValueList tagProcessingList; + tagProcessingList << TagProcessing ( "BOOKMARKITEM", ProcessBookmarkItemTag, tag ); + ProcessSubtags (myNode, tagProcessingList, leader); +} + +void ProcessDocTag ( TQDomNode myNode, + void* /*tagData*/, KWEFKWordLeader* leader ) +{ + //kdDebug (30508) << "Entering ProcessDocTag" << endl; + + TQString editor, author; + + TQValueList attrProcessingList; + + attrProcessingList + << AttrProcessing ( "xmlns" ) + << AttrProcessing ( "editor", editor ) + << AttrProcessing ( "mime" ) + << AttrProcessing ( "syntaxVersion", leader->m_syntaxVersion ) + << AttrProcessing ( "author", author ) + << AttrProcessing ( "email" ) + ; + + ProcessAttributes( myNode, attrProcessingList ); + + kdDebug(30508) << "Document written by " << editor << endl; + kdDebug(30508) << "Document of syntax version " << leader->m_syntaxVersion << endl; + + if ( leader->m_syntaxVersion == 1 ) + { + leader->m_oldSyntax = true; // Syntax 1 is old syntax + } + else if ( leader->m_syntaxVersion == -1 ) + { + // We do not know the version, but it still might be an old syntax. + // However such old documents have still an author attribute, so check its value + if ( author == "Reginald Stadlbauer and Torben Weis" ) + { + kdDebug(30508) << "No syntax version but author attribute matches => assuming old syntax" << endl; + leader->m_oldSyntax = true; + } + else + { + kdWarning(30508) << "No syntax version found, author attribute does not match => assuming new syntax" << endl; + } + } + + leader->doOpenHead(); + + // At first, process , even if mostly it will not be needed + TQDomNode nodeIgnoreList=myNode.namedItem("SPELLCHECKIGNORELIST"); + if ( nodeIgnoreList.isNull () ) + kdDebug (30508) << "No " << endl; // Most files will not have it! + else + ProcessSpellCheckIgnoreListTag (nodeIgnoreList, NULL, leader); + + // Process now, even if mostly the output will need to be delayed. + TQDomNode nodePaper=myNode.namedItem("PAPER"); + if ( nodePaper.isNull () ) + kdWarning (30508) << "No " << endl; + else + ProcessPaperTag (nodePaper, NULL, leader); + + // Process + TQDomNode nodeVariableSettings=myNode.namedItem("VARIABLESETTINGS"); + if ( nodeVariableSettings.isNull () ) + kdWarning (30508) << "No " << endl; + else + ProcessVariableSettingsTag (nodeVariableSettings, NULL, leader); + + // Then we process the styles + TQDomNode nodeStyles=myNode.namedItem("STYLES"); + if ( nodeStyles.isNull () ) + kdWarning (30508) << "No " << endl; + else + ProcessStylesPluralTag (nodeStyles, NULL, leader); + + // Process framesets, but only to find and extract footnotes (also endnotes) + TQValueList footnotes; + TQDomNode nodeFramesets=myNode.namedItem("FRAMESETS"); + if ( !nodeFramesets.isNull() ) + ProcessFootnoteFramesetsTag(nodeFramesets, &footnotes, leader ); + + // Process all framesets and pictures + TQValueList tagProcessingList; + TQValueList paraList; + + tagProcessingList + << TagProcessing ( "PAPER" ) // Already done + << TagProcessing ( "ATTRIBUTES" ) + << TagProcessing ( "FRAMESETS", ProcessFramesetsTag, ¶List ) + << TagProcessing ( "STYLES" ) // Already done + << TagProcessing ( "PICTURES", ProcessPixmapsTag, ¶List ) + << TagProcessing ( "PIXMAPS", ProcessPixmapsTag, ¶List ) + << TagProcessing ( "CLIPARTS", ProcessPixmapsTag, ¶List ) + << TagProcessing ( "EMBEDDED" ) + << TagProcessing ( "BOOKMARKS", ProcessBookmarksTag, &leader->m_bookmarkList ) + ; + + // TODO: why are the followings used by KWord 1.2 but are not in its DTD? + tagProcessingList << TagProcessing ( "SERIALL" ); + tagProcessingList << TagProcessing ( "FOOTNOTEMGR" ); + + ProcessSubtags (myNode, tagProcessingList, leader); + + leader->doCloseHead(); + leader->doDeclareNonInlinedFramesets( leader->m_nonInlinedPictureAnchors, leader->m_nonInlinedTableAnchors ); + leader->doOpenBody(); + + leader->doFullDocument (paraList); + + kdDebug(30508) << "Unachored Framesets : START" << endl; + TQStringList::ConstIterator it; + for ( it = leader->m_unanchoredFramesets.begin(); it != leader->m_unanchoredFramesets.end(); ++it ) + { + kdDebug(30508) << (*it) << endl; + } + kdDebug(30508) << "Unachored Framesets : END" << endl; + + FreeCellParaLists (paraList); + + leader->doCloseBody(); + + //kdDebug (30508) << "Exiting ProcessDocTag" << endl; +} + + +void KWEFKWordLeader::setWorker ( KWEFBaseWorker *newWorker ) +{ + m_worker = newWorker; + + if (newWorker) + newWorker->registerKWordLeader(this); +} + + +KWEFBaseWorker *KWEFKWordLeader::getWorker(void) const +{ + return m_worker; +} + + +// Short simple definition for methods with void parameter +#define DO_VOID_DEFINITION(string) \ + bool KWEFKWordLeader::string() \ + {\ + if (m_worker) \ + return m_worker->string(); \ + return false; \ + } + + +bool KWEFKWordLeader::doOpenFile ( const TQString &filenameOut, const TQString &to ) +{ + if ( m_worker ) + return m_worker->doOpenFile (filenameOut, to); + + // As it would be the first method to be called, warn if worker is NULL + kdError (30508) << "No Worker! (in KWEFKWordLeader::doOpenFile)" << endl; + + return false; +} + + +DO_VOID_DEFINITION (doCloseFile) +DO_VOID_DEFINITION (doAbortFile) +DO_VOID_DEFINITION (doOpenDocument) +DO_VOID_DEFINITION (doCloseDocument) +DO_VOID_DEFINITION (doOpenStyles) +DO_VOID_DEFINITION (doCloseStyles) +DO_VOID_DEFINITION (doOpenHead) +DO_VOID_DEFINITION (doCloseHead) +DO_VOID_DEFINITION (doOpenBody) +DO_VOID_DEFINITION (doCloseBody) +DO_VOID_DEFINITION (doOpenSpellCheckIgnoreList) +DO_VOID_DEFINITION (doCloseSpellCheckIgnoreList) + +bool KWEFKWordLeader::doFullDocumentInfo (const KWEFDocumentInfo &docInfo) +{ + if ( m_worker ) + return m_worker->doFullDocumentInfo (docInfo); + + return false; +} + + +bool KWEFKWordLeader::doVariableSettings (const VariableSettingsData &varSettings) +{ + if ( m_worker ) + return m_worker->doVariableSettings (varSettings); + + return false; +} + + +bool KWEFKWordLeader::doFullDocument (const TQValueList ¶List) +{ + if ( m_worker ) + return m_worker->doFullDocument (paraList); + + return false; +} + +bool KWEFKWordLeader::doPageInfo ( const int headerType, const int footerType ) +{ + if ( m_worker ) + return m_worker->doPageInfo ( headerType, footerType ); + + return false; +} + +bool KWEFKWordLeader::doFullPaperFormat ( const int format, const double width, const double height, const int orientation ) +{ + if ( m_worker ) + return m_worker->doFullPaperFormat (format, width, height, orientation); + + return false; +} + +bool KWEFKWordLeader::doFullPaperBorders (const double top, const double left, const double bottom, const double right) +{ + if ( m_worker ) + return m_worker->doFullPaperBorders (top, left, bottom, right); + + return false; +} + +bool KWEFKWordLeader::doFullPaperFormatOther ( const int columns, const double columnspacing, const int numPages ) +{ + if ( m_worker ) + return m_worker->doFullPaperFormatOther ( columns, columnspacing, numPages ); + + return false; +} + +bool KWEFKWordLeader::doFullDefineStyle ( LayoutData &layout ) +{ + if ( m_worker ) + return m_worker->doFullDefineStyle (layout); + + return false; +} + +bool KWEFKWordLeader::doFullSpellCheckIgnoreWord (const TQString& ignoreword) +{ + if ( m_worker ) + return m_worker->doFullSpellCheckIgnoreWord (ignoreword); + + return false; +} + +bool KWEFKWordLeader::doHeader ( const HeaderData& header ) +{ + if ( m_worker ) + return m_worker->doHeader (header); + + return false; +} + +bool KWEFKWordLeader::doFooter ( const FooterData& footer ) +{ + if ( m_worker ) + return m_worker->doFooter (footer); + + return false; +} + +bool KWEFKWordLeader::doDeclareNonInlinedFramesets( TQValueList& pictureAnchors, TQValueList& tableAnchors ) +{ + if ( m_worker ) + return m_worker->doDeclareNonInlinedFramesets( pictureAnchors, tableAnchors ); + + return false; +} + +static bool ParseFile ( TQIODevice* subFile, TQDomDocument& doc) +{ + TQString errorMsg; + int errorLine; + int errorColumn; + + if ( !doc.setContent (subFile, &errorMsg, &errorLine, &errorColumn) ) + { + kdError (30508) << "Parsing Error! Aborting! (in ParseFile)" << endl + << " Line: " << errorLine << " Column: " << errorColumn << endl + << " Message: " << errorMsg << endl; + // ### TODO: the error is in which sub-file? + KMessageBox::error( 0L, i18n("An error has occurred while parsing the KWord file.\nAt line: %1, column %2\nError message: %3") + .arg( errorLine ).arg( errorColumn ).arg(i18n( "TQXml", errorMsg.utf8() ) ), + i18n("KWord Export Filter Library"), 0 ); + return false; + } + return true; +} + +static bool ProcessStoreFile ( TQIODevice* subFile, + void (*processor) (TQDomNode, void *, KWEFKWordLeader *), + KWEFKWordLeader* leader) +{ + if (!subFile) + { + kdWarning(30508) << "Could not get a device for the document!" << endl; + } + else if ( subFile->open ( IO_ReadOnly ) ) + { + kdDebug (30508) << "Processing Document..." << endl; + TQDomDocument doc; + if (!ParseFile(subFile, doc)) + { + subFile->close(); + return false; + } + // We must close the subFile before processing, + // as the processing could open other sub files. + // However, it would crash if two sub files are opened together + subFile->close(); + + TQDomNode docNode = doc.documentElement(); + processor (docNode, NULL, leader); + return true; + } + else + { + // Note: we do not worry too much if we cannot open the document info! + kdWarning (30508) << "Unable to open document!" << endl; + } + return false; +} + +TQIODevice* KWEFKWordLeader::getSubFileDevice(const TQString& fileName) +{ + KoStoreDevice* subFile; + + subFile=m_chain->storageFile(fileName,KoStore::Read); + + if (!subFile) + { + kdError(30508) << "Could not get a device for sub-file: " << fileName << endl; + return NULL; + } + return subFile; +} + + +bool KWEFKWordLeader::loadSubFile(const TQString& fileName, TQByteArray& array) +{ + KoStoreDevice* subFile; + + subFile=m_chain->storageFile(fileName,KoStore::Read); + + if (!subFile) + { + kdError(30508) << "Could not get a device for sub-file: " << fileName << endl; + return false; + } + else if ( subFile->open ( IO_ReadOnly ) ) + { + array = subFile->readAll(); + subFile->close (); + } + else + { + kdError(30508) << "Unable to open " << fileName << " sub-file" << endl; + return false; + } + + return true; +} + +KoFilter::ConversionStatus KWEFKWordLeader::convert( KoFilterChain* chain, + const TQCString& from, const TQCString& to) +{ + if ( from != "application/x-kword" ) + { + return KoFilter::NotImplemented; + } + + if (!chain) + { + kdError(30508) << "'Chain' is NULL! Internal error of the filter system?" << endl; + return KoFilter::StupidError; + } + + m_chain=chain; + + if ( !doOpenFile (chain->outputFile(),to) ) + { + kdError (30508) << "Worker could not open export file! Aborting!" << endl; + return KoFilter::StupidError; + } + + if ( !doOpenDocument () ) + { + kdError (30508) << "Worker could not open document! Aborting!" << endl; + doAbortFile (); + return KoFilter::StupidError; + } + + KoStoreDevice* subFile; + + subFile=chain->storageFile("documentinfo.xml",KoStore::Read); + kdDebug (30508) << "Processing documentinfo.xml..." << endl; + // Do not care if we cannot open the document info. + ProcessStoreFile (subFile, ProcessDocumentInfoTag, this); + + subFile=chain->storageFile("root",KoStore::Read); + kdDebug (30508) << "Processing root..." << endl; + if (!ProcessStoreFile (subFile, ProcessDocTag, this)) + { + kdWarning(30508) << "Opening root has failed. Trying raw XML file!" << endl; + + const TQString filename( chain->inputFile() ); + if (filename.isEmpty() ) + { + kdError(30508) << "Could not open document as raw XML! Aborting!" << endl; + doAbortFile(); + return KoFilter::StupidError; + } + else + { + TQFile file( filename ); + if ( ! ProcessStoreFile( TQT_TQIODEVICE(&file), ProcessDocTag, this ) ) + { + kdError(30508) << "Could not process document! Aborting!" << endl; + doAbortFile(); + return KoFilter::StupidError; + } + } + } + + doCloseDocument (); + + doCloseFile (); + + return KoFilter::OK; +} diff --git a/filters/kword/libexport/KWEFStructures.cc b/filters/kword/libexport/KWEFStructures.cpp similarity index 100% rename from filters/kword/libexport/KWEFStructures.cc rename to filters/kword/libexport/KWEFStructures.cpp diff --git a/filters/kword/libexport/KWEFStructures.h b/filters/kword/libexport/KWEFStructures.h index 682606feb..2f8ba74ab 100644 --- a/filters/kword/libexport/KWEFStructures.h +++ b/filters/kword/libexport/KWEFStructures.h @@ -22,8 +22,8 @@ /* The classes in this file are based on a class in the old files: - /home/kde/koffice/filters/kword/ascii/asciiexport.cc - /home/kde/koffice/filters/kword/docbookexpert/docbookexport.cc + /home/kde/koffice/filters/kword/ascii/asciiexport.cpp + /home/kde/koffice/filters/kword/docbookexpert/docbookexport.cpp The old file was copyrighted by Copyright (C) 1998, 1999 Reginald Stadlbauer diff --git a/filters/kword/libexport/KWEFUtil.cc b/filters/kword/libexport/KWEFUtil.cpp similarity index 100% rename from filters/kword/libexport/KWEFUtil.cc rename to filters/kword/libexport/KWEFUtil.cpp diff --git a/filters/kword/libexport/Makefile.am b/filters/kword/libexport/Makefile.am index 6e2581749..cef09322c 100644 --- a/filters/kword/libexport/Makefile.am +++ b/filters/kword/libexport/Makefile.am @@ -10,8 +10,8 @@ libkwordexportfilters_la_LIBADD = $(KOFFICE_LIBS) lib_LTLIBRARIES = libkwordexportfilters.la -libkwordexportfilters_la_SOURCES = TagProcessing.cc KWEFStructures.cc\ -ProcessDocument.cc KWEFUtil.cc KWEFKWordLeader.cc KWEFBaseWorker.cc +libkwordexportfilters_la_SOURCES = TagProcessing.cpp KWEFStructures.cpp\ +ProcessDocument.cpp KWEFUtil.cpp KWEFKWordLeader.cpp KWEFBaseWorker.cpp noinst_HEADERS = TagProcessing.h KWEFStructures.h\ ProcessDocument.h KWEFUtil.h KWEFKWordLeader.h KWEFBaseWorker.h diff --git a/filters/kword/libexport/ProcessDocument.cc b/filters/kword/libexport/ProcessDocument.cc deleted file mode 100644 index 3a626f7f1..000000000 --- a/filters/kword/libexport/ProcessDocument.cc +++ /dev/null @@ -1,1063 +0,0 @@ -/* - This file is part of the KDE project - Copyright (C) 2001, 2002, 2004 Nicolas GOUTTE - Copyright (c) 2001 IABG mbH. All rights reserved. - Contact: Wolf-Michael Bolle - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. -*/ - -/* - This file is based on the old file: - /home/kde/koffice/filters/kword/ascii/asciiexport.cc - - The old file was copyrighted by - Copyright (C) 1998, 1999 Reginald Stadlbauer - Copyright (c) 2000 ID-PRO Deutschland GmbH. All rights reserved. - Contact: Wolf-Michael Bolle - - The old file was licensed under the terms of the GNU Library General Public - License version 2. -*/ - -/* - Part of the code is based on code licensed under the terms of the - GNU Library General Public License version 2: - Copyright 2001 Michael Johnson -*/ - -#include -#include - -#include - -#include "KWEFStructures.h" -#include "TagProcessing.h" -#include "ProcessDocument.h" -#include "KWEFKWordLeader.h" - - -// == KOFFICE DOCUMENT INFORMATION == - -// TODO: verify that all document info is read! - -void ProcessTextTag ( TQDomNode myNode, void *tagData, KWEFKWordLeader *leader ) -{ - TQString *tagText = (TQString *) tagData; - - *tagText = myNode.toElement().text(); // Get the text, also from a CDATA section - - TQValueList tagProcessingList; - tagProcessingList.append ( TagProcessing ( "xml:space" ) ); - ProcessSubtags (myNode, tagProcessingList, leader); - - AllowNoSubtags (myNode, leader); -} - -static void ProcessAboutTag ( TQDomNode myNode, - void *tagData, - KWEFKWordLeader *leader ) -{ - KWEFDocumentInfo *docInfo = (KWEFDocumentInfo *) tagData; - - AllowNoAttributes (myNode); - - TQValueList tagProcessingList; - tagProcessingList.append ( TagProcessing ( "title", ProcessTextTag, &docInfo->title ) ); - tagProcessingList.append ( TagProcessing ( "abstract", ProcessTextTag, &docInfo->abstract ) ); - tagProcessingList.append ( TagProcessing ( "keyword", ProcessTextTag, &docInfo->keywords ) ); - tagProcessingList.append ( TagProcessing ( "subject", ProcessTextTag, &docInfo->subject ) ); - ProcessSubtags (myNode, tagProcessingList, leader); -} - - -static void ProcessAuthorTag ( TQDomNode myNode, - void *tagData, - KWEFKWordLeader *leader ) -{ - KWEFDocumentInfo *docInfo = (KWEFDocumentInfo *) tagData; - - AllowNoAttributes (myNode); - - TQValueList tagProcessingList; - tagProcessingList.append ( TagProcessing ( "full-name", ProcessTextTag, &docInfo->fullName ) ); - tagProcessingList.append ( TagProcessing ( "title", ProcessTextTag, &docInfo->jobTitle ) ); - tagProcessingList.append ( TagProcessing ( "company", ProcessTextTag, &docInfo->company ) ); - tagProcessingList.append ( TagProcessing ( "email", ProcessTextTag, &docInfo->email ) ); - tagProcessingList.append ( TagProcessing ( "telephone", ProcessTextTag, &docInfo->telephone ) ); - tagProcessingList.append ( TagProcessing ( "telephone-work", ProcessTextTag, &docInfo->telephonework ) ); - tagProcessingList.append ( TagProcessing ( "fax", ProcessTextTag, &docInfo->fax ) ); - tagProcessingList.append ( TagProcessing ( "country", ProcessTextTag, &docInfo->country ) ); - tagProcessingList.append ( TagProcessing ( "postal-code", ProcessTextTag, &docInfo->postalCode ) ); - tagProcessingList.append ( TagProcessing ( "city", ProcessTextTag, &docInfo->city ) ); - tagProcessingList.append ( TagProcessing ( "street", ProcessTextTag, &docInfo->street ) ); - tagProcessingList.append ( TagProcessing ( "initial", ProcessTextTag, &docInfo->initial ) ); - tagProcessingList.append ( TagProcessing ( "position", ProcessTextTag, &docInfo->position ) ); - ProcessSubtags (myNode, tagProcessingList, leader); -} - - -void ProcessDocumentInfoTag ( TQDomNode myNode, - void *, - KWEFKWordLeader *leader ) -{ - AllowNoAttributes (myNode); - - KWEFDocumentInfo docInfo; - - TQValueList tagProcessingList; - tagProcessingList.append ( TagProcessing ( "log" ) ); - tagProcessingList.append ( TagProcessing ( "author", ProcessAuthorTag, &docInfo ) ); - tagProcessingList.append ( TagProcessing ( "about", ProcessAboutTag, &docInfo ) ); - ProcessSubtags (myNode, tagProcessingList, leader); - - leader->doFullDocumentInfo (docInfo); -} - - -// == KWORD == - -// Every tag has its own processing function. All of those functions -// have the same parameters since the functions are passed to -// ProcessSubtags throuch the TagProcessing class. The top level -// function is ProcessDocTag and can be called with the node returned -// by TQDomDocument::documentElement (). The tagData argument can be -// used to either pass variables down to the subtags or to allow -// subtags to return values. As a bare minimum the tag processing -// functions must handle the tag's attributes and the tag's subtags -// (which it can choose to ignore). Currently implemented is -// processing for the following tags and attributes: -// -// TODO: make this list up-to-date -// -// DOC -// FRAMESETS -// FRAMESET -// PARAGRAPH -// TEXT - Text Element -// FORMATS -// FORMAT id=1 pos= len= -// LAYOUT -// NAME value= - - -// -------------------------------------------------------------------------------- - - -static void ProcessOneAttrTag ( TQDomNode myNode, - TQString attrName, - TQString attrType, - void *attrData, - KWEFKWordLeader *leader ) -{ - TQValueList attrProcessingList; - attrProcessingList << AttrProcessing (attrName, attrType, attrData); - ProcessAttributes (myNode, attrProcessingList); - - AllowNoSubtags (myNode, leader); -} - - -static void ProcessColorAttrTag ( TQDomNode myNode, void *tagData, KWEFKWordLeader * ) -{ - TQColor *attrValue = (TQColor *) tagData; - - int red, green, blue; - - TQValueList attrProcessingList; - attrProcessingList << AttrProcessing ( "red", red ); - attrProcessingList << AttrProcessing ( "green", green ); - attrProcessingList << AttrProcessing ( "blue", blue ); - ProcessAttributes (myNode, attrProcessingList); - - attrValue->setRgb (red, green, blue); -} - - -static void ProcessBoolIntAttrTag ( TQDomNode myNode, - TQString attrName, - void *attrData, - KWEFKWordLeader *leader ) -{ - ProcessOneAttrTag (myNode, attrName, "bool", attrData, leader); -} - - -// -------------------------------------------------------------------------------- - - -static void ProcessIntValueTag (TQDomNode myNode, void *tagData, KWEFKWordLeader *leader ) -{ - ProcessOneAttrTag (myNode, "value", "int", tagData, leader); -} - - -static void ProcessBoolIntValueTag ( TQDomNode myNode, void *tagData, KWEFKWordLeader *leader ) -{ - ProcessBoolIntAttrTag (myNode, "value", tagData, leader); -} - - -static void ProcessStringValueTag ( TQDomNode myNode, void *tagData, KWEFKWordLeader *leader ) -{ - ProcessOneAttrTag (myNode, "value", TQSTRING_OBJECT_NAME_STRING, tagData, leader); -} - -static void ProcessStringNameTag (TQDomNode myNode, void *tagData, KWEFKWordLeader *leader ) -{ - ProcessOneAttrTag (myNode, "name", TQSTRING_OBJECT_NAME_STRING, tagData, leader); -} - - -// -------------------------------------------------------------------------------- - - -static void ProcessOldLayoutChildTag (TQDomNode myNode, void *tagData, KWEFKWordLeader* /*leader*/) -{ - TQValueList attrProcessingList; - - double* d = (double*) ( tagData ); - *d = 0.0; // Put a sensible default - - attrProcessingList - << AttrProcessing ( "pt", *d ) - << AttrProcessing ( "inch" ) - << AttrProcessing ( "mm" ) - ; - ProcessAttributes (myNode, attrProcessingList); -} - -static void ProcessUnderlineTag (TQDomNode myNode, void *tagData, KWEFKWordLeader* /*leader*/ ) -{ - TextFormatting* text=(TextFormatting*) tagData; - TQString str,style; - TQString strColor; - - text->underlineWord = false; - - TQValueList attrProcessingList; - - attrProcessingList - << AttrProcessing ( "value", str ) - << AttrProcessing ( "styleline", style ) - << AttrProcessing ( "wordbyword", text->underlineWord ) - << AttrProcessing ( "underlinecolor", strColor ) - ; - ProcessAttributes (myNode, attrProcessingList); - - str=str.stripWhiteSpace(); - text->underlineValue=str; - if ( (str=="0") || (str.isEmpty()) ) - { - text->underline=false; - } - else - { - // We assume that anything else is underlined - text->underline=true; - text->underlineStyle = style; - text->underlineColor.setNamedColor(strColor); - } -} - -static void ProcessStrikeoutTag (TQDomNode myNode, void *tagData, KWEFKWordLeader* /*leader*/ ) -{ - TextFormatting* text=(TextFormatting*) tagData; - TQString type, linestyle; - - text->strikeoutWord = false; - - TQValueList attrProcessingList; - attrProcessingList << AttrProcessing ("value" , type ); - attrProcessingList << AttrProcessing ("styleline" , linestyle ); - attrProcessingList << AttrProcessing ( "wordbyword", text->strikeoutWord ); - ProcessAttributes (myNode, attrProcessingList); - - if( type.isEmpty() || ( type == "0" ) ) - text->strikeout = false; - else - { - text->strikeout = true; - text->strikeoutType = type; - text->strikeoutLineStyle = linestyle; - if( text->strikeoutType == "1" ) - text->strikeoutType = "single"; - if( text->strikeoutLineStyle.isEmpty() ) - text->strikeoutLineStyle = "solid"; - } -} - - -void ProcessAnchorTag ( TQDomNode myNode, - void *tagData, - KWEFKWordLeader *leader ) -{ - TQString *instance = (TQString *) tagData; - - TQString type; - *instance = TQString(); - TQValueList attrProcessingList; - attrProcessingList << AttrProcessing ( "type", type ) - << AttrProcessing ( "instance", TQSTRING_OBJECT_NAME_STRING, instance ); - ProcessAttributes (myNode, attrProcessingList); - - if ( type != "frameset" ) - { - kdWarning (30508) << "Unknown ANCHOR type " << type << "!" << endl; - } - - if ( (*instance).isEmpty () ) - { - kdWarning (30508) << "Bad ANCHOR instance name!" << endl; - } - - AllowNoSubtags (myNode, leader); -} - - -static void ProcessLinkTag (TQDomNode myNode, void *tagData, KWEFKWordLeader *) -{ - VariableData *variable = (VariableData *) tagData; - - TQString linkName, hrefName; - - TQValueList attrProcessingList; - attrProcessingList.append ( AttrProcessing ("linkName", linkName) ); - attrProcessingList.append ( AttrProcessing ("hrefName", hrefName) ); - ProcessAttributes (myNode, attrProcessingList); - - variable->setLink(linkName, hrefName); -} - - -static void ProcessPgNumTag (TQDomNode myNode, void *tagData, KWEFKWordLeader *) -{ - VariableData *variable = (VariableData *) tagData; - - TQString subtype, value; - - TQValueList attrProcessingList; - attrProcessingList.append ( AttrProcessing ("subtype", subtype) ); - attrProcessingList.append ( AttrProcessing ("value", value ) ); - ProcessAttributes (myNode, attrProcessingList); - - variable->setPgNum(subtype, value); -} - - -static void ProcessTypeTag (TQDomNode myNode, void *tagData, KWEFKWordLeader *) -{ - VariableData *variable = (VariableData *) tagData; - - TQValueList attrProcessingList; - attrProcessingList.append ( AttrProcessing ("key", variable->m_key ) ); - attrProcessingList.append ( AttrProcessing ("text", variable->m_text) ); - attrProcessingList.append ( AttrProcessing ("type", variable->m_type) ); - ProcessAttributes (myNode, attrProcessingList); -} - -static void ProcessFieldTag (TQDomNode myNode, void *tagData, KWEFKWordLeader *) -{ - VariableData *variable = (VariableData *) tagData; - int subtype; - TQString name, value; - - TQValueList attrProcessingList; - attrProcessingList.append ( AttrProcessing ("subtype", subtype) ); - attrProcessingList.append ( AttrProcessing ("value", value ) ); - ProcessAttributes (myNode, attrProcessingList); - - switch( subtype ) - { - case 0: name = "fileName"; break; - case 1: name = "dirName"; break; - case 2: name = "authorName"; break; - case 3: name = "authorEmail"; break; - case 4: name = "authorCompany"; break; - case 10: name = "docTitle"; break; - case 11: name = "docAbstract"; break; - case 16: name = "authorInitial"; break; - default: break; - } - - if(!name.isEmpty()) - variable->setField(name, value); -} - -static void ProcessFootnoteTag (TQDomNode myNode, void *tagData, KWEFKWordLeader *leader) -{ - VariableData *variable = (VariableData *) tagData; - TQString frameset, value, numberingtype, notetype; - - TQValueList attrProcessingList; - attrProcessingList - << AttrProcessing ( "value", value ) - << AttrProcessing ( "numberingtype", numberingtype ) - << AttrProcessing ( "frameset", frameset ) - << AttrProcessing ( "notetype", notetype ) - ; - ProcessAttributes (myNode, attrProcessingList); - - // search for frameset in the footnoteList - for(unsigned i=0;ifootnoteList.count();i++) - { - if( leader->footnoteList[i].frameName == frameset ) - { - variable->setFootnote( notetype, numberingtype, value, &leader->footnoteList[i].para ); - break; - } - } -} - -static void ProcessNoteTag (TQDomNode myNode, void *tagData, KWEFKWordLeader *leader) -{ - VariableData *variable = (VariableData *) tagData; - - TQString note; - - TQValueList attrProcessingList; - attrProcessingList - << AttrProcessing ( "note", note ) - ; - ProcessAttributes (myNode, attrProcessingList); - - // set it even if note is empty - variable->setGenericData( "note", note ); -} - -// ### TODO: some files have not a tag but its supposed children are directly children of -static void ProcessVariableTag (TQDomNode myNode, void* tagData, KWEFKWordLeader* leader) -{ - VariableData *variable = (VariableData *) tagData; - - TQValueList tagProcessingList; - // "TYPE|PGNUM|DATE|TIME|CUSTOM|SERIALLETTER|FIELD|LINK|NOTE" - tagProcessingList - << TagProcessing ( "TYPE", ProcessTypeTag, variable ) - << TagProcessing ( "PGNUM", ProcessPgNumTag, variable ) - << TagProcessing ( "DATE" ) - << TagProcessing ( "TIME" ) - << TagProcessing ( "CUSTOM" ) - << TagProcessing ( "SERIALLETTER" ) - << TagProcessing ( "FIELD", ProcessFieldTag, variable ) - << TagProcessing ( "LINK", ProcessLinkTag, variable ) - << TagProcessing ( "NOTE", ProcessNoteTag, variable ) - << TagProcessing ( "FOOTNOTE", ProcessFootnoteTag, variable ) - ; - ProcessSubtags (myNode, tagProcessingList, leader); -} - -static void AppendTagProcessingFormatOne(TQValueList& tagProcessingList, FormatData& formatData) -{ - tagProcessingList - << TagProcessing ( "COLOR", ProcessColorAttrTag, &formatData.text.fgColor ) - << TagProcessing ( "FONT", ProcessStringNameTag, &formatData.text.fontName ) - << TagProcessing ( "SIZE", ProcessIntValueTag, &formatData.text.fontSize ) - << TagProcessing ( "WEIGHT", ProcessIntValueTag, &formatData.text.weight ) - << TagProcessing ( "ITALIC", ProcessBoolIntValueTag, &formatData.text.italic ) - << TagProcessing ( "UNDERLINE", ProcessUnderlineTag, &formatData.text ) - << TagProcessing ( "STRIKEOUT", ProcessStrikeoutTag, &formatData.text ) - << TagProcessing ( "VERTALIGN", ProcessIntValueTag, &formatData.text.verticalAlignment ) - << TagProcessing ( "SHADOW" ) - << TagProcessing ( "FONTATTRIBUTE", ProcessStringValueTag, &formatData.text.fontAttribute ) - << TagProcessing ( "LANGUAGE", ProcessStringValueTag, &formatData.text.language ) - << TagProcessing ( "ANCHOR" ) - << TagProcessing ( "IMAGE" ) - << TagProcessing ( "PICTURE" ) - << TagProcessing ( "VARIABLE" ) - << TagProcessing ( "TEXTBACKGROUNDCOLOR", ProcessColorAttrTag, &formatData.text.bgColor ) - << TagProcessing ( "OFFSETFROMBASELINE" ) - << TagProcessing ( "CHARSET" ) // Old KWord documents or KWord's RTF import filter - ; - - if ( formatData.text.language == "xx" ) - { - // The text language should have been named "x-test" or so to follow the specification - // As it does not, we need to convert it. - formatData.text.language = "en_US"; - } -} - - -static void SubProcessFormatOneTag(TQDomNode myNode, - ValueListFormatData *formatDataList, int formatPos, int formatLen, - KWEFKWordLeader *leader) -{ - if ( formatPos == -1 || formatLen == -1 ) - { - // We have no position and no length defined - // It can happen in a child of