• 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
popup.cc
Go to the documentation of this file.
1 
21 #include "popup.h"
22 #include "popup.moc"
23 
24 #include "../../kig/kig_part.h"
25 #include "../../kig/kig_document.h"
26 #include "../../kig/kig_view.h"
27 #include "../../kig/kig_commands.h"
28 #include "../../objects/object_imp.h"
29 #include "../../objects/object_drawer.h"
30 #include "../../objects/bogus_imp.h"
31 #include "../../objects/point_imp.h"
32 #include "../../objects/line_imp.h"
33 #include "../../objects/other_type.h"
34 #include "../../objects/object_factory.h"
35 #include "../../objects/polygon_imp.h"
36 #include "../../objects/text_imp.h"
37 #include "../../objects/text_type.h"
38 #include "../../misc/lists.h"
39 #include "../../misc/argsparser.h"
40 #include "../../misc/kigpainter.h"
41 #include "../../misc/coordinate_system.h"
42 #include "../../misc/object_constructor.h"
43 #include "../construct_mode.h"
44 #include "../normal.h"
45 #include "../moving.h"
46 
47 #include "builtindocumentactionsprovider.h"
48 #include "builtinobjectactionsprovider.h"
49 #include "nameobjectactionsprovider.h"
50 #include "objectconstructoractionsprovider.h"
51 #include "objecttypeactionsprovider.h"
52 #include "propertiesactionsprovider.h"
53 
54 #include <algorithm>
55 #include <functional>
56 
57 #include <qaction.h>
58 #include <qcursor.h>
59 #include <qdialog.h>
60 #include <qfont.h>
61 #include <qpen.h>
62 #include <qregexp.h>
63 #include <qvalidator.h>
64 
65 #include <kaction.h>
66 #include <kcolordialog.h>
67 #include <kicon.h>
68 #include <kinputdialog.h>
69 #include <klocale.h>
70 
71 #include <config-kig.h>
72 
73 #ifdef KIG_ENABLE_PYTHON_SCRIPTING
74 #include "scriptactionsprovider.h"
75 #endif
76 
77 #define MAXMENUITEMS 20
78 /*
79  * mp: if a submenus requires more than MAXMENUITEMS items then a new
80  * submenu titled " more..." is added
81  */
82 
83 using namespace std;
84 
85 NormalModePopupObjects::NormalModePopupObjects( KigPart& part,
86  KigWidget& view,
87  NormalMode& mode,
88  const std::vector<ObjectHolder*>& objs,
89  const QPoint& plc )
90  : KMenu( &view ), mplc( plc ), mpart( part ), mview( view ), mobjs( objs ),
91  mmode( mode ), monlylabels( false )
92 {
93  bool empty = objs.empty();
94  bool single = objs.size() == 1;
95 
96  QString title;
97  if ( empty )
98  title = i18n( "Kig Document" );
99  else if ( single )
100  {
101  if ( !objs[0]->name().isNull() )
102  title = QString::fromLatin1( "%1 %2" ).arg( objs[0]->imp()->type()->translatedName() ).arg( objs[0]->name() );
103  else
104  title = objs[0]->imp()->type()->translatedName();
105  }
106  else
107  title = i18np( "%1 Object", "%1 Objects", objs.size() );
108  addTitle( title );
109 
110  if ( !empty )
111  {
112  monlylabels = true;
113  uint i = 0;
114  while ( i < objs.size() && monlylabels )
115  {
116  monlylabels &= objs[i]->imp()->inherits( TextImp::stype() );
117  ++i;
118  }
119  }
120 
121  if ( empty )
122  {
123  // provides some diverse stuff like "unhide all", set coordinate
124  // system etc.
125  mproviders.push_back( new BuiltinDocumentActionsProvider() );
126  };
127  // construct an object using these objects and start constructing an
128  // object using these objects
129  mproviders.push_back( new ObjectConstructorActionsProvider() );
130  if ( single )
131  mproviders.push_back( new NameObjectActionsProvider() );
132  if ( ! empty )
133  {
134  // stuff like hide, show, delete, set size, set color..
135  mproviders.push_back( new BuiltinObjectActionsProvider() );
136  // show property as text label -> show menu
137  // and construct property's as objects -> construct menu
138  mproviders.push_back( new PropertiesActionsProvider() );
139  // stuff like "redefine point" for a fixed or constrained point..
140  mproviders.push_back( new ObjectTypeActionsProvider() );
141  }
142 #ifdef KIG_ENABLE_PYTHON_SCRIPTING
143  // script action..
144  mproviders.push_back( new ScriptActionsProvider() );
145 #endif
146 
147  static const QString menunames[NumberOfMenus] =
148  {
149  i18n( "&Transform" ),
150  i18n( "T&est" ),
151  i18n( "Const&ruct" ),
152  i18n( "&Start" ),
153  i18n( "Add Te&xt Label" ),
154  i18n( "Set Co&lor" ),
155  i18n( "Set &Pen Width" ),
156  i18n( "Set St&yle" ),
157  QString(),
158  i18n( "Set Coordinate S&ystem" )
159  };
160  static const QString menuicons[NumberOfMenus] =
161  {
162  "centralsymmetry",
163  "test",
164  QString(),
165  "system-run",
166  "kig_text", // <- draw-text... hope I manage to rename it in time
167  "format-fill-color",
168 // "colorize",
169  "sizer",
170  "draw-brush",
171  QString(),
172  QString()
173  };
174 
175  // creating the menus and setting their title and icon
176  KIconLoader* l = part.iconLoader();
177  for ( uint i = 0; i < NumberOfMenus; ++i )
178  {
179  if ( i == ToplevelMenu ) continue;
180  mmenus[i] = mmenuslast[i] = new QMenu( this );
181  if ( !menunames[i].isEmpty() )
182  mmenus[i]->setTitle( menunames[i] );
183  if ( !menuicons[i].isEmpty() )
184  {
185  mmenus[i]->setIcon( KIcon( menuicons[i], l ) );
186  }
187  }
188  mmenus[ToplevelMenu] = mmenuslast[ToplevelMenu] = this;
189  /*
190  * mp: previously ToplevelMenu was treated like a submenu (of itself).
191  * unfortunately this had as side effect a duplicated triggering of its
192  * actions with unpredictable consequences. In this way the addAction
193  * in addInternalAction directly adds the action at toplevel.
194  */
195 
196  connect( this, SIGNAL( triggered( QAction* ) ),
197  this, SLOT( toplevelMenuSlot( QAction* ) ) );
198 
199  for ( int i = 0; i < NumberOfMenus; ++i )
200  {
201  int nextfree = 10;
202  for ( uint j = 0; j < mproviders.size(); ++j )
203  mproviders[j]->fillUpMenu( *this, i, nextfree );
204  };
205  QAction* firstrealaction = actions()[1];
206  for ( int i = 0; i < NumberOfMenus; ++i )
207  {
208  if ( i == ToplevelMenu ) continue;
209  if ( mmenus[i]->actions().count() == 0 ) continue;
210  //addMenu( mmenus[i] );
211  insertMenu( firstrealaction, mmenus[i] );
212  };
213  // addActions( mmenus[ToplevelMenu]->actions() );
214 }
215 
216 void NormalModePopupObjects::toplevelMenuSlot( QAction* act )
217 {
218 // activateAction( ToplevelMenu, i );
219  int data = act->data().toInt();
220  int id = data & 0xFF;
221  int menu = data >> 8;
222 kDebug() << "menu: " << menu << " - id: " << id;
223  activateAction( menu, id );
224 }
225 
226 void NormalModePopupObjects::activateAction( int menu, int action )
227 {
228  bool done = false;
229  // we need action - 10 cause we called fillUpMenu with nextfree set
230  // to 10 initially..
231  action -= 10;
232 kDebug() << "MENU: " << menu << " - ACTION: " << action;
233  for ( uint i = 0; ! done && i < mproviders.size(); ++i )
234  done = mproviders[i]->executeAction( menu, action, mobjs, *this, mpart, mview, mmode );
235 }
236 
237 NormalModePopupObjects::~NormalModePopupObjects()
238 {
239  delete_all ( mproviders.begin(), mproviders.end() );
240 }
241 
242 struct color_struct
243 {
244  const Qt::GlobalColor color;
245  const char* name;
246 };
247 
248 static const color_struct colors[] =
249 {
250  { Qt::black, I18N_NOOP( "Black" ) },
251  { Qt::gray, I18N_NOOP( "Gray" ) },
252  { Qt::red, I18N_NOOP( "Red" ) },
253  { Qt::green, I18N_NOOP( "Green" ) },
254  { Qt::cyan, I18N_NOOP( "Cyan" ) },
255  { Qt::yellow, I18N_NOOP( "Yellow" ) },
256  { Qt::darkRed, I18N_NOOP( "Dark Red" ) }
257 };
258 
259 const int numberofcolors = 7; // is there a better way to calc that?
260 
261 QAction* NormalModePopupObjects::addInternalAction( int menu, const QIcon& pix, int id )
262 {
263  return addInternalAction( menu, pix, "", id );
264 }
265 
266 QAction* NormalModePopupObjects::addInternalAction( int menu, const QIcon& icon, const QString& name, int id )
267 {
268 //kDebug() << "ID: " << id;
269  if ( mmenuslast[menu]->actions().size() >= MAXMENUITEMS )
270  mmenuslast[menu] = mmenuslast[menu]->addMenu( i18nc( "More menu items", "More..." ) );
271  QAction* newaction = mmenuslast[menu]->addAction( icon, name );
272  newaction->setData( QVariant::fromValue( ( menu << 8 ) | id ) );
273  return newaction;
274 }
275 
276 QAction* NormalModePopupObjects::addInternalAction( int menu, const QString& name, int id )
277 {
278  if ( mmenuslast[menu]->actions().size() >= MAXMENUITEMS )
279  mmenuslast[menu] = mmenuslast[menu]->addMenu( i18nc( "More menu items", "More..." ) );
280  QAction* newaction = mmenuslast[menu]->addAction( name );
281  newaction->setData( QVariant::fromValue( ( menu << 8 ) | id ) );
282  return newaction;
283 }
284 
285 QAction* NormalModePopupObjects::addInternalAction( int menu, QAction* act )
286 {
287  if ( mmenuslast[menu]->actions().size() >= MAXMENUITEMS )
288  mmenuslast[menu] = mmenuslast[menu]->addMenu( i18nc( "More menu items", "More..." ) );
289  mmenuslast[menu]->addAction( act );
290  return act;
291 }
popup.h
nameobjectactionsprovider.h
objectconstructoractionsprovider.h
NameObjectActionsProvider
This file is part of Kig, a KDE program for Interactive Geometry...
Definition: nameobjectactionsprovider.h:25
NormalModePopupObjects::mview
KigWidget & mview
Definition: popup.h:85
NormalModePopupObjects::addInternalAction
QAction * addInternalAction(int menu, const QString &name, int id)
Definition: popup.cc:276
KMenu
NormalModePopupObjects::ToplevelMenu
Definition: popup.h:60
colors
static const color_struct colors[]
Definition: popup.cc:248
BuiltinDocumentActionsProvider
This file is part of Kig, a KDE program for Interactive Geometry...
Definition: builtindocumentactionsprovider.h:25
NormalModePopupObjects::activateAction
void activateAction(int menu, int action)
Definition: popup.cc:226
NormalModePopupObjects::mpart
KigPart & mpart
Definition: popup.h:84
BuiltinObjectActionsProvider
This file is part of Kig, a KDE program for Interactive Geometry...
Definition: builtinobjectactionsprovider.h:25
delete_all
void delete_all(T begin, T end)
Definition: objects/common.h:53
PropertiesActionsProvider
This file is part of Kig, a KDE program for Interactive Geometry...
Definition: propertiesactionsprovider.h:27
NormalModePopupObjects::NumberOfMenus
Definition: popup.h:61
NormalModePopupObjects::mmenus
QMenu * mmenus[NumberOfMenus]
Definition: popup.h:91
KigWidget
This class is the real widget showing the document.
Definition: kig_view.h:50
ObjectConstructorActionsProvider
Definition: objectconstructoractionsprovider.h:30
builtinobjectactionsprovider.h
NormalModePopupObjects::mmenuslast
QMenu * mmenuslast[NumberOfMenus]
Definition: popup.h:92
numberofcolors
const int numberofcolors
Definition: popup.cc:259
NormalModePopupObjects::mproviders
std::vector< PopupActionProvider * > mproviders
Definition: popup.h:89
NormalModePopupObjects::~NormalModePopupObjects
~NormalModePopupObjects()
Definition: popup.cc:237
builtindocumentactionsprovider.h
NormalModePopupObjects::mmode
NormalMode & mmode
Definition: popup.h:87
ObjectTypeActionsProvider
This file is part of Kig, a KDE program for Interactive Geometry...
Definition: objecttypeactionsprovider.h:25
objecttypeactionsprovider.h
propertiesactionsprovider.h
NormalModePopupObjects::mobjs
std::vector< ObjectHolder * > mobjs
Definition: popup.h:86
KigPart
This is a "Part".
Definition: kig_part.h:68
NormalModePopupObjects::NormalModePopupObjects
NormalModePopupObjects(KigPart &part, KigWidget &view, NormalMode &mode, const std::vector< ObjectHolder * > &objs, const QPoint &p)
Definition: popup.cc:85
TextImp::stype
static const ObjectImpType * stype()
Definition: text_imp.cc:143
scriptactionsprovider.h
NormalMode
Definition: normal.h:26
uint
unsigned int uint
Definition: object_imp.h:87
MAXMENUITEMS
#define MAXMENUITEMS
This file is part of Kig, a KDE program for Interactive Geometry...
Definition: popup.cc:77
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