1 /* 2 SPDX-License-Identifier: GPL-2.0-or-later 3 SPDX-FileCopyrightText: 2003-2020 Umbrello UML Modeller Authors <umbrello-devel@kde.org> 4 */ 5 6 #ifndef LISTPOPUPMENU_H 7 #define LISTPOPUPMENU_H 8 9 #include "basictypes.h" 10 #include "umllistviewitem.h" 11 #include "umlobject.h" 12 #include "widgetbase.h" 13 #include <kmenu.h> 14 15 #include <QHash> 16 17 class UMLCategory; 18 class ListPopupMenuPrivate; 19 20 /** 21 * A popup menu that depending on what type is set to will 22 * display a different menu. 23 * 24 * The data field of actions is used to carry user data 25 * between objects. Because different types of data are used, a map is loaded 26 * with an enum as key (see @ref DataType). 27 * 28 * @short Displays a popup menu. 29 * @author Paul Hensgen <phensgen@techie.com> 30 * Bugs and comments to umbrello-devel@kde.org or https://bugs.kde.org 31 */ 32 class ListPopupMenu : public KMenu 33 { 34 Q_OBJECT 35 Q_ENUMS(MenuType) 36 Q_ENUMS(DataType) 37 public: 38 enum MenuType ///< This type hosts all possible menu entry types 39 { 40 mt_Model, 41 // diagrams 42 mt_Activity_Diagram, 43 mt_Class_Diagram, 44 mt_Collaboration_Diagram, 45 mt_Component_Diagram, 46 mt_Deployment_Diagram, 47 mt_EntityRelationship_Diagram, 48 mt_Sequence_Diagram, 49 mt_State_Diagram, 50 mt_UseCase_Diagram, 51 mt_Logical_Folder, 52 mt_UseCase_Folder, 53 mt_Component_Folder, 54 mt_Deployment_Folder, 55 mt_EntityRelationship_Folder, 56 // widgets, uml objects 57 mt_Accept_Signal, 58 mt_Accept_Time_Event, 59 mt_Activity, 60 mt_Activity_Transition, 61 mt_Actor, 62 mt_Artifact, 63 mt_Attribute, 64 mt_Branch, 65 mt_Category, 66 mt_CheckConstraint, 67 mt_Choice, 68 mt_Class, 69 mt_CombinedState, 70 mt_Component, 71 mt_Datatype, 72 mt_DeepHistory, 73 mt_DisjointSpecialisation, 74 mt_EditCombinedState, 75 mt_End_Activity, 76 mt_End_State, 77 mt_Entity, 78 mt_EntityAttribute, 79 mt_Enum, 80 mt_EnumLiteral, 81 mt_Exception, 82 mt_FloatText, 83 mt_Final_Activity, 84 mt_ForeignKeyConstraint, 85 mt_Fork, 86 mt_GoToStateDiagram, 87 mt_Initial_Activity, 88 mt_Initial_State, 89 mt_Invoke_Activity, 90 mt_Instance, 91 mt_InstanceAttribute, 92 mt_Interface, 93 mt_InterfaceComponent, 94 mt_InterfaceProvided, 95 mt_InterfaceRequired, 96 mt_Junction, 97 mt_MessageAsynchronous, 98 mt_MessageCreation, 99 mt_MessageDestroy, 100 mt_MessageFound, 101 mt_MessageLost, 102 mt_MessageSynchronous, 103 mt_Node, 104 mt_Note, 105 mt_Object, 106 mt_Object_Node, 107 mt_Operation, 108 mt_OverlappingSpecialisation, 109 mt_Package, 110 mt_Param_Activity, 111 mt_Pin, 112 mt_Port, 113 mt_PrePostCondition, 114 mt_PrimaryKeyConstraint, 115 mt_Region, 116 mt_SelectStateDiagram, 117 mt_Send_Signal, 118 mt_ShallowHistory, 119 mt_State, 120 mt_StateFork, 121 mt_StateJoin, 122 mt_StateTransition, 123 mt_Subsystem, 124 mt_Template, 125 mt_Union, 126 mt_UniqueConstraint, 127 mt_UseCase, 128 // new from dialogs 129 mt_New_Activity, 130 mt_New_Attribute, 131 mt_New_EntityAttribute, 132 mt_New_EnumLiteral, 133 mt_New_InstanceAttribute, 134 mt_New_Operation, 135 mt_New_Parameter, 136 mt_New_Template, 137 mt_RemoveStateDiagram, 138 mt_ReturnToClass, 139 mt_ReturnToCombinedState, 140 // selection 141 // visual properties 142 mt_Hide_Attribute_Signature_Selection, 143 mt_Hide_Attributes_Selection, // Unset visual property on multiple widgets 144 mt_Hide_Destruction_Box, 145 mt_Hide_NonPublic_Selection, // Could be named "show public only" 146 mt_Hide_Operation_Signature_Selection, 147 mt_Hide_Operations_Selection, // Hide operations 148 mt_Hide_Packages_Selection, 149 mt_Hide_Stereotypes_Selection, 150 mt_Hide_Visibility_Selection, 151 mt_Show_Attribute_Signature, 152 mt_Show_Attribute_Signature_Selection, 153 mt_Show_Attributes_Selection, // Set visual property on multiple widgets 154 mt_Show_Attributes, // Toggle visual property on a widget 155 mt_Show_Destruction_Box, 156 mt_Show_Documentation, 157 mt_Show_NonPublic_Selection, // Could be named "hide public only" (crazy!) 158 mt_Show_Operation_Signature, 159 mt_Show_Operation_Signature_Selection, 160 mt_Show_Operations_Selection, // Show operations 161 mt_Show_Operations, // Toggle 'show operations' 162 mt_Show_Packages, // etc... 163 mt_Show_Packages_Selection, 164 mt_Show_Public_Only, 165 mt_Show_Stereotypes, 166 mt_Show_Stereotypes_Selection, 167 mt_Show_Visibility_Selection, 168 mt_Visibility, 169 // other 170 mt_DrawAsCircle, 171 mt_ChangeToClass, 172 mt_ChangeToInterface, 173 mt_ChangeToPackage, 174 mt_Open_File, 175 mt_Rename_Object, 176 mt_Select_Operation, 177 mt_Properties, 178 mt_Rename, 179 mt_NameAsTooltip, 180 mt_Show, 181 mt_Delete, 182 mt_Export_Image, 183 mt_Import_Class, 184 mt_Import_Project, 185 mt_Cut, 186 mt_Copy, 187 mt_Paste, 188 mt_Clear, 189 mt_Redo, 190 mt_Undo, 191 mt_Reset_Label_Positions, 192 mt_Line_Color, 193 mt_Line_Color_Selection, 194 mt_Fill_Color, 195 mt_Fill_Color_Selection, 196 mt_Use_Fill_Color, 197 mt_Set_Use_Fill_Color_Selection, 198 mt_Unset_Use_Fill_Color_Selection, 199 mt_Rename_MultiA, 200 mt_Rename_MultiB, 201 mt_Rename_Name, 202 mt_Rename_RoleAName, 203 mt_Rename_RoleBName, 204 mt_Change_Font, 205 mt_Change_Font_Selection, 206 mt_SnapToGrid, 207 mt_SnapComponentSizeToGrid, 208 mt_ShowDocumentationIndicator, 209 mt_ShowSnapGrid, 210 mt_AutoResize, 211 mt_Resize, 212 mt_Up, 213 mt_Down, 214 mt_FlipHorizontal, 215 mt_FlipVertical, 216 mt_Add_Point, 217 mt_Delete_Point, 218 mt_Auto_Layout_Spline, 219 220 mt_Expand_All, // Expand all items in the list 221 mt_Collapse_All, // Collapse all items in the list 222 223 mt_Refactoring, 224 mt_ViewCode, // view code document contents 225 mt_Clone, // Create a deep copy of the object. 226 mt_Externalize_Folder, // Mark folder for saving as separate submodel 227 mt_Internalize_Folder, // Reintegrate separate submodel into main model 228 229 mt_AddInteractionOperand, // add a dash line to an alternative or a parallel combined fragment 230 mt_Apply_Layout, // apply automatically created layout 231 mt_Apply_Layout1, // apply automatically created layout 232 mt_Apply_Layout2, // apply automatically created layout 233 mt_Apply_Layout3, // apply automatically created layout 234 mt_Apply_Layout4, // apply automatically created layout 235 mt_Apply_Layout5, // apply automatically created layout 236 mt_Apply_Layout6, // apply automatically created layout 237 mt_Apply_Layout7, // apply automatically created layout 238 mt_Apply_Layout8, // apply automatically created layout 239 mt_Apply_Layout9, // apply automatically created layout 240 241 mt_LayoutDirect, // associations with direct lines 242 mt_LayoutSpline, // associations with slines 243 mt_LayoutOrthogonal, // associations with orthogonal lines 244 mt_LayoutPolyline, // associations with polylines 245 246 mt_Align_Right, 247 mt_Align_Left, 248 mt_Align_Top, 249 mt_Align_Bottom, 250 mt_Align_VerticalMiddle, 251 mt_Align_HorizontalMiddle, 252 mt_Align_VerticalDistribute, 253 mt_Align_HorizontalDistribute, 254 mt_Import_from_File, 255 mt_Remove, 256 // add new entries above 257 mt_Undefined = - 1 258 }; 259 260 static QString toString(MenuType menu); 261 262 enum DataType ///< Key value of the data map used in actions. 263 { 264 dt_MenuPointer, 265 dt_ApplyLayout 266 }; 267 268 static QString toString(DataType data); 269 static QVariant dataFromAction(DataType key, QAction* action); 270 271 ListPopupMenu(QWidget* parent = 0); 272 273 virtual ~ListPopupMenu(); 274 275 static UMLObject::ObjectType convert_MT_OT(MenuType mt); 276 277 static ListPopupMenu* menuFromAction(QAction *action); 278 static MenuType typeFromAction(QAction *action); 279 280 QAction* getAction(MenuType idx); 281 282 void setActionEnabled(MenuType idx, bool value); 283 284 MenuType getMenuType(QAction* action); 285 286 void dumpActions(const QString &title); 287 288 KMenu *newMenu(const QString &title, QWidget *widget); 289 void addMenu(KMenu *menu); 290 protected: 291 void insert(MenuType m); 292 void insertFromActionKey(const MenuType m, KMenu *menu, const QString &action); 293 void insert(const MenuType m, KMenu* menu); 294 void insert(const MenuType m, KMenu* menu, const QIcon & icon, const QString & text); 295 void insert(const MenuType m, KMenu* menu, const QString & text, const bool checkable = false); 296 void insert(const MenuType m, const QIcon & icon, const QString & text); 297 void insert(const MenuType m, const QString & text, const bool checkable = false); 298 299 void insertContainerItems(bool folders, bool diagrams, bool packages); 300 void insertContainerItems(KMenu* menu, bool folders, bool diagrams, bool packages); 301 void insertAssociationTextItem(const QString &label, MenuType mt); 302 303 KMenu *makeNewMenu(); 304 void insertSubMenuCategoryType(UMLCategory *category); 305 306 void setActionChecked(MenuType idx, bool value); 307 void setupActionsData(); 308 309 QHash<MenuType, QAction*> m_actions; 310 ListPopupMenuPrivate *d; 311 }; 312 313 /// Need this for ability to store ListPopupMenu* in a QVariant 314 Q_DECLARE_METATYPE(ListPopupMenu*) 315 316 #endif 317