Salome HOME
Merge from BR_Dev_For_4_0 branch (from tag mergeto_BR_QT4_Dev_17Jan08)
[modules/geom.git] / src / MeasureGUI / MeasureGUI_WhatisDlg.cxx
1 // GEOM GEOMGUI : GUI for Geometry component
2 //
3 // Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
6 // This library is free software; you can redistribute it and/or 
7 // modify it under the terms of the GNU Lesser General Public 
8 // License as published by the Free Software Foundation; either 
9 // version 2.1 of the License. 
10 // 
11 // This library is distributed in the hope that it will be useful, 
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 // Lesser General Public License for more details. 
15 // 
16 // You should have received a copy of the GNU Lesser General Public 
17 // License along with this library; if not, write to the Free Software 
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19 // 
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 // File   : MeasureGUI_WhatisDlg.cxx
23 // Author : Nicolas REJNERI, Open CASCADE S.A.S.
24 //
25
26 #include "MeasureGUI_WhatisDlg.h"
27 #include "MeasureGUI_Widgets.h"
28
29 #include <GEOMBase.h>
30
31 #include <SUIT_Session.h>
32 #include <SUIT_ResourceMgr.h>
33 #include <SalomeApp_Tools.h>
34
35 #include <QScrollBar>
36
37 //=================================================================================
38 // class    : MeasureGUI_WhatisDlg( )
39 // purpose  : Constructs a MeasureGUI_WhatisDlg which is a child of 'parent', with the
40 //            name 'name' and widget flags set to 'f'.
41 //            The dialog will by default be modeless, unless you set 'modal' to
42 //            true to construct a modal dialog.
43 //=================================================================================
44 MeasureGUI_WhatisDlg::MeasureGUI_WhatisDlg( GeometryGUI* GUI, QWidget* parent )
45   : MeasureGUI_Skeleton( GUI, parent )
46 {
47   QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap(
48     "GEOM", tr( "ICON_DLG_WHATIS" ) ) );
49   QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap(
50     "GEOM", tr( "ICON_SELECT" ) ) );
51
52   setWindowTitle( tr( "GEOM_WHATIS_TITLE" ) );
53
54   /***************************************************************/
55   
56   mainFrame()->GroupConstructors->setTitle( tr( "GEOM_WHATIS" ) );
57   mainFrame()->RadioButton1->setIcon( image0 );
58
59   myGrp = new MeasureGUI_1Sel1TextView( centralWidget() );
60   myGrp->GroupBox1->setTitle( tr( "GEOM_WHATIS_OBJECT" ) );
61   myGrp->TextLabel1->setText( tr( "GEOM_OBJECT" ) );
62   myGrp->TextView1->setReadOnly( true );
63
64   // fix height to fit all text
65   myGrp->TextView1->setLineWrapMode( QTextEdit::NoWrap );
66   // myGrp->TextView1->setTextFormat( Qt::PlainText ); // VSR : TODO
67   QString allLines ("\n\n\n\n\n\n\n\n\n"); // 10 lines
68   myGrp->TextView1->setText( allLines );
69   int sbHeight = myGrp->TextView1->horizontalScrollBar()->height();
70   myGrp->TextView1->setFixedHeight( myGrp->TextView1->document()->size().height() + sbHeight );
71
72   myGrp->PushButton1->setIcon( image1 );
73   myGrp->LineEdit1->setReadOnly( true );
74
75   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
76   layout->setMargin( 0 ); layout->setSpacing( 6 );
77   layout->addWidget( myGrp );
78
79   /***************************************************************/
80
81   myHelpFileName = "using_measurement_tools_page.html#whatis_anchor";
82
83   /* Initialisation */
84   Init();
85 }
86
87
88 //=================================================================================
89 // function : ~MeasureGUI_WhatisDlg()
90 // purpose  : Destroys the object and frees any allocated resources
91 //=================================================================================
92 MeasureGUI_WhatisDlg::~MeasureGUI_WhatisDlg()
93 {
94 }
95
96
97 //=================================================================================
98 // function : Init()
99 // purpose  :
100 //=================================================================================
101 void MeasureGUI_WhatisDlg::Init()
102 {
103   mySelBtn = myGrp->PushButton1;
104   mySelEdit = myGrp->LineEdit1;
105   MeasureGUI_Skeleton::Init();
106 }
107
108 //=================================================================================
109 // function : processObject
110 // purpose  :
111 //=================================================================================
112 void MeasureGUI_WhatisDlg::processObject()
113 {
114   QString aText;
115   myGrp->TextView1->setText( getParameters( aText ) ? aText : QString( "" ) );
116 }
117
118
119 //=================================================================================
120 // function : getParameters
121 // purpose  :
122 //=================================================================================
123 bool MeasureGUI_WhatisDlg::getParameters( QString& theText )
124 {
125   if ( myObj->_is_nil() )
126     return false;
127   else {
128     try {
129       theText = GEOM::GEOM_IMeasureOperations::_narrow( getOperation() )->WhatIs( myObj );
130     }
131     catch( const SALOME::SALOME_Exception& e ) {
132       SalomeApp_Tools::QtCatchCorbaException( e );
133       return false;
134     }
135
136     return getOperation()->IsDone();
137   }
138 }