FreeCAD

Форк
0
/
CommandWindow.cpp 
525 строк · 16.5 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2005 Werner Mayer <wmayer[at]users.sourceforge.net>     *
3
 *                                                                         *
4
 *   This file is part of the FreeCAD CAx development system.              *
5
 *                                                                         *
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.      *
10
 *                                                                         *
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.                  *
15
 *                                                                         *
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                                *
20
 *                                                                         *
21
 ***************************************************************************/
22

23

24
#include "PreCompiled.h"
25
#ifndef _PreComp_
26
# include <QCoreApplication>
27
# include <QStatusBar>
28
# include <QEvent>
29
#endif
30

31
#include "Command.h"
32
#include "Action.h"
33
#include "Application.h"
34
#include "MainWindow.h"
35
#include "View.h"
36
#include "Document.h"
37
#include "DlgActivateWindowImp.h"
38
#include "DockWindowManager.h"
39
#include "ToolBarManager.h"
40

41
#include <Base/Exception.h>
42
#include <App/Document.h>
43

44
using namespace Gui;
45

46

47
//===========================================================================
48
// Std_TileWindows
49
//===========================================================================
50
DEF_STD_CMD_A(StdCmdTileWindows)
51

52
StdCmdTileWindows::StdCmdTileWindows()
53
  : Command("Std_TileWindows")
54
{
55
    sGroup        = "Window";
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";
61
    eType         = 0;
62
}
63

64
void StdCmdTileWindows::activated(int iMsg)
65
{
66
    Q_UNUSED(iMsg);
67
    getMainWindow()->tile();
68
}
69

70
bool StdCmdTileWindows::isActive()
71
{
72
    return !(getMainWindow()->windows().isEmpty());
73
}
74

75
//===========================================================================
76
// Std_CascadeWindows
77
//===========================================================================
78
DEF_STD_CMD_A(StdCmdCascadeWindows)
79

80
StdCmdCascadeWindows::StdCmdCascadeWindows()
81
  : Command("Std_CascadeWindows")
82
{
83
    sGroup        = "Window";
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";
89
    eType         = 0;
90
}
91

92
void StdCmdCascadeWindows::activated(int iMsg)
93
{
94
    Q_UNUSED(iMsg);
95
    getMainWindow()->cascade();
96
}
97

98
bool StdCmdCascadeWindows::isActive()
99
{
100
    return !(getMainWindow()->windows().isEmpty());
101
}
102

103
//===========================================================================
104
// Std_CloseActiveWindow
105
//===========================================================================
106
DEF_STD_CMD_A(StdCmdCloseActiveWindow)
107

108
StdCmdCloseActiveWindow::StdCmdCloseActiveWindow()
109
  : Command("Std_CloseActiveWindow")
110
{
111
    sGroup        = "Window";
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;
122
}
123

124
void StdCmdCloseActiveWindow::activated(int iMsg)
125
{
126
    Q_UNUSED(iMsg);
127
    getMainWindow()->closeActiveWindow();
128
}
129

130
bool StdCmdCloseActiveWindow::isActive()
131
{
132
    return !(getMainWindow()->windows().isEmpty());
133
}
134

135
//===========================================================================
136
// Std_CloseAllWindows
137
//===========================================================================
138
DEF_STD_CMD_A(StdCmdCloseAllWindows)
139

140
StdCmdCloseAllWindows::StdCmdCloseAllWindows()
141
  : Command("Std_CloseAllWindows")
142
{
143
    sGroup        = "Window";
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;
150
}
151

152
void StdCmdCloseAllWindows::activated(int iMsg)
153
{
154
    Q_UNUSED(iMsg);
155
    getMainWindow()->closeAllDocuments();
156
}
157

158
bool StdCmdCloseAllWindows::isActive()
159
{
160
    return !(getMainWindow()->windows().isEmpty()) || !App::GetApplication().getDocuments().empty();
161
}
162

163
//===========================================================================
164
// Std_ActivateNextWindow
165
//===========================================================================
166
DEF_STD_CMD_A(StdCmdActivateNextWindow)
167

