514
518
case ResizeButton:
515
519
case RotateButton:
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;
527
QRectF rect = QRectF(m_applet->pos(), m_applet->size());
528
QPointF center = rect.center();
530
521
m_angle += m_tempAngle;
534
matrix.translate(center.x(), center.y());
535
matrix.rotateRadians(m_angle);
536
matrix.translate(-center.x(), -center.y());
538
setTransform(matrix);
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;
542
530
case ConfigureButton:
560
m_applet->d->ghost = false;
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));
577
544
// test for containment change
578
545
//kDebug() << "testing for containment change, sceneBoundingRect = "
579
546
// << m_containment->sceneBoundingRect();
645
611
if (m_pressedButton == MoveButton) {
646
612
m_pos += deltaScene;
648
//Are we moving out of the current view?
649
bool toTopLevel = leaveCurrentView(event->screenPos());
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));
654
//We were on a toplevel view, but are moving back on the scene
655
//again. destroy the toplevel view:
659
m_applet->d->ghost = false;
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());
667
//kDebug() << "screenRect = " << screenRect;
669
if (!m_topview) { //create a new toplevel view
670
m_topview = new View(m_containment, -1, 0);
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);
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);
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());
691
QPainter shapePainter;
692
shapePainter.begin(&bitmap);
693
shapePainter.fillRect(0, 0, screenRect.width(),
696
shapePainter.setBrush(Qt::black);
697
shapePainter.drawPath(m_applet->shape());
700
m_topview->setMask(bitmap);
704
m_applet->d->ghost = true;
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.
713
m_topview->setGeometry(screenRect);
716
629
} else if (m_pressedButton == RotateButton ||
717
630
m_pressedButton == ResizeButton) {
718
631
if (_k_distanceForPoint(deltaScene) <= 1.0) {
756
677
qreal newScaleWidth = 0;
757
678
qreal newScaleHeight = 0;
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();
764
if (qAbs(w - (newScaleWidth * w)) <= KGlobalSettings::dndEventDelay()) {
685
if (qAbs(event->pos().x() - pressPos.x()) <= KGlobalSettings::dndEventDelay()) {
686
newScaleWidth = m_originalSize.width() / originalRect.width();
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();
771
692
if (newScaleHeight * h < min.height()) {
801
723
m_scaleHeight = m_scaleWidth = newScale;
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);
733
// Adjust position based on new applet size
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) {
741
deltaY = -cos(m_angle) * deltaH;
742
} else if (m_angle >= M_PI_2 && m_angle <= M_PI) {
743
deltaX = cos(m_angle) * deltaW;
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;
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) {
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;
762
} else if (m_angle >= -M_PI && m_angle < M_PI_2) {
763
deltaX = sin(m_angle) * deltaH;
768
//kDebug() << "delta:" << deltaX << "," << deltaY;
769
//kDebug() << "Scale:" << m_scaleWidth << "," << m_scaleHeight;
770
moveBy(deltaX, deltaY);
773
//kDebug() << "Angle:" << m_angle * 180/M_PI << "," << (m_angle + m_tempAngle)*180/M_PI;
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);
813
784
QGraphicsItem::mouseMoveEvent(event);
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");
1007
971
void AppletHandle::forceDisappear()