From 81710f983b2806939fc75ed34baa26d9c0920114 Mon Sep 17 00:00:00 2001 From: ana Date: Wed, 19 Oct 2011 08:33:00 +0000 Subject: [PATCH] 021385: [CEA 509] Modify font properties in legend --- src/Plot2d/Plot2d_PlotItems.cxx | 14 ++++++ src/Plot2d/Plot2d_PlotItems.h | 1 + src/Plot2d/Plot2d_SetupViewDlg.cxx | 64 ++++++++++++++++++++------- src/Plot2d/Plot2d_SetupViewDlg.h | 7 ++- src/Plot2d/Plot2d_ViewFrame.cxx | 62 +++++++++++++++++++++++++- src/Plot2d/Plot2d_ViewFrame.h | 6 +++ src/Plot2d/resources/Plot2d_msg_en.ts | 4 ++ 7 files changed, 139 insertions(+), 19 deletions(-) diff --git a/src/Plot2d/Plot2d_PlotItems.cxx b/src/Plot2d/Plot2d_PlotItems.cxx index e86168eaf..2f058acb2 100644 --- a/src/Plot2d/Plot2d_PlotItems.cxx +++ b/src/Plot2d/Plot2d_PlotItems.cxx @@ -112,6 +112,20 @@ void Plot2d_QwtLegendItem::drawIdentifier( QPainter* painter, const QRect& rect } } +void Plot2d_QwtLegendItem::drawText(QPainter * painter, const QRect &rect) { + QWidget* pw = parentWidget(); + QColor col = palette().color( QPalette::WindowText ); + while( pw ) { + if ( qobject_cast( pw ) ) { + col = pw->palette().color( QPalette::WindowText ); + break; + } + pw = pw->parentWidget(); + } + painter->setPen( col ); + QwtLegendItem::drawText( painter, rect ); +} + /*! Constructor of Plot2d_QwtPlotCurve */ diff --git a/src/Plot2d/Plot2d_PlotItems.h b/src/Plot2d/Plot2d_PlotItems.h index dc7f9d89e..68decac65 100644 --- a/src/Plot2d/Plot2d_PlotItems.h +++ b/src/Plot2d/Plot2d_PlotItems.h @@ -47,6 +47,7 @@ public: protected: virtual void drawIdentifier( QPainter*, const QRect& ) const; + virtual void drawText(QPainter *, const QRect &); private: int myYAxisIdentifierMode; diff --git a/src/Plot2d/Plot2d_SetupViewDlg.cxx b/src/Plot2d/Plot2d_SetupViewDlg.cxx index 44f18aa0f..b5770fa90 100755 --- a/src/Plot2d/Plot2d_SetupViewDlg.cxx +++ b/src/Plot2d/Plot2d_SetupViewDlg.cxx @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -89,6 +90,9 @@ Plot2d_SetupViewDlg::Plot2d_SetupViewDlg( QWidget* parent, // legend myLegendCheck = new QCheckBox( tr( "PLOT2D_ENABLE_LEGEND" ), this ); myLegendCombo = new QComboBox( this ); + myLegendFont = new QtxFontEdit( this ); + myLegendColor = new QtxColorButton( this ); + QLabel* aLegendFontLab = new QLabel( tr( "PLOT2D_LEGEND_FONT" ), this ); myLegendCombo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); myLegendCombo->setMinimumWidth( MIN_COMBO_WIDTH ); myLegendCombo->addItem( tr( "PLOT2D_LEGEND_POSITION_LEFT" ) ); @@ -321,22 +325,26 @@ Plot2d_SetupViewDlg::Plot2d_SetupViewDlg( QWidget* parent, // layout widgets topLayout->addWidget( myTitleCheck, 0, 0 ); topLayout->addWidget( myTitleEdit, 0, 1, 1, 3 ); - topLayout->addWidget( aCurveLab, 1, 0 ); - topLayout->addWidget( myCurveCombo, 1, 1 ); - topLayout->addWidget( myLegendCheck, 1, 2 ); - topLayout->addWidget( myLegendCombo, 1, 3 ); - topLayout->addWidget( aMarkerLab, 2, 0 ); - topLayout->addWidget( myMarkerSpin, 2, 1 ); + topLayout->addWidget( myLegendCheck, 1, 0 ); + topLayout->addWidget( myLegendCombo, 1, 1 ); + topLayout->addWidget( aCurveLab, 1, 2 ); + topLayout->addWidget( myCurveCombo, 1, 3 ); + topLayout->addWidget( aLegendFontLab,2, 0 ); + topLayout->addWidget( myLegendFont, 2, 1 ); + topLayout->addWidget( myLegendColor, 2, 2 ); + + topLayout->addWidget( aMarkerLab, 3, 0 ); + topLayout->addWidget( myMarkerSpin, 3, 1 ); QHBoxLayout* bgLayout = new QHBoxLayout; bgLayout->addWidget( myBackgroundBtn ); bgLayout->addStretch(); - topLayout->addWidget( aBGLab, 2, 2 ); - topLayout->addLayout( bgLayout, 2, 3 ); - topLayout->addWidget( aScaleGrp, 3, 0, 1, 4 ); - topLayout->addWidget( aTabWidget, 4, 0, 1, 4 ); - topLayout->addWidget( myDefCheck, 5, 0, 1, 4 ); - topLayout->setRowStretch( 5, 5 ); - - topLayout->addLayout( btnLayout, 6, 0, 1, 4 ); + topLayout->addWidget( aBGLab, 3, 2 ); + topLayout->addLayout( bgLayout, 3, 3 ); + topLayout->addWidget( aScaleGrp, 4, 0, 1, 4 ); + topLayout->addWidget( aTabWidget, 5, 0, 1, 4 ); + topLayout->addWidget( myDefCheck, 6, 0, 1, 4 ); + topLayout->setRowStretch( 6, 5 ); + + topLayout->addLayout( btnLayout, 7, 0, 1, 4 ); if ( !showDefCheck ) myDefCheck->hide(); @@ -543,12 +551,16 @@ int Plot2d_SetupViewDlg::getCurveType() \brief Set legend attribute. \param if \c true legend is shown \param pos legend position: 0 (left), 1 (right), 2 (top), 3 (bottom) - \sa isLegendEnabled(), getLegendPos() + \param fnt legend font + \param col legend font color + \sa isLegendEnabled(), getLegendPos(), getLegendFont() */ -void Plot2d_SetupViewDlg::setLegend( bool enable, int pos ) +void Plot2d_SetupViewDlg::setLegend( bool enable, int pos, const QFont& fnt, const QColor& col ) { myLegendCheck->setChecked( enable ); myLegendCombo->setCurrentIndex( pos ); + myLegendFont->setCurrentFont( fnt ); + myLegendColor->setColor( col ); onLegendChecked(); } @@ -572,6 +584,26 @@ int Plot2d_SetupViewDlg::getLegendPos() return myLegendCombo->currentIndex(); } +/*! + \brief Get legend font. + \return legend font + \sa setLegend() +*/ +QFont Plot2d_SetupViewDlg::getLegendFont() +{ + return myLegendFont->currentFont(); +} + +/*! + \brief Get legend font color. + \return legend font color + \sa setLegend() +*/ +QColor Plot2d_SetupViewDlg::getLegendColor() +{ + return myLegendColor->color(); +} + /*! \brief Set marker size. \param size marker size diff --git a/src/Plot2d/Plot2d_SetupViewDlg.h b/src/Plot2d/Plot2d_SetupViewDlg.h index c36385964..50c7e8c37 100755 --- a/src/Plot2d/Plot2d_SetupViewDlg.h +++ b/src/Plot2d/Plot2d_SetupViewDlg.h @@ -36,6 +36,7 @@ class QLineEdit; class QComboBox; class QPushButton; class QtxColorButton; +class QtxFontEdit; class PLOT2D_EXPORT Plot2d_SetupViewDlg : public QDialog { @@ -63,9 +64,11 @@ public: void setCurveType( const int ); int getCurveType(); - void setLegend( bool, int ); + void setLegend( bool, int, const QFont&, const QColor& ); bool isLegendEnabled(); int getLegendPos(); + QFont getLegendFont(); + QColor getLegendColor(); void setMarkerSize( const int ); int getMarkerSize(); @@ -108,6 +111,8 @@ private: QLineEdit* myTitleYEdit; QLineEdit* myTitleY2Edit; QtxColorButton* myBackgroundBtn; + QtxColorButton* myLegendColor; + QtxFontEdit* myLegendFont; QCheckBox* myXGridCheck; QSpinBox* myXGridSpin; QCheckBox* myYGridCheck; diff --git a/src/Plot2d/Plot2d_ViewFrame.cxx b/src/Plot2d/Plot2d_ViewFrame.cxx index 09ddbcc12..10f2367a7 100755 --- a/src/Plot2d/Plot2d_ViewFrame.cxx +++ b/src/Plot2d/Plot2d_ViewFrame.cxx @@ -157,7 +157,8 @@ Plot2d_ViewFrame::Plot2d_ViewFrame( QWidget* parent, const QString& title ) : QWidget (parent, 0), myOperation( NoOpId ), myCurveType( 1 ), - myShowLegend( true ), myLegendPos( 1 ), + myShowLegend( true ), myLegendPos( 1 ), myLegendFont("Helvetic",12), + myLegendColor(Qt::black), myMarkerSize( DEFAULT_MARKER_SIZE ), myBackground( Qt::white ), myTitle( "" ), myXTitle( "" ), myYTitle( "" ), myY2Title( "" ), @@ -209,6 +210,8 @@ Plot2d_ViewFrame::Plot2d_ViewFrame( QWidget* parent, const QString& title ) setVerScaleMode( myYMode, false ); setBackgroundColor( myBackground ); setLegendPos( myLegendPos ); + setLegendFont( myLegendFont ); + setLegendColor( myLegendColor ); showLegend( myShowLegend, false ); myPlot->replot(); @@ -374,6 +377,8 @@ void Plot2d_ViewFrame::readPreferences() myShowLegend = resMgr->booleanValue( "Plot2d", "ShowLegend", myShowLegend ); myLegendPos = resMgr->integerValue( "Plot2d", "LegendPos", myLegendPos ); + myLegendFont = resMgr->fontValue( "Plot2d", "LegendFont", myLegendFont ); + myLegendColor = resMgr->colorValue( "Plot2d", "LegendColor", myLegendColor ); myMarkerSize = resMgr->integerValue( "Plot2d", "MarkerSize", myMarkerSize ); myBackground = resMgr->colorValue( "Plot2d", "Background", myBackground ); @@ -414,6 +419,8 @@ void Plot2d_ViewFrame::writePreferences() resMgr->setValue( "Plot2d", "CurveType", myCurveType ); resMgr->setValue( "Plot2d", "ShowLegend", myShowLegend ); resMgr->setValue( "Plot2d", "LegendPos", myLegendPos ); + resMgr->setValue( "Plot2d", "LegendFont", myLegendFont ); + resMgr->setValue( "Plot2d", "LegendColor", myLegendColor ); resMgr->setValue( "Plot2d", "MarkerSize", myMarkerSize ); resMgr->setValue( "Plot2d", "Background", myBackground ); resMgr->setValue( "Plot2d", "ShowTitle", myTitleEnabled ); @@ -1028,7 +1035,7 @@ void Plot2d_ViewFrame::onSettings() if (mySecondY) dlg->setY2Title( myY2TitleEnabled, myY2Title ); dlg->setCurveType( myCurveType ); - dlg->setLegend( myShowLegend, myLegendPos ); + dlg->setLegend( myShowLegend, myLegendPos, myLegendFont, myLegendColor ); dlg->setMarkerSize( myMarkerSize ); dlg->setBackgroundColor( myBackground ); dlg->setScaleMode(myXMode, myYMode); @@ -1062,6 +1069,13 @@ void Plot2d_ViewFrame::onSettings() if ( myLegendPos != dlg->getLegendPos() ) { setLegendPos( dlg->getLegendPos() ); } + if ( myLegendFont != dlg->getLegendFont() ) { + setLegendFont( dlg->getLegendFont() ); + } + if ( myLegendColor != dlg->getLegendColor() ) { + setLegendColor( dlg->getLegendColor() ); + } + // marker size if ( myMarkerSize != dlg->getMarkerSize() ) { setMarkerSize( dlg->getMarkerSize(), false ); @@ -1187,6 +1201,8 @@ void Plot2d_ViewFrame::showLegend( bool show, bool update ) legend->setItemMode( QwtLegend::ClickableItem ); myPlot->insertLegend( legend ); setLegendPos( myLegendPos ); + setLegendFont( myLegendFont ); + setLegendColor( myLegendColor ); } else myPlot->insertLegend( 0 ); @@ -1227,6 +1243,48 @@ int Plot2d_ViewFrame::getLegendPos() const return myLegendPos; } +/*! + Sets legend font +*/ +void Plot2d_ViewFrame::setLegendFont( const QFont& fnt ) +{ + myLegendFont = fnt; + QwtLegend* legend = myPlot->legend(); + if ( legend ) { + legend->setFont(fnt); + } +} + +/*! + Gets legend font +*/ +QFont Plot2d_ViewFrame::getLegendFont() const +{ + return myLegendFont; +} + +/*! + Gets legend font color +*/ +QColor Plot2d_ViewFrame::getLegendColor() const +{ + return myLegendColor; +} + +/*! + Sets legend font color +*/ +void Plot2d_ViewFrame::setLegendColor( const QColor& col ) +{ + myLegendColor = col; + QwtLegend* legend = myPlot->legend(); + if ( legend ) { + QPalette pal = legend->palette(); + pal.setColor( QPalette::WindowText, col ); + legend->setPalette( pal ); + } +} + /*! Sets new marker size */ diff --git a/src/Plot2d/Plot2d_ViewFrame.h b/src/Plot2d/Plot2d_ViewFrame.h index e35b2ce71..63811bae9 100755 --- a/src/Plot2d/Plot2d_ViewFrame.h +++ b/src/Plot2d/Plot2d_ViewFrame.h @@ -117,6 +117,10 @@ public: void showLegend( bool, bool = true ); void setLegendPos( int ); int getLegendPos() const; + void setLegendFont( const QFont& ); + QFont getLegendFont() const; + void setLegendColor( const QColor& ); + QColor getLegendColor() const; void setMarkerSize( const int, bool = true ); int getMarkerSize() const; void setBackgroundColor( const QColor& ); @@ -212,6 +216,8 @@ protected: int myCurveType; bool myShowLegend; int myLegendPos; + QFont myLegendFont; + QColor myLegendColor; int myMarkerSize; QColor myBackground; QString myTitle, myXTitle, myYTitle, myY2Title; diff --git a/src/Plot2d/resources/Plot2d_msg_en.ts b/src/Plot2d/resources/Plot2d_msg_en.ts index 20d717d6c..3a0ad346b 100644 --- a/src/Plot2d/resources/Plot2d_msg_en.ts +++ b/src/Plot2d/resources/Plot2d_msg_en.ts @@ -341,6 +341,10 @@ Logarithmic scale for ordinate axis is not allowed. PLOT2D_ENABLE_LEGEND Show legend + + PLOT2D_LEGEND_FONT + Legend font + DSC_ZOOM_VIEW Zoom the view -- 2.39.2