Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   Related Pages   Examples  

example5.cpp

Example 5

This example shows:


example5.png


The header file:
#ifndef _EXAMPLE5_H
#define _EXAMPLE5_H

#include <qdbt/qdbttabular.h>

#include <qmainwindow.h>
#include <qmap.h>
#include <qstring.h>

class QdbtTabular;

class QPushButton;
class QPopupMenu;
class QWidget;

class Example5Tabular : public QdbtTabular
{
  Q_OBJECT

  Example5Tabular( const Example5Tabular & );
  void operator=( const Example5Tabular & );

public:
  Example5Tabular( QWidget *parent ) :
    QdbtTabular(parent)
  {
  }
public slots:
  void setYOffset( int offset )
  {
    QdbtTabular::setYOffset( offset );
  }
};


class Example5 : public QMainWindow
{
  Q_OBJECT

  Example5( const Example5 & );
  void operator=( const Example5 & );

public:
  Example5( QWidget *parent = 0, const char *name = 0, WFlags f = 0 );
  ~Example5();
  
private slots:
  void editDone( int row, int col, int action );
  void showIDs();
  void sectionClicked( int section );
  void changeRowState( bool );
  void changeMultiState( bool );
  void changeExtended( bool );
  void changeTraverseRow( bool );
  void changeTraverseCol( bool );
  void changeDeselectState( bool );
  void changeFollowState( bool );
  void clearSet();
  void changeDisEnableState( bool );
  
  void stylePlatinum();
  void styleWindows();
  void styleCDE();
  void styleMotif();

  void slotStyleFactory( int );
  
  void selectStyleMenu( int );
  void showAll();
  
  void trace_sectionClicked( int col );
  void trace_selected( int row, bool state );
  void trace_activated( int row );
  void trace_cellEdited( int row, int col );
  void trace_cellSelected( int row, int col, bool state );
  void trace_cellActivated( int row, int col );
  void trace_cellEditDone( int row, int col, int action,
                           const QString &oldText );
  void trace_yOffsetChanged( int offset );
  void trace_xOffsetChanged( int offset );
  void trace_columnWidthChanged( int col, int width );
  void trace_rightButtonClicked( int row, int col );

  void selMultRow();
  void selSingRow();
  void selMultCell();
  void selFancy();
  
private:
  QString generateName( int i );

  QMap< int, const char * > _editResultMap;
  Example5Tabular *_tabular;
  Example5Tabular *_tabular2;
  QPushButton     *_trace;
  QPushButton     *_multiPB;
  QPushButton     *_extendPB;
  QPushButton     *_deselectPB;
  QPopupMenu      *_popup;
  bool             _showIDs;
  bool             _clearMode;
  int              _id_left;
  int              _id_right;
  int              _id_hide;

#if QT_VERSION >= 300
  int              selectedStyleId;
#else

  int              sPlatinum;
  int              sWindows;
  int              sCDE;
  int              sMotif;
#endif
};

#endif

The source file:

#include <qapplication.h>
#include <qcursor.h>
#include <qlabel.h>
#include <qlayout.h>
#include <qmenubar.h>
#include <qpopupmenu.h>
#include <qpushbutton.h>
#include <qtimer.h>

#include "arrleft.xpm"
#include "arrright.xpm"
#include "example5.h"

#include <qdbt/qdbtsection.h>
#include <qdbt/qdbtselection.h>
#include <qdbt/qdbttabcell.h>
#include <qdbt/qdbttabular.h>

#if QT_VERSION >= 300
#include <qstylefactory.h>
#else
#include <qcdestyle.h>
#include <qmotifstyle.h>
#include <qplatinumstyle.h>
#include <qwindowsstyle.h>
#endif

const int rowCount = 80;
const int colCount = 8;

class Example5CustomSelection : public QdbtRowSelection
{
  bool _fancyMode;
  int  _beginFancyRow;
  int  _beginFancyCol;
  int  _endFancyRow;
  int  _endFancyCol;
public:
  Example5CustomSelection( QdbtBaseTabular * );
  virtual ~Example5CustomSelection();

  virtual bool cellSelected( int row, int col );
  virtual bool cellSelectable( int row, int col );
  virtual void setCellSelected( int row, int col, bool sel );
  virtual void setCellSelectable( int row, int col, bool sel );

