]> SALOME platform Git repositories - modules/hydro.git/blob - src/HYDROCurveCreator/CurveCreator_NewSectionDlg.cxx
Salome HOME
It removes unnecessary margin.
[modules/hydro.git] / src / HYDROCurveCreator / CurveCreator_NewSectionDlg.cxx
1 // Copyright (C) 2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "CurveCreator_NewSectionDlg.h"
21 //#include "CurveCreator_Curve.hxx"
22
23 #include <SUIT_Session.h>
24 #include <SUIT_ResourceMgr.h>
25
26 #include <QGridLayout>
27 #include <QLabel>
28 #include <QLineEdit>
29 #include <QComboBox>
30 #include <QCheckBox>
31 #include <QDialogButtonBox>
32 #include <QPushButton>
33
34 CurveCreator_NewSectionDlg::CurveCreator_NewSectionDlg( QWidget *parent, bool enableClosed ) :
35   QWidget(parent), myIsEnableClosed( enableClosed )
36 {
37   QFrame* aFrame = new QFrame( this );
38   QVBoxLayout* aLayout = new QVBoxLayout( aFrame );
39   aLayout->setMargin( 0 );
40
41   QFrame* aCoordFrame = new QFrame( aFrame );
42   QGridLayout* aCoordLayout = new QGridLayout( aCoordFrame );
43
44   QLabel* aLbl = new QLabel(tr("NAME"), this);
45   myName = new QLineEdit(this);
46   aCoordLayout->addWidget(aLbl, 0, 0);
47   aCoordLayout->addWidget(myName, 0 , 1);
48
49   aLbl = new QLabel(tr("LINE_TYPE"));
50   myLineType = new QComboBox(this);
51
52   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
53   QPixmap aPolylinePixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_POLYLINE")));
54   QPixmap aSplinePixmap(aResMgr->loadPixmap("GEOM", tr("ICON_CC_SPLINE")));
55
56 //  QPixmap aPolylinePixmap = QPixmap(tr(":images/ICON_POLYLINE"));
57 //  QPixmap aSplinePixmap = QPixmap(tr(":images/ICON_SPLINE"));
58   myLineType->addItem(aPolylinePixmap, tr("POLYLINE_TYPE"));
59   myLineType->addItem(aSplinePixmap, tr("SPLINE_TYPE"));
60   myLineType->setCurrentIndex(0);
61   aCoordLayout->addWidget(aLbl, 1, 0);
62   aCoordLayout->addWidget(myLineType, 1 , 1);
63
64   aLbl = new QLabel(tr("LINE_CLOSED"));
65   myIsClosed = new QCheckBox(this);
66   aCoordLayout->addWidget(aLbl, 2, 0);
67   aCoordLayout->addWidget(myIsClosed, 2, 1);
68   if ( !myIsEnableClosed ) {
69     aLbl->hide();
70     myIsClosed->hide();
71   }
72
73   myBtnFrame = new QFrame( aFrame );
74   QHBoxLayout* aBtnsLayout = new QHBoxLayout( myBtnFrame );
75
76   myAddBtn = new QPushButton( tr( "ADD_BTN" ), myBtnFrame );
77   myCancelBtn = new QPushButton( tr( "CANCEL" ), myBtnFrame );
78
79   connect( myAddBtn,  SIGNAL( clicked() ), this, SIGNAL( addSection() ) );
80   connect( myCancelBtn, SIGNAL( clicked() ), this, SIGNAL( cancelSection() ) );
81
82   aBtnsLayout->addWidget( myAddBtn );
83   aBtnsLayout->addStretch( 1 );
84   aBtnsLayout->addWidget( myCancelBtn );
85
86   aLayout->addWidget( aCoordFrame, 0 );
87   aLayout->addWidget( myBtnFrame, 1 );
88 }
89
90 void CurveCreator_NewSectionDlg::setSectionParameters( const QString& theName, bool isClosed, CurveCreator::SectionType theType )
91 {
92   myName->setText(theName);
93   myIsClosed->setChecked(isClosed);
94   if( theType == CurveCreator::Polyline )
95     myLineType->setCurrentIndex(0);
96   else
97     myLineType->setCurrentIndex(1);
98 }
99
100 void CurveCreator_NewSectionDlg::clear()
101 {
102   myName->setText("");
103   myIsClosed->setChecked(true);
104   myLineType->setCurrentIndex(0);
105 }
106
107 void CurveCreator_NewSectionDlg::setEditMode( bool isEdit )
108 {
109   myIsEdit = isEdit;
110   if( myIsEdit ){
111     myAddBtn->setText(tr("OK"));
112     myAddBtn->disconnect( SIGNAL( clicked() ) );
113     connect( myAddBtn, SIGNAL( clicked() ), this, SIGNAL( modifySection() ) );
114   }
115   else{
116     myAddBtn->setText(tr("ADD_BTN"));
117     myAddBtn->disconnect( SIGNAL( clicked() ) );
118     connect( myAddBtn, SIGNAL( clicked() ), this, SIGNAL( addSection() ) );
119   }
120   updateTitle();
121 }
122
123 QString CurveCreator_NewSectionDlg::getName() const
124 {
125   return myName->text();
126 }
127
128 bool CurveCreator_NewSectionDlg::isClosed() const
129 {
130   return myIsClosed->isChecked();
131 }
132
133 CurveCreator::SectionType CurveCreator_NewSectionDlg::getSectionType() const
134 {
135   if( myLineType->currentIndex() == 0 )
136     return CurveCreator::Polyline;
137   else
138     return CurveCreator::Spline;
139 }
140
141 void CurveCreator_NewSectionDlg::updateTitle()
142 {
143   QString aTitle;
144   if( !myIsEdit )
145     aTitle = tr("ADD_NEW_SECTION");
146   else
147     aTitle = QString(tr("SET_SECTION_PARAMETERS"));
148   setWindowTitle(aTitle);
149 }
150
151 void CurveCreator_NewSectionDlg::setSectionName( const QString& theName )
152 {
153   myName->setText(theName);
154 }