Source Code (Use browser search to find items of interest.)

Class Index

kdelibs'KDockTabBar (./kdelibs/kdeui/kdocktabctl.h:57)

class KDockTabBar : public QWidget
{
  Q_OBJECT
  
  friend KDockTabBarPainter;

public:
  
  /**
   * Constructs a tab bar widget.
   * The parent and name argument are sent to the QWidget constructor.
   */
  KDockTabBar( QWidget * parent = 0, const char * name = 0 );

  /**
   * Destructs this.
   */
  ~KDockTabBar();

  /**
   * For clearer setting (or asking for) the current tab page position.
   */
  enum TabPos
  {
    TAB_TOP,
    TAB_RIGHT
  };

  /**
   * Sets the position to tabpos and repaints this.
   * @param tabpos either TAB_TOP or TAB_RIGHT, just where you want it to be
   */
  void setTabPos( TabPos tabpos);

  /**
   * Inserts a new empty tab page to the tab bar.
   * If id is not specified, the tab is simply added. Otherwise it's inserted at the specified position.
   *
   * @param label the title in the tab page header
   * @param id an identification number for access operations
   * @return the new allocated id
   */
  int insertTab( const QString &label, int id = -1 );

  /**
   * Sets an icon for the tab page with that id.
   *
   * @param id the identification number of that desired page
   * @param pix the new pixmap
   */
  void setPixmap( int id, const QPixmap &pix );

  /**
   * Sets the text colour for the tab page with that id.
   *
   * @param id the identification number of that desired page
   * @param color the new text colour
   */
  void setTextColor( int id, const QColor &color );

  /**
   * Returns the text colour for the tab page with that id.
   *
   * @param id the identification number of that desired tab page
   * @return the current text colour of that tab page
   */
  const QColor& textColor( int id );

  /**
   * Removes the tab page with that id.
   *
   * @param id the identification number of that desired page
   */
  void removeTab( int id);

  /**
   * Returns the current tab page.
   *
   * @return the id of the tab page
   */
  int  currentTab(){ return _currentTab; }

  /**
   * Sets the current tab page to the page with that id.
   *
   * @param id the identification number of that desired page
   * @param allowDisable disables the tab page
   */
  void setCurrentTab( int id, bool allowDisable = false );

  /**
   * Enables or disables the tab page with that id.
   */
  void setTabEnabled( int id, bool e);

  /**
   * Returns if the tab page with that id is enabled or disabled.
   */
  bool isTabEnabled( int id);

  /**
   * Sets the title of the tab page with that id.
   *
   * @param id the identification number of that desired page
   * @param caption a string for the title
   */
  void setTabCaption( int id, const QString &caption );

  /**
   * Returns the title of the tab page with that id.
   *
   * @param id the identification number of that desired page
   */
  QString tabCaption( int id );

  /**
   * Calls QWidget::show() and showPage(..) for the current tab page, additionally.
   */
  virtual void show();

  /**
   * Sets the font of this.
   */
  virtual void setFont( const QFont & );

  /**
   * Shows or Hides the icons for the tab pages in the header.
   */
  void showTabIcon( bool );

  /**
   * Returns if the icons for the tab pages are shown in the header.
   */
  bool isShowTabIcon(){ return iconShow; }

signals:

  /**
   * Signals that a tab page with that id is selected.
   *
   * @param id the identification number of that desired page
   */
  void tabSelected( int id);

  /**
   * Signals that the right mouse buttons is pressed on the tab page with that id.
   *
   * @param id the identification number of that desired page
   */
  void rightButtonPress( int id, QPoint );

protected slots:

  /**
   * Does things that should be done if someone has clicked the left mouse button.
   */
  void leftClicked();

  /**
   * Does things that should be done if someone has clicked the right mouse button.
   */
  void rightClicked();

protected:

  /**
   * Handles paint events for this widgets
   * Reimplemented from QWidget
   */
  virtual void paintEvent( QPaintEvent* );

  /**
   * Handles resize events for this widgets
   * Reimplemented from QWidget
   */
  virtual void resizeEvent( QResizeEvent* );

private:
  /** For internal use */
  void setButtonPixmap();
  /** For internal use */
  void updateHeight();

