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

📄 qscrollview.cpp

📁 qtopia-phone-2.2.0下公共的控件实现源代码。
💻 CPP
📖 第 1 页 / 共 5 页
字号:
  <li> \c Manual - the view stays the size set by resizeContents().  <li> \c AutoOne - if there is only child widget, the view stays  the size of that widget.  Otherwise, the behaviour is undefined.  <li> \c AutoOneFit - if there is only one child widget the view stays  the size of that widget's sizeHint(). If the scrollview is resized bigger  than the child's sizeHint(), the child will be resized to fit.  If there is more than one child, the behaviour is undefined.  </ul>*///####  The widget will be resized to its sizeHint() when a LayoutHint event//#### is received/*!  Constructs a QScrollView with a \a parent, a \a name and widget  flags \a f.  The widget flags \c WNorthWestGravity, \c WRepaintNoErase and \c  WPaintClever are propagated to the viewport() widget. The other  widget flags are propagated to the parent constructor as usual.*/QScrollView::QScrollView( QWidget *parent, const char *name, WFlags f ) :    QFrame( parent, name, f & (~WNorthWestGravity) & (~WRepaintNoErase), FALSE ){    d = new QScrollViewData(this,WResizeNoErase |	    (f&WPaintClever) | (f&WRepaintNoErase) | (f&WNorthWestGravity) );#ifndef QT_NO_DRAGANDDROP    connect( &d->autoscroll_timer, SIGNAL( timeout() ),	     this, SLOT( doDragAutoScroll() ) );#endif    connect( &d->hbar, SIGNAL( valueChanged(int) ),	this, SLOT( hslide(int) ) );    connect( &d->vbar, SIGNAL( valueChanged(int) ),	this, SLOT( vslide(int) ) );    d->viewport.installEventFilter( this );    setFrameStyle( QFrame::StyledPanel | QFrame::Sunken );    setLineWidth( style().defaultFrameWidth() );    setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );#ifdef QT_KEYPAD_MODE    if( qt_modalEditingEnabled ) {	installEventFilter(this);    }#endif}/*!  Destructs the QScrollView.  Any children added with addChild()  will be destructed.*/QScrollView::~QScrollView(){    // Be careful not to get all those useless events...    if ( d->clipped_viewport )	d->clipped_viewport->removeEventFilter( this );    else	d->viewport.removeEventFilter( this );    QScrollViewData* d2 = d;    d = 0;    delete d2;}/*!  \reimp*/void QScrollView::styleChange( QStyle& old ){    QWidget::styleChange( old );    updateScrollBars();}void QScrollView::hslide( int pos ){    if ( !d->signal_choke ) {	moveContents( -pos, -contentsY() );	QApplication::syncX();    }}void QScrollView::vslide( int pos ){    if ( !d->signal_choke ) {	if ( testWState(WState_GlobalBrushOrigin) ) {	    // Reduce flicker by moving line at a time.	    if (pos < verticalScrollBar()->maxValue()) {		int step = verticalScrollBar()->lineStep();		pos = (pos + step/2) / step * step;	    }	}	moveContents( -contentsX(), -pos );	QApplication::syncX();    }}/*!  Called when the horizontal scrollbar geometry changes.  This is provided  as a protected function so that subclasses can do interesting things  like providing extra buttons in some of the space normally used by the  scrollbars.  The default implementation simply gives all the space to \a hbar.  \sa setVBarGeometry()*/void QScrollView::setHBarGeometry(QScrollBar& hbar,    int x, int y, int w, int h){    hbar.setGeometry( x, y, w, h );}/*!  Called when the vertical scrollbar geometry changes.  This is provided  as a protected function so that subclasses can do interesting things  like providing extra buttons in some of the space normally used by the  scrollbars.  The default implementation simply gives all the space to \a vbar.  \sa setHBarGeometry()*/void QScrollView::setVBarGeometry( QScrollBar& vbar,    int x, int y, int w, int h){    vbar.setGeometry( x, y, w, h );}/*! Returns the viewport size for size (\a x, \a y).  The viewport size depends on \a x,y (the size of the contents), the  size of this widget, the modes of the horizontal and vertical scroll  bars.  This function permits widgets that can trade vertical and horizontal  space for each other to control scroll bar appearance better.  For  example, a word processor or web browser can control the width of  the right margin accurately, whether there needs to be a vertical  scroll bar or not.*/QSize QScrollView::viewportSize( int x, int y ) const{    int fw = frameWidth();    int lmarg = fw+d->l_marg;    int rmarg = fw+d->r_marg;    int tmarg = fw+d->t_marg;    int bmarg = fw+d->b_marg;    int w = width();    int h = height();    bool needh, needv;    bool showh, showv;    int hsbExt = horizontalScrollBar()->sizeHint().height();    int vsbExt = verticalScrollBar()->sizeHint().width();    if ( d->policy != AutoOne || d->anyVisibleChildren() ) {	// Do we definitely need the scrollbar?	needh = w-lmarg-rmarg < x;	needv = h-tmarg-bmarg < y;	// Do we intend to show the scrollbar?	if (d->hMode == AlwaysOn)	    showh = TRUE;	else if (d->hMode == AlwaysOff)	    showh = FALSE;	else	    showh = needh;	if (d->vMode == AlwaysOn)	    showv = TRUE;	else if (d->vMode == AlwaysOff)	    showv = FALSE;	else	    showv = needv;	// Given other scrollbar will be shown, NOW do we need one?	if ( showh && h-vsbExt-tmarg-bmarg < y ) {	    if (d->vMode == Auto)		showv=TRUE;	}	if ( showv && w-hsbExt-lmarg-rmarg < x ) {	    if (d->hMode == Auto)		showh=TRUE;	}    } else {	// Scrollbars not needed, only show scrollbar that are always on.	showh = d->hMode == AlwaysOn;	showv = d->vMode == AlwaysOn;    }    return QSize( w-lmarg-rmarg - (showv ? vsbExt : 0),		  h-tmarg-bmarg - (showh ? hsbExt : 0) );}/*  The surrounding environment (or application, if there is no  environment, may set this. Requires Qt >= 2.3.8.*/bool qt_left_hand_scrollbars = FALSE;/*!  Updates scrollbars - all possibilities considered.  You should never  need to call this in your code.*/void QScrollView::updateScrollBars(){    // I support this should use viewportSize()... but it needs    // so many of the temporary variables from viewportSize.  hm.    int fw = frameWidth();    int lmarg = fw+d->l_marg;    int rmarg = fw+d->r_marg;    int tmarg = fw+d->t_marg;    int bmarg = fw+d->b_marg;    int w = width();    int h = height();    int portw, porth;    bool needh;    bool needv;    bool showh;    bool showv;    int hsbExt = horizontalScrollBar()->sizeHint().height();    int vsbExt = verticalScrollBar()->sizeHint().width();    if ( d->policy != AutoOne || d->anyVisibleChildren() ) {	// Do we definitely need the scrollbar?	needh = w-lmarg-rmarg < contentsWidth();	needv = h-tmarg-bmarg < contentsHeight();	// Do we intend to show the scrollbar?	if (d->hMode == AlwaysOn)	    showh = TRUE;	else if (d->hMode == AlwaysOff)	    showh = FALSE;	else	    showh = needh;	if (d->vMode == AlwaysOn)	    showv = TRUE;	else if (d->vMode == AlwaysOff)	    showv = FALSE;	else	    showv = needv;	// Given other scrollbar will be shown, NOW do we need one?	if ( showh && h-vsbExt-tmarg-bmarg < contentsHeight() ) {	    needv=TRUE;	    if (d->vMode == Auto)		showv=TRUE;	}	if ( showv && w-hsbExt-lmarg-rmarg < contentsWidth() ) {	    needh=TRUE;	    if (d->hMode == Auto)		showh=TRUE;	}    } else {	// Scrollbars not needed, only show scrollbar that are always on.	needh = needv = FALSE;	showh = d->hMode == AlwaysOn;	showv = d->vMode == AlwaysOn;    }    bool sc = d->signal_choke;    d->signal_choke=TRUE;    // Hide unneeded scrollbar, calculate viewport size    if ( showh ) {        porth=h-hsbExt-tmarg-bmarg;    } else {	if (!needh)	    d->hbar.setValue(0);	d->hbar.hide();	porth=h-tmarg-bmarg;    }    if ( showv ) {	portw=w-vsbExt-lmarg-rmarg;    } else {	if (!needv)	    d->vbar.setValue(0);	d->vbar.hide();	portw=w-lmarg-rmarg;    }    // Configure scrollbars that we will show	if ( needv ) {	    d->vbar.setRange( 0, contentsHeight()-porth );	    d->vbar.setSteps( QScrollView::d->vbar.lineStep(), porth );	} else {	    d->vbar.setRange( 0, 0 );	}	if ( needh ) {	    d->hbar.setRange( 0, contentsWidth()-portw );	    d->hbar.setSteps( QScrollView::d->hbar.lineStep(), portw );	} else {	    d->hbar.setRange( 0, 0 );	}    // Position the scrollbars, viewport, and corner widget.    int bottom;    int xoffset = ( qt_left_hand_scrollbars && ( showv || cornerWidget() ) ) ? vsbExt : 0;    int xpos    =   qt_left_hand_scrollbars ? 0 : w-vsbExt;    xpos    =  (style() == WindowsStyle) && qt_left_hand_scrollbars ? xpos + fw : xpos - fw;    int ypos    = tmarg;    ypos        = (style() == WindowsStyle) ? ypos +fw : 0;    if ( showh ) {	int right = ( showv || cornerWidget() ) ? w-vsbExt : w;	if ( style() == WindowsStyle )            setHBarGeometry(d->hbar, fw + xoffset , h-hsbExt-fw,                            right-fw-fw, hsbExt );	else            setHBarGeometry(d->hbar, 0+  xoffset, h-hsbExt, right,                            hsbExt );	bottom=h-hsbExt;    } else {        bottom=h;    }    if ( showv ) {	clipper()->setGeometry( lmarg + xoffset, tmarg,                                w-vsbExt-lmarg-rmarg,                                bottom-tmarg-bmarg );	d->viewportResized( w-vsbExt-lmarg-rmarg, bottom-tmarg-bmarg );	if ( style() == WindowsStyle )	    changeFrameRect(QRect(xoffset, 0, w, h) );	else	    changeFrameRect(QRect(xoffset, 0, w-vsbExt, bottom));	if (cornerWidget()) {	    bottom = h-hsbExt;	// must reserve space for corner button	    if ( style() == WindowsStyle )                setVBarGeometry( d->vbar, xpos,                                 ypos, vsbExt,                                 bottom-fw-ypos );	    else                setVBarGeometry( d->vbar, xpos, ypos,                                 vsbExt,                                 bottom-ypos );	}	else {	    if ( style() == WindowsStyle )                setVBarGeometry( d->vbar, xpos,                                 ypos, vsbExt,                                 bottom-fw-ypos );	    else                setVBarGeometry( d->vbar, xpos, ypos,                                 vsbExt, bottom-ypos );	}    } else {	if ( style() == WindowsStyle )	    changeFrameRect(QRect(0, 0, w, h));	else	    changeFrameRect(QRect(0, 0, w, bottom));	clipper()->setGeometry( lmarg, tmarg,				 w-lmarg-rmarg, bottom-tmarg-bmarg );	d->viewportResized( w-lmarg-rmarg, bottom-tmarg-bmarg );    }    if ( d->corner ) {	if ( style() == WindowsStyle )            d->corner->setGeometry( xpos,                                    h-hsbExt-fw,                                    vsbExt,                                    hsbExt );	else            d->corner->setGeometry( xpos,                                    h-hsbExt,                                    vsbExt,                                    hsbExt );    }    d->signal_choke=sc;    if ( contentsX()+visibleWidth() > contentsWidth() ) {	int x=QMAX(0,contentsWidth()-visibleWidth());	d->hbar.setValue(x);	// Do it even if it is recursive	moveContents( -x, -contentsY() );    }    if ( contentsY()+visibleHeight() > contentsHeight() ) {	int y=QMAX(0,contentsHeight()-visibleHeight());	d->vbar.setValue(y);	// Do it even if it is recursive	moveContents( -contentsX(), -y );    }    // Finally, show the scrollbars.    if ( showh && !d->hbar.isVisible() )	d->hbar.show();    if ( showv && !d->vbar.isVisible() )	d->vbar.show();}/*! \reimp*/void QScrollView::show(){    //     Ensures that scrollbars have the correct size when the    //     widget is shown.    if (isVisible()) return;    QWidget::show();    updateScrollBars();    d->hideOrShowAll(this);}/*! \reimp */void QScrollView::resize( int w, int h ){    //   Ensures that scrollbars have the correct size when the widget is    //   resized.    QWidget::resize( w, h );}/*! \reimp*/void QScrollView::resize( const QSize& s ){    //   Ensures that scrollbars have the correct size when the widget is    //   resized.    resize(s.width(),s.height());}/*! \reimp*/void QScrollView::resizeEvent( QResizeEvent* event ){    // Ensures that scrollbars have the correct size when the widget    // is resized.    bool u = isUpdatesEnabled();    setUpdatesEnabled( FALSE );    QFrame::resizeEvent( event );    // do _not_ update the scrollbars when updates have been    // disabled. This makes it possible for subclasses to implement    // dynamic wrapping without a horizontal scrollbar showing up all    // the time when making a window smaller.    if ( u )	updateScrollBars();    d->hideOrShowAll(this);    setUpdatesEnabled( u );}/*! \reimp*/void QScrollView::wheelEvent( QWheelEvent *e ){    QWheelEvent ce( viewport()->mapFromGlobal( e->globalPos() ),		    e->globalPos(), e->delta(), e->state());    viewportWheelEvent(&ce);    if ( !ce.isAccepted() ) {	if (verticalScrollBar())	    QApplication::sendEvent( verticalScrollBar(), e);    }}/*!  Returns the currently set mode for the vertical scrollbar.  \sa setVScrollBarMode()*/QScrollView::ScrollBarMode QScrollView::vScrollBarMode() const{    return d->vMode;}/*! \enum QScrollView::ScrollBarMode  This enum type describes the various modes of QScrollView's scroll  bars.  The defined modes are: <ul>   <li> \c Auto - QScrollView shows a scrollbar when the content is   too tall to fit and not else.  This is the default.   <li> \c AlwaysOff - QScrollView never shows a scrollbar.   <li> \c AlwaysOn - QScrollView always shows a scrollbar.

⌨️ 快捷键说明

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