KM
Қаз. 23, 2020, 5:25 Т.Қ.

Qt анимация диалога c++

qt, Dialog, QPropertyAnimation

Хочу сдедать диалог который будет выпадать с помощью анимации
Анимация готова но я не знаю как попровать ее так чтобы мой диалог выезжал с верху на центр, при закрытии диалог заезжает наверх

  1. первый класс
  2.  
  3. void ConnectionEditor::setupPoint()
  4. {
  5. if(pAdder.state) return;
  6. auto *pin = qobject_cast<PinPoint*>(sender());
  7. auto *dialog = new ConfigDialog(pin, &pin->getConnection(), this->parentWidget());
  8. // dialog->setAttribute(Qt::WA_DeleteOnClose, true);
  9. dialog->open();
  10.  
  11. connect(dialog, &ConfigDialog::finished, [=] {});
  12. }
  13.  
  14.  
  15. QWidget *ConnectionEditor::getView()
  16. {
  17. return this;
  18. }
  19.  
  20.  
  21.  
  22.  
  23. второй класс
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31. void ConfigDialog::open()
  32.  
  33. {
  34. animate(false);
  35. QDialog::open();
  36. }
  37.  
  38. void ConfigDialog::done(int r)
  39. {
  40. if (!animation_on) {
  41. animate(true);
  42. setResult(r);
  43. if (r == QDialog::Accepted)
  44. emit accepted();
  45. else if (r == QDialog::Rejected)
  46. emit rejected();
  47.  
  48. emit finished(r);
  49. }
  50. }
  51.  
  52. void ConfigDialog::animate(bool reverse)
  53. {
  54.  
  55. Animator::dialogAnimation(this);
  56.  
  57. if (!reverse) {
  58.  
  59. Animator::dialogAnimationIfReverse(this, 0.0, 1.0);
  60.  
  61. } else {
  62.  
  63. emit reverseAnimStarted();
  64.  
  65. Animator::dialogAnimationIfElse(this, 1.0, 0.0, 1000, 1500 );
  66. }
  67.  
  68. }
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75. третий класс
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85. void Animator::dialogAnimation(QWidget *widget)
  86. {
  87. auto animFade= new QPropertyAnimation(widget, "windowOpacity", widget);
  88. animFade->setDuration(1500);
  89. animFade->setEasingCurve(QEasingCurve::Linear);
  90.  
  91. auto pos1 = widget->mapToParent(widget->rect().topLeft());
  92. auto pos2 = QPoint(pos1.x(), -widget->height());
  93.  
  94.  
  95. auto animMove = new QPropertyAnimation(widget, "pos", widget);
  96. animFade->setDuration(1500);
  97. animMove->setEasingCurve(QEasingCurve::OutQuad);
  98.  
  99. }
  100.  
  101. void Animator::dialogAnimationIfReverse(QWidget *widget, const QVariant StartVal1, const QVariant EndVal2)
  102. {
  103. auto pos1 = widget->mapToParent(widget->rect().topLeft());
  104. auto pos2 = QPoint(pos1.x(), -widget->height());
  105. auto animFade= new QPropertyAnimation(widget, "windowOpacity", widget);
  106. auto animMove = new QPropertyAnimation(widget, "pos", widget);
  107. animFade->setStartValue(StartVal1);
  108. animFade->setEndValue(EndVal2);
  109. animMove->setStartValue(pos2);
  110. animMove->setEndValue(pos1);
  111. }
  112.  
  113. void Animator::dialogAnimationIfElse(QWidget *widget, const QVariant StartVal1, const QVariant EndVal2, int timeInMS1, int timeInMS2)
  114. {
  115. auto pos1 = widget->mapToParent(widget->rect().topLeft());
  116. auto pos2 = QPoint(pos1.x(), -widget->height());
  117. auto animFade= new QPropertyAnimation(widget, "windowOpacity", widget);
  118. auto animMove = new QPropertyAnimation(widget, "pos", widget);
  119. {
  120. animFade->setDuration(timeInMS1);
  121. animMove->setDuration(timeInMS2);
  122. animFade->setStartValue(StartVal1);
  123. animFade->setEndValue(EndVal2);
  124. animMove->setStartValue(pos1);
  125. animMove->setEndValue(pos2);
  126.  
  127. QObject::connect(animFade, &QPropertyAnimation::finished,
  128. [widget] { widget->hide(); });
  129.  
  130. }
  131.  
  132. animFade->start(QAbstractAnimation::DeleteWhenStopped);
  133. animMove->start(QAbstractAnimation::DeleteWhenStopped);
  134. }
  135.  
  136.  
  137. void Animator::StartConfidDialog(QWidget *widget, const QVariant StartVal1, const QVariant EndVal2, int timeInMS1, int timeInMS2)
  138.  
  139. {
  140. auto pos1 = widget->mapToParent(widget->rect().topLeft());
  141. auto pos2 = QPoint(pos1.x(), -widget->height());
  142. auto animFade= new QPropertyAnimation(widget, "windowOpacity", widget);
  143. auto animMove = new QPropertyAnimation(widget, "pos", widget);
  144. {
  145. animFade->setDuration(timeInMS1);
  146. animMove->setDuration(timeInMS2);
  147. animFade->setStartValue(StartVal1);
  148. animFade->setEndValue(EndVal2);
  149. animMove->setStartValue(pos1);
  150. animMove->setEndValue(pos2);
  151. QObject::connect(animFade, &QPropertyAnimation::finished,
  152. [widget] { widget->hide(); });
  153.  
  154. }
  155.  
  156. animFade->start(QAbstractAnimation::DeleteWhenStopped);
  157. animMove->start(QAbstractAnimation::DeleteWhenStopped);
  158. }
  159.  
  160.  
  161. void Animator::startdialogAnimation(QWidget *widget)
  162. {
  163. auto animFade= new QPropertyAnimation(widget, "windowOpacity", widget);
  164. animFade->setEasingCurve(QEasingCurve::Linear);
  165. auto animMove = new QPropertyAnimation(widget, "pos", widget);
  166. animMove->setEasingCurve(QEasingCurve::OutQuad);
  167.  
  168. }
2

Ол саған ұнайды ма? Әлеуметтік желілерде бөлісіңіз!

0

Пікірлер

Тек рұқсаты бар пайдаланушылар ғана пікір қалдыра алады.
Кіріңіз немесе Тіркеліңіз