Open Inventor Release 2023.2.3
 
Loading...
Searching...
No Matches
SoQtComponent.h
Go to the documentation of this file.
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-2018 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
29
30#include <QString>
31#include <QPointer>
32
33#include <Inventor/Qt/SoQt.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
46typedef void SoQtComponentCB( void* userData, SoQtComponent* comp );
47
100class SoQtComponent : public QObject
101{
102 Q_OBJECT
103
104 public:
105
109 virtual void show();
110
114 virtual void hide();
115
122
126 virtual QWidget* getWidget() const { return _baseWidget; }
127
133 SbBool isTopLevelShell() const { return m_guiComponent->isTopLevelShell(); }
134
139 QWidget* getShellWidget() const { return m_guiComponent->isTopLevelShell() ? parentWidget : NULL; }
140
144 QWidget* getParentWidget() const { return parentWidget; }
145
149 void setSize( const SbVec2s& size );
150
162
166 SbBool isFullScreen( void ) const;
167
174
180
185
192 void setTitle( const char* newTitle );
193
200 void setTitle( const SbString& newTitle );
201
208 void setTitle( const QString& newTitle );
209
213 const QString getTitle() const;
214
218 void setIconTitle( const QString& newIconTitle );
219
223 const QString getIconTitle() const;
224
229 static SoQtComponent* getComponent( QWidget* widget );
230
235 SbString getWidgetName() const;
236
241 SbString getClassName() const;
242
247
248#ifdef _WIN32
253 UINT helpContextID;
254#endif
255
265 void setWindowCloseCallback( SoQtComponentCB* func, void* data = NULL )
266 { m_windowCloseFunc = func; m_windowCloseData = data; }
267
268
269 private:
270
271 virtual ~SoQtComponent();
272
273 void setFullScreenOn( SbBool enable ) { m_guiComponent->setFullScreen( enable ); };
274
275 static void finish();
276
277 SoGuiComponent* getGuiComponent() const;
278
279Q_SIGNALS:
280#ifndef HIDDEN_FROM_DOC
281 void visibilityChanged(SbBool visible);
282#endif // HIDDEN_FROM_DOC
283
284 private:
285
286 SoQtComponent( QWidget* parent = NULL,
287 const char* name = NULL,
288 SbBool buildInsideParent = TRUE,
289 SbBool sync = TRUE );
290
291 SoQtComponent( QWidget* parent,
292 const char* name,
293 SbBool buildInsideParent,
294 SbBool sync,
295 SoGuiComponent* guiComponent );
296
297 void setBaseWidget( QWidget* w );
298
299 void setClassName( const char* n ) { m_guiComponent->setClassName( n ); }
300
301 virtual void afterRealizeHook();
302
303 //First realize state
304 SbBool firstRealize;
305
306 virtual SbString getDefaultWidgetName() const;
307 virtual SbString getDefaultTitle() const;
308 virtual SbString getDefaultIconTitle() const;
309
310 //
311 // Register widget - should be called by subclasses after
312 // they have created their top most widget (which is passed here),
313 // and before they build any child widgets. Calling this method
314 // ensures that the widgets name and class will be used when
315 // calls are made to get X resource values for this widget.
316 //
317 // *** NOTE ***
318 // ALL subclasses should register their top most widget within the
319 // component, whether they retrieve resources or not, so that children
320 // widgets can get X resources properly.
321 // Unregister the widget when the widget is destroyed.
322 //
323 void registerWidget( QWidget* w );
324 void unregisterWidget( QWidget* w );
325
326#ifdef _WIN32
327 // Utility function to setup logical color palette for 8bit devices
328 static HPALETTE _setupColorPalette( HDC );
329#endif //_WIN32
330
331 virtual bool eventFilter( QObject* object,QEvent *event );
332 //
333 // This method can be used by subclasses to open a component help
334 // card. The name of the file should be supplied withought a path
335 // name. By default the file will be searched using:
336 // 1) current working directory
337 // 2) SO_HELP_DIR environment variable
338 // 3) /usr/share/help/Inventor
339 // 4) else bring a no help card found dialog
340 //
341 void openHelpCard( const char* cardName );
342
343 static void windowCloseActionCB( SoWidget widget, SoQtComponent* p, void* data );
344
345 private:
346#ifdef _WIN32
347 const char* buildHelpPath( const char* filename );
348#endif
349 void constructorCommon( QWidget* parent, const char* name, SbBool buildInsideParent, SbBool sync );
350
351 //Implementation class for SoXxComponent
352 SoGuiComponent* m_guiComponent;
353
354 SbBool createdShell; // TRUE if we created that toplevel shell
355 QWidget* parentWidget; // topLevel shell if in its own window
356 QPointer<QWidget> _baseWidget; // returned by getWidget()
357
358 SbVec2s size; // size of the '_baseWidget' and 'shell' (if toplevel)
359
360 // The widget dictionary maps widgets to SoXtComponents. It's used
361 // by getComponent(), and kept up to date by registerWidget().
362 static SbDict* widgetDictionary;
363
364 // For fullscreen mode.
365 SbBool wasTopLevel;
366
367 QWidget* m_oldParentWidget;
368 QRect m_oldGeometry;
369 int m_widgetIndex;
370
371 // Window close action data
372 SoQtComponentCB* m_windowCloseFunc;
373 void* m_windowCloseData;
374};
375
376// Inline routines
382
383inline const QString
385{
386 return QString::fromUtf16( m_guiComponent->getTitle().toUtf16() );
387}
388
389inline const QString
391{
392 return QString::fromUtf16( m_guiComponent->getIconTitle().toUtf16() );
393}
394
395inline SbString
397{
398 return m_guiComponent->getClassName();
399}
400
401inline SbString
403{
404 return m_guiComponent->getWidgetName();
405}
406
407#endif // _SO_QT_COMPONENT_
408
409
#define TRUE
Possible value of SbBool.
Definition SbBase.h:77
void SoQtComponentCB(void *userData, SoQtComponent *comp)
#define SoWidget
Definition SoQtDef.h:40
virtual void enable(QWidget *w, XtEventHandler f, XtPointer data, void *unused=NULL)
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.
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
unsigned int UINT
Definition port.h:357
#define HDC
Definition port.h:351