libyui-qt-pkg  2.45.15
QY2LayoutUtils.cc
1 /**************************************************************************
2 Copyright (C) 2000 - 2010 Novell, Inc.
3 All Rights Reserved.
4 
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9 
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 
19 **************************************************************************/
20 
21 
22 /*---------------------------------------------------------------------\
23 | |
24 | __ __ ____ _____ ____ |
25 | \ \ / /_ _/ ___|_ _|___ \ |
26 | \ V / _` \___ \ | | __) | |
27 | | | (_| |___) || | / __/ |
28 | |_|\__,_|____/ |_| |_____| |
29 | |
30 | core system |
31 | (C) SuSE GmbH |
32 \----------------------------------------------------------------------/
33 
34  File: QY2LayoutUtils.cc
35 
36  Author: Stefan Hundhammer <sh@suse.de>
37 
38  These are pure Qt functions - they can be used independently of YaST2.
39 
40 /-*/
41 
42 
43 #include <qapplication.h>
44 #include <qwidget.h>
45 #include <QDesktopWidget>
46 #include "QY2LayoutUtils.h"
47 
48 
49 QWidget * addVStretch( QWidget * parent )
50 {
51  QWidget * spacer = new QWidget( parent );
52  spacer->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Expanding ) ); // hor/vert
53 
54  return spacer;
55 }
56 
57 
58 QWidget * addHStretch( QWidget * parent )
59 {
60  QWidget * spacer = new QWidget( parent );
61  spacer->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Minimum ) ); // hor/vert
62 
63  return spacer;
64 }
65 
66 
67 QWidget * addVSpacing( QWidget * parent, int height )
68 {
69  QWidget * spacer = new QWidget( parent );
70  Q_CHECK_PTR( spacer );
71  spacer->setFixedHeight( height );
72 
73  return spacer;
74 }
75 
76 
77 QWidget * addHSpacing( QWidget * parent, int width )
78 {
79  QWidget * spacer = new QWidget( parent );
80  Q_CHECK_PTR( spacer );
81  spacer->setFixedWidth( width );
82 
83  return spacer;
84 }
85 
86 
87 QSize
88 limitToScreenSize( const QWidget * widget, int width, int height )
89 {
90  return limitToScreenSize( widget, QSize( width, height ) );
91 }
92 
93 
94 QSize
95 limitToScreenSize( const QWidget * widget, const QSize & desiredSize )
96 {
97  QSize availableSize = QApplication::desktop()->availableGeometry( const_cast<QWidget*> (widget) ).size();
98 
99  // Subtract WM decorations. There seems to be no reliable way to tell if
100  // this is necessary at all (even fvwm2 claims it is a NETWM compliant
101  // window manager) or how large the WM decorations are.
102  // For the purpose of this function, let's assume we have to subtract the
103  // common fvwm2 decoration size. This is simplistic and should be improved.
104  availableSize -= QSize( 10, 35 );
105 
106  return desiredSize.boundedTo( availableSize );
107 }
108