📄 q3scrollview.cpp
字号:
void Q3ScrollView::viewportDragEnterEvent(QDragEnterEvent* e){ e->setPoint(viewportToContents(e->pos())); contentsDragEnterEvent(e); e->setPoint(contentsToViewport(e->pos()));}/*!\internal To provide simple processing of events on the contents, this function receives all drag move events sent to the viewport, translates the event and calls contentsDragMoveEvent(). \sa QWidget::dragMoveEvent()*/void Q3ScrollView::viewportDragMoveEvent(QDragMoveEvent* e){ e->setPoint(viewportToContents(e->pos())); contentsDragMoveEvent(e); e->setPoint(contentsToViewport(e->pos()));}/*!\internal To provide simple processing of events on the contents, this function receives all drag leave events sent to the viewport and calls contentsDragLeaveEvent(). \sa QWidget::dragLeaveEvent()*/void Q3ScrollView::viewportDragLeaveEvent(QDragLeaveEvent* e){ contentsDragLeaveEvent(e);}/*!\internal To provide simple processing of events on the contents, this function receives all drop events sent to the viewport, translates the event and calls contentsDropEvent(). \sa QWidget::dropEvent()*/void Q3ScrollView::viewportDropEvent(QDropEvent* e){ e->setPoint(viewportToContents(e->pos())); contentsDropEvent(e); e->setPoint(contentsToViewport(e->pos()));}#endif // QT_NO_DRAGANDDROP/*!\internal To provide simple processing of events on the contents, this function receives all wheel events sent to the viewport, translates the event and calls contentsWheelEvent(). \sa QWidget::wheelEvent()*/#ifndef QT_NO_WHEELEVENTvoid Q3ScrollView::viewportWheelEvent(QWheelEvent* e){ /* Different than standard mouse events, because wheel events might be sent to the focus widget if the widget-under-mouse doesn't want the event itself. */ QWheelEvent ce(viewportToContents(e->pos()), e->globalPos(), e->delta(), e->state()); contentsWheelEvent(&ce); if (ce.isAccepted()) e->accept(); else e->ignore();}#endif/*! \internal To provide simple processing of events on the contents, this function receives all context menu events sent to the viewport, translates the event and calls contentsContextMenuEvent().*/void Q3ScrollView::viewportContextMenuEvent(QContextMenuEvent *e){ QContextMenuEvent ce(e->reason(), viewportToContents(e->pos()), e->globalPos(), e->state()); contentsContextMenuEvent(&ce); if (ce.isAccepted()) e->accept(); else e->ignore();}/*! Returns the component horizontal scroll bar. It is made available to allow accelerators, autoscrolling, etc. It should not be used for other purposes. This function never returns 0.*/QScrollBar* Q3ScrollView::horizontalScrollBar() const{ return d->hbar;}/*! Returns the component vertical scroll bar. It is made available to allow accelerators, autoscrolling, etc. It should not be used for other purposes. This function never returns 0.*/QScrollBar* Q3ScrollView::verticalScrollBar() const { return d->vbar;}/*! Scrolls the content so that the point (\a x, \a y) is visible with at least 50-pixel margins (if possible, otherwise centered).*/void Q3ScrollView::ensureVisible(int x, int y){ ensureVisible(x, y, 50, 50);}/*! \overload Scrolls the content so that the point (\a x, \a y) is visible with at least the \a xmargin and \a ymargin margins (if possible, otherwise centered).*/void Q3ScrollView::ensureVisible(int x, int y, int xmargin, int ymargin){ int pw=visibleWidth(); int ph=visibleHeight(); int cx=-d->contentsX(); int cy=-d->contentsY(); int cw=d->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 (\a x, \a y) is in the top-left corner.*/void Q3ScrollView::setContentsPos(int x, int y){#if 0 // bounds checking... if (QApplication::reverseLayout()) if (x > d->contentsWidth() - visibleWidth()) x = d->contentsWidth() - visibleWidth(); else#endif 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); d->signal_choke=false;}/*! Scrolls the content by \a dx to the left and \a dy upwards.*/void Q3ScrollView::scrollBy(int dx, int dy){ setContentsPos(QMAX(d->contentsX()+dx, 0), QMAX(d->contentsY()+dy, 0));}/*! Scrolls the content so that the point (\a x, \a y) is in the center of visible area.*/void Q3ScrollView::center(int x, int y){ ensureVisible(x, y, 32000, 32000);}/*! \overload Scrolls the content so that the point (\a x, \a y) is visible with the \a xmargin and \a ymargin margins (as fractions of visible the area). For example: \list \i Margin 0.0 allows (x, y) to be on the edge of the visible area. \i Margin 0.5 ensures that (x, y) is in middle 50% of the visible area. \i Margin 1.0 ensures that (x, y) is in the center of the the visible area. \endlist*/void Q3ScrollView::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 Q3ScrollView::contentsMoving(int x, int y) This signal is emitted just before the contents are moved to position (\a x, \a y). \sa contentsX(), contentsY()*//*! Moves the contents by (\a x, \a y).*/void Q3ScrollView::moveContents(int x, int y){ if (-x+visibleWidth() > d->contentsWidth())#if 0 if(QApplication::reverseLayout()) x=QMAX(0,-d->contentsWidth()+visibleWidth()); else#endif x=QMIN(0,-d->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()->updatesEnabled()) viewport()->update(); d->moveAllBy(dx,dy); } else if (!d->fake_scroll || d->contentsWidth() > visibleWidth()) { // Small move clipper()->scroll(dx,dy); } d->hideOrShowAll(this, true);}/*! \property Q3ScrollView::contentsX \brief the X coordinate of the contents that are at the left edge of the viewport.*/int Q3ScrollView::contentsX() const{ return d->contentsX();}/*! \property Q3ScrollView::contentsY \brief the Y coordinate of the contents that are at the top edge of the viewport.*/int Q3ScrollView::contentsY() const{ return d->contentsY();}/*! \property Q3ScrollView::contentsWidth \brief the width of the contents area*/int Q3ScrollView::contentsWidth() const{ return d->contentsWidth();}/*! \property Q3ScrollView::contentsHeight \brief the height of the contents area*/int Q3ScrollView::contentsHeight() const{ return d->vheight;}/*! Sets the size of the contents area to \a w pixels wide and \a h pixels high and updates the viewport accordingly.*/void Q3ScrollView::resizeContents(int w, int h){ int ow = d->vwidth; int oh = d->vheight; d->vwidth = w; d->vheight = h; d->scrollbar_timer.start(0, true); 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(d->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, d->contentsY()+oh, visibleWidth(), h-oh); }}/*! Calls update() on a rectangle defined by \a x, \a y, \a w, \a h, translated appropriately. If the rectangle is not visible, nothing is repainted. \sa repaintContents()*/void Q3ScrollView::updateContents(int x, int y, int w, int h){ if (!isVisible() || !updatesEnabled()) return; QWidget* vp = viewport(); // Translate x -= d->contentsX(); y -= d->contentsY(); if (x < 0) { w += x; x = 0; } if (y < 0) { h += y; y = 0; } if (w < 0 || h < 0) return; if (x > visibleWidth() || y > visibleHeight()) 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 Updates the contents in rectangle \a r*/void Q3ScrollView::updateContents(const QRect& r){ updateContents(r.x(), r.y(), r.width(), r.height());}/*! \overload*/void Q3ScrollView::updateContents(){ updateContents(d->contentsX(), d->contentsY(), visibleWidth(), visibleHeight());}/*! \overload Repaints the contents of rectangle \a r. If \a erase is true the background is cleared using the background color.*/void Q3ScrollView::repaintContents(const QRect& r, bool erase){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -