1
/***************************************************************************
2
* Copyright (c) 2004 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
***************************************************************************/
23
#include "PreCompiled.h"
25
# include <QApplication>
26
# include <QPushButton>
29
#include "DlgActivateWindowImp.h"
30
#include "ui_DlgActivateWindow.h"
31
#include "MainWindow.h"
35
using namespace Gui::Dialog;
37
/* TRANSLATOR Gui::Dialog::DlgActivateWindowImp */
40
* Constructs a DlgActivateWindowImp which is a child of 'parent', with the
41
* name 'name' and widget flags set to 'f'
43
* The dialog will by default be modeless, unless you set 'modal' to
44
* true to construct a modal dialog.
46
DlgActivateWindowImp::DlgActivateWindowImp(QWidget* parent, Qt::WindowFlags fl)
47
: QDialog(parent, fl), ui(new Ui_DlgActivateWindow)
51
QPushButton* buttonOk = ui->buttonBox->button(QDialogButtonBox::Ok);
52
buttonOk->setText(QApplication::translate("Gui::Dialog::DlgActivateWindow", "&Activate"));
53
QTreeWidgetItem* active=nullptr;
54
QStringList labels; labels << tr("Windows");
55
ui->treeWidget->setHeaderLabels(labels);
56
ui->treeWidget->header()->hide();
58
QList<QWidget*> windows = getMainWindow()->windows();
59
if (windows.isEmpty()) {
60
buttonOk->setDisabled(true);
64
QWidget* activeWnd = getMainWindow()->activeWindow();
66
for (QWidget* it : windows) {
67
auto item = new QTreeWidgetItem(ui->treeWidget);
68
QString title = it->windowTitle();
69
title.replace(QLatin1String("[*]"), QLatin1String(""));
70
if (it->isWindowModified())
71
title += QLatin1String("*");
72
item->setText(0, title);
78
ui->treeWidget->setCurrentItem( active );
79
ui->treeWidget->setFocus();
82
/** Destroys the object and frees any allocated resources */
83
DlgActivateWindowImp::~DlgActivateWindowImp()
89
* Activates the MDI window you wish and closes the dialog.
91
void DlgActivateWindowImp::accept()
93
QTreeWidgetItem* item = ui->treeWidget->currentItem();
94
QList<QWidget*> windows = getMainWindow()->windows();
97
int index = ui->treeWidget->indexOfTopLevelItem(item);
98
getMainWindow()->setActiveWindow(static_cast<MDIView*>(windows.at(index)));
104
#include "moc_DlgActivateWindowImp.cpp"