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 TOOLBAR_H 00011 #define TOOLBAR_H 00012 00013 #include "Window.h" 00014 00015 #include <string> 00016 #include <vector> 00017 00018 class MenuBar; 00019 class QAction; 00020 class QWidget; 00021 00022 /** 00023 * A widget containing buttons and other widgets to invoke custom processes. 00024 * 00025 * Each toolbar contains a menu bar as the first widget in the toolbar in 00026 * which command actions can be added that relate to the other widgets and 00027 * buttons on the toolbar. 00028 * 00029 * This class provides a means for objects to add and remove buttons and other 00030 * widgets from toolbars displayed in the main application window. The 00031 * location of the button or widget can also be specified relative to the 00032 * other buttons and widgets on the toolbar. 00033 * 00034 * This subclass of Subject will notify upon the following conditions: 00035 * - The following methods are called: addButton(), insertWidget(), 00036 * addSeparator(), and removeItem(). 00037 * - Everything else documented in Window. 00038 * 00039 * @see Window 00040 */ 00041 class ToolBar : public Window 00042 { 00043 public: 00044 /** 00045 * Emitted when the toolbar is shown. 00046 */ 00047 SIGNAL_METHOD(ToolBar, Shown) 00048 00049 /** 00050 * Emitted when the toolbar is hidden. 00051 */ 00052 SIGNAL_METHOD(ToolBar, Hidden) 00053 00054 /** 00055 * Returns the menu bar associated with this toolbar. 00056 * 00057 * @return A pointer to the toolbar's menu bar. 00058 */ 00059 virtual MenuBar* getMenuBar() const = 0; 00060 00061 /** 00062 * Adds the button to the toolbar. 00063 * 00064 * This method adds a button to the toolbar based on the given action. The 00065 * object calling this method is responsible for setting the icon and any 00066 * other associated properties with the action and also any necessary 00067 * connections to slot methods. 00068 * 00069 * The button is added directly to the toolbar and the user will not be 00070 * able to edit and save a keyboard shortcut in the user-defined 00071 * configuration settings. To allow the user to edit the keyboard 00072 * shortcut, call the overloaded 00073 * addButton(QAction*, const std::string&, QAction*) method or call 00074 * DesktopServices::initializeAction() prior to calling this method. 00075 * 00076 * @param pAction 00077 * The action to add to the toolbar as a button. 00078 * @param pBefore 00079 * The button or widget that should immediately follow the added 00080 * button. The button is added at the end of the toolbar if 00081 * \b NULL is passed in or if the given action does not exist on 00082 * the toolbar. 00083 * 00084 * @notify This method will notify Subject::signalModified if the action 00085 * was successfully added to the toolbar. 00086 * 00087 * @see addSeparator() 00088 */ 00089 virtual void addButton(QAction* pAction, QAction* pBefore = NULL) = 0; 00090 00091 /** 00092 * Adds the button to the toolbar. 00093 * 00094 * This method adds a button to the toolbar based on the given action and 00095 * allows the user to edit and save a keyboard shortcut based on the given 00096 * context. If the user should not be able to edit the shortcut, call the 00097 * overloaded addButton(QAction*, QAction*) method instead. 00098 * 00099 * The object calling this method is responsible for setting the icon and 00100 * any other associated properties with the action and also any necessary 00101 * connections to slot methods. 00102 * 00103 * @param pAction 00104 * The action to add to the toolbar as a button. 00105 * @param shortcutContext 00106 * The context name for the keyboard shortcut of the action. When 00107 * the user edits keyboard shortcuts, the shortcuts are grouped 00108 * according to their context string. Contexts can be nested by 00109 * using a slash (/) between context levels. If the top-level 00110 * context name is the same as a plug-in name, the shortcut is 00111 * grouped under a single Plug-Ins context. Passing in an empty 00112 * string indicates that the user should not be able to edit the 00113 * keyboard shortcut of the command, which is the same as calling 00114 * the overloaded addButton(QAction*, QAction*) method. 00115 * @param pBefore 00116 * The button or widget that should immediately follow the added 00117 * button. The button is added at the end of the toolbar if 00118 * \b NULL is passed in or if the given action does not exist on 00119 * the toolbar. 00120 * 00121 * @notify This method will notify Subject::signalModified if the action 00122 * was successfully added to the toolbar. 00123 * 00124 * @see addSeparator() 00125 */ 00126 virtual void addButton(QAction* pAction, const std::string& shortcutContext, QAction* pBefore = NULL) = 0; 00127 00128 /** 00129 * Adds an existing widget to the toolbar. 00130 * 00131 * @param pWidget 00132 * The widget to add to the toolbar. 00133 * @param pBefore 00134 * The button or widget that should immediately follow the added 00135 * widget. The separator is added at the end of the toolbar if 00136 * \b NULL is passed in or if the given action does not exist on 00137 * the toolbar. 00138 * 00139 * @return A pointer to the Qt action for the widget created by the 00140 * toolbar. 00141 * 00142 * @notify This method will notify Subject::signalModified if the widget 00143 * was successfully added to the toolbar. 00144 */ 00145 virtual QAction* insertWidget(QWidget* pWidget, QAction* pBefore = NULL) = 0; 00146 00147 /** 00148 * Adds a separator to the toolbar. 00149 * 00150 * This method creates a separator widget on the toolbar to separate 00151 * buttons into groups. 00152 * 00153 * @param pBefore 00154 * The button or widget that should immediately follow the added 00155 * separator. The separator is added at the end of the toolbar if 00156 * \b NULL is passed in or if the given action does not exist on 00157 * the toolbar. 00158 * 00159 * @return A pointer to the Qt action for the separator created by the 00160 * toolbar. 00161 * 00162 * @notify This method will notify Subject::signalModified if the separator 00163 * was successfully added to the toolbar. 00164 */ 00165 virtual QAction* addSeparator(QAction* pBefore = NULL) = 0; 00166 00167 /** 00168 * Returns all buttons and widgets on the toolbar as actions. 00169 * 00170 * @return A vector of actions defining all buttons and widgets on the 00171 * toolbar. 00172 */ 00173 virtual std::vector<QAction*> getItems() const = 0; 00174 00175 /** 00176 * Removes a button or widget from the toolbar. 00177 * 00178 * This method removes the button or widget defined by the given action 00179 * from the toolbar. The action is not deleted. 00180 * 00181 * @param pAction 00182 * The action defining the button or widget to remove from the 00183 * toolbar. 00184 * 00185 * @notify This method will notify Subject::signalModified if the action 00186 * was successfully removed from the toolbar. 00187 */ 00188 virtual void removeItem(QAction* pAction) = 0; 00189 00190 /** 00191 * Shows the toolbar. 00192 * 00193 * This method will display the toolbar only if it's hidden. 00194 * If the toolbar already shown, this method will do nothing. 00195 * 00196 * @notify This method will notify signalShown() if the window was 00197 * successfully displayed from a previously hidden state. 00198 * 00199 * @see hide() 00200 */ 00201 virtual void show() = 0; 00202 00203 /** 00204 * Hides the toolbar. 00205 * 00206 * This method will hide the toolbar only if it's shown. 00207 * If the toolbar already hidden, this method will do nothing. 00208 * 00209 * @notify This method will notify signalHidden() if the window was 00210 * successfully hidden from a previously visible state. 00211 * 00212 * @see show() 00213 */ 00214 virtual void hide() = 0; 00215 00216 /** 00217 * This method will return the current visiblity state of the toolbar. 00218 * 00219 * @return Returns \c true if the toolbar is shown or \c false 00220 * if the toolbar is hidden. 00221 */ 00222 virtual bool isShown() const = 0; 00223 00224 protected: 00225 /** 00226 * This should be destroyed by calling DesktopServices::deleteWindow. 00227 */ 00228 virtual ~ToolBar() {} 00229 }; 00230 00231 #endif