Changeset View
Changeset View
Standalone View
Standalone View
tools/kpTool_KeyboardEvents.cpp
Show First 20 Lines • Show All 91 Lines • ▼ Show 20 Line(s) | |||||
92 | // Returns in <dx> and <dy> the direction the arrow key "e->key()" is | 92 | // Returns in <dx> and <dy> the direction the arrow key "e->key()" is | ||
93 | // pointing in or (0,0) if it's not a recognised arrow key. | 93 | // pointing in or (0,0) if it's not a recognised arrow key. | ||
94 | void kpTool::arrowKeyPressDirection (const QKeyEvent *e, int *dx, int *dy) | 94 | void kpTool::arrowKeyPressDirection (const QKeyEvent *e, int *dx, int *dy) | ||
95 | { | 95 | { | ||
96 | int dxLocal = 0, dyLocal = 0; | 96 | int dxLocal = 0, dyLocal = 0; | ||
97 | 97 | | |||
98 | switch (e->key ()) | 98 | switch (e->key ()) | ||
99 | { | 99 | { | ||
100 | case Qt::Key_Home: dxLocal = -1, dyLocal = -1; break; | 100 | case Qt::Key_Home: dxLocal = -1; dyLocal = -1; break; | ||
101 | case Qt::Key_Up: dyLocal = -1; break; | 101 | case Qt::Key_Up: dyLocal = -1; break; | ||
102 | case Qt::Key_PageUp: dxLocal = +1, dyLocal = -1; break; | 102 | case Qt::Key_PageUp: dxLocal = +1; dyLocal = -1; break; | ||
103 | 103 | | |||
104 | case Qt::Key_Left: dxLocal = -1; break; | 104 | case Qt::Key_Left: dxLocal = -1; break; | ||
105 | case Qt::Key_Right: dxLocal = +1; break; | 105 | case Qt::Key_Right: dxLocal = +1; break; | ||
106 | 106 | | |||
107 | case Qt::Key_End: dxLocal = -1, dyLocal = +1; break; | 107 | case Qt::Key_End: dxLocal = -1; dyLocal = +1; break; | ||
108 | case Qt::Key_Down: dyLocal = +1; break; | 108 | case Qt::Key_Down: dyLocal = +1; break; | ||
109 | case Qt::Key_PageDown: dxLocal = +1, dyLocal = +1; break; | 109 | case Qt::Key_PageDown: dxLocal = +1; dyLocal = +1; break; | ||
110 | } | 110 | } | ||
tcanabrava: this is harder to read. | |||||
111 | 111 | | |||
112 | if (dx) | 112 | if (dx) | ||
113 | *dx = dxLocal; | 113 | *dx = dxLocal; | ||
114 | if (dy) | 114 | if (dy) | ||
115 | *dy = dyLocal; | 115 | *dy = dyLocal; | ||
116 | } | 116 | } | ||
117 | 117 | | |||
118 | //--------------------------------------------------------------------- | 118 | //--------------------------------------------------------------------- | ||
119 | 119 | | |||
120 | void kpTool::seeIfAndHandleArrowKeyPress (QKeyEvent *e) | 120 | void kpTool::seeIfAndHandleArrowKeyPress (QKeyEvent *e) | ||
121 | { | 121 | { | ||
122 | int dx, dy; | 122 | int dx, dy; | ||
123 | 123 | | |||
124 | arrowKeyPressDirection (e, &dx, &dy); | 124 | arrowKeyPressDirection (e, &dx, &dy); | ||
125 | if (dx == 0 && dy == 0) | 125 | if (dx == 0 && dy == 0) | ||
126 | return; | 126 | return; | ||
127 | 127 | | |||
mkoller: Please keep the "tabular" style as it was. It's more readable. | |||||
128 | 128 | | |||
129 | kpView * const view = viewUnderCursor (); | 129 | kpView * const view = viewUnderCursor (); | ||
130 | if (!view) | 130 | if (!view) | ||
131 | return; | 131 | return; | ||
132 | 132 | | |||
133 | 133 | | |||
134 | const QPoint oldPoint = view->mapFromGlobal (QCursor::pos ()); | 134 | const QPoint oldPoint = view->mapFromGlobal (QCursor::pos ()); | ||
135 | #if DEBUG_KP_TOOL && 0 | 135 | #if DEBUG_KP_TOOL && 0 | ||
Show All 14 Lines | |||||
150 | #endif | 150 | #endif | ||
151 | 151 | | |||
152 | // Make sure we really moved at least one doc point (needed due to | 152 | // Make sure we really moved at least one doc point (needed due to | ||
153 | // rounding error). | 153 | // rounding error). | ||
154 | 154 | | |||
155 | if (view->transformViewToDoc (QPoint (newViewX, newViewY)) == | 155 | if (view->transformViewToDoc (QPoint (newViewX, newViewY)) == | ||
156 | view->transformViewToDoc (oldPoint)) | 156 | view->transformViewToDoc (oldPoint)) | ||
157 | { | 157 | { | ||
158 | newViewX += viewIncX, newViewY += viewIncY; | 158 | newViewX += viewIncX; | ||
159 | newViewY += viewIncY; | ||||
159 | 160 | | |||
160 | #if DEBUG_KP_TOOL && 0 | 161 | #if DEBUG_KP_TOOL && 0 | ||
161 | qCDebug(kpLogTools) << "\tneed adjust for doc - newPoint=" | 162 | qCDebug(kpLogTools) << "\tneed adjust for doc - newPoint=" | ||
162 | << QPoint (newViewX, newViewY) << endl; | 163 | << QPoint (newViewX, newViewY) << endl; | ||
163 | #endif | 164 | #endif | ||
164 | } | 165 | } | ||
165 | 166 | | |||
166 | 167 | | |||
▲ Show 20 Lines • Show All 246 Lines • Show Last 20 Lines |
this is harder to read.