18 #include <qdrawutil.h> 20 #include <qstyleoption.h> 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 )
126 QSizePolicy policy( QSizePolicy::MinimumExpanding, QSizePolicy::Fixed );
130 setSizePolicy( policy );
132 setAttribute( Qt::WA_WState_OwnSizePolicy,
false );
237 QPainter painter(
this );
238 painter.setClipRegion( event->region() );
242 style()->drawPrimitive(QStyle::PE_Widget, &opt, &painter,
this);
246 if ( !tRect.contains( event->rect() ) )
254 const QBrush brush = palette().brush( QPalette::Base );
255 qDrawShadePanel( &painter,
256 tRect.adjusted( -bw, -bw, bw, bw ),
279 switch( event->type() )
281 case QEvent::StyleChange:
282 case QEvent::FontChange:
374 if ( update_geometry )
392 mbd = qMax( d1, d2 );
395 const int scaleOff = bw + mbd;
397 const QRect cr = contentsRect();
402 pipeRect.adjust( scaleOff, 0, -scaleOff, 0 );
407 pipeRect.setTop( bw );
413 pipeRect.adjust( 0, scaleOff, 0, -scaleOff );
416 pipeRect.setLeft( bw );
439 if ( !testAttribute( Qt::WA_WState_OwnSizePolicy ) )
441 QSizePolicy sp = sizePolicy();
445 setAttribute( Qt::WA_WState_OwnSizePolicy,
false );
522 if ( testAttribute( Qt::WA_WState_Polished ) )
547 QPainter *painter,
const QRect &
pipeRect )
const 550 painter->setClipRect( pipeRect, Qt::IntersectClip );
551 painter->setPen( Qt::NoPen );
555 QRect liquidRect =
fillRect( pipeRect );
567 std::sort( values.begin(), values.end(), std::greater<double>() );
569 std::sort( values.begin(), values.end(), std::less<double>() );
572 if ( !values.isEmpty() )
574 from = qRound( scaleMap.
transform( values[0] ) );
580 for (
int i = 1; i < values.size(); i++ )
582 const int to = qRound( scaleMap.
transform( values[i] ) );
584 for (
int pos = from + 1; pos < to; pos++ )
607 painter->fillRect( r, palette().brush( QPalette::Highlight ) );
608 liquidRect = QRegion( liquidRect ).subtracted( r ).boundingRect();
612 painter->fillRect( liquidRect, palette().brush( QPalette::ButtonText ) );
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 );
882 const QMargins m = contentsMargins();
883 w += m.left() + m.right();
884 h += m.top() + m.bottom();
886 return QSize( w, h );
916 int to = qRound( scaleMap.
transform( origin ) );
924 fillRect.setLeft( from );
925 fillRect.setRight( to );
929 fillRect.setTop( from );
930 fillRect.setBottom( to );
933 return fillRect.normalized();
972 v1 = fillRect.left();
975 v2 = qMin( v2, increasing ? fillRect.right() : valuePos );
980 v1 = qMax( v1, increasing ? fillRect.left() : valuePos );
982 v2 = fillRect.right();
985 alarmRect.setRect( v1, fillRect.top(), v2 - v1 + 1, fillRect.height() );
993 v1 = qMax( v1, increasing ? fillRect.top() : valuePos );
995 v2 = fillRect.bottom();
1002 v2 = qMin( v2, increasing ? fillRect.bottom() : valuePos );
1004 alarmRect.setRect( fillRect.left(), v1, fillRect.width(), v2 - v1 + 1 );
1011 #include "moc_qwt_thermo.cpp"
The scale is right of a vertical or below of a horizontal slider.
virtual QSize minimumSizeHint() const QWT_OVERRIDE
double alarmLevel() const
void setScalePosition(ScalePosition)
Change the position of the scale.
virtual void paintEvent(QPaintEvent *) QWT_OVERRIDE
QwtInterval normalized() const
Normalize the limits of the interval.
An abstract base class for widgets having a scale.
QFlags< BorderFlag > BorderFlags
Border flags.
void setAlignment(Alignment)
The origin is specified using the origin() property.
void setLength(double length)
Qt::Orientation orientation() const
The scale is left of a vertical or above of a horizontal slider.
void setAbstractScaleDraw(QwtAbstractScaleDraw *)
Set a scale draw.
void setColorMap(QwtColorMap *)
Assign a color map for the fill color.
A class representing an interval.
OriginMode originMode() const
void setAlarmEnabled(bool)
Enable or disable the alarm threshold.
Max value is not included in the interval.
void setAlarmBrush(const QBrush &)
Specify the liquid brush above the alarm threshold.
The origin is the minimum of the scale.
void setFillBrush(const QBrush &)
Change the brush of the liquid.
void setRangeFlags(QwtInterval::BorderFlags)
Exclude/Include min/max values.
void setSpacing(int)
Change the spacing between pipe and scale.
QwtThermo(QWidget *parent=NULL)
virtual void setValue(double)
const QwtScaleMap & scaleMap() const
virtual void scaleChange() QWT_OVERRIDE
Notify a scale change.
static void qwtDrawLine(QPainter *painter, int pos, const QColor &color, const QRect &pipeRect, const QRect &liquidRect, Qt::Orientation orientation)
A class representing a scale division.
Qt::Orientation orientation
const QwtScaleMap & scaleMap() const
void getBorderDistHint(const QFont &, int &start, int &end) const
Determine the minimum border distance.
virtual void changeEvent(QEvent *) QWT_OVERRIDE
int minLength(const QFont &) const
void setOriginMode(OriginMode)
Change how the origin is determined.
QBrush alarmBrush() const
The origin is the maximum of the scale.
const QwtScaleDiv & scaleDiv() const
QwtColorMap is used to map values into colors.
static int sort(lua_State *L)
Min value is not included in the interval.
void setAlarmLevel(double)
virtual QSize sizeHint() const QWT_OVERRIDE
const QwtAbstractScaleDraw * abstractScaleDraw() const
QColor color(const QwtInterval &, double value) const
double invTransform(double p) const
Number of valid tick types.
QwtThermo::ScalePosition scalePosition
QwtInterval::BorderFlags rangeFlags
QwtThermo::OriginMode originMode
virtual ~QwtThermo()
Destructor.
virtual void draw(QPainter *, const QPalette &) const
Draw the scale.
double lowerBound() const
QwtInterval::BorderFlags rangeFlags() const
bool alarmEnabled() const
const QwtScaleDraw * scaleDraw() const
void setOrientation(Qt::Orientation)
Set the orientation.
virtual void resizeEvent(QResizeEvent *) QWT_OVERRIDE
void setScaleDraw(QwtScaleDraw *)
Set a scale draw.
QwtInterval interval() const
A class for drawing scales.
ScalePosition scalePosition() const
void setOrigin(double)
Specifies the custom origin.
double transform(double s) const
double upperBound() const
QRect fillRect(const QRect &) const
Calculate the filled rectangle of the pipe.
static QVector< double > qwtTickList(const QwtScaleDiv &scaleDiv)
QList< double > ticks(int tickType) const
virtual void drawLiquid(QPainter *, const QRect &) const
Min/Max values are inside the interval.
void move(double x, double y)
QRect alarmRect(const QRect &) const
Calculate the alarm rectangle of the pipe.