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

📄 qscrollview.cpp

📁 qtopia-phone-2.2.0下公共的控件实现源代码。
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    vp->repaint( x, y, w, h, erase );}/*!  For backward compatibility only.  It is easier to use drawContents(QPainter*,int,int,int,int).  The default implementation translates the painter appropriately  and calls drawContents(QPainter*,int,int,int,int).*/void QScrollView::drawContentsOffset(QPainter* p, int offsetx, int offsety, int clipx, int clipy, int clipw, int cliph){    p->translate(-offsetx,-offsety);    drawContents(p, clipx, clipy, clipw, cliph);}/*!  \fn void QScrollView::drawContents(QPainter* p, int clipx, int clipy, int clipw, int cliph)  Reimplement this method if you are viewing a drawing area rather  than a widget.  The function should draw the rectangle (\a clipx, \a clipy, \a clipw, \a  cliph ) of the contents, using painter \a p.  The clip rectangle is  in the scroll views's coordinates.  For example:  \code  {    // Fill a 40000 by 50000 rectangle at (100000,150000)    // Calculate the coordinates...    int x1 = 100000, y1 = 150000;    int x2 = x1+40000-1, y2 = y1+50000-1;    // Clip the coordinates so X/Windows will not have problems...    if (x1 < clipx) x1=clipx;    if (y1 < clipy) y1=clipy;    if (x2 > clipx+clipw-1) x2=clipx+clipw-1;    if (y2 > clipy+cliph-1) y2=clipy+cliph-1;    // Paint using the small coordinates...    if ( x2 >= x1 && y2 >= y1 )	p->fillRect(x1, y1, x2-x1+1, y2-y1+1, red);  }  \endcode  The clip rectangle and translation of the painter \a p is already set  appropriately.*/void QScrollView::drawContents(QPainter*, int, int, int, int){}/*!  \reimp*/void QScrollView::frameChanged(){    // Ensures that scrollbars have the correct size when the frame    // style changes.    updateScrollBars();}/*!  Returns the viewport widget of the scrollview.  This is the widget  containing the contents widget or which is the drawing area.*/QWidget* QScrollView::viewport() const{    return d->clipped_viewport ? d->clipped_viewport : &d->viewport;}/*!  Returns the clipper widget.  Contents in the scrollview is ultimately clipped to be inside  the clipper widget.  You should not need to access this.  \sa visibleWidth(), visibleHeight()*/QWidget* QScrollView::clipper() const{    return &d->viewport;}/*!  Returns the horizontal amount of the content that is visible.*/int QScrollView::visibleWidth() const{    return clipper()->width();}/*!  Returns the vertical amount of the content that is visible.*/int QScrollView::visibleHeight() const{    return clipper()->height();}void QScrollView::changeFrameRect(const QRect& r){    QRect oldr = frameRect();    if (oldr != r) {	QRect cr = contentsRect();	QRegion fr( frameRect() );	fr = fr.subtract( contentsRect() );	setFrameRect( r );	if ( isVisible() ) {	    cr = cr.intersect( contentsRect() );	    fr = fr.unite( frameRect() );	    fr = fr.subtract( cr );	    if ( !fr.isEmpty() )		QApplication::postEvent( this, new QPaintEvent( fr, FALSE ) );	}    }}/*!  Sets the margins around the scrolling area.  This is useful for  applications such as spreadsheets with `locked' rows and columns.  The marginal space is \e inside the frameRect() and is left blank -  reimplement drawContents() or put widgets in the unused area.  By default all margins are zero.  \sa frameChanged()*/void QScrollView::setMargins(int left, int top, int right, int bottom){    if ( left == d->l_marg &&	 top == d->t_marg &&	 right == d->r_marg &&	 bottom == d->b_marg )	return;    d->l_marg = left;    d->t_marg = top;    d->r_marg = right;    d->b_marg = bottom;    updateScrollBars();}/*!  Returns the current left margin.  \sa setMargins()*/int QScrollView::leftMargin() const{    return d->l_marg;}/*!  Returns the current top margin.  \sa setMargins()*/int QScrollView::topMargin() const{    return d->t_marg;}/*!  Returns the current right margin.  \sa setMargins()*/int QScrollView::rightMargin() const{    return d->r_marg;}/*!  Returns the current bottom margin.  \sa setMargins()*/int QScrollView::bottomMargin() const{    return d->b_marg;}/*!  \reimp*/bool QScrollView::focusNextPrevChild( bool next ){    //  Makes sure that the new focus widget is on-screen, if    //  necessary by scrolling the scroll view.    // first set things up for the scan    QFocusData *f = focusData();    QWidget *startingPoint = f->home();    QWidget *candidate = 0;    QWidget *w = next ? f->next() : f->prev();    QSVChildRec *r;    // then scan for a possible focus widget candidate    while( !candidate && w != startingPoint ) {	if ( w != startingPoint &&	     (w->focusPolicy() & TabFocus) == TabFocus	     && w->isEnabled() &&!w->focusProxy() && w->isVisible() )	    candidate = w;	w = next ? f->next() : f->prev();    }    // if we could not find one, maybe super or parentWidget() can?    if ( !candidate )	return QFrame::focusNextPrevChild( next );    // we've found one.    r = d->ancestorRec( candidate );    if ( r && ( r->child == candidate ||		candidate->isVisibleTo( r->child ) ) ) {	QPoint cp = r->child->mapToGlobal(QPoint(0,0));	QPoint cr = candidate->mapToGlobal(QPoint(0,0)) - cp;	ensureVisible( r->x+cr.x()+candidate->width()/2,		       r->y+cr.y()+candidate->height()/2,		       candidate->width()/2,		       candidate->height()/2 );    }    candidate->setFocus();    return TRUE;}/*!  When large numbers of child widgets are in a scrollview, especially  if they are close together, the scrolling performance can suffer  greatly.  If you call enableClipper(TRUE), the scrollview will  use an extra widget to group child widgets.  Note that you may only call enableClipper() prior to adding widgets.  For a full discussion, see the overview documentation of this  class.*/void QScrollView::enableClipper(bool y){    if ( !d->clipped_viewport == !y )	return;    if ( d->children.count() )	qFatal("May only call QScrollView::enableClipper() before adding widgets");    if ( y ) {	d->clipped_viewport = new QClipperWidget(clipper(), "qt_clipped_viewport", d->flags);	d->clipped_viewport->setGeometry(-coord_limit/2,-coord_limit/2,					coord_limit,coord_limit);	d->viewport.setBackgroundMode(NoBackground); // no exposures for this	d->viewport.removeEventFilter( this );	d->clipped_viewport->installEventFilter( this );    } else {	delete d->clipped_viewport;	d->clipped_viewport = 0;    }}/*!  Sets the scrollview to have a static background if \a y is TRUE, or a scrolling background otherwise. By default,  the background is scrolling.  Beware that this mode is quite slow, as a full repaint of the visible area has to be triggered on every contents move.  \sa hasStaticBackground()*/void  QScrollView::setStaticBackground(bool y){    d->static_bg = y;}/*!  Returns wether QScrollView uses a static background.  \sa setStaticBackground()*/bool QScrollView::hasStaticBackground() const{    return d->static_bg;}/*!  Returns the    point \a p  translated to    a point on the viewport() widget.*///### make this const in 3.0QPoint QScrollView::contentsToViewport(const QPoint& p){    if ( d->clipped_viewport ) {	return QPoint( p.x() - contentsX() - d->clipped_viewport->x(),		       p.y() - contentsY() - d->clipped_viewport->y() );    } else {	return QPoint( p.x() - contentsX(),		       p.y() - contentsY() );    }}/*!  Returns the    point on the viewport \a vp  translated to    a point in the contents.*///### make this const in 3.0QPoint QScrollView::viewportToContents(const QPoint& vp){    if ( d->clipped_viewport ) {	return QPoint( vp.x() + contentsX() + d->clipped_viewport->x(),		       vp.y() + contentsY() + d->clipped_viewport->y() );    } else {	return QPoint( vp.x() + contentsX(),		       vp.y() + contentsY() );    }}/*!  Translates    a point (\a x, \a y) in the contents  to    a point (\a vx, \a vy) on the viewport() widget.*/void QScrollView::contentsToViewport(int x, int y, int& vx, int& vy){    const QPoint v = contentsToViewport(QPoint(x,y));    vx = v.x();    vy = v.y();}/*!  Translates    a point (\a vx, \a vy) on the viewport() widget  to    a point (\a x, \a y) in the contents.*/void QScrollView::viewportToContents(int vx, int vy, int& x, int& y){    const QPoint c = viewportToContents(QPoint(vx,vy));    x = c.x();    y = c.y();}/*!  \reimp*/QSizePolicy QScrollView::sizePolicy() const{    //### removeme 3.0    return QWidget::sizePolicy();}/*!  \reimp*/QSize QScrollView::sizeHint() const{    constPolish();    QSize result = QSize(frameWidth()*2, frameWidth()*2);    if ( d->policy > Manual ) {	QSVChildRec* r = d->children.first();	if (r)	{            QSize cs = r->child->sizeHint();	    if ( cs.isValid() )        	result += cs.boundedTo( r->child->maximumSize() );	    else        	result += r->child->size();        }    } else {	result += QSize(contentsWidth(),contentsHeight());    }    return result;}/*!  \reimp*/QSize QScrollView::minimumSizeHint() const{    return QSize(100+frameWidth()*2,		 100+frameWidth()*2);}/*!  \reimp  (Implemented to get rid of a compiler warning.)*/void QScrollView::drawContents( QPainter * ){}#ifndef QT_NO_DRAGANDDROP/*!  \internal*/void QScrollView::startDragAutoScroll(){    if ( !d->autoscroll_timer.isActive() ) {	d->autoscroll_time = initialScrollTime;	d->autoscroll_accel = initialScrollAccel;	d->autoscroll_timer.start( d->autoscroll_time );    }}/*!  \internal*/void QScrollView::stopDragAutoScroll(){    d->autoscroll_timer.stop();}/*!  \internal*/void QScrollView::doDragAutoScroll(){    QPoint p = d->viewport.mapFromGlobal( QCursor::pos() );    if ( d->autoscroll_accel-- <= 0 && d->autoscroll_time ) {	d->autoscroll_accel = initialScrollAccel;	d->autoscroll_time--;	d->autoscroll_timer.start( d->autoscroll_time );    }    int l = QMAX( 1, ( initialScrollTime- d->autoscroll_time ) );    int dx = 0, dy = 0;    if ( p.y() < autoscroll_margin ) {	dy = -l;    } else if ( p.y() > visibleHeight() - autoscroll_margin ) {	dy = +l;    }    if ( p.x() < autoscroll_margin ) {	dx = -l;    } else if ( p.x() > visibleWidth() - autoscroll_margin ) {	dx = +l;    }    if ( dx || dy ) {	scrollBy(dx,dy);    } else {	stopDragAutoScroll();    }}/*!  If \a b is set to TRUE, the QScrollView automatically scrolls the contents  in drag move events if the user moves the cursor close to a border of the  view. This of course only works id the viewport accepts drops!  Specifying FALSE here disables this autoscroll feature.*/void QScrollView::setDragAutoScroll( bool b ){    d->drag_autoscroll = b;}/*!  Returns TRUE if autoscrolling in drag move events is enabled, else  FALSE.  \sa setDragAutoScroll()*/bool QScrollView::dragAutoScroll() const{    return d->drag_autoscroll;}#endif // QT_NO_DRAGANDDROP#endif // QT_NO_SCROLLVIEW

⌨️ 快捷键说明

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