  virtual void tableChanged( change_t op, int row, int col );
  virtual void keyEvent( QKeyEvent &, int row, int col );
  virtual void mouseEvent( QMouseEvent &, int row, int col );
protected:
  void redrawArea( int, int );
};


Example5CustomSelection::Example5CustomSelection( QdbtBaseTabular *context ) :
  QdbtRowSelection( context ),
  _fancyMode( FALSE ),
  _beginFancyRow( 0 ),
  _beginFancyCol( 0 ),
  _endFancyRow( 0 ),
  _endFancyCol( 0 )
{
  tableChanged( DIMENSION_SET,
                QdbtSelection::context()->numRows(),
                QdbtSelection::context()->numCols() );
}

Example5CustomSelection::~Example5CustomSelection()
{
}

bool Example5CustomSelection::cellSelected( int row, int col )
{
  if ( !_fancyMode )
    return QdbtRowSelection::cellSelected( row, col );

  if ( col != 1 && col != 2 )
    return FALSE;
  
  int srow = QMIN( _beginFancyRow, _endFancyRow );
  int erow = QMAX( _beginFancyRow, _endFancyRow );
  int scol = _beginFancyRow == srow ? _beginFancyCol : _endFancyCol;
  int ecol = _endFancyRow == erow ? _endFancyCol : _beginFancyCol;
    
  if ( row < srow || row > erow )
  {
    return FALSE;
  }
  else if ( row == srow && row == erow )
  {
    return col == scol || col == ecol;
  }
  else if ( row == srow )
  {
    if ( col == 1 )
      return scol == 1;
    return TRUE;
  }
  else if ( row == erow )
  {
    if ( col == 2 )
      return ecol == 2;
    return TRUE;
  }
  
  return TRUE;
}

bool Example5CustomSelection::cellSelectable( int row, int col )
{
  if ( !_fancyMode )
    return QdbtRowSelection::cellSelectable( row, col );

  // todo
  return TRUE;
}

void Example5CustomSelection::setCellSelected( int row, int col, bool sel )
{
  if ( !_fancyMode )
  {
    QdbtRowSelection::setCellSelected( row, col, sel );
  }
  else
  {
  }
  // todo
  
}

void Example5CustomSelection::setCellSelectable( int /*row*/, int /*col*/,
                                            bool /*sel*/ )
{
  // ignored!
}
    

void Example5CustomSelection::tableChanged( change_t op, int row, int col )
{
  QdbtRowSelection::tableChanged( op, row, col );
}

void Example5CustomSelection::keyEvent( QKeyEvent &e, int row, int col )
{
  QdbtRowSelection::keyEvent( e, row, col );
}

void Example5CustomSelection::mouseEvent( QMouseEvent &e, int row, int col )
{
  if ( e.type() == QEvent::MouseButtonPress )
  {
    if ( e.button() & Qt::LeftButton )
    {
      if ( col == 1 || col == 2 )
      {
        _fancyMode = TRUE;
        _beginFancyRow = row;
        _beginFancyCol = col;
        _endFancyRow = row;
        _endFancyCol = col;

        QTimer::singleShot( 0, context(), SLOT( update() ) );
//        qDebug( "mouse button pressed at %i, %i", row, col );
      }
      else
      {
        _fancyMode = FALSE;
        QdbtRowSelection::mouseEvent( e, row, col );
        QTimer::singleShot( 0, context(), SLOT( update() ) );
      }
    }
  }
  else if ( e.type() == QEvent::MouseButtonRelease )
  {
    if ( e.button() & Qt::LeftButton )
    {
      if ( _fancyMode )
      {
        _endFancyRow = row;
        _endFancyCol = col;
//        qDebug( "mouse button released at %i, %i", row, col );
        redrawArea( _beginFancyRow, _endFancyRow );
      }
      else
      {
        QdbtRowSelection::mouseEvent( e, row, col );
      }
    }
  }
  else if ( e.type() == QEvent::MouseButtonDblClick )
  {
    if ( e.button() & Qt::LeftButton )
    {
      if ( _fancyMode )
      {
        qDebug( "mouse double clicked pressed at %i, %i", row, col );
      }
      else
      {
        QdbtRowSelection::mouseEvent( e, row, col );
      }
    }
  }
  else if ( e.type() == QEvent::MouseMove )
  {
    if ( e.state() & Qt::LeftButton )
    {
      if ( _fancyMode )
      {
        int row1 = _endFancyRow;
        _endFancyRow = row;
        _endFancyCol = col;

        redrawArea( row1, _endFancyRow );
//        qDebug( "mouse moved to %i, %i", row, col );
      }
      else
      {
        QdbtRowSelection::mouseEvent( e, row, col );
      }
    }
  }

}

void Example5CustomSelection::redrawArea( int row1, int row2 )
{
  int i;
  for ( i = QMIN( row1, row2 ); i <= QMAX( row1, row2 ); i++ )
  {
    repaintCell( i, 1 );
    repaintCell( i, 2 );
  }
}


Example5::Example5( QWidget *parent, const char *name, WFlags f ) :
  QMainWindow( parent, name, f ),
  _tabular( 0 ),
  _tabular2( 0 ),
  _trace( 0 ),
  _multiPB( 0 ),
  _extendPB( 0 ),
  _deselectPB( 0 ),
  _popup( 0 ),
  _showIDs( FALSE ),
  _clearMode( FALSE ),
  _id_left( 0 ),
  _id_right( 0 ),
  _id_hide( 0 ),
#if QT_VERSION >= 300
  selectedStyleId( -1 )
#else
  sPlatinum( 0 ),
  sWindows( 0 ),
  sCDE( 0 ),
  sMotif( 0 )
#endif
{
  _editResultMap[ QdbtBaseTabular::NotChanged ] = "NotChanged";
  _editResultMap[ QdbtBaseTabular::Changed ] = "Changed";
  _editResultMap[ QdbtBaseTabular::EditESCed ] = "EditESCed";
  _editResultMap[ QdbtBaseTabular::LoseFocus ] = "LoseFocus";
  
  QPopupMenu *style = new QPopupMenu( this );
  style->setCheckable( TRUE );
  menuBar()->insertItem( "&Style", style );
  

#if QT_VERSION >= 300
  QStringList str = QStyleFactory::keys();

  QStringList::Iterator it = str.begin();
  while ( it != str.end() )
  {
    selectedStyleId = style->insertItem( *it, this,
                                         SLOT( slotStyleFactory( int ) ) );
    ++it;
  }
  slotStyleFactory( selectedStyleId );
#else
  sPlatinum = style->insertItem( "&Platinum", this, SLOT( stylePlatinum() ) );
  sWindows = style->insertItem( "&Windows", this, SLOT( styleWindows() ) );
  sCDE = style->insertItem( "&CDE", this, SLOT( styleCDE() ) );
  sMotif = style->insertItem( "M&otif", this, SLOT( styleMotif() ) );
  styleMotif();
#endif
  style->insertSeparator();
  style->insertItem( "Show All", this, SLOT( showAll() ) );
  style->insertSeparator();
  style->insertItem( "&Quit", qApp, SLOT( quit() ), CTRL | Key_Q );


  QPopupMenu *selections = new QPopupMenu( this );
  menuBar()->insertItem( "Se&lection", selections );
  selections->insertItem( "Row selection, multiple",
                          this, SLOT( selMultRow() ) );
  selections->insertItem( "Row selection, single",
                          this, SLOT( selSingRow() ) );
  selections->insertItem( "Cell selection, multiple",
                          this, SLOT( selMultCell() ) );
  selections->insertSeparator();
  selections->insertItem( "Fancy selection mode",
                          this, SLOT( selFancy() ) );

  // Set the caption of the window
  setCaption( "Example 5" );

  // The Layout managers
  QWidget     *wid = new QWidget( this );
  setCentralWidget( wid );
  QGridLayout *layout   = new QGridLayout( wid, 4, 1, 5 );
  QBoxLayout  *buttons  = new QBoxLayout( QBoxLayout::LeftToRight );
  QBoxLayout  *buttons2 = new QBoxLayout( QBoxLayout::LeftToRight );
  
  // Create a new QdbtTabular object
  QHBoxLayout *hlay = new QHBoxLayout( 0, 2, 10, "hlayout" );
  _tabular  = new Example5Tabular( wid );
  _tabular2 = new Example5Tabular( wid );

  // Set the minimal widget size
  _tabular->setMinimumSize( 300, 100 );
  _tabular2->setMinimumSize( 60, 100 );

  // set the initial table size (this is faster than
  // inserting the columns and rows one by one
  _tabular->setDimensions( rowCount, colCount );
  _tabular2->setDimensions( rowCount, 1 );

  _tabular->selectByRow( TRUE );
  _tabular2->selectByRow( TRUE );
  _tabular->setMultiSelect( FALSE );
  _tabular2->setMultiSelect( FALSE );
  _tabular->setAllowDeselect( FALSE );
  _tabular2->setAllowDeselect( FALSE );

  int i;
  for ( i = 0; i < rowCount; i++ )
  {
    _tabular2->changeCell( QString::number( i ), i, 0 );
    for ( int j = 0; j < colCount; j++ )
    {
      QString name, size;
      if ( j == 0 )
      {
        name.sprintf( "+%i", i );
      }
      else if ( j == 1 )
      {
        name.sprintf( "-0.%i", i );
      }
      else if ( j >= 2 )
        name.sprintf( "%i@%i", i, j );

      QdbtTableCell cell;

      // define a cell `cell'
      cell.setText( name );
      cell.setEditable( TRUE );
      cell.setAlignment( AlignLeft );
      cell.setBorderMode( (j>1 ? QdbtTableCell::LeftBorder  : 0) |
                          (j>0 ? QdbtTableCell::RightBorder : 0)   );
      // let cell (i,0) be a (deep) copy of `cell' 
      _tabular->changeCell( &cell, i, j );
    }
  }

  QdbtSection *sec = _tabular2->section( 0 );
  sec->setText( "Row" );

  for ( i = 0; i < colCount; i++ )
  {
    QdbtSection *sec = _tabular->section( i );
    sec->setText( generateName( i ) );
    _tabular->setColumnWidth( i, _tabular->columnWidthHint( i ) );
    _tabular->setColumnIdentifier( i, 1 << i );
  }

  _tabular->setColumnPattern( 0, "^[+-]?[0-9]+$" );
  _tabular->setColumnPattern( 1, "^[+-]?[0-9]*\\.?[0-9]*$" );

  _tabular->setHeaderAppearance( QdbtTabular::MODE_QLISTVIEW );
  _tabular2->setHeaderAppearance( QdbtTabular::MODE_QLISTVIEW );
  connect( _tabular, SIGNAL( cellEditDone( int, int, int, const QString & ) ),
            this, SLOT( editDone( int, int, int ) ) );
  connect( _tabular, SIGNAL(sectionClicked(int)),
           this, SLOT( sectionClicked( int ) )  );
  connect( _tabular2, SIGNAL( yOffsetChanged( int ) ),
           _tabular, SLOT( setYOffset( int ) ) );

  _tabular->fitAll();
  _tabular2->fitAll();

  // Create the control button
  QPushButton *able   = new QPushButton( "Dis/Enable", wid );
  QPushButton *clr    = new QPushButton( "Clear/Set", wid );
  QPushButton *tr     = new QPushButton( "Row Jail", wid );
  QPushButton *tc     = new QPushButton( "Col Jail", wid );
  QPushButton *follow = new QPushButton( "Follow", wid );
  _deselectPB         = new QPushButton( "Deselect", wid );
  QPushButton *row    = new QPushButton( "Row", wid );
  _multiPB            = new QPushButton( "Multi", wid );
  _extendPB           = new QPushButton( "Extended", wid );

  QPushButton *id     = new QPushButton( "Identifiers", wid );
  _trace              = new QPushButton( "Trace Signals", wid );

  QPushButton *close  = new QPushButton( "Close", wid );

  // Set their minimum sizes
 close       ->setMinimumSize( close->sizeHint() );
  _trace     ->setMinimumSize( _trace->sizeHint() );
  id         ->setMinimumSize( id->sizeHint() );
  _multiPB   ->setMinimumSize( _multiPB->sizeHint() );
  _extendPB  ->setMinimumSize( _extendPB->sizeHint() );
  row        ->setMinimumSize( row->sizeHint() );
  follow     ->setMinimumSize( follow->sizeHint() );
  _deselectPB->setMinimumSize( _deselectPB->sizeHint() );
  tc         ->setMinimumSize( tc->sizeHint() );
  tr         ->setMinimumSize( tr->sizeHint() );
  clr        ->setMinimumSize( clr->sizeHint() );
  able       ->setMinimumSize( able->sizeHint() );

  _trace->setToggleButton( TRUE );
  _trace->setOn( FALSE );

  _multiPB->setToggleButton( TRUE );
  _multiPB->setOn( FALSE );
  connect( _multiPB, SIGNAL( toggled( bool ) ),
           this, SLOT( changeMultiState( bool ) ) );

  _extendPB->setToggleButton( TRUE );
  _extendPB->setOn( FALSE );
  connect( _extendPB, SIGNAL(toggled(bool)),
           this, SLOT(changeExtended(bool)) );

  row->setToggleButton( TRUE );
  row->setOn( TRUE );
  connect( row, SIGNAL(toggled(bool)),
           this, SLOT(changeRowState(bool)) );

  _deselectPB->setToggleButton( TRUE );
  _deselectPB->setOn( FALSE );
  connect( _deselectPB, SIGNAL(toggled(bool)),
           this, SLOT(changeDeselectState(bool)) );

  follow->setToggleButton( TRUE );
  follow->setOn( FALSE );
  connect( follow, SIGNAL(toggled(bool)),
           this, SLOT(changeFollowState(bool)) );

  tr->setToggleButton( TRUE );
  connect( tr, SIGNAL(toggled(bool)),
           this, SLOT(changeTraverseRow(bool)) );

  tc->setToggleButton( TRUE );
  connect( tc, SIGNAL(toggled(bool)),
           this, SLOT(changeTraverseCol(bool)) );


  able->setToggleButton( TRUE );
  able->setOn( TRUE );
  connect( able, SIGNAL(toggled( bool )),
           this, SLOT(changeDisEnableState( bool )) );

  hlay->addWidget( _tabular2, 0 );
  hlay->addWidget( _tabular, 1 );
  
  // Add Widgets and layouts to the layout-manager
  layout->addLayout( hlay, 0, 0 );
  layout->addLayout( buttons, 2, 0 );
  layout->addLayout( buttons2, 3, 0 );
  layout->setColStretch( 0, 1 ); // make the table strechable
  layout->setRowStretch( 0, 1 );

  // Add Widgets to the button layout
  buttons->addStretch( 1 );
  buttons->addWidget( tc );
  buttons->addWidget( tr );
  buttons->addWidget( follow );
  buttons->addWidget( _deselectPB );
  buttons->addWidget( row );
  buttons->addWidget( _multiPB );
  buttons->addWidget( _extendPB );

  buttons2->addWidget( _trace );
  buttons2->addStretch( 1 );
  buttons2->addWidget( clr );
  buttons2->addWidget( able );
  buttons2->addWidget( id );
  buttons2->addWidget( close );

  // don't forget to activate the top layout manager
  layout->activate();

  // Let the close button quit the application
  connect( close,  SIGNAL(clicked()), qApp, SLOT(quit()) );
  connect( id, SIGNAL(clicked()), this, SLOT(showIDs()) );
  connect( clr, SIGNAL(clicked()), this, SLOT(clearSet()) );
  // Resize the widget to its minimal size
  resize( layout->mainWidget()->sizeHint() );

  _popup    = new QPopupMenu( wid );
  _id_left  = _popup->insertItem( QPixmap( arrleft_xpm ), "Move left" );
  _id_right = _popup->insertItem( QPixmap( arrright_xpm ), "Move right" );
  _id_hide  = _popup->insertItem( "Hide column" );

  resize( 400, 400 );

  stylePlatinum();

  QdbtTabular *t = _tabular;
  connect( t, SIGNAL(sectionClicked( int )),
           this, SLOT(trace_sectionClicked( int )) );
  connect( t, SIGNAL(selected( int, bool )),
           this, SLOT(trace_selected( int, bool )) );
  connect( t, SIGNAL(activated( int )),
           this, SLOT(trace_activated( int )) );
  connect( t, SIGNAL(cellEdited( int, int )),
           this, SLOT(trace_cellEdited( int, int )) );
  connect( t, SIGNAL(cellSelected( int, int, bool )),
           this, SLOT(trace_cellSelected( int, int, bool )) );
  connect( t, SIGNAL(cellActivated( int, int )),
           this, SLOT(trace_cellActivated( int, int )) );
  connect( t, SIGNAL(cellEditDone( int, int, int, const QString & )),
           this, SLOT(trace_cellEditDone( int, int, int, const QString &) ) );
  connect( t, SIGNAL(yOffsetChanged( int )),
           this, SLOT(trace_yOffsetChanged( int )) );
  connect( t, SIGNAL(xOffsetChanged( int )),
           this, SLOT(trace_xOffsetChanged( int )) );
  connect( t, SIGNAL(columnWidthChanged( int, int )),
           this, SLOT(trace_columnWidthChanged( int, int )) );
  connect( t, SIGNAL(rightButtonClicked( int, int )),
           this, SLOT(trace_rightButtonClicked( int, int )) );

  _tabular->setScrollbarVisible( TRUE, FALSE );
}

