2
This file is part of Kig, a KDE program for Interactive Geometry...
3
Copyright (C) 2012 David E. Narvaez <david.narvaez@computer.org>
5
This program is free software; you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published by
7
the Free Software Foundation; either version 2 of the License, or
8
(at your option) any later version.
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
15
You should have received a copy of the GNU General Public License along
16
with this program; if not, write to the Free Software Foundation, Inc.,
17
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20
#include "objectconstructoractionsprovider.h"
22
#include "../kig/kig_part.h"
23
#include "../kig/kig_view.h"
24
#include "../misc/argsparser.h"
25
#include "../misc/lists.h"
26
#include "../misc/object_constructor.h"
27
#include "../modes/construct_mode.h"
28
#include "../modes/normal.h"
30
void ObjectConstructorActionsProvider::fillUpMenu( NormalModePopupObjects& popup, int menu, int& nextfree )
32
const KigDocument& d = popup.part().document();
33
const KigWidget& v = popup.widget();
34
typedef ObjectConstructorList::vectype vectype;
35
vectype vec = ObjectConstructorList::instance()->constructors();
37
for ( vectype::iterator i = vec.begin(); i != vec.end(); ++i )
40
if ( popup.objects().empty() )
42
add = menu == NormalModePopupObjects::StartMenu && ! (*i)->isTransform() && ! (*i)->isTest();
46
int ret = (*i)->wantArgs( getCalcers( popup.objects() ), d, v );
47
if ( ret == ArgsParser::Invalid ) continue;
48
if ( (*i)->isTransform() && popup.objects().size() == 1 ) add = menu == NormalModePopupObjects::TransformMenu;
49
else if ( (*i)->isTest() ) add = menu == NormalModePopupObjects::TestMenu;
50
else if ( ( *i )->isIntersection() ) add = menu == NormalModePopupObjects::ToplevelMenu;
51
else if ( ret == ArgsParser::Complete ) add = menu == NormalModePopupObjects::ConstructMenu;
52
else add = menu == NormalModePopupObjects::StartMenu;
56
QByteArray iconfile = (*i)->iconFileName();
57
if ( !iconfile.isEmpty() && !iconfile.isNull() )
59
popup.addInternalAction( menu, KIcon( iconfile, popup.part().iconLoader() ), (*i)->descriptiveName(), nextfree++ );
62
popup.addInternalAction( menu, (*i)->descriptiveName(), nextfree++ );
63
mctors[menu].push_back( *i );
68
bool ObjectConstructorActionsProvider::executeAction(
69
int menu, int& id, const std::vector<ObjectHolder*>& os,
70
NormalModePopupObjects&,
71
KigPart& doc, KigWidget& w, NormalMode& m )
73
if ( (uint) id >= mctors[menu].size() )
75
id -= mctors[menu].size();
79
ObjectConstructor* ctor = mctors[menu][id];
80
std::vector<ObjectCalcer*> osc = getCalcers( os );
81
if ( ! os.empty() && ctor->wantArgs( osc, doc.document(), w ) == ArgsParser::Complete )
83
ctor->handleArgs( osc, doc, w );
88
BaseConstructMode* mode = ctor->constructMode( doc );
89
mode->selectObjects( os, w );