Ejemplo n.º 1
0
/*!
   Qt paint event handler
   \param event Paint event
*/
void QwtSlider::paintEvent( QPaintEvent *event )
{
    QPainter painter( this );
    painter.setClipRegion( event->region() );

    QStyleOption opt;
    opt.init(this);
    style()->drawPrimitive(QStyle::PE_Widget, &opt, &painter, this);

    if ( d_data->scalePosition != QwtSlider::NoScale )
    {
        if ( !d_data->sliderRect.contains( event->rect() ) )
            scaleDraw()->draw( &painter, palette() );
    }

    drawSlider( &painter, d_data->sliderRect );

    if ( hasFocus() )
        QwtPainter::drawFocusRect( &painter, this, d_data->sliderRect );
}
Ejemplo n.º 2
0
Archivo: dial.cpp Proyecto: z80/avrusb
Dial::Dial( QWidget * parent )
: QwtDial( parent ),
  d_label( "[a.u.]" )
{
    setWrapping( false );
    setReadOnly( true );

    setOrigin( 135.0 );
    setScaleArc( 0.0, 270.0 );
    scaleDraw()->setSpacing( 8 );

    QwtDialSimpleNeedle * needle = new QwtDialSimpleNeedle(
            QwtDialSimpleNeedle::Arrow, true, Qt::red, 
            QColor( Qt::gray ).light( 130 ) );
    setNeedle( needle );

    setScaleComponents( 
        QwtAbstractScaleDraw::Ticks | QwtAbstractScaleDraw::Labels );
    setScaleTicks( 0, 4, 8 );
}
Ejemplo n.º 3
0
/*!
  Draw the focus indicator
  \param painter Painter
*/
void QwtKnob::drawFocusIndicator( QPainter *painter ) const
{
    const QRect cr = contentsRect();

    int w = d_data->knobWidth;
    if ( w <= 0 )
    {
        w = qMin( cr.width(), cr.height() );
    }
    else
    {
        const int extent = qCeil( scaleDraw()->extent( font() ) );
        w += 2 * ( extent + d_data->scaleDist );
    }

    QRect focusRect( 0, 0, w, w );
    focusRect.moveCenter( cr.center() );

    QwtPainter::drawFocusRect( painter, this, focusRect );
}
Ejemplo n.º 4
0
//---------------------------------------------------------------------------
void VFXElement::draw (void)
{
	
	if (!noScaleDraw)
		scaleDraw (shapeTable, frameNum, x, y, reverse, fadeTable, scaleUp);
	else
	{
		//----------------------------------------------------------------
		// Check if shape is actually valid.
		if ((*(int*)shapeTable!=*(int*)"1.10"))
			return;
			
		if (!reverse)
		{
			if (!fadeTable)
				AG_shape_draw(globalPane,shapeTable,frameNum,x,y);
			else
			{
				AG_shape_lookaside(fadeTable);
				AG_shape_translate_draw(globalPane,shapeTable,frameNum,x,y);
			}
		}
		else		//45Pixel mechs dealt with here.
		{
			if (!tempBuffer)
				//tempBuffer = (MemoryPtr)systemHeap->Malloc(MAX_X * MAX_Y);
				tempBuffer = (MemoryPtr)gos_Malloc(MAX_X * MAX_Y); //magic 02102011

			if (fadeTable)
			{
				AG_shape_lookaside(fadeTable);
				AG_shape_translate_transform(globalPane,shapeTable,frameNum,x,y,tempBuffer,reverse,TRUE);
			}
			else
			{
				AG_shape_transform(globalPane,shapeTable,frameNum,x,y,tempBuffer,reverse,TRUE);
			}
		}
	}
	
}
void QwtAnalogClock::initClock()
{
    setWrapping( true );
    setReadOnly( true );

    setOrigin( 270.0 );
    setRange( 0.0, 60.0 * 60.0 * 12.0 ); // seconds
    setScale( -1, 5, 60.0 * 60.0 );

    setScaleComponents(
        QwtAbstractScaleDraw::Ticks | QwtAbstractScaleDraw::Labels );
    setScaleTicks( 1, 0, 8 );
    scaleDraw()->setSpacing( 8 );

    QColor knobColor = palette().color( QPalette::Active, QPalette::Text );
    knobColor = knobColor.dark( 120 );

    QColor handColor;
    int width;

    for ( int i = 0; i < NHands; i++ )
    {
        if ( i == SecondHand )
        {
            width = 2;
            handColor = knobColor.dark( 120 );
        }
        else
        {
            width = 8;
            handColor = knobColor;
        }

        QwtDialSimpleNeedle *hand = new QwtDialSimpleNeedle(
            QwtDialSimpleNeedle::Arrow, true, handColor, knobColor );
        hand->setWidth( width );

        d_hand[i] = NULL;
        setHand( ( Hand )i, hand );
    }
}
Ejemplo n.º 6
0
//! Recalculate the slider's geometry and layout based on
//  the current rect and fonts.
//  \param update_geometry  notify the layout system and call update
//         to redraw the scale
void QwtKnob::layoutKnob( bool update_geometry )
{
    const QRect &r = rect();

    const int width = qwtMin(qwtMin(r.height(), r.width()), d_knobWidth);
    const int width_2 = width / 2;

    d_kRect.setRect(r.x() + r.width() / 2 - width_2,
            r.y() + r.height() / 2 - width_2,
            width, width);

    scaleDraw()->setGeometry(d_kRect.x() - d_scaleDist,
            d_kRect.y() - d_scaleDist,
            width + 2 * d_scaleDist, QwtScaleDraw::Round );

    if ( update_geometry )
    {
        updateGeometry();
        update();
    }
}
Ejemplo n.º 7
0
/*!
  \return Bounding rectangle of the pipe ( without borders )
          in widget coordinates
*/
QRect QwtThermo::pipeRect() const
{
    int mbd = 0;
    if ( d_data->scalePosition != QwtThermo::NoScale )
    {
        int d1, d2;
        scaleDraw()->getBorderDistHint( font(), d1, d2 );
        mbd = qMax( d1, d2 );
    }
    const int bw = d_data->borderWidth;
    const int scaleOff = bw + mbd;

    const QRect cr = contentsRect();

    QRect pipeRect = cr;
    if ( d_data->orientation == Qt::Horizontal )
    {
        pipeRect.adjust( scaleOff, 0, -scaleOff, 0 );

        if ( d_data->scalePosition == QwtThermo::TrailingScale )
            pipeRect.setTop( cr.top() + cr.height() - bw - d_data->pipeWidth );
        else
            pipeRect.setTop( bw );

        pipeRect.setHeight( d_data->pipeWidth );
    }
    else // Qt::Vertical
    {
        pipeRect.adjust( 0, scaleOff, 0, -scaleOff );

        if ( d_data->scalePosition == QwtThermo::LeadingScale )
            pipeRect.setLeft( bw );
        else 
            pipeRect.setLeft( cr.left() + cr.width() - bw - d_data->pipeWidth );

        pipeRect.setWidth( d_data->pipeWidth );
    }

    return pipeRect;
}
Ejemplo n.º 8
0
/*!
  \brief Set the orientation.
  \param orientation Allowed values are Qt::Horizontal and Qt::Vertical.

  \sa orientation(), scalePosition()
*/
void QwtSlider::setOrientation( Qt::Orientation orientation )
{
    if ( orientation == d_data->orientation )
        return;

    d_data->orientation = orientation;

    scaleDraw()->setAlignment( 
        qwtScaleDrawAlignment( orientation, d_data->scalePosition ) );

    if ( !testAttribute( Qt::WA_WState_OwnSizePolicy ) )
    {
        QSizePolicy sp = sizePolicy();
        sp.transpose();
        setSizePolicy( sp );

        setAttribute( Qt::WA_WState_OwnSizePolicy, false );
    }

    if ( testAttribute( Qt::WA_WState_Polished ) )
        layoutSlider( true );
}
Ejemplo n.º 9
0
/*!
  Repaint the knob
  \param event Paint event
*/
void QwtKnob::paintEvent( QPaintEvent *event )
{
    QPainter painter( this );
    painter.setClipRegion( event->region() );

    QStyleOption opt;
    opt.init(this);
    style()->drawPrimitive(QStyle::PE_Widget, &opt, &painter, this);

    painter.setRenderHint( QPainter::Antialiasing, true );

    if ( !d_data->knobRect.contains( event->region().boundingRect() ) )
        scaleDraw()->draw( &painter, palette() );

    drawKnob( &painter, d_data->knobRect );
    drawMarker( &painter, d_data->knobRect, d_data->angle );

    painter.setRenderHint( QPainter::Antialiasing, false );

    if ( hasFocus() )
        QwtPainter::drawFocusRect( &painter, this );
}
Ejemplo n.º 10
0
/*!
  \brief Calculate the filled rectangle of the pipe

  \param pipeRect Rectangle of the pipe
  \return Rectangle to be filled ( fill and alarm brush )

  \sa pipeRect(), alarmRect()
 */
