1 /*
2     This file is part of Kig, a KDE program for Interactive Geometry...
3     SPDX-FileCopyrightText: 2002 Dominique Devriese <devriese@kde.org>
4 
5     SPDX-License-Identifier: GPL-2.0-or-later
6 */
7 
8 #ifndef KIG_MODES_POPUP_H
9 #define KIG_MODES_POPUP_H
10 
11 #include <vector>
12 
13 #include <QMenu>
14 
15 class QAction;
16 class KigPart;
17 class KigWidget;
18 class NormalMode;
19 class PopupActionProvider;
20 class ObjectHolder;
21 
22 /**
23  * This is the popup menu that appears when you click on selected
24  * objects in NormalMode..  It's quite complex, since it has to fetch
25  * a lot of information from various places, and dispatch it again
26  * when the user selects something.
27  * Update: I'm also using it for when you clicked on an empty space in
28  * the document, because the difference between the two cases is not
29  * that important, and this class is generic enough to handle both
30  * cases..  When this is the case, mobjs is empty, some
31  * PopupActionProviders are disabled, and some others enabled..
32  */
33 class NormalModePopupObjects
34   : public QMenu
35 {
36   Q_OBJECT
37 
38 public:
39   NormalModePopupObjects( KigPart& part, KigWidget& view,
40                           NormalMode& mode,
41                           const std::vector<ObjectHolder*>& objs, const QPoint& p );
42   ~NormalModePopupObjects();
43 
44   // the different "menu's", the toplevel is considered as just
45   // another menu..
46   enum { TransformMenu = 0, TestMenu, ConstructMenu, StartMenu, ShowMenu,
47          SetColorMenu, SetSizeMenu, SetStyleMenu, ToplevelMenu,
48          SetCoordinateSystemMenu, NumberOfMenus };
49 
50   // used by the PopupActionProvider's to add actions to us..
51   QAction* addInternalAction( int menu, const QString& name, int id );
52   QAction* addInternalAction( int menu, const QIcon& icon, const QString& name, int id );
53   QAction* addInternalAction( int menu, const QIcon& pix, int id );
54   QAction* addInternalAction( int menu, QAction* act );
55 
objects()56   std::vector<ObjectHolder*> objects() const { return mobjs; }
part()57   KigPart& part() { return mpart; }
widget()58   KigWidget& widget() { return mview; }
plc()59   QPoint plc() { return mplc; }
60 
onlyLabels()61   bool onlyLabels() const { return monlylabels; }
62 
63 protected:
64   void activateAction( int menu, int action );
65 
66 private slots:
67   void toplevelMenuSlot( QAction* );
68 
69 protected:
70   QPoint mplc;
71   KigPart& mpart;
72   KigWidget& mview;
73   std::vector<ObjectHolder*> mobjs;
74   NormalMode& mmode;
75 
76   std::vector<PopupActionProvider*> mproviders;
77 
78   QMenu* mmenus[NumberOfMenus];
79   QMenu* mmenuslast[NumberOfMenus];
80   /* mp: usually mmenus[i] = mmenuslast[i], however, if there are too many entries
81    * in the submenu, new subsubmenus are added and mmenuslast[i] points to
82    * the last of these (where new actions can be inserted)
83    * presently this happens only in the "start" menu for a point
84    */
85 
86 private:
87   bool monlylabels;
88 };
89 
90 #endif
91