1 // SALOME SALOMEGUI : implementation of desktop and GUI kernel
3 // Copyright (C) 2003 CEA/DEN, EDF R&D
7 // File : SALOMEGUI_SetupCurveDlg.cxx
8 // Author : Vadim SANDLER
13 #include "SALOMEGUI_SetupCurveDlg.h"
14 #include "QAD_Tools.h"
17 #include <qpushbutton.h>
18 #include <qcombobox.h>
20 #include <qtoolbutton.h>
21 #include <qgroupbox.h>
22 #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 SALOMEGUI_SetupCurveDlg::SALOMEGUI_SetupCurveDlg( QWidget* parent )
34 : QDialog( parent, "SALOMEGUI_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 );
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 );
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 );
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 );
108 GroupButtonsLayout->addWidget( myOkBtn );
109 GroupButtonsLayout->addStretch();
110 GroupButtonsLayout->addWidget( myCancelBtn );
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 ) );
117 topLayout->addWidget( TopGroup, 0, 0 );
118 topLayout->addWidget( GroupButtons, 1, 0 );
120 QAD_Tools::centerWidget( this, parent );
125 SALOMEGUI_SetupCurveDlg::~SALOMEGUI_SetupCurveDlg()
129 Sets line style and width
131 void SALOMEGUI_SetupCurveDlg::setLine( const int line, const int width )
133 myLineCombo->setCurrentItem( line );
134 myLineSpin->setValue( width );
139 int SALOMEGUI_SetupCurveDlg::getLine() const
141 return myLineCombo->currentItem();
146 int SALOMEGUI_SetupCurveDlg::getLineWidth() const
148 return myLineSpin->value();
153 void SALOMEGUI_SetupCurveDlg::setMarker( const int marker )
155 myMarkerCombo->setCurrentItem( marker );
160 int SALOMEGUI_SetupCurveDlg::getMarker() const
162 return myMarkerCombo->currentItem();
167 void SALOMEGUI_SetupCurveDlg::setColor( const QColor& color )
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 );
175 pal.setInactive( ci );
176 myColorBtn->setPalette( pal );
181 QColor SALOMEGUI_SetupCurveDlg::getColor() const
183 return myColorBtn->palette().active().button();
186 <Color> button slot, invokes color selection dialog box
188 void SALOMEGUI_SetupCurveDlg::onColorChanged()
190 QColor color = QColorDialog::getColor( getColor() );
191 if ( color.isValid() ) {