Example5::~Example5()
{
}

void Example5::editDone( int row, int col, int action )
{
  //  qDebug("editDone(%i,%i,%i)",row,col,action);

  if ( col == _tabular->numCols()-1 && action == QdbtTabular::Changed )
  {
    col++;
    _tabular->insertCol();
    for ( int j = 0; j < rowCount; j++ )
    {
      QString name;
      name.sprintf( "%i@%i", j, col );
      QdbtTableCell cell;
      
      // define a cell `cell'
      cell.setText( name );
      cell.setEditable( TRUE );
      cell.setAlignment( AlignLeft );
      cell.setBorderMode( QdbtTableCell::LeftBorder|
                          QdbtTableCell::RightBorder );
      // let cell (i,0) be a (deep) copy of `cell' 
      _tabular->changeCell( &cell, j, col );
    }
    QdbtSection *sec = _tabular->section( col );
    _tabular->setColumnIdentifier( col, 1 << col );
    sec->setText( generateName( col ) );
    _tabular->setColumnWidth( col, _tabular->columnWidthHint(col) );
  }

  if ( action == QdbtTabular::EditESCed && col >= 2 )
  {
    _tabular->editCell( (row+1)%_tabular->numRows(), col, TRUE );
  }

  //  int r,c;
  //  bool v = _tabular->currentKeyboardFocus(r,c);
  //  qDebug("%i R%i C%i",v,r,c);
}

