Changeset View
Changeset View
Standalone View
Standalone View
kpViewScrollableContainer.cpp
Show First 20 Lines • Show All 180 Lines • ▼ Show 20 Line(s) | |||||
181 | //--------------------------------------------------------------------- | 181 | //--------------------------------------------------------------------- | ||
182 | 182 | | |||
183 | // protected | 183 | // protected | ||
184 | void kpGrip::cancel () | 184 | void kpGrip::cancel () | ||
185 | { | 185 | { | ||
186 | #if DEBUG_KP_VIEW_SCROLLABLE_CONTAINER | 186 | #if DEBUG_KP_VIEW_SCROLLABLE_CONTAINER | ||
187 | qCDebug(kpLogMisc) << "kpGrip::cancel()"; | 187 | qCDebug(kpLogMisc) << "kpGrip::cancel()"; | ||
188 | #endif | 188 | #endif | ||
189 | if (m_currentPoint == KP_INVALID_POINT) | 189 | if (m_currentPoint == KP_INVALID_POINT) { | ||
190 | return; | 190 | return; | ||
191 | } | ||||
191 | 192 | | |||
192 | m_startPoint = KP_INVALID_POINT; | 193 | m_startPoint = KP_INVALID_POINT; | ||
193 | m_currentPoint = KP_INVALID_POINT; | 194 | m_currentPoint = KP_INVALID_POINT; | ||
194 | 195 | | |||
195 | setUserMessage (i18n ("Resize Image: Let go of all the mouse buttons.")); | 196 | setUserMessage (i18n ("Resize Image: Let go of all the mouse buttons.")); | ||
196 | setCursor (Qt::ArrowCursor); | 197 | setCursor (Qt::ArrowCursor); | ||
197 | m_shouldReleaseMouseButtons = true; | 198 | m_shouldReleaseMouseButtons = true; | ||
198 | 199 | | |||
Show All 26 Lines | 223 | { | |||
225 | emit beganDraw (); | 226 | emit beganDraw (); | ||
226 | grabKeyboard (); | 227 | grabKeyboard (); | ||
227 | 228 | | |||
228 | setUserMessage (i18n ("Resize Image: Right click to cancel.")); | 229 | setUserMessage (i18n ("Resize Image: Right click to cancel.")); | ||
229 | setCursor (cursorForType (m_type)); | 230 | setCursor (cursorForType (m_type)); | ||
230 | } | 231 | } | ||
231 | else | 232 | else | ||
232 | { | 233 | { | ||
233 | if (m_startPoint != KP_INVALID_POINT) | 234 | if (m_startPoint != KP_INVALID_POINT) { | ||
234 | cancel (); | 235 | cancel (); | ||
235 | } | 236 | } | ||
236 | } | 237 | } | ||
238 | } | ||||
237 | 239 | | |||
238 | //--------------------------------------------------------------------- | 240 | //--------------------------------------------------------------------- | ||
239 | 241 | | |||
240 | // public | 242 | // public | ||
241 | QPoint kpGrip::viewDeltaPoint () const | 243 | QPoint kpGrip::viewDeltaPoint () const | ||
242 | { | 244 | { | ||
243 | if (m_startPoint == KP_INVALID_POINT) | 245 | if (m_startPoint == KP_INVALID_POINT) { | ||
244 | return KP_INVALID_POINT; | 246 | return KP_INVALID_POINT; | ||
247 | } | ||||
245 | 248 | | |||
246 | const QPoint point = mapFromGlobal (QCursor::pos ()); | 249 | const QPoint point = mapFromGlobal (QCursor::pos ()); | ||
247 | 250 | | |||
248 | // TODO: this is getting out of sync with m_currentPoint | 251 | // TODO: this is getting out of sync with m_currentPoint | ||
249 | 252 | | |||
250 | return QPoint (((m_type & kpGrip::Right) ? point.x () - m_startPoint.x () : 0), | 253 | return {(m_type & kpGrip::Right) ? point.x () - m_startPoint.x () : 0, | ||
251 | ((m_type & kpGrip::Bottom) ? point.y () - m_startPoint.y () : 0)); | 254 | (m_type & kpGrip::Bottom) ? point.y () - m_startPoint.y () : 0}; | ||
252 | 255 | | |||
253 | } | 256 | } | ||
254 | 257 | | |||
255 | //--------------------------------------------------------------------- | 258 | //--------------------------------------------------------------------- | ||
256 | 259 | | |||
257 | // public | 260 | // public | ||
258 | void kpGrip::mouseMovedTo (const QPoint &point, bool dueToDragScroll) | 261 | void kpGrip::mouseMovedTo (const QPoint &point, bool dueToDragScroll) | ||
259 | { | 262 | { | ||
260 | if (m_startPoint == KP_INVALID_POINT) | 263 | if (m_startPoint == KP_INVALID_POINT) { | ||
261 | return; | 264 | return; | ||
265 | } | ||||
262 | 266 | | |||
263 | m_currentPoint = point; | 267 | m_currentPoint = point; | ||
264 | 268 | | |||
265 | emit continuedDraw (((m_type & kpGrip::Right) ? point.x () - m_startPoint.x () : 0), | 269 | emit continuedDraw (((m_type & kpGrip::Right) ? point.x () - m_startPoint.x () : 0), | ||
266 | ((m_type & kpGrip::Bottom) ? point.y () - m_startPoint.y () : 0), | 270 | ((m_type & kpGrip::Bottom) ? point.y () - m_startPoint.y () : 0), | ||
267 | dueToDragScroll); | 271 | dueToDragScroll); | ||
268 | } | 272 | } | ||
269 | 273 | | |||
270 | //--------------------------------------------------------------------- | 274 | //--------------------------------------------------------------------- | ||
271 | 275 | | |||
272 | // protected virtual [base QWidget] | 276 | // protected virtual [base QWidget] | ||
273 | void kpGrip::mouseMoveEvent (QMouseEvent *e) | 277 | void kpGrip::mouseMoveEvent (QMouseEvent *e) | ||
274 | { | 278 | { | ||
275 | #if DEBUG_KP_VIEW_SCROLLABLE_CONTAINER | 279 | #if DEBUG_KP_VIEW_SCROLLABLE_CONTAINER | ||
276 | qCDebug(kpLogMisc) << "kpGrip::mouseMoveEvent() m_startPoint=" << m_startPoint | 280 | qCDebug(kpLogMisc) << "kpGrip::mouseMoveEvent() m_startPoint=" << m_startPoint | ||
277 | << " stateAfter: buttons=" << (int *) (int) e->buttons () | 281 | << " stateAfter: buttons=" << (int *) (int) e->buttons (); | ||
278 | << endl; | | |||
279 | #endif | 282 | #endif | ||
280 | 283 | | |||
281 | if (m_startPoint == KP_INVALID_POINT) | 284 | if (m_startPoint == KP_INVALID_POINT) | ||
282 | { | 285 | { | ||
283 | if ((e->buttons () & Qt::MouseButtonMask) == 0) | 286 | if ((e->buttons () & Qt::MouseButtonMask) == 0) { | ||
284 | setUserMessage (haventBegunDrawUserMessage ()); | 287 | setUserMessage (haventBegunDrawUserMessage ()); | ||
288 | } | ||||
285 | return; | 289 | return; | ||
286 | } | 290 | } | ||
287 | 291 | | |||
288 | mouseMovedTo (e->pos (), false/*not due to drag scroll*/); | 292 | mouseMovedTo (e->pos (), false/*not due to drag scroll*/); | ||
289 | } | 293 | } | ||
290 | 294 | | |||
291 | //--------------------------------------------------------------------- | 295 | //--------------------------------------------------------------------- | ||
292 | 296 | | |||
293 | // protected virtual [base QWidget] | 297 | // protected virtual [base QWidget] | ||
294 | void kpGrip::mouseReleaseEvent (QMouseEvent *e) | 298 | void kpGrip::mouseReleaseEvent (QMouseEvent *e) | ||
295 | { | 299 | { | ||
296 | #if DEBUG_KP_VIEW_SCROLLABLE_CONTAINER | 300 | #if DEBUG_KP_VIEW_SCROLLABLE_CONTAINER | ||
297 | qCDebug(kpLogMisc) << "kpGrip::mouseReleaseEvent() m_startPoint=" << m_startPoint | 301 | qCDebug(kpLogMisc) << "kpGrip::mouseReleaseEvent() m_startPoint=" << m_startPoint | ||
298 | << " stateAfter: buttons=" << (int *) (int) e->buttons () | 302 | << " stateAfter: buttons=" << (int *) (int) e->buttons (); | ||
299 | << endl; | | |||
300 | #endif | 303 | #endif | ||
301 | 304 | | |||
302 | if (m_startPoint != KP_INVALID_POINT) | 305 | if (m_startPoint != KP_INVALID_POINT) | ||
303 | { | 306 | { | ||
304 | const int dx = m_currentPoint.x () - m_startPoint.x (), | 307 | const int dx = m_currentPoint.x () - m_startPoint.x (), | ||
305 | dy = m_currentPoint.y () - m_startPoint.y (); | 308 | dy = m_currentPoint.y () - m_startPoint.y (); | ||
306 | 309 | | |||
307 | m_currentPoint = KP_INVALID_POINT; | 310 | m_currentPoint = KP_INVALID_POINT; | ||
Show All 19 Lines | |||||
327 | 330 | | |||
328 | // protected virtual [base QWidget] | 331 | // protected virtual [base QWidget] | ||
329 | void kpGrip::enterEvent (QEvent * /*e*/) | 332 | void kpGrip::enterEvent (QEvent * /*e*/) | ||
330 | { | 333 | { | ||
331 | #if DEBUG_KP_VIEW_SCROLLABLE_CONTAINER | 334 | #if DEBUG_KP_VIEW_SCROLLABLE_CONTAINER | ||
332 | qCDebug(kpLogMisc) << "kpGrip::enterEvent()" | 335 | qCDebug(kpLogMisc) << "kpGrip::enterEvent()" | ||
333 | << " m_startPoint=" << m_startPoint | 336 | << " m_startPoint=" << m_startPoint | ||
334 | << " shouldReleaseMouseButtons=" | 337 | << " shouldReleaseMouseButtons=" | ||
335 | << m_shouldReleaseMouseButtons << endl; | 338 | << m_shouldReleaseMouseButtons; | ||
336 | #endif | 339 | #endif | ||
337 | 340 | | |||
338 | if (m_startPoint == KP_INVALID_POINT && | 341 | if (m_startPoint == KP_INVALID_POINT && | ||
339 | !m_shouldReleaseMouseButtons) | 342 | !m_shouldReleaseMouseButtons) | ||
340 | { | 343 | { | ||
341 | #if DEBUG_KP_VIEW_SCROLLABLE_CONTAINER | 344 | #if DEBUG_KP_VIEW_SCROLLABLE_CONTAINER | ||
342 | qCDebug(kpLogMisc) << "\tsending message"; | 345 | qCDebug(kpLogMisc) << "\tsending message"; | ||
343 | #endif | 346 | #endif | ||
344 | setUserMessage (haventBegunDrawUserMessage ()); | 347 | setUserMessage (haventBegunDrawUserMessage ()); | ||
345 | } | 348 | } | ||
346 | } | 349 | } | ||
347 | 350 | | |||
348 | //--------------------------------------------------------------------- | 351 | //--------------------------------------------------------------------- | ||
349 | 352 | | |||
350 | // protected virtual [base QWidget] | 353 | // protected virtual [base QWidget] | ||
351 | void kpGrip::leaveEvent (QEvent * /*e*/) | 354 | void kpGrip::leaveEvent (QEvent * /*e*/) | ||
352 | { | 355 | { | ||
353 | #if DEBUG_KP_VIEW_SCROLLABLE_CONTAINER | 356 | #if DEBUG_KP_VIEW_SCROLLABLE_CONTAINER | ||
354 | qCDebug(kpLogMisc) << "kpGrip::leaveEvent()" | 357 | qCDebug(kpLogMisc) << "kpGrip::leaveEvent()" | ||
355 | << " m_startPoint=" << m_startPoint | 358 | << " m_startPoint=" << m_startPoint | ||
356 | << " shouldReleaseMouseButtons=" | 359 | << " shouldReleaseMouseButtons=" | ||
357 | << m_shouldReleaseMouseButtons << endl; | 360 | << m_shouldReleaseMouseButtons; | ||
358 | #endif | 361 | #endif | ||
359 | if (m_startPoint == KP_INVALID_POINT && | 362 | if (m_startPoint == KP_INVALID_POINT && | ||
360 | !m_shouldReleaseMouseButtons) | 363 | !m_shouldReleaseMouseButtons) | ||
361 | { | 364 | { | ||
362 | setUserMessage(QString()); | 365 | setUserMessage(QString()); | ||
363 | } | 366 | } | ||
364 | } | 367 | } | ||
365 | 368 | | |||
▲ Show 20 Lines • Show All 108 Lines • ▼ Show 20 Line(s) | 474 | #endif | |||
474 | m_rightGrip->setUserMessage(QString()); | 477 | m_rightGrip->setUserMessage(QString()); | ||
475 | } | 478 | } | ||
476 | 479 | | |||
477 | //--------------------------------------------------------------------- | 480 | //--------------------------------------------------------------------- | ||
478 | 481 | | |||
479 | // protected | 482 | // protected | ||
480 | QSize kpViewScrollableContainer::newDocSize (int viewDX, int viewDY) const | 483 | QSize kpViewScrollableContainer::newDocSize (int viewDX, int viewDY) const | ||
481 | { | 484 | { | ||
482 | if (!m_view) | 485 | if (!m_view) { | ||
483 | return QSize (); | 486 | return {}; | ||
487 | } | ||||
484 | 488 | | |||
485 | if (!docResizingGrip ()) | 489 | if (!docResizingGrip ()) { | ||
486 | return QSize (); | 490 | return {}; | ||
491 | } | ||||
487 | 492 | | |||
488 | const int docX = static_cast<int> (m_view->transformViewToDocX (m_view->width () + viewDX)); | 493 | const int docX = static_cast<int> (m_view->transformViewToDocX (m_view->width () + viewDX)); | ||
489 | const int docY = static_cast<int> (m_view->transformViewToDocY (m_view->height () + viewDY)); | 494 | const int docY = static_cast<int> (m_view->transformViewToDocY (m_view->height () + viewDY)); | ||
490 | 495 | | |||
491 | return QSize (qMax (1, docX), qMax (1, docY)); | 496 | return {qMax (1, docX), qMax (1, docY)}; | ||
492 | } | 497 | } | ||
493 | 498 | | |||
494 | //--------------------------------------------------------------------- | 499 | //--------------------------------------------------------------------- | ||
495 | 500 | | |||
496 | // protected | 501 | // protected | ||
497 | void kpViewScrollableContainer::calculateDocResizingGrip () | 502 | void kpViewScrollableContainer::calculateDocResizingGrip () | ||
498 | { | 503 | { | ||
499 | if (m_bottomRightGrip->isDrawing ()) | 504 | if (m_bottomRightGrip->isDrawing ()) { | ||
500 | m_docResizingGrip = m_bottomRightGrip; | 505 | m_docResizingGrip = m_bottomRightGrip; | ||
501 | else if (m_bottomGrip->isDrawing ()) | 506 | } | ||
507 | else if (m_bottomGrip->isDrawing ()) { | ||||
502 | m_docResizingGrip = m_bottomGrip; | 508 | m_docResizingGrip = m_bottomGrip; | ||
503 | else if (m_rightGrip->isDrawing ()) | 509 | } | ||
510 | else if (m_rightGrip->isDrawing ()) { | ||||
504 | m_docResizingGrip = m_rightGrip; | 511 | m_docResizingGrip = m_rightGrip; | ||
505 | else | 512 | } | ||
513 | else { | ||||
506 | m_docResizingGrip = nullptr; | 514 | m_docResizingGrip = nullptr; | ||
507 | } | 515 | } | ||
516 | } | ||||
508 | 517 | | |||
509 | //--------------------------------------------------------------------- | 518 | //--------------------------------------------------------------------- | ||
510 | 519 | | |||
511 | // protected | 520 | // protected | ||
512 | kpGrip *kpViewScrollableContainer::docResizingGrip () const | 521 | kpGrip *kpViewScrollableContainer::docResizingGrip () const | ||
513 | { | 522 | { | ||
514 | return m_docResizingGrip; | 523 | return m_docResizingGrip; | ||
515 | } | 524 | } | ||
516 | 525 | | |||
517 | //--------------------------------------------------------------------- | 526 | //--------------------------------------------------------------------- | ||
518 | 527 | | |||
519 | // protected | 528 | // protected | ||
520 | int kpViewScrollableContainer::bottomResizeLineWidth () const | 529 | int kpViewScrollableContainer::bottomResizeLineWidth () const | ||
521 | { | 530 | { | ||
522 | if (!docResizingGrip ()) | 531 | if (!docResizingGrip ()) { | ||
523 | return -1; | 532 | return -1; | ||
533 | } | ||||
524 | 534 | | |||
525 | if (!m_view) | 535 | if (!m_view) { | ||
526 | return -1; | 536 | return -1; | ||
537 | } | ||||
527 | 538 | | |||
528 | if (docResizingGrip ()->type () & kpGrip::Bottom) | 539 | if (docResizingGrip ()->type () & kpGrip::Bottom) { | ||
529 | return qMax (m_view->zoomLevelY () / 100, 1); | 540 | return qMax (m_view->zoomLevelY () / 100, 1); | ||
530 | else | 541 | } | ||
542 | | ||||
531 | return 1; | 543 | return 1; | ||
532 | } | 544 | } | ||
533 | 545 | | |||
534 | //--------------------------------------------------------------------- | 546 | //--------------------------------------------------------------------- | ||
535 | 547 | | |||
536 | // protected | 548 | // protected | ||
537 | int kpViewScrollableContainer::rightResizeLineWidth () const | 549 | int kpViewScrollableContainer::rightResizeLineWidth () const | ||
538 | { | 550 | { | ||
539 | if (!docResizingGrip ()) | 551 | if (!docResizingGrip ()) { | ||
540 | return -1; | 552 | return -1; | ||
553 | } | ||||
541 | 554 | | |||
542 | if (!m_view) | 555 | if (!m_view) { | ||
543 | return -1; | 556 | return -1; | ||
557 | } | ||||
544 | 558 | | |||
545 | if (docResizingGrip ()->type () & kpGrip::Right) | 559 | if (docResizingGrip ()->type () & kpGrip::Right) { | ||
546 | return qMax (m_view->zoomLevelX () / 100, 1); | 560 | return qMax (m_view->zoomLevelX () / 100, 1); | ||
547 | else | 561 | } | ||
562 | | ||||
548 | return 1; | 563 | return 1; | ||
549 | } | 564 | } | ||
550 | 565 | | |||
551 | //--------------------------------------------------------------------- | 566 | //--------------------------------------------------------------------- | ||
552 | 567 | | |||
553 | // protected | 568 | // protected | ||
554 | QRect kpViewScrollableContainer::bottomResizeLineRect () const | 569 | QRect kpViewScrollableContainer::bottomResizeLineRect () const | ||
555 | { | 570 | { | ||
556 | if (m_resizeRoundedLastViewX < 0 || m_resizeRoundedLastViewY < 0) | 571 | if (m_resizeRoundedLastViewX < 0 || m_resizeRoundedLastViewY < 0) { | ||
557 | return QRect (); | 572 | return {}; | ||
573 | } | ||||
558 | 574 | | |||
559 | QRect visibleArea = QRect(QPoint(horizontalScrollBar()->value(),verticalScrollBar()->value()), viewport()->size()); | 575 | QRect visibleArea = QRect(QPoint(horizontalScrollBar()->value(),verticalScrollBar()->value()), viewport()->size()); | ||
560 | 576 | | |||
561 | return QRect (QPoint (0, | 577 | return QRect (QPoint (0, | ||
562 | m_resizeRoundedLastViewY), | 578 | m_resizeRoundedLastViewY), | ||
563 | QPoint (m_resizeRoundedLastViewX - 1, | 579 | QPoint (m_resizeRoundedLastViewX - 1, | ||
564 | m_resizeRoundedLastViewY + bottomResizeLineWidth () - 1)).intersected(visibleArea); | 580 | m_resizeRoundedLastViewY + bottomResizeLineWidth () - 1)).intersected(visibleArea); | ||
565 | } | 581 | } | ||
566 | 582 | | |||
567 | //--------------------------------------------------------------------- | 583 | //--------------------------------------------------------------------- | ||
568 | 584 | | |||
569 | // protected | 585 | // protected | ||
570 | QRect kpViewScrollableContainer::rightResizeLineRect () const | 586 | QRect kpViewScrollableContainer::rightResizeLineRect () const | ||
571 | { | 587 | { | ||
572 | if (m_resizeRoundedLastViewX < 0 || m_resizeRoundedLastViewY < 0) | 588 | if (m_resizeRoundedLastViewX < 0 || m_resizeRoundedLastViewY < 0) { | ||
573 | return QRect (); | 589 | return {}; | ||
590 | } | ||||
574 | 591 | | |||
575 | QRect visibleArea = QRect(QPoint(horizontalScrollBar()->value(),verticalScrollBar()->value()), viewport()->size()); | 592 | QRect visibleArea = QRect(QPoint(horizontalScrollBar()->value(),verticalScrollBar()->value()), viewport()->size()); | ||
576 | 593 | | |||
577 | return QRect (QPoint (m_resizeRoundedLastViewX, | 594 | return QRect (QPoint (m_resizeRoundedLastViewX, | ||
578 | 0), | 595 | 0), | ||
579 | QPoint (m_resizeRoundedLastViewX + rightResizeLineWidth () - 1, | 596 | QPoint (m_resizeRoundedLastViewX + rightResizeLineWidth () - 1, | ||
580 | m_resizeRoundedLastViewY - 1)).intersected(visibleArea); | 597 | m_resizeRoundedLastViewY - 1)).intersected(visibleArea); | ||
581 | } | 598 | } | ||
582 | 599 | | |||
583 | //--------------------------------------------------------------------- | 600 | //--------------------------------------------------------------------- | ||
584 | 601 | | |||
585 | // protected | 602 | // protected | ||
586 | QRect kpViewScrollableContainer::bottomRightResizeLineRect () const | 603 | QRect kpViewScrollableContainer::bottomRightResizeLineRect () const | ||
587 | { | 604 | { | ||
588 | if (m_resizeRoundedLastViewX < 0 || m_resizeRoundedLastViewY < 0) | 605 | if (m_resizeRoundedLastViewX < 0 || m_resizeRoundedLastViewY < 0) { | ||
589 | return QRect (); | 606 | return {}; | ||
607 | } | ||||
590 | 608 | | |||
591 | QRect visibleArea = QRect(QPoint(horizontalScrollBar()->value(),verticalScrollBar()->value()), viewport()->size()); | 609 | QRect visibleArea = QRect(QPoint(horizontalScrollBar()->value(),verticalScrollBar()->value()), viewport()->size()); | ||
592 | 610 | | |||
593 | return QRect (QPoint (m_resizeRoundedLastViewX, | 611 | return QRect (QPoint (m_resizeRoundedLastViewX, | ||
594 | m_resizeRoundedLastViewY), | 612 | m_resizeRoundedLastViewY), | ||
595 | QPoint (m_resizeRoundedLastViewX + rightResizeLineWidth () - 1, | 613 | QPoint (m_resizeRoundedLastViewX + rightResizeLineWidth () - 1, | ||
596 | m_resizeRoundedLastViewY + bottomResizeLineWidth () - 1)).intersected(visibleArea); | 614 | m_resizeRoundedLastViewY + bottomResizeLineWidth () - 1)).intersected(visibleArea); | ||
597 | } | 615 | } | ||
598 | 616 | | |||
599 | //--------------------------------------------------------------------- | 617 | //--------------------------------------------------------------------- | ||
600 | 618 | | |||
601 | // private | 619 | // private | ||
602 | QRect kpViewScrollableContainer::mapViewToViewport (const QRect &viewRect) | 620 | QRect kpViewScrollableContainer::mapViewToViewport (const QRect &viewRect) | ||
603 | { | 621 | { | ||
604 | if (!viewRect.isValid ()) | 622 | if (!viewRect.isValid ()) { | ||
605 | return QRect (); | 623 | return {}; | ||
624 | } | ||||
606 | 625 | | |||
607 | QRect ret = viewRect; | 626 | QRect ret = viewRect; | ||
608 | ret.translate (-horizontalScrollBar()->value() - viewport()->x(), -verticalScrollBar()->value() - viewport()->y()); | 627 | ret.translate (-horizontalScrollBar()->value() - viewport()->x(), -verticalScrollBar()->value() - viewport()->y()); | ||
609 | return ret; | 628 | return ret; | ||
610 | } | 629 | } | ||
611 | 630 | | |||
612 | //--------------------------------------------------------------------- | 631 | //--------------------------------------------------------------------- | ||
613 | 632 | | |||
▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Line(s) | 681 | void kpViewScrollableContainer::updateResizeLines (int viewX, int viewY, | |||
663 | int viewDX, int viewDY) | 682 | int viewDX, int viewDY) | ||
664 | { | 683 | { | ||
665 | #if DEBUG_KP_VIEW_SCROLLABLE_CONTAINER && 0 | 684 | #if DEBUG_KP_VIEW_SCROLLABLE_CONTAINER && 0 | ||
666 | qCDebug(kpLogMisc) << "kpViewScrollableContainer::updateResizeLines(" | 685 | qCDebug(kpLogMisc) << "kpViewScrollableContainer::updateResizeLines(" | ||
667 | << viewX << "," << viewY << ")" | 686 | << viewX << "," << viewY << ")" | ||
668 | << " oldViewX=" << m_resizeRoundedLastViewX | 687 | << " oldViewX=" << m_resizeRoundedLastViewX | ||
669 | << " oldViewY=" << m_resizeRoundedLastViewY | 688 | << " oldViewY=" << m_resizeRoundedLastViewY | ||
670 | << " viewDX=" << viewDX | 689 | << " viewDX=" << viewDX | ||
671 | << " viewDY=" << viewDY | 690 | << " viewDY=" << viewDY; | ||
672 | << endl; | | |||
673 | #endif | 691 | #endif | ||
674 | 692 | | |||
675 | 693 | | |||
676 | if (viewX >= 0 && viewY >= 0) | 694 | if (viewX >= 0 && viewY >= 0) | ||
677 | { | 695 | { | ||
678 | m_resizeRoundedLastViewX = | 696 | m_resizeRoundedLastViewX = | ||
679 | static_cast<int> (m_view->transformDocToViewX (m_view->transformViewToDocX (viewX))); | 697 | static_cast<int> (m_view->transformDocToViewX (m_view->transformViewToDocX (viewX))); | ||
680 | 698 | | |||
Show All 15 Lines | |||||
696 | m_overlay->update(); | 714 | m_overlay->update(); | ||
697 | } | 715 | } | ||
698 | 716 | | |||
699 | //--------------------------------------------------------------------- | 717 | //--------------------------------------------------------------------- | ||
700 | 718 | | |||
701 | // protected slot | 719 | // protected slot | ||
702 | void kpViewScrollableContainer::slotGripBeganDraw () | 720 | void kpViewScrollableContainer::slotGripBeganDraw () | ||
703 | { | 721 | { | ||
704 | if (!m_view) | 722 | if (!m_view) { | ||
705 | return; | 723 | return; | ||
724 | } | ||||
706 | 725 | | |||
707 | m_overlay->resize(viewport()->size()); // make it cover whole viewport | 726 | m_overlay->resize(viewport()->size()); // make it cover whole viewport | ||
708 | m_overlay->move(viewport()->pos()); | 727 | m_overlay->move(viewport()->pos()); | ||
709 | m_overlay->show(); | 728 | m_overlay->show(); | ||
710 | m_overlay->raise(); // make it top-most | 729 | m_overlay->raise(); // make it top-most | ||
711 | 730 | | |||
712 | calculateDocResizingGrip (); | 731 | calculateDocResizingGrip (); | ||
713 | 732 | | |||
Show All 13 Lines | |||||
727 | { | 746 | { | ||
728 | int viewDX = inViewDX, | 747 | int viewDX = inViewDX, | ||
729 | viewDY = inViewDY; | 748 | viewDY = inViewDY; | ||
730 | 749 | | |||
731 | #if DEBUG_KP_VIEW_SCROLLABLE_CONTAINER | 750 | #if DEBUG_KP_VIEW_SCROLLABLE_CONTAINER | ||
732 | qCDebug(kpLogMisc) << "kpViewScrollableContainer::slotGripContinuedDraw(" | 751 | qCDebug(kpLogMisc) << "kpViewScrollableContainer::slotGripContinuedDraw(" | ||
733 | << viewDX << "," << viewDY << ") size=" | 752 | << viewDX << "," << viewDY << ") size=" | ||
734 | << newDocSize (viewDX, viewDY) | 753 | << newDocSize (viewDX, viewDY) | ||
735 | << " dueToDragScroll=" << dueToDragScroll | 754 | << " dueToDragScroll=" << dueToDragScroll; | ||
736 | << endl; | | |||
737 | #endif | 755 | #endif | ||
738 | 756 | | |||
739 | if (!m_view) | 757 | if (!m_view) { | ||
740 | return; | 758 | return; | ||
759 | } | ||||
741 | 760 | | |||
742 | if (!dueToDragScroll && | 761 | if (!dueToDragScroll && | ||
743 | beginDragScroll(m_view->zoomLevelX ())) | 762 | beginDragScroll(m_view->zoomLevelX ())) | ||
744 | { | 763 | { | ||
745 | const QPoint newViewDeltaPoint = docResizingGrip ()->viewDeltaPoint (); | 764 | const QPoint newViewDeltaPoint = docResizingGrip ()->viewDeltaPoint (); | ||
746 | viewDX = newViewDeltaPoint.x (); | 765 | viewDX = newViewDeltaPoint.x (); | ||
747 | viewDY = newViewDeltaPoint.y (); | 766 | viewDY = newViewDeltaPoint.y (); | ||
748 | #if DEBUG_KP_VIEW_SCROLLABLE_CONTAINER | 767 | #if DEBUG_KP_VIEW_SCROLLABLE_CONTAINER | ||
749 | qCDebug(kpLogMisc) << "\tdrag scrolled - new view delta point=" | 768 | qCDebug(kpLogMisc) << "\tdrag scrolled - new view delta point=" | ||
750 | << newViewDeltaPoint | 769 | << newViewDeltaPoint; | ||
751 | << endl; | | |||
752 | #endif | 770 | #endif | ||
753 | } | 771 | } | ||
754 | 772 | | |||
755 | m_haveMovedFromOriginalDocSize = true; | 773 | m_haveMovedFromOriginalDocSize = true; | ||
756 | 774 | | |||
757 | updateResizeLines (qMax (1, qMax (m_view->width () + viewDX, static_cast<int> (m_view->transformDocToViewX (1)))), | 775 | updateResizeLines (qMax (1, qMax (m_view->width () + viewDX, static_cast<int> (m_view->transformDocToViewX (1)))), | ||
758 | qMax (1, qMax (m_view->height () + viewDY, static_cast<int> (m_view->transformDocToViewY (1)))), | 776 | qMax (1, qMax (m_view->height () + viewDY, static_cast<int> (m_view->transformDocToViewY (1)))), | ||
759 | viewDX, viewDY); | 777 | viewDX, viewDY); | ||
Show All 22 Lines | |||||
782 | //--------------------------------------------------------------------- | 800 | //--------------------------------------------------------------------- | ||
783 | 801 | | |||
784 | // protected slot | 802 | // protected slot | ||
785 | void kpViewScrollableContainer::slotGripEndedDraw (int viewDX, int viewDY) | 803 | void kpViewScrollableContainer::slotGripEndedDraw (int viewDX, int viewDY) | ||
786 | { | 804 | { | ||
787 | #if DEBUG_KP_VIEW_SCROLLABLE_CONTAINER | 805 | #if DEBUG_KP_VIEW_SCROLLABLE_CONTAINER | ||
788 | qCDebug(kpLogMisc) << "kpViewScrollableContainer::slotGripEndedDraw(" | 806 | qCDebug(kpLogMisc) << "kpViewScrollableContainer::slotGripEndedDraw(" | ||
789 | << viewDX << "," << viewDY << ") size=" | 807 | << viewDX << "," << viewDY << ") size=" | ||
790 | << newDocSize (viewDX, viewDY) | 808 | << newDocSize (viewDX, viewDY); | ||
791 | << endl; | | |||
792 | #endif | 809 | #endif | ||
793 | 810 | | |||
794 | if (!m_view) | 811 | if (!m_view) { | ||
795 | return; | 812 | return; | ||
813 | } | ||||
796 | 814 | | |||
797 | const QSize newSize = newDocSize (viewDX, viewDY); | 815 | const QSize newSize = newDocSize (viewDX, viewDY); | ||
798 | 816 | | |||
799 | m_haveMovedFromOriginalDocSize = false; | 817 | m_haveMovedFromOriginalDocSize = false; | ||
800 | 818 | | |||
801 | // must erase lines before view size changes | 819 | // must erase lines before view size changes | ||
802 | updateResizeLines (-1, -1, 0, 0); | 820 | updateResizeLines (-1, -1, 0, 0); | ||
803 | 821 | | |||
804 | calculateDocResizingGrip (); | 822 | calculateDocResizingGrip (); | ||
805 | 823 | | |||
806 | emit endedDocResize (newSize); | 824 | emit endedDocResize (newSize); | ||
807 | 825 | | |||
808 | endDragScroll (); | 826 | endDragScroll (); | ||
809 | 827 | | |||
810 | m_overlay->hide(); | 828 | m_overlay->hide(); | ||
811 | } | 829 | } | ||
812 | 830 | | |||
813 | //--------------------------------------------------------------------- | 831 | //--------------------------------------------------------------------- | ||
814 | 832 | | |||
815 | // protected slot | 833 | // protected slot | ||
816 | void kpViewScrollableContainer::slotGripStatusMessageChanged (const QString &string) | 834 | void kpViewScrollableContainer::slotGripStatusMessageChanged (const QString &string) | ||
817 | { | 835 | { | ||
818 | if (string == m_gripStatusMessage) | 836 | if (string == m_gripStatusMessage) { | ||
819 | return; | 837 | return; | ||
838 | } | ||||
820 | 839 | | |||
821 | m_gripStatusMessage = string; | 840 | m_gripStatusMessage = string; | ||
822 | emit statusMessageChanged (string); | 841 | emit statusMessageChanged (string); | ||
823 | } | 842 | } | ||
824 | 843 | | |||
825 | //--------------------------------------------------------------------- | 844 | //--------------------------------------------------------------------- | ||
826 | 845 | | |||
827 | // public slot | 846 | // public slot | ||
828 | void kpViewScrollableContainer::recalculateStatusMessage () | 847 | void kpViewScrollableContainer::recalculateStatusMessage () | ||
829 | { | 848 | { | ||
830 | #if DEBUG_KP_VIEW_SCROLLABLE_CONTAINER | 849 | #if DEBUG_KP_VIEW_SCROLLABLE_CONTAINER | ||
831 | qCDebug(kpLogMisc) << "kpViewScrollabelContainer::recalculateStatusMessage()"; | 850 | qCDebug(kpLogMisc) << "kpViewScrollabelContainer::recalculateStatusMessage()"; | ||
832 | qCDebug(kpLogMisc) << "\tQCursor::pos=" << QCursor::pos () | 851 | qCDebug(kpLogMisc) << "\tQCursor::pos=" << QCursor::pos () | ||
833 | << " global visibleRect=" | 852 | << " global visibleRect=" | ||
834 | << kpWidgetMapper::toGlobal (this, | 853 | << kpWidgetMapper::toGlobal (this, | ||
835 | QRect(0, 0, viewport->width(), viewport->height())) | 854 | QRect(0, 0, viewport->width(), viewport->height())); | ||
836 | << endl; | | |||
837 | #endif | 855 | #endif | ||
838 | 856 | | |||
839 | // HACK: After dragging to a new size, handles move so that they are now | 857 | // HACK: After dragging to a new size, handles move so that they are now | ||
840 | // under the mouse pointer but no mouseMoveEvent() is generated for | 858 | // under the mouse pointer but no mouseMoveEvent() is generated for | ||
841 | // any grip. This also handles the case of canceling over any | 859 | // any grip. This also handles the case of canceling over any | ||
842 | // grip. | 860 | // grip. | ||
843 | // | 861 | // | ||
844 | if (kpWidgetMapper::toGlobal (this, | 862 | if (kpWidgetMapper::toGlobal (this, | ||
▲ Show 20 Lines • Show All 75 Lines • ▼ Show 20 Line(s) | 937 | { | |||
920 | return m_view; | 938 | return m_view; | ||
921 | } | 939 | } | ||
922 | 940 | | |||
923 | //--------------------------------------------------------------------- | 941 | //--------------------------------------------------------------------- | ||
924 | 942 | | |||
925 | // public | 943 | // public | ||
926 | void kpViewScrollableContainer::setView (kpView *view) | 944 | void kpViewScrollableContainer::setView (kpView *view) | ||
927 | { | 945 | { | ||
928 | if (m_view == view) | 946 | if (m_view == view) { | ||
929 | return; | 947 | return; | ||
948 | } | ||||
930 | 949 | | |||
931 | if (m_view) | 950 | if (m_view) | ||
932 | { | 951 | { | ||
933 | disconnectViewSignals (); | 952 | disconnectViewSignals (); | ||
934 | } | 953 | } | ||
935 | 954 | | |||
936 | m_view = view; | 955 | m_view = view; | ||
937 | 956 | | |||
▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Line(s) | 1002 | { | |||
985 | updateGrips (); | 1004 | updateGrips (); | ||
986 | } | 1005 | } | ||
987 | 1006 | | |||
988 | //--------------------------------------------------------------------- | 1007 | //--------------------------------------------------------------------- | ||
989 | 1008 | | |||
990 | // public slot | 1009 | // public slot | ||
991 | bool kpViewScrollableContainer::beginDragScroll(int zoomLevel, bool *didSomething) | 1010 | bool kpViewScrollableContainer::beginDragScroll(int zoomLevel, bool *didSomething) | ||
992 | { | 1011 | { | ||
993 | if (didSomething) | 1012 | if (didSomething) { | ||
994 | *didSomething = false; | 1013 | *didSomething = false; | ||
1014 | } | ||||
995 | 1015 | | |||
996 | m_zoomLevel = zoomLevel; | 1016 | m_zoomLevel = zoomLevel; | ||
997 | 1017 | | |||
998 | const QPoint p = mapFromGlobal (QCursor::pos ()); | 1018 | const QPoint p = mapFromGlobal (QCursor::pos ()); | ||
999 | 1019 | | |||
1000 | bool stopDragScroll = true; | 1020 | bool stopDragScroll = true; | ||
1001 | bool scrolled = false; | 1021 | bool scrolled = false; | ||
1002 | 1022 | | |||
Show All 10 Lines | 1024 | { | |||
1013 | { | 1033 | { | ||
1014 | m_scrollTimerRunOnce = false; | 1034 | m_scrollTimerRunOnce = false; | ||
1015 | m_dragScrollTimer->start (DragScrollInitialInterval); | 1035 | m_dragScrollTimer->start (DragScrollInitialInterval); | ||
1016 | } | 1036 | } | ||
1017 | 1037 | | |||
1018 | stopDragScroll = false; | 1038 | stopDragScroll = false; | ||
1019 | } | 1039 | } | ||
1020 | 1040 | | |||
1021 | if (stopDragScroll) | 1041 | if (stopDragScroll) { | ||
1022 | m_dragScrollTimer->stop (); | 1042 | m_dragScrollTimer->stop (); | ||
1043 | } | ||||
1023 | 1044 | | |||
1024 | if (didSomething) | 1045 | if (didSomething) { | ||
1025 | *didSomething = scrolled; | 1046 | *didSomething = scrolled; | ||
1047 | } | ||||
1026 | 1048 | | |||
1027 | return scrolled; | 1049 | return scrolled; | ||
1028 | } | 1050 | } | ||
1029 | 1051 | | |||
1030 | //--------------------------------------------------------------------- | 1052 | //--------------------------------------------------------------------- | ||
1031 | 1053 | | |||
1032 | // public slot | 1054 | // public slot | ||
1033 | bool kpViewScrollableContainer::beginDragScroll(int zoomLevel) | 1055 | bool kpViewScrollableContainer::beginDragScroll(int zoomLevel) | ||
1034 | { | 1056 | { | ||
1035 | return beginDragScroll(zoomLevel, | 1057 | return beginDragScroll(zoomLevel, | ||
1036 | nullptr/*don't want scrolled notification*/); | 1058 | nullptr/*don't want scrolled notification*/); | ||
1037 | } | 1059 | } | ||
1038 | 1060 | | |||
1039 | //--------------------------------------------------------------------- | 1061 | //--------------------------------------------------------------------- | ||
1040 | 1062 | | |||
1041 | // public slot | 1063 | // public slot | ||
1042 | bool kpViewScrollableContainer::endDragScroll () | 1064 | bool kpViewScrollableContainer::endDragScroll () | ||
1043 | { | 1065 | { | ||
1044 | if (m_dragScrollTimer->isActive ()) | 1066 | if (m_dragScrollTimer->isActive ()) | ||
1045 | { | 1067 | { | ||
1046 | m_dragScrollTimer->stop (); | 1068 | m_dragScrollTimer->stop (); | ||
1047 | return true; | 1069 | return true; | ||
1048 | } | 1070 | } | ||
1049 | else | 1071 | | ||
1050 | { | | |||
1051 | return false; | 1072 | return false; | ||
1052 | } | 1073 | } | ||
1053 | } | | |||
1054 | 1074 | | |||
1055 | //--------------------------------------------------------------------- | 1075 | //--------------------------------------------------------------------- | ||
1056 | 1076 | | |||
1057 | static int distanceFromRectToMultiplier (int dist) | 1077 | static int distanceFromRectToMultiplier (int dist) | ||
1058 | { | 1078 | { | ||
1059 | if (dist < 0) | 1079 | if (dist < 0) { | ||
1060 | return 0; | 1080 | return 0; | ||
1061 | else if (dist < DragDistanceFromRectMaxFor1stMultiplier) | 1081 | } | ||
1082 | | ||||
1083 | if (dist < DragDistanceFromRectMaxFor1stMultiplier) { | ||||
1062 | return 1; | 1084 | return 1; | ||
1063 | else if (dist < DragDistanceFromRectMaxFor2ndMultiplier) | 1085 | } | ||
1086 | | ||||
1087 | if (dist < DragDistanceFromRectMaxFor2ndMultiplier) { | ||||
1064 | return 2; | 1088 | return 2; | ||
1065 | else | 1089 | } | ||
1090 | | ||||
1066 | return 4; | 1091 | return 4; | ||
1067 | } | 1092 | } | ||
1068 | 1093 | | |||
1069 | //--------------------------------------------------------------------- | 1094 | //--------------------------------------------------------------------- | ||
1070 | 1095 | | |||
1071 | // protected slot | 1096 | // protected slot | ||
1072 | bool kpViewScrollableContainer::slotDragScroll (bool *didSomething) | 1097 | bool kpViewScrollableContainer::slotDragScroll (bool *didSomething) | ||
1073 | { | 1098 | { | ||
1074 | bool scrolled = false; | 1099 | bool scrolled = false; | ||
1075 | 1100 | | |||
1076 | if (didSomething) | 1101 | if (didSomething) { | ||
1077 | *didSomething = false; | 1102 | *didSomething = false; | ||
1103 | } | ||||
1078 | 1104 | | |||
1079 | 1105 | | |||
1080 | const QRect rect = noDragScrollRect (); | 1106 | const QRect rect = noDragScrollRect (); | ||
1081 | const QPoint pos = mapFromGlobal (QCursor::pos ()); | 1107 | const QPoint pos = mapFromGlobal (QCursor::pos ()); | ||
1082 | 1108 | | |||
1083 | int dx = 0, dy = 0; | 1109 | int dx = 0, dy = 0; | ||
1084 | int dxMultiplier = 0, dyMultiplier = 0; | 1110 | int dxMultiplier = 0, dyMultiplier = 0; | ||
1085 | 1111 | | |||
▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Line(s) | 1149 | { | |||
1130 | // of scrollView. | 1156 | // of scrollView. | ||
1131 | m_view->repaint (region); | 1157 | m_view->repaint (region); | ||
1132 | } | 1158 | } | ||
1133 | } | 1159 | } | ||
1134 | 1160 | | |||
1135 | m_dragScrollTimer->start (DragScrollInterval); | 1161 | m_dragScrollTimer->start (DragScrollInterval); | ||
1136 | m_scrollTimerRunOnce = true; | 1162 | m_scrollTimerRunOnce = true; | ||
1137 | 1163 | | |||
1138 | if (didSomething) | 1164 | if (didSomething) { | ||
1139 | *didSomething = scrolled; | 1165 | *didSomething = scrolled; | ||
1166 | } | ||||
1140 | 1167 | | |||
1141 | return scrolled; | 1168 | return scrolled; | ||
1142 | } | 1169 | } | ||
1143 | 1170 | | |||
1144 | 1171 | | |||
1145 | //--------------------------------------------------------------------- | 1172 | //--------------------------------------------------------------------- | ||
1146 | 1173 | | |||
1147 | // protected virtual | 1174 | // protected virtual | ||
1148 | void kpViewScrollableContainer::wheelEvent (QWheelEvent *e) | 1175 | void kpViewScrollableContainer::wheelEvent (QWheelEvent *e) | ||
1149 | { | 1176 | { | ||
1150 | e->ignore (); | 1177 | e->ignore (); | ||
1151 | 1178 | | |||
1152 | if (m_view) | 1179 | if (m_view) { | ||
1153 | m_view->wheelEvent (e); | 1180 | m_view->wheelEvent (e); | ||
1181 | } | ||||
1154 | 1182 | | |||
1155 | if ( !e->isAccepted() ) | 1183 | if ( !e->isAccepted() ) { | ||
1156 | QScrollArea::wheelEvent(e); | 1184 | QScrollArea::wheelEvent(e); | ||
1157 | } | 1185 | } | ||
1186 | } | ||||
1158 | 1187 | | |||
1159 | //--------------------------------------------------------------------------------- | 1188 | //--------------------------------------------------------------------------------- | ||
1160 | 1189 | | |||
1161 | QRect kpViewScrollableContainer::noDragScrollRect () const | 1190 | QRect kpViewScrollableContainer::noDragScrollRect () const | ||
1162 | { | 1191 | { | ||
1163 | return QRect (DragScrollLeftTopMargin, DragScrollLeftTopMargin, | 1192 | return {DragScrollLeftTopMargin, DragScrollLeftTopMargin, | ||
1164 | width () - DragScrollLeftTopMargin - DragScrollRightBottomMargin, | 1193 | width () - DragScrollLeftTopMargin - DragScrollRightBottomMargin, | ||
1165 | height () - DragScrollLeftTopMargin - DragScrollRightBottomMargin); | 1194 | height () - DragScrollLeftTopMargin - DragScrollRightBottomMargin}; | ||
1166 | } | 1195 | } | ||
1167 | 1196 | | |||
1168 | //--------------------------------------------------------------------- | 1197 | //--------------------------------------------------------------------- | ||
1169 | 1198 | | |||
1170 | // protected virtual [base QScrollView] | 1199 | // protected virtual [base QScrollView] | ||
1171 | void kpViewScrollableContainer::resizeEvent (QResizeEvent *e) | 1200 | void kpViewScrollableContainer::resizeEvent (QResizeEvent *e) | ||
1172 | { | 1201 | { | ||
1173 | QScrollArea::resizeEvent (e); | 1202 | QScrollArea::resizeEvent (e); | ||
1174 | 1203 | | |||
1175 | emit resized (); | 1204 | emit resized (); | ||
1176 | } | 1205 | } | ||
1177 | 1206 | | |||
1178 | //--------------------------------------------------------------------- | 1207 | //--------------------------------------------------------------------- | ||
1179 | 1208 | |