1.bool isVisibleTo(const QWidget *) const;
/*!
Returns \c true if this widget would become visible if \a ancestor is
shown; otherwise returns \c false.
The true case occurs if neither the widget itself nor any parent
up to but excluding \a ancestor has been explicitly hidden.
This function will still return true if the widget is obscured by
other windows on the screen, but could be physically visible if it
or they were to be moved.
isVisibleTo(0) is identical to isVisible().
\sa show(), hide(), isVisible()
*/
bool QWidget::isVisibleTo(const QWidget *ancestor) const
{
if (!ancestor)
return isVisible();
const QWidget * w = this;
while (!w->isHidden()
&& !w->isWindow()
&& w->parentWidget()
&& w->parentWidget() != ancestor)
w = w->parentWidget();
return !w->isHidden();
}
如果QWidget本身或任何父级(但不包括祖先)都没有被显式隐藏,则返回true。
2.bool isEnabledTo(const QWidget *) const;
bool QWidget::isEnabledTo(const QWidget *ancestor) const
{
const QWidget * w = this;
while (!w->testAttribute(Qt::WA_ForceDisabled)
&& !w->isWindow()
&& w->parentWidget()
&& w->parentWidget() != ancestor)
w = w->parentWidget();
return !w->testAttribute(Qt::WA_ForceDisabled);
}
3.bool isWindow() const;
inline bool QWidget::isWindow() const
{ return (windowType() & Qt::Window); }
inline Qt::WindowType QWidget::windowType() const
{ return static_cast<Qt::WindowType>(int(data->window_flags & Qt::WindowType_Mask)); }
根据QWidget类型判断是否是window.
4.QRegion visibleRegion() const;
/*!
Returns the unobscured region where paint events can occur.
For visible widgets, this is an approximation of the area not
covered by other widgets; otherwise, this is an empty region.
The repaint() function calls this function if necessary, so in
general you do not need to call it.
*/
QRegion QWidget::visibleRegion() const
{
Q_D(const QWidget);
QRect clipRect = d->clipRect();
if (clipRect.isEmpty())
return QRegion();
QRegion r(clipRect);
d->subtractOpaqueChildren(r, clipRect);
d->subtractOpaqueSiblings(r);
return r;
}
QRect QWidgetPrivate::clipRect() const
{
Q_Q(const QWidget);
const QWidget * w = q;
if (!w->isVisible())
return QRect();
QRect r = effectiveRectFor(q->rect());
int ox = 0;
int oy = 0;
while (w
&& w->isVisible()
&& !w->isWindow()
&& w->parentWidget()) {
ox -= w->x();
oy -= w->y();
w = w->parentWidget();
r &= QRect(ox, oy, w->width(), w->height());
}
return r;
}
inline QRect effectiveRectFor(const QRect &rect) const
{
#if QT_CONFIG(graphicseffect)
if (graphicsEffect && graphicsEffect->isEnabled())
return graphicsEffect->boundingRectFor(rect).toAlignedRect();
#endif // QT_CONFIG(graphicseffect)
return rect;
}
void QWidgetPrivate::subtractOpaqueChildren(QRegion &source, const QRect &clipRect) const
{
if (children.isEmpty() || clipRect.isEmpty())
return;
const QRegion &r = getOpaqueChildren();
if (!r.isEmpty())
source -= (r & clipRect);
}
void QWidgetPrivate::subtractOpaqueSiblings(QRegion &sourceRegion, bool *hasDirtySiblingsAbove,
bool alsoNonOpaque) const
{
Q_Q(const QWidget);
static int disableSubtractOpaqueSiblings = qEnvironmentVariableIntValue("QT_NO_SUBTRACTOPAQUESIBLINGS");
if (disableSubtractOpaqueSiblings || q->isWindow())
return;
QRect clipBoundingRect;
bool dirtyClipBoundingRect = true;
QRegion parentClip;
bool dirtyParentClip = true;
QPoint parentOffset = data.crect.topLeft();
const QWidget *w = q;
while (w) {
if (w->isWindow())
break;
QWidgetPrivate *pd = w->parentWidget()->d_func();
const int myIndex = pd->children.indexOf(const_cast<QWidget *>(w));
const QRect widgetGeometry = w->d_func()->effectiveRectFor(w->data->crect);
for (int i = myIndex + 1; i < pd->children.size(); ++i) {
QWidget *sibling = qobject_cast<QWidget *>(pd->children.at(i));
if (!sibling || !sibling->isVisible() || sibling->isWindow())
continue;
const QRect siblingGeometry = sibling->d_func()->effectiveRectFor(sibling->data->crect);
if (!qRectIntersects(siblingGeometry, widgetGeometry))
continue;
if (dirtyClipBoundingRect) {
clipBoundingRect = sourceRegion.boundingRect();
dirtyClipBoundingRect = false;
}
if (!qRectIntersects(siblingGeometry, clipBoundingRect.translated(parentOffset)))
continue;
if (dirtyParentClip) {
parentClip = sourceRegion.translated(parentOffset);
dirtyParentClip = false;
}
const QPoint siblingPos(sibling->data->crect.topLeft());
const QRect siblingClipRect(sibling->d_func()->clipRect());
QRegion siblingDirty(parentClip);
siblingDirty &= (siblingClipRect.translated(siblingPos));
const bool hasMask = sibling->d_func()->extra && sibling->d_func()->extra->hasMask
&& !sibling->d_func()->graphicsEffect;
if (hasMask)
siblingDirty &= sibling->d_func()->extra->mask.translated(siblingPos);
if (siblingDirty.isEmpty())
continue;
if (sibling->d_func()->isOpaque || alsoNonOpaque) {
if (hasMask) {
siblingDirty.translate(-parentOffset);
sourceRegion -= siblingDirty;
} else {
sourceRegion -= siblingGeometry.translated(-parentOffset);
}
} else {
if (hasDirtySiblingsAbove)
*hasDirtySiblingsAbove = true;
if (sibling->d_func()->children.isEmpty())
continue;
QRegion opaqueSiblingChildren(sibling->d_func()->getOpaqueChildren());
opaqueSiblingChildren.translate(-parentOffset + siblingPos);
sourceRegion -= opaqueSiblingChildren;
}
if (sourceRegion.isEmpty())
return;
dirtyClipBoundingRect = true;
dirtyParentClip = true;
}
w = w->parentWidget();
parentOffset += pd->data.crect.topLeft();
dirtyParentClip = true;
}
}
返回可以发生绘制事件的未遮挡区域。对于可见的QWidget,这是没被被其他小部件覆盖的面积的近似值; 否则,这是一个空白区域。