]> icculus.org git repositories - duncan/yast2-qt4.git/blob - src/QY2LayoutUtils.cc
restart qt4 porting
[duncan/yast2-qt4.git] / src / QY2LayoutUtils.cc
1 /*---------------------------------------------------------------------\
2 |                                                                      |
3 |                      __   __    ____ _____ ____                      |
4 |                      \ \ / /_ _/ ___|_   _|___ \                     |
5 |                       \ V / _` \___ \ | |   __) |                    |
6 |                        | | (_| |___) || |  / __/                     |
7 |                        |_|\__,_|____/ |_| |_____|                    |
8 |                                                                      |
9 |                               core system                            |
10 |                                                        (C) SuSE GmbH |
11 \----------------------------------------------------------------------/
12
13   File:       QY2LayoutUtils.cc
14
15   Author:     Stefan Hundhammer <sh@suse.de>
16
17   These are pure Qt functions - they can be used independently of YaST2.
18
19 /-*/
20
21
22 #include <qapplication.h>
23 #include <qwidget.h>
24 #include "QY2LayoutUtils.h"
25
26
27 QWidget * addVStretch( QWidget * parent )
28 {
29     QWidget * spacer = new QWidget( parent );
30     spacer->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Expanding ) ); // hor/vert
31
32     return spacer;
33 }
34
35
36 QWidget * addHStretch( QWidget * parent )
37 {
38     QWidget * spacer = new QWidget( parent );
39     spacer->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum ) ); // hor/vert
40
41     return spacer;
42 }
43
44
45 QWidget * addVSpacing( QWidget * parent, int height )
46 {
47     QWidget * spacer = new QWidget( parent );
48     CHECK_PTR( spacer );
49     spacer->setFixedHeight( height );
50
51     return spacer;
52 }
53
54
55 QWidget * addHSpacing( QWidget * parent, int width )
56 {
57     QWidget * spacer = new QWidget( parent );
58     CHECK_PTR( spacer );
59     spacer->setFixedWidth( width );
60
61     return spacer;
62 }
63
64
65 QSize
66 limitToScreenSize( const QWidget * widget, int width, int height )
67 {
68     return limitToScreenSize( widget, QSize( width, height ) );
69 }
70
71
72 QSize
73 limitToScreenSize( const QWidget * widget, const QSize & desiredSize )
74 {
75     QSize availableSize = qApp->desktop()->availableGeometry( const_cast<QWidget*> (widget) ).size();
76
77     // Subtract WM decorations. There seems to be no reliable way to tell if
78     // this is necessary at all (even fvwm2 claims it is a NETWM compliant
79     // window manager) or how large the WM decorations are.
80     // For the purpose of this function, let's assume we have to subtract the
81     // common fvwm2 decoration size. This is simplistic and should be improved.
82     availableSize -= QSize( 10, 35 );
83
84     return desiredSize.boundedTo( availableSize );
85 }
86