From 4a80a7ced1f643a6794f6550d01c1fe60295a21c Mon Sep 17 00:00:00 2001 From: Rick Stockton Date: Mon, 6 Feb 2012 17:20:08 -0800 Subject: [PATCH] add widget mousebuttons example 'mousetester'. This is an xev-like program. A user clicks a mouse button inside the Window, and the program displays (a) the "raw" button number; (b) the corresponding Qt::MouseButton name; and (c) the type of mouse Event. Task-number: QTBUG-24112 Change-Id: I8a76ff37b5b85639f662706072cc4a2ce490754b Reviewed-by: Casper van Donderen --- doc/src/examples/widgets/mousebuttons.qdoc | 94 ++++++++++ .../widgets/mousebutton-buttontester.png | Bin 0 -> 14492 bytes .../widgets/mousebuttons/buttontester.cpp | 172 ++++++++++++++++++ examples/widgets/mousebuttons/buttontester.h | 64 +++++++ .../widgets/mousebuttons/buttontester.pro | 18 ++ examples/widgets/mousebuttons/main.cpp | 66 +++++++ examples/widgets/widgets.pro | 1 + 7 files changed, 415 insertions(+) create mode 100644 doc/src/examples/widgets/mousebuttons.qdoc create mode 100644 doc/src/images/widgets/mousebutton-buttontester.png create mode 100644 examples/widgets/mousebuttons/buttontester.cpp create mode 100644 examples/widgets/mousebuttons/buttontester.h create mode 100644 examples/widgets/mousebuttons/buttontester.pro create mode 100644 examples/widgets/mousebuttons/main.cpp diff --git a/doc/src/examples/widgets/mousebuttons.qdoc b/doc/src/examples/widgets/mousebuttons.qdoc new file mode 100644 index 00000000000..bf63cd50767 --- /dev/null +++ b/doc/src/examples/widgets/mousebuttons.qdoc @@ -0,0 +1,94 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2012 Rick Stockton +** Contact: http://www.qt-project.org/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** GNU Free Documentation License +** Alternatively, this file may be used under the terms of the GNU Free +** Documentation License version 1.3 as published by the Free Software +** Foundation and appearing in the file included in the packaging of +** this file. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms +** and conditions contained in a signed written agreement between you +** and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \example widgets/mousebuttons/buttontester + \title Mouse Button Tester + + \brief The 'Mouse Button Tester' example demonstrates how to reimplement + mouse events within a custom class. You can also use this program to + verify that Qt is actually receiving mouse events from your mouse. + + Many 'gamer' mouse devices are configured with high-numbered "buttons" + sending text shortcuts for certain games. With such a mouse, no mouse + button events occur: The "mouse" sends keystrokes, and the + 'Mouse Button Tester' Window will not see the event. Receving no event, + it will not repaint the Window with new text describing a \button event. + + And so, in addition to it's use as Qt example code, the program may be + useful s a mouse device tester. Note that there is another example + muouse buttons example which provides the same function, written in QML. + + This program (the Widget-based example) consists of three classes, + in addition to the main() parent program: + + \list + \o \c A QPushButton, "Quit". + \o \c ButtonTester. This is derived from Qt's TextArea class, for + purpose of customizing/re-implementing the mouse and wheel event + member functions. + \o \c A simple QVBoxLayout layout. + \endlist + + First we will review the main program, with it's layout and "Quit" + QPushButton. Then we will take a look at the \c ButtonTester class. + + \section1 The Main Program + + Note that the QPushButton, "Quit", is defined directly within the main() + program, rather than another class. This is a correct way of defining a + "Quit" QPushButton: A "Quit" Button defined inside another + class would result in the destructor of that second class being + called twice. This "Quit" Button uses the traditional Signal/Slot + connection to invoke termination of the QApp, which will properly destroy + its child classes \before terminating itself. + + The remainder of the main() program is concerned with defining the layout, + and applying a minimum size to the customized ButtonTester. + + \section1 ButtonTester Class Definition + + The \c ButtonTester class inherits from QTextEdit, and listens for + mouse events on all possible Qt::MouseButton values. It also listens for + wheel events from the mouse, and indicates the direction of wheel motion + ("up", down", "left", or "right"). It prints short debug messages into + the Window, and also on the console QDebug() stream, when mouse button + and wheel events occur. Our reimplementation of mousePressEvent(), + mouseReleaseEvent(), mouseDoubleClickEvent(), and wheelEvent() "drive" + the program; the other functions simply convert the Qt::MouseButton + values into text strings. + + You should call the ignore() function on any mouse event (or other event) + which your widget-based classes do not use and consume. This function + assures that Qt will propagate the event through each parent widget, + until it is used or propagated to the Window Manager. (Qt attempts to do + this automatically, but it is better programming practice to explicitly + invoke the function.) + + \image widgets/mousebutton-buttontester.png +*/ diff --git a/doc/src/images/widgets/mousebutton-buttontester.png b/doc/src/images/widgets/mousebutton-buttontester.png new file mode 100644 index 0000000000000000000000000000000000000000..82fcb7617fff868031ecb8bb30775de970c60d13 GIT binary patch literal 14492 zcmeHuc{E#J`>&y;rF5c$7Hw6{v^CYNH5D~W%v4noV-bWJT189IQncndBE%RWL^>N% zW5f_siW=d8V-v(K~l`FuY6t+}ZI50?NJ z3kwU6;X_?Z78bTMEG(?36C6h#(x%UYqrl_TfnU_IMlYp-A*cNP~N$n&$tzd2xKhd#X5!AcC5|hl! zHhA^{*AjUAK!o+&H4=OAtG@Nzh}5x_-WT#?d61B2A$2#sR!ZZXSy@;VzDQ+(>#FL~ zFNEXA%b0k#BVWQBk`%D(x?wNZf|kYw7M6e$uu~^Ierjp({$oFXn3fcC)CP`waYtp} z5hA$0_ss)e2c_Tade-o9De*l{%%_0HvoR+%lvAQ!FfU0Pz2e%;!gBRg6MI{b;UQ>pD34h|OW z+3VMMEwzWDxI|oDW}|}3(2Xe>9jidkfWjy8!0tS9iRIyAQrxfZw2w1(i1&r!J+(WhLr6Yxa;MK>0CaUMapbeD=5my!Lvk_-msXniMB{K+Kt}RF zjKk+~pL_ZoHO$)4vgqAA^+;Moc@%D|b2rIBI_E~oKB-H_BEOXtrOc6&8lIO{K5z%@ zv*GAY-#vQljYAe}_WZh|?A2o4f|%M$CLCeY)4m>bo2|HbElK=vTghrSUJ;c2*h){Y zBAdfTyuq_oJ!&8j_*$y?2_{?2#&gY#JL6*XJL|sf81^R+5(OA>`JOa#GB8U>qD|ko zIP#`p)1TXd{9e=4Vv9Ylp2$C{r2MVIv{$F+eol5)%H%+OTA7YHQV~z(MLRepMMX`! z{ziKdl0=DT=SKb*a@=a{SJWvc{B|ytNR2K{j;iKgtOa2(1EV)lsQlXjena0nWQV_f zO|6I|Ob-rCw>#d`RgBVZ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y{4l8b!tkevneUEH5OjLze!o% z#rz*t%Sw!Faqd658G$3+%)Qq~dKudb)3Tf_U!n<7oUgksnjIyd@7({NNao*C!~b9c zXW>=sI>m>u=l`UzPDD&CTM4u4Ung%w4Y_R)G$x+?D4!+7%X-OF9kNS5#@}HtdV8c3 QVqr1VGu1^rc>L;r0SA!xoB#j- literal 0 HcmV?d00001 diff --git a/examples/widgets/mousebuttons/buttontester.cpp b/examples/widgets/mousebuttons/buttontester.cpp new file mode 100644 index 00000000000..32f73ebb72d --- /dev/null +++ b/examples/widgets/mousebuttons/buttontester.cpp @@ -0,0 +1,172 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2012 Rick Stockton +** Contact: http://www.qt-project.org/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "buttontester.h" + +void ButtonTester::mousePressEvent(QMouseEvent *e) +{ + int j = ButtonTester::buttonByNumber (e->button()); + QString result = "Mouse Press: raw button=" + QString::number(j) + " Qt=" + enumNameFromValue(e->button()); + qDebug() << result; + this->setText(result); + if (j == 2) { + this->repaint(); + } +} + +void ButtonTester::mouseReleaseEvent(QMouseEvent *e) +{ + int j = ButtonTester::buttonByNumber (e->button()); + QString result = "Mouse Release: raw button=" + QString::number(j) + " Qt=" + enumNameFromValue(e->button()); + qDebug() << result; + this->setText(result); +} + +void ButtonTester::mouseDoubleClickEvent(QMouseEvent *e) +{ + int j = ButtonTester::buttonByNumber (e->button()); + QString result = "Mouse DoubleClick: raw button=" + QString::number(j) + " Qt=" + enumNameFromValue(e->button()); + qDebug() << result; + this->setText(result); +} + +void ButtonTester::wheelEvent (QWheelEvent *e) +{ + QString result; + if (e->delta() > 0) { + + if (e->orientation() == Qt::Vertical) { + result = "Mouse Wheel Event: UP"; + } else { + result = "Mouse Wheel Event: LEFT"; + } + } else if (e->delta() < 0) { + if (e->orientation() == Qt::Vertical) { + result = "Mouse Wheel Event: DOWN"; + } else { + result = "Mouse Wheel Event: RIGHT"; + } + } + qDebug() << result; + this->setText(result); +} + +int ButtonTester::buttonByNumber(const Qt::MouseButton button) +{ + if (button == Qt::NoButton) return 0; + if (button == Qt::LeftButton) return 1; + if (button == Qt::RightButton) return 2; + if (button == Qt::MiddleButton) return 3; + +/* Please note that Qt Button #4 corresponds to button #8 on all + * platforms which EMULATE wheel events by creating button events + * (Button #4 = Scroll Up; Button #5 = Scroll Down; Button #6 = Scroll + * Left; and Button #7 = Scroll Right.) This includes X11, with both + * Xlib and XCB. So, the "raw button" for "Qt::BackButton" is + * usually described as "Button #8". + + * If your platform supports "smooth scrolling", then, for the cases of + * Qt::BackButton and higher, this program will show "raw button" with a + * value which is too large. Subtract 4 to get the correct button ID for + * your platform. + */ + + if (button == Qt::BackButton) return 8; + if (button == Qt::ForwardButton) return 9; + if (button == Qt::TaskButton) return 10; + if (button == Qt::ExtraButton4) return 11; + if (button == Qt::ExtraButton5) return 12; + if (button == Qt::ExtraButton6) return 13; + if (button == Qt::ExtraButton7) return 14; + if (button == Qt::ExtraButton8) return 15; + if (button == Qt::ExtraButton9) return 16; + if (button == Qt::ExtraButton10) return 17; + if (button == Qt::ExtraButton11) return 18; + if (button == Qt::ExtraButton12) return 19; + if (button == Qt::ExtraButton13) return 20; + if (button == Qt::ExtraButton14) return 21; + if (button == Qt::ExtraButton15) return 22; + if (button == Qt::ExtraButton16) return 23; + if (button == Qt::ExtraButton17) return 24; + if (button == Qt::ExtraButton18) return 25; + if (button == Qt::ExtraButton19) return 26; + if (button == Qt::ExtraButton20) return 27; + if (button == Qt::ExtraButton21) return 28; + if (button == Qt::ExtraButton22) return 29; + if (button == Qt::ExtraButton23) return 30; + if (button == Qt::ExtraButton24) return 31; + qDebug("QMouseShortcutEntry::addShortcut contained Invalid Qt::MouseButton value"); + return 0; +} + +QString ButtonTester::enumNameFromValue(const Qt::MouseButton button) +{ + if (button == Qt::NoButton) return "NoButton"; + if (button == Qt::LeftButton) return "LeftButton"; + if (button == Qt::RightButton) return "RightButton"; + if (button == Qt::MiddleButton) return "MiddleButton"; + if (button == Qt::BackButton) return "BackButton"; + if (button == Qt::ForwardButton) return "ForwardButton"; + if (button == Qt::TaskButton) return "TaskButton"; + if (button == Qt::ExtraButton4) return "ExtraButton4"; + if (button == Qt::ExtraButton5) return "ExtraButton5"; + if (button == Qt::ExtraButton6) return "ExtraButton6"; + if (button == Qt::ExtraButton7) return "ExtraButton7"; + if (button == Qt::ExtraButton8) return "ExtraButton8"; + if (button == Qt::ExtraButton9) return "ExtraButton9"; + if (button == Qt::ExtraButton10) return "ExtraButton10"; + if (button == Qt::ExtraButton11) return "ExtraButton11"; + if (button == Qt::ExtraButton12) return "ExtraButton12"; + if (button == Qt::ExtraButton13) return "ExtraButton13"; + if (button == Qt::ExtraButton14) return "ExtraButton14"; + if (button == Qt::ExtraButton15) return "ExtraButton15"; + if (button == Qt::ExtraButton16) return "ExtraButton16"; + if (button == Qt::ExtraButton17) return "ExtraButton17"; + if (button == Qt::ExtraButton18) return "ExtraButton18"; + if (button == Qt::ExtraButton19) return "ExtraButton19"; + if (button == Qt::ExtraButton20) return "ExtraButton20"; + if (button == Qt::ExtraButton21) return "ExtraButton21"; + if (button == Qt::ExtraButton22) return "ExtraButton22"; + if (button == Qt::ExtraButton23) return "ExtraButton23"; + if (button == Qt::ExtraButton24) return "ExtraButton24"; + qDebug("QMouseShortcutEntry::addShortcut contained Invalid Qt::MouseButton value"); + return "NoButton"; +} diff --git a/examples/widgets/mousebuttons/buttontester.h b/examples/widgets/mousebuttons/buttontester.h new file mode 100644 index 00000000000..0801a9ae5c4 --- /dev/null +++ b/examples/widgets/mousebuttons/buttontester.h @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2012 Rick Stockton +** Contact: http://www.qt-project.org/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef BUTTONTESTER_H +#define BUTTONTESTER_H + +#include +#include +#include +#include +#include +#include + +class ButtonTester : public QTextEdit +{ + Q_OBJECT + +protected: + void mousePressEvent(QMouseEvent *event); + void mouseReleaseEvent(QMouseEvent *event); + void mouseDoubleClickEvent(QMouseEvent *event); + void wheelEvent(QWheelEvent * event); + int buttonByNumber(const Qt::MouseButton button); + QString enumNameFromValue(const Qt::MouseButton button); +}; + +#endif // BUTTONTESTER_H diff --git a/examples/widgets/mousebuttons/buttontester.pro b/examples/widgets/mousebuttons/buttontester.pro new file mode 100644 index 00000000000..823b04657e6 --- /dev/null +++ b/examples/widgets/mousebuttons/buttontester.pro @@ -0,0 +1,18 @@ +TEMPLATE = app + +TARGET = buttontester +TEMPLATE = app + +SOURCES += \ + main.cpp\ + buttontester.cpp \ + +HEADERS += \ + buttontester.h \ + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/qtbase/examples/widgets/mousebuttons +sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS buttontester.pro +sources.path = $$[QT_INSTALL_EXAMPLES]/qtbase/examples/widgets/mousebuttons +INSTALLS += target sources +QT += core widgets diff --git a/examples/widgets/mousebuttons/main.cpp b/examples/widgets/mousebuttons/main.cpp new file mode 100644 index 00000000000..7c9674a9d9f --- /dev/null +++ b/examples/widgets/mousebuttons/main.cpp @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2012 Rick Stockton +** Contact: http://www.qt-project.org/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "buttontester.h" +#include + +int main(int argv, char **args) +{ + QApplication app(argv, args); + + ButtonTester *testArea = new ButtonTester; + testArea->setMinimumSize(500, 350); + testArea->setText("To test your mouse with Qt, press buttons in this area.\nYou may also scroll or tilt your mouse wheel."); + QPushButton *quitButton = new QPushButton("Quit"); + + QObject::connect(quitButton, SIGNAL(clicked()), qApp, SLOT(quit())); + + QVBoxLayout *layout = new QVBoxLayout; + layout->addWidget(testArea); + layout->addWidget(quitButton); + + QWidget window; + window.setLayout(layout); + window.setWindowTitle("Mouse Button Tester"); + window.show(); + + return app.exec(); +} diff --git a/examples/widgets/widgets.pro b/examples/widgets/widgets.pro index 51a92bcc29e..f5c98c3c778 100644 --- a/examples/widgets/widgets.pro +++ b/examples/widgets/widgets.pro @@ -12,6 +12,7 @@ SUBDIRS = analogclock \ imageviewer \ lineedits \ movie \ + mousebuttons \ orientation \ scribble \ shapedclock \