QRect Toplevel::visibleRect() const { QRect r = decorationRect(); if (hasShadow() && !shadow()->shadowRegion().isEmpty()) { r |= shadow()->shadowRegion().boundingRect(); } return r.translated(geometry().topLeft()); }
void TxViewDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index ) const { painter->save(); QIcon icon = qvariant_cast<QIcon>(index.data(Qt::DecorationRole)); QRect mainRect = option.rect; QRect decorationRect(mainRect.topLeft(), QSize(DECORATION_SIZE, DECORATION_SIZE)); int xspace = DECORATION_SIZE + 8; int ypad = 6; int halfheight = (mainRect.height() - 2*ypad)/2; QRect amountRect(mainRect.left() + xspace, mainRect.top()+ypad, mainRect.width() - xspace, halfheight); QRect addressRect(mainRect.left() + xspace, mainRect.top()+ypad+halfheight, mainRect.width() - xspace, halfheight); icon.paint(painter, decorationRect); QDateTime date = index.data(TransactionTableModel::DateRole).toDateTime(); QString address = index.data(Qt::DisplayRole).toString(); qint64 amount = index.data(TransactionTableModel::AmountRole).toLongLong(); bool confirmed = index.data(TransactionTableModel::ConfirmedRole).toBool(); QVariant value = index.data(Qt::ForegroundRole); QColor foreground = option.palette.color(QPalette::Text); #if QT_VERSION < 0x050000 if(qVariantCanConvert<QColor>(value)) #else if(value.canConvert(QMetaType::QColor)) #endif { foreground = qvariant_cast<QColor>(value); } painter->setPen(foreground); painter->drawText(addressRect, Qt::AlignLeft|Qt::AlignVCenter, address); if(amount < 0) { foreground = COLOR_NEGATIVE; } else if(!confirmed) { foreground = COLOR_UNCONFIRMED; } else { foreground = option.palette.color(QPalette::Text); } painter->setPen(foreground); QString amountText = BitcoinUnits::formatWithUnit(unit, amount, true); if(!confirmed) { amountText = QString("[") + amountText + QString("]"); } painter->drawText(amountRect, Qt::AlignRight|Qt::AlignVCenter, amountText); painter->setPen(option.palette.color(QPalette::Text)); painter->drawText(amountRect, Qt::AlignLeft|Qt::AlignVCenter, GUIUtil::dateTimeStr(date)); painter->restore(); }
void KoDocumentSectionDelegate::drawDecoration(QPainter *p, const QStyleOptionViewItem &option, const QModelIndex &index) const { const QRect r = decorationRect(option, index).translated(option.rect.topLeft()); p->save(); { p->setClipRect(r); p->translate(r.topLeft()); if (!index.data(Qt::DecorationRole).value<QIcon>().isNull()) p->drawPixmap(0, 0, index.data(Qt::DecorationRole).value<QIcon>().pixmap(option.decorationSize, (option.state & QStyle::State_Enabled) ? QIcon::Normal : QIcon::Disabled)); } p->restore(); }
QRect KoDocumentSectionDelegate::textRect(const QStyleOptionViewItem &option, const QModelIndex &index) const { if (d->view->displayMode() == View::ThumbnailMode) { const QRect r = decorationRect(option, index); const int left = r.right() + d->margin; return QRect(left, r.top(), option.rect.width() - left, textBoxHeight(option)); } else { static QFont f; static int minbearing = 1337 + 666; //can be 0 or negative, 2003 is less likely if (minbearing == 2003 || f != option.font) { f = option.font; //getting your bearings can be expensive, so we cache them minbearing = option.fontMetrics.minLeftBearing() + option.fontMetrics.minRightBearing(); } int indent = decorationRect(option, index).right() + d->margin; const int width = (d->view->displayMode() == View::DetailedMode ? option.rect.width() : iconsRect(option, index).left()) - indent - d->margin + minbearing; return QRect(indent, 0, width, textBoxHeight(option)); } }
void paint(QPainter* painter, const QStyleOptionViewItem & option, const QModelIndex & index) const { QStyleOptionViewItem opt = option; if (opt.state & QStyle::State_Selected) { painter->fillRect(opt.rect, opt.palette.highlight()); } QIcon icon = qvariant_cast<QIcon>(index.data(Qt::DecorationRole)); QSize ds = opt.decorationSize; QRect decorationRect(opt.rect.x() + 4, opt.rect.top() + 4, opt.rect.width() - 8, ds.height()); icon.paint(painter, decorationRect, Qt::AlignHCenter | Qt::AlignTop, opt.state & QStyle::State_Enabled ? ((opt.state & QStyle::State_Selected) && opt.showDecorationSelected ? QIcon::Selected : QIcon::Normal) : QIcon::Disabled); QString displayText = index.data(Qt::DisplayRole).toString(); painter->setPen(opt.palette.color(option.state & QStyle::State_Selected ? QPalette::HighlightedText : QPalette::Text)); QRect displayRect = opt.rect.adjusted(2, ds.height() + 2, -2, -2); painter->drawText(displayRect, Qt::AlignHCenter | Qt::AlignBottom | Qt::TextWordWrap, opt.fontMetrics.elidedText(displayText, opt.textElideMode, displayRect.width())); }