QRect QwtThermo::fillRect( const QRect &pipeRect ) const
{
    double origin;        
    if ( d_data->originMode == OriginMinimum )
    {
        origin = qMin( lowerBound(), upperBound() );
    }
    else if ( d_data->originMode == OriginMaximum )
    {
        origin = qMax( lowerBound(), upperBound() );
    }
    else // OriginCustom
    {
        origin = d_data->origin;
    }

    const QwtScaleMap scaleMap = scaleDraw()->scaleMap();

    int from = qRound( scaleMap.transform( d_data->value ) );
    int to = qRound( scaleMap.transform( origin ) );

    if ( to < from )
        qSwap( from, to );
    
    QRect fillRect = pipeRect;
    if ( d_data->orientation == Qt::Horizontal )
    {
        fillRect.setLeft( from );
        fillRect.setRight( to );
    }
    else // Qt::Vertical
    {
        fillRect.setTop( from );
        fillRect.setBottom( to );
    }

    return fillRect.normalized();
}
Ejemplo n.º 11
0
/*!
  \brief Constructor
  \param parent Parent widget
  \param name Name
*/
QwtKnob::QwtKnob(QWidget* parent, const char *name): 
    QwtSliderBase(Qt::Horizontal, parent, name, 
                Qt::WRepaintNoErase|Qt::WResizeNoErase)
{
    d_angle = 0.0;
    d_oldAngle = 0.0;
    d_nTurns = 0.0;
    d_borderWidth = 2;
    d_borderDist = 4;
    d_totalAngle = 270.0;
    d_scaleDist = 4;
    d_hasScale = 0;
    d_symbol = Line;
    d_maxScaleTicks = 11;
    d_knobWidth = 50;
    d_dotWidth = 8;

    scaleDraw()->setGeometry(
        0, 0, d_knobWidth + 2 * d_scaleDist, QwtScaleDraw::Round );
    setUpdateTime(50);
    setTotalAngle( 270.0 );
    recalcAngle();
    setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum));
}
Ejemplo n.º 12
0
/*!
  Recalculate the QwtThermo geometry and layout based on
  the QwtThermo::rect() and the fonts.
  \param update_geometry notify the layout system and call update
         to redraw the scale
*/
void QwtThermo::layoutThermo( bool update_geometry )
{
    QRect r = rect();
    int mbd = 0;
    if ( d_data->scalePos != NoScale )
    {
        int d1, d2;
        scaleDraw()->getBorderDistHint(font(), d1, d2);
        mbd = qwtMax(d1, d2);
    }

    if ( d_data->orientation == Qt::Horizontal )
    {
        switch ( d_data->scalePos )
        {
        case TopScale:
        {
            d_data->thermoRect.setRect(
                r.x() + mbd + d_data->borderWidth,
                r.y() + r.height()
                - d_data->thermoWidth - 2*d_data->borderWidth,
                r.width() - 2*(d_data->borderWidth + mbd),
                d_data->thermoWidth);
            scaleDraw()->setAlignment(QwtScaleDraw::TopScale);
            scaleDraw()->move( d_data->thermoRect.x(),
                               d_data->thermoRect.y() - d_data->borderWidth
                               - d_data->scaleDist);
            scaleDraw()->setLength(d_data->thermoRect.width());
            break;
        }

        case BottomScale:
        case NoScale: // like Bottom but without scale
        default:   // inconsistent orientation and scale position
            // Mapping between values and pixels requires
            // initialization of the scale geometry
        {
            d_data->thermoRect.setRect(
                r.x() + mbd + d_data->borderWidth,
                r.y() + d_data->borderWidth,
                r.width() - 2*(d_data->borderWidth + mbd),
                d_data->thermoWidth);
            scaleDraw()->setAlignment(QwtScaleDraw::BottomScale);
            scaleDraw()->move(
                d_data->thermoRect.x(),
                d_data->thermoRect.y() + d_data->thermoRect.height()
                + d_data->borderWidth + d_data->scaleDist );
            scaleDraw()->setLength(d_data->thermoRect.width());
            break;
        }
        }
        d_data->map.setPaintInterval(d_data->thermoRect.x(),
                                     d_data->thermoRect.x() + d_data->thermoRect.width() - 1);
    }
    else // Qt::Vertical
    {
        switch ( d_data->scalePos )
        {
        case RightScale:
        {
            d_data->thermoRect.setRect(
                r.x() + d_data->borderWidth,
                r.y() + mbd + d_data->borderWidth,
                d_data->thermoWidth,
                r.height() - 2*(d_data->borderWidth + mbd));
            scaleDraw()->setAlignment(QwtScaleDraw::RightScale);
            scaleDraw()->move(
                d_data->thermoRect.x() + d_data->thermoRect.width()
                + d_data->borderWidth + d_data->scaleDist,
                d_data->thermoRect.y());
            scaleDraw()->setLength(d_data->thermoRect.height());
            break;
        }

        case LeftScale:
        case NoScale: // like Left but without scale
        default:   // inconsistent orientation and scale position
            // Mapping between values and pixels requires
            // initialization of the scale geometry
        {
            d_data->thermoRect.setRect(
                r.x() + r.width() - 2*d_data->borderWidth - d_data->thermoWidth,
                r.y() + mbd + d_data->borderWidth,
                d_data->thermoWidth,
                r.height() - 2*(d_data->borderWidth + mbd));
            scaleDraw()->setAlignment(QwtScaleDraw::LeftScale);
            scaleDraw()->move(
                d_data->thermoRect.x() - d_data->scaleDist
                - d_data->borderWidth,
                d_data->thermoRect.y() );
            scaleDraw()->setLength(d_data->thermoRect.height());
            break;
        }
        }
        d_data->map.setPaintInterval(
            d_data->thermoRect.y() + d_data->thermoRect.height() - 1,
            d_data->thermoRect.y());
    }
    if ( update_geometry )
    {
        updateGeometry();
        update();
    }
}
Ejemplo n.º 13
0
/*!
  Recalculate the slider's geometry and layout based on
  the current rect and fonts.
  \param update_geometry  notify the layout system and call update
         to redraw the scale
*/
void QwtSlider::layoutSlider( bool update_geometry )
{
    int handleThickness;
    if ( orientation() == Qt::Horizontal )
        handleThickness = d_data->handleSize.width();
    else
        handleThickness = d_data->handleSize.height();

    int sld1 = handleThickness / 2 - 1;
    int sld2 = handleThickness / 2 + handleThickness % 2;

    if ( d_data->bgStyle & QwtSlider::Trough )
    {
        sld1 += d_data->borderWidth;
        sld2 += d_data->borderWidth;
    }

    int scd = 0;
    if ( d_data->scalePos != QwtSlider::NoScale )
    {
        int d1, d2;
        scaleDraw()->getBorderDistHint( font(), d1, d2 );
        scd = qMax( d1, d2 );
    }

    int slo = scd - sld1;
    if ( slo < 0 )
        slo = 0;

    int x, y, length;
    QRect sliderRect;

    length = x = y = 0;

    const QRect cr = contentsRect();
    if ( orientation() == Qt::Horizontal )
    {
        int sh = d_data->handleSize.height();
        if ( d_data->bgStyle & QwtSlider::Trough )
            sh += 2 * d_data->borderWidth;

        sliderRect.setLeft( cr.left() + slo );
        sliderRect.setRight( cr.right() - slo );
        sliderRect.setTop( cr.top() );
        sliderRect.setBottom( cr.top() + sh - 1);

        if ( d_data->scalePos == QwtSlider::BottomScale )
        {
            y = sliderRect.bottom() + d_data->spacing;
        }
        else if ( d_data->scalePos == QwtSlider::TopScale )
        {
            sliderRect.setTop( cr.bottom() - sh + 1 );
            sliderRect.setBottom( cr.bottom() );

            y = sliderRect.top() - d_data->spacing;
        }

        x = sliderRect.left() + sld1;
        length = sliderRect.width() - ( sld1 + sld2 );
    }
    else // Qt::Vertical
    {
        int sw = d_data->handleSize.width();
        if ( d_data->bgStyle & QwtSlider::Trough )
            sw += 2 * d_data->borderWidth;

        sliderRect.setLeft( cr.right() - sw + 1 );
        sliderRect.setRight( cr.right() );
        sliderRect.setTop( cr.top() + slo );
        sliderRect.setBottom( cr.bottom() - slo );

        if ( d_data->scalePos == QwtSlider::LeftScale )
        {
            x = sliderRect.left() - d_data->spacing;
        }
        else if ( d_data->scalePos == QwtSlider::RightScale )
        {
            sliderRect.setLeft( cr.left() );
            sliderRect.setRight( cr.left() + sw - 1);

            x = sliderRect.right() + d_data->spacing;
        }

        y = sliderRect.top() + sld1;
        length = sliderRect.height() - ( sld1 + sld2 );
    }

    d_data->sliderRect = sliderRect;

    scaleDraw()->move( x, y );
    scaleDraw()->setLength( length );

    d_data->map.setPaintInterval( scaleDraw()->scaleMap().p1(),
        scaleDraw()->scaleMap().p2() );

    if ( update_geometry )
    {
        d_data->sizeHintCache = QSize(); // invalidate
        updateGeometry();
        update();
    }
}
Ejemplo n.º 14
0
void QwtSlider::initSlider(Qt::Orientation orientation, 
    ScalePos scalePos, BGSTYLE bgStyle)
{
    if (orientation == Qt::Vertical) 
        setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding);
    else
        setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);

