void nsRubyTextContainerFrame::BeginRTCLineLayout(nsPresContext* aPresContext, const nsHTMLReflowState& aReflowState) { // Construct block reflow state and line layout nscoord consumedBSize = GetConsumedBSize(); ClearLineCursor(); mISize = 0; nsBlockReflowState state(aReflowState, aPresContext, this, true, true, false, consumedBSize); NS_ASSERTION(!mLines.empty(), "There should be at least one line in the ruby text container"); line_iterator firstLine = begin_lines(); mLineLayout = mozilla::MakeUnique<nsLineLayout>( state.mPresContext, state.mReflowState.mFloatManager, &state.mReflowState, &firstLine); mLineLayout->Init(&state, state.mMinLineHeight, state.mLineNumber); mozilla::WritingMode lineWM = aReflowState.mLineLayout->GetWritingMode(); mozilla::LogicalRect lineRect(state.mContentArea); nscoord iStart = lineRect.IStart(lineWM); nscoord availISize = lineRect.ISize(lineWM); nscoord availBSize = NS_UNCONSTRAINEDSIZE; mLineLayout->BeginLineReflow(iStart, state.mBCoord, availISize, availBSize, false, false, lineWM, state.mContainerWidth); }
void PlaceholderEdit46::paintEvent(QPaintEvent *evt) { QLineEdit::paintEvent(evt); if(text().isEmpty() && !hasFocus() && !m_placeholderText.isEmpty()) { QPainter p(this); QStyleOptionFrameV2 panel; QLineEdit::initStyleOption(&panel); QRect r = style()->subElementRect(QStyle::SE_LineEditContents, &panel, this); int leftMgn, topMgn, rightMgn, bottomMgn; getTextMargins(&leftMgn, &topMgn, &rightMgn, &bottomMgn); r.setX(r.x() + leftMgn); r.setY(r.y() + topMgn); r.setRight(r.right() - rightMgn); r.setBottom(r.bottom() - bottomMgn); p.setClipRect(r); QFontMetrics fm = fontMetrics(); QRect lineRect(r.x() + 2, r.y() + (r.height() - fm.height() + 1) / 2, r.width() - 4, fm.height()); QColor col(palette().text().color()); col.setAlpha(128); QPen oldpen = p.pen(); p.setPen(col); p.drawText(lineRect, m_placeholderText); p.setPen(oldpen); } }
void KPrTimeLineView::paintLine(QPainter *painter, int row, const QRect &rect, bool selected) { QColor m_color = m_mainView->barColor(row); const int lineHeight = qMin(LINE_HEIGHT , rect.height()); const int vPadding = (rect.height() - lineHeight) / 2; qreal stepSize = m_mainView->widthOfColumn(KPrShapeAnimations::StartTime) / m_mainView->numberOfSteps(); qreal startOffSet = m_mainView->calculateStartOffset(row) / 1000.0; qreal duration = m_mainView->model()->data(m_mainView->model()->index(row, KPrShapeAnimations::Duration)).toInt() / 1000.0; qreal start = m_mainView->model()->data(m_mainView->model()->index(row, KPrShapeAnimations::StartTime)).toInt() / 1000.0 + startOffSet; QRectF lineRect(rect.x() + stepSize * start, rect.y() + vPadding, stepSize * duration, lineHeight); QRectF fillRect (lineRect.x(),lineRect.y() + BAR_MARGIN, lineRect.width(), lineRect.height() - BAR_MARGIN * 2); QLinearGradient s_grad(lineRect.center().x(), lineRect.top(), lineRect.center().x(), lineRect.bottom()); if (selected) { s_grad.setColorAt(0, m_color.darker(150)); s_grad.setColorAt(0.5, m_color.lighter(150)); s_grad.setColorAt(1, m_color.darker(150)); s_grad.setSpread(QGradient::ReflectSpread); painter->fillRect(fillRect, s_grad); } else { s_grad.setColorAt(0, m_color.darker(200)); s_grad.setColorAt(0.5, m_color.lighter(125)); s_grad.setColorAt(1, m_color.darker(200)); s_grad.setSpread(QGradient::ReflectSpread); painter->fillRect(fillRect, s_grad); } QRect startRect(lineRect.x(), lineRect.y(), 3, lineRect.height()); painter->fillRect(startRect, Qt::black); QRect endRect(lineRect.x() + lineRect.width(), lineRect.y(), 3, lineRect.height()); painter->fillRect(endRect, Qt::black); }
void ExLineEdit::paintEvent(QPaintEvent *event) { Q_UNUSED(event) //! draw the frame QPainter p(this); QStyleOptionFrameV2 panel; initStyleOption(&panel); style()->drawPrimitive(QStyle::PE_PanelLineEdit, &panel, &p, this); // draw line edit inactive text if (m_lineEdit->text().isEmpty() && !hasFocus()) { QRect r = style()->subElementRect(QStyle::SE_LineEditContents, &panel, this); QFontMetrics fm = fontMetrics(); int horizontalMargin = 2; int leftMargin = !m_left_icons.isEmpty() ? m_left_icons.count()*(this->height()) : 2; QRect lineRect(horizontalMargin + r.x() + leftMargin, r.y() + (r.height() - fm.height() + 1) / 2, r.width() - 2 * horizontalMargin, fm.height()); QPainter painter(this); painter.setPen(palette().brush(QPalette::Disabled, QPalette::WindowText).color()); painter.drawText(lineRect, Qt::AlignLeft|Qt::AlignVCenter, m_inactiveText); } }
void SourceEdit::paintEvent(QPaintEvent * event) { QPainter p(viewport()); QRect rect = lineRect().intersected(event->region().boundingRect()); p.fillRect(rect, QBrush(QColor(248, 248, 248))); p.end(); QTextEdit::paintEvent(event); }
void KCategoryDrawer::drawCategory(const QModelIndex &index, int /*sortRole*/, const QStyleOption &option, QPainter *painter) const { const QString category = index.model()->data(index, KCategorizedSortFilterProxyModel::CategoryDisplayRole).toString(); QColor color; painter->save(); painter->setRenderHint(QPainter::Antialiasing); if (option.state & QStyle::State_Selected) { color = option.palette.color(QPalette::HighlightedText); QColor bgcolor = option.palette.color(QPalette::Highlight); painter->fillRect(option.rect, linearG( option, bgcolor )); } else { color = option.palette.color(QPalette::Text); } QStyleOptionViewItemV4 viewOptions; viewOptions.rect = option.rect; viewOptions.palette = option.palette; viewOptions.direction = option.direction; viewOptions.state = option.state; viewOptions.viewItemPosition = QStyleOptionViewItemV4::OnlyOne; QApplication::style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &viewOptions, painter, 0); QFont painterFont = painter->font(); painterFont.setWeight(QFont::Bold); QFontMetrics metrics(painterFont); painter->setFont(painterFont); QRect lineRect(option.rect.left(), option.rect.bottom() - 1, option.rect.width(), 1); painter->fillRect(lineRect, linearG( option, color )); painter->setPen(color); QRect textRect(option.rect); textRect.setLeft(textRect.left() + HORIZONTAL_HINT); textRect.setRight(textRect.right() - HORIZONTAL_HINT); painter->drawText(textRect, Qt::AlignVCenter | Qt::AlignLeft, metrics.elidedText(category, Qt::ElideRight, option.rect.width())); painter->restore(); }
void SearchLineEdit::paintEvent(QPaintEvent *e) { ExLineEdit::paintEvent(e); if (m_lineEdit->text().isEmpty() && !hasFocus() && !inactiveText.isEmpty()) { QStyleOptionFrame panel; initStyleOption(&panel); QRect r = style()->subElementRect(QStyle::SE_LineEditContents, &panel, this); QFontMetrics fm = fontMetrics(); int horizontalMargin = m_lineEdit->x(); QRect lineRect(horizontalMargin + r.x(), r.y() + (r.height() - fm.height() + 1) / 2, r.width() - 2 * horizontalMargin, fm.height()); QPainter painter(this); painter.setPen(palette().brush(QPalette::Disabled, QPalette::Text).color()); painter.drawText(lineRect, Qt::AlignLeft | Qt::AlignVCenter, inactiveText); } }
void SourceEdit::cursorChanged() { if (m_line != textCursor().blockNumber()) { viewport()->update(); // @@ Optimize updated. //viewport()->update(m_lineRect); m_lineRect = lineRect(); m_line = textCursor().blockNumber(); //viewport()->update(m_lineRect); } }
QRect PrimerLineEdit::placeHolderRect() const { QStyleOptionFrame panel; initStyleOption(&panel); QRect r = style()->subElementRect(QStyle::SE_LineEditContents, &panel, this); r.setX(r.x() + textMargins().left()); r.setY(r.y() + textMargins().top()); r.setRight(r.right() - textMargins().right()); r.setBottom(r.bottom() - textMargins().bottom()); QFontMetrics fm = fontMetrics(); int minLB = qMax(0, -fm.minLeftBearing()); int minRB = qMax(0, -fm.minRightBearing()); int vscroll = r.y() + (r.height() - fm.height() + 1) / 2; static const int horizontalMargin = 2; // QLineEditPrivate::horizontalMargin QRect lineRect(r.x() + horizontalMargin, vscroll, r.width() - 2*horizontalMargin, fm.height()); return lineRect.adjusted(minLB, 0, -minRB, 0); }
void RasterShapeIntervals::getIncludedIntervals(int y1, int y2, SegmentList& result) const { ASSERT(y2 >= y1); IntRect lineRect(bounds().x(), y1, bounds().width(), y2 - y1); Region lineRegion(lineRect); lineRegion.intersect(m_region); if (lineRegion.isEmpty()) return; const Vector<IntRect>& lineRects = lineRegion.rects(); ASSERT(lineRects.size() > 0); Region segmentsRegion(lineRect); Region intervalsRegion; // The loop below uses Regions to compute the intersection of the horizontal // shape intervals that fall within the line's box. int currentLineY = lineRects[0].y(); int currentLineMaxY = lineRects[0].maxY(); for (unsigned i = 0; i < lineRects.size(); ++i) { int lineY = lineRects[i].y(); ASSERT(lineY >= currentLineY); if (lineY > currentLineMaxY) { // We've encountered a vertical gap in lineRects, there are no included intervals. return; } if (lineY > currentLineY) { currentLineY = lineY; currentLineMaxY = lineRects[i].maxY(); segmentsRegion.intersect(intervalsRegion); intervalsRegion = Region(); } else currentLineMaxY = std::max<int>(currentLineMaxY, lineRects[i].maxY()); intervalsRegion.unite(Region(alignedRect(lineRects[i], y1, y2))); } if (!intervalsRegion.isEmpty()) segmentsRegion.intersect(intervalsRegion); const Vector<IntRect>& segmentRects = segmentsRegion.rects(); for (unsigned i = 0; i < segmentRects.size(); ++i) result.append(LineSegment(segmentRects[i].x(), segmentRects[i].maxX())); }
BOOL CArcView::IsHighlighted(const Point& cursorPoint) { Point currentPoint(*pathPoints.begin()); for(auto it=pathPoints.begin() + 1; it != pathPoints.end(); ++it) { CRect lineRect(currentPoint.X, currentPoint.Y, it->X, it->Y); lineRect.NormalizeRect(); if(lineRect.Width() == 0) lineRect.InflateRect(5,0); if(lineRect.Height() == 0) lineRect.InflateRect(0,5); //La distance du curseur à la droite est-elle acceptable ? //Le curseur se trouve-t-il dans enclosingRect ? double distance = Geometry::LinePointDistance(currentPoint, *it, cursorPoint); if(distance < penWidth/2 + 5 && lineRect.PtInRect(CPoint(cursorPoint.X, cursorPoint.Y))) return TRUE; currentPoint = *it; } return FALSE; }
void RasterShapeIntervals::getExcludedIntervals(int y1, int y2, SegmentList& result) const { ASSERT(y2 >= y1); IntRect lineRect(bounds().x(), y1, bounds().width(), y2 - y1); Region lineRegion(lineRect); lineRegion.intersect(m_region); if (lineRegion.isEmpty()) return; const Vector<IntRect>& lineRects = lineRegion.rects(); ASSERT(lineRects.size() > 0); Region segmentsRegion; for (unsigned i = 0; i < lineRects.size(); i++) segmentsRegion.unite(Region(alignedRect(lineRects[i], y1, y2))); const Vector<IntRect>& segmentRects = segmentsRegion.rects(); for (unsigned i = 0; i < segmentRects.size(); i++) result.append(LineSegment(segmentRects[i].x(), segmentRects[i].maxX() + 1)); }
void ScrollWindow::computeLineIndices() { _gfxText32.setFont(_fontId); // NOTE: Unlike SSCI, foreColor and alignment are not // set since these properties do not affect the width of // lines if (_gfxText32._font->getHeight() != _pointSize) { error("Illegal font size font = %d pointSize = %d, should be %d.", _fontId, _gfxText32._font->getHeight(), _pointSize); } Common::Rect lineRect(0, 0, _textRect.width(), _pointSize + 3); _startsOfLines.clear(); // NOTE: The original engine had a 1000-line limit; we // do not enforce any limit for (uint charIndex = 0; charIndex < _text.size(); ) { _startsOfLines.push_back(charIndex); charIndex += _gfxText32.getTextCount(_text, charIndex, lineRect, false); } _numLines = _startsOfLines.size(); _startsOfLines.push_back(_text.size()); _lastVisibleChar = _gfxText32.getTextCount(_text, 0, _fontId, _textRect, false) - 1; _bottomVisibleLine = 0; while ( _bottomVisibleLine < _numLines - 1 && _startsOfLines[_bottomVisibleLine + 1] < _lastVisibleChar ) { ++_bottomVisibleLine; } _numVisibleLines = _bottomVisibleLine + 1; }
SourceEdit::SourceEdit(QWidget * parent): QTextEdit(parent), m_line(0), m_lineRect(lineRect()) { connect(this, SIGNAL(cursorPositionChanged()), this, SLOT(cursorChanged())); }
void AbstractMargin::updateLineRect( int line ) { update( lineRect( line ) ); }
void nsColumnSetFrame::PaintColumnRule(nsRenderingContext* aCtx, const nsRect& aDirtyRect, const nsPoint& aPt) { nsIFrame* child = mFrames.FirstChild(); if (!child) return; // no columns nsIFrame* nextSibling = child->GetNextSibling(); if (!nextSibling) return; // 1 column only - this means no gap to draw on bool isRTL = GetStyleVisibility()->mDirection == NS_STYLE_DIRECTION_RTL; const nsStyleColumn* colStyle = GetStyleColumn(); PRUint8 ruleStyle; // Per spec, inset => ridge and outset => groove if (colStyle->mColumnRuleStyle == NS_STYLE_BORDER_STYLE_INSET) ruleStyle = NS_STYLE_BORDER_STYLE_RIDGE; else if (colStyle->mColumnRuleStyle == NS_STYLE_BORDER_STYLE_OUTSET) ruleStyle = NS_STYLE_BORDER_STYLE_GROOVE; else ruleStyle = colStyle->mColumnRuleStyle; nsPresContext* presContext = PresContext(); nscoord ruleWidth = colStyle->GetComputedColumnRuleWidth(); if (!ruleWidth) return; nscolor ruleColor = GetVisitedDependentColor(eCSSProperty__moz_column_rule_color); // In order to re-use a large amount of code, we treat the column rule as a border. // We create a new border style object and fill in all the details of the column rule as // the left border. PaintBorder() does all the rendering for us, so we not // only save an enormous amount of code but we'll support all the line styles that // we support on borders! nsStyleBorder border(presContext); border.SetBorderWidth(NS_SIDE_LEFT, ruleWidth); border.SetBorderStyle(NS_SIDE_LEFT, ruleStyle); border.SetBorderColor(NS_SIDE_LEFT, ruleColor); // Get our content rect as an absolute coordinate, not relative to // our parent (which is what the X and Y normally is) nsRect contentRect = GetContentRect() - GetRect().TopLeft() + aPt; nsSize ruleSize(ruleWidth, contentRect.height); while (nextSibling) { // The frame tree goes RTL in RTL nsIFrame* leftSibling = isRTL ? nextSibling : child; nsIFrame* rightSibling = isRTL ? child : nextSibling; // Each child frame's position coordinates is actually relative to this nsColumnSetFrame. // linePt will be at the top-left edge to paint the line. nsPoint edgeOfLeftSibling = leftSibling->GetRect().TopRight() + aPt; nsPoint edgeOfRightSibling = rightSibling->GetRect().TopLeft() + aPt; nsPoint linePt((edgeOfLeftSibling.x + edgeOfRightSibling.x - ruleWidth) / 2, contentRect.y); nsRect lineRect(linePt, ruleSize); nsCSSRendering::PaintBorderWithStyleBorder(presContext, *aCtx, this, aDirtyRect, lineRect, border, GetStyleContext(), // Remember, we only have the "left" "border". Skip everything else (1 << NS_SIDE_TOP | 1 << NS_SIDE_RIGHT | 1 << NS_SIDE_BOTTOM)); child = nextSibling; nextSibling = nextSibling->GetNextSibling(); } }
void LocationCompleterDelegate::paint(QPainter* painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { QStyleOptionViewItemV4 opt = option; initStyleOption(&opt, index); const QWidget* w = opt.widget; const QStyle* style = w ? w->style() : QApplication::style(); const int height = opt.rect.height(); const int center = height / 2 + opt.rect.top(); // Prepare title font QFont titleFont = opt.font; titleFont.setPointSize(titleFont.pointSize() + 1); const QFontMetrics titleMetrics(titleFont); int leftPosition = m_padding * 2; int rightPosition = opt.rect.right() - m_padding; opt.state &= ~QStyle::State_MouseOver; if (m_view->hoveredIndex() == index) { opt.state |= QStyle::State_Selected; } else { opt.state &= ~QStyle::State_Selected; } #ifdef Q_OS_WIN const QPalette::ColorRole colorRole = QPalette::Text; const QPalette::ColorRole colorLinkRole = QPalette::Link; #else const QPalette::ColorRole colorRole = opt.state & QStyle::State_Selected ? QPalette::HighlightedText : QPalette::Text; const QPalette::ColorRole colorLinkRole = opt.state & QStyle::State_Selected ? QPalette::HighlightedText : QPalette::Link; #endif // Draw background style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, w); // Draw icon const int iconSize = 16; const int iconYPos = center - (iconSize / 2); QRect iconRect(leftPosition, iconYPos, iconSize, iconSize); QPixmap pixmap = index.data(Qt::DecorationRole).value<QIcon>().pixmap(iconSize); painter->drawPixmap(iconRect, pixmap); leftPosition = iconRect.right() + m_padding * 2; // Draw star to bookmark items int starPixmapWidth = 0; if (index.data(LocationCompleterModel::BookmarkRole).toBool()) { const QIcon icon = IconProvider::instance()->bookmarkIcon(); const QSize starSize(16, 16); starPixmapWidth = starSize.width(); QPoint pos(rightPosition - starPixmapWidth, center - starSize.height() / 2); QRect starRect(pos, starSize); painter->drawPixmap(starRect, icon.pixmap(starSize)); } const QString searchText = index.data(LocationCompleterModel::SearchStringRole).toString(); // Draw title const int leftTitleEdge = leftPosition + 2; // RTL Support: remove conflicting of right-aligned text and starpixmap! const int rightTitleEdge = rightPosition - m_padding - starPixmapWidth; QRect titleRect(leftTitleEdge, opt.rect.top() + m_padding, rightTitleEdge - leftTitleEdge, titleMetrics.height()); QString title = index.data(LocationCompleterModel::TitleRole).toString(); painter->setFont(titleFont); viewItemDrawText(painter, &opt, titleRect, title, colorRole, searchText); // Draw link const int infoYPos = titleRect.bottom() + opt.fontMetrics.leading() + 2; QRect linkRect(titleRect.x(), infoYPos, titleRect.width(), opt.fontMetrics.height()); const QByteArray linkArray = index.data(Qt::DisplayRole).toByteArray(); // Let's assume that more than 500 characters won't fit in line on any display... // Fixes performance when trying to get elidedText for a really long // (length() > 1000000) urls - data: urls can get that long QString link; if (!linkArray.startsWith("data") && !linkArray.startsWith("javascript")) { link = QString::fromUtf8(QByteArray::fromPercentEncoding(linkArray)).left(500); } else { link = QString::fromLatin1(linkArray.left(500)); } painter->setFont(opt.font); // Draw url (or switch to tab) int tabPos = index.data(LocationCompleterModel::TabPositionTabRole).toInt(); if (drawSwitchToTab() && tabPos != -1) { const QIcon tabIcon = QIcon(QSL(":icons/menu/tab.png")); QRect iconRect(linkRect); iconRect.setWidth(m_padding + 16 + m_padding); tabIcon.paint(painter, iconRect); QRect textRect(linkRect); textRect.setX(textRect.x() + m_padding + 16 + m_padding); viewItemDrawText(painter, &opt, textRect, LocationCompleterView::tr("Switch to tab"), colorLinkRole); } else { viewItemDrawText(painter, &opt, linkRect, link, colorLinkRole, searchText); } // Draw line at the very bottom of item if the item is not highlighted if (!(opt.state & QStyle::State_Selected)) { QRect lineRect(opt.rect.left(), opt.rect.bottom(), opt.rect.width(), 1); painter->fillRect(lineRect, opt.palette.color(QPalette::AlternateBase)); } }
/************************************************************************* Render text lines. *************************************************************************/ void MultiLineEditbox::cacheTextLines(const Rect& dest_area) { // text is already formatted, we just grab the lines and render them with the required alignment. Rect drawArea(dest_area); drawArea.offset(Point(-d_horzScrollbar->getScrollPosition(), -d_vertScrollbar->getScrollPosition())); Renderer* renderer = System::getSingleton().getRenderer(); const Font* fnt = getFont(); if (fnt) { // get layers to use for rendering float textZ = renderer->getZLayer(4) - renderer->getCurrentZ(); float selZ = renderer->getZLayer(3) - renderer->getCurrentZ(); // calculate final colours to use. ColourRect colours; float alpha = getEffectiveAlpha(); colour normalTextCol = d_normalTextColour; normalTextCol.setAlpha(normalTextCol.getAlpha() * alpha); colour selectTextCol = d_selectTextColour; selectTextCol.setAlpha(selectTextCol.getAlpha() * alpha); colour selectBrushCol = hasInputFocus() ? d_selectBrushColour : d_inactiveSelectBrushColour; selectBrushCol.setAlpha(selectBrushCol.getAlpha() * alpha); // Cache font info const float fLineSpacing = fnt->getLineSpacing (); // for each formatted line. for (size_t i = 0; i < d_lines.size(); ++i) { Rect lineRect(drawArea); // Check line is within the dest_area if ( lineRect.d_top < dest_area.d_bottom && lineRect.d_top + fLineSpacing > dest_area.d_top ) { const LineInfo& currLine = d_lines[i]; String lineText(d_text.substr(currLine.d_startIdx, currLine.d_length)); // if it is a simple 'no selection area' case if ((currLine.d_startIdx >= d_selectionEnd) || ((currLine.d_startIdx + currLine.d_length) <= d_selectionStart) || (d_selectionBrush == NULL)) { colours.setColours(normalTextCol); // render the complete line. d_renderCache.cacheText(lineText, fnt, LeftAligned, lineRect, textZ, colours, &dest_area); } // we have at least some selection highlighting to do else { // Start of actual rendering section. String sect; size_t sectIdx = 0, sectLen; float selStartOffset = 0.0f, selAreaWidth = 0.0f; // render any text prior to selected region of line. if (currLine.d_startIdx < d_selectionStart) { // calculate length of text section sectLen = d_selectionStart - currLine.d_startIdx; // get text for this section sect = lineText.substr(sectIdx, sectLen); sectIdx += sectLen; // get the pixel offset to the beginning of the selection area highlight. selStartOffset = fnt->getTextExtent(sect); // draw this portion of the text colours.setColours(normalTextCol); d_renderCache.cacheText(sect, fnt, LeftAligned, lineRect, textZ, colours, &dest_area); // set position ready for next portion of text lineRect.d_left += selStartOffset; } // calculate the length of the selected section sectLen = ceguimin(d_selectionEnd - currLine.d_startIdx, currLine.d_length) - sectIdx; // get the text for this section sect = lineText.substr(sectIdx, sectLen); sectIdx += sectLen; // get the extent to use as the width of the selection area highlight selAreaWidth = fnt->getTextExtent(sect); // draw the text for this section colours.setColours(selectTextCol); d_renderCache.cacheText(sect, fnt, LeftAligned, lineRect, textZ, colours, &dest_area); // render any text beyond selected region of line if (sectIdx < currLine.d_length) { // update render position to the end of the selected area. lineRect.d_left += selAreaWidth; // calculate length of this section sectLen = currLine.d_length - sectIdx; // get the text for this section sect = lineText.substr(sectIdx, sectLen); // render the text for this section. colours.setColours(normalTextCol); d_renderCache.cacheText(sect, fnt, LeftAligned, lineRect, textZ, colours, &dest_area); } // calculate area for the selection brush on this line lineRect.d_left = drawArea.d_left + selStartOffset; lineRect.d_right = lineRect.d_left + selAreaWidth; lineRect.d_bottom = lineRect.d_top + fLineSpacing; // render the selection area brush for this line colours.setColours(selectBrushCol); d_renderCache.cacheImage(*d_selectionBrush, lineRect, selZ, colours, &dest_area); } } // update master position for next line in paragraph. drawArea.d_top += fLineSpacing; } } }
void LocationCompleterDelegate::paint(QPainter* painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { QStyleOptionViewItemV4 opt = option; initStyleOption(&opt, index); const QWidget* w = opt.widget; const QStyle* style = w ? w->style() : QApplication::style(); const int height = opt.rect.height(); const int center = height / 2 + opt.rect.top(); // Prepare title font QFont titleFont = opt.font; titleFont.setPointSize(titleFont.pointSize() + 1); const QFontMetrics titleMetrics(titleFont); int leftPosition = m_padding * 2; int rightPosition = opt.rect.right() - m_padding; opt.state &= ~QStyle::State_MouseOver; if (m_view->hoveredIndex() == index) { opt.state |= QStyle::State_Selected; } else { opt.state &= ~QStyle::State_Selected; } #ifdef Q_OS_WIN const QPalette::ColorRole colorRole = QPalette::Text; const QPalette::ColorRole colorLinkRole = QPalette::Link; #else const QPalette::ColorRole colorRole = opt.state & QStyle::State_Selected ? QPalette::HighlightedText : QPalette::Text; const QPalette::ColorRole colorLinkRole = opt.state & QStyle::State_Selected ? QPalette::HighlightedText : QPalette::Link; #endif // Draw background style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, w); // Draw icon const int iconSize = 16; const int iconYPos = center - (iconSize / 2); QRect iconRect(leftPosition, iconYPos, iconSize, iconSize); QPixmap pixmap = index.data(Qt::DecorationRole).value<QIcon>().pixmap(iconSize); painter->drawPixmap(iconRect, pixmap); leftPosition = iconRect.right() + m_padding * 2; // Draw star to bookmark items int starPixmapWidth = 0; if (index.data(LocationCompleterModel::BookmarkRole).toBool()) { const QPixmap starPixmap = qIconProvider->bookmarkIcon(); QSize starSize = starPixmap.size(); //new starPixmapWidth = starSize.width(); QPoint pos(rightPosition - starPixmapWidth, opt.rect.top() + m_padding); QRect starRect(pos, starSize); painter->drawPixmap(starRect, starPixmap); } const QString &searchText = index.data(LocationCompleterModel::SearchStringRole).toString(); // Draw title const int leftTitleEdge = leftPosition + 2; // RTL Support: remove conflicting of right-aligned text and starpixmap! const int rightTitleEdge = rightPosition - m_padding - starPixmapWidth; QRect titleRect(leftTitleEdge, opt.rect.top() + m_padding, rightTitleEdge - leftTitleEdge, titleMetrics.height()); QString title(titleMetrics.elidedText(index.data(LocationCompleterModel::TitleRole).toString(), Qt::ElideRight, titleRect.width())); painter->setFont(titleFont); drawHighlightedTextLine(titleRect, title, searchText, painter, style, opt, colorRole); // Draw link const int infoYPos = titleRect.bottom() + opt.fontMetrics.leading() + 2; QRect linkRect(titleRect.x(), infoYPos, titleRect.width(), opt.fontMetrics.height()); QString link(opt.fontMetrics.elidedText(index.data(Qt::DisplayRole).toString(), Qt::ElideRight, linkRect.width())); painter->setFont(opt.font); TabPosition pos = index.data(LocationCompleterModel::TabPositionRole).value<TabPosition>(); if (m_drawSwitchToTab && pos.windowIndex != -1) { const QIcon tabIcon = QIcon(":icons/menu/tab.png"); QRect iconRect(linkRect); iconRect.setWidth(m_padding + 16 + m_padding); tabIcon.paint(painter, iconRect); QRect textRect(linkRect); textRect.setX(textRect.x() + m_padding + 16 + m_padding); drawTextLine(textRect, LocationCompleterView::tr("Switch to tab"), painter, style, opt, colorLinkRole); } else { drawHighlightedTextLine(linkRect, link, searchText, painter, style, opt, colorLinkRole); } // Draw line at the very bottom of item if the item is not highlighted if (!(opt.state & QStyle::State_Selected)) { QRect lineRect(opt.rect.left(), opt.rect.bottom(), opt.rect.width(), 1); painter->fillRect(lineRect, opt.palette.color(QPalette::AlternateBase)); } }
// -------------------------------------------------- void ctkSearchBox::paintEvent(QPaintEvent * event) { Q_D(ctkSearchBox); // Draw the line edit with text. // Text has already been shifted to the right (in resizeEvent()) to leave // space for the search icon. this->Superclass::paintEvent(event); QPainter p(this); QRect cRect = d->clearRect(); QRect sRect = d->showSearchIcon ? d->searchRect() : QRect(); #if QT_VERSION >= 0x040700 QRect r = rect(); QPalette pal = palette(); QStyleOptionFrameV2 panel; initStyleOption(&panel); r = this->style()->subElementRect(QStyle::SE_LineEditContents, &panel, this); r.setX(r.x() + this->textMargins().left()); r.setY(r.y() + this->textMargins().top()); r.setRight(r.right() - this->textMargins().right()); r.setBottom(r.bottom() - this->textMargins().bottom()); p.setClipRect(r); QFontMetrics fm = fontMetrics(); Qt::Alignment va = QStyle::visualAlignment(this->layoutDirection(), QFlag(this->alignment())); int vscroll = 0; const int verticalMargin = 1; const int horizontalMargin = 2; switch (va & Qt::AlignVertical_Mask) { case Qt::AlignBottom: vscroll = r.y() + r.height() - fm.height() - verticalMargin; break; case Qt::AlignTop: vscroll = r.y() + verticalMargin; break; default: //center vscroll = r.y() + (r.height() - fm.height() + 1) / 2; break; } QRect lineRect(r.x() + horizontalMargin, vscroll, r.width() - 2*horizontalMargin, fm.height()); int minLB = qMax(0, -fm.minLeftBearing()); if (this->text().isEmpty()) { if (!this->hasFocus() && !this->placeholderText().isEmpty()) { QColor col = pal.text().color(); col.setAlpha(128); QPen oldpen = p.pen(); p.setPen(col); lineRect.adjust(minLB, 0, 0, 0); QString elidedText = fm.elidedText(this->placeholderText(), Qt::ElideRight, lineRect.width()); p.drawText(lineRect, va, elidedText); p.setPen(oldpen); } } p.setClipRect(this->rect()); #endif // Draw clearIcon if (!d->hideClearIcon) { QPixmap closePixmap = d->clearIcon.pixmap(cRect.size(),this->isEnabled() ? QIcon::Normal : QIcon::Disabled); this->style()->drawItemPixmap(&p, cRect, Qt::AlignCenter, closePixmap); } // Draw searchIcon if (d->showSearchIcon) { QPixmap searchPixmap = d->searchIcon.pixmap(sRect.size(), this->isEnabled() ? QIcon::Normal : QIcon::Disabled); this->style()->drawItemPixmap(&p, sRect, Qt::AlignCenter, searchPixmap); } }
void FalagardMultiLineEditbox::cacheTextLines(const Rectf& dest_area) { MultiLineEditbox* w = (MultiLineEditbox*)d_window; // text is already formatted, we just grab the lines and render them with the required alignment. Rectf drawArea(dest_area); float vertScrollPos = w->getVertScrollbar()->getScrollPosition(); drawArea.offset(Vector2f(-w->getHorzScrollbar()->getScrollPosition(), -vertScrollPos)); const Font* fnt = w->getFont(); if (fnt) { // calculate final colours to use. ColourRect colours; const float alpha = w->getEffectiveAlpha(); ColourRect normalTextCol; setColourRectToUnselectedTextColour(normalTextCol); normalTextCol.modulateAlpha(alpha); ColourRect selectTextCol; setColourRectToSelectedTextColour(selectTextCol); selectTextCol.modulateAlpha(alpha); ColourRect selectBrushCol; w->hasInputFocus() ? setColourRectToActiveSelectionColour(selectBrushCol) : setColourRectToInactiveSelectionColour(selectBrushCol); selectBrushCol.modulateAlpha(alpha); const MultiLineEditbox::LineList& d_lines = w->getFormattedLines(); const size_t numLines = d_lines.size(); // calculate the range of visible lines size_t sidx,eidx; sidx = static_cast<size_t>(vertScrollPos / fnt->getLineSpacing()); eidx = 1 + sidx + static_cast<size_t>(dest_area.getHeight() / fnt->getLineSpacing()); eidx = ceguimin(eidx, numLines); drawArea.d_min.d_y += fnt->getLineSpacing()*static_cast<float>(sidx); // for each formatted line. for (size_t i = sidx; i < eidx; ++i) { Rectf lineRect(drawArea); const MultiLineEditbox::LineInfo& currLine = d_lines[i]; String lineText(w->getTextVisual().substr(currLine.d_startIdx, currLine.d_length)); // offset the font little down so that it's centered within its own spacing const float old_top = lineRect.top(); lineRect.d_min.d_y += (fnt->getLineSpacing() - fnt->getFontHeight()) * 0.5f; // if it is a simple 'no selection area' case if ((currLine.d_startIdx >= w->getSelectionEndIndex()) || ((currLine.d_startIdx + currLine.d_length) <= w->getSelectionStartIndex()) || (w->getSelectionBrushImage() == 0)) { colours = normalTextCol; // render the complete line. fnt->drawText(w->getGeometryBuffer(), lineText, lineRect.getPosition(), &dest_area, colours); } // we have at least some selection highlighting to do else { // Start of actual rendering section. String sect; size_t sectIdx = 0, sectLen; float selStartOffset = 0.0f, selAreaWidth = 0.0f; // render any text prior to selected region of line. if (currLine.d_startIdx < w->getSelectionStartIndex()) { // calculate length of text section sectLen = w->getSelectionStartIndex() - currLine.d_startIdx; // get text for this section sect = lineText.substr(sectIdx, sectLen); sectIdx += sectLen; // get the pixel offset to the beginning of the selection area highlight. selStartOffset = fnt->getTextAdvance(sect); // draw this portion of the text colours = normalTextCol; fnt->drawText(w->getGeometryBuffer(), sect, lineRect.getPosition(), &dest_area, colours); // set position ready for next portion of text lineRect.d_min.d_x += selStartOffset; } // calculate the length of the selected section sectLen = ceguimin(w->getSelectionEndIndex() - currLine.d_startIdx, currLine.d_length) - sectIdx; // get the text for this section sect = lineText.substr(sectIdx, sectLen); sectIdx += sectLen; // get the extent to use as the width of the selection area highlight selAreaWidth = fnt->getTextAdvance(sect); const float text_top = lineRect.top(); lineRect.top(old_top); // calculate area for the selection brush on this line lineRect.left(drawArea.left() + selStartOffset); lineRect.right(lineRect.left() + selAreaWidth); lineRect.bottom(lineRect.top() + fnt->getLineSpacing()); // render the selection area brush for this line colours = selectBrushCol; w->getSelectionBrushImage()->render(w->getGeometryBuffer(), lineRect, &dest_area, colours); // draw the text for this section colours = selectTextCol; fnt->drawText(w->getGeometryBuffer(), sect, lineRect.getPosition(), &dest_area, colours); lineRect.top(text_top); // render any text beyond selected region of line if (sectIdx < currLine.d_length) { // update render position to the end of the selected area. lineRect.d_min.d_x += selAreaWidth; // calculate length of this section sectLen = currLine.d_length - sectIdx; // get the text for this section sect = lineText.substr(sectIdx, sectLen); // render the text for this section. colours = normalTextCol; fnt->drawText(w->getGeometryBuffer(), sect, lineRect.getPosition(), &dest_area, colours); } } // update master position for next line in paragraph. drawArea.d_min.d_y += fnt->getLineSpacing(); } } }
void Console::draw( gfx::Engine& painter ) { if( !font().isValid() ) { Widget::draw( painter ); return; } if( visible() ) // render only if the console is visible { if( toggle_visible_ != NONE ) { if( toggle_visible_ == DOWNLIGTH ) { if (_opacity > 5) _opacity -= 9; else setVisible(false); _d->dirty = true; } else { if (_opacity < 0xff) _opacity += 3; else toggle_visible_ = NONE; _d->dirty = true; } } Rect textRect, shellRect; //we calculate where the message log shall be printed and where the prompt shall be printed calculatePrintRects(textRect,shellRect); if(_d->dirty) { Decorator::drawLines(_d->bg, ColorList::red, relativeRect().lines()); _d->bg.fill(ColorList::blue); unsigned int maxLines, lineHeight; //now, render the messages int fontHeight=0; if (!calculateLimits(maxLines,lineHeight,fontHeight)) { return; } Rect lineRect( textRect.left(), //calculate the line rectangle textRect.top(), textRect.right(), textRect.bottom() + lineHeight); for (unsigned int index = 0; index < console_messages_.size(); index++) { unsigned int rindex = (_d->curIndex + index) % console_messages_.size(); const std::string& line = console_messages_[rindex]; font().draw(_d->bg, line, lineRect.lefttop(), false, false); lineRect += Point(0, lineHeight); //update line rectangle } std::string shellText = "$>" + currentCommand_; font().draw( _d->bg, shellText, shellRect.lefttop(), false, false); //draw the prompt string _d->dirty = false; _d->bg.update(); _d->bg.setAlpha(_opacity/3*2); } painter.draw( _d->bg, absoluteRect().lefttop() ); if( DateTime::elapsedTime() % 700 < 350 ) { NColor color = ColorList::white; color.setAlpha(_opacity/2); painter.fillRect( color, Rect(0, 0, _d->commandCursorWidth,shellRect.height()*0.8) +absoluteRect().leftbottom() + Point(_d->commandTextSize.width(), -shellRect.height()) ); } } Widget::draw( painter ); }