~ubuntu-branches/ubuntu/jaunty/kde4libs/jaunty-updates

« back to all changes in this revision

Viewing changes to plasma/private/applethandle.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Harald Sitter
  • Date: 2008-12-11 18:26:08 UTC
  • mfrom: (1.1.24 upstream)
  • Revision ID: james.westby@ubuntu.com-20081211182608-tsu6p8ncbw1gnqxt
Tags: 4:4.1.85-0ubuntu1
* New upstream release
* Patches:
  + Removed 15_kfreebsd_support.diff from patches/series (doesn't apply and
    has no use for Ubuntu)
  + Redid 20_use_dejavu_as_default_font.diff
  + Completely removed kubuntu_09_fix_application_menu.diff (applied upstream)
  + Refreshed kubuntu_54_use_xdg_menu_prefix.diff
  + Dropped plasma/widgets/toolbutton.cpp from kubuntu_qt_ftbfs.diff (applied
    upstream)
  + Global quilt refresh

Show diffs side-by-side

added added

removed removed

Lines of Context:
63
63
      m_tempAngle(0.0),
64
64
      m_scaleWidth(1.0),
65
65
      m_scaleHeight(1.0),
66
 
      m_topview(0),
67
66
      m_backgroundBuffer(0),
68
67
      m_currentView(applet->view()),
69
68
      m_entryPos(hoverPos),
136
135
{
137
136
    detachApplet();
138
137
    delete m_backgroundBuffer;
139
 
    if (m_topview) {
140
 
        delete m_topview;
141
 
    }
142
138
}
143
139
 
144
140
Applet *AppletHandle::applet() const
229
225
    Q_UNUSED(option);
230
226
    Q_UNUSED(widget);
231
227
 
 
228
    //kDebug() << m_opacity << m_anim << FadeOut;
232
229
    if (qFuzzyCompare(m_opacity + 1.0, 1.0)) {
233
230
        if (m_anim == FadeOut) {
 
231
            //kDebug() << "WOOOOOOOOO";
234
232
            QTimer::singleShot(0, this, SLOT(emitDisappear()));
235
233
        }
236
234
        return;
237
235
    }
238
236
 
239
 
    painter->save();
240
 
 
241
237
    qreal translation;
242
238
 
243
239
    if (m_buttonsOnRight) {
393
389
    basePoint = m_rect.bottomLeft() + QPointF(HANDLE_MARGIN, 0) - step;
394
390
    sourceIconRect.translate(0, m_iconSize);
395
391
    painter->drawPixmap(QRectF(basePoint + shiftD, iconSize), *m_backgroundBuffer, sourceIconRect);
396
 
 
397
 
    painter->restore();
398
392
}
399
393
 
400
394
void AppletHandle::emitDisappear()
465
459
        if (m_pressedButton == MoveButton) {
466
460
            m_pos = pos();
467
461
        }
 
462
 
 
463
        if (m_pressedButton == ResizeButton) {
 
464
            QRectF rect = QRectF(m_applet->pos(), m_applet->size());
 
465
            m_originalSize = rect.size();
 
466
            if (m_buttonsOnRight) {
 
467
                m_resizeAnchor = rect.bottomLeft();
 
468
                m_resizeOffset = event->pos() - rect.topRight();
 
469
            } else {
 
470
                m_resizeAnchor = rect.bottomRight(); 
 
471
                m_resizeOffset = event->pos() - rect.topLeft();
 
472
            }
 
473
        }
 
474
 
468
475
        event->accept();
469
476
 
470
477
        update();
487
494
            //is this widget a plasma view, a different view then our current one,
488
495
            //AND not a dashboardview?
489
496
            Plasma::View *v = qobject_cast<Plasma::View *>(widget);
490
 
            if (v &&
491
 
                v != m_currentView &&
492
 
                v != m_topview &&
493
 
                v->containment() != m_containment) {
 
497
            if (v && v != m_currentView && v->containment() != m_containment) {
494
498
                return true;
495
499
            }
496
500
        }
514
518
        case ResizeButton:
515
519
        case RotateButton:
