1 /*---------------------------------------------------------------------\
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
11 \----------------------------------------------------------------------/
13 File: QY2LayoutUtils.cc
15 Author: Stefan Hundhammer <sh@suse.de>
17 These are pure Qt functions - they can be used independently of YaST2.
22 #include <qapplication.h>
24 #include <QDesktopWidget>
25 #include "QY2LayoutUtils.h"
28 QWidget * addVStretch( QWidget * parent )
30 QWidget * spacer = new QWidget( parent );
31 spacer->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Expanding ) ); // hor/vert
37 QWidget * addHStretch( QWidget * parent )
39 QWidget * spacer = new QWidget( parent );
40 spacer->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum ) ); // hor/vert
46 QWidget * addVSpacing( QWidget * parent, int height )
48 QWidget * spacer = new QWidget( parent );
49 Q_CHECK_PTR( spacer );
50 spacer->setFixedHeight( height );
56 QWidget * addHSpacing( QWidget * parent, int width )
58 QWidget * spacer = new QWidget( parent );
59 Q_CHECK_PTR( spacer );
60 spacer->setFixedWidth( width );
67 limitToScreenSize( const QWidget * widget, int width, int height )
69 return limitToScreenSize( widget, QSize( width, height ) );
74 limitToScreenSize( const QWidget * widget, const QSize & desiredSize )
76 QSize availableSize = QApplication::desktop()->availableGeometry( const_cast<QWidget*> (widget) ).size();
78 // Subtract WM decorations. There seems to be no reliable way to tell if
79 // this is necessary at all (even fvwm2 claims it is a NETWM compliant
80 // window manager) or how large the WM decorations are.
81 // For the purpose of this function, let's assume we have to subtract the
82 // common fvwm2 decoration size. This is simplistic and should be improved.
83 availableSize -= QSize( 10, 35 );
85 return desiredSize.boundedTo( availableSize );