00001 /*======================================================================= 00002 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), *** 00003 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. *** 00004 *** *** 00005 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS *** 00006 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR *** 00007 *** WRITTEN AUTHORIZATION OF FEI S.A.S. *** 00008 *** *** 00009 *** RESTRICTED RIGHTS LEGEND *** 00010 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS *** 00011 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN *** 00012 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT *** 00013 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN *** 00014 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. *** 00015 *** *** 00016 *** COPYRIGHT (C) 1996-2022 BY FEI S.A.S, *** 00017 *** BORDEAUX, FRANCE *** 00018 *** ALL RIGHTS RESERVED *** 00019 **=======================================================================*/ 00020 /*======================================================================= 00021 ** Author : VSG (MMM YYYY) 00022 **=======================================================================*/ 00023 00024 #ifndef _SB_QT_HELPER 00025 #define _SB_QT_HELPER 00026 00027 #include <QCoreApplication> 00028 #include <QString> 00029 #include <QFile> 00030 #include <QWidget> 00031 #include <QApplication> 00032 00033 #include <Inventor/SoPreferences.h> 00034 #include <Inventor/nodes/SoNode.h> 00035 #include <Inventor/helpers/SbFileHelper.h> 00036 #include <Inventor/sys/SoDynamicLibManager.h> 00037 00045 class SbQtHelper 00046 { 00047 public: 00062 static void addPlatformPluginsPath(SbString path = "") 00063 { 00064 // if the QApplication alraady exists, we can safely assume everything is in order 00065 // if there is a qt.conf file, we do not want to apply our library path modifications 00066 // as we should trust the qt.conf to do everything that is required. 00067 const bool qtconfExists = QFile::exists( "qt.conf"); 00068 if ( qApp || qtconfExists ) 00069 return; 00070 00071 if ( SoPreferences::getString("QT_QPA_PLATFORM_PLUGIN_PATH", "").isEmpty() ) 00072 { 00073 if ( path.isEmpty() ) 00074 { 00075 // Try to guess QT platforms path from Open Inventor binaries path 00076 const SbString binariesPath = SoDynamicLibManager::getLibraryFromSymbol((void*)SoInventorBase::init); 00077 if ( !binariesPath.isEmpty() ) 00078 { 00079 const SbString qtPlatformsPath = SbFileHelper::toUnixPath(SbFileHelper::getDirName(binariesPath)); 00080 if ( SbFileHelper::isAccessible(qtPlatformsPath) ) 00081 { 00082 QCoreApplication::addLibraryPath( QString(qtPlatformsPath.getString()) ); 00083 } 00084 } 00085 } 00086 else 00087 { 00088 QCoreApplication::addLibraryPath( QString(path.getString()) ); 00089 } 00090 } 00091 } 00092 00102 static float getDevicePixelRatio(QWidget* widget) 00103 { 00104 return static_cast<float>(widget->devicePixelRatio()); 00105 } 00106 00107 }; 00108 00109 #endif // SB_QT_HELPER 00110 00111 00112