Changeset 8127 in ntrip for trunk/BNC/qwt/qwt_plot_panner.cpp
- Timestamp:
- May 10, 2017, 3:20:54 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/qwt/qwt_plot_panner.cpp
r4271 r8127 11 11 #include "qwt_scale_div.h" 12 12 #include "qwt_plot.h" 13 #include "qwt_plot_canvas.h" 13 #include "qwt_painter.h" 14 #include <qbitmap.h> 15 #include <qstyle.h> 16 #include <qstyleoption.h> 17 18 static QBitmap qwtBorderMask( const QWidget *canvas, const QSize &size ) 19 { 20 const QRect r( 0, 0, size.width(), size.height() ); 21 22 QPainterPath borderPath; 23 24 ( void )QMetaObject::invokeMethod( 25 const_cast< QWidget *>( canvas ), "borderPath", Qt::DirectConnection, 26 Q_RETURN_ARG( QPainterPath, borderPath ), Q_ARG( QRect, r ) ); 27 28 if ( borderPath.isEmpty() ) 29 { 30 if ( canvas->contentsRect() == canvas->rect() ) 31 return QBitmap(); 32 33 QBitmap mask( size ); 34 mask.fill( Qt::color0 ); 35 36 QPainter painter( &mask ); 37 painter.fillRect( canvas->contentsRect(), Qt::color1 ); 38 39 return mask; 40 } 41 42 QImage image( size, QImage::Format_ARGB32_Premultiplied ); 43 image.fill( Qt::color0 ); 44 45 QPainter painter( &image ); 46 painter.setClipPath( borderPath ); 47 painter.fillRect( r, Qt::color1 ); 48 49 // now erase the frame 50 51 painter.setCompositionMode( QPainter::CompositionMode_DestinationOut ); 52 53 if ( canvas->testAttribute(Qt::WA_StyledBackground ) ) 54 { 55 QStyleOptionFrame opt; 56 opt.initFrom(canvas); 57 opt.rect = r; 58 canvas->style()->drawPrimitive( QStyle::PE_Frame, &opt, &painter, canvas ); 59 } 60 else 61 { 62 const QVariant borderRadius = canvas->property( "borderRadius" ); 63 const QVariant frameWidth = canvas->property( "frameWidth" ); 64 65 if ( borderRadius.type() == QVariant::Double 66 && frameWidth.type() == QVariant::Int ) 67 { 68 const double br = borderRadius.toDouble(); 69 const int fw = frameWidth.toInt(); 70 71 if ( br > 0.0 && fw > 0 ) 72 { 73 painter.setPen( QPen( Qt::color1, fw ) ); 74 painter.setBrush( Qt::NoBrush ); 75 painter.setRenderHint( QPainter::Antialiasing, true ); 76 77 painter.drawPath( borderPath ); 78 } 79 } 80 } 81 82 painter.end(); 83 84 const QImage mask = image.createMaskFromColor( 85 QColor( Qt::color1 ).rgb(), Qt::MaskOutColor ); 86 87 return QBitmap::fromImage( mask ); 88 } 14 89 15 90 class QwtPlotPanner::PrivateData … … 26 101 27 102 /*! 28 \brief Create a plot panner103 \brief A panner for the canvas of a QwtPlot 29 104 30 105 The panner is enabled for all axes … … 34 109 \sa setAxisEnabled() 35 110 */ 36 QwtPlotPanner::QwtPlotPanner( Q wtPlotCanvas*canvas ):111 QwtPlotPanner::QwtPlotPanner( QWidget *canvas ): 37 112 QwtPanner( canvas ) 38 113 { … … 83 158 84 159 //! Return observed plot canvas 85 Q wtPlotCanvas*QwtPlotPanner::canvas()86 { 87 return qobject_cast<QwtPlotCanvas *>( parentWidget());160 QWidget *QwtPlotPanner::canvas() 161 { 162 return parentWidget(); 88 163 } 89 164 90 165 //! Return Observed plot canvas 91 const Q wtPlotCanvas*QwtPlotPanner::canvas() const92 { 93 return qobject_cast<const QwtPlotCanvas *>( parentWidget());166 const QWidget *QwtPlotPanner::canvas() const 167 { 168 return parentWidget(); 94 169 } 95 170 … … 97 172 QwtPlot *QwtPlotPanner::plot() 98 173 { 99 Q wtPlotCanvas*w = canvas();174 QWidget *w = canvas(); 100 175 if ( w ) 101 return w->plot();102 103 return NULL;176 w = w->parentWidget(); 177 178 return qobject_cast<QwtPlot *>( w ); 104 179 } 105 180 … … 107 182 const QwtPlot *QwtPlotPanner::plot() const 108 183 { 109 const Q wtPlotCanvas*w = canvas();184 const QWidget *w = canvas(); 110 185 if ( w ) 111 return w->plot();112 113 return NULL;186 w = w->parentWidget(); 187 188 return qobject_cast<const QwtPlot *>( w ); 114 189 } 115 190 … … 141 216 const QwtScaleMap map = plot->canvasMap( axis ); 142 217 143 const double p1 = map.transform( plot->axisScaleDiv( axis ) ->lowerBound() );144 const double p2 = map.transform( plot->axisScaleDiv( axis ) ->upperBound() );218 const double p1 = map.transform( plot->axisScaleDiv( axis ).lowerBound() ); 219 const double p2 = map.transform( plot->axisScaleDiv( axis ).upperBound() ); 145 220 146 221 double d1, d2; … … 164 239 165 240 /*! 166 Calculate a mask from the border mask of the canvas 167 \sa QwtPlotCanvas::borderMask() 241 Calculate a mask from the border path of the canvas 242 243 \return Mask as bitmap 244 \sa QwtPlotCanvas::borderPath() 168 245 */ 169 246 QBitmap QwtPlotPanner::contentsMask() const 170 247 { 171 248 if ( canvas() ) 172 return canvas()->borderMask(size() );249 return qwtBorderMask( canvas(), size() ); 173 250 174 251 return QwtPanner::contentsMask(); 175 252 } 253 254 /*! 255 \return Pixmap with the content of the canvas 256 */ 257 QPixmap QwtPlotPanner::grab() const 258 { 259 const QWidget *cv = canvas(); 260 if ( cv && cv->inherits( "QGLWidget" ) ) 261 { 262 // we can't grab from a QGLWidget 263 264 QPixmap pm( cv->size() ); 265 QwtPainter::fillPixmap( cv, pm ); 266 267 QPainter painter( &pm ); 268 const_cast<QwtPlot *>( plot() )->drawCanvas( &painter ); 269 270 return pm; 271 } 272 273 return QwtPanner::grab(); 274 } 275
Note:
See TracChangeset
for help on using the changeset viewer.