void Example5::showIDs()
{
  _showIDs = !_showIDs;

  int i;
  _tabular->setAutoUpdate( FALSE );
  for ( i = 0; i < _tabular->numCols(); i++ )
  {
    QdbtSection *sec = new QdbtSection( _tabular );
    sec->setText( generateName( i ) );
    _tabular->changeSection( sec, i );
  }
  _tabular->setAutoUpdate( TRUE );
  _tabular->update();
}

QString Example5::generateName( int i )
{
  QString name;
  if ( i == 0 )
    return QString("INTEGER");
  else if ( i == 1 )
    return QString("FLOAT");

  if ( _showIDs )
    name.sprintf( "0x%04X", _tabular->columnIdentifier( i ) );
  else
    name.sprintf( "Col %2i", i );

  return name;
}

void Example5::sectionClicked( int section )
{
  //  int r,c;
  //  bool v = _tabular->currentKeyboardFocus(r,c);
  //  qDebug("%i R%i C%i",v,r,c);

  if ( section <= 1 )
    return;

  _popup->setItemEnabled( _id_left,  section > 2 );
  _popup->setItemEnabled( _id_right, section < _tabular->numCols()-1 );
  int sel = _popup->exec( QCursor::pos() );

  // Dirty, but it deselects the pressed QdbtSection ;)
  _tabular->section( section )->setEnabled(FALSE);
  _tabular->section( section )->setEnabled(TRUE);

  if ( sel == _id_left )
  {
    _tabular->exchangeCols( section, section-1 );
  }
  else if ( sel == _id_right )
  {
    _tabular->exchangeCols( section, section+1 );
  }
  else if ( sel == _id_hide )
  {
    _tabular->setColumnVisible( section, FALSE );
  }
}

void Example5::changeRowState( bool state )
{
  //  qDebug("crs %i",state);
  _tabular->selectByRow( state );
  _tabular->update();
}

void Example5::changeMultiState( bool state )
{
  //  qDebug("cms %i",state);
  _tabular->setMultiSelect( state );
  if ( !state )
  {
    _extendPB->setOn( FALSE );
    _tabular->modifyConfiguration(
      QdbtBaseTabular::SELECT_NONE,
      QdbtBaseTabular::CLEAR_SELECTION_UNLESS_CTRL );
    _tabular->modifyConfiguration(
      QdbtBaseTabular::SELECT_NONE,
      QdbtBaseTabular::SHIFT_CLICK_MARKS_REGION );
  }
}

void Example5::changeExtended( bool state )
{
  if ( state )
  {
    _multiPB->setOn( TRUE );
    _deselectPB->setOn( TRUE );

    _tabular->setAllowDeselect( TRUE );
    _tabular->setMultiSelect( TRUE );
    _tabular->modifyConfiguration(
      QdbtBaseTabular::CLEAR_SELECTION_UNLESS_CTRL,
      QdbtBaseTabular::SELECT_NONE );
    _tabular->modifyConfiguration(
      QdbtBaseTabular::SHIFT_CLICK_MARKS_REGION,
      QdbtBaseTabular::SELECT_NONE );
  }
  else
  {
    _tabular->modifyConfiguration(
      QdbtBaseTabular::SELECT_NONE,
      QdbtBaseTabular::CLEAR_SELECTION_UNLESS_CTRL );
    _tabular->modifyConfiguration(
      QdbtBaseTabular::SELECT_NONE,
      QdbtBaseTabular::SHIFT_CLICK_MARKS_REGION );
  }
}

