📄 qwt_thermo.cpp
字号:
// // calculate recangles // if ( d_orient == Qt::Horizontal ) { if (inverted) { bRect.setRect(d_thermoRect.x(), d_thermoRect.y(), tval - d_thermoRect.x(), d_thermoRect.height()); if (alarm) { aRect.setRect(tval, d_thermoRect.y(), taval - tval + 1, d_thermoRect.height()); fRect.setRect(taval + 1, d_thermoRect.y(), d_thermoRect.x() + d_thermoRect.width() - (taval + 1), d_thermoRect.height()); } else { fRect.setRect(tval, d_thermoRect.y(), d_thermoRect.x() + d_thermoRect.width() - tval, d_thermoRect.height()); } } else { bRect.setRect(tval + 1, d_thermoRect.y(), d_thermoRect.width() - (tval + 1 - d_thermoRect.x()), d_thermoRect.height()); if (alarm) { aRect.setRect(taval, d_thermoRect.y(), tval - taval + 1, d_thermoRect.height()); fRect.setRect(d_thermoRect.x(), d_thermoRect.y(), taval - d_thermoRect.x(), d_thermoRect.height()); } else { fRect.setRect(d_thermoRect.x(), d_thermoRect.y(), tval - d_thermoRect.x() + 1, d_thermoRect.height()); } } } else // Qt::Vertical { if (tval < d_thermoRect.y()) tval = d_thermoRect.y(); else { if (tval > d_thermoRect.y() + d_thermoRect.height()) tval = d_thermoRect.y() + d_thermoRect.height(); } if (inverted) { bRect.setRect(d_thermoRect.x(), tval + 1, d_thermoRect.width(), d_thermoRect.height() - (tval + 1 - d_thermoRect.y())); if (alarm) { aRect.setRect(d_thermoRect.x(), taval, d_thermoRect.width(), tval - taval + 1); fRect.setRect(d_thermoRect.x(), d_thermoRect.y(), d_thermoRect.width(), taval - d_thermoRect.y()); } else { fRect.setRect(d_thermoRect.x(), d_thermoRect.y(), d_thermoRect.width(), tval - d_thermoRect.y() + 1); } } else { bRect.setRect(d_thermoRect.x(), d_thermoRect.y(), d_thermoRect.width(), tval - d_thermoRect.y()); if (alarm) { aRect.setRect(d_thermoRect.x(),tval, d_thermoRect.width(), taval - tval + 1); fRect.setRect(d_thermoRect.x(),taval + 1, d_thermoRect.width(), d_thermoRect.y() + d_thermoRect.height() - (taval + 1)); } else { fRect.setRect(d_thermoRect.x(),tval, d_thermoRect.width(), d_thermoRect.y() + d_thermoRect.height() - tval); } } } // // paint thermometer // p->fillRect(bRect, colorGroup().color(QColorGroup::Background)); if (alarm) p->fillRect(aRect, d_alarmColor); p->fillRect(fRect, d_fillColor);}//! Set the border width of the pipe.void QwtThermo::setBorderWidth(int w){ if ((w >= 0) && (w < (qwtMin(d_thermoRect.width(), d_thermoRect.height()) + d_borderWidth) / 2 - 1)) { d_borderWidth = w; layoutThermo(); }}/*! \brief Set the range \param vmin Value corresponding lower or left end of the thermometer \param vmax Value corresponding to the upper or right end of the thermometer*/void QwtThermo::setRange(double vmin, double vmax){ d_minValue = vmin; d_maxValue = vmax; d_map.setDblRange(d_minValue, d_maxValue); if (!hasUserScale()) { QwtScaleDiv oldscl(scaleDraw()->scaleDiv()); scaleDraw()->setScale(d_minValue, d_maxValue, scaleMaxMajor(), scaleMaxMinor()); if (oldscl != scaleDraw()->scaleDiv()) scaleChange(); } layoutThermo();}/*! \brief Change the color of the liquid. \param c New color. The default color is black.*/void QwtThermo::setFillColor(const QColor &c){ d_fillColor = c; update();}/*! \brief Specify liquid color above the alarm threshold \param c New color. The default is white.*/void QwtThermo::setAlarmColor(const QColor &c){ d_alarmColor = c; update();}//! Specify the alarm thresholdvoid QwtThermo::setAlarmLevel(double v){ d_alarmLevel = v; d_alarmEnabled = 1; update();}//! Change the width of the pipevoid QwtThermo::setPipeWidth(int w){ if (w > 0) { d_thermoWidth = w; layoutThermo(); }}/*! \brief Specify the distance between the pipe's endpoints and the widget's border The margin is used to leave some space for the scale labels. If a large font is used, it is advisable to adjust the margins. \param m New Margin. The default values are 10 for horizontal orientation and 20 for vertical orientation. \warning The margin has no effect if the scale is disabled. \warning This function is a NOOP because margins are determined automatically.*/void QwtThermo::setMargin(int){}/*! \brief Enable or disable alarm threshold \param tf \c ZERO (disabled) or non-zero (enabled)*/void QwtThermo::setAlarmEnabled(int tf){ d_alarmEnabled = tf; update();}/*! \return Fixed/MinimumExpanding for vertical, MinimumExpanding/Fixed for horizontal thermos.*/ QSizePolicy QwtThermo::sizePolicy() const{ QSizePolicy sp; if ( scaleDraw()->orientation() == QwtScaleDraw::Left || scaleDraw()->orientation() == QwtScaleDraw::Right ) { sp.setHorData( QSizePolicy::Fixed ); sp.setVerData( QSizePolicy::MinimumExpanding ); } else { sp.setHorData( QSizePolicy::MinimumExpanding ); sp.setVerData( QSizePolicy::Fixed ); } return sp;}/*! \return the minimum size hint \sa QwtThermo::minimumSizeHint*/QSize QwtThermo::sizeHint() const{ return minimumSizeHint();}/*! \brief Return a minimum size hint \warning The return value depends on the font and the scale. \sa QwtThermo::sizeHint*/QSize QwtThermo::minimumSizeHint() const{ int w = 0, h = 0; if ( d_scalePos != None ) { int smw = scaleDraw()->minWidth( QPen(), fontMetrics() ); int smh = scaleDraw()->minHeight( QPen(), fontMetrics() ); if ( d_orient == Qt::Vertical ) { w = d_thermoWidth + smw + 3 * d_borderWidth + d_scaleDist; h = smh + 2 * d_borderWidth; } else { w = smw + 2 * d_borderWidth; h = d_thermoWidth + smh + 3 * d_borderWidth + d_scaleDist; } } else // no scale { if ( d_orient == Qt::Vertical ) { w = d_thermoWidth + 2 * d_borderWidth; h = 200 + 2 * d_borderWidth; } else { w = 200 + 2 * d_borderWidth; h = d_thermoWidth + 2 * d_borderWidth; } } return QSize( w, h );}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -