Back to index

salome-gui  6.5.0
Plot2d_SetupCurveDlg.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 // File   : Plot2d_SetupCurveDlg.cxx
00024 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
00025 //
00026 #include "Plot2d_SetupCurveDlg.h"
00027 
00028 #include <QtxColorButton.h>
00029 #include <SUIT_Tools.h>
00030 
00031 #include <QGridLayout>
00032 #include <QHBoxLayout>
00033 #include <QLabel>
00034 #include <QPushButton>
00035 #include <QComboBox>
00036 #include <QSpinBox>
00037 #include <QPainter>
00038 
00039 const int MARGIN_SIZE     = 11;
00040 const int SPACING_SIZE    = 6;
00041 const int MIN_COMBO_WIDTH = 100;
00042 const int MIN_SPIN_WIDTH  = 50;
00043 const int MAX_LINE_WIDTH  = 10;
00044 const int MSIZE           = 9;
00045 
00055 Plot2d_SetupCurveDlg::Plot2d_SetupCurveDlg( QWidget* parent )
00056 : QDialog( parent )
00057 {
00058   setModal( true );
00059   setWindowTitle( tr("TLT_SETUP_CURVE") );
00060   setSizeGripEnabled( true );
00061 
00062   // curve type
00063   QLabel* aLineTypeLab = new QLabel( tr( "CURVE_LINE_TYPE_LAB" ), this );
00064   myLineCombo = new QComboBox( this );
00065   myLineCombo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
00066   myLineCombo->setMinimumWidth( MIN_COMBO_WIDTH );
00067   QSize lsz( 40, 16 );
00068   myLineCombo->setIconSize( lsz );
00069 
00070   // curve width
00071   QLabel* aLineWidthLab = new QLabel( tr( "CURVE_LINE_WIDTH_LAB" ), this );
00072   myLineSpin = new QSpinBox( this );
00073   myLineSpin->setMinimum( 0 );
00074   myLineSpin->setMaximum( MAX_LINE_WIDTH );
00075   myLineSpin->setSingleStep( 1 );
00076   myLineSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
00077   myLineSpin->setMinimumWidth( MIN_SPIN_WIDTH );
00078 
00079   // marker type
00080   QLabel* aMarkerLab = new QLabel( tr( "CURVE_MARKER_TYPE_LAB" ), this );
00081   myMarkerCombo = new QComboBox( this );
00082   myMarkerCombo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
00083   myMarkerCombo->setMinimumWidth( MIN_COMBO_WIDTH );
00084   QSize sz(16, 16);
00085   myMarkerCombo->setIconSize(sz);
00086 
00087   // curve color
00088   QLabel* aColorLab = new QLabel( tr( "CURVE_COLOR_LAB" ), this );
00089   myColorBtn = new QtxColorButton( this );
00090 
00091   // preview
00092   QLabel* aPreviewLab = new QLabel( tr( "CURVE_PREVIEW_LAB" ), this );
00093   myPreview = new QLabel( this );
00094   myPreview->setFrameStyle( QLabel::Box | QLabel::Sunken );
00095   myPreview->setAlignment( Qt::AlignCenter );
00096   myPreview->setScaledContents( false );
00097 
00098   myOkBtn     = new QPushButton( tr( "BUT_OK" ),     this );
00099   myCancelBtn = new QPushButton( tr( "BUT_CANCEL" ), this );
00100 
00101   // layouting widgets
00102   QGridLayout* topLayout = new QGridLayout( this );
00103   topLayout->setSpacing( SPACING_SIZE );
00104   topLayout->setMargin( MARGIN_SIZE );
00105 
00106   topLayout->addWidget( aLineTypeLab,  0, 0 );
00107   topLayout->addWidget( myLineCombo,   0, 1, 1, 2 );
00108   topLayout->addWidget( aLineWidthLab, 1, 0 );
00109   topLayout->addWidget( myLineSpin,    1, 1, 1, 2 );
00110   topLayout->addWidget( aMarkerLab,    2, 0 );
00111   topLayout->addWidget( myMarkerCombo, 2, 1, 1, 2 );
00112   topLayout->addWidget( aColorLab,     3, 0 );
00113   topLayout->addWidget( myColorBtn,    3, 1 );
00114   topLayout->addWidget( aPreviewLab,   4, 0 );
00115   topLayout->addWidget( myPreview,     4, 1, 1, 2 );
00116   topLayout->setColumnStretch( 2, 5 );
00117 
00118   QHBoxLayout* btnLayout = new QHBoxLayout;
00119   btnLayout->setSpacing( SPACING_SIZE );
00120   btnLayout->setMargin( 0 );
00121 
00122   btnLayout->addWidget( myOkBtn );
00123   btnLayout->addSpacing( 20 );
00124   btnLayout->addStretch();
00125   btnLayout->addWidget( myCancelBtn );
00126 
00127   topLayout->addLayout( btnLayout, 5, 0, 1, 3 );
00128 
00129   // fill then combo boxes
00130   QColor cl = myLineCombo->palette().color( QPalette::Text );
00131 
00132   myLineCombo->addItem( Plot2d::lineIcon( lsz, cl, Plot2d::NoPen ),      tr( "NONE_LINE_LBL" ) );
00133   myLineCombo->addItem( Plot2d::lineIcon( lsz, cl, Plot2d::Solid ),      tr( "SOLID_LINE_LBL" ) );
00134   myLineCombo->addItem( Plot2d::lineIcon( lsz, cl, Plot2d::Dash ),       tr( "DASH_LINE_LBL" ) );
00135   myLineCombo->addItem( Plot2d::lineIcon( lsz, cl, Plot2d::Dot ),        tr( "DOT_LINE_LBL" ) );
00136   myLineCombo->addItem( Plot2d::lineIcon( lsz, cl, Plot2d::DashDot ),    tr( "DASHDOT_LINE_LBL" ) );
00137   myLineCombo->addItem( Plot2d::lineIcon( lsz, cl, Plot2d::DashDotDot ), tr( "DAHSDOTDOT_LINE_LBL" ) );
00138 
00139   cl = myMarkerCombo->palette().color( QPalette::Text );
00140 
00141   myMarkerCombo->addItem( Plot2d::markerIcon( sz, cl, Plot2d::None ),      tr( "NONE_MARKER_LBL" ) );
00142   myMarkerCombo->addItem( Plot2d::markerIcon( sz, cl, Plot2d::Circle ),    tr( "CIRCLE_MARKER_LBL" ) );
00143   myMarkerCombo->addItem( Plot2d::markerIcon( sz, cl, Plot2d::Rectangle ), tr( "RECTANGLE_MARKER_LBL" ) );
00144   myMarkerCombo->addItem( Plot2d::markerIcon( sz, cl, Plot2d::Diamond ),   tr( "DIAMOND_MARKER_LBL" ) );
00145   myMarkerCombo->addItem( Plot2d::markerIcon( sz, cl, Plot2d::DTriangle ), tr( "DTRIANGLE_MARKER_LBL" ) );
00146   myMarkerCombo->addItem( Plot2d::markerIcon( sz, cl, Plot2d::UTriangle ), tr( "UTRIANGLE_MARKER_LBL" ) );
00147   myMarkerCombo->addItem( Plot2d::markerIcon( sz, cl, Plot2d::LTriangle ), tr( "LTRIANGLE_MARKER_LBL" ) );
00148   myMarkerCombo->addItem( Plot2d::markerIcon( sz, cl, Plot2d::RTriangle ), tr( "RTRIANGLE_MARKER_LBL" ) );
00149   myMarkerCombo->addItem( Plot2d::markerIcon( sz, cl, Plot2d::Cross ),     tr( "CROSS_MARKER_LBL" ) );
00150   myMarkerCombo->addItem( Plot2d::markerIcon( sz, cl, Plot2d::XCross ),    tr( "XCROSS_MARKER_LBL" ) );
00151 
00152   // default settings
00153   setLine( Plot2d::Solid, 0 );   // solid line, width = 0
00154   setMarker( Plot2d::Circle );   // circle
00155   setColor( QColor( 0, 0, 0 ) ); // black
00156 
00157   // connections
00158   connect( myLineCombo,   SIGNAL( activated( int ) ),    this, SLOT( updatePreview() ) );
00159   connect( myLineSpin,    SIGNAL( valueChanged( int ) ), this, SLOT( updatePreview() ) );
00160   connect( myMarkerCombo, SIGNAL( activated( int ) ),    this, SLOT( updatePreview() ) );
00161   connect( myColorBtn,    SIGNAL( changed( QColor ) ),   this, SLOT( updatePreview() ) );
00162   connect( myOkBtn,       SIGNAL( clicked() ),           this, SLOT( accept() ) );
00163   connect( myCancelBtn,   SIGNAL( clicked() ),           this, SLOT( reject() ) );
00164 
00165   SUIT_Tools::centerWidget( this, parent );
00166   updatePreview();
00167 }
00168 
00172 Plot2d_SetupCurveDlg::~Plot2d_SetupCurveDlg()
00173 {
00174 }
00175 
00182 void Plot2d_SetupCurveDlg::setLine( Plot2d::LineType type, const int width )
00183 {
00184   myLineCombo->setCurrentIndex( (int)type );
00185   if ( width > myLineSpin->maximum() )
00186     myLineSpin->setMaximum( width );
00187   myLineSpin->setValue( width );
00188   updatePreview();
00189 }
00190 
00196 Plot2d::LineType Plot2d_SetupCurveDlg::getLine() const
00197 {
00198   return (Plot2d::LineType)myLineCombo->currentIndex();
00199 }
00200 
00206 int Plot2d_SetupCurveDlg::getLineWidth() const
00207 {
00208   return myLineSpin->value();
00209 }
00210 
00216 void Plot2d_SetupCurveDlg::setMarker( Plot2d::MarkerType type )
00217 {
00218   myMarkerCombo->setCurrentIndex( (int)type );
00219   updatePreview();
00220 }
00221 
00227 Plot2d::MarkerType Plot2d_SetupCurveDlg::getMarker() const
00228 {
00229   return (Plot2d::MarkerType)myMarkerCombo->currentIndex();
00230 }
00231 
00237 void Plot2d_SetupCurveDlg::setColor( const QColor& color )
00238 {
00239   myColorBtn->setColor( color );
00240   updatePreview();
00241 }
00242 
00248 QColor Plot2d_SetupCurveDlg::getColor() const
00249 {
00250   return myColorBtn->color();
00251 }
00252 
00253 /*
00254   \brief Update preview widget.
00255 */
00256 void Plot2d_SetupCurveDlg::updatePreview()
00257 {
00258   QSize sz( 150, 20 );
00259   QPixmap px( sz );
00260   px.fill( palette().color( QPalette::Background ) );
00261 
00262   QPainter p( &px );
00263 
00264   Plot2d::drawLine( &p, 5+MSIZE/2, sz.height()/2, sz.width()-5-MSIZE/2, sz.height()/2,
00265                     getLine(), getColor(), getLineWidth() );
00266   Plot2d::drawMarker( &p, 5+MSIZE/2, sz.height()/2, MSIZE, MSIZE,
00267                       getMarker(), getColor() );
00268   Plot2d::drawMarker( &p, sz.width()-5-MSIZE/2, sz.height()/2, MSIZE, MSIZE,
00269                       getMarker(), getColor() );
00270 
00271   myPreview->setPixmap( px );
00272 }