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

Class Index

kdelibs'KDockTabBarPainter (./kdelibs/kdeui/kdocktabctl.h:272)

class KDockTabBarPainter : public QWidget
{
  Q_OBJECT
  friend KDockTabBar;

private:
  
  KDockTabBarPainter( KDockTabBar* parent );
  ~KDockTabBarPainter();

  void drawBuffer();
    int findBarByPos( int x, int y );

  QPixmap* buffer;
  int mousePressTab;
  int delta;

protected:
  
  /**
   * Handles mouse press events for this widgets
   * Reimplemented from QWidget
   */
  virtual void mousePressEvent ( QMouseEvent * );
  
  /**
   * Handles mouse release events for this widgets
   * Reimplemented from QWidget
   */
  virtual void mouseReleaseEvent ( QMouseEvent * );

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

/**
 * A manager for a single @ref KDockTabBar  (and member of the dockwidget class set).
 * The @ref KDockWidget class ever use this class instead of accessing the KDockTabBar directly.
 *
 * For some reasons it's more practical for the Dockwidget class set than @ref QTabBar or @ref KTabBar .
 *
 * @author Max Judin (documentation: Falk Brettschneider).
 * @version $Id: kdocktabctl.h,v 1.5 2000/03/28 00:12:35 falkbr Exp $
 */

kdelibs'KDockTabBarPainter::KDockTabBarPainter() (./kdelibs/kdeui/kdocktabctl.cpp:408)

KDockTabBarPainter::KDockTabBarPainter( KDockTabBar* parent )
:QWidget( parent )
{
  delta = 0;
  buffer = new QPixmap(0,0);
}


kdelibs'KDockTabBarPainter::~KDockTabBarPainter() (./kdelibs/kdeui/kdocktabctl.cpp:415)

KDockTabBarPainter::~KDockTabBarPainter()
{
  delete buffer;
}


kdelibs'KDockTabBarPainter::paintEvent() (./kdelibs/kdeui/kdocktabctl.cpp:420)

void KDockTabBarPainter::paintEvent( QPaintEvent* )
{
  if ( buffer->isNull() ) return;
  drawBuffer();

  switch ( ((KDockTabBar*)parent())->tabPos ){
    case KDockTabBar::TAB_TOP:
      bitBlt( this, 0, 0, buffer, 0, 0, width(), height() );
      break;
    case KDockTabBar::TAB_RIGHT:{
      QWMatrix m;
      m.rotate( -90 );
      QPixmap xbuffer = buffer->xForm(m);
      bitBlt( this, 0, 0, &xbuffer, 0, 0, width(), height() );
      break;
    }
  }
}


kdelibs'KDockTabBarPainter::resizeEvent() (./kdelibs/kdeui/kdocktabctl.cpp:439)

void KDockTabBarPainter::resizeEvent( QResizeEvent* )
{
  delete buffer;
  switch ( ((KDockTabBar*)parent())->tabPos ){
    case KDockTabBar::TAB_TOP:
      buffer = new QPixmap( width(), height() );
      break;
    case KDockTabBar::TAB_RIGHT:
      buffer = new QPixmap( height(), width() );
      break;
  }
}


kdelibs'KDockTabBarPainter::drawBuffer() (./kdelibs/kdeui/kdocktabctl.cpp:452)

void KDockTabBarPainter::drawBuffer()
{
  QColor c1 = colorGroup().light();
  QColor c2 = colorGroup().dark();
  QColor c4 = colorGroup().light(); // for paint top line;

  int W = 0;
  int H = 0;
  int shadowX = 1;
  int shadowY = 1;
  switch ( ((KDockTabBar*)parent())->tabPos ){
    case KDockTabBar::TAB_TOP:
      W = width();
      H = height();
      break;
    case KDockTabBar::TAB_RIGHT:
      shadowX = -1;
      c1 = colorGroup().dark();
      c2 = colorGroup().light();
      H = width();
      W = height();
      break;
  }

  QPainter paint;
  paint.begin(buffer);
  paint.setBrushOrigin(0,0);
  paint.fillRect( 0, 0, W, H, QBrush( colorGroup().brush( QColorGroup::Background ) ));

  int x = 2;
  int curTab  = ((KDockTabBar*)parent())->_currentTab;
  int curTabNum = -1;
  int leftTab = ((KDockTabBar*)parent())->leftTab;
  int curx = -1; // start current tab ( selected )
  int curWidth = -1;
  int broken = -1;
  bool iconShow = ((KDockTabBar*)parent())->iconShow;

  QList<KDockTabBar_Private> *mainData = ((KDockTabBar*)parent())->mainData;
  for ( uint k = 0; k < mainData->count(); k++ ){
    int x1 = x;
    int y1 = 2;
    int width = mainData->at(k)->width;

    if ( mainData->at(k)->id == curTab ){  // store current tab start x
      curTabNum = k;
      curx = x;
      curWidth = width;
      x1 -= 1;
      y1 -= 1;
    }

    if ( mainData->at(k)->pix != 0L && iconShow ){
      QWMatrix m;
      switch ( ((KDockTabBar*)parent())->tabPos ){
        case KDockTabBar::TAB_TOP:
          break;
        case KDockTabBar::TAB_RIGHT:
          m.rotate( 90 );
          break;
      }
      paint.drawPixmap( x1+ 11, y1 + 2 , mainData->at(k)->pix->xForm(m) );
    }

    int ty = ( H + fontMetrics().height() ) / 2 - 2;
    int tx = ( mainData->at(k)->pix != 0L && iconShow ) ? 32:12;

    paint.setFont( parentWidget()->font() );

    if ( mainData->at(k)->enabled ){
//      if ( (int)k == curTab )
//        paint.setPen( colorGroup().buttonText() );
//      else
        paint.setPen( mainData->at(k)->textColor );
      paint.drawText( x1 + tx , ty + y1 , mainData->at(k)->label );
    } else {
      paint.setPen( colorGroup().light() );
      paint.drawText( x1 + tx + shadowX, ty + y1 + shadowY, mainData->at(k)->label );
      paint.setPen( colorGroup().mid() );
      paint.drawText( x1 + tx , ty + y1 , mainData->at(k)->label );
    }

    paint.setPen( c1 );
    paint.moveTo( x1, H + 1 -y1 );
    paint.lineTo( x1, y1 );

    paint.setPen( c4 );
    paint.lineTo( x1 + width - 1, y1 );

    paint.setPen( c2 );
    paint.lineTo( x1 + width - 1, H+1-y1 );

/***************************************************************/
    paint.setPen( c1 );
    paint.moveTo( x1 + 4, y1 + H - 5 );
    paint.lineTo( x1 + 4, 3+y1 );

    paint.moveTo( x1 + 7, y1 + H - 5 );
    paint.lineTo( x1 + 7, 3+y1 );

    paint.setPen( c2 );
    paint.moveTo( x1 + 5, y1 + H - 5 );
    paint.lineTo( x1 + 5, 3+y1 );

    paint.moveTo( x1 + 8, y1 + H - 5 );
    paint.lineTo( x1 + 8, 3+y1 );
/***************************************************************/

    // fixed picture for leftTab
    if ( leftTab == (int)k + 1 ){
      paint.fillRect( x1 + width - 2, 0, 2, H - 1, QBrush( colorGroup().brush( QColorGroup::Background ) ));
    }

    // paint broken left
    if ( (int)k == leftTab && k != 0 )
    {
      int yy = y1;
      int xx = x1 - 2;
      paint.fillRect( x1, 0, 1, H - 1, QBrush( colorGroup().brush( QColorGroup::Background ) ));
      paint.setPen( c1 );
      do {
          paint.drawPoint( xx + 2, yy );
          paint.drawPoint( xx + 1, yy + 1 );
          paint.moveTo( xx + 1, yy + 1 );
          paint.lineTo( xx + 1, yy + 3 );
          paint.drawPoint( xx + 2, yy + 4 );
          paint.lineTo( xx + 2, yy + 6 );
          paint.drawPoint( xx + 3, yy + 7 );
          paint.lineTo( xx + 3, yy + 9 );
          paint.drawPoint( xx + 2, yy + 10 );
          paint.drawPoint( xx + 2, yy + 11 );
          yy+= 12;
      } while ( yy < H );
    }

    x += width;
    if ( x >= W && broken == -1 ) broken = k; // store right broken tab
  }

  // modify ( paint ) selected tab
  if ( curx != -1 && curTabNum >= leftTab ){
    curx -= 2;
    curWidth += 4;
    paint.setPen( c1 );
    paint.moveTo( curx, H-1 );
    paint.lineTo( curx, 0 );
    paint.setPen( c4 );
    paint.lineTo( curx + curWidth - 2, 0 );

    paint.setPen( c2 );
    paint.moveTo( curx + curWidth - 1, 0 );
    paint.lineTo( curx + curWidth - 1, H-1 );

    paint.fillRect( curx + 1, 1, 2, H - 1, QBrush( colorGroup().brush( QColorGroup::Background ) ));
    paint.fillRect( curx + curWidth - 4, 1, 3, H - 1, QBrush( colorGroup().brush( QColorGroup::Background ) ));
    paint.fillRect( curx + 1, 1, curWidth - 3, 2, QBrush( colorGroup().brush( QColorGroup::Background ) ));
  }

  if ( curTabNum == leftTab && curTabNum != 0 )
  {
    int yy = 0;
    int xx = curx;
    paint.fillRect( curx, 0, 1, H - 1, QBrush( colorGroup().brush( QColorGroup::Background ) ));
    paint.setPen( c1 );
    do {
        paint.drawPoint( xx + 2, yy );
        paint.drawPoint( xx + 1, yy + 1 );
        paint.moveTo( xx + 1, yy + 1 );
        paint.lineTo( xx + 1, yy + 3 );
        paint.drawPoint( xx + 2, yy + 4 );
        paint.lineTo( xx + 2, yy + 6 );
        paint.drawPoint( xx + 3, yy + 7 );
        paint.lineTo( xx + 3, yy + 9 );
        paint.drawPoint( xx + 2, yy + 10 );
        paint.drawPoint( xx + 2, yy + 11 );
        yy+= 12;
    } while ( yy < H );
  }

  // paint broken right
  if ( broken != -1 )
  {
    int yy = broken == curTabNum ? 0:2;
    int xx = W;
    paint.fillRect( xx - 2, 0, 2, H - 1, QBrush( colorGroup().brush( QColorGroup::Background ) ) );
    paint.fillRect( xx - 5, yy + 1, 5, H - 2 - yy, QBrush( colorGroup().brush( QColorGroup::Background ) ) );
    paint.setPen( c2 );
    do {
        paint.drawPoint( xx - 2, yy );
        paint.drawPoint( xx - 1, yy + 1 );
        paint.moveTo( xx - 1, yy + 1 );
        paint.lineTo( xx - 1, yy + 3 );
        paint.drawPoint( xx - 2, yy + 4 );
        paint.lineTo( xx - 2, yy + 6 );
        paint.drawPoint( xx - 3, yy + 7 );
        paint.lineTo( xx - 3, yy + 9 );
        paint.drawPoint( xx - 2, yy + 10 );
        paint.drawPoint( xx - 2, yy + 11 );
        yy+= 12;
    } while ( yy < H );
  }
  paint.end();
}


kdelibs'KDockTabBarPainter::findBarByPos() (./kdelibs/kdeui/kdocktabctl.cpp:656)

int KDockTabBarPainter::findBarByPos( int x, int y )
{
  int dx = 5; // overlaped

  switch ( ((KDockTabBar*)parent())->tabPos ){
    case KDockTabBar::TAB_TOP:
      break;
    case KDockTabBar::TAB_RIGHT:
      x = height() - y;
      break;
  }

  KDockTabBar* bar = (KDockTabBar*)parent();

  QList<KDockTabBar_Private> *mainData = bar->mainData;
  if ( mainData->isEmpty() ) return -1;

  int end = 0;
  int find = -1;
  int findWidth = -1;
  for ( uint k = 0; k < mainData->count(); k++ ){
    end += mainData->at(k)->width;
    if ( x < end ){
      find = k;
      findWidth = mainData->at(k)->width;
      break;
    }
  }

  int idCurTab = bar->_currentTab;
  int curTab = -1;
  for ( uint k = 0; k < mainData->count(); k++ )
    if ( mainData->at(k)->id == idCurTab ){
      curTab = k;
      break;
    }

  // process first Tab manualy
  if ( x < dx && curTab != mainData->at(0)->id ) return -1;

  // process last Tab manyaly
  if ( find == -1 )
    if ( x < (end + dx) && curTab == (int)mainData->count() - 1 )
      find = mainData->count() - 1;

  if ( find == -1 ) return -1;

  // process overlaped
  if ( find > 0 )
    if ( curTab == (find - 1) &&  x < (end - findWidth + dx ) ) find -= 1;

  if ( find < (int)mainData->count() - 1 )
    if ( curTab == (find + 1) &&  x > (end - dx ) ) find += 1;

  return mainData->at(find)->id;
}


kdelibs'KDockTabBarPainter::mousePressEvent() (./kdelibs/kdeui/kdocktabctl.cpp:713)

void KDockTabBarPainter::mousePressEvent( QMouseEvent* e )
{
  int cur = findBarByPos( e->x(), e->y() );
  if ( e->button() == RightButton )
    emit ((KDockTabBar*)parent())->rightButtonPress( cur, e->globalPos() );
  else
    mousePressTab = cur;
}


kdelibs'KDockTabBarPainter::mouseReleaseEvent() (./kdelibs/kdeui/kdocktabctl.cpp:722)

void KDockTabBarPainter::mouseReleaseEvent( QMouseEvent* e )
{
  int cur = findBarByPos( e->x(), e->y() );
  if ( cur != -1 && cur == mousePressTab ){
    ((KDockTabBar*)parent())->setCurrentTab( cur );
  }
}

/***************************************************************************/