libyui-qt  2.53.0
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 #include "YQFrame.h"
33 
34 using std::string;
35 
36 
37 
38 YQFrame::YQFrame( YWidget * parent,
39  const string & initialLabel )
40  : QGroupBox( (QWidget *) parent->widgetRep() )
41  , YFrame( parent, initialLabel )
42 {
43  setWidgetRep ( this );
44  QGroupBox::setTitle( fromUTF8( label() ) );
45 }
46 
47 
49 {
50  // NOP
51 }
52 
53 
54 void YQFrame::setEnabled( bool enabled )
55 {
56  QGroupBox::setEnabled( enabled );
57  YWidget::setEnabled( enabled );
58 }
59 
60 
61 void
62 YQFrame::setSize( int newWidth, int newHeight )
63 {
64  resize( newWidth, newHeight );
65 
66  if ( hasChildren() )
67  {
68  QMargins margins = contentsMargins();
69  int newChildWidth = newWidth - margins.left() - margins.right();
70  int newChildHeight = newHeight - margins.bottom() - margins.top();
71 
72  firstChild()->setSize( newChildWidth, newChildHeight );
73 
74  QWidget * qChild = (QWidget *) firstChild()->widgetRep();
75  qChild->move( margins.left(), margins.top() );
76  }
77 }
78 
79 
80 void
81 YQFrame::setLabel( const string & newLabel )
82 {
83  YFrame::setLabel( newLabel );
84  QGroupBox::setTitle( fromUTF8( label() ) );
85 }
86 
87 
89 {
90  int preferredWidth = hasChildren() ? firstChild()->preferredWidth() : 0;
91  QMargins margins = contentsMargins();
92 
93  preferredWidth += margins.left() + margins.right();
94 
95  if ( minimumSizeHint().width() > preferredWidth )
96  preferredWidth = minimumSizeHint().width();
97 
98  return preferredWidth;
99 }
100 
101 
103 {
104  int preferredHeight = hasChildren() ? firstChild()->preferredHeight() : 0;
105  QMargins margins = contentsMargins();
106 
107  return preferredHeight + margins.top() + margins.left();
108 }
109 
YQFrame::setLabel
virtual void setLabel(const std::string &newLabel)
Change the frame label.
Definition: YQFrame.cc:81
YQFrame::~YQFrame
virtual ~YQFrame()
Destructor.
Definition: YQFrame.cc:48
YQFrame::preferredWidth
virtual int preferredWidth()
Preferred width of the widget.
Definition: YQFrame.cc:88
YQFrame::setEnabled
virtual void setEnabled(bool enabled)
Set enabled/disabled state.
Definition: YQFrame.cc:54
YQFrame::preferredHeight
virtual int preferredHeight()
Preferred height of the widget.
Definition: YQFrame.cc:102
YQFrame::YQFrame
YQFrame(YWidget *parent, const std::string &label)
Constructor.
Definition: YQFrame.cc:38
YQFrame::setSize
virtual void setSize(int newWidth, int newHeight)
Set the new size of the widget.
Definition: YQFrame.cc:62