From f8cb31ba0e85f620b912c5da1c7ba9494ca9c59b Mon Sep 17 00:00:00 2001 From: Syres916 <46537884+Syres916@users.noreply.github.com> Date: Thu, 2 May 2024 19:05:33 +0100 Subject: [PATCH] [TechDraw] Improve visibility of TD preference icons in combo boxes... ...when using dark style sheets. --- src/Mod/TechDraw/App/BalloonPropEnum.cpp | 51 ++++ src/Mod/TechDraw/App/BalloonPropEnum.h | 58 ++++ src/Mod/TechDraw/App/CMakeLists.txt | 4 + src/Mod/TechDraw/App/MattingPropEnum.cpp | 39 +++ src/Mod/TechDraw/App/MattingPropEnum.h | 49 ++++ .../Gui/DlgPrefsTechDrawAnnotation.ui | 90 ------ .../Gui/DlgPrefsTechDrawAnnotationImp.cpp | 50 +++- .../Gui/DlgPrefsTechDrawAnnotationImp.h | 2 + src/Mod/TechDraw/Gui/DrawGuiUtil.cpp | 271 +++++++++++++----- src/Mod/TechDraw/Gui/DrawGuiUtil.h | 14 +- 10 files changed, 451 insertions(+), 177 deletions(-) create mode 100644 src/Mod/TechDraw/App/BalloonPropEnum.cpp create mode 100644 src/Mod/TechDraw/App/BalloonPropEnum.h create mode 100644 src/Mod/TechDraw/App/MattingPropEnum.cpp create mode 100644 src/Mod/TechDraw/App/MattingPropEnum.h diff --git a/src/Mod/TechDraw/App/BalloonPropEnum.cpp b/src/Mod/TechDraw/App/BalloonPropEnum.cpp new file mode 100644 index 0000000000..5ebc8cf388 --- /dev/null +++ b/src/Mod/TechDraw/App/BalloonPropEnum.cpp @@ -0,0 +1,51 @@ +/*************************************************************************** + * 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" + +#include "BalloonPropEnum.h" + + +namespace TechDraw { + +const int BalloonPropEnum::BalloonCount = 8; +const char* BalloonPropEnum::BalloonTypeEnums[]= { + QT_TRANSLATE_NOOP("BalloonPropEnum", "Circular"), + QT_TRANSLATE_NOOP("BalloonPropEnum", "None"), + QT_TRANSLATE_NOOP("BalloonPropEnum", "Triangle"), + QT_TRANSLATE_NOOP("BalloonPropEnum", "Inspection"), + QT_TRANSLATE_NOOP("BalloonPropEnum", "Hexagon"), + QT_TRANSLATE_NOOP("BalloonPropEnum", "Square"), + QT_TRANSLATE_NOOP("BalloonPropEnum", "Rectangle"), + QT_TRANSLATE_NOOP("BalloonPropEnum", "Line"), + nullptr}; + +const std::vector BalloonPropEnum::BalloonTypeIcons = { ":icons/circular.svg", + ":icons/none.svg", + ":icons/triangle.svg", + ":icons/inspection.svg", + ":icons/hexagon.svg", + ":icons/square.svg", + ":icons/rectangle.svg", + ":icons/bottomline.svg"}; + +} diff --git a/src/Mod/TechDraw/App/BalloonPropEnum.h b/src/Mod/TechDraw/App/BalloonPropEnum.h new file mode 100644 index 0000000000..d2ce78a760 --- /dev/null +++ b/src/Mod/TechDraw/App/BalloonPropEnum.h @@ -0,0 +1,58 @@ +/*************************************************************************** + * 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 * + * * + ***************************************************************************/ + +#ifndef BALLOONENUMS_H_ +#define BALLOONENUMS_H_ + +#include +#include +#include + +#include + + +namespace TechDraw +{ + +enum BalloonType { Circular = 0, + None, + Triangle, + Inspection, + Hexagon, + Square, + Rectangle, + Line}; + +class TechDrawExport BalloonPropEnum { + Q_DECLARE_TR_FUNCTIONS(TechDraw::BalloonPropEnum) + + public: + static const char* BalloonTypeEnums[]; + static const int BalloonCount; + static const std::vector BalloonTypeIcons; + +private: + +}; + +} //end namespace TechDraw +#endif diff --git a/src/Mod/TechDraw/App/CMakeLists.txt b/src/Mod/TechDraw/App/CMakeLists.txt index 4df2f85daf..5cf6d234b8 100644 --- a/src/Mod/TechDraw/App/CMakeLists.txt +++ b/src/Mod/TechDraw/App/CMakeLists.txt @@ -164,6 +164,10 @@ SET(TechDraw_SRCS LineNameEnum.h ArrowPropEnum.cpp ArrowPropEnum.h + BalloonPropEnum.cpp + BalloonPropEnum.h + MattingPropEnum.cpp + MattingPropEnum.h Preferences.cpp Preferences.h TechDrawExport.cpp diff --git a/src/Mod/TechDraw/App/MattingPropEnum.cpp b/src/Mod/TechDraw/App/MattingPropEnum.cpp new file mode 100644 index 0000000000..713c4c7c97 --- /dev/null +++ b/src/Mod/TechDraw/App/MattingPropEnum.cpp @@ -0,0 +1,39 @@ +/*************************************************************************** + * 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" + +#include "MattingPropEnum.h" + + +namespace TechDraw { + +const int MattingPropEnum::MattingCount = 2; +const char* MattingPropEnum::MattingTypeEnums[]= { + QT_TRANSLATE_NOOP("MattingPropEnum", "Circle"), + QT_TRANSLATE_NOOP("MattingPropEnum", "Square"), + nullptr}; + +const std::vector MattingPropEnum::MattingTypeIcons = { ":icons/circular.svg", + ":icons/square.svg"}; + +} diff --git a/src/Mod/TechDraw/App/MattingPropEnum.h b/src/Mod/TechDraw/App/MattingPropEnum.h new file mode 100644 index 0000000000..80e22eff0e --- /dev/null +++ b/src/Mod/TechDraw/App/MattingPropEnum.h @@ -0,0 +1,49 @@ +/*************************************************************************** + * 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 * + * * + ***************************************************************************/ + +#ifndef MATTINGENUMS_H_ +#define MATTINGENUMS_H_ + +#include +#include +#include + +#include + + +namespace TechDraw +{ + +class TechDrawExport MattingPropEnum { + Q_DECLARE_TR_FUNCTIONS(TechDraw::MattingPropEnum) + + public: + static const char* MattingTypeEnums[]; + static const int MattingCount; + static const std::vector MattingTypeIcons; + +private: + +}; + +} //end namespace TechDraw +#endif diff --git a/src/Mod/TechDraw/Gui/DlgPrefsTechDrawAnnotation.ui b/src/Mod/TechDraw/Gui/DlgPrefsTechDrawAnnotation.ui index e21e117665..8ec48c36d6 100644 --- a/src/Mod/TechDraw/Gui/DlgPrefsTechDrawAnnotation.ui +++ b/src/Mod/TechDraw/Gui/DlgPrefsTechDrawAnnotation.ui @@ -457,24 +457,6 @@ /Mod/TechDraw/Decorations - - - Circle - - - - :/icons/circular.svg:/icons/circular.svg - - - - - Square - - - - :/icons/square.svg:/icons/square.svg - - @@ -500,78 +482,6 @@ Mod/TechDraw/Decorations - - - Circular - - - - :/icons/circular.svg:/icons/circular.svg - - - - - None - - - - :/icons/none.svg:/icons/none.svg - - - - - Triangle - - - - :/icons/triangle.svg:/icons/triangle.svg - - - - - Inspection - - - - :/icons/inspection.svg:/icons/inspection.svg - - - - - Hexagon - - - - :/icons/hexagon.svg:/icons/hexagon.svg - - - - - Square - - - - :/icons/square.svg:/icons/square.svg - - - - - Rectangle - - - - :/icons/rectangle.svg:/icons/rectangle.svg - - - - - Line - - - - :/icons/bottomline.svg:/icons/bottomline.svg - - diff --git a/src/Mod/TechDraw/Gui/DlgPrefsTechDrawAnnotationImp.cpp b/src/Mod/TechDraw/Gui/DlgPrefsTechDrawAnnotationImp.cpp index 19fb25184a..ff4a43e974 100644 --- a/src/Mod/TechDraw/Gui/DlgPrefsTechDrawAnnotationImp.cpp +++ b/src/Mod/TechDraw/Gui/DlgPrefsTechDrawAnnotationImp.cpp @@ -41,9 +41,9 @@ using namespace TechDrawGui; using namespace TechDraw; -DlgPrefsTechDrawAnnotationImp::DlgPrefsTechDrawAnnotationImp( QWidget* parent ) - : PreferencePage( parent ) - , ui(new Ui_DlgPrefsTechDrawAnnotationImp) +DlgPrefsTechDrawAnnotationImp::DlgPrefsTechDrawAnnotationImp(QWidget* parent) + : PreferencePage(parent) + , ui(new Ui_DlgPrefsTechDrawAnnotationImp) { ui->setupUi(this); ui->pdsbBalloonKink->setUnit(Base::Unit::Length); @@ -62,14 +62,18 @@ DlgPrefsTechDrawAnnotationImp::DlgPrefsTechDrawAnnotationImp( QWidget* parent ) ui->pcbHiddenStyle->setStyleSheet(ssOverride); // connect the LineGroup the update the tooltip if index changed - connect(ui->pcbLineGroup, qOverload(&QComboBox::currentIndexChanged), - this, &DlgPrefsTechDrawAnnotationImp::onLineGroupChanged); + connect(ui->pcbLineGroup, + qOverload(&QComboBox::currentIndexChanged), + this, + &DlgPrefsTechDrawAnnotationImp::onLineGroupChanged); // NOTE that we block onChanged processing while loading the Line Standard combobox - connect(ui->pcbLineStandard, qOverload(&QComboBox::currentIndexChanged), - this, &DlgPrefsTechDrawAnnotationImp::onLineStandardChanged); + connect(ui->pcbLineStandard, + qOverload(&QComboBox::currentIndexChanged), + this, + &DlgPrefsTechDrawAnnotationImp::onLineStandardChanged); - m_lineGenerator = new LineGenerator(); + m_lineGenerator = new LineGenerator(); } DlgPrefsTechDrawAnnotationImp::~DlgPrefsTechDrawAnnotationImp() @@ -103,7 +107,7 @@ void DlgPrefsTechDrawAnnotationImp::saveSettings() if (ui->pcbSectionStyle->currentIndex() >= 0) { ui->pcbSectionStyle->onSave(); } - if (ui->pcbCenterStyle->currentIndex() >= 0) { + if (ui->pcbCenterStyle->currentIndex() >= 0) { ui->pcbCenterStyle->onSave(); } if (ui->pcbHighlightStyle->currentIndex() >= 0) { @@ -125,9 +129,9 @@ void DlgPrefsTechDrawAnnotationImp::saveSettings() void DlgPrefsTechDrawAnnotationImp::loadSettings() { - //set defaults for Quantity widgets if property not found - //Quantity widgets do not use preset value since they are based on - //QAbstractSpinBox + // set defaults for Quantity widgets if property not found + // Quantity widgets do not use preset value since they are based on + // QAbstractSpinBox double kinkDefault = 5.0; ui->pdsbBalloonKink->setValue(kinkDefault); // re-read the available LineGroup files @@ -151,16 +155,22 @@ void DlgPrefsTechDrawAnnotationImp::loadSettings() ui->cbComplexMarks->onRestore(); ui->cbShowCenterMarks->onRestore(); ui->pcbLineGroup->onRestore(); - ui->pcbBalloonArrow->onRestore(); - ui->pcbBalloonShape->onRestore(); - ui->pcbMatting->onRestore(); ui->pdsbBalloonKink->onRestore(); ui->cbCutSurface->onRestore(); ui->pcbDetailMatting->onRestore(); ui->pcbDetailHighlight->onRestore(); + ui->cb_ShowSectionLine->onRestore(); ui->cb_IncludeCutLine->onRestore(); + ui->pcbMatting->onRestore(); + DrawGuiUtil::loadMattingStyleBox(ui->pcbMatting); + ui->pcbMatting->setCurrentIndex(prefMattingStyle()); + + ui->pcbBalloonShape->onRestore(); + DrawGuiUtil::loadBalloonShapeBox(ui->pcbBalloonShape); + ui->pcbBalloonShape->setCurrentIndex(prefBalloonShape()); + ui->pcbBalloonArrow->onRestore(); DrawGuiUtil::loadArrowBox(ui->pcbBalloonArrow); ui->pcbBalloonArrow->setCurrentIndex(prefBalloonArrow()); @@ -208,6 +218,16 @@ int DlgPrefsTechDrawAnnotationImp::prefBalloonArrow() const return Preferences::balloonArrow(); } +int DlgPrefsTechDrawAnnotationImp::prefBalloonShape() const +{ + return Preferences::balloonShape(); +} + +int DlgPrefsTechDrawAnnotationImp::prefMattingStyle() const +{ + return Preferences::mattingStyle(); +} + /** * Updates the tooltip of the LineGroup combobox */ diff --git a/src/Mod/TechDraw/Gui/DlgPrefsTechDrawAnnotationImp.h b/src/Mod/TechDraw/Gui/DlgPrefsTechDrawAnnotationImp.h index 63c733dcd9..1b2b67b8f6 100644 --- a/src/Mod/TechDraw/Gui/DlgPrefsTechDrawAnnotationImp.h +++ b/src/Mod/TechDraw/Gui/DlgPrefsTechDrawAnnotationImp.h @@ -54,6 +54,8 @@ protected: void changeEvent(QEvent *e) override; int prefBalloonArrow() const; + int prefBalloonShape() const; + int prefMattingStyle() const; void loadLineStyleBoxes(); private: diff --git a/src/Mod/TechDraw/Gui/DrawGuiUtil.cpp b/src/Mod/TechDraw/Gui/DrawGuiUtil.cpp index 49b09b89f3..50c0137347 100644 --- a/src/Mod/TechDraw/Gui/DrawGuiUtil.cpp +++ b/src/Mod/TechDraw/Gui/DrawGuiUtil.cpp @@ -25,12 +25,15 @@ #ifndef _PreComp_ # include -# include -# include -# include -# include -# include -# include +#include +#include +#include +#include +#include +#include +#include +#include +#include # include # include @@ -58,7 +61,9 @@ #include #include +#include #include +#include #include #include #include @@ -78,11 +83,84 @@ using DU = DrawUtil; void DrawGuiUtil::loadArrowBox(QComboBox* qcb) { qcb->clear(); + QPalette qcbPal = qcb->palette(); + QColor textColor = qcbPal.color(QPalette::WindowText); + auto curStyleSheet = + App::GetApplication() + .GetParameterGroupByPath("User parameter:BaseApp/Preferences/MainWindow") + ->GetASCII("StyleSheet", "None"); + + bool darkSS = isStyleSheetDark(curStyleSheet); + int i = 0; for (; i < ArrowPropEnum::ArrowCount; i++) { - qcb->addItem(QCoreApplication::translate("ArrowPropEnum", ArrowPropEnum::ArrowTypeEnums[i])); + qcb->addItem( + QCoreApplication::translate("ArrowPropEnum", ArrowPropEnum::ArrowTypeEnums[i])); QIcon itemIcon(QString::fromUtf8(ArrowPropEnum::ArrowTypeIcons[i].c_str())); - qcb->setItemIcon(i, itemIcon); + if (darkSS) { + QSize iconSize(48, 48); + QIcon itemUpdatedIcon(maskBlackPixels(itemIcon, iconSize, textColor)); + qcb->setItemIcon(i, itemUpdatedIcon); + } + else { + qcb->setItemIcon(i, itemIcon); + } + } +} + +void DrawGuiUtil::loadBalloonShapeBox(QComboBox* qballooncb) +{ + qballooncb->clear(); + QPalette qballooncbPal = qballooncb->palette(); + QColor textColor = qballooncbPal.color(QPalette::WindowText); + auto curStyleSheet = + App::GetApplication() + .GetParameterGroupByPath("User parameter:BaseApp/Preferences/MainWindow") + ->GetASCII("StyleSheet", "None"); + + bool darkSS = isStyleSheetDark(curStyleSheet); + + int i = 0; + for (; i < BalloonPropEnum::BalloonCount; i++) { + qballooncb->addItem( + QCoreApplication::translate("BalloonPropEnum", BalloonPropEnum::BalloonTypeEnums[i])); + QIcon itemIcon(QString::fromUtf8(BalloonPropEnum::BalloonTypeIcons[i].c_str())); + if (darkSS) { + QSize iconSize(48, 48); + QIcon itemUpdatedIcon(maskBlackPixels(itemIcon, iconSize, textColor)); + qballooncb->setItemIcon(i, itemUpdatedIcon); + } + else { + qballooncb->setItemIcon(i, itemIcon); + } + } +} + +void DrawGuiUtil::loadMattingStyleBox(QComboBox* qmattingcb) +{ + qmattingcb->clear(); + QPalette qmattingcbPal = qmattingcb->palette(); + QColor textColor = qmattingcbPal.color(QPalette::WindowText); + auto curStyleSheet = + App::GetApplication() + .GetParameterGroupByPath("User parameter:BaseApp/Preferences/MainWindow") + ->GetASCII("StyleSheet", "None"); + + bool darkSS = isStyleSheetDark(curStyleSheet); + + int i = 0; + for (; i < MattingPropEnum::MattingCount; i++) { + qmattingcb->addItem( + QCoreApplication::translate("MattingPropEnum", MattingPropEnum::MattingTypeEnums[i])); + QIcon itemIcon(QString::fromUtf8(MattingPropEnum::MattingTypeIcons[i].c_str())); + if (darkSS) { + QSize iconSize(48, 48); + QIcon itemUpdatedIcon(maskBlackPixels(itemIcon, iconSize, textColor)); + qmattingcb->setItemIcon(i, itemUpdatedIcon); + } + else { + qmattingcb->setItemIcon(i, itemIcon); + } } } @@ -102,16 +180,19 @@ void DrawGuiUtil::loadLineStyleChoices(QComboBox* combo, LineGenerator* generato std::vector choices; if (generator) { choices = generator->getLoadedDescriptions(); - } else { + } + else { choices = LineGenerator::getLineDescriptions(); } + QPalette comboPal = combo->palette(); + QColor textColor = comboPal.color(QPalette::WindowText); - int itemNumber{0}; + int itemNumber {0}; for (auto& entry : choices) { QString qentry = Base::Tools::fromStdString(entry); combo->addItem(qentry); if (generator) { - combo->setItemIcon(itemNumber, iconForLine(itemNumber + 1, generator)); + combo->setItemIcon(itemNumber, iconForLine(itemNumber + 1, generator, textColor)); } itemNumber++; } @@ -119,15 +200,17 @@ void DrawGuiUtil::loadLineStyleChoices(QComboBox* combo, LineGenerator* generato //! make an icon that shows a sample of lineNumber in the current line standard -QIcon DrawGuiUtil::iconForLine(size_t lineNumber, TechDraw::LineGenerator* generator) +QIcon DrawGuiUtil::iconForLine(size_t lineNumber, + TechDraw::LineGenerator* generator, + QColor textColor) { -// Base::Console().Message("DGU::iconForLine(lineNumber: %d)\n", lineNumber); - constexpr int iconSize{64}; - constexpr int borderSize{4}; - constexpr double iconLineWeight{1.0}; - size_t lineCount{4}; + // Base::Console().Message("DGU::iconForLine(lineNumber: %d)\n", lineNumber); + constexpr int iconSize {64}; + constexpr int borderSize {4}; + constexpr double iconLineWeight {1.0}; + size_t lineCount {4}; double maxLineLength = iconSize - borderSize * 2.0; - QBitmap bitmap{iconSize, iconSize}; + QBitmap bitmap {iconSize, iconSize}; bitmap.clear(); QPainter painter(&bitmap); @@ -136,12 +219,27 @@ QIcon DrawGuiUtil::iconForLine(size_t lineNumber, TechDraw::LineGenerator* gener linePen.setCapStyle(Qt::FlatCap); linePen.setColor(Qt::color1); + QSize lineIconSize(iconSize, iconSize); + + auto curStyleSheet = + App::GetApplication() + .GetParameterGroupByPath("User parameter:BaseApp/Preferences/MainWindow") + ->GetASCII("StyleSheet", "None"); + + bool darkSS = isStyleSheetDark(curStyleSheet); + // handle simple case of continuous line if (linePen.style() == Qt::SolidLine) { linePen.setWidthF(iconLineWeight * lineCount); painter.setPen(linePen); painter.drawLine(borderSize, iconSize / 2, iconSize - borderSize, iconSize / 2); - return QIcon{bitmap}; + if (darkSS) { + QIcon lineItemIcon(bitmap); + return QIcon(maskBlackPixels(lineItemIcon, lineIconSize, textColor)); + } + else { + return QIcon(bitmap); + } } // dashed line @@ -151,11 +249,17 @@ QIcon DrawGuiUtil::iconForLine(size_t lineNumber, TechDraw::LineGenerator* gener size_t iLine = 0; // draw multiple lines to stretch the line vertically without horizontal // distortion - for ( ; iLine < lineCount; iLine++){ + for (; iLine < lineCount; iLine++) { painter.drawLine(borderSize, yHeight, maxLineLength, yHeight); yHeight += iconLineWeight; } - return QIcon{bitmap}; + if (darkSS) { + QIcon lineItemIcon(bitmap); + return QIcon(maskBlackPixels(lineItemIcon, lineIconSize, textColor)); + } + else { + return QIcon(bitmap); + } } @@ -163,7 +267,7 @@ QIcon DrawGuiUtil::iconForLine(size_t lineNumber, TechDraw::LineGenerator* gener // validate helper routines //=========================================================================== -//find a page in Selection, Document or CurrentWindow. +// find a page in Selection, Document or CurrentWindow. TechDraw::DrawPage* DrawGuiUtil::findPage(Gui::Command* cmd, bool findAny) { // Base::Console().Message("DGU::findPage()\n"); @@ -172,26 +276,27 @@ TechDraw::DrawPage* DrawGuiUtil::findPage(Gui::Command* cmd, bool findAny) auto docs = App::GetApplication().getDocuments(); if (findAny) { - //find a page in any open document + // find a page in any open document std::vector foundPageObjects; - //no page found in the usual places, but we have been asked to search all - //open documents for a page. + // no page found in the usual places, but we have been asked to search all + // open documents for a page. auto docsAll = App::GetApplication().getDocuments(); for (auto& doc : docsAll) { auto docPages = doc->getObjectsOfType(TechDraw::DrawPage::getClassTypeId()); if (docPages.empty()) { - //this open document has no TD pages + // this open document has no TD pages continue; } foundPageObjects.insert(foundPageObjects.end(), docPages.begin(), docPages.end()); } if (foundPageObjects.empty()) { - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No page found"), + QMessageBox::warning(Gui::getMainWindow(), + QObject::tr("No page found"), QObject::tr("No Drawing Pages available.")); return nullptr; } else if (foundPageObjects.size() > 1) { - //multiple pages available, ask for help + // multiple pages available, ask for help for (auto obj : foundPageObjects) { std::string name = obj->getNameInDocument(); names.push_back(name); @@ -206,25 +311,26 @@ TechDraw::DrawPage* DrawGuiUtil::findPage(Gui::Command* cmd, bool findAny) } } else { - //only 1 page found + // only 1 page found return static_cast(foundPageObjects.front()); } } - //check Selection for a page + // check Selection for a page std::vector selPages = cmd->getSelection().getObjectsOfType(TechDraw::DrawPage::getClassTypeId()); if (selPages.empty()) { - //no page in selection, try this document + // no page in selection, try this document auto docPages = cmd->getDocument()->getObjectsOfType(TechDraw::DrawPage::getClassTypeId()); if (docPages.empty()) { - //we are only to look in this document, and there is no page in this document - QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No page found"), + // we are only to look in this document, and there is no page in this document + QMessageBox::warning(Gui::getMainWindow(), + QObject::tr("No page found"), QObject::tr("No Drawing Pages in document.")); return nullptr; } else if (docPages.size() > 1) { - //multiple pages in document, use active page if there is one + // multiple pages in document, use active page if there is one Gui::MainWindow* w = Gui::getMainWindow(); Gui::MDIView* mv = w->activeWindow(); MDIViewPage* mvp = dynamic_cast(mv); @@ -250,12 +356,12 @@ TechDraw::DrawPage* DrawGuiUtil::findPage(Gui::Command* cmd, bool findAny) } } else { - //only 1 page in document - use it + // only 1 page in document - use it return static_cast(docPages.front()); } } else if (selPages.size() > 1) { - //multiple pages in selection + // multiple pages in selection for (auto obj : selPages) { std::string name = obj->getNameInDocument(); names.push_back(name); @@ -270,11 +376,11 @@ TechDraw::DrawPage* DrawGuiUtil::findPage(Gui::Command* cmd, bool findAny) } } else { - //exactly 1 page in selection, use it + // exactly 1 page in selection, use it return static_cast(selPages.front()); } - //we can not actually reach this point. + // we can not actually reach this point. return nullptr; } @@ -285,8 +391,8 @@ bool DrawGuiUtil::isDraftObject(App::DocumentObject* obj) dynamic_cast(obj->getPropertyByName("Proxy")); if (proxy) { - //if no proxy, can not be Draft obj - //if has proxy, might be Draft obj + // if no proxy, can not be Draft obj + // if has proxy, might be Draft obj std::stringstream ss; Py::Object proxyObj = proxy->getValue(); Base::PyGILStateLocker lock; @@ -303,7 +409,7 @@ bool DrawGuiUtil::isDraftObject(App::DocumentObject* obj) } } catch (Py::Exception&) { - Base::PyException e;// extract the Python error text + Base::PyException e; // extract the Python error text e.ReportException(); result = false; } @@ -318,8 +424,8 @@ bool DrawGuiUtil::isArchObject(App::DocumentObject* obj) dynamic_cast(obj->getPropertyByName("Proxy")); if (proxy) { - //if no proxy, can not be Arch obj - //if has proxy, might be Arch obj + // if no proxy, can not be Arch obj + // if has proxy, might be Arch obj Py::Object proxyObj = proxy->getValue(); std::stringstream ss; Base::PyGILStateLocker lock; @@ -327,14 +433,14 @@ bool DrawGuiUtil::isArchObject(App::DocumentObject* obj) if (proxyObj.hasAttr("__module__")) { Py::String mod(proxyObj.getAttr("__module__")); ss << (std::string)mod; - //does this have to be an ArchSection, or can it be any Arch object? + // does this have to be an ArchSection, or can it be any Arch object? if (ss.str().find("Arch") != std::string::npos) { result = true; } } } catch (Py::Exception&) { - Base::PyException e;// extract the Python error text + Base::PyException e; // extract the Python error text e.ReportException(); result = false; } @@ -349,8 +455,8 @@ bool DrawGuiUtil::isArchSection(App::DocumentObject* obj) dynamic_cast(obj->getPropertyByName("Proxy")); if (proxy) { - //if no proxy, can not be Arch obj - //if has proxy, might be Arch obj + // if no proxy, can not be Arch obj + // if has proxy, might be Arch obj Py::Object proxyObj = proxy->getValue(); std::stringstream ss; Base::PyGILStateLocker lock; @@ -358,14 +464,14 @@ bool DrawGuiUtil::isArchSection(App::DocumentObject* obj) if (proxyObj.hasAttr("__module__")) { Py::String mod(proxyObj.getAttr("__module__")); ss << (std::string)mod; - //does this have to be an ArchSection, or can it be other Arch objects? + // does this have to be an ArchSection, or can it be other Arch objects? if (ss.str().find("ArchSectionPlane") != std::string::npos) { result = true; } } } catch (Py::Exception&) { - Base::PyException e;// extract the Python error text + Base::PyException e; // extract the Python error text e.ReportException(); result = false; } @@ -376,24 +482,24 @@ bool DrawGuiUtil::isArchSection(App::DocumentObject* obj) bool DrawGuiUtil::needPage(Gui::Command* cmd, bool findAny) { if (findAny) { - //look for any page in any open document + // look for any page in any open document auto docsAll = App::GetApplication().getDocuments(); for (auto& doc : docsAll) { auto docPages = doc->getObjectsOfType(TechDraw::DrawPage::getClassTypeId()); if (docPages.empty()) { - //this open document has no TD pages + // this open document has no TD pages continue; } else { - //found at least 1 page + // found at least 1 page return true; } } - //did not find any pages + // did not find any pages return false; } - //need a Document and a Page + // need a Document and a Page if (cmd->hasActiveDocument()) { auto drawPageType(TechDraw::DrawPage::getClassTypeId()); auto selPages = cmd->getDocument()->getObjectsOfType(drawPageType); @@ -431,7 +537,10 @@ void DrawGuiUtil::dumpRectF(const char* text, const QRectF& r) double right = r.right(); double top = r.top(); double bottom = r.bottom(); - Base::Console().Message("Extents: L: %.3f, R: %.3f, T: %.3f, B: %.3f\n", left, right, top, + Base::Console().Message("Extents: L: %.3f, R: %.3f, T: %.3f, B: %.3f\n", + left, + right, + top, bottom); Base::Console().Message("Size: W: %.3f H: %.3f\n", r.width(), r.height()); Base::Console().Message("Centre: (%.3f, %.3f)\n", r.center().x(), r.center().y()); @@ -446,13 +555,13 @@ void DrawGuiUtil::dumpPointF(const char* text, const QPointF& p) std::pair DrawGuiUtil::get3DDirAndRot() { std::pair result; - Base::Vector3d viewDir(0.0, -1.0, 0.0); //default to front - Base::Vector3d viewUp(0.0, 0.0, 1.0); //default to top - Base::Vector3d viewRight(1.0, 0.0, 0.0);//default to right + Base::Vector3d viewDir(0.0, -1.0, 0.0); // default to front + Base::Vector3d viewUp(0.0, 0.0, 1.0); // default to top + Base::Vector3d viewRight(1.0, 0.0, 0.0); // default to right std::list mdis = Gui::Application::Instance->activeDocument()->getMDIViews(); Gui::View3DInventor* view; Gui::View3DInventorViewer* viewer = nullptr; - for (auto& m : mdis) {//find the 3D viewer + for (auto& m : mdis) { // find the 3D viewer view = dynamic_cast(m); if (view) { viewer = view->getViewer(); @@ -478,7 +587,7 @@ std::pair DrawGuiUtil::get3DDirAndRot() double dvecY = roundToDigits(dvec[1], digits); double dvecZ = roundToDigits(dvec[2], digits); viewDir = Base::Vector3d(dvecX, dvecY, dvecZ); - viewDir = viewDir * (-1.0);// Inventor dir is opposite TD projection dir + viewDir = viewDir * (-1.0); // Inventor dir is opposite TD projection dir SbVec3f upvec = viewer->getUpDirection(); double upvecX = roundToDigits(upvec[0], digits); @@ -497,7 +606,7 @@ std::pair DrawGuiUtil::getProjDirFromFace(App::D { std::pair d3Dirs = get3DDirAndRot(); std::pair dirs; - dirs.first = Base::Vector3d(0.0, 0.0, 1.0);//set a default + dirs.first = Base::Vector3d(0.0, 0.0, 1.0); // set a default dirs.second = Base::Vector3d(1.0, 0.0, 0.0); Base::Vector3d projDir, rotVec; projDir = d3Dirs.first; @@ -543,17 +652,17 @@ double DrawGuiUtil::roundToDigits(double original, int digits) } // Returns true if the item or any of its descendants is selected -bool DrawGuiUtil::isSelectedInTree(QGraphicsItem *item) +bool DrawGuiUtil::isSelectedInTree(QGraphicsItem* item) { if (item) { if (item->isSelected()) { return true; } - for (QGraphicsItem *child : item->childItems()) { - if (isSelectedInTree(child)) { - return true; - } + for (QGraphicsItem* child : item->childItems()) { + if (isSelectedInTree(child)) { + return true; + } } } @@ -561,12 +670,12 @@ bool DrawGuiUtil::isSelectedInTree(QGraphicsItem *item) } // Selects or deselects the item and all its descendants -void DrawGuiUtil::setSelectedTree(QGraphicsItem *item, bool selected) +void DrawGuiUtil::setSelectedTree(QGraphicsItem* item, bool selected) { if (item) { item->setSelected(selected); - for (QGraphicsItem *child : item->childItems()) { + for (QGraphicsItem* child : item->childItems()) { setSelectedTree(child, selected); } } @@ -625,3 +734,29 @@ bool DrawGuiUtil::findObjectInSelection(const std::vector& return false; } +bool DrawGuiUtil::isStyleSheetDark(std::string curStyleSheet) +{ + // normalize stylesheet name + auto normalizeCurStyleSheet = [](std::string str) { + std::transform(str.begin(), str.end(), str.begin(), [](unsigned char ch) { + return ch == ' ' ? '_' : std::tolower(ch); + }); + return str; + }; + std::string styleSheetName = normalizeCurStyleSheet(curStyleSheet); + if (styleSheetName.find("dark") != std::string::npos) { + return true; + } + return false; +} + + +QIcon DrawGuiUtil::maskBlackPixels(QIcon itemIcon, QSize iconSize, QColor textColor) +{ + QPixmap originalPix = itemIcon.pixmap(iconSize, QIcon::Mode::Normal, QIcon::State::On); + QPixmap filler(iconSize); + filler.fill(QColor(textColor)); + filler.setMask(originalPix.createMaskFromColor(Qt::black, Qt::MaskOutColor)); + return filler; +} + diff --git a/src/Mod/TechDraw/Gui/DrawGuiUtil.h b/src/Mod/TechDraw/Gui/DrawGuiUtil.h index 35e0a28f5a..8d9b8fc2f5 100644 --- a/src/Mod/TechDraw/Gui/DrawGuiUtil.h +++ b/src/Mod/TechDraw/Gui/DrawGuiUtil.h @@ -71,14 +71,20 @@ class TechDrawGuiExport DrawGuiUtil { static std::pair getProjDirFromFace(App::DocumentObject* obj, std::string faceName); static void loadArrowBox(QComboBox* qcb); + static void loadBalloonShapeBox(QComboBox* qballooncb); + static void loadMattingStyleBox(QComboBox* qmattingcb); static void loadLineStandardsChoices(QComboBox* combo); - static void loadLineStyleChoices(QComboBox* combo, TechDraw::LineGenerator* generator = nullptr); - static QIcon iconForLine(size_t lineNumber, TechDraw::LineGenerator* generator); + static void loadLineStyleChoices(QComboBox* combo, + TechDraw::LineGenerator* generator = nullptr); + static QIcon + iconForLine(size_t lineNumber, TechDraw::LineGenerator* generator, QColor textColor); static double roundToDigits(double original, int digits); - static bool isSelectedInTree(QGraphicsItem *item); - static void setSelectedTree(QGraphicsItem *item, bool selected); + static bool isSelectedInTree(QGraphicsItem* item); + static void setSelectedTree(QGraphicsItem* item, bool selected); + static bool isStyleSheetDark(std::string curStyleSheet); + static QIcon maskBlackPixels(QIcon itemIcon, QSize iconSize, QColor textColor); static Base::Vector3d fromSceneCoords(const Base::Vector3d& sceneCoord, bool invert = true); static Base::Vector3d toSceneCoords(const Base::Vector3d& pageCoord, bool invert = true);