/*************************************************************************** * Copyright (c) 2020 WandererFan * * * * This file is part of the FreeCAD CAx development system. * * * * This library is free software; you can redistribute it and/or * * modify it under the terms of the GNU Library General Public * * License as published by the Free Software Foundation; either * * version 2 of the License, or (at your option) any later version. * * * * This library is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU Library General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this library; see the file COPYING.LIB. If not, * * write to the Free Software Foundation, Inc., 59 Temple Place, * * Suite 330, Boston, MA 02111-1307, USA * * * ***************************************************************************/ #include "PreCompiled.h" #ifndef _PreComp_ # include # include # include # include #endif #include #include #include #include #include #include #include #include "PreferencesGui.h" #include "Rez.h" //getters for parameters used in multiple places. //ensure this is in sync with preference page user interfaces using namespace TechDrawGui; using namespace TechDraw; QFont PreferencesGui::labelFontQFont() { QString name = Preferences::labelFontQString(); return QFont(name); } int PreferencesGui::labelFontSizePX() { return (int) (Rez::guiX(Preferences::labelFontSizeMM()) + 0.5); } int PreferencesGui::dimFontSizePX() { return (int) (Rez::guiX(Preferences::dimFontSizeMM()) + 0.5); } QColor PreferencesGui::normalQColor() { App::Color fcColor = Preferences::normalColor(); return fcColor.asValue(); } QColor PreferencesGui::selectQColor() { App::Color fcColor = Preferences::selectColor(); return fcColor.asValue(); } QColor PreferencesGui::preselectQColor() { App::Color fcColor = Preferences::preselectColor(); return fcColor.asValue(); } App::Color PreferencesGui::sectionLineColor() { App::Color fcColor; fcColor.setPackedValue(Preferences::getPreferenceGroup("Decorations")->GetUnsigned("SectionColor", 0x000000FF)); return fcColor; } QColor PreferencesGui::sectionLineQColor() { //if the App::Color version has already lightened the color, we don't want to do it again App::Color fcColor; fcColor.setPackedValue(Preferences::getPreferenceGroup("Decorations")->GetUnsigned("SectionColor", 0x000000FF)); return fcColor.asValue(); } App::Color PreferencesGui::breaklineColor() { App::Color fcColor; fcColor.setPackedValue(Preferences::getPreferenceGroup("Decorations")->GetUnsigned("BreaklineColor", 0x000000FF)); return fcColor; } QColor PreferencesGui::breaklineQColor() { //if the App::Color version has already lightened the color, we don't want to do it again App::Color fcColor; fcColor.setPackedValue(Preferences::getPreferenceGroup("Decorations")->GetUnsigned("BreaklineColor", 0x000000FF)); return fcColor.asValue(); } App::Color PreferencesGui::centerColor() { return App::Color((uint32_t) Preferences::getPreferenceGroup("Decorations")->GetUnsigned("CenterColor", 0x000000FF)); } QColor PreferencesGui::centerQColor() { App::Color fcColor = App::Color((uint32_t) Preferences::getPreferenceGroup("Decorations")->GetUnsigned("CenterColor", 0x000000FF)); return fcColor.asValue(); } QColor PreferencesGui::vertexQColor() { return Preferences::vertexColor().asValue(); } App::Color PreferencesGui::dimColor() { App::Color fcColor; fcColor.setPackedValue(Preferences::getPreferenceGroup("Dimensions")->GetUnsigned("Color", 0x000000FF)); //#000000 black return fcColor; } QColor PreferencesGui::dimQColor() { App::Color fcColor; fcColor.setPackedValue(Preferences::getPreferenceGroup("Dimensions")->GetUnsigned("Color", 0x000000FF)); //#000000 black return fcColor.asValue(); } App::Color PreferencesGui::leaderColor() { App::Color fcColor; fcColor.setPackedValue(Preferences::getPreferenceGroup("LeaderLine")->GetUnsigned("Color", 0x000000FF)); //#000000 black return fcColor; } QColor PreferencesGui::leaderQColor() { App::Color fcColor; fcColor.setPackedValue(Preferences::getPreferenceGroup("LeaderLine")->GetUnsigned("Color", 0x000000FF)); //#000000 black return fcColor.asValue(); } int PreferencesGui::dimArrowStyle() { return Preferences::getPreferenceGroup("Dimensions")->GetInt("ArrowStyle", 0); } double PreferencesGui::dimArrowSize() { return Preferences::getPreferenceGroup("Dimensions")->GetFloat("ArrowSize", Preferences::dimArrowSize()); } double PreferencesGui::edgeFuzz() { return Preferences::getPreferenceGroup("General")->GetFloat("EdgeFuzz", 10.0); } QString PreferencesGui::weldingDirectory() { std::string defaultDir = App::Application::getResourceDir() + "Mod/TechDraw/Symbols/Welding/AWS/"; std::string symbolDir = Preferences::getPreferenceGroup("Files")->GetASCII("WeldingDir", defaultDir.c_str()); if (symbolDir.empty()) { symbolDir = defaultDir; } QString qSymbolDir = QString::fromUtf8(symbolDir.c_str()); Base::FileInfo fi(symbolDir); if (!fi.isReadable()) { Base::Console().Warning("Welding Directory: %s is not readable\n", symbolDir.c_str()); qSymbolDir = QString::fromUtf8(defaultDir.c_str()); } return qSymbolDir; } App::Color PreferencesGui::gridColor() { App::Color fcColor; fcColor.setPackedValue(Preferences::getPreferenceGroup("Colors")->GetUnsigned("gridColor", 0x000000FF)); //#000000 black return fcColor; } QColor PreferencesGui::gridQColor() { App::Color fcColor; fcColor.setPackedValue(Preferences::getPreferenceGroup("Colors")->GetUnsigned("gridColor", 0x000000FF)); //#000000 black return fcColor.asValue(); } double PreferencesGui::gridSpacing() { return Preferences::getPreferenceGroup("General")->GetFloat("gridSpacing", 10.0); } bool PreferencesGui::showGrid() { return Preferences::getPreferenceGroup("General")->GetBool("showGrid", false); } bool PreferencesGui::multiSelection() { bool greedy = Gui::Selection().getSelectionStyle() == Gui::SelectionSingleton::SelectionStyle::GreedySelection; return greedy || Preferences::getPreferenceGroup("General")->GetBool("multiSelection", false); } App::Color PreferencesGui::pageColor() { App::Color result; result.setPackedValue(Preferences::getPreferenceGroup("Colors")->GetUnsigned("PageColor", 0xFFFFFFFF)); //#FFFFFFFF white return result; } QColor PreferencesGui::pageQColor() { return PreferencesGui::pageColor().asValue(); } QColor PreferencesGui::getAccessibleQColor(QColor orig) { if (Preferences::lightOnDark() && Preferences::monochrome()) { return lightTextQColor(); } if (Preferences::lightOnDark()) { return lightenColor(orig); } return orig; } QColor PreferencesGui::lightTextQColor() { return Preferences::lightTextColor().asValue(); } QColor PreferencesGui::reverseColor(QColor orig) { int revRed = 255 - orig.red(); int revBlue = 255 - orig.blue(); int revGreen = 255 - orig.green(); return QColor(revRed, revGreen, revBlue); } // largely based on code from https://invent.kde.org/graphics/okular and // https://en.wikipedia.org/wiki/HSL_and_HSV#HSL_to_RGB QColor PreferencesGui::lightenColor(QColor orig) { // get component colours on [0, 255] uchar red = orig.red(); uchar blue = orig.blue(); uchar green = orig.green(); uchar alpha = orig.alpha(); // shift color values uchar m = std::min( {red, blue, green} ); red -= m; blue -= m; green -= m; // calculate chroma (colour range) uchar chroma = std::max( {red, blue, green} ); // calculate lightened colour value uchar newm = 255 - chroma - m; red += newm; green += newm; blue += newm; return QColor(red, green, blue, alpha); } double PreferencesGui::templateClickBoxSize() { return Preferences::getPreferenceGroup("General")->GetFloat("TemplateDotSize", 5.0); } QColor PreferencesGui::templateClickBoxColor() { App::Color fcColor; fcColor.setPackedValue(Preferences::getPreferenceGroup("Colors")->GetUnsigned("TemplateUnderlineColor", 0x0000FFFF)); //#0000FF blue return fcColor.asValue(); } int PreferencesGui::get3dMarkerSize() { ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath ("User parameter:BaseApp/Preferences/View"); return hGrp->GetInt("MarkerSize", 9L); }