1 // Copyright (C) 2003 Dominique Devriese <devriese@kde.org>
3 // This program is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU General Public License
5 // as published by the Free Software Foundation; either version 2
6 // of the License, or (at your option) any later version.
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
18 #ifndef KIG_MODES_CONSTRUCT_MODE_H
19 #define KIG_MODES_CONSTRUCT_MODE_H
21 #include "base_mode.h"
23 #include "../objects/object_calcer.h"
25 class ArgsParserObjectType
;
26 class ObjectConstructor
;
29 class PointConstructMode
32 // this is the point that we move around, for the user to add
34 ObjectTypeCalcer::shared_ptr mpt
;
36 PointConstructMode( KigPart
& d
);
37 ~PointConstructMode();
39 void leftClickedObject( ObjectHolder
* o
, const QPoint
& p
,
40 KigWidget
& w
, bool ctrlOrShiftDown
);
41 void midClicked( const QPoint
& p
, KigWidget
& w
);
42 void rightClicked( const std::vector
<ObjectHolder
*>& oco
, const QPoint
& p
, KigWidget
& w
);
43 void mouseMoved( const std::vector
<ObjectHolder
*>& os
, const QPoint
& p
, KigWidget
& w
, bool shiftpressed
);
46 void cancelConstruction();
48 void redrawScreen( KigWidget
* );
51 class BaseConstructMode
54 // this is the point that we move around, in case the user wants to
55 // add a point somewhere..
56 ObjectTypeCalcer::shared_ptr mpt
;
57 // mp: this point always follows the cursor
58 // IMPORTANT: this Calcer must NEVER be added to the document, since
59 // its is used in constructors that need more input from the user
60 // to decide parameters of the constructed object that will be fixed
61 // afterwards (like the number of sides of a regular polygon)
62 ObjectTypeCalcer
* mcursor
;
63 // we also allocate here the corresponding objectholder, since the
64 // only sensible place where to deallocate it is in the destructor
66 // ObjectHolder* mcursorholder;
67 std::vector
<ObjectHolder
*> mparents
;
70 void selectObject( ObjectHolder
* o
, KigWidget
& w
);
71 void selectObjects( const std::vector
<ObjectHolder
*>& os
, KigWidget
& w
);
72 virtual ~BaseConstructMode();
74 BaseConstructMode( KigPart
& d
);
76 void leftClickedObject( ObjectHolder
* o
, const QPoint
& p
,
77 KigWidget
& w
, bool ctrlOrShiftDown
);
78 void midClicked( const QPoint
& p
, KigWidget
& w
);
79 void rightClicked( const std::vector
<ObjectHolder
*>& oco
, const QPoint
& p
, KigWidget
& w
);
80 void mouseMoved( const std::vector
<ObjectHolder
*>& os
, const QPoint
& p
, KigWidget
& w
, bool shiftpressed
);
83 void cancelConstruction();
87 virtual void handlePrelim( const std::vector
<ObjectCalcer
*>& os
, const QPoint
& p
, KigPainter
&, KigWidget
& w
) = 0;
88 virtual QString
selectStatement( const std::vector
<ObjectCalcer
*>& args
, const KigWidget
& w
) = 0;
89 virtual int isAlreadySelectedOK( const std::vector
<ObjectCalcer
*>&, const int& ) = 0;
90 virtual int wantArgs( const std::vector
<ObjectCalcer
*>&, KigDocument
& d
, KigWidget
& w
) = 0;
91 virtual void handleArgs( const std::vector
<ObjectCalcer
*>& args
, KigWidget
& w
) = 0;
93 void redrawScreen( KigWidget
* );
97 : public BaseConstructMode
99 const ObjectConstructor
* mctor
;
101 ConstructMode( KigPart
& d
, const ObjectConstructor
* ctor
);
104 void handlePrelim( const std::vector
<ObjectCalcer
*>& os
, const QPoint
& p
, KigPainter
&, KigWidget
& w
);
105 QString
selectStatement( const std::vector
<ObjectCalcer
*>& args
, const KigWidget
& w
);
106 int isAlreadySelectedOK( const std::vector
<ObjectCalcer
*>&, const int& );
107 int wantArgs( const std::vector
<ObjectCalcer
*>&, KigDocument
& d
, KigWidget
& w
);
108 void handleArgs( const std::vector
<ObjectCalcer
*>& args
, KigWidget
& w
);
112 * This class constructs a test object. It has special needs over
113 * ConstructMode because first the arguments need to be chosen, and
114 * then the location for the resulting TextImp needs to be chosen. It
115 * also needs special code for the drawPrelim and wantArgs code.
117 * Therefore, we inherit from BaseConstructMode, and override the
118 * event callbacks, so that this mode behaves like a
119 * BaseConstructMode, until handleArgs is called. After that, mresult
120 * is no longer 0, and then the mode behaves in its own way, allowing
121 * the user to choose a location for the new label object.
123 class TestConstructMode
124 : public BaseConstructMode
126 const ArgsParserObjectType
* mtype
;
127 ObjectCalcer::shared_ptr mresult
;
129 TestConstructMode( KigPart
& d
, const ArgsParserObjectType
* type
);
130 ~TestConstructMode();
132 void handlePrelim( const std::vector
<ObjectCalcer
*>& os
, const QPoint
& p
, KigPainter
&, KigWidget
& w
);
133 QString
selectStatement( const std::vector
<ObjectCalcer
*>& args
, const KigWidget
& w
);
134 int isAlreadySelectedOK( const std::vector
<ObjectCalcer
*>&, const int& );
135 int wantArgs( const std::vector
<ObjectCalcer
*>&, KigDocument
& d
, KigWidget
& w
);
136 void handleArgs( const std::vector
<ObjectCalcer
*>& args
, KigWidget
& w
);
138 void leftClickedObject( ObjectHolder
* o
, const QPoint
& p
,
139 KigWidget
& w
, bool ctrlOrShiftDown
);
140 void midClicked( const QPoint
& p
, KigWidget
& w
);
141 void rightClicked( const std::vector
<ObjectHolder
*>& oco
, const QPoint
& p
, KigWidget
& w
);
142 void mouseMoved( const std::vector
<ObjectHolder
*>& os
, const QPoint
& p
, KigWidget
& w
, bool shiftpressed
);