1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
// Copyright (C) 2003 Dominique Devriese <devriese@kde.org>
// 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.
#ifndef KIG_MODES_CONSTRUCT_MODE_H
#define KIG_MODES_CONSTRUCT_MODE_H
#include "base_mode.h"
#include "../objects/object_calcer.h"
class ArgsParserObjectType;
class ObjectConstructor;
class ObjectCalcer;
class PointConstructMode
: public BaseMode
{
/**
* this is the point that we move around, for the user to add
* somewhere..
*/
ObjectTypeCalcer::shared_ptr mpt;
public:
PointConstructMode( KigPart& d );
~PointConstructMode();
protected:
void leftClickedObject( ObjectHolder* o, const QPoint& p,
KigWidget& w, bool ctrlOrShiftDown );
void midClicked( const QPoint& p, KigWidget& w );
void rightClicked( const std::vector<ObjectHolder*>& oco, const QPoint& p, KigWidget& w );
void mouseMoved( const std::vector<ObjectHolder*>& os, const QPoint& p, KigWidget& w, bool shiftpressed );
void enableActions();
void cancelConstruction();
void redrawScreen( KigWidget* );
};
class BaseConstructMode
: public BaseMode
{
/**
* this is the point that we move around, in case the user wants to
* add a point somewhere..
*/
ObjectTypeCalcer::shared_ptr mpt;
/**
* mp: this point always follows the cursor
*
* IMPORTANT: this Calcer must NEVER be added to the document, since
* its is used in constructors that need more input from the user
* to decide parameters of the constructed object that will be fixed
* afterwards (like the number of sides of a regular polygon)
*/
ObjectTypeCalcer* mcursor;
// we also allocate here the corresponding objectholder, since the
// only sensible place where to deallocate it is in the destructor
// of this class
// ObjectHolder* mcursorholder;
std::vector<ObjectHolder*> mparents;
void leftReleased( QMouseEvent* e, KigWidget* v );
public:
void selectObject( ObjectHolder* o, KigWidget& w );
void selectObjects( const std::vector<ObjectHolder*>& os, KigWidget& w );
virtual ~BaseConstructMode();
protected:
BaseConstructMode( KigPart& d );
protected:
void leftClickedObject( ObjectHolder* o, const QPoint& p,
KigWidget& w, bool ctrlOrShiftDown );
void midClicked( const QPoint& p, KigWidget& w );
void rightClicked( const std::vector<ObjectHolder*>& oco, const QPoint& p, KigWidget& w );
void mouseMoved( const std::vector<ObjectHolder*>& os, const QPoint& p, KigWidget& w, bool shiftpressed );
void enableActions();
void cancelConstruction();
void finish();
protected:
virtual void handlePrelim( const std::vector<ObjectCalcer*>& os, const QPoint& p, KigPainter&, KigWidget& w ) = 0;
virtual QString selectStatement( const std::vector<ObjectCalcer*>& args, const KigWidget& w ) = 0;
virtual int isAlreadySelectedOK( const std::vector<ObjectCalcer*>&, const int& ) = 0;
virtual int wantArgs( const std::vector<ObjectCalcer*>&, KigDocument& d, KigWidget& w ) = 0;
virtual void handleArgs( const std::vector<ObjectCalcer*>& args, KigWidget& w ) = 0;
void redrawScreen( KigWidget* );
};
class ConstructMode
: public BaseConstructMode
{
const ObjectConstructor* mctor;
public:
ConstructMode( KigPart& d, const ObjectConstructor* ctor );
~ConstructMode();
void handlePrelim( const std::vector<ObjectCalcer*>& os, const QPoint& p, KigPainter&, KigWidget& w );
QString selectStatement( const std::vector<ObjectCalcer*>& args, const KigWidget& w );
int isAlreadySelectedOK( const std::vector<ObjectCalcer*>&, const int& );
int wantArgs( const std::vector<ObjectCalcer*>&, KigDocument& d, KigWidget& w );
void handleArgs( const std::vector<ObjectCalcer*>& args, KigWidget& w );
};
/**
* This class constructs a test object. It has special needs over
* ConstructMode because first the arguments need to be chosen, and
* then the location for the resulting TextImp needs to be chosen. It
* also needs special code for the drawPrelim and wantArgs code.
*
* Therefore, we inherit from BaseConstructMode, and override the
* event callbacks, so that this mode behaves like a
* BaseConstructMode, until handleArgs is called. After that, mresult
* is no longer 0, and then the mode behaves in its own way, allowing
* the user to choose a location for the new label object.
*/
class TestConstructMode
: public BaseConstructMode
{
const ArgsParserObjectType* mtype;
ObjectCalcer::shared_ptr mresult;
public:
TestConstructMode( KigPart& d, const ArgsParserObjectType* type );
~TestConstructMode();
void handlePrelim( const std::vector<ObjectCalcer*>& os, const QPoint& p, KigPainter&, KigWidget& w );
QString selectStatement( const std::vector<ObjectCalcer*>& args, const KigWidget& w );
int isAlreadySelectedOK( const std::vector<ObjectCalcer*>&, const int& );
int wantArgs( const std::vector<ObjectCalcer*>&, KigDocument& d, KigWidget& w );
void handleArgs( const std::vector<ObjectCalcer*>& args, KigWidget& w );
void leftClickedObject( ObjectHolder* o, const QPoint& p,
KigWidget& w, bool ctrlOrShiftDown );
void midClicked( const QPoint& p, KigWidget& w );
void rightClicked( const std::vector<ObjectHolder*>& oco, const QPoint& p, KigWidget& w );
void mouseMoved( const std::vector<ObjectHolder*>& os, const QPoint& p, KigWidget& w, bool shiftpressed );
};
#endif
|