1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : Plot2d_SetupCurveDlg.cxx
24 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
26 #include "Plot2d_SetupCurveDlg.h"
28 #include <QtxColorButton.h>
30 #include <SUIT_Tools.h>
33 #include <QGridLayout>
34 #include <QHBoxLayout>
36 #include <QPushButton>
41 const int MARGIN_SIZE = 11;
42 const int SPACING_SIZE = 6;
43 const int MIN_COMBO_WIDTH = 100;
44 const int MIN_SPIN_WIDTH = 50;
45 const int MAX_LINE_WIDTH = 10;
49 \class Plot2d_SetupCurveDlg
50 \brief Dialog box for modifying 2d curve settings.
55 \param parent parent widget
57 Plot2d_SetupCurveDlg::Plot2d_SetupCurveDlg( QWidget* parent )
61 setWindowTitle( tr("TLT_SETUP_CURVE") );
62 setSizeGripEnabled( true );
65 QLabel* aLineTypeLab = new QLabel( tr( "CURVE_LINE_TYPE_LAB" ), this );
66 myLineCombo = new QComboBox( this );
67 myLineCombo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
68 myLineCombo->setMinimumWidth( MIN_COMBO_WIDTH );
70 myLineCombo->setIconSize( lsz );
73 QLabel* aLineWidthLab = new QLabel( tr( "CURVE_LINE_WIDTH_LAB" ), this );
74 myLineSpin = new QSpinBox( this );
75 myLineSpin->setMinimum( 0 );
76 myLineSpin->setMaximum( MAX_LINE_WIDTH );
77 myLineSpin->setSingleStep( 1 );
78 myLineSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
79 myLineSpin->setMinimumWidth( MIN_SPIN_WIDTH );
82 QLabel* aMarkerLab = new QLabel( tr( "CURVE_MARKER_TYPE_LAB" ), this );
83 myMarkerCombo = new QComboBox( this );
84 myMarkerCombo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
85 myMarkerCombo->setMinimumWidth( MIN_COMBO_WIDTH );
87 myMarkerCombo->setIconSize(sz);
90 QLabel* aColorLab = new QLabel( tr( "CURVE_COLOR_LAB" ), this );
91 myColorBtn = new QtxColorButton( this );
94 QLabel* aPreviewLab = new QLabel( tr( "CURVE_PREVIEW_LAB" ), this );
95 myPreview = new QLabel( this );
96 myPreview->setFrameStyle( QLabel::Box | QLabel::Sunken );
97 myPreview->setAlignment( Qt::AlignCenter );
98 myPreview->setScaledContents( false );
100 myOkBtn = new QPushButton( tr( "BUT_OK" ), this );
101 myCancelBtn = new QPushButton( tr( "BUT_CANCEL" ), this );
104 QGridLayout* topLayout = new QGridLayout( this );
105 topLayout->setSpacing( SPACING_SIZE );
106 topLayout->setMargin( MARGIN_SIZE );
108 topLayout->addWidget( aLineTypeLab, 0, 0 );
109 topLayout->addWidget( myLineCombo, 0, 1, 1, 2 );
110 topLayout->addWidget( aLineWidthLab, 1, 0 );
111 topLayout->addWidget( myLineSpin, 1, 1, 1, 2 );
112 topLayout->addWidget( aMarkerLab, 2, 0 );
113 topLayout->addWidget( myMarkerCombo, 2, 1, 1, 2 );
114 topLayout->addWidget( aColorLab, 3, 0 );
115 topLayout->addWidget( myColorBtn, 3, 1 );
116 topLayout->addWidget( aPreviewLab, 4, 0 );
117 topLayout->addWidget( myPreview, 4, 1, 1, 2 );
118 topLayout->setColumnStretch( 2, 5 );
120 QHBoxLayout* btnLayout = new QHBoxLayout;
121 btnLayout->setSpacing( SPACING_SIZE );
122 btnLayout->setMargin( 0 );
124 btnLayout->addWidget( myOkBtn );
125 btnLayout->addSpacing( 20 );
126 btnLayout->addStretch();
127 btnLayout->addWidget( myCancelBtn );
129 topLayout->addLayout( btnLayout, 5, 0, 1, 3 );
131 // fill then combo boxes
132 QColor cl = myLineCombo->palette().color( QPalette::Text );
134 myLineCombo->addItem( Plot2d::lineIcon( lsz, cl, Plot2d::NoPen ), tr( "NONE_LINE_LBL" ) );
135 myLineCombo->addItem( Plot2d::lineIcon( lsz, cl, Plot2d::Solid ), tr( "SOLID_LINE_LBL" ) );
136 myLineCombo->addItem( Plot2d::lineIcon( lsz, cl, Plot2d::Dash ), tr( "DASH_LINE_LBL" ) );
137 myLineCombo->addItem( Plot2d::lineIcon( lsz, cl, Plot2d::Dot ), tr( "DOT_LINE_LBL" ) );
138 myLineCombo->addItem( Plot2d::lineIcon( lsz, cl, Plot2d::DashDot ), tr( "DASHDOT_LINE_LBL" ) );
139 myLineCombo->addItem( Plot2d::lineIcon( lsz, cl, Plot2d::DashDotDot ), tr( "DAHSDOTDOT_LINE_LBL" ) );
141 cl = myMarkerCombo->palette().color( QPalette::Text );
143 myMarkerCombo->addItem( Plot2d::markerIcon( sz, cl, Plot2d::None ), tr( "NONE_MARKER_LBL" ) );
144 myMarkerCombo->addItem( Plot2d::markerIcon( sz, cl, Plot2d::Circle ), tr( "CIRCLE_MARKER_LBL" ) );
145 myMarkerCombo->addItem( Plot2d::markerIcon( sz, cl, Plot2d::Rectangle ), tr( "RECTANGLE_MARKER_LBL" ) );
146 myMarkerCombo->addItem( Plot2d::markerIcon( sz, cl, Plot2d::Diamond ), tr( "DIAMOND_MARKER_LBL" ) );
147 myMarkerCombo->addItem( Plot2d::markerIcon( sz, cl, Plot2d::DTriangle ), tr( "DTRIANGLE_MARKER_LBL" ) );
148 myMarkerCombo->addItem( Plot2d::markerIcon( sz, cl, Plot2d::UTriangle ), tr( "UTRIANGLE_MARKER_LBL" ) );
149 myMarkerCombo->addItem( Plot2d::markerIcon( sz, cl, Plot2d::LTriangle ), tr( "LTRIANGLE_MARKER_LBL" ) );
150 myMarkerCombo->addItem( Plot2d::markerIcon( sz, cl, Plot2d::RTriangle ), tr( "RTRIANGLE_MARKER_LBL" ) );
151 myMarkerCombo->addItem( Plot2d::markerIcon( sz, cl, Plot2d::Cross ), tr( "CROSS_MARKER_LBL" ) );
152 myMarkerCombo->addItem( Plot2d::markerIcon( sz, cl, Plot2d::XCross ), tr( "XCROSS_MARKER_LBL" ) );
155 setLine( Plot2d::Solid, 0 ); // solid line, width = 0
156 setMarker( Plot2d::Circle ); // circle
157 setColor( QColor( 0, 0, 0 ) ); // black
160 connect( myLineCombo, SIGNAL( activated( int ) ), this, SLOT( updatePreview() ) );
161 connect( myLineSpin, SIGNAL( valueChanged( int ) ), this, SLOT( updatePreview() ) );
162 connect( myMarkerCombo, SIGNAL( activated( int ) ), this, SLOT( updatePreview() ) );
163 connect( myColorBtn, SIGNAL( changed( QColor ) ), this, SLOT( updatePreview() ) );
164 connect( myOkBtn, SIGNAL( clicked() ), this, SLOT( accept() ) );
165 connect( myCancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) );
168 SUIT_Tools::centerWidget( this, parent );
176 Plot2d_SetupCurveDlg::~Plot2d_SetupCurveDlg()
181 \brief Set curve line type and width.
182 \param type curve line type
183 \param width curve line width
184 \sa getLine(), getLineWidth()
186 void Plot2d_SetupCurveDlg::setLine( Plot2d::LineType type, const int width )
188 myLineCombo->setCurrentIndex( (int)type );
189 if ( width > myLineSpin->maximum() )
190 myLineSpin->setMaximum( width );
191 myLineSpin->setValue( width );
196 \brief Get curve line type.
197 \return chosen curve line type
198 \sa setLine(), getLineWidth()
200 Plot2d::LineType Plot2d_SetupCurveDlg::getLine() const
202 return (Plot2d::LineType)myLineCombo->currentIndex();
206 \brief Get curve line width.
207 \return chosen curve line width
208 \sa setLine(), getLine()
210 int Plot2d_SetupCurveDlg::getLineWidth() const
212 return myLineSpin->value();
216 \brief Set curve marker type.
217 \param type curve marker type
220 void Plot2d_SetupCurveDlg::setMarker( Plot2d::MarkerType type )
222 myMarkerCombo->setCurrentIndex( (int)type );
227 \brief Get curve marker type.
228 \return chosen curve marker type
231 Plot2d::MarkerType Plot2d_SetupCurveDlg::getMarker() const
233 return (Plot2d::MarkerType)myMarkerCombo->currentIndex();
237 \brief Set curve color.
238 \param color curve color
241 void Plot2d_SetupCurveDlg::setColor( const QColor& color )
243 myColorBtn->setColor( color );
248 \brief Get curve color.
252 QColor Plot2d_SetupCurveDlg::getColor() const
254 return myColorBtn->color();
258 \brief Update preview widget.
260 void Plot2d_SetupCurveDlg::updatePreview()
264 px.fill( palette().color( QPalette::Background ) );
268 Plot2d::drawLine( &p, 5+MSIZE/2, sz.height()/2, sz.width()-5-MSIZE/2, sz.height()/2,
269 getLine(), getColor(), getLineWidth() );
270 Plot2d::drawMarker( &p, 5+MSIZE/2, sz.height()/2, MSIZE, MSIZE,
271 getMarker(), getColor() );
272 Plot2d::drawMarker( &p, sz.width()-5-MSIZE/2, sz.height()/2, MSIZE, MSIZE,
273 getMarker(), getColor() );
275 myPreview->setPixmap( px );