Debian Codegraph @

src/Gui/Dialogs/DlgActivateWindowImp.cpp

raw
1 /***************************************************************************
2 * Copyright (c) 2004 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 #include <QApplication>
24 #include <QPushButton>
25
26 #include "Dialogs/DlgActivateWindowImp.h"
27 #include "ui_DlgActivateWindow.h"
28 #include "MainWindow.h"
29 #include "MDIView.h"
30
31
32 using namespace Gui::Dialog;
33
34 /* TRANSLATOR Gui::Dialog::DlgActivateWindowImp */
35
36 /**
37 * Constructs a DlgActivateWindowImp which is a child of 'parent', with the
38 * name 'name' and widget flags set to 'f'
39 *
40 * The dialog will by default be modeless, unless you set 'modal' to
41 * true to construct a modal dialog.
42 */
43 DlgActivateWindowImp::DlgActivateWindowImp(QWidget* parent, Qt::WindowFlags fl)
44 : QDialog(parent, fl)
45 , ui(new Ui_DlgActivateWindow)
46 {
47 // create widgets
48 ui->setupUi(this);
49 QPushButton* buttonOk = ui->buttonBox->button(QDialogButtonBox::Ok);
50 buttonOk->setText(QApplication::translate("Gui::Dialog::DlgActivateWindow", "&Activate"));
51 QTreeWidgetItem* active = nullptr;
52 QStringList labels;
53 labels << tr("Windows");
54 ui->treeWidget->setHeaderLabels(labels);
55 ui->treeWidget->header()->hide();
56
57 QList<QWidget*> windows = getMainWindow()->windows();
58 if (windows.isEmpty()) {
59 buttonOk->setDisabled(true);
60 return;
61 }
62
63 QWidget* activeWnd = getMainWindow()->activeWindow();
64
65 for (QWidget* it : windows) {
66 auto item = new QTreeWidgetItem(ui->treeWidget);
67 QString title = it->windowTitle();
68 title.replace(QLatin1String("[*]"), QLatin1String(""));
69 if (it->isWindowModified()) {
70 title += QLatin1String("*");
71 }
72 item->setText(0, title);
73 if (it == activeWnd) {
74 active = item;
75 }
76 }
77
78 if (active) {
79 ui->treeWidget->setCurrentItem(active);
80 }
81 ui->treeWidget->setFocus();
82 }
83
84 /** Destroys the object and frees any allocated resources */
85 DlgActivateWindowImp::~DlgActivateWindowImp()
86 {
87 delete ui;
88 }
89
90 /**
91 * Activates the MDI window you wish and closes the dialog.
92 */
93 void DlgActivateWindowImp::accept()
94 {
95 QTreeWidgetItem* item = ui->treeWidget->currentItem();
96 QList<QWidget*> windows = getMainWindow()->windows();
97
98 if (item) {
99 int index = ui->treeWidget->indexOfTopLevelItem(item);
100 getMainWindow()->setActiveWindow(static_cast<MDIView*>(windows.at(index)));
101 }
102
103 QDialog::accept();
104 }
105
106 #include "moc_DlgActivateWindowImp.cpp"