Exemplo n.º 1
0
/*!
  See QwtAbstractSlider::getScrollMode()

  \param pos point where the mouse was pressed
  \retval scrollMode The scrolling mode
  \retval direction  direction: 1, 0, or -1.

  \sa QwtAbstractSlider::getScrollMode()
*/
void QwtDial::getScrollMode( const QPoint &pos,
    QwtAbstractSlider::ScrollMode &scrollMode, int &direction ) const
{
    direction = 0;
    scrollMode = QwtAbstractSlider::ScrNone;

    const QRegion region( innerRect().toRect(), QRegion::Ellipse );
    if ( region.contains( pos ) && pos != innerRect().center() )
    {
        scrollMode = QwtAbstractSlider::ScrMouse;
        d_data->previousDir = -1.0;
    }
}
void AttitudeIndicator::drawScale(QPainter *painter, const QPointF &center,
    double radius, double origin, double minArc, double maxArc) const
{
    // counter clockwise, radian

    const double dir = (360.0 - origin) * M_PI / 180.0;
    const double offset = 4.0;

    const QPointF p0 = qwtPolar2Pos( center, offset, dir + M_PI );

    const double w = innerRect().width();

    QPainterPath path;
    path.moveTo( qwtPolar2Pos( p0, w, dir - M_PI_2 ) );
    path.lineTo( qwtPolar2Pos( path.currentPosition(), 2 * w, dir + M_PI_2 ) );
    path.lineTo( qwtPolar2Pos( path.currentPosition(), w, dir ) );
    path.lineTo( qwtPolar2Pos( path.currentPosition(), w, dir - M_PI_2 ) );

    painter->save();
    painter->setClipPath( path ); // swallow 180 - 360 degrees

    QwtDial::drawScale(painter,
        center, radius, origin, minArc, maxArc);

    painter->restore();
}
Exemplo n.º 3
0
void XYScale::paint(const QRect &rect, QPainter *painter) {
    KSL_PUBLIC(XYScale);

    // Check if any item has NaN or Infs
    if (!std::isfinite(m->width) || !std::isfinite(m->height)) {
        m->figure->informError();
        return;
    }

    // Update figure bounds
    m->figXmin = rect.left() + m->xLowBound;
    m->figXmax = rect.right() - m->xUpBound;
    m->figWidth = m->figXmax - m->figXmin;
    m->figYmin = rect.top() + m->yLowBound;
    m->figYmax = rect.bottom() - m->yUpBound;
    m->figHeight = m->figYmax - m->figYmin;

    // Use base class meyhod to paint item
    QRect innerRect(m->figXmin, m->figYmin,
                    m->figWidth+1, m->figHeight+1);
    painter->save();
    painter->setClipRect(innerRect);
    painter->fillRect(innerRect, m->backBrush);
    FigureScale::paint(rect, painter);
    painter->restore();

    // Inform data bounds to axis and paint them
    m->positionAxis();
    for (auto axis : m->axisHash)
        if (axis->visible())
            axis->paint(painter);
}
Exemplo n.º 4
0
		void ActionGraphicsItem::calculateLayout()
		{
			if(elementLayout() == 0)
				return;

			const ElementLayout & el = *elementLayout();

			// calculate the size of the label
			QSizeF labelSize = calculateLabelSize();
			QSize connectorSize = inputLayout()->connector().size();

			// find the new width & height
			float height = labelSize.height() + 2*el.yMargin();
			float width = labelSize.width() + 2*el.xMargin() + connectorSize.width();

			if(width < el.minSize().width()) width = el.minSize().width();
			if(height < el.minSize().height()) height = el.minSize().height();

			// the height should be bigger or the same as the attached elements
			if(inputItem() && height < inputItem()->boundingRect().height())
				height = inputItem()->boundingRect().height();

			// update the bounding rect & position where text should start
			setInnerRect(QRectF(0, -height/2.0f, width, height));
			setLabelStart(QPointF(connectorSize.width() + el.xMargin(), -labelSize.height()/2.0f));
			setBoundingRect(innerRect().adjusted(-inputItem()->innerRect().width(), 0, 0, 0));
		}
Exemplo n.º 5
0
		void ActionGraphicsItem::paint(QPainter * painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/)
		{
			if(elementLayout() == 0)
				return;

			const ElementLayout & el = *elementLayout();

			painter->save();

			// use the right brush & pen
			painter->setPen(isHovered() ? el.selectedStrokePen() : el.strokePen());
			painter->setBrush(isHovered() ? el.selectedBackgroundBrush() : el.backgroundBrush());

			// draw the shape
			painter->drawRoundedRect(innerRect(), el.roundness(), el.roundness());
			drawConnector(inputLayout(), QPointF(0,0), painter, isHovered());

			// draw the label
			if(delegate())
			{
				QTransform transform  = QTransform::fromTranslate(labelStart().x(), labelStart().y());
				painter->setTransform(transform, true);
				delegate()->paint(painter, element());
			}

			painter->restore();
		}