168
StdCmdActivateNextWindow::StdCmdActivateNextWindow()
169
  : Command("Std_ActivateNextWindow")
170
{
171
    sGroup        = "Window";
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);
178
    eType         = 0;
179
}
180

181
void StdCmdActivateNextWindow::activated(int iMsg)
182
{
183
    Q_UNUSED(iMsg);
184
    getMainWindow()->activateNextWindow();
185
}
186

187
bool StdCmdActivateNextWindow::isActive()
188
{
189
    return !(getMainWindow()->windows().isEmpty());
190
}
191

192
//===========================================================================
193
// Std_ActivatePrevWindow
194
//===========================================================================
195
DEF_STD_CMD_A(StdCmdActivatePrevWindow)
196

197
StdCmdActivatePrevWindow::StdCmdActivatePrevWindow()
198
  : Command("Std_ActivatePrevWindow")
199
{
200
    sGroup        = "Window";
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();
212
    eType         = 0;
213
}
214

215
void StdCmdActivatePrevWindow::activated(int iMsg)
216
{
217
    Q_UNUSED(iMsg);
218
    getMainWindow()->activatePreviousWindow();
219
}
220

221
bool StdCmdActivatePrevWindow::isActive()
222
{
223
    return !(getMainWindow()->windows().isEmpty());
224
}
225

226
//===========================================================================
227
// Std_Windows
228
//===========================================================================
229
DEF_STD_CMD(StdCmdWindows)
230

231
StdCmdWindows::StdCmdWindows()
232
  : Command("Std_Windows")
233
{
234
    sGroup        = "Window";
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";
240
    eType         = 0;
241
}
242

243
void StdCmdWindows::activated(int iMsg)
244
{
245
    Q_UNUSED(iMsg);
246
    Gui::Dialog::DlgActivateWindowImp dlg( getMainWindow() );
247
    dlg.exec();
248
}
249

250
//===========================================================================
251
// Std_UserInterface
252
//===========================================================================
253
DEF_STD_CMD(StdCmdUserInterface)
254

255
StdCmdUserInterface::StdCmdUserInterface()
256
  : Command("Std_UserInterface")
257
{
258
    sGroup        = "View";
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");
263
    eType         = 0;
264
}
265

266
void StdCmdUserInterface::activated(int)
267
{
268
    getMainWindow()->switchToDockedMode();
269
}
270

271
//===========================================================================
272
// Std_DockWindowMenu
273
//===========================================================================
274

275
DEF_STD_CMD_AC(StdCmdDockViewMenu)
276

277
StdCmdDockViewMenu::StdCmdDockViewMenu()
278
  : Command("Std_DockViewMenu")
279
{
280
    sGroup        = "View";
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");
285
    eType         = 0;
286
}
287

288
void StdCmdDockViewMenu::activated(int iMsg)
289
{
290
    // Handled by the related QAction objects
291
    Q_UNUSED(iMsg);
292
}
293

294
bool StdCmdDockViewMenu::isActive()
295
{
296
    return true;
297
}
298

299
Action * StdCmdDockViewMenu::createAction()
300
{
301
    Action *pcAction;
302
    pcAction = new DockWidgetAction(this, getMainWindow());
303
    applyCommandData(this->className(), pcAction);
304
    return pcAction;
305
}
306

307
//===========================================================================
308
// Std_ToolBarMenu
309
//===========================================================================
310

311
DEF_STD_CMD_AC(StdCmdToolBarMenu)
312

313
StdCmdToolBarMenu::StdCmdToolBarMenu()
314
  : Command("Std_ToolBarMenu")
315
{
316
    sGroup        = "View";
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");
321
    eType         = 0;
322
}
323

324
void StdCmdToolBarMenu::activated(int iMsg)
325
{
326
    // Handled by the related QAction objects
327
    Q_UNUSED(iMsg);
328
}
329

330
bool StdCmdToolBarMenu::isActive()
331
{
332
    return true;
333
}
334

