void GraphicsScene::drawForeground(QPainter *painter, const QRectF &rect) { QRectF textRect(rect.left(), rect.bottom()-100, rect.width(), 100); painter->drawText(textRect, QString("copyright @ Wang Wei. SEU. Nanjing"), QTextOption(Qt::AlignCenter) ); QRectF titleRect(rect.left(), rect.top(), rect.width(), 50); QFont titleFont; titleFont.setPointSizeF(20); titleFont.setWeight(QFont::Bold); painter->setFont(titleFont); painter->drawText(titleRect, QString(mTitle), QTextOption(Qt::AlignCenter)); }
QPixmap QzTools::createPixmapForSite(const QIcon &icon, const QString &title, const QString &url) { const QFontMetrics fontMetrics = QApplication::fontMetrics(); const int padding = 4; const int maxWidth = fontMetrics.width(title.length() > url.length() ? title : url) + 3 * padding + 16; const int width = qMin(maxWidth, 150); const int height = fontMetrics.height() * 2 + fontMetrics.leading() + 2 * padding; QPixmap pixmap(width, height); QPainter painter(&pixmap); // Draw background QPen pen(Qt::black); pen.setWidth(1); painter.setPen(pen); painter.fillRect(QRect(0, 0, width, height), Qt::white); painter.drawRect(0, 0, width - 1, height - 1); // Draw icon QRect iconRect(0, 0, 16 + 2 * padding, height); icon.paint(&painter, iconRect); // Draw title QRect titleRect(iconRect.width(), padding, width - padding - iconRect.width(), fontMetrics.height()); painter.drawText(titleRect, fontMetrics.elidedText(title, Qt::ElideRight, titleRect.width())); // Draw url QRect urlRect(titleRect.x(), titleRect.bottom() + fontMetrics.leading(), titleRect.width(), titleRect.height()); painter.setPen(QApplication::palette().color(QPalette::Link)); painter.drawText(urlRect, fontMetrics.elidedText(url, Qt::ElideRight, urlRect.width())); return pixmap; }
bool ScalePicker::eventFilter(QObject *object, QEvent *e) { if (!object->inherits("QwtScaleWidget")) return QObject::eventFilter(object, e); QwtScaleWidget *scale = (QwtScaleWidget *)object; d_current_axis = scale; if ( e->type() == QEvent::MouseButtonDblClick ){ mouseDblClicked(scale, ((QMouseEvent *)e)->pos()); return true; } if ( e->type() == QEvent::MouseButtonPress){ const QMouseEvent *me = (const QMouseEvent *)e; QPoint pos = me->pos(); if (me->button() == Qt::LeftButton){ scale->setFocus(); emit clicked(); deselect(); if (titleRect(scale).contains(pos)) selectTitle(scale); else if (!scaleTicksRect(scale).contains(pos)) selectLabels(scale); return !(me->modifiers() & Qt::ShiftModifier) && !scaleTicksRect(scale).contains(pos); } else if (me->button() == Qt::RightButton){ mouseRightClicked(scale, pos); return true; } } return QObject::eventFilter(object, e); }
void nodeWidget::paint( QPainter *painter, const QStyleOptionGraphicsItem *, QWidget * ) { QString title( "Hello" ); QList <QString> properties; properties << "Thing" << "lalala" << "bouind" << "hahaha"; QRectF originalRect( titlebarRect( painter->font() ) ); _titlePath = QPainterPath(); _titlePath.addRect( originalRect ); QRectF titleRect( originalRect ); titleRect.setHeight( titleRect.height() + ( ROUNDRADIUS * 2 + 1 ) ); QRectF contentsRect( titleRect ); contentsRect.setY( originalRect.height() ); contentsRect.setHeight( originalRect.height() + NODEPROPERTYHEIGHT*( properties.size() - 1 ) - 2*ROUNDRADIUS - 4 ); QPainterPath titleBar( makeRoundedPath( titleRect ) ); QPainterPath contents( makeRoundedPath( contentsRect ) ); QPen outlinePen( Qt::black, 3 ); if( isSelected() ) { outlinePen.setColor( SELECTED_COLOUR ); } QPainterPath globalLine( makeRoundedPath( titleRect.unite( contentsRect ) ) ); painter->setPen( outlinePen ); painter->drawPath( globalLine ); painter->fillPath( titleBar, titleGradient( titleRect ) ); painter->fillPath( contents, contentsBrush( contentsRect ) ); QColor separatingLineColor( Qt::black ); if( isSelected() ) { separatingLineColor = SELECTED_COLOUR; } separatingLineColor.setAlpha( 128 ); QPen separatingLinePen( separatingLineColor ); QPen whitePen( Qt::white ); painter->setPen( whitePen ); painter->drawText( originalRect, Qt::AlignCenter, title ); QRectF textRect( titleRect ); textRect.moveTop( textRect.top() + originalRect.height() - 2*ROUNDRADIUS - 2 ); FOREACH( properties, prop ) { painter->setPen( whitePen ); painter->drawText( textRect, Qt::AlignCenter, *prop ); if( &(*prop) != &(properties.back()) ) { painter->setPen( separatingLinePen ); painter->drawLine( titleRect.x(), textRect.y()+NODEPROPERTYHEIGHT+4, titleRect.x()+titleRect.width(), textRect.y()+NODEPROPERTYHEIGHT+4 ); } textRect.moveTop( textRect.top() + NODEPROPERTYHEIGHT ); }
void CMyListBoxAppView::ConstructL(const TRect& aRect) { iIsDoubleLine = 0; CreateWindowL(); CreateListBoxL(); iTitle = CCknAppTitle::NewL(CCknAppTitle::EList); iTitle->SetContainerWindowL(*this); HBufC* text = iCoeEnv->AllocReadResourceLC(R_APP_TITLE); iTitle->SetTextL(*text, CCknAppTitle::EMainTitle); CleanupStack::PopAndDestroy(text); TRect titleRect(1, 1, aRect.Width()-KShadowMargin, iTitle->MinimumSize().iHeight); iTitle->SetRect(titleRect); // Indicate that the control is blank SetBlank(); // Set the control's border //SetBorder(TGulBorder::EFlatContainer); // Set the correct application view (Note: ESkinAppViewWithCbaNoToolband is the default) CknEnv::Skin().SetAppViewType(ESkinAppViewWithCbaNoToolband); SetRect(aRect); ActivateL(); }
/** * Event: OnPaint * * Render the Notification Window */ LRESULT NotificationWindow::OnPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { PAINTSTRUCT ps; BeginPaint(&ps); { MyGdiplusHelper gdi_plus_autostart; { // get draw area RECT clientRect; ::GetClientRect(m_hWnd, &clientRect); // create Gdiplus Graphics object Gdiplus::Graphics graphics(m_hWnd, FALSE); graphics.SetClip(Gdiplus::Rect(clientRect.left, clientRect.top, clientRect.right - clientRect.left, clientRect.bottom - clientRect.top)); // draw a background Gdiplus::SolidBrush backgroundBrush(Gdiplus::Color(DEFAULT_ALPHA, 255, 255, 255)); graphics.FillRectangle(&backgroundBrush, clientRect.left, clientRect.top, clientRect.right - clientRect.left, clientRect.bottom - clientRect.top); // shrink draw area int inset = 4; clientRect.left += inset; clientRect.top += inset; clientRect.right -= inset; clientRect.bottom -= inset; // whack a logo TODO //Bitmap* bitmap = new Bitmap(m_icon.c_str(), FALSE); int bitmapWidth = 0;//bitmap->GetWidth(); int bitmapHeight = 15;//bitmap->GetHeight(); //graphics->DrawImage(bitmap, clientRect.left, clientRect.top, //bitmapWidth, bitmapHeight); // draw a separator Gdiplus::Pen blackPen(Gdiplus::Color(0, 0, 0), 1.0f); graphics.DrawLine(&blackPen, clientRect.left, clientRect.top + bitmapHeight + inset, clientRect.right, clientRect.top + bitmapHeight + inset); // setup text properties Gdiplus::Font titleFont(L"Verdana", 10, Gdiplus::FontStyleBold); Gdiplus::Font textFont(L"Verdana", 10, Gdiplus::FontStyleRegular); Gdiplus::RectF titleRect((float)clientRect.left + inset + bitmapWidth, (float)clientRect.top, (float)clientRect.right, 20.0f); Gdiplus::RectF textRect((float)clientRect.left, (float)clientRect.top + bitmapHeight + (inset * 2), (float)clientRect.right, (float)clientRect.bottom - bitmapHeight - (inset * 2)); Gdiplus::StringFormat format; format.SetTrimming(Gdiplus::StringTrimmingEllipsisCharacter); format.SetFormatFlags(Gdiplus::StringFormatFlagsLineLimit); Gdiplus::SolidBrush blackBrush(Gdiplus::Color(255, 0, 0, 0)); // draw the message graphics.DrawString(m_title.c_str(), (int)m_title.length(), &titleFont, titleRect, &format, &blackBrush); graphics.DrawString(m_message.c_str(), (int)m_message.length(), &textFont, textRect, &format, &blackBrush); } } EndPaint(&ps); bHandled = TRUE; return 0; }
void ScalePicker::mouseDblClicked(const QwtScaleWidget *scale, const QPoint &pos) { if (titleRect(scale).contains(pos)) emit axisTitleDblClicked(); else if (scaleRect(scale).contains(pos)) emit axisDblClicked(scale->alignment()); }
void ListItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { QStyleOptionViewItemV4 opt = option; initStyleOption(&opt, index); const QWidget* w = opt.widget; const QStyle* style = w ? w->style() : QApplication::style(); const Qt::LayoutDirection direction = w ? w->layoutDirection() : QApplication::layoutDirection(); #ifdef Q_OS_WIN const QPalette::ColorRole colorRole = QPalette::Text; #else const QPalette::ColorRole colorRole = opt.state & QStyle::State_Selected ? QPalette::HighlightedText : QPalette::Text; #endif int topPosition = opt.rect.top() + m_padding; // Draw background style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, w); // Draw icon QRect iconRect(opt.rect.left() + (opt.rect.width() - m_iconSize) / 2, topPosition, m_iconSize, m_iconSize); QRect visualIconRect = style->visualRect(direction, opt.rect, iconRect); QPixmap pixmap = index.data(Qt::DecorationRole).value<QIcon>().pixmap(m_iconSize); painter->drawPixmap(visualIconRect, pixmap); topPosition += m_iconSize + m_padding; // Draw title const QString title = index.data(Qt::DisplayRole).toString(); const int leftTitleEdge = opt.rect.left() + m_padding; QRect titleRect(leftTitleEdge, topPosition, opt.rect.width() - 2 * m_padding, opt.fontMetrics.height()); QRect visualTitleRect = style->visualRect(direction, opt.rect, titleRect); style->drawItemText(painter, visualTitleRect, Qt::AlignCenter, opt.palette, true, title, colorRole); }
void QgsCollapsibleGroupBox::setCollapsed( bool collapse ) { mCollapsed = collapse; if ( !isVisible() ) return; // for consistent look/spacing across platforms when collapsed if ( ! mInitFlat ) // skip if initially set to flat in Designer setFlat( collapse ); // avoid flicker in X11 QApplication::processEvents(); // set maximum height to hide contents - does this work in all envs? // setMaximumHeight( collapse ? 25 : 16777215 ); setMaximumHeight( collapse ? titleRect().bottom() + 6 : 16777215 ); mCollapseButton->setIcon( collapse ? mExpandIcon : mCollapseIcon ); // if expanding and is in a QScrollArea, scroll down to make entire widget visible if ( mShown && mScrollOnExpand && !collapse && mParentScrollArea ) { // process events so entire widget is shown QApplication::processEvents(); mParentScrollArea->ensureWidgetVisible( this ); } emit collapsedStateChanged( this ); }
void LaptopClient::updateActiveBuffer( ) { QRect rTitle = titleRect(); if( !bufferDirty && (lastBufferWidth == rTitle.width())) return; if ( rTitle.width() <= 0 || rTitle.height() <= 0 ) return; lastBufferWidth = rTitle.width(); bufferDirty = false; activeBuffer = QPixmap(rTitle.width(), rTitle.height()); QPainter p; QRect r(0, 0, activeBuffer.width(), activeBuffer.height()); p.begin(&activeBuffer); if(aUpperGradient){ p.drawTiledPixmap(r, *aUpperGradient); } else{ p.fillRect(r, options()->color(KDecoration::ColorTitleBar, true)); } if(titlePix) p.drawTiledPixmap(r, *titlePix); p.setFont(options()->font(true, isToolWindow() )); QFontMetrics fm(options()->font(true)); QPalette g = options()->palette(KDecoration::ColorTitleBar, true); g.setCurrentColorGroup( QPalette::Active ); if(aUpperGradient) p.drawTiledPixmap(r.x()+((r.width()-fm.width(caption()))/2)-4, r.y(), fm.width(caption())+8, r.height()-1, *aUpperGradient); else p.fillRect(r.x()+((r.width()-fm.width(caption()))/2)-4, 0, fm.width(caption())+8, r.height(), g.brush(QPalette::Background)); p.setPen(g.mid().color()); p.drawLine(r.x(), r.y(), r.right(), r.y()); p.drawLine(r.x(), r.y(), r.x(), r.bottom()); p.setPen(g.color(QPalette::Button)); p.drawLine(r.right(), r.y(), r.right(), r.bottom()); p.drawLine(r.x(), r.bottom(), r.right(), r.bottom()); p.setPen(options()->color(KDecoration::ColorFont, true)); p.drawText(r.x(), r.y()+1, r.width(), r.height()-1, Qt::AlignCenter, caption() ); g = options()->palette(KDecoration::ColorFrame, true); g.setCurrentColorGroup( QPalette::Active ); p.setPen(g.background().color()); p.drawPoint(r.x(), r.y()); p.drawPoint(r.right(), r.y()); p.drawLine(r.right()+1, r.y(), r.right()+1, r.bottom()); p.end(); }
void QgsCollapsibleGroupBox::mouseReleaseEvent( QMouseEvent *event ) { // catch mouse release over title when non checkable, to collapse/expand if ( !isCheckable() && event->button() == Qt::LeftButton ) { if ( titleRect().contains( event->pos() ) ) { toggleCollapsed(); return; } } // default behaviour - pass to QGroupBox QGroupBox::mouseReleaseEvent( event ); }
// Handle size changes. Set the contained controls extents. Called by framework void CMessageListBox::SizeChanged() { innerRect = Border().InnerRect(Rect()); // Application Title rect. Fills the controls top area TSize titleSize(innerRect.Width(), iAppTitle->MinimumSize().iHeight); TRect titleRect(innerRect.iTl, titleSize); iAppTitle->SetRect(titleRect); // List box size and rect. Fills the remaining area TSize listBoxSize(innerRect.Width(), innerRect.Height() - iAppTitle->MinimumSize().iHeight); TRect listBoxRect(TPoint(titleRect.iTl.iX, titleRect.iBr.iY+1), listBoxSize); iListbox->SetRect(listBoxRect); }
void InventoryInfoWindow::onPaint() { Common::ScopedPtr<Graphics::Surface> background(_vm->_gfx->getBitmap(IDB_INVENTORY_INFO_BACKGROUND)); // Draw the title uint32 textColor = _vm->_gfx->getColor(212, 109, 0); Common::Rect titleRect(10, 56, 263, 71); Common::String title = _vm->getString(IDES_ITEM_TITLE_BASE + _currentItemID); assert(!title.empty()); _vm->_gfx->renderText(background.get(), _textFont, title, titleRect.left, titleRect.top, titleRect.width(), titleRect.height(), textColor, _fontHeight); // Draw the description Common::Rect descRect(10, 89, 263, 186); Common::String desc = _vm->getString(IDES_ITEM_DESC_BASE + _currentItemID * 5); assert(!desc.empty()); _vm->_gfx->renderText(background.get(), _textFont, desc, descRect.left, descRect.top, descRect.width(), descRect.height(), textColor, _fontHeight); Common::Rect absoluteRect = getAbsoluteRect(); _vm->_gfx->blit(background.get(), absoluteRect.left, absoluteRect.top); }
void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const { QStyleOptionViewItem newOption; newOption = option; newOption.state &= ~QStyle::State_HasFocus; newOption.palette.setColor( QPalette::Disabled, QPalette::Text, Qt::black ); QTableWidget* pWidget = static_cast<QTableWidget*>( parent() ); RecentTableWidgetItem* pItem = static_cast<RecentTableWidgetItem*>(pWidget->item(index.row(), index.column())); painter->setFont(fontTitle); QFontMetrics tfm(fontTitle); int fontTitleSize = tfm.height(); QRect titleRect( newOption.rect.x(), newOption.rect.y(), newOption.rect.width(), fontTitleSize ); painter->drawText( titleRect, Qt::TextSingleLine, tfm.elidedText(pItem->title, Qt::ElideRight, newOption.rect.width() )); painter->setFont(fontInfo); QFontMetrics ifm(fontInfo); int fontAuthorSize = ifm.height(); QRect infoRect( newOption.rect.x(), newOption.rect.y() + fontTitleSize, newOption.rect.width(), fontAuthorSize ); int percentWidth = ifm.boundingRect(pItem->percent).width(); infoRect.adjust(0,0,-percentWidth,0); painter->drawText( infoRect, Qt::TextSingleLine, ifm.elidedText(pItem->info, Qt::ElideRight, infoRect.width() ) ); QRect percentRect( infoRect.right(), infoRect.top(), percentWidth, infoRect.height() ); painter->drawText( percentRect, Qt::TextSingleLine, pItem->percent ); if (index.flags() & Qt::ItemIsSelectable) { Qt::GlobalColor lineColor = Qt::black; int lineWidth = newOption.state & QStyle::State_Selected ? 5:0; QPen pen(lineColor, lineWidth, Qt::SolidLine); painter->setPen(pen); painter->drawLine(newOption.rect.left(), newOption.rect.bottom()-lineWidth/2, newOption.rect.right(), newOption.rect.bottom()-lineWidth/2); } }
void CCardLabel::paintEvent(QPaintEvent *ev) { QRectF titleRect(translatePoint(5, 2), translatePoint(155, 25)); QRectF imgRect(translatePoint(5, 24), translatePoint(155, 144)); QRectF blackRect(translatePoint(6, 24 + 40), translatePoint(156, 24 + 80)); QRectF setRect(translatePoint(155 - 2 - 32, 144 + 8), translatePoint(155 - 2, 144 + 8 + 32)); QRectF delayRect(translatePoint(155 - 40, 24), translatePoint(155, 24 + 40)); QRectF attackRect(translatePoint(5 + 2, 215 - 20), translatePoint(5 + 2 + 20, 215)); QRectF healthRect(translatePoint(155 - 2 - 20, 215 - 20), translatePoint(155 - 2, 215)); QRectF ownedRect(translatePoint(155 - 60 - 2, 144 - 28), translatePoint(155 - 2, 144)); QPointF upgradePos(translatePoint(50, 193)); QPointF uniquePos(translatePoint(5 + 2, 144 - 28 - 2)); QPointF skillPos(translatePoint(5 + 2, 144 + 8)); // Update lock button geo before parent paint if (mLockButton) { mLockButton->setGeometry(QRect(imgRect.x() + 2, imgRect.y() + 2, 24, 24)); } // Regular label painting (background image) QLabel::paintEvent(ev); if (mCard.isValid()) { const CGlobalConfig &cfg = CGlobalConfig::getCfg(); QPainter painter(this); // Paint upgrade symbol QString cardName = mCard.getName(); if (mCard.getUpgradeLevel() != EUpgradeNotAvailable) { if (cardName.endsWith(QChar('*'))) { cardName.replace("*", ""); } switch(mCard.getUpgradeLevel()) { case EUpgradeLevel1: painter.drawPixmap(upgradePos, QPixmap(cfg.getResourcePicturePath() + "UpgradeIcon1.png")); break; case EUpgradeLevel2: painter.drawPixmap(upgradePos, QPixmap(cfg.getResourcePicturePath() + "UpgradeIcon2.png")); break; default: break; } } // Paint title QPen inPen(Qt::white); painter.setPen(inPen); painter.drawText(titleRect.adjusted(titleRect.height() + 2, -1, 0, -1), Qt::AlignLeft | Qt::AlignVCenter, cardName); painter.setRenderHint(QPainter::SmoothPixmapTransform, true); if (!mTitleIcon.isNull()) { painter.drawPixmap(titleRect.topLeft(), mTitleIcon.scaled(titleRect.height() + 1, titleRect.height() + 1, Qt::KeepAspectRatio, Qt::SmoothTransformation)); } // Paint unique symbol if (mCard.isUnique()) { painter.drawPixmap(uniquePos, QPixmap(":/img/unique.png")); //painter.drawText(dx + 2, dySkill - 15, 100, 12, Qt::AlignLeft | Qt::AlignVCenter, "Unique"); } // Paint skill symbols const TSkillList &skills = mCard.getSkills(); int curIdx = 0; for (TSkillList::const_iterator i = skills.begin(); i != skills.end(); ++i, ++curIdx) { const CSkill& curSkill = mCards.getSkillForId(i->getId()); if (curSkill.isValid()) { QPixmap skillPixmap; if (!skillPixmap.load(cfg.getResourcePicturePath() + curSkill.getPicture() + ".png")) { skillPixmap.load(cfg.getCustomPicturePath() + curSkill.getPicture() + ".png"); } painter.drawPixmap(skillPos, skillPixmap); skillPos += QPointF(16 + 2, 0); //painter.drawText(dx, 80 + i*10, 100, 10, Qt::AlignLeft | Qt::AlignVCenter, curSkill.makeSignature(skills.at(i))); } } // Paint set symbol if (mCard.getSet() != EUnknownSet) { QPixmap setPixmap; if (!setPixmap.load(cfg.getResourcePicturePath() + mCards.getPictureForCardSet(mCard.getSet()))) { setPixmap.load(cfg.getCustomPicturePath() + mCards.getPictureForCardSet(mCard.getSet())); } painter.drawPixmap(setRect, setPixmap, QRectF(0, 0, 24, 24)); } // Paint delay symbol if (mCard.getDelay() > -1) { painter.drawPixmap(delayRect, QPixmap(cfg.getResourcePicturePath() + "ClockIcon.png"), QRectF(0, 0, 32, 32)); painter.drawText(delayRect, Qt::AlignCenter, QString("%1").arg(mCard.getDelay())); } // Paint attack symbol if (mCard.hasAttack()) { painter.drawPixmap(attackRect, QPixmap(cfg.getResourcePicturePath() + "AttackIcon.png"), QRectF(0, 0, 20, 20)); painter.drawText(attackRect.translated(attackRect.width() + 1, 0), Qt::AlignLeft | Qt::AlignVCenter, QString("%1").arg(mCard.getAttack())); } // Paint health symbol if (mCard.hasHealth()) { painter.drawPixmap(healthRect, QPixmap(cfg.getResourcePicturePath() + "HealthIcon.png"), QRectF(0, 0, 20, 20)); painter.drawText(healthRect.adjusted(-2 * healthRect.width() - 1, 0, -healthRect.width() - 1, 0), Qt::AlignRight | Qt::AlignVCenter, QString("%1").arg(mCard.getHealth())); } if (!mIsVirtual) { // Display owned status SCardStatus status = mCards.getCardStatus(mCard); { painter.setPen(Qt::green); QString ownageStr("x0"); if (status.numOwned > 0) { ownageStr = QString("x%1").arg(status.numOwned); } painter.drawText(ownedRect, Qt::AlignRight | Qt::AlignVCenter, ownageStr); } if (cfg.isCardShadingEnabled() && status.numOwned <= 0) { painter.setPen(Qt::NoPen); painter.setBrush(Qt::black); painter.setOpacity(0.6); painter.drawRoundedRect(rect(), 2.0, 2.0); } if (cfg.isBlackLabellingEnabled() && status.isBlack) { // Display black list status painter.setPen(Qt::white); painter.setOpacity(0.6); painter.fillRect(blackRect, QBrush(Qt::black)); painter.setOpacity(1.0); painter.drawText(blackRect, Qt::AlignCenter, "Blacklisted"); } else if (cfg.isWhiteLabellingEnabled() && status.isWhite) { // Display white list status painter.setPen(Qt::black); painter.setOpacity(0.6); painter.fillRect(blackRect, QBrush(Qt::white)); painter.setOpacity(1.0); painter.drawText(blackRect, Qt::AlignCenter, "Whitelisted"); } } } }
void YZPrinter::doPrint( ) { const double fontsize = 10.0; PSDoc *doc = PS_new(); if (!doc) return ; QByteArray p = m_path.toLatin1(); PS_open_file(doc, p.data()); PS_set_info(doc, "Creator", "Yzis"); PS_set_info(doc, "Author", ""); PS_set_info(doc, "Title", p.data()); // Set so it'll fit on both A4 and letter paper; // some of us live in the US, with archaic paper sizes. ;-) PS_set_info(doc, "BoundingBox", "0 0 596 792"); int font; font = PS_findfont(doc, "Fixed", "", 0); dbg() << "findfont returned " << font << endl; if ( !font ) return ; //no font => abort QPrinter lpr(QPrinter::PrinterResolution); QPainter p( &lpr ); QFont f( "fixed" ); f.setFixedPitch( true ); f.setStyleHint( QFont::TypeWriter ); p.setFont( f ); unsigned int height = lpr.height(); unsigned int width = lpr.width(); unsigned int linespace = p.fontMetrics().lineSpacing(); unsigned int maxwidth = p.fontMetrics().maxWidth(); p.end(); PS_set_value(doc, "leading", linespace); unsigned int clipw = width / maxwidth - 1; unsigned int cliph = height / linespace - 1; unsigned int oldLinesVis = mView->getLinesVisible( ); unsigned int oldColumnsVis = mView->getColumnsVisible( ); //should be current's view setting no ? XXX bool number = mView->getLocalBooleanOption( "number" ); unsigned int marginLeft = 0; double red, green, blue; if ( number ) { marginLeft = ( 2 + QString::number( mView->buffer()->lineCount() ).length() ); } YOptionValue* ov_wrap = mView->getLocalOption( "wrap" ); bool oldWrap = ov_wrap->boolean(); ov_wrap->setBoolean( true ); mView->setVisibleArea( clipw - marginLeft, cliph, false ); unsigned int totalHeight = mView->drawTotalHeight(); mView->setVisibleArea( clipw - marginLeft, totalHeight, false ); mView->initDraw( 0, 0, 0, 0 ); unsigned int lastLineNumber = 0; unsigned int pageNumber = 0; QRect titleRect( 0, 0, width, linespace + linespace / 2 ); unsigned int topY = titleRect.height() + linespace; unsigned int curY = topY; unsigned int curX; cliph = ( height - topY ) / linespace; int nbPages = totalHeight / cliph + ( totalHeight % cliph ? 1 : 0 ); PS_begin_page(doc, 596, 792); PS_setfont(doc, font, fontsize); PS_set_parameter(doc, "hyphenation", "false"); PS_set_parameter(doc, "linebreak", "true"); PS_set_parameter(doc, "parbreak", "false"); PS_set_value(doc, "parindent", 0.0); PS_set_value(doc, "numindentlines", 0.0); while ( mView->drawNextLine( ) ) { if ( curY == topY ) { if ( pageNumber ) { PS_end_page(doc); PS_begin_page(doc, 596, 792); PS_setfont(doc, font, fontsize); PS_set_value(doc, "leading", linespace); } ++pageNumber; convertColor(Qt::black, red, green, blue); PS_setcolor(doc, "fillstroke", "rgb", red, green, blue, 0.0); QByteArray n = ( ' ' + mView->buffer()->fileName() ).toLatin1(); PS_show_boxed(doc, n.data(), titleRect.x(), titleRect.y(), titleRect.width(), titleRect.height(), "left", ""); QByteArray nb = ( QString::number( pageNumber ) + '/' + QString::number( nbPages ) + ' ' ).toLatin1(); PS_show_boxed(doc, nb.data(), titleRect.x(), titleRect.y(), titleRect.width(), titleRect.height(), "right", ""); } if ( number ) { unsigned int lineNumber = mView->drawLineNumber(); if ( lineNumber != lastLineNumber ) { //p.setPen( Qt::gray ); convertColor(Qt::gray, red, green, blue); PS_setcolor(doc, "fillstroke", "rgb", red, green, blue, 0.0); PS_moveto(doc, 0, curY); QByteArray m = QString::number( lineNumber ).rightJustified( marginLeft - 1, ' ' ).toLatin1(); PS_show(doc, m.data()); lastLineNumber = lineNumber; } } curX = marginLeft * maxwidth; while ( mView->drawNextCol( ) ) { QColor c = mView->drawColor( ); if ( c.isValid() && c != Qt::white ) convertColor(mView->drawColor(), red, green, blue); else convertColor(Qt::black, red, green, blue); PS_setcolor(doc, "fillstroke", "rgb", red, green, blue, 0.0); char buf[2] = { 0, 0 }; buf[0] = mView->drawChar().toLatin1(); PS_show_xy(doc, buf, curX, curY); curX += mView->drawLength( ) * maxwidth; } curY += linespace * mView->drawHeight(); if ( curY >= cliph * linespace + topY ) { // draw Rect convertColor(Qt::black, red, green, blue); PS_setcolor(doc, "fillstroke", "rgb", red, green, blue, 0.0); PS_rect(doc, 0, 0, width, curY); if ( number ) { PS_moveto(doc, marginLeft*maxwidth - maxwidth / 2, titleRect.height()); PS_lineto(doc, marginLeft*maxwidth - maxwidth / 2, curY); } PS_moveto(doc, titleRect.x(), titleRect.height()); PS_lineto(doc, titleRect.width(), titleRect.height()); curY = topY; } } if ( curY != topY ) { // draw Rect convertColor(Qt::black, red, green, blue); PS_setcolor(doc, "fillstroke", "rgb", red, green, blue, 0.0); PS_rect(doc, 0, 0, width, curY); if ( number ) { PS_moveto(doc, marginLeft*maxwidth - maxwidth / 2, titleRect.height()); PS_lineto(doc, marginLeft*maxwidth - maxwidth / 2, curY); } PS_moveto(doc, titleRect.x(), titleRect.height()); PS_lineto(doc, titleRect.width(), titleRect.height()); } PS_end_page(doc); PS_deletefont(doc, font); PS_close(doc); PS_delete(doc); PS_shutdown(); ov_wrap->setBoolean( oldWrap ); mView->setVisibleArea( oldColumnsVis, oldLinesVis, false ); }
void LocationCompleterDelegate::paint(QPainter* painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { QStyleOptionViewItemV4 opt = option; initStyleOption(&opt, index); const QWidget* w = opt.widget; const QStyle* style = w ? w->style() : QApplication::style(); const int height = opt.rect.height(); const int center = height / 2 + opt.rect.top(); // Prepare title font QFont titleFont = opt.font; titleFont.setPointSize(titleFont.pointSize() + 1); const QFontMetrics titleMetrics(titleFont); int leftPosition = m_padding * 2; int rightPosition = opt.rect.right() - m_padding; opt.state &= ~QStyle::State_MouseOver; if (m_view->hoveredIndex() == index) { opt.state |= QStyle::State_Selected; } else { opt.state &= ~QStyle::State_Selected; } #ifdef Q_OS_WIN const QPalette::ColorRole colorRole = QPalette::Text; const QPalette::ColorRole colorLinkRole = QPalette::Link; #else const QPalette::ColorRole colorRole = opt.state & QStyle::State_Selected ? QPalette::HighlightedText : QPalette::Text; const QPalette::ColorRole colorLinkRole = opt.state & QStyle::State_Selected ? QPalette::HighlightedText : QPalette::Link; #endif // Draw background style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, w); // Draw icon const int iconSize = 16; const int iconYPos = center - (iconSize / 2); QRect iconRect(leftPosition, iconYPos, iconSize, iconSize); QPixmap pixmap = index.data(Qt::DecorationRole).value<QIcon>().pixmap(iconSize); painter->drawPixmap(iconRect, pixmap); leftPosition = iconRect.right() + m_padding * 2; // Draw star to bookmark items int starPixmapWidth = 0; if (index.data(LocationCompleterModel::BookmarkRole).toBool()) { const QIcon icon = IconProvider::instance()->bookmarkIcon(); const QSize starSize(16, 16); starPixmapWidth = starSize.width(); QPoint pos(rightPosition - starPixmapWidth, center - starSize.height() / 2); QRect starRect(pos, starSize); painter->drawPixmap(starRect, icon.pixmap(starSize)); } const QString searchText = index.data(LocationCompleterModel::SearchStringRole).toString(); // Draw title const int leftTitleEdge = leftPosition + 2; // RTL Support: remove conflicting of right-aligned text and starpixmap! const int rightTitleEdge = rightPosition - m_padding - starPixmapWidth; QRect titleRect(leftTitleEdge, opt.rect.top() + m_padding, rightTitleEdge - leftTitleEdge, titleMetrics.height()); QString title = index.data(LocationCompleterModel::TitleRole).toString(); painter->setFont(titleFont); viewItemDrawText(painter, &opt, titleRect, title, colorRole, searchText); // Draw link const int infoYPos = titleRect.bottom() + opt.fontMetrics.leading() + 2; QRect linkRect(titleRect.x(), infoYPos, titleRect.width(), opt.fontMetrics.height()); const QByteArray linkArray = index.data(Qt::DisplayRole).toByteArray(); // Let's assume that more than 500 characters won't fit in line on any display... // Fixes performance when trying to get elidedText for a really long // (length() > 1000000) urls - data: urls can get that long QString link; if (!linkArray.startsWith("data") && !linkArray.startsWith("javascript")) { link = QString::fromUtf8(QByteArray::fromPercentEncoding(linkArray)).left(500); } else { link = QString::fromLatin1(linkArray.left(500)); } painter->setFont(opt.font); // Draw url (or switch to tab) int tabPos = index.data(LocationCompleterModel::TabPositionTabRole).toInt(); if (drawSwitchToTab() && tabPos != -1) { const QIcon tabIcon = QIcon(QSL(":icons/menu/tab.png")); QRect iconRect(linkRect); iconRect.setWidth(m_padding + 16 + m_padding); tabIcon.paint(painter, iconRect); QRect textRect(linkRect); textRect.setX(textRect.x() + m_padding + 16 + m_padding); viewItemDrawText(painter, &opt, textRect, LocationCompleterView::tr("Switch to tab"), colorLinkRole); } else { viewItemDrawText(painter, &opt, linkRect, link, colorLinkRole, searchText); } // Draw line at the very bottom of item if the item is not highlighted if (!(opt.state & QStyle::State_Selected)) { QRect lineRect(opt.rect.left(), opt.rect.bottom(), opt.rect.width(), 1); painter->fillRect(lineRect, opt.palette.color(QPalette::AlternateBase)); } }
void CalendarWidget::calculateAndDrawMonth(int j_y, int j_m, int j_d) { monthPixmap = QPixmap(this->size()); //Must be done. //`Qt::transparent` is equivalent to `QColor::fromRgb(0,0,0,0)` or `QColor::fromRgba(0)`. //We could also have used `palette().color(QPalette::Window)`. monthPixmap.fill(Qt::transparent); QPainter p(&monthPixmap); QPen blackPen(QColor(0, 0, 0)); QPen grayPen(QColor(192, 192, 192)); QPen blueThickPen(QColor(0, 0, 255), 2); p.setPen(blackPen); int hUnit = this->width() / 7; int vUnit = this->height() / 7; QString title = Ct::Date::PersianDate::nameOfMonth(j_m) + " " + QString::number(j_y); QRect titleRect(0, 0, this->width(), vUnit); titleRect.adjust(1, 1, -1, -1); p.fillRect(titleRect, QColor(64, 128, 255)); QFont boldFont = this->font(); boldFont.setBold(true); p.setFont(boldFont); p.drawText(titleRect, Qt::AlignCenter, title); for (int i = 0; i < 7; i++) { QRect cellRect((6 - i) * hUnit, vUnit, hUnit, vUnit); cellRect.adjust(1, 1, -1, -1); if (i == 6) p.fillRect(cellRect, QColor(96, 160, 255)); else p.fillRect(cellRect, QColor(128, 192, 255)); p.drawText(cellRect, Qt::AlignCenter, Ct::Date::PersianDate::nameOfPersianWeekDay(i + 1)); for (int j = 0; j < 7; j++) datestamps[j][i] = 0; } QDate firstDayOfJalaliMonth; Ct::Date::PersianDate::JalaliToGregorian(firstDayOfJalaliMonth, j_y, j_m, 1); //Without the QTime of 12 P.M, we got problems on 26/27 Esfand 1391 = 16/17 March 2013: // Both shows the same date! This was on Win7. On WinXP it was on the same month at different // days and in linux I did not test. QDateTime dateStamp(firstDayOfJalaliMonth, QTime(12, 0, 0)); int hPos = 0; int vPos = 2; int mapWeekStartDayFromMondayToSaturday[] = { 0, 3, 4, 5, 6, 7, 1, 2 }; int PersianWeekStartDay = mapWeekStartDayFromMondayToSaturday[firstDayOfJalaliMonth.dayOfWeek()]; hPos = PersianWeekStartDay - 1; int modFridays = (8 - PersianWeekStartDay) % 7; int jalaliMonthDayCount = Ct::Date::PersianDate::numberOfDaysInJalaliMonth(j_y, j_m); QFont smallEnglishFont("Tahoma", 8, QFont::Bold); for (int i = 1; i <= jalaliMonthDayCount; i++) { QRect cellRect((6 - hPos) * hUnit, vPos * vUnit, hUnit, vUnit); cellRect.adjust(1, 1, -1, -1); if (i % 7 == modFridays) p.fillRect(cellRect, QColor(128, 192, 255)); else p.fillRect(cellRect, Qt::white); if (i == j_d) //Today { p.setPen(blueThickPen); p.drawRect(cellRect); } //Draw the Gregorian number FIRST so that it goes lower than the Persian day in high-DPI. if (settings.showGregorianDates) { p.setPen(grayPen); p.setFont(smallEnglishFont); QString dayText = ""; //In case either Persian or Gregorian day is 1, we add the short month name (MMM). Since // in Persian locale the month name is localized, we also add space before it to have // some right margin. if (i == 1 || dateStamp.date().day() == 1) dayText = " " + dateStamp.date().toString("MMM") + " "; //We add space after the day because some right margin is always useful! Of course this space // is used if a localized month name wasn't added to the day number. dayText += QString::number(dateStamp.date().day()) + " "; p.drawText(cellRect, Qt::AlignRight | Qt::AlignBottom, dayText); } p.setPen(blackPen); p.setFont(this->font()); p.drawText(cellRect, Qt::AlignCenter, QString::number(i)); //FIRST save the datestamps datestamps[(6 - hPos)][vPos] = dateStamp.toMSecsSinceEpoch(); dateStamp = dateStamp.addDays(1); //THEN 'increase' hPos/vPos hPos++; if (hPos == 7) { hPos = 0; vPos++; if (vPos == 7) vPos = 2; //Draw the excess 30th and 31th day in the top row. } } }
//____________________________________________________________________________ void ClientGroupItemDataList::animate( AnimationTypes type, int target ) { // store animation type animationType_ = type; if( type == AnimationNone ) { if( isAnimationRunning() ) animation().data()->stop(); targetItem_ = NoItem; draggedItem_ = NoItem; targetRect_ = QRect(); } else if( type & (AnimationEnter|AnimationMove ) ) { // store dragged item bool animate( true ); if( (type&AnimationSameTarget) && draggedItem_ == NoItem ) { animate = false; draggedItem_ = target; } else if( (type&AnimationMove) && targetItem_ == target ) return; // check animation state if( isAnimationRunning() ) animation().data()->stop(); targetItem_ = target; targetRect_ = QRect(); QRect titleRect( _client.titleRect() ); int left( titleRect.left() ); int width = (type&AnimationSameTarget) ? titleRect.width()/count(): titleRect.width()/(count()+1); if( (type&AnimationSameTarget) && draggedItem_ < target ) { target++; if( target >= count() ) target = NoItem; } // loop over items and update bounding rects for( int index = 0; index < count(); index++ ) { ClientGroupItemData& item( ClientGroupItemDataList::operator[](index) ); if( index == target ) { targetRect_ = item._refBoundingRect; targetRect_.setLeft( left ); targetRect_.setWidth( width ); left+=width; } item._startBoundingRect = item._boundingRect; item._endBoundingRect = item._refBoundingRect; item._endBoundingRect.setLeft( left ); if( (type&AnimationSameTarget) && index == draggedItem_ ) { item._endBoundingRect.setWidth( 0 ); } else { item._endBoundingRect.setWidth( width ); left+=width; } } if( targetRect_.isNull() ) { targetRect_ = back()._refBoundingRect; targetRect_.setLeft( left ); targetRect_.setWidth( width ); } if( animate ) { if( animationsEnabled() ) animation().data()->start(); else { // change progress to maximum progress_ = 1; updateBoundingRects(); } } else { for( int index = 0; index < count(); index++ ) { ClientGroupItemData& item( ClientGroupItemDataList::operator[](index) ); item._boundingRect = item._endBoundingRect; } updateButtons( true ); } } else if( type & AnimationLeave ) { // stop animation state if( isAnimationRunning() ) animation().data()->stop(); // reset target targetItem_ = NoItem; targetRect_ = QRect(); if( type & AnimationSameTarget ) { // store dragged item draggedItem_ = target; // do nothing if only one item if( count() <= 1 ) return; QRect titleRect( _client.titleRect() ); int left( titleRect.left() ); int width = titleRect.width()/(count()-1); // loop over items and update bounding rects for( int index = 0; index < count(); index++ ) { ClientGroupItemData& item( ClientGroupItemDataList::operator[](index) ); item._startBoundingRect = item._boundingRect; item._endBoundingRect = item._refBoundingRect; item._endBoundingRect.setLeft( left ); if( index != target ) { if( count() <= 2 ) { item._endBoundingRect = _client.defaultTitleRect( _client.tabId(index) == _client.currentTabId() ); } else { item._endBoundingRect.setWidth( width ); left+=width; } } else { item._endBoundingRect.setWidth( 0 ); } } } else { // loop over items and update bounding rects for( int index = 0; index < count(); index++ ) { ClientGroupItemData& item( ClientGroupItemDataList::operator[](index) ); item._startBoundingRect = item._boundingRect; item._endBoundingRect = item._refBoundingRect; } } if( animationsEnabled() ) animation().data()->start(); else { // change progress to maximum progress_ = 1; updateBoundingRects(); } } return; }
void LaptopClient::paintEvent( QPaintEvent* ) { QPainter p(widget()); QPalette g = options()->palette(KDecoration::ColorFrame, isActive()); g.setCurrentColorGroup( QPalette::Active ); QRect r(widget()->rect()); p.setPen(Qt::black); p.drawRect(r.adjusted(0, 0, -1, -1)); // fill mid frame... p.setPen(g.background().color()); p.drawLine(r.x()+2, r.y()+2, r.right()-2, r.y()+2); p.drawLine(r.left()+2, r.y()+3, r.left()+2, r.bottom()-layoutMetric(LM_BorderBottom)+1); p.drawLine(r.right()-2, r.y()+3, r.right()-2, r.bottom()-layoutMetric(LM_BorderBottom)+1); p.drawLine(r.left()+3, r.y()+3, r.left()+3, r.y()+layoutMetric(LM_TitleEdgeTop)+layoutMetric(LM_TitleHeight)+layoutMetric(LM_TitleEdgeTop) ); p.drawLine(r.right()-3, r.y()+3, r.right()-3, r.y()+layoutMetric(LM_TitleEdgeTop)+layoutMetric(LM_TitleHeight)+layoutMetric(LM_TitleEdgeTop) ); if (!mustDrawHandle() ) p.drawLine(r.left()+1, r.bottom()-2, r.right()-1, r.bottom()-2); // outer frame p.setPen(g.color(QPalette::Light)); p.drawLine(r.x()+1, r.y()+1, r.right()-1, r.y()+1); p.drawLine(r.x()+1, r.y()+1, r.x()+1, r.bottom()-1); p.setPen(g.dark().color()); p.drawLine(r.right()-1, r.y()+1, r.right()-1, r.bottom()-1); p.drawLine(r.x()+1, r.bottom()-1, r.right()-1, r.bottom()-1); int th = titleHeight; int bb = handleSize + 2; // Bottom border int bs = handleSize - 2; // inner size of bottom border if (!mustDrawHandle()) { bb = 6; bs = 0; } if ( isToolWindow() ) th -= 2; // inner rect p.drawRect(r.x() + 3, r.y() + th + 3, r.width() - 7, r.height() - th - bb - 1); // handles if (mustDrawHandle()) { if (r.width() > 3*handleSize + 20) { int range = 8 + 3*handleSize/2; qDrawShadePanel(&p, r.x() + 1, r.bottom() - bs, range, handleSize - 2, g, false, 1, &g.brush(QPalette::Mid)); qDrawShadePanel(&p, r.x() + range + 1, r.bottom() - bs, r.width() - 2*range - 2, handleSize - 2, g, false, 1, isActive() ? &g.brush(QPalette::Background) : &g.brush(QPalette::Mid)); qDrawShadePanel(&p, r.right() - range, r.bottom() - bs, range, bs, g, false, 1, &g.brush(QPalette::Mid)); } else { qDrawShadePanel(&p, r.x() + 1, r.bottom() - bs, r.width() - 2, bs, g, false, 1, isActive() ? &g.brush(QPalette::Background) : &g.brush(QPalette::Mid)); } } r = titleRect(); if(isActive()){ updateActiveBuffer(); p.drawPixmap(r.x(), r.y(), activeBuffer); p.setPen(g.background().color()); p.drawPoint(r.x(), r.y()); p.drawPoint(r.right(), r.y()); p.drawLine(r.right()+1, r.y(), r.right()+1, r.bottom()); } else{ if(iUpperGradient) p.drawTiledPixmap(r.x(), r.y(), r.width(), r.height()-1, *iUpperGradient); else p.fillRect(r.x(), r.y(), r.width(), r.height()-1, options()->color(KDecoration::ColorTitleBar, false)); p.setFont(options()->font(false, isToolWindow() )); QFontMetrics fm(options()->font(false)); g = options()->palette(KDecoration::ColorTitleBar, false); g.setCurrentColorGroup( QPalette::Active ); if(iUpperGradient) p.drawTiledPixmap(r.x()+((r.width()-fm.width(caption()))/2)-4, r.y(), fm.width(caption())+8, r.height()-1, *iUpperGradient); else p.fillRect(r.x()+((r.width()-fm.width(caption()))/2)-4, r.y(), fm.width(caption())+8, r.height()-1, g.brush(QPalette::Background)); p.setPen(g.mid().color()); p.drawLine(r.x(), r.y(), r.right(), r.y()); p.drawLine(r.x(), r.y(), r.x(), r.bottom()); p.setPen(g.color(QPalette::Button)); p.drawLine(r.right(), r.y(), r.right(), r.bottom()); p.drawLine(r.x(), r.bottom(), r.right(), r.bottom()); p.setPen(options()->color(KDecoration::ColorFont, false)); p.drawText(r.x(), r.y()+1, r.width(), r.height()-1, Qt::AlignCenter, caption() ); g = options()->palette(KDecoration::ColorFrame, true); g.setCurrentColorGroup( QPalette::Active ); p.setPen(g.background().color()); p.drawPoint(r.x(), r.y()); p.drawPoint(r.right(), r.y()); p.drawLine(r.right()+1, r.y(), r.right()+1, r.bottom()); } }
void LocationCompleterDelegate::paint(QPainter* painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { QStyleOptionViewItemV4 opt = option; initStyleOption(&opt, index); const QWidget* w = opt.widget; const QStyle* style = w ? w->style() : QApplication::style(); const int height = opt.rect.height(); const int center = height / 2 + opt.rect.top(); // Prepare title font QFont titleFont = opt.font; titleFont.setPointSize(titleFont.pointSize() + 1); const QFontMetrics titleMetrics(titleFont); int leftPosition = m_padding * 2; int rightPosition = opt.rect.right() - m_padding; opt.state &= ~QStyle::State_MouseOver; if (m_view->hoveredIndex() == index) { opt.state |= QStyle::State_Selected; } else { opt.state &= ~QStyle::State_Selected; } #ifdef Q_OS_WIN const QPalette::ColorRole colorRole = QPalette::Text; const QPalette::ColorRole colorLinkRole = QPalette::Link; #else const QPalette::ColorRole colorRole = opt.state & QStyle::State_Selected ? QPalette::HighlightedText : QPalette::Text; const QPalette::ColorRole colorLinkRole = opt.state & QStyle::State_Selected ? QPalette::HighlightedText : QPalette::Link; #endif // Draw background style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, w); // Draw icon const int iconSize = 16; const int iconYPos = center - (iconSize / 2); QRect iconRect(leftPosition, iconYPos, iconSize, iconSize); QPixmap pixmap = index.data(Qt::DecorationRole).value<QIcon>().pixmap(iconSize); painter->drawPixmap(iconRect, pixmap); leftPosition = iconRect.right() + m_padding * 2; // Draw star to bookmark items int starPixmapWidth = 0; if (index.data(LocationCompleterModel::BookmarkRole).toBool()) { const QPixmap starPixmap = qIconProvider->bookmarkIcon(); QSize starSize = starPixmap.size(); //new starPixmapWidth = starSize.width(); QPoint pos(rightPosition - starPixmapWidth, opt.rect.top() + m_padding); QRect starRect(pos, starSize); painter->drawPixmap(starRect, starPixmap); } const QString &searchText = index.data(LocationCompleterModel::SearchStringRole).toString(); // Draw title const int leftTitleEdge = leftPosition + 2; // RTL Support: remove conflicting of right-aligned text and starpixmap! const int rightTitleEdge = rightPosition - m_padding - starPixmapWidth; QRect titleRect(leftTitleEdge, opt.rect.top() + m_padding, rightTitleEdge - leftTitleEdge, titleMetrics.height()); QString title(titleMetrics.elidedText(index.data(LocationCompleterModel::TitleRole).toString(), Qt::ElideRight, titleRect.width())); painter->setFont(titleFont); drawHighlightedTextLine(titleRect, title, searchText, painter, style, opt, colorRole); // Draw link const int infoYPos = titleRect.bottom() + opt.fontMetrics.leading() + 2; QRect linkRect(titleRect.x(), infoYPos, titleRect.width(), opt.fontMetrics.height()); QString link(opt.fontMetrics.elidedText(index.data(Qt::DisplayRole).toString(), Qt::ElideRight, linkRect.width())); painter->setFont(opt.font); TabPosition pos = index.data(LocationCompleterModel::TabPositionRole).value<TabPosition>(); if (m_drawSwitchToTab && pos.windowIndex != -1) { const QIcon tabIcon = QIcon(":icons/menu/tab.png"); QRect iconRect(linkRect); iconRect.setWidth(m_padding + 16 + m_padding); tabIcon.paint(painter, iconRect); QRect textRect(linkRect); textRect.setX(textRect.x() + m_padding + 16 + m_padding); drawTextLine(textRect, LocationCompleterView::tr("Switch to tab"), painter, style, opt, colorLinkRole); } else { drawHighlightedTextLine(linkRect, link, searchText, painter, style, opt, colorLinkRole); } // Draw line at the very bottom of item if the item is not highlighted if (!(opt.state & QStyle::State_Selected)) { QRect lineRect(opt.rect.left(), opt.rect.bottom(), opt.rect.width(), 1); painter->fillRect(lineRect, opt.palette.color(QPalette::AlternateBase)); } }
/* Draws the about screen and remembers some state for hyperlinking. It transcribes the design I did in graphics software - hopeless to understand without seeing the design. */ static void DrawAbout(HWND hwnd, HDC hdc, RectI rect, Vec<StaticLinkInfo>& linkInfo) { HPEN penBorder = CreatePen(PS_SOLID, ABOUT_LINE_OUTER_SIZE, WIN_COL_BLACK); HPEN penDivideLine = CreatePen(PS_SOLID, ABOUT_LINE_SEP_SIZE, WIN_COL_BLACK); HPEN penLinkLine = CreatePen(PS_SOLID, ABOUT_LINE_SEP_SIZE, COL_BLUE_LINK); ScopedFont fontLeftTxt(GetSimpleFont(hdc, LEFT_TXT_FONT, LEFT_TXT_FONT_SIZE)); ScopedFont fontRightTxt(GetSimpleFont(hdc, RIGHT_TXT_FONT, RIGHT_TXT_FONT_SIZE)); HGDIOBJ origFont = SelectObject(hdc, fontLeftTxt); /* Just to remember the orig font */ ClientRect rc(hwnd); FillRect(hdc, &rc.ToRECT(), gBrushAboutBg); /* render title */ RectI titleRect(rect.TL(), CalcSumatraVersionSize(hdc)); SelectObject(hdc, gBrushLogoBg); SelectObject(hdc, penBorder); #ifndef ABOUT_USE_LESS_COLORS Rectangle(hdc, rect.x, rect.y + ABOUT_LINE_OUTER_SIZE, rect.x + rect.dx, rect.y + titleRect.dy + ABOUT_LINE_OUTER_SIZE); #else RectI titleBgBand(0, rect.y, rc.dx, titleRect.dy); FillRect(hdc, &titleBgBand.ToRECT(), gBrushLogoBg); PaintLine(hdc, RectI(0, rect.y, rc.dx, 0)); PaintLine(hdc, RectI(0, rect.y + titleRect.dy, rc.dx, 0)); #endif titleRect.Offset((rect.dx - titleRect.dx) / 2, 0); DrawSumatraVersion(hdc, titleRect); /* render attribution box */ SetTextColor(hdc, ABOUT_BORDER_COL); SetBkMode(hdc, TRANSPARENT); #ifndef ABOUT_USE_LESS_COLORS Rectangle(hdc, rect.x, rect.y + titleRect.dy, rect.x + rect.dx, rect.y + rect.dy); #endif /* render text on the left*/ SelectObject(hdc, fontLeftTxt); for (AboutLayoutInfoEl *el = gAboutLayoutInfo; el->leftTxt; el++) { TextOut(hdc, el->leftPos.x, el->leftPos.y, el->leftTxt, (int)str::Len(el->leftTxt)); } /* render text on the right */ SelectObject(hdc, fontRightTxt); SelectObject(hdc, penLinkLine); linkInfo.Reset(); for (AboutLayoutInfoEl *el = gAboutLayoutInfo; el->leftTxt; el++) { bool hasUrl = HasPermission(Perm_DiskAccess) && el->url; SetTextColor(hdc, hasUrl ? COL_BLUE_LINK : ABOUT_BORDER_COL); TextOut(hdc, el->rightPos.x, el->rightPos.y, el->rightTxt, (int)str::Len(el->rightTxt)); if (hasUrl) { int underlineY = el->rightPos.y + el->rightPos.dy - 3; PaintLine(hdc, RectI(el->rightPos.x, underlineY, el->rightPos.dx, 0)); linkInfo.Append(StaticLinkInfo(el->rightPos, el->url, el->url)); } } SelectObject(hdc, penDivideLine); RectI divideLine(gAboutLayoutInfo[0].rightPos.x - ABOUT_LEFT_RIGHT_SPACE_DX, rect.y + titleRect.dy + 4, 0, rect.y + rect.dy - 4 - gAboutLayoutInfo[0].rightPos.y); PaintLine(hdc, divideLine); SelectObject(hdc, origFont); DeleteObject(penBorder); DeleteObject(penDivideLine); DeleteObject(penLinkLine); }