]> icculus.org git repositories - duncan/yast2-qt4.git/blob - src/YQFrame.cc
give duncan something to grep for :)
[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 //Added by qt3to4:
25
26 using std::max;
27
28 #include "YQFrame.h"
29
30
31 YQFrame::YQFrame( YWidget *             parent,
32                   const string &        initialLabel )
33     : Q3GroupBox( (QWidget *) parent->widgetRep() )
34     , YFrame( parent, initialLabel )
35 {
36     setWidgetRep ( this );
37     QGroupBox::setTitle( fromUTF8( label() ) );
38 }
39
40
41 YQFrame::~YQFrame()
42 {
43     // NOP
44 }
45
46
47 void YQFrame::setEnabled( bool enabled )
48 {
49     QGroupBox::setEnabled( enabled );
50     YWidget::setEnabled( enabled );
51 }
52
53
54 void
55 YQFrame::setSize( int newWidth, int newHeight )
56 {
57     resize( newWidth, newHeight );
58
59     if ( hasChildren() )
60     {
61         int newChildWidth  = max ( 0, newWidth  - 2 * frameWidth() - 1 );
62         int newChildHeight = max ( 0, newHeight - frameWidth() - fontMetrics().height() - 1 );
63
64         firstChild()->setSize( newChildWidth, newChildHeight );
65         
66         QWidget * qChild = (QWidget *) firstChild()->widgetRep();
67         qChild->move( frameWidth(), fontMetrics().height() );
68     }
69 }
70
71
72 void
73 YQFrame::setLabel( const string & newLabel )
74 {
75     YFrame::setLabel( newLabel );
76     QGroupBox::setTitle( fromUTF8( label() ) );
77 }
78
79
80 int YQFrame::preferredWidth()
81 {
82     int preferredWidth;
83     int childPreferredWidth = hasChildren() ? firstChild()->preferredWidth() : 0;
84
85     preferredWidth = max( childPreferredWidth,
86                           (10 + fontMetrics().width( title() ) ) );
87     preferredWidth += 2*frameWidth() + 1;
88
89     return preferredWidth;
90 }
91
92
93 int YQFrame::preferredHeight()
94 {
95     int preferredHeight = hasChildren() ? firstChild()->preferredHeight() : 0;
96     preferredHeight += frameWidth() + fontMetrics().height() + 1;
97     
98     return preferredHeight;
99 }
100
101
102 #include "YQFrame.moc"