void drawPopupMenuItem (Graphics& g, const Rectangle<int>& area, const bool isSeparator, const bool isActive, const bool isHighlighted, const bool isTicked, const bool hasSubMenu, const String& text, const String& shortcutKeyText, const Drawable* icon, const Colour* const textColourToUse) { Rectangle<int> r(area.reduced(1)); if(isHighlighted) { g.setColour(Env::getColorTxt()); g.fillRect(r); g.setColour(Env::getColorBg()); } else { g.setColour(Env::getColorTxt()); } g.setFont(Env::getFont()); Rectangle<float> iconArea(r.removeFromRight((r.getHeight() * 5) / 4).reduced(3).toFloat()); if(isTicked) { const Path tick (getTickShape (1.0f)); g.fillPath(tick, tick.getTransformToScaleToFit (iconArea, true)); } g.drawFittedText(text, 4, 1, area.getWidth() - 4, area.getHeight() - 1, Justification::centredLeft, 1); }
void QTorrentItemDelegat::drawTorrent(QPainter* painter, const QStyleOptionViewItem& option, const Torrent& tor, const QModelIndex& index) const { QStyleOptionViewItemV4 opt = option; initStyleOption(&opt, index); QStyle* style; if(opt.widget != NULL) { style = opt.widget->style(); } else { style = QApplication::style(); } const int iconSize(style->pixelMetric(QStyle::PM_LargeIconSize)); QFont nameFont(option.font); nameFont.setWeight(QFont::Bold); const QFontMetrics nameFM(nameFont); const QIcon mimeIcon(tor.GetMimeTypeIcon()); QString nameStr(tor.GetName()); QSize nameSize(nameFM.size(0, nameStr)); QFont statusFont(option.font); statusFont.setPointSize(int (option.font.pointSize() * 0.9)); const QFontMetrics statusFM(statusFont); QString statusStr(GetStatusString(tor)); int statusWidth = statusFM.width(statusStr); QFont progressFont(statusFont); const QFontMetrics progressFM(progressFont); QString progressStr(GetProgressString(tor)); bool isPaused(tor.isPaused()); painter->save(); painter->setRenderHint(QPainter::Antialiasing); style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, opt.widget); /* if (option.state & QStyle::State_Selected) { QPalette::ColorGroup cg = option.state & QStyle::State_Enabled ? QPalette::Active : QPalette::Disabled; if (cg == QPalette::Normal && !(option.state & QStyle::State_Active)) cg = QPalette::Inactive; painter->fillRect(option.rect, opt.backgroundBrush); }*/ //style->drawControl(QStyle::CE_ItemViewItem,&option,painter); QIcon::Mode im; if(isPaused || !(option.state & QStyle::State_Enabled)) { im = QIcon::Disabled; } else if(option.state & QStyle::State_Selected) { im = QIcon::Selected; } else { im = QIcon::Normal; } QIcon::State qs; if(isPaused) { qs = QIcon::Off; } else { qs = QIcon::On; } QPalette::ColorGroup cg = QPalette::Normal; if(isPaused || !(option.state & QStyle::State_Enabled)) { cg = QPalette::Disabled; } if(cg == QPalette::Normal && !(option.state & QStyle::State_Active)) { cg = QPalette::Inactive; } QPalette::ColorRole cr; if(option.state & QStyle::State_Selected) { cr = QPalette::HighlightedText; } cr = QPalette::Text; // layout const QSize m(margin(*style)); QRect fillArea(option.rect); fillArea.adjust(m.width(), m.height(), -m.width(), -m.height()); QRect iconArea(fillArea.x(), fillArea.y() + (fillArea.height() - iconSize) / 2, iconSize, iconSize); QRect nameArea(iconArea.x() + iconArea.width() + GUI_PAD, fillArea.y(), fillArea.width() - GUI_PAD - iconArea.width(), nameSize.height()); if (nameArea.width() + nameArea.x() > opt.rect.width()) { nameArea.setWidth(opt.rect.width() - nameArea.x()); } QRect barArea(nameArea.x(), nameArea.y() + statusFM.lineSpacing() + GUI_PAD / 2, nameArea.width(), BAR_HEIGHT); QRect progArea(nameArea.x(), barArea.y() + barArea.height() + GUI_PAD / 2, barArea.width() - statusWidth, nameArea.height()); QRect statusArea(progArea.x() + progArea.width(), progArea.y(), statusWidth, progArea.height()); if(tor.hasError()) { painter->setPen(QColor("red")); } else { painter->setPen(opt.palette.color(cg, cr)); } mimeIcon.paint(painter, iconArea, Qt::AlignCenter, im, qs); painter->setFont(nameFont); nameStr = nameFM.elidedText(nameStr, Qt::ElideRight, nameArea.width()); style->drawItemText(painter, nameArea, Qt::AlignLeft, opt.palette, option.state & QStyle::State_Enabled, nameStr); painter->setFont(statusFont); statusStr = statusFM.elidedText(statusStr, Qt::ElideRight, statusArea.width()); style->drawItemText(painter, statusArea, Qt::AlignRight, opt.palette, option.state & QStyle::State_Enabled, statusStr); painter->setFont(progressFont); progressStr = statusFM.elidedText(progressStr, Qt::ElideRight, progArea.width()); style->drawItemText(painter, progArea, Qt::AlignLeft, opt.palette, option.state & QStyle::State_Enabled, progressStr); int progressPercentage = tor.GetProgress(); myProgressBarStyle->resize(barArea.size()); myProgressBarStyle->setValue(progressPercentage); //painter->translate(barArea.topLeft()); //myProgressBarStyle->render(painter); QStyleOptionProgressBarV2 pbStyleOpt; myProgressBarStyle->initilizeStyleOption(&pbStyleOpt); pbStyleOpt.rect = barArea; /*myProgressBarStyle->rect = barArea; if ( tor.isDownloading() ) { myProgressBarStyle->palette.setBrush( QPalette::Highlight, blueBrush ); myProgressBarStyle->palette.setColor( QPalette::Base, blueBack ); myProgressBarStyle->palette.setColor( QPalette::Background, blueBack ); } else if ( tor.isSeeding() ) { myProgressBarStyle->palette.setBrush( QPalette::Highlight, greenBrush ); myProgressBarStyle->palette.setColor( QPalette::Base, greenBack ); myProgressBarStyle->palette.setColor( QPalette::Background, greenBack ); } myProgressBarStyle->state = progressBarState; setProgressBarPercentDone( option, tor ); */ style->drawControl(QStyle::CE_ProgressBar, &pbStyleOpt, painter, myProgressBarStyle); painter->restore(); }