libyui-qt  2.43.5
/usr/src/RPM/BUILD/libyui-qt-2.43.5/src/YQFrame.cc
00001 /*
00002   Copyright (C) 2000-2012 Novell, Inc
00003   This library is free software; you can redistribute it and/or modify
00004   it under the terms of the GNU Lesser General Public License as
00005   published by the Free Software Foundation; either version 2.1 of the
00006   License, or (at your option) version 3.0 of the License. This library
00007   is distributed in the hope that it will be useful, but WITHOUT ANY
00008   WARRANTY; without even the implied warranty of MERCHANTABILITY or
00009   FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
00010   License for more details. You should have received a copy of the GNU
00011   Lesser General Public License along with this library; if not, write
00012   to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
00013   Floor, Boston, MA 02110-1301 USA
00014 */
00015 
00016 
00017 /*-/
00018 
00019   File:       YQFrame.cc
00020 
00021   Author:     Stefan Hundhammer <sh@suse.de>
00022 
00023 /-*/
00024 
00025 
00026 #define YUILogComponent "qt-ui"
00027 #include <yui/YUILog.h>
00028 #include "YQUI.h"
00029 #include "utf8.h"
00030 #include <QDebug>
00031 
00032 using std::max;
00033 
00034 #include "YQFrame.h"
00035 
00036 
00037 YQFrame::YQFrame( YWidget *             parent,
00038                   const std::string &   initialLabel )
00039     : QGroupBox( (QWidget *) parent->widgetRep() )
00040     , YFrame( parent, initialLabel )
00041 {
00042     setWidgetRep ( this );
00043     QGroupBox::setTitle( fromUTF8( label() ) );
00044 }
00045 
00046 
00047 YQFrame::~YQFrame()
00048 {
00049     // NOP
00050 }
00051 
00052 
00053 void YQFrame::setEnabled( bool enabled )
00054 {
00055     QGroupBox::setEnabled( enabled );
00056     YWidget::setEnabled( enabled );
00057 }
00058 
00059 
00060 void
00061 YQFrame::setSize( int newWidth, int newHeight )
00062 {
00063     resize( newWidth, newHeight );
00064 
00065     if ( hasChildren() )
00066     {
00067         int left, top, right, bottom;
00068         getContentsMargins( &left, &top, &right, &bottom );
00069         int newChildWidth  = newWidth - left - right;
00070         int newChildHeight = newHeight - bottom - top;
00071 
00072         firstChild()->setSize( newChildWidth, newChildHeight );
00073 
00074         QWidget * qChild = (QWidget *) firstChild()->widgetRep();
00075         qChild->move( left, top );
00076     }
00077 }
00078 
00079 
00080 void
00081 YQFrame::setLabel( const std::string & newLabel )
00082 {
00083     YFrame::setLabel( newLabel );
00084     QGroupBox::setTitle( fromUTF8( label() ) );
00085 }
00086 
00087 
00088 int YQFrame::preferredWidth()
00089 {
00090     int preferredWidth = hasChildren() ? firstChild()->preferredWidth() : 0;
00091     int left, top, right, bottom;
00092     getContentsMargins( &left, &top, &right, &bottom );
00093 
00094     preferredWidth += left + right;
00095 
00096     if ( minimumSizeHint().width() >  preferredWidth )
00097         preferredWidth = minimumSizeHint().width();
00098 
00099     return preferredWidth;
00100 }
00101 
00102 
00103 int YQFrame::preferredHeight()
00104 {
00105     int preferredHeight = hasChildren() ? firstChild()->preferredHeight() : 0;
00106     int left, top, right, bottom;
00107     getContentsMargins( &left, &top, &right, &bottom );
00108 
00109     return preferredHeight + top + left;
00110 }
00111 
00112 
00113 #include "YQFrame.moc"
 All Classes Functions Variables