Debian Codegraph @

src/Gui/Dialogs/DlgCustomizeImp.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 <QEvent>
24 #include <QGridLayout>
25 #include <QPushButton>
26 #include <QSizePolicy>
27
28 #include "Dialogs/DlgCustomizeImp.h"
29 #include "MainWindow.h"
30 #include "WidgetFactory.h"
31
32
33 using namespace Gui::Dialog;
34
35 QList<QByteArray> DlgCustomizeImp::_pages;
36
37 /* TRANSLATOR Gui::Dialog::DlgCustomizeImp */
38
39 /**
40 * Constructs a DlgCustomizeImp 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 DlgCustomizeImp::DlgCustomizeImp(QWidget* parent, Qt::WindowFlags fl)
47 : QDialog(parent, fl)
48 {
49 setModal(false);
50 setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
51 resize(690, 365);
52
53 setWindowTitle(tr("Customize"));
54 setSizeGripEnabled(true);
55
56 customLayout = new QGridLayout(this);
57 customLayout->setSpacing(6);
58 customLayout->setContentsMargins(11, 11, 11, 11);
59
60 layout = new QHBoxLayout;
61 layout->setSpacing(6);
62 layout->setContentsMargins(0, 0, 0, 0);
63
64 buttonHelp = new QPushButton(this);
65 buttonHelp->setText(tr("&Help"));
66 layout->addWidget(buttonHelp);
67
68 auto spacer = new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
69 layout->addItem(spacer);
70
71 buttonClose = new QPushButton(this);
72 buttonClose->setText(tr("&Close"));
73 layout->addWidget(buttonClose);
74
75 customLayout->addLayout(layout, 1, 0);
76
77 tabWidget = new QTabWidget(this);
78 tabWidget->setObjectName(QStringLiteral("Gui__Dialog__TabWidget")); // so we can find it in
79 // DlgMacroExecuteImp
80
81 // make sure that pages are ready to create
82 GetWidgetFactorySupplier();
83 for (const QByteArray& it : _pages) {
84 addPage(WidgetFactory().createWidget(it.constData()));
85 }
86
87 customLayout->addWidget(tabWidget, 0, 0);
88
89
90 // tab order
91 setTabOrder(tabWidget, buttonClose);
92 setTabOrder(buttonClose, buttonHelp);
93
94 // connections
95 //
96 connect(buttonHelp, &QPushButton::clicked, getMainWindow(), &MainWindow::whatsThis);
97 connect(buttonClose, &QPushButton::clicked, this, &QDialog::close);
98 }
99
100 /**
101 * Destroys the object and frees any allocated resources
102 */
103 DlgCustomizeImp::~DlgCustomizeImp() = default;
104
105 /**
106 * Adds a customize page with its class name \a className.
107 * To create this page it must be registered in the WidgetFactory.
108 * @see WidgetFactory
109 * @see CustomPageProducer
110 */
111 void DlgCustomizeImp::addPage(const char* className)
112 {
113 _pages.push_back(className);
114 }
115
116 /** Inserts a new tab page with its caption */
117 void DlgCustomizeImp::addPage(QWidget* w)
118 {
119 tabWidget->addTab(w, w->windowTitle());
120 }
121
122 void DlgCustomizeImp::changeEvent(QEvent* e)
123 {
124 if (e->type() == QEvent::LanguageChange) {
125 setWindowTitle(tr("Customize"));
126 buttonHelp->setText(tr("&Help"));
127 buttonClose->setText(tr("&Close"));
128 int count = tabWidget->count();
129 for (int i = 0; i < count; i++) {
130 QWidget* w = tabWidget->widget(i);
131 tabWidget->setTabText(i, w->windowTitle());
132 }
133 }
134 QDialog::changeEvent(e);
135 }
136
137 #include "moc_DlgCustomizeImp.cpp"