////////////////// // Draw tab in normal or highlighted state // int CFolderTab::Draw(CDC& dc, CFont& font, BOOL bSelected) { COLORREF bgColor = GetSysColor(bSelected ? COLOR_WINDOW : COLOR_3DFACE); CBrush brush(bgColor); // background brush dc.SetBkColor(bgColor); // text background dc.SetTextColor(m_colour); // text color = fg color CPen blackPen(PS_SOLID, 1, RGB(0,0,0)); // black CPen shadowPen(PS_SOLID, 1, GetSysColor(COLOR_3DSHADOW)); // Fill trapezoid CPoint pts[4]; CRect rc = m_rect; GetTrapezoid(rc, pts); CPen* pOldPen = dc.SelectObject(&blackPen); dc.FillRgn(&m_rgn, &brush); // Draw edges. This is requires two corrections: // 1) Trapezoid dimensions don't include the right and bottom edges, // so must use one pixel less on bottom (cybottom) // 2) the endpoint of LineTo is not included when drawing the line, so // must add one pixel (cytop) // pts[1].y--; // correction #1: true bottom edge y-coord pts[2].y--; // ...ditto pts[3].y--; // correction #2: extend final LineTo dc.MoveTo(pts[0]); // upper left dc.LineTo(pts[1]); // bottom left dc.SelectObject(&shadowPen); // bottom line is shadow color dc.MoveTo(pts[1]); // line is inside trapezoid bottom dc.LineTo(pts[2]); // ... dc.SelectObject(&blackPen); // upstroke is black dc.LineTo(pts[3]); // y-1 to include endpoint if (!bSelected) { // if not highlighted, upstroke has a 3D shadow, one pixel inside pts[2].x--; // offset left one pixel pts[3].x--; // ...ditto dc.SelectObject(&shadowPen); dc.MoveTo(pts[2]); dc.LineTo(pts[3]); } dc.SelectObject(pOldPen); // draw text rc.DeflateRect(CXOFFSET + CXMARGIN, CYMARGIN); CFont* pOldFont = dc.SelectObject(&font); dc.DrawText(m_sText, &rc, DT_CENTER|DT_VCENTER|DT_SINGLELINE); dc.SelectObject(pOldFont); return m_rect.right; }
void PlexyDayWidget::drawBox(QPainter *painter, QLinearGradient titleCornerGrad, const QRectF &rect, QRectF titleCornerRect) { painter->fillRect(titleCornerRect, titleCornerGrad); PlexyDesk::StyleFeatures feature; feature.exposeRect = titleCornerRect; feature.state = PlexyDesk::StyleFeatures::SF_FrontView; QPen pen(QColor(88, 88, 88), 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); QPen shadowPen(QColor(255, 255, 255), 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); #ifdef Q_WS_QPA QFont font = QFont("Georgia", 10); #else QFont font = QFont("Georgia", 34); #endif painter->setFont(font); painter->setPen(shadowPen); painter->drawText(titleCornerRect.adjusted(1, 1, 1, 1), Qt::AlignVCenter | Qt::AlignHCenter, "Your Day, Simplified!"); painter->setOpacity(0.9); painter->setPen(pen); painter->drawText(titleCornerRect, Qt::AlignVCenter | Qt::AlignHCenter, "Your Day, Simplified!"); // QPen pen2(QColor(244, 242, 246), 1, Qt::SolidLine, Qt::RoundCap, // Qt::RoundJoin); // painter->setPen(pen2); // QRectF titleHeaderRect = QRect(titleCornerRect.width(), 3.0, (rect.width() // - titleCornerRect.width()), titleCornerRect.height()); // painter->fillRect(titleHeaderRect, titleCornerGrad); // painter->drawRect(titleCornerRect); // QPen pen3(QColor(0, 255, 0), 1, Qt::SolidLine, Qt::RoundCap, // Qt::RoundJoin); // painter->setPen(pen3); // painter->drawLine(QPointF(titleCornerRect.x(), titleCornerRect.height() - // 1), QPointF(titleCornerRect.width(), titleCornerRect.height() -1)); }
void GcBubble::paintEvent(QPaintEvent *) { // Init paint settings QPainter painter(this); // outline border, adjust to offset, for now we outline painter.setBrush(Qt::NoBrush); QColor shadow = QColor(0,0,0,alpha); QPen shadowPen(shadow); shadowPen.setWidth(lineWidth); painter.setPen(shadowPen); painter.translate(0,1); painter.drawPath(path); // now draw for real painter.translate(0,-1); // adjust to offset, for now we outline // contents fill with a linear gradient QLinearGradient linearGradient(0, 0, 0, height()); linearGradient.setColorAt(0.0, QColor(80,80,80, alpha)); linearGradient.setColorAt(1.0, QColor(0, 0, 0, alpha)); linearGradient.setSpread(QGradient::PadSpread); painter.setBrush(linearGradient); // border gray and opaque QColor borderColor = QColor(150,150,150); QPen border = QPen(borderColor); border.setWidth(lineWidth); painter.setPen(border); // draw the background painter.drawPath(path); #if 0 // debugging painter.setBrush(Qt::NoBrush); painter.setPen(Qt::red); painter.drawRect(1,1,width()-2, height()-2); painter.setPen(Qt::blue); painter.drawRect(display->geometry()); #endif }
void Canvas::setSceneRect(qreal x, qreal y, qreal w, qreal h) { currentScene->setSceneRect(x, y, w, h); qreal borderWidth = 0.5; QPen borderPen(QBrush(Qt::black), borderWidth); borderPen.setCapStyle(Qt::SquareCap); borderPen.setJoinStyle(Qt::MiterJoin); qreal shadowWidth = 5; QPen shadowPen(QBrush(Qt::lightGray), shadowWidth); shadowPen.setCapStyle(Qt::SquareCap); shadowPen.setJoinStyle(Qt::MiterJoin); QGraphicsItemGroup * group = new QGraphicsItemGroup; QGraphicsLineItem * shadowRight = new QGraphicsLineItem(x + w + (shadowWidth - borderWidth) / 2, y + shadowWidth, x + w + (shadowWidth - borderWidth) / 2, y + h + shadowWidth / 2); shadowRight->setPen(shadowPen); QGraphicsLineItem * shadowBottom = new QGraphicsLineItem(x + shadowWidth, y + h + (shadowWidth - borderWidth) / 2, x + w + shadowWidth / 2, y + h + (shadowWidth - borderWidth) / 2); shadowBottom->setPen(shadowPen); QGraphicsRectItem * rect = new QGraphicsRectItem(x, y, w, h); rect->setPen(borderPen); group->addToGroup(shadowRight); group->addToGroup(shadowBottom); group->addToGroup(rect); currentScene->addItem(group); }
void AlbumItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const { AlbumItem* item = m_model->sourceModel()->itemFromIndex( m_model->mapToSource( index ) ); if ( !item ) return; QStyleOptionViewItemV4 opt = option; initStyleOption( &opt, QModelIndex() ); qApp->style()->drawControl( QStyle::CE_ItemViewItem, &opt, painter ); painter->save(); painter->setRenderHint( QPainter::Antialiasing ); if ( !( option.state & QStyle::State_Selected ) ) { QRect shadowRect = option.rect.adjusted( 5, 4, -5, -40 ); painter->setPen( QColor( 90, 90, 90 ) ); painter->drawRoundedRect( shadowRect, 0.5, 0.5 ); QPen shadowPen( QColor( 30, 30, 30 ) ); shadowPen.setWidth( 0.4 ); painter->drawLine( shadowRect.bottomLeft() + QPoint( -1, 2 ), shadowRect.bottomRight() + QPoint( 1, 2 ) ); shadowPen.setColor( QColor( 160, 160, 160 ) ); painter->setPen( shadowPen ); painter->drawLine( shadowRect.topLeft() + QPoint( -1, 2 ), shadowRect.bottomLeft() + QPoint( -1, 2 ) ); painter->drawLine( shadowRect.topRight() + QPoint( 2, 2 ), shadowRect.bottomRight() + QPoint( 2, 2 ) ); painter->drawLine( shadowRect.bottomLeft() + QPoint( 0, 3 ), shadowRect.bottomRight() + QPoint( 0, 3 ) ); shadowPen.setColor( QColor( 180, 180, 180 ) ); painter->setPen( shadowPen ); painter->drawLine( shadowRect.topLeft() + QPoint( -2, 3 ), shadowRect.bottomLeft() + QPoint( -2, 1 ) ); painter->drawLine( shadowRect.topRight() + QPoint( 3, 3 ), shadowRect.bottomRight() + QPoint( 3, 1 ) ); painter->drawLine( shadowRect.bottomLeft() + QPoint( 0, 4 ), shadowRect.bottomRight() + QPoint( 0, 4 ) ); } QPixmap cover; if ( !item->album().isNull() ) { cover.loadFromData( item->album()->cover() ); } else if ( !item->artist().isNull() ) { cover.loadFromData( item->artist()->cover() ); } if ( cover.isNull() ) cover = m_defaultCover; QRect r = option.rect.adjusted( 6, 5, -6, -41 ); if ( option.state & QStyle::State_Selected ) { #if defined(Q_WS_MAC) || defined(Q_WS_WIN) painter->save(); painter->setRenderHint( QPainter::Antialiasing ); QPainterPath border; border.addRoundedRect( r.adjusted( -2, -2, 2, 2 ), 3, 3 ); QPen borderPen( QColor( 86, 170, 243 ) ); borderPen.setWidth( 5 ); painter->setPen( borderPen ); painter->drawPath( border ); painter->restore(); #else opt.palette.setColor( QPalette::Text, opt.palette.color( QPalette::HighlightedText ) ); #endif } QPixmap scover; if ( m_cache.contains( cover.cacheKey() ) ) { scover = m_cache.value( cover.cacheKey() ); } else { scover = cover.scaled( r.size(), Qt::KeepAspectRatio, Qt::SmoothTransformation ); m_cache.insert( cover.cacheKey(), scover ); } painter->drawPixmap( r, scover ); painter->setPen( opt.palette.color( QPalette::Text ) ); QTextOption to; to.setWrapMode( QTextOption::NoWrap ); QString text; QFont font = opt.font; font.setPixelSize( 11 ); QFont boldFont = font; boldFont.setBold( true ); QRect textRect = option.rect.adjusted( 0, option.rect.height() - 32, 0, -2 ); QString name; if ( !item->album().isNull() ) name = item->album()->name(); else if ( !item->artist().isNull() ) name = item->artist()->name(); painter->setFont( boldFont ); bool oneLiner = false; if ( item->album().isNull() || item->album()->artist().isNull() ) oneLiner = true; else oneLiner = ( textRect.height() / 2 < painter->fontMetrics().boundingRect( item->album()->name() ).height() || textRect.height() / 2 < painter->fontMetrics().boundingRect( item->album()->artist()->name() ).height() ); if ( oneLiner ) { to.setAlignment( Qt::AlignHCenter | Qt::AlignVCenter ); text = painter->fontMetrics().elidedText( name, Qt::ElideRight, textRect.width() - 3 ); painter->drawText( textRect, text, to ); } else { to.setAlignment( Qt::AlignHCenter | Qt::AlignTop ); text = painter->fontMetrics().elidedText( item->album()->name(), Qt::ElideRight, textRect.width() - 3 ); painter->drawText( textRect, text, to ); // If the user is hovering over an artist rect, draw a background so she knows it's clickable QRect r = textRect; r.setTop( r.bottom() - painter->fontMetrics().height() ); r.adjust( 4, 0, -4, -1 ); if ( m_hoveringOver == index ) { TomahawkUtils::drawQueryBackground( painter, opt.palette, r, 1.1 ); painter->setPen( opt.palette.color( QPalette::HighlightedText ) ); } else { if ( !( option.state & QStyle::State_Selected ) ) #ifdef Q_WS_MAC painter->setPen( opt.palette.color( QPalette::Dark ).darker( 200 ) ); #else painter->setPen( opt.palette.color( QPalette::Dark ) ); #endif } to.setAlignment( Qt::AlignHCenter | Qt::AlignBottom ); text = painter->fontMetrics().elidedText( item->album()->artist()->name(), Qt::ElideRight, textRect.width() - 10 ); painter->drawText( textRect.adjusted( 5, -1, -5, -1 ), text, to ); // Calculate rect of artist on-hover button click area m_artistNameRects[ index ] = r; } painter->restore(); }
void MeasureToolPlugin::drawSegments( GeoPainter* painter ) { for ( int segmentIndex = 0; segmentIndex < m_measureLineString.size() - 1; ++segmentIndex ) { GeoDataLineString segment( Tessellate ); segment << m_measureLineString[segmentIndex] ; segment << m_measureLineString[segmentIndex + 1]; QPen shadowPen( Oxygen::aluminumGray5 ); shadowPen.setWidthF(4.0); painter->setPen( shadowPen ); painter->drawPolyline( segment ); QString infoString; if ( (m_paintMode == Polygon && m_showDistanceLabel) || (m_paintMode == Circular && m_showRadius) ) { const qreal segmentLength = segment.length( marbleModel()->planet()->radius() ); m_radius = segmentLength; infoString = meterToPreferredUnit(segmentLength); } if ( m_showBearingLabel && m_paintMode != Circular ) { GeoDataCoordinates coordinates = segment.first(); qreal bearing = coordinates.bearing( segment.last(), GeoDataCoordinates::Degree ); if ( bearing < 0 ) { bearing += 360; } QString bearingString = QString::fromUtf8( "%1°" ).arg( bearing, 0, 'f', 2 ); if ( !infoString.isEmpty() ) { infoString.append( "\n" ); } infoString.append( bearingString ); } if ( m_showBearingChangeLabel && segmentIndex != 0 ) { GeoDataCoordinates currentCoordinates = m_measureLineString[segmentIndex]; qreal currentBearing = currentCoordinates.bearing(m_measureLineString[segmentIndex+1]); qreal previousBearing = currentCoordinates.bearing( m_measureLineString[segmentIndex-1]); GeoDataLinearRing ring; painter->setPen( Qt::NoPen ); painter->setBrush( QBrush ( QColor ( 127, 127, 127, 127 ) ) ); if (currentBearing < previousBearing) currentBearing += 2 * M_PI; ring << currentCoordinates; qreal angleLength = qAbs(m_latLonAltBox.north() - m_latLonAltBox.south()) / 20; qreal iterBearing = previousBearing; while ( iterBearing < currentBearing ) { ring << currentCoordinates.moveByBearing( iterBearing, angleLength );; iterBearing += 0.1; } ring << currentCoordinates.moveByBearing( currentBearing, angleLength );; painter->drawPolygon( ring ); qreal currentBearingChange = (currentBearing - previousBearing) * RAD2DEG; if (currentBearingChange < 0) currentBearingChange += 360; QString bearingChangedString = QString::fromUtf8( "%1°" ).arg( currentBearingChange, 0, 'f', 2 ); painter->setPen( Qt::black ); GeoDataCoordinates textPosition = ring.latLonAltBox().center(); qreal deltaEast = ring.latLonAltBox().east() - currentCoordinates.longitude(); qreal deltaWest = currentCoordinates.longitude() - ring.latLonAltBox().west(); if (deltaEast > deltaWest) { textPosition.setLongitude(currentCoordinates.longitude() + deltaEast / 2); } else { textPosition.setLongitude(currentCoordinates.longitude() - deltaWest); } painter->drawText(textPosition, bearingChangedString ); } // Drawing ellipse around 1st point towards the 2nd if ( m_paintMode == Circular ) { GeoDataCoordinates currentCoordinates = m_measureLineString[segmentIndex]; GeoDataLinearRing ring; // planetRadius - planet radius // d - distance between points // S - area of the painted circle qreal planetRadius = marbleModel()->planet()->radius(); qreal d = m_measureLineString.length(1); m_circularArea = 2 * M_PI * planetRadius * planetRadius * (1 - qCos(d)); qreal iterBearing = 0; while ( iterBearing < 2 * M_PI ) { ring << currentCoordinates.moveByBearing(iterBearing, d); iterBearing += 0.1; } painter->setPen( Qt::NoPen ); painter->setBrush( QBrush ( QColor ( 127, 127, 127, 127 ) ) ); painter->drawPolygon(ring); if ( m_showCircularArea ) { painter->setPen(Qt::white); GeoDataCoordinates textPosition = ring.latLonAltBox().center(); QString areaText = tr("Area:\n%1").arg(meterToPreferredUnit(m_circularArea, true)); QFontMetrics fontMetrics = painter->fontMetrics(); QRect boundingRect = fontMetrics.boundingRect(QRect(), Qt::AlignCenter, areaText); painter->drawText(textPosition, areaText, -boundingRect.width()/2, -boundingRect.height()*1.5, boundingRect.width(), boundingRect.height(), QTextOption(Qt::AlignCenter)); } if ( m_showCircumference ) { painter->setPen(Qt::white); GeoDataCoordinates textPosition = ring.latLonAltBox().center(); m_circumference = 2 * M_PI * planetRadius * qSin(d); QString circumferenceText = tr("Circumference:\n%1").arg(meterToPreferredUnit(m_circumference)); QFontMetrics fontMetrics = painter->fontMetrics(); QRect boundingRect = fontMetrics.boundingRect(QRect(),Qt::AlignCenter, circumferenceText); painter->drawText(textPosition, circumferenceText, -boundingRect.width()/2, boundingRect.height(), boundingRect.width(), boundingRect.height(), QTextOption(Qt::AlignCenter)); } } if ( !infoString.isEmpty() ) { QPen linePen; // have three alternating colors for the segments switch ( segmentIndex % 3 ) { case 0: linePen.setColor( Oxygen::brickRed4 ); break; case 1: linePen.setColor( Oxygen::forestGreen4 ); break; case 2: linePen.setColor( Oxygen::skyBlue4 ); break; } linePen.setWidthF(2.0); painter->setPen( linePen ); painter->drawPolyline( segment, infoString, LineCenter ); } } if (m_paintMode == Polygon && m_measureLineString.size() > 2) { GeoDataLinearRing measureRing = m_measureLineString; if (m_showPolygonArea || m_showPerimeter) { painter->setPen( Qt::NoPen ); painter->setBrush( QBrush ( QColor ( 127, 127, 127, 127 ) ) ); painter->drawPolygon(measureRing); QPen shadowPen( Oxygen::aluminumGray5 ); shadowPen.setStyle(Qt::DashLine); shadowPen.setWidthF(3.0); painter->setPen( shadowPen ); painter->drawPolyline(GeoDataLineString( Tessellate ) << m_measureLineString.first() << m_measureLineString.last()); } if (m_showPolygonArea) { qreal theta1 = 0.0; qreal n = m_measureLineString.size(); for (int segmentIndex = 1; segmentIndex < m_measureLineString.size()-1; segmentIndex++) { GeoDataCoordinates current = m_measureLineString[segmentIndex]; qreal prevBearing = current.bearing(m_measureLineString[segmentIndex-1]); qreal nextBearing = current.bearing(m_measureLineString[segmentIndex+1]); if (nextBearing < prevBearing) nextBearing += 2 * M_PI; qreal angle = nextBearing - prevBearing; theta1 += angle; } // Traversing first vertex GeoDataCoordinates current = m_measureLineString[0]; qreal prevBearing = current.bearing(m_measureLineString[n-1]); qreal nextBearing = current.bearing(m_measureLineString[1]); if (nextBearing < prevBearing) nextBearing += 2 * M_PI; qreal angle = nextBearing - prevBearing; theta1 += angle; // And the last one current = m_measureLineString[n-1]; prevBearing = current.bearing(m_measureLineString[n-2]); nextBearing = current.bearing(m_measureLineString[0]); if (nextBearing < prevBearing) nextBearing += 2 * M_PI; angle = nextBearing - prevBearing; theta1 += angle; qreal theta2 = 2 * M_PI * n - theta1; // theta = smaller of theta1 and theta2 qreal theta = (theta1 < theta2) ? theta1 : theta2; qreal planetRadius = marbleModel()->planet()->radius(); qreal S = qAbs((theta - (n-2) * M_PI) * planetRadius * planetRadius); m_polygonArea = S; painter->setPen(Qt::white); GeoDataCoordinates textPosition = measureRing.latLonAltBox().center(); QString areaText = tr("Area:\n%1").arg(meterToPreferredUnit(S, true)); QFontMetrics fontMetrics = painter->fontMetrics(); QRect boundingRect = fontMetrics.boundingRect(QRect(), Qt::AlignCenter, areaText); painter->drawText(textPosition, areaText, -boundingRect.width()/2, -(boundingRect.height()+fontMetrics.height()*0.25), boundingRect.width(), boundingRect.height(), QTextOption(Qt::AlignCenter)); } if (m_showPerimeter) { painter->setPen(Qt::white); GeoDataCoordinates textPosition = measureRing.latLonAltBox().center(); qreal P = measureRing.length(marbleModel()->planet()->radius()); m_perimeter = P; QString perimeterText = tr("Perimeter:\n%1").arg(meterToPreferredUnit(P)); QFontMetrics fontMetrics = painter->fontMetrics(); QRect boundingRect = fontMetrics.boundingRect(QRect(),Qt::AlignCenter, perimeterText); painter->drawText(textPosition, perimeterText, -boundingRect.width()/2, 0, boundingRect.width(), boundingRect.height(), QTextOption(Qt::AlignCenter)); } } }
void FlatButton::DrawItem(LPDRAWITEMSTRUCT dis) { CDC* dcPaint = CDC::FromHandle(dis->hDC); CRect rectPaint(dis->rcItem); bool disabled = (dis->itemState & ODS_DISABLED) != 0; // Create a bitmap to paint into CDC dc; dc.CreateCompatibleDC(dcPaint); CRect rect(0,0,rectPaint.Width(),rectPaint.Height()); CDibSection bitmap; if (bitmap.CreateBitmap(dc.GetSafeHdc(),rect.Width(),rect.Height()) == FALSE) return; CBitmap* oldBitmap = CDibSection::SelectDibSection(dc,&bitmap); // Draw the background if (dis->itemState & ODS_SELECTED) { // Get the bitmap to indicate a selected button CBitmap selectBitmap; selectBitmap.LoadBitmap(IDR_FLAT_SELECT); CDC selectDC; selectDC.CreateCompatibleDC(&dc); CBitmap* oldBitmap = selectDC.SelectObject(&selectBitmap); // Get the bitmap's dimensions BITMAP bitmapInfo; selectBitmap.GetBitmap(&bitmapInfo); // Stretch the bitmap into the selected item's background dc.StretchBlt(0,0,rect.Width(),rect.Height(), &selectDC,0,0,bitmapInfo.bmWidth,bitmapInfo.bmHeight,SRCCOPY); selectDC.SelectObject(oldBitmap); } else dc.FillSolidRect(rect,::GetSysColor(COLOR_BTNFACE)); // Get the button's text CString text; GetWindowText(text); // Draw the contents of the button if (text == "?<") { CRect imageRect(rect); if (imageRect.Width() > imageRect.Height()) imageRect.DeflateRect((imageRect.Width() - imageRect.Height())/2,0); int gap = imageRect.Height()/6; imageRect.DeflateRect(gap,gap); CDibSection* dib = GetImage("Arrow-left",imageRect.Size(),disabled); bitmap.AlphaBlend(dib,gap,gap,FALSE); } else if (text == "?>") { CRect imageRect(rect); if (imageRect.Width() > imageRect.Height()) imageRect.DeflateRect((imageRect.Width() - imageRect.Height())/2,0); int gap = imageRect.Height()/6; imageRect.DeflateRect(gap,gap); CDibSection* dib = GetImage("Arrow-right",imageRect.Size(),disabled); bitmap.AlphaBlend(dib,gap,gap,FALSE); } // Draw the separator CPen shadowPen(PS_SOLID,0,::GetSysColor(COLOR_BTNSHADOW)); dc.SelectObject(shadowPen); int gap = rect.Height()/6; dc.MoveTo(rect.right-1,gap); dc.LineTo(rect.right-1,rect.bottom-gap); // Draw the control from the bitmap dcPaint->BitBlt(rectPaint.left,rectPaint.top,rectPaint.Width(),rectPaint.Height(),&dc,0,0,SRCCOPY); dc.SelectObject(oldBitmap); }