FreeCAD

Форк
0
/
PreferencesGui.cpp 
281 строка · 8.5 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2020 WandererFan <wandererfan@gmail.com>                *
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

25
#ifndef _PreComp_
26
# include <string>
27
# include <QColor>
28
# include <QFont>
29
# include <QString>
30
#endif
31

32
#include <App/Application.h>
33
#include <App/Material.h>
34
#include <Base/Console.h>
35
#include <Base/Parameter.h>
36
#include <Mod/TechDraw/App/Preferences.h>
37
#include <Mod/TechDraw/App/LineGenerator.h>
38

39

40
#include "PreferencesGui.h"
41
#include "Rez.h"
42

43

44
//getters for parameters used in multiple places.
45
//ensure this is in sync with preference page user interfaces
46

47
using namespace TechDrawGui;
48
using namespace TechDraw;
49

50
QFont PreferencesGui::labelFontQFont()
51
{
52
    QString name = Preferences::labelFontQString();
53
    return QFont(name);
54
}
55

56
int PreferencesGui::labelFontSizePX()
57
{
58
    return (int) (Rez::guiX(Preferences::labelFontSizeMM()) + 0.5);
59
}
60

61
int PreferencesGui::dimFontSizePX()
62
{
63
    return (int) (Rez::guiX(Preferences::dimFontSizeMM()) + 0.5);
64
}
65

66
QColor PreferencesGui::normalQColor()
67
{
68
    App::Color fcColor = Preferences::normalColor();
69
    return fcColor.asValue<QColor>();
70
}
71

72
QColor PreferencesGui::selectQColor()
73
{
74
    App::Color fcColor = Preferences::selectColor();
75
    return fcColor.asValue<QColor>();
76
}
77

78
QColor PreferencesGui::preselectQColor()
79
{
80
    App::Color fcColor = Preferences::preselectColor();
81
    return fcColor.asValue<QColor>();
82
}
83

84
App::Color PreferencesGui::sectionLineColor()
85
{
86
    App::Color fcColor;
87
    fcColor.setPackedValue(Preferences::getPreferenceGroup("Decorations")->GetUnsigned("SectionColor", 0x000000FF));
88
    return fcColor;
89
}
90

91
QColor PreferencesGui::sectionLineQColor()
92
{
93
//if the App::Color version has already lightened the color, we don't want to do it again
94
    App::Color fcColor;
95
    fcColor.setPackedValue(Preferences::getPreferenceGroup("Decorations")->GetUnsigned("SectionColor", 0x000000FF));
96
    return fcColor.asValue<QColor>();
97
}
98

99
App::Color PreferencesGui::centerColor()
100
{
101
    return App::Color((uint32_t) Preferences::getPreferenceGroup("Decorations")->GetUnsigned("CenterColor", 0x000000FF));
102
}
103

104
QColor PreferencesGui::centerQColor()
105
{
106
    App::Color fcColor = App::Color((uint32_t) Preferences::getPreferenceGroup("Decorations")->GetUnsigned("CenterColor", 0x000000FF));
107
    return fcColor.asValue<QColor>();
108
}
109

110
QColor PreferencesGui::vertexQColor()
111
{
112
    return Preferences::vertexColor().asValue<QColor>();
113
}
114

115
App::Color PreferencesGui::dimColor()
116
{
117
    App::Color fcColor;
118
    fcColor.setPackedValue(Preferences::getPreferenceGroup("Dimensions")->GetUnsigned("Color", 0x000000FF));  //#000000 black
119
    return fcColor;
120
}
121

122
QColor PreferencesGui::dimQColor()
123
{
124
    App::Color fcColor;
125
    fcColor.setPackedValue(Preferences::getPreferenceGroup("Dimensions")->GetUnsigned("Color", 0x000000FF));  //#000000 black
126
    return fcColor.asValue<QColor>();
127
}
128

129
App::Color PreferencesGui::leaderColor()
130
{
131
    App::Color fcColor;
132
    fcColor.setPackedValue(Preferences::getPreferenceGroup("LeaderLine")->GetUnsigned("Color", 0x000000FF));  //#000000 black
133
    return fcColor;
134
}
135

136
QColor PreferencesGui::leaderQColor()
137
{
138
    App::Color fcColor;
139
    fcColor.setPackedValue(Preferences::getPreferenceGroup("LeaderLine")->GetUnsigned("Color", 0x000000FF));  //#000000 black
140
    return fcColor.asValue<QColor>();
141
}
142

143
int PreferencesGui::dimArrowStyle()
144
{
145
    return Preferences::getPreferenceGroup("Dimensions")->GetInt("ArrowStyle", 0);
146
}
147

148
double PreferencesGui::dimArrowSize()
149
{
150
    return Preferences::getPreferenceGroup("Dimensions")->GetFloat("ArrowSize", Preferences::dimArrowSize());
151
}
152

