Open Inventor Release 2024.1.3
 
Loading...
Searching...
No Matches
SoQtComponent.h
1/*=======================================================================
2 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), ***
3 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. ***
4 *** ***
5 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS ***
6 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR ***
7 *** WRITTEN AUTHORIZATION OF FEI S.A.S. ***
8 *** ***
9 *** RESTRICTED RIGHTS LEGEND ***
10 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS ***
11 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN ***
12 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT ***
13 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN ***
14 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. ***
15 *** ***
16 *** COPYRIGHT (C) 1996-2024 BY FEI S.A.S, ***
17 *** BORDEAUX, FRANCE ***
18 *** ALL RIGHTS RESERVED ***
19**=======================================================================*/
20/*=======================================================================
21** Author : VSG (MMM YYYY)
22**=======================================================================*/
23
24
25#ifndef _SO_QT_COMPONENT_
26#define _SO_QT_COMPONENT_
27
28#include <Inventor/Qt/OivQtCompat.h>
29
30#include <QString>
31#include <QPointer>
32
33#include <Inventor/Qt/SoQt.h>
34#include <Inventor/Gui/SoGuiComponent.h>
35
36#include <Inventor/SbBasic.h>
37#include <Inventor/SbString.h>
38#include <Inventor/SbDict.h>
39
40#if defined(__APPLE__)
41# undef Display
42#endif
43
44class SoQtComponent;
45
47typedef void SoQtComponentCB( void* userData, SoQtComponent* comp );
48
101class SoQtComponent : public QObject
102{
103 Q_OBJECT
104
105 public:
106
110 virtual void show();
111
115 virtual void hide();
116
123
127 virtual QWidget* getWidget() const { return _baseWidget; }
128
134 SbBool isTopLevelShell() const { return m_guiComponent->isTopLevelShell(); }
135
140 QWidget* getShellWidget() const { return m_guiComponent->isTopLevelShell() ? parentWidget : NULL; }
141
145 QWidget* getParentWidget() const { return parentWidget; }
146
150 void setSize( const SbVec2s& size );
151
162 virtual SbBool setFullScreen( const SbBool enable );
163
167 SbBool isFullScreen( void ) const;
168
174 void setFullScreenEnable( const SbBool enable );
175
181
186
193 void setTitle( const char* newTitle );
194
201 void setTitle( const SbString& newTitle );
202
209 void setTitle( const QString& newTitle );
210
214 const QString getTitle() const;
215
219 void setIconTitle( const QString& newIconTitle );
220
224 const QString getIconTitle() const;
225
230 static SoQtComponent* getComponent( QWidget* widget );
231
236 SbString getWidgetName() const;
237
242 SbString getClassName() const;
243
248
249#ifdef _WIN32
254 UINT helpContextID;
255#endif
256
266 void setWindowCloseCallback( SoQtComponentCB* func, void* data = NULL )
267 { m_windowCloseFunc = func; m_windowCloseData = data; }
268
269
270 private:
271
272 virtual ~SoQtComponent();
273
274 void setFullScreenOn( SbBool enable ) { m_guiComponent->setFullScreen( enable ); };
275
276 static void finish();
277
278 SoGuiComponent* getGuiComponent() const;
279
280Q_SIGNALS:
281#ifndef HIDDEN_FROM_DOC
282 void visibilityChanged(SbBool visible);
283#endif // HIDDEN_FROM_DOC
284
285 private:
286
287 SoQtComponent( QWidget* parent = NULL,
288 const char* name = NULL,
289 SbBool buildInsideParent = TRUE,
290 SbBool sync = TRUE );
291
292 SoQtComponent( QWidget* parent,
293 const char* name,
294 SbBool buildInsideParent,
295 SbBool sync,
296 SoGuiComponent* guiComponent );
297
298 void setBaseWidget( QWidget* w );
299
300 void setClassName( const char* n ) { m_guiComponent->setClassName( n ); }
301
302 virtual void afterRealizeHook();
303
304 //First realize state
305 SbBool firstRealize;
306
307 virtual SbString getDefaultWidgetName() const;
308 virtual SbString getDefaultTitle() const;
309 virtual SbString getDefaultIconTitle() const;
310
311 //
312 // Register widget - should be called by subclasses after
313 // they have created their top most widget (which is passed here),
314 // and before they build any child widgets. Calling this method
315 // ensures that the widgets name and class will be used when
316 // calls are made to get X resource values for this widget.
317 //
318 // *** NOTE ***
319 // ALL subclasses should register their top most widget within the
320 // component, whether they retrieve resources or not, so that children
321 // widgets can get X resources properly.
322 // Unregister the widget when the widget is destroyed.
323 //
324 void registerWidget( QWidget* w );
325 void unregisterWidget( QWidget* w );
326
327#ifdef _WIN32
328 // Utility function to setup logical color palette for 8bit devices
329 static HPALETTE _setupColorPalette( HDC );
330#endif //_WIN32
331
332 virtual bool eventFilter( QObject* object,QEvent *event );
333 //
334 // This method can be used by subclasses to open a component help
335 // card. The name of the file should be supplied withought a path
336 // name. By default the file will be searched using:
337 // 1) current working directory
338 // 2) SO_HELP_DIR environment variable
339 // 3) /usr/share/help/Inventor
340 // 4) else bring a no help card found dialog
341 //
342 void openHelpCard( const char* cardName );
343
344 static void windowCloseActionCB( SoWidget widget, SoQtComponent* p, void* data );
345
346 private:
347#ifdef _WIN32
348 const char* buildHelpPath( const char* filename );
349#endif
350 void constructorCommon( QWidget* parent, const char* name, SbBool buildInsideParent, SbBool sync );
351
352 //Implementation class for SoXxComponent
353 SoGuiComponent* m_guiComponent;
354
355 SbBool createdShell; // TRUE if we created that toplevel shell
356 QWidget* parentWidget; // topLevel shell if in its own window
357 QPointer<QWidget> _baseWidget; // returned by getWidget()
358
359 SbVec2s size; // size of the '_baseWidget' and 'shell' (if toplevel)
360
361 // The widget dictionary maps widgets to SoXtComponents. It's used
362 // by getComponent(), and kept up to date by registerWidget().
363 static SbDict* widgetDictionary;
364
365 // For fullscreen mode.
366 SbBool wasTopLevel;
367
368 QWidget* m_oldParentWidget;
369 QRect m_oldGeometry;
370 int m_widgetIndex;
371
372 // Window close action data
373 SoQtComponentCB* m_windowCloseFunc;
374 void* m_windowCloseData;
375};
376
377// Inline routines
383
384inline const QString
386{
387 return QString::fromUtf16( m_guiComponent->getTitle().toUtf16() );
388}
389
390inline const QString
392{
393 return QString::fromUtf16( m_guiComponent->getIconTitle().toUtf16() );
394}
395
396inline SbString
398{
399 return m_guiComponent->getClassName();
400}
401
402inline SbString
404{
405 return m_guiComponent->getWidgetName();
406}
407
408#endif // _SO_QT_COMPONENT_
409
410
Class for smart character strings.
Definition SbString.h:202
unsigned short * toUtf16() const
Returns the string as a UTF-16 string.
2D vector class.
Definition SbVec.h:700
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> Abstract base cl...
void setTitle(const SbString &newTitle)
Sets window title.
const QString getIconTitle() const
Included for portability only.
const QString getTitle() const
Gets window title.
SbString getWidgetName() const
Returns the widget handle name.
QWidget * getShellWidget() const
Returns the topLevelShell widget handle (NULL if the topLevelShell hasn't been created by this compon...
virtual void show()
This shows the component.
SbString getClassName() const
Returns the class name.
void SoQtComponentCB(void *userData, SoQtComponent *comp)
SbVec2s getSize()
Convenience routine on the widget handle.
SbBool isTopLevelShell() const
Returns TRUE if this component is a top level shell component (has its own window).
SbBool isFullScreen(void) const
Queries if the viewer is in fullscreen mode.
SbGlContextHelper::Display getDisplay()
On UNIX, returns the X display associated with this components widget.
static SoQtComponent * getComponent(QWidget *widget)
Returns the SoQtComponent for this widget handle.
QWidget * getParentWidget() const
Returns the parent widget handle.
SbBool isFullScreenEnable(void) const
Queries if it is possible to put the viewer in fullscreen mode.
void setFullScreenEnable(const SbBool enable)
Enables/disables fullscreen mode.
void setWindowCloseCallback(SoQtComponentCB *func, void *data=NULL)
Sets which callback to call when the user closes this component (double click in the upper left corne...
void setTitle(const char *newTitle)
Sets window title.
void setSize(const SbVec2s &size)
Convenience routine on the widget handle.
void setIconTitle(const QString &newIconTitle)
Included for portability only.
SbBool isVisible()
Returns TRUE if this component is mapped onto the screen.
virtual SbBool setFullScreen(const SbBool enable)
Switches the viewer into (or out of) fullscreen mode.
virtual void hide()
This hides the component.
virtual QWidget * getWidget() const
This returns the base widget handle for this component.
void setTitle(const QString &newTitle)
Sets window title.
SbString helpFileName
Name of help file to open when the viewer Help button is pressed.
static SbGlContextHelper::Display getDisplay()
This method is included for portability only.
int SbBool
Boolean type.
Definition SbBase.h:87