📄 q3scrollview.cpp
字号:
You may want to call enableClipper(true) if you add a large number of widgets.*/void Q3ScrollView::addChild(QWidget* child, int x, int y){ if (!child) {#if defined(QT_CHECK_NULL) qWarning("Q3ScrollView::addChild(): Cannot add null child");#endif return; } child->polish(); child->setBackgroundOrigin(WidgetOrigin); if (child->parentWidget() == viewport()) { // May already be there QSVChildRec *r = d->rec(child); if (r) { r->moveTo(this,x,y,d->clipped_viewport); if (d->policy > Manual) { d->autoResizeHint(this); d->autoResize(this); // #### better to just deal with this one widget! } return; } } if (d->children.isEmpty() && d->policy != Manual) { if (d->policy == Default) setResizePolicy(AutoOne); child->installEventFilter(this); } else if (d->policy == AutoOne) { child->removeEventFilter(this); //#### ????? setResizePolicy(Manual); } if (child->parentWidget() != viewport()) { child->reparent(viewport(), 0, QPoint(0,0), false); } d->addChildRec(child,x,y)->hideOrShow(this, d->clipped_viewport); if (d->policy > Manual) { d->autoResizeHint(this); d->autoResize(this); // #### better to just deal with this one widget! }}/*! Repositions the \a child widget to (\a x, \a y). This function is the same as addChild().*/void Q3ScrollView::moveChild(QWidget* child, int x, int y){ addChild(child,x,y);}/*! Returns the X position of the given \a child widget. Use this rather than QWidget::x() for widgets added to the view. This function returns 0 if \a child has not been added to the view.*/int Q3ScrollView::childX(QWidget* child){ QSVChildRec *r = d->rec(child); return r ? r->x : 0;}/*! Returns the Y position of the given \a child widget. Use this rather than QWidget::y() for widgets added to the view. This function returns 0 if \a child has not been added to the view.*/int Q3ScrollView::childY(QWidget* child){ QSVChildRec *r = d->rec(child); return r ? r->y : 0;}/*! \fn bool Q3ScrollView::childIsVisible(QWidget*) \obsolete Returns true if \a child is visible. This is equivalent to child->isVisible().*//*! \fn void Q3ScrollView::showChild(QWidget* child, bool y) \obsolete Sets the visibility of \a child. Equivalent to QWidget::show() or QWidget::hide().*//*! This event filter ensures the scroll bars are updated when a single contents widget is resized, shown, hidden or destroyed; it passes mouse events to the Q3ScrollView. The event is in \a e and the object is in \a obj.*/bool Q3ScrollView::eventFilter(QObject *obj, QEvent *e){ bool disabled = !(qobject_cast<QWidget*>(obj)->isEnabled()); if (!d) return false; // we are destructing if (obj == d->viewport || obj == d->clipped_viewport) { switch (e->type()) { /* Forward many events to viewport...() functions */ case QEvent::Paint: viewportPaintEvent((QPaintEvent*)e); break; case QEvent::Resize: if (!d->clipped_viewport) viewportResizeEvent((QResizeEvent *)e); break; case QEvent::MouseButtonPress: if (disabled) return false; viewportMousePressEvent((QMouseEvent*)e); if (((QMouseEvent*)e)->isAccepted()) return true; break; case QEvent::MouseButtonRelease: if (disabled) return false; viewportMouseReleaseEvent((QMouseEvent*)e); if (((QMouseEvent*)e)->isAccepted()) return true; break; case QEvent::MouseButtonDblClick: if (disabled) return false; viewportMouseDoubleClickEvent((QMouseEvent*)e); if (((QMouseEvent*)e)->isAccepted()) return true; break; case QEvent::MouseMove: if (disabled) return false; viewportMouseMoveEvent((QMouseEvent*)e); if (((QMouseEvent*)e)->isAccepted()) return true; break;#ifndef QT_NO_DRAGANDDROP case QEvent::DragEnter: if (disabled) return false; viewportDragEnterEvent((QDragEnterEvent*)e); break; case QEvent::DragMove: { if (disabled) return false; if (d->drag_autoscroll) { QPoint vp = ((QDragMoveEvent*) e)->pos(); QRect inside_margin(autoscroll_margin, autoscroll_margin, visibleWidth() - autoscroll_margin * 2, visibleHeight() - autoscroll_margin * 2); if (!inside_margin.contains(vp)) { startDragAutoScroll(); // Keep sending move events ((QDragMoveEvent*)e)->accept(QRect(0,0,0,0)); } } viewportDragMoveEvent((QDragMoveEvent*)e); } break; case QEvent::DragLeave: if (disabled) return false; stopDragAutoScroll(); viewportDragLeaveEvent((QDragLeaveEvent*)e); break; case QEvent::Drop: if (disabled) return false; stopDragAutoScroll(); viewportDropEvent((QDropEvent*)e); break;#endif // QT_NO_DRAGANDDROP#ifndef QT_NO_WHEELEVENT case QEvent::Wheel: if (disabled) return false; break;#endif case QEvent::ContextMenu: if (disabled) return false; viewportContextMenuEvent((QContextMenuEvent*)e); if (((QContextMenuEvent*)e)->isAccepted()) return true; break; case QEvent::ChildRemoved: removeChild((QWidget*)((QChildEvent*)e)->child()); break; case QEvent::LayoutHint: d->autoResizeHint(this); break; default: break; } } else if (d && d->rec((QWidget*)obj)) { // must be a child if (e->type() == QEvent::Resize) d->autoResize(this); else if (e->type() == QEvent::Move) d->autoMove(this); } return Q3Frame::eventFilter(obj, e); // always continue with standard event processing}/*! This event handler is called whenever the Q3ScrollView receives a mousePressEvent(): the press position in \a e is translated to be a point on the contents.*/void Q3ScrollView::contentsMousePressEvent(QMouseEvent* e){ e->ignore();}/*! This event handler is called whenever the Q3ScrollView receives a mouseReleaseEvent(): the release position in \a e is translated to be a point on the contents.*/void Q3ScrollView::contentsMouseReleaseEvent(QMouseEvent* e){ e->ignore();}/*! This event handler is called whenever the Q3ScrollView receives a mouseDoubleClickEvent(): the click position in \a e is translated to be a point on the contents. The default implementation generates a normal mouse press event.*/void Q3ScrollView::contentsMouseDoubleClickEvent(QMouseEvent* e){ contentsMousePressEvent(e); // try mouse press event}/*! This event handler is called whenever the Q3ScrollView receives a mouseMoveEvent(): the mouse position in \a e is translated to be a point on the contents.*/void Q3ScrollView::contentsMouseMoveEvent(QMouseEvent* e){ e->ignore();}#ifndef QT_NO_DRAGANDDROP/*! This event handler is called whenever the Q3ScrollView receives a dragEnterEvent(): the drag position is translated to be a point on the contents. The default implementation does nothing. The \a event parameter is ignored.*/void Q3ScrollView::contentsDragEnterEvent(QDragEnterEvent * /* event */){}/*! This event handler is called whenever the Q3ScrollView receives a dragMoveEvent(): the drag position is translated to be a point on the contents. The default implementation does nothing. The \a event parameter is ignored.*/void Q3ScrollView::contentsDragMoveEvent(QDragMoveEvent * /* event */){}/*! This event handler is called whenever the Q3ScrollView receives a dragLeaveEvent(): the drag position is translated to be a point on the contents. The default implementation does nothing. The \a event parameter is ignored.*/void Q3ScrollView::contentsDragLeaveEvent(QDragLeaveEvent * /* event */){}/*! This event handler is called whenever the Q3ScrollView receives a dropEvent(): the drop position is translated to be a point on the contents. The default implementation does nothing. The \a event parameter is ignored.*/void Q3ScrollView::contentsDropEvent(QDropEvent * /* event */){}#endif // QT_NO_DRAGANDDROP/*! This event handler is called whenever the Q3ScrollView receives a wheelEvent() in \a{e}: the mouse position is translated to be a point on the contents.*/#ifndef QT_NO_WHEELEVENTvoid Q3ScrollView::contentsWheelEvent(QWheelEvent * e){ e->ignore();}#endif/*! This event handler is called whenever the Q3ScrollView receives a contextMenuEvent() in \a{e}: the mouse position is translated to be a point on the contents.*/void Q3ScrollView::contentsContextMenuEvent(QContextMenuEvent *e){ e->ignore();}/*! This is a low-level painting routine that draws the viewport contents. Reimplement this if drawContents() is too high-level (for example, if you don't want to open a QPainter on the viewport). The paint event is passed in \a pe.*/void Q3ScrollView::viewportPaintEvent(QPaintEvent* pe){ QWidget* vp = viewport(); QPainter p(vp); QRect r = pe->rect(); if (d->clipped_viewport) { QRect rr( -d->clipped_viewport->x(), -d->clipped_viewport->y(), d->viewport->width(), d->viewport->height() ); r &= rr; if (r.isValid()) { int ex = r.x() + d->clipped_viewport->x() + d->contentsX(); int ey = r.y() + d->clipped_viewport->y() + d->contentsY(); int ew = r.width(); int eh = r.height(); drawContentsOffset(&p, d->contentsX()+d->clipped_viewport->x(), d->contentsY()+d->clipped_viewport->y(), ex, ey, ew, eh); } } else { r &= d->viewport->rect(); int ex = r.x() + d->contentsX(); int ey = r.y() + d->contentsY(); int ew = r.width(); int eh = r.height(); drawContentsOffset(&p, d->contentsX(), d->contentsY(), ex, ey, ew, eh); }}/*! To provide simple processing of events on the contents, this function receives all resize events sent to the viewport. The default implementation does nothing. The \a event parameter is ignored. \sa QWidget::resizeEvent()*/void Q3ScrollView::viewportResizeEvent(QResizeEvent * /* event */){}/*! \internal To provide simple processing of events on the contents, this function receives all mouse press events sent to the viewport, translates the event and calls contentsMousePressEvent(). \sa contentsMousePressEvent(), QWidget::mousePressEvent()*/void Q3ScrollView::viewportMousePressEvent(QMouseEvent* e){ QMouseEvent ce(e->type(), viewportToContents(e->pos()), e->globalPos(), e->button(), e->state()); contentsMousePressEvent(&ce); if (!ce.isAccepted()) e->ignore();}/*!\internal To provide simple processing of events on the contents, this function receives all mouse release events sent to the viewport, translates the event and calls contentsMouseReleaseEvent(). \sa QWidget::mouseReleaseEvent()*/void Q3ScrollView::viewportMouseReleaseEvent(QMouseEvent* e){ QMouseEvent ce(e->type(), viewportToContents(e->pos()), e->globalPos(), e->button(), e->state()); contentsMouseReleaseEvent(&ce); if (!ce.isAccepted()) e->ignore();}/*!\internal To provide simple processing of events on the contents, this function receives all mouse double click events sent to the viewport, translates the event and calls contentsMouseDoubleClickEvent(). \sa QWidget::mouseDoubleClickEvent()*/void Q3ScrollView::viewportMouseDoubleClickEvent(QMouseEvent* e){ QMouseEvent ce(e->type(), viewportToContents(e->pos()), e->globalPos(), e->button(), e->state()); contentsMouseDoubleClickEvent(&ce); if (!ce.isAccepted()) e->ignore();}/*!\internal To provide simple processing of events on the contents, this function receives all mouse move events sent to the viewport, translates the event and calls contentsMouseMoveEvent(). \sa QWidget::mouseMoveEvent()*/void Q3ScrollView::viewportMouseMoveEvent(QMouseEvent* e){ QMouseEvent ce(e->type(), viewportToContents(e->pos()), e->globalPos(), e->button(), e->state()); contentsMouseMoveEvent(&ce); if (!ce.isAccepted()) e->ignore();}#ifndef QT_NO_DRAGANDDROP/*!\internal To provide simple processing of events on the contents, this function receives all drag enter events sent to the viewport, translates the event and calls contentsDragEnterEvent(). \sa QWidget::dragEnterEvent()*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -