mouse buttons - my view from X11 upwards into Qt
David Faure
faure at kde.org
Mon Feb 21 20:03:21 GMT 2011
On Sunday 20 February 2011, Rick Stockton wrote:
> Qt::NoButton 0x00000000 The button state does not refer to any
> button (see QMouseEvent::button
> <http://doc.qt.nokia.com/4.7-snapshot/qmouseevent.html#button>()).
> Qt::LeftButton 0x00000001 The left button is pressed, or an event
> refers to the left button. (The left button may be the right button on
> left-handed mice.)
> Qt::RightButton 0x00000002 The right button.
> Qt::MidButton 0x00000004 The middle button.
> Qt::MiddleButton MidButton The middle button.
> Qt::XButton1 0x00000008 The first X button.
> Qt::XButton2 0x00000010 The second X button.
Let's look at the header file rather than the API docs:
enum MouseButton {
NoButton = 0x00000000,
LeftButton = 0x00000001,
RightButton = 0x00000002,
MidButton = 0x00000004, // ### Qt 5: remove me
MiddleButton = MidButton,
XButton1 = 0x00000008,
XButton2 = 0x00000010,
MouseButtonMask = 0x000000ff
};
"Qt::MouseButton defines all values as 32-bit hex values
(with leading zeroes)" is true, but does this really matter to the compiler?
0x00000001 is really just 1.
> I think that an enumerated item with an explicit value will NEVER be
> compressed, even though a Compiler which wanted to squeeze an enum of 7
> items (defined without specific values) into a SINGLE BYTE would be free
> to do so. If my understanding is correct on all platforms, then we can
> safely use the entire Uint32.
The standard (6.7.2.2 Enumeration specifiers) (not that I know this by heart,
google helped) says:
Each enumerated type shall be compatible with char, a signed integer type, or
an unsigned integer type. The choice of type is implementation-defined, but
shall be capable of representing the values of all the members of the
enumeration.
So this enum might very well be a single byte on some compilers, since 0xff
fits. AFAIK gcc and msvc don't do this, though. I'll let Thiago answer about
the more unusual compilers out there :-)
> This portion of "more mouse buttons", the part within Qt, isn't big
> enough for GSOC. Perhaps the KDE follow-ups are, and I will touch on a
> few in separate messages. I intend to write and fully document the Qt
> Updates myself, after I receive your comments and recommendation -- and,
> I hope, a similar input from a Qt person working in the "input devices"
> area. (I know that they have other, big things to think about, but I'd
> hate to do a bunch of work and be told "this isn't the right design"
> AFTERWARDS.) So, if you can link me up with such a Qt person, please do
> so. This is a REAL email address and a good contact point for me.
You might want to try IRC, irc.freenode.net, channel #qt-labs.
--
David Faure, faure at kde.org, http://www.davidfaure.fr
Sponsored by Nokia to work on KDE, incl. Konqueror (http://www.konqueror.org).
More information about the kde-core-devel
mailing list