153

154
double PreferencesGui::edgeFuzz()
155
{
156
    return Preferences::getPreferenceGroup("General")->GetFloat("EdgeFuzz", 10.0);
157
}
158

159
QString PreferencesGui::weldingDirectory()
160
{
161
    std::string defaultDir = App::Application::getResourceDir() + "Mod/TechDraw/Symbols/Welding/AWS/";
162

163
    std::string symbolDir = Preferences::getPreferenceGroup("Files")->GetASCII("WeldingDir", defaultDir.c_str());
164
    if (symbolDir.empty()) {
165
        symbolDir = defaultDir;
166
    }
167
    QString qSymbolDir = QString::fromUtf8(symbolDir.c_str());
168
    Base::FileInfo fi(symbolDir);
169
    if (!fi.isReadable()) {
170
        Base::Console().Warning("Welding Directory: %s is not readable\n", symbolDir.c_str());
171
        qSymbolDir = QString::fromUtf8(defaultDir.c_str());
172
    }
173
    return qSymbolDir;
174
}
175

176
App::Color PreferencesGui::gridColor()
177
{
178
    App::Color fcColor;
179
    fcColor.setPackedValue(Preferences::getPreferenceGroup("Colors")->GetUnsigned("gridColor", 0x000000FF));  //#000000 black
180
    return fcColor;
181
}
182

183
QColor PreferencesGui::gridQColor()
184
{
185
    App::Color fcColor;
186
    fcColor.setPackedValue(Preferences::getPreferenceGroup("Colors")->GetUnsigned("gridColor", 0x000000FF));  //#000000 black
187
    return fcColor.asValue<QColor>();
188
}
189

190
double PreferencesGui::gridSpacing()
191
{
192
    return Preferences::getPreferenceGroup("General")->GetFloat("gridSpacing", 10.0);
193
}
194

195
bool PreferencesGui::showGrid()
196
{
197
    return Preferences::getPreferenceGroup("General")->GetBool("showGrid", false);
198
}
199

200
bool PreferencesGui::multiSelection()
201
{
202
  return Preferences::getPreferenceGroup("General")->GetBool("multiSelection", false);
203
}
204

205
App::Color PreferencesGui::pageColor()
206
{
207
    App::Color result;
208
    result.setPackedValue(Preferences::getPreferenceGroup("Colors")->GetUnsigned("PageColor", 0xFFFFFFFF));  //#FFFFFFFF white
209
    return result;
210
}
211

212
QColor PreferencesGui::pageQColor()
213
{
214
    return PreferencesGui::pageColor().asValue<QColor>();
215
}
216

217
QColor PreferencesGui::getAccessibleQColor(QColor orig)
218
{
219
    if (Preferences::lightOnDark() && Preferences::monochrome()) {
220
        return lightTextQColor();
221
    }
222
    if (Preferences::lightOnDark()) {
223
        return lightenColor(orig);
224
    }
225
    return orig;
226
}
227

228
QColor PreferencesGui::lightTextQColor()
229
{
230
    return Preferences::lightTextColor().asValue<QColor>();
231
}
232

233
QColor PreferencesGui::reverseColor(QColor orig)
234
{
235
    int revRed = 255 - orig.red();
236
    int revBlue = 255 - orig.blue();
237
    int revGreen = 255 - orig.green();
238
    return QColor(revRed, revGreen, revBlue);
239
}
240

241
// largely based on code from https://invent.kde.org/graphics/okular and
242
// https://en.wikipedia.org/wiki/HSL_and_HSV#HSL_to_RGB
243
QColor PreferencesGui::lightenColor(QColor orig)
244
{
245
    // get component colours on [0, 255]
246
    uchar red = orig.red();
247
    uchar blue = orig.blue();
248
    uchar green = orig.green();
249
    uchar alpha = orig.alpha();
250

251
    // shift color values
252
    uchar m = std::min( {red, blue, green} );
253
    red -= m;
254
    blue -= m;
255
    green -= m;
256

257
    // calculate chroma (colour range)
258
    uchar chroma = std::max( {red, blue, green} );
259

260
    // calculate lightened colour value
261
    uchar newm = 255 - chroma - m;
262
    red += newm;
263
    green += newm;
264
    blue += newm;
265

266
    return QColor(red, green, blue, alpha);
267
}
268

269

270
double PreferencesGui::templateClickBoxSize()
271
{
272
    return Preferences::getPreferenceGroup("General")->GetFloat("TemplateDotSize", 5.0);
273
}
274

275

276
QColor PreferencesGui::templateClickBoxColor()
277
{
278
    App::Color fcColor;
279
    fcColor.setPackedValue(Preferences::getPreferenceGroup("Colors")->GetUnsigned("TemplateUnderlineColor", 0x0000FFFF));  //#0000FF blue
280
    return fcColor.asValue<QColor>();
281
}
282

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

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

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

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