From: vsv Date: Thu, 5 Sep 2019 11:01:59 +0000 (+0300) Subject: Issue #3009: Adapt the application to HD screen X-Git-Tag: VEDF2019Lot4~4 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=7c3fffdb58f97da7c236a71697f8d82e4230eeeb;p=modules%2Fshaper.git Issue #3009: Adapt the application to HD screen --- diff --git a/src/ModuleBase/ModuleBase_Tools.cpp b/src/ModuleBase/ModuleBase_Tools.cpp index ca1d2950b..a3c4d0ebd 100644 --- a/src/ModuleBase/ModuleBase_Tools.cpp +++ b/src/ModuleBase/ModuleBase_Tools.cpp @@ -82,6 +82,8 @@ #include #include #include +#include +#include #include #include @@ -1319,6 +1321,14 @@ bool isSameShape(const TopoDS_Shape& theShape1, const TopoDS_Shape& theShape2) return true; } +qreal currentPixelRatio() +{ + QWindowList aWnds = qApp->topLevelWindows(); + if (aWnds.size() > 0) + return aWnds.first()->devicePixelRatio(); + return qApp->primaryScreen()->devicePixelRatio(); +} + } // namespace ModuleBase_Tools diff --git a/src/ModuleBase/ModuleBase_Tools.h b/src/ModuleBase/ModuleBase_Tools.h index d6e4c4c55..2d1ad9227 100644 --- a/src/ModuleBase/ModuleBase_Tools.h +++ b/src/ModuleBase/ModuleBase_Tools.h @@ -404,6 +404,8 @@ bool MODULEBASE_EXPORT isSameShape(const TopoDS_Shape& theShape1, const TopoDS_S std::string MODULEBASE_EXPORT generateName(const AttributePtr& theAttribute, ModuleBase_IWorkshop* theWorkshop); +/// Returns pixel ratio of a screen where main window is displayed +qreal MODULEBASE_EXPORT currentPixelRatio(); } #endif diff --git a/src/PartSet/PartSet_SketcherMgr.cpp b/src/PartSet/PartSet_SketcherMgr.cpp index f76e254c6..e936d729b 100644 --- a/src/PartSet/PartSet_SketcherMgr.cpp +++ b/src/PartSet/PartSet_SketcherMgr.cpp @@ -961,6 +961,8 @@ void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation) if (!aFOperation) return; + SketcherPrs_Tools::setPixelRatio(ModuleBase_Tools::currentPixelRatio()); + myModule->onViewTransformed(); // Display all sketcher sub-Objects diff --git a/src/SketcherPrs/SketcherPrs_Coincident.cpp b/src/SketcherPrs/SketcherPrs_Coincident.cpp index 9397f212a..d6029af48 100644 --- a/src/SketcherPrs/SketcherPrs_Coincident.cpp +++ b/src/SketcherPrs/SketcherPrs_Coincident.cpp @@ -140,12 +140,14 @@ void SketcherPrs_Coincident::Compute( Quantity_Color aExternalColor = aIsEdge ? Quantity_NOC_BLACK : Quantity_NOC_YELLOW; Quantity_Color aInternalColor = aIsEdge ? Quantity_NOC_YELLOW : Quantity_NOC_BLACK; + int aRatio = SketcherPrs_Tools::pixelRatio(); + // Create the presentation as a combination of standard point markers bool aCustomColor = myIsCustomColor; // The external yellow contour Handle(Graphic3d_AspectMarker3d) aPtA = new Graphic3d_AspectMarker3d(); aPtA->SetType(Aspect_TOM_RING3); - aPtA->SetScale(2.); + aPtA->SetScale(2. * aRatio); aPtA->SetColor(!aCustomColor ? aExternalColor : myCustomColor); Handle(Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup(thePresentation); @@ -157,7 +159,7 @@ void SketcherPrs_Coincident::Compute( // Make a black mid ring aPtA = new Graphic3d_AspectMarker3d(); aPtA->SetType(aIsEdge ? Aspect_TOM_STAR : Aspect_TOM_RING1); - aPtA->SetScale(1.); + aPtA->SetScale(1. * aRatio); aPtA->SetColor(!aCustomColor ? aInternalColor : myCustomColor); aGroup->SetPrimitivesAspect(aPtA); aGroup->AddPrimitiveArray (aPntArray); @@ -165,7 +167,7 @@ void SketcherPrs_Coincident::Compute( // Make an internal ring aPtA = new Graphic3d_AspectMarker3d(); aPtA->SetType(Aspect_TOM_POINT); - aPtA->SetScale(5.); + aPtA->SetScale(5. * aRatio); aPtA->SetColor(!aCustomColor ? aInternalColor : myCustomColor); aGroup->SetPrimitivesAspect(aPtA); aGroup->AddPrimitiveArray (aPntArray); diff --git a/src/SketcherPrs/SketcherPrs_SymbolPrs.cpp b/src/SketcherPrs/SketcherPrs_SymbolPrs.cpp index d23827aa7..a251d2539 100644 --- a/src/SketcherPrs/SketcherPrs_SymbolPrs.cpp +++ b/src/SketcherPrs/SketcherPrs_SymbolPrs.cpp @@ -177,6 +177,19 @@ Handle(Image_AlienPixMap) SketcherPrs_SymbolPrs::icon() aFile += iconName(); Handle(Image_AlienPixMap) aPixMap = new Image_AlienPixMap(); if (aPixMap->Load(aFile.c_str())) { + int aRatio = SketcherPrs_Tools::pixelRatio(); + if (aRatio > 1) { + Handle(Image_AlienPixMap) aSizedMap = new Image_AlienPixMap(); + Standard_Size aWidth = aPixMap->Width() * aRatio; + Standard_Size aHeigh = aPixMap->Height() * aRatio; + aSizedMap->InitTrash(aPixMap->Format(), aWidth, aHeigh); + for (Standard_Size i = 0; i < aWidth; i++) { + for (Standard_Size j = 0; j < aHeigh; j++) { + aSizedMap->SetPixelColor(i, j, aPixMap->PixelColor(i / aRatio, j / aRatio)); + } + } + aPixMap = aSizedMap; + } myIconsMap[iconName()] = aPixMap; return aPixMap; } diff --git a/src/SketcherPrs/SketcherPrs_Tools.cpp b/src/SketcherPrs/SketcherPrs_Tools.cpp index 0aecb72c9..394a638ff 100644 --- a/src/SketcherPrs/SketcherPrs_Tools.cpp +++ b/src/SketcherPrs/SketcherPrs_Tools.cpp @@ -255,8 +255,20 @@ std::shared_ptr getProjectionPoint(const FeaturePtr theLine, return aLin2d.project(thePoint); } +static int MyPixelRatio = 1; + +void setPixelRatio(int theRatio) +{ + MyPixelRatio = theRatio; +} + +int pixelRatio() +{ + return MyPixelRatio; +} static double MyArrowSize = 20; + double getArrowSize() { return MyArrowSize; @@ -280,7 +292,7 @@ int getConfigArrowSize() static double MyTextHeight = 16; double getTextHeight() { - return MyTextHeight; + return MyTextHeight * MyPixelRatio; } void setTextHeight(double theHeight) @@ -290,12 +302,12 @@ void setTextHeight(double theHeight) double getDefaultTextHeight() { - return 16; + return 16 * MyPixelRatio; } double getConfigTextHeight() { - return Config_PropManager::integer("Visualization", "dimension_value_size"); + return Config_PropManager::integer("Visualization", "dimension_value_size") * MyPixelRatio; } double getFlyoutDistance(const ModelAPI_Feature* theConstraint) diff --git a/src/SketcherPrs/SketcherPrs_Tools.h b/src/SketcherPrs/SketcherPrs_Tools.h index 75d1b351e..5a719646c 100644 --- a/src/SketcherPrs/SketcherPrs_Tools.h +++ b/src/SketcherPrs/SketcherPrs_Tools.h @@ -206,6 +206,10 @@ namespace SketcherPrs_Tools { /// \param theError a debug error information SKETCHERPRS_EXPORT void sendEmptyPresentationError(ModelAPI_Feature* theFeature, const std::string theError); + + SKETCHERPRS_EXPORT void setPixelRatio(int theRatio); + + SKETCHERPRS_EXPORT int pixelRatio(); }; #endif