1 // Copyright (C) 2007-2008 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
22 // File : Plot2d_SetupCurveDlg.cxx
23 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
25 #include "Plot2d_SetupCurveDlg.h"
27 #include <QtxColorButton.h>
28 #include <SUIT_Tools.h>
30 #include <QGridLayout>
31 #include <QHBoxLayout>
33 #include <QPushButton>
38 const int MARGIN_SIZE = 11;
39 const int SPACING_SIZE = 6;
40 const int MIN_COMBO_WIDTH = 100;
41 const int MIN_SPIN_WIDTH = 50;
42 const int MAX_LINE_WIDTH = 10;
46 \class Plot2d_SetupCurveDlg
47 \brief Dialog box for modifying 2d curve settings.
52 \param parent parent widget
54 Plot2d_SetupCurveDlg::Plot2d_SetupCurveDlg( QWidget* parent )
58 setWindowTitle( tr("TLT_SETUP_CURVE") );
59 setSizeGripEnabled( true );
62 QLabel* aLineTypeLab = new QLabel( tr( "CURVE_LINE_TYPE_LAB" ), this );
63 myLineCombo = new QComboBox( this );
64 myLineCombo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
65 myLineCombo->setMinimumWidth( MIN_COMBO_WIDTH );
66 myLineCombo->setIconSize( QSize( 40, 16 ) );
69 QLabel* aLineWidthLab = new QLabel( tr( "CURVE_LINE_WIDTH_LAB" ), this );
70 myLineSpin = new QSpinBox( this );
71 myLineSpin->setMinimum( 0 );
72 myLineSpin->setMaximum( MAX_LINE_WIDTH );
73 myLineSpin->setSingleStep( 1 );
74 myLineSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
75 myLineSpin->setMinimumWidth( MIN_SPIN_WIDTH );
78 QLabel* aMarkerLab = new QLabel( tr( "CURVE_MARKER_TYPE_LAB" ), this );
79 myMarkerCombo = new QComboBox( this );
80 myMarkerCombo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
81 myMarkerCombo->setMinimumWidth( MIN_COMBO_WIDTH );
82 myMarkerCombo->setIconSize( QSize( 16, 16 ) );
85 QLabel* aColorLab = new QLabel( tr( "CURVE_COLOR_LAB" ), this );
86 myColorBtn = new QtxColorButton( this );
89 QLabel* aPreviewLab = new QLabel( tr( "CURVE_PREVIEW_LAB" ), this );
90 myPreview = new QLabel( this );
91 myPreview->setFrameStyle( QLabel::Box | QLabel::Sunken );
92 myPreview->setAlignment( Qt::AlignCenter );
93 myPreview->setScaledContents( false );
95 myOkBtn = new QPushButton( tr( "BUT_OK" ), this );
96 myCancelBtn = new QPushButton( tr( "BUT_CANCEL" ), this );
99 QGridLayout* topLayout = new QGridLayout( this );
100 topLayout->setSpacing( SPACING_SIZE );
101 topLayout->setMargin( MARGIN_SIZE );
103 topLayout->addWidget( aLineTypeLab, 0, 0 );
104 topLayout->addWidget( myLineCombo, 0, 1, 1, 2 );
105 topLayout->addWidget( aLineWidthLab, 1, 0 );
106 topLayout->addWidget( myLineSpin, 1, 1, 1, 2 );
107 topLayout->addWidget( aMarkerLab, 2, 0 );
108 topLayout->addWidget( myMarkerCombo, 2, 1, 1, 2 );
109 topLayout->addWidget( aColorLab, 3, 0 );
110 topLayout->addWidget( myColorBtn, 3, 1 );
111 topLayout->addWidget( aPreviewLab, 4, 0 );
112 topLayout->addWidget( myPreview, 4, 1, 1, 2 );
113 topLayout->setColumnStretch( 2, 5 );
115 QHBoxLayout* btnLayout = new QHBoxLayout;
116 btnLayout->setSpacing( SPACING_SIZE );
117 btnLayout->setMargin( 0 );
119 btnLayout->addWidget( myOkBtn );
120 btnLayout->addSpacing( 20 );
121 btnLayout->addStretch();
122 btnLayout->addWidget( myCancelBtn );
124 topLayout->addLayout( btnLayout, 5, 0, 1, 3 );
126 // fill then combo boxes
127 myLineCombo->addItem( lineIcon( Plot2d::NoPen ), tr( "NONE_LINE_LBL" ) );
128 myLineCombo->addItem( lineIcon( Plot2d::Solid ), tr( "SOLID_LINE_LBL" ) );
129 myLineCombo->addItem( lineIcon( Plot2d::Dash ), tr( "DASH_LINE_LBL" ) );
130 myLineCombo->addItem( lineIcon( Plot2d::Dot ), tr( "DOT_LINE_LBL" ) );
131 myLineCombo->addItem( lineIcon( Plot2d::DashDot ), tr( "DASHDOT_LINE_LBL" ) );
132 myLineCombo->addItem( lineIcon( Plot2d::DashDotDot ), tr( "DAHSDOTDOT_LINE_LBL" ) );
134 myMarkerCombo->addItem( markerIcon( Plot2d::None ), tr( "NONE_MARKER_LBL" ) );
135 myMarkerCombo->addItem( markerIcon( Plot2d::Circle ), tr( "CIRCLE_MARKER_LBL" ) );
136 myMarkerCombo->addItem( markerIcon( Plot2d::Rectangle ), tr( "RECTANGLE_MARKER_LBL" ) );
137 myMarkerCombo->addItem( markerIcon( Plot2d::Diamond ), tr( "DIAMOND_MARKER_LBL" ) );
138 myMarkerCombo->addItem( markerIcon( Plot2d::DTriangle ), tr( "DTRIANGLE_MARKER_LBL" ) );
139 myMarkerCombo->addItem( markerIcon( Plot2d::UTriangle ), tr( "UTRIANGLE_MARKER_LBL" ) );
140 myMarkerCombo->addItem( markerIcon( Plot2d::LTriangle ), tr( "LTRIANGLE_MARKER_LBL" ) );
141 myMarkerCombo->addItem( markerIcon( Plot2d::RTriangle ), tr( "RTRIANGLE_MARKER_LBL" ) );
142 myMarkerCombo->addItem( markerIcon( Plot2d::Cross ), tr( "CROSS_MARKER_LBL" ) );
143 myMarkerCombo->addItem( markerIcon( Plot2d::XCross ), tr( "XCROSS_MARKER_LBL" ) );
146 setLine( Plot2d::Solid, 0 ); // solid line, width = 0
147 setMarker( Plot2d::Circle ); // circle
148 setColor( QColor( 0, 0, 0 ) ); // black
151 connect( myLineCombo, SIGNAL( activated( int ) ), this, SLOT( updatePreview() ) );
152 connect( myLineSpin, SIGNAL( valueChanged( int ) ), this, SLOT( updatePreview() ) );
153 connect( myMarkerCombo, SIGNAL( activated( int ) ), this, SLOT( updatePreview() ) );
154 connect( myColorBtn, SIGNAL( changed( QColor ) ), this, SLOT( updatePreview() ) );
155 connect( myOkBtn, SIGNAL( clicked() ), this, SLOT( accept() ) );
156 connect( myCancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) );
158 SUIT_Tools::centerWidget( this, parent );
165 Plot2d_SetupCurveDlg::~Plot2d_SetupCurveDlg()
170 \brief Set curve line type and width.
171 \param type curve line type
172 \param width curve line width
173 \sa getLine(), getLineWidth()
175 void Plot2d_SetupCurveDlg::setLine( Plot2d::LineType type, const int width )
177 myLineCombo->setCurrentIndex( (int)type );
178 if ( width > myLineSpin->maximum() )
179 myLineSpin->setMaximum( width );
180 myLineSpin->setValue( width );
185 \brief Get curve line type.
186 \return chosen curve line type
187 \sa setLine(), getLineWidth()
189 Plot2d::LineType Plot2d_SetupCurveDlg::getLine() const
191 return (Plot2d::LineType)myLineCombo->currentIndex();
195 \brief Get curve line width.
196 \return chosen curve line width
197 \sa setLine(), getLine()
199 int Plot2d_SetupCurveDlg::getLineWidth() const
201 return myLineSpin->value();
205 \brief Set curve marker type.
206 \param type curve marker type
209 void Plot2d_SetupCurveDlg::setMarker( Plot2d::MarkerType type )
211 myMarkerCombo->setCurrentIndex( (int)type );
216 \brief Get curve marker type.
217 \return chosen curve marker type
220 Plot2d::MarkerType Plot2d_SetupCurveDlg::getMarker() const
222 return (Plot2d::MarkerType)myMarkerCombo->currentIndex();
226 \brief Set curve color.
227 \param color curve color
230 void Plot2d_SetupCurveDlg::setColor( const QColor& color )
232 myColorBtn->setColor( color );
237 \brief Get curve color.
241 QColor Plot2d_SetupCurveDlg::getColor() const
243 return myColorBtn->color();
247 \brief Create icon pixmap according to the line type.
248 \param type line type
251 QPixmap Plot2d_SetupCurveDlg::lineIcon( Plot2d::LineType type ) const
253 QSize sz = myLineCombo->iconSize();
255 px.fill( QColor( 255, 255, 255, 0 ) );
257 Plot2d::drawLine( &p, 5, sz.height()/2, sz.width()-5, sz.height()/2, type,
258 myLineCombo->palette().color( QPalette::Text ), 1 );
263 \brief Create icon pixmap according to the marker type.
264 \param type marker type
267 QPixmap Plot2d_SetupCurveDlg::markerIcon( Plot2d::MarkerType type ) const
269 QSize sz = myMarkerCombo->iconSize();
271 px.fill( QColor( 255, 255, 255, 0 ) );
273 Plot2d::drawMarker( &p, sz.width()/2, sz.height()/2, MSIZE, MSIZE, type,
274 myMarkerCombo->palette().color( QPalette::Text ) );
279 \brief Update preview widget.
281 void Plot2d_SetupCurveDlg::updatePreview()
285 px.fill( palette().color( QPalette::Background ) );
289 Plot2d::drawLine( &p, 5+MSIZE/2, sz.height()/2, sz.width()-5-MSIZE/2, sz.height()/2,
290 getLine(), getColor(), getLineWidth() );
291 Plot2d::drawMarker( &p, 5+MSIZE/2, sz.height()/2, MSIZE, MSIZE,
292 getMarker(), getColor() );
293 Plot2d::drawMarker( &p, sz.width()-5-MSIZE/2, sz.height()/2, MSIZE, MSIZE,
294 getMarker(), getColor() );
296 myPreview->setPixmap( px );