Source Code (Use browser search to find items of interest.)
Class Index
qt'QTipManager (./qt-2.1.0/src/widgets/qtooltip.cpp:67)
class QTipManager : public QObject
{
Q_OBJECT
public:
QTipManager();
~QTipManager();
struct Tip
{
QRect rect;
QString text;
QString groupText;
QToolTipGroup *group;
QToolTip *tip;
bool autoDelete;
QRect geometry;
Tip *next;
};
bool eventFilter( QObject * o, QEvent * e );
void add( const QRect &gm, QWidget *, const QRect &, const QString& ,
QToolTipGroup *, const QString& , QToolTip *, bool );
void add( QWidget *, const QRect &, const QString& ,
QToolTipGroup *, const QString& , QToolTip *, bool );
void remove( QWidget *, const QRect & );
void remove( QWidget * );
void removeFromGroup( QToolTipGroup * );
public slots:
void hideTip();
private slots:
void labelDestroyed();
void clientWidgetDestroyed();
void showTip();
private:
QTimer wakeUp;
QTimer fallAsleep;
QPtrDict<Tip> *tips;
QLabel *label;
QPoint pos;
QGuardedPtr<QWidget> widget;
Tip *currentTip;
Tip *previousTip;
bool isApplicationFilter;
};
// We have a global, internal QTipManager object
qt'QTipManager::QTipManager() (./qt-2.1.0/src/widgets/qtooltip.cpp:143)
QTipManager::QTipManager()
: QObject( 0, "toolTipManager" )
{
tips = new QPtrDict<QTipManager::Tip>( 313 );
currentTip = 0;
previousTip = 0;
label = 0;
isApplicationFilter = FALSE;
connect( &wakeUp, SIGNAL(timeout()), SLOT(showTip()) );
connect( &fallAsleep, SIGNAL(timeout()), SLOT(hideTip()) );
}
qt'QTipManager::~QTipManager() (./qt-2.1.0/src/widgets/qtooltip.cpp:156)
QTipManager::~QTipManager()
{
if ( isApplicationFilter && !qApp->closingDown() ) {
qApp->setGlobalMouseTracking( FALSE );
qApp->removeEventFilter( tipManager );
}
if ( tips ) {
QPtrDictIterator<QTipManager::Tip> i( *tips );
QTipManager::Tip *t, *n;
void *k;
while( (t = i.current()) != 0 ) {
k = i.currentKey();
++i;
tips->take( k );
while ( t ) {
n = t->next;
delete t;
t = n;
}
}
delete tips;
}
delete label;
}
qt'QTipManager::add() (./qt-2.1.0/src/widgets/qtooltip.cpp:183)
void QTipManager::add( const QRect &gm, QWidget *w, const QRect &r, const QString &s,
QToolTipGroup *g, const QString& gs,
QToolTip *tt, bool a )
{
QTipManager::Tip *h = (*tips)[ w ];
QTipManager::Tip *t = new QTipManager::Tip;
t->next = h;
t->tip = tt;
t->autoDelete = a;
t->text = s;
t->rect = r;
t->groupText = gs;
t->group = g;
t->geometry = gm;
if ( h )
tips->take( w );
else
connect( w, SIGNAL(destroyed()), this, SLOT(clientWidgetDestroyed()) );
tips->insert( w, t );
if ( a && t->rect.contains( pos ) && (!g || g->enabled()) )
showTip();
if ( !isApplicationFilter && qApp ) {
isApplicationFilter = TRUE;
qApp->installEventFilter( tipManager );
qApp->setGlobalMouseTracking( TRUE );
}
}
qt'QTipManager::add() (./qt-2.1.0/src/widgets/qtooltip.cpp:215)
void QTipManager::add( QWidget *w, const QRect &r, const QString &s,
QToolTipGroup *g, const QString& gs,
QToolTip *tt, bool a )
{
add( QRect( -1, -1, -1, -1 ),
w, r, s, g, gs, tt, a );
}
qt'QTipManager::remove() (./qt-2.1.0/src/widgets/qtooltip.cpp:224)
void QTipManager::remove( QWidget *w, const QRect & r )
{
QTipManager::Tip *t = (*tips)[ w ];
if ( t == 0 )
return;
if ( t == currentTip )
hideTip();
if ( t == previousTip )
previousTip = 0;
if ( t->rect == r ) {
tips->take( w );
if ( t->next )
tips->insert( w, t->next );
delete t;
} else {
while( t->next && t->next->rect != r )
t = t->next;
if ( t->next ) {
QTipManager::Tip *d = t->next;
t->next = t->next->next;
delete d;
}
}
if ( tips->isEmpty() ) {
// the manager will be recreated if needed
delete tipManager;
tipManager = 0;
}
}
/*!
The label was destroyed in the program cleanup phase.
*/
qt'QTipManager::labelDestroyed() (./qt-2.1.0/src/widgets/qtooltip.cpp:263)
void QTipManager::labelDestroyed()
{
label = 0;
}
/*!
Remove sender() from the tool tip data structures.
*/
qt'QTipManager::clientWidgetDestroyed() (./qt-2.1.0/src/widgets/qtooltip.cpp:273)
void QTipManager::clientWidgetDestroyed()
{
const QObject *s = sender();
if ( s )
remove( (QWidget*) s );
}
qt'QTipManager::remove() (./qt-2.1.0/src/widgets/qtooltip.cpp:281)
void QTipManager::remove( QWidget *w )
{
QTipManager::Tip *t = (*tips)[ w ];
if ( t == 0 )
return;
tips->take( w );
QTipManager::Tip * d;
while ( t ) {
if ( t == currentTip )
hideTip();
d = t->next;
delete t;
t = d;
}
if ( tips->isEmpty() ) {
delete tipManager;
tipManager = 0;
}
}
qt'QTipManager::removeFromGroup() (./qt-2.1.0/src/widgets/qtooltip.cpp:304)
void QTipManager::removeFromGroup( QToolTipGroup *g )
{
QPtrDictIterator<QTipManager::Tip> i( *tips );
QTipManager::Tip *t;
while( (t = i.current()) != 0 ) {
++i;
while ( t ) {
if ( t->group == g )
t->group = 0;
t = t->next;
}
}
}
qt'QTipManager::eventFilter() (./qt-2.1.0/src/widgets/qtooltip.cpp:320)
bool QTipManager::eventFilter( QObject *obj, QEvent *e )
{
// avoid dumping core in case of application madness, and return
// quickly for some common but irrelevant events
if ( !qApp || !qApp->focusWidget() ||
!obj || !obj->isWidgetType() || // isWidgetType() catches most stuff
!e ||
e->type() == QEvent::Paint ||
e->type() == QEvent::Timer ||
e->type() == QEvent::SockAct ||
!tips )
return FALSE;
QWidget *w = (QWidget *)obj;
if ( e->type() == QEvent::FocusOut || e->type() == QEvent::FocusIn ) {
// user moved focus somewhere - hide the tip
hideTip();
fallAsleep.stop();
return FALSE;
}
QTipManager::Tip *t = 0;
while( w && !t ) {
t = (*tips)[ w ];
if ( !t )
w = w->isTopLevel() ? 0 : w->parentWidget();
}
if ( !t ) {
if ( e->type() >= QEvent::MouseButtonPress &&
e->type() <= QEvent::Leave ) {
hideTip();
}
return FALSE;
}
// with that out of the way, let's get down to action
switch( e->type() ) {
case QEvent::MouseButtonPress:
case QEvent::MouseButtonRelease:
case QEvent::MouseButtonDblClick:
case QEvent::KeyPress:
case QEvent::KeyRelease:
// input - turn off tool tip mode
hideTip();
fallAsleep.stop();
break;
case QEvent::MouseMove:
{ // a whole scope just for one variable
QMouseEvent * m = (QMouseEvent *)e;
QPoint mousePos( m->pos() );
mousePos = ((QWidget*)obj)->mapToGlobal( mousePos );
mousePos = w->mapFromGlobal( mousePos );
if ( currentTip && !currentTip->rect.contains( mousePos ) ) {
hideTip();
if ( m->state() == 0 )
return FALSE;
}
wakeUp.stop();
if ( m->state() == 0 ) {
if ( label && label->isVisible() ) {
return FALSE;
} else {
if ( fallAsleep.isActive() ) {
wakeUp.start( 1, TRUE );
} else {
previousTip = 0;
wakeUp.start( 700, TRUE );
}
if ( t->group && t->group->ena &&
!t->group->del && !t->groupText.isEmpty() )
emit t->group->showTip( t->groupText );
}
widget = w;
pos = mousePos;
return FALSE;
} else {
hideTip();
}
}
break;
case QEvent::Leave:
case QEvent::Hide:
case QEvent::Destroy:
if ( w == widget )
hideTip();
break;
default:
break;
}
return FALSE;
}
qt'QTipManager::showTip() (./qt-2.1.0/src/widgets/qtooltip.cpp:419)
void QTipManager::showTip()
{
if ( !widget || !globally_enabled )
return;
QTipManager::Tip *t = (*tips)[ widget ];
while ( t && !t->rect.contains( pos ) )
t = t->next;
if ( t == 0 )
return;
if ( t->tip ) {
t->tip->maybeTip( pos );
return;
}
if ( t->group && !t->group->ena )
return;
if ( label ) {
label->setText( t->text );
label->adjustSize();
if ( t->geometry != QRect( -1, -1, -1, -1 ) )
label->resize( t->geometry.size() );
} else {
label = new QTipLabel(t->text);
if ( t->geometry != QRect( -1, -1, -1, -1 ) )
label->resize( t->geometry.size() );
CHECK_PTR( label );
connect( label, SIGNAL(destroyed()), SLOT(labelDestroyed()) );
}
QPoint p;
if ( t->geometry == QRect( -1, -1, -1, -1 ) ) {
p = widget->mapToGlobal( pos ) + QPoint( 2, 16 );
} else {
p = widget->mapToGlobal( t->geometry.topLeft() );
label->setAlignment( WordBreak | AlignCenter );
int h = label->heightForWidth( t->geometry.width() - 4 );
label->resize( label->width(), h );
}
if ( p.x() + label->width() > QApplication::desktop()->width() )
p.setX( QApplication::desktop()->width() - label->width() );
if ( p.y() + label->height() > QApplication::desktop()->height() )
p.setY( p.y() - 20 - label->height() );
if ( label->text().length() ) {
label->move( p );
label->show();
label->raise();
fallAsleep.start( 10000, TRUE );
}
if ( t->group && t->group->del && !t->groupText.isEmpty() )
emit t->group->showTip( t->groupText );
currentTip = t;
previousTip = 0;
}
qt'QTipManager::hideTip() (./qt-2.1.0/src/widgets/qtooltip.cpp:477)
void QTipManager::hideTip()
{
if ( label && label->isVisible() ) {
label->hide();
fallAsleep.start( 2000, TRUE );
wakeUp.stop();
if ( currentTip && currentTip->group )
emit currentTip->group->removeTip();
} else if ( wakeUp.isActive() ) {
wakeUp.stop();
if ( currentTip && currentTip->group &&
!currentTip->group->del && !currentTip->groupText.isEmpty() )
emit currentTip->group->removeTip();
}
previousTip = currentTip;
currentTip = 0;
if ( previousTip && previousTip->autoDelete )
remove( widget, previousTip->rect );
widget = 0;
}
// NOT REVISED
/*!
\class QToolTip qtooltip.h
\brief The QToolTip class provides tool tips (sometimes called
balloon help) for any widget or rectangular part of a widget.
\ingroup helpsystem
The tip is a short, one-line text reminding the user of the widget's
or rectangle's function. It is drawn immediately below the region,
in a distinctive black on yellow combination. In Motif style, Qt's
tool tips look much like Motif's but feel more like Windows 95 tool
tips.
QToolTipGroup provides a way for tool tips to display another text
elsewhere (most often in a status bar).
At any point in time, QToolTip is either dormant or active. In
dormant mode the tips are not shown, and in active mode they are.
The mode is global, not particular to any one widget.
QToolTip switches from dormant to active mode when the user lets the
mouse rest on a tip-equipped region for a second or so, and remains
in active mode until the user either clicks a mouse button, presses
a key, lets the mouse rest for five seconds, or moves the mouse
outside \e all tip-equpped regions for at least a second.
The QToolTip class can be used in three different ways: <ol> <li>
Adding a tip to an entire widget. <li> Adding a tip to a fixed
rectangle within a widget. <li> Adding a tip to a dynamic rectangle
within a widget. </ol>
To add a tip to a widget, call the \e static function QToolTip::add()
with the widget and tip as arguments:
\code
QToolTip::add( quitButton, "Leave the application" );
\endcode
This is the simplest and most common use of QToolTip. The tip will
be deleted automatically when \e quitButton is deleted, but you can
remove it yourself, too:
\code
QToolTip::remove( quitButton );
\endcode
You can also display another text (typically in a \link QStatusBar
status bar),\endlink courtesy of QToolTipGroup. This example
assumes that \e g is a <code>QToolTipGroup *</code> and already
connected to the appropriate status bar:
\code
QToolTip::add( quitButton, "Leave the application", g,
"Leave the application, without asking for confirmation" );
QToolTip::add( closeButton, "Close this window", g,
"Close this window, without asking for confirmation" );
\endcode
To add a tip to a fixed rectangle within a widget, call the static
function QToolTip::add() with the widget, rectangle and tip as
arguments. (See the tooltip/tooltip.cpp example.) Again, you can supply a
QToolTipGroup * and another text if you want.
Both of the above are one-liners and cover the vast majority of
cases. The third and most general way to use QToolTip uses a pure
virtual function to decide whether to pop up a tool tip. The
tooltip/tooltip.cpp example demonstrates this too. This mode can be
used to implement e.g. tips for text that can move as the user
scrolls.
To use QToolTip like this, you need to subclass QToolTip and
reimplement maybeTip(). maybeTip() will be called when there's a
chance that a tip should pop up. It must decide whether to show a
tip, and possibly call add() with the rectangle the tip applies to,
the tip's text and optionally the QToolTipGroup details. The tip
will disappear once the mouse moves outside the rectangle you
supply, and \e not \e reappear - maybeTip() will be called again if
the user lets the mouse rest within the same rectangle again. You
can forcibly remove the tip by calling remove() with no arguments.
This is handy if the widget scrolls.
Tooltips can be globally disabled using QToolTip::setEnabled(), or
disabled in groups with QToolTipGroup::setEnabled().
\sa QStatusBar QWhatsThis QToolTipGroup
<a href="guibooks.html#fowler">GUI Design Handbook: Tool Tip</a>
*/
/*
Global settings for tool tips.
*/