10 #include "qwt_thermo.h" 
   11 #include "qwt_scale_draw.h" 
   12 #include "qwt_scale_map.h" 
   13 #include "qwt_color_map.h" 
   18 #include <qdrawutil.h> 
   20 #include <qstyleoption.h> 
   26 static inline void qwtDrawLine( QPainter* painter, 
int pos,
 
   27     const QColor& color, 
const QRect& pipeRect, 
const QRect& liquidRect,
 
   28     Qt::Orientation orientation )
 
   30     painter->setPen( color );
 
   31     if ( orientation == Qt::Horizontal )
 
   33         if ( pos >= liquidRect.left() && pos < liquidRect.right() )
 
   34             painter->drawLine( pos, pipeRect.top(), pos, pipeRect.bottom() );
 
   38         if ( pos >= liquidRect.top() && pos < liquidRect.bottom() )
 
   39             painter->drawLine( pipeRect.left(), pos, pipeRect.right(), pos );
 
   50     if ( upperLimit < lowerLimit )
 
   51         qSwap( lowerLimit, upperLimit );
 
   60         for ( 
int i = 0; i < ticks.count(); i++ )
 
   62             const double v = ticks[i];
 
   63             if ( v > lowerLimit && v < upperLimit )
 
   73 class QwtThermo::PrivateData
 
   84         , autoFillPipe( true )
 
  124     m_data = 
new PrivateData;
 
  126     QSizePolicy policy( QSizePolicy::MinimumExpanding, QSizePolicy::Fixed );
 
  127     if ( m_data->orientation == Qt::Vertical )
 
  130     setSizePolicy( policy );
 
  132     setAttribute( Qt::WA_WState_OwnSizePolicy, 
false );
 
  133     layoutThermo( 
true );
 
  159     if ( m_data->rangeFlags != flags )
 
  161         m_data->rangeFlags = flags;
 
  172     return m_data->rangeFlags;
 
  183     if ( m_data->value != 
value )
 
  185         m_data->value = 
value;
 
  193     return m_data->value;
 
  210     layoutThermo( 
true );
 
  237     QPainter painter( 
this );
 
  238     painter.setClipRegion( event->region() );
 
  242     style()->drawPrimitive(QStyle::PE_Widget, &opt, &painter, 
this);
 
  246     if ( !tRect.contains( event->rect() ) )
 
  252     const int bw = m_data->borderWidth;
 
  254     const QBrush brush = palette().brush( QPalette::Base );
 
  255     qDrawShadePanel( &painter,
 
  256         tRect.adjusted( -bw, -bw, bw, bw ),
 
  258         m_data->autoFillPipe ? &brush : NULL );
 
  270     layoutThermo( 
false );
 
  279     switch( event->type() )
 
  281         case QEvent::StyleChange:
 
  282         case QEvent::FontChange:
 
  284             layoutThermo( 
true );
 
  299 void QwtThermo::layoutThermo( 
bool update_geometry )
 
  302     const int bw = m_data->borderWidth + m_data->spacing;
 
  307     if ( m_data->orientation == Qt::Horizontal )
 
  374     if ( update_geometry )
 
  392         mbd = qMax( d1, d2 );
 
  394     const int bw = m_data->borderWidth;
 
  395     const int scaleOff = bw + mbd;
 
  397     const QRect cr = contentsRect();
 
  400     if ( m_data->orientation == Qt::Horizontal )
 
  402         pipeRect.adjust( scaleOff, 0, -scaleOff, 0 );
 
  405             pipeRect.setTop( cr.top() + cr.height() - bw - m_data->pipeWidth );
 
  409         pipeRect.setHeight( m_data->pipeWidth );
 
  413         pipeRect.adjust( 0, scaleOff, 0, -scaleOff );
 
  418             pipeRect.setLeft( cr.left() + cr.width() - bw - m_data->pipeWidth );
 
  420         pipeRect.setWidth( m_data->pipeWidth );
 
  439     if ( !testAttribute( Qt::WA_WState_OwnSizePolicy ) )
 
  441         QSizePolicy sp = sizePolicy();
 
  445         setAttribute( Qt::WA_WState_OwnSizePolicy, 
false );
 
  448     layoutThermo( 
true );
 
  457     return m_data->orientation;
 
  466     if ( m == m_data->originMode )
 
  469     m_data->originMode = m;
 
  479     return m_data->originMode;
 
  493     if ( 
origin == m_data->origin )
 
  506     return m_data->origin;
 
  522     if ( testAttribute( Qt::WA_WState_Polished ) )
 
  523         layoutThermo( 
true );
 
  532     return m_data->scalePosition;
 
  538     layoutThermo( 
true );
 
  547     QPainter* painter, 
const QRect& pipeRect )
 const 
  550     painter->setClipRect( 
pipeRect, Qt::IntersectClip );
 
  551     painter->setPen( Qt::NoPen );
 
  557     if ( m_data->colorMap != NULL )
 
  567             std::sort( values.begin(), values.end(), std::greater< double >() );
 
  569             std::sort( values.begin(), values.end(), std::less< double >() );
 
  572         if ( !values.isEmpty() )
 
  575             qwtDrawLine( painter, from,
 
  576                 m_data->colorMap->color( interval, values[0] ),
 
  577                 pipeRect, liquidRect, m_data->orientation );
 
  580         for ( 
int i = 1; i < values.size(); i++ )
 
  584             for ( 
int pos = from + 1; pos < to; pos++ )
 
  588                 qwtDrawLine( painter, pos,
 
  589                     m_data->colorMap->color( interval, v ),
 
  590                     pipeRect, liquidRect, m_data->orientation );
 
  593             qwtDrawLine( painter, to,
 
  594                 m_data->colorMap->color( interval, values[i] ),
 
  595                 pipeRect, liquidRect, m_data->orientation );
 
  602         if ( !liquidRect.isEmpty() && m_data->alarmEnabled )
 
  607                 painter->fillRect( r, palette().brush( QPalette::Highlight ) );
 
  608                 liquidRect = QRegion( liquidRect ).subtracted( r ).boundingRect();
 
  612         painter->fillRect( liquidRect, palette().brush( QPalette::ButtonText ) );
 
  634     if ( 
spacing != m_data->spacing  )
 
  637         layoutThermo( 
true );
 
  647     return m_data->spacing;
 
  660     if ( width != m_data->borderWidth  )
 
  662         m_data->borderWidth = width;
 
  663         layoutThermo( 
true );
 
  673     return m_data->borderWidth;
 
  687         delete m_data->colorMap;
 
  699     return m_data->colorMap;
 
  709     return m_data->colorMap;
 
  722     QPalette pal = palette();
 
  723     pal.setBrush( QPalette::ButtonText, brush );
 
  733     return palette().brush( QPalette::ButtonText );
 
  749     QPalette pal = palette();
 
  750     pal.setBrush( QPalette::Highlight, brush );
 
  763     return palette().brush( QPalette::Highlight );
 
  777     m_data->alarmLevel = level;
 
  778     m_data->alarmEnabled = 1;
 
  791     return m_data->alarmLevel;
 
  804         m_data->pipeWidth = width;
 
  805         layoutThermo( 
true );
 
  815     return m_data->pipeWidth;
 
  827     m_data->alarmEnabled = on;
 
  839     return m_data->alarmEnabled;
 
  860     if ( m_data->scalePosition != 
NoScale )
 
  862         const int sdExtent = qwtCeil( 
scaleDraw()->extent( font() ) );
 
  866         h = m_data->pipeWidth + sdExtent + m_data->spacing;
 
  872         h = m_data->pipeWidth;
 
  875     if ( m_data->orientation == Qt::Vertical )
 
  878     w += 2 * m_data->borderWidth;
 
  879     h += 2 * m_data->borderWidth;
 
  882     const QMargins m = contentsMargins();
 
  883     w += m.left() + m.right();
 
  884     h += m.top() + m.bottom();
 
  886     return QSize( w, h );
 
  922     if ( m_data->orientation == Qt::Horizontal )
 
  948     if ( !m_data->alarmEnabled )
 
  956         increasing = m_data->value > m_data->origin;
 
  964     const int alarmPos = qRound( map.
transform( m_data->alarmLevel ) );
 
  965     const int valuePos = qRound( map.
transform( m_data->value ) );
 
  967     if ( m_data->orientation == Qt::Horizontal )
 
  975             v2 = qMin( v2, increasing ? 
fillRect.right() : valuePos );
 
  980             v1 = qMax( v1, increasing ? 
fillRect.left() : valuePos );
 
  993             v1 = qMax( v1, increasing ? 
fillRect.top() : valuePos );
 
 1002             v2 = qMin( v2, increasing ? 
fillRect.bottom() : valuePos );
 
 1011 #include "moc_qwt_thermo.cpp" 
