qwt_column_symbol.cpp
Go to the documentation of this file.
1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
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 &&
43  outerRect.height() > 2 * lw )
44  {
45  const QRectF innerRect = outerRect.adjusted( lw, lw, -lw, -lw );
46  polygon = polygon.subtracted( innerRect );
47  }
48 
49  p->setPen( Qt::NoPen );
50 
51  p->setBrush( pal.dark() );
52  p->drawPolygon( polygon );
53  }
54 
55  const QRectF windowRect = rect.adjusted( lw, lw, -lw + 1, -lw + 1 );
56  if ( windowRect.isValid() )
57  p->fillRect( windowRect, pal.window() );
58 }
59 
60 static void qwtDrawPanel( QPainter *painter, const QRectF &rect,
61  const QPalette &pal, double lw )
62 {
63  if ( lw > 0.0 )
64  {
65  if ( rect.width() == 0.0 )
66  {
67  painter->setPen( pal.window().color() );
68  painter->drawLine( rect.topLeft(), rect.bottomLeft() );
69  return;
70  }
71 
72  if ( rect.height() == 0.0 )
73  {
74  painter->setPen( pal.window().color() );
75  painter->drawLine( rect.topLeft(), rect.topRight() );
76  return;
77  }
78 
79  lw = qwtMinF( lw, rect.height() / 2.0 - 1.0 );
80  lw = qwtMinF( lw, rect.width() / 2.0 - 1.0 );
81 
82  const QRectF outerRect = rect.adjusted( 0, 0, 1, 1 );
83  const QRectF innerRect = outerRect.adjusted( lw, lw, -lw, -lw );
84 
85  QPolygonF lines[2];
86 
87  lines[0] += outerRect.bottomLeft();
88  lines[0] += outerRect.topLeft();
89  lines[0] += outerRect.topRight();
90  lines[0] += innerRect.topRight();
91  lines[0] += innerRect.topLeft();
92  lines[0] += innerRect.bottomLeft();
93 
94  lines[1] += outerRect.topRight();
95  lines[1] += outerRect.bottomRight();
96  lines[1] += outerRect.bottomLeft();
97  lines[1] += innerRect.bottomLeft();
98  lines[1] += innerRect.bottomRight();
99  lines[1] += innerRect.topRight();
100 
101  painter->setPen( Qt::NoPen );
102 
103  painter->setBrush( pal.light() );
104  painter->drawPolygon( lines[0] );
105  painter->setBrush( pal.dark() );
106  painter->drawPolygon( lines[1] );
107  }
108 
109  painter->fillRect( rect.adjusted( lw, lw, -lw + 1, -lw + 1 ), pal.window() );
110 }
111 
113 {
114 public:
118  palette( Qt::gray ),
119  lineWidth( 2 )
120  {
121  }
122 
125 
126  QPalette palette;
128 };
129 
137 {
138  d_data = new PrivateData();
139  d_data->style = style;
140 }
141 
144 {
145  delete d_data;
146 }
147 
155 {
156  d_data->style = style;
157 }
158 
164 {
165  return d_data->style;
166 }
167 
174 void QwtColumnSymbol::setPalette( const QPalette &palette )
175 {
177 }
178 
183 const QPalette& QwtColumnSymbol::palette() const
184 {
185  return d_data->palette;
186 }
187 
195 {
197 }
198 
204 {
205  return d_data->frameStyle;
206 }
207 
215 {
216  if ( width < 0 )
217  width = 0;
218 
219  d_data->lineWidth = width;
220 }
221 
227 {
228  return d_data->lineWidth;
229 }
230 
239 void QwtColumnSymbol::draw( QPainter *painter,
240  const QwtColumnRect &rect ) const
241 {
242  painter->save();
243 
244  switch ( d_data->style )
245  {
247  {
248  drawBox( painter, rect );
249  break;
250  }
251  default:;
252  }
253 
254  painter->restore();
255 }
256 
265 void QwtColumnSymbol::drawBox( QPainter *painter,
266  const QwtColumnRect &rect ) const
267 {
268  QRectF r = rect.toRect();
269  if ( QwtPainter::roundingAlignment( painter ) )
270  {
271  r.setLeft( qRound( r.left() ) );
272  r.setRight( qRound( r.right() ) );
273  r.setTop( qRound( r.top() ) );
274  r.setBottom( qRound( r.bottom() ) );
275  }
276 
277  switch ( d_data->frameStyle )
278  {
280  {
281  qwtDrawPanel( painter, r, d_data->palette, d_data->lineWidth );
282  break;
283  }
285  {
286  qwtDrawBox( painter, r, d_data->palette, d_data->lineWidth );
287  break;
288  }
289  default:
290  {
291  painter->fillRect( r.adjusted( 0, 0, 1, 1 ), d_data->palette.window() );
292  }
293  }
294 }
295 
297 QRectF QwtColumnRect::toRect() const
298 {
299  QRectF r( hInterval.minValue(), vInterval.minValue(),
300  hInterval.maxValue() - hInterval.minValue(),
301  vInterval.maxValue() - vInterval.minValue() );
302 
303  r = r.normalized();
304 
305  if ( hInterval.borderFlags() & QwtInterval::ExcludeMinimum )
306  r.adjust( 1, 0, 0, 0 );
307 
308  if ( hInterval.borderFlags() & QwtInterval::ExcludeMaximum )
309  r.adjust( 0, 0, -1, 0 );
310 
311  if ( vInterval.borderFlags() & QwtInterval::ExcludeMinimum )
312  r.adjust( 0, 1, 0, 0 );
313 
314  if ( vInterval.borderFlags() & QwtInterval::ExcludeMaximum )
315  r.adjust( 0, 0, 0, -1 );
316 
317  return r;
318 }
319 
Style style() const
virtual ~QwtColumnSymbol()
Destructor.
A plain frame style.
Max value is not included in the interval.
Definition: qwt_interval.h:38
QRectF toRect() const
A drawing primitive for columns.
static void qwtDrawBox(QPainter *p, const QRectF &rect, const QPalette &pal, double lw)
FrameStyle frameStyle() const
QwtColumnSymbol(Style=NoStyle)
static void qwtDrawPanel(QPainter *painter, const QRectF &rect, const QPalette &pal, double lw)
QwtColumnSymbol::FrameStyle frameStyle
QWT_CONSTEXPR float qwtMinF(float a, float b)
Definition: qwt_math.h:99
QwtColumnSymbol::Style style
int lineWidth() const
A raised frame style.
void setPalette(const QPalette &)
Min value is not included in the interval.
Definition: qwt_interval.h:35
void setFrameStyle(FrameStyle)
void setLineWidth(int width)
PrivateData * d_data
const QPalette & palette() const
Directed rectangle representing bounding rectangle and orientation of a column.
virtual void draw(QPainter *, const QwtColumnRect &) const
void drawBox(QPainter *, const QwtColumnRect &) const
static bool roundingAlignment()
Definition: qwt_painter.h:181


plotjuggler
Author(s): Davide Faconti
autogenerated on Sun Dec 6 2020 03:48:10