Exemplo n.º 6
0
void IntroWidget::resizeEvent(QResizeEvent *e) {
	QRect r(innerRect());
	if (steps) steps->setGeometry(r);
	if (phone) phone->setGeometry(r);
	if (code) code->setGeometry(r);
	if (signup) signup->setGeometry(r);
}
Exemplo n.º 7
0
void KisColorSelector::createRing(ColorRing& ring, quint8 numPieces, qreal innerRadius, qreal outerRadius)
{
    int numParts = qMax<int>(numPieces, 1);

    ring.innerRadius = innerRadius;
    ring.outerRadius = outerRadius;
    ring.pieced.resize(numParts);
    
    qreal  partSize = 360.0 / qreal(numParts);
    QRectF outerRect(-outerRadius, -outerRadius, outerRadius*2.0, outerRadius*2.0);
    QRectF innerRect(-innerRadius, -innerRadius, innerRadius*2.0, innerRadius*2.0);
    
    for(int i=0; i<numParts; ++i) {
        qreal aBeg  = partSize*i;
        qreal aEnd  = aBeg + partSize;
        
        aBeg -= partSize / 2.0;
        aEnd -= partSize / 2.0;
        
        ring.pieced[i] = QPainterPath();
        ring.pieced[i].arcMoveTo(innerRect, aBeg);
        ring.pieced[i].arcTo(outerRect, aBeg, partSize);
        ring.pieced[i].arcTo(innerRect, aEnd,-partSize);
    }
}
Exemplo n.º 8
0
/*!
  Draw a dotted round circle, if !isReadOnly()

  \param painter Painter
*/
void QwtDial::drawFocusIndicator( QPainter *painter ) const
{
    if ( !isReadOnly() )
    {
        QRectF focusRect = innerRect();

        const int margin = 2;
        focusRect.adjust( margin, margin, -margin, -margin );

        QColor color = palette().color( QPalette::Base );
        if ( color.isValid() )
        {
            const QColor gray( Qt::gray );

            int h, s, v;
            color.getHsv( &h, &s, &v );
            color = ( v > 128 ) ? gray.dark( 120 ) : gray.light( 120 );
        }
        else
            color = Qt::darkGray;

        painter->save();
        painter->setBrush( Qt::NoBrush );
        painter->setPen( QPen( color, 0, Qt::DotLine ) );
        painter->drawEllipse( focusRect );
        painter->restore();
    }
}
Exemplo n.º 9
0
void
MonitorView::Draw(BRect updateRect)
{
	rgb_color darkColor = {160, 160, 160, 255};
	rgb_color blackColor = {0, 0, 0, 255};
	rgb_color redColor = {228, 0, 0, 255};
	rgb_color whiteColor = {255, 255, 255, 255};
	BRect outerRect = _MonitorBounds();

	SetHighColor(fBackgroundColor);
	FillRect(updateRect);

	SetDrawingMode(B_OP_OVER);

	// frame & background

	SetHighColor(darkColor);
	FillRoundRect(outerRect, 3.0, 3.0);

	SetHighColor(blackColor);
	StrokeRoundRect(outerRect, 3.0, 3.0);

	SetHighColor(fDesktopColor);

	BRect innerRect(outerRect.InsetByCopy(4, 4));
	FillRoundRect(innerRect, 2.0, 2.0);

	SetHighColor(blackColor);
	StrokeRoundRect(innerRect, 2.0, 2.0);

	SetDrawingMode(B_OP_COPY);

	// power light

	SetHighColor(redColor);
	BPoint powerPos(outerRect.left + 5, outerRect.bottom - 2);
	StrokeLine(powerPos, BPoint(powerPos.x + 2, powerPos.y));

	// DPI

	if (fDPI == 0)
		return;

	font_height fontHeight;
	GetFontHeight(&fontHeight);
	float height = ceilf(fontHeight.ascent + fontHeight.descent);

	char text[64];
	snprintf(text, sizeof(text), B_TRANSLATE("%ld dpi"), fDPI);

	float width = StringWidth(text);
	if (width > innerRect.Width() || height > innerRect.Height())
		return;

	SetLowColor(fDesktopColor);
	SetHighColor(whiteColor);

	DrawString(text, BPoint(innerRect.left + (innerRect.Width() - width) / 2,
		innerRect.top + fontHeight.ascent + (innerRect.Height() - height) / 2));
}
Exemplo n.º 10
0
void KisVisualEllipticalSelectorShape::drawCursor()
{
    //qDebug() << this << "KisVisualEllipticalSelectorShape::drawCursor: image needs update" << imagesNeedUpdate();
    QPointF cursorPoint = convertShapeCoordinateToWidgetCoordinate(getCursorPosition());
    QImage fullSelector = getImageMap();
    QColor col = getColorFromConverter(getCurrentColor());
    QPainter painter;
    painter.begin(&fullSelector);
    painter.setRenderHint(QPainter::Antialiasing);
    QRect innerRect(m_barWidth, m_barWidth, width()-(m_barWidth*2), height()-(m_barWidth*2));

    painter.save();
    painter.setCompositionMode(QPainter::CompositionMode_Clear);
    QPen pen;
    pen.setWidth(5);
    painter.setPen(pen);
    painter.drawEllipse(QRect(0,0,width(),height()));

    if (getDimensions()==KisVisualColorSelectorShape::onedimensional) {
        painter.setBrush(Qt::SolidPattern);
        painter.drawEllipse(innerRect);
    }
    painter.restore();

    QBrush fill;
    fill.setStyle(Qt::SolidPattern);

    int cursorwidth = 5;

    if (m_type==KisVisualEllipticalSelectorShape::borderMirrored) {
        painter.setPen(Qt::white);
        fill.setColor(Qt::white);
        painter.setBrush(fill);
        painter.drawEllipse(cursorPoint, cursorwidth, cursorwidth);
        QPoint mirror(innerRect.center().x()+(innerRect.center().x()-cursorPoint.x()),cursorPoint.y());
        painter.drawEllipse(mirror, cursorwidth, cursorwidth);
        fill.setColor(col);
        painter.setPen(Qt::black);
        painter.setBrush(fill);
        painter.drawEllipse(cursorPoint, cursorwidth-1, cursorwidth-1);
        painter.drawEllipse(mirror, cursorwidth-1, cursorwidth-1);

    } else {
        painter.setPen(Qt::white);
        fill.setColor(Qt::white);
        painter.setBrush(fill);
        painter.drawEllipse(cursorPoint, cursorwidth, cursorwidth);
        fill.setColor(col);
        painter.setPen(Qt::black);
        painter.setBrush(fill);
        painter.drawEllipse(cursorPoint, cursorwidth-1.0, cursorwidth-1.0);
    }
    painter.end();
    setFullImage(fullSelector);
}
// ----------------------------------------------------------------------------
// CBCTestSkinsContainer::Draw
// Fills the window's rectangle.
// ----------------------------------------------------------------------------
//
void CBCTestSkinsContainer::Draw( const TRect& aRect ) const
    {    
    CWindowGc& gc = SystemGc();
    gc.SetPenStyle( CGraphicsContext::ENullPen );
    gc.SetBrushColor( KAknAtListGray );
    gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
    gc.DrawRect( aRect );
    
	if( !iDrawFlag ) 
		{
		return;	
		}
    
    // AknsDrawUtils::Background
    TBool boolflag = ETrue;   
    _LIT( KMsg, "Great");
    TBuf<16> info( KMsg );   
    
    _LIT( KErr, "Error");
    TBuf<16> errInfo( KErr );   
    
    MAknsSkinInstance* skin = AknsUtils::SkinInstance();
    MAknsControlContext* cc = AknsDrawUtils::ControlContext( this );
    if( skin != NULL )    
	    {
		CEikonEnv::Static()->InfoMsg( KMsg );				    	
	    }
    
    boolflag = AknsDrawUtils::Background( skin, cc, gc, aRect );    
    if (boolflag) 
		{
		CEikonEnv::Static()->InfoMsg( info );			
		}
	else
		{
		CEikonEnv::Static()->InfoMsg( errInfo );			
		}
			
    // AknsDrawUtils::BackgroundBetweenRects
    TRect innerRect( 5, 5, 100, 100);    
    boolflag = AknsDrawUtils::BackgroundBetweenRects( skin, cc, gc, aRect, innerRect);
    if (boolflag) 
		{
		CEikonEnv::Static()->InfoMsg( info );			
		}
	else
		{
		CEikonEnv::Static()->InfoMsg( errInfo );			
		}    
	
	boolflag = AknsDrawUtils::DrawFramePart(skin, gc, aRect, KAknsIIDQsnFrSetOptCornerTl, 
	    EAknsFrameIndexCenter );  
    }
Exemplo n.º 12
0
/*************************************************************************
	Handler for when frame state changes.
*************************************************************************/
void StaticImage::onStaticFrameChanged(WindowEventArgs& e)
{
	// base class processing
	Static::onStaticFrameChanged(e);

	// update the size and position of the image to reflect changes made
	// to the frame in the base class
	Rect absRect(getUnclippedPixelRect());
	Rect innerRect(getUnclippedInnerRect());
	d_image.setSize(innerRect.getSize());
	d_image.setPosition(Point(innerRect.d_left - absRect.d_left, innerRect.d_top - absRect.d_top));

	e.handled = true;
}
Exemplo n.º 13
0
/*!
  \return rect inside the scale
  \sa setLineWidth(), boundingRect(), innerRect()
*/
QRectF QwtDial::scaleInnerRect() const
{
    QRectF rect = innerRect();

    if ( d_data->scaleDraw )
    {
        double scaleDist = qCeil( d_data->scaleDraw->extent( font() ) );
        scaleDist++; // margin

        rect.adjust( scaleDist, scaleDist, -scaleDist, -scaleDist );
    }

    return rect;
}
Exemplo n.º 14
0
/*!
   Draw the slider into the specified rectangle.

   \param painter Painter
   \param sliderRect Bounding rectangle of the slider
*/
void QwtSlider::drawSlider( 
    QPainter *painter, const QRect &sliderRect ) const
{
    QRect innerRect( sliderRect );

    if ( d_data->hasTrough )
    {
        const int bw = d_data->borderWidth;
        innerRect = sliderRect.adjusted( bw, bw, -bw, -bw );

        painter->fillRect( innerRect, palette().brush( QPalette::Mid ) );
        qDrawShadePanel( painter, sliderRect, palette(), true, bw, NULL );
    }

    const QSize handleSize = qwtHandleSize( d_data->handleSize,
        d_data->orientation, d_data->hasTrough );

    if ( d_data->hasGroove )
    {
        const int slotExtent = 4;
        const int slotMargin = 4;

        QRect slotRect; 
        if ( orientation() == Qt::Horizontal )
        {
            int slotOffset = qMax( 1, handleSize.width() / 2 - slotMargin );
            int slotHeight = slotExtent + ( innerRect.height() % 2 );

            slotRect.setWidth( innerRect.width() - 2 * slotOffset );
            slotRect.setHeight( slotHeight );
        }
        else
        {
            int slotOffset = qMax( 1, handleSize.height() / 2 - slotMargin );
            int slotWidth = slotExtent + ( innerRect.width() % 2 );

            slotRect.setWidth( slotWidth );
            slotRect.setHeight( innerRect.height() - 2 * slotOffset );

        }

        slotRect.moveCenter( innerRect.center() );

        QBrush brush = palette().brush( QPalette::Dark );
        qDrawShadePanel( painter, slotRect, palette(), true, 1 , &brush );
    }

    if ( isValid() )
        drawHandle( painter, handleRect(), transform( value() ) );
}
Exemplo n.º 15
0
/*!
   Draw the slider into the specified rectangle.

   \param painter Painter
   \param sliderRect Bounding rectangle of the slider
*/
void QwtSlider::drawSlider( 
    QPainter *painter, const QRect &sliderRect ) const
{
    QRect innerRect( sliderRect );

    if ( d_data->bgStyle & QwtSlider::Trough )
    {
        const int bw = d_data->borderWidth;

        qDrawShadePanel( painter, sliderRect, palette(), true, bw, NULL );

        innerRect = sliderRect.adjusted( bw, bw, -bw, -bw );
        painter->fillRect( innerRect, palette().brush( QPalette::Mid ) );
    }

    if ( d_data->bgStyle & QwtSlider::Groove )
    {
        int ws = 4;
        int ds = d_data->handleSize.width() / 2 - 4;
        if ( ds < 1 )
            ds = 1;

        QRect rSlot;
        if ( orientation() == Qt::Horizontal )
        {
            if ( innerRect.height() & 1 )
                ws++;

            rSlot = QRect( innerRect.x() + ds,
                    innerRect.y() + ( innerRect.height() - ws ) / 2,
                    innerRect.width() - 2 * ds, ws );
        }
        else
        {
            if ( innerRect.width() & 1 )
                ws++;

            rSlot = QRect( innerRect.x() + ( innerRect.width() - ws ) / 2,
                           innerRect.y() + ds,
                           ws, innerRect.height() - 2 * ds );
        }

        QBrush brush = palette().brush( QPalette::Dark );
        qDrawShadePanel( painter, rSlot, palette(), true, 1 , &brush );
    }

    if ( isValid() )
        drawHandle( painter, innerRect, transform( value() ) );
}
Exemplo n.º 16
0
bool RenderThemeSymbian::paintButton(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r)
{
    i.context->save();
    IntRect clipRect(intersection(r, i.rect));
    i.context->clip(clipRect);
    EAppearance appearance = o->style()->appearance();    
    IntRect innerRect(r);
    IntSize cr(1,1);
    for (int j = 4; j > 0; --j) {
        innerRect.setSize(innerRect.size() - IntSize(1,1));
        i.context->fillRoundedRect(innerRect, IntSize(1,1), IntSize(1,1), IntSize(1,1), IntSize(1,1), Color(226 - j*10, 226 - j*10, 226 - j*2));
    }

    i.context->restore();
    return false;
}
Exemplo n.º 17
0
bool RenderTheme::paintMeter(RenderObject* renderObject, const RenderObject::PaintInfo& paintInfo, const IntRect& rect)
{
    // Some platforms do not have a native gauge widget, so we draw here a default implementation.
    RenderMeter* renderMeter = toRenderMeter(renderObject);
    RenderStyle* style = renderObject->style();
    int left = style->borderLeft().width() + style->paddingLeft().value();
    int top = style->borderTop().width() + style->paddingTop().value();
    int right = style->borderRight().width() + style->paddingRight().value();
    int bottom = style->borderBottom().width() + style->paddingBottom().value();
    FloatRect innerRect(rect.x() + left, rect.y() + top, rect.width() - left - right, rect.height() - top - bottom);

    HTMLMeterElement* element = static_cast<HTMLMeterElement*>(renderMeter->node());
    double min = element->min();
    double max = element->max();
    double value = element->value();

    if (min >= max) {
        paintInfo.context->fillRect(innerRect, Color::black, style->colorSpace());
        return false;
    }

    // Paint the background first
    paintInfo.context->fillRect(innerRect, Color::lightGray, style->colorSpace());

    FloatRect valueRect;

    if (rect.width() < rect.height()) {
        // Vertical gauge
        double scale = innerRect.height() / (max - min);
        valueRect.setLocation(FloatPoint(innerRect.x(), innerRect.y() + narrowPrecisionToFloat((max - value) * scale)));
        valueRect.setSize(FloatSize(innerRect.width(), narrowPrecisionToFloat((value - min) * scale)));
    } else if (renderMeter->style()->direction() == RTL) {
        // right to left horizontal gauge
        double scale = innerRect.width() / (max - min);
        valueRect.setLocation(FloatPoint(innerRect.x() + narrowPrecisionToFloat((max - value) * scale), innerRect.y()));
        valueRect.setSize(FloatSize(narrowPrecisionToFloat((value - min) * scale), innerRect.height()));
    } else {
        // left to right horizontal gauge
        double scale = innerRect.width() / (max - min);
        valueRect.setLocation(innerRect.location());
        valueRect.setSize(FloatSize(narrowPrecisionToFloat((value - min)) * scale, innerRect.height()));
    }
    if (!valueRect.isEmpty())
        paintInfo.context->fillRect(valueRect, Color::black, style->colorSpace());

    return false;
}
Exemplo n.º 18
0
RoundedRect RenderStyle::getRoundedInnerBorderFor(const LayoutRect& borderRect,
    int topWidth, int bottomWidth, int leftWidth, int rightWidth, bool includeLogicalLeftEdge, bool includeLogicalRightEdge) const
{
    LayoutRect innerRect(borderRect.x() + leftWidth,
               borderRect.y() + topWidth,
               borderRect.width() - leftWidth - rightWidth,
               borderRect.height() - topWidth - bottomWidth);

    RoundedRect roundedRect(pixelSnappedIntRect(innerRect));

    if (hasBorderRadius()) {
        RoundedRect::Radii radii = getRoundedBorderFor(borderRect).radii();
        radii.shrink(topWidth, bottomWidth, leftWidth, rightWidth);
        roundedRect.includeLogicalEdges(radii, includeLogicalLeftEdge, includeLogicalRightEdge);
    }
    return roundedRect;
}
// ---------------------------------------------------------------------------
// CBCTestDrawUtilsCase::TestFunctionL
// ---------------------------------------------------------------------------
//   
void CBCTestDrawUtilsCase::TestFunctionL()
    {
    iContainer->DrawTest();
    _LIT( KMsg, "Test AknsDrawUtils API");
    AssertNotNullL( iContainer, KMsg );
    
    // Test CAknsFrameBackgroundControlContext API
    TAknsItemID frameId;
    TRect outerRect( 0, 0, 100, 100 );
    TRect innerRect( 10, 10, 90, 90 );
    TBool absolute = ETrue;
    CAknsFrameBackgroundControlContext* ctrlContext = 
        CAknsFrameBackgroundControlContext::NewL ( frameId, outerRect, 
        innerRect, absolute );
    CleanupStack::PushL( ctrlContext );
    ctrlContext->SetFramePartRect( outerRect, EAknsFrameIndexTl );     
    _LIT( KSetFramePartRect, "CAknsFrameBackgroundControlContext::SetFramePartRect" );
    AssertNotNullL( ctrlContext, KSetFramePartRect );
    CleanupStack::PopAndDestroy( ctrlContext );    
    }
Exemplo n.º 20
0
void KoResourcePopupAction::updateIcon()
{
    QSize iconSize;
    QToolButton *toolButton = dynamic_cast<QToolButton*>(parentWidget());
    if (toolButton) {
        iconSize = QSize(toolButton->iconSize());
    } else {
        iconSize = QSize(16, 16);
    }

    // This must be a QImage, as drawing to a QPixmap outside the
    // UI thread will cause sporadic crashes.
    QImage pm = QImage(iconSize, QImage::Format_ARGB32_Premultiplied);

    pm.fill(Qt::transparent);

    QPainter p(&pm);
    QSharedPointer<KoGradientBackground> gradientBackground = qSharedPointerDynamicCast<KoGradientBackground>(d->background);
    QSharedPointer<KoPatternBackground> patternBackground = qSharedPointerDynamicCast<KoPatternBackground>(d->background);

    if (gradientBackground) {
        QRect innerRect(0, 0, iconSize.width(), iconSize.height());
        QLinearGradient paintGradient;
        paintGradient.setStops(gradientBackground->gradient()->stops());
        paintGradient.setStart(innerRect.topLeft());
        paintGradient.setFinalStop(innerRect.topRight());

        d->checkerPainter.paint(p, innerRect);
        p.fillRect(innerRect, QBrush(paintGradient));
    } else if (patternBackground) {
        d->checkerPainter.paint(p, QRect(QPoint(),iconSize));
        p.fillRect(0, 0, iconSize.width(), iconSize.height(), patternBackground->pattern());
    }

    p.end();

    setIcon(QIcon(QPixmap::fromImage(pm)));
}
Exemplo n.º 21
0
/*!
  Find the value for a given position

  \param pos Position
  \return Value
*/
double QwtDial::getValue( const QPoint &pos )
{
    if ( d_data->maxScaleArc == d_data->minScaleArc || maxValue() == minValue() )
        return minValue();

    double dir = line2Radians( innerRect().center(), pos ) - d_data->origin;
    if ( dir < 0.0 )
        dir += 360.0;

    if ( mode() == RotateScale )
        dir = 360.0 - dir;

    // The position might be in the area that is outside the scale arc.
    // We need the range of the scale if it was a complete circle.

    const double completeCircle = 360.0 / ( d_data->maxScaleArc - d_data->minScaleArc )
        * ( maxValue() - minValue() );

    double posValue = minValue() + completeCircle * dir / 360.0;

    if ( scrollMode() == ScrMouse )
    {
        if ( d_data->previousDir >= 0.0 ) // valid direction
        {
            // We have to find out whether the mouse is moving
            // clock or counter clockwise

            bool clockWise = false;

            const double angle = dir - d_data->previousDir;
            if ( ( angle >= 0.0 && angle <= 180.0 ) || angle < -180.0 )
                clockWise = true;

            if ( clockWise )
            {
                if ( dir < d_data->previousDir && mouseOffset() > 0.0 )
                {
                    // We passed 360 -> 0
                    setMouseOffset( mouseOffset() - completeCircle );
                }

                if ( wrapping() )
                {
                    if ( posValue - mouseOffset() > maxValue() )
                    {
                        // We passed maxValue and the value will be set
                        // to minValue. We have to adjust the mouseOffset.

                        setMouseOffset( posValue - minValue() );
                    }
                }
                else
                {
                    if ( posValue - mouseOffset() > maxValue() ||
                            value() == maxValue() )
                    {
                        // We fix the value at maxValue by adjusting
                        // the mouse offset.

                        setMouseOffset( posValue - maxValue() );
                    }
                }
            }
            else
            {
                if ( dir > d_data->previousDir && mouseOffset() < 0.0 )
                {
                    // We passed 0 -> 360
                    setMouseOffset( mouseOffset() + completeCircle );
                }

                if ( wrapping() )
                {
                    if ( posValue - mouseOffset() < minValue() )
                    {
                        // We passed minValue and the value will be set
                        // to maxValue. We have to adjust the mouseOffset.

                        setMouseOffset( posValue - maxValue() );
                    }
                }
                else
                {
                    if ( posValue - mouseOffset() < minValue() ||
                        value() == minValue() )
                    {
                        // We fix the value at minValue by adjusting
                        // the mouse offset.

                        setMouseOffset( posValue - minValue() );
                    }
                }
            }
        }
        d_data->previousDir = dir;
    }

    return posValue;
}
Exemplo n.º 22
0
void IntroWidget::resizeEvent(QResizeEvent *e) {
	QRect r(innerRect());
	for (IntroStep *step : _stepHistory) {
		step->setGeometry(r);
	}
}
Exemplo n.º 23
0
  //-----------------------------------------------------------------------
  // Class MacroItem
  //-----------------------------------------------------------------------
  void MacroItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
  {
    app::Macro::Ptr macroInstance = vertex().dataRef().staticCast<app::Macro>();
    Q_ASSERT(!macroInstance.isNull());

    graph::VertexItem::paint(painter,option,widget);
    QRectF rcInner = innerRect();

    // calculate text sizes
    QString macroName = macroInstance->getName();
    QFontMetrics fmName(*Resource::font(Resource::FONT_MACRONAME));
    QRect rectName = fmName.boundingRect(macroName);
    QString macroRuntime = macroInstance->getRuntimeString();
    QFontMetrics fmStatus(*Resource::font(Resource::FONT_MACROSTATUS));
    QRect rectRuntime = fmStatus.boundingRect("000.000 ms");
    QPixmap statusIcon;
    switch(macroInstance->getState())
    {
      case app::Macro::Idle:
        statusIcon = QPixmap(":/icons/resources/bullet_black.png");
        break;
      case app::Macro::Running:
        statusIcon = QPixmap(":/icons/resources/bullet_orange.png");
        break;
      case app::Macro::Ok:
        if (!toolTip().isEmpty()) setToolTip(QString());
        statusIcon = QPixmap(":/icons/resources/bullet_green.png");
        break;
      case app::Macro::Failure:
        setToolTip(macroInstance->getErrorMsg());
        statusIcon = QPixmap(":/icons/resources/bullet_red.png");
        break;
    }
    QString macroOrder = QString(QObject::tr("Order No.: "));
    if (vertex().topologicalOrder() >= 0)
    {
      macroOrder += QString("%1").arg(vertex().topologicalOrder());
    }
    else
    {
      macroOrder += '-';
    }
    QPixmap orderStatus;
    if (vertex().isInCycle() && vertex().topologicalOrder() == 0 && vertex().topologicalOrderForced())
    {
      orderStatus = QPixmap(":/icons/resources/anchor.png");
    }
    else if (vertex().isInCycle() && vertex().topologicalOrder() < 0 && !vertex().topologicalOrderForced())
    {
      orderStatus = QPixmap(":/icons/resources/cycle.png");
    }
    else if (!vertex().isInCycle() && vertex().topologicalOrder() < 0)
    {
      orderStatus = QPixmap(":/icons/resources/error.png");
    }
    QRect rectOrder = fmStatus.boundingRect(macroOrder);
    rectOrder.adjust(0,0,orderStatus.width(),16 - rectOrder.height());

    // paint macro name
    QRectF rcTextName(rcInner.left(),rcInner.top(),rcInner.width(),(qreal)rectName.height());
    painter->setPen(QPen(Qt::black));
    painter->setFont(*Resource::font(Resource::FONT_MACRONAME));
    painter->drawText(rcTextName,Qt::AlignCenter,macroName);
    // paint runtime including indicator
    QRectF rcTextRuntime(rcInner.left() + rcInner.width() * 0.02 + statusIcon.width(),rcInner.top() + rectName.height() + 1.0,rcInner.width() - 2 * rcInner.width() * 0.02 - statusIcon.width(),(qreal)rectRuntime.height());
    painter->setPen(QPen(Qt::blue));
    painter->setFont(*Resource::font(Resource::FONT_MACROSTATUS));
    painter->setClipRect(rcTextRuntime);
    painter->drawText(rcTextRuntime,Qt::AlignRight,macroRuntime);
    painter->setClipRect(rcInner);
    painter->drawPixmap(rcInner.left() + rcInner.width() * 0.02,rcTextRuntime.top(),statusIcon.rect().width(),statusIcon.rect().height(),statusIcon);
    // paint topological order
    QRectF rcTextOrder(rcInner.left() + orderStatus.rect().width() + (rcInner.width() - rectOrder.width()) / 2.0,rcInner.bottom() - (qreal)rectOrder.height(),rcInner.width(),(qreal)rectOrder.height());
    painter->setPen(QPen(Qt::black));
    painter->drawText(rcTextOrder,Qt::AlignLeft,macroOrder);
    if (!orderStatus.isNull())
    {
      painter->drawPixmap(rcTextOrder.left() - orderStatus.rect().width() - 1.0,rcTextOrder.top(),orderStatus.rect().width(),orderStatus.rect().height(),orderStatus);
    }
    painter->setClipRect(itemRect());
  }
Exemplo n.º 24
0
    void onDraw(SkCanvas* canvas) override {
        canvas->clear(SK_ColorBLACK);
        {
            sk_sp<SkImageFilter> bitmapSource(SkImageSource::Make(fImage));
            sk_sp<SkColorFilter> cf(SkColorFilter::MakeModeFilter(SK_ColorRED,
                                                                  SkBlendMode::kSrcIn));
            sk_sp<SkImageFilter> blur(SkBlurImageFilter::Make(4.0f, 4.0f, std::move(bitmapSource)));
            sk_sp<SkImageFilter> erode(SkErodeImageFilter::Make(4, 4, blur));
            sk_sp<SkImageFilter> color(SkColorFilterImageFilter::Make(std::move(cf),
                                                                      std::move(erode)));
            sk_sp<SkImageFilter> merge(SkMergeImageFilter::Make(blur, color,
                                                                SkBlendMode::kSrcOver));

            SkPaint paint;
            paint.setImageFilter(std::move(merge));
            canvas->drawPaint(paint);
            canvas->translate(SkIntToScalar(100), 0);
        }
        {
            sk_sp<SkImageFilter> morph(SkDilateImageFilter::Make(5, 5, nullptr));

            SkScalar matrix[20] = { SK_Scalar1, 0, 0, 0, 0,
                                    0, SK_Scalar1, 0, 0, 0,
                                    0, 0, SK_Scalar1, 0, 0,
                                    0, 0, 0, 0.5f, 0 };

            sk_sp<SkColorFilter> matrixFilter(SkColorFilter::MakeMatrixFilterRowMajor255(matrix));
            sk_sp<SkImageFilter> colorMorph(SkColorFilterImageFilter::Make(std::move(matrixFilter),
                                                                           std::move(morph)));
            SkPaint paint;
            paint.setImageFilter(SkXfermodeImageFilter::Make(SkBlendMode::kSrcOver,
                                                             std::move(colorMorph)));

            DrawClippedImage(canvas, fImage.get(), paint);
            canvas->translate(SkIntToScalar(100), 0);
        }
        {
            SkScalar matrix[20] = { SK_Scalar1, 0, 0, 0, 0,
                                    0, SK_Scalar1, 0, 0, 0,
                                    0, 0, SK_Scalar1, 0, 0,
                                    0, 0, 0, 0.5f, 0 };
            sk_sp<SkColorFilter> matrixCF(SkColorFilter::MakeMatrixFilterRowMajor255(matrix));
            sk_sp<SkImageFilter> matrixFilter(SkColorFilterImageFilter::Make(std::move(matrixCF),
                                                                             nullptr));
            sk_sp<SkImageFilter> offsetFilter(SkOffsetImageFilter::Make(10.0f, 10.f,
                                                                        matrixFilter));

            SkPaint paint;
            paint.setImageFilter(
                SkXfermodeImageFilter::MakeArithmetic(0, 1, 1, 0, true,
                                            std::move(matrixFilter),
                                            std::move(offsetFilter),
                                            nullptr));

            DrawClippedImage(canvas, fImage.get(), paint);
            canvas->translate(SkIntToScalar(100), 0);
        }
        {
            sk_sp<SkImageFilter> blur(SkBlurImageFilter::Make(SkIntToScalar(10),
                                                              SkIntToScalar(10),
                                                              nullptr));

            SkImageFilter::CropRect cropRect(SkRect::MakeWH(SkIntToScalar(95), SkIntToScalar(100)));
            SkPaint paint;
            paint.setImageFilter(
                SkXfermodeImageFilter::Make(SkBlendMode::kSrcIn, std::move(blur), nullptr,
                                            &cropRect));
            DrawClippedImage(canvas, fImage.get(), paint);
            canvas->translate(SkIntToScalar(100), 0);
        }
        {
            // Dilate -> matrix convolution.
            // This tests that a filter using asFragmentProcessor (matrix
            // convolution) correctly handles a non-zero source offset
            // (supplied by the dilate).
            sk_sp<SkImageFilter> dilate(SkDilateImageFilter::Make(5, 5, nullptr));

            SkScalar kernel[9] = {
                SkIntToScalar(-1), SkIntToScalar( -1 ), SkIntToScalar(-1),
                SkIntToScalar(-1), SkIntToScalar(  7 ), SkIntToScalar(-1),
                SkIntToScalar(-1), SkIntToScalar( -1 ), SkIntToScalar(-1),
            };
            SkISize kernelSize = SkISize::Make(3, 3);
            SkScalar gain = 1.0f, bias = SkIntToScalar(0);
            SkIPoint kernelOffset = SkIPoint::Make(1, 1);
            auto tileMode = SkMatrixConvolutionImageFilter::kClamp_TileMode;
            bool convolveAlpha = false;
            sk_sp<SkImageFilter> convolve(SkMatrixConvolutionImageFilter::Make(kernelSize,
                                                                               kernel,
                                                                               gain,
                                                                               bias,
                                                                               kernelOffset,
                                                                               tileMode,
                                                                               convolveAlpha,
                                                                               std::move(dilate)));

            SkPaint paint;
            paint.setImageFilter(std::move(convolve));
            DrawClippedImage(canvas, fImage.get(), paint);
            canvas->translate(SkIntToScalar(100), 0);
        }
        {
            // Test that crop offsets are absolute, not relative to the parent's crop rect.
            sk_sp<SkColorFilter> cf1(SkColorFilter::MakeModeFilter(SK_ColorBLUE,
                                                                   SkBlendMode::kSrcIn));
            sk_sp<SkColorFilter> cf2(SkColorFilter::MakeModeFilter(SK_ColorGREEN,
                                                                   SkBlendMode::kSrcIn));
            SkImageFilter::CropRect outerRect(SkRect::MakeXYWH(SkIntToScalar(10), SkIntToScalar(10),
                                                               SkIntToScalar(80), SkIntToScalar(80)));
            SkImageFilter::CropRect innerRect(SkRect::MakeXYWH(SkIntToScalar(20), SkIntToScalar(20),
                                                               SkIntToScalar(60), SkIntToScalar(60)));
            sk_sp<SkImageFilter> color1(SkColorFilterImageFilter::Make(std::move(cf1),
                                                                       nullptr,
                                                                       &outerRect));
            sk_sp<SkImageFilter> color2(SkColorFilterImageFilter::Make(std::move(cf2),
                                                                       std::move(color1),
                                                                       &innerRect));

            SkPaint paint;
            paint.setImageFilter(std::move(color2));
            paint.setColor(SK_ColorRED);
            canvas->drawRect(SkRect::MakeXYWH(0, 0, 100, 100), paint);
            canvas->translate(SkIntToScalar(100), 0);
        }
    }