⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ktablistbox.cpp

📁 一种效率高
💻 CPP
📖 第 1 页 / 共 4 页
字号:
    item->setText(i, pos);    pos = strtok(0L, sepStr);  }  item->setForeground(black);  if (needsUpdate(row)) lbox.repaint();}//-----------------------------------------------------------------------------void KTabListBox::changeItemPart(const char* aStr, int row, int col){  if (row < 0 || row >= numRows()) return;  if (col < 0 || col >= numCols()) return;  itemList[row]->setText(col, aStr);  if (needsUpdate(row)) lbox.repaint();}//-----------------------------------------------------------------------------void KTabListBox::changeItemColor(const QColor& newColor, int row){  if (row >= numRows()) return;  if (row < 0) row = numRows()-1;  itemList[row]->setForeground(newColor);  if (needsUpdate(row)) lbox.repaint();}//-----------------------------------------------------------------------------void KTabListBox::removeItem(int row){  KTabListBoxItemPtr it;  int i, nr;  bool upd;  if (row < 0 || row >= numRows()) return;  upd = needsUpdate(row);  if (itemPosList(current) >itemPosList(row))    current=itemShowList[itemPosList(current-1)];  nr = numRows()-1;  it = itemList[row];  for (i=row; i<nr; i++)    itemList[i] = itemList[i+1];  for(i=itemPosList(row); i<nr;i++)    itemShowList[i]=itemShowList[i+1];  for(i=0;i<nr;i++) if(itemShowList[i]>row) itemShowList[i]--;  itemList[nr] = it;  setNumRows(nr);  if (nr==0) current = -1;  if (upd) lbox.repaint();}//-----------------------------------------------------------------------------void KTabListBox::updateItem(int row, bool erase){  int i;  for (i=numCols()-1; i>=0; i--)    lbox.updateCell(itemPosList(row), i, erase);}//-----------------------------------------------------------------------------bool KTabListBox::needsUpdate(int id){return (lbox.autoUpdate() && itemVisible(itemPosList(id)));}//-----------------------------------------------------------------------------void KTabListBox::changeMode(int col){  // Add optimization HERE!!!!  if(col >= lbox.numCols() || col < 0)    return;  if(colList[col]->changeMode())    reorderRows();}//-----------------------------------------------------------------------------void KTabListBox::adjustNumber(int num){  int t;  for(t=0;t<numColumns;t++)    if(colList[t]->number()>num)      colList[t]->setNumber(colList[t]->number()-1);  lastSelectedColumn--;}//-----------------------------------------------------------------------------int KTabListBox::colPosList(int cl){  int t;  if (cl<0) return cl;  for(t=0;t<numColumns;t++) if(cl==colShowList[t]) break;  return t;}//-----------------------------------------------------------------------------int KTabListBox::itemPosList(int it){  int t;  for(t=0;t<maxItems;t++) if(it==itemShowList[t]) break;  return t;}//-----------------------------------------------------------------------------void KTabListBox::clearAllNum(){  int t;  for(t=0;t<numColumns;t++)    colList[t]->setNumber(0);  lastSelectedColumn=0;}//-----------------------------------------------------------------------------void KTabListBox::clear(void){  int i;  for (i=maxItems-1; i>=0; i--)  {    if (itemList[i])      itemList[i]->setMarked(-2);  }  setNumRows(0);  lbox.setTopLeftCell(0,0);  current = -1;}//-----------------------------------------------------------------------------void KTabListBox::repaint(){  if(needsSort) reorderRows();  QWidget::repaint();  lbox.repaint();}//-----------------------------------------------------------------------------void KTabListBox::resizeList(int newNumItems){  KTabListBoxItemPtr* newItemList;  int *newItemShowList;  int i, ih, nc, oldNum;  if (newNumItems < 0) newNumItems = (maxItems << 1);  if (newNumItems < INIT_MAX_ITEMS) newNumItems = INIT_MAX_ITEMS;  nc = numCols();  oldNum = numRows();  newItemList = new KTabListBoxItemPtr[newNumItems];  newItemShowList = new int[newNumItems];  ih = newNumItems < oldNum ? newNumItems : oldNum;  for (i = ih-1; i>=0; i--)  {    newItemList[i] = itemList[i];    newItemShowList[i] = itemShowList[i];  }  if (newNumItems > oldNum)  {    for (i = oldNum; i < newNumItems; i++) {      newItemList[i] = new KTabListBoxItem(nc);      newItemShowList[i] = 0;    }  }  else  {    for (i = newNumItems; i < oldNum; i++)      delete itemList[i];  }  if (itemList) delete [] itemList;  if (itemShowList) delete [] itemShowList;  itemList = newItemList;  itemShowList = newItemShowList;  maxItems = newNumItems;  setNumRows(ih);}//-----------------------------------------------------------------------------// This should really go into kdecore. Currently it's used by khtml and this.// It prevents the tablist to continue to scroll after the user has released// the key.void KTabListBox::flushKeys(){    XEvent ev_return;    Display *dpy = qt_xdisplay();    while ( XCheckTypedEvent( dpy, KeyPress, &ev_return ) );}//-----------------------------------------------------------------------------void KTabListBox::keyPressEvent( QKeyEvent *e ){    QScrollBar *sY=(QScrollBar*)lbox.verticalScrollBar();    QScrollBar *sX=(QScrollBar*)lbox.horizontalScrollBar();    bool thereIsX=sX->isVisible();    //int pageJump = lbox.lastRowVisible()-lbox.topCell();    int t;    switch ( e->key() ) {    case Key_Left:        if(thereIsX) sX->setValue( sX->value() - sX->lineStep() );        flushKeys();        break;    case Key_Right:        if(thereIsX) sX->setValue( sX->value() + sX->lineStep() );        flushKeys();        break;    case Key_Up:        if(current==topCell())          sY->setValue( sY->value() - sY->lineStep() );        setCItem(itemShowList[itemPosList(current)-1]);        flushKeys();        break;    case Key_Down:        if(current==lastRowVisible())          sY->setValue( sY->value() + sY->lineStep() );        if((t=itemPosList(current)+1)<numRows())          setCItem(itemShowList[t]);        flushKeys();        break;    case Key_PageUp:        sY->setValue( sY->value() - sY->pageStep() );        t=lbox.lastRowVisible()-1;        if(lbox.topCell()==0) t=0;        /*if((t=itemPosList(current)-pageJump)>0)          setCItem(itemShowList[t]);        else          setCItem(itemShowList[0]);*/        setCItem(itemShowList[t]);        flushKeys();        break;    case Key_PageDown:        sY->setValue( sY->value() + sY->pageStep() );        t=lbox.topCell()+1;        if(lbox.lastRowVisible()==numRows()-1) t=numRows()-1;        /*if((t=itemPosList(current)+pageJump+1)<numRows())          setCItem(itemShowList[t]);        else          setCItem(itemShowList[numRows()-1]);*/        setCItem(itemShowList[t]);        flushKeys();        break;    case Key_Home:        sY->setValue( sY->minValue() );        setCItem(itemShowList[0]);        flushKeys();        break;    case Key_End:        sY->setValue( sY->maxValue() );        setCItem(itemShowList[numRows()-1]);        flushKeys();        break;    case Key_Enter:    case Key_Return:        emit selected(current, -1);        break;    case Key_Space:        emit highlighted(current, -1);        break;    default:        e->ignore();        break;    }}//-----------------------------------------------------------------------------void KTabListBox::resizeEvent(QResizeEvent* e){  int i, w,t;  KTabListBoxInherited::resizeEvent(e);  for (i=0, w=0; i<numCols(); i++)  {    colList[i]->setWidth(colList[i]->defaultWidth());    w += colList[i]->defaultWidth();  }  t=lbox.width()-lbox.viewWidth();  if (w < e->size().width()-t)    colList[colShowList[numCols()-1]]->setWidth(    e->size().width()-w-t+colList[colShowList[numCols()-1]]->defaultWidth() );  lbox.setGeometry(0, labelHeight, e->size().width(),		    e->size().height()-labelHeight);  lbox.reconnectSBSignals();  repaint();}//-----------------------------------------------------------------------------void KTabListBox::paintEvent(QPaintEvent*){  int i, ih, x, w;  QPainter paint;  QWMatrix matrix;  QRect    clipR;  QFont    font, oldFont;  ih = numCols();  x  = -lbox.xOffset();  matrix.translate(x, 0);  paint.begin(this);  for (i=0; i<ih; i++)  {    w = colList[colShowList[i]]->width();    if (w + x >= 0)    {      clipR.setRect(x, 0, w, labelHeight);      paint.setWorldMatrix(matrix, FALSE);      paint.setClipRect(clipR);      colList[colShowList[i]]->paint(&paint);      qDrawShadeLine(&paint, w, 0, w, labelHeight,                     KTabListBoxInherited::colorGroup());    }    else colList[colShowList[i]]->hideCheckButton();    matrix.translate(w, 0);    x += w;  }  paint.resetXForm();  paint.setClipping (false);  if ( style() == MotifStyle )    qDrawShadePanel(&paint, 0, 0, width(), height(),                    KTabListBoxInherited::colorGroup(), false, 1);  else    qDrawShadeRect (&paint, 0, 0, width(), height(),                    KTabListBoxInherited::colorGroup(), true, 1);  paint.end();}//-----------------------------------------------------------------------------void KTabListBox::mouseMoveEvent(QMouseEvent* e){  register int i, x, ex, ey;  bool mayResize = FALSE;  ex = e->pos().x();  ey = e->pos().y();  if ((e->state() & LeftButton))  {    if (!drag)    {      if(mMouseDragColumn) doMouseMoveCol(e);      if (mResizeCol && abs(mMouseStart.x() - ex) > 4)	doMouseResizeCol(e);      else if (!mResizeCol &&	       (ex < mMouseColLeft ||		ex > (mMouseColLeft+mMouseColWidth)))      {        mMouseDragColumn=true;        doMouseMoveCol(e);      }    }    KTabListBoxInherited::mouseMoveEvent(e);    return;  }  for (i=1, x=colList[colShowList[0]]->width()-lbox.xOffset(); ; i++)  {    if (ex >= x-4 && ex <= x+4)    {      mayResize = TRUE;      mMouseCol   = colShowList[i-1];      mMouseColLeft = ex;      mMouseColWidth = lbox.cellWidth(i-1);      break;    }    if (i >= numColumns) break;    x += colList[colShowList[i]]->width();  }  if (mayResize)  {    if (!mResizeCol)    {      mResizeCol = TRUE;      setCursor(sizeHorCursor);    }  }  else  {    if (mResizeCol)    {      mResizeCol = FALSE;      mMouseCol = -1;      setCursor(arrowCursor);    }  }}//-----------------------------------------------------------------------------void KTabListBox::mousePressEvent(QMouseEvent* e){  if (!mResizeCol && e->button() == LeftButton)  {    mMouseStart = e->pos();    mMouseCol = lbox.findRealCol(e->pos().x());    if (mMouseCol < 0) return;    mMouseColWidth = colList[mMouseCol]->width();    mMouseColLeft = 0;    int t;    colPosList(mMouseCol);    for(t=0;t<colPosList(mMouseCol);t++)        mMouseColLeft+=colList[colShowList[t]]->width();    mLastX=mMouseColLeft;  }  KTabListBoxInherited::mousePressEvent(e);}//-----------------------------------------------------------------------------void KTabListBox::mouseReleaseEvent(QMouseEvent* e){  if (e->button() == LeftButton)  {    if (!mMouseAction)    {      // user wants to select the column rather than drag or move it      if (mMouseCol >= 0)      {        emit headerClicked(mMouseCol);        // changeMode knows if to do a repaint or not.        changeMode(mMouseCol);      }    }    else if(mMouseDragColumn)    {      // The user had dragged a column! We need to change the order?      mMouseDragColumn=false;      mMouseCol=colPosList(mMouseCol);      int actualColumn=colPosList(lbox.findRealCol(e->pos().x()));      if(actualColumn>=0 && actualColumn!=mMouseCol)      {        int tmp, t;        tmp=colShowList[mMouseCol];        if(actualColumn>mMouseCol)          for(t=mMouseCol;t<actualColumn;t++)              colShowList[t]=colShowList[t+1];        else          for(t=mMouseCol;t>=actualColumn;t--)              colShowList[t]=colShowList[t-1];        colShowList[actualColumn]=tmp;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -