00001 /* 00002 * The information in this file is 00003 * Copyright(c) 2007 Ball Aerospace & Technologies Corporation 00004 * and is subject to the terms and conditions of the 00005 * GNU Lesser General Public License Version 2.1 00006 * The license text is available from 00007 * http://www.gnu.org/licenses/lgpl.html 00008 */ 00009 00010 #ifndef CONTEXTMENUACTION_H 00011 #define CONTEXTMENUACTION_H 00012 00013 #include "EnumWrapper.h" 00014 00015 #include <string> 00016 00017 class QAction; 00018 00019 /** 00020 * An action to be used on a context menu. 00021 * 00022 * @see \ref contextmenus "Customizing context menus" 00023 */ 00024 struct ContextMenuAction 00025 { 00026 /** 00027 * Defines how the associated buddy action is used when adding this action 00028 * to the context menu. 00029 */ 00030 enum BuddyTypeEnum 00031 { 00032 BEFORE, /**< This action should appear above the buddy action. */ 00033 AFTER, /**< This action should appear below the buddy action. */ 00034 REMOVE /**< The buddy action should be removed from the context menu. */ 00035 }; 00036 00037 /** 00038 * @EnumWrapper ::BuddyTypeEnum. 00039 */ 00040 typedef EnumWrapper<BuddyTypeEnum> BuddyType; 00041 00042 /** 00043 * Creates the context menu action. 00044 * 00045 * @param pAction 00046 * The Qt action to add to the context menu. If \b NULL is passed 00047 * in, this action can only be used to remove an action from the 00048 * menu. 00049 * @param id 00050 * The unique identifier for this action. If an empty string is 00051 * passed in, this action can only be used to remove an action 00052 * from the menu. 00053 */ 00054 ContextMenuAction(QAction* pAction, const std::string& id) : 00055 mpAction(pAction), 00056 mId(id) 00057 { 00058 } 00059 00060 /** 00061 * Assigns the values in this action to those of another action. 00062 * 00063 * @param menuAction 00064 * The source action from which to assign this action's values. 00065 * 00066 * @return A reference to *this, which has been changed to have the same 00067 * values as \em menuAction. 00068 */ 00069 ContextMenuAction& operator=(const ContextMenuAction& menuAction) 00070 { 00071 if (this != &menuAction) 00072 { 00073 mpAction = menuAction.mpAction; 00074 mId = menuAction.mId; 00075 mBuddyType = menuAction.mBuddyType; 00076 mBuddyId = menuAction.mBuddyId; 00077 } 00078 00079 return *this; 00080 } 00081 00082 /** 00083 * Compares two actions. 00084 * 00085 * @param menuAction 00086 * The action to compare against this action. 00087 * 00088 * @return Returns \b true if all values in this action are equal to those 00089 * of \em menuAction. 00090 */ 00091 bool operator==(const ContextMenuAction& menuAction) const 00092 { 00093 if ((menuAction.mpAction == mpAction) && (menuAction.mId == mId) && 00094 (menuAction.mBuddyType == mBuddyType) && (menuAction.mBuddyId == mBuddyId)) 00095 { 00096 return true; 00097 } 00098 00099 return false; 00100 } 00101 00102 /** 00103 * The Qt action that should appear on the context menu. 00104 * 00105 * If this value is \b NULL, this ContextMenuAction can only be used to 00106 * remove an action from the menu. 00107 * 00108 * @see mBuddyId 00109 */ 00110 QAction* mpAction; 00111 00112 /** 00113 * The unique identifier for the Qt action that should appear on the 00114 * context menu. 00115 * 00116 * If this string is empty, this ContextMenuAction can only be used to 00117 * remove an action from the menu. 00118 * 00119 * @see mBuddyId 00120 */ 00121 std::string mId; 00122 00123 /** 00124 * Defines how the buddy action is used. 00125 * 00126 * @see BuddyType 00127 */ 00128 BuddyType mBuddyType; 00129 00130 /** 00131 * The unique identifier for the associated buddy action. 00132 * 00133 * The buddy action is used as a reference when placing this action on the 00134 * menu. It can also be used as an action which should be removed from the 00135 * menu. 00136 * 00137 * @see mBuddyType 00138 */ 00139 std::string mBuddyId; 00140 }; 00141 00142 #endif