1 #include "SUIT_Tools.h"
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.
13 void SUIT_Tools::trace( const char* lpszLog, const char* lpszFormat, ... )
15 QString tmpPath = tmpDir();
16 if ( !tmpPath.isEmpty() )
17 tmpPath += QDir::separator();
19 tmpPath += QString( "Salome_trace" );
22 pStream = fopen( lpszLog ? lpszLog : tmpPath.latin1(), "a" );
26 va_start( argptr, lpszFormat );
27 fprintf( pStream, "- Trace %s [%d] : %s", __FILE__, __LINE__, lpszFormat );
35 Creates a rect with TopLeft = ( min(x1,x2), min(y1,y2) )
36 and BottomRight = ( TopLeft + (x2-x1)(y2-y1) )
38 QRect SUIT_Tools::makeRect( const int x1, const int y1, const int x2, const int y2 )
41 aRect.setRect( QMIN( x1, x2 ), QMIN( y1, y2 ), QABS( x2 - x1 ), QABS( y2 - y1 ) );
46 Creates font from string description
48 QFont SUIT_Tools::stringToFont( const QString& fontDescription )
51 if ( fontDescription.stripWhiteSpace().isEmpty() || !font.fromString( fontDescription ) )
52 font = QFont( "Courier", 11 );
57 Creates font's string description
59 QString SUIT_Tools::fontToString( const QFont& font )
61 return font.toString();
64 void SUIT_Tools::centerWidget( QWidget* src, const QWidget* ref )
66 SUIT_Tools::alignWidget(src, ref, Qt::AlignCenter);
70 Aligns widget 'w' as refered to widget 'ref' [ static ]
72 void SUIT_Tools::alignWidget ( QWidget* src, const QWidget* ref, int alignFlags )
74 if ( !src || !ref || !alignFlags ) return;
76 QPoint srcOri = src->mapToGlobal( QPoint( 1, 1 ) );
77 QPoint refOri = ref->mapToGlobal( QPoint( 1, 1 ) );
79 int x = srcOri.x(), y = srcOri.y();
80 int refWidth = ref->width(), refHei = ref->height();
81 int srcWidth = src->width(), srcHei = src->height();
83 srcWidth = src->sizeHint().width();
85 srcHei = src->sizeHint().height();
87 if ( alignFlags & AlignLeft )
89 if ( alignFlags & AlignRight )
90 x = refOri.x() + refWidth - srcWidth;
91 if ( alignFlags & AlignTop )
93 if ( alignFlags & AlignBottom )
94 y = refOri.y() + refHei - srcHei;
95 if ( alignFlags & AlignHCenter )
96 x = refOri.x() + ( refWidth - srcWidth ) / 2;
97 if ( alignFlags & AlignVCenter )
98 y = refOri.y() + ( refHei - srcHei ) / 2;
100 if ( src->parentWidget() && /* we move a widget inside its parent */
101 !src->inherits( "QDialog" )) /* dialogs use global coordinates */
103 QPoint pos = src->parentWidget()->mapFromGlobal( QPoint(x,y) );
104 x = pos.x(); y = pos.y();
107 x -= 4; /* - frame border width ( approx. ) */
108 y -= 30; /* - caption height ( approx. ) */