const QwtScaleMap & scaleMap() const
virtual void draw(QPainter *, const QPalette &) const
Draw the scale.
An abstract base class for widgets having a scale.
const QwtScaleMap & scaleMap() const
double lowerBound() const
const QwtAbstractScaleDraw * abstractScaleDraw() const
const QwtScaleDiv & scaleDiv() const
void setAbstractScaleDraw(QwtAbstractScaleDraw *)
Set a scale draw.
double upperBound() const
QwtColorMap is used to map values into colors.
A class representing an interval.
QwtInterval normalized() const
Normalize the limits of the interval.
@ ExcludeMaximum
Max value is not included in the interval.
@ ExcludeMinimum
Min value is not included in the interval.
@ IncludeBorders
Min/Max values are inside the interval.
QFlags< BorderFlag > BorderFlags
Border flags.
A class representing a scale division.
QwtInterval interval() const
QList< double > ticks(int tickType) const
@ NTickTypes
Number of valid tick types.
A class for drawing scales.
void setLength(double length)
void move(double x, double y)
void getBorderDistHint(const QFont &, int &start, int &end) const
Determine the minimum border distance.
int minLength(const QFont &) const
void setAlignment(Alignment)
@ BottomScale
The scale is below.
@ TopScale
The scale is above.
@ RightScale
The scale is right.
@ LeftScale
The scale is left.
double transform(double s) const
double invTransform(double p) const
void setOrigin(double)
Specifies the custom origin.
void setScalePosition(ScalePosition)
Change the position of the scale.
void setAlarmEnabled(bool)
Enable or disable the alarm threshold.
void setAlarmLevel(double)
virtual void resizeEvent(QResizeEvent *) override
QwtThermo(QWidget *parent=NULL)
virtual void setValue(double)
const QwtScaleDraw * scaleDraw() const
void setAlarmBrush(const QBrush &)
Specify the liquid brush above the alarm threshold.
@ NoScale
The slider has no scale.
@ TrailingScale
The scale is left of a vertical or above of a horizontal slider.
@ LeadingScale
The scale is right of a vertical or below of a horizontal slider.
virtual void paintEvent(QPaintEvent *) override
void setSpacing(int)
Change the spacing between pipe and scale.
void setScaleDraw(QwtScaleDraw *)
Set a scale draw.
@ OriginMaximum
The origin is the maximum of the scale.
@ OriginCustom
The origin is specified using the origin() property.
@ OriginMinimum
The origin is the minimum of the scale.
void setOriginMode(OriginMode)
Change how the origin is determined.
QwtInterval::BorderFlags rangeFlags() const
double value() const
Return the value.
QBrush alarmBrush() const
void setRangeFlags(QwtInterval::BorderFlags)
Exclude/Include min/max values.
virtual void changeEvent(QEvent *) override
QRect fillRect(const QRect &) const
Calculate the filled rectangle of the pipe.
virtual QSize minimumSizeHint() const override
virtual void drawLiquid(QPainter *, const QRect &) const
void setFillBrush(const QBrush &)
Change the brush of the liquid.
virtual ~QwtThermo()
Destructor.
void setColorMap(QwtColorMap *)
Assign a color map for the fill color.
bool alarmEnabled() const
Qt::Orientation orientation() const
OriginMode originMode() const
void setOrientation(Qt::Orientation)
Set the orientation.
ScalePosition scalePosition() const
QRect alarmRect(const QRect &) const
Calculate the alarm rectangle of the pipe.
virtual void scaleChange() override
Notify a scale change.
double alarmLevel() const
virtual QSize sizeHint() const override