Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 1 | /*************************************************************************** |
Edric Milaret | 5f316da | 2015-09-28 11:57:42 -0400 | [diff] [blame] | 2 | * Copyright (C) 2015 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 | |
| 21 | NavStack::NavStack(QStackedWidget* bar, QStackedWidget* stack, QWidget *parent) |
| 22 | : bar_(bar) |
| 23 | , stack_(stack) |
| 24 | { |
Edric Milaret | ed0b280 | 2015-10-01 15:10:02 -0400 | [diff] [blame] | 25 | Q_UNUSED(parent) |
| 26 | |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 27 | navList_.append(new NavBar()); |
| 28 | |
| 29 | navList_.append(new CallWidget()); |
| 30 | navList_.append(new ConfigurationWidget()); |
| 31 | |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 32 | for (int i = 0; i < END; i++) { |
| 33 | if (i < CallScreen) |
| 34 | bar_->addWidget(navList_[i]); |
| 35 | else |
| 36 | stack_->addWidget(navList_[i]); |
| 37 | connect(navList_[i], SIGNAL(NavigationRequested(ScreenEnum)), |
| 38 | this, SLOT(onNavigationRequested(ScreenEnum))); |
| 39 | connect(navList_[i], SIGNAL(BackRequested()), |
| 40 | this, SLOT(onBackRequested())); |
| 41 | } |
Edric Milaret | ed0b280 | 2015-10-01 15:10:02 -0400 | [diff] [blame] | 42 | bar_->hide(); |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | NavStack::~NavStack() |
Edric Milaret | 01f2384 | 2015-06-22 14:46:01 -0400 | [diff] [blame] | 46 | { |
| 47 | for (int i = 0; i < END; i++) { |
| 48 | delete navList_[i]; |
| 49 | } |
| 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 |
| 59 | NavStack::onNavigationRequested(ScreenEnum screen) { |
Edric Milaret | 2cf3429 | 2015-06-22 16:27:03 -0400 | [diff] [blame] | 60 | if (navList_[screen] == stack_->currentWidget()) |
| 61 | return; |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 62 | if (screen < CallScreen) { |
Edric Milaret | ed0b280 | 2015-10-01 15:10:02 -0400 | [diff] [blame] | 63 | bar_->show(); |
| 64 | if (auto barItem = navList_[screen]) |
| 65 | bar_->setCurrentWidget(barItem); |
| 66 | else |
| 67 | bar_->hide(); |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 68 | } else { |
| 69 | stack_->setCurrentWidget(navList_[screen]); |
| 70 | setNavBar(navList_[screen]); |
| 71 | stackNav_.append(screen); |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | void |
| 76 | NavStack::onBackRequested() { |
| 77 | |
| 78 | navList_[stackNav_.pop()]->atExit(); |
| 79 | ScreenEnum screen; |
| 80 | |
| 81 | if (stackNav_.size() == 0) |
| 82 | screen = CallScreen; |
| 83 | else |
| 84 | screen = stackNav_.first(); |
| 85 | |
| 86 | stack_->setCurrentWidget(navList_[screen]); |
| 87 | setNavBar(navList_[screen]); |
| 88 | } |
| 89 | |
| 90 | void |
| 91 | NavStack::setNavBar(NavWidget* navW) { |
Edric Milaret | ed0b280 | 2015-10-01 15:10:02 -0400 | [diff] [blame] | 92 | if (navW->barDesired != END) { |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 93 | bar_->setCurrentWidget(navList_[navW->barDesired]); |
Edric Milaret | ed0b280 | 2015-10-01 15:10:02 -0400 | [diff] [blame] | 94 | bar_->show(); |
| 95 | } else { |
| 96 | bar_->hide(); |
| 97 | } |
Edric Milaret | 627500d | 2015-03-27 16:41:40 -0400 | [diff] [blame] | 98 | } |