Salome HOME
Patch for RH&Debian
[samples/light.git] / src / LIGHTGUI / LIGHTGUI_DataObject.cxx
1 //  LIGHT : sample (no-corba-engine) SALOME module
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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
21 //
22 //  Author : Julia DOROVSKIKH
23 //  Date   : 01/01/2005
24 //  $Header$
25
26 #include "LIGHTGUI_DataObject.h"
27 #include <SUIT_Session.h>
28 #include <SUIT_ResourceMgr.h>
29
30 /*!
31  *  Class:       LIGHTGUI_DataObject
32  *  Description: LIGHT module's data object
33  */
34
35 //=================================================================================
36 // function : LIGHTGUI_DataObject()
37 // purpose  : default constructor
38 //=================================================================================
39 LIGHTGUI_DataObject::LIGHTGUI_DataObject ( SUIT_DataObject* parent )
40      : CAM_DataObject( parent )
41 {
42 }
43
44 //=================================================================================
45 // function : LIGHTGUI_DataObject()
46 // purpose  : constructor
47 //=================================================================================
48 LIGHTGUI_DataObject::LIGHTGUI_DataObject ( const QString& line_text, SUIT_DataObject* parent )
49      : CAM_DataObject( parent ),
50        myLineTxt( line_text )
51 {
52 }
53
54 //=================================================================================
55 // function : ~LIGHTGUI_DataObject()
56 // purpose  : destructor
57 //=================================================================================
58 LIGHTGUI_DataObject::~LIGHTGUI_DataObject()
59 {
60 }
61
62 //=================================================================================
63 // function : name()
64 // purpose  : gets an name of the object
65 //=================================================================================
66 QString LIGHTGUI_DataObject::name() const
67 {
68   return myLineTxt.stripWhiteSpace().isEmpty() ? QObject::tr( "LIGHT_PARAGRAPH" ) : myLineTxt ;
69 }
70
71 //=================================================================================
72 // function : icon()
73 // purpose  : gets an icon for the data object
74 //=================================================================================
75 QPixmap LIGHTGUI_DataObject::icon() const
76 {
77   static QPixmap pxp = SUIT_Session::session()->resourceMgr()->loadPixmap( "LIGHT", QObject::tr( "ICON_PARAGRAPH" ), false );
78   static QPixmap pxl = SUIT_Session::session()->resourceMgr()->loadPixmap( "LIGHT", QObject::tr( "ICON_LINE" ), false );
79   return myLineTxt.stripWhiteSpace().isEmpty() ? pxp : pxl;
80 }
81
82 //=================================================================================
83 // function : toolTip()
84 // purpose  : gets a tooltip for the object (to be displayed in the Object Browser)
85 //=================================================================================
86 QString LIGHTGUI_DataObject::toolTip() const
87 {
88   return lineText().stripWhiteSpace().isEmpty() ?
89     QString( QObject::tr( "LIGHT_PARAGRAPH") + " %1" ).arg( parent()->childPos( this ) + 1 ) :
90     QString( QObject::tr( "LIGHT_LINE" ) + " %1: %2" ).arg( lineNb() ).arg( lineText() );
91 }
92
93 //=================================================================================
94 // function : lineText()
95 // purpose  : gets line text
96 //=================================================================================
97 QString LIGHTGUI_DataObject::lineText() const
98 {
99   return myLineTxt;
100 }
101
102 //=================================================================================
103 // function : setLineText()
104 // purpose  : sets line text
105 //=================================================================================
106 void LIGHTGUI_DataObject::setLineText( const QString& text )
107 {
108   myLineTxt = text;
109 }
110
111 //=================================================================================
112 // function : lineNb()
113 // purpose  : gets the line number
114 //=================================================================================
115 int LIGHTGUI_DataObject::lineNb() const
116 {
117   if ( level() == 1 ) // root object
118     return -1;
119   int pos = 0;
120   if ( parent() ) {
121     SUIT_DataObject* o = (SUIT_DataObject*)this;
122     if ( level() == 3 ) {
123       pos += parent()->childPos( this ) + 1;
124       o = parent();
125     }
126     o = o->prevBrother();
127     while ( o ) {
128       pos += o->childCount() + 1;
129       o = o->prevBrother();
130     }
131   }
132   return pos;
133 }
134
135 /*!
136  *  Class:       LIGHTGUI_ModuleObject
137  *  Description: LIGHT module's root data object
138  */
139
140 //=================================================================================
141 // function : LIGHTGUI_ModuleObject()
142 // purpose  : one more constructor
143 //=================================================================================
144 LIGHTGUI_ModuleObject::LIGHTGUI_ModuleObject ( CAM_DataModel* dm, SUIT_DataObject* parent )
145      : LIGHTGUI_DataObject( parent ),
146        CAM_RootObject( dm, parent ),
147        CAM_DataObject( parent )
148 {
149 }
150
151 //=================================================================================
152 // function : name()
153 // purpose  : gets an name of the root object
154 //=================================================================================
155 QString LIGHTGUI_ModuleObject::name() const
156 {
157   return QObject::tr( "LIGHT_LIGHT" );
158 }
159
160 //=================================================================================
161 // function : icon()
162 // purpose  : gets an icon for the root object
163 //=================================================================================
164 QPixmap LIGHTGUI_ModuleObject::icon() const
165 {
166   static QPixmap px = SUIT_Session::session()->resourceMgr()->loadPixmap( "LIGHT", QObject::tr( "ICON_LIGHT" ), false );
167   return px;
168 }
169
170 //=================================================================================
171 // function : toolTip()
172 // purpose  : gets a tootip for the root object
173 //=================================================================================
174 QString LIGHTGUI_ModuleObject::toolTip() const
175 {
176   return QObject::tr( "LIGHT_ROOT_TOOLTIP" );
177 }