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>
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
36 Plot2d_SetupCurveDlg::Plot2d_SetupCurveDlg( QWidget* parent )
37 : QDialog( parent, "Plot2d_SetupCurveDlg", true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
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 );
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 );
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
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
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
86 QLabel* aColorLab = new QLabel( tr( "CURVE_COLOR_LAB" ), TopGroup );
87 myColorBtn = new QToolButton( TopGroup );
88 myColorBtn->setMinimumSize(25, 25);
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 );
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 );
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 );
112 GroupButtonsLayout->addWidget( myOkBtn );
113 GroupButtonsLayout->addStretch();
114 GroupButtonsLayout->addWidget( myCancelBtn );
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 ) );
121 topLayout->addWidget( TopGroup, 0, 0 );
122 topLayout->addWidget( GroupButtons, 1, 0 );
124 SUIT_Tools::centerWidget( this, parent );
129 Plot2d_SetupCurveDlg::~Plot2d_SetupCurveDlg()
133 Sets line style and width
135 void Plot2d_SetupCurveDlg::setLine( const int line, const int width )
137 myLineCombo->setCurrentItem( line );
138 myLineSpin->setValue( width );
143 int Plot2d_SetupCurveDlg::getLine() const
145 return myLineCombo->currentItem();
150 int Plot2d_SetupCurveDlg::getLineWidth() const
152 return myLineSpin->value();
157 void Plot2d_SetupCurveDlg::setMarker( const int marker )
159 myMarkerCombo->setCurrentItem( marker );
164 int Plot2d_SetupCurveDlg::getMarker() const
166 return myMarkerCombo->currentItem();
171 void Plot2d_SetupCurveDlg::setColor( const QColor& color )
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 );
179 pal.setInactive( ci );
180 myColorBtn->setPalette( pal );
185 QColor Plot2d_SetupCurveDlg::getColor() const
187 return myColorBtn->palette().active().button();
190 <Color> button slot, invokes color selection dialog box
192 void Plot2d_SetupCurveDlg::onColorChanged()
194 QColor color = QColorDialog::getColor( getColor() );
195 if ( color.isValid() ) {