PageRenderTime 53ms CodeModel.GetById 13ms app.highlight 35ms RepoModel.GetById 1ms app.codeStats 0ms

/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
 23#include <QParallelAnimationGroup>
 24#include <QPropertyAnimation>
 25
 26mainMenuFrame::mainMenuFrame(MWindow *parent) :
 27    QFrame(parent),
 28    ui(new Ui::mainMenuFrame),
 29    m_animationGrp(NULL)
 30{
 31    ui->setupUi(this);
 32
 33    // TODO disable these until ready
 34    //ui->m_settingsBtn->setVisible(false);
 35    //ui->m_settingsBtn->setEnabled(false);
 36    ui->m_inputBtn->setVisible(false);
 37    ui->m_inputBtn->setEnabled(false);
 38    ui->m_playCupGameBtn->setVisible(false);
 39    ui->m_playCupGameBtn->setEnabled(false);
 40
 41    animateButtons(size().width());
 42
 43    connect(parent, SIGNAL(setFrame(MWindow::Frame)),
 44            this, SLOT(showFrame(MWindow::Frame)));
 45
 46    connect(ui->actionGameSingle, SIGNAL(triggered()),
 47            parent, SLOT(showSingleGameTeamSelection()));
 48    connect(ui->actionWorld_Cup, SIGNAL(triggered()),
 49            parent, SLOT(showCupTeamSelection()));
 50    connect(ui->actionSettings, SIGNAL(triggered()),
 51            parent, SLOT(showSettingsFrame()));
 52    connect(ui->actionInputSettings, SIGNAL(triggered()),
 53            parent, SLOT(showInputSettingsFrame()));
 54    connect(ui->actionHelp, SIGNAL(triggered()),
 55            parent,SLOT(showHelpFrame()));
 56    connect(ui->actionQuit, SIGNAL(triggered()),
 57            parent, SLOT(close()));
 58    connect(ui->actionAbout, SIGNAL(triggered()),
 59            parent, SLOT(showAboutFrame()));
 60}
 61
 62QPropertyAnimation* mainMenuFrame::createAnimation(QWidget* widget, QPoint finalPosition)
 63{
 64    QPropertyAnimation* anim = new QPropertyAnimation(widget, "pos");
 65    anim->setDuration(1200);
 66    anim->setEasingCurve(QEasingCurve::OutElastic);
 67    anim->setStartValue(QPoint(0,finalPosition.y()));
 68    anim->setEndValue(finalPosition);
 69    return anim;
 70
 71}
 72
 73mainMenuFrame::~mainMenuFrame()
 74{
 75    delete ui;
 76    delete m_animationGrp;
 77}
 78
 79void mainMenuFrame::showFrame(MWindow::Frame f)
 80{
 81    qDebug() << "mainMenuFrame::showFrame" << f;
 82    if ( f == MWindow::MainMenu ) {
 83        ui->m_newGameBtn->setFocus();
 84        showMaximized();
 85        m_animationGrp->start();
 86    } else {
 87        setVisible(false);
 88        m_animationGrp->stop();
 89    }
 90}
 91
 92void mainMenuFrame::resizeEvent(QResizeEvent *e)
 93{
 94    const int offset = ui->m_newGameBtn->size().width()/2;
 95    const int xPos = e->size().width()/2 - offset;
 96    ui->m_newGameBtn->setProperty("pos", QPoint(xPos,ui->m_newGameBtn->property("pos").toPoint().y()));
 97    if (ui->m_playCupGameBtn->isEnabled())
 98        ui->m_playCupGameBtn->setProperty("pos", QPoint(xPos,ui->m_playCupGameBtn->property("pos").toPoint().y()));
 99    if (ui->m_settingsBtn->isEnabled())
100        ui->m_settingsBtn->setProperty("pos", QPoint(xPos,ui->m_settingsBtn->property("pos").toPoint().y()));
101    if (ui->m_inputBtn->isEnabled())
102        ui->m_inputBtn->setProperty("pos", QPoint(xPos,ui->m_inputBtn->property("pos").toPoint().y()));
103    ui->m_informationBtn->setProperty("pos", QPoint(xPos,ui->m_informationBtn->property("pos").toPoint().y()));
104    ui->m_aboutBtn->setProperty("pos", QPoint(xPos,ui->m_aboutBtn->property("pos").toPoint().y()));
105    ui->m_quitBtn->setProperty("pos", QPoint(xPos,ui->m_quitBtn->property("pos").toPoint().y()));
106
107    animateButtons(e->size().width());
108}
109
110void mainMenuFrame::animateButtons(const int width)
111{
112    if (m_animationGrp) {
113        delete m_animationGrp;
114        m_animationGrp = NULL;
115    }
116    m_animationGrp = new QParallelAnimationGroup(this);
117    const int offset = ui->m_newGameBtn->size().width()/2;
118    const int xPoint = width/2 - offset;
119    int yPoint(10);
120    m_animationGrp->addAnimation(createAnimation(ui->m_newGameBtn, QPoint(xPoint,yPoint+=30)));
121    if (ui->m_playCupGameBtn->isEnabled())
122        m_animationGrp->addAnimation(createAnimation(ui->m_playCupGameBtn, QPoint(xPoint,yPoint+=30)));
123    if (ui->m_settingsBtn->isEnabled())
124        m_animationGrp->addAnimation(createAnimation(ui->m_settingsBtn, QPoint(xPoint,yPoint+=30)));
125    if (ui->m_inputBtn->isEnabled())
126        m_animationGrp->addAnimation(createAnimation(ui->m_inputBtn, QPoint(xPoint,yPoint+=30)));
127    m_animationGrp->addAnimation(createAnimation(ui->m_informationBtn, QPoint(xPoint,yPoint+=30)));
128    m_animationGrp->addAnimation(createAnimation(ui->m_aboutBtn, QPoint(xPoint,yPoint+=30)));
129    m_animationGrp->addAnimation(createAnimation(ui->m_quitBtn, QPoint(xPoint,yPoint+=30)));
130}