1 // SPDX-FileCopyrightText: 2002 Dominique Devriese <devriese@kde.org> 2 3 // SPDX-License-Identifier: GPL-2.0-or-later 4 5 #ifndef MOVING_H 6 #define MOVING_H 7 8 #include "mode.h" 9 10 #include "../misc/coordinate.h" 11 #include "../objects/object_calcer.h" 12 13 class ObjectType; 14 class Coordinate; 15 class NormalPoint; 16 class KigWidget; 17 class MonitorDataObjects; 18 19 /** 20 * "Template method" pattern ( see the Design patterns book ): 21 * This is a base class for two modes: normal MovingMode: used for 22 * moving a set of objects around, using Object::startMove, 23 * Object::moveTo and Object::stopMove, and another mode 24 * PointRedefineMode, used for redefining a NormalPoint... 25 */ 26 class MovingModeBase 27 : public KigMode 28 { 29 protected: 30 KigWidget& mview; 31 private: 32 // all moving objects: these objects are all of the objects that 33 // need to be redrawn every time the cursor moves, and after calc is 34 // called. 35 std::vector<ObjectCalcer*> mcalcable; 36 std::vector<ObjectHolder*> mdrawable; 37 protected: 38 MovingModeBase( KigPart& doc, KigWidget& v ); 39 ~MovingModeBase(); 40 41 /** 42 * Subclasses should call this in their constructor, when they know 43 * which objects will be moving around... They are expected to be in 44 * the right order for being calc()'ed... 45 */ 46 void initScreen( const std::vector<ObjectCalcer*>& amo ); 47 48 // in these functions, subclasses should do the equivalent of 49 // Object::stopMove() and moveTo()... Note that no calc()'ing or 50 // drawing is to be done.. 51 virtual void stopMove() = 0; 52 virtual void moveTo( const Coordinate& o, bool snaptogrid ) = 0; 53 54 public: 55 void leftReleased( QMouseEvent*, KigWidget* ) override; 56 void leftMouseMoved( QMouseEvent*, KigWidget* ) override; 57 void mouseMoved( QMouseEvent*, KigWidget* ) override; 58 }; 59 60 class MovingMode 61 : public MovingModeBase 62 { 63 class Private; 64 Private* d; 65 void stopMove() override; 66 void moveTo( const Coordinate& o, bool snaptogrid ) override; 67 public: 68 MovingMode( const std::vector<ObjectHolder*>& objects, const Coordinate& c, 69 KigWidget&, KigPart& ); 70 ~MovingMode(); 71 }; 72 73 class PointRedefineMode 74 : public MovingModeBase 75 { 76 ObjectHolder* mp; 77 std::vector<ObjectCalcer::shared_ptr> moldparents; 78 const ObjectType* moldtype; 79 MonitorDataObjects* mmon; 80 void stopMove() override; 81 void moveTo( const Coordinate& o, bool snaptogrid ) override; 82 public: 83 PointRedefineMode( ObjectHolder* p, KigPart& d, KigWidget& v ); 84 ~PointRedefineMode(); 85 }; 86 87 #endif 88