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>
40 GLViewer_ObjectTip::GLViewer_ObjectTip( GLViewer_ViewPort2d* theParent )
45 mypViewPort = theParent;
47 mypLabel = new QLabel( "Test", NULL, "ObjectTipText",
48 WStyle_StaysOnTop | WStyle_Customize | WStyle_NoBorder | WStyle_Tool | WX11BypassWM );
49 mypLabel->setMargin( 1 );
50 mypLabel->setAutoMask( FALSE );
51 mypLabel->setFrameStyle( QFrame::Plain | QFrame::Box );
52 mypLabel->setLineWidth( 1 );
53 mypLabel->setAlignment( AlignAuto | AlignTop );
54 mypLabel->setIndent( 0 );
57 //mypLabel->setPalette( QToolTip::palette() );
59 mypTimer = new QTimer( this );
61 connect( mypTimer, SIGNAL( timeout() ), this, SLOT( showTip() ) );
67 GLViewer_ObjectTip::~GLViewer_ObjectTip()
82 It is called when there is a possibility that a tool tip should be shown
83 \param p - position of tooltip
85 bool GLViewer_ObjectTip::maybeTip( const QPoint &p )
89 GLViewer_Context* aContext = ((GLViewer_Viewer2d*)mypViewPort->getViewFrame()->getViewer())->getGLContext();
91 /*if( !aContext->currentObjectIsChanged() )
95 if( myPoint.x() == -1 && myPoint.y() == -1 || aContext->currentObjectIsChanged())
99 else/if( abs(myPoint.y() - p.y()) < 16 )
108 GLViewer_Object* anObj = aContext->getCurrentObject();
111 setText( anObj->getName() );
118 //GLViewer_Rect* aRect = anObj->getRect();
119 //QRect aWinRect = mypViewPort->GLV2win( *aRect );
120 tip( QRect( p.x(), p.y(), 1, 1 ), anObj->getName() );
121 //QFontMetrics aFM( font() );
122 //showTip( aWinRect, anObj->getName(), QRect( 0, 0, aFM.width( anObj->getName() + " " ), aFM.height()*1.5 ) );
123 //tip( aWinRect, anObj->getName(), aWinRect( aFM.width( anObj->getName() + " " ), aFM.height()*1.5 ) );
128 //tip( QRect( 0, 0, mypViewPort->getGLWidget()->width(),mypViewPort->getGLWidget()->height() ) , "test Tool tip" );
135 bool GLViewer_ObjectTip::eventFilter( QObject* theObj, QEvent* e )
140 /*case QEvent::MouseButtonPress:
141 case QEvent::MouseButtonRelease:
142 case QEvent::MouseButtonDblClick:
143 case QEvent::KeyPress:
144 case QEvent::KeyRelease:
145 // input - turn off tool tip mode
148 case QEvent::MouseMove:
151 /*if( mypTimer->isActive() )
156 QWidget* aWidget = (QWidget*) theObj;
157 if( aWidget == mypViewPort->getGLWidget() )
160 QMouseEvent* m = (QMouseEvent *)e;
162 // mypPoint = new QPoint();
164 myPoint.setX( m->x() );
165 myPoint.setY( m->y() );
173 Hides tooltip and stops timer
175 void GLViewer_ObjectTip::hideTipAndSleep()
193 void GLViewer_ObjectTip::showTip()
195 if( maybeTip( myPoint ) )
198 mypLabel->setText( myText );
199 mypLabel->adjustSize( );
201 QPoint pos = mypViewPort->getGLWidget()->mapToGlobal( myPoint );
205 QCursor* aCursor = QApplication::overrideCursor();
208 const QBitmap* aBitmap = aCursor->bitmap();
210 cur_height = aBitmap->height();
212 mypLabel->setGeometry( pos.x(), pos.y() + cur_height, mypLabel->width(), mypLabel->height() );
213 mypLabel->setPalette( QToolTip::palette() );
223 void GLViewer_ObjectTip::wakeup( int theTime )
225 if( mypTimer->isActive() )
227 mypTimer->start( theTime );