📄 render_object.cpp
字号:
p->setRasterOp(Qt::CopyROP);}void RenderObject::printBorder(QPainter *p, int _tx, int _ty, int w, int h, const RenderStyle* style, bool begin, bool end){ const QColor& tc = style->borderTopColor(); const QColor& lc = style->borderLeftColor(); const QColor& rc = style->borderRightColor(); const QColor& bc = style->borderBottomColor(); bool render_t = style->borderTopStyle() != BNONE && style->borderTopStyle() != BHIDDEN; bool render_l = style->borderLeftStyle() != BNONE && style->borderLeftStyle() != BHIDDEN && begin; bool render_r = style->borderRightStyle() != BNONE && style->borderRightStyle() != BHIDDEN && end; bool render_b = style->borderBottomStyle() != BNONE && style->borderBottomStyle() != BHIDDEN; if(render_r) drawBorder(p, _tx + w, _ty, _tx + w, _ty + h, style->borderRightWidth(), BSRight, rc, style->color(), style->borderRightStyle(), render_t && tc != rc, render_b && bc != rc, style->borderTopWidth(), style->borderBottomWidth()); if(render_b) drawBorder(p, _tx, _ty + h, _tx + w, _ty + h, style->borderBottomWidth(), BSBottom, bc, style->color(), style->borderBottomStyle(), render_l && lc != bc, render_r && rc != bc, style->borderLeftWidth(), end ? style->borderRightWidth() : 0); if(render_l) drawBorder(p, _tx, _ty, _tx, _ty + h, style->borderLeftWidth(), BSLeft, lc, style->color(), style->borderLeftStyle(), render_t && tc != lc, render_b && bc != lc, style->borderTopWidth(), style->borderBottomWidth()); if(render_t) drawBorder(p, _tx, _ty, _tx + w, _ty, style->borderTopWidth(), BSTop, tc, style->color(), style->borderTopStyle(), render_l && lc != tc, render_r && rc != tc, begin ? style->borderLeftWidth() : 0, style->borderRightWidth());}void RenderObject::printOutline(QPainter *p, int _tx, int _ty, int w, int h, const RenderStyle* style){ int ow = style->outlineWidth(); if(!ow) return; const QColor& oc = style->outlineColor(); EBorderStyle os = style->outlineStyle(); drawBorder(p, _tx - ow, _ty-ow, _tx - ow, _ty + h+ow, ow, BSLeft, oc, style->color(), os, false, false, ow, ow, true); drawBorder(p, _tx - ow, _ty - ow, _tx + w + ow, _ty - ow, ow, BSTop, oc, style->color(), os, false, false, ow, ow, true); drawBorder(p, _tx + w + ow, _ty - ow, _tx + w + ow, _ty + h + ow, ow, BSRight, oc, style->color(), os, false, false, ow, ow, true); drawBorder(p, _tx -ow, _ty + h + ow, _tx + w + ow, _ty + h + ow, ow, BSBottom, oc, style->color(), os, false, false, ow, ow, true);}void RenderObject::print( QPainter *p, int x, int y, int w, int h, int tx, int ty){ printObject(p, x, y, w, h, tx, ty);}void RenderObject::repaintRectangle(int x, int y, int w, int h, bool f){ if(parent()) parent()->repaintRectangle(x, y, w, h, f);}void RenderObject::printTree(int indent) const{ QString ind; ind.fill(' ', indent); int childcount = 0; for(RenderObject* c = firstChild(); c; c = c->nextSibling()) childcount++; kdDebug() << ind << renderName() << (childcount ? (QString::fromLatin1("[") + QString::number(childcount) + QString::fromLatin1("]")) : QString::null) << "(" << (style() ? style()->refCount() : 0) << ")" << ": " << (void*)this << " il=" << (int)isInline() << " ci=" << (int) childrenInline() << " fl=" << (int)isFloating() << " rp=" << (int)isReplaced() << " an=" << (int)isAnonymousBox() << " ps=" << (int)isPositioned() << " cp=" << (int)containsPositioned() << " lt=" << (int)layouted() << " cw=" << (int)containsWidget() << " pa=" << (int)parsing() << " (" << xPos() << "," << yPos() << "," << width() << "," << height() << ")" << endl; RenderObject *child = firstChild(); while( child != 0 ) { child->printTree(indent+2); child = child->nextSibling(); }}void RenderObject::selectionStartEnd(int& spos, int& epos){ if (parent()) parent()->selectionStartEnd(spos, epos);}void RenderObject::updateSize(){ containingBlock()->updateSize();}void RenderObject::setStyle(RenderStyle *style){ if (m_style == style) return; // reset style flags m_floating = false; m_positioned = false; m_relPositioned = false; m_printSpecial = false; // no support for changing the display type dynamically... object must be // detached and re-attached as a different type //m_inline = true; m_visible = true; RenderStyle *oldStyle = m_style; m_style = style; CachedImage* ob = 0; CachedImage* nb = 0; if (m_style) { m_style->ref(); nb = m_style->backgroundImage(); } if (oldStyle) { ob = oldStyle->backgroundImage(); oldStyle->deref(); } if( ob != nb ) { if(ob) ob->deref(this); if(nb) nb->ref(this); } if( m_style->backgroundColor().isValid() || m_style->hasBorder() || nb ) setSpecialObjects(true); else setSpecialObjects(false); if( m_style->visiblity() == HIDDEN || m_style->visiblity() == COLLAPSE ) m_visible = false; m_hasFirstLine = (style->getPseudoStyle(RenderStyle::FIRST_LINE) != 0); setMinMaxKnown(false); setLayouted(false);}void RenderObject::setContainsPositioned(bool p){ if (p) { m_containsPositioned = true; if (containingBlock()!=this) containingBlock()->setContainsPositioned(true); } else { RenderObject *n; bool c=false; for( n = firstChild(); n != 0; n = n->nextSibling() ) { if (n->isPositioned() || n->containsPositioned()) c=true; } if (c) return; else { m_containsPositioned = false; if (containingBlock()!=this) containingBlock()->setContainsPositioned(false); } }}QRect RenderObject::viewRect() const{ return containingBlock()->viewRect();}bool RenderObject::absolutePosition(int &xPos, int &yPos, bool f){ if(parent()) return parent()->absolutePosition(xPos, yPos, f); else { xPos = yPos = 0; return false; }}void RenderObject::cursorPos(int /*offset*/, int &_x, int &_y, int &height){ _x = _y = height = -1;}int RenderObject::paddingTop() const{ int cw=0; if (style()->paddingTop().isPercent()) cw = containingBlock()->contentWidth(); return m_style->paddingTop().minWidth(cw);}int RenderObject::paddingBottom() const{ int cw=0; if (style()->paddingBottom().isPercent()) cw = containingBlock()->contentWidth(); return m_style->paddingBottom().minWidth(cw);}int RenderObject::paddingLeft() const{ int cw=0; if (style()->paddingLeft().isPercent()) cw = containingBlock()->contentWidth(); return m_style->paddingLeft().minWidth(cw);}int RenderObject::paddingRight() const{ int cw=0; if (style()->paddingRight().isPercent()) cw = containingBlock()->contentWidth(); return m_style->paddingRight().minWidth(cw);}RenderRoot* RenderObject::root() const{ RenderObject* o = const_cast<RenderObject*>( this ); while ( o->parent() ) o = o->parent(); assert( o->isRoot() ); return static_cast<RenderRoot*>( o );}RenderObject *RenderObject::container() const{ EPosition pos = m_style->position(); RenderObject *o = 0; if( pos == FIXED ) o = root(); else if ( pos == ABSOLUTE ) o = containingBlock(); else o = parent(); return o;}void RenderObject::invalidateLayout(){ setLayouted(false); if (m_parent && m_parent->layouted()) m_parent->invalidateLayout();}void RenderObject::removeFromSpecialObjects(){ if (isPositioned() || isFloating()) { RenderObject *p; for (p = parent(); p; p = p->parent()) { if (p->isFlow()) static_cast<RenderFlow*>(p)->removeSpecialObject(this); } }}void RenderObject::detach(){ // deleting a selected object means big trouble... if (selectionState() != SelectionNone) root()->clearSelection(); remove(); // by default no refcounting delete this;}bool RenderObject::containsPoint(int _x, int _y, int _tx, int _ty){ return ((_y >= _ty) && (_y < _ty + height()) && (_x >= _tx) && (_x < _tx + width()));}short RenderObject::verticalPositionHint( bool firstLine ) const{ short vpos = m_verticalPosition; if ( m_verticalPosition == PositionUndefined || firstLine ) { vpos = getVerticalPosition( firstLine ); if ( !firstLine ) const_cast<RenderObject *>(this)->m_verticalPosition = vpos; } return vpos;}short RenderObject::getVerticalPosition( bool firstLine ) const{ // vertical align for table cells has a different meaning int vpos = 0; if ( !isTableCell() ) { EVerticalAlign va = style()->verticalAlign(); if ( va == TOP ) { vpos = PositionTop; } else if ( va == BOTTOM ) { vpos = PositionBottom; } else if ( va == LENGTH ) { vpos = -style()->verticalAlignLength().width( lineHeight( firstLine ) ); } else if ( parent() && parent()->childrenInline() ) { vpos = parent()->verticalPositionHint( firstLine ); // don't allow elements nested inside text-top to have a different valignment. if ( va == BASELINE || vpos == PositionBottom ) return vpos; if ( vpos == PositionTop ) vpos = 0; QFont f = parent()->font( firstLine ); int fontheight = parent()->lineHeight( firstLine ); int fontsize = f.pixelSize(); int halfleading = ( fontheight - fontsize ) / 2; if ( va == SUB ) vpos += fontsize/5 + 1; else if ( va == SUPER ) vpos -= fontsize/3 + 1; else if ( va == TEXT_TOP ) { vpos += baselinePosition( firstLine ) - parent()->baselinePosition( firstLine ) + halfleading; } else if ( va == MIDDLE ) { QRect b = QFontMetrics(f).boundingRect('x'); vpos += -b.height()/2 - lineHeight( firstLine )/2 + baselinePosition( firstLine ); } else if ( va == TEXT_BOTTOM ) { vpos += QFontMetrics(f).descent(); if ( !isReplaced() ) vpos -= QFontMetrics(font(firstLine)).descent(); } else if ( va == BASELINE_MIDDLE ) vpos += - lineHeight( firstLine )/2 + baselinePosition( firstLine ); } } return vpos;}int RenderObject::lineHeight( bool firstLine ) const{ Length lh; if( firstLine && hasFirstLine() ) { RenderStyle *pseudoStyle = style()->getPseudoStyle(RenderStyle::FIRST_LINE); if ( pseudoStyle ) lh = pseudoStyle->lineHeight(); } else lh = style()->lineHeight(); // its "unset", choose nice default if ( lh.value < 0 ) return QFontMetrics( style()->font() ).height(); if ( lh.isPercent() ) return lh.minWidth( style()->font().pixelSize() ); // its fixed return lh.value;}short RenderObject::baselinePosition( bool firstLine ) const{ QFont f = font( firstLine ); return QFontMetrics( f ).ascent() + ( lineHeight( firstLine ) - QFontMetrics( f ).height() ) / 2;}QFont RenderObject::font(bool firstLine) const{ if( firstLine && hasFirstLine() ) { RenderStyle *pseudoStyle = style()->getPseudoStyle(RenderStyle::FIRST_LINE); if ( pseudoStyle ) return pseudoStyle->font(); } return style()->font();}void RenderObject::invalidateVerticalPositions(){ m_verticalPosition = PositionUndefined; RenderObject *child = firstChild(); while( child ) { child->invalidateVerticalPositions(); child = child->nextSibling(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -