10#include "qwt_scale_widget.h"
11#include "qwt_painter.h"
12#include "qwt_color_map.h"
13#include "qwt_scale_map.h"
15#include "qwt_scale_div.h"
17#include "qwt_interval.h"
18#include "qwt_scale_engine.h"
23#include <qstyleoption.h>
24#include <qapplication.h>
27class QwtScaleWidget::PrivateData
33 colorBar.colorMap = NULL;
39 delete colorBar.colorMap;
94 m_data =
new PrivateData;
99 m_data->borderDist[0] = 0;
100 m_data->borderDist[1] = 0;
101 m_data->minBorderDist[0] = 0;
102 m_data->minBorderDist[1] = 0;
104 m_data->titleOffset = 0;
115 m_data->colorBar.isEnabled =
false;
116 m_data->colorBar.width = 10;
118 const int flags = Qt::AlignHCenter
119 | Qt::TextExpandTabs | Qt::TextWordWrap;
121 m_data->title.
setFont( font() );
123 QSizePolicy policy( QSizePolicy::MinimumExpanding,
124 QSizePolicy::Fixed );
125 if ( m_data->scaleDraw->
orientation() == Qt::Vertical )
128 setSizePolicy( policy );
130 setAttribute( Qt::WA_WState_OwnSizePolicy,
false );
143 if ( ( ( m_data->layoutFlags & flag ) != 0 ) != on )
146 m_data->layoutFlags |= flag;
148 m_data->layoutFlags &= ~flag;
163 return ( m_data->layoutFlags & flag );
193 const int flags =
title.
renderFlags() & ~( Qt::AlignTop | Qt::AlignBottom );
196 if ( t != m_data->title )
211 if ( m_data->scaleDraw == NULL )
216 if ( !testAttribute( Qt::WA_WState_OwnSizePolicy ) )
218 QSizePolicy policy( QSizePolicy::MinimumExpanding, QSizePolicy::Fixed );
219 if ( m_data->scaleDraw->
orientation() == Qt::Vertical )
222 setSizePolicy( policy );
224 setAttribute( Qt::WA_WState_OwnSizePolicy,
false );
253 if ( dist1 != m_data->borderDist[0] || dist2 != m_data->borderDist[1] )
255 m_data->borderDist[0] = dist1;
256 m_data->borderDist[1] = dist2;
269 if (
margin != m_data->margin )
284 if (
spacing != m_data->spacing )
344 delete m_data->scaleDraw;
356 return m_data->scaleDraw;
365 return m_data->scaleDraw;
374 return m_data->title;
383 return m_data->borderDist[0];
392 return m_data->borderDist[1];
401 return m_data->margin;
410 return m_data->spacing;
418 QPainter painter(
this );
419 painter.setClipRegion( event->region() );
423 style()->drawPrimitive(QStyle::PE_Widget, &opt, &painter,
this);
433 m_data->scaleDraw->
draw( painter, palette() );
435 if ( m_data->colorBar.isEnabled && m_data->colorBar.width > 0 &&
436 m_data->colorBar.interval.
isValid() )
441 QRect r = contentsRect();
442 if ( m_data->scaleDraw->
orientation() == Qt::Horizontal )
444 r.setLeft( r.left() + m_data->borderDist[0] );
445 r.setWidth( r.width() - m_data->borderDist[1] );
449 r.setTop( r.top() + m_data->borderDist[0] );
450 r.setHeight( r.height() - m_data->borderDist[1] );
453 if ( !m_data->title.
isEmpty() )
467 if ( m_data->scaleDraw->
orientation() == Qt::Horizontal )
469 cr.setLeft( cr.left() + m_data->borderDist[0] );
470 cr.setWidth( cr.width() - m_data->borderDist[1] + 1 );
474 cr.setTop( cr.top() + m_data->borderDist[0] );
475 cr.setHeight( cr.height() - m_data->borderDist[1] + 1 );
478 switch ( m_data->scaleDraw->
alignment() )
482 cr.setLeft( cr.right() - m_data->margin
483 - m_data->colorBar.width );
484 cr.setWidth( m_data->colorBar.width );
490 cr.setLeft( cr.left() + m_data->margin );
491 cr.setWidth( m_data->colorBar.width );
497 cr.setTop( cr.top() + m_data->margin );
498 cr.setHeight( m_data->colorBar.width );
504 cr.setTop( cr.bottom() - m_data->margin
505 - m_data->colorBar.width );
506 cr.setHeight( m_data->colorBar.width );
522 if ( event->type() == QEvent::LocaleChange )
527 QWidget::changeEvent( event );
552 if ( m_data->borderDist[0] > bd0 )
553 bd0 = m_data->borderDist[0];
554 if ( m_data->borderDist[1] > bd1 )
555 bd1 = m_data->borderDist[1];
558 if ( m_data->colorBar.isEnabled && m_data->colorBar.interval.
isValid() )
561 const QRectF r = contentsRect();
564 if ( m_data->scaleDraw->
orientation() == Qt::Vertical )
567 length = r.height() - ( bd0 + bd1 );
577 length = r.width() - ( bd0 + bd1 );
585 m_data->scaleDraw->
move( x, y );
588 const int extent = qwtCeil( m_data->scaleDraw->
extent( font() ) );
590 m_data->titleOffset =
593 if ( update_geometry )
603 if ( QWidget* w = parentWidget() )
605 if ( !w->isVisible() && w->layout() == NULL )
607 if ( w->testAttribute( Qt::WA_WState_Polished ) )
608 QApplication::postEvent( w,
new QEvent( QEvent::LayoutRequest ) );
627 if ( !m_data->colorBar.interval.
isValid() )
651 ~( Qt::AlignTop | Qt::AlignBottom | Qt::AlignVCenter );
657 flags |= Qt::AlignTop;
658 r.setRect( r.left(), r.bottom(),
659 r.height(), r.width() - m_data->titleOffset );
664 flags |= Qt::AlignTop;
665 r.setRect( r.left() + m_data->titleOffset, r.bottom(),
666 r.height(), r.width() - m_data->titleOffset );
671 flags |= Qt::AlignBottom;
672 r.setTop( r.top() + m_data->titleOffset );
678 flags |= Qt::AlignTop;
679 r.setBottom( r.bottom() - m_data->titleOffset );
689 r.setRect( r.x() + r.height(), r.y() - r.width(),
690 r.width(), r.height() );
695 painter->setFont( font() );
696 painter->setPen( palette().color( QPalette::Text ) );
698 painter->translate( r.x(), r.y() );
700 painter->rotate( angle );
704 title.
draw( painter, QRectF( 0.0, 0.0, r.width(), r.height() ) );
735 const Qt::Orientation o = m_data->scaleDraw->
orientation();
742 length += qMax( 0, m_data->borderDist[0] - mbd1 );
743 length += qMax( 0, m_data->borderDist[1] - mbd2 );
744 length += m_data->scaleDraw->
minLength( font() );
754 QSize size( length + 2, dim );
755 if ( o == Qt::Vertical )
758 const QMargins m = contentsMargins();
759 return size + QSize( m.left() + m.right(), m.top() + m.bottom() );
784 const int extent = qwtCeil( m_data->scaleDraw->
extent( scaleFont ) );
786 int dim = m_data->margin + extent + 1;
788 if ( !m_data->title.
isEmpty() )
791 if ( m_data->colorBar.isEnabled && m_data->colorBar.interval.
isValid() )
792 dim += m_data->colorBar.width + m_data->spacing;
819 if ( start < m_data->minBorderDist[0] )
820 start = m_data->minBorderDist[0];
822 if ( end < m_data->minBorderDist[1] )
823 end = m_data->minBorderDist[1];
838 m_data->minBorderDist[0] = start;
839 m_data->minBorderDist[1] = end;
855 start = m_data->minBorderDist[0];
856 end = m_data->minBorderDist[1];
897 if ( on != m_data->colorBar.isEnabled )
899 m_data->colorBar.isEnabled = on;
910 return m_data->colorBar.isEnabled;
921 if ( width != m_data->colorBar.width )
923 m_data->colorBar.width = width;
935 return m_data->colorBar.width;
944 return m_data->colorBar.interval;
959 m_data->colorBar.interval = interval;
961 if (
colorMap != m_data->colorBar.colorMap )
963 delete m_data->colorBar.colorMap;
964 m_data->colorBar.colorMap =
colorMap;
977 return m_data->colorBar.colorMap;
980#include "moc_qwt_scale_widget.cpp"
void setScaleDiv(const QwtScaleDiv &)
const QwtScaleMap & scaleMap() const
void setTransformation(QwtTransform *)
virtual void draw(QPainter *, const QPalette &) const
Draw the scale.
const QwtScaleDiv & scaleDiv() const
QwtColorMap is used to map values into colors.
A class representing an interval.
QwtInterval normalized() const
Normalize the limits of the interval.
QwtLinearColorMap builds a color map from color stops.
A scale engine for linear scales.
static void drawColorBar(QPainter *, const QwtColorMap &, const QwtInterval &, const QwtScaleMap &, Qt::Orientation, const QRectF &)
A class representing a scale division.
A class for drawing scales.
void setLength(double length)
void move(double x, double y)
virtual double extent(const QFont &) const override
void getBorderDistHint(const QFont &, int &start, int &end) const
Determine the minimum border distance.
void setLabelAlignment(Qt::Alignment)
Change the label flags.
int minLength(const QFont &) const
void setAlignment(Alignment)
Alignment alignment() const
Qt::Orientation orientation() const
void setLabelRotation(double rotation)
@ BottomScale
The scale is below.
@ TopScale
The scale is above.
@ RightScale
The scale is right.
@ LeftScale
The scale is left.
const QwtTransform * transformation() const
Get the transformation.
A class representing a text.
void setText(const QString &, QwtText::TextFormat textFormat=AutoText)
void setFont(const QFont &)
void draw(QPainter *painter, const QRectF &rect) const
double heightForWidth(double width) const
void setRenderFlags(int)
Change the render flags.