Salome HOME
Dialog SetupCurveDlg has been added
[modules/gui.git] / src / Plot2d / Plot2d_SetupCurveDlg.cxx
1 //  SALOME Plot2d : implementation of desktop and GUI kernel
2 //
3 //  Copyright (C) 2003  CEA/DEN, EDF R&D
4 //
5 //
6 //
7 //  File   : Plot2d_SetupCurveDlg.cxx
8 //  Author : Vadim SANDLER
9 //  Module : SALOME
10 //  $Header$
11
12 #include "Plot2d_SetupCurveDlg.h"
13 #include "SUIT_Tools.h"
14 #include <qlayout.h>
15 #include <qlabel.h>
16 #include <qpushbutton.h>
17 #include <qcombobox.h>
18 #include <qspinbox.h>
19 #include <qtoolbutton.h>
20 #include <qgroupbox.h>
21 #include <qcolordialog.h>
22 using namespace std;
23
24 #define MARGIN_SIZE      11
25 #define SPACING_SIZE     6
26 #define MIN_COMBO_WIDTH  100
27 #define MIN_SPIN_WIDTH   50
28 #define MAX_LINE_WIDTH   100
29
30 /*!
31   Constructor
32 */
33 Plot2d_SetupCurveDlg::Plot2d_SetupCurveDlg( QWidget* parent )
34      : QDialog( parent, "Plot2d_SetupCurveDlg", true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
35 {
36   setCaption( tr("TLT_SETUP_CURVE") );
37   setSizeGripEnabled( TRUE );
38   QGridLayout* topLayout = new QGridLayout( this ); 
39   topLayout->setSpacing( SPACING_SIZE );
40   topLayout->setMargin( MARGIN_SIZE );
41
42   QGroupBox* TopGroup = new QGroupBox( this );
43   TopGroup->setColumnLayout( 0, Qt::Vertical );
44   TopGroup->layout()->setSpacing( 0 ); TopGroup->layout()->setMargin( 0 );
45   QGridLayout* TopGroupLayout = new QGridLayout( TopGroup->layout() );
46   TopGroupLayout->setAlignment( Qt::AlignTop );
47   TopGroupLayout->setSpacing( SPACING_SIZE ); TopGroupLayout->setMargin( MARGIN_SIZE );
48
49   QLabel* aLineTypeLab = new QLabel( tr( "CURVE_LINE_TYPE_LAB" ), TopGroup );
50   myLineCombo = new QComboBox( false, TopGroup );
51   myLineCombo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
52   myLineCombo->setMinimumWidth( MIN_COMBO_WIDTH );
53   myLineCombo->insertItem( tr( "NONE_LINE_LBL" ) );
54   myLineCombo->insertItem( tr( "SOLID_LINE_LBL" ) );
55   myLineCombo->insertItem( tr( "DASH_LINE_LBL" ) );
56   myLineCombo->insertItem( tr( "DOT_LINE_LBL" ) );
57   myLineCombo->insertItem( tr( "DASHDOT_LINE_LBL" ) );
58   myLineCombo->insertItem( tr( "DAHSDOTDOT_LINE_LBL" ) );
59   myLineCombo->setCurrentItem( 1 ); // SOLID by default
60
61   QLabel* aLineWidthLab = new QLabel( tr( "CURVE_LINE_WIDTH_LAB" ), TopGroup );
62   myLineSpin = new QSpinBox( 0, MAX_LINE_WIDTH, 1, TopGroup );
63   myLineSpin->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
64   myLineSpin->setMinimumWidth( MIN_SPIN_WIDTH );
65   myLineSpin->setValue( 0 );        // default width is 0
66
67   QLabel* aMarkerLab = new QLabel( tr( "CURVE_MARKER_TYPE_LAB" ), TopGroup );
68   myMarkerCombo = new QComboBox( false, TopGroup );
69   myMarkerCombo->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
70   myMarkerCombo->setMinimumWidth( MIN_COMBO_WIDTH );
71   myMarkerCombo->insertItem( tr( "NONE_MARKER_LBL" ) );
72   myMarkerCombo->insertItem( tr( "CIRCLE_MARKER_LBL" ) );
73   myMarkerCombo->insertItem( tr( "RECTANGLE_MARKER_LBL" ) );
74   myMarkerCombo->insertItem( tr( "DIAMOND_MARKER_LBL" ) );
75   myMarkerCombo->insertItem( tr( "DTRIANGLE_MARKER_LBL" ) );
76   myMarkerCombo->insertItem( tr( "UTRIANGLE_MARKER_LBL" ) );
77   myMarkerCombo->insertItem( tr( "LTRIANGLE_MARKER_LBL" ) );
78   myMarkerCombo->insertItem( tr( "RTRIANGLE_MARKER_LBL" ) );
79   myMarkerCombo->insertItem( tr( "CROSS_MARKER_LBL" ) );
80   myMarkerCombo->insertItem( tr( "XCROSS_MARKER_LBL" ) );
81   myMarkerCombo->setCurrentItem( 1 ); // CIRCLE by default
82
83   QLabel* aColorLab = new QLabel( tr( "CURVE_COLOR_LAB" ), TopGroup );
84   myColorBtn = new QToolButton( TopGroup );
85   myColorBtn->setMinimumWidth(25);
86
87   TopGroupLayout->addWidget( aLineTypeLab, 0, 0 );
88   TopGroupLayout->addMultiCellWidget( myLineCombo, 0, 0, 1, 2 );
89   TopGroupLayout->addWidget( aLineWidthLab, 1, 0 );
90   TopGroupLayout->addMultiCellWidget( myLineSpin, 1, 1, 1, 2 );
91   TopGroupLayout->addWidget( aMarkerLab, 2, 0 );
92   TopGroupLayout->addMultiCellWidget( myMarkerCombo, 2, 2, 1, 2 );
93   TopGroupLayout->addWidget( aColorLab, 3, 0 );
94   TopGroupLayout->addWidget( myColorBtn, 3, 1 );
95   TopGroupLayout->setColStretch( 2, 5 );
96
97   QGroupBox* GroupButtons = new QGroupBox( this );
98   GroupButtons->setColumnLayout( 0, Qt::Vertical );
99   GroupButtons->layout()->setSpacing( 0 ); GroupButtons->layout()->setMargin( 0 );
100   QHBoxLayout* GroupButtonsLayout = new QHBoxLayout( GroupButtons->layout() );
101   GroupButtonsLayout->setAlignment( Qt::AlignTop );
102   GroupButtonsLayout->setSpacing( SPACING_SIZE ); GroupButtonsLayout->setMargin( MARGIN_SIZE );
103
104   myOkBtn = new QPushButton( tr( "BUT_OK" ), GroupButtons );
105   myOkBtn->setAutoDefault( true ); myOkBtn->setDefault( true );
106   myCancelBtn = new QPushButton( tr( "BUT_CANCEL" ) , GroupButtons );
107   myCancelBtn->setAutoDefault( true );
108
109   GroupButtonsLayout->addWidget( myOkBtn );
110   GroupButtonsLayout->addStretch();
111   GroupButtonsLayout->addWidget( myCancelBtn );
112
113   connect( myColorBtn,  SIGNAL( clicked() ), this, SLOT( onColorChanged() ) );
114   connect( myOkBtn,     SIGNAL( clicked() ), this, SLOT( accept() ) );
115   connect( myCancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) );
116   setColor( QColor( 0, 0, 0 ) );
117
118   topLayout->addWidget( TopGroup,     0, 0 );
119   topLayout->addWidget( GroupButtons, 1, 0 );
120
121   SUIT_Tools::centerWidget( this, parent );
122 }
123 /*!
124   Destructor
125 */
126 Plot2d_SetupCurveDlg::~Plot2d_SetupCurveDlg()
127 {
128 }
129 /*!
130   Sets line style and width
131 */
132 void Plot2d_SetupCurveDlg::setLine( const int line, const int width )
133 {
134   myLineCombo->setCurrentItem( line );
135   myLineSpin->setValue( width );
136 }
137 /*!
138   Gets line style
139 */
140 int Plot2d_SetupCurveDlg::getLine() const
141 {
142   return myLineCombo->currentItem();
143 }
144 /*!
145   Gets line width
146 */
147 int Plot2d_SetupCurveDlg::getLineWidth() const
148 {
149   return myLineSpin->value();
150 }
151 /*!
152   Sets marker style
153 */
154 void Plot2d_SetupCurveDlg::setMarker( const int marker )
155 {
156   myMarkerCombo->setCurrentItem( marker );
157 }
158 /*!
159   Gets marker style
160 */
161 int Plot2d_SetupCurveDlg::getMarker() const 
162 {
163   return myMarkerCombo->currentItem();
164 }
165 /*!
166   Sets color
167 */
168 void Plot2d_SetupCurveDlg::setColor( const QColor& color )
169 {
170   QPalette pal = myColorBtn->palette();
171   QColorGroup ca = pal.active();
172   ca.setColor( QColorGroup::Button, color );
173   QColorGroup ci = pal.inactive();
174   ci.setColor( QColorGroup::Button, color );
175   pal.setActive( ca );
176   pal.setInactive( ci );
177   myColorBtn->setPalette( pal );
178 }
179 /*!
180   Gets color
181 */
182 QColor Plot2d_SetupCurveDlg::getColor() const 
183 {
184   return myColorBtn->palette().active().button();
185 }
186 /*!
187   <Color> button slot, invokes color selection dialog box
188 */
189 void Plot2d_SetupCurveDlg::onColorChanged()
190 {
191   QColor color = QColorDialog::getColor( getColor() );
192   if ( color.isValid() ) {
193     setColor( color );
194   }
195 }
196
197
198
199
200