From ce599e4f9f94b4eb00c1b5edb85bce5431ab3df2 Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdeedu@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- kig/objects/text_type.cc | 215 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 215 insertions(+) create mode 100644 kig/objects/text_type.cc (limited to 'kig/objects/text_type.cc') diff --git a/kig/objects/text_type.cc b/kig/objects/text_type.cc new file mode 100644 index 00000000..6594c05a --- /dev/null +++ b/kig/objects/text_type.cc @@ -0,0 +1,215 @@ +// Copyright (C) 2003 Dominique Devriese + +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +// 02110-1301, USA. + +#include "text_type.h" + +#include "text_imp.h" +#include "bogus_imp.h" +#include "point_imp.h" +#include "line_imp.h" + +#include "../kig/kig_view.h" +#include "../kig/kig_part.h" +#include "../kig/kig_commands.h" +#include "../modes/label.h" +#include "../misc/coordinate_system.h" + +#include + +#include +#include + +#include + +#include + +static const ArgsParser::spec arggspeccs[] = +{ + { IntImp::stype(), "UNUSED", "SHOULD NOT BE SEEN", false }, + { PointImp::stype(), "UNUSED", "SHOULD NOT BE SEEN", false }, + { StringImp::stype(), "UNUSED", "SHOULD NOT BE SEEN", false } +}; + +KIG_INSTANTIATE_OBJECT_TYPE_INSTANCE( TextType ) + +TextType::TextType() + : ObjectType( "Label" ), mparser( arggspeccs, 3 ) +{ +} + +TextType::~TextType() +{ +} + +const TextType* TextType::instance() +{ + static const TextType t; + return &t; +} + +const ObjectImpType* TextType::resultId() const +{ + return TextImp::stype(); +} + +const ObjectImpType* TextType::impRequirement( const ObjectImp* o, const Args& args ) const +{ + assert( args.size() >= 3 ); + Args firstthree( args.begin(), args.begin() + 3 ); + if ( o == args[0] || o == args[1] || o == args[2] ) + return mparser.impRequirement( o, firstthree ); + else + return ObjectImp::stype(); +} + +ObjectImp* TextType::calc( const Args& parents, const KigDocument& doc ) const +{ + if( parents.size() < 3 ) return new InvalidImp; + Args firstthree( parents.begin(), parents.begin() + 3 ); + Args varargs( parents.begin() + 3, parents.end() ); + + if ( ! mparser.checkArgs( firstthree ) ) return new InvalidImp; + + int frame = static_cast( firstthree[0] )->data(); + bool needframe = frame != 0; + const Coordinate t = static_cast( firstthree[1] )->coordinate(); + QString s = static_cast( firstthree[2] )->data(); + + for ( Args::iterator i = varargs.begin(); i != varargs.end(); ++i ) + (*i)->fillInNextEscape( s, doc ); + + return new TextImp( s, t, needframe ); +} + +bool TextType::canMove( const ObjectTypeCalcer& ) const +{ + return true; +} + +bool TextType::isFreelyTranslatable( const ObjectTypeCalcer& ) const +{ + return true; +} + +void TextType::move( ObjectTypeCalcer& ourobj, const Coordinate& to, + const KigDocument& d ) const +{ + const std::vector parents = ourobj.parents(); + assert( parents.size() >= 3 ); + const std::vector firstthree( parents.begin(), parents.begin() + 3 ); + if( dynamic_cast( firstthree[1] ) ) + { + ObjectConstCalcer* c = static_cast( firstthree[1] ); + c->setImp( new PointImp( to ) ); + } + else + firstthree[1]->move( to, d ); +} + +QStringList TextType::specialActions() const +{ + QStringList ret; + ret << i18n( "&Copy Text" ); + ret << i18n( "&Toggle Frame" ); + ret << i18n( "&Redefine..." ); + return ret; +} + +void TextType::executeAction( int i, ObjectHolder& o, ObjectTypeCalcer& c, + KigPart& doc, KigWidget&, + NormalMode& ) const +{ + std::vector parents = c.parents(); + assert( parents.size() >= 3 ); + + std::vector firstthree( parents.begin(), parents.begin() + 3 ); + + assert( mparser.checkArgs( firstthree ) ); + assert( dynamic_cast( firstthree[0] ) ); + assert( dynamic_cast( firstthree[2] ) ); + + if ( i == 0 ) + { + QClipboard* cb = kapp->clipboard(); + + // copy the text into the clipboard + const TextImp* ti = static_cast( c.imp() ); + cb->setText( ti->text(), QClipboard::Clipboard ); + } + else if ( i == 1 ) + { + // toggle label frame + int n = (static_cast( firstthree[0]->imp() )->data() + 1) % 2; + KigCommand* kc = new KigCommand( doc, i18n( "Toggle Label Frame" ) ); + kc->addTask( new ChangeObjectConstCalcerTask( + static_cast( firstthree[0] ), + new IntImp( n ) ) ); + doc.history()->addCommand( kc ); + } + else if ( i == 2 ) + { + assert( dynamic_cast( o.calcer() ) ); + // redefine.. + TextLabelRedefineMode m( doc, static_cast( o.calcer() ) ); + doc.runMode( &m ); + } + else assert( false ); +} + +const ArgsParser& TextType::argParser() const +{ + return mparser; +} + +const Coordinate TextType::moveReferencePoint( const ObjectTypeCalcer& ourobj ) const +{ + assert( ourobj.imp()->inherits( TextImp::stype() ) ); + return static_cast( ourobj.imp() )->coordinate(); +} + +std::vector TextType::sortArgs( const std::vector& os ) const +{ + assert( os.size() >= 3 ); + std::vector ret( os.begin(), os.begin() + 3 ); + ret = mparser.parse( ret ); + std::copy( os.begin() + 3, os.end(), std::back_inserter( ret ) ); + return ret; +} + +Args TextType::sortArgs( const Args& args ) const +{ + assert( args.size() >= 3 ); + Args ret( args.begin(), args.begin() + 3 ); + ret = mparser.parse( ret ); + std::copy( args.begin() + 3, args.end(), std::back_inserter( ret ) ); + return ret; +} + +std::vector TextType::movableParents( const ObjectTypeCalcer& ourobj ) const +{ + const std::vector parents = ourobj.parents(); + assert( parents.size() >= 3 ); + std::vector ret = parents[1]->movableParents(); + ret.push_back( parents[1] ); + return ret; +} + +bool TextType::isDefinedOnOrThrough( const ObjectImp*, const Args& ) const +{ + return false; +} + -- cgit v1.2.1