]> icculus.org git repositories - duncan/yast2-qt4.git/blob - src/YQFrame.cc
restart qt4 porting
[duncan/yast2-qt4.git] / src / YQFrame.cc
1 /*---------------------------------------------------------------------\
2 |                                                                      |
3 |                      __   __    ____ _____ ____                      |
4 |                      \ \ / /_ _/ ___|_   _|___ \                     |
5 |                       \ V / _` \___ \ | |   __) |                    |
6 |                        | | (_| |___) || |  / __/                     |
7 |                        |_|\__,_|____/ |_| |_____|                    |
8 |                                                                      |
9 |                               core system                            |
10 |                                                        (C) SuSE GmbH |
11 \----------------------------------------------------------------------/
12
13   File:       YQFrame.cc
14
15   Author:     Stefan Hundhammer <sh@suse.de>
16
17 /-*/
18
19
20 #define y2log_component "qt-ui"
21 #include <ycp/y2log.h>
22 #include "YQUI.h"
23 #include "utf8.h"
24
25 using std::max;
26
27 #include "YQFrame.h"
28
29
30 YQFrame::YQFrame( YWidget *             parent,
31                   const string &        initialLabel )
32     : QGroupBox( (QWidget *) parent->widgetRep() )
33     , YFrame( parent, initialLabel )
34 {
35     setWidgetRep ( this );
36     QGroupBox::setTitle( fromUTF8( label() ) );
37 }
38
39
40 YQFrame::~YQFrame()
41 {
42     // NOP
43 }
44
45
46 void YQFrame::setEnabled( bool enabled )
47 {
48     QGroupBox::setEnabled( enabled );
49     YWidget::setEnabled( enabled );
50 }
51
52
53 void
54 YQFrame::setSize( int newWidth, int newHeight )
55 {
56     resize( newWidth, newHeight );
57
58     if ( hasChildren() )
59     {
60         int newChildWidth  = max ( 0, newWidth  - 2 * frameWidth() - 1 );
61         int newChildHeight = max ( 0, newHeight - frameWidth() - fontMetrics().height() - 1 );
62
63         firstChild()->setSize( newChildWidth, newChildHeight );
64         
65         QWidget * qChild = (QWidget *) firstChild()->widgetRep();
66         qChild->move( frameWidth(), fontMetrics().height() );
67     }
68 }
69
70
71 void
72 YQFrame::setLabel( const string & newLabel )
73 {
74     YFrame::setLabel( newLabel );
75     QGroupBox::setTitle( fromUTF8( label() ) );
76 }
77
78
79 int YQFrame::preferredWidth()
80 {
81     int preferredWidth;
82     int childPreferredWidth = hasChildren() ? firstChild()->preferredWidth() : 0;
83
84     preferredWidth = max( childPreferredWidth,
85                           (10 + fontMetrics().width( title() ) ) );
86     preferredWidth += 2*frameWidth() + 1;
87
88     return preferredWidth;
89 }
90
91
92 int YQFrame::preferredHeight()
93 {
94     int preferredHeight = hasChildren() ? firstChild()->preferredHeight() : 0;
95     preferredHeight += frameWidth() + fontMetrics().height() + 1;
96     
97     return preferredHeight;
98 }
99
100
101 #include "YQFrame.moc"