Changeset View
Changeset View
Standalone View
Standalone View
ui/pageviewutils.cpp
1 | /*************************************************************************** | 1 | /*************************************************************************** | ||
---|---|---|---|---|---|
2 | * Copyright (C) 2004-2005 by Enrico Ros <eros.kde@email.it> * | 2 | * Copyright (C) 2004-2005 by Enrico Ros <eros.kde@email.it> * | ||
3 | * Copyright (C) 2017 Klarälvdalens Datakonsult AB, a KDAB Group * | 3 | * Copyright (C) 2017 Klarälvdalens Datakonsult AB, a KDAB Group * | ||
4 | * company, info@kdab.com. Work sponsored by the * | 4 | * company, info@kdab.com. Work sponsored by the * | ||
5 | * LiMux project of the city of Munich * | 5 | * LiMux project of the city of Munich * | ||
6 | * * | 6 | * * | ||
7 | * This program is free software; you can redistribute it and/or modify * | 7 | * This program is free software; you can redistribute it and/or modify * | ||
8 | * it under the terms of the GNU General Public License as published by * | 8 | * it under the terms of the GNU General Public License as published by * | ||
9 | * the Free Software Foundation; either version 2 of the License, or * | 9 | * the Free Software Foundation; either version 2 of the License, or * | ||
10 | * (at your option) any later version. * | 10 | * (at your option) any later version. * | ||
11 | ***************************************************************************/ | 11 | ***************************************************************************/ | ||
12 | 12 | | |||
13 | #include "pageviewutils.h" | 13 | #include "pageviewutils.h" | ||
14 | 14 | | |||
15 | // qt/kde includes | 15 | // qt/kde includes | ||
16 | #include <qapplication.h> | 16 | #include <qapplication.h> | ||
17 | #include <qbitmap.h> | 17 | #include <qmenu.h> | ||
18 | #include <qbrush.h> | | |||
19 | #include <qimage.h> | | |||
20 | #include <qlabel.h> | | |||
21 | #include <qlayout.h> | | |||
22 | #include <qpainter.h> | 18 | #include <qpainter.h> | ||
23 | #include <qevent.h> | | |||
24 | #include <qstyle.h> | | |||
25 | #include <qtimer.h> | 19 | #include <qtimer.h> | ||
26 | #include <qtoolbutton.h> | | |||
27 | #include <kacceleratormanager.h> | | |||
28 | #include <kactioncollection.h> | | |||
29 | #include <kcolorscheme.h> | | |||
30 | #include <kiconloader.h> | 20 | #include <kiconloader.h> | ||
31 | #include <KLocalizedString> | | |||
32 | | ||||
33 | // system includes | | |||
34 | #include <math.h> | | |||
35 | 21 | | |||
36 | // local includes | 22 | // local includes | ||
37 | #include "formwidgets.h" | 23 | #include "formwidgets.h" | ||
38 | #include "pageview.h" | | |||
39 | #include "videowidget.h" | 24 | #include "videowidget.h" | ||
40 | #include "core/movie.h" | | |||
41 | #include "core/page.h" | 25 | #include "core/page.h" | ||
42 | #include "core/form.h" | 26 | #include "core/form.h" | ||
43 | #include "settings.h" | 27 | #include "settings.h" | ||
44 | 28 | | |||
45 | /*********************/ | 29 | /*********************/ | ||
46 | /** PageViewItem */ | 30 | /** PageViewItem */ | ||
47 | /*********************/ | 31 | /*********************/ | ||
48 | 32 | | |||
▲ Show 20 Lines • Show All 375 Lines • ▼ Show 20 Line(s) | |||||
424 | 408 | | |||
425 | void PageViewMessage::mousePressEvent( QMouseEvent * /*e*/ ) | 409 | void PageViewMessage::mousePressEvent( QMouseEvent * /*e*/ ) | ||
426 | { | 410 | { | ||
427 | if ( m_timer ) | 411 | if ( m_timer ) | ||
428 | m_timer->stop(); | 412 | m_timer->stop(); | ||
429 | hide(); | 413 | hide(); | ||
430 | } | 414 | } | ||
431 | 415 | | |||
432 | | ||||
433 | /*********************/ | | |||
434 | /** PageViewToolBar */ | | |||
435 | /*********************/ | | |||
436 | | ||||
437 | ToolBarButton::ToolBarButton( QWidget * parent, const AnnotationToolItem &item ) | | |||
438 | : QToolButton( parent ), m_id( item.id ), m_isText( item.isText ) | | |||
439 | { | | |||
440 | setCheckable( true ); | | |||
441 | setAutoRaise( true ); | | |||
442 | resize( buttonSize, buttonSize ); | | |||
443 | setIconSize( QSize( iconSize, iconSize ) ); | | |||
444 | setIcon( QIcon( item.pixmap ) ); | | |||
445 | // set shortcut if defined | | |||
446 | if ( !item.shortcut.isEmpty() ) | | |||
447 | setShortcut( QKeySequence( item.shortcut ) ); | | |||
448 | else | | |||
449 | KAcceleratorManager::setNoAccel( this ); | | |||
450 | | ||||
451 | // if accel is set display it along name | | |||
452 | QString accelString = shortcut().toString( QKeySequence::NativeText ); | | |||
453 | if ( !accelString.isEmpty() ) | | |||
454 | setToolTip( QStringLiteral("%1 [%2]").arg( item.text, accelString ) ); | | |||
455 | else | | |||
456 | setToolTip( item.text ); | | |||
457 | } | | |||
458 | | ||||
459 | void ToolBarButton::mouseDoubleClickEvent( QMouseEvent * /*event*/ ) | | |||
460 | { | | |||
461 | emit buttonDoubleClicked( buttonID() ); | | |||
462 | } | | |||
463 | | ||||
464 | /* PageViewToolBar */ | | |||
465 | | ||||
466 | static const int toolBarGridSize = 40; | | |||
467 | | ||||
468 | class ToolBarPrivate | | |||
469 | { | | |||
470 | public: | | |||
471 | ToolBarPrivate( PageViewToolBar * qq ) | | |||
472 | : q( qq ) | | |||
473 | { | | |||
474 | } | | |||
475 | | ||||
476 | // rebuild contents and reposition then widget | | |||
477 | void buildToolBar(); | | |||
478 | void reposition(); | | |||
479 | // compute the visible and hidden positions along current side | | |||
480 | QPoint getInnerPoint() const; | | |||
481 | QPoint getOuterPoint() const; | | |||
482 | void selectButton( ToolBarButton * button ); | | |||
483 | | ||||
484 | PageViewToolBar * q; | | |||
485 | | ||||
486 | // anchored widget and side | | |||
487 | QWidget * anchorWidget; | | |||
488 | PageViewToolBar::Side anchorSide; | | |||
489 | | ||||
490 | // slide in/out stuff | | |||
491 | QTimer * animTimer; | | |||
492 | QPoint currentPosition; | | |||
493 | QPoint endPosition; | | |||
494 | bool hiding; | | |||
495 | bool visible; | | |||
496 | | ||||
497 | // background pixmap and buttons | | |||
498 | QPixmap backgroundPixmap; | | |||
499 | QLinkedList< ToolBarButton * > buttons; | | |||
500 | }; | | |||
501 | | ||||
502 | PageViewToolBar::PageViewToolBar( PageView * parent, QWidget * anchorWidget ) | | |||
503 | : QWidget( parent ), d( new ToolBarPrivate( this ) ) | | |||
504 | { | | |||
505 | // initialize values of the private data storage structure | | |||
506 | d->anchorWidget = anchorWidget; | | |||
507 | d->anchorSide = Left; | | |||
508 | d->hiding = false; | | |||
509 | d->visible = false; | | |||
510 | | ||||
511 | // create the animation timer | | |||
512 | d->animTimer = new QTimer( this ); | | |||
513 | connect( d->animTimer, &QTimer::timeout, this, &PageViewToolBar::slotAnimate ); | | |||
514 | | ||||
515 | // apply a filter to get notified when anchor changes geometry | | |||
516 | d->anchorWidget->installEventFilter( this ); | | |||
517 | | ||||
518 | setContextMenuPolicy( Qt::ActionsContextMenu ); | | |||
519 | addAction( parent->actionCollection()->action( QStringLiteral("options_configure_annotations") ) ); | | |||
520 | } | | |||
521 | | ||||
522 | PageViewToolBar::~PageViewToolBar() | | |||
523 | { | | |||
524 | // delete the private data storage structure | | |||
525 | delete d; | | |||
526 | } | | |||
527 | | ||||
528 | void PageViewToolBar::setItems( const QLinkedList<AnnotationToolItem> &items ) | | |||
529 | { | | |||
530 | // delete buttons if already present | | |||
531 | if ( !d->buttons.isEmpty() ) | | |||
532 | { | | |||
533 | QLinkedList< ToolBarButton * >::iterator it = d->buttons.begin(), end = d->buttons.end(); | | |||
534 | for ( ; it != end; ++it ) | | |||
535 | delete *it; | | |||
536 | d->buttons.clear(); | | |||
537 | } | | |||
538 | | ||||
539 | // create new buttons for given items | | |||
540 | QLinkedList<AnnotationToolItem>::const_iterator it = items.begin(), end = items.end(); | | |||
541 | for ( ; it != end; ++it ) | | |||
542 | { | | |||
543 | ToolBarButton * button = new ToolBarButton( this, *it ); | | |||
544 | connect(button, &ToolBarButton::clicked, this, &PageViewToolBar::slotButtonClicked); | | |||
545 | connect(button, &ToolBarButton::buttonDoubleClicked, this, &PageViewToolBar::buttonDoubleClicked); | | |||
546 | d->buttons.append( button ); | | |||
547 | } | | |||
548 | | ||||
549 | // rebuild toolbar shape and contents | | |||
550 | d->reposition(); | | |||
551 | } | | |||
552 | | ||||
553 | void PageViewToolBar::setSide( Side side ) | | |||
554 | { | | |||
555 | d->anchorSide = side; | | |||
556 | | ||||
557 | d->reposition(); | | |||
558 | } | | |||
559 | | ||||
560 | void PageViewToolBar::showAndAnimate() | | |||
561 | { | | |||
562 | // set parameters for sliding in | | |||
563 | d->hiding = false; | | |||
564 | | ||||
565 | show(); | | |||
566 | | ||||
567 | #ifdef OKULAR_ANIMATE_REVIEW_TOOBAR | | |||
568 | // start scrolling in | | |||
569 | d->animTimer->start( 20 ); | | |||
570 | #else | | |||
571 | d->currentPosition = d->endPosition; | | |||
572 | | ||||
573 | move( d->currentPosition ); | | |||
574 | | ||||
575 | d->visible = true; | | |||
576 | #endif | | |||
577 | } | | |||
578 | | ||||
579 | void PageViewToolBar::hideAndDestroy() | | |||
580 | { | | |||
581 | // set parameters for sliding out | | |||
582 | d->hiding = true; | | |||
583 | d->endPosition = d->getOuterPoint(); | | |||
584 | | ||||
585 | #ifdef OKULAR_ANIMATE_REVIEW_TOOBAR | | |||
586 | // start scrolling out | | |||
587 | d->animTimer->start( 20 ); | | |||
588 | #else | | |||
589 | d->currentPosition = d->endPosition; | | |||
590 | | ||||
591 | move( d->currentPosition ); | | |||
592 | | ||||
593 | d->visible = false; | | |||
594 | deleteLater(); | | |||
595 | #endif | | |||
596 | } | | |||
597 | | ||||
598 | void PageViewToolBar::selectButton( int id ) | | |||
599 | { | | |||
600 | ToolBarButton * button = nullptr; | | |||
601 | if ( id >= 0 && id < d->buttons.count() ) | | |||
602 | button = *(d->buttons.begin() + id); | | |||
603 | else | | |||
604 | { | | |||
605 | QLinkedList< ToolBarButton * >::const_iterator it = d->buttons.begin(), end = d->buttons.end(); | | |||
606 | for ( ; !button && it != end; ++it ) | | |||
607 | if ( (*it)->isChecked() ) | | |||
608 | button = *it; | | |||
609 | if ( button ) | | |||
610 | button->setChecked( false ); | | |||
611 | } | | |||
612 | d->selectButton( button ); | | |||
613 | } | | |||
614 | | ||||
615 | bool PageViewToolBar::eventFilter( QObject * obj, QEvent * e ) | | |||
616 | { | | |||
617 | // if anchorWidget changed geometry reposition toolbar | | |||
618 | if ( obj == d->anchorWidget && e->type() == QEvent::Resize ) | | |||
619 | { | | |||
620 | d->animTimer->stop(); | | |||
621 | if ( d->hiding ) | | |||
622 | deleteLater(); | | |||
623 | else | | |||
624 | d->reposition(); | | |||
625 | } | | |||
626 | | ||||
627 | // don't block event | | |||
628 | return false; | | |||
629 | } | | |||
630 | | ||||
631 | void PageViewToolBar::paintEvent( QPaintEvent * e ) | | |||
632 | { | | |||
633 | // paint the internal pixmap over the widget | | |||
634 | QPainter p( this ); | | |||
635 | p.drawImage( e->rect().topLeft(), d->backgroundPixmap.toImage(), e->rect() ); | | |||
636 | } | | |||
637 | | ||||
638 | void PageViewToolBar::mousePressEvent( QMouseEvent * e ) | | |||
639 | { | | |||
640 | // set 'dragging' cursor | | |||
641 | if ( e->button() == Qt::LeftButton ) | | |||
642 | setCursor( Qt::SizeAllCursor ); | | |||
643 | } | | |||
644 | | ||||
645 | void PageViewToolBar::mouseMoveEvent( QMouseEvent * e ) | | |||
646 | { | | |||
647 | if ( ( QApplication::mouseButtons() & Qt::LeftButton ) != Qt::LeftButton ) | | |||
648 | return; | | |||
649 | | ||||
650 | // compute the nearest side to attach the widget to | | |||
651 | QPoint parentPos = mapToParent( e->pos() ); | | |||
652 | float nX = (float)parentPos.x() / (float)d->anchorWidget->width(), | | |||
653 | nY = (float)parentPos.y() / (float)d->anchorWidget->height(); | | |||
654 | if ( nX > 0.3 && nX < 0.7 && nY > 0.3 && nY < 0.7 ) | | |||
655 | return; | | |||
656 | bool LT = nX < (1.0 - nY); | | |||
657 | bool LB = nX < (nY); | | |||
658 | Side side = LT ? ( LB ? Left : Top ) : ( LB ? Bottom : Right ); | | |||
659 | | ||||
660 | // check if side changed | | |||
661 | if ( side == d->anchorSide ) | | |||
662 | return; | | |||
663 | | ||||
664 | d->anchorSide = side; | | |||
665 | d->reposition(); | | |||
666 | emit orientationChanged( (int)side ); | | |||
667 | } | | |||
668 | | ||||
669 | void PageViewToolBar::mouseReleaseEvent( QMouseEvent * e ) | | |||
670 | { | | |||
671 | // set normal cursor | | |||
672 | if ( e->button() == Qt::LeftButton ) | | |||
673 | setCursor( Qt::ArrowCursor ); | | |||
674 | } | | |||
675 | | ||||
676 | void ToolBarPrivate::buildToolBar() | | |||
677 | { | | |||
678 | int buttonsNumber = buttons.count(), | | |||
679 | parentWidth = anchorWidget->width(), | | |||
680 | parentHeight = anchorWidget->height(), | | |||
681 | myCols = 1, | | |||
682 | myRows = 1; | | |||
683 | | ||||
684 | // 1. find out columns and rows we're going to use | | |||
685 | bool topLeft = anchorSide == PageViewToolBar::Left || anchorSide == PageViewToolBar::Top; | | |||
686 | bool vertical = anchorSide == PageViewToolBar::Left || anchorSide == PageViewToolBar::Right; | | |||
687 | if ( vertical ) | | |||
688 | { | | |||
689 | myCols = 1 + (buttonsNumber * toolBarGridSize) / | | |||
690 | (parentHeight - toolBarGridSize); | | |||
691 | myRows = (int)ceil( (float)buttonsNumber / (float)myCols ); | | |||
692 | } | | |||
693 | else | | |||
694 | { | | |||
695 | myRows = 1 + (buttonsNumber * toolBarGridSize) / | | |||
696 | (parentWidth - toolBarGridSize); | | |||
697 | myCols = (int)ceil( (float)buttonsNumber / (float)myRows ); | | |||
698 | } | | |||
699 | | ||||
700 | // 2. compute widget size (from rows/cols) | | |||
701 | int myWidth = myCols * toolBarGridSize, | | |||
702 | myHeight = myRows * toolBarGridSize, | | |||
703 | xOffset = (toolBarGridSize - ToolBarButton::buttonSize) / 2, | | |||
704 | yOffset = (toolBarGridSize - ToolBarButton::buttonSize) / 2; | | |||
705 | | ||||
706 | if ( vertical ) | | |||
707 | { | | |||
708 | myHeight += 16; | | |||
709 | myWidth += 4; | | |||
710 | yOffset += 12; | | |||
711 | if ( anchorSide == PageViewToolBar::Right ) | | |||
712 | xOffset += 4; | | |||
713 | } | | |||
714 | else | | |||
715 | { | | |||
716 | myWidth += 16; | | |||
717 | myHeight += 4; | | |||
718 | xOffset += 12; | | |||
719 | if ( anchorSide == PageViewToolBar::Bottom ) | | |||
720 | yOffset += 4; | | |||
721 | } | | |||
722 | | ||||
723 | bool prevUpdates = q->updatesEnabled(); | | |||
724 | q->setUpdatesEnabled( false ); | | |||
725 | | ||||
726 | // 3. resize pixmap, mask and widget | | |||
727 | QBitmap mask( myWidth + 1, myHeight + 1 ); | | |||
728 | backgroundPixmap = QPixmap( myWidth + 1, myHeight + 1 ); | | |||
729 | backgroundPixmap.fill(Qt::transparent); | | |||
730 | q->resize( myWidth + 1, myHeight + 1 ); | | |||
731 | | ||||
732 | // 4. create and set transparency mask // 4. draw background | | |||
733 | QPainter maskPainter( &mask); | | |||
734 | mask.fill( Qt::white ); | | |||
735 | maskPainter.setBrush( Qt::black ); | | |||
736 | if ( vertical ) | | |||
737 | maskPainter.drawRoundRect( topLeft ? -10 : 0, 0, myWidth + 11, myHeight, 2000 / (myWidth + 10), 2000 / myHeight ); | | |||
738 | else | | |||
739 | maskPainter.drawRoundRect( 0, topLeft ? -10 : 0, myWidth, myHeight + 11, 2000 / myWidth, 2000 / (myHeight + 10) ); | | |||
740 | maskPainter.end(); | | |||
741 | q->setMask( mask ); | | |||
742 | | ||||
743 | // 5. draw background | | |||
744 | QPainter bufferPainter( &backgroundPixmap ); | | |||
745 | bufferPainter.translate( 0.5, 0.5 ); | | |||
746 | QPalette pal = q->palette(); | | |||
747 | // 5.1. draw horizontal/vertical gradient | | |||
748 | QLinearGradient grad; | | |||
749 | switch ( anchorSide ) | | |||
750 | { | | |||
751 | case PageViewToolBar::Left: | | |||
752 | grad = QLinearGradient( 0, 1, myWidth + 1, 1 ); | | |||
753 | break; | | |||
754 | case PageViewToolBar::Right: | | |||
755 | grad = QLinearGradient( myWidth + 1, 1, 0, 1 ); | | |||
756 | break; | | |||
757 | case PageViewToolBar::Top: | | |||
758 | grad = QLinearGradient( 1, 0, 1, myHeight + 1 ); | | |||
759 | break; | | |||
760 | case PageViewToolBar::Bottom: | | |||
761 | grad = QLinearGradient( 1, myHeight + 1, 0, 1 ); | | |||
762 | break; | | |||
763 | } | | |||
764 | grad.setColorAt( 0, pal.color( QPalette::Active, QPalette::Button ) ); | | |||
765 | grad.setColorAt( 1, pal.color( QPalette::Active, QPalette::Light ) ); | | |||
766 | bufferPainter.setBrush( QBrush( grad ) ); | | |||
767 | // 5.2. draw rounded border | | |||
768 | bufferPainter.setPen( pal.color( QPalette::Active, QPalette::Dark ).lighter( 140 ) ); | | |||
769 | bufferPainter.setRenderHints( QPainter::Antialiasing ); | | |||
770 | if ( vertical ) | | |||
771 | bufferPainter.drawRoundRect( topLeft ? -10 : 0, 0, myWidth + 10, myHeight, 2000 / (myWidth + 10), 2000 / myHeight ); | | |||
772 | else | | |||
773 | bufferPainter.drawRoundRect( 0, topLeft ? -10 : 0, myWidth, myHeight + 10, 2000 / myWidth, 2000 / (myHeight + 10) ); | | |||
774 | // 5.3. draw handle | | |||
775 | bufferPainter.translate( -0.5, -0.5 ); | | |||
776 | bufferPainter.setPen( pal.color( QPalette::Active, QPalette::Mid ) ); | | |||
777 | if ( vertical ) | | |||
778 | { | | |||
779 | int dx = anchorSide == PageViewToolBar::Left ? 2 : 4; | | |||
780 | bufferPainter.drawLine( dx, 6, dx + myWidth - 8, 6 ); | | |||
781 | bufferPainter.drawLine( dx, 9, dx + myWidth - 8, 9 ); | | |||
782 | bufferPainter.setPen( pal.color( QPalette::Active, QPalette::Light ) ); | | |||
783 | bufferPainter.drawLine( dx + 1, 7, dx + myWidth - 7, 7 ); | | |||
784 | bufferPainter.drawLine( dx + 1, 10, dx + myWidth - 7, 10 ); | | |||
785 | } | | |||
786 | else | | |||
787 | { | | |||
788 | int dy = anchorSide == PageViewToolBar::Top ? 2 : 4; | | |||
789 | bufferPainter.drawLine( 6, dy, 6, dy + myHeight - 8 ); | | |||
790 | bufferPainter.drawLine( 9, dy, 9, dy + myHeight - 8 ); | | |||
791 | bufferPainter.setPen( pal.color( QPalette::Active, QPalette::Light ) ); | | |||
792 | bufferPainter.drawLine( 7, dy + 1, 7, dy + myHeight - 7 ); | | |||
793 | bufferPainter.drawLine( 10, dy + 1, 10, dy + myHeight - 7 ); | | |||
794 | } | | |||
795 | bufferPainter.end(); | | |||
796 | | ||||
797 | // 6. reposition buttons (in rows/col grid) | | |||
798 | int gridX = 0, | | |||
799 | gridY = 0; | | |||
800 | QLinkedList< ToolBarButton * >::const_iterator it = buttons.begin(), end = buttons.end(); | | |||
801 | for ( ; it != end; ++it ) | | |||
802 | { | | |||
803 | ToolBarButton * button = *it; | | |||
804 | button->move( gridX * toolBarGridSize + xOffset, | | |||
805 | gridY * toolBarGridSize + yOffset ); | | |||
806 | button->show(); | | |||
807 | if ( ++gridX == myCols ) | | |||
808 | { | | |||
809 | gridX = 0; | | |||
810 | gridY++; | | |||
811 | } | | |||
812 | } | | |||
813 | | ||||
814 | q->setUpdatesEnabled( prevUpdates ); | | |||
815 | } | | |||
816 | | ||||
817 | void ToolBarPrivate::reposition() | | |||
818 | { | | |||
819 | // note: hiding widget here will gives better gfx, but ends drag operation | | |||
820 | // rebuild widget and move it to its final place | | |||
821 | buildToolBar(); | | |||
822 | if ( !visible ) | | |||
823 | { | | |||
824 | currentPosition = getOuterPoint(); | | |||
825 | endPosition = getInnerPoint(); | | |||
826 | } | | |||
827 | else | | |||
828 | { | | |||
829 | currentPosition = getInnerPoint(); | | |||
830 | endPosition = getOuterPoint(); | | |||
831 | } | | |||
832 | q->move( currentPosition ); | | |||
833 | | ||||
834 | // repaint all buttons (to update background) | | |||
835 | QLinkedList< ToolBarButton * >::const_iterator it = buttons.begin(), end = buttons.end(); | | |||
836 | for ( ; it != end; ++it ) | | |||
837 | (*it)->update(); | | |||
838 | } | | |||
839 | | ||||
840 | QPoint ToolBarPrivate::getInnerPoint() const | | |||
841 | { | | |||
842 | // returns the final position of the widget | | |||
843 | QPoint newPos; | | |||
844 | switch ( anchorSide ) | | |||
845 | { | | |||
846 | case PageViewToolBar::Left: | | |||
847 | newPos = QPoint( 0, ( anchorWidget->height() - q->height() ) / 2 ); | | |||
848 | break; | | |||
849 | case PageViewToolBar::Top: | | |||
850 | newPos = QPoint( ( anchorWidget->width() - q->width() ) / 2, 0 ); | | |||
851 | break; | | |||
852 | case PageViewToolBar::Right: | | |||
853 | newPos = QPoint( anchorWidget->width() - q->width(), ( anchorWidget->height() - q->height() ) / 2 ); | | |||
854 | break; | | |||
855 | case PageViewToolBar::Bottom: | | |||
856 | newPos = QPoint( ( anchorWidget->width() - q->width()) / 2, anchorWidget->height() - q->height() ); | | |||
857 | break; | | |||
858 | } | | |||
859 | return newPos + anchorWidget->pos(); | | |||
860 | } | | |||
861 | | ||||
862 | QPoint ToolBarPrivate::getOuterPoint() const | | |||
863 | { | | |||
864 | // returns the point from which the transition starts | | |||
865 | QPoint newPos; | | |||
866 | switch ( anchorSide ) | | |||
867 | { | | |||
868 | case PageViewToolBar::Left: | | |||
869 | newPos = QPoint( -q->width(), ( anchorWidget->height() - q->height() ) / 2 ); | | |||
870 | break; | | |||
871 | case PageViewToolBar::Top: | | |||
872 | newPos = QPoint( ( anchorWidget->width() - q->width() ) / 2, -q->height() ); | | |||
873 | break; | | |||
874 | case PageViewToolBar::Right: | | |||
875 | newPos = QPoint( anchorWidget->width(), ( anchorWidget->height() - q->height() ) / 2 ); | | |||
876 | break; | | |||
877 | case PageViewToolBar::Bottom: | | |||
878 | newPos = QPoint( ( anchorWidget->width() - q->width() ) / 2, anchorWidget->height() ); | | |||
879 | break; | | |||
880 | } | | |||
881 | return newPos + anchorWidget->pos(); | | |||
882 | } | | |||
883 | | ||||
884 | void PageViewToolBar::slotAnimate() | | |||
885 | { | | |||
886 | // move currentPosition towards endPosition | | |||
887 | int dX = d->endPosition.x() - d->currentPosition.x(), | | |||
888 | dY = d->endPosition.y() - d->currentPosition.y(); | | |||
889 | dX = dX / 6 + qMax( -1, qMin( 1, dX) ); | | |||
890 | dY = dY / 6 + qMax( -1, qMin( 1, dY) ); | | |||
891 | d->currentPosition.setX( d->currentPosition.x() + dX ); | | |||
892 | d->currentPosition.setY( d->currentPosition.y() + dY ); | | |||
893 | | ||||
894 | // move the widget | | |||
895 | move( d->currentPosition ); | | |||
896 | | ||||
897 | // handle arrival to the end | | |||
898 | if ( d->currentPosition == d->endPosition ) | | |||
899 | { | | |||
900 | d->animTimer->stop(); | | |||
901 | if ( d->hiding ) | | |||
902 | { | | |||
903 | d->visible = false; | | |||
904 | deleteLater(); | | |||
905 | } | | |||
906 | else | | |||
907 | { | | |||
908 | d->visible = true; | | |||
909 | } | | |||
910 | } | | |||
911 | } | | |||
912 | | ||||
913 | void PageViewToolBar::slotButtonClicked() | | |||
914 | { | | |||
915 | ToolBarButton * button = qobject_cast<ToolBarButton *>( sender() ); | | |||
916 | d->selectButton( button ); | | |||
917 | } | | |||
918 | | ||||
919 | void ToolBarPrivate::selectButton( ToolBarButton * button ) | | |||
920 | { | | |||
921 | if ( button ) | | |||
922 | { | | |||
923 | // deselect other buttons | | |||
924 | QLinkedList< ToolBarButton * >::const_iterator it = buttons.begin(), end = buttons.end(); | | |||
925 | for ( ; it != end; ++it ) | | |||
926 | if ( *it != button ) | | |||
927 | (*it)->setChecked( false ); | | |||
928 | // emit signal (-1 if button has been unselected) | | |||
929 | emit q->toolSelected( button->isChecked() ? button->buttonID() : -1 ); | | |||
930 | } | | |||
931 | } | | |||
932 | | ||||
933 | void PageViewToolBar::setToolsEnabled( bool on ) | | |||
934 | { | | |||
935 | QLinkedList< ToolBarButton * >::const_iterator it = d->buttons.begin(), end = d->buttons.end(); | | |||
936 | for ( ; it != end; ++it ) | | |||
937 | (*it)->setEnabled( on ); | | |||
938 | } | | |||
939 | | ||||
940 | void PageViewToolBar::setTextToolsEnabled( bool on ) | | |||
941 | { | | |||
942 | QLinkedList< ToolBarButton * >::const_iterator it = d->buttons.begin(), end = d->buttons.end(); | | |||
943 | for ( ; it != end; ++it ) | | |||
944 | if ( (*it)->isText() ) | | |||
945 | (*it)->setEnabled( on ); | | |||
946 | } | | |||
947 | | ||||
948 | #include "moc_pageviewutils.cpp" | 416 | #include "moc_pageviewutils.cpp" |