1
/***************************************************************************
2
* Copyright (c) 2020 WandererFan <wandererfan@gmail.com> *
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"
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>
40
#include "PreferencesGui.h"
44
//getters for parameters used in multiple places.
45
//ensure this is in sync with preference page user interfaces
47
using namespace TechDrawGui;
48
using namespace TechDraw;
50
QFont PreferencesGui::labelFontQFont()
52
QString name = Preferences::labelFontQString();
56
int PreferencesGui::labelFontSizePX()
58
return (int) (Rez::guiX(Preferences::labelFontSizeMM()) + 0.5);
61
int PreferencesGui::dimFontSizePX()
63
return (int) (Rez::guiX(Preferences::dimFontSizeMM()) + 0.5);
66
QColor PreferencesGui::normalQColor()
68
App::Color fcColor = Preferences::normalColor();
69
return fcColor.asValue<QColor>();
72
QColor PreferencesGui::selectQColor()
74
App::Color fcColor = Preferences::selectColor();
75
return fcColor.asValue<QColor>();
78
QColor PreferencesGui::preselectQColor()
80
App::Color fcColor = Preferences::preselectColor();
81
return fcColor.asValue<QColor>();
84
App::Color PreferencesGui::sectionLineColor()
87
fcColor.setPackedValue(Preferences::getPreferenceGroup("Decorations")->GetUnsigned("SectionColor", 0x000000FF));
91
QColor PreferencesGui::sectionLineQColor()
93
//if the App::Color version has already lightened the color, we don't want to do it again
95
fcColor.setPackedValue(Preferences::getPreferenceGroup("Decorations")->GetUnsigned("SectionColor", 0x000000FF));
96
return fcColor.asValue<QColor>();
99
App::Color PreferencesGui::centerColor()
101
return App::Color((uint32_t) Preferences::getPreferenceGroup("Decorations")->GetUnsigned("CenterColor", 0x000000FF));
104
QColor PreferencesGui::centerQColor()
106
App::Color fcColor = App::Color((uint32_t) Preferences::getPreferenceGroup("Decorations")->GetUnsigned("CenterColor", 0x000000FF));
107
return fcColor.asValue<QColor>();
110
QColor PreferencesGui::vertexQColor()
112
return Preferences::vertexColor().asValue<QColor>();
115
App::Color PreferencesGui::dimColor()
118
fcColor.setPackedValue(Preferences::getPreferenceGroup("Dimensions")->GetUnsigned("Color", 0x000000FF)); //#000000 black
122
QColor PreferencesGui::dimQColor()
125
fcColor.setPackedValue(Preferences::getPreferenceGroup("Dimensions")->GetUnsigned("Color", 0x000000FF)); //#000000 black
126
return fcColor.asValue<QColor>();
129
App::Color PreferencesGui::leaderColor()
132
fcColor.setPackedValue(Preferences::getPreferenceGroup("LeaderLine")->GetUnsigned("Color", 0x000000FF)); //#000000 black
136
QColor PreferencesGui::leaderQColor()
139
fcColor.setPackedValue(Preferences::getPreferenceGroup("LeaderLine")->GetUnsigned("Color", 0x000000FF)); //#000000 black
140
return fcColor.asValue<QColor>();
143
int PreferencesGui::dimArrowStyle()
145
return Preferences::getPreferenceGroup("Dimensions")->GetInt("ArrowStyle", 0);
148
double PreferencesGui::dimArrowSize()
150
return Preferences::getPreferenceGroup("Dimensions")->GetFloat("ArrowSize", Preferences::dimArrowSize());
154
double PreferencesGui::edgeFuzz()
156
return Preferences::getPreferenceGroup("General")->GetFloat("EdgeFuzz", 10.0);
159
QString PreferencesGui::weldingDirectory()
161
std::string defaultDir = App::Application::getResourceDir() + "Mod/TechDraw/Symbols/Welding/AWS/";
163
std::string symbolDir = Preferences::getPreferenceGroup("Files")->GetASCII("WeldingDir", defaultDir.c_str());
164
if (symbolDir.empty()) {
165
symbolDir = defaultDir;
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());
176
App::Color PreferencesGui::gridColor()
179
fcColor.setPackedValue(Preferences::getPreferenceGroup("Colors")->GetUnsigned("gridColor", 0x000000FF)); //#000000 black
183
QColor PreferencesGui::gridQColor()
186
fcColor.setPackedValue(Preferences::getPreferenceGroup("Colors")->GetUnsigned("gridColor", 0x000000FF)); //#000000 black
187
return fcColor.asValue<QColor>();
190
double PreferencesGui::gridSpacing()
192
return Preferences::getPreferenceGroup("General")->GetFloat("gridSpacing", 10.0);
195
bool PreferencesGui::showGrid()
197
return Preferences::getPreferenceGroup("General")->GetBool("showGrid", false);
200
bool PreferencesGui::multiSelection()
202
return Preferences::getPreferenceGroup("General")->GetBool("multiSelection", false);
205
App::Color PreferencesGui::pageColor()
208
result.setPackedValue(Preferences::getPreferenceGroup("Colors")->GetUnsigned("PageColor", 0xFFFFFFFF)); //#FFFFFFFF white
212
QColor PreferencesGui::pageQColor()
214
return PreferencesGui::pageColor().asValue<QColor>();
217
QColor PreferencesGui::getAccessibleQColor(QColor orig)
219
if (Preferences::lightOnDark() && Preferences::monochrome()) {
220
return lightTextQColor();
222
if (Preferences::lightOnDark()) {
223
return lightenColor(orig);
228
QColor PreferencesGui::lightTextQColor()
230
return Preferences::lightTextColor().asValue<QColor>();
233
QColor PreferencesGui::reverseColor(QColor orig)
235
int revRed = 255 - orig.red();
236
int revBlue = 255 - orig.blue();
237
int revGreen = 255 - orig.green();
238
return QColor(revRed, revGreen, revBlue);
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)
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();
251
// shift color values
252
uchar m = std::min( {red, blue, green} );
257
// calculate chroma (colour range)
258
uchar chroma = std::max( {red, blue, green} );
260
// calculate lightened colour value
261
uchar newm = 255 - chroma - m;
266
return QColor(red, green, blue, alpha);
270
double PreferencesGui::templateClickBoxSize()
272
return Preferences::getPreferenceGroup("General")->GetFloat("TemplateDotSize", 5.0);
276
QColor PreferencesGui::templateClickBoxColor()
279
fcColor.setPackedValue(Preferences::getPreferenceGroup("Colors")->GetUnsigned("TemplateUnderlineColor", 0x0000FFFF)); //#0000FF blue
280
return fcColor.asValue<QColor>();