#if QT_VERSION >= 0x040000
    setAttribute(Qt::WA_WState_OwnSizePolicy, false);
#else
    clearWState( WState_OwnSizePolicy );
#endif


#if QT_VERSION < 0x040000
    setWFlags(Qt::WNoAutoErase);
#endif

    d_data = new QwtSlider::PrivateData;

    d_data->borderWidth = 2;
    d_data->scaleDist = 4;
    d_data->scalePos = scalePos;
    d_data->xMargin = 0;
    d_data->yMargin = 0;
    d_data->bgStyle = bgStyle;

    if (bgStyle == BgSlot)
    {
        d_data->thumbLength = 16;
        d_data->thumbWidth = 30;
    }
    else
    {
        d_data->thumbLength = 31;
        d_data->thumbWidth = 16;
    }

    d_data->sliderRect.setRect(0,0,8,8);

    QwtScaleDraw::Alignment align;
    if ( orientation == Qt::Vertical )
    {
        // enforce a valid combination of scale position and orientation
        if ((d_data->scalePos == BottomScale) || (d_data->scalePos == TopScale))
            d_data->scalePos = NoScale;
        // adopt the policy of layoutSlider (NoScale lays out like Left)
        if (d_data->scalePos == RightScale)
           align = QwtScaleDraw::RightScale;
        else
           align = QwtScaleDraw::LeftScale;
    }
    else
    {
        // enforce a valid combination of scale position and orientation
        if ((d_data->scalePos == LeftScale) || (d_data->scalePos == RightScale))
            d_data->scalePos = NoScale;
        // adopt the policy of layoutSlider (NoScale lays out like Bottom)
        if (d_data->scalePos == TopScale)
           align = QwtScaleDraw::TopScale;
        else
           align = QwtScaleDraw::BottomScale;
    }

    scaleDraw()->setAlignment(align);
    scaleDraw()->setLength(100);

    setRange(0.0, 100.0, 1.0);
    setValue(0.0);
}
Ejemplo n.º 15
0
/*!
  Recalculate the slider's geometry and layout based on
  the current rect and fonts.
  \param update_geometry  notify the layout system and call update
         to redraw the scale
*/
void QwtSlider::layoutSlider( bool update_geometry )
{
    int sliderWidth = d_thumbWidth;
    int sld1 = d_thumbLength / 2 - 1;
    int sld2 = d_thumbLength / 2 + d_thumbLength % 2;
    if ( d_bgStyle & BgTrough )
    {
        sliderWidth += 2 * d_borderWidth;
        sld1 += d_borderWidth;
        sld2 += d_borderWidth;
    }

    int scd = 0;
    if ( d_scalePos != None )
    {
        int d1, d2;
        scaleDraw()->minBorderDist(fontMetrics(), d1, d2);
        scd = QMAX(d1, d2);
    }

    int slo = scd - sld1;
    if ( slo < 0 )
        slo = 0;

    const QRect r = rect();
    if (orientation() == Qt::Horizontal)
    {
        switch (d_scalePos)
        {
        case Top:
            d_sliderRect.setRect(
        r.x() + d_xMargin + slo,
                r.y() + r.height() -
                d_yMargin - sliderWidth,
                r.width() - 2 * d_xMargin - 2 * slo,
                sliderWidth);
            scaleDraw()->setGeometry(
        d_sliderRect.x() + sld1,
                d_sliderRect.y() - d_scaleDist,
                d_sliderRect.width() - sld1 - sld2,
                QwtScaleDraw::Top);
            break;

        case Bottom:
            d_sliderRect.setRect(
        r.x() + d_xMargin + slo,
                r.y() + d_yMargin,
                r.width() - 2 * d_xMargin - 2 * slo,
                sliderWidth);
            scaleDraw()->setGeometry(
                d_sliderRect.x() + sld1,
                d_sliderRect.y() + d_sliderRect.height() + d_scaleDist,
                d_sliderRect.width() - sld1 - sld2,
                QwtScaleDraw::Bottom);
            break;

        case None: // like Bottom, but no scale. See QwtSlider().
        default:   // inconsistent orientation and scale position
            // QwtScaleDraw is derived from QwtDiMap.
            // The map serves to transform between coordinates and doubles.
            d_sliderRect.setRect(
                r.x() + d_xMargin + slo,
                r.y() + d_yMargin,
                r.width() - 2 * d_xMargin - 2 * slo,
                sliderWidth);
            scaleDraw()->setIntRange(
                d_sliderRect.x() + sld1,
                d_sliderRect.x() + d_sliderRect.width() - sld2 - 1);
            break;
        }
    }
    else // if (orientation() == Qt::Vertical
    {
        switch (d_scalePos)
        {
        case Right:
            d_sliderRect.setRect(
        r.x() + d_xMargin,
                r.y() + d_yMargin + slo,
                sliderWidth,
                r.height() - 2 * d_yMargin - 2 * slo);
            scaleDraw()->setGeometry(
        d_sliderRect.x() + d_sliderRect.width() + d_scaleDist,
                d_sliderRect.y() + sld1,
                d_sliderRect.height() - sld1 - sld2,
                QwtScaleDraw::Right);
            break;

        case Left:
            d_sliderRect.setRect(
        r.x() + r.width() - sliderWidth - d_xMargin,
                r.y() + d_yMargin + slo,
                sliderWidth,
                r.height() - 2 * d_yMargin - 2 * slo);
            scaleDraw()->setGeometry(
        d_sliderRect.x() - d_scaleDist,
                d_sliderRect.y() + sld1,
                d_sliderRect.height() - sld1 - sld2,
                QwtScaleDraw::Left);
            break;

        case None: // like Left, but no scale. See QwtSlider().
        default:   // inconsistent orientation and scale position
            // QwtScaleDraw is derived from QwtDiMap.
            // The map serves to transform between coordinates and doubles.
            d_sliderRect.setRect(
                r.x() + r.width() - sliderWidth - d_xMargin,
                r.y() + d_yMargin + slo,
                sliderWidth,
                r.height() - 2 * d_yMargin - 2 * slo);
            scaleDraw()->setIntRange(
                d_sliderRect.y() + d_sliderRect.height() - sld2 - 1,
                d_sliderRect.y() + sld1);
            break;
        }
    }

    if ( update_geometry )
    {
        updateGeometry();
        update();
    }
}
Ejemplo n.º 16
0
void TimelineWidget::draw(QPainter *pPainter, const QRect &update_rect)
{
   scaleDraw()->draw(pPainter, palette());

   if(mpD->animCount > 0)
   {
      const std::vector<Animation*> &animations = mpD->mpController->getAnimations();
      int ypos = mpD->animRect.y();
      for(std::vector<Animation*>::const_iterator animation = animations.begin(); animation != animations.end(); ++animation)
      {
         int xpos = transform((*animation)->getStartValue());
         int xend = transform((*animation)->getStopValue());
         int animWidth = xend - xpos;
         if(mpDragging == *animation)
         {
            int xdiff = mDragPos.x() - mDragStartPos.x();
            switch(mDragType)
            {
            case DRAGGING_MOVE:
               xpos += xdiff;
               break;
            case DRAGGING_LEFT:
               xpos += xdiff;
               animWidth -= xdiff;
               break;
            case DRAGGING_RIGHT:
               animWidth += xdiff;
               break;
            }
         }
         pPainter->setBrush(palette().brush(QPalette::Base));
         pPainter->drawRect(xpos, ypos, animWidth, mpD->animHeight);
         qDrawShadePanel(pPainter, xpos, ypos, animWidth, mpD->animHeight, palette());
         int textXpos = xpos + mpD->borderWidth;
         int textYpos = ypos + (fontMetrics().height() + mpD->animHeight) / 2;
         pPainter->drawText(textXpos, textYpos, QString::fromStdString((*animation)->getName()));
         if(mpDragging != *animation)
         {
            const std::vector<AnimationFrame> &frames = (*animation)->getFrames();
            pPainter->setPen(QPen(QBrush(Qt::lightGray), 1));
            int prevPos = 0;
            for(std::vector<AnimationFrame>::const_iterator frame = frames.begin(); frame != frames.end(); ++frame)
            {
               int framePos = transform((*animation)->getFrameType() == FRAME_ID ? frame->mFrameNumber : frame->mTime);
               while((framePos - prevPos) < 32 && ++frame != frames.end())
               {
                  framePos = transform((*animation)->getFrameType() == FRAME_ID ? frame->mFrameNumber : frame->mTime);
               }
               if(frame == frames.end())
               {
                  break;
               }
#pragma message(__FILE__ "(" STRING(__LINE__) ") : warning : Add code to draw thumbnails if they are available (tclarke)")
               pPainter->drawLine(framePos, ypos, framePos, ypos + mpD->animHeight);
               prevPos = framePos;
            }
         }
         ypos += mpD->animHeight + mpD->animSpacing;
      }
     int lineX = transform(mpD->mpController->getCurrentFrame());
     pPainter->setPen(QPen(QBrush(Qt::darkGreen), 1, Qt::DashLine, Qt::RoundCap));
     pPainter->drawLine(lineX, mpD->borderWidth, lineX, mpD->animRect.bottom());
   }
}
Ejemplo n.º 17
0
/*!
  Recalculate the slider's geometry and layout based on
  the current rect and fonts.
  \param update_geometry  notify the layout system and call update
         to redraw the scale
*/
void QwtSlider::layoutSlider( bool update_geometry )
{
    int sliderWidth = d_data->thumbWidth;
    int sld1 = d_data->thumbLength / 2 - 1;
    int sld2 = d_data->thumbLength / 2 + d_data->thumbLength % 2;
    if ( d_data->bgStyle & BgTrough )
    {
        sliderWidth += 2 * d_data->borderWidth;
        sld1 += d_data->borderWidth;
        sld2 += d_data->borderWidth;
    }

    int scd = 0;
    if ( d_data->scalePos != NoScale )
    {
        int d1, d2;
        scaleDraw()->getBorderDistHint(font(), d1, d2);
        scd = qwtMax(d1, d2);
    }

    int slo = scd - sld1;
    if ( slo < 0 )
        slo = 0;

    int x, y, length;

    const QRect r = rect();
    if (orientation() == Qt::Horizontal)
    {
        switch (d_data->scalePos)
        {
            case TopScale:
            {
                d_data->sliderRect.setRect(
                    r.x() + d_data->xMargin + slo,
                    r.y() + r.height() -
                    d_data->yMargin - sliderWidth,
                    r.width() - 2 * d_data->xMargin - 2 * slo,
                    sliderWidth);

                x = d_data->sliderRect.x() + sld1;
                y = d_data->sliderRect.y() - d_data->scaleDist;

                break;
            }

            case BottomScale:
            {
                d_data->sliderRect.setRect(
                    r.x() + d_data->xMargin + slo,
                    r.y() + d_data->yMargin,
                    r.width() - 2 * d_data->xMargin - 2 * slo,
                    sliderWidth);
    
                x = d_data->sliderRect.x() + sld1;
                y = d_data->sliderRect.y() + d_data->sliderRect.height() 
                    + d_data->scaleDist;

                break;
            }

            case NoScale: // like Bottom, but no scale. See QwtSlider().
            default:   // inconsistent orientation and scale position
            {
                d_data->sliderRect.setRect(
                    r.x() + d_data->xMargin + slo,
                    r.y() + d_data->yMargin,
                    r.width() - 2 * d_data->xMargin - 2 * slo,
                    sliderWidth);

                x = d_data->sliderRect.x() + sld1;
                y = 0;

                break;
            }
        }
        length = d_data->sliderRect.width() - (sld1 + sld2);
    }
    else // if (orientation() == Qt::Vertical
    {
        switch (d_data->scalePos)
        {
            case RightScale:
                d_data->sliderRect.setRect(
                    r.x() + d_data->xMargin,
                    r.y() + d_data->yMargin + slo,
                    sliderWidth,
                    r.height() - 2 * d_data->yMargin - 2 * slo);

                x = d_data->sliderRect.x() + d_data->sliderRect.width() 
                    + d_data->scaleDist;
                y = d_data->sliderRect.y() + sld1;

                break;

            case LeftScale:
                d_data->sliderRect.setRect(
                    r.x() + r.width() - sliderWidth - d_data->xMargin,
                    r.y() + d_data->yMargin + slo,
                    sliderWidth,
                    r.height() - 2 * d_data->yMargin - 2 * slo);

                x = d_data->sliderRect.x() - d_data->scaleDist;
                y = d_data->sliderRect.y() + sld1;

                break;

            case NoScale: // like Left, but no scale. See QwtSlider().
            default:   // inconsistent orientation and scale position
                d_data->sliderRect.setRect(
                    r.x() + r.width() - sliderWidth - d_data->xMargin,
                    r.y() + d_data->yMargin + slo,
                    sliderWidth,
                    r.height() - 2 * d_data->yMargin - 2 * slo);

                x = 0;
                y = d_data->sliderRect.y() + sld1;

                break;
        }
        length = d_data->sliderRect.height() - (sld1 + sld2);
    }

    scaleDraw()->move(x, y);
    scaleDraw()->setLength(length);

    d_data->map.setPaintXInterval(scaleDraw()->map().p1(),
        scaleDraw()->map().p2());

    if ( update_geometry )
    {
        d_data->sizeHintCache = QSize(); // invalidate
        updateGeometry();
        update();
    }
}
Ejemplo n.º 18
0
/*!
  Recalculate the slider's geometry and layout based on
  the current geometry and fonts.

  \param update_geometry  notify the layout system and call update
         to redraw the scale
*/
void QwtSlider::layoutSlider( bool update_geometry )
{
    int bw = 0;
    if ( d_data->hasTrough )
        bw = d_data->borderWidth;

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

    QRect sliderRect = contentsRect();

    /*
       The marker line of the handle needs to be aligned to
       the scale. But the marker is in the center 
       and we need space enough to display the rest of the handle.

       But the scale itself usually needs margins for displaying
       the tick labels, that also might needs space beyond the
       backbone.

       Now it depends on what needs more margins. If it is the
       slider the scale gets shrunk, otherwise the slider.
     */

    int scaleMargin = 0;
    if ( d_data->scalePosition != QwtSlider::NoScale )
    {
        int d1, d2;
        scaleDraw()->getBorderDistHint( font(), d1, d2 );

        scaleMargin = qMax( d1, d2 ) - bw;
    }

    int scaleX, scaleY, scaleLength;

    if ( d_data->orientation == Qt::Horizontal )
    {
        const int handleMargin = handleSize.width() / 2 - 1;
        if ( scaleMargin > handleMargin )
        {
            int off = scaleMargin - handleMargin;
            sliderRect.adjust( off, 0, -off, 0 );
        }

        scaleX = sliderRect.left() + bw + handleSize.width() / 2 - 1;
        scaleLength = sliderRect.width() - handleSize.width();
    }
    else
    {
        int handleMargin = handleSize.height() / 2 - 1;
        if ( scaleMargin > handleMargin )
        {
            int off = scaleMargin - handleMargin;
            sliderRect.adjust( 0, off, 0, -off );
        }

        scaleY = sliderRect.top() + bw + handleSize.height() / 2 - 1;
        scaleLength = sliderRect.height() - handleSize.height();
    }

    scaleLength -= 2 * bw;

    // now align slider and scale according to the ScalePosition

    if ( d_data->orientation == Qt::Horizontal )
    {
        const int h = handleSize.height() + 2 * bw;

        if ( d_data->scalePosition == QwtSlider::TrailingScale )
        {
            sliderRect.setTop( sliderRect.bottom() + 1 - h );
            scaleY = sliderRect.top() - d_data->spacing;
        }
        else
        {
            sliderRect.setHeight( h );
            scaleY = sliderRect.bottom() + 1 + d_data->spacing;
        }
    }
    else // Qt::Vertical
    {
        const int w = handleSize.width() + 2 * bw;

        if ( d_data->scalePosition == QwtSlider::LeadingScale )
        {
            sliderRect.setWidth( w );
            scaleX = sliderRect.right() + 1 + d_data->spacing;
        }
        else
        {
            sliderRect.setLeft( sliderRect.right() + 1 - w );
            scaleX = sliderRect.left() - d_data->spacing;
        }
    }

    d_data->sliderRect = sliderRect;

    scaleDraw()->move( scaleX, scaleY );
    scaleDraw()->setLength( scaleLength );

    if ( update_geometry )
    {
        d_data->sizeHintCache = QSize(); // invalidate
        updateGeometry();
        update();
    }
}
Ejemplo n.º 19
0
/*!
  \return Minimum size hint
  \sa sizeHint()
*/
QSize QwtSlider::minimumSizeHint() const
{
    if ( !d_data->sizeHintCache.isEmpty() )
        return d_data->sizeHintCache;

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

    int bw = 0;
    if ( d_data->hasTrough )
        bw = d_data->borderWidth;

    int sliderLength = 0; 
    int scaleExtent = 0;

    if ( d_data->scalePosition != QwtSlider::NoScale )
    {
        int d1, d2;
        scaleDraw()->getBorderDistHint( font(), d1, d2 );

        const int scaleBorderDist = 2 * ( qMax( d1, d2 ) - bw );

        int handleBorderDist;
        if ( d_data->orientation == Qt::Horizontal )
            handleBorderDist = handleSize.width();
        else
            handleBorderDist = handleSize.height();

        sliderLength = scaleDraw()->minLength( font() );
        if ( handleBorderDist > scaleBorderDist )
        {
            // We need additional space for the overlapping handle
            sliderLength += handleBorderDist - scaleBorderDist;
        }

        scaleExtent += d_data->spacing;
        scaleExtent += qCeil( scaleDraw()->extent( font() ) );
    }

    sliderLength = qMax( sliderLength, 84 ); // from QSlider

    int w = 0;
    int h = 0;

    if ( d_data->orientation == Qt::Horizontal )
    {
        w = sliderLength;
        h = handleSize.height() + 2 * bw + scaleExtent;
    }
    else
    {
        w = handleSize.width() + 2 * bw + scaleExtent;
        h = sliderLength;
    }

    // finally add margins
    int left, right, top, bottom;
    getContentsMargins( &left, &top, &right, &bottom );

    w += left + right;
    h += top + bottom;

    d_data->sizeHintCache = QSize( w, h );
    return d_data->sizeHintCache;
}
Ejemplo n.º 20
0
/*!
  \return Bounding rectangle of the pipe ( without borders )
          in widget coordinates
*/
QRect QwtThermo::pipeRect() const
{
    const QRect cr = contentsRect();

    int mbd = 0;
    if ( d_data->scalePos != NoScale )
    {
        int d1, d2;
        scaleDraw()->getBorderDistHint( font(), d1, d2 );
        mbd = qMax( d1, d2 );
    }
    int bw = d_data->borderWidth;

    QRect tRect;
    if ( d_data->orientation == Qt::Horizontal )
    {
        switch ( d_data->scalePos )
        {
            case TopScale:
            {
                tRect.setRect(
                    cr.x() + mbd + bw,
                    cr.y() + cr.height() - d_data->pipeWidth - 2 * bw,
                    cr.width() - 2 * ( bw + mbd ),
                    d_data->pipeWidth 
                );
                break;
            }

            case BottomScale:
            case NoScale: 
            default:   
            {
                tRect.setRect(
                    cr.x() + mbd + bw,
                    cr.y() + d_data->borderWidth,
                    cr.width() - 2 * ( bw + mbd ),
                    d_data->pipeWidth 
                );
                break;
            }
        }
    }
    else // Qt::Vertical
    {
        switch ( d_data->scalePos )
        {
            case RightScale:
            {
                tRect.setRect(
                    cr.x() + bw,
                    cr.y() + mbd + bw,
                    d_data->pipeWidth,
                    cr.height() - 2 * ( bw + mbd ) 
                );
                break;
            }
            case LeftScale:
            case NoScale: 
            default:   
            {
                tRect.setRect(
                    cr.x() + cr.width() - 2 * bw - d_data->pipeWidth,
                    cr.y() + mbd + bw,
                    d_data->pipeWidth,
                    cr.height() - 2 * ( bw + mbd ) );
                break;
            }
        }
    }

    return tRect;
}
Ejemplo n.º 21
0
/*!
  Recalculate the QwtThermo geometry and layout based on
  the QwtThermo::contentsRect() and the fonts.

  \param update_geometry notify the layout system and call update
         to redraw the scale
*/
void QwtThermo::layoutThermo( bool update_geometry )
{
    const QRect tRect = pipeRect();
    const int bw = d_data->borderWidth + d_data->spacing;
    const bool inverted = ( maxValue() < minValue() );

    int from, to;

    if ( d_data->orientation == Qt::Horizontal )
    {
        from = tRect.left();
        to = tRect.right();

        if ( d_data->rangeFlags & QwtInterval::ExcludeMinimum )
        {
            if ( inverted )
                to++;
            else
                from--;
        }
        if ( d_data->rangeFlags & QwtInterval::ExcludeMaximum )
        {
            if ( inverted )
                from--;
            else
                to++;
        }

        switch ( d_data->scalePos )
        {
            case TopScale:
            {
                scaleDraw()->setAlignment( QwtScaleDraw::TopScale );
                scaleDraw()->move( from, tRect.top() - bw );
                scaleDraw()->setLength( to - from );
                break;
            }

            case BottomScale:
            case NoScale: 
            default:
            {
                scaleDraw()->setAlignment( QwtScaleDraw::BottomScale );
                scaleDraw()->move( from, tRect.bottom() + bw );
                scaleDraw()->setLength( to - from );
                break;
            }
        }

        d_data->map.setPaintInterval( from, to );
    }
    else // Qt::Vertical
    {
        from = tRect.top();
        to = tRect.bottom();

        if ( d_data->rangeFlags & QwtInterval::ExcludeMinimum )
        {
            if ( inverted )
                from--;
            else
                to++;
        }
        if ( d_data->rangeFlags & QwtInterval::ExcludeMaximum )
        {
            if ( inverted )
                to++;
            else
                from--;
        }

        switch ( d_data->scalePos )
        {
            case RightScale:
            {
                scaleDraw()->setAlignment( QwtScaleDraw::RightScale );
                scaleDraw()->move( tRect.right() + bw, from );
                scaleDraw()->setLength( to - from );
                break;
            }

            case LeftScale:
            case NoScale: 
            default:
            {
                scaleDraw()->setAlignment( QwtScaleDraw::LeftScale );
                scaleDraw()->move( tRect.left() - bw, from );
                scaleDraw()->setLength( to - from );
                break;
            }
        }
        d_data->map.setPaintInterval( to, from );
    }

    if ( update_geometry )
    {
        updateGeometry();
        update();
    }
}
Ejemplo n.º 22
0
/*!
   Redraw the liquid in thermometer pipe.
   \param painter Painter
   \param pipeRect Bounding rectangle of the pipe without borders
*/
void QwtThermo::drawLiquid( 
    QPainter *painter, const QRect &pipeRect ) const
{
    painter->save();
    painter->setClipRect( pipeRect, Qt::IntersectClip );

    const bool inverted = ( maxValue() < minValue() );
    if ( d_data->colorMap != NULL )
    {
        QwtInterval interval( d_data->minValue, d_data->maxValue );
        interval = interval.normalized();

        // Because the positions of the ticks are rounded
        // we calculate the colors for the rounded tick values

        QVector<double> values = qwtTickList(
            scaleDraw()->scaleDiv(), d_data->value );

        if ( d_data->map.isInverting() )
            qSort( values.begin(), values.end(), qGreater<double>() );
        else
            qSort( values.begin(), values.end(), qLess<double>() );

        int from;
        if ( !values.isEmpty() )
        {
            from = qRound( d_data->map.transform( values[0] ) );
            qwtDrawLine( painter, from,
                d_data->colorMap->color( interval, values[0] ),
                pipeRect, d_data->orientation );
        }

        for ( int i = 1; i < values.size(); i++ )
        {
            const int to = qRound( d_data->map.transform( values[i] ) );

            for ( int pos = from + 1; pos < to; pos++ )
            {
                const double v = d_data->map.invTransform( pos );

                qwtDrawLine( painter, pos, 
                    d_data->colorMap->color( interval, v ),
                    pipeRect, d_data->orientation );
            }
            qwtDrawLine( painter, to,
                d_data->colorMap->color( interval, values[i] ),
                pipeRect, d_data->orientation );

            from = to;
        }
    }
    else
    {
        const int tval = qRound( d_data->map.transform( d_data->value ) );

        QRect fillRect = pipeRect;
        if ( d_data->orientation == Qt::Horizontal )
        {
            if ( inverted )
                fillRect.setLeft( tval );
            else
                fillRect.setRight( tval );
        }
        else // Qt::Vertical
        {
            if ( inverted )
                fillRect.setBottom( tval );
            else
                fillRect.setTop( tval );
        }

        if ( d_data->alarmEnabled &&
            d_data->value >= d_data->alarmLevel )
        {
            QRect alarmRect = fillRect;

            const int taval = qRound( d_data->map.transform( d_data->alarmLevel ) );
            if ( d_data->orientation == Qt::Horizontal )
            {
                if ( inverted )
                    alarmRect.setRight( taval );
                else
                    alarmRect.setLeft( taval );
            }
            else
            {
                if ( inverted )
                    alarmRect.setTop( taval );
                else
                    alarmRect.setBottom( taval );
            }

            fillRect = QRegion( fillRect ).subtracted( alarmRect ).boundingRect();

            painter->fillRect( alarmRect, palette().brush( QPalette::Highlight ) );
        }

        painter->fillRect( fillRect, palette().brush( QPalette::ButtonText ) );
    }

    painter->restore();
}
Ejemplo n.º 23
0
/*!
  Recalculate the QwtThermo geometry and layout based on
  pipeRect() and the fonts.

  \param update_geometry notify the layout system and call update
         to redraw the scale
*/
void QwtThermo::layoutThermo( bool update_geometry )
{
    const QRect tRect = pipeRect();
    const int bw = d_data->borderWidth + d_data->spacing;
    const bool inverted = ( upperBound() < lowerBound() );

    int from, to;

    if ( d_data->orientation == Qt::Horizontal )
    {
        from = tRect.left();
        to = tRect.right();

        if ( d_data->rangeFlags & QwtInterval::ExcludeMinimum )
        {
            if ( inverted )
                to++;
            else
                from--;
        }
        if ( d_data->rangeFlags & QwtInterval::ExcludeMaximum )
        {
            if ( inverted )
                from--;
            else
                to++;
        }

        if ( d_data->scalePosition == QwtThermo::TrailingScale )
        {
            scaleDraw()->setAlignment( QwtScaleDraw::TopScale );
            scaleDraw()->move( from, tRect.top() - bw );
        }
        else
        {
            scaleDraw()->setAlignment( QwtScaleDraw::BottomScale );
            scaleDraw()->move( from, tRect.bottom() + bw );
        }

        scaleDraw()->setLength( qMax( to - from, 0 ) );
    }
    else // Qt::Vertical
    {
        from = tRect.top();
        to = tRect.bottom();

        if ( d_data->rangeFlags & QwtInterval::ExcludeMinimum )
        {
            if ( inverted )
                from--;
            else
                to++;
        }
        if ( d_data->rangeFlags & QwtInterval::ExcludeMaximum )
        {
            if ( inverted )
                to++;
            else
                from--;
        }

        if ( d_data->scalePosition == QwtThermo::LeadingScale )
        {
            scaleDraw()->setAlignment( QwtScaleDraw::RightScale );
            scaleDraw()->move( tRect.right() + bw, from );
        }
        else
        {
            scaleDraw()->setAlignment( QwtScaleDraw::LeftScale );
            scaleDraw()->move( tRect.left() - bw, from );
        }

        scaleDraw()->setLength( qMax( to - from, 0 ) );
    }

    if ( update_geometry )
    {
        updateGeometry();
        update();
    }
}
Ejemplo n.º 24
0
void QwtSlider::initSlider( Qt::Orientation orientation,
    ScalePos scalePos, BackgroundStyles bgStyle )
{
    if ( orientation == Qt::Vertical )
        setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Expanding );
    else
        setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );

    setAttribute( Qt::WA_WState_OwnSizePolicy, false );

    d_data = new QwtSlider::PrivateData;

    d_data->borderWidth = 2;
    d_data->spacing = 4;
    d_data->scalePos = scalePos;
    d_data->bgStyle = bgStyle;

    const int handleThickness = 16;
    d_data->handleSize.setWidth( 2 * handleThickness );
    d_data->handleSize.setHeight( handleThickness );

    if ( !( bgStyle & QwtSlider::Trough ) )
        d_data->handleSize.transpose();

    if ( orientation == Qt::Vertical )
        d_data->handleSize.transpose();

    d_data->sliderRect.setRect( 0, 0, 8, 8 );

    QwtScaleDraw::Alignment align;
    if ( orientation == Qt::Vertical )
    {
        // enforce a valid combination of scale position and orientation
        if ( ( d_data->scalePos == QwtSlider::BottomScale ) 
            || ( d_data->scalePos == QwtSlider::TopScale ) )
        {
            d_data->scalePos = NoScale;
        }

        // adopt the policy of layoutSlider (NoScale lays out like Left)
        if ( d_data->scalePos == QwtSlider::RightScale )
            align = QwtScaleDraw::RightScale;
        else
            align = QwtScaleDraw::LeftScale;
    }
    else
    {
        // enforce a valid combination of scale position and orientation
        if ( ( d_data->scalePos == QwtSlider::LeftScale ) 
            || ( d_data->scalePos == QwtSlider::RightScale ) )
        {
            d_data->scalePos = QwtSlider::NoScale;
        }

        // adopt the policy of layoutSlider (NoScale lays out like Bottom)
        if ( d_data->scalePos == QwtSlider::TopScale )
            align = QwtScaleDraw::TopScale;
        else
            align = QwtScaleDraw::BottomScale;
    }

    scaleDraw()->setAlignment( align );
    scaleDraw()->setLength( 100 );

    setRange( 0.0, 100.0, 1.0 );
    setValue( 0.0 );
}
Ejemplo n.º 25
0
/*!
  \brief Calculate the alarm rectangle of the pipe

  \param fillRect Filled rectangle in the pipe
  \return Rectangle to be filled with the alarm brush

  \sa pipeRect(), fillRect(), alarmLevel(), alarmBrush()
 */
