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

📄 qscrollview.cpp

📁 qtopia-phone-2.2.0下公共的控件实现源代码。
💻 CPP
📖 第 1 页 / 共 5 页
字号:
/*!  To provide simple processing of events on the contents,  this method receives all mouse  double click events sent to the viewport.  The default implementation translates the event and calls  contentsMouseDoubleClickEvent().  \sa QWidget::mouseDoubleClickEvent()*/void QScrollView::viewportMouseDoubleClickEvent( QMouseEvent* e ){    QMouseEvent ce(e->type(), viewportToContents(e->pos()),	e->globalPos(), e->button(), e->state());    contentsMouseDoubleClickEvent(&ce);}/*!  To provide simple processing of events on the contents,  this method receives all mouse  move events sent to the viewport.  The default implementation translates the event and calls  contentsMouseMoveEvent().  \sa QWidget::mouseMoveEvent()*/void QScrollView::viewportMouseMoveEvent( QMouseEvent* e ){    QMouseEvent ce(e->type(), viewportToContents(e->pos()),	e->globalPos(), e->button(), e->state());    contentsMouseMoveEvent(&ce);}#ifndef QT_NO_DRAGANDDROP/*!  To provide simple processing of events on the contents,  this method receives all drag enter  events sent to the viewport.  The default implementation translates the event and calls  contentsDragEnterEvent().  \sa QWidget::dragEnterEvent()*/void QScrollView::viewportDragEnterEvent( QDragEnterEvent* e ){    e->setPoint(viewportToContents(e->pos()));    contentsDragEnterEvent(e);    e->setPoint(contentsToViewport(e->pos()));}/*!  To provide simple processing of events on the contents,  this method receives all drag move  events sent to the viewport.  The default implementation translates the event and calls  contentsDragMoveEvent().  \sa QWidget::dragMoveEvent()*/void QScrollView::viewportDragMoveEvent( QDragMoveEvent* e ){    e->setPoint(viewportToContents(e->pos()));    contentsDragMoveEvent(e);    e->setPoint(contentsToViewport(e->pos()));}/*!  To provide simple processing of events on the contents,  this method receives all drag leave  events sent to the viewport.  The default implementation calls contentsDragLeaveEvent().  \sa QWidget::dragLeaveEvent()*/void QScrollView::viewportDragLeaveEvent( QDragLeaveEvent* e ){    contentsDragLeaveEvent(e);}/*!  To provide simple processing of events on the contents,  this method receives all drop  events sent to the viewport.  The default implementation translates the event and calls  contentsDropEvent().  \sa QWidget::dropEvent()*/void QScrollView::viewportDropEvent( QDropEvent* e ){    e->setPoint(viewportToContents(e->pos()));    contentsDropEvent(e);    e->setPoint(contentsToViewport(e->pos()));}#endif // QT_NO_DRAGANDDROP/*!  To provide simple processing of events on the contents,  this method receives all wheel  events sent to the viewport.  The default implementation translates the event and calls  contentsWheelEvent().  \sa QWidget::wheelEvent()*/void QScrollView::viewportWheelEvent( QWheelEvent* e ){    QWheelEvent ce( viewportToContents(e->pos()),	e->globalPos(), e->delta(), e->state());    contentsWheelEvent(&ce);    if ( ce.isAccepted() )	e->accept();    else	e->ignore();}/*! Returns the component horizontal scrollbar.  It is made available to allow accelerators, autoscrolling, etc., and to allow changing of arrow scroll rates: bar->setSteps( rate, bar->pageStep() ). It should not be otherwise manipulated. This function never returns 0.*/QScrollBar* QScrollView::horizontalScrollBar() const{    return &d->hbar;}/*! Returns the component vertical scrollbar.  It is made available to allow accelerators, autoscrolling, etc., and to allow changing of arrow scroll rates: bar->setSteps( rate, bar->pageStep() ). It should not be otherwise manipulated. This function never returns 0.*/QScrollBar* QScrollView::verticalScrollBar() const {    return &d->vbar;}/*! Scrolls the content so that the point (x, y) is visible with at least 50-pixel margins (if possible, otherwise centered).*/void QScrollView::ensureVisible( int x, int y ){    ensureVisible(x, y, 50, 50);}/*! Scrolls the content so that the point (x, y) is visible with at least the given pixel margins (if possible, otherwise centered).*/void QScrollView::ensureVisible( int x, int y, int xmargin, int ymargin ){    int pw=visibleWidth();    int ph=visibleHeight();    int cx=-contentsX();    int cy=-contentsY();    int cw=contentsWidth();    int ch=contentsHeight();    if ( pw < xmargin*2 )	xmargin=pw/2;    if ( ph < ymargin*2 )	ymargin=ph/2;    if ( cw <= pw ) {	xmargin=0;	cx=0;    }    if ( ch <= ph ) {	ymargin=0;	cy=0;    }    if ( x < -cx+xmargin )	cx = -x+xmargin;    else if ( x >= -cx+pw-xmargin )	cx = -x+pw-xmargin;    if ( y < -cy+ymargin )	cy = -y+ymargin;    else if ( y >= -cy+ph-ymargin )	cy = -y+ph-ymargin;    if ( cx > 0 )	cx=0;    else if ( cx < pw-cw && cw>pw )	cx=pw-cw;    if ( cy > 0 )	cy=0;    else if ( cy < ph-ch && ch>ph )	cy=ph-ch;    setContentsPos( -cx, -cy );}/*! Scrolls the content so that the point (x, y) is in the top-left corner.*/void QScrollView::setContentsPos( int x, int y ){    if ( x < 0 ) x = 0;    if ( y < 0 ) y = 0;    // Choke signal handling while we update BOTH sliders.    d->signal_choke=TRUE;    moveContents( -x, -y );    d->vbar.setValue( y );    d->hbar.setValue( x );//     updateScrollBars(); // ### warwick, why should we need that???    d->signal_choke=FALSE;//     updateScrollBars(); // ### warwick, why should we need that???}/*! Scrolls the content by \a dx to the left and \a dy upwards.*/void QScrollView::scrollBy( int dx, int dy ){    setContentsPos( contentsX()+dx, contentsY()+dy );}/*! Scrolls the content so that the point (x,y) is in the center of visible area.*/void QScrollView::center( int x, int y ){    ensureVisible( x, y, 32000, 32000 );}/*! Scrolls the content so that the point (x,y) is visible, with the given margins (as fractions of visible area). eg. <ul>   <li>Margin 0.0 allows (x,y) to be on edge of visible area.   <li>Margin 0.5 ensures (x,y) is in middle 50% of visible area.   <li>Margin 1.0 ensures (x,y) is in the center of the visible area. </ul>*/void QScrollView::center( int x, int y, float xmargin, float ymargin ){    int pw=visibleWidth();    int ph=visibleHeight();    ensureVisible( x, y, int( xmargin/2.0*pw+0.5 ), int( ymargin/2.0*ph+0.5 ) );}/*!  \fn void QScrollView::contentsMoving(int x, int y)  This signal is emitted just before the contents is moved  to the given position.  \sa contentsX(), contentsY()*//*!  Moves the contents.*/void QScrollView::moveContents(int x, int y){    if ( -x+visibleWidth() > contentsWidth() )	x=QMIN(0,-contentsWidth()+visibleWidth());    if ( -y+visibleHeight() > contentsHeight() )	y=QMIN(0,-contentsHeight()+visibleHeight());    int dx = x - d->vx;    int dy = y - d->vy;    if (!dx && !dy)	return; // Nothing to do    emit contentsMoving( -x, -y );    d->vx = x;    d->vy = y;    if ( d->clipped_viewport || d->static_bg ) {	// Cheap move (usually)	d->moveAllBy(dx,dy);    } else if ( /*dx && dy ||*/	 ( QABS(dy) * 5 > visibleHeight() * 4 ) ||	 ( QABS(dx) * 5 > visibleWidth() * 4 )	)    {	// Big move	if ( viewport()->isUpdatesEnabled() )	    viewport()->update();	d->moveAllBy(dx,dy);    } else {	// Small move	clipper()->scroll(dx,dy);    }    d->hideOrShowAll(this, TRUE );}/*!  Returns the X coordinate of the contents which is at the left  edge of the viewport.*/int QScrollView::contentsX() const{    return -d->vx;}/*!  Returns the Y coordinate of the contents which is at the top  edge of the viewport.*/int QScrollView::contentsY() const{    return -d->vy;}/*!  Returns the width of the contents area.*/int QScrollView::contentsWidth() const{    return d->vwidth;}/*!  Returns the height of the contents area.*/int QScrollView::contentsHeight() const{    return d->vheight;}/*!  Set the size of the contents area to \a w pixels wide and \a h  pixels high, and updates the viewport accordingly.*/void QScrollView::resizeContents( int w, int h ){    int ow = d->vwidth;    int oh = d->vheight;    d->vwidth = w;    d->vheight = h;    // Could more efficiently scroll if shrinking, repaint if growing, etc.    updateScrollBars();    if ( d->children.isEmpty() && d->policy == Default )	setResizePolicy( Manual );    if ( ow > w ) {	// Swap	int t=w;	w=ow;	ow=t;    }    // Refresh area ow..w    if ( ow < visibleWidth() && w >= 0 ) {	if ( ow < 0 )	    ow = 0;	if ( w > visibleWidth() )	    w = visibleWidth();	clipper()->update( contentsX()+ow, 0, w-ow, visibleHeight() );    }    if ( oh > h ) {	// Swap	int t=h;	h=oh;	oh=t;    }    // Refresh area oh..h    if ( oh < visibleHeight() && h >= 0 ) {	if ( oh < 0 )	    oh = 0;	if ( h > visibleHeight() )	    h = visibleHeight();	clipper()->update( 0, contentsY()+oh, visibleWidth(), h-oh);    }}/*!  Calls update() on rectangle defined by \a x, \a y, \a w, \a h,  translated appropriately.  If the rectangle in not visible,  nothing is repainted.  \sa repaintContents()*/void QScrollView::updateContents( int x, int y, int w, int h ){    QWidget* vp = viewport();    // Translate    x -= contentsX();    y -= contentsY();    // Clip to QCOORD space    if ( x < 0 ) {	w += x;	x = 0;    }    if ( y < 0 ) {	h += y;	y = 0;    }    if ( w < 0 || h < 0 )	return;    if ( w > visibleWidth() )	w = visibleWidth();    if ( h > visibleHeight() )	h = visibleHeight();    if ( d->clipped_viewport ) {	// Translate clipper() to viewport()	x -= d->clipped_viewport->x();	y -= d->clipped_viewport->y();    }    vp->update( x, y, w, h );}/*!  \overload*/void QScrollView::updateContents( const QRect& r ){    updateContents(r.x(), r.y(), r.width(), r.height());}/*!  \overload*/void QScrollView::repaintContents( const QRect& r, bool erase ){    repaintContents(r.x(), r.y(), r.width(), r.height(), erase);}/*!  Calls repaint() on rectangle defined by \a x, \a y, \a w, \a h,  translated appropriately.  If the rectangle in not visible,  nothing is repainted.  \sa updateContents()*/void QScrollView::repaintContents( int x, int y, int w, int h, bool erase ){    QWidget* vp = viewport();    // Translate logical to clipper()    x -= contentsX();    y -= contentsY();    // Clip to QCOORD space    if ( x < 0 ) {	w += x;	x = 0;    }    if ( y < 0 ) {	h += y;	y = 0;    }    if ( w < 0 || h < 0 )	return;    if ( w > visibleWidth() )	w = visibleWidth();    if ( h > visibleHeight() )	h = visibleHeight();    if ( d->clipped_viewport ) {	// Translate clipper() to viewport()	x -= d->clipped_viewport->x();	y -= d->clipped_viewport->y();    }

⌨️ 快捷键说明

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