1
/***************************************************************************
2
* Copyright (c) 2005 Werner Mayer <wmayer[at]users.sourceforge.net> *
4
* This file is part of the FreeCAD CAx development system. *
6
* This library is free software; you can redistribute it and/or *
7
* modify it under the terms of the GNU Library General Public *
8
* License as published by the Free Software Foundation; either *
9
* version 2 of the License, or (at your option) any later version. *
11
* This library is distributed in the hope that it will be useful, *
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14
* GNU Library General Public License for more details. *
16
* You should have received a copy of the GNU Library General Public *
17
* License along with this library; see the file COPYING.LIB. If not, *
18
* write to the Free Software Foundation, Inc., 59 Temple Place, *
19
* Suite 330, Boston, MA 02111-1307, USA *
21
***************************************************************************/
24
#include "PreCompiled.h"
26
# include <QCoreApplication>
33
#include "Application.h"
34
#include "MainWindow.h"
37
#include "DlgActivateWindowImp.h"
38
#include "DockWindowManager.h"
39
#include "ToolBarManager.h"
41
#include <Base/Exception.h>
42
#include <App/Document.h>
47
//===========================================================================
49
//===========================================================================
50
DEF_STD_CMD_A(StdCmdTileWindows)
52
StdCmdTileWindows::StdCmdTileWindows()
53
: Command("Std_TileWindows")
56
sMenuText = QT_TR_NOOP("&Tile");
57
sToolTipText = QT_TR_NOOP("Tile the windows");
58
sWhatsThis = "Std_TileWindows";
59
sStatusTip = QT_TR_NOOP("Tile the windows");
60
sPixmap = "Std_WindowTileVer";
64
void StdCmdTileWindows::activated(int iMsg)
67
getMainWindow()->tile();
70
bool StdCmdTileWindows::isActive()
72
return !(getMainWindow()->windows().isEmpty());
75
//===========================================================================
77
//===========================================================================
78
DEF_STD_CMD_A(StdCmdCascadeWindows)
80
StdCmdCascadeWindows::StdCmdCascadeWindows()
81
: Command("Std_CascadeWindows")
84
sMenuText = QT_TR_NOOP("&Cascade");
85
sToolTipText = QT_TR_NOOP("Tile pragmatic");
86
sWhatsThis = "Std_CascadeWindows";
87
sStatusTip = QT_TR_NOOP("Tile pragmatic");
88
sPixmap = "Std_WindowCascade";
92
void StdCmdCascadeWindows::activated(int iMsg)
95
getMainWindow()->cascade();
98
bool StdCmdCascadeWindows::isActive()
100
return !(getMainWindow()->windows().isEmpty());
103
//===========================================================================
104
// Std_CloseActiveWindow
105
//===========================================================================
106
DEF_STD_CMD_A(StdCmdCloseActiveWindow)
108
StdCmdCloseActiveWindow::StdCmdCloseActiveWindow()
109
: Command("Std_CloseActiveWindow")
112
sMenuText = QT_TR_NOOP("Cl&ose");
113
sToolTipText = QT_TR_NOOP("Close active window");
114
sWhatsThis = "Std_CloseActiveWindow";
115
sStatusTip = QT_TR_NOOP("Close active window");
116
// In QMdiSubWindow the 'QKeySequence::Close' shortcut is set which will
117
// collide with this shortcut. Thus the shortcut of QMdiSubWindow will be
118
// reset in MainWindow::addWindow() (#0002631)
119
sAccel = keySequenceToAccel(QKeySequence::Close);
120
sPixmap = "Std_CloseActiveWindow";
121
eType = NoTransaction;
124
void StdCmdCloseActiveWindow::activated(int iMsg)
127
getMainWindow()->closeActiveWindow();
130
bool StdCmdCloseActiveWindow::isActive()
132
return !(getMainWindow()->windows().isEmpty());
135
//===========================================================================
136
// Std_CloseAllWindows
137
//===========================================================================
138
DEF_STD_CMD_A(StdCmdCloseAllWindows)
140
StdCmdCloseAllWindows::StdCmdCloseAllWindows()
141
: Command("Std_CloseAllWindows")
144
sMenuText = QT_TR_NOOP("Close Al&l");
145
sToolTipText = QT_TR_NOOP("Close all windows");
146
sWhatsThis = "Std_CloseAllWindows";
147
sStatusTip = QT_TR_NOOP("Close all windows");
148
sPixmap = "Std_CloseAllWindows";
149
eType = NoTransaction;
152
void StdCmdCloseAllWindows::activated(int iMsg)
155
getMainWindow()->closeAllDocuments();
158
bool StdCmdCloseAllWindows::isActive()
160
return !(getMainWindow()->windows().isEmpty()) || !App::GetApplication().getDocuments().empty();
163
//===========================================================================
164
// Std_ActivateNextWindow
165
//===========================================================================
166
DEF_STD_CMD_A(StdCmdActivateNextWindow)
168
StdCmdActivateNextWindow::StdCmdActivateNextWindow()
169
: Command("Std_ActivateNextWindow")
172
sMenuText = QT_TR_NOOP("Ne&xt");
173
sToolTipText = QT_TR_NOOP("Activate next window");
174
sWhatsThis = "Std_ActivateNextWindow";
175
sStatusTip = QT_TR_NOOP("Activate next window");
176
sPixmap = "Std_WindowNext";
177
sAccel = keySequenceToAccel(QKeySequence::NextChild);
181
void StdCmdActivateNextWindow::activated(int iMsg)
184
getMainWindow()->activateNextWindow();
187
bool StdCmdActivateNextWindow::isActive()
189
return !(getMainWindow()->windows().isEmpty());
192
//===========================================================================
193
// Std_ActivatePrevWindow
194
//===========================================================================
195
DEF_STD_CMD_A(StdCmdActivatePrevWindow)
197
StdCmdActivatePrevWindow::StdCmdActivatePrevWindow()
198
: Command("Std_ActivatePrevWindow")
201
sMenuText = QT_TR_NOOP("Pre&vious");
202
sToolTipText = QT_TR_NOOP("Activate previous window");
203
sWhatsThis = "Std_ActivatePrevWindow";
204
sStatusTip = QT_TR_NOOP("Activate previous window");
205
sPixmap = "Std_WindowPrev";
206
// Depending on the OS 'QKeySequence::PreviousChild' gives
207
// Ctrl+Shift+Backtab instead of Ctrl+Shift+Tab which leads
208
// to a strange behaviour when using it.
209
// A workaround is to create a shortcut as Shift + QKeySequence::NextChild
210
static std::string previousChild = std::string("Shift+") + keySequenceToAccel(QKeySequence::NextChild);
211
sAccel = previousChild.c_str();
215
void StdCmdActivatePrevWindow::activated(int iMsg)
218
getMainWindow()->activatePreviousWindow();
221
bool StdCmdActivatePrevWindow::isActive()
223
return !(getMainWindow()->windows().isEmpty());
226
//===========================================================================
228
//===========================================================================
229
DEF_STD_CMD(StdCmdWindows)
231
StdCmdWindows::StdCmdWindows()
232
: Command("Std_Windows")
235
sMenuText = QT_TR_NOOP("&Windows...");
236
sToolTipText = QT_TR_NOOP("Windows list");
237
sWhatsThis = "Std_Windows";
238
sStatusTip = QT_TR_NOOP("Windows list");
239
sPixmap = "Std_Windows";
243
void StdCmdWindows::activated(int iMsg)
246
Gui::Dialog::DlgActivateWindowImp dlg( getMainWindow() );
250
//===========================================================================
252
//===========================================================================
253
DEF_STD_CMD(StdCmdUserInterface)
255
StdCmdUserInterface::StdCmdUserInterface()
256
: Command("Std_UserInterface")
259
sMenuText = QT_TR_NOOP("Dock views");
260
sToolTipText = QT_TR_NOOP("Dock all top-level views");
261
sWhatsThis = "Std_UserInterface";
262
sStatusTip = QT_TR_NOOP("Dock all top-level views");
266
void StdCmdUserInterface::activated(int)
268
getMainWindow()->switchToDockedMode();
271
//===========================================================================
273
//===========================================================================
275
DEF_STD_CMD_AC(StdCmdDockViewMenu)
277
StdCmdDockViewMenu::StdCmdDockViewMenu()
278
: Command("Std_DockViewMenu")
281
sMenuText = QT_TR_NOOP("Panels");
282
sToolTipText = QT_TR_NOOP("List of available dock panels");
283
sWhatsThis = "Std_DockViewMenu";
284
sStatusTip = QT_TR_NOOP("List of available dock panels");
288
void StdCmdDockViewMenu::activated(int iMsg)
290
// Handled by the related QAction objects
294
bool StdCmdDockViewMenu::isActive()
299
Action * StdCmdDockViewMenu::createAction()
302
pcAction = new DockWidgetAction(this, getMainWindow());
303
applyCommandData(this->className(), pcAction);
307
//===========================================================================
309
//===========================================================================
311
DEF_STD_CMD_AC(StdCmdToolBarMenu)
313
StdCmdToolBarMenu::StdCmdToolBarMenu()
314
: Command("Std_ToolBarMenu")
317
sMenuText = QT_TR_NOOP("Tool&bars");
318
sToolTipText = QT_TR_NOOP("Toggles this window");
319
sWhatsThis = "Std_ToolBarMenu";
320
sStatusTip = QT_TR_NOOP("Toggles this window");
324
void StdCmdToolBarMenu::activated(int iMsg)
326
// Handled by the related QAction objects
330
bool StdCmdToolBarMenu::isActive()
335
Action * StdCmdToolBarMenu::createAction()
338
pcAction = new ToolBarAction(this, getMainWindow());
339
applyCommandData(this->className(), pcAction);
343
//===========================================================================
344
// Std_DlgToggleToolBarLock
345
//===========================================================================
346
DEF_STD_CMD_C(StdCmdToggleToolBarLock)
348
StdCmdToggleToolBarLock::StdCmdToggleToolBarLock()
349
:Command("Std_ToggleToolBarLock")
352
sMenuText = QT_TR_NOOP("Lock toolbars");
353
sToolTipText = QT_TR_NOOP("Lock toolbars so they are no longer moveable");
354
sWhatsThis = "Std_ToggleToolBarLock";
355
sStatusTip = QT_TR_NOOP("Lock toolbars so they are no longer moveable");
360
Action* StdCmdToggleToolBarLock::createAction()
362
Action* action = Command::createAction();
364
action->setCheckable(true);
365
action->setChecked(ToolBarManager::getInstance()->areToolBarsLocked(), true);
370
void StdCmdToggleToolBarLock::activated(int iMsg)
374
auto manager = ToolBarManager::getInstance();
375
auto toggled = !manager->areToolBarsLocked();
377
manager->setToolBarsLocked(toggled);
379
getAction()->setChecked(toggled);
383
//===========================================================================
385
//===========================================================================
387
class FilterStatusBar : public QObject
392
FilterStatusBar(Action * action):QObject(action) {this->action = action;}
393
// virtual ~FilterStatusBar() {}
396
bool eventFilter(QObject *obj, QEvent *event) override
398
if (getMainWindow() && getMainWindow()->findChild<QStatusBar *>() && obj == getMainWindow()->statusBar() &&
399
((event->type() == QEvent::Hide) || (event->type() == QEvent::Show))) {
400
this->action->setChecked(getMainWindow()->statusBar()->isVisible());
406
DEF_STD_CMD_AC(StdCmdStatusBar)
408
StdCmdStatusBar::StdCmdStatusBar()
409
: Command("Std_ViewStatusBar")
412
sMenuText = QT_TR_NOOP("Status bar");
413
sToolTipText = QT_TR_NOOP("Toggles the status bar");
414
sWhatsThis = "Std_ViewStatusBar";
415
sStatusTip = QT_TR_NOOP("Toggles the status bar");
419
Action * StdCmdStatusBar::createAction()
421
Action *pcAction = Command::createAction();
422
pcAction->setCheckable(true);
423
pcAction->setChecked(false, true);
424
auto fsb = new FilterStatusBar(pcAction);
425
getMainWindow()->statusBar()->installEventFilter(fsb);
430
void StdCmdStatusBar::activated(int iMsg)
432
getMainWindow()->statusBar()->setVisible(iMsg != 0);
435
bool StdCmdStatusBar::isActive()
437
static bool checked = false;
439
Action* act = this->getAction();
441
act->setChecked(getMainWindow()->statusBar()->isVisible());
448
//===========================================================================
450
//===========================================================================
452
DEF_STD_CMD_AC(StdCmdWindowsMenu)
454
StdCmdWindowsMenu::StdCmdWindowsMenu()
455
: Command("Std_WindowsMenu")
458
sMenuText = QT_TR_NOOP("Activate window"); // Replaced with the name of the window
459
sToolTipText = QT_TR_NOOP("Activates this window");
460
sWhatsThis = "Std_WindowsMenu";
461
sStatusTip = QT_TR_NOOP("Activates this window");
465
void StdCmdWindowsMenu::activated(int iMsg)
467
// already handled by the main window
471
bool StdCmdWindowsMenu::isActive()
476
Action * StdCmdWindowsMenu::createAction()
478
// Allow to show 10 menu items in the 'Window' menu and one separator.
479
// If we have more windows then the user can use the 'Windows...' item.
480
WindowAction *pcAction;
481
pcAction = new WindowAction(this, getMainWindow());
482
for ( int i=0; i<10; i++ ) {
483
QAction* window = pcAction->addAction(QObject::tr(getToolTipText()));
484
window->setCheckable(true);
485
window->setToolTip(QCoreApplication::translate(
486
this->className(), getToolTipText()));
487
window->setStatusTip(QCoreApplication::translate(
488
this->className(), getStatusTip()));
489
window->setWhatsThis(QCoreApplication::translate(
490
this->className(), getWhatsThis()));
493
QAction* sep = pcAction->addAction(QLatin1String(""));
494
sep->setSeparator(true);
499
//===========================================================================
501
//===========================================================================
506
void CreateWindowStdCommands()
508
CommandManager &rcCmdMgr = Application::Instance->commandManager();
510
rcCmdMgr.addCommand(new StdCmdTileWindows());
511
rcCmdMgr.addCommand(new StdCmdCascadeWindows());
512
rcCmdMgr.addCommand(new StdCmdCloseActiveWindow());
513
rcCmdMgr.addCommand(new StdCmdCloseAllWindows());
514
rcCmdMgr.addCommand(new StdCmdActivateNextWindow());
515
rcCmdMgr.addCommand(new StdCmdActivatePrevWindow());
516
rcCmdMgr.addCommand(new StdCmdWindows());
517
rcCmdMgr.addCommand(new StdCmdDockViewMenu());
518
rcCmdMgr.addCommand(new StdCmdToolBarMenu());
519
rcCmdMgr.addCommand(new StdCmdToggleToolBarLock());
520
rcCmdMgr.addCommand(new StdCmdWindowsMenu());
521
rcCmdMgr.addCommand(new StdCmdStatusBar());
522
rcCmdMgr.addCommand(new StdCmdUserInterface());