Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 1 | /*************************************************************************** |
Nicolas Jager | 74fe46f | 2016-02-29 14:55:09 -0500 | [diff] [blame] | 2 | * Copyright (C) 2015-2016 by Savoir-faire Linux * |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 3 | * 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 Jager | 74fe46f | 2016-02-29 14:55:09 -0500 | [diff] [blame] | 21 | #include <QPropertyAnimation> |
| 22 | |
| 23 | NavStack::NavStack(QStackedWidget* stack, QWidget *parent) |
| 24 | : stack_(stack) |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 25 | { |
Edric Milaret | ed0b280 | 2015-10-01 15:10:02 -0400 | [diff] [blame] | 26 | Q_UNUSED(parent) |
| 27 | |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 28 | navList_.append(new CallWidget()); |
| 29 | navList_.append(new ConfigurationWidget()); |
| 30 | |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 31 | for (int i = 0; i < END; i++) { |
Nicolas Jager | 74fe46f | 2016-02-29 14:55:09 -0500 | [diff] [blame] | 32 | stack_->addWidget(navList_[i]); |
| 33 | connect(navList_[i], |
| 34 | SIGNAL(NavigationRequested(ScreenEnum)), |
| 35 | this, |
| 36 | SLOT(onNavigationRequested(ScreenEnum))); |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 37 | } |
Nicolas Jager | 74fe46f | 2016-02-29 14:55:09 -0500 | [diff] [blame] | 38 | slideStacked_ = new QPropertyAnimation(); |
| 39 | slideStacked_->setPropertyName("pos"); |
| 40 | slideStacked_->setDuration(animDuration_); |
| 41 | slideStacked_->setEasingCurve(QEasingCurve::OutQuad); |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | NavStack::~NavStack() |
Edric Milaret | 01f2384 | 2015-06-22 14:46:01 -0400 | [diff] [blame] | 45 | { |
| 46 | for (int i = 0; i < END; i++) { |
| 47 | delete navList_[i]; |
| 48 | } |
Nicolas Jager | 74fe46f | 2016-02-29 14:55:09 -0500 | [diff] [blame] | 49 | delete slideStacked_; |
Edric Milaret | 01f2384 | 2015-06-22 14:46:01 -0400 | [diff] [blame] | 50 | } |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 51 | |
Nicolas Jager | 97a21b4 | 2015-12-03 16:55:45 -0500 | [diff] [blame] | 52 | NavWidget* |
| 53 | NavStack::getNavWidget(ScreenEnum wantedNavWidget) |
| 54 | { |
| 55 | return navList_[wantedNavWidget]; |
| 56 | } |
| 57 | |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 58 | void |
Nicolas Jager | 74fe46f | 2016-02-29 14:55:09 -0500 | [diff] [blame] | 59 | NavStack::onNavigationRequested(ScreenEnum screen) |
| 60 | { |
Edric Milaret | 2cf3429 | 2015-06-22 16:27:03 -0400 | [diff] [blame] | 61 | if (navList_[screen] == stack_->currentWidget()) |
| 62 | return; |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 63 | |
| 64 | stack_->setCurrentWidget(navList_[screen]); |
Nicolas Jager | 74fe46f | 2016-02-29 14:55:09 -0500 | [diff] [blame] | 65 | stackNav_.append(screen); |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 66 | |
Nicolas Jager | 74fe46f | 2016-02-29 14:55:09 -0500 | [diff] [blame] | 67 | 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 Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 74 | } |