1 // Copyright (C) 2005 OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
19 // Author : OPEN CASCADE
22 // File: GLViewer_ToolTip.xx
23 // Created: March, 2005
25 //#include "GLViewerAfx.h"
26 #include "GLViewer_Context.h"
27 #include "GLViewer_ToolTip.h"
28 #include "GLViewer_Viewer2d.h"
29 #include "GLViewer_ViewPort2d.h"
34 #include <qapplication.h>
37 /***************************************************************************
38 ** Class: GLViewer_ToolTip
39 ** Descr: ToolTip of GLViewer_Objects
41 ** Created: UI team, 25.03.05
42 ****************************************************************************/
44 //--------------------------------------------------------------------------
45 //Function: GLViewer_ToolTip()
46 //Description: constructor
47 //--------------------------------------------------------------------------
48 GLViewer_ObjectTip::GLViewer_ObjectTip( GLViewer_ViewPort2d* theParent )
53 mypViewPort = theParent;
55 mypLabel = new QLabel( "Test", NULL, "ObjectTipText",
56 WStyle_StaysOnTop | WStyle_Customize | WStyle_NoBorder | WStyle_Tool | WX11BypassWM );
57 mypLabel->setMargin( 1 );
58 mypLabel->setAutoMask( FALSE );
59 mypLabel->setFrameStyle( QFrame::Plain | QFrame::Box );
60 mypLabel->setLineWidth( 1 );
61 mypLabel->setAlignment( AlignAuto | AlignTop );
62 mypLabel->setIndent( 0 );
65 //mypLabel->setPalette( QToolTip::palette() );
67 mypTimer = new QTimer( this );
69 connect( mypTimer, SIGNAL( timeout() ), this, SLOT( showTip() ) );
72 //--------------------------------------------------------------------------
73 //Function: GLViewer_ToolTip()
74 //Description: destructor
75 //--------------------------------------------------------------------------
76 GLViewer_ObjectTip::~GLViewer_ObjectTip()
90 //--------------------------------------------------------------------------
91 //Function: GLViewer_ToolTip()
92 //Description: destructor
93 //--------------------------------------------------------------------------
94 bool GLViewer_ObjectTip::maybeTip( const QPoint &p )
98 GLViewer_Context* aContext = ((GLViewer_Viewer2d*)mypViewPort->getViewFrame()->getViewer())->getGLContext();
100 /*if( !aContext->currentObjectIsChanged() )
104 if( myPoint.x() == -1 && myPoint.y() == -1 || aContext->currentObjectIsChanged())
108 else/if( abs(myPoint.y() - p.y()) < 16 )
117 GLViewer_Object* anObj = aContext->getCurrentObject();
120 setText( anObj->getName() );
127 //GLViewer_Rect* aRect = anObj->getRect();
128 //QRect aWinRect = mypViewPort->GLV2win( *aRect );
129 tip( QRect( p.x(), p.y(), 1, 1 ), anObj->getName() );
130 //QFontMetrics aFM( font() );
131 //showTip( aWinRect, anObj->getName(), QRect( 0, 0, aFM.width( anObj->getName() + " " ), aFM.height()*1.5 ) );
132 //tip( aWinRect, anObj->getName(), aWinRect( aFM.width( anObj->getName() + " " ), aFM.height()*1.5 ) );
137 //tip( QRect( 0, 0, mypViewPort->getGLWidget()->width(),mypViewPort->getGLWidget()->height() ) , "test Tool tip" );
141 bool GLViewer_ObjectTip::eventFilter( QObject* theObj, QEvent* e )
146 /*case QEvent::MouseButtonPress:
147 case QEvent::MouseButtonRelease:
148 case QEvent::MouseButtonDblClick:
149 case QEvent::KeyPress:
150 case QEvent::KeyRelease:
151 // input - turn off tool tip mode
154 case QEvent::MouseMove:
157 /*if( mypTimer->isActive() )
162 QWidget* aWidget = (QWidget*) theObj;
163 if( aWidget == mypViewPort->getGLWidget() )
166 QMouseEvent* m = (QMouseEvent *)e;
168 // mypPoint = new QPoint();
170 myPoint.setX( m->x() );
171 myPoint.setY( m->y() );
179 void GLViewer_ObjectTip::hideTipAndSleep()
194 void GLViewer_ObjectTip::showTip()
196 if( maybeTip( myPoint ) )
199 mypLabel->setText( myText );
200 mypLabel->adjustSize( );
202 QPoint pos = mypViewPort->getGLWidget()->mapToGlobal( myPoint );
206 QCursor* aCursor = QApplication::overrideCursor();
209 const QBitmap* aBitmap = aCursor->bitmap();
211 cur_height = aBitmap->height();
213 mypLabel->setGeometry( pos.x(), pos.y() + cur_height, mypLabel->width(), mypLabel->height() );
214 mypLabel->setPalette( QToolTip::palette() );
221 void GLViewer_ObjectTip::wakeup( int theTime )
223 if( mypTimer->isActive() )
225 mypTimer->start( theTime );