QRect QwtThermo::alarmRect( const QRect &fillRect ) const
{
    QRect alarmRect( 0, 0, -1, -1); // something invalid

    if ( !d_data->alarmEnabled )
        return alarmRect;

    const bool inverted = ( upperBound() < lowerBound() );
    
    bool increasing;
    if ( d_data->originMode == OriginCustom )
    {
        increasing = d_data->value > d_data->origin;
    }
    else
    {
        increasing = d_data->originMode == OriginMinimum;
    }

    const QwtScaleMap map = scaleDraw()->scaleMap();
    const int alarmPos = qRound( map.transform( d_data->alarmLevel ) );
    const int valuePos = qRound( map.transform( d_data->value ) );
    
    if ( d_data->orientation == Qt::Horizontal )
    {
        int v1, v2;
        if ( inverted )
        {
            v1 = fillRect.left();

            v2 = alarmPos - 1;
            v2 = qMin( v2, increasing ? fillRect.right() : valuePos );
        }
        else
        {
            v1 = alarmPos + 1;
            v1 = qMax( v1, increasing ? fillRect.left() : valuePos );

            v2 = fillRect.right();

        }
        alarmRect.setRect( v1, fillRect.top(), v2 - v1 + 1, fillRect.height() );
    }
    else
    {
        int v1, v2;
        if ( inverted )
        {
            v1 = alarmPos + 1;
            v1 = qMax( v1, increasing ? fillRect.top() : valuePos );

            v2 = fillRect.bottom();
        }
        else
        {
            v1 = fillRect.top();

            v2 = alarmPos - 1;
            v2 = qMin( v2, increasing ? fillRect.bottom() : valuePos );
        }
        alarmRect.setRect( fillRect.left(), v1, fillRect.width(), v2 - v1 + 1 );
    }

    return alarmRect;
} 
Ejemplo n.º 26
0
/*!
   Redraw the liquid in thermometer pipe.
   \param painter Painter
   \param pipeRect Bounding rectangle of the pipe without borders
*/
void QwtThermo::drawLiquid( 
    QPainter *painter, const QRect &pipeRect ) const
{
    painter->save();
    painter->setClipRect( pipeRect, Qt::IntersectClip );
    painter->setPen( Qt::NoPen );

    const QwtScaleMap scaleMap = scaleDraw()->scaleMap();

    QRect liquidRect = fillRect( pipeRect );

    if ( d_data->colorMap != NULL )
    {
        const QwtInterval interval = scaleDiv().interval().normalized();

        // Because the positions of the ticks are rounded
        // we calculate the colors for the rounded tick values

        QVector<double> values = qwtTickList( scaleDraw()->scaleDiv() );

        if ( scaleMap.isInverting() )
            qSort( values.begin(), values.end(), qGreater<double>() );
        else
            qSort( values.begin(), values.end(), qLess<double>() );

        int from;
        if ( !values.isEmpty() )
        {
            from = qRound( scaleMap.transform( values[0] ) );
            qwtDrawLine( painter, from,
                d_data->colorMap->color( interval, values[0] ),
                pipeRect, liquidRect, d_data->orientation );
        }

        for ( int i = 1; i < values.size(); i++ )
        {
            const int to = qRound( scaleMap.transform( values[i] ) );

            for ( int pos = from + 1; pos < to; pos++ )
            {
                const double v = scaleMap.invTransform( pos );

                qwtDrawLine( painter, pos, 
                    d_data->colorMap->color( interval, v ),
                    pipeRect, liquidRect, d_data->orientation );
            }

            qwtDrawLine( painter, to,
                d_data->colorMap->color( interval, values[i] ),
                pipeRect, liquidRect, d_data->orientation );

            from = to;
        }
    }
    else
    {
        if ( !liquidRect.isEmpty() && d_data->alarmEnabled )
        {
            const QRect r = alarmRect( liquidRect );
            if ( !r.isEmpty() )
            {
                painter->fillRect( r, palette().brush( QPalette::Highlight ) );
                liquidRect = QRegion( liquidRect ).subtracted( r ).boundingRect();
            }
        }

        painter->fillRect( liquidRect, palette().brush( QPalette::ButtonText ) );
    }

    painter->restore();
}