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-2018 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 00032 #include <Inventor/SoPreferences.h> 00033 #include <Inventor/nodes/SoNode.h> 00034 #include <Inventor/helpers/SbFileHelper.h> 00035 #include <Inventor/sys/SoDynamicLibManager.h> 00036 00044 class SbQtHelper 00045 { 00046 public: 00061 static void addPlatformPluginsPath(SbString path = "") 00062 { 00063 // if the QApplication alraady exists, we can safely assume everything is in order 00064 // if there is a qt.conf file, we do not want to apply our library path modifications 00065 // as we should trust the qt.conf to do everything that is required. 00066 const bool qtconfExists = QFile::exists( "qt.conf"); 00067 if ( qApp || qtconfExists ) 00068 return; 00069 00070 if ( SoPreferences::getString("QT_QPA_PLATFORM_PLUGIN_PATH", "").isEmpty() ) 00071 { 00072 if ( path.isEmpty() ) 00073 { 00074 // Try to guess QT platforms path from Open Inventor binaries path 00075 const SbString pluginPath = qtPluginsPath(); 00076 if ( SbFileHelper::isAccessible(pluginPath) ) 00077 { 00078 QCoreApplication::addLibraryPath( QString(pluginPath.getString()) ); 00079 } 00080 } 00081 else 00082 { 00083 QCoreApplication::addLibraryPath( QString(path.getString()) ); 00084 } 00085 } 00086 } 00087 00088 static SbString qtPluginsPath() 00089 { 00090 const SbString binariesPath = SoDynamicLibManager::getLibraryFromSymbol((void*)SoInventorBase::init); 00091 const SbString qtPlatformsPath = SbFileHelper::toUnixPath(SbFileHelper::getDirName(binariesPath) + "qtplugins/"); 00092 return qtPlatformsPath; 00093 } 00094 00104 static float getDevicePixelRatio(QWidget* widget) 00105 { 00106 float ratio = 1.0f; 00107 if ( widget->windowHandle() != NULL ) 00108 ratio = static_cast<float>(widget->devicePixelRatio()); 00109 return ratio; 00110 } 00111 00112 }; 00113 00114 #endif // SB_QT_HELPER 00115 00116 00117