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