[TechDraw] Improve visibility of TD preference icons in combo boxes...

...when using dark style sheets.
This commit is contained in:
Syres916
2024-05-02 19:05:33 +01:00
committed by WandererFan
parent 06f79b5ebd
commit f8cb31ba0e
10 changed files with 451 additions and 177 deletions

View File

@@ -0,0 +1,51 @@
/***************************************************************************
* Copyright (c) 2020 WandererFan <wandererfan@gmail.com> *
* *
* 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<std::string> 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"};
}

View File

@@ -0,0 +1,58 @@
/***************************************************************************
* Copyright (c) 2020 WandererFan <wandererfan@gmail.com> *
* *
* 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 <string>
#include <vector>
#include <QCoreApplication>
#include <Mod/TechDraw/TechDrawGlobal.h>
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<std::string> BalloonTypeIcons;
private:
};
} //end namespace TechDraw
#endif

View File

@@ -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

View File

@@ -0,0 +1,39 @@
/***************************************************************************
* Copyright (c) 2020 WandererFan <wandererfan@gmail.com> *
* *
* 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<std::string> MattingPropEnum::MattingTypeIcons = { ":icons/circular.svg",
":icons/square.svg"};
}

View File

@@ -0,0 +1,49 @@
/***************************************************************************
* Copyright (c) 2020 WandererFan <wandererfan@gmail.com> *
* *
* 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 <string>
#include <vector>
#include <QCoreApplication>
#include <Mod/TechDraw/TechDrawGlobal.h>
namespace TechDraw
{
class TechDrawExport MattingPropEnum {
Q_DECLARE_TR_FUNCTIONS(TechDraw::MattingPropEnum)
public:
static const char* MattingTypeEnums[];
static const int MattingCount;
static const std::vector<std::string> MattingTypeIcons;
private:
};
} //end namespace TechDraw
#endif

View File

@@ -457,24 +457,6 @@
<property name="prefPath" stdset="0">
<cstring>/Mod/TechDraw/Decorations</cstring>
</property>
<item>
<property name="text">
<string>Circle</string>
</property>
<property name="icon">
<iconset resource="Resources/TechDraw.qrc">
<normaloff>:/icons/circular.svg</normaloff>:/icons/circular.svg</iconset>
</property>
</item>
<item>
<property name="text">
<string>Square</string>
</property>
<property name="icon">
<iconset resource="Resources/TechDraw.qrc">
<normaloff>:/icons/square.svg</normaloff>:/icons/square.svg</iconset>
</property>
</item>
</widget>
</item>
<item row="7" column="2">
@@ -500,78 +482,6 @@
<property name="prefPath" stdset="0">
<cstring>Mod/TechDraw/Decorations</cstring>
</property>
<item>
<property name="text">
<string>Circular</string>
</property>
<property name="icon">
<iconset resource="Resources/TechDraw.qrc">
<normaloff>:/icons/circular.svg</normaloff>:/icons/circular.svg</iconset>
</property>
</item>
<item>
<property name="text">
<string>None</string>
</property>
<property name="icon">
<iconset resource="Resources/TechDraw.qrc">
<normaloff>:/icons/none.svg</normaloff>:/icons/none.svg</iconset>
</property>
</item>
<item>
<property name="text">
<string>Triangle</string>
</property>
<property name="icon">
<iconset resource="Resources/TechDraw.qrc">
<normaloff>:/icons/triangle.svg</normaloff>:/icons/triangle.svg</iconset>
</property>
</item>
<item>
<property name="text">
<string>Inspection</string>
</property>
<property name="icon">
<iconset resource="Resources/TechDraw.qrc">
<normaloff>:/icons/inspection.svg</normaloff>:/icons/inspection.svg</iconset>
</property>
</item>
<item>
<property name="text">
<string>Hexagon</string>
</property>
<property name="icon">
<iconset resource="Resources/TechDraw.qrc">
<normaloff>:/icons/hexagon.svg</normaloff>:/icons/hexagon.svg</iconset>
</property>
</item>
<item>
<property name="text">
<string>Square</string>
</property>
<property name="icon">
<iconset resource="Resources/TechDraw.qrc">
<normaloff>:/icons/square.svg</normaloff>:/icons/square.svg</iconset>
</property>
</item>
<item>
<property name="text">
<string>Rectangle</string>
</property>
<property name="icon">
<iconset resource="Resources/TechDraw.qrc">
<normaloff>:/icons/rectangle.svg</normaloff>:/icons/rectangle.svg</iconset>
</property>
</item>
<item>
<property name="text">
<string>Line</string>
</property>
<property name="icon">
<iconset resource="Resources/TechDraw.qrc">
<normaloff>:/icons/bottomline.svg</normaloff>:/icons/bottomline.svg</iconset>
</property>
</item>
</widget>
</item>
<item row="9" column="0">

View File

@@ -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<int>(&QComboBox::currentIndexChanged),
this, &DlgPrefsTechDrawAnnotationImp::onLineGroupChanged);
connect(ui->pcbLineGroup,
qOverload<int>(&QComboBox::currentIndexChanged),
this,
&DlgPrefsTechDrawAnnotationImp::onLineGroupChanged);
// NOTE that we block onChanged processing while loading the Line Standard combobox
connect(ui->pcbLineStandard, qOverload<int>(&QComboBox::currentIndexChanged),
this, &DlgPrefsTechDrawAnnotationImp::onLineStandardChanged);
connect(ui->pcbLineStandard,
qOverload<int>(&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
*/