516
520
        {
517
 
            if (m_scaleWidth > 0 && m_scaleHeight > 0) {
518
 
                QRectF rect(m_applet->boundingRect());
519
 
                const qreal newWidth = rect.width() * m_scaleWidth;
520
 
                const qreal newHeight = rect.height() * m_scaleHeight;
521
 
                m_applet->resetTransform();
522
 
                m_applet->resize(newWidth, newHeight);
523
 
                scale(1.0 / m_scaleWidth, 1.0 / m_scaleHeight);
524
 
                moveBy((rect.width() - newWidth) / 2, (rect.height() - newHeight) / 2);
525
 
                m_scaleWidth = m_scaleHeight = 0;
526
 
            }
527
 
            QRectF rect = QRectF(m_applet->pos(), m_applet->size());
528
 
            QPointF center = rect.center();
529
 
 
530
521
            m_angle += m_tempAngle;
531
 
            m_tempAngle = 0;
532
 
 
533
 
            QTransform matrix;
534
 
            matrix.translate(center.x(), center.y());
535
 
            matrix.rotateRadians(m_angle);
536
 
            matrix.translate(-center.x(), -center.y());
537
 
 
538
 
            setTransform(matrix);
539
 
            m_applet->update();
 
522
            if (m_angle > M_PI) {
 
523
                m_angle = m_angle - 2 * M_PI;
 
524
            } else if (m_angle < -M_PI) {
 
525
                m_angle = m_angle + 2 * M_PI;
 
526
            }
 
527
            m_tempAngle = 0; 
540
528
            break;
541
529
        }
542
530
        case ConfigureButton:
553
541
            break;
554
542
        case MoveButton:
555
543
        {
556
 
            if (m_topview) {
557
 
                m_topview->hide();
558
 
                delete m_topview;
559
 
                m_topview = 0;
560
 
                m_applet->d->ghost = false;
561
 
                m_applet->update();
562
 
            }
563
 
 
564
 
            //find out if we were dropped on a panel or something
565
 
            if (leaveCurrentView(event->screenPos())) {
566
 
                startFading(FadeOut, m_entryPos);
567
 
                Plasma::View *v = Plasma::View::topLevelViewAt(event->screenPos());
568
 
                if (v && v != m_currentView) {
569
 
                    Containment *c = v->containment();
570
 
                    QPoint pos = v->mapFromGlobal(event->screenPos());
571
 
                    //we actually have been dropped on another containment, so
572
 
                    //move there: we have a screenpos, we need a scenepos
573
 
                    //FIXME how reliable is this transform?
574
 
                    switchContainment(c, v->mapToScene(pos));
575
 
                }
576
 
            } else {
577
544
                // test for containment change
578
545
                //kDebug() << "testing for containment change, sceneBoundingRect = "
579
546
                //         << m_containment->sceneBoundingRect();
602
569
                        }
603
570
                    }
604
571
                }
605
 
            }
606
572
            break;
607
573
        }
608
574
        default:
644
610
 
