• 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
nameobjectactionsprovider.cc
Go to the documentation of this file.
1 
20 #include "nameobjectactionsprovider.h"
21 
22 #include <cassert>
23 
24 #include "popup.h"
25 
26 #include "../../kig/kig_commands.h"
27 #include "../../kig/kig_part.h"
28 #include "../../kig/kig_view.h"
29 #include "../../modes/normal.h"
30 #include "../../objects/curve_imp.h"
31 #include "../../objects/bogus_imp.h"
32 #include "../../objects/object_calcer.h"
33 #include "../../objects/object_factory.h"
34 #include "../../objects/point_imp.h"
35 
36 #include <QRegExpValidator>
37 
38 #include <KInputDialog>
39 #include <KLocale>
40 
41 void addNameLabel( ObjectCalcer* object, ObjectCalcer* namecalcer, const Coordinate& loc, KigPart& doc )
42 {
43  std::vector<ObjectCalcer*> args;
44  args.push_back( namecalcer );
45  const bool namelabelneedsframe = false;
46  ObjectCalcer* attachto = 0;
47  if ( object->imp()->inherits( PointImp::stype() ) ||
48  object->imp()->attachPoint().valid() ||
49  object->imp()->inherits( CurveImp::stype() ) )
50  attachto = object;
51  ObjectHolder* label = ObjectFactory::instance()->attachedLabel(
52  QString::fromLatin1( "%1" ), attachto, loc, namelabelneedsframe, args, doc.document() );
53  doc.addObject( label );
54 }
55 
56 void NameObjectActionsProvider::fillUpMenu( NormalModePopupObjects& popup, int menu, int& nextfree )
57 {
58  if ( menu == NormalModePopupObjects::ToplevelMenu )
59  {
60  popup.addInternalAction( menu, i18n( "Set &Name..." ), nextfree++ );
61  }
62  else if ( menu == NormalModePopupObjects::ShowMenu )
63  {
64  popup.addInternalAction( menu, i18n( "&Name" ), nextfree++ );
65  }
66 }
67 
68 bool NameObjectActionsProvider::executeAction(
69  int menu, int& id, const std::vector<ObjectHolder*>& os, NormalModePopupObjects& popup,
70  KigPart& doc, KigWidget& w, NormalMode& )
71 {
72  if ( menu == NormalModePopupObjects::ToplevelMenu )
73  {
74  if ( id >= 1 )
75  {
76  id -= 1;
77  return false;
78  }
79  assert( os.size() == 1 );
80  QString name = os[0]->name();
81  bool ok;
82  QRegExp re( ".*" );
83  QRegExpValidator* rev = new QRegExpValidator( re, &doc );
84  name = KInputDialog::getText(
85  i18n( "Set Object Name" ), i18n( "Set Name of this Object:" ),
86  name, &ok, &w, rev );
87  if ( ok )
88  {
89  bool justadded = false;
90  ObjectCalcer* namecalcer = os[0]->nameCalcer();
91  if ( !namecalcer )
92  {
93  justadded = true;
94  ObjectConstCalcer* c = new ObjectConstCalcer( new StringImp( i18n( "<unnamed object>" ) ) );
95  os[0]->setNameCalcer( c );
96  namecalcer = c;
97  }
98  assert( dynamic_cast<ObjectConstCalcer*>( namecalcer ) );
99  ObjectConstCalcer* cnamecalcer = static_cast<ObjectConstCalcer*>( os[0]->nameCalcer() );
100  MonitorDataObjects mon( cnamecalcer );
101  cnamecalcer->setImp( new StringImp( name ) );
102  KigCommand* kc = new KigCommand( doc, i18n( "Set Object Name" ) );
103  mon.finish( kc );
104  doc.history()->push( kc );
105 
106  // if we just added the name, we add a label to show it to the user.
107  if ( justadded )
108  addNameLabel( os[0]->calcer(), namecalcer,
109 // w.fromScreen( w.mapFromGlobal( popup.mapToGlobal( QPoint( 5, 0 ) ) ) ),
110  w.fromScreen( popup.plc() ),
111  doc );
112  }
113  return true;
114  }
115  else if ( menu == NormalModePopupObjects::ShowMenu )
116  {
117  if ( id >= 1 )
118  {
119  id -= 1;
120  return false;
121  }
122  assert( os.size() == 1 );
123  ObjectCalcer* namecalcer = os[0]->nameCalcer();
124  if ( !namecalcer )
125  {
126  ObjectConstCalcer* c = new ObjectConstCalcer( new StringImp( i18n( "<unnamed object>" ) ) );
127  os[0]->setNameCalcer( c );
128  namecalcer = c;
129  }
130  addNameLabel( os[0]->calcer(), namecalcer,
131 // w.fromScreen( w.mapFromGlobal( popup.mapToGlobal( QPoint( 5, 0 ) ) ) ), doc );
132  w.fromScreen( popup.plc() ), doc );
133  return true;
134  }
135  else
136  {
137  return false;
138  }
139 }
popup.h
ObjectFactory::instance
static const ObjectFactory * instance()
Definition: object_factory.cc:90
NameObjectActionsProvider::fillUpMenu
void fillUpMenu(NormalModePopupObjects &popup, int menu, int &nextfree)
add all your entries to menu menu in popup popup.
Definition: nameobjectactionsprovider.cc:56
nameobjectactionsprovider.h
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
ObjectConstCalcer::setImp
void setImp(ObjectImp *newimp)
Set the ObjectImp of this ObjectConstCalcer to the given newimp.
Definition: object_calcer.cc:241
addNameLabel
void addNameLabel(ObjectCalcer *object, ObjectCalcer *namecalcer, const Coordinate &loc, KigPart &doc)
This file is part of Kig, a KDE program for Interactive Geometry...
Definition: nameobjectactionsprovider.cc:41
StringImp
This ObjectImp is a BogusImp containing only a string value.
Definition: bogus_imp.h:167
KigCommand
a KigCommand represents almost every action performed in Kig.
Definition: kig_commands.h:44
NormalModePopupObjects::addInternalAction
QAction * addInternalAction(int menu, const QString &name, int id)
Definition: popup.cc:276
ObjectConstCalcer
This is an ObjectCalcer that keeps an ObjectImp, and never calculates a new one.
Definition: object_calcer.h:232
KigPart::document
const KigDocument & document() const
Definition: kig_part.cpp:989
NormalModePopupObjects::ToplevelMenu
Definition: popup.h:60
KigPart::history
QUndoStack * history()
Definition: kig_part.cpp:633
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
NormalModePopupObjects
This is the popup menu that appears when you click on selected objects in NormalMode.
Definition: popup.h:46
ObjectHolder
An ObjectHolder represents an object as it is known to the document.
Definition: object_holder.h:40
ObjectCalcer
An ObjectCalcer is an object that represents an algorithm for calculating an ObjectImp from other Obj...
Definition: object_calcer.h:66
KigWidget::fromScreen
const Coordinate fromScreen(const QPoint &p)
Definition: kig_view.cpp:282
MonitorDataObjects
this class monitors a set of DataObjects for changes and returns an appropriate ChangeObjectImpsComma...
Definition: kig_commands.h:153
NormalModePopupObjects::plc
QPoint plc()
Definition: popup.h:72
KigWidget
This class is the real widget showing the document.
Definition: kig_view.h:50
MonitorDataObjects::finish
void finish(KigCommand *comm)
add the generated KigCommandTasks to the command comm .
Definition: kig_commands.cpp:227
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
CurveImp::stype
static const ObjectImpType * stype()
Returns the ObjectImpType representing the CurveImp type.
Definition: curve_imp.cc:27
ObjectCalcer::imp
virtual const ObjectImp * imp() const =0
Returns the ObjectImp of this ObjectCalcer.
NameObjectActionsProvider::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: nameobjectactionsprovider.cc:68
KigPart
This is a "Part".
Definition: kig_part.h:68
NormalMode
Definition: normal.h:26
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