Salome HOME
Method setShown( bool ) was added. This method allow to show or hide all views.
[modules/gui.git] / src / SUIT / SUIT_Tools.cxx
1 #include "SUIT_Tools.h"
2
3 #include <qdir.h>
4
5 #include <stdio.h>
6 #include <stdarg.h>
7
8 /*!
9   Traces output to log-file.
10   If log is NULL, 'Salome_trace' file is created in temp directory.
11   Log file is written in 'append' mode.
12 */
13 void SUIT_Tools::trace( const char* lpszLog, const char* lpszFormat, ... )
14 {
15   QString tmpPath = tmpDir();
16   if ( !tmpPath.isEmpty() )
17     tmpPath += QDir::separator();
18
19   tmpPath += QString( "Salome_trace" );
20
21   FILE* pStream;
22   pStream = fopen( lpszLog ? lpszLog : tmpPath.latin1(), "a" );
23   if ( pStream ) 
24   {     
25     va_list argptr;
26     va_start( argptr, lpszFormat );
27     fprintf( pStream, "- Trace %s [%d] : %s", __FILE__, __LINE__, lpszFormat );
28     va_end( argptr );
29
30     fclose( pStream );
31   }
32 }
33
34 /*! 
35     Creates a rect with TopLeft = ( min(x1,x2), min(y1,y2) )
36     and BottomRight = ( TopLeft + (x2-x1)(y2-y1) )    
37 */      
38 QRect SUIT_Tools::makeRect( const int x1, const int y1, const int x2, const int y2 )
39 {  
40   return QRect( QMIN( x1, x2 ), QMIN( y1, y2 ), QABS( x2 - x1 ), QABS( y2 - y1 ) );
41 }
42
43 /*!
44   Creates font from string description
45 */
46 QFont SUIT_Tools::stringToFont( const QString& fontDescription )
47 {
48   QFont font;
49   if ( fontDescription.stripWhiteSpace().isEmpty() || !font.fromString( fontDescription ) )
50     font = QFont( "Courier", 11 );
51   return font;
52 }
53
54 /*!
55   Creates font's string description
56 */
57 QString SUIT_Tools::fontToString( const QFont& font )
58 {
59   return font.toString();
60 }
61
62 /*!
63   Center widget 'src' relative to widget 'ref'.
64 */
65 void SUIT_Tools::centerWidget( QWidget* src, const QWidget* ref )
66 {
67   SUIT_Tools::alignWidget( src, ref, Qt::AlignCenter );
68 }