Changeset View
Changeset View
Standalone View
Standalone View
tools/kpTool_Utilities.cpp
Show First 20 Lines • Show All 50 Lines • ▼ Show 20 Line(s) | |||||
51 | //--------------------------------------------------------------------- | 51 | //--------------------------------------------------------------------- | ||
52 | 52 | | |||
53 | // static | 53 | // static | ||
54 | QRect kpTool::neededRect (const QRect &rect, int lineWidth) | 54 | QRect kpTool::neededRect (const QRect &rect, int lineWidth) | ||
55 | { | 55 | { | ||
56 | int x1, y1, x2, y2; | 56 | int x1, y1, x2, y2; | ||
57 | rect.getCoords (&x1, &y1, &x2, &y2); | 57 | rect.getCoords (&x1, &y1, &x2, &y2); | ||
58 | 58 | | |||
59 | if (lineWidth < 1) | 59 | if (lineWidth < 1) { | ||
60 | lineWidth = 1; | 60 | lineWidth = 1; | ||
61 | } | ||||
61 | 62 | | |||
62 | // TODO: why not divide by 2? | 63 | // TODO: why not divide by 2? | ||
63 | return QRect (QPoint (x1 - lineWidth + 1, y1 - lineWidth + 1), | 64 | return QRect (QPoint (x1 - lineWidth + 1, y1 - lineWidth + 1), | ||
64 | QPoint (x2 + lineWidth - 1, y2 + lineWidth - 1)); | 65 | QPoint (x2 + lineWidth - 1, y2 + lineWidth - 1)); | ||
65 | } | 66 | } | ||
66 | 67 | | |||
67 | //--------------------------------------------------------------------- | 68 | //--------------------------------------------------------------------- | ||
68 | 69 | | |||
Show All 33 Lines | 97 | { | |||
102 | } | 103 | } | ||
103 | } | 104 | } | ||
104 | 105 | | |||
105 | 106 | | |||
106 | const QPoint globalPos = QCursor::pos (); | 107 | const QPoint globalPos = QCursor::pos (); | ||
107 | const QPoint viewPos = v->mapFromGlobal (globalPos); | 108 | const QPoint viewPos = v->mapFromGlobal (globalPos); | ||
108 | qCDebug(kpLogTools) << "\tglobalPos=" << globalPos | 109 | qCDebug(kpLogTools) << "\tglobalPos=" << globalPos | ||
109 | << " viewPos=" << viewPos; | 110 | << " viewPos=" << viewPos; | ||
110 | if (!zoomToDoc) | 111 | if (!zoomToDoc) { | ||
111 | return viewPos; | 112 | return viewPos; | ||
113 | } | ||||
112 | 114 | | |||
113 | 115 | | |||
114 | const QPoint docPos = v->transformViewToDoc (viewPos); | 116 | const QPoint docPos = v->transformViewToDoc (viewPos); | ||
115 | qCDebug(kpLogTools) << "\tdocPos=" << docPos; | 117 | qCDebug(kpLogTools) << "\tdocPos=" << docPos; | ||
116 | return docPos; | 118 | return docPos; | ||
117 | } | 119 | } | ||
118 | 120 | | |||
119 | //--------------------------------------------------------------------- | 121 | //--------------------------------------------------------------------- | ||
Show All 39 Lines | 160 | { | |||
159 | hover (d->currentPoint); | 161 | hover (d->currentPoint); | ||
160 | } | 162 | } | ||
161 | } | 163 | } | ||
162 | 164 | | |||
163 | //--------------------------------------------------------------------- | 165 | //--------------------------------------------------------------------- | ||
164 | 166 | | |||
165 | bool kpTool::currentPointNextToLast () const | 167 | bool kpTool::currentPointNextToLast () const | ||
166 | { | 168 | { | ||
167 | if (d->lastPoint == QPoint (-1, -1)) | 169 | if (d->lastPoint == QPoint (-1, -1)) { | ||
168 | return true; | 170 | return true; | ||
171 | } | ||||
169 | 172 | | |||
170 | int dx = qAbs (d->currentPoint.x () - d->lastPoint.x ()); | 173 | int dx = qAbs (d->currentPoint.x () - d->lastPoint.x ()); | ||
171 | int dy = qAbs (d->currentPoint.y () - d->lastPoint.y ()); | 174 | int dy = qAbs (d->currentPoint.y () - d->lastPoint.y ()); | ||
172 | 175 | | |||
173 | return (dx <= 1 && dy <= 1); | 176 | return (dx <= 1 && dy <= 1); | ||
174 | } | 177 | } | ||
175 | 178 | | |||
176 | //--------------------------------------------------------------------- | 179 | //--------------------------------------------------------------------- | ||
177 | 180 | | |||
178 | bool kpTool::currentPointCardinallyNextToLast () const | 181 | bool kpTool::currentPointCardinallyNextToLast () const | ||
179 | { | 182 | { | ||
180 | if (d->lastPoint == QPoint (-1, -1)) | 183 | if (d->lastPoint == QPoint (-1, -1)) { | ||
181 | return true; | 184 | return true; | ||
185 | } | ||||
182 | 186 | | |||
183 | return (d->currentPoint == d->lastPoint || | 187 | return (d->currentPoint == d->lastPoint || | ||
184 | kpPainter::pointsAreCardinallyAdjacent (d->currentPoint, d->lastPoint)); | 188 | kpPainter::pointsAreCardinallyAdjacent (d->currentPoint, d->lastPoint)); | ||
185 | } | 189 | } | ||
186 | 190 | | |||
187 | //--------------------------------------------------------------------- | 191 | //--------------------------------------------------------------------- | ||
188 | 192 | | |||
189 | // static | 193 | // static | ||
190 | // TODO: we don't handle Qt::XButton1 and Qt::XButton2 at the moment. | 194 | // TODO: we don't handle Qt::XButton1 and Qt::XButton2 at the moment. | ||
191 | int kpTool::mouseButton (Qt::MouseButtons mouseButtons) | 195 | int kpTool::mouseButton (Qt::MouseButtons mouseButtons) | ||
192 | { | 196 | { | ||
193 | // we have nothing to do with mid-buttons | 197 | // we have nothing to do with mid-buttons | ||
194 | if (mouseButtons & Qt::MidButton) | 198 | if (mouseButtons & Qt::MidButton) { | ||
195 | return -1; | 199 | return -1; | ||
200 | } | ||||
196 | 201 | | |||
197 | // both left & right together is quite meaningless... | 202 | // both left & right together is quite meaningless... | ||
198 | const Qt::MouseButtons bothButtons = (Qt::LeftButton | Qt::RightButton); | 203 | const Qt::MouseButtons bothButtons = (Qt::LeftButton | Qt::RightButton); | ||
199 | if ((mouseButtons & bothButtons) == bothButtons) | 204 | if ((mouseButtons & bothButtons) == bothButtons) { | ||
200 | return -1; | 205 | return -1; | ||
206 | } | ||||
201 | 207 | | |||
202 | if (mouseButtons & Qt::LeftButton) | 208 | if (mouseButtons & Qt::LeftButton) { | ||
203 | return 0; | 209 | return 0; | ||
204 | else if (mouseButtons & Qt::RightButton) | 210 | } | ||
211 | if (mouseButtons & Qt::RightButton) { | ||||
205 | return 1; | 212 | return 1; | ||
206 | else | 213 | } | ||
214 | | ||||
207 | return -1; | 215 | return -1; | ||
208 | } | 216 | } | ||
209 | 217 | | |||
210 | //--------------------------------------------------------------------- | 218 | //--------------------------------------------------------------------- | ||
211 | 219 | | |||
212 | // public static | 220 | // public static | ||
213 | int kpTool::calculateLength (int start, int end) | 221 | int kpTool::calculateLength (int start, int end) | ||
214 | { | 222 | { | ||
215 | if (start <= end) | 223 | if (start <= end) | ||
216 | { | 224 | { | ||
217 | return end - start + 1; | 225 | return end - start + 1; | ||
218 | } | 226 | } | ||
219 | else | 227 | | ||
220 | { | | |||
221 | return end - start - 1; | 228 | return end - start - 1; | ||
222 | } | 229 | } | ||
223 | } | | |||
224 | 230 | | |||
225 | //--------------------------------------------------------------------- | 231 | //--------------------------------------------------------------------- | ||
226 | 232 | | |||
227 | // public static | 233 | // public static | ||
228 | bool kpTool::warnIfBigImageSize (int oldWidth, int oldHeight, | 234 | bool kpTool::warnIfBigImageSize (int oldWidth, int oldHeight, | ||
229 | int newWidth, int newHeight, | 235 | int newWidth, int newHeight, | ||
230 | const QString &text, | 236 | const QString &text, | ||
231 | const QString &caption, | 237 | const QString &caption, | ||
Show All 20 Lines | 257 | int accept = KMessageBox::warningContinueCancel (parent, | |||
252 | text, | 258 | text, | ||
253 | caption, | 259 | caption, | ||
254 | KGuiItem (continueButtonText), | 260 | KGuiItem (continueButtonText), | ||
255 | KStandardGuiItem::cancel(), | 261 | KStandardGuiItem::cancel(), | ||
256 | QLatin1String ("BigImageDontAskAgain")); | 262 | QLatin1String ("BigImageDontAskAgain")); | ||
257 | 263 | | |||
258 | return (accept == KMessageBox::Continue); | 264 | return (accept == KMessageBox::Continue); | ||
259 | } | 265 | } | ||
260 | else | 266 | | ||
261 | { | | |||
262 | return true; | 267 | return true; | ||
263 | } | 268 | } | ||
264 | } | | |||
265 | 269 | | |||
266 | //--------------------------------------------------------------------- | 270 | //--------------------------------------------------------------------- |