qwt_column_symbol.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  * Qwt Widget Library
3  * Copyright (C) 1997 Josef Wilgen
4  * Copyright (C) 2002 Uwe Rathmann
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the Qwt License, Version 1.0
8  *****************************************************************************/
9 
10 #include "qwt_column_symbol.h"
11 #include "qwt_painter.h"
12 #include "qwt_math.h"
13 
14 #include <qpainter.h>
15 #include <qpalette.h>
16 
17 static void qwtDrawBox( QPainter* p, const QRectF& rect,
18  const QPalette& pal, double lw )
19 {
20  if ( lw > 0.0 )
21  {
22  if ( rect.width() == 0.0 )
23  {
24  p->setPen( pal.dark().color() );
25  p->drawLine( rect.topLeft(), rect.bottomLeft() );
26  return;
27  }
28 
29  if ( rect.height() == 0.0 )
30  {
31  p->setPen( pal.dark().color() );
32  p->drawLine( rect.topLeft(), rect.topRight() );
33  return;
34  }
35 
36  lw = qwtMinF( lw, rect.height() / 2.0 - 1.0 );
37  lw = qwtMinF( lw, rect.width() / 2.0 - 1.0 );
38 
39  const QRectF outerRect = rect.adjusted( 0, 0, 1, 1 );
40  QPolygonF polygon( outerRect );
41 
42  if ( outerRect.width() > 2 * lw && outerRect.height() > 2 * lw )
43  {
44  const QRectF innerRect = outerRect.adjusted( lw, lw, -lw, -lw );
45  polygon = polygon.subtracted( innerRect );
46  }
47 
48  p->setPen( Qt::NoPen );
49 
50  p->setBrush( pal.dark() );
51  p->drawPolygon( polygon );
52  }
53 
54  const QRectF windowRect = rect.adjusted( lw, lw, -lw + 1, -lw + 1 );
55  if ( windowRect.isValid() )
56  p->fillRect( windowRect, pal.window() );
57 }
58 
59 static void qwtDrawPanel( QPainter* painter, const QRectF& rect,
60  const QPalette& pal, double lw )
61 {
62  if ( lw > 0.0 )
63  {
64  if ( rect.width() == 0.0 )
65  {
66  painter->setPen( pal.window().color() );
67  painter->drawLine( rect.topLeft(), rect.bottomLeft() );
68  return;
69  }
70 
71  if ( rect.height() == 0.0 )
72  {
73  painter->setPen( pal.window().color() );
74  painter->drawLine( rect.topLeft(), rect.topRight() );
75  return;
76  }
77 
78  lw = qwtMinF( lw, rect.height() / 2.0 - 1.0 );
79  lw = qwtMinF( lw, rect.width() / 2.0 - 1.0 );
80 
81  const QRectF outerRect = rect.adjusted( 0, 0, 1, 1 );
82  const QRectF innerRect = outerRect.adjusted( lw, lw, -lw, -lw );
83 
84  QPolygonF lines[2];
85 
86  lines[0] += outerRect.bottomLeft();
87  lines[0] += outerRect.topLeft();
88  lines[0] += outerRect.topRight();
89  lines[0] += innerRect.topRight();
90  lines[0] += innerRect.topLeft();
91  lines[0] += innerRect.bottomLeft();
92 
93  lines[1] += outerRect.topRight();
94  lines[1] += outerRect.bottomRight();
95  lines[1] += outerRect.bottomLeft();
96  lines[1] += innerRect.bottomLeft();
97  lines[1] += innerRect.bottomRight();
98  lines[1] += innerRect.topRight();
99 
100  painter->setPen( Qt::NoPen );
101 
102  painter->setBrush( pal.light() );
103  painter->drawPolygon( lines[0] );
104  painter->setBrush( pal.dark() );
105  painter->drawPolygon( lines[1] );
106  }
107 
108  painter->fillRect( rect.adjusted( lw, lw, -lw + 1, -lw + 1 ), pal.window() );
109 }
110 
112 {
113  public:
117  , palette( Qt::gray )
118  , lineWidth( 2 )
119  {
120  }
121 
124 
125  QPalette palette;
127 };
128 
136 {
137  m_data = new PrivateData();
138  m_data->style = style;
139 }
140 
143 {
144  delete m_data;
145 }
146 
154 {
155  m_data->style = style;
156 }
157 
163 {
164  return m_data->style;
165 }
166 
173 void QwtColumnSymbol::setPalette( const QPalette& palette )
174 {
176 }
177 
182 const QPalette& QwtColumnSymbol::palette() const
183 {
184  return m_data->palette;
185 }
186 
194 {
196 }
197 
203 {
204  return m_data->frameStyle;
205 }
206 
214 {
215  if ( width < 0 )
216  width = 0;
217 
218  m_data->lineWidth = width;
219 }
220 
226 {
227  return m_data->lineWidth;
228 }
229 
238 void QwtColumnSymbol::draw( QPainter* painter,
239  const QwtColumnRect& rect ) const
240 {
241  painter->save();
242 
243  switch ( m_data->style )
244  {
246  {
247  drawBox( painter, rect );
248  break;
249  }
250  default:;
251  }
252 
253  painter->restore();
254 }
255 
264 void QwtColumnSymbol::drawBox( QPainter* painter,
265  const QwtColumnRect& rect ) const
266 {
267  QRectF r = rect.toRect();
268  if ( QwtPainter::roundingAlignment( painter ) )
269  {
270  r.setLeft( qRound( r.left() ) );
271  r.setRight( qRound( r.right() ) );
272  r.setTop( qRound( r.top() ) );
273  r.setBottom( qRound( r.bottom() ) );
274  }
275 
276  switch ( m_data->frameStyle )
277  {
279  {
280  qwtDrawPanel( painter, r, m_data->palette, m_data->lineWidth );
281  break;
282  }
284  {
285  qwtDrawBox( painter, r, m_data->palette, m_data->lineWidth );
286  break;
287  }
288  default:
289  {
290  painter->fillRect( r.adjusted( 0, 0, 1, 1 ), m_data->palette.window() );
291  }
292  }
293 }
294 
296 QRectF QwtColumnRect::toRect() const
297 {
298  QRectF r( hInterval.minValue(), vInterval.minValue(),
301 
302  r = r.normalized();
303 
305  r.adjust( 1, 0, 0, 0 );
306 
308  r.adjust( 0, 0, -1, 0 );
309 
311  r.adjust( 0, 1, 0, 0 );
312 
314  r.adjust( 0, 0, 0, -1 );
315 
316  return r;
317 }
318 
qwt_column_symbol.h
QwtColumnRect::vInterval
QwtInterval vInterval
Interval for the vertical coordinates.
Definition: qwt_column_symbol.h:67
QwtColumnSymbol::QwtColumnSymbol
QwtColumnSymbol(Style=NoStyle)
Definition: qwt_column_symbol.cpp:135
QwtInterval::ExcludeMaximum
@ ExcludeMaximum
Max value is not included in the interval.
Definition: qwt_interval.h:52
QwtColumnSymbol::frameStyle
FrameStyle frameStyle() const
Definition: qwt_column_symbol.cpp:202
QwtInterval::minValue
double minValue() const
Definition: qwt_interval.h:192
QwtColumnSymbol
A drawing primitive for columns.
Definition: qwt_column_symbol.h:74
QwtColumnSymbol::setStyle
void setStyle(Style)
Definition: qwt_column_symbol.cpp:153
QwtColumnSymbol::Plain
@ Plain
A plain frame style.
Definition: qwt_column_symbol.h:110
QwtColumnSymbol::PrivateData::palette
QPalette palette
Definition: qwt_column_symbol.cpp:125
qwt_math.h
QwtPainter::roundingAlignment
static bool roundingAlignment()
Definition: qwt_painter.h:183
QwtColumnSymbol::lineWidth
int lineWidth() const
Definition: qwt_column_symbol.cpp:225
qwtMinF
QWT_CONSTEXPR float qwtMinF(float a, float b)
Definition: qwt_math.h:103
QwtInterval::borderFlags
BorderFlags borderFlags() const
Definition: qwt_interval.h:166
QwtColumnSymbol::style
Style style() const
Definition: qwt_column_symbol.cpp:162
QwtColumnSymbol::FrameStyle
FrameStyle
Definition: qwt_column_symbol.h:104
color::gray
@ gray
QwtColumnSymbol::~QwtColumnSymbol
virtual ~QwtColumnSymbol()
Destructor.
Definition: qwt_column_symbol.cpp:142
QwtColumnRect::hInterval
QwtInterval hInterval
Interval for the horizontal coordinates.
Definition: qwt_column_symbol.h:64
QwtColumnSymbol::Style
Style
Definition: qwt_column_symbol.h:81
QwtInterval::ExcludeMinimum
@ ExcludeMinimum
Min value is not included in the interval.
Definition: qwt_interval.h:49
qwtDrawPanel
static void qwtDrawPanel(QPainter *painter, const QRectF &rect, const QPalette &pal, double lw)
Definition: qwt_column_symbol.cpp:59
QwtColumnSymbol::Box
@ Box
Definition: qwt_column_symbol.h:90
QwtColumnSymbol::setFrameStyle
void setFrameStyle(FrameStyle)
Definition: qwt_column_symbol.cpp:193
QwtColumnSymbol::drawBox
void drawBox(QPainter *, const QwtColumnRect &) const
Definition: qwt_column_symbol.cpp:264
QwtColumnRect
Directed rectangle representing bounding rectangle and orientation of a column.
Definition: qwt_column_symbol.h:26
qwt_painter.h
QwtColumnSymbol::PrivateData::frameStyle
QwtColumnSymbol::FrameStyle frameStyle
Definition: qwt_column_symbol.cpp:123
qwtDrawBox
static void qwtDrawBox(QPainter *p, const QRectF &rect, const QPalette &pal, double lw)
Definition: qwt_column_symbol.cpp:17
QwtColumnRect::toRect
QRectF toRect() const
Definition: qwt_column_symbol.cpp:296
QwtInterval::maxValue
double maxValue() const
Definition: qwt_interval.h:198
QwtColumnSymbol::m_data
PrivateData * m_data
Definition: qwt_column_symbol.h:140
QwtColumnSymbol::PrivateData::lineWidth
int lineWidth
Definition: qwt_column_symbol.cpp:126
QwtColumnSymbol::palette
const QPalette & palette() const
Definition: qwt_column_symbol.cpp:182
QwtColumnSymbol::PrivateData::PrivateData
PrivateData()
Definition: qwt_column_symbol.cpp:114
QwtColumnSymbol::PrivateData::style
QwtColumnSymbol::Style style
Definition: qwt_column_symbol.cpp:122
QwtColumnSymbol::Raised
@ Raised
A raised frame style.
Definition: qwt_column_symbol.h:113
QwtColumnSymbol::draw
virtual void draw(QPainter *, const QwtColumnRect &) const
Definition: qwt_column_symbol.cpp:238
QwtColumnSymbol::setLineWidth
void setLineWidth(int width)
Definition: qwt_column_symbol.cpp:213
QwtColumnSymbol::setPalette
void setPalette(const QPalette &)
Definition: qwt_column_symbol.cpp:173
QwtColumnSymbol::PrivateData
Definition: qwt_column_symbol.cpp:111


plotjuggler
Author(s): Davide Faconti
autogenerated on Mon Nov 11 2024 03:23:45