📄 qwt_scale.cpp
字号:
\sa QwtScale::setBorderDist*/int QwtScale::endBorderDist() const { return d_borderDist[1]; }/*! \return base line distance \sa QwtScale::setBaselineDist*/int QwtScale::baseLineDist() const { return d_baseDist; }/*! \return distance between scale and title \sa QwtScale::setBaselineDist*/int QwtScale::titleDist() const { return d_titleDist; }/*! \brief paintEvent*/void QwtScale::paintEvent(QPaintEvent *e){ const QRect &ur = e->rect(); if ( ur.isValid() ) { QwtPaintBuffer paintBuffer(this, ur); draw(paintBuffer.painter()); }}/*! \brief draw the scale*/void QwtScale::draw(QPainter *p) const{ d_scaleDraw->draw(p); QRect r = rect(); switch(d_scaleDraw->orientation()) { case QwtScaleDraw::Bottom: r.setTop( r.top() + d_titleOffset ); break; case QwtScaleDraw::Left: r.setRight( r.right() - d_titleOffset ); break; case QwtScaleDraw::Right: r.setLeft( r.left() + d_titleOffset ); break; case QwtScaleDraw::Top: default: r.setBottom( r.bottom() - d_titleOffset ); break; } drawTitle(p, d_scaleDraw->orientation(), r);}/*! \brief resizeEvent*/void QwtScale::resizeEvent(QResizeEvent *){ layoutScale(FALSE);}//! Recalculate the scale's geometry and layout based on// the current rect and fonts.// \param update_geometry notify the layout system and call update// to redraw the scalevoid QwtScale::layoutScale( bool update_geometry ){ QRect r = this->rect(); // Borders cannot be less than the minBorderDist int bd0, bd1; minBorderDist(bd0, bd1); if ( d_borderDist[0] > bd0 ) bd0 = d_borderDist[0]; if ( d_borderDist[1] > bd1 ) bd1 = d_borderDist[1]; const QFontMetrics fm(font()); switch(d_scaleDraw->orientation()) { case QwtScaleDraw::Bottom: d_scaleDraw->setGeometry(r.x() + bd0, r.y() + d_baseDist, r.width() - bd0 - bd1, QwtScaleDraw::Bottom); d_titleOffset = d_titleDist + d_baseDist + d_scaleDraw->maxHeight(QPen(), fm); break; case QwtScaleDraw::Top: d_scaleDraw->setGeometry(r.x() + bd0, r.bottom() - d_baseDist, r.width() - bd0 - bd1, QwtScaleDraw::Top); d_titleOffset = d_titleDist + d_baseDist + d_scaleDraw->maxHeight(QPen(), fm); break; case QwtScaleDraw::Left: d_scaleDraw->setGeometry(r.right() - d_baseDist, r.y() + bd0, r.height() - bd0 - bd1, QwtScaleDraw::Left); d_titleOffset = d_baseDist + d_titleDist + d_scaleDraw->maxWidth(QPen(), fm); break; case QwtScaleDraw::Right: d_scaleDraw->setGeometry(r.x() + d_baseDist, r.y() + bd0, r.height() - bd0 - bd1, QwtScaleDraw::Right); d_titleOffset = d_baseDist + d_titleDist + d_scaleDraw->maxWidth(QPen(), fm); break; default: break; } if ( update_geometry ) { updateGeometry(); update(); }}/*! Rotate and paint a title according to its position into a given rectangle. \param painter Painter \param o Orientation \param rect Bounding rectangle*/void QwtScale::drawTitle(QPainter *painter, QwtScaleDraw::Orientation o, const QRect &rect) const{ QRect r; double angle; int align = d_title->alignment() & ~(AlignTop | AlignBottom); switch(o) {#ifndef QT_NO_TRANSFORMATIONS case QwtScaleDraw::Left: align |= AlignTop; angle = -90.0; r.setRect(rect.left(), rect.bottom(), rect.height(), rect.width()); break; case QwtScaleDraw::Right: align |= AlignTop; angle = 90.0; r.setRect(rect.right(), rect.top(), rect.height(), rect.width()); break;#else case QwtScaleDraw::Left: case QwtScaleDraw::Right: // swallow vertical titles return;#endif case QwtScaleDraw::Top: align |= AlignTop; angle = 0.0; r = rect; break; case QwtScaleDraw::Bottom: default: align |= AlignBottom; angle = 0.0; r = rect; break; } d_title->setAlignment(align); painter->save(); painter->translate(r.x(), r.y());#ifndef QT_NO_TRANSFORMATIONS if (angle != 0.0) painter->rotate(angle);#endif d_title->draw(painter, QRect(0, 0, r.width(), r.height())); painter->restore();}/*! \brief Notify a change of the scale This virtual function can be overloaded by derived classes. The default implementation updates the geometry and repaints the widget.*/void QwtScale::scaleChange(){ layoutScale();}/*! \return Fixed/MinimumExpanding for vertical, MinimumExpanding/Fixed for horizontal scales.*/QSizePolicy QwtScale::sizePolicy() const{ QSizePolicy sp; if ( d_scaleDraw->orientation() == QwtScaleDraw::Left || d_scaleDraw->orientation() == QwtScaleDraw::Right ) { sp.setHorData( QSizePolicy::Fixed ); sp.setVerData( QSizePolicy::MinimumExpanding ); } else { sp.setHorData( QSizePolicy::MinimumExpanding ); sp.setVerData( QSizePolicy::Fixed ); } return sp;}/*! \return a size hint*/QSize QwtScale::sizeHint() const{ return minimumSizeHint();}/*! \return a minimum size hint*/QSize QwtScale::minimumSizeHint() const{ Qt::Orientation o = Qt::Horizontal; if ( d_scaleDraw->orientation() == QwtScaleDraw::Left || d_scaleDraw->orientation() == QwtScaleDraw::Right ) { o = Qt::Vertical; } // Border Distance cannot be less than the scale minBorderDist // Note, the minBorderDist is already included in minHeight/minWidth int length = 0; int mbd1, mbd2; minBorderDist(mbd1, mbd2); length += qwtMax( 0, d_borderDist[0] - mbd1 ); length += qwtMax( 0, d_borderDist[1] - mbd2 ); const QFontMetrics fm(font()); if ( o == Qt::Vertical ) length += d_scaleDraw->minHeight(QPen(), fm); else length += d_scaleDraw->minWidth(QPen(), fm); int dim = dimForLength(length, fm); if ( length < dim ) { // compensate for long titles length = dim; dim = dimForLength(length, fm); } QSize size(length + 2, dim); if ( o == Qt::Vertical ) size.transpose(); return size;}/*! \brief Find the height of the title for a given width. \param width Width \return height Height */int QwtScale::titleHeightForWidth(int width) const{ return d_title->heightForWidth(width);}/*! \brief Find the minimum dimension for a given length. dim is the height, length the width seen in direction of the title. \param length width for horizontal, height for vertical scales \param scaleFontMetrics Font metrics of the scale \return height for horizontal, width for vertical scales*/int QwtScale::dimForLength(int length, const QFontMetrics &scaleFontMetrics) const{ int dim = d_baseDist; if ( d_scaleDraw->orientation() == QwtScaleDraw::Left || d_scaleDraw->orientation() == QwtScaleDraw::Right ) { dim += d_scaleDraw->minWidth(QPen(), scaleFontMetrics);#ifdef QT_NO_TRANSFORMATIONS return dim;#endif } else dim += d_scaleDraw->minHeight(QPen(), scaleFontMetrics); if ( !d_title->text().isEmpty() ) { dim += titleHeightForWidth(length) + d_titleDist; } return dim;}/*! \brief Determine the minimum Border distances. This member function returns the minimum distance of the scale's endpoints from the widget borders which is required for the mark labels to fit into the widget. \warning <ul> <li>The minimum border distance depends on the font.</ul> \sa QwtScale::setBorderDist()*/void QwtScale::minBorderDist(int &start, int &end) const{ const QFontMetrics fm(font()); d_scaleDraw->minBorderDist(fm, start, end);}/*! \brief Notify a change of the font This virtual function may be overloaded by derived widgets. The default implementation resizes the scale and repaints the widget. \param oldFont Previous font*/void QwtScale::fontChange(const QFont &oldFont){ QWidget::fontChange( oldFont ); layoutScale();}/*! \brief Assign a scale division The scale division determines where to set the tick marks. \param sd Scale Division \sa For more information about scale divisions, see QwtScaleDiv.*/void QwtScale::setScaleDiv(const QwtScaleDiv &sd){ if (d_scaleDraw->scaleDiv() != sd) { d_scaleDraw->setScale(sd); layoutScale(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -