Пример #1
0
  void Interface::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
  {
    // draw a gradient background
    QLinearGradient gradient(0, 0, 0, boundingRect().height());
    if(m_drawHover)
    {
      gradient.setColorAt(0, color().lighter(110));
    }
    else
    {
      gradient.setColorAt(0, color());
    }
    int penWidth;
    if(m_selected)
    {
      penWidth = SELECTED_PEN_WIDTH;
      painter->setPen(QPen(QBrush(Qt::SolidPattern), penWidth));
    }
    else
    {
      penWidth = BORDER_PEN_WIDTH;
      painter->setPen(QPen(QBrush(Qt::SolidPattern), penWidth));
    }
    gradient.setColorAt(1, Qt::white);
    QBrush gradientBrush(gradient);
    painter->setBrush(gradientBrush);
    QRect drawingRect(boundingRect().x() + penWidth / 2, boundingRect().y() + penWidth / 2, boundingRect().width() - penWidth, boundingRect().height() - penWidth);
    painter->drawRoundedRect(drawingRect, 5, 5);

    // draw the name
    // FIXME: figure out how to make the font hinting look optimal
    painter->setPen(QPen());
    painter->setFont(*m_font);
    painter->drawText(drawingRect, Qt::AlignCenter, name());
  }
Пример #2
0
void Clock::paintInterface(QPainter *p, const QStyleOptionGraphicsItem *option, const QRect &contentsRect)
{
    Q_UNUSED(option);

    if (!m_time.isValid() || !m_date.isValid()) {
        return;
    }

    p->setPen(QPen(m_plainClockColor));
    p->setRenderHint(QPainter::SmoothPixmapTransform);
    p->setRenderHint(QPainter::Antialiasing);

    /* ... helps debugging contentsRect and sizing ...
       QColor c = QColor(Qt::blue);
       c.setAlphaF(.5);
       p->setBrush(c);
       p->drawRect(contentsRect);
     */

    // Paint the date, conditionally, and let us know afterwards how much
    // space is left for painting the time on top of it.
    QRectF dateRect;
    const QString timeString = KGlobal::locale()->formatTime(m_time, m_showSeconds);
    const QString fakeTimeString = KGlobal::locale()->formatTime(QTime(23,59,59), m_showSeconds);
    QFont smallFont = KGlobalSettings::smallestReadableFont();

    //create the string for the date and/or the timezone
    if (m_dateStyle || showTimezone()) {
        QString dateString;

        //Create the localized date string if needed
        if (m_dateStyle) {
            // JPL This needs a complete rewrite for l10n issues
            QString day = KGlobal::locale()->calendar()->formatDate(m_date, KLocale::Day, KLocale::ShortNumber);
            QString month = KGlobal::locale()->calendar()->formatDate(m_date, KLocale::Month, KLocale::LongNumber);

            if (m_dateStyle == 1) {         //compact date
                dateString = i18nc("@label Compact date: "
                        "%1 day in the month, %2 month number",
                        "%1/%2", day, month);
            } else if (m_dateStyle == 2) {    //short date
                dateString = KGlobal::locale()->formatDate(m_date, KLocale::ShortDate);
            } else if (m_dateStyle == 3) {    //long date
                dateString = KGlobal::locale()->formatDate(m_date, KLocale::LongDate);
            } else if (m_dateStyle == 4) {    //ISO date
                dateString = KGlobal::locale()->formatDate(m_date, KLocale::IsoDate);
            } else {                          //shouldn't happen
                dateString = KGlobal::locale()->formatDate(m_date, KLocale::ShortDate);
            }

            if (showTimezone()) {
                QString currentTimezone = prettyTimezone();
                dateString = i18nc("@label Date with currentTimezone: "
                        "%1 day of the week with date, %2 currentTimezone",
                        "%1 %2", dateString, currentTimezone);
            }
        } else if (showTimezone()) {
            dateString = prettyTimezone();
        }

        dateString = dateString.trimmed();

        if (m_dateString != dateString) {
            // If this string has changed (for example due to changes in the config
            // we have to reset the sizing of the applet
            m_dateString = dateString;
            updateSize();
        }

        // Check sizes
        // magic 10 is for very big spaces,
        // where there's enough space to grow without harming time space
        QFontMetrics fm(smallFont);

        if (contentsRect.height() > contentsRect.width() * 2) {
            //kDebug() << Plasma::Vertical << contentsRect.height() <<contentsRect.width() * 2;
            QRect dateRect = contentsRect;
            dateRect.setHeight(dateRect.width());
            smallFont.setPixelSize(qMax(dateRect.height() / 2, fm.ascent()));
            m_dateRect = preparePainter(p, dateRect, smallFont, dateString);
        } else {
            // Find a suitable size for the date font
            if (formFactor() == Plasma::Vertical) {
                smallFont.setPixelSize(qMax(contentsRect.height()/6, fm.ascent()));
            } else if (formFactor() == Plasma::Horizontal) {
                smallFont.setPixelSize(qMax(qMin(contentsRect.height(), contentsRect.width())*2/7, fm.ascent()));

                //we want to write the date always on one line
                fm = QFontMetrics(smallFont);
                const int tempWidth = fm.width(dateString);
                if(tempWidth > contentsRect.width()){
                    smallFont.setPixelSize((contentsRect.width() * smallFont.pixelSize())/tempWidth);
                }

            } else {
                smallFont.setPixelSize(qMax(qMin(contentsRect.height(), contentsRect.width())/8, KGlobalSettings::smallestReadableFont().pointSize()));
            }

            m_dateRect = preparePainter(p, contentsRect, smallFont, dateString);
        }

        // kDebug(96669) << "m_dateRect: " << m_dateRect;

        const int subtitleHeight = m_dateRect.height();
        const int subtitleWidth = m_dateRect.width();
        // kDebug(96669) << "subtitleWitdh: " << subtitleWitdh;
        // kDebug(96669) << "subtitleHeight: " << subtitleHeight;

        if (m_dateTimezoneBesides) {
            //kDebug(96669) << contentsRect.height() << subtitleHeight << smallFont.pixelSize();
            if (contentsRect.height() - subtitleHeight >= smallFont.pixelSize() || formFactor() != Plasma::Horizontal) {
                // to small to display the time on top of the date/timezone
                // put them side by side
                // kDebug(96669) << "switching to normal";
                m_dateTimezoneBesides = false;
                dateRect = normalLayout(subtitleWidth, subtitleHeight, contentsRect);
            } else {
                dateRect = sideBySideLayout(subtitleWidth, subtitleHeight, contentsRect);
            }
        } else {
            /* kDebug(96669) << "checking timezone placement"
                          << contentsRect.height() << dateRect.height() << subtitleHeight
                          << smallFont.pixelSize() << smallFont.pointSize();*/
            if (contentsRect.height() - subtitleHeight < smallFont.pixelSize() && formFactor() == Plasma::Horizontal) {
                // to small to display the time on top of the date/timezone
                // put them side by side
                // kDebug(96669) << "switching to s-b-s";
                m_dateTimezoneBesides = true;
                dateRect = sideBySideLayout(subtitleWidth, subtitleHeight, contentsRect);
            } else {
                dateRect = normalLayout(subtitleWidth, subtitleHeight, contentsRect);
            }
        }
    } else {
        m_timeRect = contentsRect;
    }
    // kDebug(96669) << "timeRect: " << m_timeRect;
    // p->fillRect(timeRect, QBrush(QColor("red")));

    // kDebug(96669) << m_time;
    // Choose a relatively big font size to start with
    m_plainClockFont.setPointSizeF(qMax(m_timeRect.height(), KGlobalSettings::smallestReadableFont().pointSize()));
    preparePainter(p, m_timeRect, m_plainClockFont, fakeTimeString, true);

    if (!m_dateString.isEmpty()) {
        if (m_dateTimezoneBesides) {
            QFontMetrics fm(m_plainClockFont);
            //kDebug() << dateRect << m_timeRect << fm.boundingRect(m_timeRect, Qt::AlignCenter, timeString);
            QRect br = fm.boundingRect(m_timeRect, Qt::AlignCenter, timeString);

            QFontMetrics smallfm(smallFont);
            dateRect.moveLeft(br.right() + qMin(0, br.left()) + smallfm.width(" "));
        }

        // When we're relatively low, force everything into a single line
        QFont f = p->font();
        p->setFont(smallFont);

        QPen datePen = p->pen();
        QColor dateColor = m_plainClockColor;
        dateColor.setAlphaF(0.7);
        datePen.setColor(dateColor);
        p->setPen(datePen);

        if (formFactor() == Plasma::Horizontal && (contentsRect.height() < smallFont.pointSize()*6)) {
            p->drawText(dateRect, Qt::TextSingleLine | Qt::AlignHCenter, m_dateString);
        } else {
            p->drawText(dateRect, Qt::TextWordWrap | Qt::AlignHCenter, m_dateString);
        }

        p->setFont(f);
    }

    if (m_useCustomColor || !m_svgExistsInTheme) {
        QFontMetrics fm(p->font());

        QPointF timeTextOrigin(QPointF(qMax(0, (m_timeRect.center().x() - fm.width(fakeTimeString) / 2)),
                            (m_timeRect.center().y() + fm.height() / 3)));
        p->translate(-0.5, -0.5);

        if (m_drawShadow) {
            QPen tmpPen = p->pen();

            // Paint a backdrop behind the time's text
            qreal shadowOffset = 1.0;
            QPen shadowPen;
            QColor shadowColor = m_plainClockShadowColor;
            shadowColor.setAlphaF(.4);
            shadowPen.setColor(shadowColor);
            p->setPen(shadowPen);
            QPointF shadowTimeTextOrigin = QPointF(timeTextOrigin.x() + shadowOffset,
                                                timeTextOrigin.y() + shadowOffset);
            p->drawText(shadowTimeTextOrigin, timeString);

            p->setPen(tmpPen);

            // Paint the time itself with a linear translucency gradient
            QLinearGradient gradient = QLinearGradient(QPointF(0, 0), QPointF(0, fm.height()));

            QColor startColor = m_plainClockColor;
            startColor.setAlphaF(.95);
            QColor stopColor = m_plainClockColor;
            stopColor.setAlphaF(.7);

            gradient.setColorAt(0.0, startColor);
            gradient.setColorAt(0.5, stopColor);
            gradient.setColorAt(1.0, startColor);
            QBrush gradientBrush(gradient);

            QPen gradientPen(gradientBrush, tmpPen.width());
            p->setPen(gradientPen);
        }
        p->drawText(timeTextOrigin, timeString);
    //when use the custom theme colors, draw the time textured
    } else {
        QRect adjustedTimeRect = m_pixmap.rect();
        adjustedTimeRect.moveCenter(m_timeRect.center());
        p->drawPixmap(adjustedTimeRect, m_pixmap);
    }
}
void QGCRadioChannelDisplay::paintEvent(QPaintEvent *event)
{
    Q_UNUSED(event);
    
    //Values range from 0-3000.
    //1500 is the middle, static servo value.
    QPainter painter(this);




    int fontHeight = painter.fontMetrics().height();
    int twiceFontHeight = fontHeight * 2;

    painter.setBrush(Qt::Dense4Pattern);
    painter.setPen(QColor::fromRgb(128,128,64));

    int curVal = m_value;
    if (curVal > m_max)  {
        curVal = m_max;
    }
    if (curVal < m_min) {
        curVal = m_min;
    }

    if (m_orientation == Qt::Vertical)
    {
        QLinearGradient gradientBrush(0, 0, this->width(), this->height());
        gradientBrush.setColorAt(1.0,DIMMEST_COLOR);
        gradientBrush.setColorAt(0.5,MIDBRIGHT_COLOR);
        gradientBrush.setColorAt(0.0, BRIGHTEST_COLOR);

        //draw border
        painter.drawRect(0,0,width()-1,(height()-1) - twiceFontHeight);
        painter.setPen(QColor::fromRgb(50,255,50));
        painter.setBrush(Qt::SolidPattern);

        //draw the text value of the widget, and its label
        painter.setPen(QColor::fromRgb(255,255,255));
        painter.drawText((width()/2.0) - (painter.fontMetrics().width(m_name)/2.0),((height()-3) - (fontHeight*1)),m_name);

        if (isEnabled()) {
            QString valStr = QString::number(m_value);
            painter.drawText((width()/2.0) - (painter.fontMetrics().width(valStr)/2.0),((height()-3) - (fontHeight * 0)),valStr);

            painter.setPen(QColor::fromRgb(128,128,64));
            painter.setBrush(gradientBrush);

            if (!m_showMinMax) {
                //draw just the value
                int newval = (height()-2-twiceFontHeight) * ((float)(curVal - m_min) / ((m_max-m_min)+1));
                int yVal = (height()-2-twiceFontHeight) - newval;
                painter.drawRect(1,yVal,width()-3,((height()-2) - yVal - twiceFontHeight));
            }
            else {
                //draw the value
                int newval = (height()-2-twiceFontHeight) * ((float)(curVal / 3001.0));
                int yVal = (height()-2-twiceFontHeight) - newval;
                painter.drawRect(1,yVal,width()-3,((height()-2) - yVal - twiceFontHeight));

                //draw min max indicator bars
                painter.setPen(QColor::fromRgb(255,0,0));
                painter.setBrush(Qt::NoBrush);

                int yMax = (height()-3 - twiceFontHeight) - (((height()-3-twiceFontHeight) * ((float)m_max / 3000.0)));
                int yMin = (height()-3 - twiceFontHeight) - (((height()-3-twiceFontHeight) * ((float)m_min / 3000.0)));
                painter.drawRect(2,yMax,width()-3,yMin - yMax);

                //draw min and max labels
                QString minstr = QString::number(m_min);
                painter.drawText((width() / 2.0) - (painter.fontMetrics().width("min")/2.0),yMin,"min");
                painter.drawText((width() / 2.0) - (painter.fontMetrics().width(minstr)/2.0),yMin + fontHeight,minstr);

                QString maxstr = QString::number(m_max);
                painter.drawText((width() / 2.0) - (painter.fontMetrics().width("max")/2.0),yMax,"max");
                painter.drawText((width() / 2.0) - (painter.fontMetrics().width(maxstr)/2.0),yMax + fontHeight,maxstr);

            }
        }
    }
    else //horizontal orientation
    {
        QLinearGradient hGradientBrush(0, 0, this->width(), this->height());
        hGradientBrush.setColorAt(0.0,DIMMEST_COLOR);
        hGradientBrush.setColorAt(0.5,MIDBRIGHT_COLOR);
        hGradientBrush.setColorAt(1.0, BRIGHTEST_COLOR);

        //draw the value
        painter.drawRect(0,0,width()-1,(height()-1) - twiceFontHeight);
        painter.setPen(QColor::fromRgb(50,255,50));
        painter.setBrush(hGradientBrush);

        //draw the value string
        painter.setPen(QColor::fromRgb(255,255,255));
        painter.drawText((width()/2.0) - (painter.fontMetrics().width(m_name)/2.0),((height()-3) - (fontHeight*1)),m_name);

        if (isEnabled()) {
            QString valstr = QString::number(m_value);
            painter.drawText((width()/2.0) - (painter.fontMetrics().width(valstr)/2.0),((height()-3) - (fontHeight * 0)),valstr);

            painter.setPen(QColor::fromRgb(0,128,0));
            painter.setBrush(hGradientBrush);

            if (!m_showMinMax) {
                //draw just the value
                painter.drawRect(1,1,(width()-3) * ((float)(curVal-m_min) / (m_max-m_min)),(height()-3) - twiceFontHeight);
            }
            else {
                //draw the value
                painter.drawRect(1,1,(width()-3) * ((float)curVal / 3000.0),(height()-3) - twiceFontHeight);

                 //draw the min and max bars
                painter.setBrush(Qt::NoBrush);
                painter.setPen(QColor::fromRgb(255,0,0));
                painter.drawRect(width() * ((float)m_min / 3000.0),2,((width()-1) * ((float)m_max / 3000.0)) - (width() * ((float)m_min / 3000.0)),(height()-5) - twiceFontHeight);

                //draw the min and max strings
                QString minstr = QString::number(m_min);
                painter.drawText((width() * ((float)m_min / 3000.0)) - (painter.fontMetrics().width("min")/2.0),((height()-3) - (painter.fontMetrics().height()*1)),"min");
                painter.drawText((width() * ((float)m_min / 3000.0)) - (painter.fontMetrics().width(minstr)/2.0),((height()-3) - (painter.fontMetrics().height() * 0)),minstr);

                QString maxstr = QString::number(m_max);
                painter.drawText((width() * ((float)m_max / 3000.0)) - (painter.fontMetrics().width("max")/2.0),((height()-3) - (painter.fontMetrics().height()*1)),"max");
                painter.drawText((width() * ((float)m_max / 3000.0)) - (painter.fontMetrics().width(maxstr)/2.0),((height()-3) - (painter.fontMetrics().height() * 0)),maxstr);
            }
        }
    }
}
Пример #4
0
int QPdfEnginePrivate::addBrushPattern(const QTransform &m, bool *specifyColor, int *gStateObject)
{
    int paintType = 2; // Uncolored tiling
    int w = 8;
    int h = 8;

    *specifyColor = true;
    *gStateObject = 0;

    QTransform matrix = m;
    matrix.translate(brushOrigin.x(), brushOrigin.y());
    matrix = matrix * pageMatrix();
    //qDebug() << brushOrigin << matrix;

    Qt::BrushStyle style = brush.style();
    if (style == Qt::LinearGradientPattern) {// && style <= Qt::ConicalGradientPattern) {
#ifdef USE_NATIVE_GRADIENTS
        *specifyColor = false;
        return gradientBrush(b, matrix, gStateObject);
#else
        return 0;
#endif
    }

    if ((!brush.isOpaque() && brush.style() < Qt::LinearGradientPattern) || opacity != 1.0)
        *gStateObject = addConstantAlphaObject(qRound(brush.color().alpha() * opacity),
                                               qRound(pen.color().alpha() * opacity));

    int imageObject = -1;
    QByteArray pattern = QPdf::patternForBrush(brush);
    if (pattern.isEmpty()) {
        if (brush.style() != Qt::TexturePattern)
            return 0;
        QImage image = brush.texture().toImage();
        bool bitmap = true;
        imageObject = addImage(image, &bitmap, qt_pixmap_id(brush.texture()));
        if (imageObject != -1) {
            QImage::Format f = image.format();
            if (f != QImage::Format_MonoLSB && f != QImage::Format_Mono) {
                paintType = 1; // Colored tiling
                *specifyColor = false;
            }
            w = image.width();
            h = image.height();
            QTransform m(w, 0, 0, -h, 0, h);
            QPdf::ByteStream s(&pattern);
            s << QPdf::generateMatrix(m);
            s << "/Im" << imageObject << " Do\n";
        }
    }

    QByteArray str;
    QPdf::ByteStream s(&str);
    s << "<<\n"
        "/Type /Pattern\n"
        "/PatternType 1\n"
        "/PaintType " << paintType << "\n"
        "/TilingType 1\n"
        "/BBox [0 0 " << w << h << "]\n"
        "/XStep " << w << "\n"
        "/YStep " << h << "\n"
        "/Matrix ["
      << matrix.m11()
      << matrix.m12()
      << matrix.m21()
      << matrix.m22()
      << matrix.dx()
      << matrix.dy() << "]\n"
        "/Resources \n<< "; // open resource tree
    if (imageObject > 0) {
        s << "/XObject << /Im" << imageObject << ' ' << imageObject << "0 R >> ";
    }
    s << ">>\n"
        "/Length " << pattern.length() << "\n"
        ">>\n"
        "stream\n"
      << pattern
      << "endstream\n"
        "endobj\n";

    int patternObj = addXrefEntry(-1);
    write(str);
    currentPage->patterns.append(patternObj);
    return patternObj;
}
Пример #5
0
void CStartupView::DrawBackground(Gdiplus::Graphics &graphics)
{
   CSize siTotal = GetTotalSize();
   CRect rcClient(0, 0, siTotal.cx, siTotal.cy);
   CRect rc;
   GetClientRect(&rc);

  /* int iLeft = 6;
   int iRight = 13;
   int iMiddle = rcClient.Width() - iLeft - iRight;*/
   Gdiplus::Rect gdipRcClient(rcClient.left, rcClient.top, rcClient.Width(), rcClient.Height());
   Gdiplus::SolidBrush bgBrush(Gdiplus::Color(255, 238, 238, 238));
   graphics.FillRectangle(&bgBrush, gdipRcClient);

   Gdiplus::REAL offsetY = (Gdiplus::REAL)OFFSET_Y;
   Gdiplus::REAL y = offsetY;
   float fHeight = (Gdiplus::REAL)TOP_HEIGHT;
   Gdiplus::RectF gdipRcLeft;
   Gdiplus::RectF gdipRcMiddle;
   Gdiplus::RectF gdipRcRight;

   
   CalculateBkgRects(gdipRcLeft, gdipRcMiddle, gdipRcRight, y, fHeight);

   
   graphics.DrawImage(m_pBmpTopLeft, gdipRcLeft);
   graphics.DrawImage(m_pBmpTopMiddle, gdipRcMiddle, 0.0, 0.0, 1.0, (Gdiplus::REAL)fHeight, Gdiplus::UnitPixel);
   graphics.DrawImage(m_pBmpTopRight, gdipRcRight);

   fHeight = (Gdiplus::REAL)BLUE_HEIGHT;
   CalculateBkgRects(gdipRcLeft, gdipRcMiddle, gdipRcRight, y, fHeight);
   graphics.DrawImage(m_pBmpBlueLeft, gdipRcLeft);
   graphics.DrawImage(m_pBmpBlueMiddle, gdipRcMiddle, 0.0, 0.0, 1.0, (Gdiplus::REAL)fHeight, Gdiplus::UnitPixel);
   graphics.DrawImage(m_pBmpBlueRight, gdipRcRight);

   fHeight =(Gdiplus::REAL)( rcClient.Height()  - OFFSET_Y  - TOP_HEIGHT - BLUE_HEIGHT - LIGHT_BLUE_HEIGHT - FOOT_HEIGHT); 
   CalculateBkgRects(gdipRcLeft, gdipRcMiddle, gdipRcRight, y, fHeight);
   graphics.DrawImage(m_pBmpWhiteLeft, gdipRcLeft/*, 0.0, 0.0, 1.0, (Gdiplus::REAL)296, Gdiplus::UnitPixel*/);
   graphics.DrawImage(m_pBmpWhiteMiddle, gdipRcMiddle, 0.0, 0.0, 1.0, (Gdiplus::REAL)296, Gdiplus::UnitPixel);
   graphics.DrawImage(m_pBmpWhiteRight, gdipRcRight/*, 0.0, 0.0, 1.0, (Gdiplus::REAL)296, Gdiplus::UnitPixel*/);

   fHeight = (Gdiplus::REAL)LIGHT_BLUE_HEIGHT;
   y--;
   CalculateBkgRects(gdipRcLeft, gdipRcMiddle, gdipRcRight, y , fHeight);
   graphics.DrawImage(m_pBmpLightBlueLeft, gdipRcLeft);
   graphics.DrawImage(m_pBmpLightBlueMiddle, gdipRcMiddle, 0.0, 0.0, 1.0, (Gdiplus::REAL)fHeight, Gdiplus::UnitPixel);
   graphics.DrawImage(m_pBmpLightBlueRight, gdipRcRight);

   fHeight = (Gdiplus::REAL)FOOT_HEIGHT;
   CalculateBkgRects(gdipRcLeft, gdipRcMiddle, gdipRcRight, y, fHeight);
   graphics.DrawImage(m_pBmpFootLeft, gdipRcLeft);
   graphics.DrawImage(m_pBmpFootMiddle, gdipRcMiddle, 0.0, 0.0, 1.0, (Gdiplus::REAL)fHeight, Gdiplus::UnitPixel);
   graphics.DrawImage(m_pBmpFootRight, gdipRcRight);

   Gdiplus::Color colorFrom[] = {Gdiplus::Color(255, 220, 223, 224),
      Gdiplus::Color(255, 215, 215, 215),
      Gdiplus::Color(255, 216, 216, 216),
      Gdiplus::Color(255, 219, 219, 219),
      Gdiplus::Color(255, 223, 223, 223),
      Gdiplus::Color(255, 226, 226, 226),
      Gdiplus::Color(255, 229, 229, 229),
      Gdiplus::Color(255, 231, 231, 231),
   };
   Gdiplus::Color colorTo[] = {Gdiplus::Color(255, 198, 199, 201),
      Gdiplus::Color(255, 185, 185, 185),
      Gdiplus::Color(255, 190, 190, 190),
      Gdiplus::Color(255, 197, 197, 197),
      Gdiplus::Color(255, 203, 203, 203),
      Gdiplus::Color(255, 213, 213, 213),
      Gdiplus::Color(255, 218, 218, 218),
      Gdiplus::Color(255, 226, 226, 226),
   };
   Gdiplus::RectF gdipRcM2;
   for(int i = 0; i < 8; i++)
   {
      gdipRcM2.X = gdipRcMiddle.X + gdipRcMiddle.Width - 30.0;
      gdipRcM2.Y = gdipRcMiddle.Y + gdipRcMiddle.Height - 8 + i;
      gdipRcM2.Width = 30.0;
      gdipRcM2.Height = 1.0;

      Gdiplus::LinearGradientBrush gradientBrush(gdipRcM2, 
      colorFrom[i], 
      colorTo[i], 
      Gdiplus::LinearGradientModeHorizontal);
      graphics.FillRectangle(&gradientBrush, gdipRcM2);
   }
}
Пример #6
0
void DateTimeGroup::paintInterface(QPainter *p, const QStyleOptionGraphicsItem *option, const QRect &contentsRect)
{
	Q_UNUSED(option);
	if (dtg.isEmpty()) {
		return;
	}
	
	p->setPen(QPen(m_plainDateTimeGroupColor));
	p->setRenderHint(QPainter::SmoothPixmapTransform);
	p->setRenderHint(QPainter::Antialiasing);
	
	QFont smallFont = KGlobalSettings::smallestReadableFont();
	
	dtgRect = contentsRect;
	
	m_plainDateTimeGroupFont.setPointSizeF(qMax(dtgRect.height(), KGlobalSettings::smallestReadableFont().pointSize()));
	preparePainter(p, dtgRect, m_plainDateTimeGroupFont, dtg, true);
	
	if (m_useCustomColor || !m_svgExistsInTheme) {
		QFontMetrics fm(p->font());
		
		QPointF timeTextOrigin(QPointF(qMax(0, (dtgRect.center().x() - fm.width(dtg) / 2)),
						(dtgRect.center().y() + fm.height() / 3)));
		p->translate(-0.5, -0.5);
		
		if (m_drawShadow) {
			QPen tmpPen = p->pen();
			
			qreal shadowOffset = 1.0;
			QPen shadowPen;
			QColor shadowColor = m_plainDateTimeGroupShadowColor;
			shadowColor.setAlphaF(.4);
			shadowPen.setColor(shadowColor);
			p->setPen(shadowPen);
			QPointF shadowTimeTextOrigin = QPointF(timeTextOrigin.x() + shadowOffset,
								timeTextOrigin.y() + shadowOffset);
			p->drawText(shadowTimeTextOrigin, dtg);
			
			p->setPen(tmpPen);
			
			QLinearGradient gradient = QLinearGradient(QPointF(0, 0), QPointF(0, fm.height()));
			
			QColor startColor = m_plainDateTimeGroupColor;
			startColor.setAlphaF(.95);
			QColor stopColor = m_plainDateTimeGroupColor;
			stopColor.setAlphaF(.7);
			
			gradient.setColorAt(0.0, startColor);
			gradient.setColorAt(0.5, stopColor);
			gradient.setColorAt(1.0, startColor);
			QBrush gradientBrush(gradient);
			
			QPen gradientPen(gradientBrush, tmpPen.width());
			p->setPen(gradientPen);
		}
		p->drawText(timeTextOrigin, dtg);
	} else {
		QRect adjustedTimeRect = m_pixmap.rect();
		adjustedTimeRect.moveCenter(dtgRect.center());
		p->drawPixmap(adjustedTimeRect, m_pixmap);
	}
}