00001 /* 00002 * The information in this file is 00003 * Copyright(c) 2009 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 DOCKWINDOWSHELL_H 00011 #define DOCKWINDOWSHELL_H 00012 00013 #include <QtCore/QObject> 00014 #include <QtCore/QPointer> 00015 #include <QtGui/QAction> 00016 #include <QtGui/QWidget> 00017 00018 #include "AttachmentPtr.h" 00019 #include "DockWindow.h" 00020 #include "ExecutableShell.h" 00021 00022 /** 00023 * A plug-in shell class for creating dock windows. 00024 * 00025 * This class provides capabilities to create a dock window in the main 00026 * application window. A dock window plug-in is executed on application 00027 * startup and when a new session is created. The execute() method creates 00028 * the dock window with the same name as the plug-in and hides it by default. 00029 * 00030 * Subclasses are only responsible for implementing the following items: 00031 * - Creating the action that toggles the display of the dock window and 00032 * adding it to a menu and/or toolbar in an override of the createAction() 00033 * method. 00034 * - Creating the widget that is used as the dock window contents in an 00035 * override of the createWidget() method. 00036 * - Removing the action from a menu and/or toolbar and deleting it in the 00037 * subclass destructor. 00038 * 00039 * Subclasses do not need to destroy the contents widget since it is 00040 * automatically destroyed when the dock window is destroyed. 00041 * 00042 * @see ExecutableShell 00043 */ 00044 class DockWindowShell : public QObject, public ExecutableShell 00045 { 00046 Q_OBJECT 00047 00048 public: 00049 using ExecutableShell::setName; 00050 00051 /** 00052 * Creates a dock window plug-in. 00053 * 00054 * The constructor sets the following values on the plug-in: 00055 * - The type is set to PlugInManagerServices::DockWindowType(). 00056 * - Multiple instances are not allowed. 00057 * - The plug-in is executed on startup. 00058 * - The plug-in is not destroyed after executing. 00059 * - Wizard support is disabled. 00060 * - The plug-in defaults to execute in interactive mode. 00061 * 00062 * @see getType() 00063 */ 00064 DockWindowShell(); 00065 00066 /** 00067 * Destroys the dock window plug-in. 00068 * 00069 * The destructor destroys the dock window. Subclasses should remove the 00070 * action created in createAction() from the menu and/or toolbar to which 00071 * it was added and then delete the action. Subclasses do not need 00072 * to destroy the contents widget created in createWidget() since it is 00073 * destroyed when the dock window is destroyed. 00074 */ 00075 virtual ~DockWindowShell(); 00076 00077 /** 00078 * @copydoc Executable::setBatch() 00079 * 00080 * @default The default implementation calls the base class to set the 00081 * internal flag and returns \c false indicating that batch mode 00082 * operation is not supported. 00083 */ 00084 virtual bool setBatch(); 00085 00086 /** 00087 * @copydoc Executable::getInputSpecification() 00088 * 00089 * @default The default implementation sets \em pArgList to \c NULL and 00090 * returns \c true. 00091 */ 00092 virtual bool getInputSpecification(PlugInArgList*& pArgList); 00093 00094 /** 00095 * @copydoc Executable::getOutputSpecification() 00096 * 00097 * @default The default implementation sets \em pArgList to \c NULL and 00098 * returns \c true. 00099 */ 00100 virtual bool getOutputSpecification(PlugInArgList*& pArgList); 00101 00102 /** 00103 * Creates the dock window. 00104 * 00105 * This method is called on application startup and when a new session is 00106 * created. The createAction() method is called for subclasses to create 00107 * an action and add it to a menu and/or toolbar. If a valid non-\c NULL 00108 * action is returned, this method sets the action to be a checkable action, 00109 * sets the action to not auto-repeat, and connects its triggered() signal 00110 * to the displayDockWindow() slot. 00111 * 00112 * After initializing the action, the dock window is created by calling 00113 * DesktopServices::createWindow() with the window name set to the same name 00114 * as the plug-in. If the dock window already exists, the existing window 00115 * is used instead of creating a new window. If a new window is created, it 00116 * is hidden by default. 00117 * 00118 * After the dock window is created or the existing dock window is obtained, 00119 * the icon which appears in the session explorer is set to the created 00120 * action's icon, and the createWidget() method is called to create the 00121 * widget that should be used as the dock window's contents widget. If 00122 * createWidget() returns a valid non-\c NULL widget, this method 00123 * automatically sets it into the dock window by calling 00124 * DockWindow::setWidget(). 00125 * 00126 * @param pInArgList 00127 * This parameter is ignored since the default implementation of 00128 * getInputSpecification() does not define any input arguments. 00129 * @param pOutArgList 00130 * This parameter is ignored since the default implementation of 00131 * getOutputSpecification() does not define any output arguments. 00132 * 00133 * @return Returns \c true if the action has been successfully created and 00134 * the dock window has been successfully created or the existing 00135 * window obtained from DesktopServices. Returns \c false if the 00136 * plug-in is set to execute in batch mode, if the call to 00137 * createAction() returns \c false, or if the dock window does not 00138 * already exist and it could not be created from DesktopServices. 00139 */ 00140 virtual bool execute(PlugInArgList* pInArgList, PlugInArgList* pOutArgList); 00141 00142 /** 00143 * Saves the current state of the dock window plug-in. 00144 * 00145 * The current displayed state of the dock window is saved so that the 00146 * check state of the action can be properly initialized when loaded. 00147 * Subclasses should override this method to save the current state of 00148 * the contents widget if necessary. 00149 * 00150 * @param serializer 00151 * The object with which to save the item as part of the current 00152 * session. 00153 * 00154 * @return Returns \c true if the window display state was successfully 00155 * saved; otherwise returns \c false. 00156 */ 00157 virtual bool serialize(SessionItemSerializer& serializer) const; 00158 00159 /** 00160 * Loads the current state of the dock window plug-in. 00161 * 00162 * The displayed state of the dock window is loaded and the check state of 00163 * the action initialized. Subclasses should override this method to load 00164 * the current state of the contents widget if necessary. 00165 * 00166 * @param deserializer 00167 * The object from which the item is loaded as part of the current 00168 * session. 00169 * 00170 * @return Returns \c true if the window display state was successfully 00171 * loaded; otherwise returns \c false. 00172 */ 00173 virtual bool deserialize(SessionItemDeserializer& deserializer); 00174 00175 protected: 00176 /** 00177 * Creates the action to toggle the display of the dock window. 00178 * 00179 * This method is called from execute() and subclasses must implement it to 00180 * create an action and add it to a menu and/or toolbar. Typically, the 00181 * action is created by calling MenuBar::addCommand(). After the action is 00182 * created, only the action icon, tool tip, and status tip need to be set. 00183 * The execute() method will set the action to be checkable and to not 00184 * auto-repeat, and will connect it to the displayDockWindow() slot. 00185 * 00186 * The action should be removed from the menu and/or toolbar and deleted in 00187 * the subclass destructor. 00188 * 00189 * Subclasses do not need to store a pointer to the created action. It can 00190 * be retrieved by calling getAction(). 00191 * 00192 * @return A pointer to the created action. The dock window will not be 00193 * created and execute() will return \c false if \c NULL is 00194 * returned. 00195 */ 00196 virtual QAction* createAction() = 0; 00197 00198 /** 00199 * Returns the action that is used to toggle the display of the dock window. 00200 * 00201 * @return Returns a pointer to the action that was created in 00202 * createAction(). Returns \c NULL if createAction() has not yet 00203 * been called. 00204 * 00205 * @see getAction() const 00206 */ 00207 QAction* getAction(); 00208 00209 /** 00210 * Returns read-only access to the action that is used to toggle the display 00211 * of the dock window. 00212 * 00213 * @return Returns a const pointer to the action that was created in 00214 * createAction(). Returns \c NULL if createAction() has not yet 00215 * been called. The action represented by the returned pointer 00216 * should not be modified. To modify its values, call the 00217 * non-const version of getAction() instead. 00218 * 00219 * @see getAction() 00220 */ 00221 const QAction* getAction() const; 00222 00223 /** 00224 * Creates the widget that is added to the dock window as its contents. 00225 * 00226 * This method is called from execute() after the action has been 00227 * successfully created. Subclasses do not need to destroy the created 00228 * widget because it is automatically destroyed when the dock window is 00229 * destroyed. 00230 * 00231 * @return A pointer to the created widget that is set into the dock 00232 * window. The dock window will still be successfully created if 00233 * \c NULL is returned, but the window will be empty. 00234 */ 00235 virtual QWidget* createWidget() = 0; 00236 00237 /** 00238 * Returns the widget that is set into the dock window. 00239 * 00240 * This method is a convenience method that calls DockWindow::getWidget(). 00241 * 00242 * @return Returns a pointer to the widget that was created in 00243 * createWidget(). Returns \c NULL if createWidget() has not yet 00244 * been called. 00245 */ 00246 QWidget* getWidget() const; 00247 00248 /** 00249 * Returns a pointer to the dock window. 00250 * 00251 * @return Returns a pointer to the dock window that was created in 00252 * execute(). Returns \c NULL if the dock window has not yet been 00253 * created, or if execute() returned \c false. 00254 * 00255 * @see getDockWindow() const 00256 */ 00257 DockWindow* getDockWindow(); 00258 00259 /** 00260 * Returns read-only access to the dock window. 00261 * 00262 * @return Returns a const pointer to the dock window that was created in 00263 * execute(). Returns \c NULL if the dock window has not yet been 00264 * created, or if execute() returned \c false. The dock window 00265 * represented by the returned pointer should not be modified. To 00266 * modify its values, call the non-const version of getDockWindow() 00267 * instead. 00268 * 00269 * @see getDockWindow() 00270 */ 00271 const DockWindow* getDockWindow() const; 00272 00273 protected slots: 00274 /** 00275 * Toggles the display state of the dock window. 00276 * 00277 * This slot is called automatically when the user triggers the action 00278 * created in createAction(). 00279 * 00280 * @param bDisplay 00281 * Shows the window if the value is \c true or hides the window if 00282 * the value is \c false. 00283 */ 00284 void displayDockWindow(bool bDisplay); 00285 00286 private: 00287 DockWindowShell(const DockWindowShell& rhs); 00288 DockWindowShell& operator=(const DockWindowShell& rhs); 00289 00290 void windowShown(Subject& subject, const std::string& signal, const boost::any& value); 00291 void windowHidden(Subject& subject, const std::string& signal, const boost::any& value); 00292 00293 QPointer<QAction> mpWindowAction; 00294 AttachmentPtr<DockWindow> mpDockWindow; 00295 }; 00296 00297 #endif