void Example5::changeDeselectState( bool state )
{
  _tabular->setAllowDeselect( state );
  if ( !state )
  {
    _extendPB->setOn( FALSE );
    _tabular->modifyConfiguration(
      QdbtBaseTabular::SELECT_NONE,
      QdbtBaseTabular::CLEAR_SELECTION_UNLESS_CTRL );
    _tabular->modifyConfiguration(
      QdbtBaseTabular::SELECT_NONE,
      QdbtBaseTabular::SHIFT_CLICK_MARKS_REGION );
  }
}

void Example5::changeFollowState( bool state )
{
  _tabular->setFollowKeyboardFocus( state );
}

void Example5::changeTraverseRow( bool state )
{
  _tabular->setTraverseMode(
    _tabular->traverseMode() & ~QdbtTabular::TRAV_LOCK_ROW |
    (state ? QdbtTabular::TRAV_LOCK_ROW : 0 ) );
}

void Example5::changeTraverseCol( bool state )
{
  _tabular->setTraverseMode(
    _tabular->traverseMode() & ~QdbtTabular::TRAV_LOCK_COL |
    (state ? QdbtTabular::TRAV_LOCK_COL : 0 ) );
}

void Example5::changeDisEnableState( bool state )
{
  _tabular->setEnabled( state );
}

void Example5::clearSet()
{
  _tabular->clearSelection( _clearMode );
  _clearMode = !_clearMode;
}

void Example5::stylePlatinum()
{
#if QT_VERSION >= 300
#else
  qApp->setStyle( new QPlatinumStyle );
  selectStyleMenu( sPlatinum );
#endif
}

void Example5::styleWindows()
{
#if QT_VERSION >= 300
#else
  qApp->setStyle( new QWindowsStyle );
  selectStyleMenu( sWindows );
#endif
}

void Example5::styleCDE()
{
#if QT_VERSION >= 300
#else
  qApp->setStyle( new QCDEStyle( TRUE ) );
  selectStyleMenu( sCDE );
#endif
}

void Example5::styleMotif()
{
#if QT_VERSION >= 300
#else
  qApp->setStyle( new QMotifStyle( TRUE ) );
  selectStyleMenu( sMotif );
#endif
}

void Example5::showAll()
{
  int i;
  for ( i = 0; i<_tabular->numCols(); i++ )
  {
    _tabular->setColumnVisible( i, TRUE );
  }
}

void Example5::selectStyleMenu( int s )
{
#if QT_VERSION >= 300
#else
  menuBar()->setItemChecked( sPlatinum, FALSE );
  menuBar()->setItemChecked( sWindows, FALSE );
  menuBar()->setItemChecked( sCDE, FALSE );
  menuBar()->setItemChecked( sMotif, FALSE );
  menuBar()->setItemChecked( s, TRUE );
#endif
}

void Example5::trace_sectionClicked( int col )
{
  if ( _trace->isOn() )
  {
    qDebug( "sectionClicked(%i)", col );
  }
}

