blob: 21f13e87deff16e41666eeae6f6564e70fdb5cd2 [file] [log] [blame]
Edric Milaret627500d2015-03-27 16:41:40 -04001/***************************************************************************
Nicolas Jager74fe46f2016-02-29 14:55:09 -05002 * Copyright (C) 2015-2016 by Savoir-faire Linux *
Edric Milaret627500d2015-03-27 16:41:40 -04003 * Author: Edric Ladent Milaret <edric.ladent-milaret@savoirfairelinux.com>*
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 3 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
17 **************************************************************************/
18
19#include "navstack.h"
20
Nicolas Jager74fe46f2016-02-29 14:55:09 -050021#include <QPropertyAnimation>
22
23NavStack::NavStack(QStackedWidget* stack, QWidget *parent)
24 : stack_(stack)
Edric Milaret627500d2015-03-27 16:41:40 -040025{
Edric Milareted0b2802015-10-01 15:10:02 -040026 Q_UNUSED(parent)
27
Edric Milaret627500d2015-03-27 16:41:40 -040028 navList_.append(new CallWidget());
29 navList_.append(new ConfigurationWidget());
30
Edric Milaret627500d2015-03-27 16:41:40 -040031 for (int i = 0; i < END; i++) {
Nicolas Jager74fe46f2016-02-29 14:55:09 -050032 stack_->addWidget(navList_[i]);
33 connect(navList_[i],
34 SIGNAL(NavigationRequested(ScreenEnum)),
35 this,
36 SLOT(onNavigationRequested(ScreenEnum)));
Edric Milaret627500d2015-03-27 16:41:40 -040037 }
Nicolas Jager74fe46f2016-02-29 14:55:09 -050038 slideStacked_ = new QPropertyAnimation();
39 slideStacked_->setPropertyName("pos");
40 slideStacked_->setDuration(animDuration_);
41 slideStacked_->setEasingCurve(QEasingCurve::OutQuad);
Edric Milaret627500d2015-03-27 16:41:40 -040042}
43
44NavStack::~NavStack()
Edric Milaret01f23842015-06-22 14:46:01 -040045{
46 for (int i = 0; i < END; i++) {
47 delete navList_[i];
48 }
Nicolas Jager74fe46f2016-02-29 14:55:09 -050049 delete slideStacked_;
Edric Milaret01f23842015-06-22 14:46:01 -040050}
Edric Milaret627500d2015-03-27 16:41:40 -040051
Nicolas Jager97a21b42015-12-03 16:55:45 -050052NavWidget*
53NavStack::getNavWidget(ScreenEnum wantedNavWidget)
54{
55 return navList_[wantedNavWidget];
56}
57
Edric Milaret627500d2015-03-27 16:41:40 -040058void
Nicolas Jager74fe46f2016-02-29 14:55:09 -050059NavStack::onNavigationRequested(ScreenEnum screen)
60{
Edric Milaret2cf34292015-06-22 16:27:03 -040061 if (navList_[screen] == stack_->currentWidget())
62 return;
Edric Milaret627500d2015-03-27 16:41:40 -040063
64 stack_->setCurrentWidget(navList_[screen]);
Nicolas Jager74fe46f2016-02-29 14:55:09 -050065 stackNav_.append(screen);
Edric Milaret627500d2015-03-27 16:41:40 -040066
Nicolas Jager74fe46f2016-02-29 14:55:09 -050067 slideStacked_->setTargetObject(navList_[screen]);
68 if(screen == CallScreen)
69 slideStacked_->setStartValue(-QPoint(navList_[screen]->width(), navList_[screen]->y()));
70 else
71 slideStacked_->setStartValue(QPoint(navList_[screen]->width(), navList_[screen]->y()));
72 slideStacked_->setEndValue(QPoint(navList_[screen]->x(), navList_[screen]->y()));
73 slideStacked_->start();
Edric Milaret627500d2015-03-27 16:41:40 -040074}