CommandWindow.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) 2005 Werner Mayer <wmayer[at]users.sourceforge.net>     *
00003  *                                                                         *
00004  *   This file is part of the FreeCAD CAx development system.              *
00005  *                                                                         *
00006  *   This library is free software; you can redistribute it and/or         *
00007  *   modify it under the terms of the GNU Library General Public           *
00008  *   License as published by the Free Software Foundation; either          *
00009  *   version 2 of the License, or (at your option) any later version.      *
00010  *                                                                         *
00011  *   This library  is distributed in the hope that it will be useful,      *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00014  *   GNU Library General Public License for more details.                  *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Library General Public     *
00017  *   License along with this library; see the file COPYING.LIB. If not,    *
00018  *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
00019  *   Suite 330, Boston, MA  02111-1307, USA                                *
00020  *                                                                         *
00021  ***************************************************************************/
00022 
00023 
00024 #include "PreCompiled.h"
00025 #ifndef _PreComp_
00026 # include <QStatusBar>
00027 #endif
00028 
00029 #include "Command.h"
00030 #include "Action.h"
00031 #include "Application.h"
00032 #include "MainWindow.h"
00033 #include "View.h"
00034 #include "Document.h"
00035 #include "DlgActivateWindowImp.h"
00036 #include "DockWindowManager.h"
00037 
00038 #include <Base/Exception.h>
00039 #include <App/Document.h>
00040 
00041 using namespace Gui;
00042 
00043 
00044 //===========================================================================
00045 // Std_ArrangeIcons
00046 //===========================================================================
00047 DEF_STD_CMD_A(StdCmdArrangeIcons);
00048 
00049 StdCmdArrangeIcons::StdCmdArrangeIcons()
00050   : Command("Std_ArrangeIcons")
00051 {
00052     sGroup        = QT_TR_NOOP("Window");
00053     sMenuText     = QT_TR_NOOP("Arrange &Icons");
00054     sToolTipText  = QT_TR_NOOP("Arrange Icons");
00055     sWhatsThis    = QT_TR_NOOP("Arrange Icons");
00056     sStatusTip    = QT_TR_NOOP("Arrange Icons");
00057     eType         = 0;
00058 }
00059 
00060 void StdCmdArrangeIcons::activated(int iMsg)
00061 {
00062     getMainWindow()->arrangeIcons ();
00063 }
00064 
00065 bool StdCmdArrangeIcons::isActive(void)
00066 {
00067     return !(getMainWindow()->windows().isEmpty());
00068 }
00069 
00070 //===========================================================================
00071 // Std_TileWindows
00072 //===========================================================================
00073 DEF_STD_CMD_A(StdCmdTileWindows);
00074 
00075 StdCmdTileWindows::StdCmdTileWindows()
00076   : Command("Std_TileWindows")
00077 {
00078     sGroup        = QT_TR_NOOP("Window");
00079     sMenuText     = QT_TR_NOOP("&Tile");
00080     sToolTipText  = QT_TR_NOOP("Tile the windows");
00081     sWhatsThis    = QT_TR_NOOP("Tile the windows");
00082     sStatusTip    = QT_TR_NOOP("Tile the windows");
00083     sPixmap       = "Std_WindowTileVer";
00084     eType         = 0;
00085 }
00086 
00087 void StdCmdTileWindows::activated(int iMsg)
00088 {
00089     getMainWindow()->tile();
00090 }
00091 
00092 bool StdCmdTileWindows::isActive(void)
00093 {
00094     return !(getMainWindow()->windows().isEmpty());
00095 }
00096 
00097 //===========================================================================
00098 // Std_CascadeWindows
00099 //===========================================================================
00100 DEF_STD_CMD_A(StdCmdCascadeWindows);
00101 
00102 StdCmdCascadeWindows::StdCmdCascadeWindows()
00103   : Command("Std_CascadeWindows")
00104 {
00105     sGroup        = QT_TR_NOOP("Window");
00106     sMenuText     = QT_TR_NOOP("&Cascade");
00107     sToolTipText  = QT_TR_NOOP("Tile pragmatic");
00108     sWhatsThis    = QT_TR_NOOP("Tile pragmatic");
00109     sStatusTip    = QT_TR_NOOP("Tile pragmatic");
00110     sPixmap       = "Std_WindowCascade";
00111     eType         = 0;
00112 }
00113 
00114 void StdCmdCascadeWindows::activated(int iMsg)
00115 {
00116     getMainWindow()->cascade();
00117 }
00118 
00119 bool StdCmdCascadeWindows::isActive(void)
00120 {
00121     return !(getMainWindow()->windows().isEmpty());
00122 }
00123 
00124 //===========================================================================
00125 // Std_CloseActiveWindow
00126 //===========================================================================
00127 DEF_STD_CMD_A(StdCmdCloseActiveWindow);
00128 
00129 StdCmdCloseActiveWindow::StdCmdCloseActiveWindow()
00130   : Command("Std_CloseActiveWindow")
00131 {
00132     sGroup        = QT_TR_NOOP("Window");
00133     sMenuText     = QT_TR_NOOP("Cl&ose");
00134     sToolTipText  = QT_TR_NOOP("Close active window");
00135     sWhatsThis    = QT_TR_NOOP("Close active window");
00136     sStatusTip    = QT_TR_NOOP("Close active window");
00137     // CTRL+F4 is already set by an QMdiSubWindow and thus we must use the
00138     // alternative CTRL+W here to avoid an ambiguous shortcut overload
00139         sAccel        = "Ctrl+W";
00140     eType         = 0;
00141 }
00142 
00143 void StdCmdCloseActiveWindow::activated(int iMsg)
00144 {
00145     getMainWindow()->closeActiveWindow();
00146 }
00147 
00148 bool StdCmdCloseActiveWindow::isActive(void)
00149 {
00150     return !(getMainWindow()->windows().isEmpty());
00151 }
00152 
00153 //===========================================================================
00154 // Std_CloseAllWindows
00155 //===========================================================================
00156 DEF_STD_CMD_A(StdCmdCloseAllWindows);
00157 
00158 StdCmdCloseAllWindows::StdCmdCloseAllWindows()
00159   : Command("Std_CloseAllWindows")
00160 {
00161     sGroup        = QT_TR_NOOP("Window");
00162     sMenuText     = QT_TR_NOOP("Close Al&l");
00163     sToolTipText  = QT_TR_NOOP("Close all windows");
00164     sWhatsThis    = QT_TR_NOOP("Close all windows");
00165     sStatusTip    = QT_TR_NOOP("Close all windows");
00166     eType         = 0;
00167 }
00168 
00169 void StdCmdCloseAllWindows::activated(int iMsg)
00170 {
00171     getMainWindow()->closeAllWindows();
00172 }
00173 
00174 bool StdCmdCloseAllWindows::isActive(void)
00175 {
00176     return !(getMainWindow()->windows().isEmpty());
00177 }
00178 
00179 //===========================================================================
00180 // Std_ActivateNextWindow
00181 //===========================================================================
00182 DEF_STD_CMD_A(StdCmdActivateNextWindow);
00183 
00184 StdCmdActivateNextWindow::StdCmdActivateNextWindow()
00185   : Command("Std_ActivateNextWindow")
00186 {
00187     sGroup        = QT_TR_NOOP("Window");
00188     sMenuText     = QT_TR_NOOP("Ne&xt");
00189     sToolTipText  = QT_TR_NOOP("Activate next window");
00190     sWhatsThis    = QT_TR_NOOP("Activate next window");
00191     sStatusTip    = QT_TR_NOOP("Activate next window");
00192     sPixmap       = "Std_WindowNext";
00193 #ifndef NO_USE_QT_MDI_AREA
00194     sAccel        = keySequenceToAccel(QKeySequence::NextChild);
00195 #else
00196     sAccel        = "";
00197 #endif
00198     eType         = 0;
00199 }
00200 
00201 void StdCmdActivateNextWindow::activated(int iMsg)
00202 {
00203     getMainWindow()->activateNextWindow();
00204 }
00205 
00206 bool StdCmdActivateNextWindow::isActive(void)
00207 {
00208     return !(getMainWindow()->windows().isEmpty());
00209 }
00210 
00211 //===========================================================================
00212 // Std_ActivatePrevWindow
00213 //===========================================================================
00214 DEF_STD_CMD_A(StdCmdActivatePrevWindow);
00215 
00216 StdCmdActivatePrevWindow::StdCmdActivatePrevWindow()
00217   : Command("Std_ActivatePrevWindow")
00218 {
00219     sGroup        = QT_TR_NOOP("Window");
00220     sMenuText     = QT_TR_NOOP("Pre&vious");
00221     sToolTipText  = QT_TR_NOOP("Activate previous window");
00222     sWhatsThis    = QT_TR_NOOP("Activate previous window");
00223     sStatusTip    = QT_TR_NOOP("Activate previous window");
00224     sPixmap       = "Std_WindowPrev";
00225 #ifndef NO_USE_QT_MDI_AREA
00226     sAccel        = keySequenceToAccel(QKeySequence::PreviousChild);
00227 #else
00228     sAccel        = "";
00229 #endif
00230     eType         = 0;
00231 }
00232 
00233 void StdCmdActivatePrevWindow::activated(int iMsg)
00234 {
00235     getMainWindow()->activatePreviousWindow();
00236 }
00237 
00238 bool StdCmdActivatePrevWindow::isActive(void)
00239 {
00240     return !(getMainWindow()->windows().isEmpty());
00241 }
00242 
00243 //===========================================================================
00244 // Std_Windows
00245 //===========================================================================
00246 DEF_STD_CMD(StdCmdWindows);
00247 
00248 StdCmdWindows::StdCmdWindows()
00249   : Command("Std_Windows")
00250 {
00251     sGroup        = QT_TR_NOOP("Window");
00252     sMenuText     = QT_TR_NOOP("&Windows...");
00253     sToolTipText  = QT_TR_NOOP("Windows list");
00254     sWhatsThis    = QT_TR_NOOP("Windows list");
00255     sStatusTip    = QT_TR_NOOP("Windows list");
00256     //sPixmap     = "";
00257     eType         = 0;
00258 }
00259 
00260 void StdCmdWindows::activated(int iMsg)
00261 {
00262     Gui::Dialog::DlgActivateWindowImp dlg( getMainWindow() );
00263     dlg.exec();
00264 }
00265 
00266 //===========================================================================
00267 // Std_UserInterface
00268 //===========================================================================
00269 DEF_STD_CMD(StdCmdUserInterface);
00270 
00271 StdCmdUserInterface::StdCmdUserInterface()
00272   : Command("Std_UserInterface")
00273 {
00274     sGroup        = QT_TR_NOOP("View");
00275     sMenuText     = QT_TR_NOOP("Dock views");
00276     sToolTipText  = QT_TR_NOOP("Dock all top-level views");
00277     sWhatsThis    = QT_TR_NOOP("Dock all top-level views");
00278     sStatusTip    = QT_TR_NOOP("Dock all top-level views");
00279     eType         = 0;
00280 }
00281 
00282 void StdCmdUserInterface::activated(int)
00283 {
00284     getMainWindow()->switchToDockedMode();
00285 }
00286 
00287 //===========================================================================
00288 // Std_DockWindowMenu
00289 //===========================================================================
00290 
00291 DEF_STD_CMD_AC(StdCmdDockViewMenu);
00292 
00293 StdCmdDockViewMenu::StdCmdDockViewMenu()
00294   : Command("Std_DockViewMenu")
00295 {
00296     sGroup        = QT_TR_NOOP("View");
00297     sMenuText     = QT_TR_NOOP("Vie&ws");
00298     sToolTipText  = QT_TR_NOOP("Toggles this window");
00299     sWhatsThis    = QT_TR_NOOP("Toggles this window");
00300     sStatusTip    = QT_TR_NOOP("Toggles this window");
00301     eType         = 0;
00302 }
00303 
00304 void StdCmdDockViewMenu::activated(int iMsg)
00305 {
00306     // Handled by the related QAction objects
00307 }
00308 
00309 bool StdCmdDockViewMenu::isActive(void)
00310 {
00311     return true;
00312 }
00313 
00314 Action * StdCmdDockViewMenu::createAction(void)
00315 {
00316     Action *pcAction;
00317     pcAction = new DockWidgetAction(this, getMainWindow());
00318     applyCommandData(pcAction);
00319     return pcAction;
00320 }
00321 
00322 //===========================================================================
00323 // Std_ToolBarMenu
00324 //===========================================================================
00325 
00326 DEF_STD_CMD_AC(StdCmdToolBarMenu);
00327 
00328 StdCmdToolBarMenu::StdCmdToolBarMenu()
00329   : Command("Std_ToolBarMenu")
00330 {
00331     sGroup        = QT_TR_NOOP("View");
00332     sMenuText     = QT_TR_NOOP("Tool&bars");
00333     sToolTipText  = QT_TR_NOOP("Toggles this window");
00334     sWhatsThis    = QT_TR_NOOP("Toggles this window");
00335     sStatusTip    = QT_TR_NOOP("Toggles this window");
00336     eType         = 0;
00337 }
00338 
00339 void StdCmdToolBarMenu::activated(int iMsg)
00340 {
00341     // Handled by the related QAction objects
00342 }
00343 
00344 bool StdCmdToolBarMenu::isActive(void)
00345 {
00346     return true;
00347 }
00348 
00349 Action * StdCmdToolBarMenu::createAction(void)
00350 {
00351     Action *pcAction;
00352     pcAction = new ToolBarAction(this, getMainWindow());
00353     applyCommandData(pcAction);
00354     return pcAction;
00355 }
00356 
00357 //===========================================================================
00358 // Std_ViewStatusBar
00359 //===========================================================================
00360 
00361 DEF_STD_CMD_C(StdCmdStatusBar);
00362 
00363 StdCmdStatusBar::StdCmdStatusBar()
00364   : Command("Std_ViewStatusBar")
00365 {
00366     sGroup        = QT_TR_NOOP("View");
00367     sMenuText     = QT_TR_NOOP("Status bar");
00368     sToolTipText  = QT_TR_NOOP("Toggles the status bar");
00369     sWhatsThis    = QT_TR_NOOP("Toggles the status bar");
00370     sStatusTip    = QT_TR_NOOP("Toggles the status bar");
00371     eType         = 0;
00372 }
00373 
00374 Action * StdCmdStatusBar::createAction(void)
00375 {
00376     Action *pcAction = Command::createAction();
00377     pcAction->setCheckable(true);
00378     pcAction->setChecked(true);
00379 
00380     return pcAction;
00381 }
00382 
00383 void StdCmdStatusBar::activated(int iMsg)
00384 {
00385     getMainWindow()->statusBar()->setShown(iMsg != 0);
00386 }
00387 
00388 //===========================================================================
00389 // Std_WindowsMenu
00390 //===========================================================================
00391 
00392 DEF_STD_CMD_AC(StdCmdWindowsMenu );
00393 
00394 StdCmdWindowsMenu::StdCmdWindowsMenu()
00395   : Command("Std_WindowsMenu")
00396 {
00397     sGroup        = QT_TR_NOOP("Window");
00398     sMenuText     = QT_TR_NOOP("Activates this window");
00399     sToolTipText  = QT_TR_NOOP("Activates this window");
00400     sWhatsThis    = QT_TR_NOOP("Activates this window");
00401     sStatusTip    = QT_TR_NOOP("Activates this window");
00402     eType         = 0;
00403 }
00404 
00405 void StdCmdWindowsMenu::activated(int iMsg)
00406 {
00407     // already handled by the main window
00408 }
00409 
00410 bool StdCmdWindowsMenu::isActive(void)
00411 {
00412     return true;
00413 }
00414 
00415 Action * StdCmdWindowsMenu::createAction(void)
00416 {
00417     // Allow to show 10 menu items in the 'Window' menu and one separator.
00418     // If we have more windows then the user can use the 'Windows...' item.
00419     WindowAction *pcAction;
00420     pcAction = new WindowAction(this, getMainWindow());
00421     for ( int i=0; i<10; i++ ) {
00422         QAction* window = pcAction->addAction(QObject::tr(sToolTipText));
00423         window->setCheckable(true);
00424         window->setToolTip(QCoreApplication::translate(
00425             this->className(), sToolTipText, 0,
00426             QCoreApplication::CodecForTr));
00427         window->setStatusTip(QCoreApplication::translate(
00428             this->className(), sStatusTip, 0,
00429             QCoreApplication::CodecForTr));
00430         window->setWhatsThis(QCoreApplication::translate(
00431             this->className(), sWhatsThis, 0,
00432             QCoreApplication::CodecForTr));
00433     }
00434 
00435     QAction* sep = pcAction->addAction(QLatin1String(""));
00436     sep->setSeparator(true);
00437 
00438     return pcAction;
00439 }
00440 
00441 //===========================================================================
00442 // Instanciation
00443 //===========================================================================
00444 
00445 
00446 namespace Gui {
00447 
00448 void CreateWindowStdCommands(void)
00449 {
00450     CommandManager &rcCmdMgr = Application::Instance->commandManager();
00451 
00452     rcCmdMgr.addCommand(new StdCmdArrangeIcons());
00453     rcCmdMgr.addCommand(new StdCmdTileWindows());
00454     rcCmdMgr.addCommand(new StdCmdCascadeWindows());
00455     rcCmdMgr.addCommand(new StdCmdCloseActiveWindow());
00456     rcCmdMgr.addCommand(new StdCmdCloseAllWindows());
00457     rcCmdMgr.addCommand(new StdCmdActivateNextWindow());
00458     rcCmdMgr.addCommand(new StdCmdActivatePrevWindow());
00459     rcCmdMgr.addCommand(new StdCmdWindows());
00460     rcCmdMgr.addCommand(new StdCmdDockViewMenu());
00461     rcCmdMgr.addCommand(new StdCmdToolBarMenu());
00462     rcCmdMgr.addCommand(new StdCmdWindowsMenu());
00463     rcCmdMgr.addCommand(new StdCmdStatusBar());
00464     rcCmdMgr.addCommand(new StdCmdUserInterface());
00465 }
00466 
00467 } // namespace Gui
00468 
00469 

Generated on Wed Nov 23 19:00:03 2011 for FreeCAD by  doxygen 1.6.1