Skip to content

Commit d3844f3

Browse files
committed
ticket:4196 Convert the drawing unit to pixels.
1 parent cf592af commit d3844f3

File tree

4 files changed

+47
-14
lines changed

4 files changed

+47
-14
lines changed

OMEdit/OMEditGUI/Annotations/ShapeAnnotation.cpp

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -473,30 +473,37 @@ QRectF ShapeAnnotation::getBoundingRect() const
473473
}
474474

475475
/*!
476-
Applies the shape line pattern.
477-
\param painter - pointer to QPainter
478-
*/
476+
* \brief ShapeAnnotation::applyLinePattern
477+
* Applies the shape line pattern.
478+
* \param painter - pointer to QPainter
479+
*/
479480
void ShapeAnnotation::applyLinePattern(QPainter *painter)
480481
{
481-
qreal thicknessFactor = mLineThickness / 0.5;
482-
qreal thickness = thicknessFactor < 1 ? 1.0 : thicknessFactor;
482+
qreal thickness = Utilities::convertMMToPixel(mLineThickness);
483483
QPen pen(mLineColor, thickness, StringHandler::getLinePatternType(mLinePattern), Qt::SquareCap, Qt::MiterJoin);
484+
/* The specification doesn't say anything about it.
485+
* But just to keep this consist with Dymola we use Qt::BevelJoin for Line shapes.
486+
* All other shapes use Qt::MiterJoin
487+
*/
488+
if (dynamic_cast<LineAnnotation*>(this)) {
489+
pen.setJoinStyle(Qt::BevelJoin);
490+
}
484491
/* Ticket #3222
485492
* Make all the shapes use cosmetic pens so that they perserve their pen widht when scaled i.e zoomed in/out.
486493
* Only shapes with border patterns raised & sunken don't use cosmetic pens. We need better handling of border patterns.
487494
*/
488495
if (mBorderPattern != StringHandler::BorderRaised && mBorderPattern != StringHandler::BorderSunken) {
489496
pen.setCosmetic(true);
490497
}
491-
if (mpGraphicsView && mpGraphicsView->isRenderingLibraryPixmap()) {
492-
/* Ticket #2272, Ticket #2268.
493-
* If thickness is greater than 2 then don't make the pen cosmetic since cosmetic pens don't change the width with respect to zoom.
494-
*/
495-
if (thickness <= 2) {
496-
pen.setCosmetic(true);
497-
} else {
498-
pen.setCosmetic(false);
499-
}
498+
/* Ticket #2272, Ticket #2268.
499+
* If thickness is greater than 2 then don't make the pen cosmetic since cosmetic pens don't change the width with respect to zoom.
500+
*/
501+
if (mpGraphicsView && mpGraphicsView->isRenderingLibraryPixmap() && thickness > 2) {
502+
pen.setCosmetic(false);
503+
}
504+
// if thickness is greater than 1 pixel then use antialiasing.
505+
if (thickness > 1) {
506+
painter->setRenderHint(QPainter::Antialiasing);
500507
}
501508
painter->setPen(pen);
502509
}

OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,6 +1209,17 @@ void GraphicsView::addConnection(Component *pComponent)
12091209
mpConnectionLineAnnotation->addPoint(startPos);
12101210
mpConnectionLineAnnotation->addPoint(startPos);
12111211
mpConnectionLineAnnotation->addPoint(startPos);
1212+
/* Ticket:4196
1213+
* If we are starting connection from expandable connector or array connector
1214+
* then set the line thickness to 0.5
1215+
*/
1216+
if ((pComponent->getLibraryTreeItem() && pComponent->getLibraryTreeItem()->getRestriction() == StringHandler::ExpandableConnector) ||
1217+
(pComponent->getParentComponent() && pComponent->getRootParentComponent()->getComponentInfo()->isArray()) ||
1218+
(!pComponent->getParentComponent() && pComponent->getRootParentComponent()->getLibraryTreeItem() && pComponent->getRootParentComponent()->getLibraryTreeItem()->getRestriction() == StringHandler::ExpandableConnector) ||
1219+
(pComponent->getParentComponent() && pComponent->getLibraryTreeItem() && pComponent->getLibraryTreeItem()->getRestriction() == StringHandler::ExpandableConnector) ||
1220+
(pComponent->getComponentInfo() && pComponent->getComponentInfo()->isArray())) {
1221+
mpConnectionLineAnnotation->setLineThickness(0.5);
1222+
}
12121223
} else if (isCreatingConnection()) { // When clicking the end component
12131224
mpConnectionLineAnnotation->setEndComponent(pComponent);
12141225
// update the last point to the center of component

OMEdit/OMEditGUI/Util/Utilities.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "Modeling/LibraryTreeWidget.h"
3939

4040
#include <QApplication>
41+
#include <QDesktopWidget>
4142
#include <QGridLayout>
4243
#include <QStylePainter>
4344
#include <QPainter>
@@ -886,3 +887,16 @@ bool Utilities::containsWord(QString text, int index, QString keyword, bool chec
886887
}
887888
return false;
888889
}
890+
891+
/*!
892+
* \brief Utilities::convertMMToPixel
893+
* Converts the value from mm to pixels
894+
* pixel = (dpi * mm / 1 inch)
895+
* 1 inch is 25.4
896+
* \param value
897+
* \return
898+
*/
899+
qreal Utilities::convertMMToPixel(qreal value)
900+
{
901+
return (QApplication::desktop()->screen()->logicalDpiX() * value) / 25.4;
902+
}

OMEdit/OMEditGUI/Util/Utilities.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,7 @@ namespace Utilities {
470470
} // namespace FileIconProvider
471471

472472
bool containsWord(QString text, int index, QString keyword, bool checkParenthesis = false);
473+
qreal convertMMToPixel(qreal value);
473474

474475
} // namespace Utilities
475476

0 commit comments

Comments
 (0)