View File

@@ -54,6 +54,8 @@ protected:
void changeEvent(QEvent *e) override;
int prefBalloonArrow() const;
int prefBalloonShape() const;
int prefMattingStyle() const;
void loadLineStyleBoxes();
private:

View File

@@ -25,12 +25,15 @@
#ifndef _PreComp_
# include <sstream>
# include <QBitmap>
# include <QComboBox>
# include <QMessageBox>
# include <QPointF>
# include <QRectF>
# include <QString>
#include <QBitmap>
#include <QColor>
#include <QComboBox>
#include <QMessageBox>
#include <QPalette>
#include <QPixmap>
#include <QPointF>
#include <QRectF>
#include <QString>
# include <BRepAdaptor_Surface.hxx>
# include <BRepLProp_SLProps.hxx>
@@ -58,7 +61,9 @@
#include <Inventor/SbVec3f.h>
#include <Mod/TechDraw/App/ArrowPropEnum.h>
#include <Mod/TechDraw/App/BalloonPropEnum.h>
#include <Mod/TechDraw/App/LineNameEnum.h>
#include <Mod/TechDraw/App/MattingPropEnum.h>
#include <Mod/TechDraw/App/DrawPage.h>
#include <Mod/TechDraw/App/DrawUtil.h>
#include <Mod/TechDraw/App/DrawViewPart.h>
@@ -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<std::string> 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<App::DocumentObject*> 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<TechDraw::DrawPage*>(foundPageObjects.front());
}
}
//check Selection for a page
// check Selection for a page
std::vector<App::DocumentObject*> 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<MDIViewPage*>(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<TechDraw::DrawPage*>(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<TechDraw::DrawPage*>(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<App::PropertyPythonObject*>(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<App::PropertyPythonObject*>(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<App::PropertyPythonObject*>(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<Base::Vector3d, Base::Vector3d> DrawGuiUtil::get3DDirAndRot()
{
std::pair<Base::Vector3d, Base::Vector3d> 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<Gui::MDIView*> 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<Gui::View3DInventor*>(m);
if (view) {
viewer = view->getViewer();
@@ -478,7 +587,7 @@ std::pair<Base::Vector3d, Base::Vector3d> 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<Base::Vector3d, Base::Vector3d> DrawGuiUtil::getProjDirFromFace(App::D
{
std::pair<Base::Vector3d, Base::Vector3d> d3Dirs = get3DDirAndRot();
std::pair<Base::Vector3d, Base::Vector3d> 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<Gui::SelectionObject>&
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;
}

View File

@@ -71,14 +71,20 @@ class TechDrawGuiExport DrawGuiUtil {
static std::pair<Base::Vector3d, Base::Vector3d> 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);