From d63c9d696eb6e2539528b99afc21f4086c9defe3 Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Sun, 23 May 2021 20:48:35 +0900 Subject: Renaming of files in preparation for code style tools. Signed-off-by: Michele Calgaro (cherry picked from commit 8b78a8791bc539bcffe7159f9d9714d577cb3d7d) --- karbon/tools/Makefile.am | 38 +- karbon/tools/vcurvefit.cc | 565 ------------------ karbon/tools/vcurvefit.cpp | 565 ++++++++++++++++++ karbon/tools/vdefaulttools.cc | 87 --- karbon/tools/vdefaulttools.cpp | 87 +++ karbon/tools/vellipsetool.cc | 279 --------- karbon/tools/vellipsetool.cpp | 279 +++++++++ karbon/tools/vgradienttool.cc | 526 ----------------- karbon/tools/vgradienttool.cpp | 526 +++++++++++++++++ karbon/tools/vpatterntool.cc | 509 ---------------- karbon/tools/vpatterntool.cpp | 509 ++++++++++++++++ karbon/tools/vpenciltool.cc | 411 ------------- karbon/tools/vpenciltool.cpp | 411 +++++++++++++ karbon/tools/vpolygontool.cc | 165 ------ karbon/tools/vpolygontool.cpp | 165 ++++++ karbon/tools/vpolylinetool.cc | 504 ---------------- karbon/tools/vpolylinetool.cpp | 504 ++++++++++++++++ karbon/tools/vrectangletool.cc | 143 ----- karbon/tools/vrectangletool.cpp | 143 +++++ karbon/tools/vrotatetool.cc | 175 ------ karbon/tools/vrotatetool.cpp | 175 ++++++ karbon/tools/vroundrecttool.cc | 179 ------ karbon/tools/vroundrecttool.cpp | 179 ++++++ karbon/tools/vselectnodestool.cc | 443 -------------- karbon/tools/vselectnodestool.cpp | 443 ++++++++++++++ karbon/tools/vselecttool.cc | 613 -------------------- karbon/tools/vselecttool.cpp | 613 ++++++++++++++++++++ karbon/tools/vshapetool.cc | 274 --------- karbon/tools/vshapetool.cpp | 274 +++++++++ karbon/tools/vsheartool.cc | 219 ------- karbon/tools/vsheartool.cpp | 219 +++++++ karbon/tools/vsinustool.cc | 162 ------ karbon/tools/vsinustool.cpp | 162 ++++++ karbon/tools/vspiraltool.cc | 213 ------- karbon/tools/vspiraltool.cpp | 213 +++++++ karbon/tools/vstartool.cc | 249 -------- karbon/tools/vstartool.cpp | 249 ++++++++ karbon/tools/vtexttool.cc | 1159 ------------------------------------- karbon/tools/vtexttool.cpp | 1159 +++++++++++++++++++++++++++++++++++++ 39 files changed, 6894 insertions(+), 6894 deletions(-) delete mode 100644 karbon/tools/vcurvefit.cc create mode 100644 karbon/tools/vcurvefit.cpp delete mode 100644 karbon/tools/vdefaulttools.cc create mode 100644 karbon/tools/vdefaulttools.cpp delete mode 100644 karbon/tools/vellipsetool.cc create mode 100644 karbon/tools/vellipsetool.cpp delete mode 100644 karbon/tools/vgradienttool.cc create mode 100644 karbon/tools/vgradienttool.cpp delete mode 100644 karbon/tools/vpatterntool.cc create mode 100644 karbon/tools/vpatterntool.cpp delete mode 100644 karbon/tools/vpenciltool.cc create mode 100644 karbon/tools/vpenciltool.cpp delete mode 100644 karbon/tools/vpolygontool.cc create mode 100644 karbon/tools/vpolygontool.cpp delete mode 100644 karbon/tools/vpolylinetool.cc create mode 100644 karbon/tools/vpolylinetool.cpp delete mode 100644 karbon/tools/vrectangletool.cc create mode 100644 karbon/tools/vrectangletool.cpp delete mode 100644 karbon/tools/vrotatetool.cc create mode 100644 karbon/tools/vrotatetool.cpp delete mode 100644 karbon/tools/vroundrecttool.cc create mode 100644 karbon/tools/vroundrecttool.cpp delete mode 100644 karbon/tools/vselectnodestool.cc create mode 100644 karbon/tools/vselectnodestool.cpp delete mode 100644 karbon/tools/vselecttool.cc create mode 100644 karbon/tools/vselecttool.cpp delete mode 100644 karbon/tools/vshapetool.cc create mode 100644 karbon/tools/vshapetool.cpp delete mode 100644 karbon/tools/vsheartool.cc create mode 100644 karbon/tools/vsheartool.cpp delete mode 100644 karbon/tools/vsinustool.cc create mode 100644 karbon/tools/vsinustool.cpp delete mode 100644 karbon/tools/vspiraltool.cc create mode 100644 karbon/tools/vspiraltool.cpp delete mode 100644 karbon/tools/vstartool.cc create mode 100644 karbon/tools/vstartool.cpp delete mode 100644 karbon/tools/vtexttool.cc create mode 100644 karbon/tools/vtexttool.cpp (limited to 'karbon/tools') diff --git a/karbon/tools/Makefile.am b/karbon/tools/Makefile.am index 06d4e305..44880a13 100644 --- a/karbon/tools/Makefile.am +++ b/karbon/tools/Makefile.am @@ -36,25 +36,25 @@ noinst_HEADERS = \ vdefaulttools.h karbon_defaulttools_la_SOURCES = \ - vcurvefit.cc \ - vrotatetool.cc \ - vselectnodestool.cc \ - vselecttool.cc \ - vsheartool.cc \ - vellipsetool.cc \ - vgradienttool.cc \ - vpatterntool.cc \ - vpenciltool.cc \ - vpolygontool.cc \ - vpolylinetool.cc \ - vrectangletool.cc \ - vroundrecttool.cc \ - vshapetool.cc \ - vsinustool.cc \ - vspiraltool.cc \ - vstartool.cc \ - vtexttool.cc \ - vdefaulttools.cc + vcurvefit.cpp \ + vrotatetool.cpp \ + vselectnodestool.cpp \ + vselecttool.cpp \ + vsheartool.cpp \ + vellipsetool.cpp \ + vgradienttool.cpp \ + vpatterntool.cpp \ + vpenciltool.cpp \ + vpolygontool.cpp \ + vpolylinetool.cpp \ + vrectangletool.cpp \ + vroundrecttool.cpp \ + vshapetool.cpp \ + vsinustool.cpp \ + vspiraltool.cpp \ + vstartool.cpp \ + vtexttool.cpp \ + vdefaulttools.cpp karbon_defaulttools_la_LIBADD = $(LIB_TDEPARTS) $(LIB_KOFFICECORE) $(LIB_KOFFICEUI) $(LIB_KOPAINTER) ../libkarboncommon.la karbon_defaulttools_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) -ltdecore -ltdeui $(LIB_QT) -lkjs -ltdefx -ltdeio diff --git a/karbon/tools/vcurvefit.cc b/karbon/tools/vcurvefit.cc deleted file mode 100644 index 40d7b7e3..00000000 --- a/karbon/tools/vcurvefit.cc +++ /dev/null @@ -1,565 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2001, 2002, 2003 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 -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* - An Algorithm for Automatically Fitting Digitized Curves - by Philip J. Schneider - from "Graphics Gems", Academic Press, 1990 - - http://www.acm.org/pubs/tog/GraphicsGems/gems/FitCurves.c - http://www.acm.org/pubs/tog/GraphicsGems/gems/README -*/ - - -#include "vcurvefit.h" - -#define MAXPOINTS 1000 /* The most points you can have */ - - -class FitVector { - public: - FitVector(KoPoint &p){ - m_X=p.x(); - m_Y=p.y(); - } - - FitVector(){ - m_X=0; - m_Y=0; - } - - FitVector(KoPoint &a,KoPoint &b){ - m_X=a.x()-b.x(); - m_Y=a.y()-b.y(); - } - - void normalize(){ - double len=length(); - if(len==0.0f) - return; - m_X/=len; m_Y/=len; - } - - void negate(){ - m_X = -m_X; - m_Y = -m_Y; - } - - void scale(double s){ - double len = length(); - if(len==0.0f) - return; - m_X *= s/len; - m_Y *= s/len; - } - - double dot(FitVector &v){ - return ((m_X*v.m_X)+(m_Y*v.m_Y)); - } - - double length(){ - return (double) sqrt(m_X*m_X+m_Y*m_Y); - } - - KoPoint operator+(KoPoint &p){ - KoPoint b(p.x()+m_X,p.y()+m_Y); - return b; - } - - public: - double m_X,m_Y; -}; - -double distance(KoPoint *p1,KoPoint *p2){ - double dx = (p1->x()-p2->x()); - double dy = (p1->y()-p2->y()); - return sqrt( dx*dx + dy*dy ); -} - - -FitVector ComputeLeftTangent(TQPtrList &points,int end){ - FitVector tHat1(*points.at(end+1),*points.at(end)); - - tHat1.normalize(); - - return tHat1; -} - -FitVector ComputeRightTangent(TQPtrList &points,int end){ - FitVector tHat1(*points.at(end-1),*points.at(end)); - - tHat1.normalize(); - - return tHat1; -} - -/* - * ChordLengthParameterize : - * Assign parameter values to digitized points - * using relative distances between points. - */ -static double *ChordLengthParameterize(TQPtrList points,int first,int last) -{ - int i; - double *u; /* Parameterization */ - - u = new double[(last-first+1)]; - - u[0] = 0.0; - for (i = first+1; i <= last; i++) { - u[i-first] = u[i-first-1] + - distance(points.at(i), points.at(i-1)); - } - - for (i = first + 1; i <= last; i++) { - u[i-first] = u[i-first] / u[last-first]; - } - - return(u); -} - -static FitVector VectorAdd(FitVector a,FitVector b) -{ - FitVector c; - c.m_X = a.m_X + b.m_X; c.m_Y = a.m_Y + b.m_Y; - return (c); -} -static FitVector VectorScale(FitVector v,double s) -{ - FitVector result; - result.m_X = v.m_X * s; result.m_Y = v.m_Y * s; - return (result); -} - -static FitVector VectorSub(FitVector a,FitVector b) -{ - FitVector c; - c.m_X = a.m_X - b.m_X; c.m_Y = a.m_Y - b.m_Y; - return (c); -} - -static FitVector ComputeCenterTangent(TQPtrList points,int center) -{ - FitVector V1, V2, tHatCenter; - - FitVector cpointb = *points.at(center-1); - FitVector cpoint = *points.at(center); - FitVector cpointa = *points.at(center+1); - - V1 = VectorSub(cpointb,cpoint); - V2 = VectorSub(cpoint,cpointa); - tHatCenter.m_X= ((V1.m_X + V2.m_X)/2.0); - tHatCenter.m_Y= ((V1.m_Y + V2.m_Y)/2.0); - tHatCenter.normalize(); - return tHatCenter; -} - -/* - * B0, B1, B2, B3 : - * Bezier multipliers - */ -static double B0(double u) -{ - double tmp = 1.0 - u; - return (tmp * tmp * tmp); -} - - -static double B1(double u) -{ - double tmp = 1.0 - u; - return (3 * u * (tmp * tmp)); -} - -static double B2(double u) -{ - double tmp = 1.0 - u; - return (3 * u * u * tmp); -} - -static double B3(double u) -{ - return (u * u * u); -} - -/* - * GenerateBezier : - * Use least-squares method to find Bezier control points for region. - * - */ -KoPoint* GenerateBezier(TQPtrList &points, int first, int last, double *uPrime,FitVector tHat1,FitVector tHat2) -{ - int i; - FitVector A[MAXPOINTS][2]; /* Precomputed rhs for eqn */ - int nPts; /* Number of pts in sub-curve */ - double C[2][2]; /* Matrix C */ - double X[2]; /* Matrix X */ - double det_C0_C1, /* Determinants of matrices */ - det_C0_X, - det_X_C1; - double alpha_l, /* Alpha values, left and right */ - alpha_r; - FitVector tmp; /* Utility variable */ - KoPoint *curve; - - curve = new KoPoint[4]; - nPts = last - first + 1; - - - /* Compute the A's */ - for (i = 0; i < nPts; i++) { - FitVector v1, v2; - v1 = tHat1; - v2 = tHat2; - v1.scale(B1(uPrime[i])); - v2.scale(B2(uPrime[i])); - A[i][0] = v1; - A[i][1] = v2; - } - - /* Create the C and X matrices */ - C[0][0] = 0.0; - C[0][1] = 0.0; - C[1][0] = 0.0; - C[1][1] = 0.0; - X[0] = 0.0; - X[1] = 0.0; - - for (i = 0; i < nPts; i++) { - C[0][0] += (A[i][0]).dot(A[i][0]); - C[0][1] += A[i][0].dot(A[i][1]); - /* C[1][0] += V2Dot(&A[i][0], &A[i][1]);*/ - C[1][0] = C[0][1]; - C[1][1] += A[i][1].dot(A[i][1]); - - FitVector vfirstp1(*points.at(first+i)); - FitVector vfirst(*points.at(first)); - FitVector vlast(*points.at(last)); - - tmp = VectorSub(vfirstp1, - VectorAdd( - VectorScale(vfirst, B0(uPrime[i])), - VectorAdd( - VectorScale(vfirst, B1(uPrime[i])), - VectorAdd( - VectorScale(vlast, B2(uPrime[i])), - VectorScale(vlast, B3(uPrime[i])) )))); - - - X[0] += A[i][0].dot(tmp); - X[1] += A[i][1].dot(tmp); - } - - /* Compute the determinants of C and X */ - det_C0_C1 = C[0][0] * C[1][1] - C[1][0] * C[0][1]; - det_C0_X = C[0][0] * X[1] - C[0][1] * X[0]; - det_X_C1 = X[0] * C[1][1] - X[1] * C[0][1]; - - /* Finally, derive alpha values */ - if (det_C0_C1 == 0.0) { - det_C0_C1 = (C[0][0] * C[1][1]) * 10e-12; - } - alpha_l = det_X_C1 / det_C0_C1; - alpha_r = det_C0_X / det_C0_C1; - - - /* If alpha negative, use the Wu/Barsky heuristic (see text) */ - /* (if alpha is 0, you get coincident control points that lead to - * divide by zero in any subsequent NewtonRaphsonRootFind() call. */ - if (alpha_l < 1.0e-6 || alpha_r < 1.0e-6) { - double dist = distance(points.at(last),points.at(first)) / - 3.0; - - curve[0] = *points.at(first); - curve[3] = *points.at(last); - - tHat1.scale(dist); - tHat2.scale(dist); - - curve[1] = tHat1 + curve[0]; - curve[2] = tHat2 + curve[3]; - return curve; - } - - /* First and last control points of the Bezier curve are */ - /* positioned exactly at the first and last data points */ - /* Control points 1 and 2 are positioned an alpha distance out */ - /* on the tangent vectors, left and right, respectively */ - curve[0] = *points.at(first); - curve[3] = *points.at(last); - - tHat1.scale(alpha_l); - tHat2.scale(alpha_r); - - curve[1] = tHat1 + curve[0]; - curve[2] = tHat2 + curve[3]; - - return (curve); -} - -/* - * Bezier : - * Evaluate a Bezier curve at a particular parameter value - * - */ -static KoPoint BezierII(int degree,KoPoint *V, double t) -{ - int i, j; - KoPoint Q; /* Point on curve at parameter t */ - KoPoint *Vtemp; /* Local copy of control points */ - - Vtemp = new KoPoint[degree+1]; - - for (i = 0; i <= degree; i++) { - Vtemp[i] = V[i]; - } - - /* Triangle computation */ - for (i = 1; i <= degree; i++) { - for (j = 0; j <= degree-i; j++) { - Vtemp[j].setX((1.0 - t) * Vtemp[j].x() + t * Vtemp[j+1].x()); - Vtemp[j].setY((1.0 - t) * Vtemp[j].y() + t * Vtemp[j+1].y()); - } - } - - Q = Vtemp[0]; - delete[] Vtemp; - return Q; -} - -/* - * ComputeMaxError : - * Find the maximum squared distance of digitized points - * to fitted curve. -*/ -static double ComputeMaxError(TQPtrList points,int first,int last,KoPoint *curve,double *u,int *splitPoint) -{ - int i; - double maxDist; /* Maximum error */ - double dist; /* Current error */ - KoPoint P; /* Point on curve */ - FitVector v; /* Vector from point to curve */ - - *splitPoint = (last - first + 1)/2; - maxDist = 0.0; - for (i = first + 1; i < last; i++) { - P = BezierII(3, curve, u[i-first]); - v = VectorSub(P, *points.at(i)); - dist = v.length(); - if (dist >= maxDist) { - maxDist = dist; - *splitPoint = i; - } - } - return (maxDist); -} - - -/* - * NewtonRaphsonRootFind : - * Use Newton-Raphson iteration to find better root. - */ -static double NewtonRaphsonRootFind(KoPoint *Q,KoPoint P,double u) -{ - double numerator, denominator; - KoPoint Q1[3], Q2[2]; /* Q' and Q'' */ - KoPoint TQ_u, Q1_u, Q2_u; /*u evaluated at Q, Q', & Q'' */ - double uPrime; /* Improved u */ - int i; - - /* Compute Q(u) */ - TQ_u = BezierII(3,Q, u); - - /* Generate control vertices for Q' */ - for (i = 0; i <= 2; i++) { - Q1[i].setX((Q[i+1].x() - Q[i].x()) * 3.0); - Q1[i].setY((Q[i+1].y() - Q[i].y()) * 3.0); - } - - /* Generate control vertices for Q'' */ - for (i = 0; i <= 1; i++) { - Q2[i].setX((Q1[i+1].x() - Q1[i].x()) * 2.0); - Q2[i].setY((Q1[i+1].y() - Q1[i].y()) * 2.0); - } - - /* Compute Q'(u) and Q''(u) */ - Q1_u = BezierII(2, Q1, u); - Q2_u = BezierII(1, Q2, u); - - /* Compute f(u)/f'(u) */ - numerator = (TQ_u.x() - P.x()) * (Q1_u.x()) + (TQ_u.y() - P.y()) * (Q1_u.y()); - denominator = (Q1_u.x()) * (Q1_u.x()) + (Q1_u.y()) * (Q1_u.y()) + - (TQ_u.x() - P.x()) * (Q2_u.x()) + (TQ_u.y() - P.y()) * (Q2_u.y()); - - /* u = u - f(u)/f'(u) */ - uPrime = u - (numerator/denominator); - return (uPrime); -} - -/* - * Reparameterize: - * Given set of points and their parameterization, try to find - * a better parameterization. - * - */ -static double *Reparameterize(TQPtrList points,int first,int last,double *u,KoPoint *curve) -{ - int nPts = last-first+1; - int i; - double *uPrime; /* New parameter values */ - - uPrime = new double[nPts]; - for (i = first; i <= last; i++) { - uPrime[i-first] = NewtonRaphsonRootFind(curve, *points.at(i), u[i- - first]); - } - return (uPrime); -} - -KoPoint *FitCubic(TQPtrList &points,int first,int last,FitVector tHat1,FitVector tHat2,float error,int &width){ - double *u; - double *uPrime; - double maxError; - int splitPoint; - int nPts; - double iterationError; - int maxIterations=4; - FitVector tHatCenter; - KoPoint *curve; - int i; - - width=0; - - - iterationError=error*error; - nPts = last-first+1; - - if(nPts == 2){ - double dist = distance(points.at(last), points.at(first)) / 3.0; - - curve = new KoPoint[4]; - - curve[0] = *points.at(first); - curve[3] = *points.at(last); - - tHat1.scale(dist); - tHat2.scale(dist); - - curve[1] = tHat1 + curve[0]; - curve[2] = tHat2 + curve[3]; - - width=4; - return curve; - } - - /* Parameterize points, and attempt to fit curve */ - u = ChordLengthParameterize(points, first, last); - curve = GenerateBezier(points, first, last, u, tHat1, tHat2); - - - /* Find max deviation of points to fitted curve */ - maxError = ComputeMaxError(points, first, last, curve, u, &splitPoint); - if (maxError < error) { - delete[] u; - width=4; - return curve; - } - - - /* If error not too large, try some reparameterization */ - /* and iteration */ - if (maxError < iterationError) { - for (i = 0; i < maxIterations; i++) { - uPrime = Reparameterize(points, first, last, u, curve); - curve = GenerateBezier(points, first, last, uPrime, tHat1, tHat2); - maxError = ComputeMaxError(points, first, last, - curve, uPrime, &splitPoint); - if (maxError < error) { - delete[] u; - width=4; - return curve; - } - delete[] u; - u = uPrime; - } - } - - /* Fitting failed -- split at max error point and fit recursively */ - delete[] u; - delete[] curve; - tHatCenter = ComputeCenterTangent(points, splitPoint); - - int w1,w2; - KoPoint *cu1=NULL, *cu2=NULL; - cu1 = FitCubic(points, first, splitPoint, tHat1, tHatCenter, error,w1); - - tHatCenter.negate(); - cu2 = FitCubic(points, splitPoint, last, tHatCenter, tHat2, error,w2); - - KoPoint *newcurve = new KoPoint[w1+w2]; - for(int i=0;i &points,float error){ - FitVector tHat1, tHat2; - - tHat1 = ComputeLeftTangent(points,0); - tHat2 = ComputeRightTangent(points,points.count()-1); - - int width=0; - KoPoint *curve; - curve = FitCubic(points,0,points.count()-1,tHat1,tHat2,error,width); - - VPath *path = new VPath(NULL); - - if(width>3){ - path->moveTo(curve[0]); - path->curveTo(curve[1],curve[2],curve[3]); - for(int i=4;icurveTo(curve[i+1],curve[i+2],curve[i+3]); - } - } - - - delete[] curve; - return path; -} - diff --git a/karbon/tools/vcurvefit.cpp b/karbon/tools/vcurvefit.cpp new file mode 100644 index 00000000..40d7b7e3 --- /dev/null +++ b/karbon/tools/vcurvefit.cpp @@ -0,0 +1,565 @@ +/* This file is part of the KDE project + Copyright (C) 2001, 2002, 2003 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* + An Algorithm for Automatically Fitting Digitized Curves + by Philip J. Schneider + from "Graphics Gems", Academic Press, 1990 + + http://www.acm.org/pubs/tog/GraphicsGems/gems/FitCurves.c + http://www.acm.org/pubs/tog/GraphicsGems/gems/README +*/ + + +#include "vcurvefit.h" + +#define MAXPOINTS 1000 /* The most points you can have */ + + +class FitVector { + public: + FitVector(KoPoint &p){ + m_X=p.x(); + m_Y=p.y(); + } + + FitVector(){ + m_X=0; + m_Y=0; + } + + FitVector(KoPoint &a,KoPoint &b){ + m_X=a.x()-b.x(); + m_Y=a.y()-b.y(); + } + + void normalize(){ + double len=length(); + if(len==0.0f) + return; + m_X/=len; m_Y/=len; + } + + void negate(){ + m_X = -m_X; + m_Y = -m_Y; + } + + void scale(double s){ + double len = length(); + if(len==0.0f) + return; + m_X *= s/len; + m_Y *= s/len; + } + + double dot(FitVector &v){ + return ((m_X*v.m_X)+(m_Y*v.m_Y)); + } + + double length(){ + return (double) sqrt(m_X*m_X+m_Y*m_Y); + } + + KoPoint operator+(KoPoint &p){ + KoPoint b(p.x()+m_X,p.y()+m_Y); + return b; + } + + public: + double m_X,m_Y; +}; + +double distance(KoPoint *p1,KoPoint *p2){ + double dx = (p1->x()-p2->x()); + double dy = (p1->y()-p2->y()); + return sqrt( dx*dx + dy*dy ); +} + + +FitVector ComputeLeftTangent(TQPtrList &points,int end){ + FitVector tHat1(*points.at(end+1),*points.at(end)); + + tHat1.normalize(); + + return tHat1; +} + +FitVector ComputeRightTangent(TQPtrList &points,int end){ + FitVector tHat1(*points.at(end-1),*points.at(end)); + + tHat1.normalize(); + + return tHat1; +} + +/* + * ChordLengthParameterize : + * Assign parameter values to digitized points + * using relative distances between points. + */ +static double *ChordLengthParameterize(TQPtrList points,int first,int last) +{ + int i; + double *u; /* Parameterization */ + + u = new double[(last-first+1)]; + + u[0] = 0.0; + for (i = first+1; i <= last; i++) { + u[i-first] = u[i-first-1] + + distance(points.at(i), points.at(i-1)); + } + + for (i = first + 1; i <= last; i++) { + u[i-first] = u[i-first] / u[last-first]; + } + + return(u); +} + +static FitVector VectorAdd(FitVector a,FitVector b) +{ + FitVector c; + c.m_X = a.m_X + b.m_X; c.m_Y = a.m_Y + b.m_Y; + return (c); +} +static FitVector VectorScale(FitVector v,double s) +{ + FitVector result; + result.m_X = v.m_X * s; result.m_Y = v.m_Y * s; + return (result); +} + +static FitVector VectorSub(FitVector a,FitVector b) +{ + FitVector c; + c.m_X = a.m_X - b.m_X; c.m_Y = a.m_Y - b.m_Y; + return (c); +} + +static FitVector ComputeCenterTangent(TQPtrList points,int center) +{ + FitVector V1, V2, tHatCenter; + + FitVector cpointb = *points.at(center-1); + FitVector cpoint = *points.at(center); + FitVector cpointa = *points.at(center+1); + + V1 = VectorSub(cpointb,cpoint); + V2 = VectorSub(cpoint,cpointa); + tHatCenter.m_X= ((V1.m_X + V2.m_X)/2.0); + tHatCenter.m_Y= ((V1.m_Y + V2.m_Y)/2.0); + tHatCenter.normalize(); + return tHatCenter; +} + +/* + * B0, B1, B2, B3 : + * Bezier multipliers + */ +static double B0(double u) +{ + double tmp = 1.0 - u; + return (tmp * tmp * tmp); +} + + +static double B1(double u) +{ + double tmp = 1.0 - u; + return (3 * u * (tmp * tmp)); +} + +static double B2(double u) +{ + double tmp = 1.0 - u; + return (3 * u * u * tmp); +} + +static double B3(double u) +{ + return (u * u * u); +} + +/* + * GenerateBezier : + * Use least-squares method to find Bezier control points for region. + * + */ +KoPoint* GenerateBezier(TQPtrList &points, int first, int last, double *uPrime,FitVector tHat1,FitVector tHat2) +{ + int i; + FitVector A[MAXPOINTS][2]; /* Precomputed rhs for eqn */ + int nPts; /* Number of pts in sub-curve */ + double C[2][2]; /* Matrix C */ + double X[2]; /* Matrix X */ + double det_C0_C1, /* Determinants of matrices */ + det_C0_X, + det_X_C1; + double alpha_l, /* Alpha values, left and right */ + alpha_r; + FitVector tmp; /* Utility variable */ + KoPoint *curve; + + curve = new KoPoint[4]; + nPts = last - first + 1; + + + /* Compute the A's */ + for (i = 0; i < nPts; i++) { + FitVector v1, v2; + v1 = tHat1; + v2 = tHat2; + v1.scale(B1(uPrime[i])); + v2.scale(B2(uPrime[i])); + A[i][0] = v1; + A[i][1] = v2; + } + + /* Create the C and X matrices */ + C[0][0] = 0.0; + C[0][1] = 0.0; + C[1][0] = 0.0; + C[1][1] = 0.0; + X[0] = 0.0; + X[1] = 0.0; + + for (i = 0; i < nPts; i++) { + C[0][0] += (A[i][0]).dot(A[i][0]); + C[0][1] += A[i][0].dot(A[i][1]); + /* C[1][0] += V2Dot(&A[i][0], &A[i][1]);*/ + C[1][0] = C[0][1]; + C[1][1] += A[i][1].dot(A[i][1]); + + FitVector vfirstp1(*points.at(first+i)); + FitVector vfirst(*points.at(first)); + FitVector vlast(*points.at(last)); + + tmp = VectorSub(vfirstp1, + VectorAdd( + VectorScale(vfirst, B0(uPrime[i])), + VectorAdd( + VectorScale(vfirst, B1(uPrime[i])), + VectorAdd( + VectorScale(vlast, B2(uPrime[i])), + VectorScale(vlast, B3(uPrime[i])) )))); + + + X[0] += A[i][0].dot(tmp); + X[1] += A[i][1].dot(tmp); + } + + /* Compute the determinants of C and X */ + det_C0_C1 = C[0][0] * C[1][1] - C[1][0] * C[0][1]; + det_C0_X = C[0][0] * X[1] - C[0][1] * X[0]; + det_X_C1 = X[0] * C[1][1] - X[1] * C[0][1]; + + /* Finally, derive alpha values */ + if (det_C0_C1 == 0.0) { + det_C0_C1 = (C[0][0] * C[1][1]) * 10e-12; + } + alpha_l = det_X_C1 / det_C0_C1; + alpha_r = det_C0_X / det_C0_C1; + + + /* If alpha negative, use the Wu/Barsky heuristic (see text) */ + /* (if alpha is 0, you get coincident control points that lead to + * divide by zero in any subsequent NewtonRaphsonRootFind() call. */ + if (alpha_l < 1.0e-6 || alpha_r < 1.0e-6) { + double dist = distance(points.at(last),points.at(first)) / + 3.0; + + curve[0] = *points.at(first); + curve[3] = *points.at(last); + + tHat1.scale(dist); + tHat2.scale(dist); + + curve[1] = tHat1 + curve[0]; + curve[2] = tHat2 + curve[3]; + return curve; + } + + /* First and last control points of the Bezier curve are */ + /* positioned exactly at the first and last data points */ + /* Control points 1 and 2 are positioned an alpha distance out */ + /* on the tangent vectors, left and right, respectively */ + curve[0] = *points.at(first); + curve[3] = *points.at(last); + + tHat1.scale(alpha_l); + tHat2.scale(alpha_r); + + curve[1] = tHat1 + curve[0]; + curve[2] = tHat2 + curve[3]; + + return (curve); +} + +/* + * Bezier : + * Evaluate a Bezier curve at a particular parameter value + * + */ +static KoPoint BezierII(int degree,KoPoint *V, double t) +{ + int i, j; + KoPoint Q; /* Point on curve at parameter t */ + KoPoint *Vtemp; /* Local copy of control points */ + + Vtemp = new KoPoint[degree+1]; + + for (i = 0; i <= degree; i++) { + Vtemp[i] = V[i]; + } + + /* Triangle computation */ + for (i = 1; i <= degree; i++) { + for (j = 0; j <= degree-i; j++) { + Vtemp[j].setX((1.0 - t) * Vtemp[j].x() + t * Vtemp[j+1].x()); + Vtemp[j].setY((1.0 - t) * Vtemp[j].y() + t * Vtemp[j+1].y()); + } + } + + Q = Vtemp[0]; + delete[] Vtemp; + return Q; +} + +/* + * ComputeMaxError : + * Find the maximum squared distance of digitized points + * to fitted curve. +*/ +static double ComputeMaxError(TQPtrList points,int first,int last,KoPoint *curve,double *u,int *splitPoint) +{ + int i; + double maxDist; /* Maximum error */ + double dist; /* Current error */ + KoPoint P; /* Point on curve */ + FitVector v; /* Vector from point to curve */ + + *splitPoint = (last - first + 1)/2; + maxDist = 0.0; + for (i = first + 1; i < last; i++) { + P = BezierII(3, curve, u[i-first]); + v = VectorSub(P, *points.at(i)); + dist = v.length(); + if (dist >= maxDist) { + maxDist = dist; + *splitPoint = i; + } + } + return (maxDist); +} + + +/* + * NewtonRaphsonRootFind : + * Use Newton-Raphson iteration to find better root. + */ +static double NewtonRaphsonRootFind(KoPoint *Q,KoPoint P,double u) +{ + double numerator, denominator; + KoPoint Q1[3], Q2[2]; /* Q' and Q'' */ + KoPoint TQ_u, Q1_u, Q2_u; /*u evaluated at Q, Q', & Q'' */ + double uPrime; /* Improved u */ + int i; + + /* Compute Q(u) */ + TQ_u = BezierII(3,Q, u); + + /* Generate control vertices for Q' */ + for (i = 0; i <= 2; i++) { + Q1[i].setX((Q[i+1].x() - Q[i].x()) * 3.0); + Q1[i].setY((Q[i+1].y() - Q[i].y()) * 3.0); + } + + /* Generate control vertices for Q'' */ + for (i = 0; i <= 1; i++) { + Q2[i].setX((Q1[i+1].x() - Q1[i].x()) * 2.0); + Q2[i].setY((Q1[i+1].y() - Q1[i].y()) * 2.0); + } + + /* Compute Q'(u) and Q''(u) */ + Q1_u = BezierII(2, Q1, u); + Q2_u = BezierII(1, Q2, u); + + /* Compute f(u)/f'(u) */ + numerator = (TQ_u.x() - P.x()) * (Q1_u.x()) + (TQ_u.y() - P.y()) * (Q1_u.y()); + denominator = (Q1_u.x()) * (Q1_u.x()) + (Q1_u.y()) * (Q1_u.y()) + + (TQ_u.x() - P.x()) * (Q2_u.x()) + (TQ_u.y() - P.y()) * (Q2_u.y()); + + /* u = u - f(u)/f'(u) */ + uPrime = u - (numerator/denominator); + return (uPrime); +} + +/* + * Reparameterize: + * Given set of points and their parameterization, try to find + * a better parameterization. + * + */ +static double *Reparameterize(TQPtrList points,int first,int last,double *u,KoPoint *curve) +{ + int nPts = last-first+1; + int i; + double *uPrime; /* New parameter values */ + + uPrime = new double[nPts]; + for (i = first; i <= last; i++) { + uPrime[i-first] = NewtonRaphsonRootFind(curve, *points.at(i), u[i- + first]); + } + return (uPrime); +} + +KoPoint *FitCubic(TQPtrList &points,int first,int last,FitVector tHat1,FitVector tHat2,float error,int &width){ + double *u; + double *uPrime; + double maxError; + int splitPoint; + int nPts; + double iterationError; + int maxIterations=4; + FitVector tHatCenter; + KoPoint *curve; + int i; + + width=0; + + + iterationError=error*error; + nPts = last-first+1; + + if(nPts == 2){ + double dist = distance(points.at(last), points.at(first)) / 3.0; + + curve = new KoPoint[4]; + + curve[0] = *points.at(first); + curve[3] = *points.at(last); + + tHat1.scale(dist); + tHat2.scale(dist); + + curve[1] = tHat1 + curve[0]; + curve[2] = tHat2 + curve[3]; + + width=4; + return curve; + } + + /* Parameterize points, and attempt to fit curve */ + u = ChordLengthParameterize(points, first, last); + curve = GenerateBezier(points, first, last, u, tHat1, tHat2); + + + /* Find max deviation of points to fitted curve */ + maxError = ComputeMaxError(points, first, last, curve, u, &splitPoint); + if (maxError < error) { + delete[] u; + width=4; + return curve; + } + + + /* If error not too large, try some reparameterization */ + /* and iteration */ + if (maxError < iterationError) { + for (i = 0; i < maxIterations; i++) { + uPrime = Reparameterize(points, first, last, u, curve); + curve = GenerateBezier(points, first, last, uPrime, tHat1, tHat2); + maxError = ComputeMaxError(points, first, last, + curve, uPrime, &splitPoint); + if (maxError < error) { + delete[] u; + width=4; + return curve; + } + delete[] u; + u = uPrime; + } + } + + /* Fitting failed -- split at max error point and fit recursively */ + delete[] u; + delete[] curve; + tHatCenter = ComputeCenterTangent(points, splitPoint); + + int w1,w2; + KoPoint *cu1=NULL, *cu2=NULL; + cu1 = FitCubic(points, first, splitPoint, tHat1, tHatCenter, error,w1); + + tHatCenter.negate(); + cu2 = FitCubic(points, splitPoint, last, tHatCenter, tHat2, error,w2); + + KoPoint *newcurve = new KoPoint[w1+w2]; + for(int i=0;i &points,float error){ + FitVector tHat1, tHat2; + + tHat1 = ComputeLeftTangent(points,0); + tHat2 = ComputeRightTangent(points,points.count()-1); + + int width=0; + KoPoint *curve; + curve = FitCubic(points,0,points.count()-1,tHat1,tHat2,error,width); + + VPath *path = new VPath(NULL); + + if(width>3){ + path->moveTo(curve[0]); + path->curveTo(curve[1],curve[2],curve[3]); + for(int i=4;icurveTo(curve[i+1],curve[i+2],curve[i+3]); + } + } + + + delete[] curve; + return path; +} + diff --git a/karbon/tools/vdefaulttools.cc b/karbon/tools/vdefaulttools.cc deleted file mode 100644 index 3be8a8bd..00000000 --- a/karbon/tools/vdefaulttools.cc +++ /dev/null @@ -1,87 +0,0 @@ -/* 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 - -#include "karbon_factory.h" -#include "karbon_tool_factory.h" -#include "karbon_tool_registry.h" - -#include "vdefaulttools.h" - -#include "vellipsetool.h" -#include "vgradienttool.h" -#include "vpatterntool.h" -#include "vpenciltool.h" -#include "vpolygontool.h" -#include "vpolylinetool.h" -#include "vrectangletool.h" -#include "vrotatetool.h" -#include "vroundrecttool.h" -#include "vselectnodestool.h" -#include "vselecttool.h" -#include "vshapetool.h" -#include "vsheartool.h" -#include "vsinustool.h" -#include "vspiraltool.h" -#include "vstartool.h" -#include "vtexttool.h" - -typedef KGenericFactory VDefaultToolsFactory; -K_EXPORT_COMPONENT_FACTORY( karbon_defaulttools, VDefaultToolsFactory( "karbon_defaulttools" ) ) - -VDefaultTools::VDefaultTools(TQObject *parent, const char *name, const TQStringList &) - : KParts::Plugin(parent, name) -{ - setInstance(VDefaultToolsFactory::instance()); - - kdDebug() << "VDefaultTools. Class: " - << className() - << ", Parent: " - << parent -> className() - << "\n"; - - if ( parent->inherits("KarbonFactory") ) - { - KarbonToolRegistry* r = KarbonToolRegistry::instance(); - r->add(new KarbonToolFactory()); - r->add(new KarbonToolFactory()); - r->add(new KarbonToolFactory()); - r->add(new KarbonToolFactory()); - r->add(new KarbonToolFactory()); - r->add(new KarbonToolFactory()); - r->add(new KarbonToolFactory()); - r->add(new KarbonToolFactory()); - r->add(new KarbonToolFactory()); - r->add(new KarbonToolFactory()); - r->add(new KarbonToolFactory()); - r->add(new KarbonToolFactory()); - r->add(new KarbonToolFactory()); - r->add(new KarbonToolFactory()); - r->add(new KarbonToolFactory()); - r->add(new KarbonToolFactory()); - } -} - -VDefaultTools::~VDefaultTools() -{ -} - -#include "vdefaulttools.moc" diff --git a/karbon/tools/vdefaulttools.cpp b/karbon/tools/vdefaulttools.cpp new file mode 100644 index 00000000..3be8a8bd --- /dev/null +++ b/karbon/tools/vdefaulttools.cpp @@ -0,0 +1,87 @@ +/* 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 + +#include "karbon_factory.h" +#include "karbon_tool_factory.h" +#include "karbon_tool_registry.h" + +#include "vdefaulttools.h" + +#include "vellipsetool.h" +#include "vgradienttool.h" +#include "vpatterntool.h" +#include "vpenciltool.h" +#include "vpolygontool.h" +#include "vpolylinetool.h" +#include "vrectangletool.h" +#include "vrotatetool.h" +#include "vroundrecttool.h" +#include "vselectnodestool.h" +#include "vselecttool.h" +#include "vshapetool.h" +#include "vsheartool.h" +#include "vsinustool.h" +#include "vspiraltool.h" +#include "vstartool.h" +#include "vtexttool.h" + +typedef KGenericFactory VDefaultToolsFactory; +K_EXPORT_COMPONENT_FACTORY( karbon_defaulttools, VDefaultToolsFactory( "karbon_defaulttools" ) ) + +VDefaultTools::VDefaultTools(TQObject *parent, const char *name, const TQStringList &) + : KParts::Plugin(parent, name) +{ + setInstance(VDefaultToolsFactory::instance()); + + kdDebug() << "VDefaultTools. Class: " + << className() + << ", Parent: " + << parent -> className() + << "\n"; + + if ( parent->inherits("KarbonFactory") ) + { + KarbonToolRegistry* r = KarbonToolRegistry::instance(); + r->add(new KarbonToolFactory()); + r->add(new KarbonToolFactory()); + r->add(new KarbonToolFactory()); + r->add(new KarbonToolFactory()); + r->add(new KarbonToolFactory()); + r->add(new KarbonToolFactory()); + r->add(new KarbonToolFactory()); + r->add(new KarbonToolFactory()); + r->add(new KarbonToolFactory()); + r->add(new KarbonToolFactory()); + r->add(new KarbonToolFactory()); + r->add(new KarbonToolFactory()); + r->add(new KarbonToolFactory()); + r->add(new KarbonToolFactory()); + r->add(new KarbonToolFactory()); + r->add(new KarbonToolFactory()); + } +} + +VDefaultTools::~VDefaultTools() +{ +} + +#include "vdefaulttools.moc" diff --git a/karbon/tools/vellipsetool.cc b/karbon/tools/vellipsetool.cc deleted file mode 100644 index 170a51dd..00000000 --- a/karbon/tools/vellipsetool.cc +++ /dev/null @@ -1,279 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2001, 2002, 2003 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 -#include - -#include -#include "KoUnitWidgets.h" -#include -#include -#include - -#include -#include -#include -#include "vellipsetool.h" -#include "vglobal.h" - - -VEllipseOptionsWidget::VEllipseOptionsWidget( KarbonPart *part, TQWidget *parent, const char *name ) - : KDialogBase( parent, name, true, i18n( "Insert Ellipse" ), Ok | Cancel ), m_part( part ) -{ - TQGroupBox *group = new TQGroupBox( 2, Qt::Horizontal, i18n( "Properties" ), this ); - new TQLabel( i18n( "Type:" ), group ); - m_type = new KComboBox( false, group ); - m_type->insertItem( i18n( "Full" ), VEllipse::full ); - m_type->insertItem( i18n( "Section" ), VEllipse::section ); - m_type->insertItem( i18n( "Pie" ), VEllipse::cut ); - m_type->insertItem( i18n( "Arc" ), VEllipse::arc ); - connect( m_type, TQT_SIGNAL( activated( int ) ), this, TQT_SLOT( typeChanged( int ) ) ); - - // add width/height-input: - m_widthLabel = new TQLabel( i18n( "object width", "Width:" ), group ); - m_width = new KoUnitDoubleSpinBox( group, 0.0, 1000.0, 0.5, 100.0, KoUnit::U_MM ); - m_heightLabel = new TQLabel( i18n( "Height:" ), group ); - m_height = new KoUnitDoubleSpinBox( group, 0.0, 1000.0, 0.5, 100.0, KoUnit::U_MM ); - - new TQLabel( i18n( "Start angle:" ), group ); - m_startAngle = new KIntSpinBox( group ); - m_startAngle->setMinValue( 0 ); - m_startAngle->setMaxValue( 360 ); - - new TQLabel( i18n( "End angle:" ), group ); - m_endAngle = new KIntSpinBox( group ); - m_endAngle->setMinValue( 0 ); - m_endAngle->setMaxValue( 360 ); - - typeChanged( VEllipse::full ); - - refreshUnit(); - - group->setInsideMargin( 4 ); - group->setInsideSpacing( 2 ); - - setMainWidget( group ); - setFixedSize( baseSize() ); -} - -void -VEllipseOptionsWidget::typeChanged( int type ) -{ - m_startAngle->setEnabled( type != VEllipse::full ); - m_endAngle->setEnabled( type != VEllipse::full ); -} - -uint -VEllipseOptionsWidget::type() const -{ - return m_type->currentItem(); -} - -uint -VEllipseOptionsWidget::startAngle() const -{ - return m_startAngle->value(); -} - -uint -VEllipseOptionsWidget::endAngle() const -{ - return m_endAngle->value(); -} - -double -VEllipseOptionsWidget::width() const -{ - return m_width->value(); -} - -double -VEllipseOptionsWidget::height() const -{ - return m_height->value(); -} - -void -VEllipseOptionsWidget::setWidth( double value ) -{ - m_width->changeValue( value ); -} - -void -VEllipseOptionsWidget::setHeight( double value ) -{ - m_height->changeValue( value ); -} - -void -VEllipseOptionsWidget::refreshUnit () -{ - m_width->setUnit( m_part->unit() ); - m_height->setUnit( m_part->unit() ); -} - -VEllipseTool::VEllipseTool( KarbonView *view ) - : VShapeTool( view, "tool_ellipse" ) -{ - // create config dialog: - m_optionsWidget = new VEllipseOptionsWidget( view->part() ); - registerTool( this ); - - m_startAngle = m_endAngle = 0; - m_state = normal; -} - -VEllipseTool::~VEllipseTool() -{ - delete( m_optionsWidget ); -} - -void -VEllipseTool::refreshUnit() -{ - m_optionsWidget->refreshUnit(); -} - -VPath* -VEllipseTool::shape( bool interactive ) const -{ - if( interactive ) - { - double d1 = m_optionsWidget->width() / 2.0; - double d2 = m_optionsWidget->height() / 2.0; - return - new VEllipse( - 0L, - KoPoint( m_center.x() - d1, m_center.y() - d2 ), - d1 * 2.0, d2 * 2.0, - (VEllipse::VEllipseType)m_optionsWidget->type(), - m_optionsWidget->startAngle(), - m_optionsWidget->endAngle() ); - } - else - return - new VEllipse( - 0L, - KoPoint( m_center.x() - m_d1, m_center.y() - m_d2 ), - m_d1 * 2.0, - m_d2 * 2.0, - (VEllipse::VEllipseType)m_optionsWidget->type(), - m_startAngle, m_endAngle ); -} - -void -VEllipseTool::mouseMove() -{ - if( m_state == normal ) - return; - - draw(); - - //recalc(); - - if( m_state == startangle ) - { - m_startAngle = atan2( last().y() - m_center.y(), last().x() - m_center.x() ); - m_startAngle = ( m_startAngle / VGlobal::pi_2 ) * 90.0; - if( m_startAngle < 0 ) - m_startAngle += 360.0; - } - else - { - m_endAngle = atan2( last().y() - m_center.y(), last().x() - m_center.x() ); - m_endAngle = ( m_endAngle / VGlobal::pi_2 ) * 90.0; - if( m_endAngle < 0 ) - m_endAngle += 360.0; - } - - draw(); -} - -void -VEllipseTool::mouseDragRelease() -{ - if( m_optionsWidget->type() == VEllipse::full ) - VShapeTool::mouseDragRelease(); - - if( m_state == normal ) - if( m_optionsWidget->type() != VEllipse::full ) - m_state = startangle; -} - -void -VEllipseTool::mouseButtonPress() -{ - if( m_state == normal ) - { - VShapeTool::mouseButtonPress(); - m_center = first(); - } -} - -void -VEllipseTool::mouseButtonRelease() -{ - if( m_optionsWidget->type() == VEllipse::full || m_state == normal ) - VShapeTool::mouseButtonRelease(); - - if( m_state == startangle ) - m_state = endangle; - else if( m_state == endangle ) - { - VShapeTool::mouseDragRelease(); - m_startAngle = m_endAngle = 0; - m_state = normal; - } -} - -void -VEllipseTool::cancel() -{ - if( isDragging() ) - VShapeTool::cancel(); - else - draw(); - - m_startAngle = m_endAngle = 0; - m_state = normal; -} - -bool -VEllipseTool::showDialog() const -{ - return m_optionsWidget->exec() == TQDialog::Accepted; -} - -void -VEllipseTool::setup( TDEActionCollection *collection ) -{ - m_action = static_cast(collection -> action( name() ) ); - - if( m_action == 0 ) - { - m_action = new TDERadioAction( i18n( "Ellipse Tool" ), "14_ellipse", TQt::SHIFT+TQt::Key_H, this, TQT_SLOT( activate() ), collection, name() ); - m_action->setToolTip( i18n( "Ellipse" ) ); - m_action->setExclusiveGroup( "shapes" ); - //m_ownAction = true; - } -} - -#include "vellipsetool.moc" - diff --git a/karbon/tools/vellipsetool.cpp b/karbon/tools/vellipsetool.cpp new file mode 100644 index 00000000..170a51dd --- /dev/null +++ b/karbon/tools/vellipsetool.cpp @@ -0,0 +1,279 @@ +/* This file is part of the KDE project + Copyright (C) 2001, 2002, 2003 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 +#include + +#include +#include "KoUnitWidgets.h" +#include +#include +#include + +#include +#include +#include +#include "vellipsetool.h" +#include "vglobal.h" + + +VEllipseOptionsWidget::VEllipseOptionsWidget( KarbonPart *part, TQWidget *parent, const char *name ) + : KDialogBase( parent, name, true, i18n( "Insert Ellipse" ), Ok | Cancel ), m_part( part ) +{ + TQGroupBox *group = new TQGroupBox( 2, Qt::Horizontal, i18n( "Properties" ), this ); + new TQLabel( i18n( "Type:" ), group ); + m_type = new KComboBox( false, group ); + m_type->insertItem( i18n( "Full" ), VEllipse::full ); + m_type->insertItem( i18n( "Section" ), VEllipse::section ); + m_type->insertItem( i18n( "Pie" ), VEllipse::cut ); + m_type->insertItem( i18n( "Arc" ), VEllipse::arc ); + connect( m_type, TQT_SIGNAL( activated( int ) ), this, TQT_SLOT( typeChanged( int ) ) ); + + // add width/height-input: + m_widthLabel = new TQLabel( i18n( "object width", "Width:" ), group ); + m_width = new KoUnitDoubleSpinBox( group, 0.0, 1000.0, 0.5, 100.0, KoUnit::U_MM ); + m_heightLabel = new TQLabel( i18n( "Height:" ), group ); + m_height = new KoUnitDoubleSpinBox( group, 0.0, 1000.0, 0.5, 100.0, KoUnit::U_MM ); + + new TQLabel( i18n( "Start angle:" ), group ); + m_startAngle = new KIntSpinBox( group ); + m_startAngle->setMinValue( 0 ); + m_startAngle->setMaxValue( 360 ); + + new TQLabel( i18n( "End angle:" ), group ); + m_endAngle = new KIntSpinBox( group ); + m_endAngle->setMinValue( 0 ); + m_endAngle->setMaxValue( 360 ); + + typeChanged( VEllipse::full ); + + refreshUnit(); + + group->setInsideMargin( 4 ); + group->setInsideSpacing( 2 ); + + setMainWidget( group ); + setFixedSize( baseSize() ); +} + +void +VEllipseOptionsWidget::typeChanged( int type ) +{ + m_startAngle->setEnabled( type != VEllipse::full ); + m_endAngle->setEnabled( type != VEllipse::full ); +} + +uint +VEllipseOptionsWidget::type() const +{ + return m_type->currentItem(); +} + +uint +VEllipseOptionsWidget::startAngle() const +{ + return m_startAngle->value(); +} + +uint +VEllipseOptionsWidget::endAngle() const +{ + return m_endAngle->value(); +} + +double +VEllipseOptionsWidget::width() const +{ + return m_width->value(); +} + +double +VEllipseOptionsWidget::height() const +{ + return m_height->value(); +} + +void +VEllipseOptionsWidget::setWidth( double value ) +{ + m_width->changeValue( value ); +} + +void +VEllipseOptionsWidget::setHeight( double value ) +{ + m_height->changeValue( value ); +} + +void +VEllipseOptionsWidget::refreshUnit () +{ + m_width->setUnit( m_part->unit() ); + m_height->setUnit( m_part->unit() ); +} + +VEllipseTool::VEllipseTool( KarbonView *view ) + : VShapeTool( view, "tool_ellipse" ) +{ + // create config dialog: + m_optionsWidget = new VEllipseOptionsWidget( view->part() ); + registerTool( this ); + + m_startAngle = m_endAngle = 0; + m_state = normal; +} + +VEllipseTool::~VEllipseTool() +{ + delete( m_optionsWidget ); +} + +void +VEllipseTool::refreshUnit() +{ + m_optionsWidget->refreshUnit(); +} + +VPath* +VEllipseTool::shape( bool interactive ) const +{ + if( interactive ) + { + double d1 = m_optionsWidget->width() / 2.0; + double d2 = m_optionsWidget->height() / 2.0; + return + new VEllipse( + 0L, + KoPoint( m_center.x() - d1, m_center.y() - d2 ), + d1 * 2.0, d2 * 2.0, + (VEllipse::VEllipseType)m_optionsWidget->type(), + m_optionsWidget->startAngle(), + m_optionsWidget->endAngle() ); + } + else + return + new VEllipse( + 0L, + KoPoint( m_center.x() - m_d1, m_center.y() - m_d2 ), + m_d1 * 2.0, + m_d2 * 2.0, + (VEllipse::VEllipseType)m_optionsWidget->type(), + m_startAngle, m_endAngle ); +} + +void +VEllipseTool::mouseMove() +{ + if( m_state == normal ) + return; + + draw(); + + //recalc(); + + if( m_state == startangle ) + { + m_startAngle = atan2( last().y() - m_center.y(), last().x() - m_center.x() ); + m_startAngle = ( m_startAngle / VGlobal::pi_2 ) * 90.0; + if( m_startAngle < 0 ) + m_startAngle += 360.0; + } + else + { + m_endAngle = atan2( last().y() - m_center.y(), last().x() - m_center.x() ); + m_endAngle = ( m_endAngle / VGlobal::pi_2 ) * 90.0; + if( m_endAngle < 0 ) + m_endAngle += 360.0; + } + + draw(); +} + +void +VEllipseTool::mouseDragRelease() +{ + if( m_optionsWidget->type() == VEllipse::full ) + VShapeTool::mouseDragRelease(); + + if( m_state == normal ) + if( m_optionsWidget->type() != VEllipse::full ) + m_state = startangle; +} + +void +VEllipseTool::mouseButtonPress() +{ + if( m_state == normal ) + { + VShapeTool::mouseButtonPress(); + m_center = first(); + } +} + +void +VEllipseTool::mouseButtonRelease() +{ + if( m_optionsWidget->type() == VEllipse::full || m_state == normal ) + VShapeTool::mouseButtonRelease(); + + if( m_state == startangle ) + m_state = endangle; + else if( m_state == endangle ) + { + VShapeTool::mouseDragRelease(); + m_startAngle = m_endAngle = 0; + m_state = normal; + } +} + +void +VEllipseTool::cancel() +{ + if( isDragging() ) + VShapeTool::cancel(); + else + draw(); + + m_startAngle = m_endAngle = 0; + m_state = normal; +} + +bool +VEllipseTool::showDialog() const +{ + return m_optionsWidget->exec() == TQDialog::Accepted; +} + +void +VEllipseTool::setup( TDEActionCollection *collection ) +{ + m_action = static_cast(collection -> action( name() ) ); + + if( m_action == 0 ) + { + m_action = new TDERadioAction( i18n( "Ellipse Tool" ), "14_ellipse", TQt::SHIFT+TQt::Key_H, this, TQT_SLOT( activate() ), collection, name() ); + m_action->setToolTip( i18n( "Ellipse" ) ); + m_action->setExclusiveGroup( "shapes" ); + //m_ownAction = true; + } +} + +#include "vellipsetool.moc" + diff --git a/karbon/tools/vgradienttool.cc b/karbon/tools/vgradienttool.cc deleted file mode 100644 index e7d2db3c..00000000 --- a/karbon/tools/vgradienttool.cc +++ /dev/null @@ -1,526 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2001, 2002, 2003 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 -#include - -#include - -#include -#include -#include -#include -#include -#include "vgradienttool.h" -#include -#include -#include -#include -#include -#include - -#include - -VGradientTool::VGradientOptionsWidget::VGradientOptionsWidget( VGradient& gradient ) - : KDialogBase( 0L, "", true, i18n( "Edit Gradient" ), Ok | Cancel ) -{ - m_gradientWidget = new VGradientTabWidget( gradient, KarbonFactory::rServer(), this ); - setMainWidget( m_gradientWidget ); - setFixedSize( baseSize() ); -} - -VGradientTool::VGradientTool( KarbonView *view ) - : VTool( view, "gradienttool" ), m_state( normal ), m_handleSize( 3 ), m_active( false ) -{ - setName( "tool_gradient" ); - m_optionsWidget = new VGradientOptionsWidget( m_gradient ); - registerTool( this ); -} - -VGradientTool::~VGradientTool() -{ - delete m_optionsWidget; -} - -void -VGradientTool::activate() -{ - m_active = true; - m_state = normal; - view()->statusMessage()->setText( i18n( "Gradient" ) ); - view()->setCursor( TQCursor( TQt::crossCursor ) ); - VTool::activate(); - - if( view() ) - { - // disable selection handles - view()->part()->document().selection()->showHandle( false ); - // connect to the stroke-fill-preview to get notice when the stroke or fill gets selected - VStrokeFillPreview* preview = view()->strokeFillPreview(); - if( preview ) - { - connect( preview, TQT_SIGNAL( fillSelected() ), this, TQT_SLOT( targetChanged() ) ); - connect( preview, TQT_SIGNAL( strokeSelected() ), this, TQT_SLOT( targetChanged() ) ); - } - view()->repaintAll( view()->part()->document().selection()->boundingBox() ); - } -} - -void -VGradientTool::deactivate() -{ - m_active = false; - - if( view() ) - { - // enable selection handles - view()->part()->document().selection()->showHandle( true ); - VStrokeFillPreview* preview = view()->strokeFillPreview(); - if( preview ) - { - disconnect( preview, TQT_SIGNAL( fillSelected() ), this, TQT_SLOT( targetChanged() ) ); - disconnect( preview, TQT_SIGNAL( strokeSelected() ), this, TQT_SLOT( targetChanged() ) ); - } - view()->repaintAll( view()->part()->document().selection()->boundingBox() ); - } -} - -TQString -VGradientTool::statusText() -{ - return i18n( "Gradient Tool" ); -} - -TQString -VGradientTool::contextHelp() -{ - TQString s = i18n( "Gradient tool:
" ); - s += i18n( "Click and drag to choose the gradient vector.
" ); - s += i18n( "Click and drag a gradient vector handle to change the gradient vector.
" ); - s += i18n( "Shift click and drag to move the radial gradient focal point.
" ); - s += i18n( "Press i or Shift+i to decrease or increase the handle size.
" ); - s += i18n( "
Gradient editing:
" ); - s += i18n( "Click and drag to move points.
" ); - s += i18n( "Double click on a color point to edit it.
" ); - s += i18n( "Right click on a color point to remove it.
" ); - return s; -} - -bool -VGradientTool::getGradient( VGradient &gradient ) -{ - if( ! view() ) - return false; - - // determine if stroke of fill is selected for editing - VStrokeFillPreview *preview = view()->strokeFillPreview(); - bool strokeSelected = ( preview && preview->strokeIsSelected() ); - - VSelection* selection = view()->part()->document().selection(); - if( selection->objects().count() != 1 ) - return false; - - VObject *obj = selection->objects().getFirst(); - // get the gradient of the first selected object, if any - if( strokeSelected && obj->stroke()->type() == VStroke::grad ) - gradient = obj->stroke()->gradient(); - else if( ! strokeSelected && obj->fill()->type() == VFill::grad ) - gradient = obj->fill()->gradient(); - else - return false; - - return true; -} - -bool -VGradientTool::getOpacity( double &opacity ) -{ - if( ! view() ) - return false; - - // determine if stroke of fill is selected for editing - VStrokeFillPreview *preview = view()->strokeFillPreview(); - bool strokeSelected = ( preview && preview->strokeIsSelected() ); - - VSelection* selection = view()->part()->document().selection(); - if( selection->objects().count() != 1 ) - return false; - - VObject *obj = selection->objects().getFirst(); - // get the opacity of the first selected object, if any - if( strokeSelected && obj->stroke()->type() == VStroke::grad ) - opacity = obj->stroke()->color().opacity(); - else if( ! strokeSelected && obj->fill()->type() == VFill::grad ) - opacity = obj->fill()->color().opacity(); - else return false; - - return true; -} - -void -VGradientTool::draw( VPainter* painter ) -{ - if( ! m_active ) - return; - - if( m_state != normal ) - return; - - if( ! getGradient( m_gradient ) ) - return; - - KoPoint s = m_gradient.origin(); - KoPoint e = m_gradient.vector(); - KoPoint f = m_gradient.focalPoint(); - - // save the handle rects for later inside testing - m_origin = KoRect( s.x()-m_handleSize, s.y()-m_handleSize, 2*m_handleSize, 2*m_handleSize ); - m_vector = KoRect( e.x()-m_handleSize, e.y()-m_handleSize, 2*m_handleSize, 2*m_handleSize ); - m_center = KoRect( f.x()-m_handleSize, f.y()-m_handleSize, 2*m_handleSize, 2*m_handleSize ); - - painter->setPen( TQt::blue.light() ); - painter->setBrush( TQt::blue.light() ); - painter->setRasterOp( TQt::XorROP ); - - // draw the gradient vector - painter->newPath(); - painter->moveTo( s ); - painter->lineTo( e ); - painter->strokePath(); - - if( m_gradient.type() == VGradient::radial ) - { - // draw the focal point cross - double size = (double)m_handleSize / view()->zoom(); - KoPoint focal = m_center.center(); - KoRect cross = KoRect( focal.x()-3*size, focal.y()-3*size, 6*size, 6*size ); - painter->newPath(); - painter->moveTo( cross.topLeft() ); - painter->lineTo( cross.bottomRight() ); - painter->strokePath(); - painter->newPath(); - painter->moveTo( cross.bottomLeft() ); - painter->lineTo( cross.topRight() ); - painter->strokePath(); - } - // draw the handle rects - painter->drawNode( m_origin.center(), m_handleSize ); - painter->drawNode( m_vector.center(), m_handleSize ); -} - -void -VGradientTool::draw() -{ - if( ! view() || view()->part()->document().selection()->objects().count() == 0 ) - return; - - VPainter *painter = view()->painterFactory()->editpainter(); - painter->setRasterOp( TQt::NotROP ); - - painter->setPen( TQt::DotLine ); - painter->newPath(); - - // differentiate between moving a handle and creating a complete new vector - if( m_state == moveOrigin || m_state == moveVector ) - { - painter->moveTo( m_fixed ); - painter->lineTo( m_current ); - // draw the handle rects - painter->drawNode( m_fixed, m_handleSize ); - painter->drawNode( m_current, m_handleSize ); - } - else if( m_state == createNew ) - { - painter->moveTo( first() ); - painter->lineTo( m_current ); - // draw the handle rects - painter->drawNode( first(), m_handleSize ); - painter->drawNode( m_current, m_handleSize ); - } - else if( m_state == moveCenter ) - { - // draw the focal point cross - double size = (double)m_handleSize / view()->zoom(); - KoRect cross = KoRect( m_current.x()-3*size, m_current.y()-3*size, 6*size, 6*size ); - painter->moveTo( cross.topLeft() ); - painter->lineTo( cross.bottomRight() ); - painter->strokePath(); - painter->newPath(); - painter->moveTo( cross.bottomLeft() ); - painter->lineTo( cross.topRight() ); - } - - painter->strokePath(); -} - -void -VGradientTool::mouseDrag() -{ - if( m_state == normal ) - return; - - // undo old line - draw(); - - m_current = last(); - - draw(); -} - -void -VGradientTool::mouseButtonPress() -{ - m_current = first(); - - // set the apropriate editing state - if( m_center.contains( m_current ) && shiftPressed()) - { - m_state = moveCenter; - } - else if( m_origin.contains( m_current ) ) - { - m_state = moveOrigin; - m_fixed = m_vector.center(); - } - else if( m_vector.contains( m_current ) ) - { - m_state = moveVector; - m_fixed = m_origin.center(); - } - else - m_state = createNew; -} - -void -VGradientTool::mouseButtonRelease() -{ - m_state = normal; - - if( ! view() || view()->part()->document().selection()->objects().count() == 0 ) - return; - - // save old gradient position - VGradient oldGradient = m_gradient; - - bool strokeSelected = false; - - // determine the target from the stroke-fill-preview-widget - VStrokeFillPreview* preview = view()->strokeFillPreview(); - if( preview && preview->strokeIsSelected() ) - strokeSelected = true; - - if( first() == last() ) - { - m_optionsWidget->gradientWidget()->setGradient( m_gradient ); - if( strokeSelected ) - { - m_optionsWidget->gradientWidget()->setTarget( VGradientTabWidget::STROKE ); - m_optionsWidget->gradientWidget()->setOpacity( 1.0 ); - } - else - { - m_optionsWidget->gradientWidget()->setTarget( VGradientTabWidget::FILL ); - double opacity; - if( getOpacity( opacity ) ) - m_optionsWidget->gradientWidget()->setOpacity( opacity ); - } - - if( ! showDialog() ) - return; - - m_gradient = m_optionsWidget->gradientWidget()->gradient(); - - // if the gradient dialog was shown and accepted, determine the target from the dialog - strokeSelected = ( m_optionsWidget->gradientWidget()->target() == VGradientTabWidget::STROKE ); - } - - // calculate a sane intial position for the new gradient - if( view()->part()->document().selection()->objects().count() == 1 ) - { - VObject *obj = view()->part()->document().selection()->objects().getFirst(); - - if( ( ! strokeSelected && obj->fill()->type() != VFill::grad ) - || ( strokeSelected && obj->stroke()->type() != VStroke::grad ) ) - { - KoRect bbox = obj->boundingBox(); - switch( m_gradient.type() ) - { - case VGradient::linear: - oldGradient.setOrigin( bbox.bottomLeft() + 0.5*(bbox.bottomRight()-bbox.bottomLeft()) ); - oldGradient.setVector( bbox.topLeft() + 0.5*(bbox.topRight()-bbox.topLeft()) ); - oldGradient.setFocalPoint( bbox.center() ); - break; - case VGradient::radial: - oldGradient.setOrigin( bbox.center() ); - oldGradient.setVector( bbox.topLeft() + 0.5*(bbox.topRight()-bbox.topLeft()) ); - oldGradient.setFocalPoint( bbox.center() ); - break; - case VGradient::conic: - oldGradient.setOrigin( bbox.center() ); - oldGradient.setVector( bbox.topLeft() + 0.5*(bbox.topRight()-bbox.topLeft()) ); - oldGradient.setFocalPoint( bbox.center() ); - break; - } - } - } - - // workaround for a libart 2.3.10 bug - if( oldGradient.origin() == oldGradient.vector() ) - oldGradient.vector().rx()+=1; - - // use the old gradient position - m_gradient.setVector( oldGradient.vector() ); - m_gradient.setOrigin( oldGradient.origin() ); - m_gradient.setFocalPoint( oldGradient.focalPoint() ); - - if( ! strokeSelected ) - { - VFill fill; - fill.gradient() = m_gradient; - fill.setType( VFill::grad ); - VColor c = fill.color(); - c.setOpacity( m_optionsWidget->gradientWidget()->opacity() ); - fill.setColor( c, false ); - view()->part()->addCommand( - new VFillCmd( &view()->part()->document(), fill, "14_gradient" ), true ); - } - else - { - view()->part()->addCommand( - new VStrokeCmd( &view()->part()->document(), &m_gradient ), true ); - } -} - -void -VGradientTool::mouseDragRelease() -{ - if( ! view() || m_state == normal ) - return; - - if( view()->part()->document().selection()->objects().count() == 0 ) - { - draw(); - return; - } - - if( m_state == moveOrigin ) - m_gradient.setOrigin( last() ); - else if( m_state == moveVector ) - m_gradient.setVector( last() ); - else if( m_state == moveCenter ) - m_gradient.setFocalPoint( last() ); - else if( m_state == createNew ) - { - m_gradient.setOrigin( first() ); - m_gradient.setFocalPoint( first() ); - m_gradient.setVector( last() ); - } - - m_state = normal; - - VStrokeFillPreview* preview = view()->strokeFillPreview(); - if( ! preview ) - return; - - if( ! preview->strokeIsSelected() ) - { - VFill fill; - fill.gradient() = m_gradient; - fill.setType( VFill::grad ); - VColor c = fill.color(); - c.setOpacity( m_optionsWidget->gradientWidget()->opacity() ); - fill.setColor( c, false ); - view()->part()->addCommand( - new VFillCmd( &view()->part()->document(), fill, "14_gradient" ), true ); - } - else - view()->part()->addCommand( - new VStrokeCmd( &view()->part()->document(), &m_gradient ), true ); -} - -void -VGradientTool::cancel() -{ - // Erase old object: - if( isDragging() ) - draw(); - m_state = normal; -} - -bool -VGradientTool::showDialog() const -{ - return m_optionsWidget->exec() == TQDialog::Accepted; -} - -void -VGradientTool::setup( TDEActionCollection *collection ) -{ - m_action = static_cast(collection -> action( name() ) ); - - if( m_action == 0 ) - { - m_action = new TDERadioAction( i18n( "Gradient Tool" ), "14_gradient", TQt::Key_G, this, TQT_SLOT( activate() ), collection, name() ); - m_action->setToolTip( i18n( "Gradient" ) ); - m_action->setExclusiveGroup( "misc" ); - //m_ownAction = true; - } -} - -void -VGradientTool::setCursor() const -{ - if( !view() ) return; - - // set a different cursor if mouse is inside the handle rects - if( m_origin.contains( last() ) || m_vector.contains( last() ) || m_center.contains( last() ) ) - view()->setCursor( TQCursor( TQt::SizeAllCursor ) ); - else - view()->setCursor( TQCursor( TQt::arrowCursor ) ); -} - -bool -VGradientTool::keyReleased( TQt::Key key ) -{ - // increase/decrease the handle size - switch( key ) - { - case TQt::Key_I: - if( shiftPressed() ) - m_handleSize++; - else if( m_handleSize > 3 ) - m_handleSize--; - break; - default: return false; - } - - if( view() ) - view()->repaintAll( view()->part()->document().selection()->boundingBox() ); - - return true; -} - -void -VGradientTool::targetChanged() -{ - if( view() ) - view()->repaintAll( view()->part()->document().selection()->boundingBox() ); -} - -#include "vgradienttool.moc" diff --git a/karbon/tools/vgradienttool.cpp b/karbon/tools/vgradienttool.cpp new file mode 100644 index 00000000..e7d2db3c --- /dev/null +++ b/karbon/tools/vgradienttool.cpp @@ -0,0 +1,526 @@ +/* This file is part of the KDE project + Copyright (C) 2001, 2002, 2003 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 +#include + +#include + +#include +#include +#include +#include +#include +#include "vgradienttool.h" +#include +#include +#include +#include +#include +#include + +#include + +VGradientTool::VGradientOptionsWidget::VGradientOptionsWidget( VGradient& gradient ) + : KDialogBase( 0L, "", true, i18n( "Edit Gradient" ), Ok | Cancel ) +{ + m_gradientWidget = new VGradientTabWidget( gradient, KarbonFactory::rServer(), this ); + setMainWidget( m_gradientWidget ); + setFixedSize( baseSize() ); +} + +VGradientTool::VGradientTool( KarbonView *view ) + : VTool( view, "gradienttool" ), m_state( normal ), m_handleSize( 3 ), m_active( false ) +{ + setName( "tool_gradient" ); + m_optionsWidget = new VGradientOptionsWidget( m_gradient ); + registerTool( this ); +} + +VGradientTool::~VGradientTool() +{ + delete m_optionsWidget; +} + +void +VGradientTool::activate() +{ + m_active = true; + m_state = normal; + view()->statusMessage()->setText( i18n( "Gradient" ) ); + view()->setCursor( TQCursor( TQt::crossCursor ) ); + VTool::activate(); + + if( view() ) + { + // disable selection handles + view()->part()->document().selection()->showHandle( false ); + // connect to the stroke-fill-preview to get notice when the stroke or fill gets selected + VStrokeFillPreview* preview = view()->strokeFillPreview(); + if( preview ) + { + connect( preview, TQT_SIGNAL( fillSelected() ), this, TQT_SLOT( targetChanged() ) ); + connect( preview, TQT_SIGNAL( strokeSelected() ), this, TQT_SLOT( targetChanged() ) ); + } + view()->repaintAll( view()->part()->document().selection()->boundingBox() ); + } +} + +void +VGradientTool::deactivate() +{ + m_active = false; + + if( view() ) + { + // enable selection handles + view()->part()->document().selection()->showHandle( true ); + VStrokeFillPreview* preview = view()->strokeFillPreview(); + if( preview ) + { + disconnect( preview, TQT_SIGNAL( fillSelected() ), this, TQT_SLOT( targetChanged() ) ); + disconnect( preview, TQT_SIGNAL( strokeSelected() ), this, TQT_SLOT( targetChanged() ) ); + } + view()->repaintAll( view()->part()->document().selection()->boundingBox() ); + } +} + +TQString +VGradientTool::statusText() +{ + return i18n( "Gradient Tool" ); +} + +TQString +VGradientTool::contextHelp() +{ + TQString s = i18n( "Gradient tool:
" ); + s += i18n( "Click and drag to choose the gradient vector.
" ); + s += i18n( "Click and drag a gradient vector handle to change the gradient vector.
" ); + s += i18n( "Shift click and drag to move the radial gradient focal point.
" ); + s += i18n( "Press i or Shift+i to decrease or increase the handle size.
" ); + s += i18n( "
Gradient editing:
" ); + s += i18n( "Click and drag to move points.
" ); + s += i18n( "Double click on a color point to edit it.
" ); + s += i18n( "Right click on a color point to remove it.
" ); + return s; +} + +bool +VGradientTool::getGradient( VGradient &gradient ) +{ + if( ! view() ) + return false; + + // determine if stroke of fill is selected for editing + VStrokeFillPreview *preview = view()->strokeFillPreview(); + bool strokeSelected = ( preview && preview->strokeIsSelected() ); + + VSelection* selection = view()->part()->document().selection(); + if( selection->objects().count() != 1 ) + return false; + + VObject *obj = selection->objects().getFirst(); + // get the gradient of the first selected object, if any + if( strokeSelected && obj->stroke()->type() == VStroke::grad ) + gradient = obj->stroke()->gradient(); + else if( ! strokeSelected && obj->fill()->type() == VFill::grad ) + gradient = obj->fill()->gradient(); + else + return false; + + return true; +} + +bool +VGradientTool::getOpacity( double &opacity ) +{ + if( ! view() ) + return false; + + // determine if stroke of fill is selected for editing + VStrokeFillPreview *preview = view()->strokeFillPreview(); + bool strokeSelected = ( preview && preview->strokeIsSelected() ); + + VSelection* selection = view()->part()->document().selection(); + if( selection->objects().count() != 1 ) + return false; + + VObject *obj = selection->objects().getFirst(); + // get the opacity of the first selected object, if any + if( strokeSelected && obj->stroke()->type() == VStroke::grad ) + opacity = obj->stroke()->color().opacity(); + else if( ! strokeSelected && obj->fill()->type() == VFill::grad ) + opacity = obj->fill()->color().opacity(); + else return false; + + return true; +} + +void +VGradientTool::draw( VPainter* painter ) +{ + if( ! m_active ) + return; + + if( m_state != normal ) + return; + + if( ! getGradient( m_gradient ) ) + return; + + KoPoint s = m_gradient.origin(); + KoPoint e = m_gradient.vector(); + KoPoint f = m_gradient.focalPoint(); + + // save the handle rects for later inside testing + m_origin = KoRect( s.x()-m_handleSize, s.y()-m_handleSize, 2*m_handleSize, 2*m_handleSize ); + m_vector = KoRect( e.x()-m_handleSize, e.y()-m_handleSize, 2*m_handleSize, 2*m_handleSize ); + m_center = KoRect( f.x()-m_handleSize, f.y()-m_handleSize, 2*m_handleSize, 2*m_handleSize ); + + painter->setPen( TQt::blue.light() ); + painter->setBrush( TQt::blue.light() ); + painter->setRasterOp( TQt::XorROP ); + + // draw the gradient vector + painter->newPath(); + painter->moveTo( s ); + painter->lineTo( e ); + painter->strokePath(); + + if( m_gradient.type() == VGradient::radial ) + { + // draw the focal point cross + double size = (double)m_handleSize / view()->zoom(); + KoPoint focal = m_center.center(); + KoRect cross = KoRect( focal.x()-3*size, focal.y()-3*size, 6*size, 6*size ); + painter->newPath(); + painter->moveTo( cross.topLeft() ); + painter->lineTo( cross.bottomRight() ); + painter->strokePath(); + painter->newPath(); + painter->moveTo( cross.bottomLeft() ); + painter->lineTo( cross.topRight() ); + painter->strokePath(); + } + // draw the handle rects + painter->drawNode( m_origin.center(), m_handleSize ); + painter->drawNode( m_vector.center(), m_handleSize ); +} + +void +VGradientTool::draw() +{ + if( ! view() || view()->part()->document().selection()->objects().count() == 0 ) + return; + + VPainter *painter = view()->painterFactory()->editpainter(); + painter->setRasterOp( TQt::NotROP ); + + painter->setPen( TQt::DotLine ); + painter->newPath(); + + // differentiate between moving a handle and creating a complete new vector + if( m_state == moveOrigin || m_state == moveVector ) + { + painter->moveTo( m_fixed ); + painter->lineTo( m_current ); + // draw the handle rects + painter->drawNode( m_fixed, m_handleSize ); + painter->drawNode( m_current, m_handleSize ); + } + else if( m_state == createNew ) + { + painter->moveTo( first() ); + painter->lineTo( m_current ); + // draw the handle rects + painter->drawNode( first(), m_handleSize ); + painter->drawNode( m_current, m_handleSize ); + } + else if( m_state == moveCenter ) + { + // draw the focal point cross + double size = (double)m_handleSize / view()->zoom(); + KoRect cross = KoRect( m_current.x()-3*size, m_current.y()-3*size, 6*size, 6*size ); + painter->moveTo( cross.topLeft() ); + painter->lineTo( cross.bottomRight() ); + painter->strokePath(); + painter->newPath(); + painter->moveTo( cross.bottomLeft() ); + painter->lineTo( cross.topRight() ); + } + + painter->strokePath(); +} + +void +VGradientTool::mouseDrag() +{ + if( m_state == normal ) + return; + + // undo old line + draw(); + + m_current = last(); + + draw(); +} + +void +VGradientTool::mouseButtonPress() +{ + m_current = first(); + + // set the apropriate editing state + if( m_center.contains( m_current ) && shiftPressed()) + { + m_state = moveCenter; + } + else if( m_origin.contains( m_current ) ) + { + m_state = moveOrigin; + m_fixed = m_vector.center(); + } + else if( m_vector.contains( m_current ) ) + { + m_state = moveVector; + m_fixed = m_origin.center(); + } + else + m_state = createNew; +} + +void +VGradientTool::mouseButtonRelease() +{ + m_state = normal; + + if( ! view() || view()->part()->document().selection()->objects().count() == 0 ) + return; + + // save old gradient position + VGradient oldGradient = m_gradient; + + bool strokeSelected = false; + + // determine the target from the stroke-fill-preview-widget + VStrokeFillPreview* preview = view()->strokeFillPreview(); + if( preview && preview->strokeIsSelected() ) + strokeSelected = true; + + if( first() == last() ) + { + m_optionsWidget->gradientWidget()->setGradient( m_gradient ); + if( strokeSelected ) + { + m_optionsWidget->gradientWidget()->setTarget( VGradientTabWidget::STROKE ); + m_optionsWidget->gradientWidget()->setOpacity( 1.0 ); + } + else + { + m_optionsWidget->gradientWidget()->setTarget( VGradientTabWidget::FILL ); + double opacity; + if( getOpacity( opacity ) ) + m_optionsWidget->gradientWidget()->setOpacity( opacity ); + } + + if( ! showDialog() ) + return; + + m_gradient = m_optionsWidget->gradientWidget()->gradient(); + + // if the gradient dialog was shown and accepted, determine the target from the dialog + strokeSelected = ( m_optionsWidget->gradientWidget()->target() == VGradientTabWidget::STROKE ); + } + + // calculate a sane intial position for the new gradient + if( view()->part()->document().selection()->objects().count() == 1 ) + { + VObject *obj = view()->part()->document().selection()->objects().getFirst(); + + if( ( ! strokeSelected && obj->fill()->type() != VFill::grad ) + || ( strokeSelected && obj->stroke()->type() != VStroke::grad ) ) + { + KoRect bbox = obj->boundingBox(); + switch( m_gradient.type() ) + { + case VGradient::linear: + oldGradient.setOrigin( bbox.bottomLeft() + 0.5*(bbox.bottomRight()-bbox.bottomLeft()) ); + oldGradient.setVector( bbox.topLeft() + 0.5*(bbox.topRight()-bbox.topLeft()) ); + oldGradient.setFocalPoint( bbox.center() ); + break; + case VGradient::radial: + oldGradient.setOrigin( bbox.center() ); + oldGradient.setVector( bbox.topLeft() + 0.5*(bbox.topRight()-bbox.topLeft()) ); + oldGradient.setFocalPoint( bbox.center() ); + break; + case VGradient::conic: + oldGradient.setOrigin( bbox.center() ); + oldGradient.setVector( bbox.topLeft() + 0.5*(bbox.topRight()-bbox.topLeft()) ); + oldGradient.setFocalPoint( bbox.center() ); + break; + } + } + } + + // workaround for a libart 2.3.10 bug + if( oldGradient.origin() == oldGradient.vector() ) + oldGradient.vector().rx()+=1; + + // use the old gradient position + m_gradient.setVector( oldGradient.vector() ); + m_gradient.setOrigin( oldGradient.origin() ); + m_gradient.setFocalPoint( oldGradient.focalPoint() ); + + if( ! strokeSelected ) + { + VFill fill; + fill.gradient() = m_gradient; + fill.setType( VFill::grad ); + VColor c = fill.color(); + c.setOpacity( m_optionsWidget->gradientWidget()->opacity() ); + fill.setColor( c, false ); + view()->part()->addCommand( + new VFillCmd( &view()->part()->document(), fill, "14_gradient" ), true ); + } + else + { + view()->part()->addCommand( + new VStrokeCmd( &view()->part()->document(), &m_gradient ), true ); + } +} + +void +VGradientTool::mouseDragRelease() +{ + if( ! view() || m_state == normal ) + return; + + if( view()->part()->document().selection()->objects().count() == 0 ) + { + draw(); + return; + } + + if( m_state == moveOrigin ) + m_gradient.setOrigin( last() ); + else if( m_state == moveVector ) + m_gradient.setVector( last() ); + else if( m_state == moveCenter ) + m_gradient.setFocalPoint( last() ); + else if( m_state == createNew ) + { + m_gradient.setOrigin( first() ); + m_gradient.setFocalPoint( first() ); + m_gradient.setVector( last() ); + } + + m_state = normal; + + VStrokeFillPreview* preview = view()->strokeFillPreview(); + if( ! preview ) + return; + + if( ! preview->strokeIsSelected() ) + { + VFill fill; + fill.gradient() = m_gradient; + fill.setType( VFill::grad ); + VColor c = fill.color(); + c.setOpacity( m_optionsWidget->gradientWidget()->opacity() ); + fill.setColor( c, false ); + view()->part()->addCommand( + new VFillCmd( &view()->part()->document(), fill, "14_gradient" ), true ); + } + else + view()->part()->addCommand( + new VStrokeCmd( &view()->part()->document(), &m_gradient ), true ); +} + +void +VGradientTool::cancel() +{ + // Erase old object: + if( isDragging() ) + draw(); + m_state = normal; +} + +bool +VGradientTool::showDialog() const +{ + return m_optionsWidget->exec() == TQDialog::Accepted; +} + +void +VGradientTool::setup( TDEActionCollection *collection ) +{ + m_action = static_cast(collection -> action( name() ) ); + + if( m_action == 0 ) + { + m_action = new TDERadioAction( i18n( "Gradient Tool" ), "14_gradient", TQt::Key_G, this, TQT_SLOT( activate() ), collection, name() ); + m_action->setToolTip( i18n( "Gradient" ) ); + m_action->setExclusiveGroup( "misc" ); + //m_ownAction = true; + } +} + +void +VGradientTool::setCursor() const +{ + if( !view() ) return; + + // set a different cursor if mouse is inside the handle rects + if( m_origin.contains( last() ) || m_vector.contains( last() ) || m_center.contains( last() ) ) + view()->setCursor( TQCursor( TQt::SizeAllCursor ) ); + else + view()->setCursor( TQCursor( TQt::arrowCursor ) ); +} + +bool +VGradientTool::keyReleased( TQt::Key key ) +{ + // increase/decrease the handle size + switch( key ) + { + case TQt::Key_I: + if( shiftPressed() ) + m_handleSize++; + else if( m_handleSize > 3 ) + m_handleSize--; + break; + default: return false; + } + + if( view() ) + view()->repaintAll( view()->part()->document().selection()->boundingBox() ); + + return true; +} + +void +VGradientTool::targetChanged() +{ + if( view() ) + view()->repaintAll( view()->part()->document().selection()->boundingBox() ); +} + +#include "vgradienttool.moc" diff --git a/karbon/tools/vpatterntool.cc b/karbon/tools/vpatterntool.cc deleted file mode 100644 index 8c42d5e0..00000000 --- a/karbon/tools/vpatterntool.cc +++ /dev/null @@ -1,509 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2001, 2002, 2003 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 "vpatterntool.h" - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -VPatternWidget::VPatternWidget( TQPtrList* patterns, VTool*, TQWidget* parent ) - : KDialogBase( parent, "", true, i18n( "Choose Pattern" ), Ok | Cancel ), m_pattern( 0 ) -{ - TQWidget *base = new TQWidget( this ); - TQVBoxLayout* layout = new TQVBoxLayout( base ); - layout->addWidget( m_patternChooser = new KoIconChooser( TQSize( 32, 32 ), base ) ); - layout->addWidget( m_buttonGroup = new TQHButtonGroup( base ) ); - m_buttonGroup->insert( m_importPatternButton = new TQToolButton( m_buttonGroup ) ); - m_buttonGroup->insert( m_deletePatternButton = new TQToolButton( m_buttonGroup ) ); - m_patternChooser->setFixedSize( 180, 120 ); - m_importPatternButton->setIconSet( SmallIconSet( "14_layer_newlayer" ) ); - m_importPatternButton->setTextLabel( i18n( "Import" ) ); - m_deletePatternButton->setIconSet( SmallIconSet("14_layer_deletelayer" ) ); - m_deletePatternButton->setTextLabel( i18n( "Delete" ) ); - - m_buttonGroup->setInsideMargin( 3 ); - m_importPatternButton->setEnabled( true ); - m_deletePatternButton->setEnabled( false ); - - //setFrameStyle( Box | Sunken ); - layout->setMargin( 3 ); - - connect( m_buttonGroup, TQT_SIGNAL( clicked( int ) ), this, TQT_SLOT( slotButtonClicked( int ) ) ); - connect( m_patternChooser, TQT_SIGNAL( selected( KoIconItem* ) ), this, TQT_SLOT( patternSelected( KoIconItem* ) ) ); - - KoIconItem* item; - for( item = patterns->first(); item; item = patterns->next() ) - m_patternChooser->addItem( item ); - m_pattern = (VPattern*)patterns->first(); - - setMainWidget( base ); -} // VPatternWidget::VPatternWidget - -VPatternWidget::~VPatternWidget() -{ -} // VPatternWidget::~VPatternWidget - -VPattern* VPatternWidget::selectedPattern() -{ - return m_pattern; -} // VPatternWidget::selectedPattern - -void VPatternWidget::importPattern() -{ - VPattern* pattern = KarbonFactory::rServer()->addPattern( KFileDialog::getOpenFileName( TQString(), - "*.jpg *.gif *.png *.tif *.xpm *.bmp", this, i18n( "Choose Pattern to Add" ) ) ); - if( pattern ) - m_patternChooser->addItem( pattern ); -} // VPatternWidget::importPattern - -void VPatternWidget::deletePattern() -{ - m_patternChooser->removeItem( m_pattern ); - KarbonFactory::rServer()->removePattern( m_pattern ); - m_patternChooser->updateContents(); - m_pattern = static_cast( m_patternChooser->currentItem() ); -} // VPatternWidget::deletePattern - -void VPatternWidget::slotButtonClicked( int id ) -{ - switch( id ) - { - case 0: importPattern(); - break; - case 1: deletePattern(); - break; - } -} // VPatternWidget::slotButtonClicked - -void VPatternWidget::patternSelected( KoIconItem* item ) -{ - m_pattern = (VPattern*)item; - m_deletePatternButton->setEnabled( TQFileInfo( m_pattern->tilename() ).isWritable() ); -} // VPatternWidget::patternSelected - -VPatternTool::VPatternTool( KarbonView *view ) - : VTool( view, "tool_pattern" ), m_state( normal ), m_handleSize( 3 ), m_active( false ) -{ - TQPtrList patterns = KarbonFactory::rServer()->patterns(); - m_optionsWidget = new VPatternWidget( &patterns, this ); - registerTool( this ); -} // VPatternTool::VPatternTool - -VPatternTool::~VPatternTool() -{ - delete m_optionsWidget; -} // VPatternTool::~VPatternTool - -void -VPatternTool::activate() -{ - m_active = true; - m_state = normal; - VTool::activate(); - view()->statusMessage()->setText( i18n( "Pattern" ) ); - view()->setCursor( TQCursor( TQt::crossCursor ) ); - - if( view() ) - { - // disable selection handles - view()->part()->document().selection()->showHandle( false ); - // connect to the stroke-fill-preview to get notice when the stroke or fill gets selected - VStrokeFillPreview* preview = view()->strokeFillPreview(); - if( preview ) - { - connect( preview, TQT_SIGNAL( fillSelected() ), this, TQT_SLOT( targetChanged() ) ); - connect( preview, TQT_SIGNAL( strokeSelected() ), this, TQT_SLOT( targetChanged() ) ); - } - view()->repaintAll( view()->part()->document().selection()->boundingBox() ); - } -} - -void -VPatternTool::deactivate() -{ - m_active = false; - - if( view() ) - { - // enable selection handles - view()->part()->document().selection()->showHandle( true ); - VStrokeFillPreview* preview = view()->strokeFillPreview(); - if( preview ) - { - disconnect( preview, TQT_SIGNAL( fillSelected() ), this, TQT_SLOT( targetChanged() ) ); - disconnect( preview, TQT_SIGNAL( strokeSelected() ), this, TQT_SLOT( targetChanged() ) ); - } - view()->repaintAll( view()->part()->document().selection()->boundingBox() ); - } -} - - -TQString -VPatternTool::contextHelp() -{ - TQString s = i18n( "Pattern tool:
" ); - s += i18n( "Click on the pattern you want in the chooser.
" ); - s += i18n( "Click and drag to choose the pattern vector.
" ); - s += i18n( "Press i or Shift+i to decrease or increase the handle size.
" ); - return s; -} // VPatternTool::contextHelp - -void VPatternTool::draw() -{ - if( ! view() || view()->part()->document().selection()->objects().count() == 0 ) - return; - - VPainter *painter = view()->painterFactory()->editpainter(); - painter->setRasterOp( TQt::NotROP ); - - painter->setPen( TQt::DotLine ); - - // differentiate between moving a handle and creating a complete new vector - if( m_state == moveOrigin || m_state == moveVector ) - { - painter->newPath(); - painter->moveTo( m_fixed ); - painter->lineTo( m_current ); - painter->strokePath(); - // draw the handle rects - painter->drawNode( m_fixed, m_handleSize ); - painter->drawNode( m_current, m_handleSize ); - } - else if( m_state == createNew ) - { - painter->newPath(); - painter->moveTo( first() ); - painter->lineTo( m_current ); - painter->strokePath(); - // draw the handle rects - painter->drawNode( first(), m_handleSize ); - painter->drawNode( m_current, m_handleSize ); - } -} // VPatternTool::draw - -bool -VPatternTool::getPattern( VPattern &pattern ) -{ - if( ! view() ) - return false; - - // determine if stroke of fill is selected for editing - //VStrokeFillPreview *preview = view()->strokeFillPreview(); - //bool strokeSelected = ( preview && preview->strokeIsSelected() ); - bool strokeSelected = false; // FIXME: stroke patterns don't work - - VSelection* selection = view()->part()->document().selection(); - if( selection->objects().count() != 1 ) - return false; - - VObject *obj = selection->objects().getFirst(); - // get the pattern of the first selected object, if any - if( strokeSelected && obj->stroke()->type() == VStroke::patt ) - pattern = obj->stroke()->pattern(); - else if( ! strokeSelected && obj->fill()->type() == VFill::patt ) - pattern = obj->fill()->pattern(); - else - return false; - - return true; -} - -void -VPatternTool::draw( VPainter* painter ) -{ - if( ! m_active ) - return; - - if( m_state != normal ) - return; - - if( ! getPattern( m_pattern ) ) - return; - - KoPoint s = m_pattern.origin(); - KoPoint e = m_pattern.vector(); - - // save the handle rects for later inside testing - m_origin = KoRect( s.x()-m_handleSize, s.y()-m_handleSize, 2*m_handleSize, 2*m_handleSize ); - m_vector = KoRect( e.x()-m_handleSize, e.y()-m_handleSize, 2*m_handleSize, 2*m_handleSize ); - - painter->setPen( TQt::blue.light() ); - painter->setBrush( TQt::blue.light() ); - painter->setRasterOp( TQt::XorROP ); - - // draw the pattern vector - painter->newPath(); - painter->moveTo( s ); - painter->lineTo( e ); - painter->strokePath(); - - // draw the handle rects - painter->drawNode( m_origin.center(), m_handleSize ); - painter->drawNode( m_vector.center(), m_handleSize ); -} - -void -VPatternTool::mouseDrag() -{ - if( m_state == normal ) - return; - - draw(); - - m_current = last(); - - draw(); -} // VPatternTool::mouseDrag - -void -VPatternTool::mouseButtonPress() -{ - m_current = first(); - - // set the apropriate editing state - if( m_origin.contains( m_current ) ) - { - m_state = moveOrigin; - m_fixed = m_vector.center(); - } - else if( m_vector.contains( m_current ) ) - { - m_state = moveVector; - m_fixed = m_origin.center(); - } - else - m_state = createNew; -} // VPatternTool::mouseButtonPress - -void -VPatternTool::mouseButtonRelease() -{ - m_state = normal; - - if( view()->part()->document().selection()->objects().count() == 0 ) - return; - - // save old pattern position - VPattern oldPattern = m_pattern; - - if( first() == last() ) - { - if( showDialog() != TQDialog::Accepted ) - return; - } - - if( !m_optionsWidget->selectedPattern() ) - { - KMessageBox::error( 0L, i18n( "Please select a pattern." ), "" ); - return; - } - - bool strokeSelected = false; - - // determine the target from the stroke-fill-preview-widget - //VStrokeFillPreview* preview = view()->strokeFillPreview(); - //if( preview && preview->strokeIsSelected() ) // FIXME: stroke patterns don't work - // strokeSelected = true; - - // calculate a sane intial position for the new pattern - if( view()->part()->document().selection()->objects().count() == 1 ) - { - VObject *obj = view()->part()->document().selection()->objects().getFirst(); - - if( ( ! strokeSelected && obj->fill()->type() != VFill::patt ) || (strokeSelected && obj->stroke()->type() != VStroke::patt ) ) - { - KoRect bbox = obj->boundingBox(); - oldPattern.setOrigin( bbox.bottomLeft() + 0.5*(bbox.topLeft()-bbox.bottomLeft()) ); - oldPattern.setVector( bbox.bottomRight() + 0.5*(bbox.topRight()-bbox.bottomRight()) ); - } - } - - m_pattern = *m_optionsWidget->selectedPattern(); - - // use the old pattern position - m_pattern.setOrigin( oldPattern.origin() ); - m_pattern.setVector( oldPattern.vector() ); - - if( ! strokeSelected ) - { - VFill fill; - fill.pattern() = m_pattern; - fill.setType( VFill::patt ); - view()->part()->addCommand( - new VFillCmd( &view()->part()->document(), fill, "14_pattern" ), true ); - } - else - { - VStroke stroke; - stroke.pattern() = m_pattern; - stroke.setType( VStroke::patt ); - view()->part()->addCommand( - new VStrokeCmd( &view()->part()->document(), &stroke, "14_pattern" ), true ); - } -} // VPatternTool::mouseButtonRelease - -void -VPatternTool::mouseDragRelease() -{ - if( ! view() || m_state == normal ) - return; - - if( view()->part()->document().selection()->objects().count() == 0 ) - { - draw(); - return; - } - - if( !m_optionsWidget->selectedPattern() ) - { - draw(); - KMessageBox::error( 0L, i18n( "Please select a pattern." ), "" ); - return; - } - //m_pattern = *m_optionsWidget->selectedPattern(); - - if( m_state == moveOrigin ) - m_pattern.setOrigin( last() ); - else if( m_state == moveVector ) - m_pattern.setVector( last() ); - else if( m_state == createNew ) - { - m_pattern.setOrigin( first() ); - m_pattern.setVector( last() ); - } - - m_state = normal; - - VStrokeFillPreview* preview = view()->strokeFillPreview(); - if( ! preview ) - return; - - //if( ! preview->strokeIsSelected() ) // FIXME: stroke patterns don't work - { - VFill fill; - fill.pattern() = m_pattern; - fill.setType( VFill::patt ); - view()->part()->addCommand( - new VFillCmd( &view()->part()->document(), fill, "14_pattern" ), true ); - } - /* - else - { - VStroke stroke; - stroke.pattern() = m_pattern; - stroke.setType( VStroke::patt ); - view()->part()->addCommand( - new VStrokeCmd( &view()->part()->document(), &stroke, "14_pattern" ), true ); - } - */ -} // VPatternTool::mouseDragRelease - -void -VPatternTool::cancel() -{ - // Erase old object: - if( isDragging() ) - draw(); - m_state = normal; -} - -bool -VPatternTool::showDialog() const -{ - return m_optionsWidget->exec() == TQDialog::Accepted; -} - -void -VPatternTool::setup( TDEActionCollection *collection ) -{ - m_action = static_cast(collection -> action( name() ) ); - - if( m_action == 0 ) - { - m_action = new TDERadioAction( i18n( "Pattern Tool" ), "14_pattern", TQt::SHIFT+TQt::Key_H, this, TQT_SLOT( activate() ), collection, name() ); - m_action->setToolTip( i18n( "Pattern" ) ); - m_action->setExclusiveGroup( "misc" ); - //m_ownAction = true; - } -} - -void -VPatternTool::setCursor() const -{ - if( !view() ) return; - - // set a different cursor if mouse is inside the handle rects - if( m_origin.contains( last() ) || m_vector.contains( last() ) ) - view()->setCursor( TQCursor( TQt::SizeAllCursor ) ); - else - view()->setCursor( TQCursor( TQt::arrowCursor ) ); -} - -bool -VPatternTool::keyReleased( TQt::Key key ) -{ - // increase/decrease the handle size - switch( key ) - { - case TQt::Key_I: - if( shiftPressed() ) - m_handleSize++; - else if( m_handleSize > 3 ) - m_handleSize--; - break; - default: return false; - } - - if( view() ) - view()->repaintAll( view()->part()->document().selection()->boundingBox() ); - - return true; -} - -void -VPatternTool::targetChanged() -{ - if( view() ) - view()->repaintAll( view()->part()->document().selection()->boundingBox() ); -} - -#include "vpatterntool.moc" diff --git a/karbon/tools/vpatterntool.cpp b/karbon/tools/vpatterntool.cpp new file mode 100644 index 00000000..8c42d5e0 --- /dev/null +++ b/karbon/tools/vpatterntool.cpp @@ -0,0 +1,509 @@ +/* This file is part of the KDE project + Copyright (C) 2001, 2002, 2003 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 "vpatterntool.h" + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +VPatternWidget::VPatternWidget( TQPtrList* patterns, VTool*, TQWidget* parent ) + : KDialogBase( parent, "", true, i18n( "Choose Pattern" ), Ok | Cancel ), m_pattern( 0 ) +{ + TQWidget *base = new TQWidget( this ); + TQVBoxLayout* layout = new TQVBoxLayout( base ); + layout->addWidget( m_patternChooser = new KoIconChooser( TQSize( 32, 32 ), base ) ); + layout->addWidget( m_buttonGroup = new TQHButtonGroup( base ) ); + m_buttonGroup->insert( m_importPatternButton = new TQToolButton( m_buttonGroup ) ); + m_buttonGroup->insert( m_deletePatternButton = new TQToolButton( m_buttonGroup ) ); + m_patternChooser->setFixedSize( 180, 120 ); + m_importPatternButton->setIconSet( SmallIconSet( "14_layer_newlayer" ) ); + m_importPatternButton->setTextLabel( i18n( "Import" ) ); + m_deletePatternButton->setIconSet( SmallIconSet("14_layer_deletelayer" ) ); + m_deletePatternButton->setTextLabel( i18n( "Delete" ) ); + + m_buttonGroup->setInsideMargin( 3 ); + m_importPatternButton->setEnabled( true ); + m_deletePatternButton->setEnabled( false ); + + //setFrameStyle( Box | Sunken ); + layout->setMargin( 3 ); + + connect( m_buttonGroup, TQT_SIGNAL( clicked( int ) ), this, TQT_SLOT( slotButtonClicked( int ) ) ); + connect( m_patternChooser, TQT_SIGNAL( selected( KoIconItem* ) ), this, TQT_SLOT( patternSelected( KoIconItem* ) ) ); + + KoIconItem* item; + for( item = patterns->first(); item; item = patterns->next() ) + m_patternChooser->addItem( item ); + m_pattern = (VPattern*)patterns->first(); + + setMainWidget( base ); +} // VPatternWidget::VPatternWidget + +VPatternWidget::~VPatternWidget() +{ +} // VPatternWidget::~VPatternWidget + +VPattern* VPatternWidget::selectedPattern() +{ + return m_pattern; +} // VPatternWidget::selectedPattern + +void VPatternWidget::importPattern() +{ + VPattern* pattern = KarbonFactory::rServer()->addPattern( KFileDialog::getOpenFileName( TQString(), + "*.jpg *.gif *.png *.tif *.xpm *.bmp", this, i18n( "Choose Pattern to Add" ) ) ); + if( pattern ) + m_patternChooser->addItem( pattern ); +} // VPatternWidget::importPattern + +void VPatternWidget::deletePattern() +{ + m_patternChooser->removeItem( m_pattern ); + KarbonFactory::rServer()->removePattern( m_pattern ); + m_patternChooser->updateContents(); + m_pattern = static_cast( m_patternChooser->currentItem() ); +} // VPatternWidget::deletePattern + +void VPatternWidget::slotButtonClicked( int id ) +{ + switch( id ) + { + case 0: importPattern(); + break; + case 1: deletePattern(); + break; + } +} // VPatternWidget::slotButtonClicked + +void VPatternWidget::patternSelected( KoIconItem* item ) +{ + m_pattern = (VPattern*)item; + m_deletePatternButton->setEnabled( TQFileInfo( m_pattern->tilename() ).isWritable() ); +} // VPatternWidget::patternSelected + +VPatternTool::VPatternTool( KarbonView *view ) + : VTool( view, "tool_pattern" ), m_state( normal ), m_handleSize( 3 ), m_active( false ) +{ + TQPtrList patterns = KarbonFactory::rServer()->patterns(); + m_optionsWidget = new VPatternWidget( &patterns, this ); + registerTool( this ); +} // VPatternTool::VPatternTool + +VPatternTool::~VPatternTool() +{ + delete m_optionsWidget; +} // VPatternTool::~VPatternTool + +void +VPatternTool::activate() +{ + m_active = true; + m_state = normal; + VTool::activate(); + view()->statusMessage()->setText( i18n( "Pattern" ) ); + view()->setCursor( TQCursor( TQt::crossCursor ) ); + + if( view() ) + { + // disable selection handles + view()->part()->document().selection()->showHandle( false ); + // connect to the stroke-fill-preview to get notice when the stroke or fill gets selected + VStrokeFillPreview* preview = view()->strokeFillPreview(); + if( preview ) + { + connect( preview, TQT_SIGNAL( fillSelected() ), this, TQT_SLOT( targetChanged() ) ); + connect( preview, TQT_SIGNAL( strokeSelected() ), this, TQT_SLOT( targetChanged() ) ); + } + view()->repaintAll( view()->part()->document().selection()->boundingBox() ); + } +} + +void +VPatternTool::deactivate() +{ + m_active = false; + + if( view() ) + { + // enable selection handles + view()->part()->document().selection()->showHandle( true ); + VStrokeFillPreview* preview = view()->strokeFillPreview(); + if( preview ) + { + disconnect( preview, TQT_SIGNAL( fillSelected() ), this, TQT_SLOT( targetChanged() ) ); + disconnect( preview, TQT_SIGNAL( strokeSelected() ), this, TQT_SLOT( targetChanged() ) ); + } + view()->repaintAll( view()->part()->document().selection()->boundingBox() ); + } +} + + +TQString +VPatternTool::contextHelp() +{ + TQString s = i18n( "Pattern tool:
" ); + s += i18n( "Click on the pattern you want in the chooser.
" ); + s += i18n( "Click and drag to choose the pattern vector.
" ); + s += i18n( "Press i or Shift+i to decrease or increase the handle size.
" ); + return s; +} // VPatternTool::contextHelp + +void VPatternTool::draw() +{ + if( ! view() || view()->part()->document().selection()->objects().count() == 0 ) + return; + + VPainter *painter = view()->painterFactory()->editpainter(); + painter->setRasterOp( TQt::NotROP ); + + painter->setPen( TQt::DotLine ); + + // differentiate between moving a handle and creating a complete new vector + if( m_state == moveOrigin || m_state == moveVector ) + { + painter->newPath(); + painter->moveTo( m_fixed ); + painter->lineTo( m_current ); + painter->strokePath(); + // draw the handle rects + painter->drawNode( m_fixed, m_handleSize ); + painter->drawNode( m_current, m_handleSize ); + } + else if( m_state == createNew ) + { + painter->newPath(); + painter->moveTo( first() ); + painter->lineTo( m_current ); + painter->strokePath(); + // draw the handle rects + painter->drawNode( first(), m_handleSize ); + painter->drawNode( m_current, m_handleSize ); + } +} // VPatternTool::draw + +bool +VPatternTool::getPattern( VPattern &pattern ) +{ + if( ! view() ) + return false; + + // determine if stroke of fill is selected for editing + //VStrokeFillPreview *preview = view()->strokeFillPreview(); + //bool strokeSelected = ( preview && preview->strokeIsSelected() ); + bool strokeSelected = false; // FIXME: stroke patterns don't work + + VSelection* selection = view()->part()->document().selection(); + if( selection->objects().count() != 1 ) + return false; + + VObject *obj = selection->objects().getFirst(); + // get the pattern of the first selected object, if any + if( strokeSelected && obj->stroke()->type() == VStroke::patt ) + pattern = obj->stroke()->pattern(); + else if( ! strokeSelected && obj->fill()->type() == VFill::patt ) + pattern = obj->fill()->pattern(); + else + return false; + + return true; +} + +void +VPatternTool::draw( VPainter* painter ) +{ + if( ! m_active ) + return; + + if( m_state != normal ) + return; + + if( ! getPattern( m_pattern ) ) + return; + + KoPoint s = m_pattern.origin(); + KoPoint e = m_pattern.vector(); + + // save the handle rects for later inside testing + m_origin = KoRect( s.x()-m_handleSize, s.y()-m_handleSize, 2*m_handleSize, 2*m_handleSize ); + m_vector = KoRect( e.x()-m_handleSize, e.y()-m_handleSize, 2*m_handleSize, 2*m_handleSize ); + + painter->setPen( TQt::blue.light() ); + painter->setBrush( TQt::blue.light() ); + painter->setRasterOp( TQt::XorROP ); + + // draw the pattern vector + painter->newPath(); + painter->moveTo( s ); + painter->lineTo( e ); + painter->strokePath(); + + // draw the handle rects + painter->drawNode( m_origin.center(), m_handleSize ); + painter->drawNode( m_vector.center(), m_handleSize ); +} + +void +VPatternTool::mouseDrag() +{ + if( m_state == normal ) + return; + + draw(); + + m_current = last(); + + draw(); +} // VPatternTool::mouseDrag + +void +VPatternTool::mouseButtonPress() +{ + m_current = first(); + + // set the apropriate editing state + if( m_origin.contains( m_current ) ) + { + m_state = moveOrigin; + m_fixed = m_vector.center(); + } + else if( m_vector.contains( m_current ) ) + { + m_state = moveVector; + m_fixed = m_origin.center(); + } + else + m_state = createNew; +} // VPatternTool::mouseButtonPress + +void +VPatternTool::mouseButtonRelease() +{ + m_state = normal; + + if( view()->part()->document().selection()->objects().count() == 0 ) + return; + + // save old pattern position + VPattern oldPattern = m_pattern; + + if( first() == last() ) + { + if( showDialog() != TQDialog::Accepted ) + return; + } + + if( !m_optionsWidget->selectedPattern() ) + { + KMessageBox::error( 0L, i18n( "Please select a pattern." ), "" ); + return; + } + + bool strokeSelected = false; + + // determine the target from the stroke-fill-preview-widget + //VStrokeFillPreview* preview = view()->strokeFillPreview(); + //if( preview && preview->strokeIsSelected() ) // FIXME: stroke patterns don't work + // strokeSelected = true; + + // calculate a sane intial position for the new pattern + if( view()->part()->document().selection()->objects().count() == 1 ) + { + VObject *obj = view()->part()->document().selection()->objects().getFirst(); + + if( ( ! strokeSelected && obj->fill()->type() != VFill::patt ) || (strokeSelected && obj->stroke()->type() != VStroke::patt ) ) + { + KoRect bbox = obj->boundingBox(); + oldPattern.setOrigin( bbox.bottomLeft() + 0.5*(bbox.topLeft()-bbox.bottomLeft()) ); + oldPattern.setVector( bbox.bottomRight() + 0.5*(bbox.topRight()-bbox.bottomRight()) ); + } + } + + m_pattern = *m_optionsWidget->selectedPattern(); + + // use the old pattern position + m_pattern.setOrigin( oldPattern.origin() ); + m_pattern.setVector( oldPattern.vector() ); + + if( ! strokeSelected ) + { + VFill fill; + fill.pattern() = m_pattern; + fill.setType( VFill::patt ); + view()->part()->addCommand( + new VFillCmd( &view()->part()->document(), fill, "14_pattern" ), true ); + } + else + { + VStroke stroke; + stroke.pattern() = m_pattern; + stroke.setType( VStroke::patt ); + view()->part()->addCommand( + new VStrokeCmd( &view()->part()->document(), &stroke, "14_pattern" ), true ); + } +} // VPatternTool::mouseButtonRelease + +void +VPatternTool::mouseDragRelease() +{ + if( ! view() || m_state == normal ) + return; + + if( view()->part()->document().selection()->objects().count() == 0 ) + { + draw(); + return; + } + + if( !m_optionsWidget->selectedPattern() ) + { + draw(); + KMessageBox::error( 0L, i18n( "Please select a pattern." ), "" ); + return; + } + //m_pattern = *m_optionsWidget->selectedPattern(); + + if( m_state == moveOrigin ) + m_pattern.setOrigin( last() ); + else if( m_state == moveVector ) + m_pattern.setVector( last() ); + else if( m_state == createNew ) + { + m_pattern.setOrigin( first() ); + m_pattern.setVector( last() ); + } + + m_state = normal; + + VStrokeFillPreview* preview = view()->strokeFillPreview(); + if( ! preview ) + return; + + //if( ! preview->strokeIsSelected() ) // FIXME: stroke patterns don't work + { + VFill fill; + fill.pattern() = m_pattern; + fill.setType( VFill::patt ); + view()->part()->addCommand( + new VFillCmd( &view()->part()->document(), fill, "14_pattern" ), true ); + } + /* + else + { + VStroke stroke; + stroke.pattern() = m_pattern; + stroke.setType( VStroke::patt ); + view()->part()->addCommand( + new VStrokeCmd( &view()->part()->document(), &stroke, "14_pattern" ), true ); + } + */ +} // VPatternTool::mouseDragRelease + +void +VPatternTool::cancel() +{ + // Erase old object: + if( isDragging() ) + draw(); + m_state = normal; +} + +bool +VPatternTool::showDialog() const +{ + return m_optionsWidget->exec() == TQDialog::Accepted; +} + +void +VPatternTool::setup( TDEActionCollection *collection ) +{ + m_action = static_cast(collection -> action( name() ) ); + + if( m_action == 0 ) + { + m_action = new TDERadioAction( i18n( "Pattern Tool" ), "14_pattern", TQt::SHIFT+TQt::Key_H, this, TQT_SLOT( activate() ), collection, name() ); + m_action->setToolTip( i18n( "Pattern" ) ); + m_action->setExclusiveGroup( "misc" ); + //m_ownAction = true; + } +} + +void +VPatternTool::setCursor() const +{ + if( !view() ) return; + + // set a different cursor if mouse is inside the handle rects + if( m_origin.contains( last() ) || m_vector.contains( last() ) ) + view()->setCursor( TQCursor( TQt::SizeAllCursor ) ); + else + view()->setCursor( TQCursor( TQt::arrowCursor ) ); +} + +bool +VPatternTool::keyReleased( TQt::Key key ) +{ + // increase/decrease the handle size + switch( key ) + { + case TQt::Key_I: + if( shiftPressed() ) + m_handleSize++; + else if( m_handleSize > 3 ) + m_handleSize--; + break; + default: return false; + } + + if( view() ) + view()->repaintAll( view()->part()->document().selection()->boundingBox() ); + + return true; +} + +void +VPatternTool::targetChanged() +{ + if( view() ) + view()->repaintAll( view()->part()->document().selection()->boundingBox() ); +} + +#include "vpatterntool.moc" diff --git a/karbon/tools/vpenciltool.cc b/karbon/tools/vpenciltool.cc deleted file mode 100644 index 1239923e..00000000 --- a/karbon/tools/vpenciltool.cc +++ /dev/null @@ -1,411 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2001, 2002, 2003 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 - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -//#include - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "vpenciltool.h" -#include - -#include "vcurvefit.h" - -#include "vpenciltool.moc" - -VPencilOptionsWidget::VPencilOptionsWidget( KarbonView*view, TQWidget* parent, const char* name ) - : KDialogBase( parent, name, true, i18n( "Pencil Settings" ), Ok | Cancel ), m_view( view ) -{ - TQVBox *vbox = new TQVBox( this ); - - m_combo = new TQComboBox( vbox ); - - m_combo->insertItem( i18n( "Raw" ) ); - m_combo->insertItem( i18n( "Curve" ) ); - m_combo->insertItem( i18n( "Straight" ) ); - - m_widgetStack = new TQWidgetStack( vbox ); - - TQGroupBox *group1 = new TQGroupBox( 2, Qt::Horizontal, i18n( "Properties" ), m_widgetStack ); - m_widgetStack->addWidget( group1, 1 ); - m_optimizeRaw = new TQCheckBox( i18n( "Optimize" ), group1 ); - - group1->setInsideMargin( 4 ); - group1->setInsideSpacing( 2 ); - - TQGroupBox *group2 = new TQGroupBox( 2, Qt::Horizontal, i18n( "Properties" ), m_widgetStack ); - m_widgetStack->addWidget( group2, 2 ); - - TQVBox *vbox2 = new TQVBox( group2 ); - - m_optimizeCurve = new TQCheckBox( i18n( "Optimize" ), vbox2 ); - m_fittingError = new KDoubleNumInput( 0.0, 400.0, 4.00, 0.50, 3, vbox2 ); - m_fittingError->setLabel( i18n( "Exactness:" ) ); - - group2->setInsideMargin( 4 ); - group2->setInsideSpacing( 2 ); - - TQGroupBox *group3 = new TQGroupBox( 2, Qt::Horizontal, i18n( "Properties" ), m_widgetStack ); - m_widgetStack->addWidget( group3, 3 ); - - m_combineAngle = new KDoubleNumInput( 0.0, 360.0, 0.10, 0.50, 3, group3 ); - m_combineAngle->setSuffix( " deg" ); - m_combineAngle->setLabel( i18n( "Combine angle:" ) ); - - group3->setInsideMargin( 4 ); - group3->setInsideSpacing( 2 ); - - connect( m_combo, TQT_SIGNAL( activated( int ) ), this, TQT_SLOT( selectMode() ) ); - - //Set the default settings - m_mode = VPencilTool::CURVE; - selectMode(); - - m_optimizeCurve->setChecked( true ); - m_optimizeRaw->setChecked( true ); - - setMainWidget( vbox ); -} - -float VPencilOptionsWidget::combineAngle() -{ - return m_combineAngle->value(); -} - -bool VPencilOptionsWidget::optimize() -{ - return ( m_optimizeRaw->isChecked() || m_optimizeCurve->isChecked() ); -} - -float VPencilOptionsWidget::fittingError() -{ - return m_fittingError->value(); -} - -void VPencilOptionsWidget::selectMode() -{ - m_widgetStack->raiseWidget( m_combo->currentItem() + 1 ); - - switch( m_combo->currentItem() ) - { - case 0: m_mode = VPencilTool::RAW; break; - case 1: m_mode = VPencilTool::CURVE; break; - case 2: m_mode = VPencilTool::STRAIGHT; break; - } -} - -int VPencilOptionsWidget::currentMode(){ - return m_mode; -} - -/* ------------------------------------------------------------------------------------------------------------------------*/ - -VPencilTool::VPencilTool( KarbonView *view ) - : VTool( view, "tool_pencil" ) -{ - m_Points.setAutoDelete( true ); - m_optionWidget = new VPencilOptionsWidget( view ); - registerTool( this ); - m_mode = CURVE; - m_optimize = true; - m_combineAngle = 3.0f; - m_cursor = new TQCursor( VCursor::createCursor( VCursor::CrossHair ) ); -} - -VPencilTool::~VPencilTool() -{ - delete m_cursor; -} - -TQString -VPencilTool::contextHelp() -{ - TQString s = i18n( "Pencil tool:
" ); - s += i18n( "- Click to begin drawing, release when you have finished."); - s += i18n( "- Press Enter or double click to end the polyline.
" ); - - return s; -} - -void -VPencilTool::activate() -{ - VTool::activate(); - view()->statusMessage()->setText( i18n( "Pencil Tool" ) ); - view()->setCursor( *m_cursor ); - view()->part()->document().selection()->showHandle( false ); - - m_Points.clear(); - m_close = false; -} - -void -VPencilTool::deactivate() -{ - m_Points.removeLast(); - m_Points.removeLast(); - - VPath* line = 0L; - - TQPtrList complete; - TQPtrList *points = &m_Points; - - if( m_Points.count() > 1 ) - { - if( m_optimize || m_mode == STRAIGHT ) - { - complete.setAutoDelete( true ); - m_Points.setAutoDelete( false ); - - float cangle; - - if( m_mode == STRAIGHT ) - cangle = m_combineAngle; - else - cangle = 0.50f; - - #define ANGLE(P0,P1)\ - atan((P1)->y()-(P0)->y())/((P1)->x()-(P0)->x())*(180/M_PI) - - //Add the first point - complete.append( m_Points.first() ); - complete.append( m_Points.next() ); - - //Now we need to get the angle of the first line - float langle = ANGLE( complete.at( 0 ), complete.at( 1 ) ); - - KoPoint *nextp = NULL; - while( ( nextp = m_Points.next() ) ) - { - float angle = ANGLE( complete.last(), nextp ); - if( TQABS( angle - langle ) < cangle ) - complete.removeLast(); - complete.append(nextp); - langle=angle; - } - m_Points.clear(); - m_Points.setAutoDelete(true); - - points = &complete; - } - - switch(m_mode) - { - case CURVE: - { - line = bezierFit( *points, m_optionWidget->fittingError() ); - break; - } - case STRAIGHT: - case RAW: - { - line = new VPath( 0L ); - KoPoint* p1 = (*points).first(); - KoPoint* plast = p1; - line->moveTo( *p1 ); - - KoPoint* pnext = 0L; - - while( ( pnext = (*points).next() ) ) - { - line->lineTo( *pnext ); - plast = pnext; - } - break; - } - } - - if( shiftPressed() ) - line->close(); - } - - if( line ) - { - VShapeCmd* cmd = new VShapeCmd( - &view()->part()->document(), - i18n( "Pencil" ), - line, - "14_pencil" ); - - view()->part()->addCommand( cmd, true ); - } -} - -void -VPencilTool::draw() -{ - VPainter* painter = view()->painterFactory()->editpainter(); - painter->setRasterOp( TQt::NotROP ); - - m_mode = m_optionWidget->currentMode(); - m_optimize = m_optionWidget->optimize(); - m_combineAngle = m_optionWidget->combineAngle(); - - if( m_Points.count() > 1 ) - { - VPath line( 0L ); - line.moveTo( *m_Points.first() ); - - KoPoint *pnext; - while((pnext=m_Points.next())){ - line.lineTo( *pnext ); - } - - line.setState( VObject::edit ); - line.draw( painter, &line.boundingBox() ); - } - -} - - -void -VPencilTool::mouseMove() -{ -} - -void -VPencilTool::mouseButtonPress() -{ - m_Points.append( new KoPoint( last() ) ); - - draw(); -} - -void -VPencilTool::mouseButtonRelease() -{ - m_Points.append( new KoPoint( last() ) ); - draw(); - accept(); - return; -} - -void -VPencilTool::mouseButtonDblClick() -{ - accept(); -} - -void -VPencilTool::mouseDrag() -{ - if( m_Points.count() != 0 ) - { - draw(); - - m_Points.append( new KoPoint( last() ) ); - - draw(); - } -} - -void -VPencilTool::mouseDragRelease() -{ - mouseButtonRelease(); -} - -void -VPencilTool::mouseDragShiftPressed() -{ -} - -void -VPencilTool::mouseDragCtrlPressed() -{ - -} - -void -VPencilTool::mouseDragShiftReleased() -{ -} - -void -VPencilTool::mouseDragCtrlReleased() -{ -} - -void -VPencilTool::cancel() -{ - draw(); - - m_Points.clear(); -} - -void -VPencilTool::cancelStep() -{ - draw(); - - m_Points.clear(); - - draw(); -} - -void -VPencilTool::accept() -{ - deactivate(); - activate(); -} - -bool -VPencilTool::showDialog() const -{ - return m_optionWidget->exec() == TQDialog::Accepted; -} - -void -VPencilTool::setup( TDEActionCollection *collection ) -{ - m_action = static_cast(collection -> action( name() ) ); - - if( m_action == 0 ) - { - m_action = new TDERadioAction( i18n( "Pencil Tool" ), "14_pencil", TQt::SHIFT+TQt::Key_P, this, TQT_SLOT( activate() ), collection, name() ); - m_action->setToolTip( i18n( "Pencil" ) ); - m_action->setExclusiveGroup( "freehand" ); - //m_ownAction = true; - } -} - diff --git a/karbon/tools/vpenciltool.cpp b/karbon/tools/vpenciltool.cpp new file mode 100644 index 00000000..1239923e --- /dev/null +++ b/karbon/tools/vpenciltool.cpp @@ -0,0 +1,411 @@ +/* This file is part of the KDE project + Copyright (C) 2001, 2002, 2003 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 + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +//#include + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "vpenciltool.h" +#include + +#include "vcurvefit.h" + +#include "vpenciltool.moc" + +VPencilOptionsWidget::VPencilOptionsWidget( KarbonView*view, TQWidget* parent, const char* name ) + : KDialogBase( parent, name, true, i18n( "Pencil Settings" ), Ok | Cancel ), m_view( view ) +{ + TQVBox *vbox = new TQVBox( this ); + + m_combo = new TQComboBox( vbox ); + + m_combo->insertItem( i18n( "Raw" ) ); + m_combo->insertItem( i18n( "Curve" ) ); + m_combo->insertItem( i18n( "Straight" ) ); + + m_widgetStack = new TQWidgetStack( vbox ); + + TQGroupBox *group1 = new TQGroupBox( 2, Qt::Horizontal, i18n( "Properties" ), m_widgetStack ); + m_widgetStack->addWidget( group1, 1 ); + m_optimizeRaw = new TQCheckBox( i18n( "Optimize" ), group1 ); + + group1->setInsideMargin( 4 ); + group1->setInsideSpacing( 2 ); + + TQGroupBox *group2 = new TQGroupBox( 2, Qt::Horizontal, i18n( "Properties" ), m_widgetStack ); + m_widgetStack->addWidget( group2, 2 ); + + TQVBox *vbox2 = new TQVBox( group2 ); + + m_optimizeCurve = new TQCheckBox( i18n( "Optimize" ), vbox2 ); + m_fittingError = new KDoubleNumInput( 0.0, 400.0, 4.00, 0.50, 3, vbox2 ); + m_fittingError->setLabel( i18n( "Exactness:" ) ); + + group2->setInsideMargin( 4 ); + group2->setInsideSpacing( 2 ); + + TQGroupBox *group3 = new TQGroupBox( 2, Qt::Horizontal, i18n( "Properties" ), m_widgetStack ); + m_widgetStack->addWidget( group3, 3 ); + + m_combineAngle = new KDoubleNumInput( 0.0, 360.0, 0.10, 0.50, 3, group3 ); + m_combineAngle->setSuffix( " deg" ); + m_combineAngle->setLabel( i18n( "Combine angle:" ) ); + + group3->setInsideMargin( 4 ); + group3->setInsideSpacing( 2 ); + + connect( m_combo, TQT_SIGNAL( activated( int ) ), this, TQT_SLOT( selectMode() ) ); + + //Set the default settings + m_mode = VPencilTool::CURVE; + selectMode(); + + m_optimizeCurve->setChecked( true ); + m_optimizeRaw->setChecked( true ); + + setMainWidget( vbox ); +} + +float VPencilOptionsWidget::combineAngle() +{ + return m_combineAngle->value(); +} + +bool VPencilOptionsWidget::optimize() +{ + return ( m_optimizeRaw->isChecked() || m_optimizeCurve->isChecked() ); +} + +float VPencilOptionsWidget::fittingError() +{ + return m_fittingError->value(); +} + +void VPencilOptionsWidget::selectMode() +{ + m_widgetStack->raiseWidget( m_combo->currentItem() + 1 ); + + switch( m_combo->currentItem() ) + { + case 0: m_mode = VPencilTool::RAW; break; + case 1: m_mode = VPencilTool::CURVE; break; + case 2: m_mode = VPencilTool::STRAIGHT; break; + } +} + +int VPencilOptionsWidget::currentMode(){ + return m_mode; +} + +/* ------------------------------------------------------------------------------------------------------------------------*/ + +VPencilTool::VPencilTool( KarbonView *view ) + : VTool( view, "tool_pencil" ) +{ + m_Points.setAutoDelete( true ); + m_optionWidget = new VPencilOptionsWidget( view ); + registerTool( this ); + m_mode = CURVE; + m_optimize = true; + m_combineAngle = 3.0f; + m_cursor = new TQCursor( VCursor::createCursor( VCursor::CrossHair ) ); +} + +VPencilTool::~VPencilTool() +{ + delete m_cursor; +} + +TQString +VPencilTool::contextHelp() +{ + TQString s = i18n( "Pencil tool:
" ); + s += i18n( "- Click to begin drawing, release when you have finished."); + s += i18n( "- Press Enter or double click to end the polyline.
" ); + + return s; +} + +void +VPencilTool::activate() +{ + VTool::activate(); + view()->statusMessage()->setText( i18n( "Pencil Tool" ) ); + view()->setCursor( *m_cursor ); + view()->part()->document().selection()->showHandle( false ); + + m_Points.clear(); + m_close = false; +} + +void +VPencilTool::deactivate() +{ + m_Points.removeLast(); + m_Points.removeLast(); + + VPath* line = 0L; + + TQPtrList complete; + TQPtrList *points = &m_Points; + + if( m_Points.count() > 1 ) + { + if( m_optimize || m_mode == STRAIGHT ) + { + complete.setAutoDelete( true ); + m_Points.setAutoDelete( false ); + + float cangle; + + if( m_mode == STRAIGHT ) + cangle = m_combineAngle; + else + cangle = 0.50f; + + #define ANGLE(P0,P1)\ + atan((P1)->y()-(P0)->y())/((P1)->x()-(P0)->x())*(180/M_PI) + + //Add the first point + complete.append( m_Points.first() ); + complete.append( m_Points.next() ); + + //Now we need to get the angle of the first line + float langle = ANGLE( complete.at( 0 ), complete.at( 1 ) ); + + KoPoint *nextp = NULL; + while( ( nextp = m_Points.next() ) ) + { + float angle = ANGLE( complete.last(), nextp ); + if( TQABS( angle - langle ) < cangle ) + complete.removeLast(); + complete.append(nextp); + langle=angle; + } + m_Points.clear(); + m_Points.setAutoDelete(true); + + points = &complete; + } + + switch(m_mode) + { + case CURVE: + { + line = bezierFit( *points, m_optionWidget->fittingError() ); + break; + } + case STRAIGHT: + case RAW: + { + line = new VPath( 0L ); + KoPoint* p1 = (*points).first(); + KoPoint* plast = p1; + line->moveTo( *p1 ); + + KoPoint* pnext = 0L; + + while( ( pnext = (*points).next() ) ) + { + line->lineTo( *pnext ); + plast = pnext; + } + break; + } + } + + if( shiftPressed() ) + line->close(); + } + + if( line ) + { + VShapeCmd* cmd = new VShapeCmd( + &view()->part()->document(), + i18n( "Pencil" ), + line, + "14_pencil" ); + + view()->part()->addCommand( cmd, true ); + } +} + +void +VPencilTool::draw() +{ + VPainter* painter = view()->painterFactory()->editpainter(); + painter->setRasterOp( TQt::NotROP ); + + m_mode = m_optionWidget->currentMode(); + m_optimize = m_optionWidget->optimize(); + m_combineAngle = m_optionWidget->combineAngle(); + + if( m_Points.count() > 1 ) + { + VPath line( 0L ); + line.moveTo( *m_Points.first() ); + + KoPoint *pnext; + while((pnext=m_Points.next())){ + line.lineTo( *pnext ); + } + + line.setState( VObject::edit ); + line.draw( painter, &line.boundingBox() ); + } + +} + + +void +VPencilTool::mouseMove() +{ +} + +void +VPencilTool::mouseButtonPress() +{ + m_Points.append( new KoPoint( last() ) ); + + draw(); +} + +void +VPencilTool::mouseButtonRelease() +{ + m_Points.append( new KoPoint( last() ) ); + draw(); + accept(); + return; +} + +void +VPencilTool::mouseButtonDblClick() +{ + accept(); +} + +void +VPencilTool::mouseDrag() +{ + if( m_Points.count() != 0 ) + { + draw(); + + m_Points.append( new KoPoint( last() ) ); + + draw(); + } +} + +void +VPencilTool::mouseDragRelease() +{ + mouseButtonRelease(); +} + +void +VPencilTool::mouseDragShiftPressed() +{ +} + +void +VPencilTool::mouseDragCtrlPressed() +{ + +} + +void +VPencilTool::mouseDragShiftReleased() +{ +} + +void +VPencilTool::mouseDragCtrlReleased() +{ +} + +void +VPencilTool::cancel() +{ + draw(); + + m_Points.clear(); +} + +void +VPencilTool::cancelStep() +{ + draw(); + + m_Points.clear(); + + draw(); +} + +void +VPencilTool::accept() +{ + deactivate(); + activate(); +} + +bool +VPencilTool::showDialog() const +{ + return m_optionWidget->exec() == TQDialog::Accepted; +} + +void +VPencilTool::setup( TDEActionCollection *collection ) +{ + m_action = static_cast(collection -> action( name() ) ); + + if( m_action == 0 ) + { + m_action = new TDERadioAction( i18n( "Pencil Tool" ), "14_pencil", TQt::SHIFT+TQt::Key_P, this, TQT_SLOT( activate() ), collection, name() ); + m_action->setToolTip( i18n( "Pencil" ) ); + m_action->setExclusiveGroup( "freehand" ); + //m_ownAction = true; + } +} + diff --git a/karbon/tools/vpolygontool.cc b/karbon/tools/vpolygontool.cc deleted file mode 100644 index de475691..00000000 --- a/karbon/tools/vpolygontool.cc +++ /dev/null @@ -1,165 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2001, 2002, 2003 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 -#include - -#include -#include -#include - -#include -#include -#include -#include "vpolygontool.h" - -VPolygonTool::VPolygonOptionsWidget::VPolygonOptionsWidget( KarbonView *view, TQWidget* parent, const char* name ) - : KDialogBase( parent, name, true, i18n( "Insert Polygon" ), Ok | Cancel ), m_view(view) -{ - TQGroupBox *group = new TQGroupBox( 2, Qt::Horizontal, i18n( "Properties" ), this ); - - new TQLabel( i18n( "Radius:" ), group ); - m_radius = new KoUnitDoubleSpinBox( group, 0.0, 1000.0, 0.5, 50.0, KoUnit::U_MM ); - refreshUnit(); - new TQLabel( i18n( "Edges:" ), group ); - m_edges = new KIntSpinBox( group ); - m_edges->setMinValue( 3 ); - - group->setInsideMargin( 4 ); - group->setInsideSpacing( 2 ); - - setMainWidget( group ); - //setFixedSize( baseSize() ); -} - -double -VPolygonTool::VPolygonOptionsWidget::radius() const -{ - return m_radius->value(); -} - -uint -VPolygonTool::VPolygonOptionsWidget::edges() const -{ - return m_edges->value(); -} - -void -VPolygonTool::VPolygonOptionsWidget::setRadius( double value ) -{ - m_radius->changeValue( value ); -} - -void -VPolygonTool::VPolygonOptionsWidget::setEdges( uint value ) -{ - m_edges->setValue( value ); -} - -void -VPolygonTool::VPolygonOptionsWidget::refreshUnit() -{ - m_radius->setUnit( m_view->part()->unit() ); -} - -VPolygonTool::VPolygonTool( KarbonView *view ) - : VShapeTool( view, "tool_polygon", true ) -{ - // create config dialog: - m_optionsWidget = new VPolygonOptionsWidget( view ); - m_optionsWidget->setEdges( 5 ); - registerTool( this ); -} - -VPolygonTool::~VPolygonTool() -{ - delete( m_optionsWidget ); -} - -void -VPolygonTool::refreshUnit() -{ - m_optionsWidget->refreshUnit(); -} - -void -VPolygonTool::arrowKeyReleased( TQt::Key key ) -{ - int change = 0; - if( key == TQt::Key_Up ) - change = 1; - else if( key == TQt::Key_Down ) - change = -1; - - if( change != 0 ) - { - draw(); - - m_optionsWidget->setEdges( m_optionsWidget->edges() + change ); - - draw(); - } -} - -VPath* -VPolygonTool::shape( bool interactive ) const -{ - if( interactive ) - { - return - new VStar( - 0L, - m_p, - m_optionsWidget->radius(), - m_optionsWidget->radius(), - m_optionsWidget->edges(), 0, 0, 0, VStar::polygon ); - } - else - return - new VStar( - 0L, - m_p, - m_d1, m_d1, - m_optionsWidget->edges(), - m_d2, 0, 0, VStar::polygon ); -} - -bool -VPolygonTool::showDialog() const -{ - return m_optionsWidget->exec() == TQDialog::Accepted; -} - -void -VPolygonTool::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" ), "14_polygon", shortcut, this, TQT_SLOT( activate() ), collection, name() ); - m_action->setToolTip( i18n( "Polygon" ) ); - m_action->setExclusiveGroup( "shapes" ); - //m_ownAction = true; - } -} - diff --git a/karbon/tools/vpolygontool.cpp b/karbon/tools/vpolygontool.cpp new file mode 100644 index 00000000..de475691 --- /dev/null +++ b/karbon/tools/vpolygontool.cpp @@ -0,0 +1,165 @@ +/* This file is part of the KDE project + Copyright (C) 2001, 2002, 2003 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 +#include + +#include +#include +#include + +#include +#include +#include +#include "vpolygontool.h" + +VPolygonTool::VPolygonOptionsWidget::VPolygonOptionsWidget( KarbonView *view, TQWidget* parent, const char* name ) + : KDialogBase( parent, name, true, i18n( "Insert Polygon" ), Ok | Cancel ), m_view(view) +{ + TQGroupBox *group = new TQGroupBox( 2, Qt::Horizontal, i18n( "Properties" ), this ); + + new TQLabel( i18n( "Radius:" ), group ); + m_radius = new KoUnitDoubleSpinBox( group, 0.0, 1000.0, 0.5, 50.0, KoUnit::U_MM ); + refreshUnit(); + new TQLabel( i18n( "Edges:" ), group ); + m_edges = new KIntSpinBox( group ); + m_edges->setMinValue( 3 ); + + group->setInsideMargin( 4 ); + group->setInsideSpacing( 2 ); + + setMainWidget( group ); + //setFixedSize( baseSize() ); +} + +double +VPolygonTool::VPolygonOptionsWidget::radius() const +{ + return m_radius->value(); +} + +uint +VPolygonTool::VPolygonOptionsWidget::edges() const +{ + return m_edges->value(); +} + +void +VPolygonTool::VPolygonOptionsWidget::setRadius( double value ) +{ + m_radius->changeValue( value ); +} + +void +VPolygonTool::VPolygonOptionsWidget::setEdges( uint value ) +{ + m_edges->setValue( value ); +} + +void +VPolygonTool::VPolygonOptionsWidget::refreshUnit() +{ + m_radius->setUnit( m_view->part()->unit() ); +} + +VPolygonTool::VPolygonTool( KarbonView *view ) + : VShapeTool( view, "tool_polygon", true ) +{ + // create config dialog: + m_optionsWidget = new VPolygonOptionsWidget( view ); + m_optionsWidget->setEdges( 5 ); + registerTool( this ); +} + +VPolygonTool::~VPolygonTool() +{ + delete( m_optionsWidget ); +} + +void +VPolygonTool::refreshUnit() +{ + m_optionsWidget->refreshUnit(); +} + +void +VPolygonTool::arrowKeyReleased( TQt::Key key ) +{ + int change = 0; + if( key == TQt::Key_Up ) + change = 1; + else if( key == TQt::Key_Down ) + change = -1; + + if( change != 0 ) + { + draw(); + + m_optionsWidget->setEdges( m_optionsWidget->edges() + change ); + + draw(); + } +} + +VPath* +VPolygonTool::shape( bool interactive ) const +{ + if( interactive ) + { + return + new VStar( + 0L, + m_p, + m_optionsWidget->radius(), + m_optionsWidget->radius(), + m_optionsWidget->edges(), 0, 0, 0, VStar::polygon ); + } + else + return + new VStar( + 0L, + m_p, + m_d1, m_d1, + m_optionsWidget->edges(), + m_d2, 0, 0, VStar::polygon ); +} + +bool +VPolygonTool::showDialog() const +{ + return m_optionsWidget->exec() == TQDialog::Accepted; +} + +void +VPolygonTool::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" ), "14_polygon", shortcut, this, TQT_SLOT( activate() ), collection, name() ); + m_action->setToolTip( i18n( "Polygon" ) ); + m_action->setExclusiveGroup( "shapes" ); + //m_ownAction = true; + } +} + diff --git a/karbon/tools/vpolylinetool.cc b/karbon/tools/vpolylinetool.cc deleted file mode 100644 index 38ac9d25..00000000 --- a/karbon/tools/vpolylinetool.cc +++ /dev/null @@ -1,504 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2001, 2002, 2003 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 -#include -#include - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "vpolylinetool.h" -#include -#include -#include - -VPolylineTool::VPolylineTool( KarbonView *view ) - : VTool( view, "tool_polyline" ) -{ - m_bezierPoints.setAutoDelete( true ); - registerTool( this ); - m_crossCursor = new TQCursor( VCursor::createCursor( VCursor::CrossHair ) ); -} - -VPolylineTool::~VPolylineTool() -{ - delete m_crossCursor; -} - -TQString -VPolylineTool::contextHelp() -{ - TQString s = i18n( "Polyline tool:
" ); - s += i18n( "- Click to add a node and drag to set its bezier vector.
" ); - s += i18n( "- Press Ctrl while dragging to edit the previous bezier vector.
" ); - s += i18n( "- Press Shift while dragging to change the curve in a straight line.
" ); - s += i18n( "- Press Backspace to cancel the last curve.
" ); - s += i18n( "- Press Esc to cancel the whole polyline.
" ); - s += i18n( "- Press Enter or double click to end the polyline.
" ); - - return s; -} - -void -VPolylineTool::activate() -{ - VTool::activate(); - view()->statusMessage()->setText( i18n( "Polyline Tool" ) ); - view()->setCursor( *m_crossCursor ); - - m_bezierPoints.clear(); - m_close = false; - - connect( view()->part()->commandHistory(), TQT_SIGNAL(commandExecuted()), this, TQT_SLOT(commandExecuted()) ); -} - -void -VPolylineTool::initializePath( VPath &path ) -{ - KoPoint* p1 = m_bezierPoints.first(); - KoPoint* p2; - KoPoint* p3; - KoPoint* p4; - - path.moveTo( *p1 ); - - while( - ( p2 = m_bezierPoints.next() ) && - ( p3 = m_bezierPoints.next() ) && - ( p4 = m_bezierPoints.next() ) ) - { - if ( *p1 == *p2 ) - if ( *p3 == *p4 ) - path.lineTo( *p4 ); - else - //polyline->curve1To( *p3, *p4 ); - path.curveTo( *p3, *p4, *p4 ); - else - if ( *p3 == *p4 ) - //polyline->curve2To( *p2, *p4 ); - path.curveTo( *p2, *p2, *p4 ); - else - path.curveTo( *p2, *p3, *p4 ); - p1 = p4; - } -} - -void -VPolylineTool::createObject() -{ - VPath* polyline = 0L; - if( m_bezierPoints.count() > 2 ) - { - polyline = new VPath( 0L ); - if( polyline ) - { - initializePath( *polyline ); - if( m_close ) - polyline->close(); - - VShapeCmd* cmd = new VShapeCmd( - &view()->part()->document(), - i18n( "Polyline" ), - polyline, - "14_polyline" ); - - view()->part()->addCommand( cmd, true ); - } - } - - m_bezierPoints.clear(); - m_close = false; -} - -void -VPolylineTool::deactivate() -{ - m_bezierPoints.removeLast(); - m_bezierPoints.removeLast(); - - createObject(); - - disconnect( view()->part()->commandHistory(), TQT_SIGNAL(commandExecuted()), this, TQT_SLOT(commandExecuted()) ); -} - -void -VPolylineTool::draw() -{ - VPainter* painter = view()->painterFactory()->editpainter(); - painter->setRasterOp( TQt::NotROP ); - - if( m_bezierPoints.count() > 2 ) - { - VPath polyline( 0L ); - initializePath( polyline ); - - polyline.setState( VObject::edit ); - polyline.draw( painter, &polyline.boundingBox() ); - } -} - -void -VPolylineTool::drawBezierVector( KoPoint& start, KoPoint& end ) -{ - VPainter* painter = view()->painterFactory()->editpainter(); - - painter->save(); - - float zoomFactor = view()->zoom(); - - painter->setRasterOp( TQt::NotROP ); - painter->newPath(); -/* VStroke stroke( TQt::blue, 0L, 1.0 ); - TQValueList array; - array << 2.0 << 3.0; - stroke.dashPattern().setArray( array );*/ - painter->setPen( TQt::DotLine /*stroke*/ ); - painter->setBrush( TQt::NoBrush ); - - painter->moveTo( start ); - painter->lineTo( end ); - painter->strokePath(); - painter->setRasterOp( TQt::XorROP ); - painter->newPath(); - painter->setPen( TQt::yellow ); - - float width = 2.0; - - painter->moveTo( KoPoint( - end.x() - width / zoomFactor, - end.y() - width / zoomFactor ) ); - painter->lineTo( KoPoint( - end.x() + width / zoomFactor, - end.y() - width / zoomFactor ) ); - painter->lineTo( KoPoint( - end.x() + width / zoomFactor, - end.y() + width / zoomFactor ) ); - painter->lineTo( KoPoint( - end.x() - width / zoomFactor, - end.y() + width / zoomFactor ) ); - painter->lineTo( KoPoint( - end.x() - width / zoomFactor, - end.y() - width / zoomFactor ) ); - - painter->strokePath(); - painter->restore(); -} - -void -VPolylineTool::mouseMove() -{ - if( m_bezierPoints.count() != 0 ) - { - KoPoint _last = view()->canvasWidget()->snapToGrid( last() ); - draw(); - - m_bezierPoints.removeLast(); - m_bezierPoints.removeLast(); - m_bezierPoints.append( new KoPoint( _last ) ); - m_bezierPoints.append( new KoPoint( _last ) ); - - draw(); - } -} - -void -VPolylineTool::mouseButtonPress() -{ - KoPoint _last = view()->canvasWidget()->snapToGrid( last() ); - if( m_bezierPoints.count() != 0 ) - { - draw(); - m_bezierPoints.removeLast(); - m_bezierPoints.removeLast(); - m_bezierPoints.append( new KoPoint( _last ) ); - } - - m_lastVectorEnd = m_lastVectorStart = _last; - - m_bezierPoints.append( new KoPoint( _last ) ); - m_bezierPoints.append( new KoPoint( _last ) ); - drawBezierVector( m_lastVectorStart, m_lastVectorEnd ); - draw(); -} - -void -VPolylineTool::mouseButtonRelease() -{ - KoPoint _last = view()->canvasWidget()->snapToGrid( last() ); - if( m_bezierPoints.count() == 2 ) - { - drawBezierVector( m_lastVectorStart, m_lastVectorEnd ); - - m_bezierPoints.removeLast(); - m_bezierPoints.append( new KoPoint( _last ) ); - - VPainter* painter = view()->painterFactory()->editpainter(); - painter->save(); - painter->setZoomFactor( view()->zoom() ); - painter->setRasterOp( TQt::XorROP ); - VStroke stroke( TQt::yellow, 0L, 1.0 ); - painter->setPen( stroke ); - painter->setBrush( TQt::yellow ); - painter->newPath(); - painter->drawNode( m_lastVectorStart, 2 ); - painter->strokePath(); - painter->restore(); - } - else - { - drawBezierVector( m_lastVectorStart, m_lastVectorEnd ); - draw(); - m_bezierPoints.removeLast(); - KoPoint* p = new KoPoint( *m_bezierPoints.last() ); - m_bezierPoints.removeLast(); - KoPoint* b = new KoPoint( *m_bezierPoints.last() ); - m_bezierPoints.removeLast(); - - if( shiftPressed() ) - { - m_bezierPoints.removeLast(); - m_bezierPoints.append( new KoPoint( *m_bezierPoints.last() ) ); - m_bezierPoints.append( new KoPoint( *p ) ); - m_bezierPoints.append( new KoPoint( *p ) ); - m_bezierPoints.append( new KoPoint( *p ) ); - m_lastVectorStart = m_lastVectorEnd = *p; - } - else if( ctrlPressed() ) - { - m_bezierPoints.removeLast(); - m_lastVectorStart = *m_bezierPoints.last(); - m_bezierPoints.append( new KoPoint( _last ) ); - m_bezierPoints.append( new KoPoint( *b ) ); - m_bezierPoints.append( new KoPoint( *p ) ); - m_bezierPoints.append( new KoPoint( *p - ( *b - *p ) ) ); - m_lastVectorEnd = _last; - } - else - { - m_bezierPoints.append( new KoPoint( _last ) ); - m_bezierPoints.append( new KoPoint( *p ) ); - m_bezierPoints.append( new KoPoint( *p - ( _last - *p ) ) ); - m_lastVectorStart = *p; - m_lastVectorEnd = _last; - } - if( m_bezierPoints.count() > 2 && p->isNear( *m_bezierPoints.first(), 3 ) ) - { - m_bezierPoints.append( new KoPoint( _last ) ); - m_close = true; - createObject(); - return; - } - } - - m_bezierPoints.append( new KoPoint( _last ) ); - m_bezierPoints.append( new KoPoint( _last ) ); - - draw(); -} - -void -VPolylineTool::rightMouseButtonRelease() -{ - // end line without adding new points - m_bezierPoints.removeLast(); - m_bezierPoints.removeLast(); - - createObject(); -} - -void -VPolylineTool::mouseButtonDblClick() -{ - createObject(); -} - -void -VPolylineTool::mouseDrag() -{ - KoPoint _last = view()->canvasWidget()->snapToGrid( last() ); - - if( m_bezierPoints.count() == 2 ) - { - drawBezierVector( m_lastVectorStart, m_lastVectorEnd ); - - m_bezierPoints.removeLast(); - m_bezierPoints.append( new KoPoint( _last ) ); - m_lastVectorEnd = _last; - - drawBezierVector( m_lastVectorStart, m_lastVectorEnd ); - } - else - { - drawBezierVector( m_lastVectorStart, m_lastVectorEnd ); - draw(); - - m_bezierPoints.removeLast(); - KoPoint* p = new KoPoint( *m_bezierPoints.last() ); - m_bezierPoints.removeLast(); - KoPoint* b = new KoPoint( *m_bezierPoints.last() ); - m_bezierPoints.removeLast(); - - if( shiftPressed() ) - { - m_bezierPoints.removeLast(); - m_bezierPoints.append( new KoPoint( *m_bezierPoints.last() ) ); - m_bezierPoints.append( new KoPoint( *p ) ); - m_bezierPoints.append( new KoPoint( *p ) ); - m_bezierPoints.append( new KoPoint( *p ) ); - m_lastVectorStart = m_lastVectorEnd = *p; - } - else if( ctrlPressed() ) - { - m_bezierPoints.removeLast(); - m_lastVectorStart = *m_bezierPoints.last(); - m_bezierPoints.append( new KoPoint( _last ) ); - m_bezierPoints.append( new KoPoint( *b ) ); - m_bezierPoints.append( new KoPoint( *p ) ); - m_bezierPoints.append( new KoPoint( *p - ( *b - *p ) ) ); - m_lastVectorEnd = _last; - } - else - { - m_bezierPoints.append( new KoPoint( _last ) ); - m_bezierPoints.append( new KoPoint( *p ) ); - m_bezierPoints.append( new KoPoint( *p - ( _last - *p ) ) ); - m_lastVectorStart = *p; - m_lastVectorEnd = _last; - } - - draw(); - drawBezierVector( m_lastVectorStart, m_lastVectorEnd ); - } -} - -void -VPolylineTool::mouseDragRelease() -{ - mouseButtonRelease(); -} - -void -VPolylineTool::mouseDragShiftPressed() -{ -} - -void -VPolylineTool::mouseDragCtrlPressed() -{ - // Moves the mouse to the other bezier vector position. - if( m_bezierPoints.count() > 3 ) - { - KoPoint p; - p = *m_bezierPoints.at( m_bezierPoints.count() - 4) - *m_bezierPoints.at( m_bezierPoints.count() - 3 ); - - view()->setPos( p ); - } -} - -void -VPolylineTool::mouseDragShiftReleased() -{ -} - -void -VPolylineTool::mouseDragCtrlReleased() -{ - if( m_bezierPoints.count() > 3 ) - { - KoPoint p; - p = *m_bezierPoints.at( m_bezierPoints.count() - 3) - *m_bezierPoints.at( m_bezierPoints.count() - 4 ); - - view()->setPos( p ); - } -} - -void -VPolylineTool::cancel() -{ - draw(); - - m_bezierPoints.clear(); -} - -void -VPolylineTool::cancelStep() -{ - draw(); - - if ( m_bezierPoints.count() > 6 ) - { - m_bezierPoints.removeLast(); - m_bezierPoints.removeLast(); - m_bezierPoints.removeLast(); - KoPoint p1 = *m_bezierPoints.last(); - m_bezierPoints.removeLast(); - m_bezierPoints.removeLast(); - m_bezierPoints.append( new KoPoint( p1 ) ); - m_bezierPoints.append( new KoPoint( p1 ) ); - - view()->setPos( p1 ); - } - else - { - m_bezierPoints.clear(); - } - - draw(); -} - -void -VPolylineTool::accept() -{ - activate(); -} - -void -VPolylineTool::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 Tool" ), "14_polyline", shortcut, this, TQT_SLOT( activate() ), collection, name() ); - m_action->setToolTip( i18n( "Polyline" ) ); - m_action->setExclusiveGroup( "freehand" ); - //m_ownAction = true; - } -} - -void -VPolylineTool::commandExecuted() -{ - cancel(); -} - -#include "vpolylinetool.moc" diff --git a/karbon/tools/vpolylinetool.cpp b/karbon/tools/vpolylinetool.cpp new file mode 100644 index 00000000..38ac9d25 --- /dev/null +++ b/karbon/tools/vpolylinetool.cpp @@ -0,0 +1,504 @@ +/* This file is part of the KDE project + Copyright (C) 2001, 2002, 2003 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 +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "vpolylinetool.h" +#include +#include +#include + +VPolylineTool::VPolylineTool( KarbonView *view ) + : VTool( view, "tool_polyline" ) +{ + m_bezierPoints.setAutoDelete( true ); + registerTool( this ); + m_crossCursor = new TQCursor( VCursor::createCursor( VCursor::CrossHair ) ); +} + +VPolylineTool::~VPolylineTool() +{ + delete m_crossCursor; +} + +TQString +VPolylineTool::contextHelp() +{ + TQString s = i18n( "Polyline tool:
" ); + s += i18n( "- Click to add a node and drag to set its bezier vector.
" ); + s += i18n( "- Press Ctrl while dragging to edit the previous bezier vector.
" ); + s += i18n( "- Press Shift while dragging to change the curve in a straight line.
" ); + s += i18n( "- Press Backspace to cancel the last curve.
" ); + s += i18n( "- Press Esc to cancel the whole polyline.
" ); + s += i18n( "- Press Enter or double click to end the polyline.
" ); + + return s; +} + +void +VPolylineTool::activate() +{ + VTool::activate(); + view()->statusMessage()->setText( i18n( "Polyline Tool" ) ); + view()->setCursor( *m_crossCursor ); + + m_bezierPoints.clear(); + m_close = false; + + connect( view()->part()->commandHistory(), TQT_SIGNAL(commandExecuted()), this, TQT_SLOT(commandExecuted()) ); +} + +void +VPolylineTool::initializePath( VPath &path ) +{ + KoPoint* p1 = m_bezierPoints.first(); + KoPoint* p2; + KoPoint* p3; + KoPoint* p4; + + path.moveTo( *p1 ); + + while( + ( p2 = m_bezierPoints.next() ) && + ( p3 = m_bezierPoints.next() ) && + ( p4 = m_bezierPoints.next() ) ) + { + if ( *p1 == *p2 ) + if ( *p3 == *p4 ) + path.lineTo( *p4 ); + else + //polyline->curve1To( *p3, *p4 ); + path.curveTo( *p3, *p4, *p4 ); + else + if ( *p3 == *p4 ) + //polyline->curve2To( *p2, *p4 ); + path.curveTo( *p2, *p2, *p4 ); + else + path.curveTo( *p2, *p3, *p4 ); + p1 = p4; + } +} + +void +VPolylineTool::createObject() +{ + VPath* polyline = 0L; + if( m_bezierPoints.count() > 2 ) + { + polyline = new VPath( 0L ); + if( polyline ) + { + initializePath( *polyline ); + if( m_close ) + polyline->close(); + + VShapeCmd* cmd = new VShapeCmd( + &view()->part()->document(), + i18n( "Polyline" ), + polyline, + "14_polyline" ); + + view()->part()->addCommand( cmd, true ); + } + } + + m_bezierPoints.clear(); + m_close = false; +} + +void +VPolylineTool::deactivate() +{ + m_bezierPoints.removeLast(); + m_bezierPoints.removeLast(); + + createObject(); + + disconnect( view()->part()->commandHistory(), TQT_SIGNAL(commandExecuted()), this, TQT_SLOT(commandExecuted()) ); +} + +void +VPolylineTool::draw() +{ + VPainter* painter = view()->painterFactory()->editpainter(); + painter->setRasterOp( TQt::NotROP ); + + if( m_bezierPoints.count() > 2 ) + { + VPath polyline( 0L ); + initializePath( polyline ); + + polyline.setState( VObject::edit ); + polyline.draw( painter, &polyline.boundingBox() ); + } +} + +void +VPolylineTool::drawBezierVector( KoPoint& start, KoPoint& end ) +{ + VPainter* painter = view()->painterFactory()->editpainter(); + + painter->save(); + + float zoomFactor = view()->zoom(); + + painter->setRasterOp( TQt::NotROP ); + painter->newPath(); +/* VStroke stroke( TQt::blue, 0L, 1.0 ); + TQValueList array; + array << 2.0 << 3.0; + stroke.dashPattern().setArray( array );*/ + painter->setPen( TQt::DotLine /*stroke*/ ); + painter->setBrush( TQt::NoBrush ); + + painter->moveTo( start ); + painter->lineTo( end ); + painter->strokePath(); + painter->setRasterOp( TQt::XorROP ); + painter->newPath(); + painter->setPen( TQt::yellow ); + + float width = 2.0; + + painter->moveTo( KoPoint( + end.x() - width / zoomFactor, + end.y() - width / zoomFactor ) ); + painter->lineTo( KoPoint( + end.x() + width / zoomFactor, + end.y() - width / zoomFactor ) ); + painter->lineTo( KoPoint( + end.x() + width / zoomFactor, + end.y() + width / zoomFactor ) ); + painter->lineTo( KoPoint( + end.x() - width / zoomFactor, + end.y() + width / zoomFactor ) ); + painter->lineTo( KoPoint( + end.x() - width / zoomFactor, + end.y() - width / zoomFactor ) ); + + painter->strokePath(); + painter->restore(); +} + +void +VPolylineTool::mouseMove() +{ + if( m_bezierPoints.count() != 0 ) + { + KoPoint _last = view()->canvasWidget()->snapToGrid( last() ); + draw(); + + m_bezierPoints.removeLast(); + m_bezierPoints.removeLast(); + m_bezierPoints.append( new KoPoint( _last ) ); + m_bezierPoints.append( new KoPoint( _last ) ); + + draw(); + } +} + +void +VPolylineTool::mouseButtonPress() +{ + KoPoint _last = view()->canvasWidget()->snapToGrid( last() ); + if( m_bezierPoints.count() != 0 ) + { + draw(); + m_bezierPoints.removeLast(); + m_bezierPoints.removeLast(); + m_bezierPoints.append( new KoPoint( _last ) ); + } + + m_lastVectorEnd = m_lastVectorStart = _last; + + m_bezierPoints.append( new KoPoint( _last ) ); + m_bezierPoints.append( new KoPoint( _last ) ); + drawBezierVector( m_lastVectorStart, m_lastVectorEnd ); + draw(); +} + +void +VPolylineTool::mouseButtonRelease() +{ + KoPoint _last = view()->canvasWidget()->snapToGrid( last() ); + if( m_bezierPoints.count() == 2 ) + { + drawBezierVector( m_lastVectorStart, m_lastVectorEnd ); + + m_bezierPoints.removeLast(); + m_bezierPoints.append( new KoPoint( _last ) ); + + VPainter* painter = view()->painterFactory()->editpainter(); + painter->save(); + painter->setZoomFactor( view()->zoom() ); + painter->setRasterOp( TQt::XorROP ); + VStroke stroke( TQt::yellow, 0L, 1.0 ); + painter->setPen( stroke ); + painter->setBrush( TQt::yellow ); + painter->newPath(); + painter->drawNode( m_lastVectorStart, 2 ); + painter->strokePath(); + painter->restore(); + } + else + { + drawBezierVector( m_lastVectorStart, m_lastVectorEnd ); + draw(); + m_bezierPoints.removeLast(); + KoPoint* p = new KoPoint( *m_bezierPoints.last() ); + m_bezierPoints.removeLast(); + KoPoint* b = new KoPoint( *m_bezierPoints.last() ); + m_bezierPoints.removeLast(); + + if( shiftPressed() ) + { + m_bezierPoints.removeLast(); + m_bezierPoints.append( new KoPoint( *m_bezierPoints.last() ) ); + m_bezierPoints.append( new KoPoint( *p ) ); + m_bezierPoints.append( new KoPoint( *p ) ); + m_bezierPoints.append( new KoPoint( *p ) ); + m_lastVectorStart = m_lastVectorEnd = *p; + } + else if( ctrlPressed() ) + { + m_bezierPoints.removeLast(); + m_lastVectorStart = *m_bezierPoints.last(); + m_bezierPoints.append( new KoPoint( _last ) ); + m_bezierPoints.append( new KoPoint( *b ) ); + m_bezierPoints.append( new KoPoint( *p ) ); + m_bezierPoints.append( new KoPoint( *p - ( *b - *p ) ) ); + m_lastVectorEnd = _last; + } + else + { + m_bezierPoints.append( new KoPoint( _last ) ); + m_bezierPoints.append( new KoPoint( *p ) ); + m_bezierPoints.append( new KoPoint( *p - ( _last - *p ) ) ); + m_lastVectorStart = *p; + m_lastVectorEnd = _last; + } + if( m_bezierPoints.count() > 2 && p->isNear( *m_bezierPoints.first(), 3 ) ) + { + m_bezierPoints.append( new KoPoint( _last ) ); + m_close = true; + createObject(); + return; + } + } + + m_bezierPoints.append( new KoPoint( _last ) ); + m_bezierPoints.append( new KoPoint( _last ) ); + + draw(); +} + +void +VPolylineTool::rightMouseButtonRelease() +{ + // end line without adding new points + m_bezierPoints.removeLast(); + m_bezierPoints.removeLast(); + + createObject(); +} + +void +VPolylineTool::mouseButtonDblClick() +{ + createObject(); +} + +void +VPolylineTool::mouseDrag() +{ + KoPoint _last = view()->canvasWidget()->snapToGrid( last() ); + + if( m_bezierPoints.count() == 2 ) + { + drawBezierVector( m_lastVectorStart, m_lastVectorEnd ); + + m_bezierPoints.removeLast(); + m_bezierPoints.append( new KoPoint( _last ) ); + m_lastVectorEnd = _last; + + drawBezierVector( m_lastVectorStart, m_lastVectorEnd ); + } + else + { + drawBezierVector( m_lastVectorStart, m_lastVectorEnd ); + draw(); + + m_bezierPoints.removeLast(); + KoPoint* p = new KoPoint( *m_bezierPoints.last() ); + m_bezierPoints.removeLast(); + KoPoint* b = new KoPoint( *m_bezierPoints.last() ); + m_bezierPoints.removeLast(); + + if( shiftPressed() ) + { + m_bezierPoints.removeLast(); + m_bezierPoints.append( new KoPoint( *m_bezierPoints.last() ) ); + m_bezierPoints.append( new KoPoint( *p ) ); + m_bezierPoints.append( new KoPoint( *p ) ); + m_bezierPoints.append( new KoPoint( *p ) ); + m_lastVectorStart = m_lastVectorEnd = *p; + } + else if( ctrlPressed() ) + { + m_bezierPoints.removeLast(); + m_lastVectorStart = *m_bezierPoints.last(); + m_bezierPoints.append( new KoPoint( _last ) ); + m_bezierPoints.append( new KoPoint( *b ) ); + m_bezierPoints.append( new KoPoint( *p ) ); + m_bezierPoints.append( new KoPoint( *p - ( *b - *p ) ) ); + m_lastVectorEnd = _last; + } + else + { + m_bezierPoints.append( new KoPoint( _last ) ); + m_bezierPoints.append( new KoPoint( *p ) ); + m_bezierPoints.append( new KoPoint( *p - ( _last - *p ) ) ); + m_lastVectorStart = *p; + m_lastVectorEnd = _last; + } + + draw(); + drawBezierVector( m_lastVectorStart, m_lastVectorEnd ); + } +} + +void +VPolylineTool::mouseDragRelease() +{ + mouseButtonRelease(); +} + +void +VPolylineTool::mouseDragShiftPressed() +{ +} + +void +VPolylineTool::mouseDragCtrlPressed() +{ + // Moves the mouse to the other bezier vector position. + if( m_bezierPoints.count() > 3 ) + { + KoPoint p; + p = *m_bezierPoints.at( m_bezierPoints.count() - 4) - *m_bezierPoints.at( m_bezierPoints.count() - 3 ); + + view()->setPos( p ); + } +} + +void +VPolylineTool::mouseDragShiftReleased() +{ +} + +void +VPolylineTool::mouseDragCtrlReleased() +{ + if( m_bezierPoints.count() > 3 ) + { + KoPoint p; + p = *m_bezierPoints.at( m_bezierPoints.count() - 3) - *m_bezierPoints.at( m_bezierPoints.count() - 4 ); + + view()->setPos( p ); + } +} + +void +VPolylineTool::cancel() +{ + draw(); + + m_bezierPoints.clear(); +} + +void +VPolylineTool::cancelStep() +{ + draw(); + + if ( m_bezierPoints.count() > 6 ) + { + m_bezierPoints.removeLast(); + m_bezierPoints.removeLast(); + m_bezierPoints.removeLast(); + KoPoint p1 = *m_bezierPoints.last(); + m_bezierPoints.removeLast(); + m_bezierPoints.removeLast(); + m_bezierPoints.append( new KoPoint( p1 ) ); + m_bezierPoints.append( new KoPoint( p1 ) ); + + view()->setPos( p1 ); + } + else + { + m_bezierPoints.clear(); + } + + draw(); +} + +void +VPolylineTool::accept() +{ + activate(); +} + +void +VPolylineTool::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 Tool" ), "14_polyline", shortcut, this, TQT_SLOT( activate() ), collection, name() ); + m_action->setToolTip( i18n( "Polyline" ) ); + m_action->setExclusiveGroup( "freehand" ); + //m_ownAction = true; + } +} + +void +VPolylineTool::commandExecuted() +{ + cancel(); +} + +#include "vpolylinetool.moc" diff --git a/karbon/tools/vrectangletool.cc b/karbon/tools/vrectangletool.cc deleted file mode 100644 index 4572cc23..00000000 --- a/karbon/tools/vrectangletool.cc +++ /dev/null @@ -1,143 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2001, 2002, 2003 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 -#include - -#include -#include - -#include -#include -#include -#include "vrectangletool.h" -#include - - -VRectangleTool::VRectangleOptionsWidget::VRectangleOptionsWidget( KarbonPart *part, TQWidget* parent, const char* name ) - : KDialogBase( parent, name, true, i18n( "Insert Rectangle" ), Ok | Cancel ), m_part( part ) -{ - TQGroupBox *group = new TQGroupBox( 2, Qt::Horizontal, i18n( "Properties" ), this ); - // add width/height-input: - m_widthLabel = new TQLabel( i18n( "object width", "Width:" ), group ); - m_width = new KoUnitDoubleSpinBox( group, 0.0, 1000.0, 0.5, 100.0, KoUnit::U_MM ); - - m_heightLabel = new TQLabel( i18n( "Height:" ), group ); - m_height = new KoUnitDoubleSpinBox( group, 0.0, 1000.0, 0.5, 100.0, KoUnit::U_MM ); - - refreshUnit(); - - group->setInsideMargin( 4 ); - group->setInsideSpacing( 2 ); - - setMainWidget( group ); - //setFixedSize( baseSize() ); -} - -double -VRectangleTool::VRectangleOptionsWidget::width() const -{ - return m_width->value(); -} - -double -VRectangleTool::VRectangleOptionsWidget::height() const -{ - return m_height->value(); -} - -void -VRectangleTool::VRectangleOptionsWidget::setWidth( double value ) -{ - m_width->setValue( value ); -} - -void -VRectangleTool::VRectangleOptionsWidget::setHeight( double value ) -{ - m_height->setValue( value ); -} - -void -VRectangleTool::VRectangleOptionsWidget::refreshUnit() -{ - m_width->setUnit( m_part->unit() ); - m_height->setUnit( m_part->unit() ); -} - -VRectangleTool::VRectangleTool( KarbonView *view ) - : VShapeTool( view, "tool_rectangle" ) -{ - // Create config dialog: - m_optionWidget = new VRectangleOptionsWidget( view->part() ); - registerTool( this ); -} - -VRectangleTool::~VRectangleTool() -{ - delete( m_optionWidget ); -} - -void -VRectangleTool::refreshUnit() -{ - m_optionWidget->refreshUnit(); -} - -VPath * -VRectangleTool::shape( bool interactive ) const -{ - if( interactive ) - { - return - new VRectangle( - 0L, - m_p, - m_optionWidget->width(), - m_optionWidget->height() ); - } - else - return - new VRectangle( - 0L, - m_p, - m_d1, - m_d2 ); -} - -bool -VRectangleTool::showDialog() const -{ - return m_optionWidget->exec() == TQDialog::Accepted; -} - -void -VRectangleTool::setup( TDEActionCollection *collection ) -{ - m_action = static_cast(collection -> action( name() ) ); - - if( m_action == 0 ) - { - m_action = new TDERadioAction( i18n( "Rectangle Tool" ), "14_rectangle", TQt::Key_Plus+TQt::Key_F9, this, TQT_SLOT( activate() ), collection, name() ); - m_action->setToolTip( i18n( "Rectangle" ) ); - m_action->setExclusiveGroup( "shapes" ); - //m_ownAction = true; - } -} - diff --git a/karbon/tools/vrectangletool.cpp b/karbon/tools/vrectangletool.cpp new file mode 100644 index 00000000..4572cc23 --- /dev/null +++ b/karbon/tools/vrectangletool.cpp @@ -0,0 +1,143 @@ +/* This file is part of the KDE project + Copyright (C) 2001, 2002, 2003 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 +#include + +#include +#include + +#include +#include +#include +#include "vrectangletool.h" +#include + + +VRectangleTool::VRectangleOptionsWidget::VRectangleOptionsWidget( KarbonPart *part, TQWidget* parent, const char* name ) + : KDialogBase( parent, name, true, i18n( "Insert Rectangle" ), Ok | Cancel ), m_part( part ) +{ + TQGroupBox *group = new TQGroupBox( 2, Qt::Horizontal, i18n( "Properties" ), this ); + // add width/height-input: + m_widthLabel = new TQLabel( i18n( "object width", "Width:" ), group ); + m_width = new KoUnitDoubleSpinBox( group, 0.0, 1000.0, 0.5, 100.0, KoUnit::U_MM ); + + m_heightLabel = new TQLabel( i18n( "Height:" ), group ); + m_height = new KoUnitDoubleSpinBox( group, 0.0, 1000.0, 0.5, 100.0, KoUnit::U_MM ); + + refreshUnit(); + + group->setInsideMargin( 4 ); + group->setInsideSpacing( 2 ); + + setMainWidget( group ); + //setFixedSize( baseSize() ); +} + +double +VRectangleTool::VRectangleOptionsWidget::width() const +{ + return m_width->value(); +} + +double +VRectangleTool::VRectangleOptionsWidget::height() const +{ + return m_height->value(); +} + +void +VRectangleTool::VRectangleOptionsWidget::setWidth( double value ) +{ + m_width->setValue( value ); +} + +void +VRectangleTool::VRectangleOptionsWidget::setHeight( double value ) +{ + m_height->setValue( value ); +} + +void +VRectangleTool::VRectangleOptionsWidget::refreshUnit() +{ + m_width->setUnit( m_part->unit() ); + m_height->setUnit( m_part->unit() ); +} + +VRectangleTool::VRectangleTool( KarbonView *view ) + : VShapeTool( view, "tool_rectangle" ) +{ + // Create config dialog: + m_optionWidget = new VRectangleOptionsWidget( view->part() ); + registerTool( this ); +} + +VRectangleTool::~VRectangleTool() +{ + delete( m_optionWidget ); +} + +void +VRectangleTool::refreshUnit() +{ + m_optionWidget->refreshUnit(); +} + +VPath * +VRectangleTool::shape( bool interactive ) const +{ + if( interactive ) + { + return + new VRectangle( + 0L, + m_p, + m_optionWidget->width(), + m_optionWidget->height() ); + } + else + return + new VRectangle( + 0L, + m_p, + m_d1, + m_d2 ); +} + +bool +VRectangleTool::showDialog() const +{ + return m_optionWidget->exec() == TQDialog::Accepted; +} + +void +VRectangleTool::setup( TDEActionCollection *collection ) +{ + m_action = static_cast(collection -> action( name() ) ); + + if( m_action == 0 ) + { + m_action = new TDERadioAction( i18n( "Rectangle Tool" ), "14_rectangle", TQt::Key_Plus+TQt::Key_F9, this, TQT_SLOT( activate() ), collection, name() ); + m_action->setToolTip( i18n( "Rectangle" ) ); + m_action->setExclusiveGroup( "shapes" ); + //m_ownAction = true; + } +} + diff --git a/karbon/tools/vrotatetool.cc b/karbon/tools/vrotatetool.cc deleted file mode 100644 index 4230cac7..00000000 --- a/karbon/tools/vrotatetool.cc +++ /dev/null @@ -1,175 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2001, 2002, 2003 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 - -#include -#include - -#include -#include - -#include -#include -#include -#include "vrotatetool.h" -#include -#include -#include - -#include - -VRotateTool::VRotateTool( KarbonView *view ) - : VTool( view, "tool_rotate" ) -{ - m_objects.setAutoDelete( true ); - registerTool( this ); -} - -VRotateTool::~VRotateTool() -{ - m_objects.clear(); -} - -void -VRotateTool::activate() -{ - view()->setCursor( TQCursor( TQt::arrowCursor ) ); - view()->part()->document().selection()->setState( VObject::selected ); - view()->part()->document().selection()->showHandle( false ); - VTool::activate(); -} - -TQString -VRotateTool::statusText() -{ - return i18n( "Rotate" ); -} - -void -VRotateTool::draw() -{ - VPainter* painter = view()->painterFactory()->editpainter(); - //painter->setZoomFactor( view()->zoom() ); - painter->setRasterOp( TQt::NotROP ); - - VObjectListIterator itr = m_objects; - for( ; itr.current(); ++itr ) - { - itr.current()->draw( painter, &itr.current()->boundingBox() ); - } -} - -void -VRotateTool::mouseButtonPress() -{ - //view()->painterFactory()->painter()->end(); - - recalc(); - - // Draw new object: - draw(); -} - -void -VRotateTool::mouseDrag() -{ - // Erase old object: - draw(); - - recalc(); - - // Draw new object: - draw(); -} - -void -VRotateTool::mouseDragRelease() -{ - view()->part()->addCommand( - new VRotateCmd( - &view()->part()->document(), - m_center, - m_angle, altPressed() ), - true ); -} - -void -VRotateTool::cancel() -{ - // Erase old object: - if ( isDragging() ) - { - draw(); - view()->repaintAll( view()->part()->document().selection()->boundingBox() ); - } -} - -void -VRotateTool::recalc() -{ - // Get center: - m_center = view()->part()->document().selection()->boundingBox().center(); - - // Calculate angle between vector (last - center) and (first - center): - m_angle = VGlobal::one_pi_180 * ( - atan2( - last().y() - m_center.y(), - last().x() - m_center.x() ) - - - atan2( - first().y() - m_center.y(), - first().x() - m_center.x() ) ); - - VRotateCmd cmd( 0L, m_center, m_angle ); - - // Copy selected objects and transform: - m_objects.clear(); - VObject* copy; - - VObjectListIterator itr = view()->part()->document().selection()->objects(); - for ( ; itr.current() ; ++itr ) - { - if( itr.current()->state() != VObject::deleted ) - { - copy = itr.current()->clone(); - - cmd.visit( *copy ); - - copy->setState( VObject::edit ); - - m_objects.append( copy ); - } - } -} - -void -VRotateTool::setup( TDEActionCollection *collection ) -{ - m_action = static_cast(collection -> action( name() ) ); - - if( m_action == 0 ) - { - m_action = new TDERadioAction( i18n( "Rotate Tool" ), "14_rotate", TQt::SHIFT+TQt::Key_H, this, TQT_SLOT( activate() ), collection, name() ); - m_action->setToolTip( i18n( "Rotate" ) ); - m_action->setExclusiveGroup( "manipulation" ); - //m_ownAction = true; - } -} - diff --git a/karbon/tools/vrotatetool.cpp b/karbon/tools/vrotatetool.cpp new file mode 100644 index 00000000..4230cac7 --- /dev/null +++ b/karbon/tools/vrotatetool.cpp @@ -0,0 +1,175 @@ +/* This file is part of the KDE project + Copyright (C) 2001, 2002, 2003 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 + +#include +#include + +#include +#include + +#include +#include +#include +#include "vrotatetool.h" +#include +#include +#include + +#include + +VRotateTool::VRotateTool( KarbonView *view ) + : VTool( view, "tool_rotate" ) +{ + m_objects.setAutoDelete( true ); + registerTool( this ); +} + +VRotateTool::~VRotateTool() +{ + m_objects.clear(); +} + +void +VRotateTool::activate() +{ + view()->setCursor( TQCursor( TQt::arrowCursor ) ); + view()->part()->document().selection()->setState( VObject::selected ); + view()->part()->document().selection()->showHandle( false ); + VTool::activate(); +} + +TQString +VRotateTool::statusText() +{ + return i18n( "Rotate" ); +} + +void +VRotateTool::draw() +{ + VPainter* painter = view()->painterFactory()->editpainter(); + //painter->setZoomFactor( view()->zoom() ); + painter->setRasterOp( TQt::NotROP ); + + VObjectListIterator itr = m_objects; + for( ; itr.current(); ++itr ) + { + itr.current()->draw( painter, &itr.current()->boundingBox() ); + } +} + +void +VRotateTool::mouseButtonPress() +{ + //view()->painterFactory()->painter()->end(); + + recalc(); + + // Draw new object: + draw(); +} + +void +VRotateTool::mouseDrag() +{ + // Erase old object: + draw(); + + recalc(); + + // Draw new object: + draw(); +} + +void +VRotateTool::mouseDragRelease() +{ + view()->part()->addCommand( + new VRotateCmd( + &view()->part()->document(), + m_center, + m_angle, altPressed() ), + true ); +} + +void +VRotateTool::cancel() +{ + // Erase old object: + if ( isDragging() ) + { + draw(); + view()->repaintAll( view()->part()->document().selection()->boundingBox() ); + } +} + +void +VRotateTool::recalc() +{ + // Get center: + m_center = view()->part()->document().selection()->boundingBox().center(); + + // Calculate angle between vector (last - center) and (first - center): + m_angle = VGlobal::one_pi_180 * ( + atan2( + last().y() - m_center.y(), + last().x() - m_center.x() ) + - + atan2( + first().y() - m_center.y(), + first().x() - m_center.x() ) ); + + VRotateCmd cmd( 0L, m_center, m_angle ); + + // Copy selected objects and transform: + m_objects.clear(); + VObject* copy; + + VObjectListIterator itr = view()->part()->document().selection()->objects(); + for ( ; itr.current() ; ++itr ) + { + if( itr.current()->state() != VObject::deleted ) + { + copy = itr.current()->clone(); + + cmd.visit( *copy ); + + copy->setState( VObject::edit ); + + m_objects.append( copy ); + } + } +} + +void +VRotateTool::setup( TDEActionCollection *collection ) +{ + m_action = static_cast(collection -> action( name() ) ); + + if( m_action == 0 ) + { + m_action = new TDERadioAction( i18n( "Rotate Tool" ), "14_rotate", TQt::SHIFT+TQt::Key_H, this, TQT_SLOT( activate() ), collection, name() ); + m_action->setToolTip( i18n( "Rotate" ) ); + m_action->setExclusiveGroup( "manipulation" ); + //m_ownAction = true; + } +} + diff --git a/karbon/tools/vroundrecttool.cc b/karbon/tools/vroundrecttool.cc deleted file mode 100644 index 02f694c6..00000000 --- a/karbon/tools/vroundrecttool.cc +++ /dev/null @@ -1,179 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2001, 2002, 2003 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 -#include - -#include - -#include -#include -#include -#include "vroundrecttool.h" -#include "KoUnitWidgets.h" - -#include - -VRoundRectTool::VRoundRectOptionsWidget::VRoundRectOptionsWidget( KarbonPart *part, TQWidget* parent, const char* name ) - : KDialogBase( parent, name, true, i18n( "Insert Round Rect" ), Ok | Cancel ), m_part( part ) -{ - TQGroupBox *group = new TQGroupBox( 2, Qt::Horizontal, i18n( "Properties" ), this ); - new TQLabel( i18n( "object width", "Width:" ), group ); - - KoUnit::Unit unit = KoUnit::U_CM; - m_width = new KoUnitDoubleSpinBox( group, 0.0, KoUnit::fromUserValue( 1000.0, unit ), KoUnit::fromUserValue( 0.5, unit ), KoUnit::fromUserValue( 10.0, unit ), unit ); - - new TQLabel( i18n( "Height (%1):" ).arg(KoUnit::unitName( m_part->unit() )), group ); - m_height = new KoUnitDoubleSpinBox( group, 0.0, KoUnit::fromUserValue( 1000.0, unit ), KoUnit::fromUserValue( 0.5, unit ), KoUnit::fromUserValue( 10.0, unit ), unit ); - - new TQLabel( i18n( "Edge radius X:" ), group ); - m_roundx = new KoUnitDoubleSpinBox( group, 0.0, KoUnit::fromUserValue( 100.0, unit ), KoUnit::fromUserValue( 0.1, unit ), KoUnit::fromUserValue( 1.0, unit ), unit ); - - new TQLabel( i18n( "Edge radius Y:" ), group ); - m_roundy = new KoUnitDoubleSpinBox( group, 0.0, KoUnit::fromUserValue( 100.0, unit ), KoUnit::fromUserValue( 0.1, unit ), KoUnit::fromUserValue( 1.0, unit ), unit ); - - group->setInsideMargin( 4 ); - group->setInsideSpacing( 2 ); - - setMainWidget( group ); - setFixedSize( baseSize() ); -} - -double -VRoundRectTool::VRoundRectOptionsWidget::width() const -{ - return m_width->value(); -} - -double -VRoundRectTool::VRoundRectOptionsWidget::height() const -{ - return m_height->value(); -} - -double -VRoundRectTool::VRoundRectOptionsWidget::roundx() const -{ - return m_roundx->value(); -} - -double -VRoundRectTool::VRoundRectOptionsWidget::roundy() const -{ - return m_roundy->value(); -} - -void -VRoundRectTool::VRoundRectOptionsWidget::setWidth( double value ) -{ - m_width->changeValue( value ); -} - -void -VRoundRectTool::VRoundRectOptionsWidget::setHeight( double value ) -{ - m_height->changeValue( value ); -} - -void -VRoundRectTool::VRoundRectOptionsWidget::setRoundX( double value ) -{ - m_roundx->changeValue( value ); -} - -void -VRoundRectTool::VRoundRectOptionsWidget::setRoundY( double value ) -{ - m_roundy->changeValue( value ); -} - -void -VRoundRectTool::VRoundRectOptionsWidget::refreshUnit () -{ - m_width->setUnit( m_part->unit() ); - m_height->setUnit( m_part->unit() ); - m_roundx->setUnit( m_part->unit() ); - m_roundy->setUnit( m_part->unit() ); -} - -VRoundRectTool::VRoundRectTool( KarbonView *view ) - : VShapeTool( view, "tool_round_rectangle" ) -{ - // Create config dialog: - m_optionsWidget = new VRoundRectOptionsWidget( view->part() ); - registerTool( this ); -} - -VRoundRectTool::~VRoundRectTool() -{ - delete( m_optionsWidget ); -} - -void VRoundRectTool::refreshUnit() -{ - m_optionsWidget->refreshUnit(); -} - -VPath* -VRoundRectTool::shape( bool interactive ) const -{ - if( interactive ) - { - return - new VRectangle( - 0L, - m_p, - m_optionsWidget->width(), - m_optionsWidget->height(), - m_optionsWidget->roundx(), - m_optionsWidget->roundy() ); - } - else { - return - new VRectangle( - 0L, - m_p, - m_d1, - m_d2, - m_optionsWidget->roundx(), - m_optionsWidget->roundy() ); - } -} - -bool -VRoundRectTool::showDialog() const -{ - return m_optionsWidget->exec() == TQDialog::Accepted; -} - -void -VRoundRectTool::setup( TDEActionCollection *collection ) -{ - m_action = static_cast(collection -> action( name() ) ); - - if( m_action == 0 ) - { - m_action = new TDERadioAction( i18n( "Round Rectangle Tool" ), "14_roundrect", TQt::SHIFT+TQt::Key_H, this, TQT_SLOT( activate() ), collection, name() ); - m_action->setToolTip( i18n( "Round Rectangle" ) ); - m_action->setExclusiveGroup( "shapes" ); - //m_ownAction = true; - } -} - diff --git a/karbon/tools/vroundrecttool.cpp b/karbon/tools/vroundrecttool.cpp new file mode 100644 index 00000000..02f694c6 --- /dev/null +++ b/karbon/tools/vroundrecttool.cpp @@ -0,0 +1,179 @@ +/* This file is part of the KDE project + Copyright (C) 2001, 2002, 2003 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 +#include + +#include + +#include +#include +#include +#include "vroundrecttool.h" +#include "KoUnitWidgets.h" + +#include + +VRoundRectTool::VRoundRectOptionsWidget::VRoundRectOptionsWidget( KarbonPart *part, TQWidget* parent, const char* name ) + : KDialogBase( parent, name, true, i18n( "Insert Round Rect" ), Ok | Cancel ), m_part( part ) +{ + TQGroupBox *group = new TQGroupBox( 2, Qt::Horizontal, i18n( "Properties" ), this ); + new TQLabel( i18n( "object width", "Width:" ), group ); + + KoUnit::Unit unit = KoUnit::U_CM; + m_width = new KoUnitDoubleSpinBox( group, 0.0, KoUnit::fromUserValue( 1000.0, unit ), KoUnit::fromUserValue( 0.5, unit ), KoUnit::fromUserValue( 10.0, unit ), unit ); + + new TQLabel( i18n( "Height (%1):" ).arg(KoUnit::unitName( m_part->unit() )), group ); + m_height = new KoUnitDoubleSpinBox( group, 0.0, KoUnit::fromUserValue( 1000.0, unit ), KoUnit::fromUserValue( 0.5, unit ), KoUnit::fromUserValue( 10.0, unit ), unit ); + + new TQLabel( i18n( "Edge radius X:" ), group ); + m_roundx = new KoUnitDoubleSpinBox( group, 0.0, KoUnit::fromUserValue( 100.0, unit ), KoUnit::fromUserValue( 0.1, unit ), KoUnit::fromUserValue( 1.0, unit ), unit ); + + new TQLabel( i18n( "Edge radius Y:" ), group ); + m_roundy = new KoUnitDoubleSpinBox( group, 0.0, KoUnit::fromUserValue( 100.0, unit ), KoUnit::fromUserValue( 0.1, unit ), KoUnit::fromUserValue( 1.0, unit ), unit ); + + group->setInsideMargin( 4 ); + group->setInsideSpacing( 2 ); + + setMainWidget( group ); + setFixedSize( baseSize() ); +} + +double +VRoundRectTool::VRoundRectOptionsWidget::width() const +{ + return m_width->value(); +} + +double +VRoundRectTool::VRoundRectOptionsWidget::height() const +{ + return m_height->value(); +} + +double +VRoundRectTool::VRoundRectOptionsWidget::roundx() const +{ + return m_roundx->value(); +} + +double +VRoundRectTool::VRoundRectOptionsWidget::roundy() const +{ + return m_roundy->value(); +} + +void +VRoundRectTool::VRoundRectOptionsWidget::setWidth( double value ) +{ + m_width->changeValue( value ); +} + +void +VRoundRectTool::VRoundRectOptionsWidget::setHeight( double value ) +{ + m_height->changeValue( value ); +} + +void +VRoundRectTool::VRoundRectOptionsWidget::setRoundX( double value ) +{ + m_roundx->changeValue( value ); +} + +void +VRoundRectTool::VRoundRectOptionsWidget::setRoundY( double value ) +{ + m_roundy->changeValue( value ); +} + +void +VRoundRectTool::VRoundRectOptionsWidget::refreshUnit () +{ + m_width->setUnit( m_part->unit() ); + m_height->setUnit( m_part->unit() ); + m_roundx->setUnit( m_part->unit() ); + m_roundy->setUnit( m_part->unit() ); +} + +VRoundRectTool::VRoundRectTool( KarbonView *view ) + : VShapeTool( view, "tool_round_rectangle" ) +{ + // Create config dialog: + m_optionsWidget = new VRoundRectOptionsWidget( view->part() ); + registerTool( this ); +} + +VRoundRectTool::~VRoundRectTool() +{ + delete( m_optionsWidget ); +} + +void VRoundRectTool::refreshUnit() +{ + m_optionsWidget->refreshUnit(); +} + +VPath* +VRoundRectTool::shape( bool interactive ) const +{ + if( interactive ) + { + return + new VRectangle( + 0L, + m_p, + m_optionsWidget->width(), + m_optionsWidget->height(), + m_optionsWidget->roundx(), + m_optionsWidget->roundy() ); + } + else { + return + new VRectangle( + 0L, + m_p, + m_d1, + m_d2, + m_optionsWidget->roundx(), + m_optionsWidget->roundy() ); + } +} + +bool +VRoundRectTool::showDialog() const +{ + return m_optionsWidget->exec() == TQDialog::Accepted; +} + +void +VRoundRectTool::setup( TDEActionCollection *collection ) +{ + m_action = static_cast(collection -> action( name() ) ); + + if( m_action == 0 ) + { + m_action = new TDERadioAction( i18n( "Round Rectangle Tool" ), "14_roundrect", TQt::SHIFT+TQt::Key_H, this, TQT_SLOT( activate() ), collection, name() ); + m_action->setToolTip( i18n( "Round Rectangle" ) ); + m_action->setExclusiveGroup( "shapes" ); + //m_ownAction = true; + } +} + diff --git a/karbon/tools/vselectnodestool.cc b/karbon/tools/vselectnodestool.cc deleted file mode 100644 index 2a3c38bb..00000000 --- a/karbon/tools/vselectnodestool.cc +++ /dev/null @@ -1,443 +0,0 @@ -/* 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 - -#include -#include - -#include -#include -#include - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include "vselectnodestool.h" -#include -#include -#include - -#include - -VSelectNodesTool::VSelectNodesTool( KarbonView* view ) - : VTool( view, "tool_select_nodes" ), m_state( normal ), m_select( true ) -{ - registerTool( this ); -} - -VSelectNodesTool::~VSelectNodesTool() -{ -} - -void -VSelectNodesTool::activate() -{ - if( view() ) - { - view()->setCursor( VCursor::needleArrow() ); - view()->part()->document().selection()->showHandle( false ); - view()->part()->document().selection()->setSelectObjects( false ); - // deselect all nodes - view()->part()->document().selection()->selectNodes( false ); - view()->repaintAll( view()->part()->document().selection()->boundingBox() ); - } - VTool::activate(); -} - -TQString -VSelectNodesTool::statusText() -{ - if( m_state == normal ) - return i18n( "Editing Nodes" ); - else - return TQString( "" ); -} - -void -VSelectNodesTool::draw() -{ - VPainter *painter = view()->painterFactory()->editpainter(); - painter->setZoomFactor( view()->zoom() ); - painter->setRasterOp( TQt::NotROP ); - - if( m_state == dragging ) - { - painter->setPen( TQt::DotLine ); - painter->newPath(); - painter->moveTo( KoPoint( m_first.x(), m_first.y() ) ); - painter->lineTo( KoPoint( m_current.x(), m_first.y() ) ); - painter->lineTo( KoPoint( m_current.x(), m_current.y() ) ); - painter->lineTo( KoPoint( m_first.x(), m_current.y() ) ); - painter->lineTo( KoPoint( m_first.x(), m_first.y() ) ); - painter->strokePath(); - } - else - { - VDrawSelection op( m_objects, painter, true, VSelection::handleSize() ); - VObjectListIterator itr = m_objects; - for( ; itr.current(); ++itr ) - op.visit( *( itr.current() ) ); - } -} - -void -VSelectNodesTool::setCursor() const -{ - if( m_state >= moving ) - { - view()->setCursor( VCursor::needleMoveArrow() ); - return; - } - - KoRect selrect = calcSelRect( last() ); - - TQPtrList segments = view()->part()->document().selection()->getSegments( selrect ); - if( segments.count() > 0 ) - { - VSegment* seg = segments.at( 0 ); - for( int i = 0; i < seg->degree(); ++i ) - if( seg->pointIsSelected( i ) && selrect.contains( seg->point( i ) ) ) - { - view()->setCursor( VCursor::needleMoveArrow() ); - break; - } - } - else - view()->setCursor( VCursor::needleArrow() ); -} - -void -VSelectNodesTool::mouseButtonPress() -{ - m_first = m_current = first(); - - m_state = normal; - m_select = true; - - recalc(); - - view()->part()->document().selection()->setState( VObject::edit ); - view()->repaintAll( view()->part()->document().selection()->boundingBox() ); - view()->part()->document().selection()->setState( VObject::selected ); - - VSelection* selection = view()->part()->document().selection(); - - KoRect selrect = calcSelRect( m_current ); - - // get segments with control points inside selection rect - TQPtrList segments = selection->getSegments( selrect ); - if( segments.count() > 0 ) - { - VSegment *seg = segments.at( 0 ); - VSegment* prev = seg->prev(); - VSegment* next = seg->next(); - - // allow moving bezier points only if one of the bezier points is within the selection rect - // and no neighboring knot is selected - if( segments.count() == 1 && ! selrect.contains( seg->knot() ) && ! seg->knotIsSelected() - && ( prev && ! prev->knotIsSelected() ) ) - { - if( selrect.contains( seg->point( 1 ) ) ) - { - m_state = movingbezier1; - if( next ) - next->selectPoint( 0, false ); - } - else if( selrect.contains( seg->point( 0 ) ) ) - { - m_state = movingbezier2; - if( prev ) - prev->selectPoint( 1, false ); - } - } - else - { - for( VSegment *seg = segments.first(); seg; seg = segments.next() ) - { - for( int i = 0; i < seg->degree(); ++i ) - { - if( seg->pointIsSelected( i ) && selrect.contains( seg->point( i ) ) ) - { - m_state = moving; - break; - } - } - if( m_state == moving ) - break; - } - } - - double minDist = -1.0; - // use the nearest control point of all the segments as starting point - for( VSegment *seg = segments.first(); seg; seg = segments.next() ) - { - for( int i = 0; i < seg->degree(); ++i ) - { - if( selrect.contains( seg->point( i ) ) ) - { - KoPoint vDist = seg->point( i ) - m_current; - double dist = vDist.x()*vDist.x() + vDist.y()*vDist.y(); - if( minDist < 0.0 || dist < minDist ) - { - m_first = seg->point( i ); - minDist = dist; - } - } - } - } - recalc(); - } - else - m_state = dragging; - - draw(); -} - -void -VSelectNodesTool::rightMouseButtonPress() -{ - m_first = m_current = first(); - - m_state = normal; - m_select = false; - - recalc(); - - view()->part()->document().selection()->setState( VObject::edit ); - view()->repaintAll( view()->part()->document().selection()->boundingBox() ); - view()->part()->document().selection()->setState( VObject::selected ); - - draw(); -} - -bool -VSelectNodesTool::keyReleased( TQt::Key key ) -{ - VSelection* selection = view()->part()->document().selection(); - - switch( key ) - { - // increase/decrease the handle size - case TQt::Key_I: - { - uint handleSize = selection->handleSize(); - if( shiftPressed() ) - selection->setHandleSize( ++handleSize ); - else if( handleSize > 1 ) - selection->setHandleSize( --handleSize ); - } - break; - case TQt::Key_Delete: - if( selection->objects().count() > 0 ) - view()->part()->addCommand( new VDeleteNodeCmd( &view()->part()->document() ), true ); - break; - default: return false; - } - - if( view() ) - view()->repaintAll( selection->boundingBox() ); - - return true; -} - -void -VSelectNodesTool::mouseButtonRelease() -{ - // erase old object: - draw(); - - VSelection* selection = view()->part()->document().selection(); - - KoRect selrect = calcSelRect( last() ); - - if( ctrlPressed() ) - selection->append( selrect.normalize(), false, false ); - else - selection->append( selrect.normalize(), false, true ); - - view()->selectionChanged(); - view()->part()->repaintAllViews(); - m_state = normal; -} - -void -VSelectNodesTool::rightMouseButtonRelease() -{ - // erase old object: - draw(); - - VSelection* selection = view()->part()->document().selection(); - - KoRect selrect = calcSelRect( last() ); - - selection->take( selrect.normalize(), false, false ); - - view()->selectionChanged(); - view()->part()->repaintAllViews(); - m_state = normal; -} - -void -VSelectNodesTool::mouseDrag() -{ - draw(); - - recalc(); - - draw(); -} - -void -VSelectNodesTool::mouseDragRelease() -{ - if( m_state >= moving ) - { - view()->part()->document().selection()->setState( VObject::selected ); - VCommand *cmd; - TQPtrList segments; - KoPoint _last = view()->canvasWidget()->snapToGrid( last() ); - if( m_state == movingbezier1 || m_state == movingbezier2 ) - { - KoRect selrect = calcSelRect( m_first ); - segments = view()->part()->document().selection()->getSegments( selrect ); - cmd = new VTranslateBezierCmd( &view()->part()->document(), segments.at( 0 ), - tqRound( ( _last.x() - m_first.x() ) ), - tqRound( ( _last.y() - m_first.y() ) ), - m_state == movingbezier2 ); - } - else - { - cmd = new VTranslatePointCmd( - &view()->part()->document(), - tqRound( ( _last.x() - m_first.x() ) ), - tqRound( ( _last.y() - m_first.y() ) ) ); - } - view()->part()->addCommand( cmd, true ); - m_state = normal; - } - else - { - KoPoint fp = m_first; - KoPoint lp = last(); - - if ( (fabs(lp.x() - fp.x()) + fabs(lp.y()-fp.y())) < 3.0 ) - { - // AK - should take the middle point here - fp = last() - KoPoint(8.0, 8.0); - lp = last() + KoPoint(8.0, 8.0); - } - - // erase old object: - draw(); - - if( m_select ) - { - view()->part()->document().selection()->append(); // select all - view()->part()->document().selection()->append( - KoRect( fp.x(), fp.y(), lp.x() - fp.x(), lp.y() - fp.y() ).normalize(), - false, true ); - } - else - { - view()->part()->document().selection()->take( - KoRect( fp.x(), fp.y(), lp.x() - fp.x(), lp.y() - fp.y() ).normalize(), - false, false ); - } - view()->selectionChanged(); - view()->part()->repaintAllViews(); - m_state = normal; - } -} - -void -VSelectNodesTool::cancel() -{ - // Erase old object: - if ( isDragging() ) - { - draw(); - m_state = normal; - view()->repaintAll( view()->part()->document().selection()->boundingBox() ); - } -} - -void -VSelectNodesTool::recalc() -{ - if( m_state == dragging ) - { - m_current = last(); - } - else if( m_state == moving || m_state == movingbezier1 || m_state == movingbezier2 ) - { - KoPoint _last = view()->canvasWidget()->snapToGrid( last() ); - double distx = _last.x() - m_first.x(); - double disty = _last.y() - m_first.y(); - // move operation - TQWMatrix mat; - mat.translate( distx, disty ); - - // Copy selected objects and transform: - m_objects.clear(); - VObject* copy; - - VTransformNodes op( mat ); - - VObjectListIterator itr = view()->part()->document().selection()->objects(); - for ( ; itr.current() ; ++itr ) - { - if( itr.current()->state() != VObject::deleted ) - { - copy = itr.current()->clone(); - copy->setState( VObject::edit ); - op.visit( *copy ); - m_objects.append( copy ); - } - } - } -} - -void -VSelectNodesTool::setup( TDEActionCollection *collection ) -{ - m_action = static_cast(collection -> action( name() ) ); - - if( m_action == 0 ) - { - m_action = new TDERadioAction( i18n( "Select Nodes Tool" ), "14_selectnodes", TQt::SHIFT+TQt::Key_H, this, TQT_SLOT( activate() ), collection, name() ); - m_action->setToolTip( i18n( "Select Nodes" ) ); - m_action->setExclusiveGroup( "select" ); - //m_ownAction = true; - } -} - -KoRect -VSelectNodesTool::calcSelRect( const KoPoint &pos ) const -{ - double tolerance = view()->part()->document().selection()->handleSize() / view()->zoom(); - return KoRect( pos.x() - tolerance, pos.y() - tolerance, 2 * tolerance + 1.0, 2 * tolerance + 1.0 ); -} diff --git a/karbon/tools/vselectnodestool.cpp b/karbon/tools/vselectnodestool.cpp new file mode 100644 index 00000000..2a3c38bb --- /dev/null +++ b/karbon/tools/vselectnodestool.cpp @@ -0,0 +1,443 @@ +/* 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 + +#include +#include + +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include "vselectnodestool.h" +#include +#include +#include + +#include + +VSelectNodesTool::VSelectNodesTool( KarbonView* view ) + : VTool( view, "tool_select_nodes" ), m_state( normal ), m_select( true ) +{ + registerTool( this ); +} + +VSelectNodesTool::~VSelectNodesTool() +{ +} + +void +VSelectNodesTool::activate() +{ + if( view() ) + { + view()->setCursor( VCursor::needleArrow() ); + view()->part()->document().selection()->showHandle( false ); + view()->part()->document().selection()->setSelectObjects( false ); + // deselect all nodes + view()->part()->document().selection()->selectNodes( false ); + view()->repaintAll( view()->part()->document().selection()->boundingBox() ); + } + VTool::activate(); +} + +TQString +VSelectNodesTool::statusText() +{ + if( m_state == normal ) + return i18n( "Editing Nodes" ); + else + return TQString( "" ); +} + +void +VSelectNodesTool::draw() +{ + VPainter *painter = view()->painterFactory()->editpainter(); + painter->setZoomFactor( view()->zoom() ); + painter->setRasterOp( TQt::NotROP ); + + if( m_state == dragging ) + { + painter->setPen( TQt::DotLine ); + painter->newPath(); + painter->moveTo( KoPoint( m_first.x(), m_first.y() ) ); + painter->lineTo( KoPoint( m_current.x(), m_first.y() ) ); + painter->lineTo( KoPoint( m_current.x(), m_current.y() ) ); + painter->lineTo( KoPoint( m_first.x(), m_current.y() ) ); + painter->lineTo( KoPoint( m_first.x(), m_first.y() ) ); + painter->strokePath(); + } + else + { + VDrawSelection op( m_objects, painter, true, VSelection::handleSize() ); + VObjectListIterator itr = m_objects; + for( ; itr.current(); ++itr ) + op.visit( *( itr.current() ) ); + } +} + +void +VSelectNodesTool::setCursor() const +{ + if( m_state >= moving ) + { + view()->setCursor( VCursor::needleMoveArrow() ); + return; + } + + KoRect selrect = calcSelRect( last() ); + + TQPtrList segments = view()->part()->document().selection()->getSegments( selrect ); + if( segments.count() > 0 ) + { + VSegment* seg = segments.at( 0 ); + for( int i = 0; i < seg->degree(); ++i ) + if( seg->pointIsSelected( i ) && selrect.contains( seg->point( i ) ) ) + { + view()->setCursor( VCursor::needleMoveArrow() ); + break; + } + } + else + view()->setCursor( VCursor::needleArrow() ); +} + +void +VSelectNodesTool::mouseButtonPress() +{ + m_first = m_current = first(); + + m_state = normal; + m_select = true; + + recalc(); + + view()->part()->document().selection()->setState( VObject::edit ); + view()->repaintAll( view()->part()->document().selection()->boundingBox() ); + view()->part()->document().selection()->setState( VObject::selected ); + + VSelection* selection = view()->part()->document().selection(); + + KoRect selrect = calcSelRect( m_current ); + + // get segments with control points inside selection rect + TQPtrList segments = selection->getSegments( selrect ); + if( segments.count() > 0 ) + { + VSegment *seg = segments.at( 0 ); + VSegment* prev = seg->prev(); + VSegment* next = seg->next(); + + // allow moving bezier points only if one of the bezier points is within the selection rect + // and no neighboring knot is selected + if( segments.count() == 1 && ! selrect.contains( seg->knot() ) && ! seg->knotIsSelected() + && ( prev && ! prev->knotIsSelected() ) ) + { + if( selrect.contains( seg->point( 1 ) ) ) + { + m_state = movingbezier1; + if( next ) + next->selectPoint( 0, false ); + } + else if( selrect.contains( seg->point( 0 ) ) ) + { + m_state = movingbezier2; + if( prev ) + prev->selectPoint( 1, false ); + } + } + else + { + for( VSegment *seg = segments.first(); seg; seg = segments.next() ) + { + for( int i = 0; i < seg->degree(); ++i ) + { + if( seg->pointIsSelected( i ) && selrect.contains( seg->point( i ) ) ) + { + m_state = moving; + break; + } + } + if( m_state == moving ) + break; + } + } + + double minDist = -1.0; + // use the nearest control point of all the segments as starting point + for( VSegment *seg = segments.first(); seg; seg = segments.next() ) + { + for( int i = 0; i < seg->degree(); ++i ) + { + if( selrect.contains( seg->point( i ) ) ) + { + KoPoint vDist = seg->point( i ) - m_current; + double dist = vDist.x()*vDist.x() + vDist.y()*vDist.y(); + if( minDist < 0.0 || dist < minDist ) + { + m_first = seg->point( i ); + minDist = dist; + } + } + } + } + recalc(); + } + else + m_state = dragging; + + draw(); +} + +void +VSelectNodesTool::rightMouseButtonPress() +{ + m_first = m_current = first(); + + m_state = normal; + m_select = false; + + recalc(); + + view()->part()->document().selection()->setState( VObject::edit ); + view()->repaintAll( view()->part()->document().selection()->boundingBox() ); + view()->part()->document().selection()->setState( VObject::selected ); + + draw(); +} + +bool +VSelectNodesTool::keyReleased( TQt::Key key ) +{ + VSelection* selection = view()->part()->document().selection(); + + switch( key ) + { + // increase/decrease the handle size + case TQt::Key_I: + { + uint handleSize = selection->handleSize(); + if( shiftPressed() ) + selection->setHandleSize( ++handleSize ); + else if( handleSize > 1 ) + selection->setHandleSize( --handleSize ); + } + break; + case TQt::Key_Delete: + if( selection->objects().count() > 0 ) + view()->part()->addCommand( new VDeleteNodeCmd( &view()->part()->document() ), true ); + break; + default: return false; + } + + if( view() ) + view()->repaintAll( selection->boundingBox() ); + + return true; +} + +void +VSelectNodesTool::mouseButtonRelease() +{ + // erase old object: + draw(); + + VSelection* selection = view()->part()->document().selection(); + + KoRect selrect = calcSelRect( last() ); + + if( ctrlPressed() ) + selection->append( selrect.normalize(), false, false ); + else + selection->append( selrect.normalize(), false, true ); + + view()->selectionChanged(); + view()->part()->repaintAllViews(); + m_state = normal; +} + +void +VSelectNodesTool::rightMouseButtonRelease() +{ + // erase old object: + draw(); + + VSelection* selection = view()->part()->document().selection(); + + KoRect selrect = calcSelRect( last() ); + + selection->take( selrect.normalize(), false, false ); + + view()->selectionChanged(); + view()->part()->repaintAllViews(); + m_state = normal; +} + +void +VSelectNodesTool::mouseDrag() +{ + draw(); + + recalc(); + + draw(); +} + +void +VSelectNodesTool::mouseDragRelease() +{ + if( m_state >= moving ) + { + view()->part()->document().selection()->setState( VObject::selected ); + VCommand *cmd; + TQPtrList segments; + KoPoint _last = view()->canvasWidget()->snapToGrid( last() ); + if( m_state == movingbezier1 || m_state == movingbezier2 ) + { + KoRect selrect = calcSelRect( m_first ); + segments = view()->part()->document().selection()->getSegments( selrect ); + cmd = new VTranslateBezierCmd( &view()->part()->document(), segments.at( 0 ), + tqRound( ( _last.x() - m_first.x() ) ), + tqRound( ( _last.y() - m_first.y() ) ), + m_state == movingbezier2 ); + } + else + { + cmd = new VTranslatePointCmd( + &view()->part()->document(), + tqRound( ( _last.x() - m_first.x() ) ), + tqRound( ( _last.y() - m_first.y() ) ) ); + } + view()->part()->addCommand( cmd, true ); + m_state = normal; + } + else + { + KoPoint fp = m_first; + KoPoint lp = last(); + + if ( (fabs(lp.x() - fp.x()) + fabs(lp.y()-fp.y())) < 3.0 ) + { + // AK - should take the middle point here + fp = last() - KoPoint(8.0, 8.0); + lp = last() + KoPoint(8.0, 8.0); + } + + // erase old object: + draw(); + + if( m_select ) + { + view()->part()->document().selection()->append(); // select all + view()->part()->document().selection()->append( + KoRect( fp.x(), fp.y(), lp.x() - fp.x(), lp.y() - fp.y() ).normalize(), + false, true ); + } + else + { + view()->part()->document().selection()->take( + KoRect( fp.x(), fp.y(), lp.x() - fp.x(), lp.y() - fp.y() ).normalize(), + false, false ); + } + view()->selectionChanged(); + view()->part()->repaintAllViews(); + m_state = normal; + } +} + +void +VSelectNodesTool::cancel() +{ + // Erase old object: + if ( isDragging() ) + { + draw(); + m_state = normal; + view()->repaintAll( view()->part()->document().selection()->boundingBox() ); + } +} + +void +VSelectNodesTool::recalc() +{ + if( m_state == dragging ) + { + m_current = last(); + } + else if( m_state == moving || m_state == movingbezier1 || m_state == movingbezier2 ) + { + KoPoint _last = view()->canvasWidget()->snapToGrid( last() ); + double distx = _last.x() - m_first.x(); + double disty = _last.y() - m_first.y(); + // move operation + TQWMatrix mat; + mat.translate( distx, disty ); + + // Copy selected objects and transform: + m_objects.clear(); + VObject* copy; + + VTransformNodes op( mat ); + + VObjectListIterator itr = view()->part()->document().selection()->objects(); + for ( ; itr.current() ; ++itr ) + { + if( itr.current()->state() != VObject::deleted ) + { + copy = itr.current()->clone(); + copy->setState( VObject::edit ); + op.visit( *copy ); + m_objects.append( copy ); + } + } + } +} + +void +VSelectNodesTool::setup( TDEActionCollection *collection ) +{ + m_action = static_cast(collection -> action( name() ) ); + + if( m_action == 0 ) + { + m_action = new TDERadioAction( i18n( "Select Nodes Tool" ), "14_selectnodes", TQt::SHIFT+TQt::Key_H, this, TQT_SLOT( activate() ), collection, name() ); + m_action->setToolTip( i18n( "Select Nodes" ) ); + m_action->setExclusiveGroup( "select" ); + //m_ownAction = true; + } +} + +KoRect +VSelectNodesTool::calcSelRect( const KoPoint &pos ) const +{ + double tolerance = view()->part()->document().selection()->handleSize() / view()->zoom(); + return KoRect( pos.x() - tolerance, pos.y() - tolerance, 2 * tolerance + 1.0, 2 * tolerance + 1.0 ); +} diff --git a/karbon/tools/vselecttool.cc b/karbon/tools/vselecttool.cc deleted file mode 100644 index b2c28d66..00000000 --- a/karbon/tools/vselecttool.cc +++ /dev/null @@ -1,613 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2001, 2002, 2003 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 -#include - -#include -#include -#include -#include - -#include -#include -#include - -#include -#include -#include -#include -#include -#include "vselecttool.h" -#include -#include -#include -#include - -VSelectOptionsWidget::VSelectOptionsWidget( KarbonPart *part ) - : KDialogBase( 0L, "", true, i18n( "Selection" ), Ok | Cancel ), m_part( part ) -{ - TQButtonGroup *group = new TQButtonGroup( 1, Qt::Horizontal, i18n( "Selection Mode" ), this ); - - new TQRadioButton( i18n( "Select in current layer" ), group ); - new TQRadioButton( i18n( "Select in visible layers" ), group ); - new TQRadioButton( i18n( "Select in selected layers" ), group ); - - group->setRadioButtonExclusive( true ); - group->setButton( part->document().selectionMode() ); - - connect( group, TQT_SIGNAL( clicked( int ) ), this, TQT_SLOT( modeChange( int ) ) ); - - group->setInsideMargin( 4 ); - group->setInsideSpacing( 2 ); - - setMainWidget( group ); - setFixedSize( baseSize() ); -} // VSelectOptionsWidget::VSelectOptionsWidget - -void VSelectOptionsWidget::modeChange( int mode ) -{ - m_part->document().setSelectionMode( (VDocument::VSelectionMode)mode ); -} // VSelectOptionsWidget::modeChanged - -VSelectTool::VSelectTool( KarbonView *view ) - : VTool( view, "tool_select" ), m_state( normal ) -{ - m_lock = false; - m_add = true; - m_objects.setAutoDelete( true ); - m_optionsWidget = new VSelectOptionsWidget( view->part() ); - registerTool( this ); - connect( view, TQT_SIGNAL( selectionChange() ), this, TQT_SLOT( updateStatusBar() ) ); -} - -VSelectTool::~VSelectTool() -{ - delete m_optionsWidget; -} - -void -VSelectTool::activate() -{ - VTool::activate(); - view()->setCursor( TQCursor( TQt::arrowCursor ) ); - view()->part()->document().selection()->showHandle(); - view()->part()->document().selection()->setSelectObjects(); - view()->part()->document().selection()->setState( VObject::selected ); - view()->part()->document().selection()->selectNodes(); - view()->repaintAll( view()->part()->document().selection()->boundingBox() ); - updateStatusBar(); -} - -TQString -VSelectTool::statusText() -{ - return i18n( "Select" ); -} - -TQString VSelectTool::contextHelp() -{ - TQString s = i18n( "Selection tool:
" ); - s += i18n( "Select in current layer:
The selection is made in the layer selected in the layers docker.

" ); - s += i18n( "Select in visible layers:
The selection is made in the visible layers (eye in the layers docker).

" ); - s += i18n( "Select in selected layers:
The selection is made in the checked layers in the layers docker.

" ); - s += i18n( "Position using arrow keys
The selection can be positioned up, down, left and right using the corresponding arrow keys." ); - return s; -} // VSelectTool::contextHelp - -void -VSelectTool::draw() -{ - VPainter *painter = view()->painterFactory()->editpainter(); - //painter->setZoomFactor( view()->zoom() ); - painter->setRasterOp( TQt::NotROP ); - - KoRect rect = view()->part()->document().selection()->boundingBox(); - - if( m_state != normal ) - { - VObjectListIterator itr = m_objects; - for( ; itr.current(); ++itr ) - { - itr.current()->draw( painter, &itr.current()->boundingBox() ); - } - } - else if( m_state == normal ) - { - painter->setPen( TQt::DotLine ); - painter->newPath(); - painter->moveTo( KoPoint( first().x(), first().y() ) ); - painter->lineTo( KoPoint( m_current.x(), first().y() ) ); - painter->lineTo( KoPoint( m_current.x(), m_current.y() ) ); - painter->lineTo( KoPoint( first().x(), m_current.y() ) ); - painter->lineTo( KoPoint( first().x(), first().y() ) ); - painter->strokePath(); - - m_state = normal; - } -} - -void -VSelectTool::setCursor() const -{ - if( m_state != normal || !view() ) return; - switch( view()->part()->document().selection()->handleNode( last() ) ) - { - case node_lt: - case node_rb: - view()->setCursor( TQCursor( TQt::SizeFDiagCursor ) ); - break; - case node_rt: - case node_lb: - view()->setCursor( TQCursor( TQt::SizeBDiagCursor ) ); - break; - case node_lm: - case node_rm: - view()->setCursor( TQCursor( TQt::SizeHorCursor ) ); - break; - case node_mt: - case node_mb: - view()->setCursor( TQCursor( TQt::SizeVerCursor ) ); - break; - default: - view()->setCursor( TQCursor( TQt::arrowCursor ) ); - } -} - -void -VSelectTool::mouseButtonPress() -{ - // we are adding to the selection - m_add = true; - - m_current = first(); - - m_activeNode = view()->part()->document().selection()->handleNode( first() ); - KoRect rect = view()->part()->document().selection()->boundingBox(); - - if( m_activeNode != node_none ) - m_state = scaling; - else if( rect.contains( m_current ) && m_state == normal ) - m_state = moving; - - recalc(); - - // undraw selection bounding box - view()->part()->document().selection()->setState( VObject::edit ); - view()->repaintAll( rect ); - view()->part()->document().selection()->setState( VObject::selected ); - - draw(); -} - -void -VSelectTool::rightMouseButtonPress() -{ - // we are removing from the selection - m_add = false; - - m_current = first(); - - recalc(); - - // undraw selection bounding box - view()->part()->document().selection()->setState( VObject::edit ); - view()->repaintAll( view()->part()->document().selection()->boundingBox() ); - view()->part()->document().selection()->setState( VObject::selected ); - - draw(); -} - -void -VSelectTool::mouseDrag() -{ - draw(); - - recalc(); - - draw(); -} - -void -VSelectTool::rightMouseButtonRelease() -{ - m_state = normal; - m_add = true; - - if( ctrlPressed() ) - { - // unselect the topmost object under the mouse cursor - VObjectList newSelection; - VSelectObjects selector( newSelection, first() ); - if( selector.visit( view()->part()->document() ) ) - view()->part()->document().selection()->take( *newSelection.last() ); - - view()->part()->repaintAllViews( view()->part()->document().selection()->boundingBox() ); - view()->selectionChanged(); - - updateStatusBar(); - } - else if( view()->part()->document().selection()->objects().count() > 0 ) - { - view()->showSelectionPopupMenu( TQCursor::pos() ); - } -} - -void -VSelectTool::mouseButtonRelease() -{ - m_state = normal; - m_add = true; - - // selection of next underlying object - if( shiftPressed() ) - { - VObjectList newSelection; - VObjectList oldSelection = view()->part()->document().selection()->objects(); - - // clear selection if not in multi-slection-mode - if( ! ctrlPressed() ) - view()->part()->document().selection()->clear(); - - // get a list of all object under the mouse cursor - VSelectObjects selector( newSelection, first(), true, true ); - if( selector.visit( view()->part()->document() ) ) - { - // determine the last selected object of the object stack - VObject *lastMatched = 0L; - VObjectListIterator it( newSelection ); - for( ; it.current(); ++it ) - { - if( oldSelection.contains( it.current() ) ) - lastMatched = it.current(); - } - - // select the next underlying object or the first if: - // - none is selected - // - the stack's bottom object was the last selected object - if( lastMatched && lastMatched != newSelection.first() ) - view()->part()->document().selection()->append( newSelection.at( newSelection.find( lastMatched )-1 ) ); - else - view()->part()->document().selection()->append( newSelection.last() ); - } - } - else - { - // clear selection if not in multi-slection-mode - if( ! ctrlPressed() ) - view()->part()->document().selection()->clear(); - - // append the topmost object under the mouse cursor to the selection - VObjectList newSelection; - VSelectObjects selector( newSelection, first() ); - if( selector.visit( view()->part()->document() ) ) - view()->part()->document().selection()->append( newSelection.last() ); - } - - view()->part()->repaintAllViews( view()->part()->document().selection()->boundingBox() ); - view()->selectionChanged(); - - updateStatusBar(); -} - -void -VSelectTool::mouseDragRelease() -{ - if( m_state == normal ) - { - // Y mirroring - KoPoint fp = first(); - KoPoint lp = last(); - if( ! ctrlPressed() ) - view()->part()->document().selection()->clear(); - - KoRect selRect = KoRect( fp.x(), fp.y(), lp.x() - fp.x(), lp.y() - fp.y() ).normalize(); - if( m_add ) - view()->part()->document().selection()->append( selRect ); - else - view()->part()->document().selection()->take( selRect ); - view()->part()->repaintAllViews( selRect ); - } - else if( m_state == moving ) - { - m_state = normal; - recalc(); - if( m_lock ) - view()->part()->addCommand( - new VTranslateCmd( - &view()->part()->document(), - abs( int( m_distx ) ) >= abs( int( m_disty ) ) ? tqRound( m_distx ) : 0, - abs( int( m_distx ) ) <= abs( int( m_disty ) ) ? tqRound( m_disty ) : 0, altPressed() ), - true ); - else - view()->part()->addCommand( - new VTranslateCmd( &view()->part()->document(), tqRound( m_distx ), tqRound( m_disty ), altPressed() ), - true ); - } - else if( m_state == scaling ) - { - m_state = normal; - view()->part()->addCommand( - new VScaleCmd( &view()->part()->document(), m_sp, m_s1, m_s2, altPressed() ), - true ); - m_s1 = m_s2 = 1; - } - - view()->selectionChanged(); - m_lock = false; - updateStatusBar(); -} - -void -VSelectTool::arrowKeyReleased( TQt::Key key ) -{ - int dx = 0; - int dy = 0; - switch( key ) - { - case TQt::Key_Up: dy = 10; break; - case TQt::Key_Down: dy = -10; break; - case TQt::Key_Right: dx = 10; break; - case TQt::Key_Left: dx = -10; break; - default: return; - } - m_state = normal; - view()->part()->addCommand( - new VTranslateCmd( - &view()->part()->document(), - dx, dy ), - true ); - view()->selectionChanged(); - updateStatusBar(); -} - -bool -VSelectTool::keyReleased( TQt::Key key ) -{ - - VSelection* selection = view()->part()->document().selection(); - - switch( key ) - { - // increase/decrease the handle size - case TQt::Key_I: - { - uint handleSize = selection->handleSize(); - if( shiftPressed() ) - selection->setHandleSize( ++handleSize ); - else if( handleSize > 1 ) - selection->setHandleSize( --handleSize ); - } - break; - default: return false; - } - - if( view() ) - view()->repaintAll( selection->boundingBox() ); - - return true; -} - -void -VSelectTool::updateStatusBar() const -{ - if( ! view() ) - return; - - if( ! view()->part() ) - return; - - int objcount = view()->part()->document().selection()->objects().count(); - if( objcount > 0 ) - { - KoRect rect = view()->part()->document().selection()->boundingBox(); - - double x = KoUnit::toUserValue( rect.x(), view()->part()->unit() ); - double y = KoUnit::toUserValue( rect.y(), view()->part()->unit() ); - double r = KoUnit::toUserValue( rect.right(), view()->part()->unit() ); - double b = KoUnit::toUserValue( rect.bottom(), view()->part()->unit() ); - - // print bottom-left (%1,%2), top-right (%3,%4) corner of selection bounding box and document unit (%5) - TQString selectMessage = i18n( "[(left,bottom), (right,top)] (actual unit)", "Selection [(%1, %2), (%3, %4)] (%5)").arg( x, 0, 'f', 1 ).arg( y, 0, 'f', 1 ).arg( r, 0, 'f', 1 ).arg( b, 0, 'f', 1 ).arg( view()->part()->unitName() ); - - VSelectionDescription selectionDesc; - selectionDesc.visit( *view()->part()->document().selection() ); - selectMessage += TQString( "(%1)" ).arg( selectionDesc.description() ); - - view()->statusMessage()->setText( selectMessage ); - } - else - view()->statusMessage()->setText( i18n( "No selection" ) ); -} - -void -VSelectTool::mouseDragCtrlPressed() -{ - m_lock = true; -} - -void -VSelectTool::mouseDragCtrlReleased() -{ - m_lock = false; -} - -void -VSelectTool::mouseDragShiftPressed() -{ - draw(); - - recalc(); - - draw(); -} - -void -VSelectTool::mouseDragShiftReleased() -{ - draw(); - - recalc(); - - draw(); -} - -void -VSelectTool::cancel() -{ - // Erase old object: - if ( isDragging() ) - { - draw(); - m_state = normal; - view()->repaintAll( view()->part()->document().selection()->boundingBox() ); - } -} - -void -VSelectTool::recalc() -{ - if( m_state == normal ) - { - m_current = last(); - } - else - { - VTransformCmd* cmd; - KoPoint _first = view()->canvasWidget()->snapToGrid( first() ); - KoPoint _last = view()->canvasWidget()->snapToGrid( last() ); - KoRect rect = view()->part()->document().selection()->boundingBox(); - - if( m_state == moving ) - { - KoPoint p( rect.x() + last().x() - first().x(), rect.bottom() + last().y() - first().y() ); - p = view()->canvasWidget()->snapToGrid( p ); - m_distx = p.x() - rect.x(); - m_disty = p.y() - rect.bottom(); - if( m_lock ) - cmd = new VTranslateCmd( 0L, abs( int( m_distx ) ) >= abs( int( m_disty ) ) ? m_distx : 0, - abs( int( m_distx ) ) <= abs( int( m_disty ) ) ? m_disty : 0 ); - else - cmd = new VTranslateCmd( 0L, m_distx, m_disty ); - } - else - { - if( m_activeNode == node_lb ) - { - m_sp = KoPoint( rect.right(), rect.bottom() ); - m_s1 = ( rect.right() - _last.x() ) / double( rect.width() ); - m_s2 = ( rect.bottom() - _last.y() ) / double( rect.height() ); - } - else if( m_activeNode == node_mb ) - { - m_sp = KoPoint( ( ( rect.right() + rect.left() ) / 2 ), rect.bottom() ); - m_s1 = 1; - m_s2 = ( rect.bottom() - _last.y() ) / double( rect.height() ); - } - else if( m_activeNode == node_rb ) - { - m_sp = KoPoint( rect.x(), rect.bottom() ); - m_s1 = ( _last.x() - rect.x() ) / double( rect.width() ); - m_s2 = ( rect.bottom() - _last.y() ) / double( rect.height() ); - } - else if( m_activeNode == node_rm) - { - m_sp = KoPoint( rect.x(), ( rect.bottom() + rect.top() ) / 2 ); - m_s1 = ( _last.x() - rect.x() ) / double( rect.width() ); - m_s2 = 1; - } - else if( m_activeNode == node_rt ) - { - m_sp = KoPoint( rect.x(), rect.y() ); - m_s1 = ( _last.x() - rect.x() ) / double( rect.width() ); - m_s2 = ( _last.y() - rect.y() ) / double( rect.height() ); - } - else if( m_activeNode == node_mt ) - { - m_sp = KoPoint( ( ( rect.right() + rect.left() ) / 2 ), rect.y() ); - m_s1 = 1; - m_s2 = ( _last.y() - rect.y() ) / double( rect.height() ); - } - else if( m_activeNode == node_lt ) - { - m_sp = KoPoint( rect.right(), rect.y() ); - m_s1 = ( rect.right() - _last.x() ) / double( rect.width() ); - m_s2 = ( _last.y() - rect.y() ) / double( rect.height() ); - } - else if( m_activeNode == node_lm ) - { - m_sp = KoPoint( rect.right(), ( rect.bottom() + rect.top() ) / 2 ); - m_s1 = ( rect.right() - _last.x() ) / double( rect.width() ); - m_s2 = 1; - } - - if( shiftPressed() ) - m_s1 = m_s2 = kMax( m_s1, m_s2 ); - cmd = new VScaleCmd( 0L, m_sp, m_s1, m_s2 ); - } - - // Copy selected objects and transform: - m_objects.clear(); - VObject* copy; - - VObjectListIterator itr = view()->part()->document().selection()->objects(); - for( ; itr.current() ; ++itr ) - { - if( itr.current()->state() != VObject::deleted ) - { - copy = itr.current()->clone(); - copy->setState( VObject::edit ); - - cmd->visit( *copy ); - - m_objects.append( copy ); - } - } - - delete( cmd ); - } -} - -bool -VSelectTool::showDialog() const -{ - return m_optionsWidget->exec() == TQDialog::Accepted; -} - -void -VSelectTool::refreshUnit() -{ - updateStatusBar(); -} - -void -VSelectTool::setup( TDEActionCollection *collection ) -{ - m_action = static_cast(collection -> action( name() ) ); - - if( m_action == 0 ) - { - m_action = new TDERadioAction( i18n( "Select Tool" ), "14_select", TQt::SHIFT+TQt::Key_H, this, TQT_SLOT( activate() ), collection, name() ); - m_action->setToolTip( i18n( "Select" ) ); - m_action->setExclusiveGroup( "select" ); - //m_ownAction = true; - } -} - -#include "vselecttool.moc" diff --git a/karbon/tools/vselecttool.cpp b/karbon/tools/vselecttool.cpp new file mode 100644 index 00000000..b2c28d66 --- /dev/null +++ b/karbon/tools/vselecttool.cpp @@ -0,0 +1,613 @@ +/* This file is part of the KDE project + Copyright (C) 2001, 2002, 2003 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 +#include + +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include +#include "vselecttool.h" +#include +#include +#include +#include + +VSelectOptionsWidget::VSelectOptionsWidget( KarbonPart *part ) + : KDialogBase( 0L, "", true, i18n( "Selection" ), Ok | Cancel ), m_part( part ) +{ + TQButtonGroup *group = new TQButtonGroup( 1, Qt::Horizontal, i18n( "Selection Mode" ), this ); + + new TQRadioButton( i18n( "Select in current layer" ), group ); + new TQRadioButton( i18n( "Select in visible layers" ), group ); + new TQRadioButton( i18n( "Select in selected layers" ), group ); + + group->setRadioButtonExclusive( true ); + group->setButton( part->document().selectionMode() ); + + connect( group, TQT_SIGNAL( clicked( int ) ), this, TQT_SLOT( modeChange( int ) ) ); + + group->setInsideMargin( 4 ); + group->setInsideSpacing( 2 ); + + setMainWidget( group ); + setFixedSize( baseSize() ); +} // VSelectOptionsWidget::VSelectOptionsWidget + +void VSelectOptionsWidget::modeChange( int mode ) +{ + m_part->document().setSelectionMode( (VDocument::VSelectionMode)mode ); +} // VSelectOptionsWidget::modeChanged + +VSelectTool::VSelectTool( KarbonView *view ) + : VTool( view, "tool_select" ), m_state( normal ) +{ + m_lock = false; + m_add = true; + m_objects.setAutoDelete( true ); + m_optionsWidget = new VSelectOptionsWidget( view->part() ); + registerTool( this ); + connect( view, TQT_SIGNAL( selectionChange() ), this, TQT_SLOT( updateStatusBar() ) ); +} + +VSelectTool::~VSelectTool() +{ + delete m_optionsWidget; +} + +void +VSelectTool::activate() +{ + VTool::activate(); + view()->setCursor( TQCursor( TQt::arrowCursor ) ); + view()->part()->document().selection()->showHandle(); + view()->part()->document().selection()->setSelectObjects(); + view()->part()->document().selection()->setState( VObject::selected ); + view()->part()->document().selection()->selectNodes(); + view()->repaintAll( view()->part()->document().selection()->boundingBox() ); + updateStatusBar(); +} + +TQString +VSelectTool::statusText() +{ + return i18n( "Select" ); +} + +TQString VSelectTool::contextHelp() +{ + TQString s = i18n( "Selection tool:
" ); + s += i18n( "Select in current layer:
The selection is made in the layer selected in the layers docker.

" ); + s += i18n( "Select in visible layers:
The selection is made in the visible layers (eye in the layers docker).

" ); + s += i18n( "Select in selected layers:
The selection is made in the checked layers in the layers docker.

" ); + s += i18n( "Position using arrow keys
The selection can be positioned up, down, left and right using the corresponding arrow keys." ); + return s; +} // VSelectTool::contextHelp + +void +VSelectTool::draw() +{ + VPainter *painter = view()->painterFactory()->editpainter(); + //painter->setZoomFactor( view()->zoom() ); + painter->setRasterOp( TQt::NotROP ); + + KoRect rect = view()->part()->document().selection()->boundingBox(); + + if( m_state != normal ) + { + VObjectListIterator itr = m_objects; + for( ; itr.current(); ++itr ) + { + itr.current()->draw( painter, &itr.current()->boundingBox() ); + } + } + else if( m_state == normal ) + { + painter->setPen( TQt::DotLine ); + painter->newPath(); + painter->moveTo( KoPoint( first().x(), first().y() ) ); + painter->lineTo( KoPoint( m_current.x(), first().y() ) ); + painter->lineTo( KoPoint( m_current.x(), m_current.y() ) ); + painter->lineTo( KoPoint( first().x(), m_current.y() ) ); + painter->lineTo( KoPoint( first().x(), first().y() ) ); + painter->strokePath(); + + m_state = normal; + } +} + +void +VSelectTool::setCursor() const +{ + if( m_state != normal || !view() ) return; + switch( view()->part()->document().selection()->handleNode( last() ) ) + { + case node_lt: + case node_rb: + view()->setCursor( TQCursor( TQt::SizeFDiagCursor ) ); + break; + case node_rt: + case node_lb: + view()->setCursor( TQCursor( TQt::SizeBDiagCursor ) ); + break; + case node_lm: + case node_rm: + view()->setCursor( TQCursor( TQt::SizeHorCursor ) ); + break; + case node_mt: + case node_mb: + view()->setCursor( TQCursor( TQt::SizeVerCursor ) ); + break; + default: + view()->setCursor( TQCursor( TQt::arrowCursor ) ); + } +} + +void +VSelectTool::mouseButtonPress() +{ + // we are adding to the selection + m_add = true; + + m_current = first(); + + m_activeNode = view()->part()->document().selection()->handleNode( first() ); + KoRect rect = view()->part()->document().selection()->boundingBox(); + + if( m_activeNode != node_none ) + m_state = scaling; + else if( rect.contains( m_current ) && m_state == normal ) + m_state = moving; + + recalc(); + + // undraw selection bounding box + view()->part()->document().selection()->setState( VObject::edit ); + view()->repaintAll( rect ); + view()->part()->document().selection()->setState( VObject::selected ); + + draw(); +} + +void +VSelectTool::rightMouseButtonPress() +{ + // we are removing from the selection + m_add = false; + + m_current = first(); + + recalc(); + + // undraw selection bounding box + view()->part()->document().selection()->setState( VObject::edit ); + view()->repaintAll( view()->part()->document().selection()->boundingBox() ); + view()->part()->document().selection()->setState( VObject::selected ); + + draw(); +} + +void +VSelectTool::mouseDrag() +{ + draw(); + + recalc(); + + draw(); +} + +void +VSelectTool::rightMouseButtonRelease() +{ + m_state = normal; + m_add = true; + + if( ctrlPressed() ) + { + // unselect the topmost object under the mouse cursor + VObjectList newSelection; + VSelectObjects selector( newSelection, first() ); + if( selector.visit( view()->part()->document() ) ) + view()->part()->document().selection()->take( *newSelection.last() ); + + view()->part()->repaintAllViews( view()->part()->document().selection()->boundingBox() ); + view()->selectionChanged(); + + updateStatusBar(); + } + else if( view()->part()->document().selection()->objects().count() > 0 ) + { + view()->showSelectionPopupMenu( TQCursor::pos() ); + } +} + +void +VSelectTool::mouseButtonRelease() +{ + m_state = normal; + m_add = true; + + // selection of next underlying object + if( shiftPressed() ) + { + VObjectList newSelection; + VObjectList oldSelection = view()->part()->document().selection()->objects(); + + // clear selection if not in multi-slection-mode + if( ! ctrlPressed() ) + view()->part()->document().selection()->clear(); + + // get a list of all object under the mouse cursor + VSelectObjects selector( newSelection, first(), true, true ); + if( selector.visit( view()->part()->document() ) ) + { + // determine the last selected object of the object stack + VObject *lastMatched = 0L; + VObjectListIterator it( newSelection ); + for( ; it.current(); ++it ) + { + if( oldSelection.contains( it.current() ) ) + lastMatched = it.current(); + } + + // select the next underlying object or the first if: + // - none is selected + // - the stack's bottom object was the last selected object + if( lastMatched && lastMatched != newSelection.first() ) + view()->part()->document().selection()->append( newSelection.at( newSelection.find( lastMatched )-1 ) ); + else + view()->part()->document().selection()->append( newSelection.last() ); + } + } + else + { + // clear selection if not in multi-slection-mode + if( ! ctrlPressed() ) + view()->part()->document().selection()->clear(); + + // append the topmost object under the mouse cursor to the selection + VObjectList newSelection; + VSelectObjects selector( newSelection, first() ); + if( selector.visit( view()->part()->document() ) ) + view()->part()->document().selection()->append( newSelection.last() ); + } + + view()->part()->repaintAllViews( view()->part()->document().selection()->boundingBox() ); + view()->selectionChanged(); + + updateStatusBar(); +} + +void +VSelectTool::mouseDragRelease() +{ + if( m_state == normal ) + { + // Y mirroring + KoPoint fp = first(); + KoPoint lp = last(); + if( ! ctrlPressed() ) + view()->part()->document().selection()->clear(); + + KoRect selRect = KoRect( fp.x(), fp.y(), lp.x() - fp.x(), lp.y() - fp.y() ).normalize(); + if( m_add ) + view()->part()->document().selection()->append( selRect ); + else + view()->part()->document().selection()->take( selRect ); + view()->part()->repaintAllViews( selRect ); + } + else if( m_state == moving ) + { + m_state = normal; + recalc(); + if( m_lock ) + view()->part()->addCommand( + new VTranslateCmd( + &view()->part()->document(), + abs( int( m_distx ) ) >= abs( int( m_disty ) ) ? tqRound( m_distx ) : 0, + abs( int( m_distx ) ) <= abs( int( m_disty ) ) ? tqRound( m_disty ) : 0, altPressed() ), + true ); + else + view()->part()->addCommand( + new VTranslateCmd( &view()->part()->document(), tqRound( m_distx ), tqRound( m_disty ), altPressed() ), + true ); + } + else if( m_state == scaling ) + { + m_state = normal; + view()->part()->addCommand( + new VScaleCmd( &view()->part()->document(), m_sp, m_s1, m_s2, altPressed() ), + true ); + m_s1 = m_s2 = 1; + } + + view()->selectionChanged(); + m_lock = false; + updateStatusBar(); +} + +void +VSelectTool::arrowKeyReleased( TQt::Key key ) +{ + int dx = 0; + int dy = 0; + switch( key ) + { + case TQt::Key_Up: dy = 10; break; + case TQt::Key_Down: dy = -10; break; + case TQt::Key_Right: dx = 10; break; + case TQt::Key_Left: dx = -10; break; + default: return; + } + m_state = normal; + view()->part()->addCommand( + new VTranslateCmd( + &view()->part()->document(), + dx, dy ), + true ); + view()->selectionChanged(); + updateStatusBar(); +} + +bool +VSelectTool::keyReleased( TQt::Key key ) +{ + + VSelection* selection = view()->part()->document().selection(); + + switch( key ) + { + // increase/decrease the handle size + case TQt::Key_I: + { + uint handleSize = selection->handleSize(); + if( shiftPressed() ) + selection->setHandleSize( ++handleSize ); + else if( handleSize > 1 ) + selection->setHandleSize( --handleSize ); + } + break; + default: return false; + } + + if( view() ) + view()->repaintAll( selection->boundingBox() ); + + return true; +} + +void +VSelectTool::updateStatusBar() const +{ + if( ! view() ) + return; + + if( ! view()->part() ) + return; + + int objcount = view()->part()->document().selection()->objects().count(); + if( objcount > 0 ) + { + KoRect rect = view()->part()->document().selection()->boundingBox(); + + double x = KoUnit::toUserValue( rect.x(), view()->part()->unit() ); + double y = KoUnit::toUserValue( rect.y(), view()->part()->unit() ); + double r = KoUnit::toUserValue( rect.right(), view()->part()->unit() ); + double b = KoUnit::toUserValue( rect.bottom(), view()->part()->unit() ); + + // print bottom-left (%1,%2), top-right (%3,%4) corner of selection bounding box and document unit (%5) + TQString selectMessage = i18n( "[(left,bottom), (right,top)] (actual unit)", "Selection [(%1, %2), (%3, %4)] (%5)").arg( x, 0, 'f', 1 ).arg( y, 0, 'f', 1 ).arg( r, 0, 'f', 1 ).arg( b, 0, 'f', 1 ).arg( view()->part()->unitName() ); + + VSelectionDescription selectionDesc; + selectionDesc.visit( *view()->part()->document().selection() ); + selectMessage += TQString( "(%1)" ).arg( selectionDesc.description() ); + + view()->statusMessage()->setText( selectMessage ); + } + else + view()->statusMessage()->setText( i18n( "No selection" ) ); +} + +void +VSelectTool::mouseDragCtrlPressed() +{ + m_lock = true; +} + +void +VSelectTool::mouseDragCtrlReleased() +{ + m_lock = false; +} + +void +VSelectTool::mouseDragShiftPressed() +{ + draw(); + + recalc(); + + draw(); +} + +void +VSelectTool::mouseDragShiftReleased() +{ + draw(); + + recalc(); + + draw(); +} + +void +VSelectTool::cancel() +{ + // Erase old object: + if ( isDragging() ) + { + draw(); + m_state = normal; + view()->repaintAll( view()->part()->document().selection()->boundingBox() ); + } +} + +void +VSelectTool::recalc() +{ + if( m_state == normal ) + { + m_current = last(); + } + else + { + VTransformCmd* cmd; + KoPoint _first = view()->canvasWidget()->snapToGrid( first() ); + KoPoint _last = view()->canvasWidget()->snapToGrid( last() ); + KoRect rect = view()->part()->document().selection()->boundingBox(); + + if( m_state == moving ) + { + KoPoint p( rect.x() + last().x() - first().x(), rect.bottom() + last().y() - first().y() ); + p = view()->canvasWidget()->snapToGrid( p ); + m_distx = p.x() - rect.x(); + m_disty = p.y() - rect.bottom(); + if( m_lock ) + cmd = new VTranslateCmd( 0L, abs( int( m_distx ) ) >= abs( int( m_disty ) ) ? m_distx : 0, + abs( int( m_distx ) ) <= abs( int( m_disty ) ) ? m_disty : 0 ); + else + cmd = new VTranslateCmd( 0L, m_distx, m_disty ); + } + else + { + if( m_activeNode == node_lb ) + { + m_sp = KoPoint( rect.right(), rect.bottom() ); + m_s1 = ( rect.right() - _last.x() ) / double( rect.width() ); + m_s2 = ( rect.bottom() - _last.y() ) / double( rect.height() ); + } + else if( m_activeNode == node_mb ) + { + m_sp = KoPoint( ( ( rect.right() + rect.left() ) / 2 ), rect.bottom() ); + m_s1 = 1; + m_s2 = ( rect.bottom() - _last.y() ) / double( rect.height() ); + } + else if( m_activeNode == node_rb ) + { + m_sp = KoPoint( rect.x(), rect.bottom() ); + m_s1 = ( _last.x() - rect.x() ) / double( rect.width() ); + m_s2 = ( rect.bottom() - _last.y() ) / double( rect.height() ); + } + else if( m_activeNode == node_rm) + { + m_sp = KoPoint( rect.x(), ( rect.bottom() + rect.top() ) / 2 ); + m_s1 = ( _last.x() - rect.x() ) / double( rect.width() ); + m_s2 = 1; + } + else if( m_activeNode == node_rt ) + { + m_sp = KoPoint( rect.x(), rect.y() ); + m_s1 = ( _last.x() - rect.x() ) / double( rect.width() ); + m_s2 = ( _last.y() - rect.y() ) / double( rect.height() ); + } + else if( m_activeNode == node_mt ) + { + m_sp = KoPoint( ( ( rect.right() + rect.left() ) / 2 ), rect.y() ); + m_s1 = 1; + m_s2 = ( _last.y() - rect.y() ) / double( rect.height() ); + } + else if( m_activeNode == node_lt ) + { + m_sp = KoPoint( rect.right(), rect.y() ); + m_s1 = ( rect.right() - _last.x() ) / double( rect.width() ); + m_s2 = ( _last.y() - rect.y() ) / double( rect.height() ); + } + else if( m_activeNode == node_lm ) + { + m_sp = KoPoint( rect.right(), ( rect.bottom() + rect.top() ) / 2 ); + m_s1 = ( rect.right() - _last.x() ) / double( rect.width() ); + m_s2 = 1; + } + + if( shiftPressed() ) + m_s1 = m_s2 = kMax( m_s1, m_s2 ); + cmd = new VScaleCmd( 0L, m_sp, m_s1, m_s2 ); + } + + // Copy selected objects and transform: + m_objects.clear(); + VObject* copy; + + VObjectListIterator itr = view()->part()->document().selection()->objects(); + for( ; itr.current() ; ++itr ) + { + if( itr.current()->state() != VObject::deleted ) + { + copy = itr.current()->clone(); + copy->setState( VObject::edit ); + + cmd->visit( *copy ); + + m_objects.append( copy ); + } + } + + delete( cmd ); + } +} + +bool +VSelectTool::showDialog() const +{ + return m_optionsWidget->exec() == TQDialog::Accepted; +} + +void +VSelectTool::refreshUnit() +{ + updateStatusBar(); +} + +void +VSelectTool::setup( TDEActionCollection *collection ) +{ + m_action = static_cast(collection -> action( name() ) ); + + if( m_action == 0 ) + { + m_action = new TDERadioAction( i18n( "Select Tool" ), "14_select", TQt::SHIFT+TQt::Key_H, this, TQT_SLOT( activate() ), collection, name() ); + m_action->setToolTip( i18n( "Select" ) ); + m_action->setExclusiveGroup( "select" ); + //m_ownAction = true; + } +} + +#include "vselecttool.moc" diff --git a/karbon/tools/vshapetool.cc b/karbon/tools/vshapetool.cc deleted file mode 100644 index 9b59104d..00000000 --- a/karbon/tools/vshapetool.cc +++ /dev/null @@ -1,274 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2001, 2002, 2003 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 -#include -#include - -#include "karbon_part.h" -#include "karbon_view.h" -#include "vcanvas.h" -#include "vcomposite.h" -#include "vglobal.h" -#include "vpainter.h" -#include "vpainterfactory.h" -#include "vshapecmd.h" -#include "vshapetool.h" -#include "vselection.h" -#include "vcursor.h" - -VShapeTool::VShapeTool( KarbonView *view, const char *name, bool polar ) - : VTool( view, name ) -{ - m_cursor = new TQCursor( VCursor::createCursor( VCursor::CrossHair ) ); - - m_isPolar = polar; - m_isSquare = false; - m_isCentered = false; -} - -VShapeTool::~VShapeTool() -{ - delete m_cursor; -} - -TQString -VShapeTool::contextHelp() -{ - TQString s = i18n( "Shape tool
" ); - s += i18n( "Click and drag to place your own shape.
" ); - s += i18n( "Click to place a shape using the tool properties values.
" ); - return s; -} - -void -VShapeTool::activate() -{ - VTool::activate(); - view()->setCursor( *m_cursor ); - view()->part()->document().selection()->showHandle( true ); -} - -TQString -VShapeTool::statusText() -{ - return uiname(); -} - -void -VShapeTool::draw() -{ - VPainter* painter = view()->painterFactory()->editpainter(); - painter->setRasterOp( TQt::NotROP ); - - VPath* composite = shape(); - composite->setState( VPath::edit ); - composite->draw( painter, &composite->boundingBox() ); - delete( composite ); -} - -void -VShapeTool::mouseButtonPress() -{ - recalc(); - - // Draw new object: - draw(); -} - -void -VShapeTool::mouseButtonRelease() -{ - draw(); - - recalc(); - - if( showDialog() ) - { - VPath* composite = shape( true ); - - if( composite ) - { - VShapeCmd* cmd = new VShapeCmd( - &view()->part()->document(), - uiname(), composite, icon() ); - - view()->part()->addCommand( cmd, true ); - } - } - - m_isSquare = false; - m_isCentered = false; -} - -void -VShapeTool::mouseDrag() -{ - // Erase old object: - draw(); - - recalc(); - - // Draw new object: - draw(); -} - -void -VShapeTool::mouseDragRelease() -{ - //recalc(); - - VShapeCmd* cmd = new VShapeCmd( - &view()->part()->document(), - uiname(), shape(), icon() ); - - view()->part()->addCommand( cmd, true ); - - m_isSquare = false; - m_isCentered = false; -} - -void -VShapeTool::mouseDragShiftPressed() -{ - // Erase old object: - draw(); - - m_isSquare = true; - recalc(); - - // Draw new object: - draw(); -} - -void -VShapeTool::mouseDragCtrlPressed() -{ - // Erase old object: - draw(); - - m_isCentered = true; - recalc(); - - // Draw new object: - draw(); -} - -void -VShapeTool::mouseDragShiftReleased() -{ - // Erase old object: - draw(); - - m_isSquare = false; - recalc(); - - // Draw new object: - draw(); -} - -void -VShapeTool::mouseDragCtrlReleased() -{ - // Erase old object: - draw(); - - m_isCentered = false; - recalc(); - - // Draw new object: - draw(); -} - -void -VShapeTool::cancel() -{ - // Erase old object: - if ( isDragging() ) - { - draw(); - m_isSquare = false; - m_isCentered = false; - } -} - -void -VShapeTool::recalc() -{ - m_isSquare = shiftPressed(); - m_isCentered = ctrlPressed(); - - KoPoint _first = view()->canvasWidget()->snapToGrid( first() ); - KoPoint _last = view()->canvasWidget()->snapToGrid( last() ); - - // Calculate radius and angle: - if( m_isPolar ) - { - // Radius: - m_d1 = sqrt( - ( _last.x() - _first.x() ) * ( _last.x() - _first.x() ) + - ( _last.y() - _first.y() ) * ( _last.y() - _first.y() ) ); - - // Angle: - m_d2 = atan2( _last.y() - _first.y(), _last.x() - _first.x() ); - - // Define pi/2 as "0.0": - m_d2 -= VGlobal::pi_2; - - m_p = _first; - } - else - // Calculate width and height: - { - m_d1 = _last.x() - _first.x(); - m_d2 = _last.y() - _first.y(); - - const int m_sign1 = VGlobal::sign( m_d1 ); -// TODO: revert when we introduce y-mirroring: - const int m_sign2 = VGlobal::sign( -m_d2 ); - - // Make unsigned: - if( m_d1 < 0.0 ) - m_d1 = -m_d1; - - if( m_d2 < 0.0 ) - m_d2 = -m_d2; - - if ( m_isSquare ) - { - if ( m_d1 > m_d2 ) - m_d2 = m_d1; - else - m_d1 = m_d2; - } - - m_p.setX( - _first.x() - ( m_sign1 == -1 ? m_d1 : 0.0 ) ); -// TODO: revert when we introduce y-mirroring: - m_p.setY( - _first.y() + ( m_sign2 == -1 ? m_d2 : 0.0 ) ); - - if ( m_isCentered ) - { - m_p.setX( m_p.x() - m_sign1 * tqRound( m_d1 * 0.5 ) ); - m_p.setY( m_p.y() + m_sign2 * tqRound( m_d2 * 0.5 ) ); - } - } -} - diff --git a/karbon/tools/vshapetool.cpp b/karbon/tools/vshapetool.cpp new file mode 100644 index 00000000..9b59104d --- /dev/null +++ b/karbon/tools/vshapetool.cpp @@ -0,0 +1,274 @@ +/* This file is part of the KDE project + Copyright (C) 2001, 2002, 2003 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 +#include +#include + +#include "karbon_part.h" +#include "karbon_view.h" +#include "vcanvas.h" +#include "vcomposite.h" +#include "vglobal.h" +#include "vpainter.h" +#include "vpainterfactory.h" +#include "vshapecmd.h" +#include "vshapetool.h" +#include "vselection.h" +#include "vcursor.h" + +VShapeTool::VShapeTool( KarbonView *view, const char *name, bool polar ) + : VTool( view, name ) +{ + m_cursor = new TQCursor( VCursor::createCursor( VCursor::CrossHair ) ); + + m_isPolar = polar; + m_isSquare = false; + m_isCentered = false; +} + +VShapeTool::~VShapeTool() +{ + delete m_cursor; +} + +TQString +VShapeTool::contextHelp() +{ + TQString s = i18n( "Shape tool
" ); + s += i18n( "Click and drag to place your own shape.
" ); + s += i18n( "Click to place a shape using the tool properties values.
" ); + return s; +} + +void +VShapeTool::activate() +{ + VTool::activate(); + view()->setCursor( *m_cursor ); + view()->part()->document().selection()->showHandle( true ); +} + +TQString +VShapeTool::statusText() +{ + return uiname(); +} + +void +VShapeTool::draw() +{ + VPainter* painter = view()->painterFactory()->editpainter(); + painter->setRasterOp( TQt::NotROP ); + + VPath* composite = shape(); + composite->setState( VPath::edit ); + composite->draw( painter, &composite->boundingBox() ); + delete( composite ); +} + +void +VShapeTool::mouseButtonPress() +{ + recalc(); + + // Draw new object: + draw(); +} + +void +VShapeTool::mouseButtonRelease() +{ + draw(); + + recalc(); + + if( showDialog() ) + { + VPath* composite = shape( true ); + + if( composite ) + { + VShapeCmd* cmd = new VShapeCmd( + &view()->part()->document(), + uiname(), composite, icon() ); + + view()->part()->addCommand( cmd, true ); + } + } + + m_isSquare = false; + m_isCentered = false; +} + +void +VShapeTool::mouseDrag() +{ + // Erase old object: + draw(); + + recalc(); + + // Draw new object: + draw(); +} + +void +VShapeTool::mouseDragRelease() +{ + //recalc(); + + VShapeCmd* cmd = new VShapeCmd( + &view()->part()->document(), + uiname(), shape(), icon() ); + + view()->part()->addCommand( cmd, true ); + + m_isSquare = false; + m_isCentered = false; +} + +void +VShapeTool::mouseDragShiftPressed() +{ + // Erase old object: + draw(); + + m_isSquare = true; + recalc(); + + // Draw new object: + draw(); +} + +void +VShapeTool::mouseDragCtrlPressed() +{ + // Erase old object: + draw(); + + m_isCentered = true; + recalc(); + + // Draw new object: + draw(); +} + +void +VShapeTool::mouseDragShiftReleased() +{ + // Erase old object: + draw(); + + m_isSquare = false; + recalc(); + + // Draw new object: + draw(); +} + +void +VShapeTool::mouseDragCtrlReleased() +{ + // Erase old object: + draw(); + + m_isCentered = false; + recalc(); + + // Draw new object: + draw(); +} + +void +VShapeTool::cancel() +{ + // Erase old object: + if ( isDragging() ) + { + draw(); + m_isSquare = false; + m_isCentered = false; + } +} + +void +VShapeTool::recalc() +{ + m_isSquare = shiftPressed(); + m_isCentered = ctrlPressed(); + + KoPoint _first = view()->canvasWidget()->snapToGrid( first() ); + KoPoint _last = view()->canvasWidget()->snapToGrid( last() ); + + // Calculate radius and angle: + if( m_isPolar ) + { + // Radius: + m_d1 = sqrt( + ( _last.x() - _first.x() ) * ( _last.x() - _first.x() ) + + ( _last.y() - _first.y() ) * ( _last.y() - _first.y() ) ); + + // Angle: + m_d2 = atan2( _last.y() - _first.y(), _last.x() - _first.x() ); + + // Define pi/2 as "0.0": + m_d2 -= VGlobal::pi_2; + + m_p = _first; + } + else + // Calculate width and height: + { + m_d1 = _last.x() - _first.x(); + m_d2 = _last.y() - _first.y(); + + const int m_sign1 = VGlobal::sign( m_d1 ); +// TODO: revert when we introduce y-mirroring: + const int m_sign2 = VGlobal::sign( -m_d2 ); + + // Make unsigned: + if( m_d1 < 0.0 ) + m_d1 = -m_d1; + + if( m_d2 < 0.0 ) + m_d2 = -m_d2; + + if ( m_isSquare ) + { + if ( m_d1 > m_d2 ) + m_d2 = m_d1; + else + m_d1 = m_d2; + } + + m_p.setX( + _first.x() - ( m_sign1 == -1 ? m_d1 : 0.0 ) ); +// TODO: revert when we introduce y-mirroring: + m_p.setY( + _first.y() + ( m_sign2 == -1 ? m_d2 : 0.0 ) ); + + if ( m_isCentered ) + { + m_p.setX( m_p.x() - m_sign1 * tqRound( m_d1 * 0.5 ) ); + m_p.setY( m_p.y() + m_sign2 * tqRound( m_d2 * 0.5 ) ); + } + } +} + diff --git a/karbon/tools/vsheartool.cc b/karbon/tools/vsheartool.cc deleted file mode 100644 index 4bc80810..00000000 --- a/karbon/tools/vsheartool.cc +++ /dev/null @@ -1,219 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2001, 2002, 2003 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 - -#include -#include - -#include -#include - -#include -#include -#include -#include -#include -#include "vsheartool.h" -#include - -VShearTool::VShearTool( KarbonView *view ) : VTool( view, "sheartool" ) -{ - setName( "tool_shear" ); - m_objects.setAutoDelete( true ); - registerTool( this ); -} - -VShearTool::~VShearTool() -{ -} - -void -VShearTool::activate() -{ - view()->setCursor( TQCursor( TQt::arrowCursor ) ); - view()->part()->document().selection()->showHandle( true ); - view()->part()->document().selection()->setState( VObject::selected ); - VTool::activate(); -} - -TQString -VShearTool::statusText() -{ - return i18n( "Shear" ); -} - -void -VShearTool::draw() -{ - VPainter* painter = view()->painterFactory()->editpainter(); - painter->setRasterOp( TQt::NotROP ); - - VObjectListIterator itr = m_objects; - for( ; itr.current(); ++itr ) - itr.current()->draw( painter, &itr.current()->boundingBox() ); -} - -void -VShearTool::setCursor() const -{ - if( isDragging() ) return; - switch( view()->part()->document().selection()->handleNode( last() ) ) - { - case node_lt: - case node_rb: - view()->setCursor( TQCursor( TQt::SizeFDiagCursor ) ); - break; - case node_rt: - case node_lb: - view()->setCursor( TQCursor( TQt::SizeBDiagCursor ) ); - break; - case node_lm: - case node_rm: - view()->setCursor( TQCursor( TQt::SizeHorCursor ) ); - break; - case node_mt: - case node_mb: - view()->setCursor( TQCursor( TQt::SizeVerCursor ) ); - break; - default: - view()->setCursor( TQCursor( TQt::arrowCursor ) ); - } -} - -void -VShearTool::mouseButtonPress() -{ - view()->painterFactory()->painter()->end(); - m_activeNode = view()->part()->document().selection()->handleNode( first() ); - recalc(); - - // Draw new object: - draw(); -} - -void -VShearTool::mouseDrag( ) -{ - // Erase old object: - draw(); - - recalc(); - - // Draw new object: - draw(); -} - - -void -VShearTool::mouseDragRelease() -{ - view()->part()->addCommand( - new VShearCmd( &view()->part()->document(), m_center, m_s1, m_s2, altPressed() ), - true ); -} - -void -VShearTool::cancel() -{ - // Erase old object: - if ( isDragging() ) - { - draw(); - view()->repaintAll( view()->part()->document().selection()->boundingBox() ); - } -} - -void -VShearTool::recalc() -{ - KoRect rect = view()->part()->document().selection()->boundingBox(); - - if( m_activeNode == node_lt ) - { - } - else if( m_activeNode == node_mt ) - { - m_s1 = 0; - m_s2 = ( last().y() - first().y() ) / double( ( rect.height() / 2 ) ); - } - else if( m_activeNode == node_rt ) - { - } - else if( m_activeNode == node_rm) - { - m_s1 = ( last().x() - first().x() ) / double( ( rect.width() / 2 ) ); - m_s2 = 0; - } - else if( m_activeNode == node_rb ) - { - } - else if( m_activeNode == node_mb ) - { - m_s1 = 0; - m_s2 = ( last().y() - first().y() ) / double( ( rect.height() / 2 ) ); - } - else if( m_activeNode == node_lb ) - { - } - else if( m_activeNode == node_lm ) - { - m_s1 = ( last().x() - first().x() ) / double( ( rect.width() / 2 ) ); - m_s2 = 0; - } - - // Get center: - m_center = view()->part()->document().selection()->boundingBox().center(); - - VShearCmd cmd( 0L, m_center, m_s1, m_s2 ); - - // Copy selected objects and transform: - m_objects.clear(); - VObject* copy; - - VObjectListIterator itr = view()->part()->document().selection()->objects(); - for ( ; itr.current() ; ++itr ) - { - if( itr.current()->state() != VObject::deleted ) - { - copy = itr.current()->clone(); - - cmd.visit( *copy ); - - copy->setState( VObject::edit ); - - m_objects.append( copy ); - } - } -} - -void -VShearTool::setup( TDEActionCollection *collection ) -{ - m_action = static_cast(collection -> action( name() ) ); - - if( m_action == 0 ) - { - m_action = new TDERadioAction( i18n( "Shear Tool" ), "14_shear", TQt::SHIFT+TQt::Key_H, this, TQT_SLOT( activate() ), collection, name() ); - m_action->setToolTip( i18n( "Shear" ) ); - m_action->setExclusiveGroup( "manipulation" ); - //m_ownAction = true; - } -} - diff --git a/karbon/tools/vsheartool.cpp b/karbon/tools/vsheartool.cpp new file mode 100644 index 00000000..4bc80810 --- /dev/null +++ b/karbon/tools/vsheartool.cpp @@ -0,0 +1,219 @@ +/* This file is part of the KDE project + Copyright (C) 2001, 2002, 2003 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 + +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include "vsheartool.h" +#include + +VShearTool::VShearTool( KarbonView *view ) : VTool( view, "sheartool" ) +{ + setName( "tool_shear" ); + m_objects.setAutoDelete( true ); + registerTool( this ); +} + +VShearTool::~VShearTool() +{ +} + +void +VShearTool::activate() +{ + view()->setCursor( TQCursor( TQt::arrowCursor ) ); + view()->part()->document().selection()->showHandle( true ); + view()->part()->document().selection()->setState( VObject::selected ); + VTool::activate(); +} + +TQString +VShearTool::statusText() +{ + return i18n( "Shear" ); +} + +void +VShearTool::draw() +{ + VPainter* painter = view()->painterFactory()->editpainter(); + painter->setRasterOp( TQt::NotROP ); + + VObjectListIterator itr = m_objects; + for( ; itr.current(); ++itr ) + itr.current()->draw( painter, &itr.current()->boundingBox() ); +} + +void +VShearTool::setCursor() const +{ + if( isDragging() ) return; + switch( view()->part()->document().selection()->handleNode( last() ) ) + { + case node_lt: + case node_rb: + view()->setCursor( TQCursor( TQt::SizeFDiagCursor ) ); + break; + case node_rt: + case node_lb: + view()->setCursor( TQCursor( TQt::SizeBDiagCursor ) ); + break; + case node_lm: + case node_rm: + view()->setCursor( TQCursor( TQt::SizeHorCursor ) ); + break; + case node_mt: + case node_mb: + view()->setCursor( TQCursor( TQt::SizeVerCursor ) ); + break; + default: + view()->setCursor( TQCursor( TQt::arrowCursor ) ); + } +} + +void +VShearTool::mouseButtonPress() +{ + view()->painterFactory()->painter()->end(); + m_activeNode = view()->part()->document().selection()->handleNode( first() ); + recalc(); + + // Draw new object: + draw(); +} + +void +VShearTool::mouseDrag( ) +{ + // Erase old object: + draw(); + + recalc(); + + // Draw new object: + draw(); +} + + +void +VShearTool::mouseDragRelease() +{ + view()->part()->addCommand( + new VShearCmd( &view()->part()->document(), m_center, m_s1, m_s2, altPressed() ), + true ); +} + +void +VShearTool::cancel() +{ + // Erase old object: + if ( isDragging() ) + { + draw(); + view()->repaintAll( view()->part()->document().selection()->boundingBox() ); + } +} + +void +VShearTool::recalc() +{ + KoRect rect = view()->part()->document().selection()->boundingBox(); + + if( m_activeNode == node_lt ) + { + } + else if( m_activeNode == node_mt ) + { + m_s1 = 0; + m_s2 = ( last().y() - first().y() ) / double( ( rect.height() / 2 ) ); + } + else if( m_activeNode == node_rt ) + { + } + else if( m_activeNode == node_rm) + { + m_s1 = ( last().x() - first().x() ) / double( ( rect.width() / 2 ) ); + m_s2 = 0; + } + else if( m_activeNode == node_rb ) + { + } + else if( m_activeNode == node_mb ) + { + m_s1 = 0; + m_s2 = ( last().y() - first().y() ) / double( ( rect.height() / 2 ) ); + } + else if( m_activeNode == node_lb ) + { + } + else if( m_activeNode == node_lm ) + { + m_s1 = ( last().x() - first().x() ) / double( ( rect.width() / 2 ) ); + m_s2 = 0; + } + + // Get center: + m_center = view()->part()->document().selection()->boundingBox().center(); + + VShearCmd cmd( 0L, m_center, m_s1, m_s2 ); + + // Copy selected objects and transform: + m_objects.clear(); + VObject* copy; + + VObjectListIterator itr = view()->part()->document().selection()->objects(); + for ( ; itr.current() ; ++itr ) + { + if( itr.current()->state() != VObject::deleted ) + { + copy = itr.current()->clone(); + + cmd.visit( *copy ); + + copy->setState( VObject::edit ); + + m_objects.append( copy ); + } + } +} + +void +VShearTool::setup( TDEActionCollection *collection ) +{ + m_action = static_cast(collection -> action( name() ) ); + + if( m_action == 0 ) + { + m_action = new TDERadioAction( i18n( "Shear Tool" ), "14_shear", TQt::SHIFT+TQt::Key_H, this, TQT_SLOT( activate() ), collection, name() ); + m_action->setToolTip( i18n( "Shear" ) ); + m_action->setExclusiveGroup( "manipulation" ); + //m_ownAction = true; + } +} + diff --git a/karbon/tools/vsinustool.cc b/karbon/tools/vsinustool.cc deleted file mode 100644 index 12dbe128..00000000 --- a/karbon/tools/vsinustool.cc +++ /dev/null @@ -1,162 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2001, 2002, 2003 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 -#include -#include - -#include -#include - -#include -#include -#include -#include "vsinustool.h" -#include "KoUnitWidgets.h" - - -VSinusTool::VSinusOptionsWidget::VSinusOptionsWidget( KarbonPart *part, TQWidget* parent, const char* name ) - : KDialogBase( parent, name, true, i18n( "Insert Sinus" ), Ok | Cancel ), m_part( part ) -{ - TQGroupBox *group = new TQGroupBox( 2, Qt::Horizontal, i18n( "Properties" ), this ); - - // add width/height-input: - m_widthLabel = new TQLabel( i18n( "object width", "Width:" ), group ); - m_width = new KoUnitDoubleSpinBox( group, 0.0, 1000.0, 0.5, 100.0, KoUnit::U_MM ); - m_heightLabel = new TQLabel( i18n( "Height:" ), group ); - m_height = new KoUnitDoubleSpinBox( group, 0.0, 1000.0, 0.5, 100.0, KoUnit::U_MM ); - - refreshUnit(); - - new TQLabel( i18n( "Periods:" ), group ); - m_periods = new KIntSpinBox( group ); - m_periods->setMinValue( 1 ); - - group->setInsideMargin( 4 ); - group->setInsideSpacing( 2 ); - - setMainWidget( group ); - setFixedSize( baseSize() ); -} - -double -VSinusTool::VSinusOptionsWidget::width() const -{ - return m_width->value(); -} - -double -VSinusTool::VSinusOptionsWidget::height() const -{ - return m_height->value(); -} - -uint -VSinusTool::VSinusOptionsWidget::periods() const -{ - return m_periods->value(); -} - -void -VSinusTool::VSinusOptionsWidget::setWidth( double value ) -{ - m_width->changeValue( value ); -} - -void -VSinusTool::VSinusOptionsWidget::setHeight( double value ) -{ - m_height->changeValue( value ); -} - -void -VSinusTool::VSinusOptionsWidget::setPeriods( uint value ) -{ - m_periods->setValue( value ); -} - -void -VSinusTool::VSinusOptionsWidget::refreshUnit () -{ - m_width->setUnit( m_part->unit() ); - m_height->setUnit( m_part->unit() ); -} - -VSinusTool::VSinusTool( KarbonView *view ) - : VShapeTool( view, "tool_sinus" ) -{ - // create config widget: - m_optionsWidget = new VSinusOptionsWidget( view->part() ); - m_optionsWidget->setPeriods( 1 ); - registerTool( this ); -} - -VSinusTool::~VSinusTool() -{ - delete( m_optionsWidget ); -} - -void -VSinusTool::refreshUnit() -{ - m_optionsWidget->refreshUnit(); -} - -VPath* -VSinusTool::shape( bool interactive ) const -{ - if( interactive ) - return - new VSinus( - 0L, - m_p, - m_optionsWidget->width(), - m_optionsWidget->height(), - m_optionsWidget->periods() ); - else - return - new VSinus( - 0L, - m_p, - m_d1, - m_d2, - m_optionsWidget->periods() ); -} - -bool -VSinusTool::showDialog() const -{ - return m_optionsWidget->exec() == TQDialog::Accepted; -} - -void -VSinusTool::setup( TDEActionCollection *collection ) -{ - m_action = static_cast(collection -> action( name() ) ); - - if( m_action == 0 ) - { - m_action = new TDERadioAction( i18n( "Sinus Tool" ), "14_sinus", TQt::SHIFT+TQt::Key_S, this, TQT_SLOT( activate() ), collection, name() ); - m_action->setToolTip( i18n( "Sinus" ) ); - m_action->setExclusiveGroup( "shapes" ); - //m_ownAction = true; - } -} - diff --git a/karbon/tools/vsinustool.cpp b/karbon/tools/vsinustool.cpp new file mode 100644 index 00000000..12dbe128 --- /dev/null +++ b/karbon/tools/vsinustool.cpp @@ -0,0 +1,162 @@ +/* This file is part of the KDE project + Copyright (C) 2001, 2002, 2003 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 +#include +#include + +#include +#include + +#include +#include +#include +#include "vsinustool.h" +#include "KoUnitWidgets.h" + + +VSinusTool::VSinusOptionsWidget::VSinusOptionsWidget( KarbonPart *part, TQWidget* parent, const char* name ) + : KDialogBase( parent, name, true, i18n( "Insert Sinus" ), Ok | Cancel ), m_part( part ) +{ + TQGroupBox *group = new TQGroupBox( 2, Qt::Horizontal, i18n( "Properties" ), this ); + + // add width/height-input: + m_widthLabel = new TQLabel( i18n( "object width", "Width:" ), group ); + m_width = new KoUnitDoubleSpinBox( group, 0.0, 1000.0, 0.5, 100.0, KoUnit::U_MM ); + m_heightLabel = new TQLabel( i18n( "Height:" ), group ); + m_height = new KoUnitDoubleSpinBox( group, 0.0, 1000.0, 0.5, 100.0, KoUnit::U_MM ); + + refreshUnit(); + + new TQLabel( i18n( "Periods:" ), group ); + m_periods = new KIntSpinBox( group ); + m_periods->setMinValue( 1 ); + + group->setInsideMargin( 4 ); + group->setInsideSpacing( 2 ); + + setMainWidget( group ); + setFixedSize( baseSize() ); +} + +double +VSinusTool::VSinusOptionsWidget::width() const +{ + return m_width->value(); +} + +double +VSinusTool::VSinusOptionsWidget::height() const +{ + return m_height->value(); +} + +uint +VSinusTool::VSinusOptionsWidget::periods() const +{ + return m_periods->value(); +} + +void +VSinusTool::VSinusOptionsWidget::setWidth( double value ) +{ + m_width->changeValue( value ); +} + +void +VSinusTool::VSinusOptionsWidget::setHeight( double value ) +{ + m_height->changeValue( value ); +} + +void +VSinusTool::VSinusOptionsWidget::setPeriods( uint value ) +{ + m_periods->setValue( value ); +} + +void +VSinusTool::VSinusOptionsWidget::refreshUnit () +{ + m_width->setUnit( m_part->unit() ); + m_height->setUnit( m_part->unit() ); +} + +VSinusTool::VSinusTool( KarbonView *view ) + : VShapeTool( view, "tool_sinus" ) +{ + // create config widget: + m_optionsWidget = new VSinusOptionsWidget( view->part() ); + m_optionsWidget->setPeriods( 1 ); + registerTool( this ); +} + +VSinusTool::~VSinusTool() +{ + delete( m_optionsWidget ); +} + +void +VSinusTool::refreshUnit() +{ + m_optionsWidget->refreshUnit(); +} + +VPath* +VSinusTool::shape( bool interactive ) const +{ + if( interactive ) + return + new VSinus( + 0L, + m_p, + m_optionsWidget->width(), + m_optionsWidget->height(), + m_optionsWidget->periods() ); + else + return + new VSinus( + 0L, + m_p, + m_d1, + m_d2, + m_optionsWidget->periods() ); +} + +bool +VSinusTool::showDialog() const +{ + return m_optionsWidget->exec() == TQDialog::Accepted; +} + +void +VSinusTool::setup( TDEActionCollection *collection ) +{ + m_action = static_cast(collection -> action( name() ) ); + + if( m_action == 0 ) + { + m_action = new TDERadioAction( i18n( "Sinus Tool" ), "14_sinus", TQt::SHIFT+TQt::Key_S, this, TQT_SLOT( activate() ), collection, name() ); + m_action->setToolTip( i18n( "Sinus" ) ); + m_action->setExclusiveGroup( "shapes" ); + //m_ownAction = true; + } +} + diff --git a/karbon/tools/vspiraltool.cc b/karbon/tools/vspiraltool.cc deleted file mode 100644 index c414be41..00000000 --- a/karbon/tools/vspiraltool.cc +++ /dev/null @@ -1,213 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2001, 2002, 2003 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 -#include - -#include -#include -#include - -#include -#include -#include -#include "vspiraltool.h" -#include "KoUnitWidgets.h" - - -VSpiralTool::VSpiralOptionsWidget::VSpiralOptionsWidget( KarbonPart *part, TQWidget* parent, const char* name ) - : KDialogBase( parent, name, true, i18n( "Insert Spiral" ), Ok | Cancel ), m_part( part ) -{ - TQGroupBox *group = new TQGroupBox( 2, Qt::Horizontal, i18n( "Properties" ), this ); - - new TQLabel( i18n( "Type:" ), group ); - m_type = new KComboBox( false, group ); - m_type->insertItem( i18n( "Round" ), 0 ); - m_type->insertItem( i18n( "Rectangular" ), 1 ); - - new TQLabel( i18n( "Radius:" ), group ); - m_radius = new KoUnitDoubleSpinBox( group, 0.0, 1000.0, 0.5, 50.0, KoUnit::U_MM ); - refreshUnit(); - new TQLabel( i18n( "Segments:" ), group ); - m_segments = new KIntSpinBox( group ); - m_segments->setMinValue( 1 ); - new TQLabel( i18n( "Fade:" ), group ); - m_fade = new KDoubleNumInput( group ); - m_fade->setRange( 0.0, 1.0, 0.05 ); - - new TQLabel( i18n( "Qt::Orientation:" ), group ); - m_clockwise = new KComboBox( false, group ); - m_clockwise->insertItem( i18n( "Clockwise" ), 0 ); - m_clockwise->insertItem( i18n( "Counter Clockwise" ), 1 ); - - group->setInsideMargin( 4 ); - group->setInsideSpacing( 2 ); - - setMainWidget( group ); - //setFixedSize( baseSize() ); -} - -double -VSpiralTool::VSpiralOptionsWidget::radius() const -{ - return m_radius->value(); -} - -uint -VSpiralTool::VSpiralOptionsWidget::segments() const -{ - return m_segments->value(); -} - -double -VSpiralTool::VSpiralOptionsWidget::fade() const -{ - return m_fade->value(); -} - -bool -VSpiralTool::VSpiralOptionsWidget::clockwise() const -{ - return m_clockwise->currentItem() == 0; -} - -uint -VSpiralTool::VSpiralOptionsWidget::type() const -{ - return m_type->currentItem(); -} - -void -VSpiralTool::VSpiralOptionsWidget::setRadius( double value ) -{ - m_radius->changeValue( value ); -} - -void -VSpiralTool::VSpiralOptionsWidget::setSegments( uint value ) -{ - m_segments->setValue( value ); -} - -void -VSpiralTool::VSpiralOptionsWidget::setFade( double value ) -{ - m_fade->setValue( value ); -} - -void -VSpiralTool::VSpiralOptionsWidget::setClockwise( bool value ) -{ - m_clockwise->setCurrentItem( value ? 0 : 1 ); -} - -void -VSpiralTool::VSpiralOptionsWidget::refreshUnit() -{ - m_radius->setUnit( m_part->unit() ); -} - -VSpiralTool::VSpiralTool( KarbonView *view ) - : VShapeTool( view, "tool_spiral", true ) -{ - // create config dialog: - m_optionsWidget = new VSpiralOptionsWidget( view->part() ); - m_optionsWidget->setSegments( 8 ); - m_optionsWidget->setFade( 0.8 ); - m_optionsWidget->setClockwise( true ); - registerTool( this ); -} - -void -VSpiralTool::arrowKeyReleased( TQt::Key key ) -{ - int change = 0; - if( key == TQt::Key_Up ) - change = 1; - else if( key == TQt::Key_Down ) - change = -1; - - if( change != 0 ) - { - draw(); - - m_optionsWidget->setSegments( m_optionsWidget->segments() + change ); - - draw(); - } -} - -VSpiralTool::~VSpiralTool() -{ - delete( m_optionsWidget ); -} - -void -VSpiralTool::refreshUnit() -{ - m_optionsWidget->refreshUnit(); -} - -VPath* -VSpiralTool::shape( bool interactive ) const -{ - if( interactive ) - { - return - new VSpiral( - 0L, - m_p, - m_optionsWidget->radius(), - m_optionsWidget->segments(), - m_optionsWidget->fade(), - m_optionsWidget->clockwise(), - m_d2, (VSpiral::VSpiralType)m_optionsWidget->type() ); - } - else - return - new VSpiral( - 0L, - m_p, - m_d1, - m_optionsWidget->segments(), - m_optionsWidget->fade(), - m_optionsWidget->clockwise(), - m_d2, (VSpiral::VSpiralType)m_optionsWidget->type() ); -} - -bool -VSpiralTool::showDialog() const -{ - return m_optionsWidget->exec() == TQDialog::Accepted; -} - -void -VSpiralTool::setup( TDEActionCollection *collection ) -{ - m_action = static_cast(collection -> action( name() ) ); - - if( m_action == 0 ) - { - m_action = new TDERadioAction( i18n( "Spiral Tool" ), "14_spiral", TQt::SHIFT+TQt::Key_H, this, TQT_SLOT( activate() ), collection, name() ); - m_action->setToolTip( i18n( "Spiral" ) ); - m_action->setExclusiveGroup( "shapes" ); - //m_ownAction = true; - } -} - diff --git a/karbon/tools/vspiraltool.cpp b/karbon/tools/vspiraltool.cpp new file mode 100644 index 00000000..c414be41 --- /dev/null +++ b/karbon/tools/vspiraltool.cpp @@ -0,0 +1,213 @@ +/* This file is part of the KDE project + Copyright (C) 2001, 2002, 2003 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 +#include + +#include +#include +#include + +#include +#include +#include +#include "vspiraltool.h" +#include "KoUnitWidgets.h" + + +VSpiralTool::VSpiralOptionsWidget::VSpiralOptionsWidget( KarbonPart *part, TQWidget* parent, const char* name ) + : KDialogBase( parent, name, true, i18n( "Insert Spiral" ), Ok | Cancel ), m_part( part ) +{ + TQGroupBox *group = new TQGroupBox( 2, Qt::Horizontal, i18n( "Properties" ), this ); + + new TQLabel( i18n( "Type:" ), group ); + m_type = new KComboBox( false, group ); + m_type->insertItem( i18n( "Round" ), 0 ); + m_type->insertItem( i18n( "Rectangular" ), 1 ); + + new TQLabel( i18n( "Radius:" ), group ); + m_radius = new KoUnitDoubleSpinBox( group, 0.0, 1000.0, 0.5, 50.0, KoUnit::U_MM ); + refreshUnit(); + new TQLabel( i18n( "Segments:" ), group ); + m_segments = new KIntSpinBox( group ); + m_segments->setMinValue( 1 ); + new TQLabel( i18n( "Fade:" ), group ); + m_fade = new KDoubleNumInput( group ); + m_fade->setRange( 0.0, 1.0, 0.05 ); + + new TQLabel( i18n( "Qt::Orientation:" ), group ); + m_clockwise = new KComboBox( false, group ); + m_clockwise->insertItem( i18n( "Clockwise" ), 0 ); + m_clockwise->insertItem( i18n( "Counter Clockwise" ), 1 ); + + group->setInsideMargin( 4 ); + group->setInsideSpacing( 2 ); + + setMainWidget( group ); + //setFixedSize( baseSize() ); +} + +double +VSpiralTool::VSpiralOptionsWidget::radius() const +{ + return m_radius->value(); +} + +uint +VSpiralTool::VSpiralOptionsWidget::segments() const +{ + return m_segments->value(); +} + +double +VSpiralTool::VSpiralOptionsWidget::fade() const +{ + return m_fade->value(); +} + +bool +VSpiralTool::VSpiralOptionsWidget::clockwise() const +{ + return m_clockwise->currentItem() == 0; +} + +uint +VSpiralTool::VSpiralOptionsWidget::type() const +{ + return m_type->currentItem(); +} + +void +VSpiralTool::VSpiralOptionsWidget::setRadius( double value ) +{ + m_radius->changeValue( value ); +} + +void +VSpiralTool::VSpiralOptionsWidget::setSegments( uint value ) +{ + m_segments->setValue( value ); +} + +void +VSpiralTool::VSpiralOptionsWidget::setFade( double value ) +{ + m_fade->setValue( value ); +} + +void +VSpiralTool::VSpiralOptionsWidget::setClockwise( bool value ) +{ + m_clockwise->setCurrentItem( value ? 0 : 1 ); +} + +void +VSpiralTool::VSpiralOptionsWidget::refreshUnit() +{ + m_radius->setUnit( m_part->unit() ); +} + +VSpiralTool::VSpiralTool( KarbonView *view ) + : VShapeTool( view, "tool_spiral", true ) +{ + // create config dialog: + m_optionsWidget = new VSpiralOptionsWidget( view->part() ); + m_optionsWidget->setSegments( 8 ); + m_optionsWidget->setFade( 0.8 ); + m_optionsWidget->setClockwise( true ); + registerTool( this ); +} + +void +VSpiralTool::arrowKeyReleased( TQt::Key key ) +{ + int change = 0; + if( key == TQt::Key_Up ) + change = 1; + else if( key == TQt::Key_Down ) + change = -1; + + if( change != 0 ) + { + draw(); + + m_optionsWidget->setSegments( m_optionsWidget->segments() + change ); + + draw(); + } +} + +VSpiralTool::~VSpiralTool() +{ + delete( m_optionsWidget ); +} + +void +VSpiralTool::refreshUnit() +{ + m_optionsWidget->refreshUnit(); +} + +VPath* +VSpiralTool::shape( bool interactive ) const +{ + if( interactive ) + { + return + new VSpiral( + 0L, + m_p, + m_optionsWidget->radius(), + m_optionsWidget->segments(), + m_optionsWidget->fade(), + m_optionsWidget->clockwise(), + m_d2, (VSpiral::VSpiralType)m_optionsWidget->type() ); + } + else + return + new VSpiral( + 0L, + m_p, + m_d1, + m_optionsWidget->segments(), + m_optionsWidget->fade(), + m_optionsWidget->clockwise(), + m_d2, (VSpiral::VSpiralType)m_optionsWidget->type() ); +} + +bool +VSpiralTool::showDialog() const +{ + return m_optionsWidget->exec() == TQDialog::Accepted; +} + +void +VSpiralTool::setup( TDEActionCollection *collection ) +{ + m_action = static_cast(collection -> action( name() ) ); + + if( m_action == 0 ) + { + m_action = new TDERadioAction( i18n( "Spiral Tool" ), "14_spiral", TQt::SHIFT+TQt::Key_H, this, TQT_SLOT( activate() ), collection, name() ); + m_action->setToolTip( i18n( "Spiral" ) ); + m_action->setExclusiveGroup( "shapes" ); + //m_ownAction = true; + } +} + diff --git a/karbon/tools/vstartool.cc b/karbon/tools/vstartool.cc deleted file mode 100644 index 9a92cd37..00000000 --- a/karbon/tools/vstartool.cc +++ /dev/null @@ -1,249 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2001, 2002, 2003 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 -#include - -#include -#include -#include - -#include -#include -#include -#include "vstartool.h" -#include "KoUnitWidgets.h" - - -VStarOptionsWidget::VStarOptionsWidget( KarbonPart *part, TQWidget* parent, const char* name ) - : KDialogBase( parent, name, true, i18n( "Insert Star" ), Ok | Cancel ), m_part( part ) -{ - TQGroupBox *group = new TQGroupBox( 2, Qt::Horizontal, i18n( "Properties" ), this ); - new TQLabel( i18n( "Type:" ), group ); - m_type = new KComboBox( false, group ); - m_type->insertItem( i18n( "Star Outline" ), VStar::star_outline ); - m_type->insertItem( i18n( "Spoke" ), VStar::spoke ); - m_type->insertItem( i18n( "Wheel" ), VStar::wheel ); - m_type->insertItem( i18n( "Polygon" ), VStar::polygon ); - m_type->insertItem( i18n( "Framed Star" ), VStar::framed_star); - m_type->insertItem( i18n( "Star" ), VStar::star ); - m_type->insertItem( i18n( "Gear" ), VStar::gear ); - connect( m_type, TQT_SIGNAL( activated( int ) ), this, TQT_SLOT( typeChanged( int ) ) ); - - // add width/height-input: - m_outerRLabel = new TQLabel( i18n( "Outer radius:" ), group ); - m_outerR = new KoUnitDoubleSpinBox( group, 0.0, 1000.0, 0.5, 50.0, KoUnit::U_MM ); - connect( m_outerR, TQT_SIGNAL( valueChanged( double ) ), this, TQT_SLOT( setOuterRadius( double ) ) ); - - m_innerRLabel = new TQLabel( i18n( "Inner radius:" ), group ); - m_innerR = new KoUnitDoubleSpinBox( group, 0.0, 1000.0, 0.5, 25.0, KoUnit::U_MM ); - - refreshUnit(); - - new TQLabel( i18n( "Edges:" ), group ); - m_edges = new KIntSpinBox( group ); - m_edges->setMinValue( 3 ); - connect( m_edges, TQT_SIGNAL( valueChanged( int ) ), this, TQT_SLOT( setEdges( int ) ) ); - - new TQLabel( i18n( "Inner angle:" ), group ); - m_innerAngle = new KIntSpinBox( group ); - m_innerAngle->setMinValue( 0 ); - m_innerAngle->setMaxValue( 360 ); - - new TQLabel( i18n( "Roundness:" ), group ); - m_roundness = new KDoubleNumInput( group ); - m_roundness->setRange( 0.0, 1.0, 0.05 ); - - typeChanged( VStar::star_outline ); - - group->setInsideMargin( 4 ); - group->setInsideSpacing( 2 ); - - setMainWidget( group ); - setFixedSize( baseSize() ); -} - -void -VStarOptionsWidget::refreshUnit() -{ - m_outerR->setUnit( m_part->unit() ); - m_innerR->setUnit( m_part->unit() ); -} - -void -VStarOptionsWidget::setEdges( int v ) -{ - m_edges->setValue( v ); - - // set optimal inner radius - if( type() == VStar::star ) - m_innerR->setValue( VStar::getOptimalInnerRadius( edges(), outerRadius(), innerAngle() ) ); -} - -void -VStarOptionsWidget::setInnerRadius( double v ) -{ - m_innerR->changeValue( v ); -} - -void -VStarOptionsWidget::setOuterRadius( double v ) -{ - m_outerR->setValue( v ); - - // set optimal inner radius - if( type() == VStar::star ) - m_innerR->setValue( VStar::getOptimalInnerRadius( edges(), outerRadius(), innerAngle() ) ); -} - -double -VStarOptionsWidget::roundness() const -{ - return m_roundness->value(); -} - -int -VStarOptionsWidget::edges() const -{ - return m_edges->value(); -} - -double -VStarOptionsWidget::innerRadius() const -{ - return m_innerR->value(); -} - -double -VStarOptionsWidget::outerRadius() const -{ - return m_outerR->value(); -} - -uint -VStarOptionsWidget::type() const -{ - return m_type->currentItem(); -} - -uint -VStarOptionsWidget::innerAngle() const -{ - return m_innerAngle->value(); -} - -void -VStarOptionsWidget::typeChanged( int type ) -{ - m_innerR->setEnabled( type == VStar::star || type == VStar::star_outline || type == VStar::framed_star || type == VStar::gear ); - m_innerAngle->setEnabled( type == VStar::star || type == VStar::star_outline || type == VStar::framed_star || type == VStar::gear ); - - // set optimal inner radius - if( type == VStar::star ) - m_innerR->changeValue( VStar::getOptimalInnerRadius( edges(), outerRadius(), innerAngle() ) ); -} - -VStarTool::VStarTool( KarbonView *view ) - : VShapeTool( view, "tool_star", true ) -{ - // create config dialog: - m_optionsWidget = new VStarOptionsWidget( view->part() ); - m_optionsWidget->setEdges( 5 ); - registerTool( this ); -} - -void VStarTool::refreshUnit() -{ - m_optionsWidget->refreshUnit(); -} - -VStarTool::~VStarTool() -{ - delete( m_optionsWidget ); -} - -void -VStarTool::arrowKeyReleased( TQt::Key key ) -{ - int change = 0; - if( key == TQt::Key_Up ) - change = 1; - else if( key == TQt::Key_Down ) - change = -1; - - if( change != 0 ) - { - draw(); - - m_optionsWidget->setEdges( m_optionsWidget->edges() + change ); - - draw(); - } -} - -VPath* -VStarTool::shape( bool interactive ) const -{ - if( interactive ) - { - return - new VStar( - 0L, - m_p, - m_optionsWidget->outerRadius(), - m_optionsWidget->innerRadius(), - m_optionsWidget->edges(), 0.0, m_optionsWidget->innerAngle(), - m_optionsWidget->roundness(), (VStar::VStarType)m_optionsWidget->type() ); - } - else - return - new VStar( - 0L, - m_p, - m_d1, - m_optionsWidget->innerRadius() * m_d1 / - m_optionsWidget->outerRadius(), - m_optionsWidget->edges(), - m_d2, m_optionsWidget->innerAngle(), - m_optionsWidget->roundness(), (VStar::VStarType)m_optionsWidget->type() ); -} - -bool -VStarTool::showDialog() const -{ - return m_optionsWidget->exec() == TQDialog::Accepted; -} - -void -VStarTool::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" ), "14_star", shortcut, this, TQT_SLOT( activate() ), collection, name() ); - m_action->setToolTip( i18n( "Draw a star" ) ); - m_action->setExclusiveGroup( "shapes" ); - //m_ownAction = true; - } -} - -#include "vstartool.moc" diff --git a/karbon/tools/vstartool.cpp b/karbon/tools/vstartool.cpp new file mode 100644 index 00000000..9a92cd37 --- /dev/null +++ b/karbon/tools/vstartool.cpp @@ -0,0 +1,249 @@ +/* This file is part of the KDE project + Copyright (C) 2001, 2002, 2003 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 +#include + +#include +#include +#include + +#include +#include +#include +#include "vstartool.h" +#include "KoUnitWidgets.h" + + +VStarOptionsWidget::VStarOptionsWidget( KarbonPart *part, TQWidget* parent, const char* name ) + : KDialogBase( parent, name, true, i18n( "Insert Star" ), Ok | Cancel ), m_part( part ) +{ + TQGroupBox *group = new TQGroupBox( 2, Qt::Horizontal, i18n( "Properties" ), this ); + new TQLabel( i18n( "Type:" ), group ); + m_type = new KComboBox( false, group ); + m_type->insertItem( i18n( "Star Outline" ), VStar::star_outline ); + m_type->insertItem( i18n( "Spoke" ), VStar::spoke ); + m_type->insertItem( i18n( "Wheel" ), VStar::wheel ); + m_type->insertItem( i18n( "Polygon" ), VStar::polygon ); + m_type->insertItem( i18n( "Framed Star" ), VStar::framed_star); + m_type->insertItem( i18n( "Star" ), VStar::star ); + m_type->insertItem( i18n( "Gear" ), VStar::gear ); + connect( m_type, TQT_SIGNAL( activated( int ) ), this, TQT_SLOT( typeChanged( int ) ) ); + + // add width/height-input: + m_outerRLabel = new TQLabel( i18n( "Outer radius:" ), group ); + m_outerR = new KoUnitDoubleSpinBox( group, 0.0, 1000.0, 0.5, 50.0, KoUnit::U_MM ); + connect( m_outerR, TQT_SIGNAL( valueChanged( double ) ), this, TQT_SLOT( setOuterRadius( double ) ) ); + + m_innerRLabel = new TQLabel( i18n( "Inner radius:" ), group ); + m_innerR = new KoUnitDoubleSpinBox( group, 0.0, 1000.0, 0.5, 25.0, KoUnit::U_MM ); + + refreshUnit(); + + new TQLabel( i18n( "Edges:" ), group ); + m_edges = new KIntSpinBox( group ); + m_edges->setMinValue( 3 ); + connect( m_edges, TQT_SIGNAL( valueChanged( int ) ), this, TQT_SLOT( setEdges( int ) ) ); + + new TQLabel( i18n( "Inner angle:" ), group ); + m_innerAngle = new KIntSpinBox( group ); + m_innerAngle->setMinValue( 0 ); + m_innerAngle->setMaxValue( 360 ); + + new TQLabel( i18n( "Roundness:" ), group ); + m_roundness = new KDoubleNumInput( group ); + m_roundness->setRange( 0.0, 1.0, 0.05 ); + + typeChanged( VStar::star_outline ); + + group->setInsideMargin( 4 ); + group->setInsideSpacing( 2 ); + + setMainWidget( group ); + setFixedSize( baseSize() ); +} + +void +VStarOptionsWidget::refreshUnit() +{ + m_outerR->setUnit( m_part->unit() ); + m_innerR->setUnit( m_part->unit() ); +} + +void +VStarOptionsWidget::setEdges( int v ) +{ + m_edges->setValue( v ); + + // set optimal inner radius + if( type() == VStar::star ) + m_innerR->setValue( VStar::getOptimalInnerRadius( edges(), outerRadius(), innerAngle() ) ); +} + +void +VStarOptionsWidget::setInnerRadius( double v ) +{ + m_innerR->changeValue( v ); +} + +void +VStarOptionsWidget::setOuterRadius( double v ) +{ + m_outerR->setValue( v ); + + // set optimal inner radius + if( type() == VStar::star ) + m_innerR->setValue( VStar::getOptimalInnerRadius( edges(), outerRadius(), innerAngle() ) ); +} + +double +VStarOptionsWidget::roundness() const +{ + return m_roundness->value(); +} + +int +VStarOptionsWidget::edges() const +{ + return m_edges->value(); +} + +double +VStarOptionsWidget::innerRadius() const +{ + return m_innerR->value(); +} + +double +VStarOptionsWidget::outerRadius() const +{ + return m_outerR->value(); +} + +uint +VStarOptionsWidget::type() const +{ + return m_type->currentItem(); +} + +uint +VStarOptionsWidget::innerAngle() const +{ + return m_innerAngle->value(); +} + +void +VStarOptionsWidget::typeChanged( int type ) +{ + m_innerR->setEnabled( type == VStar::star || type == VStar::star_outline || type == VStar::framed_star || type == VStar::gear ); + m_innerAngle->setEnabled( type == VStar::star || type == VStar::star_outline || type == VStar::framed_star || type == VStar::gear ); + + // set optimal inner radius + if( type == VStar::star ) + m_innerR->changeValue( VStar::getOptimalInnerRadius( edges(), outerRadius(), innerAngle() ) ); +} + +VStarTool::VStarTool( KarbonView *view ) + : VShapeTool( view, "tool_star", true ) +{ + // create config dialog: + m_optionsWidget = new VStarOptionsWidget( view->part() ); + m_optionsWidget->setEdges( 5 ); + registerTool( this ); +} + +void VStarTool::refreshUnit() +{ + m_optionsWidget->refreshUnit(); +} + +VStarTool::~VStarTool() +{ + delete( m_optionsWidget ); +} + +void +VStarTool::arrowKeyReleased( TQt::Key key ) +{ + int change = 0; + if( key == TQt::Key_Up ) + change = 1; + else if( key == TQt::Key_Down ) + change = -1; + + if( change != 0 ) + { + draw(); + + m_optionsWidget->setEdges( m_optionsWidget->edges() + change ); + + draw(); + } +} + +VPath* +VStarTool::shape( bool interactive ) const +{ + if( interactive ) + { + return + new VStar( + 0L, + m_p, + m_optionsWidget->outerRadius(), + m_optionsWidget->innerRadius(), + m_optionsWidget->edges(), 0.0, m_optionsWidget->innerAngle(), + m_optionsWidget->roundness(), (VStar::VStarType)m_optionsWidget->type() ); + } + else + return + new VStar( + 0L, + m_p, + m_d1, + m_optionsWidget->innerRadius() * m_d1 / + m_optionsWidget->outerRadius(), + m_optionsWidget->edges(), + m_d2, m_optionsWidget->innerAngle(), + m_optionsWidget->roundness(), (VStar::VStarType)m_optionsWidget->type() ); +} + +bool +VStarTool::showDialog() const +{ + return m_optionsWidget->exec() == TQDialog::Accepted; +} + +void +VStarTool::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" ), "14_star", shortcut, this, TQT_SLOT( activate() ), collection, name() ); + m_action->setToolTip( i18n( "Draw a star" ) ); + m_action->setExclusiveGroup( "shapes" ); + //m_ownAction = true; + } +} + +#include "vstartool.moc" diff --git a/karbon/tools/vtexttool.cc b/karbon/tools/vtexttool.cc deleted file mode 100644 index e7fa848d..00000000 --- a/karbon/tools/vtexttool.cc +++ /dev/null @@ -1,1159 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2001, 2002, 2003 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 - -#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 "vtexttool.h" - - -static void -traceShape( VKoPainter* p, int x, int y, int w, int h ) -{ - p->newPath(); - p->moveTo( KoPoint( x + w , y + h ) ); - p->lineTo( KoPoint( x + w / 3, y + h ) ); - p->lineTo( KoPoint( x + w / 3, y + h / 3 ) ); - p->lineTo( KoPoint( x + w , y + h / 3 ) ); - p->lineTo( KoPoint( x + w , y + h ) ); - - p->moveTo( KoPoint( x , y ) ); - p->lineTo( KoPoint( x + ( w / 3 ) * 2, y ) ); - p->lineTo( KoPoint( x + ( w / 3 ) * 2, y + ( h / 3 ) * 2 ) ); - p->lineTo( KoPoint( x , y + ( h / 3 ) * 2 ) ); - p->lineTo( KoPoint( x , y ) ); -} - -ShadowPreview::ShadowPreview( ShadowWidget* parent ) - : TQWidget( parent ), m_parent( parent ) -{ - setBackgroundMode( TQt::NoBackground ); - setMinimumSize( 60, 60 ); - - connect( this, TQT_SIGNAL( changed( int, int, bool ) ), m_parent, TQT_SLOT( setShadowValues( int, int, bool ) ) ); -} - -ShadowPreview::~ShadowPreview() -{ -} - -void -ShadowPreview::mouseReleaseEvent( TQMouseEvent* e ) -{ - int dx = e->x() - width() / 2; - int dy = e->y() - height() / 2; - - float fd = sqrt( double( dx * dx + dy * dy ) ); - int a; - - if( fd == 0 ) - a = 0; - else if( dy == 0 && dx < 0 ) - a = 180; - else - { - float r = acos( dx / fd ); - a = int( ( dy <= 0 ? r : VGlobal::twopi - r ) / VGlobal::twopi * 360. ); - } - - emit changed( a, ( int ) fd, m_parent->isTranslucent() ); -} - -void -ShadowPreview::paintEvent( TQPaintEvent* ) -{ - int w = width() - 4; - int h = height() - 4; - int d = m_parent->shadowDistance(); - int a = 360 - m_parent->shadowAngle(); - - TQPixmap pm( w, h ); - VKoPainter p( TQT_TQPAINTDEVICE(&pm), w, h ); - VColor color( VColor::rgb ); - - VFill fill; - TDEIconLoader il; - fill.pattern() = VPattern( il.iconPath( "karbon.png", TDEIcon::Small ) ); - fill.setType( VFill::patt ); - - p.newPath(); - p.moveTo( KoPoint( 0, 0 ) ); - p.lineTo( KoPoint( 0, h ) ); - p.lineTo( KoPoint( w, h ) ); - p.lineTo( KoPoint( w, 0 ) ); - p.lineTo( KoPoint( 0, 0 ) ); - p.setBrush( fill ); - p.fillPath(); - - color.set( 1., 1., 1. ); - color.setOpacity( .5 ); - p.setBrush( VFill( color ) ); - p.fillPath(); - - if( m_parent->isTranslucent() ) - { - color.set( 0., 0., 0. ); - color.setOpacity( .3 ); - } - else - { - color.set( .3, .3, .3 ); - color.setOpacity( 1. ); - } - - p.setPen( VStroke( color ) ); - p.setBrush( VFill( color ) ); - - traceShape( - &p, - int( w / 4 + d * cos( a / 360. * VGlobal::twopi ) ), - int( h / 4 + d * sin( a / 360. * VGlobal::twopi ) ), int( w / 2 ), int( h / 2 ) ); - - p.strokePath(); - p.fillPath(); - - color.set( 0., 0., 1. ); - color.setOpacity( 1. ); - p.setBrush( VFill( color ) ); - color.set( 0., 0., .5 ); - p.setPen( VStroke( color ) ); - traceShape( &p, w / 4, h / 4, w / 2, h / 2 ); - p.strokePath(); - p.fillPath(); - - if( !m_parent->useShadow() ) - { - p.newPath(); - p.moveTo( KoPoint( 0, 0 ) ); - p.lineTo( KoPoint( 0, h ) ); - p.lineTo( KoPoint( w, h ) ); - p.lineTo( KoPoint( w, 0 ) ); - p.lineTo( KoPoint( 0, 0 ) ); - VColor c( colorGroup().background() ); - c.setOpacity( .8 ); - p.setBrush( VFill( c ) ); - p.fillPath(); - } - - p.end(); - - TQPainter painter( this ); - painter.drawPixmap( 2, 2, pm ); - painter.setPen( colorGroup().light() ); - painter.moveTo( 1, height() - 1 ); - painter.lineTo( 1, 1 ); - painter.lineTo( width() - 1, 1 ); - painter.lineTo( width() - 1, height() - 1 ); - painter.lineTo( 1, height() - 1 ); - painter.setPen( colorGroup().dark() ); - painter.moveTo( 0, height() - 1 ); - painter.lineTo( 0, 0 ); - painter.lineTo( width() - 1, 0 ); - painter.moveTo( width() - 2, 2 ); - painter.lineTo( width() - 2, height() - 2 ); - painter.lineTo( 2, height() - 2 ); - painter.setPen( TQt::black ); - painter.drawLine( width() / 2 - 2, height() / 2, width() / 2 + 2, height() / 2 ); - painter.drawLine( width() / 2, height() / 2 - 2, width() / 2, height() / 2 + 2 ); -} - -ShadowWidget::ShadowWidget( TQWidget* parent, const char* name, int angle, int distance, bool translucent ) - : TQGroupBox( parent, name ) -{ - setTitle( i18n( "Shadow" ) ); - setSizePolicy( TQSizePolicy( TQSizePolicy::Minimum, TQSizePolicy::Minimum ) ); - - TQGridLayout* layout = new TQGridLayout( this ); - layout->addRowSpacing( 0, 12 ); - layout->setMargin( 3 ); - layout->setSpacing( 2 ); - layout->setColStretch( 0, 1 ); - layout->setColStretch( 1, 0 ); - layout->setColStretch( 2, 2 ); - layout->addMultiCellWidget( m_preview = new ShadowPreview( this ), 1, 3, 0, 0 ); - layout->addWidget( new TQLabel( i18n( "Angle:" ), this ), 1, 1 ); - layout->addWidget( m_angle = new KIntNumInput( this ), 1, 2 ); - layout->addWidget( new TQLabel( i18n( "Distance:" ), this ), 2, 1 ); - layout->addWidget( m_distance = new KIntNumInput( this ), 2, 2 ); - layout->addWidget( m_useShadow = new TQCheckBox( i18n( "Shadow" ), this ), 3, 1 ); - layout->addWidget( m_translucent = new TQCheckBox( i18n( "Draw translucent shadow" ), this ), 3, 2 ); - m_distance->setRange( 1, 37, 1, true ); - m_angle->setRange( 0, 360, 10, true ); - m_angle->setValue( angle ); - m_distance->setValue( distance ); - m_translucent->setChecked( translucent ); - - connect( m_angle, TQT_SIGNAL( valueChanged( int ) ), this, TQT_SLOT( updatePreview( int ) ) ); - connect( m_distance, TQT_SIGNAL( valueChanged( int ) ), this, TQT_SLOT( updatePreview( int ) ) ); - connect( m_useShadow, TQT_SIGNAL( clicked() ), this, TQT_SLOT( updatePreview() ) ); - connect( m_translucent, TQT_SIGNAL( clicked() ), this, TQT_SLOT( updatePreview() ) ); - - updatePreview(); -} - -ShadowWidget::~ShadowWidget() -{ -} - -void -ShadowWidget::setUseShadow( bool use ) -{ - m_useShadow->setChecked( use ); - updatePreview(); -} - -bool ShadowWidget::useShadow() -{ - return m_useShadow->isChecked(); -} - -void -ShadowWidget::setShadowAngle( int angle ) -{ - m_angle->setValue( angle ); - m_preview->repaint(); -} - -int -ShadowWidget::shadowAngle() -{ - return m_angle->value(); -} - -void -ShadowWidget::setShadowDistance( int distance ) -{ - m_distance->setValue( distance ); - m_preview->repaint(); -} - -int -ShadowWidget::shadowDistance() -{ - return m_distance->value(); -} - -void -ShadowWidget::setTranslucent( bool translucent ) -{ - m_translucent->setChecked( translucent ); - m_preview->repaint(); -} - -bool ShadowWidget::isTranslucent() -{ - return m_translucent->isChecked(); -} - -void -ShadowWidget::setShadowValues( int angle, int distance, bool translucent ) -{ - m_angle->setValue( angle ); - m_distance->setValue( distance ); - m_translucent->setChecked( translucent ); - updatePreview(); -} - -void -ShadowWidget::updatePreview( int ) -{ - m_preview->repaint(); -} - -void -ShadowWidget::updatePreview() -{ - m_preview->repaint(); - bool ok = m_useShadow->isChecked(); - m_angle->setEnabled( ok ); - m_distance->setEnabled( ok ); - m_translucent->setEnabled( ok ); -} - -VTextOptionsWidget::VTextOptionsWidget( VTextTool* tool, TQWidget *parent ) - : KDialogBase( parent, "", true, i18n( "Text" ), Ok | Cancel ), m_tool( tool ) -{ - //setSizePolicy( TQSizePolicy( TQSizePolicy::Minimum, TQSizePolicy::Minimum ) ); - //setFrameStyle( Box | Sunken ); - TQWidget *base = new TQWidget( this ); - TQVBoxLayout* mainLayout = new TQVBoxLayout( base ); - mainLayout->setMargin( 3 ); - - mainLayout->add( m_tabWidget = new TQTabWidget( base ) ); - - m_tabWidget->setFont( TQFont( TDEGlobalSettings::generalFont().family() , 8 ) ); - - TQWidget* textWidget = new TQWidget( m_tabWidget ); - - TQGridLayout* textLayout = new TQGridLayout( textWidget ); - - TQStringList list; - TDEFontChooser::getFontList( list, TDEFontChooser::SmoothScalableFonts ); - - textLayout->setMargin( 3 ); - textLayout->setSpacing( 2 ); - textLayout->addMultiCellWidget( m_fontCombo = new TDEFontCombo( list, textWidget ), 0, 0, 0, 2 ); - textLayout->addWidget( m_fontSize = new KIntNumInput( textWidget ), 1, 0 ); - textLayout->addWidget( m_boldCheck = new TQCheckBox( i18n( "Bold" ), textWidget ), 1, 1 ); - textLayout->addWidget( m_italicCheck = new TQCheckBox( i18n( "Italic" ), textWidget ), 1, 2 ); - textLayout->addMultiCellWidget( m_textEditor = new TQLineEdit( textWidget ), 2, 2, 0, 2 ); - - m_tabWidget->addTab( textWidget, i18n( "Text" ) ); - - TQWidget* posWidget = new TQWidget( m_tabWidget ); - - TQGridLayout* posLayout = new TQGridLayout( posWidget ); - textLayout->setMargin( 3 ); - posLayout->setSpacing( 2 ); - posLayout->addWidget( new TQLabel( i18n( "Alignment:" ), posWidget ), 0, 0 ); - posLayout->addWidget( m_textAlignment = new TQComboBox( posWidget ), 0, 1 ); - posLayout->addWidget( new TQLabel( i18n( "Position:" ), posWidget ), 1, 0 ); - posLayout->addWidget( m_textPosition = new TQComboBox( posWidget ), 1, 1 ); - posLayout->addWidget( new TQLabel( i18n( "Offset:" ), posWidget ), 2, 0 ); - posLayout->addWidget( m_textOffset = new KDoubleNumInput( posWidget ), 2, 1 ); - posLayout->setColStretch( 0, 0 ); - posLayout->setColStretch( 1, 1 ); - - m_tabWidget->addTab( posWidget, i18n( "Position" ) ); - - TQWidget* fxWidget = new TQWidget( m_tabWidget ); - - TQVBoxLayout* fxLayout = new TQVBoxLayout( fxWidget ); - - fxLayout->setMargin( 3 ); - fxLayout->setSpacing( 2 ); - fxLayout->add( m_shadow = new ShadowWidget( fxWidget, 0L, 315, 4, true ) ); - - TQHBoxLayout* fxLayout2 = new TQHBoxLayout( fxLayout ); - - fxLayout2->setSpacing( 2 ); - fxLayout2->addWidget( m_editBasePath = new TQPushButton( i18n( "Edit Base Path" ), fxWidget ) ); - fxLayout2->addWidget( m_convertToShapes = new TQPushButton( i18n( "Convert to Shapes" ), fxWidget ) ); - - m_tabWidget->addTab( fxWidget, i18n( "Effects" ) ); - - m_fontCombo->setCurrentText( TDEGlobalSettings::generalFont().family() ); - - m_fontSize->setValue( 12 ); - m_fontSize->setSuffix( " pt" ); - - m_textEditor->setMinimumHeight( 100 ); - m_textEditor->setText( i18n( "New text") ); - m_textEditor->selectAll(); - - m_convertToShapes->setEnabled( true ); - - m_textAlignment->insertItem( i18n( "Horizontal alignment", "Left") ); - m_textAlignment->insertItem( i18n( "Horizontal alignment", "Center") ); - m_textAlignment->insertItem( i18n( "Horizontal alignment", "Right") ); - - m_textPosition->insertItem( i18n( "Vertical alignment", "Above") ); - m_textPosition->insertItem( i18n( "Vertical alignment", "On") ); - m_textPosition->insertItem( i18n( "Vertical alignment", "Under") ); - - m_textOffset->setRange( 0.0, 100.0, 1.0, true ); - - connect( m_fontCombo, TQT_SIGNAL( activated( int ) ), this, TQT_SLOT( valueChanged( int ) ) ); - connect( m_boldCheck, TQT_SIGNAL( stateChanged( int ) ), this, TQT_SLOT( valueChanged( int ) ) ); - connect( m_italicCheck, TQT_SIGNAL( stateChanged( int ) ), this, TQT_SLOT( valueChanged( int ) ) ); - connect( m_fontSize, TQT_SIGNAL( valueChanged( int ) ), this, TQT_SLOT( valueChanged( int ) ) ); - connect( m_textPosition, TQT_SIGNAL( activated( int ) ), this, TQT_SLOT( valueChanged( int ) ) ); - connect( m_textAlignment, TQT_SIGNAL( activated( int ) ), this, TQT_SLOT( valueChanged( int ) ) ); - connect( m_textOffset, TQT_SIGNAL( valueChanged( double ) ), this, TQT_SLOT( valueChanged( double ) ) ); - connect( m_textEditor, TQT_SIGNAL( returnPressed() ), this, TQT_SLOT( accept() ) ); - connect( m_textEditor, TQT_SIGNAL( textChanged( const TQString& ) ), this, TQT_SLOT( textChanged( const TQString& ) ) ); - connect( m_editBasePath, TQT_SIGNAL( clicked() ), this, TQT_SLOT( editBasePath() ) ); - connect( m_convertToShapes, TQT_SIGNAL( clicked() ), this, TQT_SLOT( convertToShapes() ) ); - connect( this, TQT_SIGNAL( cancelClicked() ), this, TQT_SLOT( cancel() ) ); - - setMainWidget( base ); - setFixedSize( baseSize() ); -} - -VTextOptionsWidget::~VTextOptionsWidget() -{ -} - -void -VTextOptionsWidget::valueChanged( int ) -{ - m_fontCombo->setBold( m_boldCheck->isChecked() ); - m_fontCombo->setItalic( m_italicCheck->isChecked() ); - - m_textEditor->setFont( TQFont( m_fontCombo->currentText(), m_fontSize->value(), ( m_boldCheck->isChecked() ? 75 : 50 ), m_italicCheck->isChecked() ) ); - - if( m_tool && isVisible() ) - m_tool->textChanged(); -} - -void -VTextOptionsWidget::valueChanged( double ) -{ - if( m_tool && isVisible() ) - m_tool->textChanged(); -} - -void -VTextOptionsWidget::accept() -{ - if( m_tool ) - m_tool->accept(); - hide(); -} - -void -VTextOptionsWidget::cancel() -{ - if( m_tool ) - m_tool->cancel(); -} - -void -VTextOptionsWidget::textChanged( const TQString& ) -{ - if( m_tool && isVisible() ) - m_tool->textChanged(); -} - -void -VTextOptionsWidget::editBasePath() -{ - if( m_tool ) - m_tool->editBasePath(); -} - -void -VTextOptionsWidget::convertToShapes() -{ - if( m_tool ) - m_tool->convertToShapes(); -} - -void -VTextOptionsWidget::setFont( const TQFont& font ) -{ - m_fontCombo->setCurrentText( font.family() ); - - m_boldCheck->setChecked( font.bold() ); - - m_italicCheck->setChecked( font.italic() ); - - m_fontSize->setValue( font.pointSize() ); - - m_fontCombo->setBold( m_boldCheck->isChecked() ); - m_fontCombo->setItalic( m_italicCheck->isChecked() ); - - m_textEditor->setFont( TQFont( m_fontCombo->currentText(), m_fontSize->value(), ( m_boldCheck->isChecked() ? 75 : 50 ), m_italicCheck->isChecked() ) ); -} - -TQFont VTextOptionsWidget::font() -{ - return TQFont( m_fontCombo->currentText(), m_fontSize->value(), ( m_boldCheck->isChecked() ? 75 : 50 ), m_italicCheck->isChecked() ); -} - -void -VTextOptionsWidget::setText( const TQString& text ) -{ - m_textEditor->setText( text ); -} - -TQString VTextOptionsWidget::text() -{ - return m_textEditor->text(); -} - -void -VTextOptionsWidget::setPosition( VText::Position position ) -{ - m_textPosition->setCurrentItem( position ); -} - -VText::Position VTextOptionsWidget::position() -{ - return ( VText::Position ) m_textPosition->currentItem(); -} - -void -VTextOptionsWidget::setAlignment( VText::Alignment alignment ) -{ - m_textAlignment->setCurrentItem( alignment ); -} - -VText::Alignment VTextOptionsWidget::alignment() -{ - return ( VText::Alignment ) m_textAlignment->currentItem(); -} - -void -VTextOptionsWidget::setOffset( double offset ) -{ - if( offset < 0.0 ) offset = 0.0; - if( offset > 100.0 ) offset = 100.0; - - m_textOffset->setValue( offset ); -} -double -VTextOptionsWidget::offset() -{ - return m_textOffset->value(); -} - -void -VTextOptionsWidget::setUseShadow( bool state ) -{ - m_shadow->setUseShadow( state ); -} - -bool VTextOptionsWidget::useShadow() -{ - return m_shadow->useShadow(); -} - -void -VTextOptionsWidget::setShadow( int angle, int distance, bool translucent ) -{ - m_shadow->setShadowValues( angle, distance, translucent ); -} - -bool VTextOptionsWidget::translucentShadow() -{ - return m_shadow->isTranslucent(); -} - -int -VTextOptionsWidget::shadowAngle() -{ - return m_shadow->shadowAngle(); -} - -int -VTextOptionsWidget::shadowDistance() -{ - return m_shadow->shadowDistance(); -} - -void -VTextOptionsWidget::initialize( VObject &text ) -{ - if( m_tool ) - m_tool->visit( text ); -} - -VTextTool::VTextTool( KarbonView *view ) - : VTool( view, "tool_text" ) -{ - m_optionsWidget = new VTextOptionsWidget( this, 0L ); - m_text = 0L; - m_editedText = 0L; - registerTool( this ); - m_cursor = new TQCursor( VCursor::createCursor( VCursor::CrossHair ) ); -} - -VTextTool::~VTextTool() -{ - delete m_optionsWidget; - delete m_editedText; - delete m_cursor; -} - -TQString VTextTool::contextHelp() -{ - TQString s = i18n( "Text Tool
" ); - s += i18n("Click on document to place horizontal text.
" ); - s += i18n("Click and drag in document to place directional text.
" ); - s += i18n("Click on a selected path object to place text along its outline.
" ); - s += i18n("Click on a selected text object to change it.
" ); - - return s; -} - -void -VTextTool::activate() -{ - VTool::activate(); - view()->statusMessage()->setText( i18n( "Text Tool" ) ); - view()->setCursor( *m_cursor ); - - m_creating = true; - m_text = 0L; - delete m_editedText; - m_editedText = 0L; -} - -void -VTextTool::deactivate() -{ -} - -void -VTextTool::draw( VPainter* painter ) -{ - if( m_editedText ) - m_editedText->draw( painter, &m_editedText->boundingBox() ); -} - -void -VTextTool::drawPathCreation() -{ - VPainter * painter = view()->painterFactory()->editpainter(); - - painter->setZoomFactor( view()->zoom() ); - - painter->setRasterOp( TQt::NotROP ); - painter->newPath(); - painter->setPen( TQt::DotLine ); - painter->setBrush( TQt::NoBrush ); - - painter->moveTo( first() ); - painter->lineTo( m_last ); - painter->strokePath(); -} - -void -VTextTool::drawEditedText() -{ - if( m_editedText ) - view()->repaintAll( m_editedText->boundingBox() ); -} - -void -VTextTool::mouseButtonPress() -{ - m_last = first(); - drawPathCreation(); - m_stepwise = false; -} - -void -VTextTool::mouseButtonRelease() -{ - if( ! view() ) - return; - - VSelection* selection = view()->part()->document().selection(); - VObject* selObj = selection->objects().getFirst(); - - // initialize dialog with single selected object - if( selection->objects().count() == 1 && selObj->boundingBox().contains( last() ) ) - m_optionsWidget->initialize( *selObj ); - else - { - // use a default horizontal path when just clicking - VSubpath path( 0L ); - path.moveTo( first() ); - path.lineTo( KoPoint( first().x()+10, first().y() ) ); - - if( ! createText( path ) ) - return; - } - - if( dynamic_cast( selObj ) && selObj->boundingBox().contains( last() ) ) - m_optionsWidget->setCaption( i18n( "Change Text") ); - else - m_optionsWidget->setCaption( i18n( "Insert Text") ); - - m_optionsWidget->show(); -} - -void -VTextTool::mouseDrag() -{ - drawPathCreation(); - - if( m_stepwise && shiftPressed() ) - { - KoPoint act = last(); - KoPoint dst = act - first(); - - double angle = atan2( dst.y(), dst.x() ); - if( angle < 0 ) - angle += VGlobal::twopi; - - // calculate previuos and next modulo 45 degree step - double prevStep = angle - fmod( angle, VGlobal::pi_2 / 2.0f ); - double nextStep = prevStep + VGlobal::pi_2 / 2.0f; - // calculate distance between first and last point - double length = sqrt( dst.x()*dst.x() + dst.y()*dst.y() ); - - // use nearest step - if( angle - prevStep < nextStep - angle ) - { - m_last.setX( first().x() + length * cos( prevStep ) ); - m_last.setY( first().y() + length * sin( prevStep ) ); - } - else - { - m_last.setX( first().x() + length * cos( nextStep ) ); - m_last.setY( first().y() + length * sin( nextStep ) ); - } - } - else - m_last = last(); - - drawPathCreation(); -} - -void -VTextTool::mouseDragRelease() -{ - drawPathCreation(); - - if( m_creating && m_editedText ) - { - drawEditedText(); - delete m_editedText; - m_editedText = 0L; - } - - // use dragged path to create text along - VSubpath path( 0L ); - path.moveTo( first() ); - path.lineTo( m_last ); - - if( createText( path ) ) - { - m_optionsWidget->setCaption( i18n( "Insert Text") ); - m_optionsWidget->show(); - } -} - -bool -VTextTool::createText( VSubpath &path ) -{ - // no original text is used - m_text = 0L; - delete m_editedText; - - m_editedText = new VText( m_optionsWidget->font(), path, m_optionsWidget->position(), m_optionsWidget->alignment(), m_optionsWidget->text() ); - - if( ! m_editedText ) - return false; - - m_editedText->setState( VObject::edit ); - -#ifdef HAVE_KARBONTEXT - m_editedText->traceText(); -#endif - - // yes, we are creating a new text object - m_creating = true; - - return true; -} - -void -VTextTool::textChanged() -{ - if( !m_editedText ) - return; - - if( !m_creating && m_text && m_text->state() != VObject::hidden ) - { - // hide the original text if we are changing it - m_text->setState( VObject::hidden ); - view()->repaintAll( m_text->boundingBox() ); - } - else - view()->repaintAll( m_editedText->boundingBox() ); - - m_editedText->setText( m_optionsWidget->text() ); - m_editedText->setFont( m_optionsWidget->font() ); - m_editedText->setPosition( m_optionsWidget->position() ); - m_editedText->setAlignment( m_optionsWidget->alignment() ); - m_editedText->setOffset( 0.01 * m_optionsWidget->offset() ); -#ifdef HAVE_KARBONTEXT - m_editedText->traceText(); -#endif - - drawEditedText(); -} - -void -VTextTool::accept() -{ - if( !m_editedText ) - return; - - VTextCmd* cmd; - - if( !m_creating ) - { - cmd = new VTextCmd( - &view()->part()->document(), - i18n( "Change Text" ), - m_text, - m_editedText->font(), - m_editedText->basePath(), - m_editedText->position(), - m_editedText->alignment(), - m_editedText->offset(), - m_editedText->text(), - m_optionsWidget->useShadow(), - m_optionsWidget->shadowAngle(), - m_optionsWidget->shadowDistance(), - m_optionsWidget->translucentShadow() ); - } - else - { - VText *newText = m_editedText->clone(); - newText->setUseShadow( m_optionsWidget->useShadow() ); - newText->setShadow( m_optionsWidget->shadowAngle(), m_optionsWidget->shadowDistance(), m_optionsWidget->translucentShadow() ); - - cmd = new VTextCmd( - &view()->part()->document(), - i18n( "Insert Text" ), - newText ); - - delete m_editedText; - m_editedText = 0L; - } - - view()->part()->addCommand( cmd, true ); - view()->part()->repaintAllViews(); - m_creating = false; -} - -void -VTextTool::cancel() -{ - if( m_text ) - { - // show original text if we canceled changing it - m_text->setState( VObject::selected ); - view()->repaintAll( m_text->boundingBox() ); - } - else - drawPathCreation(); - - delete m_editedText; - m_editedText = 0L; -} - -void -VTextTool::editBasePath() -{ - if( !m_editedText ) - return; - - view()->part()->document().selection()->clear(); - view()->part()->document().selection()->append( &m_editedText->basePath() ); - view()->part()->repaintAllViews(); -} - -void -VTextTool::convertToShapes() -{ - if( !m_text ) - return; - - VTextToCompositeCmd* cmd = new VTextToCompositeCmd( - &view()->part()->document(), - i18n( "Text Conversion" ), - m_text ); - - view()->part()->addCommand( cmd, true ); - - m_creating = false; - - delete m_editedText; - - m_text = 0L; - m_editedText = 0L; -} - -void -VTextTool::visitVPath( VPath& composite ) -{ - if( composite.paths().count() == 0 ) - return; - - if( createText( *composite.paths().getFirst() ) ) - drawEditedText(); -} - -void -VTextTool::visitVSubpath( VSubpath& path ) -{ - if( createText( path ) ) - drawEditedText(); -} - -void -VTextTool::visitVText( VText& text ) -{ - m_text = &text; - delete m_editedText; - m_editedText = text.clone(); - - m_optionsWidget->setFont( text.font() ); - m_optionsWidget->setText( text.text() ); - m_optionsWidget->setPosition( text.position() ); - m_optionsWidget->setAlignment( text.alignment() ); - m_optionsWidget->setOffset( text.offset() * 100.0 ); - m_optionsWidget->setUseShadow( text.useShadow() ); - m_optionsWidget->setShadow( text.shadowAngle(), text.shadowDistance(), text.translucentShadow() ); - m_creating = false; - m_text->setState( VObject::hidden ); - m_editedText->setState( VObject::edit ); -} - -VTextTool::VTextCmd::VTextCmd( VDocument* doc, const TQString& name, VText* text ) - : VCommand( doc, name, "14_text" ), m_text( text ) -{ - m_textModifications = 0L; - - m_executed = false; -} - -VTextTool::VTextCmd::VTextCmd( VDocument* doc, const TQString& name, VText* text, - const TQFont &newFont, const VSubpath& newBasePath, VText::Position newPosition, VText::Alignment newAlignment, double newOffset, const TQString& newText, - bool newUseShadow, int newShadowAngle, int newShadowDistance, bool newTranslucentShadow ) - : VCommand( doc, name, "14_text" ), m_text( text ) -{ - m_textModifications = new VTextModifPrivate(); - m_textModifications->newFont = newFont; - m_textModifications->oldFont = text->font(); - m_textModifications->newBasePath = newBasePath; - m_textModifications->oldBasePath = text->basePath(); - m_textModifications->newPosition = newPosition; - m_textModifications->oldPosition = text->position(); - m_textModifications->newAlignment = newAlignment; - m_textModifications->oldAlignment = text->alignment(); - m_textModifications->newOffset = newOffset; - m_textModifications->oldOffset = text->offset(); - m_textModifications->newText = newText; - m_textModifications->oldText = text->text(); - m_textModifications->newUseShadow = newUseShadow; - m_textModifications->oldUseShadow = text->useShadow(); - m_textModifications->newShadowAngle = newShadowAngle; - m_textModifications->oldShadowAngle = text->shadowAngle(); - m_textModifications->newShadowDistance = newShadowDistance; - m_textModifications->oldShadowDistance = text->shadowDistance(); - m_textModifications->newTranslucentShadow = newTranslucentShadow; - m_textModifications->oldTranslucentShadow = text->translucentShadow(); - - m_executed = false; -} - -VTextTool::VTextCmd::~VTextCmd() -{ - delete m_textModifications; -} - -void -VTextTool::VTextCmd::execute() -{ - if( !m_text ) - return; - - if( !m_textModifications ) - { - if( m_text->state() == VObject::deleted ) - m_text->setState( VObject::normal ); - else - { - m_text->setState( VObject::normal ); - document()->append( m_text ); - document()->selection()->clear(); - document()->selection()->append( m_text ); - } - } - else - { - m_text->setFont( m_textModifications->newFont ); - m_text->setBasePath( m_textModifications->newBasePath ); - m_text->setPosition( m_textModifications->newPosition ); - m_text->setAlignment( m_textModifications->newAlignment ); - m_text->setOffset( m_textModifications->newOffset ); - m_text->setText( m_textModifications->newText ); - m_text->setUseShadow( m_textModifications->newUseShadow ); - m_text->setShadow( m_textModifications->newShadowAngle, m_textModifications->newShadowDistance, m_textModifications->newTranslucentShadow ); - -#ifdef HAVE_KARBONTEXT - m_text->traceText(); -#endif - - m_text->setState( VObject::normal ); - } - - m_executed = true; - - setSuccess( true ); -} - -void -VTextTool::VTextCmd::unexecute() -{ - if( !m_text ) - return; - - if( !m_textModifications ) - { - document()->selection()->take( *m_text ); - m_text->setState( VObject::deleted ); - } - else - { - m_text->setFont( m_textModifications->oldFont ); - m_text->setBasePath( m_textModifications->oldBasePath ); - m_text->setPosition( m_textModifications->oldPosition ); - m_text->setAlignment( m_textModifications->oldAlignment ); - m_text->setOffset( m_textModifications->oldOffset ); - m_text->setText( m_textModifications->oldText ); - m_text->setUseShadow( m_textModifications->oldUseShadow ); - m_text->setShadow( m_textModifications->oldShadowAngle, m_textModifications->oldShadowDistance, m_textModifications->oldTranslucentShadow ); - -#ifdef HAVE_KARBONTEXT - m_text->traceText(); -#endif - - m_text->setState( VObject::normal ); - } - - m_executed = false; - - setSuccess( false ); -} - -VTextTool::VTextToCompositeCmd::VTextToCompositeCmd( VDocument* doc, const TQString& name, VText* text ) - : VCommand( doc, name, "14_text" ), m_text( text ), m_group( 0L ), m_executed( false ) -{ -} - -VTextTool::VTextToCompositeCmd::~VTextToCompositeCmd() -{ -} - -void -VTextTool::VTextToCompositeCmd::execute() -{ - if( !m_text ) - return; - - if( !m_group ) - { - m_group = m_text->toVGroup(); - document()->append( m_group ); - } - - m_text->setState( VObject::deleted ); - m_group->setState( VObject::normal ); - document()->selection()->clear(); - document()->selection()->append( m_group ); - - m_executed = true; - - setSuccess( true ); -} - -void -VTextTool::VTextToCompositeCmd::unexecute() -{ - if( !m_text ) - return; - - m_text->setState( VObject::normal ); - - document()->selection()->take( *m_group ); - - m_group->setState( VObject::deleted ); - - m_executed = false; - - setSuccess( false ); -} - -bool -VTextTool::showDialog() const -{ - VSelection* selection = view()->part()->document().selection(); - - // initialize dialog with single selected object - if( selection->objects().count() == 1 ) - m_optionsWidget->initialize( *selection->objects().getFirst()); - else - return false; - - if( dynamic_cast( selection->objects().getFirst() ) ) - m_optionsWidget->setCaption(i18n( "Change Text") ); - else - m_optionsWidget->setCaption(i18n( "Insert Text") ); - - m_optionsWidget->show(); - return true; -} - -void -VTextTool::mouseDragShiftPressed() -{ - m_stepwise = true; - mouseDrag(); -} - -void -VTextTool::mouseDragShiftReleased() -{ - m_stepwise = false; - mouseDrag(); -} - -void -VTextTool::setup( TDEActionCollection *collection ) -{ - m_action = static_cast(collection -> action( name() ) ); - - if( m_action == 0 ) - { - m_action = new TDERadioAction( i18n( "Text Tool" ), "14_text", TQt::SHIFT+TQt::Key_T, this, TQT_SLOT( activate() ), collection, name() ); - m_action->setToolTip( i18n( "Text Tool" ) ); - m_action->setExclusiveGroup( "misc" ); - //m_ownAction = true; - } -} - -#include "vtexttool.moc" - diff --git a/karbon/tools/vtexttool.cpp b/karbon/tools/vtexttool.cpp new file mode 100644 index 00000000..e7fa848d --- /dev/null +++ b/karbon/tools/vtexttool.cpp @@ -0,0 +1,1159 @@ +/* This file is part of the KDE project + Copyright (C) 2001, 2002, 2003 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 + +#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 "vtexttool.h" + + +static void +traceShape( VKoPainter* p, int x, int y, int w, int h ) +{ + p->newPath(); + p->moveTo( KoPoint( x + w , y + h ) ); + p->lineTo( KoPoint( x + w / 3, y + h ) ); + p->lineTo( KoPoint( x + w / 3, y + h / 3 ) ); + p->lineTo( KoPoint( x + w , y + h / 3 ) ); + p->lineTo( KoPoint( x + w , y + h ) ); + + p->moveTo( KoPoint( x , y ) ); + p->lineTo( KoPoint( x + ( w / 3 ) * 2, y ) ); + p->lineTo( KoPoint( x + ( w / 3 ) * 2, y + ( h / 3 ) * 2 ) ); + p->lineTo( KoPoint( x , y + ( h / 3 ) * 2 ) ); + p->lineTo( KoPoint( x , y ) ); +} + +ShadowPreview::ShadowPreview( ShadowWidget* parent ) + : TQWidget( parent ), m_parent( parent ) +{ + setBackgroundMode( TQt::NoBackground ); + setMinimumSize( 60, 60 ); + + connect( this, TQT_SIGNAL( changed( int, int, bool ) ), m_parent, TQT_SLOT( setShadowValues( int, int, bool ) ) ); +} + +ShadowPreview::~ShadowPreview() +{ +} + +void +ShadowPreview::mouseReleaseEvent( TQMouseEvent* e ) +{ + int dx = e->x() - width() / 2; + int dy = e->y() - height() / 2; + + float fd = sqrt( double( dx * dx + dy * dy ) ); + int a; + + if( fd == 0 ) + a = 0; + else if( dy == 0 && dx < 0 ) + a = 180; + else + { + float r = acos( dx / fd ); + a = int( ( dy <= 0 ? r : VGlobal::twopi - r ) / VGlobal::twopi * 360. ); + } + + emit changed( a, ( int ) fd, m_parent->isTranslucent() ); +} + +void +ShadowPreview::paintEvent( TQPaintEvent* ) +{ + int w = width() - 4; + int h = height() - 4; + int d = m_parent->shadowDistance(); + int a = 360 - m_parent->shadowAngle(); + + TQPixmap pm( w, h ); + VKoPainter p( TQT_TQPAINTDEVICE(&pm), w, h ); + VColor color( VColor::rgb ); + + VFill fill; + TDEIconLoader il; + fill.pattern() = VPattern( il.iconPath( "karbon.png", TDEIcon::Small ) ); + fill.setType( VFill::patt ); + + p.newPath(); + p.moveTo( KoPoint( 0, 0 ) ); + p.lineTo( KoPoint( 0, h ) ); + p.lineTo( KoPoint( w, h ) ); + p.lineTo( KoPoint( w, 0 ) ); + p.lineTo( KoPoint( 0, 0 ) ); + p.setBrush( fill ); + p.fillPath(); + + color.set( 1., 1., 1. ); + color.setOpacity( .5 ); + p.setBrush( VFill( color ) ); + p.fillPath(); + + if( m_parent->isTranslucent() ) + { + color.set( 0., 0., 0. ); + color.setOpacity( .3 ); + } + else + { + color.set( .3, .3, .3 ); + color.setOpacity( 1. ); + } + + p.setPen( VStroke( color ) ); + p.setBrush( VFill( color ) ); + + traceShape( + &p, + int( w / 4 + d * cos( a / 360. * VGlobal::twopi ) ), + int( h / 4 + d * sin( a / 360. * VGlobal::twopi ) ), int( w / 2 ), int( h / 2 ) ); + + p.strokePath(); + p.fillPath(); + + color.set( 0., 0., 1. ); + color.setOpacity( 1. ); + p.setBrush( VFill( color ) ); + color.set( 0., 0., .5 ); + p.setPen( VStroke( color ) ); + traceShape( &p, w / 4, h / 4, w / 2, h / 2 ); + p.strokePath(); + p.fillPath(); + + if( !m_parent->useShadow() ) + { + p.newPath(); + p.moveTo( KoPoint( 0, 0 ) ); + p.lineTo( KoPoint( 0, h ) ); + p.lineTo( KoPoint( w, h ) ); + p.lineTo( KoPoint( w, 0 ) ); + p.lineTo( KoPoint( 0, 0 ) ); + VColor c( colorGroup().background() ); + c.setOpacity( .8 ); + p.setBrush( VFill( c ) ); + p.fillPath(); + } + + p.end(); + + TQPainter painter( this ); + painter.drawPixmap( 2, 2, pm ); + painter.setPen( colorGroup().light() ); + painter.moveTo( 1, height() - 1 ); + painter.lineTo( 1, 1 ); + painter.lineTo( width() - 1, 1 ); + painter.lineTo( width() - 1, height() - 1 ); + painter.lineTo( 1, height() - 1 ); + painter.setPen( colorGroup().dark() ); + painter.moveTo( 0, height() - 1 ); + painter.lineTo( 0, 0 ); + painter.lineTo( width() - 1, 0 ); + painter.moveTo( width() - 2, 2 ); + painter.lineTo( width() - 2, height() - 2 ); + painter.lineTo( 2, height() - 2 ); + painter.setPen( TQt::black ); + painter.drawLine( width() / 2 - 2, height() / 2, width() / 2 + 2, height() / 2 ); + painter.drawLine( width() / 2, height() / 2 - 2, width() / 2, height() / 2 + 2 ); +} + +ShadowWidget::ShadowWidget( TQWidget* parent, const char* name, int angle, int distance, bool translucent ) + : TQGroupBox( parent, name ) +{ + setTitle( i18n( "Shadow" ) ); + setSizePolicy( TQSizePolicy( TQSizePolicy::Minimum, TQSizePolicy::Minimum ) ); + + TQGridLayout* layout = new TQGridLayout( this ); + layout->addRowSpacing( 0, 12 ); + layout->setMargin( 3 ); + layout->setSpacing( 2 ); + layout->setColStretch( 0, 1 ); + layout->setColStretch( 1, 0 ); + layout->setColStretch( 2, 2 ); + layout->addMultiCellWidget( m_preview = new ShadowPreview( this ), 1, 3, 0, 0 ); + layout->addWidget( new TQLabel( i18n( "Angle:" ), this ), 1, 1 ); + layout->addWidget( m_angle = new KIntNumInput( this ), 1, 2 ); + layout->addWidget( new TQLabel( i18n( "Distance:" ), this ), 2, 1 ); + layout->addWidget( m_distance = new KIntNumInput( this ), 2, 2 ); + layout->addWidget( m_useShadow = new TQCheckBox( i18n( "Shadow" ), this ), 3, 1 ); + layout->addWidget( m_translucent = new TQCheckBox( i18n( "Draw translucent shadow" ), this ), 3, 2 ); + m_distance->setRange( 1, 37, 1, true ); + m_angle->setRange( 0, 360, 10, true ); + m_angle->setValue( angle ); + m_distance->setValue( distance ); + m_translucent->setChecked( translucent ); + + connect( m_angle, TQT_SIGNAL( valueChanged( int ) ), this, TQT_SLOT( updatePreview( int ) ) ); + connect( m_distance, TQT_SIGNAL( valueChanged( int ) ), this, TQT_SLOT( updatePreview( int ) ) ); + connect( m_useShadow, TQT_SIGNAL( clicked() ), this, TQT_SLOT( updatePreview() ) ); + connect( m_translucent, TQT_SIGNAL( clicked() ), this, TQT_SLOT( updatePreview() ) ); + + updatePreview(); +} + +ShadowWidget::~ShadowWidget() +{ +} + +void +ShadowWidget::setUseShadow( bool use ) +{ + m_useShadow->setChecked( use ); + updatePreview(); +} + +bool ShadowWidget::useShadow() +{ + return m_useShadow->isChecked(); +} + +void +ShadowWidget::setShadowAngle( int angle ) +{ + m_angle->setValue( angle ); + m_preview->repaint(); +} + +int +ShadowWidget::shadowAngle() +{ + return m_angle->value(); +} + +void +ShadowWidget::setShadowDistance( int distance ) +{ + m_distance->setValue( distance ); + m_preview->repaint(); +} + +int +ShadowWidget::shadowDistance() +{ + return m_distance->value(); +} + +void +ShadowWidget::setTranslucent( bool translucent ) +{ + m_translucent->setChecked( translucent ); + m_preview->repaint(); +} + +bool ShadowWidget::isTranslucent() +{ + return m_translucent->isChecked(); +} + +void +ShadowWidget::setShadowValues( int angle, int distance, bool translucent ) +{ + m_angle->setValue( angle ); + m_distance->setValue( distance ); + m_translucent->setChecked( translucent ); + updatePreview(); +} + +void +ShadowWidget::updatePreview( int ) +{ + m_preview->repaint(); +} + +void +ShadowWidget::updatePreview() +{ + m_preview->repaint(); + bool ok = m_useShadow->isChecked(); + m_angle->setEnabled( ok ); + m_distance->setEnabled( ok ); + m_translucent->setEnabled( ok ); +} + +VTextOptionsWidget::VTextOptionsWidget( VTextTool* tool, TQWidget *parent ) + : KDialogBase( parent, "", true, i18n( "Text" ), Ok | Cancel ), m_tool( tool ) +{ + //setSizePolicy( TQSizePolicy( TQSizePolicy::Minimum, TQSizePolicy::Minimum ) ); + //setFrameStyle( Box | Sunken ); + TQWidget *base = new TQWidget( this ); + TQVBoxLayout* mainLayout = new TQVBoxLayout( base ); + mainLayout->setMargin( 3 ); + + mainLayout->add( m_tabWidget = new TQTabWidget( base ) ); + + m_tabWidget->setFont( TQFont( TDEGlobalSettings::generalFont().family() , 8 ) ); + + TQWidget* textWidget = new TQWidget( m_tabWidget ); + + TQGridLayout* textLayout = new TQGridLayout( textWidget ); + + TQStringList list; + TDEFontChooser::getFontList( list, TDEFontChooser::SmoothScalableFonts ); + + textLayout->setMargin( 3 ); + textLayout->setSpacing( 2 ); + textLayout->addMultiCellWidget( m_fontCombo = new TDEFontCombo( list, textWidget ), 0, 0, 0, 2 ); + textLayout->addWidget( m_fontSize = new KIntNumInput( textWidget ), 1, 0 ); + textLayout->addWidget( m_boldCheck = new TQCheckBox( i18n( "Bold" ), textWidget ), 1, 1 ); + textLayout->addWidget( m_italicCheck = new TQCheckBox( i18n( "Italic" ), textWidget ), 1, 2 ); + textLayout->addMultiCellWidget( m_textEditor = new TQLineEdit( textWidget ), 2, 2, 0, 2 ); + + m_tabWidget->addTab( textWidget, i18n( "Text" ) ); + + TQWidget* posWidget = new TQWidget( m_tabWidget ); + + TQGridLayout* posLayout = new TQGridLayout( posWidget ); + textLayout->setMargin( 3 ); + posLayout->setSpacing( 2 ); + posLayout->addWidget( new TQLabel( i18n( "Alignment:" ), posWidget ), 0, 0 ); + posLayout->addWidget( m_textAlignment = new TQComboBox( posWidget ), 0, 1 ); + posLayout->addWidget( new TQLabel( i18n( "Position:" ), posWidget ), 1, 0 ); + posLayout->addWidget( m_textPosition = new TQComboBox( posWidget ), 1, 1 ); + posLayout->addWidget( new TQLabel( i18n( "Offset:" ), posWidget ), 2, 0 ); + posLayout->addWidget( m_textOffset = new KDoubleNumInput( posWidget ), 2, 1 ); + posLayout->setColStretch( 0, 0 ); + posLayout->setColStretch( 1, 1 ); + + m_tabWidget->addTab( posWidget, i18n( "Position" ) ); + + TQWidget* fxWidget = new TQWidget( m_tabWidget ); + + TQVBoxLayout* fxLayout = new TQVBoxLayout( fxWidget ); + + fxLayout->setMargin( 3 ); + fxLayout->setSpacing( 2 ); + fxLayout->add( m_shadow = new ShadowWidget( fxWidget, 0L, 315, 4, true ) ); + + TQHBoxLayout* fxLayout2 = new TQHBoxLayout( fxLayout ); + + fxLayout2->setSpacing( 2 ); + fxLayout2->addWidget( m_editBasePath = new TQPushButton( i18n( "Edit Base Path" ), fxWidget ) ); + fxLayout2->addWidget( m_convertToShapes = new TQPushButton( i18n( "Convert to Shapes" ), fxWidget ) ); + + m_tabWidget->addTab( fxWidget, i18n( "Effects" ) ); + + m_fontCombo->setCurrentText( TDEGlobalSettings::generalFont().family() ); + + m_fontSize->setValue( 12 ); + m_fontSize->setSuffix( " pt" ); + + m_textEditor->setMinimumHeight( 100 ); + m_textEditor->setText( i18n( "New text") ); + m_textEditor->selectAll(); + + m_convertToShapes->setEnabled( true ); + + m_textAlignment->insertItem( i18n( "Horizontal alignment", "Left") ); + m_textAlignment->insertItem( i18n( "Horizontal alignment", "Center") ); + m_textAlignment->insertItem( i18n( "Horizontal alignment", "Right") ); + + m_textPosition->insertItem( i18n( "Vertical alignment", "Above") ); + m_textPosition->insertItem( i18n( "Vertical alignment", "On") ); + m_textPosition->insertItem( i18n( "Vertical alignment", "Under") ); + + m_textOffset->setRange( 0.0, 100.0, 1.0, true ); + + connect( m_fontCombo, TQT_SIGNAL( activated( int ) ), this, TQT_SLOT( valueChanged( int ) ) ); + connect( m_boldCheck, TQT_SIGNAL( stateChanged( int ) ), this, TQT_SLOT( valueChanged( int ) ) ); + connect( m_italicCheck, TQT_SIGNAL( stateChanged( int ) ), this, TQT_SLOT( valueChanged( int ) ) ); + connect( m_fontSize, TQT_SIGNAL( valueChanged( int ) ), this, TQT_SLOT( valueChanged( int ) ) ); + connect( m_textPosition, TQT_SIGNAL( activated( int ) ), this, TQT_SLOT( valueChanged( int ) ) ); + connect( m_textAlignment, TQT_SIGNAL( activated( int ) ), this, TQT_SLOT( valueChanged( int ) ) ); + connect( m_textOffset, TQT_SIGNAL( valueChanged( double ) ), this, TQT_SLOT( valueChanged( double ) ) ); + connect( m_textEditor, TQT_SIGNAL( returnPressed() ), this, TQT_SLOT( accept() ) ); + connect( m_textEditor, TQT_SIGNAL( textChanged( const TQString& ) ), this, TQT_SLOT( textChanged( const TQString& ) ) ); + connect( m_editBasePath, TQT_SIGNAL( clicked() ), this, TQT_SLOT( editBasePath() ) ); + connect( m_convertToShapes, TQT_SIGNAL( clicked() ), this, TQT_SLOT( convertToShapes() ) ); + connect( this, TQT_SIGNAL( cancelClicked() ), this, TQT_SLOT( cancel() ) ); + + setMainWidget( base ); + setFixedSize( baseSize() ); +} + +VTextOptionsWidget::~VTextOptionsWidget() +{ +} + +void +VTextOptionsWidget::valueChanged( int ) +{ + m_fontCombo->setBold( m_boldCheck->isChecked() ); + m_fontCombo->setItalic( m_italicCheck->isChecked() ); + + m_textEditor->setFont( TQFont( m_fontCombo->currentText(), m_fontSize->value(), ( m_boldCheck->isChecked() ? 75 : 50 ), m_italicCheck->isChecked() ) ); + + if( m_tool && isVisible() ) + m_tool->textChanged(); +} + +void +VTextOptionsWidget::valueChanged( double ) +{ + if( m_tool && isVisible() ) + m_tool->textChanged(); +} + +void +VTextOptionsWidget::accept() +{ + if( m_tool ) + m_tool->accept(); + hide(); +} + +void +VTextOptionsWidget::cancel() +{ + if( m_tool ) + m_tool->cancel(); +} + +void +VTextOptionsWidget::textChanged( const TQString& ) +{ + if( m_tool && isVisible() ) + m_tool->textChanged(); +} + +void +VTextOptionsWidget::editBasePath() +{ + if( m_tool ) + m_tool->editBasePath(); +} + +void +VTextOptionsWidget::convertToShapes() +{ + if( m_tool ) + m_tool->convertToShapes(); +} + +void +VTextOptionsWidget::setFont( const TQFont& font ) +{ + m_fontCombo->setCurrentText( font.family() ); + + m_boldCheck->setChecked( font.bold() ); + + m_italicCheck->setChecked( font.italic() ); + + m_fontSize->setValue( font.pointSize() ); + + m_fontCombo->setBold( m_boldCheck->isChecked() ); + m_fontCombo->setItalic( m_italicCheck->isChecked() ); + + m_textEditor->setFont( TQFont( m_fontCombo->currentText(), m_fontSize->value(), ( m_boldCheck->isChecked() ? 75 : 50 ), m_italicCheck->isChecked() ) ); +} + +TQFont VTextOptionsWidget::font() +{ + return TQFont( m_fontCombo->currentText(), m_fontSize->value(), ( m_boldCheck->isChecked() ? 75 : 50 ), m_italicCheck->isChecked() ); +} + +void +VTextOptionsWidget::setText( const TQString& text ) +{ + m_textEditor->setText( text ); +} + +TQString VTextOptionsWidget::text() +{ + return m_textEditor->text(); +} + +void +VTextOptionsWidget::setPosition( VText::Position position ) +{ + m_textPosition->setCurrentItem( position ); +} + +VText::Position VTextOptionsWidget::position() +{ + return ( VText::Position ) m_textPosition->currentItem(); +} + +void +VTextOptionsWidget::setAlignment( VText::Alignment alignment ) +{ + m_textAlignment->setCurrentItem( alignment ); +} + +VText::Alignment VTextOptionsWidget::alignment() +{ + return ( VText::Alignment ) m_textAlignment->currentItem(); +} + +void +VTextOptionsWidget::setOffset( double offset ) +{ + if( offset < 0.0 ) offset = 0.0; + if( offset > 100.0 ) offset = 100.0; + + m_textOffset->setValue( offset ); +} +double +VTextOptionsWidget::offset() +{ + return m_textOffset->value(); +} + +void +VTextOptionsWidget::setUseShadow( bool state ) +{ + m_shadow->setUseShadow( state ); +} + +bool VTextOptionsWidget::useShadow() +{ + return m_shadow->useShadow(); +} + +void +VTextOptionsWidget::setShadow( int angle, int distance, bool translucent ) +{ + m_shadow->setShadowValues( angle, distance, translucent ); +} + +bool VTextOptionsWidget::translucentShadow() +{ + return m_shadow->isTranslucent(); +} + +int +VTextOptionsWidget::shadowAngle() +{ + return m_shadow->shadowAngle(); +} + +int +VTextOptionsWidget::shadowDistance() +{ + return m_shadow->shadowDistance(); +} + +void +VTextOptionsWidget::initialize( VObject &text ) +{ + if( m_tool ) + m_tool->visit( text ); +} + +VTextTool::VTextTool( KarbonView *view ) + : VTool( view, "tool_text" ) +{ + m_optionsWidget = new VTextOptionsWidget( this, 0L ); + m_text = 0L; + m_editedText = 0L; + registerTool( this ); + m_cursor = new TQCursor( VCursor::createCursor( VCursor::CrossHair ) ); +} + +VTextTool::~VTextTool() +{ + delete m_optionsWidget; + delete m_editedText; + delete m_cursor; +} + +TQString VTextTool::contextHelp() +{ + TQString s = i18n( "Text Tool
" ); + s += i18n("Click on document to place horizontal text.
" ); + s += i18n("Click and drag in document to place directional text.
" ); + s += i18n("Click on a selected path object to place text along its outline.
" ); + s += i18n("Click on a selected text object to change it.
" ); + + return s; +} + +void +VTextTool::activate() +{ + VTool::activate(); + view()->statusMessage()->setText( i18n( "Text Tool" ) ); + view()->setCursor( *m_cursor ); + + m_creating = true; + m_text = 0L; + delete m_editedText; + m_editedText = 0L; +} + +void +VTextTool::deactivate() +{ +} + +void +VTextTool::draw( VPainter* painter ) +{ + if( m_editedText ) + m_editedText->draw( painter, &m_editedText->boundingBox() ); +} + +void +VTextTool::drawPathCreation() +{ + VPainter * painter = view()->painterFactory()->editpainter(); + + painter->setZoomFactor( view()->zoom() ); + + painter->setRasterOp( TQt::NotROP ); + painter->newPath(); + painter->setPen( TQt::DotLine ); + painter->setBrush( TQt::NoBrush ); + + painter->moveTo( first() ); + painter->lineTo( m_last ); + painter->strokePath(); +} + +void +VTextTool::drawEditedText() +{ + if( m_editedText ) + view()->repaintAll( m_editedText->boundingBox() ); +} + +void +VTextTool::mouseButtonPress() +{ + m_last = first(); + drawPathCreation(); + m_stepwise = false; +} + +void +VTextTool::mouseButtonRelease() +{ + if( ! view() ) + return; + + VSelection* selection = view()->part()->document().selection(); + VObject* selObj = selection->objects().getFirst(); + + // initialize dialog with single selected object + if( selection->objects().count() == 1 && selObj->boundingBox().contains( last() ) ) + m_optionsWidget->initialize( *selObj ); + else + { + // use a default horizontal path when just clicking + VSubpath path( 0L ); + path.moveTo( first() ); + path.lineTo( KoPoint( first().x()+10, first().y() ) ); + + if( ! createText( path ) ) + return; + } + + if( dynamic_cast( selObj ) && selObj->boundingBox().contains( last() ) ) + m_optionsWidget->setCaption( i18n( "Change Text") ); + else + m_optionsWidget->setCaption( i18n( "Insert Text") ); + + m_optionsWidget->show(); +} + +void +VTextTool::mouseDrag() +{ + drawPathCreation(); + + if( m_stepwise && shiftPressed() ) + { + KoPoint act = last(); + KoPoint dst = act - first(); + + double angle = atan2( dst.y(), dst.x() ); + if( angle < 0 ) + angle += VGlobal::twopi; + + // calculate previuos and next modulo 45 degree step + double prevStep = angle - fmod( angle, VGlobal::pi_2 / 2.0f ); + double nextStep = prevStep + VGlobal::pi_2 / 2.0f; + // calculate distance between first and last point + double length = sqrt( dst.x()*dst.x() + dst.y()*dst.y() ); + + // use nearest step + if( angle - prevStep < nextStep - angle ) + { + m_last.setX( first().x() + length * cos( prevStep ) ); + m_last.setY( first().y() + length * sin( prevStep ) ); + } + else + { + m_last.setX( first().x() + length * cos( nextStep ) ); + m_last.setY( first().y() + length * sin( nextStep ) ); + } + } + else + m_last = last(); + + drawPathCreation(); +} + +void +VTextTool::mouseDragRelease() +{ + drawPathCreation(); + + if( m_creating && m_editedText ) + { + drawEditedText(); + delete m_editedText; + m_editedText = 0L; + } + + // use dragged path to create text along + VSubpath path( 0L ); + path.moveTo( first() ); + path.lineTo( m_last ); + + if( createText( path ) ) + { + m_optionsWidget->setCaption( i18n( "Insert Text") ); + m_optionsWidget->show(); + } +} + +bool +VTextTool::createText( VSubpath &path ) +{ + // no original text is used + m_text = 0L; + delete m_editedText; + + m_editedText = new VText( m_optionsWidget->font(), path, m_optionsWidget->position(), m_optionsWidget->alignment(), m_optionsWidget->text() ); + + if( ! m_editedText ) + return false; + + m_editedText->setState( VObject::edit ); + +#ifdef HAVE_KARBONTEXT + m_editedText->traceText(); +#endif + + // yes, we are creating a new text object + m_creating = true; + + return true; +} + +void +VTextTool::textChanged() +{ + if( !m_editedText ) + return; + + if( !m_creating && m_text && m_text->state() != VObject::hidden ) + { + // hide the original text if we are changing it + m_text->setState( VObject::hidden ); + view()->repaintAll( m_text->boundingBox() ); + } + else + view()->repaintAll( m_editedText->boundingBox() ); + + m_editedText->setText( m_optionsWidget->text() ); + m_editedText->setFont( m_optionsWidget->font() ); + m_editedText->setPosition( m_optionsWidget->position() ); + m_editedText->setAlignment( m_optionsWidget->alignment() ); + m_editedText->setOffset( 0.01 * m_optionsWidget->offset() ); +#ifdef HAVE_KARBONTEXT + m_editedText->traceText(); +#endif + + drawEditedText(); +} + +void +VTextTool::accept() +{ + if( !m_editedText ) + return; + + VTextCmd* cmd; + + if( !m_creating ) + { + cmd = new VTextCmd( + &view()->part()->document(), + i18n( "Change Text" ), + m_text, + m_editedText->font(), + m_editedText->basePath(), + m_editedText->position(), + m_editedText->alignment(), + m_editedText->offset(), + m_editedText->text(), + m_optionsWidget->useShadow(), + m_optionsWidget->shadowAngle(), + m_optionsWidget->shadowDistance(), + m_optionsWidget->translucentShadow() ); + } + else + { + VText *newText = m_editedText->clone(); + newText->setUseShadow( m_optionsWidget->useShadow() ); + newText->setShadow( m_optionsWidget->shadowAngle(), m_optionsWidget->shadowDistance(), m_optionsWidget->translucentShadow() ); + + cmd = new VTextCmd( + &view()->part()->document(), + i18n( "Insert Text" ), + newText ); + + delete m_editedText; + m_editedText = 0L; + } + + view()->part()->addCommand( cmd, true ); + view()->part()->repaintAllViews(); + m_creating = false; +} + +void +VTextTool::cancel() +{ + if( m_text ) + { + // show original text if we canceled changing it + m_text->setState( VObject::selected ); + view()->repaintAll( m_text->boundingBox() ); + } + else + drawPathCreation(); + + delete m_editedText; + m_editedText = 0L; +} + +void +VTextTool::editBasePath() +{ + if( !m_editedText ) + return; + + view()->part()->document().selection()->clear(); + view()->part()->document().selection()->append( &m_editedText->basePath() ); + view()->part()->repaintAllViews(); +} + +void +VTextTool::convertToShapes() +{ + if( !m_text ) + return; + + VTextToCompositeCmd* cmd = new VTextToCompositeCmd( + &view()->part()->document(), + i18n( "Text Conversion" ), + m_text ); + + view()->part()->addCommand( cmd, true ); + + m_creating = false; + + delete m_editedText; + + m_text = 0L; + m_editedText = 0L; +} + +void +VTextTool::visitVPath( VPath& composite ) +{ + if( composite.paths().count() == 0 ) + return; + + if( createText( *composite.paths().getFirst() ) ) + drawEditedText(); +} + +void +VTextTool::visitVSubpath( VSubpath& path ) +{ + if( createText( path ) ) + drawEditedText(); +} + +void +VTextTool::visitVText( VText& text ) +{ + m_text = &text; + delete m_editedText; + m_editedText = text.clone(); + + m_optionsWidget->setFont( text.font() ); + m_optionsWidget->setText( text.text() ); + m_optionsWidget->setPosition( text.position() ); + m_optionsWidget->setAlignment( text.alignment() ); + m_optionsWidget->setOffset( text.offset() * 100.0 ); + m_optionsWidget->setUseShadow( text.useShadow() ); + m_optionsWidget->setShadow( text.shadowAngle(), text.shadowDistance(), text.translucentShadow() ); + m_creating = false; + m_text->setState( VObject::hidden ); + m_editedText->setState( VObject::edit ); +} + +VTextTool::VTextCmd::VTextCmd( VDocument* doc, const TQString& name, VText* text ) + : VCommand( doc, name, "14_text" ), m_text( text ) +{ + m_textModifications = 0L; + + m_executed = false; +} + +VTextTool::VTextCmd::VTextCmd( VDocument* doc, const TQString& name, VText* text, + const TQFont &newFont, const VSubpath& newBasePath, VText::Position newPosition, VText::Alignment newAlignment, double newOffset, const TQString& newText, + bool newUseShadow, int newShadowAngle, int newShadowDistance, bool newTranslucentShadow ) + : VCommand( doc, name, "14_text" ), m_text( text ) +{ + m_textModifications = new VTextModifPrivate(); + m_textModifications->newFont = newFont; + m_textModifications->oldFont = text->font(); + m_textModifications->newBasePath = newBasePath; + m_textModifications->oldBasePath = text->basePath(); + m_textModifications->newPosition = newPosition; + m_textModifications->oldPosition = text->position(); + m_textModifications->newAlignment = newAlignment; + m_textModifications->oldAlignment = text->alignment(); + m_textModifications->newOffset = newOffset; + m_textModifications->oldOffset = text->offset(); + m_textModifications->newText = newText; + m_textModifications->oldText = text->text(); + m_textModifications->newUseShadow = newUseShadow; + m_textModifications->oldUseShadow = text->useShadow(); + m_textModifications->newShadowAngle = newShadowAngle; + m_textModifications->oldShadowAngle = text->shadowAngle(); + m_textModifications->newShadowDistance = newShadowDistance; + m_textModifications->oldShadowDistance = text->shadowDistance(); + m_textModifications->newTranslucentShadow = newTranslucentShadow; + m_textModifications->oldTranslucentShadow = text->translucentShadow(); + + m_executed = false; +} + +VTextTool::VTextCmd::~VTextCmd() +{ + delete m_textModifications; +} + +void +VTextTool::VTextCmd::execute() +{ + if( !m_text ) + return; + + if( !m_textModifications ) + { + if( m_text->state() == VObject::deleted ) + m_text->setState( VObject::normal ); + else + { + m_text->setState( VObject::normal ); + document()->append( m_text ); + document()->selection()->clear(); + document()->selection()->append( m_text ); + } + } + else + { + m_text->setFont( m_textModifications->newFont ); + m_text->setBasePath( m_textModifications->newBasePath ); + m_text->setPosition( m_textModifications->newPosition ); + m_text->setAlignment( m_textModifications->newAlignment ); + m_text->setOffset( m_textModifications->newOffset ); + m_text->setText( m_textModifications->newText ); + m_text->setUseShadow( m_textModifications->newUseShadow ); + m_text->setShadow( m_textModifications->newShadowAngle, m_textModifications->newShadowDistance, m_textModifications->newTranslucentShadow ); + +#ifdef HAVE_KARBONTEXT + m_text->traceText(); +#endif + + m_text->setState( VObject::normal ); + } + + m_executed = true; + + setSuccess( true ); +} + +void +VTextTool::VTextCmd::unexecute() +{ + if( !m_text ) + return; + + if( !m_textModifications ) + { + document()->selection()->take( *m_text ); + m_text->setState( VObject::deleted ); + } + else + { + m_text->setFont( m_textModifications->oldFont ); + m_text->setBasePath( m_textModifications->oldBasePath ); + m_text->setPosition( m_textModifications->oldPosition ); + m_text->setAlignment( m_textModifications->oldAlignment ); + m_text->setOffset( m_textModifications->oldOffset ); + m_text->setText( m_textModifications->oldText ); + m_text->setUseShadow( m_textModifications->oldUseShadow ); + m_text->setShadow( m_textModifications->oldShadowAngle, m_textModifications->oldShadowDistance, m_textModifications->oldTranslucentShadow ); + +#ifdef HAVE_KARBONTEXT + m_text->traceText(); +#endif + + m_text->setState( VObject::normal ); + } + + m_executed = false; + + setSuccess( false ); +} + +VTextTool::VTextToCompositeCmd::VTextToCompositeCmd( VDocument* doc, const TQString& name, VText* text ) + : VCommand( doc, name, "14_text" ), m_text( text ), m_group( 0L ), m_executed( false ) +{ +} + +VTextTool::VTextToCompositeCmd::~VTextToCompositeCmd() +{ +} + +void +VTextTool::VTextToCompositeCmd::execute() +{ + if( !m_text ) + return; + + if( !m_group ) + { + m_group = m_text->toVGroup(); + document()->append( m_group ); + } + + m_text->setState( VObject::deleted ); + m_group->setState( VObject::normal ); + document()->selection()->clear(); + document()->selection()->append( m_group ); + + m_executed = true; + + setSuccess( true ); +} + +void +VTextTool::VTextToCompositeCmd::unexecute() +{ + if( !m_text ) + return; + + m_text->setState( VObject::normal ); + + document()->selection()->take( *m_group ); + + m_group->setState( VObject::deleted ); + + m_executed = false; + + setSuccess( false ); +} + +bool +VTextTool::showDialog() const +{ + VSelection* selection = view()->part()->document().selection(); + + // initialize dialog with single selected object + if( selection->objects().count() == 1 ) + m_optionsWidget->initialize( *selection->objects().getFirst()); + else + return false; + + if( dynamic_cast( selection->objects().getFirst() ) ) + m_optionsWidget->setCaption(i18n( "Change Text") ); + else + m_optionsWidget->setCaption(i18n( "Insert Text") ); + + m_optionsWidget->show(); + return true; +} + +void +VTextTool::mouseDragShiftPressed() +{ + m_stepwise = true; + mouseDrag(); +} + +void +VTextTool::mouseDragShiftReleased() +{ + m_stepwise = false; + mouseDrag(); +} + +void +VTextTool::setup( TDEActionCollection *collection ) +{ + m_action = static_cast(collection -> action( name() ) ); + + if( m_action == 0 ) + { + m_action = new TDERadioAction( i18n( "Text Tool" ), "14_text", TQt::SHIFT+TQt::Key_T, this, TQT_SLOT( activate() ), collection, name() ); + m_action->setToolTip( i18n( "Text Tool" ) ); + m_action->setExclusiveGroup( "misc" ); + //m_ownAction = true; + } +} + +#include "vtexttool.moc" + -- cgit v1.2.1