void PlayerList::paintEvent(QPaintEvent * event) { QPainter painter(this); painter.drawImage(0, 0, *m_img); const int nameHeight = 33; const int p1x = 168; const int p2x = 226; QFont nameFont("Times New Roman"); nameFont.setPixelSize(20); QFont numFont("Calibri"); numFont.setPixelSize(18); QList<RankItem> &list = *m_list; for(int i = 0; i < list.size(); ++i) { RankItem &item = list[i]; QString gn = QString::number(item.goldNum, 10); QString sn = QString::number(item.silverNum, 10); painter.setFont(nameFont); painter.drawText(20, 66+i*nameHeight, item.name); painter.setFont(numFont); painter.drawText(p1x, 66+i*nameHeight, gn); painter.drawText(p1x+50, 66+i*nameHeight, sn); } }
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 KChatBaseModel::saveConfig(KConfig* conf) { if (!conf) { conf = KGlobal::config().data(); } KConfigGroup cg(conf, "KChatBaseModelPrivate"); cg.writeEntry("NameFont", nameFont()); cg.writeEntry("MessageFont", messageFont()); cg.writeEntry("SystemNameFont", systemNameFont()); cg.writeEntry("SystemMessageFont", systemMessageFont()); cg.writeEntry("MaxMessages", maxItems()); }
ProcessorGraphicsItem::ProcessorGraphicsItem(Processor* processor) : ProcessorObserver() , LabelGraphicsItemObserver() , processor_(processor) , processorMeta_(nullptr) , progressItem_(nullptr) , statusItem_(nullptr) , linkItem_(nullptr) , highlight_(false) #if IVW_PROFILING , processCount_(0) , countLabel_(nullptr) , maxEvalTime_(0.0) , evalTime_(0.0) , totEvalTime_(0.0) #endif { setZValue(PROCESSORGRAPHICSITEM_DEPTH); setFlags(ItemIsMovable | ItemIsSelectable | ItemIsFocusable | ItemSendsGeometryChanges); setCacheMode(QGraphicsItem::DeviceCoordinateCache); setRect(-width / 2, -height / 2, width, height); QGraphicsDropShadowEffect* processorShadowEffect = new QGraphicsDropShadowEffect(); processorShadowEffect->setOffset(3.0); processorShadowEffect->setBlurRadius(3.0); setGraphicsEffect(processorShadowEffect); nameLabel_ = new LabelGraphicsItem(this); nameLabel_->setCrop(9, 8); nameLabel_->setPos(-width / 2.0 + labelHeight, -height / 2.0 + 0.6 * labelHeight); nameLabel_->setDefaultTextColor(Qt::white); QFont nameFont("Segoe", labelHeight, QFont::Black, false); nameFont.setPixelSize(pointSizeToPixelSize(labelHeight)); nameLabel_->setFont(nameFont); LabelGraphicsItemObserver::addObservation(nameLabel_); classLabel_ = new LabelGraphicsItem(this); classLabel_->setCrop(9, 8); classLabel_->setPos(-width / 2.0 + labelHeight, -height / 2.0 + labelHeight * 2.0); classLabel_->setDefaultTextColor(Qt::lightGray); QFont classFont("Segoe", labelHeight, QFont::Normal, true); classFont.setPixelSize(pointSizeToPixelSize(labelHeight)); classLabel_->setFont(classFont); nameLabel_->setText(QString::fromStdString(processor_->getIdentifier())); classLabel_->setText(QString::fromStdString(processor_->getDisplayName() + " " + processor_->getTags().getString())); processor_->ProcessorObservable::addObserver(this); processorMeta_ = processor->getMetaData<ProcessorMetaData>(ProcessorMetaData::CLASS_IDENTIFIER); processorMeta_->addObserver(this); linkItem_ = new ProcessorLinkGraphicsItem(this); std::vector<Inport*> inports = processor_->getInports(); std::vector<Outport*> outports = processor_->getOutports(); inportX = rect().left() + 12.5f; inportY = rect().top() + 4.5f; outportX = rect().left() + 12.5f; outportY = rect().bottom() - 4.5f; for (auto& inport : inports) { addInport(inport); } for (auto& outport : outports) { addOutport(outport); } statusItem_ = new ProcessorStatusGraphicsItem(this, processor_); if (auto progressBarOwner = dynamic_cast<ProgressBarOwner*>(processor_)) { progressItem_ = new ProcessorProgressGraphicsItem(this, &(progressBarOwner->getProgressBar())); progressBarOwner->getProgressBar().ActivityIndicator::addObserver(statusItem_); } if (auto activityInd = dynamic_cast<ActivityIndicatorOwner*>(processor_)){ activityInd->getActivityIndicator().addObserver(statusItem_); } #if IVW_PROFILING countLabel_ = new LabelGraphicsItem(this); countLabel_->setCrop(9,8); countLabel_->setPos(rect().left() + labelHeight, height / 2 - labelHeight*2.5); countLabel_->setDefaultTextColor(Qt::lightGray); countLabel_->setFont(classFont); countLabel_->setTextWidth(width - 2*labelHeight); #endif setVisible(processorMeta_->isVisible()); setSelected(processorMeta_->isSelected()); setPos(QPointF(processorMeta_->getPosition().x, processorMeta_->getPosition().y)); }
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(); }