1 // File: GLViewer_ToolTip.xx
2 // Created: March, 2005
4 // Copyright (C) CEA 2005
6 //#include "GLViewerAfx.h"
7 #include "GLViewer_Context.h"
8 #include "GLViewer_ToolTip.h"
9 #include "GLViewer_Viewer2d.h"
10 #include "GLViewer_ViewPort2d.h"
15 #include <qapplication.h>
18 /***************************************************************************
19 ** Class: GLViewer_ToolTip
20 ** Descr: ToolTip of GLViewer_Objects
22 ** Created: UI team, 25.03.05
23 ****************************************************************************/
25 //--------------------------------------------------------------------------
26 //Function: GLViewer_ToolTip()
27 //Description: constructor
28 //--------------------------------------------------------------------------
29 GLViewer_ObjectTip::GLViewer_ObjectTip( GLViewer_ViewPort2d* theParent )
34 mypViewPort = theParent;
36 mypLabel = new QLabel( "Test", NULL, "ObjectTipText",
37 WStyle_StaysOnTop | WStyle_Customize | WStyle_NoBorder | WStyle_Tool | WX11BypassWM );
38 mypLabel->setMargin( 1 );
39 mypLabel->setAutoMask( FALSE );
40 mypLabel->setFrameStyle( QFrame::Plain | QFrame::Box );
41 mypLabel->setLineWidth( 1 );
42 mypLabel->setAlignment( AlignAuto | AlignTop );
43 mypLabel->setIndent( 0 );
46 //mypLabel->setPalette( QToolTip::palette() );
48 mypTimer = new QTimer( this );
50 connect( mypTimer, SIGNAL( timeout() ), this, SLOT( showTip() ) );
53 //--------------------------------------------------------------------------
54 //Function: GLViewer_ToolTip()
55 //Description: destructor
56 //--------------------------------------------------------------------------
57 GLViewer_ObjectTip::~GLViewer_ObjectTip()
71 //--------------------------------------------------------------------------
72 //Function: GLViewer_ToolTip()
73 //Description: destructor
74 //--------------------------------------------------------------------------
75 bool GLViewer_ObjectTip::maybeTip( const QPoint &p )
79 GLViewer_Context* aContext = ((GLViewer_Viewer2d*)mypViewPort->getViewFrame()->getViewer())->getGLContext();
81 /*if( !aContext->currentObjectIsChanged() )
85 if( myPoint.x() == -1 && myPoint.y() == -1 || aContext->currentObjectIsChanged())
89 else/if( abs(myPoint.y() - p.y()) < 16 )
98 GLViewer_Object* anObj = aContext->getCurrentObject();
101 setText( anObj->getName() );
108 //GLViewer_Rect* aRect = anObj->getRect();
109 //QRect aWinRect = mypViewPort->GLV2win( *aRect );
110 tip( QRect( p.x(), p.y(), 1, 1 ), anObj->getName() );
111 //QFontMetrics aFM( font() );
112 //showTip( aWinRect, anObj->getName(), QRect( 0, 0, aFM.width( anObj->getName() + " " ), aFM.height()*1.5 ) );
113 //tip( aWinRect, anObj->getName(), aWinRect( aFM.width( anObj->getName() + " " ), aFM.height()*1.5 ) );
118 //tip( QRect( 0, 0, mypViewPort->getGLWidget()->width(),mypViewPort->getGLWidget()->height() ) , "test Tool tip" );
122 bool GLViewer_ObjectTip::eventFilter( QObject* theObj, QEvent* e )
127 /*case QEvent::MouseButtonPress:
128 case QEvent::MouseButtonRelease:
129 case QEvent::MouseButtonDblClick:
130 case QEvent::KeyPress:
131 case QEvent::KeyRelease:
132 // input - turn off tool tip mode
135 case QEvent::MouseMove:
138 /*if( mypTimer->isActive() )
143 QWidget* aWidget = (QWidget*) theObj;
144 if( aWidget == mypViewPort->getGLWidget() )
147 QMouseEvent* m = (QMouseEvent *)e;
149 // mypPoint = new QPoint();
151 myPoint.setX( m->x() );
152 myPoint.setY( m->y() );
160 void GLViewer_ObjectTip::hideTipAndSleep()
175 void GLViewer_ObjectTip::showTip()
177 if( maybeTip( myPoint ) )
180 mypLabel->setText( myText );
181 mypLabel->adjustSize( );
183 QPoint pos = mypViewPort->getGLWidget()->mapToGlobal( myPoint );
187 QCursor* aCursor = QApplication::overrideCursor();
190 const QBitmap* aBitmap = aCursor->bitmap();
192 cur_height = aBitmap->height();
194 mypLabel->setGeometry( pos.x(), pos.y() + cur_height, mypLabel->width(), mypLabel->height() );
195 mypLabel->setPalette( QToolTip::palette() );
202 void GLViewer_ObjectTip::wakeup( int theTime )
204 if( mypTimer->isActive() )
206 mypTimer->start( theTime );