• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

kig

  • sources
  • kde-4.12
  • kdeedu
  • kig
  • modes
  • popup
propertiesactionsprovider.cc
Go to the documentation of this file.
1 
20 #include "propertiesactionsprovider.h"
21 
22 #include <cassert>
23 
24 #include "../../kig/kig_part.h"
25 #include "../../kig/kig_view.h"
26 #include "../../objects/bogus_imp.h"
27 #include "../../objects/object_factory.h"
28 #include "../../objects/object_holder.h"
29 #include "../../objects/point_imp.h"
30 
31 #include <KLocale>
32 #include <KIcon>
33 
34 void PropertiesActionsProvider::fillUpMenu( NormalModePopupObjects& popup,
35  int menu, int& nextfree )
36 {
37  if ( popup.objects().size() != 1 ) return;
38  ObjectHolder* o = popup.objects()[0];
39  int np = o->imp()->numberOfProperties();
40  if ( menu != NormalModePopupObjects::ConstructMenu &&
41  menu != NormalModePopupObjects::ShowMenu ) return;
42  for ( int i = 0; i < np; ++i )
43  {
44  ObjectImp* prop = o->imp()->property( i, popup.part().document() );
45  const char* iconfile = o->imp()->iconForProperty( i );
46  bool add = true;
47  if ( menu == NormalModePopupObjects::ConstructMenu )
48  {
49  // we don't want imp's like DoubleImp, since we can't show them
50  // anyway..
51  add &= ! prop->inherits( BogusImp::stype() );
52  // we don't want to construct PointImp's coordinate property,
53  // since it would construct a point at the same place as its
54  // parent..
55  add &= ! ( o->imp()->inherits( PointImp::stype() ) &&
56  prop->inherits( PointImp::stype() ) );
57  }
58  else if ( menu == NormalModePopupObjects::ShowMenu )
59  add &= prop->canFillInNextEscape();
60  if ( add )
61  {
62  if ( iconfile && *iconfile )
63  {
64  popup.addInternalAction( menu, KIcon( iconfile, popup.part().iconLoader() ), i18n( o->imp()->properties()[i] ), nextfree++ );
65  }
66  else
67  {
68  popup.addInternalAction( menu, i18n( o->imp()->properties()[i] ), nextfree++ );
69  };
70  mprops[menu-1].push_back( i );
71  };
72  delete prop;
73  };
74 }
75 
76 bool PropertiesActionsProvider::executeAction(
77  int menu, int& id, const std::vector<ObjectHolder*>& os,
78  NormalModePopupObjects& popup,
79  KigPart& doc, KigWidget& w, NormalMode& )
80 {
81  if ( menu != NormalModePopupObjects::ConstructMenu &&
82  menu != NormalModePopupObjects::ShowMenu )
83  return false;
84  if ( (uint) id >= mprops[menu - 1].size() )
85  {
86  id -= mprops[menu - 1].size();
87  return false;
88  }
89  int propid = mprops[menu-1][id];
90  assert( os.size() == 1 );
91  ObjectHolder* parent = os[0];
92  if ( menu == NormalModePopupObjects::ShowMenu )
93  {
94  std::vector<ObjectCalcer*> args;
95  args.push_back( new ObjectPropertyCalcer( parent->calcer(), propid, true ) );
96  args.back()->calc( doc.document() );
97 // TODO: recover the cursor position somehow... the following does not work
98 // in general...
99 // Coordinate c = w.fromScreen( w.mapFromGlobal( popup.mapToGlobal( QPoint( 5, 0 ) ) ) );
100 // mp: it seems that we have no idea where to position the label,
101 // btw what's the meaning of (5,0)? let the
102 // attach method decide what to do... (passing an invalidCoord)
103 // /////// Coordinate c = Coordinate::invalidCoord();
104  Coordinate c = w.fromScreen( popup.plc() );
105  ObjectHolder* label = ObjectFactory::instance()->attachedLabel(
106  QString::fromLatin1( "%1" ), parent->calcer(), c,
107  false, args, doc.document() );
108  doc.addObject( label );
109  }
110  else
111  {
112  ObjectHolder* h = new ObjectHolder(
113  new ObjectPropertyCalcer( parent->calcer(), propid, true ) );
114  h->calc( doc.document() );
115  doc.addObject( h );
116  };
117  return true;
118 }
119 
ObjectFactory::instance
static const ObjectFactory * instance()
Definition: object_factory.cc:90
NormalModePopupObjects::part
KigPart & part()
Definition: popup.h:70
ObjectImp::inherits
bool inherits(const ObjectImpType *t) const
Returns true if this ObjectImp inherits the ObjectImp type represented by t.
Definition: object_imp.cc:279
BogusImp::stype
static const ObjectImpType * stype()
Returns the ObjectImpType representing the BogusImp type.
Definition: bogus_imp.cc:286
NormalModePopupObjects::addInternalAction
QAction * addInternalAction(int menu, const QString &name, int id)
Definition: popup.cc:276
ObjectImp::property
virtual ObjectImp * property(int which, const KigDocument &d) const
Definition: object_imp.cc:70
KigPart::document
const KigDocument & document() const
Definition: kig_part.cpp:989
Coordinate
The Coordinate class is the basic class representing a 2D location by its x and y components...
Definition: coordinate.h:33
NormalModePopupObjects::ShowMenu
Definition: popup.h:59
ObjectHolder::calc
void calc(const KigDocument &)
Make our ObjectCalcer recalculate its ObjectImp.
Definition: object_holder.cc:73
NormalModePopupObjects
This is the popup menu that appears when you click on selected objects in NormalMode.
Definition: popup.h:46
ObjectImp::canFillInNextEscape
virtual bool canFillInNextEscape() const
Definition: object_imp.cc:192
ObjectImp::iconForProperty
virtual const char * iconForProperty(int which) const
Definition: object_imp.cc:187
ObjectHolder
An ObjectHolder represents an object as it is known to the document.
Definition: object_holder.h:40
KigWidget::fromScreen
const Coordinate fromScreen(const QPoint &p)
Definition: kig_view.cpp:282
NormalModePopupObjects::plc
QPoint plc()
Definition: popup.h:72
KigWidget
This class is the real widget showing the document.
Definition: kig_view.h:50
PropertiesActionsProvider::fillUpMenu
void fillUpMenu(NormalModePopupObjects &popup, int menu, int &nextfree)
This file is part of Kig, a KDE program for Interactive Geometry...
Definition: propertiesactionsprovider.cc:34
ObjectPropertyCalcer
This is an ObjectCalcer that has a single parent, and gets a certain property from it in its calc() m...
Definition: object_calcer.h:276
NormalModePopupObjects::objects
std::vector< ObjectHolder * > objects() const
Definition: popup.h:69
ObjectHolder::imp
const ObjectImp * imp() const
Definition: object_holder.cc:48
KigPart::addObject
void addObject(ObjectHolder *inObject)
Definition: kig_part.cpp:492
PointImp::stype
static const ObjectImpType * stype()
Returns the ObjectImpType representing PointImp's.
Definition: point_imp.cc:159
ObjectFactory::attachedLabel
ObjectHolder * attachedLabel(const QString &s, ObjectCalcer *locationparent, const Coordinate &loc, bool needframe, const std::vector< ObjectCalcer * > &parents, const KigDocument &doc) const
Definition: object_factory.cc:474
NormalModePopupObjects::ConstructMenu
Definition: popup.h:59
PropertiesActionsProvider::executeAction
bool executeAction(int menu, int &id, const std::vector< ObjectHolder * > &os, NormalModePopupObjects &popup, KigPart &doc, KigWidget &w, NormalMode &m)
try to execute the id'th action you added to menu menu in popup popup ( first is 0 )...
Definition: propertiesactionsprovider.cc:76
propertiesactionsprovider.h
ObjectImp
The ObjectImp class represents the behaviour of an object after it is calculated. ...
Definition: object_imp.h:226
KigPart
This is a "Part".
Definition: kig_part.h:68
NormalMode
Definition: normal.h:26
ObjectImp::numberOfProperties
virtual int numberOfProperties() const
Definition: object_imp.cc:58
uint
unsigned int uint
Definition: object_imp.h:87
ObjectImp::properties
virtual const QByteArrayList properties() const
Definition: object_imp.cc:51
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:35:39 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kig

Skip menu "kig"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal