• 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
objectchooserpopup.cc
Go to the documentation of this file.
1 
20 #include "objectchooserpopup.h"
21 
22 #include "../../objects/object_holder.h"
23 #include "../../objects/point_imp.h"
24 #include "../../objects/polygon_imp.h"
25 
26 int ObjectChooserPopup::getObjectFromList( const QPoint& p, KigWidget* w,
27  const std::vector<ObjectHolder*>& objs,
28  bool givepopup )
29 {
30  int size = objs.size();
31 
32  // no objects
33  if ( size == 0 )
34  return -1;
35 
36  int id = -1;
37 
38  int numpoints = 0;
39  int numpolygons = 0;
40  int numothers = 0;
41 
42  for ( std::vector<ObjectHolder*>::const_iterator i = objs.begin();
43  i != objs.end(); ++i )
44  {
45  if ( (*i)->imp()->inherits( PointImp::stype() ) ) numpoints++;
46  else if ( (*i)->imp()->inherits( FilledPolygonImp::stype() ) ) numpolygons++;
47  else numothers++;
48  }
49 
50  // simply cases:
51  // - only 1 point ( and eventually other objects )
52  // - no points and an object which is not a polygon
53  // - only one object
54  // FIXME: we assume that our objects are sorted ( points, others, polygons )!
55  if ( ( numpoints == 1 ) ||
56  ( ( numpoints == 0 ) && ( numothers == 1 ) ) ||
57  ( size == 1 ) )
58  id = 0;
59  else
60  {
61  if ( givepopup )
62  {
63  ObjectChooserPopup* ppp = new ObjectChooserPopup( p, *w, objs );
64  ppp->exec( QCursor::pos() );
65 
66  id = ppp->mselected;
67 
68  delete ppp;
69  ppp = 0;
70  }
71  else
72  {
73  // we don't want to show a popup to the user, so let's give a
74  // value > 0 to indicate that it's not the first
75  id = 1;
76  }
77  }
78 // kDebug() << "numpoints: " << numpoints
79 // << "numothers: " << numothers << endl
80 // << "numpolygons: " << numpolygons << endl
81 // << "id: " << id << endl;
82 
83  return id;
84 }
85 
86 ObjectChooserPopup::ObjectChooserPopup( const QPoint& p, KigWidget& view,
87  const std::vector<ObjectHolder*>& objs )
88  : KMenu(), mplc( p ), mview( view ), mobjs( objs ), mselected( -1 )
89 {
90  addTitle( i18np( "%1 Object", "%1 Objects", mobjs.size() ) );
91  QAction* newaction = 0;
92  for ( uint i = 0; i < mobjs.size(); i++ )
93  {
94  newaction = addAction(
95  !mobjs[i]->name().isEmpty()
96  ? QString::fromLatin1( "%1 %2" ).arg( mobjs[i]->imp()->type()->translatedName() ).arg( mobjs[i]->name() )
97  : mobjs[i]->imp()->type()->translatedName() );
98  newaction->setData( QVariant::fromValue( i ) );
99  }
100 
101  connect( this, SIGNAL( triggered( QAction* ) ), this, SLOT( actionActivatedSlot( QAction* ) ) );
102 }
103 
104 ObjectChooserPopup::~ObjectChooserPopup()
105 {
106 }
107 
108 void ObjectChooserPopup::actionActivatedSlot( QAction* act )
109 {
110  mselected = act->data().toInt();
111 }
KMenu
objectchooserpopup.h
ObjectChooserPopup::getObjectFromList
static int getObjectFromList(const QPoint &p, KigWidget *w, const std::vector< ObjectHolder * > &objs, bool givepopup=true)
Get the index of the chosen object from a list of objects.
Definition: objectchooserpopup.cc:26
ObjectChooserPopup::mobjs
std::vector< ObjectHolder * > mobjs
Definition: objectchooserpopup.h:67
ObjectChooserPopup::mselected
int mselected
Definition: objectchooserpopup.h:69
ObjectChooserPopup::actionActivatedSlot
void actionActivatedSlot(QAction *)
Definition: objectchooserpopup.cc:108
KigWidget
This class is the real widget showing the document.
Definition: kig_view.h:50
FilledPolygonImp::stype
static const ObjectImpType * stype()
Definition: polygon_imp.cc:660
ObjectChooserPopup
This class is useful to choose one object from a list of some, by querying the user via popup menu...
Definition: objectchooserpopup.h:35
ObjectChooserPopup::~ObjectChooserPopup
~ObjectChooserPopup()
Definition: objectchooserpopup.cc:104
PointImp::stype
static const ObjectImpType * stype()
Returns the ObjectImpType representing PointImp's.
Definition: point_imp.cc:159
ObjectChooserPopup::ObjectChooserPopup
ObjectChooserPopup(const QPoint &p, KigWidget &view, const std::vector< ObjectHolder * > &objs)
Definition: objectchooserpopup.cc:86
uint
unsigned int uint
Definition: object_imp.h:87
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