1
/***************************************************************************
2
* Copyright (c) 2006 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>
27
#include <QDesktopServices>
31
#include <App/Document.h>
32
#include <App/License.h>
33
#include <Base/UnitsApi.h>
35
#include "DlgProjectInformationImp.h"
36
#include "ui_DlgProjectInformation.h"
38
#include "MainWindow.h"
40
#if 0 // needed for Qt's lupdate utility
41
qApp->translate("Gui::Dialog::DlgSettingsDocument", "All rights reserved");
42
qApp->translate("Gui::Dialog::DlgSettingsDocument", "Creative Commons Attribution");
43
qApp->translate("Gui::Dialog::DlgSettingsDocument", "Creative Commons Attribution-ShareAlike");
44
qApp->translate("Gui::Dialog::DlgSettingsDocument", "Creative Commons Attribution-NoDerivatives");
45
qApp->translate("Gui::Dialog::DlgSettingsDocument", "Creative Commons Attribution-NonCommercial");
46
qApp->translate("Gui::Dialog::DlgSettingsDocument", "Creative Commons Attribution-NonCommercial-ShareAlike");
47
qApp->translate("Gui::Dialog::DlgSettingsDocument", "Creative Commons Attribution-NonCommercial-NoDerivatives");
48
qApp->translate("Gui::Dialog::DlgSettingsDocument", "Public Domain");
49
qApp->translate("Gui::Dialog::DlgSettingsDocument", "FreeArt");
50
qApp->translate("Gui::Dialog::DlgSettingsDocument", "CERN Open Hardware Licence strongly-reciprocal");
51
qApp->translate("Gui::Dialog::DlgSettingsDocument", "CERN Open Hardware Licence weakly-reciprocal");
52
qApp->translate("Gui::Dialog::DlgSettingsDocument", "CERN Open Hardware Licence permissive");
53
qApp->translate("Gui::Dialog::DlgSettingsDocument", "Other");
56
using namespace Gui::Dialog;
58
/* TRANSLATOR Gui::Dialog::DlgProjectInformationImp */
61
* Constructs a Gui::Dialog::DlgProjectInformationImp as a child of 'parent', with the
62
* name 'name' and widget flags set to 'fl'.
64
* The dialog will by default be modeless, unless you set 'modal' to
65
* true to construct a modal dialog.
67
DlgProjectInformationImp::DlgProjectInformationImp(App::Document* doc, QWidget* parent, Qt::WindowFlags fl)
68
: QDialog(parent, fl), _doc(doc), ui(new Ui_DlgProjectInformation)
71
ui->lineEditName->setText(QString::fromUtf8(doc->Label.getValue()));
72
ui->lineEditPath->setText(QString::fromUtf8(doc->FileName.getValue()));
73
ui->lineEditUuid->setText(QString::fromUtf8(doc->Uid.getValueStr().c_str()));
74
ui->lineEditProgramVersion->setText(QString::fromUtf8(doc->getProgramVersion()));
75
ui->lineEditCreator->setText(QString::fromUtf8(doc->CreatedBy.getValue()));
76
ui->lineEditDate->setText(QString::fromUtf8(doc->CreationDate.getValue()));
77
ui->lineEditLastMod->setText(QString::fromUtf8(doc->LastModifiedBy.getValue()));
78
ui->lineEditLastModDate->setText(QString::fromUtf8(doc->LastModifiedDate.getValue()));
79
ui->lineEditCompany->setText(QString::fromUtf8(doc->Company.getValue()));
81
// Load comboBox with unit systems
82
int num = static_cast<int>(Base::UnitSystem::NumUnitSystemTypes);
83
for (int i = 0; i < num; i++) {
84
QString item = Base::UnitsApi::getDescription(static_cast<Base::UnitSystem>(i));
85
ui->comboBox_unitSystem->addItem(item, i);
87
ui->comboBox_unitSystem->setCurrentIndex(doc->UnitSystem.getValue());
89
// load comboBox with license names
90
for (const auto& item : App::licenseItems) {
91
const char* name {item.at(App::posnOfFullName)};
92
QString translated = QApplication::translate("Gui::Dialog::DlgSettingsDocument", name);
93
ui->comboLicense->addItem(translated, QByteArray(name));
96
// set default position to match document
97
int index = ui->comboLicense->findData(QByteArray(doc->License.getValue()));
99
ui->comboLicense->setCurrentIndex(index);
102
index = ui->comboLicense->count();
103
QString text = QString::fromUtf8(doc->License.getValue());
104
ui->comboLicense->addItem(text);
105
ui->comboLicense->setCurrentIndex(index);
108
ui->lineEditLicenseURL->setText(QString::fromUtf8(doc->LicenseURL.getValue()));
110
// When saving the text to XML the newlines get lost. So we store also the newlines as '\n'.
111
// See also accept().
112
QString comment = QString::fromUtf8(doc->Comment.getValue());
113
#if QT_VERSION >= QT_VERSION_CHECK(5,15,0)
114
QStringList lines = comment.split(QLatin1String("\\n"), Qt::KeepEmptyParts);
116
QStringList lines = comment.split(QLatin1String("\\n"), QString::KeepEmptyParts);
118
QString text = lines.join(QLatin1String("\n"));
119
ui->textEditComment->setPlainText( text );
120
connect(ui->pushButtonOpenURL, &QPushButton::clicked,
121
this, &DlgProjectInformationImp::open_url);
122
connect(ui->comboLicense, qOverload<int>(&QComboBox::currentIndexChanged),
123
this, &DlgProjectInformationImp::onLicenseTypeChanged);
127
* Destroys the object and frees any allocated resources
129
DlgProjectInformationImp::~DlgProjectInformationImp()
131
// no need to delete child widgets, Qt does it all for us
136
* Applies the changes to the project information of the given document.
138
void DlgProjectInformationImp::accept()
140
_doc->CreatedBy.setValue(ui->lineEditCreator->text().toUtf8());
141
_doc->LastModifiedBy.setValue(ui->lineEditCreator->text().toUtf8());
142
_doc->Company.setValue(ui->lineEditCompany->text().toUtf8());
143
getMainWindow()->setUserSchema(ui->comboBox_unitSystem->currentIndex());
144
QByteArray licenseName {ui->comboLicense->currentData().toByteArray()};
145
// Is this really necessary?
146
if (licenseName.isEmpty()) {
147
licenseName = ui->comboLicense->currentText().toUtf8();
149
_doc->License.setValue(licenseName);
150
_doc->LicenseURL.setValue(ui->lineEditLicenseURL->text().toUtf8());
152
// Replace newline escape sequence through '\\n' string
153
QStringList lines = ui->textEditComment->toPlainText().split
154
#if QT_VERSION >= QT_VERSION_CHECK(5,15,0)
155
(QLatin1String("\n"), Qt::KeepEmptyParts);
157
(QLatin1String("\n"), QString::KeepEmptyParts);
159
QString text = lines.join(QLatin1String("\\n"));
160
_doc->Comment.setValue(text.isEmpty() ? QByteArray() : text.toUtf8());
165
void DlgProjectInformationImp::onLicenseTypeChanged(int index)
167
const char* url {index >= 0 && index < App::countOfLicenses ? App::licenseItems.at(index).at(App::posnOfUrl)
168
: _doc->LicenseURL.getValue()};
170
ui->lineEditLicenseURL->setText(QString::fromLatin1(url));
174
* Opens the text in the LicenseURL property in external browser.
176
void DlgProjectInformationImp::open_url()
178
QString url = ui->lineEditLicenseURL->text();
179
QDesktopServices::openUrl(QUrl(url, QUrl::TolerantMode));
182
#include "moc_DlgProjectInformationImp.cpp"