diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-01-20 01:29:50 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-01-20 01:29:50 +0000 |
commit | 8362bf63dea22bbf6736609b0f49c152f975eb63 (patch) | |
tree | 0eea3928e39e50fae91d4e68b21b1e6cbae25604 /karbon/plugins/whirlpinch | |
download | koffice-8362bf63dea22bbf6736609b0f49c152f975eb63.tar.gz koffice-8362bf63dea22bbf6736609b0f49c152f975eb63.zip |
Added old abandoned KDE3 version of koffice
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/koffice@1077364 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'karbon/plugins/whirlpinch')
-rw-r--r-- | karbon/plugins/whirlpinch/Makefile.am | 16 | ||||
-rw-r--r-- | karbon/plugins/whirlpinch/whirlpinchplugin.cc | 199 | ||||
-rw-r--r-- | karbon/plugins/whirlpinch/whirlpinchplugin.h | 90 | ||||
-rw-r--r-- | karbon/plugins/whirlpinch/whirlpinchplugin.rc | 11 |
4 files changed, 316 insertions, 0 deletions
diff --git a/karbon/plugins/whirlpinch/Makefile.am b/karbon/plugins/whirlpinch/Makefile.am new file mode 100644 index 00000000..a0d53a7c --- /dev/null +++ b/karbon/plugins/whirlpinch/Makefile.am @@ -0,0 +1,16 @@ +INCLUDES = $(KOFFICE_INCLUDES) -I$(top_srcdir)/karbon -I$(top_srcdir)/karbon/core $(KOPAINTER_INCLUDES) $(all_includes) + +kde_module_LTLIBRARIES = karbon_whirlpinchplugin.la + +karbon_whirlpinchplugin_la_SOURCES = whirlpinchplugin.cc +karbon_whirlpinchplugin_la_LIBADD = $(LIB_KPARTS) $(LIB_KOPAINTER) \ + ../../libkarboncommon.la + + +karbon_whirlpinchplugin_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) + +partpluginsdir = $(kde_datadir)/karbon/kpartplugins +partplugins_DATA = whirlpinchplugin.rc + +METASOURCES = AUTO + diff --git a/karbon/plugins/whirlpinch/whirlpinchplugin.cc b/karbon/plugins/whirlpinch/whirlpinchplugin.cc new file mode 100644 index 00000000..5c6c716a --- /dev/null +++ b/karbon/plugins/whirlpinch/whirlpinchplugin.cc @@ -0,0 +1,199 @@ +/* This file is part of the KDE project + Copyright (C) 2002, The Karbon Developers + + 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 <core/vselection.h> +#include "whirlpinchplugin.h" +#include <karbon_view.h> +#include <karbon_part.h> +#include <kgenericfactory.h> +#include <core/vdocument.h> +#include <core/vcomposite.h> +#include <core/vpath.h> +#include <core/vsegment.h> +#include <core/vglobal.h> + +#include <kdebug.h> + +#include <qgroupbox.h> +#include <qlabel.h> + +#include <knuminput.h> + +typedef KGenericFactory<WhirlPinchPlugin, KarbonView> WhirlPinchPluginFactory; +K_EXPORT_COMPONENT_FACTORY( karbon_whirlpinchplugin, WhirlPinchPluginFactory( "karbonwhirlpinchplugin" ) ) + +WhirlPinchPlugin::WhirlPinchPlugin( KarbonView *parent, const char* name, const QStringList & ) : Plugin( parent, name ) +{ + new KAction( + i18n( "&Whirl/Pinch..." ), "14_whirl", 0, this, + SLOT( slotWhirlPinch() ), actionCollection(), "path_whirlpinch" ); + + m_whirlPinchDlg = new VWhirlPinchDlg(); + m_whirlPinchDlg->setAngle( 20.0 ); + m_whirlPinchDlg->setPinch( 0.0 ); + m_whirlPinchDlg->setRadius( 100.0 ); +} + +void +WhirlPinchPlugin::slotWhirlPinch() +{ + KarbonPart *part = ((KarbonView *)parent())->part(); + if( part && m_whirlPinchDlg->exec() ) + part->addCommand( new VWhirlPinchCmd( &part->document(), m_whirlPinchDlg->angle(), m_whirlPinchDlg->pinch(), m_whirlPinchDlg->radius() ), true ); +} + +VWhirlPinchDlg::VWhirlPinchDlg( QWidget* parent, const char* name ) + : KDialogBase( parent, name, true, i18n( "Whirl Pinch" ), Ok | Cancel ) +{ + // add input fields: + QGroupBox* group = new QGroupBox( 2, Qt::Horizontal, i18n( "Properties" ), this ); + + new QLabel( i18n( "Angle:" ), group ); + m_angle = new KDoubleNumInput( group ); + new QLabel( i18n( "Pinch:" ), group ); + m_pinch = new KDoubleNumInput( group ); + new QLabel( i18n( "Radius:" ), group ); + m_radius = new KDoubleNumInput( group ); + group->setMinimumWidth( 300 ); + + // signals and slots: + connect( this, SIGNAL( okClicked() ), this, SLOT( accept() ) ); + connect( this, SIGNAL( cancelClicked() ), this, SLOT( reject() ) ); + + setMainWidget( group ); + setFixedSize( baseSize() ); +} + +double +VWhirlPinchDlg::angle() const +{ + return m_angle->value(); +} + +double +VWhirlPinchDlg::pinch() const +{ + return m_pinch->value(); +} + +double +VWhirlPinchDlg::radius() const +{ + return m_radius->value(); +} + +void +VWhirlPinchDlg::setAngle( double value ) +{ + m_angle->setValue( value); +} + +void +VWhirlPinchDlg::setPinch( double value ) +{ + m_pinch->setValue(value); +} + +void +VWhirlPinchDlg::setRadius( double value ) +{ + m_radius->setValue( value); +} + +VWhirlPinchCmd::VWhirlPinchCmd( VDocument* doc, + double angle, double pinch, double radius ) + : VReplacingCmd( doc, i18n( "Whirl Pinch" ) ) +{ + m_angle = angle; + m_pinch = pinch; + m_radius = radius; + m_center = document()->selection()->boundingBox().center(); +} + +VWhirlPinchCmd::~VWhirlPinchCmd() +{ +} + +void +VWhirlPinchCmd::visitVPath( VPath& composite ) +{ + // first subdivide: +// VInsertKnots insertKnots( 2 ); +// insertKnots.visit( composite ); + + VVisitor::visitVPath( composite ); +} + +void +VWhirlPinchCmd::visitVSubpath( VSubpath& path ) +{ + QWMatrix m; + KoPoint delta; + double dist; + + path.first(); + + VSegment *curr = path.current(); + + while( curr ) + { +// TODO: selfmade this function since it's gone: +// path.current()->convertToCurve(); + + // Apply effect to each segment node. + for( int i = 0; i < curr->degree(); ++i ) + { + // calculate distance from whirl center to actual point + delta = curr->point( i ) - m_center; + dist = sqrt( delta.x() * delta.x() + delta.y() * delta.y() ); + + // check if point is inside the whirl radius + if( dist < m_radius ) + { + m.reset(); + + // normalize distance to whirl radius + dist /= m_radius; + + double scale = pow( sin( VGlobal::pi_2 * dist ), -m_pinch ); + // pinch: + m.translate( m_center.x(), m_center.y() ); + m.scale( scale, scale ); + + // whirl: + m.rotate( m_angle * ( 1.0 - dist ) * ( 1.0 - dist ) ); + m.translate( -m_center.x(), -m_center.y() ); + + path.current()->setPoint( i, curr->point( i ).transform( m ) ); + } + + } + + if( !success() ) + setSuccess(); + + curr = path.next(); + } + + // Invalidate bounding box once. + path.invalidateBoundingBox(); +} + +#include "whirlpinchplugin.moc" + diff --git a/karbon/plugins/whirlpinch/whirlpinchplugin.h b/karbon/plugins/whirlpinch/whirlpinchplugin.h new file mode 100644 index 00000000..ffbff5b2 --- /dev/null +++ b/karbon/plugins/whirlpinch/whirlpinchplugin.h @@ -0,0 +1,90 @@ +/* This file is part of the KDE project + Copyright (C) 2002, The Karbon Developers + + 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. +*/ + +#ifndef __WHIRLPINCHPLUGIN_H__ +#define __WHIRLPINCHPLUGIN_H__ + +#include <kdialogbase.h> +#include <kparts/plugin.h> +#include <commands/vreplacingcmd.h> + +class KarbonView; +class VWhirlPinchDlg; + +class WhirlPinchPlugin : public KParts::Plugin +{ + Q_OBJECT +public: + WhirlPinchPlugin( KarbonView *parent, const char* name, const QStringList & ); + virtual ~WhirlPinchPlugin() {} + +private slots: + void slotWhirlPinch(); + +private: + VWhirlPinchDlg *m_whirlPinchDlg; +}; + +class KDoubleNumInput; + +class VWhirlPinchDlg : public KDialogBase +{ + Q_OBJECT + +public: + VWhirlPinchDlg( QWidget* parent = 0L, const char* name = 0L ); + + double angle() const; + double pinch() const; + double radius() const; + void setAngle( double value ); + void setPinch( double value ); + void setRadius( double value ); + +private: + KDoubleNumInput* m_angle; + KDoubleNumInput* m_pinch; + KDoubleNumInput* m_radius; +}; + +class VPath; +class VSubpath; +class VSelection; + +class VWhirlPinchCmd : public VReplacingCmd +{ +public: + VWhirlPinchCmd( VDocument* doc, + double angle, double pinch, double radius ); + virtual ~VWhirlPinchCmd(); + + virtual void visitVPath( VPath& composite ); + virtual void visitVSubpath( VSubpath& path ); + + virtual bool changesSelection() const { return true; } + +protected: + KoPoint m_center; + double m_angle; + double m_pinch; + double m_radius; +}; + +#endif + diff --git a/karbon/plugins/whirlpinch/whirlpinchplugin.rc b/karbon/plugins/whirlpinch/whirlpinchplugin.rc new file mode 100644 index 00000000..797707f7 --- /dev/null +++ b/karbon/plugins/whirlpinch/whirlpinchplugin.rc @@ -0,0 +1,11 @@ +<!DOCTYPE kpartgui> +<kpartplugin name="whirlpinchplugin" library="karbon_whirlpinchplugin"> +<MenuBar> + <Menu name="effects"> + <Action name="path_whirlpinch"/> + </Menu> +</MenuBar> +<ToolBar name="Effects" hidden="true" fullWidth="false"> + <Action name="path_whirlpinch"/> +</ToolBar> +</kpartplugin> |