|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the test suite of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #include "mainwindow.h" |
|
43 #include "ui_mainwindow.h" |
|
44 |
|
45 #include <QTimer> |
|
46 #include <QBitmap> |
|
47 #include <QImage> |
|
48 #include <QPainter> |
|
49 #include <QKeyEvent> |
|
50 |
|
51 MainWindow::MainWindow(QWidget *parent) : |
|
52 QMainWindow(parent), ui(new Ui::MainWindow) |
|
53 { |
|
54 ui->setupUi(this); |
|
55 QPixmap pix(":/data/monkey_on_64x64.png"); |
|
56 |
|
57 QImage mask(16, 16, QImage::Format_MonoLSB); |
|
58 QImage bw(16, 16, QImage::Format_MonoLSB); |
|
59 mask.fill(0); |
|
60 bw.fill(0); |
|
61 for (int x = 0; x < 16; x++) { |
|
62 bw.setPixel(x, x, 1); |
|
63 bw.setPixel(x, 15 - x, 1); |
|
64 mask.setPixel(x, x, 1); |
|
65 mask.setPixel(x, 15 - x, 1); |
|
66 if (x > 0 && x < 15) { |
|
67 mask.setPixel(x - 1, x, 1); |
|
68 mask.setPixel(x + 1, x, 1); |
|
69 mask.setPixel(x - 1, 15 - x, 1); |
|
70 mask.setPixel(x + 1, 15 - x, 1); |
|
71 } |
|
72 } |
|
73 |
|
74 ccurs = QCursor(pix); |
|
75 bcurs = QCursor(QBitmap::fromImage(bw), QBitmap::fromImage(mask)); |
|
76 ui->label->setCursor(ccurs); |
|
77 |
|
78 timer = new QTimer(this); |
|
79 connect(timer, SIGNAL(timeout()), this, SLOT(toggleOverrideCursor())); |
|
80 timer->start(2000); |
|
81 |
|
82 override = 0; |
|
83 } |
|
84 |
|
85 MainWindow::~MainWindow() |
|
86 { |
|
87 delete timer; |
|
88 delete ui; |
|
89 } |
|
90 |
|
91 void MainWindow::toggleOverrideCursor() |
|
92 { |
|
93 switch (override) { |
|
94 case 0: |
|
95 QApplication::setOverrideCursor(Qt::BusyCursor); |
|
96 break; |
|
97 case 1: |
|
98 QApplication::restoreOverrideCursor(); |
|
99 break; |
|
100 case 2: |
|
101 ui->label->grabMouse(Qt::ForbiddenCursor); |
|
102 break; |
|
103 case 3: |
|
104 case 5: |
|
105 ui->label->releaseMouse(); |
|
106 break; |
|
107 case 4: |
|
108 ui->label->grabMouse(); |
|
109 break; |
|
110 case 6: |
|
111 ui->label->setCursor(bcurs); |
|
112 break; |
|
113 case 7: |
|
114 ui->label->setCursor(ccurs); |
|
115 break; |
|
116 } |
|
117 override = (override + 1) % 8; |
|
118 } |
|
119 |
|
120 void MainWindow::keyPressEvent(QKeyEvent* event) |
|
121 { |
|
122 QPoint off(0, 0); |
|
123 switch (event->key()) { |
|
124 case Qt::Key_Up: |
|
125 off.setY(-4); |
|
126 break; |
|
127 case Qt::Key_Down: |
|
128 off.setY(4); |
|
129 break; |
|
130 case Qt::Key_Left: |
|
131 off.setX(-4); |
|
132 break; |
|
133 case Qt::Key_Right: |
|
134 off.setX(4); |
|
135 break; |
|
136 default: |
|
137 return QMainWindow::keyPressEvent(event); |
|
138 } |
|
139 off += QCursor::pos(); |
|
140 QCursor::setPos(off); |
|
141 } |