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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
|
// Copyright (C) 2002 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.
#include "normal.h"
#include "../kig/kig_view.h"
#include "../kig/kig_part.h"
#include "../kig/kig_document.h"
#include "../kig/kig_commands.h"
#include "../objects/object_factory.h"
#include "../objects/object_imp.h"
#include "../objects/object_drawer.h"
#include "../misc/kigpainter.h"
#include "popup.h"
#include "moving.h"
#include "macro.h"
#include "dragrectmode.h"
#include "typesdialog.h"
#include <kcursor.h>
#include <tdeaction.h>
#include <kcommand.h>
#include <tdelocale.h>
#include <algorithm>
#include <functional>
using namespace std;
void NormalMode::enableActions()
{
KigMode::enableActions();
mdoc.enableConstructActions( true );
mdoc.aSelectAll->setEnabled( true );
mdoc.aDeselectAll->setEnabled( true );
mdoc.aInvertSelection->setEnabled( true );
mdoc.aDeleteObjects->setEnabled( true );
mdoc.aShowHidden->setEnabled( true );
mdoc.aNewMacro->setEnabled( true );
mdoc.aConfigureTypes->setEnabled( true );
mdoc.history()->updateActions();
}
void NormalMode::deleteObjects()
{
std::vector<ObjectHolder*> sel( sos.begin(), sos.end() );
mdoc.delObjects( sel );
sos.clear();
}
void NormalMode::selectObject( ObjectHolder* o )
{
sos.insert( o );
}
void NormalMode::selectObjects( const std::vector<ObjectHolder*>& os )
{
// hehe, don't you love this c++ stuff ;)
std::for_each( os.begin(), os.end(),
std::bind1st(
std::mem_fun( &NormalMode::selectObject ), this ) );
}
void NormalMode::unselectObject( ObjectHolder* o )
{
sos.erase( o );
}
void NormalMode::clearSelection()
{
sos.clear();
}
// KigDocumentPopup* NormalMode::popup( KigDocument* )
// {
// return 0;
// }
void NormalMode::showHidden()
{
mdoc.showObjects( mdoc.document().objects() );
}
void NormalMode::newMacro()
{
DefineMacroMode m( mdoc );
mdoc.runMode( &m );
}
void NormalMode::redrawScreen( KigWidget* w )
{
// unselect removed objects..
std::vector<ObjectHolder*> nsos;
const std::set<ObjectHolder*> docobjs = mdoc.document().objectsSet();
std::set_intersection( docobjs.begin(), docobjs.end(), sos.begin(), sos.end(),
std::back_inserter( nsos ) );
sos = std::set<ObjectHolder*>( nsos.begin(), nsos.end() );
w->redrawScreen( nsos, true );
w->updateScrollBars();
}
void NormalMode::editTypes()
{
TypesDialog d( mdoc.widget(), mdoc );
d.exec();
}
NormalMode::NormalMode( KigPart& d )
: BaseMode( d )
{
}
NormalMode::~NormalMode()
{
}
void NormalMode::dragRect( const TQPoint& p, KigWidget& w )
{
DragRectMode d( p, mdoc, w );
mdoc.runMode( &d );
KigPainter pter( w.screenInfo(), TQT_TQPAINTDEVICE(&w.stillPix), mdoc.document() );
if ( ! d.cancelled() )
{
std::vector<ObjectHolder*> sel = d.ret();
if ( d.needClear() )
{
pter.drawObjects( sos.begin(), sos.end(), false );
clearSelection();
};
selectObjects( sel );
pter.drawObjects( sel, true );
};
w.updateCurPix( pter.overlay() );
w.updateWidget();
}
void NormalMode::dragObject( const std::vector<ObjectHolder*>& oco, const TQPoint& pco,
KigWidget& w, bool ctrlOrShiftDown )
{
// first determine what to move...
if( sos.find( oco.front() ) == sos.end() )
{
// the user clicked on something that is currently not
// selected... --> we select it, taking the Ctrl- and
// Shift-buttons into account...
if ( !ctrlOrShiftDown ) clearSelection();
selectObject(oco.front());
}
std::vector<ObjectHolder*> sosv( sos.begin(), sos.end() );
MovingMode m( sosv, w.fromScreen( pco ), w, mdoc );
mdoc.runMode( &m );
}
void NormalMode::leftClickedObject( ObjectHolder* o, const TQPoint&,
KigWidget& w, bool ctrlOrShiftDown )
{
KigPainter pter( w.screenInfo(), TQT_TQPAINTDEVICE(&w.stillPix), mdoc.document() );
if ( ! o )
{
pter.drawObjects( sos.begin(), sos.end(), false );
clearSelection();
}
else if( sos.find( o ) == sos.end() )
{
// clicked on an object that wasn't selected....
if (!ctrlOrShiftDown)
{
pter.drawObjects( sos.begin(), sos.end(), false );
clearSelection();
};
pter.drawObject( o, true );
selectObject( o );
}
else
{
// clicked on an object that was selected....
pter.drawObject( o, false );
unselectObject( o );
};
w.updateCurPix( pter.overlay() );
w.updateWidget();
}
void NormalMode::midClicked( const TQPoint& p, KigWidget& w )
{
ObjectHolder* pto = ObjectFactory::instance()->sensiblePoint( w.fromScreen( p ), mdoc.document(), w );
pto->calc( mdoc.document() );
mdoc.addObject( pto );
// refresh the screen...
// not necessary, done by addObjects, which calls NormalMode::redrawScreen..
// w.redrawScreen();
// w.updateScrollBars();
}
void NormalMode::rightClicked( const std::vector<ObjectHolder*>& os,
const TQPoint& plc,
KigWidget& w )
{
// saving the current cursor position
TQPoint pt = TQCursor::pos();
if( !os.empty() )
{
ObjectHolder* o = 0;
int id = ObjectChooserPopup::getObjectFromList( pt, &w, os );
if ( id >= 0 )
o = os[id];
else
return;
if( sos.find( o ) == sos.end() )
{
clearSelection();
selectObject( o );
};
// show a popup menu...
std::vector<ObjectHolder*> sosv( sos.begin(), sos.end() );
NormalModePopupObjects p( mdoc, w, *this, sosv, plc );
p.exec( pt );
}
else
{
NormalModePopupObjects p( mdoc, w, *this, std::vector<ObjectHolder*>(), plc );
p.exec( pt );
};
}
void NormalMode::mouseMoved( const std::vector<ObjectHolder*>& os,
const TQPoint& plc,
KigWidget& w,
bool )
{
w.updateCurPix();
if( os.empty() )
{
w.setCursor( KCursor::arrowCursor() );
mdoc.emitStatusBarText( 0 );
w.updateWidget();
}
else
{
// the cursor is over an object, show object type next to cursor
// and set statusbar text
w.setCursor( KCursor::handCursor() );
int id = ObjectChooserPopup::getObjectFromList( plc, &w, os, false );
TQString stat = id == 0 ? os.front()->selectStatement() : i18n( "Which object?" );
// statusbar text
mdoc.emitStatusBarText( stat );
KigPainter p( w.screenInfo(), TQT_TQPAINTDEVICE(&w.curPix), mdoc.document() );
// set the text next to the arrow cursor
TQPoint point = plc;
point.setX(point.x()+15);
p.drawTextStd( point, stat );
w.updateWidget( p.overlay() );
};
}
void NormalMode::selectAll()
{
const std::vector<ObjectHolder*> os = mdoc.document().objects();
selectObjects( os );
mdoc.redrawScreen();
}
void NormalMode::deselectAll()
{
clearSelection();
mdoc.redrawScreen();
}
void NormalMode::invertSelection()
{
std::vector<ObjectHolder*> os = mdoc.document().objects();
std::set<ObjectHolder*> oldsel = sos;
clearSelection();
for ( std::vector<ObjectHolder*>::const_iterator i = os.begin();
i != os.end(); ++i )
if ( oldsel.find( *i ) == oldsel.end() )
sos.insert( *i );
mdoc.redrawScreen();
}
|