645
611
    if (m_pressedButton == MoveButton) {
646
612
        m_pos += deltaScene;
647
 
 
648
 
        //Are we moving out of the current view?
649
 
        bool toTopLevel = leaveCurrentView(event->screenPos());
650
 
 
651
 
        if (!toTopLevel) {
 
613
        if (leaveCurrentView(event->screenPos())) {
 
614
            Plasma::View *v = Plasma::View::topLevelViewAt(event->screenPos());
 
615
            if (v && v != m_currentView) {
 
616
                Containment *c = v->containment();
 
617
                QPoint pos = v->mapFromGlobal(event->screenPos());
 
618
                //we actually have been dropped on another containment, so
 
619
                //move there: we have a screenpos, we need a scenepos
 
620
                //FIXME how reliable is this transform?
 
621
                m_pressedButton = NoButton;
 
622
                switchContainment(c, v->mapToScene(pos));
 
623
            } else {
 
624
                setPos(m_pos);
 
625
            }
 
626
        } else {
652
627
            setPos(m_pos);
653
 
            if (m_topview) {
654
 
                //We were on a toplevel view, but are moving back on the scene
655
 
                //again. destroy the toplevel view:
656
 
                m_topview->hide();
657
 
                delete m_topview;
658
 
                m_topview = 0;
659
 
                m_applet->d->ghost = false;
660
 
            }
661
 
        } else {
662
 
            //set the screenRect correctly. the screenRect contains the bounding
663
 
            //rect of the applet in screen coordinates. m_mousePos contains the
664
 
            //position of the mouse relative to the applet, in screen coords.
665
 
            QRect screenRect = QRect(event->screenPos() - m_mousePos, m_applet->size().toSize());
666
 
 
667
 
            //kDebug() << "screenRect = " << screenRect;
668
 
 
669
 
            if (!m_topview) { //create a new toplevel view
670
 
                m_topview = new View(m_containment, -1, 0);
671
 
 
672
 
                m_topview->setTrackContainmentChanges(false);
673
 
                m_topview->setWindowFlags(
674
 
                    Qt::ToolTip | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
675
 
                m_topview->setWallpaperEnabled(false);
676
 
                m_topview->resize(screenRect.size());
677
 
                m_topview->setSceneRect(m_applet->sceneBoundingRect());
678
 
                m_topview->centerOn(m_applet);
679
 
 
680
 
                //We might have to scale the view, because we might be zoomed out.
681
 
                qreal scale = screenRect.width() / m_applet->boundingRect().width();
682
 
                m_topview->scale(scale, scale);
683
 
 
684
 
                //Paint a mask based on the applets shape.
685
 
                //TODO: I think it's nicer to have this functionality in Applet.
686
 
                //TODO: When the corona tiled background is disabled, disable the
687
 
                //mask when compositing is enabled.
688
 
                //FIXME: the mask doesn't function correctly when zoomed out.
689
 
                QBitmap bitmap(screenRect.size());
690
 
                {
691
 
                    QPainter shapePainter;
692
 
                    shapePainter.begin(&bitmap);
693
 
                    shapePainter.fillRect(0, 0, screenRect.width(),
694
 
                                                screenRect.height(),
695
 
                                                Qt::white);
696
 
                    shapePainter.setBrush(Qt::black);
697
 
                    shapePainter.drawPath(m_applet->shape());
698
 
                    shapePainter.end();
699
 
                }
700
 
                m_topview->setMask(bitmap);
701
 
 
702
 
                m_topview->show();
703
 
 
704
 
                m_applet->d->ghost = true;
705
 
 
706
 
                //TODO: non compositing users are screwed: masking looks terrible.
707
 
                //Consider always enabling the applet background. Stuff like the analog clock
708
 
                //looks absolutely terrible when masked, while the minor rounded corners of most
709
 
                //themes should look quite ok. I said should, since shape() doesn't really
710
 
                //function correctly right now for applets drawing standard backgrounds.
711
 
            }
712
 
 
713
 
            m_topview->setGeometry(screenRect);
714
628
        }
715
 
 
716
629
    } else if (m_pressedButton == RotateButton ||
717
630
               m_pressedButton == ResizeButton) {
718
631
        if (_k_distanceForPoint(deltaScene) <= 1.0) {
721
634
 
722
635
        QPointF pressPos = mapFromScene(event->buttonDownScenePos(Qt::LeftButton));
723
636
 
 
637
        QRectF originalRect = m_totalRect;
724
638
        QRectF rect = QRectF(m_applet->pos(), m_applet->size());
725
639
        QPointF center = rect.center();
726
640
 
737
651
            qreal h = m_applet->size().height();
738
652
            QSizeF min = m_applet->minimumSize();
739
653
            QSizeF max = m_applet->maximumSize();
 
654
            QPointF resizePoint(0.0, 0.0);
 
655
            if (m_buttonsOnRight) {
 
656
                resizePoint = rect.topRight();
 
657
            } else {
 
658
                resizePoint = rect.topLeft();
 
659
            }
 
660
 
740
661
 
741
662
            // If the applet doesn't have a minimum size, calculate based on a
742
663
            // minimum content area size of 16x16
756
677
                qreal newScaleWidth = 0;
757
678
                qreal newScaleHeight = 0;
758
679
 
759
 
                QPointF startDistance(pressPos - center);
760
 
                QPointF currentDistance(event->pos() - center);
 
680
                QPointF startDistance(resizePoint - m_resizeAnchor);
 
681
                QPointF currentDistance((event->pos() - m_resizeOffset) - m_resizeAnchor);
761
682
                newScaleWidth = currentDistance.x() / startDistance.x();
762
683
                newScaleHeight = currentDistance.y() / startDistance.y();
763
684
 
764
 
                if (qAbs(w - (newScaleWidth * w)) <= KGlobalSettings::dndEventDelay()) {
765
 
                    newScaleWidth = 1.0;
 
685
                if (qAbs(event->pos().x() - pressPos.x()) <= KGlobalSettings::dndEventDelay()) {
 
686
                    newScaleWidth = m_originalSize.width() / originalRect.width();
766
687
                }
767
 
                if (qAbs(h - (newScaleHeight * h)) <= KGlobalSettings::dndEventDelay()) {
768
 
                    newScaleHeight = 1.0;
 
688
                if (qAbs(event->pos().y() - pressPos.y()) <= KGlobalSettings::dndEventDelay()) {
 
689
                    newScaleHeight = m_originalSize.height() / originalRect.height();
769
690
                }
770
691
 
771
692
                if (newScaleHeight * h < min.height()) {
787
708
                qreal newScale = 0;
788
709
 
789
710
                newScale =
790
 
                    _k_distanceForPoint(event->pos()-center) /
791
 
                    _k_distanceForPoint(pressPos - center);
792
 
                if (qAbs(h - (newScale * h)) <= KGlobalSettings::dndEventDelay()) {
793
 
                    newScale = 1.0;
 
711
                    _k_distanceForPoint((event->pos() - m_resizeOffset) - m_resizeAnchor) /
 
712
                    _k_distanceForPoint(resizePoint - m_resizeAnchor);
 
713
 
 
714
                if (qAbs(event->pos().y() - pressPos.y()) <= KGlobalSettings::dndEventDelay()) {
 
715
                    newScale = m_originalSize.height() / originalRect.height();
794
716
                }
795
717
 
796
718
                if (newScale * w < min.width() || newScale * h < min.height()) {
801
723
                    m_scaleHeight = m_scaleWidth = newScale;
802
724
                }
803
725
            }
 
726
            
 
727
            // Resize Applet
 
728
            QSizeF oldSize(m_applet->size());
 
729
            const qreal newWidth = oldSize.width() * m_scaleWidth;
 
730
            const qreal newHeight = oldSize.height() * m_scaleHeight;
 
731
            m_applet->resize(newWidth, newHeight);
 
732
 
 
733
            // Adjust position based on new applet size
 
734
            qreal deltaX = 0;
 
735
            qreal deltaY = 0;
 
736
            const qreal deltaH = newHeight - oldSize.height();
 
737
            const qreal deltaW = newWidth - oldSize.width();
 
738
            if (m_buttonsOnRight) {
 
739
                if (m_angle >= 0 && m_angle < M_PI_2) {
 
740
                    deltaX = 0;
 
741
                    deltaY = -cos(m_angle) * deltaH;
 
742
                } else if (m_angle >= M_PI_2 && m_angle <= M_PI) {
 
743
                    deltaX = cos(m_angle) * deltaW;
 
744
                    deltaY = 0;
 
745
                } else if (m_angle >= -M_PI_2 && m_angle < 0) {
 
746
                    deltaX = sin(m_angle) * deltaH;
 
747
                    deltaY = -cos(m_angle) * deltaH + sin(m_angle) * deltaW;
 
748
                } else if (m_angle >= -M_PI && m_angle < M_PI_2) {
 
749
                    deltaX = cos(m_angle) * deltaW + sin(m_angle) * deltaH;
 
750
                    deltaY = sin(m_angle) * deltaW;
 
751
                }
 
752
            } else {
 
753
                if (m_angle >= 0 && m_angle < M_PI_2) {
 
754
                    deltaX = -cos(m_angle) * deltaW;
 
755
                    deltaY = -cos(m_angle) * deltaH - sin(m_angle) * deltaW;
 
756
                } else if (m_angle >= M_PI_2 && m_angle <= M_PI) {
 
757
                    deltaX = 0;
 
758
                    deltaY = -sin(m_angle) * deltaW;
 
759
                } else if (m_angle >= -M_PI_2 && m_angle < 0) {
 
760
                    deltaX = sin(m_angle) * deltaH - cos(m_angle) * deltaW;
 
761
                    deltaY = 0;
 
762
                } else if (m_angle >= -M_PI && m_angle < M_PI_2) {
 
763
                    deltaX = sin(m_angle) * deltaH;
 
764
                    deltaY = 0;
 
765
                }
 
766
            }
 
767
 
 
768
            //kDebug() << "delta:" << deltaX << "," << deltaY;
 
769
            //kDebug() << "Scale:" << m_scaleWidth << "," << m_scaleHeight;
 
770
            moveBy(deltaX, deltaY);
804
771
        }
805
772
 
 
773
        //kDebug() << "Angle:" << m_angle * 180/M_PI << "," << (m_angle + m_tempAngle)*180/M_PI;
 
774
 
 
775
        rect = QRectF(m_applet->pos(), m_applet->size());
 
776
        center = rect.center();
806
777
        QTransform matrix;
807
778
        matrix.translate(center.x(), center.y());
808
779
        matrix.rotateRadians(m_angle + m_tempAngle);
809
 
        matrix.scale(m_scaleWidth, m_scaleHeight);
810
780
        matrix.translate(-center.x(), -center.y());
811
781
        setTransform(matrix);
 
782
        m_applet->update();
812
783
    } else {
813
784
        QGraphicsItem::mouseMoveEvent(event);
814
785
    }
819
790
{
820
791
    if (containment->containmentType() != Containment::PanelContainment) {
821
792
        //FIXME assuming everything else behaves like desktop?
822
 
        kDebug() << "desktop";
 
793
        //kDebug() << "desktop";
823
794
        m_containment = containment;
824
795
    }
825
796
 
875
846
        //wait a moment to hide the handle in order to recheck the mouse position
876
847
        m_leaveTimer->start();
877
848
    }
878
 
 
879
 
   if (m_topview) {
880
 
        //We were on a toplevel view, but are moving back on the scene
881
 
        //again. destroy the toplevel view:
882
 
        m_topview->hide();
883
 
        delete m_topview;
884
 
        m_topview = 0;
885
 
        m_applet->d->ghost = false;
886
 
    }
887
849
}
888
850
 
889
851
bool AppletHandle::sceneEventFilter(QGraphicsItem *watched, QEvent *event)
903
865
    } else {
904
866
        m_opacity = 1 - progress;
905
867
    }
906
 
    //kDebug() << "progress" << progress << "m_opacity" << m_opacity;// << endOpacity;
 
868
 
 
869
    //kDebug() << "progress" << progress << "m_opacity" << m_opacity << m_anim << "(" << FadeIn << ")";
907
870
    if (qFuzzyCompare(progress, qreal(1.0))) {
908
871
        m_animId = 0;
909
872
        delete m_backgroundBuffer;
954
917
 
955
918
    if (!m_applet || (anim == FadeOut && m_hoverTimer->isActive())) {
956
919
        // fading out before we've started fading in
 
920
        m_anim = FadeOut;
957
921
        fadeAnimation(1.0);
958
922
        return;
959
923
    }
1000
964
 
1001
965
    m_anim = anim;
1002
966
    //kDebug() << "animating for " << time << "ms";
1003
 
    m_animId = Animator::self()->customAnimation(
1004
 
        80 * (time / 1000.0), (int)time, Animator::EaseInCurve, this, "fadeAnimation");
 
967
    m_animId = Animator::self()->customAnimation(80 * (time / 1000.0), (int)time,
 
968
                                                 Animator::EaseInCurve, this, "fadeAnimation");
1005
969
}
1006
970
 
1007
971
void AppletHandle::forceDisappear()