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

📄 ktablistbox.cpp

📁 一种效率高
💻 CPP
📖 第 1 页 / 共 4 页
字号:
      }      repaint();    }    else if(mResizeCol) // The user had resized the column, make a resize:      resize(width(),height());    mMouseCol = -1;    mMouseAction = FALSE;  }  KTabListBoxInherited::mouseReleaseEvent(e);}//-----------------------------------------------------------------------------void KTabListBox::doMouseResizeCol(QMouseEvent* e){  int w, x,fixedmin=MINIMUM_SPACE;  if (!mMouseAction) mMouseAction = true;  if (mMouseCol >= 0)  {    x=e->pos().x();    w = mMouseColWidth + (x - mMouseColLeft);    if (colList[mMouseCol]->orderType()==ComplexOrder)       fixedmin+=ARROW_SPACE+labelHeight-BUTTON_SPACE;    else       if (colList[mMouseCol]->orderType()==SimpleOrder)          fixedmin+=ARROW_SPACE;    if (w < fixedmin) w = fixedmin;    if(w!=colList[mMouseCol]->width())    {      colList[mMouseCol]->setDefaultWidth(w);      colList[mMouseCol]->setWidth(w);      repaint();      if(x>width())      {        QScrollBar *sX=(QScrollBar*)lbox.horizontalScrollBar();        if(sX->isVisible())          sX->setValue( sX->value() +x -width() );      }    }  }}//-----------------------------------------------------------------------------void KTabListBox::doMouseMoveCol(QMouseEvent* e){  int x,old;  QPainter paint;  if (!mMouseAction) mMouseAction = true;  x = e->pos().x();  if(x<0)  {    QScrollBar *sX=(QScrollBar*)lbox.horizontalScrollBar();    if(sX->isVisible())    {      old=sX->value();      sX->setValue( sX->value() + x );      if(old!=sX->value()) mLastX=-9999;    }  }  else if(x+mMouseColWidth>width())  {    QScrollBar *sX=(QScrollBar*)lbox.horizontalScrollBar();    if(sX->isVisible())    {      old=sX->value();      sX->setValue( sX->value() + x+mMouseColWidth-width() );      if(old!=sX->value()) mLastX=-9999;    }  }  paint.begin(this);  if(mLastX!=-9999)    paint.drawWinFocusRect(mLastX+lbox.xOffset(),0,mMouseColWidth,labelHeight);  paint.drawWinFocusRect(x,0,mMouseColWidth,labelHeight);  paint.end();  mLastX=x-lbox.xOffset();}//-----------------------------------------------------------------------------bool KTabListBox::startDrag(int aCol, int aRow, const QPoint& p){  int       dx = -(dndDefaultPixmap.width() >> 1);  int       dy = -(dndDefaultPixmap.height() >> 1);  KDNDIcon* icon;  int       size, type;  char*	    data;  if (!prepareForDrag(aCol,aRow, &data, &size, &type)) return FALSE;  icon = new KDNDIcon(dndDefaultPixmap, p.x()+dx, p.y()+dy);  KTabListBoxInherited::startDrag(icon, data, size, type, dx, dy);  return TRUE;}//-----------------------------------------------------------------------------bool KTabListBox::prepareForDrag(int /*aCol*/, int /*aRow*/, char** /*data*/,				 int* /*size*/, int* /*type*/){  return FALSE;}//-----------------------------------------------------------------------------void KTabListBox::horSbValue(int){    // This update generates two paintEvent, why?    update();}//-----------------------------------------------------------------------------void KTabListBox::horSbSlidingDone(){}//=============================================================================////   C L A S S   KTabListBoxTable////=============================================================================KTabListBoxTable::KTabListBoxTable(KTabListBox *parent):  KTabListBoxTableInherited(parent){  QFontMetrics fm = fontMetrics();  initMetaObject();  dragging = FALSE;  dragCol = -1;  dragRow = -1;  selIdx  = -1;  setTableFlags(Tbl_autoVScrollBar|Tbl_autoHScrollBar|Tbl_smoothVScrolling|		 Tbl_clipCellPainting);  switch(style())  {  case MotifStyle:  case WindowsStyle:    setBackgroundColor(colorGroup().base());    setFrameStyle( QFrame::WinPanel | QFrame::Sunken );    break;  default:    setLineWidth(1);    setFrameStyle(QFrame::Panel|QFrame::Plain);  }  setCellWidth(0);  setCellHeight(fm.lineSpacing() + 1);  setNumRows(0);  setCursor(arrowCursor);  setMouseTracking(FALSE);  setFocusPolicy(NoFocus);  // You can enable it with enableKey();  //setFocusPolicy(StrongFocus);}//-----------------------------------------------------------------------------KTabListBoxTable::~KTabListBoxTable(){}//----------------------------------------------------------------------------void KTabListBoxTable::enableKey(){  setFocusPolicy(StrongFocus);}//-----------------------------------------------------------------------------int KTabListBoxTable::findRealCol(int xPos){ int column = -1; int xPos1; KTabListBox*owner =(KTabListBox*)parentWidget(); int maxCol=owner->numColumns; if ( xPos >= minViewX() && xPos <= maxViewX() ) {   column = 0;   xPos1=xPos+xOffset();   int cumWidth= 2;   while ( column < maxCol )   {     cumWidth += cellWidth( column );     if ( xPos1 < cumWidth ) break;     column++;   } } if ( column >=maxCol  )  return -1; if(column==-1) return -1; return owner->colShowList[column];}//-----------------------------------------------------------------------------void KTabListBoxTable::paintCell(QPainter* p, int row, int col){  KTabListBox*     owner =(KTabListBox*)parentWidget();  KTabListBoxItem* item  = owner->getItem(owner->itemShowList[row]);  if (!item) return;  p->setPen(item->foreground());  int t=owner->colShowList[col];  owner->colList[t]->paintCell(p, row, item->text(t),(item->marked()==-1));}//-----------------------------------------------------------------------------int KTabListBoxTable::cellWidth(int col){  KTabListBox* owner =(KTabListBox*)parentWidget();  return(owner->colList ? owner->colList[owner->colShowList[col]]->width() : 0);}//-----------------------------------------------------------------------------void KTabListBoxTable::mouseDoubleClickEvent(QMouseEvent* e){  KTabListBox* owner =(KTabListBox*)parentWidget();  int idx, colnr;  if(findRow(e->pos().y())<0) return;  idx = owner->currentItem();  colnr = findRealCol(e->pos().x());  if (idx >= 0) emit owner->selected(idx,colnr);}//-----------------------------------------------------------------------------void KTabListBoxTable::doItemSelection(QMouseEvent* e, int idx){  KTabListBox* owner =(KTabListBox*)parentWidget();  int i, di, colnr;  owner->unmarkAll();  if ((e->state()&ShiftButton)!=0 && owner->currentItem()>=0)  {    i  = owner->itemPosList(owner->currentItem());    idx= owner->itemPosList(idx);    di =(i>idx ? -1 : 1);    while(1)    {      owner->markItem(owner->itemShowList[i]);      if (i == idx) break;      i += di;    }  }  else  {    colnr = findRealCol(e->pos().x());    owner->setCurrentItem(idx,colnr);  }}//-----------------------------------------------------------------------------void KTabListBoxTable::mousePressEvent(QMouseEvent* e){  KTabListBox* owner =(KTabListBox*)parentWidget();  int row, col;  row=findRow(e->pos().y());  if(row<0) return;  row = owner->itemShowList[row];  col = findRealCol(e->pos().x());  if (e->button() == RightButton)  {    // handle popup menu    if (row >= 0 && col >= 0)      emit owner->popupMenu(row, col);    return;  }  else if (e->button() == MidButton)  {    // handle middle click    if (row >= 0 && col >= 0)      emit owner->midClick(row, col);    return;  }  // arm for possible dragging  dragStartPos = e->pos();  dragCol = col;  dragRow = row;  // handle item highlighting  if (row >= 0 && owner->getItem(row)->marked() < -1)  {    doItemSelection(e, row);    selIdx = row;  }  else selIdx = -1;}//-----------------------------------------------------------------------------void KTabListBoxTable::mouseReleaseEvent(QMouseEvent* e){  KTabListBox* owner =(KTabListBox*)parentWidget();  int idx;  if (e->button() != LeftButton) return;  if (dragging)  {    owner->mouseReleaseEvent(e);    dragRow = dragCol = -1;    dragging = FALSE;  }  else  {    idx = findRow(e->pos().y());    if(idx<0) return;    idx = owner->itemShowList[idx];    if (idx >= 0 && selIdx < 0)      doItemSelection(e, idx);  }}//-----------------------------------------------------------------------------void KTabListBoxTable::mouseMoveEvent(QMouseEvent* e){  KTabListBox* owner =(KTabListBox*)parentWidget();  if (dragging)  {    owner->mouseMoveEvent(e);    return;  }  if ((e->state() &(RightButton|LeftButton|MidButton)) != 0)  {    if (dragRow >= 0 && dragCol >= 0 &&	(abs(e->pos().x()-dragStartPos.x()) >= 5 ||	 abs(e->pos().y()-dragStartPos.y()) >= 5))    {      // we have a liftoff !      dragging = owner->startDrag(dragCol, dragRow, mapToGlobal(e->pos()));      return;    }  }}//-----------------------------------------------------------------------------void KTabListBoxTable::reconnectSBSignals(void){  QScrollBar* hsb = (QScrollBar*)horizontalScrollBar();  KTabListBox* owner =(KTabListBox*)parentWidget();  if (!hsb) return;  hsb->setTracking(TRUE);  connect(hsb, SIGNAL(valueChanged(int)), owner, SLOT(horSbValue(int)));  connect(hsb, SIGNAL(sliderReleased()), owner, SLOT(horSbSlidingDone()));}//-----------------------------------------------------------------------------void KTabListBoxTable::focusInEvent(QFocusEvent*){  // Just do nothing here to avoid the annoying flicker whick happens due  // to a redraw() call per default.}//-----------------------------------------------------------------------------void KTabListBoxTable::focusOutEvent(QFocusEvent*){  // Just do nothing here to avoid the annoying flicker whick happens due  // to a redraw() call per default.}//=============================================================================////      C L A S S  KNumCheckButton////=============================================================================KNumCheckButton::KNumCheckButton( QWidget *_parent, const char *name )    : QWidget(_parent, name){  int t=fontMetrics().height();  resize(t,t);  setText(" ");  raised = FALSE;  setFocusPolicy( NoFocus );}void KNumCheckButton::setText( const char *text ){  btext=text;  repaint();}void KNumCheckButton::enterEvent( QEvent* ){      raised = TRUE;      repaint(FALSE);}void KNumCheckButton::leaveEvent( QEvent * ){  if( raised != FALSE )    {      raised = FALSE;      repaint();    }}void KNumCheckButton::mousePressEvent( QMouseEvent *e){  if(e->button() == LeftButton)    emit selected();  else if(e->button() == RightButton)    emit deselected();}void KNumCheckButton::mouseDoubleClickEvent (QMouseEvent *e){  if(e->button() == LeftButton)    emit doubleclick(true);  else if(e->button() == RightButton)    emit doubleclick(false);}void KNumCheckButton::paintEvent( QPaintEvent *event ){  QPainter painter;  QFont font,oldfont;  painter.begin( this );  painter.setClipRect( event->rect() );  if ( raised )    {      QBrush   brush( white );      qDrawShadeRect( &painter, 0, 0, width(), height(), colorGroup(),                      TRUE, 1,1, &brush );    }  else      qDrawShadeRect( &painter, 0, 0, width(), height(), colorGroup(),                      TRUE, 1,1, 0L );  int tf = AlignCenter;  oldfont=painter.font();  font=oldfont;  font.setPointSize(height()-7);  painter.setFont(font);  painter.drawText(0, 0, width(), height(), tf, btext);  painter.setFont(oldfont);  painter.end();}#include "ktablistbox.moc"

⌨️ 快捷键说明

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