~ubuntu-branches/ubuntu/saucy/kig/saucy

« back to all changes in this revision

Viewing changes to modes/popup/objectconstructoractionsprovider.cc

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell, Jonathan Riddell, Harald Sitter
  • Date: 2012-11-19 15:58:49 UTC
  • mfrom: (1.1.16)
  • Revision ID: package-import@ubuntu.com-20121119155849-l709sjsbjijx422a
Tags: 4:4.9.80-0ubuntu1
[ Jonathan Riddell ]
* New upstream beta release

[ Harald Sitter ]
* Add libboost-python-dev as build dep to enable python script support.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
    This file is part of Kig, a KDE program for Interactive Geometry...
 
3
    Copyright (C) 2012  David E. Narvaez <david.narvaez@computer.org>
 
4
 
 
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.
 
9
 
 
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.
 
14
 
 
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.
 
18
*/
 
19
 
 
20
#include "objectconstructoractionsprovider.h"
 
21
 
 
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"
 
29
 
 
30
void ObjectConstructorActionsProvider::fillUpMenu( NormalModePopupObjects& popup, int menu, int& nextfree )
 
31
{
 
32
  const KigDocument& d = popup.part().document();
 
33
  const KigWidget& v = popup.widget();
 
34
  typedef ObjectConstructorList::vectype vectype;
 
35
  vectype vec = ObjectConstructorList::instance()->constructors();
 
36
 
 
37
  for ( vectype::iterator i = vec.begin(); i != vec.end(); ++i )
 
38
  {
 
39
    bool add = false;
 
40
    if ( popup.objects().empty() )
 
41
    {
 
42
      add = menu == NormalModePopupObjects::StartMenu && ! (*i)->isTransform() && ! (*i)->isTest();
 
43
    }
 
44
    else
 
45
    {
 
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;
 
53
    };
 
54
    if ( add )
 
55
    {
 
56
      QByteArray iconfile = (*i)->iconFileName();
 
57
      if ( !iconfile.isEmpty() && !iconfile.isNull() )
 
58
      {
 
59
        popup.addInternalAction( menu, KIcon( iconfile, popup.part().iconLoader() ), (*i)->descriptiveName(), nextfree++ );
 
60
      }
 
61
      else
 
62
        popup.addInternalAction( menu, (*i)->descriptiveName(), nextfree++ );
 
63
      mctors[menu].push_back( *i );
 
64
    }
 
65
  };
 
66
}
 
67
 
 
68
bool ObjectConstructorActionsProvider::executeAction(
 
69
  int menu, int& id, const std::vector<ObjectHolder*>& os,
 
70
  NormalModePopupObjects&,
 
71
  KigPart& doc, KigWidget& w, NormalMode& m )
 
72
{
 
73
  if ( (uint) id >= mctors[menu].size() )
 
74
  {
 
75
    id -= mctors[menu].size();
 
76
    return false;
 
77
  }
 
78
 
 
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 )
 
82
  {
 
83
    ctor->handleArgs( osc, doc, w );
 
84
    m.clearSelection();
 
85
  }
 
86
  else
 
87
  {
 
88
    BaseConstructMode* mode = ctor->constructMode( doc );
 
89
    mode->selectObjects( os, w );
 
90
    doc.runMode( mode );
 
91
    delete mode;
 
92
  };
 
93
  return true;
 
94
}
 
95