1 // Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/
19 // File: QtxGroupBox.cxx
20 // Author: Sergey TELKOV
22 #include "QtxGroupBox.h"
26 #include <qtoolbutton.h>
27 #include <qapplication.h>
28 #include <qobjectlist.h>
30 QtxGroupBox::QtxGroupBox( QWidget* parent, const char* name )
31 : QGroupBox( parent, name ),
36 QtxGroupBox::QtxGroupBox( const QString& title, QWidget* parent, const char* name )
37 : QGroupBox( title, parent, name ),
43 QtxGroupBox::QtxGroupBox( int strips, Orientation o, QWidget* parent, const char* name )
44 : QGroupBox( strips, o, parent, name ),
50 QtxGroupBox::QtxGroupBox( int strips, Orientation o, const QString& title,
51 QWidget* parent, const char* name )
52 : QGroupBox( strips, o, title, parent, name ),
58 QtxGroupBox::~QtxGroupBox()
63 void QtxGroupBox::initialize()
65 myContainer = new QHBox( this, 0, WStyle_Customize | WStyle_NoBorderEx | WStyle_Tool );
72 int QtxGroupBox::insideMargin() const
76 m = layout()->margin();
80 int QtxGroupBox::insideSpacing() const
84 s = layout()->spacing();
88 void QtxGroupBox::setInsideMargin( int m )
91 layout()->setMargin( m );
94 void QtxGroupBox::setInsideSpacing( int s )
97 layout()->setSpacing( s );
102 void QtxGroupBox::insertTitleWidget( QWidget* wid )
107 wid->reparent( myContainer, QPoint( 0, 0 ), true );
108 wid->installEventFilter( this );
113 void QtxGroupBox::removeTitleWidget( QWidget* wid )
115 if ( !myContainer || wid->parentWidget() != myContainer )
118 wid->reparent( 0, QPoint( 0, 0 ), false );
119 wid->removeEventFilter( this );
124 void QtxGroupBox::adjustInsideMargin()
126 QApplication::sendPostedEvents( myContainer, QEvent::ChildInserted );
128 myContainer->resize( myContainer->minimumSizeHint() );
130 setInsideMargin( myContainer->height() );
133 void QtxGroupBox::setAlignment( int align )
135 QGroupBox::setAlignment( align );
140 void QtxGroupBox::setTitle( const QString& title )
142 QGroupBox::setTitle( title );
147 void QtxGroupBox::setColumnLayout( int strips, Orientation o )
150 myContainer->reparent( 0, QPoint( 0, 0 ), false );
152 QGroupBox::setColumnLayout( strips, o );
155 myContainer->reparent( this, QPoint( 0, 0 ), false );
160 void QtxGroupBox::show()
167 void QtxGroupBox::update()
174 QSize QtxGroupBox::sizeHint() const
176 QSize sz = QGroupBox::sizeHint();
178 int sw = titleSize().width();
182 if ( alignment() == AlignCenter )
183 sw += 2 * ( myContainer->width() + 5 );
185 sw += 1 * ( myContainer->width() + 5 );
188 sw += frameRect().left();
190 return QSize( QMAX( sz.width(), sw ), sz.height() );
193 QSize QtxGroupBox::minimumSizeHint() const
195 QSize sz = QGroupBox::minimumSizeHint();
197 int sw = titleSize().width() + myContainer ? myContainer->width() + 5 : 0;
201 if ( alignment() == AlignCenter )
202 sw += 2 * ( myContainer->width() + 5 );
204 sw += 1 * ( myContainer->width() + 5 );
207 sw += frameRect().left();
209 return QSize( QMAX( sz.width(), sw ), sz.height() );
212 bool QtxGroupBox::eventFilter( QObject* obj, QEvent* e )
214 QEvent::Type type = e->type();
215 if ( myContainer && obj->parent() == myContainer &&
216 ( type == QEvent::Show || type == QEvent::ShowToParent ||
217 type == QEvent::Hide || type == QEvent::HideToParent ) )
218 QApplication::postEvent( this, new QCustomEvent( QEvent::User ) );
220 return QGroupBox::eventFilter( obj, e );
223 void QtxGroupBox::resizeEvent( QResizeEvent* e )
225 QGroupBox::resizeEvent( e );
230 void QtxGroupBox::childEvent( QChildEvent* e )
232 if ( e->type() == QEvent::ChildInserted && e->child() == myContainer )
235 QGroupBox::childEvent( e );
238 void QtxGroupBox::customEvent( QCustomEvent* )
243 void QtxGroupBox::frameChanged()
248 QSize QtxGroupBox::titleSize() const
255 for ( QLayoutIterator it = layout()->iterator(); it.current() && !si; ++it )
256 si = it.current()->spacerItem();
262 int h = sz.height() + insideMargin();
264 return QSize( w, h );
267 void QtxGroupBox::updateTitle()
272 int align = alignment();
273 if ( align == AlignAuto )
274 align = QApplication::reverseLayout() ? AlignRight : AlignLeft;
276 if ( title().isEmpty() )
279 QSize ts = titleSize();
283 int w = frameRect().width() - ts.width();
284 if ( align == AlignCenter )
289 QApplication::sendPostedEvents( myContainer, QEvent::ChildInserted );
290 myContainer->resize( myContainer->minimumSizeHint() );
293 const QObjectList* list = myContainer->children();
296 for ( QObjectListIt it( *list ); it.current() && !vis; ++it )
297 vis = it.current()->isWidgetType() &&
298 ((QWidget*)it.current())->isVisibleTo( myContainer );
301 if ( myContainer->height() > ts.height() || myContainer->width() > w || !vis )
306 if ( align == AlignRight )
307 x = frameRect().left() + m;
309 x = frameRect().right() - myContainer->width() - m;
311 int y = frameRect().top() - ( myContainer->height() - frameWidth() ) / 2;
313 QPoint pos( x, QMAX( 0, y ) );
314 pos = mapToGlobal( pos );
315 if ( myContainer->parentWidget() )
316 pos = myContainer->parentWidget()->mapFromGlobal( pos );
317 myContainer->move( pos );