diff --git a/src/Mod/TechDraw/App/Cosmetic.h b/src/Mod/TechDraw/App/Cosmetic.h index dfaab332e2..efd6c1e8da 100644 --- a/src/Mod/TechDraw/App/Cosmetic.h +++ b/src/Mod/TechDraw/App/Cosmetic.h @@ -23,7 +23,10 @@ #ifndef TECHDRAW_COSMETIC_H #define TECHDRAW_COSMETIC_H +#include + #include +#include #include #include @@ -49,6 +52,16 @@ public: const bool visible); ~LineFormat() = default; + int getStyle() const { return m_style; } + void setStyle(int style) { m_style = style; } + double getWidth() const { return m_weight; } + void setWidth(double width) {m_weight = width; } + App::Color getColor() const { return m_color; } + void setColor(App::Color color) { m_color = color; } + QColor getQColor() const { return m_color.asValue(); } + void setQColor(QColor qColor) { m_color.set(qColor.redF(), qColor.greenF(), qColor.blueF(), 1.0 - qColor.alphaF()); } + bool getVisible() const { return m_visible; } + void setVisible(bool viz) { m_visible = viz; } int getLineNumber() const { return m_lineNumber; } void setLineNumber(int number) { m_lineNumber = number; } diff --git a/src/Mod/TechDraw/App/LineGenerator.cpp b/src/Mod/TechDraw/App/LineGenerator.cpp index 398eb28d2e..21952ffd55 100644 --- a/src/Mod/TechDraw/App/LineGenerator.cpp +++ b/src/Mod/TechDraw/App/LineGenerator.cpp @@ -113,12 +113,6 @@ QPen LineGenerator::getLinePen(size_t lineNumber, double nominalLineWidth) proportionalAdjust = nominalLineWidth; } - // Note: if the cap style is Round or Square, the lengths of the lines, or - // dots/dashes within the line, will be wrong by 1 pen width. To get the - // exact line lengths or dash pattern, you must use Flat caps. Flat caps - // look terrible at the corners. - linePen.setCapStyle((Qt::PenCapStyle)Preferences::LineCapStyle()); - // valid line numbers are [1, number of line definitions] // line 1 is always (?) continuous // 0 substitutes for LineFormat::InvalidLine here diff --git a/src/Mod/TechDraw/Gui/CommandExtensionDims.cpp b/src/Mod/TechDraw/Gui/CommandExtensionDims.cpp index f35ddf58fc..40cb9569b7 100644 --- a/src/Mod/TechDraw/Gui/CommandExtensionDims.cpp +++ b/src/Mod/TechDraw/Gui/CommandExtensionDims.cpp @@ -1361,6 +1361,7 @@ void execCreateObliqueChainDimension(Gui::Command* cmd) { std::string edgeTag = objFeat->addCosmeticEdge(oldVertex.point / scale, nextPoint / scale); auto edge = objFeat->getCosmeticEdge(edgeTag); edge->m_format.m_style = 1; + edge->m_format.m_lineNumber = 1; edge->m_format.m_weight = 0.15; edge->m_format.m_color = App::Color(0.0f, 0.0f, 0.0f); } @@ -1716,6 +1717,7 @@ void execCreateObliqueCoordDimension(Gui::Command* cmd) { std::string edgeTag = objFeat->addCosmeticEdge(oldVertex.point / scale, nextPoint / scale); auto edge = objFeat->getCosmeticEdge(edgeTag); edge->m_format.m_style = 1; + edge->m_format.m_lineNumber = 1; edge->m_format.m_weight = 0.15; edge->m_format.m_color = App::Color(0.0f, 0.0f, 0.0f); } diff --git a/src/Mod/TechDraw/Gui/CommandExtensionPack.cpp b/src/Mod/TechDraw/Gui/CommandExtensionPack.cpp index 01c06822dd..10af1a1998 100644 --- a/src/Mod/TechDraw/Gui/CommandExtensionPack.cpp +++ b/src/Mod/TechDraw/Gui/CommandExtensionPack.cpp @@ -74,10 +74,10 @@ using DU = DrawUtil; namespace TechDrawGui { -//LineAttributes activeAttributes; // container holding global line attributes +//TechDraw::LineFormat activeAttributes; // container holding global line attributes //internal helper functions -lineAttributes& _getActiveLineAttributes(); +TechDraw::LineFormat& _getActiveLineAttributes(); Base::Vector3d _circleCenter(Base::Vector3d p1, Base::Vector3d p2, Base::Vector3d p3); void _createThreadCircle(std::string Name, TechDraw::DrawViewPart* objFeat, float factor); void _createThreadLines(std::vector SubNames, TechDraw::DrawViewPart* objFeat, @@ -1488,7 +1488,7 @@ void execExtendShortenLine(Gui::Command* cmd, bool extend) toDelete.push_back(uniTag); if (baseGeo->source() == 1) { auto cosEdge = objFeat->getCosmeticEdge(uniTag); - oldStyle = cosEdge->m_format.m_style; + oldStyle = cosEdge->m_format.m_lineNumber; oldWeight = cosEdge->m_format.m_weight; oldColor = cosEdge->m_format.m_color; objFeat->removeCosmeticEdge(toDelete); @@ -1974,9 +1974,9 @@ bool CmdTechDrawExtensionArcLengthAnnotation::isActive() namespace TechDrawGui { -lineAttributes& _getActiveLineAttributes() +LineFormat& _getActiveLineAttributes() { - static lineAttributes attributes; + static TechDraw::LineFormat attributes; return attributes; } @@ -2133,19 +2133,19 @@ void _createThreadLines(std::vector SubNames, TechDraw::DrawViewPar void _setLineAttributes(TechDraw::CosmeticEdge* cosEdge) { // set line attributes of a cosmetic edge - cosEdge->m_format.m_style = _getActiveLineAttributes().getStyle(); - cosEdge->m_format.m_weight = _getActiveLineAttributes().getWidthValue(); - cosEdge->m_format.m_color = _getActiveLineAttributes().getColorValue(); - cosEdge->m_format.m_lineNumber = _getActiveLineAttributes().getStyle(); + cosEdge->m_format.setStyle(_getActiveLineAttributes().getStyle()); + cosEdge->m_format.setWidth(_getActiveLineAttributes().getWidth()); + cosEdge->m_format.setColor(_getActiveLineAttributes().getColor()); + cosEdge->m_format.setLineNumber(_getActiveLineAttributes().getLineNumber()); } void _setLineAttributes(TechDraw::CenterLine* cosEdge) { // set line attributes of a cosmetic edge cosEdge->m_format.m_style = _getActiveLineAttributes().getStyle(); - cosEdge->m_format.m_weight = _getActiveLineAttributes().getWidthValue(); - cosEdge->m_format.m_color = _getActiveLineAttributes().getColorValue(); - cosEdge->m_format.m_lineNumber = _getActiveLineAttributes().getStyle(); + cosEdge->m_format.m_weight = _getActiveLineAttributes().getWidth(); + cosEdge->m_format.m_color = _getActiveLineAttributes().getColor(); + cosEdge->m_format.setLineNumber(_getActiveLineAttributes().getLineNumber()); } void _setLineAttributes(TechDraw::CosmeticEdge* cosEdge, int style, float weight, App::Color color) @@ -2154,16 +2154,16 @@ void _setLineAttributes(TechDraw::CosmeticEdge* cosEdge, int style, float weight cosEdge->m_format.m_style = _getActiveLineAttributes().getStyle(); cosEdge->m_format.m_weight = weight; cosEdge->m_format.m_color = color; - cosEdge->m_format.m_lineNumber = style; + cosEdge->m_format.setLineNumber(style); } void _setLineAttributes(TechDraw::CenterLine* cosEdge, int style, float weight, App::Color color) { // set line attributes of a centerline cosEdge->m_format.m_style = _getActiveLineAttributes().getStyle(); - cosEdge->m_format.m_lineNumber = style; cosEdge->m_format.m_weight = weight; cosEdge->m_format.m_color = color; + cosEdge->m_format.setLineNumber(style); } }// namespace TechDrawGui diff --git a/src/Mod/TechDraw/Gui/TaskSelectLineAttributes.cpp b/src/Mod/TechDraw/Gui/TaskSelectLineAttributes.cpp index 043b67e80c..0375cc23cf 100644 --- a/src/Mod/TechDraw/Gui/TaskSelectLineAttributes.cpp +++ b/src/Mod/TechDraw/Gui/TaskSelectLineAttributes.cpp @@ -25,6 +25,7 @@ #include #include +#include #include "ui_TaskSelectLineAttributes.h" #include "TaskSelectLineAttributes.h" @@ -34,13 +35,6 @@ using namespace Gui; using namespace TechDraw; using namespace TechDrawGui; -//enum class EdgeStyle { -// solid = 1, -// dashed = 2, -// dotted = 3, -// dashdotted = 4 -//}; - enum class EdgeWidth { small = 1, middle = 2, @@ -62,65 +56,6 @@ enum class EdgeColor { // managing global line attributes //=========================================================================== -lineAttributes::lineAttributes() -{ - style = 2; - width = int(EdgeWidth::middle); - color = int(EdgeColor::black); -} - -void lineAttributes::setStyle(int newStyle) -{ - style = newStyle; -} - -void lineAttributes::setWidth(int newWidth) -{ - width = newWidth; -} - -float lineAttributes::getWidthValue() -{ - switch(EdgeWidth(width)) { - case EdgeWidth::small: - return 0.18f; - case EdgeWidth::middle: - return 0.35f; - case EdgeWidth::thick: - return 0.5f; - default: - return 0.35f; - } -} - -void lineAttributes::setColor(int newColor) -{ - color = newColor; -} - -App::Color lineAttributes::getColorValue() -{ - switch (EdgeColor(color)) { - case EdgeColor::black: - return App::Color(0.0f, 0.0f, 0.0f); - case EdgeColor::grey: - return App::Color(0.7f, 0.7f, 0.7f); - case EdgeColor::red: - return App::Color(1.0f, 0.0f, 0.0f); - case EdgeColor::green: - return App::Color(0.0f, 1.0f, 0.0f); - case EdgeColor::blue: - return App::Color(0.0f, 0.0f, 1.0f); - case EdgeColor::magenta: - return App::Color(1.0f, 0.0f, 1.0f); - case EdgeColor::cyan: - return App::Color(0.0f, 1.0f, 1.0f); - case EdgeColor::yellow: - return App::Color(1.0f, 1.0f, 0.0f); - default: - return App::Color(0.0f, 0.0f, 0.0f); - } -} //=========================================================================== // managing global dimension attributes @@ -148,7 +83,7 @@ dimAttributes activeDimAttributes; // container holding dimension attributes // TaskSelectLineAttributes //=========================================================================== -TaskSelectLineAttributes::TaskSelectLineAttributes(lineAttributes * ptActiveAttributes) : +TaskSelectLineAttributes::TaskSelectLineAttributes(LineFormat *ptActiveAttributes) : activeAttributes(ptActiveAttributes), ui(new Ui_TaskSelectLineAttributes) { @@ -189,50 +124,24 @@ void TaskSelectLineAttributes::setUiEdit() ui->cbLineStyle->setCurrentIndex(lineStyle - 1); } - int lineWidth = activeAttributes->getWidth(); - switch(EdgeWidth(lineWidth)) { - case EdgeWidth::small: - ui->rbThin->setChecked(true); - break; - case EdgeWidth::middle: - ui->rbMiddle->setChecked(true); - break; - case EdgeWidth::thick: - ui->rbThick->setChecked(true); - break; - default: - ui->rbMiddle->setChecked(true); + // TODO: how to handle translation of a string with arg parameters in it? + ui->rbThin->setText(QString::fromUtf8("Thin %1").arg(QString::number(TechDraw::LineGroup::getDefaultWidth("Thin")))); + ui->rbMiddle->setText(QString::fromUtf8("Middle %1").arg(QString::number(TechDraw::LineGroup::getDefaultWidth("Graphic")))); + ui->rbThick->setText(QString::fromUtf8("Thick %1").arg(QString::number(TechDraw::LineGroup::getDefaultWidth("Thick")))); + + double lineWidth = activeAttributes->getWidth(); + if (lineWidth <= TechDraw::LineGroup::getDefaultWidth("Thin")) { + ui->rbThin->setChecked(true); + } else if (lineWidth <= TechDraw::LineGroup::getDefaultWidth("Graphic")) { + ui->rbMiddle->setChecked(true); + } else if (lineWidth <= TechDraw::LineGroup::getDefaultWidth("Thick")) { + ui->rbThick->setChecked(true); + } else { + ui->rbMiddle->setChecked(true); } - int lineColor = activeAttributes->getColor(); - switch(EdgeColor(lineColor)) { - case EdgeColor::black: - ui->rbBlack->setChecked(true); - break; - case EdgeColor::grey: - ui->rbGrey->setChecked(true); - break; - case EdgeColor::red: - ui->rbRed->setChecked(true); - break; - case EdgeColor::green: - ui->rbGreen->setChecked(true); - break; - case EdgeColor::blue: - ui->rbBlue->setChecked(true); - break; - case EdgeColor::magenta: - ui->rbMagenta->setChecked(true); - break; - case EdgeColor::cyan: - ui->rbCyan->setChecked(true); - break; - case EdgeColor::yellow: - ui->rbYellow->setChecked(true); - break; - default: - ui->rbBlack->setChecked(true); - } + QColor lineColor = activeAttributes->getQColor(); + ui->cbColor->setColor(lineColor); double cascadeSpacing = activeDimAttributes.getCascadeSpacing(); ui->sbSpacing->setValue(cascadeSpacing); @@ -244,47 +153,25 @@ void TaskSelectLineAttributes::setUiEdit() bool TaskSelectLineAttributes::accept() { activeAttributes->setStyle(ui->cbLineStyle->currentIndex() + 1); + activeAttributes->setLineNumber(ui->cbLineStyle->currentIndex() + 1); if (ui->rbThin->isChecked()){ - activeAttributes->setWidth(int(EdgeWidth::small)); + activeAttributes->setWidth(TechDraw::LineGroup::getDefaultWidth("Thin")); } else if (ui->rbMiddle->isChecked()){ - activeAttributes->setWidth(int(EdgeWidth::middle)); + activeAttributes->setWidth(TechDraw::LineGroup::getDefaultWidth("Graphic")); } else if (ui->rbThick->isChecked()){ - activeAttributes->setWidth(int(EdgeWidth::thick)); + activeAttributes->setWidth(TechDraw::LineGroup::getDefaultWidth("Thick")); } else { - activeAttributes->setWidth(int(EdgeWidth::middle)); + activeAttributes->setWidth(TechDraw::LineGroup::getDefaultWidth("Graphic")); } - if (ui->rbBlack->isChecked()){ - activeAttributes->setColor(int(EdgeColor::black)); - } - else if (ui->rbGrey->isChecked()){ - activeAttributes->setColor(int(EdgeColor::grey)); - } - else if (ui->rbRed->isChecked()){ - activeAttributes->setColor(int(EdgeColor::red)); - } - else if (ui->rbGreen->isChecked()){ - activeAttributes->setColor(int(EdgeColor::green)); - } - else if (ui->rbBlue->isChecked()){ - activeAttributes->setColor(int(EdgeColor::blue)); - } - else if (ui->rbMagenta->isChecked()){ - activeAttributes->setColor(int(EdgeColor::magenta)); - } - else if (ui->rbCyan->isChecked()){ - activeAttributes->setColor(int(EdgeColor::cyan)); - } - else if (ui->rbYellow->isChecked()){ - activeAttributes->setColor(int(EdgeColor::yellow)); - } - else { - activeAttributes->setColor(int(EdgeColor::black)); - } + QColor qTemp = ui->cbColor->color(); + App::Color temp; + temp.set(qTemp.redF(), qTemp.greenF(), qTemp.blueF(), 1.0 - qTemp.alphaF()); + activeAttributes->setColor(temp); double cascadeSpacing = ui->sbSpacing->value(); activeDimAttributes.setCascadeSpacing(cascadeSpacing); @@ -303,7 +190,7 @@ bool TaskSelectLineAttributes::reject() // TaskDlgSelectLineAttributes //=========================================================================== -TaskDlgSelectLineAttributes::TaskDlgSelectLineAttributes(lineAttributes * ptActiveAttributes) +TaskDlgSelectLineAttributes::TaskDlgSelectLineAttributes(LineFormat *ptActiveAttributes) : TaskDialog() { widget = new TaskSelectLineAttributes(ptActiveAttributes); diff --git a/src/Mod/TechDraw/Gui/TaskSelectLineAttributes.h b/src/Mod/TechDraw/Gui/TaskSelectLineAttributes.h index 161a0891ff..41744297fd 100644 --- a/src/Mod/TechDraw/Gui/TaskSelectLineAttributes.h +++ b/src/Mod/TechDraw/Gui/TaskSelectLineAttributes.h @@ -26,6 +26,7 @@ #include #include #include +#include class dimAttributes { @@ -69,31 +70,31 @@ class MDIViewPage; class ViewProviderViewPart; class Ui_TaskSelectLineAttributes; -class lineAttributes { - int style; - int width; - int color; +// class lineAttributes { +// int style; +// int width; +// int color; -public: +// public: - lineAttributes(); - void setStyle(int); - int getStyle() const {return style;} - void setWidth(int); - int getWidth() const {return width;} - float getWidthValue(); - void setColor(int); - int getColor() const {return color;} - App::Color getColorValue(); +// lineAttributes(); +// void setStyle(int); +// int getStyle() const {return style;} +// void setWidth(int); +// int getWidth() const {return width;} +// float getWidthValue(); +// void setColor(int); +// int getColor() const {return color;} +// App::Color getColorValue(); -}; // class lineAttributes +// }; // class lineAttributes class TaskSelectLineAttributes : public QWidget { Q_OBJECT public: - explicit TaskSelectLineAttributes(lineAttributes * ptActiveAttributes); + explicit TaskSelectLineAttributes(TechDraw::LineFormat* ptActiveAttributes); ~TaskSelectLineAttributes() override; virtual bool accept(); @@ -106,7 +107,8 @@ protected: void setUiEdit(); private: - lineAttributes* activeAttributes; + // lineAttributes* activeAttributes; + TechDraw::LineFormat* activeAttributes; std::unique_ptr ui; TechDraw::LineGenerator* m_lineGenerator; @@ -117,7 +119,7 @@ class TaskDlgSelectLineAttributes : public Gui::TaskView::TaskDialog Q_OBJECT public: - explicit TaskDlgSelectLineAttributes(lineAttributes * ptActiveAttributes); + explicit TaskDlgSelectLineAttributes(TechDraw::LineFormat * ptActiveAttributes); ~TaskDlgSelectLineAttributes() override; public: diff --git a/src/Mod/TechDraw/Gui/TaskSelectLineAttributes.ui b/src/Mod/TechDraw/Gui/TaskSelectLineAttributes.ui index 9e30a0574f..57eef4ca3e 100644 --- a/src/Mod/TechDraw/Gui/TaskSelectLineAttributes.ui +++ b/src/Mod/TechDraw/Gui/TaskSelectLineAttributes.ui @@ -6,8 +6,8 @@ 0 0 - 332 - 401 + 424 + 308 @@ -95,6 +95,9 @@ + + + @@ -102,113 +105,6 @@ - - - - Black - - - true - - - true - - - bgLineColor - - - - - - - Blue - - - true - - - bgLineColor - - - - - - - Grey - - - true - - - bgLineColor - - - - - - - Magenta - - - true - - - bgLineColor - - - - - - - Red - - - true - - - bgLineColor - - - - - - - Cyan - - - true - - - bgLineColor - - - - - - - Green - - - true - - - bgLineColor - - - - - - - Yellow - - - true - - - bgLineColor - - - @@ -267,6 +163,18 @@ + + + Gui::ColorButton + QPushButton +
Gui/Widgets.h
+
+ + Gui::PrefColorButton + Gui::ColorButton +
Gui/PrefWidgets.h
+
+