Back to index

salome-gui  6.5.0
Public Member Functions | Private Member Functions | Private Attributes
QtxDialog::Area Class Reference

Area containing dialog box buttons. More...

Collaboration diagram for QtxDialog::Area:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 Area (Qt::Orientation, QtxDialog *, QWidget *=0)
 Constructor.
virtual ~Area ()
 Destructor.
bool isBorderEnabled () const
 Check of the border is enabled.
void setBorderEnabled (const bool)
 Enable/disable border (separator between main frame and button frame)
void setBorderWidget (QLabel *)
 Set border widget (separator between main frame and button frame).
void insertButton (QAbstractButton *)
 Insert button to the area.
void removeButton (QAbstractButton *)
 Remove button from the area.
bool contains (QAbstractButton *) const
 Check if area owns the button specified.
int policy () const
 Get buttons layout policy.
void setPolicy (const int)
 Set buttons layout policy.
void layoutButtons ()
 Layout buttons in the area.
const QList< QAbstractButton * > & buttons () const
 Get all area buttons.

Private Member Functions

void updateBorder ()
 Update border visibility.

Private Attributes

QtxDialogmyDlg
 parent dialog box
QLabel * myLine
 border widget
bool myBorder
 "has border" flag
int myPolicy
 button layout type (QtxDialog::PlacePolicy)
QList< QAbstractButton * > myButtons
 buttons list
Qt::Orientation myOrientation
 buttons orientation (Qt::Orientation)

Detailed Description

Area containing dialog box buttons.

Definition at line 42 of file QtxDialog.cxx.


Constructor & Destructor Documentation

QtxDialog::Area::Area ( Qt::Orientation  o,
QtxDialog dlg,
QWidget *  parent = 0 
)

Constructor.

Parameters:
obuttons orientation
dlgdialog box owning this area
parentparent widget

Definition at line 82 of file QtxDialog.cxx.

: QFrame( parent ),
  myDlg( dlg ),
  myLine( 0 ),
  myBorder( false ),
  myPolicy( Position ),
  myOrientation( o )
{
  if ( myOrientation == Qt::Horizontal )
    setSizePolicy( QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum ) );
  else
    setSizePolicy( QSizePolicy( QSizePolicy::Maximum, QSizePolicy::Preferred ) );

  hide();
}
QtxDialog::Area::~Area ( ) [virtual]

Destructor.

Definition at line 101 of file QtxDialog.cxx.

{
}

Member Function Documentation

const QList< QAbstractButton * > & QtxDialog::Area::buttons ( ) const

Get all area buttons.

Returns:
const reference to the list of buttons

Definition at line 227 of file QtxDialog.cxx.

{
  return myButtons;
}
bool QtxDialog::Area::contains ( QAbstractButton *  b) const

Check if area owns the button specified.

Parameters:
bbutton to be checked
Returns:
true if area contains button

Definition at line 158 of file QtxDialog.cxx.

{
  return myButtons.contains( b );
}
void QtxDialog::Area::insertButton ( QAbstractButton *  b)

Insert button to the area.

Parameters:
bbutton to be added
See also:
removeButton()

Definition at line 110 of file QtxDialog.cxx.

{
  if ( !b || myButtons.contains( b ) )
    return;

  QWidget* parent = b->parentWidget();
  if ( parent != this )
    b->setParent( this );

  myButtons.append( b );

  if ( myDlg )
    myDlg->adjustButtons();
  layoutButtons();

  show();

  updateBorder();
}

Check of the border is enabled.

Returns:
true if border is enabled
See also:
setBorderEnabled(), setBorderWidget()

Definition at line 191 of file QtxDialog.cxx.

{
  return myLine && myBorder;
}

Layout buttons in the area.

Definition at line 249 of file QtxDialog.cxx.

{
  int aPolicy = policy();

  QMap<QAbstractButton*, int> buttonId;
  for ( QList<QAbstractButton*>::iterator it1 = myButtons.begin(); it1 != myButtons.end(); ++it1 )
    buttonId.insert( *it1, 0 );

  QList<QAbstractButton*> src;
  for ( ButtonMap::Iterator mit = myDlg->myButton.begin(); mit != myDlg->myButton.end(); ++mit )
  {
    if ( buttonId.contains( mit.value() ) )
    {
      buttonId[mit.value()] = mit.key();
      if ( mit.key() >= 0 )
        src.append( mit.value() );
    }
  }

  for ( QList<QAbstractButton*>::iterator it2 = myButtons.begin(); it2 != myButtons.end(); ++it2 )
  {
    if ( buttonId[*it2] < 0 )
      src.append( *it2 );
  }

  QList<QAbstractButton*> left, right, center, other;
  for ( QList<QAbstractButton*>::iterator it = src.begin(); it != src.end(); ++it )
  {
    if ( !(*it)->isVisibleTo( this ) )
      continue;

    int aPosition = myDlg->buttonPosition( *it );
    if ( aPosition == -1 )
      continue;

    if ( aPolicy != QtxDialog::Position )
      other.append( *it );
    else if ( aPosition == QtxDialog::Left )
      left.append( *it );
    else if ( aPosition == QtxDialog::Right )
      right.append( *it );
    else if ( aPosition == QtxDialog::Center )
      center.append( *it );
  }

  delete layout();

  QBoxLayout* buttonLayout = 0;
  if ( myOrientation == Qt::Vertical )
    buttonLayout = new QVBoxLayout( this );
  else
    buttonLayout = new QHBoxLayout( this );

  if ( !buttonLayout )
    return;

  buttonLayout->setMargin( 0 );
  buttonLayout->setSpacing( 5 );

  if ( aPolicy == QtxDialog::Position )
  {
    for ( QList<QAbstractButton*>::iterator lit = left.begin(); lit != left.end(); ++lit )
      buttonLayout->addWidget( *lit );
    buttonLayout->addStretch( 1 );
    for ( QList<QAbstractButton*>::iterator cit = center.begin(); cit != center.end(); ++cit )
      buttonLayout->addWidget( *cit );
    buttonLayout->addStretch( 1 );
    for ( QList<QAbstractButton*>::iterator rit = right.begin(); rit != right.end(); ++rit )
      buttonLayout->addWidget( *rit );
  }
  else
  {
    for ( int i = 0; i < (int)other.count(); i++ )
    {
      buttonLayout->addWidget( other[i] );
      if ( aPolicy == QtxDialog::Uniform && i < (int)other.count() - 1  )
        buttonLayout->addStretch( 1 );
    }
  }

  QWidgetList wids;
  if ( layout() )
  {
    for ( int i = 0; i < layout()->count(); i++ )
    {
      if ( !layout()->itemAt( i ) || layout()->itemAt( i )->widget() )
        continue;

      if ( QApplication::layoutDirection() == Qt::RightToLeft )
        wids.prepend( layout()->itemAt( i )->widget() );
      else
        wids.append( layout()->itemAt( i )->widget() );
    }
  }
  Qtx::setTabOrder( wids );
}
int QtxDialog::Area::policy ( ) const

Get buttons layout policy.

Returns:
policy of button layouting (Qtx::PlacePolicy)
See also:
setPolicy()

Definition at line 168 of file QtxDialog.cxx.

{
  return myPolicy;
}
void QtxDialog::Area::removeButton ( QAbstractButton *  b)

Remove button from the area.

Parameters:
bbutton to be removed
See also:
insertButton()

Definition at line 135 of file QtxDialog.cxx.

{
  if ( !b )
    return;

  myButtons.removeAll( b );

  if ( myButtons.isEmpty() )
    hide();

  updateBorder();

  if ( myDlg )
    myDlg->adjustButtons();

  layoutButtons();
}

Enable/disable border (separator between main frame and button frame)

Parameters:
onnew state

Definition at line 200 of file QtxDialog.cxx.

{
  if ( !myLine || myBorder == on )
    return;

  myBorder = on;
  updateBorder();
}

Set border widget (separator between main frame and button frame).

Parameters:
linenew separator widget

Definition at line 213 of file QtxDialog.cxx.

{
  if ( myLine == line )
    return;

  delete myLine;
  myLine = line;
  updateBorder();
}
void QtxDialog::Area::setPolicy ( const int  p)

Set buttons layout policy.

Parameters:
pnew policy

Definition at line 177 of file QtxDialog.cxx.

{
  if ( myPolicy == p )
    return;

  myPolicy = p;
  layoutButtons();
}

Update border visibility.

Definition at line 235 of file QtxDialog.cxx.

{
  if ( !myLine )
    return;

  bool isVis = isVisibleTo( parentWidget() );
  myLine->setVisible( isVis );

  myLine->setLineWidth( myBorder ? 1 : 0 );
}

Member Data Documentation

bool QtxDialog::Area::myBorder [private]

"has border" flag

Definition at line 70 of file QtxDialog.cxx.

QList<QAbstractButton*> QtxDialog::Area::myButtons [private]

buttons list

Definition at line 72 of file QtxDialog.cxx.

parent dialog box

Definition at line 68 of file QtxDialog.cxx.

QLabel* QtxDialog::Area::myLine [private]

border widget

Definition at line 69 of file QtxDialog.cxx.

buttons orientation (Qt::Orientation)

Definition at line 73 of file QtxDialog.cxx.

button layout type (QtxDialog::PlacePolicy)

Definition at line 71 of file QtxDialog.cxx.


The documentation for this class was generated from the following file: