FreeCAD

Форк
0
/
DlgActivateWindowImp.cpp 
104 строки · 3.9 Кб
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 "PreCompiled.h"
24
#ifndef _PreComp_
25
# include <QApplication>
26
# include <QPushButton>
27
#endif
28

29
#include "DlgActivateWindowImp.h"
30
#include "ui_DlgActivateWindow.h"
31
#include "MainWindow.h"
32
#include "MDIView.h"
33

34

35
using namespace Gui::Dialog;
36

37
/* TRANSLATOR Gui::Dialog::DlgActivateWindowImp */
38

39
/**
40
 *  Constructs a DlgActivateWindowImp which is a child of 'parent', with the
41
 *  name 'name' and widget flags set to 'f'
42
 *
43
 *  The dialog will by default be modeless, unless you set 'modal' to
44
 *  true to construct a modal dialog.
45
 */
46
DlgActivateWindowImp::DlgActivateWindowImp(QWidget* parent, Qt::WindowFlags fl)
47
  : QDialog(parent, fl), ui(new Ui_DlgActivateWindow)
48
{
49
    // create widgets
50
    ui->setupUi(this);
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();
57

58
    QList<QWidget*> windows = getMainWindow()->windows();
59
    if (windows.isEmpty()) {
60
        buttonOk->setDisabled(true);
61
        return;
62
    }
63

64
    QWidget* activeWnd = getMainWindow()->activeWindow();
65

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);
73
        if (it == activeWnd)
74
            active = item;
75
    }
76

77
    if (active)
78
        ui->treeWidget->setCurrentItem( active );
79
    ui->treeWidget->setFocus();
80
}
81

82
/** Destroys the object and frees any allocated resources */
83
DlgActivateWindowImp::~DlgActivateWindowImp()
84
{
85
    delete ui;
86
}
87

88
/**
89
 * Activates the MDI window you wish and closes the dialog.
90
 */
91
void DlgActivateWindowImp::accept()
92
{
93
    QTreeWidgetItem* item = ui->treeWidget->currentItem();
94
    QList<QWidget*> windows = getMainWindow()->windows();
95

96
    if (item) {
97
        int index = ui->treeWidget->indexOfTopLevelItem(item);
98
        getMainWindow()->setActiveWindow(static_cast<MDIView*>(windows.at(index)));
99
    }
100

101
    QDialog::accept();
102
}
103

104
#include "moc_DlgActivateWindowImp.cpp"
105

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

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

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

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