1 // SALOME Plot2d : implementation of desktop and GUI kernel
3 // Copyright (C) 2003 CEA/DEN, EDF R&D
7 // File : Plot2d_SetupCurveDlg.cxx
8 // Author : Vadim SANDLER
12 #include "Plot2d_SetupCurveDlg.h"
13 #include "SUIT_Tools.h"
16 #include <qpushbutton.h>
17 #include <qcombobox.h>
19 #include <qtoolbutton.h>
20 #include <qgroupbox.h>
21 #include <qcolordialog.h>
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
33 Plot2d_SetupCurveDlg::Plot2d_SetupCurveDlg( QWidget* parent )
34 : QDialog( parent, "Plot2d_SetupCurveDlg", true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
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 );
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 );
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
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
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
83 QLabel* aColorLab = new QLabel( tr( "CURVE_COLOR_LAB" ), TopGroup );
84 myColorBtn = new QToolButton( TopGroup );
85 myColorBtn->setMinimumWidth(25);
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 );
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 );
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 );
109 GroupButtonsLayout->addWidget( myOkBtn );
110 GroupButtonsLayout->addStretch();
111 GroupButtonsLayout->addWidget( myCancelBtn );
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 ) );
118 topLayout->addWidget( TopGroup, 0, 0 );
119 topLayout->addWidget( GroupButtons, 1, 0 );
121 SUIT_Tools::centerWidget( this, parent );
126 Plot2d_SetupCurveDlg::~Plot2d_SetupCurveDlg()
130 Sets line style and width
132 void Plot2d_SetupCurveDlg::setLine( const int line, const int width )
134 myLineCombo->setCurrentItem( line );
135 myLineSpin->setValue( width );
140 int Plot2d_SetupCurveDlg::getLine() const
142 return myLineCombo->currentItem();
147 int Plot2d_SetupCurveDlg::getLineWidth() const
149 return myLineSpin->value();
154 void Plot2d_SetupCurveDlg::setMarker( const int marker )
156 myMarkerCombo->setCurrentItem( marker );
161 int Plot2d_SetupCurveDlg::getMarker() const
163 return myMarkerCombo->currentItem();
168 void Plot2d_SetupCurveDlg::setColor( const QColor& color )
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 );
176 pal.setInactive( ci );
177 myColorBtn->setPalette( pal );
182 QColor Plot2d_SetupCurveDlg::getColor() const
184 return myColorBtn->palette().active().button();
187 <Color> button slot, invokes color selection dialog box
189 void Plot2d_SetupCurveDlg::onColorChanged()
191 QColor color = QColorDialog::getColor( getColor() );
192 if ( color.isValid() ) {