source: ntrip/trunk/BNC/qwt/qwt_column_symbol.cpp@ 8869

Last change on this file since 8869 was 8127, checked in by stoecker, 8 years ago

update qwt and qwtpolar, many QT5 fixes (unfinished)

File size: 6.7 KB
Line 
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_math.h"
12#include "qwt_painter.h"
13#include <qpainter.h>
14#include <qpalette.h>
15
16static void qwtDrawBox( QPainter *p, const QRectF &rect,
17 const QPalette &pal, double lw )
18{
19 if ( lw > 0.0 )
20 {
21 if ( rect.width() == 0.0 )
22 {
23 p->setPen( pal.dark().color() );
24 p->drawLine( rect.topLeft(), rect.bottomLeft() );
25 return;
26 }
27
28 if ( rect.height() == 0.0 )
29 {
30 p->setPen( pal.dark().color() );
31 p->drawLine( rect.topLeft(), rect.topRight() );
32 return;
33 }
34
35 lw = qMin( lw, rect.height() / 2.0 - 1.0 );
36 lw = qMin( lw, rect.width() / 2.0 - 1.0 );
37
38 const QRectF outerRect = rect.adjusted( 0, 0, 1, 1 );
39 QPolygonF polygon( outerRect );
40
41 if ( outerRect.width() > 2 * lw &&
42 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
59static 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 = qMin( lw, rect.height() / 2.0 - 1.0 );
79 lw = qMin( 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
111class QwtColumnSymbol::PrivateData
112{
113public:
114 PrivateData():
115 style( QwtColumnSymbol::Box ),
116 frameStyle( QwtColumnSymbol::Raised ),
117 lineWidth( 2 )
118 {
119 palette = QPalette( Qt::gray );
120 }
121
122 QwtColumnSymbol::Style style;
123 QwtColumnSymbol::FrameStyle frameStyle;
124
125 QPalette palette;
126 int lineWidth;
127};
128
129/*!
130 Constructor
131
132 \param style Style of the symbol
133 \sa setStyle(), style(), Style
134*/
135QwtColumnSymbol::QwtColumnSymbol( Style style )
136{
137 d_data = new PrivateData();
138 d_data->style = style;
139}
140
141//! Destructor
142QwtColumnSymbol::~QwtColumnSymbol()
143{
144 delete d_data;
145}
146
147/*!
148 Specify the symbol style
149
150 \param style Style
151 \sa style(), setPalette()
152*/
153void QwtColumnSymbol::setStyle( Style style )
154{
155 d_data->style = style;
156}
157
158/*!
159 \return Current symbol style
160 \sa setStyle()
161*/
162QwtColumnSymbol::Style QwtColumnSymbol::style() const
163{
164 return d_data->style;
165}
166
167/*!
168 Assign a palette for the symbol
169
170 \param palette Palette
171 \sa palette(), setStyle()
172*/
173void QwtColumnSymbol::setPalette( const QPalette &palette )
174{
175 d_data->palette = palette;
176}
177
178/*!
179 \return Current palette
180 \sa setPalette()
181*/
182const QPalette& QwtColumnSymbol::palette() const
183{
184 return d_data->palette;
185}
186
187/*!
188 Set the frame, that is used for the Box style.
189
190 \param frameStyle Frame style
191 \sa frameStyle(), setLineWidth(), setStyle()
192*/
193void QwtColumnSymbol::setFrameStyle( FrameStyle frameStyle )
194{
195 d_data->frameStyle = frameStyle;
196}
197
198/*!
199 \return Current frame style, that is used for the Box style.
200 \sa setFrameStyle(), lineWidth(), setStyle()
201*/
202QwtColumnSymbol::FrameStyle QwtColumnSymbol::frameStyle() const
203{
204 return d_data->frameStyle;
205}
206
207/*!
208 Set the line width of the frame, that is used for the Box style.
209
210 \param width Width
211 \sa lineWidth(), setFrameStyle()
212*/
213void QwtColumnSymbol::setLineWidth( int width )
214{
215 if ( width < 0 )
216 width = 0;
217
218 d_data->lineWidth = width;
219}
220
221/*!
222 \return Line width of the frame, that is used for the Box style.
223 \sa setLineWidth(), frameStyle(), setStyle()
224*/
225int QwtColumnSymbol::lineWidth() const
226{
227 return d_data->lineWidth;
228}
229
230/*!
231 Draw the symbol depending on its style.
232
233 \param painter Painter
234 \param rect Directed rectangle
235
236 \sa drawBox()
237*/
238void QwtColumnSymbol::draw( QPainter *painter,
239 const QwtColumnRect &rect ) const
240{
241 painter->save();
242
243 switch ( d_data->style )
244 {
245 case QwtColumnSymbol::Box:
246 {
247 drawBox( painter, rect );
248 break;
249 }
250 default:;
251 }
252
253 painter->restore();
254}
255
256/*!
257 Draw the symbol when it is in Box style.
258
259 \param painter Painter
260 \param rect Directed rectangle
261
262 \sa draw()
263*/
264void 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 ( d_data->frameStyle )
277 {
278 case QwtColumnSymbol::Raised:
279 {
280 qwtDrawPanel( painter, r, d_data->palette, d_data->lineWidth );
281 break;
282 }
283 case QwtColumnSymbol::Plain:
284 {
285 qwtDrawBox( painter, r, d_data->palette, d_data->lineWidth );
286 break;
287 }
288 default:
289 {
290 painter->fillRect( r, d_data->palette.window() );
291 }
292 }
293}
Note: See TracBrowser for help on using the repository browser.