[Kstars-devel] transient labels

Jason Harris kstars at 30doradus.org
Fri Feb 6 09:51:57 CET 2004


Hello,

I have mostly implemented transient object labels which appear on the 
map when you "hover" the mouse cursor on an object.  When you move the 
mouse cursor away, the label fades into the sky background color.

It was tricky to do, because there is no "mouseHoverEvent" in Qt.  To 
check for mouse hovering, I am checking to see if the mouse cursor 
coordinates remain fixed over a certain period of time.  

In KStarsData::updateTime(), I call a new function SkyMap::
checkHoverPoint().  Basically, it checks to see if the Mouse cursor has 
not moved for 0.5 sec, which I define as a "hover event".  When there 
is a hover event, it tries to identify the nearest object to the 
cursor,  identifies this object as TransientObject, and automatically 
attaches a label.  

Then, when checkHoverPoint() detects that we have moved the Mouse 
cursor, it triggers fadeTransientLabel(), which starts a QTimer to 
control the fading label color.  When the label has faded to the 
background, TransientObject is set to NULL and the QTimer is stopped.
Also, if you hover on a new target before the old one has faded away, 
the old label will be interrupted, and the new one drawn immediately 
(IOW, you can't have more than one TransientObject label at this 
point).

As you can see, it's pretty complicated, and I even glossed over a lot 
of the more disgusting parts!  I had to do a lot of debugging to avoid 
some instabilities, and in fact I am still chasing down a crash that 
occurs when the display is zoomed while a label is fading.

I don't know how happy I am with this code; it feels pretty kludgey 
somehow.  I really wish there was a mouseHoverEvent!   Anyway, I want 
to do some more debugging before I commit it, but I am going to be out 
of town for 10 days starting Saturday, so I may not get to work on it 
until I get back.

regards,
Jason
-- 
KStars: A KDE Planetarium
http://edu.kde.org/kstars


More information about the Kstars-devel mailing list