FreeCAD

Форк
0
/
DlgPrefsTechDrawAnnotationImp.cpp 
266 строк · 10.2 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2020 FreeCAD Developers                                 *
3
 *   Author: Uwe Stöhr <uwestoehr@lyx.org>                                 *
4
 *   Based on src/Mod/FEM/Gui/DlgSettingsFEMImp.cpp                        *
5
 *                                                                         *
6
 *   This file is part of the FreeCAD CAx development system.              *
7
 *                                                                         *
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.      *
12
 *                                                                         *
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.                  *
17
 *                                                                         *
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                                *
22
 *                                                                         *
23
 ***************************************************************************/
24

25
#include "PreCompiled.h"
26
#ifndef _PreComp_
27
# include <vector>
28
#endif
29

30
#include <Base/Tools.h>
31

32
#include <Mod/TechDraw/App/LineGroup.h>
33
#include <Mod/TechDraw/App/Preferences.h>
34
#include <Mod/TechDraw/App/LineGenerator.h>
35

36
#include "DlgPrefsTechDrawAnnotationImp.h"
37
#include "ui_DlgPrefsTechDrawAnnotation.h"
38
#include "DrawGuiUtil.h"
39

40
using namespace TechDrawGui;
41
using namespace TechDraw;
42

43

44
DlgPrefsTechDrawAnnotationImp::DlgPrefsTechDrawAnnotationImp( QWidget* parent )
45
  : PreferencePage( parent )
46
  , ui(new Ui_DlgPrefsTechDrawAnnotationImp)
47
{
48
    ui->setupUi(this);
49
    ui->pdsbBalloonKink->setUnit(Base::Unit::Length);
50
    ui->pdsbBalloonKink->setMinimum(0);
51

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);
63

64
    // connect the LineGroup the update the tooltip if index changed
65
    connect(ui->pcbLineGroup, qOverload<int>(&QComboBox::currentIndexChanged),
66
            this, &DlgPrefsTechDrawAnnotationImp::onLineGroupChanged);
67

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);
71

72
     m_lineGenerator = new LineGenerator();
73
}
74

75
DlgPrefsTechDrawAnnotationImp::~DlgPrefsTechDrawAnnotationImp()
76
{
77
    // no need to delete child widgets, Qt does it all for us
78
    delete m_lineGenerator;
79
}
80

81
void DlgPrefsTechDrawAnnotationImp::saveSettings()
82
{
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();
93

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();
99
    }
100
    if (ui->pcbSectionStyle->currentIndex() >= 0) {
101
        ui->pcbSectionStyle->onSave();
102
    }
103
    if (ui->pcbCenterStyle->currentIndex() >= 0)  {
104
        ui->pcbCenterStyle->onSave();
105
    }
106
    if (ui->pcbHighlightStyle->currentIndex() >= 0) {
107
        ui->pcbHighlightStyle->onSave();
108
    }
109
    if (ui->cbEndCap->currentIndex() >= 0) {
110
        ui->cbEndCap->onSave();
111
    }
112
    if (ui->pcbHiddenStyle->currentIndex() >= 0) {
113
        ui->pcbHiddenStyle->onSave();
114
    }
115

116
    ui->pcbDetailMatting->onSave();
117
    ui->pcbDetailHighlight->onSave();
118
}
119

120
void DlgPrefsTechDrawAnnotationImp::loadSettings()
121
{
122
    //set defaults for Quantity widgets if property not found
123
    //Quantity widgets do not use preset value since they are based on
124
    //QAbstractSpinBox
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);
136
    }
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()));
140
    }
141

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();
155

156

157
    ui->pcbBalloonArrow->onRestore();
158
    DrawGuiUtil::loadArrowBox(ui->pcbBalloonArrow);
159
    ui->pcbBalloonArrow->setCurrentIndex(prefBalloonArrow());
160

161
    ui->cbEndCap->onRestore();
162

163
    // prevent onChanged processing while loading comboBox
164
    ui->pcbLineStandard->blockSignals(true);
165
    DrawGuiUtil::loadLineStandardsChoices(ui->pcbLineStandard);
166
    ui->pcbLineStandard->blockSignals(false);
167

168
    if (ui->pcbLineStandard->count() > Preferences::lineStandard()) {
169
        ui->pcbLineStandard->setCurrentIndex(Preferences::lineStandard());
170
    }
171

172
    ui->pcbSectionStyle->onRestore();
173
    ui->pcbCenterStyle->onRestore();
174
    ui->pcbHighlightStyle->onRestore();
175
    ui->pcbHiddenStyle->onRestore();
176
    loadLineStyleBoxes();
177
}
178

179
/**
180
 * Sets the strings of the subwidgets using the current language.
181
 */
182
void DlgPrefsTechDrawAnnotationImp::changeEvent(QEvent *e)
183
{
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);
190
    }
191
    else {
192
        QWidget::changeEvent(e);
193
    }
194
}
195

196
int DlgPrefsTechDrawAnnotationImp::prefBalloonArrow() const
197
{
198
    return Preferences::balloonArrow();
199
}
200

201
/**
202
 * Updates the tooltip of the LineGroup combobox
203
 */
204
void DlgPrefsTechDrawAnnotationImp::onLineGroupChanged(int index)
205
{
206
    if (index == -1) { // there is no valid index yet
207
        ui->pcbLineGroup->setToolTip(QObject::tr("Please select a Line Group"));
208
        return;
209
    }
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);
216
    }
217
    ui->pcbLineGroup->setToolTip(
218
        QObject::tr("%1 defines these line widths:\n thin: %2\n graphic: %3\n"
219
                    "thick: %4")
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))));
224
}
225

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)
229
{
230
    if (index < 0) {
231
        // do not process invalid index
232
        return;
233
    }
234
    Preferences::setLineStandard(index);
235
    m_lineGenerator->reloadDescriptions();
236
    loadLineStyleBoxes();
237
}
238

239
//! fill the various line style comboboxes
240
void DlgPrefsTechDrawAnnotationImp::loadLineStyleBoxes()
241
{
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);
248
    }
249

250
    DrawGuiUtil::loadLineStyleChoices(ui->pcbCenterStyle, m_lineGenerator);
251
    if (ui->pcbCenterStyle->count() > Preferences::CenterLineStyle()) {
252
        ui->pcbCenterStyle->setCurrentIndex(Preferences::CenterLineStyle() - 1);
253
    }
254

255
    DrawGuiUtil::loadLineStyleChoices(ui->pcbHighlightStyle, m_lineGenerator);
256
    if (ui->pcbHighlightStyle->count() > Preferences::HighlightLineStyle()) {
257
        ui->pcbHighlightStyle->setCurrentIndex(Preferences::HighlightLineStyle() - 1);
258
    }
259

260
    DrawGuiUtil::loadLineStyleChoices(ui->pcbHiddenStyle, m_lineGenerator);
261
    if (ui->pcbHiddenStyle->count() > Preferences::HiddenLineStyle()) {
262
        ui->pcbHiddenStyle->setCurrentIndex(Preferences::HiddenLineStyle() - 1);
263
    }
264
}
265

266
#include <Mod/TechDraw/Gui/moc_DlgPrefsTechDrawAnnotationImp.cpp>
267

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

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

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

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