335
Action * StdCmdToolBarMenu::createAction()
336
{
337
    Action *pcAction;
338
    pcAction = new ToolBarAction(this, getMainWindow());
339
    applyCommandData(this->className(), pcAction);
340
    return pcAction;
341
}
342

343
//===========================================================================
344
// Std_DlgToggleToolBarLock
345
//===========================================================================
346
DEF_STD_CMD_C(StdCmdToggleToolBarLock)
347

348
StdCmdToggleToolBarLock::StdCmdToggleToolBarLock()
349
  :Command("Std_ToggleToolBarLock")
350
{
351
    sGroup        = "Tools";
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");
356
    eType         = 0;
357
}
358

359

360
Action* StdCmdToggleToolBarLock::createAction()
361
{
362
    Action* action = Command::createAction();
363

364
    action->setCheckable(true);
365
    action->setChecked(ToolBarManager::getInstance()->areToolBarsLocked(), true);
366

367
    return action;
368
}
369

370
void StdCmdToggleToolBarLock::activated(int iMsg)
371
{
372
    Q_UNUSED(iMsg);
373

374
    auto manager = ToolBarManager::getInstance();
375
    auto toggled = !manager->areToolBarsLocked();
376

377
    manager->setToolBarsLocked(toggled);
378

379
    getAction()->setChecked(toggled);
380
}
381

382

383
//===========================================================================
384
// Std_ViewStatusBar
385
//===========================================================================
386

387
class FilterStatusBar : public QObject
388
{
389
//    Q_OBJECT
390

391
public:
392
    FilterStatusBar(Action * action):QObject(action) {this->action = action;}
393
//    virtual ~FilterStatusBar() {}
394
protected:
395
    Action * action;
396
    bool eventFilter(QObject *obj, QEvent *event) override
397
    {
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());
401
        }
402
        return false;
403
    }
404
};
405

406
DEF_STD_CMD_AC(StdCmdStatusBar)
407

408
StdCmdStatusBar::StdCmdStatusBar()
409
  : Command("Std_ViewStatusBar")
410
{
411
    sGroup        = "View";
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");
416
    eType         = 0;
417
}
418

419
Action * StdCmdStatusBar::createAction()
420
{
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);
426

427
    return pcAction;
428
}
429

430
void StdCmdStatusBar::activated(int iMsg)
431
{
432
    getMainWindow()->statusBar()->setVisible(iMsg != 0);
433
}
434

435
bool StdCmdStatusBar::isActive()
436
{
437
    static bool checked = false;
438
    if (!checked) {
439
        Action* act = this->getAction();
440
        if (act) {
441
            act->setChecked(getMainWindow()->statusBar()->isVisible());
442
            checked = true;
443
        }
444
    }
445
    return true;
446
}
447

448
//===========================================================================
449
// Std_WindowsMenu
450
//===========================================================================
451

452
DEF_STD_CMD_AC(StdCmdWindowsMenu)
453

454
StdCmdWindowsMenu::StdCmdWindowsMenu()
455
  : Command("Std_WindowsMenu")
456
{
457
    sGroup        = "Window";
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");
462
    eType         = 0;
463
}
464

465
void StdCmdWindowsMenu::activated(int iMsg)
466
{
467
    // already handled by the main window
468
    Q_UNUSED(iMsg);
469
}
470

471
bool StdCmdWindowsMenu::isActive()
472
{
473
    return true;
474
}
475

476
Action * StdCmdWindowsMenu::createAction()
477
{
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()));
491
    }
492

493
    QAction* sep = pcAction->addAction(QLatin1String(""));
494
    sep->setSeparator(true);
495

496
    return pcAction;
497
}
498

499
//===========================================================================
500
// Instantiation
501
//===========================================================================
502

503

504
namespace Gui {
505

506
void CreateWindowStdCommands()
507
{
508
    CommandManager &rcCmdMgr = Application::Instance->commandManager();
509

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());
523
}
524

525
} // namespace Gui
526

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.