aboutsummaryrefslogtreecommitdiff
path: root/src-qt5/core/libLumina/RootSubWindow-animations.cpp
blob: e3deed3a9019cc6f2c0c8fb980c34faaa05cf18b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
//===========================================
//  Lumina Desktop source code
//  Copyright (c) 2017, Ken Moore
//  Available under the 3-clause BSD license
//  See the LICENSE file for full details
//===========================================
#include "RootSubWindow.h"
#include <QDebug>

QStringList RootSubWindow::validAnimations(NativeWindow::Property prop){
  QStringList valid;
  if(prop == NativeWindow::Visible){
    valid << "zoom" << "wipe-center-vertical" << "wipe-center-horizontal" << "shade-top" << "shade-right" << "shade-left" << "shade-bottom";
  }
  return valid;
}

void RootSubWindow::loadAnimation(QString name, NativeWindow::Property prop, QVariant nval){
  animResetProp.clear();
  //Special case - random animation each time
  if(name=="random"){
    QStringList valid = validAnimations(prop);
    name = valid.at(qrand()%valid.length());
  }
  //Now setup the animation
  if(prop == NativeWindow::Visible){
    //NOTE: Assigns values for "invisible->visible" animation: will reverse it afterwards as needed
    anim->setPropertyName("geometry");
    QRect geom = this->geometry();
    if(name == "zoom"){
      //Zoom to/from the center point
      anim->setStartValue( QRect(geom.center(), QSize(0,0)) );
      anim->setEndValue(geom);
    }else if(name == "wipe-center-vertical"){
      anim->setStartValue( QRect( geom.center().x(), geom.y(), 0, geom.height()) );
      anim->setEndValue( geom );
    }else if(name == "wipe-center-horizontal"){
      anim->setStartValue( QRect( geom.x(), geom.center().y(), geom.width(), 0) );
      anim->setEndValue( geom );
    }else if(name == "shade-top"){
      anim->setStartValue( QRect( geom.x(), geom.y(), geom.width(), 0) );
      anim->setEndValue( geom );
    }else if(name == "shade-bottom"){
      anim->setStartValue( QRect( geom.x(), geom.y()+geom.height(), geom.width(), 0) );
      anim->setEndValue( geom );
    }else if(name == "shade-left"){
      anim->setStartValue( QRect( geom.x(), geom.y(), 0, geom.height()) );
      anim->setEndValue( geom );
    }else if(name == "shade-right"){
      anim->setStartValue( QRect( geom.x()+geom.width(), geom.y(), 0, geom.height()) );
      anim->setEndValue( geom );
    }else{
      //Invalid/None animation
      if(nval.toBool()){ this->show(); }
      else{ this->hide(); }
      return;
    }
    if(nval.toBool()){
      this->setGeometry( anim->startValue().toRect() ); //ensure the window is the initial geom before it becomes visible
    }else{
      QVariant tmp = anim->startValue();
        anim->setStartValue(anim->endValue());
        anim->setEndValue(tmp);
      animResetProp = anim->startValue();
      QTimer::singleShot(anim->duration(), this, SLOT(hide()) );
    }
    anim->start();
    this->show();
  } //end of Visibility animation
}

void RootSubWindow::animFinished(){
  if(closing){ this->close(); return;}
  else if(anim->propertyName()=="geometry"){
    if(!animResetProp.isNull()){
      /*qDebug() << "Animation Finished, Reset Geometry:" << animResetProp.toRect();
      qDebug() << " - Starting Value:" << anim->startValue().toRect();
      qDebug() << " - Ending Value:" << anim->endValue().toRect();*/
      this->setGeometry( animResetProp.toRect() );
      //Also ensure that the proper geometry is saved to the window structure
      QRect curg = this->geometry();
      QRect wing = WIN->geometry();
      qDebug() << " - After Animation Reset:" << curg << wing;
      if(curg!=wing){
        QRect clientg = clientGlobalGeom();
        qDebug() << "Sub Window geometry:" << clientg;
        WIN->setProperties(QList< NativeWindow::Property>() << NativeWindow::Size << NativeWindow::GlobalPos,
		QList<QVariant>() << clientg.size() << clientg.topLeft() );
        WinWidget->resyncWindow(); //also let the window know about the current geometry
      }
    }
  }
  animResetProp = QVariant(); //clear the variable
}
bgstack15