d6691858e76d81b779069894a5a1946f231c13f5
[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 <QDesktopWidget>
25 #include "QY2LayoutUtils.h"
26
27
28 QWidget * addVStretch( QWidget * parent )
29 {
30     QWidget * spacer = new QWidget( parent );
31     spacer->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Expanding ) ); // hor/vert
32
33     return spacer;
34 }
35
36
37 QWidget * addHStretch( QWidget * parent )
38 {
39     QWidget * spacer = new QWidget( parent );
40     spacer->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum ) ); // hor/vert
41
42     return spacer;
43 }
44
45
46 QWidget * addVSpacing( QWidget * parent, int height )
47 {
48     QWidget * spacer = new QWidget( parent );
49     Q_CHECK_PTR( spacer );
50     spacer->setFixedHeight( height );
51
52     return spacer;
53 }
54
55
56 QWidget * addHSpacing( QWidget * parent, int width )
57 {
58     QWidget * spacer = new QWidget( parent );
59     Q_CHECK_PTR( spacer );
60     spacer->setFixedWidth( width );
61
62     return spacer;
63 }
64
65
66 QSize
67 limitToScreenSize( const QWidget * widget, int width, int height )
68 {
69     return limitToScreenSize( widget, QSize( width, height ) );
70 }
71
72
73 QSize
74 limitToScreenSize( const QWidget * widget, const QSize & desiredSize )
75 {
76     QSize availableSize = QApplication::desktop()->availableGeometry( const_cast<QWidget*> (widget) ).size();
77
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 );
84
85     return desiredSize.boundedTo( availableSize );
86 }
87