summaryrefslogtreecommitdiffstats
path: root/tests/manual/qscreen/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/manual/qscreen/main.cpp')
-rw-r--r--tests/manual/qscreen/main.cpp67
1 files changed, 67 insertions, 0 deletions
diff --git a/tests/manual/qscreen/main.cpp b/tests/manual/qscreen/main.cpp
index f9f93fd525..445af82e09 100644
--- a/tests/manual/qscreen/main.cpp
+++ b/tests/manual/qscreen/main.cpp
@@ -40,6 +40,61 @@
#include <QStatusBar>
#include <QLineEdit>
#include <QDesktopWidget>
+#include <QPushButton>
+#include <QLabel>
+#include <QMouseEvent>
+
+
+class MouseMonitor : public QLabel {
+ Q_OBJECT
+public:
+ MouseMonitor() : m_grabbed(false) {
+ setMinimumSize(540, 240);
+ setAlignment(Qt::AlignCenter);
+ setMouseTracking(true);
+ setWindowTitle(QLatin1String("Mouse Monitor"));
+ updateText();
+ }
+
+ void updateText() {
+ QString txt = m_grabbed ?
+ QLatin1String("Left-click to test QGuiApplication::topLevelAt(click pos)\nRight-click to ungrab\n") :
+ QLatin1String("Left-click to grab mouse\n");
+ if (!m_cursorPos.isNull()) {
+ txt += QString(QLatin1String("Current mouse position: %1, %2 on screen %3\n"))
+ .arg(m_cursorPos.x()).arg(m_cursorPos.y()).arg(QApplication::desktop()->screenNumber(m_cursorPos));
+ if (QGuiApplication::mouseButtons() & Qt::LeftButton) {
+ QWindow *win = QGuiApplication::topLevelAt(m_cursorPos);
+ txt += QString(QLatin1String("Top-level window found? %1\n"))
+ .arg(win ? (win->title().isEmpty() ? "no title" : win->title()) : "none");
+ }
+ }
+ setText(txt);
+ }
+
+protected:
+ void mouseMoveEvent(QMouseEvent *ev) Q_DECL_OVERRIDE {
+ m_cursorPos = ev->screenPos().toPoint();
+ updateText();
+ }
+
+ void mousePressEvent(QMouseEvent *ev) Q_DECL_OVERRIDE {
+ m_cursorPos = ev->screenPos().toPoint();
+ qDebug() << "top level @" << m_cursorPos << ":" << QGuiApplication::topLevelAt(m_cursorPos);
+ updateText();
+ if (!m_grabbed) {
+ grabMouse(Qt::CrossCursor);
+ m_grabbed = true;
+ } else if (ev->button() == Qt::RightButton) {
+ setVisible(false);
+ deleteLater();
+ }
+ }
+
+private:
+ QPoint m_cursorPos;
+ bool m_grabbed;
+};
class ScreenPropertyWatcher : public PropertyWatcher
{
@@ -96,6 +151,7 @@ public:
protected:
bool event(QEvent *event) Q_DECL_OVERRIDE;
+ void startMouseMonitor();
private:
const QString m_annotation;
@@ -119,6 +175,11 @@ ScreenWatcherMainWindow::ScreenWatcherMainWindow(QScreen *screen)
a = fileMenu->addAction(QLatin1String("Quit"));
a->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q));
connect(a, SIGNAL(triggered()), qApp, SLOT(quit()));
+
+ QMenu *toolsMenu = menuBar()->addMenu(QLatin1String("&Tools"));
+ a = toolsMenu->addAction(QLatin1String("Mouse Monitor"));
+ a->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_M));
+ connect(a, &QAction::triggered, this, &ScreenWatcherMainWindow::startMouseMonitor);
}
static inline QString msgScreenChange(const QWidget *w, const QScreen *oldScreen, const QScreen *newScreen)
@@ -154,6 +215,12 @@ bool ScreenWatcherMainWindow::event(QEvent *event)
return QMainWindow::event(event);
}
+void ScreenWatcherMainWindow::startMouseMonitor()
+{
+ MouseMonitor *mm = new MouseMonitor();
+ mm->show();
+}
+
void screenAdded(QScreen* screen)
{
screen->setOrientationUpdateMask((Qt::ScreenOrientations)0x0F);