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>
33 QtxGroupBox::QtxGroupBox( QWidget* parent, const char* name )
34 : QGroupBox( parent, name ),
42 QtxGroupBox::QtxGroupBox( const QString& title, QWidget* parent, const char* name )
43 : QGroupBox( title, parent, name ),
52 QtxGroupBox::QtxGroupBox( int strips, Orientation o, QWidget* parent, const char* name )
53 : QGroupBox( strips, o, parent, name ),
62 QtxGroupBox::QtxGroupBox( int strips, Orientation o, const QString& title,
63 QWidget* parent, const char* name )
64 : QGroupBox( strips, o, title, parent, name ),
73 QtxGroupBox::~QtxGroupBox()
79 Creates horizontal box as container
81 void QtxGroupBox::initialize()
83 myContainer = new QHBox( this, 0, WStyle_Customize | WStyle_NoBorderEx | WStyle_Tool );
91 \return the width of the empty space between the items in the group and the frame of the group
93 int QtxGroupBox::insideMargin() const
97 m = layout()->margin();
102 \return the width of the empty space between each of the items in the group
104 int QtxGroupBox::insideSpacing() const
108 s = layout()->spacing();
113 Sets the width of the empty space between the items in the group and the frame of the group
115 void QtxGroupBox::setInsideMargin( int m )
118 layout()->setMargin( m );
122 Sets the width of the empty space between each of the items in the group
124 void QtxGroupBox::setInsideSpacing( int s )
127 layout()->setSpacing( s );
134 \param wid - new title widget
136 void QtxGroupBox::insertTitleWidget( QWidget* wid )
141 wid->reparent( myContainer, QPoint( 0, 0 ), true );
142 wid->installEventFilter( this );
149 \param wid - title widget
151 void QtxGroupBox::removeTitleWidget( QWidget* wid )
153 if ( !myContainer || wid->parentWidget() != myContainer )
156 wid->reparent( 0, QPoint( 0, 0 ), false );
157 wid->removeEventFilter( this );
165 void QtxGroupBox::adjustInsideMargin()
167 QApplication::sendPostedEvents( myContainer, QEvent::ChildInserted );
169 myContainer->resize( myContainer->minimumSizeHint() );
171 setInsideMargin( myContainer->height() );
175 Sets the alignment of the group box title
177 void QtxGroupBox::setAlignment( int align )
179 QGroupBox::setAlignment( align );
185 Sets title of groop box
187 void QtxGroupBox::setTitle( const QString& title )
189 QGroupBox::setTitle( title );
195 Changes the layout of the group box
196 \param strips - number of column/rows
197 \param o - orientation
199 void QtxGroupBox::setColumnLayout( int strips, Orientation o )
202 myContainer->reparent( 0, QPoint( 0, 0 ), false );
204 QGroupBox::setColumnLayout( strips, o );
207 myContainer->reparent( this, QPoint( 0, 0 ), false );
215 void QtxGroupBox::show()
225 void QtxGroupBox::update()
233 \return the recommended size for the widget
235 QSize QtxGroupBox::sizeHint() const
237 QSize sz = QGroupBox::sizeHint();
239 int sw = titleSize().width();
243 if ( alignment() == AlignCenter )
244 sw += 2 * ( myContainer->width() + 5 );
246 sw += 1 * ( myContainer->width() + 5 );
249 sw += frameRect().left();
251 return QSize( QMAX( sz.width(), sw ), sz.height() );
255 \return the recommended minimum size for the widget
257 QSize QtxGroupBox::minimumSizeHint() const
259 QSize sz = QGroupBox::minimumSizeHint();
261 int sw = titleSize().width() + myContainer ? myContainer->width() + 5 : 0;
265 if ( alignment() == AlignCenter )
266 sw += 2 * ( myContainer->width() + 5 );
268 sw += 1 * ( myContainer->width() + 5 );
271 sw += frameRect().left();
273 return QSize( QMAX( sz.width(), sw ), sz.height() );
279 bool QtxGroupBox::eventFilter( QObject* obj, QEvent* e )
281 QEvent::Type type = e->type();
282 if ( myContainer && obj->parent() == myContainer &&
283 ( type == QEvent::Show || type == QEvent::ShowToParent ||
284 type == QEvent::Hide || type == QEvent::HideToParent ) )
285 QApplication::postEvent( this, new QCustomEvent( QEvent::User ) );
287 return QGroupBox::eventFilter( obj, e );
291 Custom resize event filter
293 void QtxGroupBox::resizeEvent( QResizeEvent* e )
295 QGroupBox::resizeEvent( e );
301 Custom child event filter
303 void QtxGroupBox::childEvent( QChildEvent* e )
305 if ( e->type() == QEvent::ChildInserted && e->child() == myContainer )
308 QGroupBox::childEvent( e );
312 Event filter of custom items
314 void QtxGroupBox::customEvent( QCustomEvent* )
322 void QtxGroupBox::frameChanged()
328 \return size of title
330 QSize QtxGroupBox::titleSize() const
337 for ( QLayoutIterator it = layout()->iterator(); it.current() && !si; ++it )
338 si = it.current()->spacerItem();
344 int h = sz.height() + insideMargin();
346 return QSize( w, h );
352 void QtxGroupBox::updateTitle()
357 int align = alignment();
358 if ( align == AlignAuto )
359 align = QApplication::reverseLayout() ? AlignRight : AlignLeft;
361 if ( title().isEmpty() )
364 QSize ts = titleSize();
368 int w = frameRect().width() - ts.width();
369 if ( align == AlignCenter )
374 QApplication::sendPostedEvents( myContainer, QEvent::ChildInserted );
375 myContainer->resize( myContainer->minimumSizeHint() );
378 const QObjectList* list = myContainer->children();
381 for ( QObjectListIt it( *list ); it.current() && !vis; ++it )
382 vis = it.current()->isWidgetType() &&
383 ((QWidget*)it.current())->isVisibleTo( myContainer );
386 if ( myContainer->height() > ts.height() || myContainer->width() > w || !vis )
391 if ( align == AlignRight )
392 x = frameRect().left() + m;
394 x = frameRect().right() - myContainer->width() - m;
396 int y = frameRect().top() - ( myContainer->height() - frameWidth() ) / 2;
398 QPoint pos( x, QMAX( 0, y ) );
399 pos = mapToGlobal( pos );
400 if ( myContainer->parentWidget() )
401 pos = myContainer->parentWidget()->mapFromGlobal( pos );
402 myContainer->move( pos );