libyui-qt  2.47.1.1
YQFrame.cc
1 /*
2  Copyright (C) 2000-2012 Novell, Inc
3  This library is free software; you can redistribute it and/or modify
4  it under the terms of the GNU Lesser General Public License as
5  published by the Free Software Foundation; either version 2.1 of the
6  License, or (at your option) version 3.0 of the License. This library
7  is distributed in the hope that it will be useful, but WITHOUT ANY
8  WARRANTY; without even the implied warranty of MERCHANTABILITY or
9  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
10  License for more details. You should have received a copy of the GNU
11  Lesser General Public License along with this library; if not, write
12  to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
13  Floor, Boston, MA 02110-1301 USA
14 */
15 
16 
17 /*-/
18 
19  File: YQFrame.cc
20 
21  Author: Stefan Hundhammer <sh@suse.de>
22 
23 /-*/
24 
25 
26 #define YUILogComponent "qt-ui"
27 #include <yui/YUILog.h>
28 #include "YQUI.h"
29 #include "utf8.h"
30 #include <QDebug>
31 
32 using std::max;
33 
34 #include "YQFrame.h"
35 
36 
37 YQFrame::YQFrame( YWidget * parent,
38  const std::string & initialLabel )
39  : QGroupBox( (QWidget *) parent->widgetRep() )
40  , YFrame( parent, initialLabel )
41 {
42  setWidgetRep ( this );
43  QGroupBox::setTitle( fromUTF8( label() ) );
44 }
45 
46 
48 {
49  // NOP
50 }
51 
52 
53 void YQFrame::setEnabled( bool enabled )
54 {
55  QGroupBox::setEnabled( enabled );
56  YWidget::setEnabled( enabled );
57 }
58 
59 
60 void
61 YQFrame::setSize( int newWidth, int newHeight )
62 {
63  resize( newWidth, newHeight );
64 
65  if ( hasChildren() )
66  {
67  int left, top, right, bottom;
68  getContentsMargins( &left, &top, &right, &bottom );
69  int newChildWidth = newWidth - left - right;
70  int newChildHeight = newHeight - bottom - top;
71 
72  firstChild()->setSize( newChildWidth, newChildHeight );
73 
74  QWidget * qChild = (QWidget *) firstChild()->widgetRep();
75  qChild->move( left, top );
76  }
77 }
78 
79 
80 void
81 YQFrame::setLabel( const std::string & newLabel )
82 {
83  YFrame::setLabel( newLabel );
84  QGroupBox::setTitle( fromUTF8( label() ) );
85 }
86 
87 
89 {
90  int preferredWidth = hasChildren() ? firstChild()->preferredWidth() : 0;
91  int left, top, right, bottom;
92  getContentsMargins( &left, &top, &right, &bottom );
93 
94  preferredWidth += left + right;
95 
96  if ( minimumSizeHint().width() > preferredWidth )
97  preferredWidth = minimumSizeHint().width();
98 
99  return preferredWidth;
100 }
101 
102 
104 {
105  int preferredHeight = hasChildren() ? firstChild()->preferredHeight() : 0;
106  int left, top, right, bottom;
107  getContentsMargins( &left, &top, &right, &bottom );
108 
109  return preferredHeight + top + left;
110 }
111 
112 
113 #include "YQFrame.moc"
YQFrame(YWidget *parent, const std::string &label)
Constructor.
Definition: YQFrame.cc:37
virtual void setSize(int newWidth, int newHeight)
Set the new size of the widget.
Definition: YQFrame.cc:61
virtual ~YQFrame()
Destructor.
Definition: YQFrame.cc:47
virtual int preferredWidth()
Preferred width of the widget.
Definition: YQFrame.cc:88
virtual void setEnabled(bool enabled)
Set enabled/disabled state.
Definition: YQFrame.cc:53
virtual int preferredHeight()
Preferred height of the widget.
Definition: YQFrame.cc:103
virtual void setLabel(const std::string &newLabel)
Change the frame label.
Definition: YQFrame.cc:81