Loading...
Searching...
No Matches
qwt_column_symbol.cpp
/******************************************************************************
* Qwt Widget Library
* Copyright (C) 1997 Josef Wilgen
* Copyright (C) 2002 Uwe Rathmann
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the Qwt License, Version 1.0
*****************************************************************************/
#include "qwt_column_symbol.h"
#include "qwt_painter.h"
#include "qwt_math.h"
#include <qpainter.h>
#include <qpalette.h>
static void qwtDrawBox( QPainter* p, const QRectF& rect,
const QPalette& pal, double lw )
{
if ( lw > 0.0 )
{
if ( rect.width() == 0.0 )
{
p->setPen( pal.dark().color() );
p->drawLine( rect.topLeft(), rect.bottomLeft() );
return;
}
if ( rect.height() == 0.0 )
{
p->setPen( pal.dark().color() );
p->drawLine( rect.topLeft(), rect.topRight() );
return;
}
lw = qwtMinF( lw, rect.height() / 2.0 - 1.0 );
lw = qwtMinF( lw, rect.width() / 2.0 - 1.0 );
const QRectF outerRect = rect.adjusted( 0, 0, 1, 1 );
QPolygonF polygon( outerRect );
if ( outerRect.width() > 2 * lw && outerRect.height() > 2 * lw )
{
const QRectF innerRect = outerRect.adjusted( lw, lw, -lw, -lw );
polygon = polygon.subtracted( innerRect );
}
p->setPen( Qt::NoPen );
p->setBrush( pal.dark() );
p->drawPolygon( polygon );
}
const QRectF windowRect = rect.adjusted( lw, lw, -lw + 1, -lw + 1 );
if ( windowRect.isValid() )
p->fillRect( windowRect, pal.window() );
}
static void qwtDrawPanel( QPainter* painter, const QRectF& rect,
const QPalette& pal, double lw )
{
if ( lw > 0.0 )
{
if ( rect.width() == 0.0 )
{
painter->setPen( pal.window().color() );
painter->drawLine( rect.topLeft(), rect.bottomLeft() );
return;
}
if ( rect.height() == 0.0 )
{
painter->setPen( pal.window().color() );
painter->drawLine( rect.topLeft(), rect.topRight() );
return;
}
lw = qwtMinF( lw, rect.height() / 2.0 - 1.0 );
lw = qwtMinF( lw, rect.width() / 2.0 - 1.0 );
const QRectF outerRect = rect.adjusted( 0, 0, 1, 1 );
const QRectF innerRect = outerRect.adjusted( lw, lw, -lw, -lw );
QPolygonF lines[2];
lines[0] += outerRect.bottomLeft();
lines[0] += outerRect.topLeft();
lines[0] += outerRect.topRight();
lines[0] += innerRect.topRight();
lines[0] += innerRect.topLeft();
lines[0] += innerRect.bottomLeft();
lines[1] += outerRect.topRight();
lines[1] += outerRect.bottomRight();
lines[1] += outerRect.bottomLeft();
lines[1] += innerRect.bottomLeft();
lines[1] += innerRect.bottomRight();
lines[1] += innerRect.topRight();
painter->setPen( Qt::NoPen );
painter->setBrush( pal.light() );
painter->drawPolygon( lines[0] );
painter->setBrush( pal.dark() );
painter->drawPolygon( lines[1] );
}
painter->fillRect( rect.adjusted( lw, lw, -lw + 1, -lw + 1 ), pal.window() );
}
class QwtColumnSymbol::PrivateData
{
public:
PrivateData()
: style( QwtColumnSymbol::Box )
, frameStyle( QwtColumnSymbol::Raised )
, palette( Qt::gray )
, lineWidth( 2 )
{
}
QwtColumnSymbol::Style style;
QwtColumnSymbol::FrameStyle frameStyle;
QPalette palette;
int lineWidth;
};
QwtColumnSymbol::QwtColumnSymbol( Style style )
{
m_data = new PrivateData();
m_data->style = style;
}
QwtColumnSymbol::~QwtColumnSymbol()
{
delete m_data;
}
void QwtColumnSymbol::setStyle( Style style )
{
m_data->style = style;
}
QwtColumnSymbol::Style QwtColumnSymbol::style() const
{
return m_data->style;
}
void QwtColumnSymbol::setPalette( const QPalette& palette )
{
m_data->palette = palette;
}
const QPalette& QwtColumnSymbol::palette() const
{
return m_data->palette;
}
void QwtColumnSymbol::setFrameStyle( FrameStyle frameStyle )
{
m_data->frameStyle = frameStyle;
}
QwtColumnSymbol::FrameStyle QwtColumnSymbol::frameStyle() const
{
return m_data->frameStyle;
}
void QwtColumnSymbol::setLineWidth( int width )
{
if ( width < 0 )
width = 0;
m_data->lineWidth = width;
}
int QwtColumnSymbol::lineWidth() const
{
return m_data->lineWidth;
}
void QwtColumnSymbol::draw( QPainter* painter,
const QwtColumnRect& rect ) const
{
painter->save();
switch ( m_data->style )
{
case QwtColumnSymbol::Box:
{
drawBox( painter, rect );
break;
}
default:;
}
painter->restore();
}
void QwtColumnSymbol::drawBox( QPainter* painter,
const QwtColumnRect& rect ) const
{
QRectF r = rect.toRect();
if ( QwtPainter::roundingAlignment( painter ) )
{
r.setLeft( qRound( r.left() ) );
r.setRight( qRound( r.right() ) );
r.setTop( qRound( r.top() ) );
r.setBottom( qRound( r.bottom() ) );
}
switch ( m_data->frameStyle )
{
case QwtColumnSymbol::Raised:
{
qwtDrawPanel( painter, r, m_data->palette, m_data->lineWidth );
break;
}
case QwtColumnSymbol::Plain:
{
qwtDrawBox( painter, r, m_data->palette, m_data->lineWidth );
break;
}
default:
{
painter->fillRect( r.adjusted( 0, 0, 1, 1 ), m_data->palette.window() );
}
}
}
QRectF QwtColumnRect::toRect() const
{
QRectF r( hInterval.minValue(), vInterval.minValue(),
hInterval.maxValue() - hInterval.minValue(),
vInterval.maxValue() - vInterval.minValue() );
r = r.normalized();
if ( hInterval.borderFlags() & QwtInterval::ExcludeMinimum )
r.adjust( 1, 0, 0, 0 );
if ( hInterval.borderFlags() & QwtInterval::ExcludeMaximum )
r.adjust( 0, 0, -1, 0 );
if ( vInterval.borderFlags() & QwtInterval::ExcludeMinimum )
r.adjust( 0, 1, 0, 0 );
if ( vInterval.borderFlags() & QwtInterval::ExcludeMaximum )
r.adjust( 0, 0, 0, -1 );
return r;
}
QwtColumnRect
Directed rectangle representing bounding rectangle and orientation of a column.
Definition qwt_column_symbol.h:27
QwtColumnRect::vInterval
QwtInterval vInterval
Interval for the vertical coordinates.
Definition qwt_column_symbol.h:67
QwtColumnRect::hInterval
QwtInterval hInterval
Interval for the horizontal coordinates.
Definition qwt_column_symbol.h:64
QwtColumnRect::toRect
QRectF toRect() const
Definition qwt_column_symbol.cpp:296
QwtColumnSymbol
A drawing primitive for columns.
Definition qwt_column_symbol.h:75
QwtColumnSymbol::setStyle
void setStyle(Style)
Definition qwt_column_symbol.cpp:153
QwtColumnSymbol::drawBox
void drawBox(QPainter *, const QwtColumnRect &) const
Definition qwt_column_symbol.cpp:264
QwtColumnSymbol::FrameStyle
FrameStyle
Definition qwt_column_symbol.h:105
QwtColumnSymbol::Raised
@ Raised
A raised frame style.
Definition qwt_column_symbol.h:113
QwtColumnSymbol::Plain
@ Plain
A plain frame style.
Definition qwt_column_symbol.h:110
QwtColumnSymbol::~QwtColumnSymbol
virtual ~QwtColumnSymbol()
Destructor.
Definition qwt_column_symbol.cpp:142
QwtColumnSymbol::lineWidth
int lineWidth() const
Definition qwt_column_symbol.cpp:225
QwtColumnSymbol::QwtColumnSymbol
QwtColumnSymbol(Style=NoStyle)
Definition qwt_column_symbol.cpp:135
QwtColumnSymbol::setPalette
void setPalette(const QPalette &)
Definition qwt_column_symbol.cpp:173
QwtColumnSymbol::draw
virtual void draw(QPainter *, const QwtColumnRect &) const
Definition qwt_column_symbol.cpp:238
QwtColumnSymbol::Style
Style
Definition qwt_column_symbol.h:82
QwtColumnSymbol::Box
@ Box
Definition qwt_column_symbol.h:90
QwtColumnSymbol::setFrameStyle
void setFrameStyle(FrameStyle)
Definition qwt_column_symbol.cpp:193
QwtColumnSymbol::palette
const QPalette & palette() const
Definition qwt_column_symbol.cpp:182
QwtColumnSymbol::frameStyle
FrameStyle frameStyle() const
Definition qwt_column_symbol.cpp:202
QwtColumnSymbol::setLineWidth
void setLineWidth(int width)
Definition qwt_column_symbol.cpp:213
QwtColumnSymbol::style
Style style() const
Definition qwt_column_symbol.cpp:162
QwtInterval::minValue
double minValue() const
Definition qwt_interval.h:192
QwtInterval::ExcludeMaximum
@ ExcludeMaximum
Max value is not included in the interval.
Definition qwt_interval.h:38
QwtInterval::ExcludeMinimum
@ ExcludeMinimum
Min value is not included in the interval.
Definition qwt_interval.h:35
QwtInterval::maxValue
double maxValue() const
Definition qwt_interval.h:198
QwtInterval::borderFlags
BorderFlags borderFlags() const
Definition qwt_interval.h:166
QwtPainter::roundingAlignment
static bool roundingAlignment()
Definition qwt_painter.h:183