QSize QTorrentItemDelegat::sizeHint(const QStyleOptionViewItem& option, const Torrent& tor) const { try { const QStyle* style(QApplication::style()); const int iconSize(style->pixelMetric(QStyle::PM_MessageBoxIconSize)); QFont nameFont(option.font); nameFont.setWeight(QFont::Bold); const QFontMetrics nameFM(nameFont); const QString nameStr(tor.GetName()); int nameWidth = nameFM.width(nameStr); QFont statusFont(option.font); statusFont.setPointSize(int (option.font.pointSize() * 0.9)); const QFontMetrics statusFM(statusFont); const QString statusStr(GetStatusString(tor)); int statusWidth = statusFM.width(statusStr); QFont progressFont(statusFont); const QFontMetrics progressFM(progressFont); const QString progressStr(GetProgressString(tor)); const int progressWidth = progressFM.width(progressStr); const QSize m(margin(*style)); int width = m.width() + iconSize + std::max(nameWidth, statusWidth + progressWidth); int height = m.height() * 3 + nameFM.lineSpacing() + 2 * GUI_PAD + progressFM.lineSpacing(); return QSize(width, height); } catch(...) { qDebug() << "exception in size hint"; } return QSize(0, 0); }
QSize QTorrentItemDelegat::sizeHint(const QStyleOptionViewItem& option, const Torrent& tor) const { const QStyle* style(QApplication::style()); const int iconSize(style->pixelMetric(QStyle::PM_MessageBoxIconSize)); QFont nameFont(option.font); nameFont.setWeight(QFont::Bold); const QFontMetrics nameFM(nameFont); QString nameStr; int queuePosition = tor.GetQueuePosition(); if (queuePosition > -1) { nameStr = QString("#%1 %2").arg(QString::number(queuePosition + 1), tor.GetName()); } else { nameStr = tor.GetName(); } int nameWidth = nameFM.width(nameStr); QFont statusFont(option.font); statusFont.setPointSize(int(option.font.pointSize() * 0.9)); const QFontMetrics statusFM(statusFont); const QString statusStr(GetStatusString(tor)); int statusWidth = statusFM.width(statusStr); QFont progressFont(statusFont); const QFontMetrics progressFM(progressFont); const QString progressStr(GetProgressString(tor)); const int progressWidth = progressFM.width(progressStr); const QSize m(margin(*style)); int width = m.width() + iconSize + std::max(nameWidth, statusWidth + progressWidth); int height = m.height() * 3 + nameFM.lineSpacing() + 2 * GUI_PAD + progressFM.lineSpacing(); return QSize(width, height); }
void AStatus::OnPaint(wxPaintEvent & event) { wxPaintDC dc(this); int width, height; GetSize(&width, &height); if (width != mWidth || height != mHeight) { mWidth = width; mHeight = height; delete mBitmap; mBitmap = NULL; } if (!mBitmap) mBitmap = new wxBitmap(mWidth, mHeight); wxMemoryDC memDC; memDC.SelectObject(*mBitmap); AColor::Medium(&memDC, false); memDC.DrawRectangle(0, 0, mWidth, mHeight); int fontSize = 10; #ifdef __WXMSW__ fontSize = 8; #endif memDC.SetPen(*wxBLACK_PEN); memDC.DrawLine(0, 0, mWidth, 0); wxRect outline; outline.x = 0; outline.y = 1; outline.width = mWidth - 1; outline.height = mHeight - 2; AColor::Bevel(memDC, true, outline); wxFont statusFont(fontSize, wxSWISS, wxNORMAL, wxNORMAL); memDC.SetFont(statusFont); wxRect msgField; msgField.x = 4; msgField.y = 6; msgField.width = mWidth - 8; msgField.height = 17; AColor::Bevel(memDC, false, msgField); wxString msg = mField[0]; long textWidth, textHeight; memDC.GetTextExtent(msg, &textWidth, &textHeight); while (msg != "" && textWidth > msgField.width) { msg = msg.Left(msg.Length() - 1); memDC.GetTextExtent(msg, &textWidth, &textHeight); } memDC.DrawText(msg, msgField.x + 3, msgField.y + 2); wxRect cursorField; cursorField.x = 140; cursorField.y = 29; cursorField.width = mWidth - 144; cursorField.height = 17; #ifdef __WXMAC__ cursorField.width -= 15; #endif AColor::Bevel(memDC, false, cursorField); msg = mField[1]; memDC.GetTextExtent(msg, &textWidth, &textHeight); while (msg != "" && textWidth > cursorField.width) { msg = msg.Left(msg.Length() - 1); memDC.GetTextExtent(msg, &textWidth, &textHeight); } memDC.DrawText(msg, cursorField.x + 3, cursorField.y + 2); mRateField.x = 80; mRateField.y = 29; mRateField.width = 50; mRateField.height = 17; AColor::Bevel(memDC, true, mRateField); memDC.DrawText(_("Project rate:"), 3, mRateField.y + 2); memDC.DrawText(wxString::Format("%d", int (mRate + 0.5)), mRateField.x + 3, mRateField.y + 2); dc.Blit(0, 0, mWidth, mHeight, &memDC, 0, 0, wxCOPY, FALSE); }
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(); }