Salome HOME
Porting to Mandrake 10.1 and new products:
[modules/kernel.git] / src / SALOMEGUI / SALOMEGUI_SetupCurveDlg.cxx
1 //  SALOME SALOMEGUI : implementation of desktop and GUI kernel
2 //
3 //  Copyright (C) 2003  CEA/DEN, EDF R&D
4 //
5 //
6 //
7 //  File   : SALOMEGUI_SetupCurveDlg.cxx
8 //  Author : Vadim SANDLER
9 //  Module : SALOME
10 //  $Header$
11
12 #include "SALOMEGUI_SetupCurveDlg.h"
13 #include "QAD_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 SALOMEGUI_SetupCurveDlg::SALOMEGUI_SetupCurveDlg( QWidget* parent )
34      : QDialog( parent, "SALOMEGUI_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
86   TopGroupLayout->addWidget( aLineTypeLab, 0, 0 );
87   TopGroupLayout->addMultiCellWidget( myLineCombo, 0, 0, 1, 2 );
88   TopGroupLayout->addWidget( aLineWidthLab, 1, 0 );
89   TopGroupLayout->addMultiCellWidget( myLineSpin, 1, 1, 1, 2 );
90   TopGroupLayout->addWidget( aMarkerLab, 2, 0 );
91   TopGroupLayout->addMultiCellWidget( myMarkerCombo, 2, 2, 1, 2 );
92   TopGroupLayout->addWidget( aColorLab, 3, 0 );
93   TopGroupLayout->addWidget( myColorBtn, 3, 1 );
94   TopGroupLayout->setColStretch( 2, 5 );
95
96   QGroupBox* GroupButtons = new QGroupBox( this );
97   GroupButtons->setColumnLayout( 0, Qt::Vertical );
98   GroupButtons->layout()->setSpacing( 0 ); GroupButtons->layout()->setMargin( 0 );
99   QHBoxLayout* GroupButtonsLayout = new QHBoxLayout( GroupButtons->layout() );
100   GroupButtonsLayout->setAlignment( Qt::AlignTop );
101   GroupButtonsLayout->setSpacing( SPACING_SIZE ); GroupButtonsLayout->setMargin( MARGIN_SIZE );
102
103   myOkBtn = new QPushButton( tr( "BUT_OK" ), GroupButtons );
104   myOkBtn->setAutoDefault( true ); myOkBtn->setDefault( true );
105   myCancelBtn = new QPushButton( tr( "BUT_CANCEL" ) , GroupButtons );
106   myCancelBtn->setAutoDefault( true );
107
108   GroupButtonsLayout->addWidget( myOkBtn );
109   GroupButtonsLayout->addStretch();
110   GroupButtonsLayout->addWidget( myCancelBtn );
111
112   connect( myColorBtn,  SIGNAL( clicked() ), this, SLOT( onColorChanged() ) );
113   connect( myOkBtn,     SIGNAL( clicked() ), this, SLOT( accept() ) );
114   connect( myCancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) );
115   setColor( QColor( 0, 0, 0 ) );
116
117   topLayout->addWidget( TopGroup,     0, 0 );
118   topLayout->addWidget( GroupButtons, 1, 0 );
119
120   QAD_Tools::centerWidget( this, parent );
121 }
122 /*!
123   Destructor
124 */
125 SALOMEGUI_SetupCurveDlg::~SALOMEGUI_SetupCurveDlg()
126 {
127 }
128 /*!
129   Sets line style and width
130 */
131 void SALOMEGUI_SetupCurveDlg::setLine( const int line, const int width )
132 {
133   myLineCombo->setCurrentItem( line );
134   myLineSpin->setValue( width );
135 }
136 /*!
137   Gets line style
138 */
139 int SALOMEGUI_SetupCurveDlg::getLine() const
140 {
141   return myLineCombo->currentItem();
142 }
143 /*!
144   Gets line width
145 */
146 int SALOMEGUI_SetupCurveDlg::getLineWidth() const
147 {
148   return myLineSpin->value();
149 }
150 /*!
151   Sets marker style
152 */
153 void SALOMEGUI_SetupCurveDlg::setMarker( const int marker )
154 {
155   myMarkerCombo->setCurrentItem( marker );
156 }
157 /*!
158   Gets marker style
159 */
160 int SALOMEGUI_SetupCurveDlg::getMarker() const 
161 {
162   return myMarkerCombo->currentItem();
163 }
164 /*!
165   Sets color
166 */
167 void SALOMEGUI_SetupCurveDlg::setColor( const QColor& color )
168 {
169   QPalette pal = myColorBtn->palette();
170   QColorGroup ca = pal.active();
171   ca.setColor( QColorGroup::Button, color );
172   QColorGroup ci = pal.inactive();
173   ci.setColor( QColorGroup::Button, color );
174   pal.setActive( ca );
175   pal.setInactive( ci );
176   myColorBtn->setPalette( pal );
177 }
178 /*!
179   Gets color
180 */
181 QColor SALOMEGUI_SetupCurveDlg::getColor() const 
182 {
183   return myColorBtn->palette().active().button();
184 }
185 /*!
186   <Color> button slot, invokes color selection dialog box
187 */
188 void SALOMEGUI_SetupCurveDlg::onColorChanged()
189 {
190   QColor color = QColorDialog::getColor( getColor() );
191   if ( color.isValid() ) {
192     setColor( color );
193   }
194 }
195
196
197
198
199