diff options
author | Morten Johan Sørvig <morten.sorvig@digia.com> | 2013-02-27 10:27:20 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-03-26 19:21:38 +0100 |
commit | b2c73c73cd0a68aae0586cf447c2612c13aeb52c (patch) | |
tree | 35c387cf8f14240e4cc3c5f10fa0acacfe27cdc7 /tests/manual | |
parent | a2fc37044ce3e7a51317a6528d121df632df5d68 (diff) |
Cocoa: Correct enter/leave event handling.
Make top-level windows generate enter/leave events
for sub-windows. Keep track of the current "under mouse"
window in mouseMoved and send EnterLeave events when
it changes.
mouseEntered/mouseExited handles enters and leaves
from the top-level window.
Add tests/manual/cocoa/nativewidgets.
Task-number: QTBUG-27550
Task-number: QTBUG-29751
Change-Id: If4b9f9e0f39d9fb05fdab45a100ffdcf107965ad
Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@digia.com>
Diffstat (limited to 'tests/manual')
-rw-r--r-- | tests/manual/cocoa/nativewidgets/main.cpp | 147 | ||||
-rw-r--r-- | tests/manual/cocoa/nativewidgets/nativewigets.pro | 7 |
2 files changed, 154 insertions, 0 deletions
diff --git a/tests/manual/cocoa/nativewidgets/main.cpp b/tests/manual/cocoa/nativewidgets/main.cpp new file mode 100644 index 0000000000..2ff919b125 --- /dev/null +++ b/tests/manual/cocoa/nativewidgets/main.cpp @@ -0,0 +1,147 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtCore> +#include <QtWidgets> + +class ColorWidget : public QWidget +{ + QColor color; + int s; + int v; + + void changeColor() + { + color.setHsv((qreal(qrand()) / RAND_MAX) * 50 + 200, s, s); + } + +public: + ColorWidget() + { + s = 150; + v = 150; + changeColor(); + setMouseTracking(true); + } + + void mousePressEvent(QMouseEvent *) + { + changeColor(); + update(); + } + + void mouseMoveEvent(QMouseEvent *) + { + changeColor(); + update(); + } + + void enterEvent(QEvent *) + { + s = 200; + v = 200; + changeColor(); + update(); + } + + void leaveEvent(QEvent *) + { + s = 75; + v = 75; + changeColor(); + update(); + } + + void paintEvent(QPaintEvent *){ + QPainter p(this); + p.fillRect(QRect(QPoint(0, 0), size()), QBrush(color)); + } +}; + + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + + ColorWidget window; + + QWidget *w1 = new ColorWidget; + QWidget *w2 = new ColorWidget; + QWidget *w3 = new ColorWidget; + + QHBoxLayout *layout = new QHBoxLayout; + layout->addWidget(w1); + layout->addWidget(w2); + layout->addWidget(w3); + + QWidget *w3_1 = new ColorWidget; + QWidget *w3_2 = new ColorWidget; + QWidget *w3_3 = new ColorWidget; + + QVBoxLayout *layout3 = new QVBoxLayout; + layout3->setMargin(0); + layout3->addWidget(w3_1); + layout3->addWidget(w3_2); + layout3->addWidget(w3_3); + w3->setLayout(layout3); + + window.setLayout(layout); + + bool native = 1; + + if (native) { + w1->winId(); + w2->winId(); + w3->winId(); + + w3_1->winId(); + w3_2->winId(); + w3_3->winId(); + } + + window.resize(640, 480); + window.show(); + + return app.exec(); +} + + + diff --git a/tests/manual/cocoa/nativewidgets/nativewigets.pro b/tests/manual/cocoa/nativewidgets/nativewigets.pro new file mode 100644 index 0000000000..f1b1260688 --- /dev/null +++ b/tests/manual/cocoa/nativewidgets/nativewigets.pro @@ -0,0 +1,7 @@ +TEMPLATE = app + +HEADERS += +SOURCES += main.cpp + +QT += core widgets +DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 |