void CanvasRenderingContext2D::scrollPathIntoViewInternal(const Path& path) { if (!state().isTransformInvertible() || path.isEmpty()) return; canvas()->document().updateStyleAndLayoutIgnorePendingStylesheets(); LayoutObject* renderer = canvas()->layoutObject(); LayoutBox* layoutBox = canvas()->layoutBox(); if (!renderer || !layoutBox) return; // Apply transformation and get the bounding rect Path transformedPath = path; transformedPath.transform(state().transform()); FloatRect boundingRect = transformedPath.boundingRect(); // Offset by the canvas rect LayoutRect pathRect(boundingRect); IntRect canvasRect = layoutBox->absoluteContentBox(); pathRect.moveBy(canvasRect.location()); renderer->scrollRectToVisible(pathRect, ScrollAlignment::alignCenterAlways, ScrollAlignment::alignTopAlways); // TODO: should implement "inform the user" that the caret and/or // selection the specified rectangle of the canvas. See // http://crbug.com/357987 }
void SkpThemedBase::skp_draw_themed() { // QPainterPath path; // path.setFillRule(Qt::WindingFill); // path.addRect(10, 10, m_parent->width()-20, m_parent->height()-20); // QPainter painter(m_parent); // painter.setRenderHint(QPainter::Antialiasing, true); // painter.fillPath(path, QBrush(Qt::white)); // QColor color(0, 0, 0, 50); // for(int i=0; i<10; i++) // { // QPainterPath path; // path.setFillRule(Qt::WindingFill); // path.addRect(10-i, 10-i, m_parent->width()-(10-i)*2, m_parent->height()-(10-i)*2); // color.setAlpha(150 - qSqrt(i)*50); // painter.setPen(color); // painter.drawPath(path); // } /* QPainter p(m_parent); QPen pen(QColor(255, 255, 255, 255)); pen.setWidth(2); pen.setStyle(Qt::NoPen); p.setPen(pen); QPainterPath path; QPoint bottomRight = m_parent->rect().bottomRight(); QRect pathRect = m_parent->rect(); pathRect.setBottomRight(QPoint(bottomRight.x()-1, bottomRight.y()-1)); path.addRoundedRect(pathRect, 0, 0); QString themeType = MOption::instance()->option("WindowBGPixmapType", "theme").toString(); if(themeType == "bitmap") { if(!m_cachedPixmap.isNull()) { p.fillPath(path, QBrush(m_cachedPixmap)); } else { QColor color(100,178,226,255); MOption::instance()->setOption(QVariant(color), "WindowBGColor", "theme"); MOption::instance()->setOption("color", "WindowBGPixmapType", "theme"); MOption::instance()->setOption(QVariant(color), OPTION_AVERAGE_COLOR, OPTION_GROUP_Theme); p.fillPath(path, color); } } else if(themeType == "color") { QImage image(QSize(100, 100), QImage::Format_ARGB32); image.fill(MOption::instance()->option("WindowBGColor", "theme").value<QColor>()); m_cachedPixmap = setAlphaPixmap(QPixmap::fromImage(image), m_aeroTransparent); p.fillPath(path, QBrush(m_cachedPixmap)); } QRect linearRect(0, m_titleHeight, m_parent->width(), m_linearHeight); QLinearGradient linear(0, m_titleHeight, 0, m_linearHeight+m_titleHeight); QColor c1(255, 255, 255, m_widgetTransparent /2);; QColor c2(255, 255, 255, m_widgetTransparent); linear.setColorAt(0.0, QColor(255, 255, 255, 255)); linear.setColorAt(0.5, c1); linear.setColorAt(1.0, c2); p.setBrush(QBrush(linear)); p.fillRect(linearRect, QBrush(linear)); QPainterPath clientPath; QRect clientRect(0, m_titleHeight + m_linearHeight, m_parent->width(), m_parent->height() - m_titleHeight - m_linearHeight - m_statusHeight); clientPath.addRect(clientRect); p.fillPath(clientPath, QBrush(QColor(255, 255, 255, m_widgetTransparent))); p.strokePath(path, QPen(QColor(0, 0, 0, 150))); */ QPainter p(m_parent); int width = 5; QColor color(0, 0, 0, 20); for(int i=0; i<width; i++) { QPainterPath path; path.setFillRule(Qt::WindingFill); path.addRect(width-i, width-i, m_parent->width()-(width-i)*2, m_parent->height()-(width-i)*2); color.setAlpha(60 - qSqrt(i)*30); p.setPen(color); p.drawPath(path); } QRect pathRect(width, width, m_parent->rect().width() - width * 2, m_parent->rect().height() - width * 2); QPainterPath path; path.addRoundedRect(pathRect, 0, 0); QString themeType = MOption::instance()->option("WindowBGPixmapType", "theme").toString(); if(themeType == "bitmap") { if(!m_cachedPixmap.isNull()) { p.fillPath(path, QBrush(m_cachedPixmap)); } else { QColor color(100,178,226,255); MOption::instance()->setOption(QVariant(color), "WindowBGColor", "theme"); MOption::instance()->setOption("color", "WindowBGPixmapType", "theme"); MOption::instance()->setOption(QVariant(color), OPTION_AVERAGE_COLOR, OPTION_GROUP_Theme); p.fillPath(path, color); } } else if(themeType == "color") { QImage image(QSize(100, 100), QImage::Format_ARGB32); image.fill(MOption::instance()->option("WindowBGColor", "theme").value<QColor>()); m_cachedPixmap = setAlphaPixmap(QPixmap::fromImage(image), m_aeroTransparent); p.fillPath(path, QBrush(m_cachedPixmap)); } QRect linearRect(0, m_titleHeight, m_parent->width(), m_linearHeight); QLinearGradient linear(0, m_titleHeight, 0, m_linearHeight+m_titleHeight); QColor c1(255, 255, 255, m_widgetTransparent /2);; QColor c2(255, 255, 255, m_widgetTransparent); linear.setColorAt(0.0, QColor(255, 255, 255, 255)); linear.setColorAt(0.5, c1); linear.setColorAt(1.0, c2); p.setBrush(QBrush(linear)); p.fillRect(linearRect, QBrush(linear)); QPainterPath clientPath; QRect clientRect(width, m_titleHeight + m_linearHeight, m_parent->width() - width * 2, m_parent->height() - m_titleHeight - m_linearHeight - m_statusHeight - width * 2); clientPath.addRect(clientRect); p.fillPath(clientPath, QBrush(QColor(255, 255, 255, m_widgetTransparent))); }
void WrapTextDelegate::paint( QPainter * p, const QStyleOptionViewItem & option, const QModelIndex & index ) const { int x1, y1, x2, y2; //(x1, y1) is the upper-left corner, (x2, y2) the lower-right option.rect.getCoords(&x1, &y1, &x2, &y2); p->save(); int lineWidths = 4; // draw a line below each row p->setPen( QPen( QBrush("#9CC"), lineWidths) ); p->drawLine(x1, y2, x2, y2); // draw a line between each column p->setPen( QPen( QBrush("#CCC"), lineWidths) ); p->drawLine( x2, y1+((y2-y1)/5), x2, y2-((y2-y1)/5)); p->restore(); if( index.isValid() && index.column() == BachAssetItem::Column_Info ) { BachAsset ba = ((RecordSuperModel*)(index.model()))->getRecord(index); QRect pathRect(x1+5, y1+5, x2-x1-10, ((y2-y1)/3)-10); QRect tagsRect(pathRect.x(), pathRect.y()+pathRect.height()+10, x2-x1-10, y2-y1-10); QRect keywordsRect(pathRect.x(), pathRect.y()+pathRect.height()+30, x2-x1-10, y2-y1-10); QRect fullSize; p->save(); QItemDelegate::drawBackground( p, option, index ); if( option.state & QStyle::State_Selected ) p->setPen( option.palette.highlightedText().color() ); else p->setPen( option.palette.text().color() ); p->drawText( pathRect, Qt::TextWordWrap, ba.path(), &fullSize ); p->drawText( tagsRect, Qt::TextWordWrap, QString("Tags: ")+ba.tags(), &fullSize ); p->drawText( keywordsRect, Qt::TextWordWrap, QString("Keywords: ")+ba.cachedKeywords(), &fullSize ); p->setPen( QPen( QBrush("#9CC"), 2) ); p->drawLine(x1+10, y1+((y2-y1)/3), x2-10, y1+((y2-y1)/3)); //QRect dateRect(tagsRect.bottomRight().x()-40,tagsRect.bottomRight().y()-14, tagsRect.bottomRight().x(), tagsRect.bottomRight.y()); QFont curFont = option.font; p->setFont( QFont(curFont.family(), curFont.pointSize()-2, curFont.weight(), true ) ); curFont.setPointSize( curFont.pointSize()-1 ); p->setPen( QColor("#CCC") ); QRect sizeRect(x1+20,y2-20,x1+100,y2-4); p->drawText( sizeRect, Qt::TextWordWrap, QString::number(ba.width())+"x"+QString::number(ba.height()), &fullSize ); p->setFont(option.font); p->restore(); return; } else { QStyleOptionViewItem newOption = QStyleOptionViewItem(option); newOption.displayAlignment = Qt::AlignHCenter | Qt::AlignVCenter; newOption.decorationAlignment = Qt::AlignHCenter | Qt::AlignVCenter; return QItemDelegate::paint( p, newOption, index ); } }