  /** For internal use */
  KDockTabBar_Private* findData( int id );
  /** For internal use */
  int tabsWidth();
  /** For internal use */
  void tabsRecreate();

  TabPos tabPos;
  KDockTabBarPainter* barPainter;
  QList<KDockTabBar_Private> *mainData;
  int _currentTab;
  int leftTab;

  QPixmap* up_xpm;
  QPixmap* down_xpm;
  QPixmap* left_xpm;
  QPixmap* right_xpm;

  QPushButton *right;
  QPushButton *left;
  bool rightscroll;
  bool leftscroll;
  bool iconShow;
};

/**
 * The draw helper for the @ref KDockTabBar (and member of the dockwidget class set).
 * Minor importance for application programmers who uses the dockwidget class set.
 *
 * @author Max Judin (documentation: Falk Brettschneider).
 * @version $Id: kdocktabctl.h,v 1.5 2000/03/28 00:12:35 falkbr Exp $
 */

kdelibs'KDockTabBar::KDockTabBar() (./kdelibs/kdeui/kdocktabctl.cpp:732)

KDockTabBar::KDockTabBar( QWidget * parent, const char * name )
:QWidget( parent, name )
{
  /* Set up bitmaps */
  left_xpm = new QPixmap( b_left_xpm );

  QWMatrix m;
  m.scale( -1, 1 );
  right_xpm = new QPixmap( left_xpm->xForm(m) );

  m.reset();
  m.rotate( 90 );
  down_xpm = new QPixmap( left_xpm->xForm(m) );

  m.reset();
  m.scale( 1, -1 );
  up_xpm = new QPixmap( down_xpm->xForm(m) );
/****************************************************************/

  tabPos = TAB_TOP;
  iconShow = true;

  barPainter = new KDockTabBarPainter( this );
  move( 0, 0 );

  mainData = new QList<KDockTabBar_Private>;
  mainData->setAutoDelete( true );
  _currentTab = -1;
  leftTab = 0;

  left = new QPushButton(this);// left->hide();
  left->setAutoRepeat( true );
  connect( left, SIGNAL(clicked()), SLOT( leftClicked()) );
  right = new QPushButton(this); right->hide();
  right->setAutoRepeat( true );
  connect( right, SIGNAL(clicked()), SLOT( rightClicked()) );

  setFixedHeight( fontMetrics().height() + 10 );

  setButtonPixmap();
}


kdelibs'KDockTabBar::~KDockTabBar() (./kdelibs/kdeui/kdocktabctl.cpp:774)

KDockTabBar::~KDockTabBar()
{
  delete mainData;
}


kdelibs'KDockTabBar::paintEvent() (./kdelibs/kdeui/kdocktabctl.cpp:779)

void KDockTabBar::paintEvent(QPaintEvent *)
{
  QPainter paint;
  paint.begin( this );

  // find current ( selected ) tab data
  KDockTabBar_Private* data = 0L;
  int curx = 2 - barPainter->delta;
  int curWidth = 0;
  for ( uint k = 0; k < mainData->count(); k++ ){
    data = mainData->at(k);
    if ( data->id == _currentTab ){
      curWidth = data->width + 4 ;
      curx -= 2;
      break;
    }
    curx += data->width;
  }

  if ( curWidth == 0 ) curx = 0; // no tab selected

  // paint button line
  switch ( tabPos ){
    case TAB_TOP:
      paint.fillRect( 0, height()-1, width(), 1, QBrush( colorGroup().brush( QColorGroup::Background ) ));
      paint.setPen( colorGroup().light() );
      paint.moveTo( 0, height()-1 );
      paint.lineTo( curx, height()-1 );
      paint.moveTo( QMIN( curx + curWidth, width() - 50 ), height()-1 );
      paint.lineTo( width() - 1, height()-1 );
      break;
    case TAB_RIGHT:
      paint.fillRect( width() - 1, 0, 1, height(), QBrush( colorGroup().brush( QColorGroup::Background ) ));
      curx = height() - curx;
      paint.setPen( colorGroup().dark() );
      paint.drawPoint( width() - 1, height()-1 );

      paint.moveTo( width() - 1, height()-2 );
      paint.setPen( colorGroup().light() );
      if ( curx != height() ) paint.lineTo( width() - 1, curx );
      paint.moveTo( width() - 1, QMAX( curx - curWidth, 50 ) );
      paint.lineTo( width() - 1, 0 );
      break;
  }
  paint.end();
  barPainter->repaint( false );
}


kdelibs'KDockTabBar::insertTab() (./kdelibs/kdeui/kdocktabctl.cpp:827)

int KDockTabBar::insertTab( const QString &label, int id )
{
  if ( id == -1 ){
    id = 0;
    for ( uint k = 0; k < mainData->count(); k++ )
      if ( mainData->at(k)->id > id ) id = mainData->at(k)->id;
  }
  KDockTabBar_Private* data = new KDockTabBar_Private( id, label );
  data->textColor = colorGroup().text();

  data->width = 4 + fontMetrics().width( label ) + 14;
  mainData->append( data );

  resizeEvent(0);
  repaint( false );
  return id;
}


kdelibs'KDockTabBar::showTabIcon() (./kdelibs/kdeui/kdocktabctl.cpp:845)

void KDockTabBar::showTabIcon( bool show )
{
  if ( iconShow == show ) return;
  iconShow = show;
  updateHeight();
  tabsRecreate();
}


kdelibs'KDockTabBar::findData() (./kdelibs/kdeui/kdocktabctl.cpp:853)

KDockTabBar_Private* KDockTabBar::findData( int id )
{
  KDockTabBar_Private* data = 0L;
  for ( uint k = 0; k < mainData->count(); k++ )
    if ( mainData->at(k)->id == id ){
      data = mainData->at(k);
      break;
    }
  return data;
}


kdelibs'KDockTabBar::setPixmap() (./kdelibs/kdeui/kdocktabctl.cpp:864)

void KDockTabBar::setPixmap( int id, const QPixmap &pix )
{
  KDockTabBar_Private* data = findData( id );
  if ( data != 0L ){
    if ( data->pix != 0L ) delete data->pix;
    data->pix = new QPixmap( pix );
    if ( iconShow ) data->width += 16 + 4;
    tabsRecreate();
  }
}


kdelibs'KDockTabBar::setTextColor() (./kdelibs/kdeui/kdocktabctl.cpp:875)

void KDockTabBar::setTextColor( int id, const QColor &color )
{
  KDockTabBar_Private* data = findData( id );
  if ( data != 0L ){
    data->textColor = color;
    repaint( false );
  }
}


kdelibs'KDockTabBar::removeTab() (./kdelibs/kdeui/kdocktabctl.cpp:884)

void KDockTabBar::removeTab( int id )
{
  KDockTabBar_Private* data = findData( id );
  if ( data != 0L ){
    if ( _currentTab == data->id )
    {
      for ( uint k = 0; k < mainData->count(); k++ )
      {
        if ( mainData->at(k)->id == data->id ){
          if ( mainData->count() == 1 ){
            setCurrentTab( -1 );
          } else {
            setCurrentTab( mainData->at(k+1)->id );
          }
          break;
        }

        if ( mainData->at(k+1)->id == data->id ){
          setCurrentTab( mainData->at(k)->id );
          break;
        }
      }
    }
    mainData->remove( data );
    leftTab = QMIN( leftTab, (int)mainData->count() - 1 );

    resizeEvent(0);
    repaint( false );
  }
}


kdelibs'KDockTabBar::setCurrentTab() (./kdelibs/kdeui/kdocktabctl.cpp:915)

void KDockTabBar::setCurrentTab( int id, bool allowDisable )
{
  KDockTabBar_Private* data = findData( id );
  if ( data != 0L )
    if ( (data->enabled || allowDisable ) && _currentTab != data->id )
    {
      _currentTab = data->id;
      repaint( false );

      int curx = 2; // _currentTab start here 
      for ( uint k = 0; k < mainData->count(); k++ ){
        KDockTabBar_Private* data  = mainData->at(k);
        if ( data->id == _currentTab ){
          break;
        }
        curx += data->width;
      }
      // curx : _currentTab start here 
      
      int count;
      switch ( tabPos ){
        case TAB_TOP:
          count = mainData->count();
          while ( count > 0 && -barPainter->delta + curx < 0 ){
            leftClicked();
            count--;
          }
          count = mainData->count();
          while ( count > 0 && -barPainter->delta + curx > width()- 100 ){
            rightClicked();
            count--;
          }
          break;
        case TAB_RIGHT:
          count = mainData->count();
          while ( count > 0 && -barPainter->delta + curx < 0 ){
            leftClicked();
            count--;
          }
          count = mainData->count();
          while ( count > 0 && -barPainter->delta + curx > height() - 100 ){
            rightClicked();
            count--;
          }
          break;
      }
      emit tabSelected( id );
    }
}


