1
/***************************************************************************
2
* Copyright (c) 2020 FreeCAD Developers *
3
* Author: Uwe Stöhr <uwestoehr@lyx.org> *
4
* Based on src/Mod/FEM/Gui/DlgSettingsFEMImp.cpp *
6
* This file is part of the FreeCAD CAx development system. *
8
* This library is free software; you can redistribute it and/or *
9
* modify it under the terms of the GNU Library General Public *
10
* License as published by the Free Software Foundation; either *
11
* version 2 of the License, or (at your option) any later version. *
13
* This library is distributed in the hope that it will be useful, *
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16
* GNU Library General Public License for more details. *
18
* You should have received a copy of the GNU Library General Public *
19
* License along with this library; see the file COPYING.LIB. If not, *
20
* write to the Free Software Foundation, Inc., 59 Temple Place, *
21
* Suite 330, Boston, MA 02111-1307, USA *
23
***************************************************************************/
25
#include "PreCompiled.h"
30
#include <Base/Tools.h>
32
#include <Mod/TechDraw/App/LineGroup.h>
33
#include <Mod/TechDraw/App/Preferences.h>
34
#include <Mod/TechDraw/App/LineGenerator.h>
36
#include "DlgPrefsTechDrawAnnotationImp.h"
37
#include "ui_DlgPrefsTechDrawAnnotation.h"
38
#include "DrawGuiUtil.h"
40
using namespace TechDrawGui;
41
using namespace TechDraw;
44
DlgPrefsTechDrawAnnotationImp::DlgPrefsTechDrawAnnotationImp( QWidget* parent )
45
: PreferencePage( parent )
46
, ui(new Ui_DlgPrefsTechDrawAnnotationImp)
49
ui->pdsbBalloonKink->setUnit(Base::Unit::Length);
50
ui->pdsbBalloonKink->setMinimum(0);
52
// stylesheet override to defeat behaviour of non-editable combobox to ignore
53
// maxVisibleItems property
54
QString ssOverride = QString::fromUtf8("combobox-popup: 0;");
55
ui->pcbSectionStyle->view()->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
56
ui->pcbSectionStyle->setStyleSheet(ssOverride);
57
ui->pcbCenterStyle->view()->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
58
ui->pcbCenterStyle->setStyleSheet(ssOverride);
59
ui->pcbHighlightStyle->view()->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
60
ui->pcbHighlightStyle->setStyleSheet(ssOverride);
61
ui->pcbHiddenStyle->view()->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
62
ui->pcbHiddenStyle->setStyleSheet(ssOverride);
64
// connect the LineGroup the update the tooltip if index changed
65
connect(ui->pcbLineGroup, qOverload<int>(&QComboBox::currentIndexChanged),
66
this, &DlgPrefsTechDrawAnnotationImp::onLineGroupChanged);
68
// NOTE that we block onChanged processing while loading the Line Standard combobox
69
connect(ui->pcbLineStandard, qOverload<int>(&QComboBox::currentIndexChanged),
70
this, &DlgPrefsTechDrawAnnotationImp::onLineStandardChanged);
72
m_lineGenerator = new LineGenerator();
75
DlgPrefsTechDrawAnnotationImp::~DlgPrefsTechDrawAnnotationImp()
77
// no need to delete child widgets, Qt does it all for us
78
delete m_lineGenerator;
81
void DlgPrefsTechDrawAnnotationImp::saveSettings()
83
ui->cbAutoHoriz->onSave();
84
ui->cbPrintCenterMarks->onSave();
85
ui->cbPyramidOrtho->onSave();
86
ui->cbComplexMarks->onSave();
87
ui->cbShowCenterMarks->onSave();
88
ui->pcbBalloonArrow->onSave();
89
ui->pcbBalloonShape->onSave();
90
ui->pcbMatting->onSave();
91
ui->pdsbBalloonKink->onSave();
92
ui->cbCutSurface->onSave();
94
// don't save invalid parameter values
95
// the comboboxes are properly loaded.
96
ui->pcbLineGroup->onSave();
97
if (ui->pcbLineStandard->currentIndex() >= 0) {
98
ui->pcbLineStandard->onSave();
100
if (ui->pcbSectionStyle->currentIndex() >= 0) {
101
ui->pcbSectionStyle->onSave();
103
if (ui->pcbCenterStyle->currentIndex() >= 0) {
104
ui->pcbCenterStyle->onSave();
106
if (ui->pcbHighlightStyle->currentIndex() >= 0) {
107
ui->pcbHighlightStyle->onSave();
109
if (ui->cbEndCap->currentIndex() >= 0) {
110
ui->cbEndCap->onSave();
112
if (ui->pcbHiddenStyle->currentIndex() >= 0) {
113
ui->pcbHiddenStyle->onSave();
116
ui->pcbDetailMatting->onSave();
117
ui->pcbDetailHighlight->onSave();
120
void DlgPrefsTechDrawAnnotationImp::loadSettings()
122
//set defaults for Quantity widgets if property not found
123
//Quantity widgets do not use preset value since they are based on
125
double kinkDefault = 5.0;
126
ui->pdsbBalloonKink->setValue(kinkDefault);
127
// re-read the available LineGroup files
128
ui->pcbLineGroup->clear();
129
std::string lgFileName = Preferences::lineGroupFile();
130
std::string lgRecord = LineGroup::getGroupNamesFromFile(lgFileName);
131
// split collected groups
132
std::stringstream ss(lgRecord);
133
std::vector<std::string> lgNames;
134
while (std::getline(ss, lgRecord, ',')) {
135
lgNames.push_back(lgRecord);
137
// fill the combobox with the found names
138
for (auto it = lgNames.begin(); it < lgNames.end(); ++it) {
139
ui->pcbLineGroup->addItem(tr((*it).c_str()));
142
ui->cbAutoHoriz->onRestore();
143
ui->cbPrintCenterMarks->onRestore();
144
ui->cbPyramidOrtho->onRestore();
145
ui->cbComplexMarks->onRestore();
146
ui->cbShowCenterMarks->onRestore();
147
ui->pcbLineGroup->onRestore();
148
ui->pcbBalloonArrow->onRestore();
149
ui->pcbBalloonShape->onRestore();
150
ui->pcbMatting->onRestore();
151
ui->pdsbBalloonKink->onRestore();
152
ui->cbCutSurface->onRestore();
153
ui->pcbDetailMatting->onRestore();
154
ui->pcbDetailHighlight->onRestore();
157
ui->pcbBalloonArrow->onRestore();
158
DrawGuiUtil::loadArrowBox(ui->pcbBalloonArrow);
159
ui->pcbBalloonArrow->setCurrentIndex(prefBalloonArrow());
161
ui->cbEndCap->onRestore();
163
// prevent onChanged processing while loading comboBox
164
ui->pcbLineStandard->blockSignals(true);
165
DrawGuiUtil::loadLineStandardsChoices(ui->pcbLineStandard);
166
ui->pcbLineStandard->blockSignals(false);
168
if (ui->pcbLineStandard->count() > Preferences::lineStandard()) {
169
ui->pcbLineStandard->setCurrentIndex(Preferences::lineStandard());
172
ui->pcbSectionStyle->onRestore();
173
ui->pcbCenterStyle->onRestore();
174
ui->pcbHighlightStyle->onRestore();
175
ui->pcbHiddenStyle->onRestore();
176
loadLineStyleBoxes();
180
* Sets the strings of the subwidgets using the current language.
182
void DlgPrefsTechDrawAnnotationImp::changeEvent(QEvent *e)
184
if (e->type() == QEvent::LanguageChange) {
185
ui->pcbLineStandard->blockSignals(true);
186
int currentIndex = ui->pcbLineStandard->currentIndex();
187
ui->retranslateUi(this);
188
ui->pcbLineStandard->setCurrentIndex(currentIndex);
189
ui->pcbLineStandard->blockSignals(false);
192
QWidget::changeEvent(e);
196
int DlgPrefsTechDrawAnnotationImp::prefBalloonArrow() const
198
return Preferences::balloonArrow();
202
* Updates the tooltip of the LineGroup combobox
204
void DlgPrefsTechDrawAnnotationImp::onLineGroupChanged(int index)
206
if (index == -1) { // there is no valid index yet
207
ui->pcbLineGroup->setToolTip(QObject::tr("Please select a Line Group"));
210
// get the definition of the selected LineGroup (includes the name)
211
std::string lgRecord = LineGroup::getRecordFromFile(Preferences::lineGroupFile(), index);
212
std::stringstream ss(lgRecord);
213
std::vector<std::string> lgNames;
214
while (std::getline(ss, lgRecord, ',')) {
215
lgNames.push_back(lgRecord);
217
ui->pcbLineGroup->setToolTip(
218
QObject::tr("%1 defines these line widths:\n thin: %2\n graphic: %3\n"
220
.arg(QString::fromStdString(lgNames.at(0).substr(1)),
221
QString::fromStdString(lgNames.at(1)),
222
QString::fromStdString(lgNames.at(2)),
223
QString::fromStdString(lgNames.at(3))));
226
//! we must set the current line group preference when it changes so that the
227
//! line style comboboxes are filled for the correct standard.
228
void DlgPrefsTechDrawAnnotationImp::onLineStandardChanged(int index)
231
// do not process invalid index
234
Preferences::setLineStandard(index);
235
m_lineGenerator->reloadDescriptions();
236
loadLineStyleBoxes();
239
//! fill the various line style comboboxes
240
void DlgPrefsTechDrawAnnotationImp::loadLineStyleBoxes()
242
// note: line numbering starts at 1, not 0. we set the preference to the
243
// currentIndex in saveSettings, Preferences returns the actual line number,
244
// so we need to subtract 1 here to get the index.
245
DrawGuiUtil::loadLineStyleChoices(ui->pcbSectionStyle, m_lineGenerator);
246
if (ui->pcbSectionStyle->count() > Preferences::SectionLineStyle()) {
247
ui->pcbSectionStyle->setCurrentIndex(Preferences::SectionLineStyle() - 1);
250
DrawGuiUtil::loadLineStyleChoices(ui->pcbCenterStyle, m_lineGenerator);
251
if (ui->pcbCenterStyle->count() > Preferences::CenterLineStyle()) {
252
ui->pcbCenterStyle->setCurrentIndex(Preferences::CenterLineStyle() - 1);
255
DrawGuiUtil::loadLineStyleChoices(ui->pcbHighlightStyle, m_lineGenerator);
256
if (ui->pcbHighlightStyle->count() > Preferences::HighlightLineStyle()) {
257
ui->pcbHighlightStyle->setCurrentIndex(Preferences::HighlightLineStyle() - 1);
260
DrawGuiUtil::loadLineStyleChoices(ui->pcbHiddenStyle, m_lineGenerator);
261
if (ui->pcbHiddenStyle->count() > Preferences::HiddenLineStyle()) {
262
ui->pcbHiddenStyle->setCurrentIndex(Preferences::HiddenLineStyle() - 1);
266
#include <Mod/TechDraw/Gui/moc_DlgPrefsTechDrawAnnotationImp.cpp>