From d3e2a75911fa9c975a1319b06e85c5b85dcdb69d Mon Sep 17 00:00:00 2001 From: sln Date: Wed, 29 Jul 2009 13:01:47 +0000 Subject: [PATCH] CATHAREGUI_PixmapWg move din H-file for reusing on CATHARE_SRC --- src/Plot2d/Plot2d_SetupCurvesDlg.cxx | 78 ++++++++++++---------------- src/Plot2d/Plot2d_SetupCurvesDlg.h | 27 +++++++++- 2 files changed, 57 insertions(+), 48 deletions(-) diff --git a/src/Plot2d/Plot2d_SetupCurvesDlg.cxx b/src/Plot2d/Plot2d_SetupCurvesDlg.cxx index 904bcd9a4..56dfa346e 100755 --- a/src/Plot2d/Plot2d_SetupCurvesDlg.cxx +++ b/src/Plot2d/Plot2d_SetupCurvesDlg.cxx @@ -50,37 +50,14 @@ #define NB_MARKERS_COL 4 -/*! - \class Plot2d_SetupCurvesDlg::PixmapWg - \internal - \brief This class is derived from QWidget is intended for drawing curves symbol - inside its area. It contains QwtSymbol as its internal field and delegates paint - event to it for drawing -*/ -class Plot2d_SetupCurvesDlg::PixmapWg : public QWidget -{ -public: - PixmapWg( QWidget* theParent ); - virtual ~PixmapWg(); - - void setColor( const QColor& ); - void setMarkerType( const int ); - -protected: - virtual void paintEvent( QPaintEvent * event ); - -private: - QwtSymbol mySymbol; -}; - -Plot2d_SetupCurvesDlg::PixmapWg::PixmapWg( QWidget* theParent ) +Plot2d_PixmapWg::Plot2d_PixmapWg( QWidget* theParent ) : QWidget( theParent ) { mySymbol.setSize( QSize( 8, 8 ) ); mySymbol.setStyle( QwtSymbol::NoSymbol ); } -Plot2d_SetupCurvesDlg::PixmapWg::~PixmapWg() +Plot2d_PixmapWg::~Plot2d_PixmapWg() { } @@ -89,7 +66,7 @@ Plot2d_SetupCurvesDlg::PixmapWg::~PixmapWg() // Function : setColor // Purpose : //============================================================================= -void Plot2d_SetupCurvesDlg::PixmapWg::setColor( const QColor& theColor ) +void Plot2d_PixmapWg::setColor( const QColor& theColor ) { mySymbol.setBrush( QBrush( theColor ) ); mySymbol.setPen( QPen( theColor ) ); @@ -99,7 +76,7 @@ void Plot2d_SetupCurvesDlg::PixmapWg::setColor( const QColor& theColor ) // Function : setMarkerType // Purpose : //============================================================================= -void Plot2d_SetupCurvesDlg::PixmapWg::setMarkerType( const int theType ) +void Plot2d_PixmapWg::setMarkerType( const int theType ) { QwtSymbol::Style aStyle = QwtSymbol::NoSymbol; switch( theType ) @@ -118,32 +95,41 @@ void Plot2d_SetupCurvesDlg::PixmapWg::setMarkerType( const int theType ) mySymbol.setStyle( aStyle ); } +//============================================================================= +// Function : setText +// Purpose : +//============================================================================= +void Plot2d_PixmapWg::setText( const QString& theText ) +{ + myText = theText; +} + //============================================================================= // Function : paint // Purpose : //============================================================================= -void Plot2d_SetupCurvesDlg::PixmapWg::paintEvent( QPaintEvent* event ) +void Plot2d_PixmapWg::paintEvent( QPaintEvent* e ) { - QRect r = event->rect(); - /*int rm, lm, tm, bm; - if ( r.width() > 8 ) + QRect r = e->rect(); + QPainter p( this ); + + if ( myText.isEmpty() ) { - rm = ( r.width() - 8 ) / 2; - lm = r.width() - 8 - rm; + mySymbol.draw( &p, r.center() ); } - if ( r.height() > 8 ) + else { - tm = ( r.height() - 8 ) / 2; - bm = r.height() - 8 - tm; + const QSize& s = mySymbol.size(); + int x = r.left() + s.width() / 2 + 2; + int y = r.top() + qMax( s.height(), r.height() ) / 2; + mySymbol.draw( &p, x, y ); + + p.setPen( QColor( 0, 0, 0 ) ); + int textH = QFontMetrics( font() ).ascent(); + x = r.left() + s.width() + 10; + y = qMax( r.top(), r.top() + ( r.height() - textH ) / 2 + textH ); + p.drawText( QPoint( x, y ), myText ); } - - r.setLeft( r.left() + lm ); - r.setRight( r.right() - rm ); - r.setTop( r.top() + tm ); - r.setBottom( r.bottom() - bm );*/ - - QPainter p( this ); - mySymbol.draw( &p, r.center() ); } /*! @@ -295,7 +281,7 @@ void Plot2d_SetupCurvesDlg::SetParameters( const QVector< int >& theMarker, for ( int i = 0; i < nbRows; i++ ) { // Pixmap - PixmapWg* aPixWg = new PixmapWg( myTable ) ; + Plot2d_PixmapWg* aPixWg = new Plot2d_PixmapWg( myTable ) ; myTable->setCellWidget( i, PIXMAP_COL, aPixWg ); // Marker type @@ -568,7 +554,7 @@ void Plot2d_SetupCurvesDlg::updatePixmap( const int theRow ) for ( anIter = aRows.begin(); anIter != aRows.end(); ++anIter ) { int r = *anIter; - PixmapWg* aWg = dynamic_cast( myTable->cellWidget( r, PIXMAP_COL ) ); + Plot2d_PixmapWg* aWg = dynamic_cast( myTable->cellWidget( r, PIXMAP_COL ) ); if ( aWg ) { // Marker type diff --git a/src/Plot2d/Plot2d_SetupCurvesDlg.h b/src/Plot2d/Plot2d_SetupCurvesDlg.h index 33364f821..e4bea7cb6 100755 --- a/src/Plot2d/Plot2d_SetupCurvesDlg.h +++ b/src/Plot2d/Plot2d_SetupCurvesDlg.h @@ -47,8 +47,6 @@ class PLOT2D_EXPORT Plot2d_SetupCurvesDlg : public QtxDialog { Q_OBJECT - class PixmapWg; - public: Plot2d_SetupCurvesDlg( QWidget* theParent = 0 ); virtual ~Plot2d_SetupCurvesDlg(); @@ -97,6 +95,31 @@ private: QList< int > myRemovedIndexes; }; +/*! + \class Plot2d_PixmapWg + \internal + \brief This class is derived from QWidget is intended for drawing curves symbol + inside its area. It contains QwtSymbol as its internal field and delegates paint + event to it for drawing +*/ +class PLOT2D_EXPORT Plot2d_PixmapWg : public QWidget +{ +public: + Plot2d_PixmapWg( QWidget* theParent ); + virtual ~Plot2d_PixmapWg(); + + void setColor( const QColor& ); + void setMarkerType( const int ); + void setText( const QString& ); + +protected: + virtual void paintEvent( QPaintEvent * event ); + +private: + QwtSymbol mySymbol; + QString myText; +}; + #endif -- 2.39.2