kdelibs'KDockTabBar::setTabEnabled() (./kdelibs/kdeui/kdocktabctl.cpp:965)

void KDockTabBar::setTabEnabled( int id , bool enabled )
{
  KDockTabBar_Private* data = findData( id );
  if ( data == 0L ) return;

  if ( data->enabled != enabled )
  {
    data->enabled = enabled;
    if ( _currentTab == data->id ){
      for ( uint k = 0; k < mainData->count(); k++ ){
        if ( mainData->at(k)->enabled ){
          setCurrentTab( mainData->at(k)->id );
          break;
        }
      }
    }
    if ( enabled ){
      data = findData( _currentTab );
      if ( !data->enabled ) setCurrentTab( id );
    }
    repaint( false );
  }
}


kdelibs'KDockTabBar::isTabEnabled() (./kdelibs/kdeui/kdocktabctl.cpp:989)

bool KDockTabBar::isTabEnabled( int id )
{
  KDockTabBar_Private* data = findData( id );
  return data == 0L ? false:data->enabled;
}


kdelibs'KDockTabBar::show() (./kdelibs/kdeui/kdocktabctl.cpp:995)

void KDockTabBar::show()
{
  if ( _currentTab == 0 )
    if ( !mainData->isEmpty() )
      _currentTab = mainData->at(0)->id;

  if ( _currentTab != 0 ){
    setCurrentTab( _currentTab );
  }
  QWidget::show();
}


kdelibs'KDockTabBar::tabsWidth() (./kdelibs/kdeui/kdocktabctl.cpp:1007)

int KDockTabBar::tabsWidth()
{
  int width = 0;
  for ( uint k = 0; k < mainData->count(); k++ ){
    width += mainData->at(k)->width;
  }
  return width == 0 ? 0:width + 4;
}


kdelibs'KDockTabBar::resizeEvent() (./kdelibs/kdeui/kdocktabctl.cpp:1016)

void KDockTabBar::resizeEvent(QResizeEvent *)
{
  int maxAllowWidth = 0;
  int maxAllowHeight = 0;

  /* reset bar position to 0 if it allowed or if _currentTab == -1 ( no current tab ) */
  switch ( tabPos ){
    case TAB_TOP:
      if ( width() - 50 > tabsWidth() || _currentTab == -1 ){
        barPainter->delta = 0;
        leftTab = 0;
      }
      maxAllowWidth = width() - 50 + barPainter->delta;
      barPainter->move( -barPainter->delta, 0 );
      barPainter->resize( QMIN(tabsWidth(),maxAllowWidth),  height() - 1 );
      break;
    case TAB_RIGHT:
      if ( height() - 50 > tabsWidth() || _currentTab == -1 ){
        barPainter->delta = 0;
        leftTab = 0;
      }
      maxAllowHeight = height() - 50 + barPainter->delta;
      barPainter->resize( width() - 1, QMIN(tabsWidth(),maxAllowHeight) );
      barPainter->move( 0, height() - barPainter->height() + barPainter->delta );
      break;
  }

  if ( tabPos == TAB_TOP ){
    int wh = height()-4;//18;
    left->setGeometry( width()-2*wh-2, height()-wh-2, wh, wh );
    right->setGeometry( width()-wh, height()-wh-2, wh, wh );

    if ( barPainter->delta > 0 ||  tabsWidth() > maxAllowWidth ){
      left->show();
      right->show();
    } else {
      left->hide();
      right->hide();
    }
  }

  if ( tabPos == TAB_RIGHT ){
    int wh = width()-4;//18;
    left->setGeometry( width()-wh-2, wh+2, wh, wh );
    right->setGeometry( width()-wh-2, 0, wh, wh );

    if ( barPainter->delta > 0 ||  tabsWidth() > maxAllowHeight ){
      left->show();
      right->show();
    } else {
      left->hide();
      right->hide();
    }
  }
}


kdelibs'KDockTabBar::leftClicked() (./kdelibs/kdeui/kdocktabctl.cpp:1072)

void KDockTabBar::leftClicked()
{
  if ( leftTab > 0 ){
    leftTab--;
    int dx = mainData->at( leftTab )->width;
    barPainter->delta -= dx;
    barPainter->move( barPainter->x() + dx, barPainter->y() );
    resizeEvent(0);
    repaint( false );
  }
}


kdelibs'KDockTabBar::rightClicked() (./kdelibs/kdeui/kdocktabctl.cpp:1084)

void KDockTabBar::rightClicked()
{
  if ( leftTab != (int)mainData->count() - 1 ){
    int dx = mainData->at( leftTab )->width;
    barPainter->delta += dx;
    leftTab++;
    barPainter->move( barPainter->x() - dx, barPainter->y() );
    resizeEvent(0);
    repaint( false );
  }
}


kdelibs'KDockTabBar::setTabPos() (./kdelibs/kdeui/kdocktabctl.cpp:1096)

void KDockTabBar::setTabPos( TabPos pos )
{
  tabPos = pos;
  updateHeight();
  setButtonPixmap();
  tabsRecreate();
}


kdelibs'KDockTabBar::updateHeight() (./kdelibs/kdeui/kdocktabctl.cpp:1104)

void KDockTabBar::updateHeight()
{
  switch ( tabPos ){
    case TAB_TOP:
      setMaximumWidth(32767);
      if ( iconShow )
        setFixedHeight( fontMetrics().height() + 10 );
      else
        setFixedHeight( fontMetrics().height() + 4 );
      break;
    case TAB_RIGHT:
      setMaximumHeight(32767);
      if ( iconShow )
        setFixedWidth( fontMetrics().height() + 10 );
      else
        setFixedWidth( fontMetrics().height() + 4 );
      break;
  }
}


kdelibs'KDockTabBar::setButtonPixmap() (./kdelibs/kdeui/kdocktabctl.cpp:1124)

void KDockTabBar::setButtonPixmap()
{
  switch ( tabPos ){
    case TAB_TOP:
      left->setPixmap( *left_xpm );
      right->setPixmap( *right_xpm );
      break;
    case TAB_RIGHT:
      left->setPixmap( *up_xpm );
      right->setPixmap( *down_xpm );
      break;
  }
}


kdelibs'KDockTabBar::setFont() (./kdelibs/kdeui/kdocktabctl.cpp:1138)

void KDockTabBar::setFont( const QFont &f )
{
  QWidget::setFont( f );
  tabsRecreate();
}


kdelibs'KDockTabBar::setTabCaption() (./kdelibs/kdeui/kdocktabctl.cpp:1144)

void KDockTabBar::setTabCaption( int id, const QString &caption )
{
  KDockTabBar_Private* data = findData( id );
  if ( data != 0L ){
    data->label = caption;
    tabsRecreate();
  }
}


kdelibs'KDockTabBar::tabCaption() (./kdelibs/kdeui/kdocktabctl.cpp:1153)

QString KDockTabBar::tabCaption( int id )
{
  KDockTabBar_Private* data = findData( id );
  return data == 0L ? QString(""):data->label;
}


kdelibs'KDockTabBar::tabsRecreate() (./kdelibs/kdeui/kdocktabctl.cpp:1159)

void KDockTabBar::tabsRecreate()
{
  for ( uint k = 0; k < mainData->count(); k++ ){
    KDockTabBar_Private* data = mainData->at(k);
    data->width = 4 + fontMetrics().width( data->label ) + 14;
    if ( iconShow && data->pix != 0L ) data->width += 16 + 4;
  }
  resizeEvent(0);
  repaint( false );
}


kdelibs'KDockTabBar::textColor() (./kdelibs/kdeui/kdocktabctl.cpp:1170)

const QColor& KDockTabBar::textColor( int id )
{
  KDockTabBar_Private* data = findData( id );
  if ( data != 0L ){
    return data->textColor;
  }
  return Qt::black;
}