void Example5::trace_selected( int row, bool state )
{
  if ( _trace->isOn() )
  {
    qDebug( "selected(%i,%i)", row, state );
  }
}

void Example5::trace_activated( int row )
{
  if ( _trace->isOn() )
  {
    qDebug( "activated(%i)", row );
  }
}

void Example5::trace_cellEdited( int row, int col )
{
  if ( _trace->isOn() )
  {
    qDebug( "cellEdited(%i,%i)", row, col );
  }
}

void Example5::trace_cellSelected( int row, int col, bool state )
{
  if ( _trace->isOn() )
  {
    qDebug( "cellSelected(%i,%i,%i)", row, col, state );
  }
}

void Example5::trace_cellActivated( int row, int col )
{
  if ( _trace->isOn() )
  {
    qDebug( "cellActivated(%i,%i)", row, col );
  }
}

void Example5::trace_cellEditDone( int row, int col, int action,
                                  const QString &oldText )
{
  if ( _trace->isOn() )
  {
    const char * actionText = "";
    if ( _editResultMap.contains( action ) )
    {
      actionText = _editResultMap[ action ];
    }
    qDebug( "cellEditDone(%i,%i,%i (%s),\"%s)\"",
            row, col, action, actionText, oldText.latin1() );
  }
}

void Example5::trace_yOffsetChanged( int offset )
{
  if ( _trace->isOn() )
  {
    qDebug( "yOffsetChanged(%i)", offset );
  }
}

void Example5::trace_xOffsetChanged( int offset )
{
  if ( _trace->isOn() )
  {
    qDebug( "xOffsetChanged(%i)", offset );
  }
}

void Example5::trace_columnWidthChanged( int col, int width )
{
  if ( _trace->isOn() )
  {
    qDebug( "columnWidthChanged(%i,%i)", col, width );
  }
}

void Example5::trace_rightButtonClicked( int row, int col )
{
  if ( _trace->isOn() )
  {
    qDebug( "rightButtonClicked(%i,%i)", row, col );
  }
}

void Example5::selMultRow()
{
  ( new QdbtRowSelection( _tabular ) )->tableChanged(
    QdbtSelection::DIMENSION_SET, _tabular->numRows(), _tabular->numCols() );
}

void Example5::selSingRow()
{
  ( new QdbtSingleRowSelection( _tabular ) )->tableChanged(
    QdbtSelection::DIMENSION_SET, _tabular->numRows(), _tabular->numCols() );
}

void Example5::selMultCell()
{
  ( new QdbtCellSelection( _tabular ) )->tableChanged(
      QdbtSelection::DIMENSION_SET, _tabular->numRows(), _tabular->numCols() );
}


void Example5::selFancy()
{
  ( new Example5CustomSelection( _tabular ) )->tableChanged(
      QdbtSelection::DIMENSION_SET, _tabular->numRows(), _tabular->numCols() );
}

void Example5::slotStyleFactory( int id )
{
  QString styleText = menuBar()->text( id );
#if QT_VERSION >= 300
  qApp->setStyle( QStyleFactory::create( styleText ) );
  menuBar()->setItemChecked( selectedStyleId, FALSE );
  menuBar()->setItemChecked( id, TRUE );
  selectedStyleId = id;
#else
  qFatal( "This function is implemented for Qt >= 3.0 only!" );
#endif
}


int main( int argc, char **argv )
{
  QApplication app( argc, argv );

  QPalette pal = qApp->palette();
  pal.setColor( QPalette::Normal, QColorGroup::Base,
                QColor( 0xd0, 0xd0, 0xd0 ) );
  pal.setColor( QPalette::Active, QColorGroup::Base,
                QColor( 0xd0, 0xd0, 0xd0 ) );
  pal.setColor( QPalette::Active, QColorGroup::Highlight, Qt::darkGreen );
  pal.setColor( QPalette::Disabled, QColorGroup::Highlight, Qt::gray );
  pal.setColor( QPalette::Normal, QColorGroup::Highlight, Qt::darkBlue );
  qApp->setPalette( pal, TRUE );

  Example5 example;
  app.setMainWidget( &example );
  qApp->setPalette( pal, TRUE );
  example.show();
  return app.exec();  
}

Generated on Mon Apr 22 12:21:53 2002 for QdbtTabular by doxygen1.2.15-20020421