/mainMenuFrame.cpp

http://cutefootball.googlecode.com/ · C++ · 130 lines · 95 code · 13 blank · 22 comment · 10 complexity · 6796e8d14261d098649c12a5e3fec7f2 MD5 · raw file

  1. /*
  2. * Copyright 2010,2011 Timothy Rochford
  3. *
  4. * This file is part of CuteFootball.
  5. *
  6. * CuteFootball is free software: you can redistribute it and/or modify
  7. * it under the terms of the Lesser GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * CuteFootball is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * Lesser GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the Lesser GNU General Public License
  17. * along with CuteFootball. If not, see <http://www.gnu.org/licenses/>.
  18. *
  19. */
  20. #include "mainMenuFrame.h"
  21. #include "ui_mainMenuFrame.h"
  22. #include <QParallelAnimationGroup>
  23. #include <QPropertyAnimation>
  24. mainMenuFrame::mainMenuFrame(MWindow *parent) :
  25. QFrame(parent),
  26. ui(new Ui::mainMenuFrame),
  27. m_animationGrp(NULL)
  28. {
  29. ui->setupUi(this);
  30. // TODO disable these until ready
  31. //ui->m_settingsBtn->setVisible(false);
  32. //ui->m_settingsBtn->setEnabled(false);
  33. ui->m_inputBtn->setVisible(false);
  34. ui->m_inputBtn->setEnabled(false);
  35. ui->m_playCupGameBtn->setVisible(false);
  36. ui->m_playCupGameBtn->setEnabled(false);
  37. animateButtons(size().width());
  38. connect(parent, SIGNAL(setFrame(MWindow::Frame)),
  39. this, SLOT(showFrame(MWindow::Frame)));
  40. connect(ui->actionGameSingle, SIGNAL(triggered()),
  41. parent, SLOT(showSingleGameTeamSelection()));
  42. connect(ui->actionWorld_Cup, SIGNAL(triggered()),
  43. parent, SLOT(showCupTeamSelection()));
  44. connect(ui->actionSettings, SIGNAL(triggered()),
  45. parent, SLOT(showSettingsFrame()));
  46. connect(ui->actionInputSettings, SIGNAL(triggered()),
  47. parent, SLOT(showInputSettingsFrame()));
  48. connect(ui->actionHelp, SIGNAL(triggered()),
  49. parent,SLOT(showHelpFrame()));
  50. connect(ui->actionQuit, SIGNAL(triggered()),
  51. parent, SLOT(close()));
  52. connect(ui->actionAbout, SIGNAL(triggered()),
  53. parent, SLOT(showAboutFrame()));
  54. }
  55. QPropertyAnimation* mainMenuFrame::createAnimation(QWidget* widget, QPoint finalPosition)
  56. {
  57. QPropertyAnimation* anim = new QPropertyAnimation(widget, "pos");
  58. anim->setDuration(1200);
  59. anim->setEasingCurve(QEasingCurve::OutElastic);
  60. anim->setStartValue(QPoint(0,finalPosition.y()));
  61. anim->setEndValue(finalPosition);
  62. return anim;
  63. }
  64. mainMenuFrame::~mainMenuFrame()
  65. {
  66. delete ui;
  67. delete m_animationGrp;
  68. }
  69. void mainMenuFrame::showFrame(MWindow::Frame f)
  70. {
  71. qDebug() << "mainMenuFrame::showFrame" << f;
  72. if ( f == MWindow::MainMenu ) {
  73. ui->m_newGameBtn->setFocus();
  74. showMaximized();
  75. m_animationGrp->start();
  76. } else {
  77. setVisible(false);
  78. m_animationGrp->stop();
  79. }
  80. }
  81. void mainMenuFrame::resizeEvent(QResizeEvent *e)
  82. {
  83. const int offset = ui->m_newGameBtn->size().width()/2;
  84. const int xPos = e->size().width()/2 - offset;
  85. ui->m_newGameBtn->setProperty("pos", QPoint(xPos,ui->m_newGameBtn->property("pos").toPoint().y()));
  86. if (ui->m_playCupGameBtn->isEnabled())
  87. ui->m_playCupGameBtn->setProperty("pos", QPoint(xPos,ui->m_playCupGameBtn->property("pos").toPoint().y()));
  88. if (ui->m_settingsBtn->isEnabled())
  89. ui->m_settingsBtn->setProperty("pos", QPoint(xPos,ui->m_settingsBtn->property("pos").toPoint().y()));
  90. if (ui->m_inputBtn->isEnabled())
  91. ui->m_inputBtn->setProperty("pos", QPoint(xPos,ui->m_inputBtn->property("pos").toPoint().y()));
  92. ui->m_informationBtn->setProperty("pos", QPoint(xPos,ui->m_informationBtn->property("pos").toPoint().y()));
  93. ui->m_aboutBtn->setProperty("pos", QPoint(xPos,ui->m_aboutBtn->property("pos").toPoint().y()));
  94. ui->m_quitBtn->setProperty("pos", QPoint(xPos,ui->m_quitBtn->property("pos").toPoint().y()));
  95. animateButtons(e->size().width());
  96. }
  97. void mainMenuFrame::animateButtons(const int width)
  98. {
  99. if (m_animationGrp) {
  100. delete m_animationGrp;
  101. m_animationGrp = NULL;
  102. }
  103. m_animationGrp = new QParallelAnimationGroup(this);
  104. const int offset = ui->m_newGameBtn->size().width()/2;
  105. const int xPoint = width/2 - offset;
  106. int yPoint(10);
  107. m_animationGrp->addAnimation(createAnimation(ui->m_newGameBtn, QPoint(xPoint,yPoint+=30)));
  108. if (ui->m_playCupGameBtn->isEnabled())
  109. m_animationGrp->addAnimation(createAnimation(ui->m_playCupGameBtn, QPoint(xPoint,yPoint+=30)));
  110. if (ui->m_settingsBtn->isEnabled())
  111. m_animationGrp->addAnimation(createAnimation(ui->m_settingsBtn, QPoint(xPoint,yPoint+=30)));
  112. if (ui->m_inputBtn->isEnabled())
  113. m_animationGrp->addAnimation(createAnimation(ui->m_inputBtn, QPoint(xPoint,yPoint+=30)));
  114. m_animationGrp->addAnimation(createAnimation(ui->m_informationBtn, QPoint(xPoint,yPoint+=30)));
  115. m_animationGrp->addAnimation(createAnimation(ui->m_aboutBtn, QPoint(xPoint,yPoint+=30)));
  116. m_animationGrp->addAnimation(createAnimation(ui->m_quitBtn, QPoint(xPoint,yPoint+=30)));
  117. }