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